blob: c13efc3268d8eb3bdf9389339c2b1f23eb427c9d [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
Kashyap, Desai31b7f2e2010-03-17 16:28:04 +05305 * Copyright (C) 2007-2010 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);
102MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 8192 default=8192");
103
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
Eric Moore635374e2009-03-09 01:21:12 -0600122/**
123 * struct sense_info - common structure for obtaining sense keys
124 * @skey: sense key
125 * @asc: additional sense code
126 * @ascq: additional sense code qualifier
127 */
128struct sense_info {
129 u8 skey;
130 u8 asc;
131 u8 ascq;
132};
133
134
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530135#define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530136#define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
137#define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
Eric Moore635374e2009-03-09 01:21:12 -0600138/**
139 * struct fw_event_work - firmware event struct
140 * @list: link list framework
141 * @work: work object (ioc->fault_reset_work_q)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530142 * @cancel_pending_work: flag set during reset handling
Eric Moore635374e2009-03-09 01:21:12 -0600143 * @ioc: per adapter object
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530144 * @device_handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -0600145 * @VF_ID: virtual function id
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530146 * @VP_ID: virtual port id
Eric Moore635374e2009-03-09 01:21:12 -0600147 * @ignore: flag meaning this event has been marked to ignore
148 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
149 * @event_data: reply event data payload follows
150 *
151 * This object stored on ioc->fw_event_list.
152 */
153struct fw_event_work {
154 struct list_head list;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +0530155 u8 cancel_pending_work;
156 struct delayed_work delayed_work;
Eric Moore635374e2009-03-09 01:21:12 -0600157 struct MPT2SAS_ADAPTER *ioc;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +0530158 u16 device_handle;
Eric Moore635374e2009-03-09 01:21:12 -0600159 u8 VF_ID;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530160 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600161 u8 ignore;
162 u16 event;
163 void *event_data;
164};
165
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +0530166/* raid transport support */
167static struct raid_template *mpt2sas_raid_template;
168
Eric Moore635374e2009-03-09 01:21:12 -0600169/**
170 * struct _scsi_io_transfer - scsi io transfer
171 * @handle: sas device handle (assigned by firmware)
172 * @is_raid: flag set for hidden raid components
173 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
174 * @data_length: data transfer length
175 * @data_dma: dma pointer to data
176 * @sense: sense data
177 * @lun: lun number
178 * @cdb_length: cdb length
179 * @cdb: cdb contents
Eric Moore635374e2009-03-09 01:21:12 -0600180 * @timeout: timeout for this command
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530181 * @VF_ID: virtual function id
182 * @VP_ID: virtual port id
183 * @valid_reply: flag set for reply message
Eric Moore635374e2009-03-09 01:21:12 -0600184 * @sense_length: sense length
185 * @ioc_status: ioc status
186 * @scsi_state: scsi state
187 * @scsi_status: scsi staus
188 * @log_info: log information
189 * @transfer_length: data length transfer when there is a reply message
190 *
191 * Used for sending internal scsi commands to devices within this module.
192 * Refer to _scsi_send_scsi_io().
193 */
194struct _scsi_io_transfer {
195 u16 handle;
196 u8 is_raid;
197 enum dma_data_direction dir;
198 u32 data_length;
199 dma_addr_t data_dma;
200 u8 sense[SCSI_SENSE_BUFFERSIZE];
201 u32 lun;
202 u8 cdb_length;
203 u8 cdb[32];
204 u8 timeout;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530205 u8 VF_ID;
206 u8 VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -0600207 u8 valid_reply;
208 /* the following bits are only valid when 'valid_reply = 1' */
209 u32 sense_length;
210 u16 ioc_status;
211 u8 scsi_state;
212 u8 scsi_status;
213 u32 log_info;
214 u32 transfer_length;
215};
216
217/*
218 * The pci device ids are defined in mpi/mpi2_cnfg.h.
219 */
220static struct pci_device_id scsih_pci_table[] = {
221 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
222 PCI_ANY_ID, PCI_ANY_ID },
223 /* Falcon ~ 2008*/
224 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
225 PCI_ANY_ID, PCI_ANY_ID },
226 /* Liberator ~ 2108 */
227 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
228 PCI_ANY_ID, PCI_ANY_ID },
229 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
230 PCI_ANY_ID, PCI_ANY_ID },
231 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
232 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530233 /* Meteor ~ 2116 */
Eric Moore635374e2009-03-09 01:21:12 -0600234 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
235 PCI_ANY_ID, PCI_ANY_ID },
236 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
237 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desaidb271362009-09-23 17:24:27 +0530238 /* Thunderbolt ~ 2208 */
239 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
240 PCI_ANY_ID, PCI_ANY_ID },
241 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
242 PCI_ANY_ID, PCI_ANY_ID },
243 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
244 PCI_ANY_ID, PCI_ANY_ID },
245 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
246 PCI_ANY_ID, PCI_ANY_ID },
247 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
248 PCI_ANY_ID, PCI_ANY_ID },
249 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
250 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530251 /* Mustang ~ 2308 */
252 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530253 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai203d65b2010-06-17 13:37:59 +0530254 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
255 PCI_ANY_ID, PCI_ANY_ID },
256 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
Kashyap, Desaidb271362009-09-23 17:24:27 +0530257 PCI_ANY_ID, PCI_ANY_ID },
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530258 /* SSS6200 */
259 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
260 PCI_ANY_ID, PCI_ANY_ID },
Eric Moore635374e2009-03-09 01:21:12 -0600261 {0} /* Terminating entry */
262};
263MODULE_DEVICE_TABLE(pci, scsih_pci_table);
264
265/**
Eric Moored5d135b2009-05-18 13:02:08 -0600266 * _scsih_set_debug_level - global setting of ioc->logging_level.
Eric Moore635374e2009-03-09 01:21:12 -0600267 *
268 * Note: The logging levels are defined in mpt2sas_debug.h.
269 */
270static int
Eric Moored5d135b2009-05-18 13:02:08 -0600271_scsih_set_debug_level(const char *val, struct kernel_param *kp)
Eric Moore635374e2009-03-09 01:21:12 -0600272{
273 int ret = param_set_int(val, kp);
274 struct MPT2SAS_ADAPTER *ioc;
275
276 if (ret)
277 return ret;
278
279 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
Eric Mooreba33fad2009-03-15 21:37:18 -0600280 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
Eric Moore635374e2009-03-09 01:21:12 -0600281 ioc->logging_level = logging_level;
282 return 0;
283}
Eric Moored5d135b2009-05-18 13:02:08 -0600284module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
Eric Moore635374e2009-03-09 01:21:12 -0600285 &logging_level, 0644);
286
287/**
288 * _scsih_srch_boot_sas_address - search based on sas_address
289 * @sas_address: sas address
290 * @boot_device: boot device object from bios page 2
291 *
292 * Returns 1 when there's a match, 0 means no match.
293 */
294static inline int
295_scsih_srch_boot_sas_address(u64 sas_address,
296 Mpi2BootDeviceSasWwid_t *boot_device)
297{
298 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
299}
300
301/**
302 * _scsih_srch_boot_device_name - search based on device name
303 * @device_name: device name specified in INDENTIFY fram
304 * @boot_device: boot device object from bios page 2
305 *
306 * Returns 1 when there's a match, 0 means no match.
307 */
308static inline int
309_scsih_srch_boot_device_name(u64 device_name,
310 Mpi2BootDeviceDeviceName_t *boot_device)
311{
312 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
313}
314
315/**
316 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
317 * @enclosure_logical_id: enclosure logical id
318 * @slot_number: slot number
319 * @boot_device: boot device object from bios page 2
320 *
321 * Returns 1 when there's a match, 0 means no match.
322 */
323static inline int
324_scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
325 Mpi2BootDeviceEnclosureSlot_t *boot_device)
326{
327 return (enclosure_logical_id == le64_to_cpu(boot_device->
328 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
329 SlotNumber)) ? 1 : 0;
330}
331
332/**
333 * _scsih_is_boot_device - search for matching boot device.
334 * @sas_address: sas address
335 * @device_name: device name specified in INDENTIFY fram
336 * @enclosure_logical_id: enclosure logical id
337 * @slot_number: slot number
338 * @form: specifies boot device form
339 * @boot_device: boot device object from bios page 2
340 *
341 * Returns 1 when there's a match, 0 means no match.
342 */
343static int
344_scsih_is_boot_device(u64 sas_address, u64 device_name,
345 u64 enclosure_logical_id, u16 slot, u8 form,
346 Mpi2BiosPage2BootDevice_t *boot_device)
347{
348 int rc = 0;
349
350 switch (form) {
351 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
352 if (!sas_address)
353 break;
354 rc = _scsih_srch_boot_sas_address(
355 sas_address, &boot_device->SasWwid);
356 break;
357 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
358 if (!enclosure_logical_id)
359 break;
360 rc = _scsih_srch_boot_encl_slot(
361 enclosure_logical_id,
362 slot, &boot_device->EnclosureSlot);
363 break;
364 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
365 if (!device_name)
366 break;
367 rc = _scsih_srch_boot_device_name(
368 device_name, &boot_device->DeviceName);
369 break;
370 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
371 break;
372 }
373
374 return rc;
375}
376
377/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530378 * _scsih_get_sas_address - set the sas_address for given device handle
379 * @handle: device handle
380 * @sas_address: sas address
381 *
382 * Returns 0 success, non-zero when failure
383 */
384static int
385_scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
386 u64 *sas_address)
387{
388 Mpi2SasDevicePage0_t sas_device_pg0;
389 Mpi2ConfigReply_t mpi_reply;
390 u32 ioc_status;
391
392 if (handle <= ioc->sas_hba.num_phys) {
393 *sas_address = ioc->sas_hba.sas_address;
394 return 0;
395 } else
396 *sas_address = 0;
397
398 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
399 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
400 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
401 ioc->name, __FILE__, __LINE__, __func__);
402 return -ENXIO;
403 }
404
405 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
406 MPI2_IOCSTATUS_MASK;
407 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
408 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)"
409 "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
410 __FILE__, __LINE__, __func__);
411 return -EIO;
412 }
413
414 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
415 return 0;
416}
417
418/**
Eric Moore635374e2009-03-09 01:21:12 -0600419 * _scsih_determine_boot_device - determine boot device.
420 * @ioc: per adapter object
421 * @device: either sas_device or raid_device object
422 * @is_raid: [flag] 1 = raid object, 0 = sas object
423 *
424 * Determines whether this device should be first reported device to
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300425 * to scsi-ml or sas transport, this purpose is for persistent boot device.
Eric Moore635374e2009-03-09 01:21:12 -0600426 * There are primary, alternate, and current entries in bios page 2. The order
427 * priority is primary, alternate, then current. This routine saves
428 * the corresponding device object and is_raid flag in the ioc object.
429 * The saved data to be used later in _scsih_probe_boot_devices().
430 */
431static void
432_scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
433 void *device, u8 is_raid)
434{
435 struct _sas_device *sas_device;
436 struct _raid_device *raid_device;
437 u64 sas_address;
438 u64 device_name;
439 u64 enclosure_logical_id;
440 u16 slot;
441
442 /* only process this function when driver loads */
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530443 if (!ioc->is_driver_loading)
444 return;
445
446 /* no Bios, return immediately */
447 if (!ioc->bios_pg3.BiosVersion)
Eric Moore635374e2009-03-09 01:21:12 -0600448 return;
449
450 if (!is_raid) {
451 sas_device = device;
452 sas_address = sas_device->sas_address;
453 device_name = sas_device->device_name;
454 enclosure_logical_id = sas_device->enclosure_logical_id;
455 slot = sas_device->slot;
456 } else {
457 raid_device = device;
458 sas_address = raid_device->wwid;
459 device_name = 0;
460 enclosure_logical_id = 0;
461 slot = 0;
462 }
463
464 if (!ioc->req_boot_device.device) {
465 if (_scsih_is_boot_device(sas_address, device_name,
466 enclosure_logical_id, slot,
467 (ioc->bios_pg2.ReqBootDeviceForm &
468 MPI2_BIOSPAGE2_FORM_MASK),
469 &ioc->bios_pg2.RequestedBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530470 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600471 "%s: req_boot_device(0x%016llx)\n",
472 ioc->name, __func__,
473 (unsigned long long)sas_address));
474 ioc->req_boot_device.device = device;
475 ioc->req_boot_device.is_raid = is_raid;
476 }
477 }
478
479 if (!ioc->req_alt_boot_device.device) {
480 if (_scsih_is_boot_device(sas_address, device_name,
481 enclosure_logical_id, slot,
482 (ioc->bios_pg2.ReqAltBootDeviceForm &
483 MPI2_BIOSPAGE2_FORM_MASK),
484 &ioc->bios_pg2.RequestedAltBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530485 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600486 "%s: req_alt_boot_device(0x%016llx)\n",
487 ioc->name, __func__,
488 (unsigned long long)sas_address));
489 ioc->req_alt_boot_device.device = device;
490 ioc->req_alt_boot_device.is_raid = is_raid;
491 }
492 }
493
494 if (!ioc->current_boot_device.device) {
495 if (_scsih_is_boot_device(sas_address, device_name,
496 enclosure_logical_id, slot,
497 (ioc->bios_pg2.CurrentBootDeviceForm &
498 MPI2_BIOSPAGE2_FORM_MASK),
499 &ioc->bios_pg2.CurrentBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530500 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600501 "%s: current_boot_device(0x%016llx)\n",
502 ioc->name, __func__,
503 (unsigned long long)sas_address));
504 ioc->current_boot_device.device = device;
505 ioc->current_boot_device.is_raid = is_raid;
506 }
507 }
508}
509
510/**
511 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
512 * @ioc: per adapter object
513 * @sas_address: sas address
514 * Context: Calling function should acquire ioc->sas_device_lock
515 *
516 * This searches for sas_device based on sas_address, then return sas_device
517 * object.
518 */
519struct _sas_device *
520mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
521 u64 sas_address)
522{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530523 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600524
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530525 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
526 if (sas_device->sas_address == sas_address)
527 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600528
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530529 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
530 if (sas_device->sas_address == sas_address)
531 return sas_device;
532
533 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600534}
535
536/**
537 * _scsih_sas_device_find_by_handle - sas device search
538 * @ioc: per adapter object
539 * @handle: sas device handle (assigned by firmware)
540 * Context: Calling function should acquire ioc->sas_device_lock
541 *
542 * This searches for sas_device based on sas_address, then return sas_device
543 * object.
544 */
545static struct _sas_device *
546_scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
547{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530548 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600549
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530550 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
551 if (sas_device->handle == handle)
552 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600553
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530554 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
555 if (sas_device->handle == handle)
556 return sas_device;
557
558 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600559}
560
561/**
562 * _scsih_sas_device_remove - remove sas_device from list.
563 * @ioc: per adapter object
564 * @sas_device: the sas_device object
565 * Context: This function will acquire ioc->sas_device_lock.
566 *
567 * Removing object and freeing associated memory from the ioc->sas_device_list.
568 */
569static void
570_scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
571 struct _sas_device *sas_device)
572{
573 unsigned long flags;
574
Kashyap, Desai980ead32010-04-08 17:55:22 +0530575 if (!sas_device)
576 return;
577
Eric Moore635374e2009-03-09 01:21:12 -0600578 spin_lock_irqsave(&ioc->sas_device_lock, flags);
Kashyap, Desai980ead32010-04-08 17:55:22 +0530579 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
580 sas_device->sas_address)) {
581 list_del(&sas_device->list);
582 kfree(sas_device);
583 }
Eric Moore635374e2009-03-09 01:21:12 -0600584 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
585}
586
587/**
588 * _scsih_sas_device_add - insert sas_device to the list.
589 * @ioc: per adapter object
590 * @sas_device: the sas_device object
591 * Context: This function will acquire ioc->sas_device_lock.
592 *
593 * Adding new object to the ioc->sas_device_list.
594 */
595static void
596_scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
597 struct _sas_device *sas_device)
598{
599 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -0600600
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530601 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600602 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
603 sas_device->handle, (unsigned long long)sas_device->sas_address));
604
605 spin_lock_irqsave(&ioc->sas_device_lock, flags);
606 list_add_tail(&sas_device->list, &ioc->sas_device_list);
607 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
608
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530609 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
610 sas_device->sas_address_parent))
Eric Moore635374e2009-03-09 01:21:12 -0600611 _scsih_sas_device_remove(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -0600612}
613
614/**
615 * _scsih_sas_device_init_add - insert sas_device to the list.
616 * @ioc: per adapter object
617 * @sas_device: the sas_device object
618 * Context: This function will acquire ioc->sas_device_lock.
619 *
620 * Adding new object at driver load time to the ioc->sas_device_init_list.
621 */
622static void
623_scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
624 struct _sas_device *sas_device)
625{
626 unsigned long flags;
627
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530628 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600629 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
630 sas_device->handle, (unsigned long long)sas_device->sas_address));
631
632 spin_lock_irqsave(&ioc->sas_device_lock, flags);
633 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
634 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
635 _scsih_determine_boot_device(ioc, sas_device, 0);
636}
637
638/**
Eric Moore635374e2009-03-09 01:21:12 -0600639 * _scsih_raid_device_find_by_id - raid device search
640 * @ioc: per adapter object
641 * @id: sas device target id
642 * @channel: sas device channel
643 * Context: Calling function should acquire ioc->raid_device_lock
644 *
645 * This searches for raid_device based on target id, then return raid_device
646 * object.
647 */
648static struct _raid_device *
649_scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
650{
651 struct _raid_device *raid_device, *r;
652
653 r = NULL;
654 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
655 if (raid_device->id == id && raid_device->channel == channel) {
656 r = raid_device;
657 goto out;
658 }
659 }
660
661 out:
662 return r;
663}
664
665/**
666 * _scsih_raid_device_find_by_handle - raid device search
667 * @ioc: per adapter object
668 * @handle: sas device handle (assigned by firmware)
669 * Context: Calling function should acquire ioc->raid_device_lock
670 *
671 * This searches for raid_device based on handle, then return raid_device
672 * object.
673 */
674static struct _raid_device *
675_scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
676{
677 struct _raid_device *raid_device, *r;
678
679 r = NULL;
680 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
681 if (raid_device->handle != handle)
682 continue;
683 r = raid_device;
684 goto out;
685 }
686
687 out:
688 return r;
689}
690
691/**
692 * _scsih_raid_device_find_by_wwid - raid device search
693 * @ioc: per adapter object
694 * @handle: sas device handle (assigned by firmware)
695 * Context: Calling function should acquire ioc->raid_device_lock
696 *
697 * This searches for raid_device based on wwid, then return raid_device
698 * object.
699 */
700static struct _raid_device *
701_scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
702{
703 struct _raid_device *raid_device, *r;
704
705 r = NULL;
706 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
707 if (raid_device->wwid != wwid)
708 continue;
709 r = raid_device;
710 goto out;
711 }
712
713 out:
714 return r;
715}
716
717/**
718 * _scsih_raid_device_add - add raid_device object
719 * @ioc: per adapter object
720 * @raid_device: raid_device object
721 *
722 * This is added to the raid_device_list link list.
723 */
724static void
725_scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
726 struct _raid_device *raid_device)
727{
728 unsigned long flags;
729
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530730 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600731 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
732 raid_device->handle, (unsigned long long)raid_device->wwid));
733
734 spin_lock_irqsave(&ioc->raid_device_lock, flags);
735 list_add_tail(&raid_device->list, &ioc->raid_device_list);
736 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
737}
738
739/**
740 * _scsih_raid_device_remove - delete raid_device object
741 * @ioc: per adapter object
742 * @raid_device: raid_device object
743 *
744 * This is removed from the raid_device_list link list.
745 */
746static void
747_scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
748 struct _raid_device *raid_device)
749{
750 unsigned long flags;
751
752 spin_lock_irqsave(&ioc->raid_device_lock, flags);
753 list_del(&raid_device->list);
754 memset(raid_device, 0, sizeof(struct _raid_device));
755 kfree(raid_device);
756 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
757}
758
759/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530760 * mpt2sas_scsih_expander_find_by_handle - expander device search
761 * @ioc: per adapter object
762 * @handle: expander handle (assigned by firmware)
763 * Context: Calling function should acquire ioc->sas_device_lock
764 *
765 * This searches for expander device based on handle, then returns the
766 * sas_node object.
767 */
768struct _sas_node *
769mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
770{
771 struct _sas_node *sas_expander, *r;
772
773 r = NULL;
774 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
775 if (sas_expander->handle != handle)
776 continue;
777 r = sas_expander;
778 goto out;
779 }
780 out:
781 return r;
782}
783
784/**
Eric Moore635374e2009-03-09 01:21:12 -0600785 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
786 * @ioc: per adapter object
787 * @sas_address: sas address
788 * Context: Calling function should acquire ioc->sas_node_lock.
789 *
790 * This searches for expander device based on sas_address, then returns the
791 * sas_node object.
792 */
793struct _sas_node *
794mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
795 u64 sas_address)
796{
797 struct _sas_node *sas_expander, *r;
798
799 r = NULL;
800 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
801 if (sas_expander->sas_address != sas_address)
802 continue;
803 r = sas_expander;
804 goto out;
805 }
806 out:
807 return r;
808}
809
810/**
811 * _scsih_expander_node_add - insert expander device to the list.
812 * @ioc: per adapter object
813 * @sas_expander: the sas_device object
814 * Context: This function will acquire ioc->sas_node_lock.
815 *
816 * Adding new object to the ioc->sas_expander_list.
817 *
818 * Return nothing.
819 */
820static void
821_scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
822 struct _sas_node *sas_expander)
823{
824 unsigned long flags;
825
826 spin_lock_irqsave(&ioc->sas_node_lock, flags);
827 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
828 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
829}
830
831/**
832 * _scsih_is_end_device - determines if device is an end device
833 * @device_info: bitfield providing information about the device.
834 * Context: none
835 *
836 * Returns 1 if end device.
837 */
838static int
839_scsih_is_end_device(u32 device_info)
840{
841 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
842 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
843 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
844 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
845 return 1;
846 else
847 return 0;
848}
849
850/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530851 * _scsih_scsi_lookup_get - returns scmd entry
Eric Moore635374e2009-03-09 01:21:12 -0600852 * @ioc: per adapter object
853 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -0600854 *
855 * Returns the smid stored scmd pointer.
856 */
857static struct scsi_cmnd *
858_scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
859{
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530860 return ioc->scsi_lookup[smid - 1].scmd;
Eric Moore635374e2009-03-09 01:21:12 -0600861}
862
863/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530864 * _scsih_scsi_lookup_get_clear - returns scmd entry
865 * @ioc: per adapter object
866 * @smid: system request message index
867 *
868 * Returns the smid stored scmd pointer.
869 * Then will derefrence the stored scmd pointer.
870 */
871static inline struct scsi_cmnd *
872_scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
873{
874 unsigned long flags;
875 struct scsi_cmnd *scmd;
876
877 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
878 scmd = ioc->scsi_lookup[smid - 1].scmd;
879 ioc->scsi_lookup[smid - 1].scmd = NULL;
880 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
881
882 return scmd;
883}
884
885/**
Eric Moore635374e2009-03-09 01:21:12 -0600886 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
887 * @ioc: per adapter object
888 * @smid: system request message index
889 * @scmd: pointer to scsi command object
890 * Context: This function will acquire ioc->scsi_lookup_lock.
891 *
892 * This will search for a scmd pointer in the scsi_lookup array,
893 * returning the revelent smid. A returned value of zero means invalid.
894 */
895static u16
896_scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
897 *scmd)
898{
899 u16 smid;
900 unsigned long flags;
901 int i;
902
903 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
904 smid = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530905 for (i = 0; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600906 if (ioc->scsi_lookup[i].scmd == scmd) {
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530907 smid = ioc->scsi_lookup[i].smid;
Eric Moore635374e2009-03-09 01:21:12 -0600908 goto out;
909 }
910 }
911 out:
912 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
913 return smid;
914}
915
916/**
917 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
918 * @ioc: per adapter object
919 * @id: target id
920 * @channel: channel
921 * Context: This function will acquire ioc->scsi_lookup_lock.
922 *
923 * This will search for a matching channel:id in the scsi_lookup array,
924 * returning 1 if found.
925 */
926static u8
927_scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
928 int channel)
929{
930 u8 found;
931 unsigned long flags;
932 int i;
933
934 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
935 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530936 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600937 if (ioc->scsi_lookup[i].scmd &&
938 (ioc->scsi_lookup[i].scmd->device->id == id &&
939 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
940 found = 1;
941 goto out;
942 }
943 }
944 out:
945 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
946 return found;
947}
948
949/**
Eric Moore993e0da2009-05-18 13:00:45 -0600950 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
951 * @ioc: per adapter object
952 * @id: target id
953 * @lun: lun number
954 * @channel: channel
955 * Context: This function will acquire ioc->scsi_lookup_lock.
956 *
957 * This will search for a matching channel:id:lun in the scsi_lookup array,
958 * returning 1 if found.
959 */
960static u8
961_scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
962 unsigned int lun, int channel)
963{
964 u8 found;
965 unsigned long flags;
966 int i;
967
968 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
969 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530970 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore993e0da2009-05-18 13:00:45 -0600971 if (ioc->scsi_lookup[i].scmd &&
972 (ioc->scsi_lookup[i].scmd->device->id == id &&
973 ioc->scsi_lookup[i].scmd->device->channel == channel &&
974 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
975 found = 1;
976 goto out;
977 }
978 }
979 out:
980 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
981 return found;
982}
983
984/**
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530985 * _scsih_get_chain_buffer_tracker - obtain chain tracker
Eric Moore635374e2009-03-09 01:21:12 -0600986 * @ioc: per adapter object
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530987 * @smid: smid associated to an IO request
Eric Moore635374e2009-03-09 01:21:12 -0600988 *
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530989 * Returns chain tracker(from ioc->free_chain_list)
Eric Moore635374e2009-03-09 01:21:12 -0600990 */
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530991static struct chain_tracker *
992_scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
Eric Moore635374e2009-03-09 01:21:12 -0600993{
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530994 struct chain_tracker *chain_req;
995 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -0600996
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530997 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
998 if (list_empty(&ioc->free_chain_list)) {
999 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1000 printk(MPT2SAS_WARN_FMT "chain buffers not available\n",
1001 ioc->name);
1002 return NULL;
1003 }
1004 chain_req = list_entry(ioc->free_chain_list.next,
1005 struct chain_tracker, tracker_list);
1006 list_del_init(&chain_req->tracker_list);
1007 list_add_tail(&chain_req->tracker_list,
1008 &ioc->scsi_lookup[smid - 1].chain_list);
1009 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1010 return chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001011}
1012
1013/**
1014 * _scsih_build_scatter_gather - main sg creation routine
1015 * @ioc: per adapter object
1016 * @scmd: scsi command
1017 * @smid: system request message index
1018 * Context: none.
1019 *
1020 * The main routine that builds scatter gather table from a given
1021 * scsi request sent via the .queuecommand main handler.
1022 *
1023 * Returns 0 success, anything else error
1024 */
1025static int
1026_scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1027 struct scsi_cmnd *scmd, u16 smid)
1028{
1029 Mpi2SCSIIORequest_t *mpi_request;
1030 dma_addr_t chain_dma;
1031 struct scatterlist *sg_scmd;
1032 void *sg_local, *chain;
1033 u32 chain_offset;
1034 u32 chain_length;
1035 u32 chain_flags;
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001036 int sges_left;
Eric Moore635374e2009-03-09 01:21:12 -06001037 u32 sges_in_segment;
1038 u32 sgl_flags;
1039 u32 sgl_flags_last_element;
1040 u32 sgl_flags_end_buffer;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301041 struct chain_tracker *chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001042
1043 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1044
1045 /* init scatter gather flags */
1046 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1047 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1048 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1049 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1050 << MPI2_SGE_FLAGS_SHIFT;
1051 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1052 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1053 << MPI2_SGE_FLAGS_SHIFT;
1054 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1055
1056 sg_scmd = scsi_sglist(scmd);
1057 sges_left = scsi_dma_map(scmd);
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001058 if (sges_left < 0) {
Eric Moore635374e2009-03-09 01:21:12 -06001059 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1060 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1061 return -ENOMEM;
1062 }
1063
1064 sg_local = &mpi_request->SGL;
1065 sges_in_segment = ioc->max_sges_in_main_message;
1066 if (sges_left <= sges_in_segment)
1067 goto fill_in_last_segment;
1068
1069 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1070 (sges_in_segment * ioc->sge_size))/4;
1071
1072 /* fill in main message segment when there is a chain following */
1073 while (sges_in_segment) {
1074 if (sges_in_segment == 1)
1075 ioc->base_add_sg_single(sg_local,
1076 sgl_flags_last_element | sg_dma_len(sg_scmd),
1077 sg_dma_address(sg_scmd));
1078 else
1079 ioc->base_add_sg_single(sg_local, sgl_flags |
1080 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1081 sg_scmd = sg_next(sg_scmd);
1082 sg_local += ioc->sge_size;
1083 sges_left--;
1084 sges_in_segment--;
1085 }
1086
1087 /* initializing the chain flags and pointers */
1088 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301089 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1090 if (!chain_req)
1091 return -1;
1092 chain = chain_req->chain_buffer;
1093 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001094 do {
1095 sges_in_segment = (sges_left <=
1096 ioc->max_sges_in_chain_message) ? sges_left :
1097 ioc->max_sges_in_chain_message;
1098 chain_offset = (sges_left == sges_in_segment) ?
1099 0 : (sges_in_segment * ioc->sge_size)/4;
1100 chain_length = sges_in_segment * ioc->sge_size;
1101 if (chain_offset) {
1102 chain_offset = chain_offset <<
1103 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1104 chain_length += ioc->sge_size;
1105 }
1106 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1107 chain_length, chain_dma);
1108 sg_local = chain;
1109 if (!chain_offset)
1110 goto fill_in_last_segment;
1111
1112 /* fill in chain segments */
1113 while (sges_in_segment) {
1114 if (sges_in_segment == 1)
1115 ioc->base_add_sg_single(sg_local,
1116 sgl_flags_last_element |
1117 sg_dma_len(sg_scmd),
1118 sg_dma_address(sg_scmd));
1119 else
1120 ioc->base_add_sg_single(sg_local, sgl_flags |
1121 sg_dma_len(sg_scmd),
1122 sg_dma_address(sg_scmd));
1123 sg_scmd = sg_next(sg_scmd);
1124 sg_local += ioc->sge_size;
1125 sges_left--;
1126 sges_in_segment--;
1127 }
1128
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301129 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1130 if (!chain_req)
1131 return -1;
1132 chain = chain_req->chain_buffer;
1133 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001134 } while (1);
1135
1136
1137 fill_in_last_segment:
1138
1139 /* fill the last segment */
1140 while (sges_left) {
1141 if (sges_left == 1)
1142 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1143 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1144 else
1145 ioc->base_add_sg_single(sg_local, sgl_flags |
1146 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1147 sg_scmd = sg_next(sg_scmd);
1148 sg_local += ioc->sge_size;
1149 sges_left--;
1150 }
1151
1152 return 0;
1153}
1154
1155/**
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301156 * _scsih_adjust_queue_depth - setting device queue depth
Eric Moore635374e2009-03-09 01:21:12 -06001157 * @sdev: scsi device struct
1158 * @qdepth: requested queue depth
1159 *
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301160 *
1161 * Returns nothing
Eric Moore635374e2009-03-09 01:21:12 -06001162 */
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301163static void
1164_scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
Eric Moore635374e2009-03-09 01:21:12 -06001165{
1166 struct Scsi_Host *shost = sdev->host;
1167 int max_depth;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301168 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1169 struct MPT2SAS_DEVICE *sas_device_priv_data;
1170 struct MPT2SAS_TARGET *sas_target_priv_data;
1171 struct _sas_device *sas_device;
1172 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001173
1174 max_depth = shost->can_queue;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301175
1176 /* limit max device queue for SATA to 32 */
1177 sas_device_priv_data = sdev->hostdata;
1178 if (!sas_device_priv_data)
1179 goto not_sata;
1180 sas_target_priv_data = sas_device_priv_data->sas_target;
1181 if (!sas_target_priv_data)
1182 goto not_sata;
1183 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1184 goto not_sata;
1185 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1186 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1187 sas_device_priv_data->sas_target->sas_address);
1188 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1189 if (sas_device && sas_device->device_info &
1190 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1191 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1192
1193 not_sata:
1194
Eric Moore635374e2009-03-09 01:21:12 -06001195 if (!sdev->tagged_supported)
1196 max_depth = 1;
1197 if (qdepth > max_depth)
1198 qdepth = max_depth;
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301199 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1200}
1201
1202/**
1203 * _scsih_change_queue_depth - setting device queue depth
1204 * @sdev: scsi device struct
1205 * @qdepth: requested queue depth
1206 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1207 * (see include/scsi/scsi_host.h for definition)
1208 *
1209 * Returns queue depth.
1210 */
1211static int
1212_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1213{
1214 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1215 _scsih_adjust_queue_depth(sdev, qdepth);
1216 else if (reason == SCSI_QDEPTH_QFULL)
1217 scsi_track_queue_full(sdev, qdepth);
1218 else
1219 return -EOPNOTSUPP;
Eric Moore635374e2009-03-09 01:21:12 -06001220
1221 if (sdev->inquiry_len > 7)
1222 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1223 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1224 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1225 sdev->ordered_tags, sdev->scsi_level,
1226 (sdev->inquiry[7] & 2) >> 1);
1227
1228 return sdev->queue_depth;
1229}
1230
1231/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301232 * _scsih_change_queue_type - changing device queue tag type
Eric Moore635374e2009-03-09 01:21:12 -06001233 * @sdev: scsi device struct
1234 * @tag_type: requested tag type
1235 *
1236 * Returns queue tag type.
1237 */
1238static int
Eric Moored5d135b2009-05-18 13:02:08 -06001239_scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
Eric Moore635374e2009-03-09 01:21:12 -06001240{
1241 if (sdev->tagged_supported) {
1242 scsi_set_tag_type(sdev, tag_type);
1243 if (tag_type)
1244 scsi_activate_tcq(sdev, sdev->queue_depth);
1245 else
1246 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1247 } else
1248 tag_type = 0;
1249
1250 return tag_type;
1251}
1252
1253/**
Eric Moored5d135b2009-05-18 13:02:08 -06001254 * _scsih_target_alloc - target add routine
Eric Moore635374e2009-03-09 01:21:12 -06001255 * @starget: scsi target struct
1256 *
1257 * Returns 0 if ok. Any other return is assumed to be an error and
1258 * the device is ignored.
1259 */
1260static int
Eric Moored5d135b2009-05-18 13:02:08 -06001261_scsih_target_alloc(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001262{
1263 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1264 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1265 struct MPT2SAS_TARGET *sas_target_priv_data;
1266 struct _sas_device *sas_device;
1267 struct _raid_device *raid_device;
1268 unsigned long flags;
1269 struct sas_rphy *rphy;
1270
1271 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1272 if (!sas_target_priv_data)
1273 return -ENOMEM;
1274
1275 starget->hostdata = sas_target_priv_data;
1276 sas_target_priv_data->starget = starget;
1277 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1278
1279 /* RAID volumes */
1280 if (starget->channel == RAID_CHANNEL) {
1281 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1282 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1283 starget->channel);
1284 if (raid_device) {
1285 sas_target_priv_data->handle = raid_device->handle;
1286 sas_target_priv_data->sas_address = raid_device->wwid;
1287 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301288 sas_target_priv_data->raid_device = raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001289 raid_device->starget = starget;
1290 }
1291 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1292 return 0;
1293 }
1294
1295 /* sas/sata devices */
1296 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1297 rphy = dev_to_rphy(starget->dev.parent);
1298 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1299 rphy->identify.sas_address);
1300
1301 if (sas_device) {
1302 sas_target_priv_data->handle = sas_device->handle;
1303 sas_target_priv_data->sas_address = sas_device->sas_address;
1304 sas_device->starget = starget;
1305 sas_device->id = starget->id;
1306 sas_device->channel = starget->channel;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05301307 if (test_bit(sas_device->handle, ioc->pd_handles))
Eric Moore635374e2009-03-09 01:21:12 -06001308 sas_target_priv_data->flags |=
1309 MPT_TARGET_FLAGS_RAID_COMPONENT;
1310 }
1311 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1312
1313 return 0;
1314}
1315
1316/**
Eric Moored5d135b2009-05-18 13:02:08 -06001317 * _scsih_target_destroy - target destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001318 * @starget: scsi target struct
1319 *
1320 * Returns nothing.
1321 */
1322static void
Eric Moored5d135b2009-05-18 13:02:08 -06001323_scsih_target_destroy(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001324{
1325 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1326 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1327 struct MPT2SAS_TARGET *sas_target_priv_data;
1328 struct _sas_device *sas_device;
1329 struct _raid_device *raid_device;
1330 unsigned long flags;
1331 struct sas_rphy *rphy;
1332
1333 sas_target_priv_data = starget->hostdata;
1334 if (!sas_target_priv_data)
1335 return;
1336
1337 if (starget->channel == RAID_CHANNEL) {
1338 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1339 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1340 starget->channel);
1341 if (raid_device) {
1342 raid_device->starget = NULL;
1343 raid_device->sdev = NULL;
1344 }
1345 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1346 goto out;
1347 }
1348
1349 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1350 rphy = dev_to_rphy(starget->dev.parent);
1351 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1352 rphy->identify.sas_address);
Eric Moore8901cbb2009-04-21 15:41:32 -06001353 if (sas_device && (sas_device->starget == starget) &&
1354 (sas_device->id == starget->id) &&
1355 (sas_device->channel == starget->channel))
Eric Moore635374e2009-03-09 01:21:12 -06001356 sas_device->starget = NULL;
1357
1358 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1359
1360 out:
1361 kfree(sas_target_priv_data);
1362 starget->hostdata = NULL;
1363}
1364
1365/**
Eric Moored5d135b2009-05-18 13:02:08 -06001366 * _scsih_slave_alloc - device add routine
Eric Moore635374e2009-03-09 01:21:12 -06001367 * @sdev: scsi device struct
1368 *
1369 * Returns 0 if ok. Any other return is assumed to be an error and
1370 * the device is ignored.
1371 */
1372static int
Eric Moored5d135b2009-05-18 13:02:08 -06001373_scsih_slave_alloc(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001374{
1375 struct Scsi_Host *shost;
1376 struct MPT2SAS_ADAPTER *ioc;
1377 struct MPT2SAS_TARGET *sas_target_priv_data;
1378 struct MPT2SAS_DEVICE *sas_device_priv_data;
1379 struct scsi_target *starget;
1380 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001381 unsigned long flags;
1382
1383 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1384 if (!sas_device_priv_data)
1385 return -ENOMEM;
1386
1387 sas_device_priv_data->lun = sdev->lun;
1388 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1389
1390 starget = scsi_target(sdev);
1391 sas_target_priv_data = starget->hostdata;
1392 sas_target_priv_data->num_luns++;
1393 sas_device_priv_data->sas_target = sas_target_priv_data;
1394 sdev->hostdata = sas_device_priv_data;
1395 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1396 sdev->no_uld_attach = 1;
1397
1398 shost = dev_to_shost(&starget->dev);
1399 ioc = shost_priv(shost);
1400 if (starget->channel == RAID_CHANNEL) {
1401 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1402 raid_device = _scsih_raid_device_find_by_id(ioc,
1403 starget->id, starget->channel);
1404 if (raid_device)
1405 raid_device->sdev = sdev; /* raid is single lun */
1406 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06001407 }
1408
Eric Moore635374e2009-03-09 01:21:12 -06001409 return 0;
1410}
1411
1412/**
Eric Moored5d135b2009-05-18 13:02:08 -06001413 * _scsih_slave_destroy - device destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001414 * @sdev: scsi device struct
1415 *
1416 * Returns nothing.
1417 */
1418static void
Eric Moored5d135b2009-05-18 13:02:08 -06001419_scsih_slave_destroy(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001420{
1421 struct MPT2SAS_TARGET *sas_target_priv_data;
1422 struct scsi_target *starget;
1423
1424 if (!sdev->hostdata)
1425 return;
1426
1427 starget = scsi_target(sdev);
1428 sas_target_priv_data = starget->hostdata;
1429 sas_target_priv_data->num_luns--;
1430 kfree(sdev->hostdata);
1431 sdev->hostdata = NULL;
1432}
1433
1434/**
Eric Moored5d135b2009-05-18 13:02:08 -06001435 * _scsih_display_sata_capabilities - sata capabilities
Eric Moore635374e2009-03-09 01:21:12 -06001436 * @ioc: per adapter object
1437 * @sas_device: the sas_device object
1438 * @sdev: scsi device struct
1439 */
1440static void
Eric Moored5d135b2009-05-18 13:02:08 -06001441_scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
Eric Moore635374e2009-03-09 01:21:12 -06001442 struct _sas_device *sas_device, struct scsi_device *sdev)
1443{
1444 Mpi2ConfigReply_t mpi_reply;
1445 Mpi2SasDevicePage0_t sas_device_pg0;
1446 u32 ioc_status;
1447 u16 flags;
1448 u32 device_info;
1449
1450 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1451 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
1452 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1453 ioc->name, __FILE__, __LINE__, __func__);
1454 return;
1455 }
1456
1457 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1458 MPI2_IOCSTATUS_MASK;
1459 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1460 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1461 ioc->name, __FILE__, __LINE__, __func__);
1462 return;
1463 }
1464
1465 flags = le16_to_cpu(sas_device_pg0.Flags);
Kashyap, Desaie94f6742010-03-17 16:24:52 +05301466 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
Eric Moore635374e2009-03-09 01:21:12 -06001467
1468 sdev_printk(KERN_INFO, sdev,
1469 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1470 "sw_preserve(%s)\n",
1471 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1472 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1473 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1474 "n",
1475 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1476 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1477 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1478}
1479
1480/**
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301481 * _scsih_is_raid - return boolean indicating device is raid volume
1482 * @dev the device struct object
1483 */
1484static int
1485_scsih_is_raid(struct device *dev)
1486{
1487 struct scsi_device *sdev = to_scsi_device(dev);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301488 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301489
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301490 if (ioc->is_warpdrive)
1491 return 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301492 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1493}
1494
1495/**
1496 * _scsih_get_resync - get raid volume resync percent complete
1497 * @dev the device struct object
1498 */
1499static void
1500_scsih_get_resync(struct device *dev)
1501{
1502 struct scsi_device *sdev = to_scsi_device(dev);
1503 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1504 static struct _raid_device *raid_device;
1505 unsigned long flags;
1506 Mpi2RaidVolPage0_t vol_pg0;
1507 Mpi2ConfigReply_t mpi_reply;
1508 u32 volume_status_flags;
1509 u8 percent_complete = 0;
1510
1511 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1512 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1513 sdev->channel);
1514 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1515
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301516 if (!raid_device || ioc->is_warpdrive)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301517 goto out;
1518
1519 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1520 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1521 sizeof(Mpi2RaidVolPage0_t))) {
1522 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1523 ioc->name, __FILE__, __LINE__, __func__);
1524 goto out;
1525 }
1526
1527 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1528 if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
1529 percent_complete = raid_device->percent_complete;
1530 out:
1531 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1532}
1533
1534/**
1535 * _scsih_get_state - get raid volume level
1536 * @dev the device struct object
1537 */
1538static void
1539_scsih_get_state(struct device *dev)
1540{
1541 struct scsi_device *sdev = to_scsi_device(dev);
1542 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1543 static struct _raid_device *raid_device;
1544 unsigned long flags;
1545 Mpi2RaidVolPage0_t vol_pg0;
1546 Mpi2ConfigReply_t mpi_reply;
1547 u32 volstate;
1548 enum raid_state state = RAID_STATE_UNKNOWN;
1549
1550 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1551 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1552 sdev->channel);
1553 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1554
1555 if (!raid_device)
1556 goto out;
1557
1558 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1559 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1560 sizeof(Mpi2RaidVolPage0_t))) {
1561 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1562 ioc->name, __FILE__, __LINE__, __func__);
1563 goto out;
1564 }
1565
1566 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1567 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1568 state = RAID_STATE_RESYNCING;
1569 goto out;
1570 }
1571
1572 switch (vol_pg0.VolumeState) {
1573 case MPI2_RAID_VOL_STATE_OPTIMAL:
1574 case MPI2_RAID_VOL_STATE_ONLINE:
1575 state = RAID_STATE_ACTIVE;
1576 break;
1577 case MPI2_RAID_VOL_STATE_DEGRADED:
1578 state = RAID_STATE_DEGRADED;
1579 break;
1580 case MPI2_RAID_VOL_STATE_FAILED:
1581 case MPI2_RAID_VOL_STATE_MISSING:
1582 state = RAID_STATE_OFFLINE;
1583 break;
1584 }
1585 out:
1586 raid_set_state(mpt2sas_raid_template, dev, state);
1587}
1588
1589/**
1590 * _scsih_set_level - set raid level
1591 * @sdev: scsi device struct
1592 * @raid_device: raid_device object
1593 */
1594static void
1595_scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device)
1596{
1597 enum raid_level level = RAID_LEVEL_UNKNOWN;
1598
1599 switch (raid_device->volume_type) {
1600 case MPI2_RAID_VOL_TYPE_RAID0:
1601 level = RAID_LEVEL_0;
1602 break;
1603 case MPI2_RAID_VOL_TYPE_RAID10:
1604 level = RAID_LEVEL_10;
1605 break;
1606 case MPI2_RAID_VOL_TYPE_RAID1E:
1607 level = RAID_LEVEL_1E;
1608 break;
1609 case MPI2_RAID_VOL_TYPE_RAID1:
1610 level = RAID_LEVEL_1;
1611 break;
1612 }
1613
1614 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1615}
1616
1617/**
Eric Moore635374e2009-03-09 01:21:12 -06001618 * _scsih_get_volume_capabilities - volume capabilities
1619 * @ioc: per adapter object
1620 * @sas_device: the raid_device object
1621 */
1622static void
1623_scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1624 struct _raid_device *raid_device)
1625{
1626 Mpi2RaidVolPage0_t *vol_pg0;
1627 Mpi2RaidPhysDiskPage0_t pd_pg0;
1628 Mpi2SasDevicePage0_t sas_device_pg0;
1629 Mpi2ConfigReply_t mpi_reply;
1630 u16 sz;
1631 u8 num_pds;
1632
1633 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1634 &num_pds)) || !num_pds) {
1635 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1636 ioc->name, __FILE__, __LINE__, __func__);
1637 return;
1638 }
1639
1640 raid_device->num_pds = num_pds;
1641 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1642 sizeof(Mpi2RaidVol0PhysDisk_t));
1643 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1644 if (!vol_pg0) {
1645 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1646 ioc->name, __FILE__, __LINE__, __func__);
1647 return;
1648 }
1649
1650 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1651 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1652 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1653 ioc->name, __FILE__, __LINE__, __func__);
1654 kfree(vol_pg0);
1655 return;
1656 }
1657
1658 raid_device->volume_type = vol_pg0->VolumeType;
1659
1660 /* figure out what the underlying devices are by
1661 * obtaining the device_info bits for the 1st device
1662 */
1663 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1664 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1665 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1666 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1667 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1668 le16_to_cpu(pd_pg0.DevHandle)))) {
1669 raid_device->device_info =
1670 le32_to_cpu(sas_device_pg0.DeviceInfo);
1671 }
1672 }
1673
1674 kfree(vol_pg0);
1675}
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301676/**
1677 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1678 * @ioc: per adapter object
1679 */
1680static void
1681_scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1682{
1683 Mpi2RaidVolPage1_t vol_pg1;
1684 Mpi2ConfigReply_t mpi_reply;
1685 struct _raid_device *raid_device;
1686 u16 handle;
1687 u16 ioc_status;
1688
1689 handle = 0xFFFF;
1690 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1691 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1692 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1693 MPI2_IOCSTATUS_MASK;
1694 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1695 break;
1696 handle = le16_to_cpu(vol_pg1.DevHandle);
1697 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1698 if (raid_device)
1699 raid_device->direct_io_enabled = 0;
1700 }
1701 return;
1702}
1703
1704
1705/**
1706 * _scsih_get_num_volumes - Get number of volumes in the ioc
1707 * @ioc: per adapter object
1708 */
1709static u8
1710_scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1711{
1712 Mpi2RaidVolPage1_t vol_pg1;
1713 Mpi2ConfigReply_t mpi_reply;
1714 u16 handle;
1715 u8 vol_cnt = 0;
1716 u16 ioc_status;
1717
1718 handle = 0xFFFF;
1719 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1720 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1721 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1722 MPI2_IOCSTATUS_MASK;
1723 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1724 break;
1725 vol_cnt++;
1726 handle = le16_to_cpu(vol_pg1.DevHandle);
1727 }
1728 return vol_cnt;
1729}
1730
1731
1732/**
1733 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1734 * @ioc: per adapter object
1735 * @raid_device: the raid_device object
1736 */
1737static void
1738_scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1739 struct _raid_device *raid_device)
1740{
1741 Mpi2RaidVolPage0_t *vol_pg0;
1742 Mpi2RaidPhysDiskPage0_t pd_pg0;
1743 Mpi2ConfigReply_t mpi_reply;
1744 u16 sz;
1745 u8 num_pds, count;
1746 u64 mb = 1024 * 1024;
1747 u64 tb_2 = 2 * mb * mb;
1748 u64 capacity;
1749 u32 stripe_sz;
1750 u8 i, stripe_exp;
1751
1752 if (!ioc->is_warpdrive)
1753 return;
1754
1755 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1756 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1757 "globally as drives are exposed\n", ioc->name);
1758 return;
1759 }
1760 if (_scsih_get_num_volumes(ioc) > 1) {
1761 _scsih_disable_ddio(ioc);
1762 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1763 "globally as number of drives > 1\n", ioc->name);
1764 return;
1765 }
1766 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1767 &num_pds)) || !num_pds) {
1768 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1769 "Failure in computing number of drives\n", ioc->name);
1770 return;
1771 }
1772
1773 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1774 sizeof(Mpi2RaidVol0PhysDisk_t));
1775 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1776 if (!vol_pg0) {
1777 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1778 "Memory allocation failure for RVPG0\n", ioc->name);
1779 return;
1780 }
1781
1782 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1783 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1784 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1785 "Failure in retrieving RVPG0\n", ioc->name);
1786 kfree(vol_pg0);
1787 return;
1788 }
1789
1790 /*
1791 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1792 * assumed for WARPDRIVE, disable direct I/O
1793 */
1794 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1795 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1796 "for the drive with handle(0x%04x): num_mem=%d, "
1797 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1798 num_pds, MPT_MAX_WARPDRIVE_PDS);
1799 kfree(vol_pg0);
1800 return;
1801 }
1802 for (count = 0; count < num_pds; count++) {
1803 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1804 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1805 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1806 pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) {
1807 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1808 "disabled for the drive with handle(0x%04x) member"
1809 "handle retrieval failed for member number=%d\n",
1810 ioc->name, raid_device->handle,
1811 vol_pg0->PhysDisk[count].PhysDiskNum);
1812 goto out_error;
1813 }
1814 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1815 }
1816
1817 /*
1818 * Assumption for WD: Direct I/O is not supported if the volume is
1819 * not RAID0, if the stripe size is not 64KB, if the block size is
1820 * not 512 and if the volume size is >2TB
1821 */
1822 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0 ||
1823 le16_to_cpu(vol_pg0->BlockSize) != 512) {
1824 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1825 "for the drive with handle(0x%04x): type=%d, "
1826 "s_sz=%uK, blk_size=%u\n", ioc->name,
1827 raid_device->handle, raid_device->volume_type,
1828 le32_to_cpu(vol_pg0->StripeSize)/2,
1829 le16_to_cpu(vol_pg0->BlockSize));
1830 goto out_error;
1831 }
1832
1833 capacity = (u64) le16_to_cpu(vol_pg0->BlockSize) *
1834 (le64_to_cpu(vol_pg0->MaxLBA) + 1);
1835
1836 if (capacity > tb_2) {
1837 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1838 "for the drive with handle(0x%04x) since drive sz > 2TB\n",
1839 ioc->name, raid_device->handle);
1840 goto out_error;
1841 }
1842
1843 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1844 stripe_exp = 0;
1845 for (i = 0; i < 32; i++) {
1846 if (stripe_sz & 1)
1847 break;
1848 stripe_exp++;
1849 stripe_sz >>= 1;
1850 }
1851 if (i == 32) {
1852 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1853 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1854 ioc->name, raid_device->handle,
1855 le32_to_cpu(vol_pg0->StripeSize)/2);
1856 goto out_error;
1857 }
1858 raid_device->stripe_exponent = stripe_exp;
1859 raid_device->direct_io_enabled = 1;
1860
1861 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1862 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1863 /*
1864 * WARPDRIVE: Though the following fields are not used for direct IO,
1865 * stored for future purpose:
1866 */
1867 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1868 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1869 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1870
1871
1872 kfree(vol_pg0);
1873 return;
1874
1875out_error:
1876 raid_device->direct_io_enabled = 0;
1877 for (count = 0; count < num_pds; count++)
1878 raid_device->pd_handle[count] = 0;
1879 kfree(vol_pg0);
1880 return;
1881}
Eric Moore635374e2009-03-09 01:21:12 -06001882
1883/**
Kashyap, Desai84f0b042009-12-16 18:56:28 +05301884 * _scsih_enable_tlr - setting TLR flags
1885 * @ioc: per adapter object
1886 * @sdev: scsi device struct
1887 *
1888 * Enabling Transaction Layer Retries for tape devices when
1889 * vpd page 0x90 is present
1890 *
1891 */
1892static void
1893_scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1894{
1895 /* only for TAPE */
1896 if (sdev->type != TYPE_TAPE)
1897 return;
1898
1899 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1900 return;
1901
1902 sas_enable_tlr(sdev);
1903 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1904 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1905 return;
1906
1907}
1908
1909/**
Eric Moored5d135b2009-05-18 13:02:08 -06001910 * _scsih_slave_configure - device configure routine.
Eric Moore635374e2009-03-09 01:21:12 -06001911 * @sdev: scsi device struct
1912 *
1913 * Returns 0 if ok. Any other return is assumed to be an error and
1914 * the device is ignored.
1915 */
1916static int
Eric Moored5d135b2009-05-18 13:02:08 -06001917_scsih_slave_configure(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001918{
1919 struct Scsi_Host *shost = sdev->host;
1920 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1921 struct MPT2SAS_DEVICE *sas_device_priv_data;
1922 struct MPT2SAS_TARGET *sas_target_priv_data;
1923 struct _sas_device *sas_device;
1924 struct _raid_device *raid_device;
1925 unsigned long flags;
1926 int qdepth;
1927 u8 ssp_target = 0;
1928 char *ds = "";
1929 char *r_level = "";
1930
1931 qdepth = 1;
1932 sas_device_priv_data = sdev->hostdata;
1933 sas_device_priv_data->configured_lun = 1;
1934 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1935 sas_target_priv_data = sas_device_priv_data->sas_target;
1936
1937 /* raid volume handling */
1938 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1939
1940 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1941 raid_device = _scsih_raid_device_find_by_handle(ioc,
1942 sas_target_priv_data->handle);
1943 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1944 if (!raid_device) {
1945 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1946 ioc->name, __FILE__, __LINE__, __func__);
1947 return 0;
1948 }
1949
1950 _scsih_get_volume_capabilities(ioc, raid_device);
1951
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301952 /*
1953 * WARPDRIVE: Initialize the required data for Direct IO
1954 */
1955 _scsih_init_warpdrive_properties(ioc, raid_device);
1956
Eric Moore635374e2009-03-09 01:21:12 -06001957 /* RAID Queue Depth Support
1958 * IS volume = underlying qdepth of drive type, either
1959 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1960 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1961 */
1962 if (raid_device->device_info &
1963 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1964 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1965 ds = "SSP";
1966 } else {
1967 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1968 if (raid_device->device_info &
1969 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1970 ds = "SATA";
1971 else
1972 ds = "STP";
1973 }
1974
1975 switch (raid_device->volume_type) {
1976 case MPI2_RAID_VOL_TYPE_RAID0:
1977 r_level = "RAID0";
1978 break;
1979 case MPI2_RAID_VOL_TYPE_RAID1E:
1980 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
Kashyap, Desaied79f122009-08-20 13:23:49 +05301981 if (ioc->manu_pg10.OEMIdentifier &&
Kashyap, Desaic97951e2011-06-14 10:54:56 +05301982 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
Kashyap, Desaied79f122009-08-20 13:23:49 +05301983 MFG10_GF0_R10_DISPLAY) &&
1984 !(raid_device->num_pds % 2))
1985 r_level = "RAID10";
1986 else
1987 r_level = "RAID1E";
Eric Moore635374e2009-03-09 01:21:12 -06001988 break;
1989 case MPI2_RAID_VOL_TYPE_RAID1:
1990 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1991 r_level = "RAID1";
1992 break;
1993 case MPI2_RAID_VOL_TYPE_RAID10:
1994 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1995 r_level = "RAID10";
1996 break;
1997 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1998 default:
1999 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2000 r_level = "RAIDX";
2001 break;
2002 }
2003
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302004 if (!ioc->hide_ir_msg)
2005 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2006 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2007 r_level, raid_device->handle,
2008 (unsigned long long)raid_device->wwid,
2009 raid_device->num_pds, ds);
Mike Christiee881a172009-10-15 17:46:39 -07002010 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05302011 /* raid transport support */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302012 if (!ioc->is_warpdrive)
2013 _scsih_set_level(sdev, raid_device);
Eric Moore635374e2009-03-09 01:21:12 -06002014 return 0;
2015 }
2016
2017 /* non-raid handling */
2018 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2019 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2020 sas_device_priv_data->sas_target->sas_address);
2021 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2022 if (sas_device) {
2023 if (sas_target_priv_data->flags &
2024 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2025 mpt2sas_config_get_volume_handle(ioc,
2026 sas_device->handle, &sas_device->volume_handle);
2027 mpt2sas_config_get_volume_wwid(ioc,
2028 sas_device->volume_handle,
2029 &sas_device->volume_wwid);
2030 }
2031 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2032 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2033 ssp_target = 1;
2034 ds = "SSP";
2035 } else {
2036 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2037 if (sas_device->device_info &
2038 MPI2_SAS_DEVICE_INFO_STP_TARGET)
2039 ds = "STP";
2040 else if (sas_device->device_info &
2041 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2042 ds = "SATA";
2043 }
2044
2045 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
Kashyap, Desai7fbae672010-06-17 13:45:17 +05302046 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
Eric Moore635374e2009-03-09 01:21:12 -06002047 ds, sas_device->handle,
2048 (unsigned long long)sas_device->sas_address,
Kashyap, Desai7fbae672010-06-17 13:45:17 +05302049 sas_device->phy,
Eric Moore635374e2009-03-09 01:21:12 -06002050 (unsigned long long)sas_device->device_name);
2051 sdev_printk(KERN_INFO, sdev, "%s: "
2052 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2053 (unsigned long long) sas_device->enclosure_logical_id,
2054 sas_device->slot);
2055
2056 if (!ssp_target)
Eric Moored5d135b2009-05-18 13:02:08 -06002057 _scsih_display_sata_capabilities(ioc, sas_device, sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002058 }
2059
Mike Christiee881a172009-10-15 17:46:39 -07002060 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Eric Moore635374e2009-03-09 01:21:12 -06002061
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302062 if (ssp_target) {
Eric Moore635374e2009-03-09 01:21:12 -06002063 sas_read_port_mode_page(sdev);
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302064 _scsih_enable_tlr(ioc, sdev);
2065 }
Eric Moore635374e2009-03-09 01:21:12 -06002066 return 0;
2067}
2068
2069/**
Eric Moored5d135b2009-05-18 13:02:08 -06002070 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
Eric Moore635374e2009-03-09 01:21:12 -06002071 * @sdev: scsi device struct
2072 * @bdev: pointer to block device context
2073 * @capacity: device size (in 512 byte sectors)
2074 * @params: three element array to place output:
2075 * params[0] number of heads (max 255)
2076 * params[1] number of sectors (max 63)
2077 * params[2] number of cylinders
2078 *
2079 * Return nothing.
2080 */
2081static int
Eric Moored5d135b2009-05-18 13:02:08 -06002082_scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
Eric Moore635374e2009-03-09 01:21:12 -06002083 sector_t capacity, int params[])
2084{
2085 int heads;
2086 int sectors;
2087 sector_t cylinders;
2088 ulong dummy;
2089
2090 heads = 64;
2091 sectors = 32;
2092
2093 dummy = heads * sectors;
2094 cylinders = capacity;
2095 sector_div(cylinders, dummy);
2096
2097 /*
2098 * Handle extended translation size for logical drives
2099 * > 1Gb
2100 */
2101 if ((ulong)capacity >= 0x200000) {
2102 heads = 255;
2103 sectors = 63;
2104 dummy = heads * sectors;
2105 cylinders = capacity;
2106 sector_div(cylinders, dummy);
2107 }
2108
2109 /* return result */
2110 params[0] = heads;
2111 params[1] = sectors;
2112 params[2] = cylinders;
2113
2114 return 0;
2115}
2116
2117/**
2118 * _scsih_response_code - translation of device response code
2119 * @ioc: per adapter object
2120 * @response_code: response code returned by the device
2121 *
2122 * Return nothing.
2123 */
2124static void
2125_scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2126{
2127 char *desc;
2128
2129 switch (response_code) {
2130 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2131 desc = "task management request completed";
2132 break;
2133 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2134 desc = "invalid frame";
2135 break;
2136 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2137 desc = "task management request not supported";
2138 break;
2139 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2140 desc = "task management request failed";
2141 break;
2142 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2143 desc = "task management request succeeded";
2144 break;
2145 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2146 desc = "invalid lun";
2147 break;
2148 case 0xA:
2149 desc = "overlapped tag attempted";
2150 break;
2151 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2152 desc = "task queued, however not sent to target";
2153 break;
2154 default:
2155 desc = "unknown";
2156 break;
2157 }
2158 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2159 ioc->name, response_code, desc);
2160}
2161
2162/**
Eric Moored5d135b2009-05-18 13:02:08 -06002163 * _scsih_tm_done - tm completion routine
Eric Moore635374e2009-03-09 01:21:12 -06002164 * @ioc: per adapter object
2165 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302166 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002167 * @reply: reply message frame(lower 32bit addr)
2168 * Context: none.
2169 *
2170 * The callback handler when using scsih_issue_tm.
2171 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302172 * Return 1 meaning mf should be freed from _base_interrupt
2173 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06002174 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302175static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302176_scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06002177{
2178 MPI2DefaultReply_t *mpi_reply;
2179
2180 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302181 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002182 if (ioc->tm_cmds.smid != smid)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302183 return 1;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05302184 mpt2sas_base_flush_reply_queues(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06002185 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2186 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2187 if (mpi_reply) {
2188 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2189 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2190 }
2191 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2192 complete(&ioc->tm_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302193 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002194}
2195
2196/**
2197 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2198 * @ioc: per adapter object
2199 * @handle: device handle
2200 *
2201 * During taskmangement request, we need to freeze the device queue.
2202 */
2203void
2204mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2205{
2206 struct MPT2SAS_DEVICE *sas_device_priv_data;
2207 struct scsi_device *sdev;
2208 u8 skip = 0;
2209
2210 shost_for_each_device(sdev, ioc->shost) {
2211 if (skip)
2212 continue;
2213 sas_device_priv_data = sdev->hostdata;
2214 if (!sas_device_priv_data)
2215 continue;
2216 if (sas_device_priv_data->sas_target->handle == handle) {
2217 sas_device_priv_data->sas_target->tm_busy = 1;
2218 skip = 1;
2219 ioc->ignore_loginfos = 1;
2220 }
2221 }
2222}
2223
2224/**
2225 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2226 * @ioc: per adapter object
2227 * @handle: device handle
2228 *
2229 * During taskmangement request, we need to freeze the device queue.
2230 */
2231void
2232mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2233{
2234 struct MPT2SAS_DEVICE *sas_device_priv_data;
2235 struct scsi_device *sdev;
2236 u8 skip = 0;
2237
2238 shost_for_each_device(sdev, ioc->shost) {
2239 if (skip)
2240 continue;
2241 sas_device_priv_data = sdev->hostdata;
2242 if (!sas_device_priv_data)
2243 continue;
2244 if (sas_device_priv_data->sas_target->handle == handle) {
2245 sas_device_priv_data->sas_target->tm_busy = 0;
2246 skip = 1;
2247 ioc->ignore_loginfos = 0;
2248 }
2249 }
2250}
2251
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302252
Eric Moore635374e2009-03-09 01:21:12 -06002253/**
2254 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2255 * @ioc: per adapter struct
2256 * @device_handle: device handle
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302257 * @channel: the channel assigned by the OS
2258 * @id: the id assigned by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002259 * @lun: lun number
2260 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2261 * @smid_task: smid assigned to the task
2262 * @timeout: timeout in seconds
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302263 * @serial_number: the serial_number from scmd
2264 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302265 * Context: user
Eric Moore635374e2009-03-09 01:21:12 -06002266 *
2267 * A generic API for sending task management requests to firmware.
2268 *
Eric Moore635374e2009-03-09 01:21:12 -06002269 * The callback index is set inside `ioc->tm_cb_idx`.
2270 *
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302271 * Return SUCCESS or FAILED.
Eric Moore635374e2009-03-09 01:21:12 -06002272 */
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302273int
2274mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2275 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302276 unsigned long serial_number, enum mutex_type m_type)
Eric Moore635374e2009-03-09 01:21:12 -06002277{
2278 Mpi2SCSITaskManagementRequest_t *mpi_request;
2279 Mpi2SCSITaskManagementReply_t *mpi_reply;
2280 u16 smid = 0;
2281 u32 ioc_state;
2282 unsigned long timeleft;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302283 struct scsiio_tracker *scsi_lookup = NULL;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302284 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06002285
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302286 if (m_type == TM_MUTEX_ON)
2287 mutex_lock(&ioc->tm_cmds.mutex);
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302288 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2289 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2290 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302291 rc = FAILED;
2292 goto err_out;
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302293 }
2294
Eric Moore3cb54692010-07-08 14:44:34 -06002295 if (ioc->shost_recovery || ioc->remove_host ||
2296 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06002297 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2298 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302299 rc = FAILED;
2300 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002301 }
Eric Moore635374e2009-03-09 01:21:12 -06002302
2303 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2304 if (ioc_state & MPI2_DOORBELL_USED) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302305 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
Eric Moore635374e2009-03-09 01:21:12 -06002306 "active!\n", ioc->name));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302307 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302308 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302309 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302310 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002311 }
2312
2313 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2314 mpt2sas_base_fault_info(ioc, ioc_state &
2315 MPI2_DOORBELL_DATA_MASK);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302316 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302317 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302318 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302319 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002320 }
2321
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302322 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06002323 if (!smid) {
2324 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2325 ioc->name, __func__);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302326 rc = FAILED;
2327 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002328 }
2329
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302330 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2331 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2332
Eric Moore635374e2009-03-09 01:21:12 -06002333 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302334 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2335 smid_task));
Eric Moore635374e2009-03-09 01:21:12 -06002336 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2337 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2338 ioc->tm_cmds.smid = smid;
2339 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302340 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
Eric Moore635374e2009-03-09 01:21:12 -06002341 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2342 mpi_request->DevHandle = cpu_to_le16(handle);
2343 mpi_request->TaskType = type;
2344 mpi_request->TaskMID = cpu_to_le16(smid_task);
2345 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2346 mpt2sas_scsih_set_tm_flag(ioc, handle);
Kashyap, Desai5b768582009-08-20 13:24:31 +05302347 init_completion(&ioc->tm_cmds.done);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302348 mpt2sas_base_put_smid_hi_priority(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06002349 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
Eric Moore635374e2009-03-09 01:21:12 -06002350 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2351 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2352 ioc->name, __func__);
2353 _debug_dump_mf(mpi_request,
2354 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302355 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302356 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302357 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302358 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302359 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2360 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2361 goto err_out;
2362 }
Eric Moore635374e2009-03-09 01:21:12 -06002363 }
2364
2365 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2366 mpi_reply = ioc->tm_cmds.reply;
2367 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2368 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2369 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2370 le32_to_cpu(mpi_reply->IOCLogInfo),
2371 le32_to_cpu(mpi_reply->TerminationCount)));
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302372 if (ioc->logging_level & MPT_DEBUG_TM) {
Eric Moore635374e2009-03-09 01:21:12 -06002373 _scsih_response_code(ioc, mpi_reply->ResponseCode);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302374 if (mpi_reply->IOCStatus)
2375 _debug_dump_mf(mpi_request,
2376 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2377 }
Eric Moore635374e2009-03-09 01:21:12 -06002378 }
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302379
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302380 switch (type) {
2381 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302382 rc = SUCCESS;
2383 if (scsi_lookup->scmd == NULL)
2384 break;
2385 rc = FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302386 break;
2387
2388 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2389 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2390 rc = FAILED;
2391 else
2392 rc = SUCCESS;
2393 break;
2394
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302395 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302396 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2397 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2398 rc = FAILED;
2399 else
2400 rc = SUCCESS;
2401 break;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302402 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2403 rc = SUCCESS;
2404 break;
2405 default:
2406 rc = FAILED;
2407 break;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302408 }
2409
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302410 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2411 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302412 if (m_type == TM_MUTEX_ON)
2413 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302414
2415 return rc;
2416
2417 err_out:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302418 if (m_type == TM_MUTEX_ON)
2419 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302420 return rc;
Eric Moore635374e2009-03-09 01:21:12 -06002421}
2422
2423/**
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302424 * _scsih_tm_display_info - displays info about the device
2425 * @ioc: per adapter struct
2426 * @scmd: pointer to scsi command object
2427 *
2428 * Called by task management callback handlers.
2429 */
2430static void
2431_scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2432{
2433 struct scsi_target *starget = scmd->device->sdev_target;
2434 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2435 struct _sas_device *sas_device = NULL;
2436 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302437 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302438
2439 if (!priv_target)
2440 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302441 if (ioc->hide_ir_msg)
2442 device_str = "WarpDrive";
2443 else
2444 device_str = "volume";
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302445
2446 scsi_print_command(scmd);
2447 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302448 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2449 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2450 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302451 } else {
2452 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2453 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2454 priv_target->sas_address);
2455 if (sas_device) {
2456 if (priv_target->flags &
2457 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2458 starget_printk(KERN_INFO, starget,
2459 "volume handle(0x%04x), "
2460 "volume wwid(0x%016llx)\n",
2461 sas_device->volume_handle,
2462 (unsigned long long)sas_device->volume_wwid);
2463 }
2464 starget_printk(KERN_INFO, starget,
2465 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2466 sas_device->handle,
2467 (unsigned long long)sas_device->sas_address,
2468 sas_device->phy);
2469 starget_printk(KERN_INFO, starget,
2470 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2471 (unsigned long long)sas_device->enclosure_logical_id,
2472 sas_device->slot);
2473 }
2474 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2475 }
2476}
2477
2478/**
Eric Moored5d135b2009-05-18 13:02:08 -06002479 * _scsih_abort - eh threads main abort routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302480 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002481 *
2482 * Returns SUCCESS if command aborted else FAILED
2483 */
2484static int
Eric Moored5d135b2009-05-18 13:02:08 -06002485_scsih_abort(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002486{
2487 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2488 struct MPT2SAS_DEVICE *sas_device_priv_data;
2489 u16 smid;
2490 u16 handle;
2491 int r;
Eric Moore635374e2009-03-09 01:21:12 -06002492
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302493 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2494 "scmd(%p)\n", scmd);
2495 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002496
2497 sas_device_priv_data = scmd->device->hostdata;
2498 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302499 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2500 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002501 scmd->result = DID_NO_CONNECT << 16;
2502 scmd->scsi_done(scmd);
2503 r = SUCCESS;
2504 goto out;
2505 }
2506
2507 /* search for the command */
2508 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2509 if (!smid) {
2510 scmd->result = DID_RESET << 16;
2511 r = SUCCESS;
2512 goto out;
2513 }
2514
2515 /* for hidden raid components and volumes this is not supported */
2516 if (sas_device_priv_data->sas_target->flags &
2517 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2518 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2519 scmd->result = DID_RESET << 16;
2520 r = FAILED;
2521 goto out;
2522 }
2523
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302524 mpt2sas_halt_firmware(ioc);
2525
Eric Moore635374e2009-03-09 01:21:12 -06002526 handle = sas_device_priv_data->sas_target->handle;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302527 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2528 scmd->device->id, scmd->device->lun,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302529 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
2530 scmd->serial_number, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002531
2532 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302533 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2534 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002535 return r;
2536}
2537
Eric Moore635374e2009-03-09 01:21:12 -06002538/**
Eric Moored5d135b2009-05-18 13:02:08 -06002539 * _scsih_dev_reset - eh threads main device reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302540 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002541 *
2542 * Returns SUCCESS if command aborted else FAILED
2543 */
2544static int
Eric Moored5d135b2009-05-18 13:02:08 -06002545_scsih_dev_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002546{
2547 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2548 struct MPT2SAS_DEVICE *sas_device_priv_data;
2549 struct _sas_device *sas_device;
2550 unsigned long flags;
2551 u16 handle;
2552 int r;
2553
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302554 struct scsi_target *starget = scmd->device->sdev_target;
2555
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302556 starget_printk(KERN_INFO, starget, "attempting device reset! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302557 "scmd(%p)\n", scmd);
2558 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002559
2560 sas_device_priv_data = scmd->device->hostdata;
2561 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302562 starget_printk(KERN_INFO, starget, "device been deleted! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302563 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002564 scmd->result = DID_NO_CONNECT << 16;
2565 scmd->scsi_done(scmd);
2566 r = SUCCESS;
2567 goto out;
2568 }
2569
2570 /* for hidden raid components obtain the volume_handle */
2571 handle = 0;
2572 if (sas_device_priv_data->sas_target->flags &
2573 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2574 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2575 sas_device = _scsih_sas_device_find_by_handle(ioc,
2576 sas_device_priv_data->sas_target->handle);
2577 if (sas_device)
2578 handle = sas_device->volume_handle;
2579 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2580 } else
2581 handle = sas_device_priv_data->sas_target->handle;
2582
2583 if (!handle) {
2584 scmd->result = DID_RESET << 16;
2585 r = FAILED;
2586 goto out;
2587 }
2588
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302589 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2590 scmd->device->id, scmd->device->lun,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302591 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0,
2592 TM_MUTEX_ON);
Eric Moore993e0da2009-05-18 13:00:45 -06002593
2594 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302595 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2596 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002597 return r;
2598}
2599
2600/**
Eric Moored5d135b2009-05-18 13:02:08 -06002601 * _scsih_target_reset - eh threads main target reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302602 * @scmd: pointer to scsi command object
Eric Moore993e0da2009-05-18 13:00:45 -06002603 *
2604 * Returns SUCCESS if command aborted else FAILED
2605 */
2606static int
Eric Moored5d135b2009-05-18 13:02:08 -06002607_scsih_target_reset(struct scsi_cmnd *scmd)
Eric Moore993e0da2009-05-18 13:00:45 -06002608{
2609 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2610 struct MPT2SAS_DEVICE *sas_device_priv_data;
2611 struct _sas_device *sas_device;
2612 unsigned long flags;
2613 u16 handle;
2614 int r;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302615 struct scsi_target *starget = scmd->device->sdev_target;
Eric Moore993e0da2009-05-18 13:00:45 -06002616
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302617 starget_printk(KERN_INFO, starget, "attempting target reset! "
2618 "scmd(%p)\n", scmd);
2619 _scsih_tm_display_info(ioc, scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002620
2621 sas_device_priv_data = scmd->device->hostdata;
2622 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302623 starget_printk(KERN_INFO, starget, "target been deleted! "
2624 "scmd(%p)\n", scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002625 scmd->result = DID_NO_CONNECT << 16;
2626 scmd->scsi_done(scmd);
2627 r = SUCCESS;
2628 goto out;
2629 }
2630
2631 /* for hidden raid components obtain the volume_handle */
2632 handle = 0;
2633 if (sas_device_priv_data->sas_target->flags &
2634 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2635 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2636 sas_device = _scsih_sas_device_find_by_handle(ioc,
2637 sas_device_priv_data->sas_target->handle);
2638 if (sas_device)
2639 handle = sas_device->volume_handle;
2640 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2641 } else
2642 handle = sas_device_priv_data->sas_target->handle;
2643
2644 if (!handle) {
2645 scmd->result = DID_RESET << 16;
2646 r = FAILED;
2647 goto out;
2648 }
2649
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302650 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2651 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302652 30, 0, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002653
2654 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302655 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2656 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002657 return r;
2658}
2659
2660/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302661 * _scsih_host_reset - eh threads main host reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302662 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002663 *
2664 * Returns SUCCESS if command aborted else FAILED
2665 */
2666static int
Eric Moored5d135b2009-05-18 13:02:08 -06002667_scsih_host_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002668{
2669 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2670 int r, retval;
2671
2672 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2673 ioc->name, scmd);
2674 scsi_print_command(scmd);
2675
2676 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2677 FORCE_BIG_HAMMER);
2678 r = (retval < 0) ? FAILED : SUCCESS;
2679 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2680 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2681
2682 return r;
2683}
2684
2685/**
2686 * _scsih_fw_event_add - insert and queue up fw_event
2687 * @ioc: per adapter object
2688 * @fw_event: object describing the event
2689 * Context: This function will acquire ioc->fw_event_lock.
2690 *
2691 * This adds the firmware event object into link list, then queues it up to
2692 * be processed from user context.
2693 *
2694 * Return nothing.
2695 */
2696static void
2697_scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2698{
2699 unsigned long flags;
2700
2701 if (ioc->firmware_event_thread == NULL)
2702 return;
2703
2704 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2705 list_add_tail(&fw_event->list, &ioc->fw_event_list);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302706 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2707 queue_delayed_work(ioc->firmware_event_thread,
2708 &fw_event->delayed_work, 0);
Eric Moore635374e2009-03-09 01:21:12 -06002709 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2710}
2711
2712/**
2713 * _scsih_fw_event_free - delete fw_event
2714 * @ioc: per adapter object
2715 * @fw_event: object describing the event
2716 * Context: This function will acquire ioc->fw_event_lock.
2717 *
2718 * This removes firmware event object from link list, frees associated memory.
2719 *
2720 * Return nothing.
2721 */
2722static void
2723_scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2724 *fw_event)
2725{
2726 unsigned long flags;
2727
2728 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2729 list_del(&fw_event->list);
2730 kfree(fw_event->event_data);
2731 kfree(fw_event);
2732 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2733}
2734
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302735
Eric Moore635374e2009-03-09 01:21:12 -06002736/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302737 * _scsih_error_recovery_delete_devices - remove devices not responding
Eric Moore635374e2009-03-09 01:21:12 -06002738 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06002739 *
2740 * Return nothing.
2741 */
2742static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302743_scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06002744{
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302745 struct fw_event_work *fw_event;
2746
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302747 if (ioc->is_driver_loading)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302748 return;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302749 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2750 fw_event->ioc = ioc;
2751 _scsih_fw_event_add(ioc, fw_event);
2752}
2753
2754/**
2755 * mpt2sas_port_enable_complete - port enable completed (fake event)
2756 * @ioc: per adapter object
2757 *
2758 * Return nothing.
2759 */
2760void
2761mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2762{
2763 struct fw_event_work *fw_event;
2764
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302765 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2766 if (!fw_event)
2767 return;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302768 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302769 fw_event->ioc = ioc;
2770 _scsih_fw_event_add(ioc, fw_event);
2771}
2772
2773/**
2774 * _scsih_fw_event_cleanup_queue - cleanup event queue
2775 * @ioc: per adapter object
2776 *
2777 * Walk the firmware event queue, either killing timers, or waiting
2778 * for outstanding events to complete
2779 *
2780 * Return nothing.
2781 */
2782static void
2783_scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2784{
2785 struct fw_event_work *fw_event, *next;
2786
2787 if (list_empty(&ioc->fw_event_list) ||
2788 !ioc->firmware_event_thread || in_interrupt())
Eric Moore635374e2009-03-09 01:21:12 -06002789 return;
2790
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302791 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2792 if (cancel_delayed_work(&fw_event->delayed_work)) {
2793 _scsih_fw_event_free(ioc, fw_event);
2794 continue;
2795 }
2796 fw_event->cancel_pending_work = 1;
2797 }
Eric Moore635374e2009-03-09 01:21:12 -06002798}
2799
Eric Moore635374e2009-03-09 01:21:12 -06002800/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302801 * _scsih_ublock_io_all_device - unblock every device
2802 * @ioc: per adapter object
2803 *
2804 * change the device state from block to running
2805 */
2806static void
2807_scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2808{
2809 struct MPT2SAS_DEVICE *sas_device_priv_data;
2810 struct scsi_device *sdev;
2811
2812 shost_for_each_device(sdev, ioc->shost) {
2813 sas_device_priv_data = sdev->hostdata;
2814 if (!sas_device_priv_data)
2815 continue;
2816 if (!sas_device_priv_data->block)
2817 continue;
2818 sas_device_priv_data->block = 0;
2819 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2820 "handle(0x%04x)\n",
2821 sas_device_priv_data->sas_target->handle));
2822 scsi_internal_device_unblock(sdev);
2823 }
2824}
2825/**
Eric Moore635374e2009-03-09 01:21:12 -06002826 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2827 * @ioc: per adapter object
2828 * @handle: device handle
2829 *
2830 * During device pull we need to appropiately set the sdev state.
2831 */
2832static void
2833_scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2834{
2835 struct MPT2SAS_DEVICE *sas_device_priv_data;
2836 struct scsi_device *sdev;
2837
2838 shost_for_each_device(sdev, ioc->shost) {
2839 sas_device_priv_data = sdev->hostdata;
2840 if (!sas_device_priv_data)
2841 continue;
2842 if (!sas_device_priv_data->block)
2843 continue;
2844 if (sas_device_priv_data->sas_target->handle == handle) {
2845 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2846 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2847 "handle(0x%04x)\n", ioc->name, handle));
2848 sas_device_priv_data->block = 0;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05302849 scsi_internal_device_unblock(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002850 }
2851 }
2852}
2853
2854/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302855 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2856 * @ioc: per adapter object
2857 * @handle: device handle
2858 *
2859 * During device pull we need to appropiately set the sdev state.
2860 */
2861static void
2862_scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2863{
2864 struct MPT2SAS_DEVICE *sas_device_priv_data;
2865 struct scsi_device *sdev;
2866
2867 shost_for_each_device(sdev, ioc->shost) {
2868 sas_device_priv_data = sdev->hostdata;
2869 if (!sas_device_priv_data)
2870 continue;
2871 if (sas_device_priv_data->block)
2872 continue;
2873 sas_device_priv_data->block = 1;
2874 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2875 "handle(0x%04x)\n",
2876 sas_device_priv_data->sas_target->handle));
2877 scsi_internal_device_block(sdev);
2878 }
2879}
2880
2881
2882/**
Eric Moore635374e2009-03-09 01:21:12 -06002883 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2884 * @ioc: per adapter object
2885 * @handle: device handle
2886 *
2887 * During device pull we need to appropiately set the sdev state.
2888 */
2889static void
2890_scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2891{
2892 struct MPT2SAS_DEVICE *sas_device_priv_data;
2893 struct scsi_device *sdev;
2894
2895 shost_for_each_device(sdev, ioc->shost) {
2896 sas_device_priv_data = sdev->hostdata;
2897 if (!sas_device_priv_data)
2898 continue;
2899 if (sas_device_priv_data->block)
2900 continue;
2901 if (sas_device_priv_data->sas_target->handle == handle) {
2902 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2903 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2904 "handle(0x%04x)\n", ioc->name, handle));
2905 sas_device_priv_data->block = 1;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05302906 scsi_internal_device_block(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002907 }
2908 }
2909}
2910
2911/**
2912 * _scsih_block_io_to_children_attached_to_ex
2913 * @ioc: per adapter object
2914 * @sas_expander: the sas_device object
2915 *
2916 * This routine set sdev state to SDEV_BLOCK for all devices
2917 * attached to this expander. This function called when expander is
2918 * pulled.
2919 */
2920static void
2921_scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2922 struct _sas_node *sas_expander)
2923{
2924 struct _sas_port *mpt2sas_port;
2925 struct _sas_device *sas_device;
2926 struct _sas_node *expander_sibling;
2927 unsigned long flags;
2928
2929 if (!sas_expander)
2930 return;
2931
2932 list_for_each_entry(mpt2sas_port,
2933 &sas_expander->sas_port_list, port_list) {
2934 if (mpt2sas_port->remote_identify.device_type ==
2935 SAS_END_DEVICE) {
2936 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2937 sas_device =
2938 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2939 mpt2sas_port->remote_identify.sas_address);
2940 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2941 if (!sas_device)
2942 continue;
2943 _scsih_block_io_device(ioc, sas_device->handle);
2944 }
2945 }
2946
2947 list_for_each_entry(mpt2sas_port,
2948 &sas_expander->sas_port_list, port_list) {
2949
2950 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05302951 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06002952 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05302953 SAS_FANOUT_EXPANDER_DEVICE) {
Eric Moore635374e2009-03-09 01:21:12 -06002954
2955 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2956 expander_sibling =
2957 mpt2sas_scsih_expander_find_by_sas_address(
2958 ioc, mpt2sas_port->remote_identify.sas_address);
2959 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2960 _scsih_block_io_to_children_attached_to_ex(ioc,
2961 expander_sibling);
2962 }
2963 }
2964}
2965
2966/**
2967 * _scsih_block_io_to_children_attached_directly
2968 * @ioc: per adapter object
2969 * @event_data: topology change event data
2970 *
2971 * This routine set sdev state to SDEV_BLOCK for all devices
2972 * direct attached during device pull.
2973 */
2974static void
2975_scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
2976 Mpi2EventDataSasTopologyChangeList_t *event_data)
2977{
2978 int i;
2979 u16 handle;
2980 u16 reason_code;
2981 u8 phy_number;
2982
2983 for (i = 0; i < event_data->NumEntries; i++) {
2984 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2985 if (!handle)
2986 continue;
2987 phy_number = event_data->StartPhyNum + i;
2988 reason_code = event_data->PHY[i].PhyStatus &
2989 MPI2_EVENT_SAS_TOPO_RC_MASK;
2990 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2991 _scsih_block_io_device(ioc, handle);
2992 }
2993}
2994
2995/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302996 * _scsih_tm_tr_send - send task management request
2997 * @ioc: per adapter object
2998 * @handle: device handle
2999 * Context: interrupt time.
3000 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003001 * This code is to initiate the device removal handshake protocol
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303002 * with controller firmware. This function will issue target reset
3003 * using high priority request queue. It will send a sas iounit
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003004 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303005 *
3006 * This is designed to send muliple task management request at the same
3007 * time to the fifo. If the fifo is full, we will append the request,
3008 * and process it in a future completion.
3009 */
3010static void
3011_scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3012{
3013 Mpi2SCSITaskManagementRequest_t *mpi_request;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303014 u16 smid;
3015 struct _sas_device *sas_device;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303016 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303017 unsigned long flags;
3018 struct _tr_list *delayed_tr;
3019
Eric Moore3cb54692010-07-08 14:44:34 -06003020 if (ioc->shost_recovery || ioc->remove_host ||
3021 ioc->pci_error_recovery) {
Kashyap, Desai1278b112010-03-09 17:34:13 +05303022 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3023 "progress!\n", __func__, ioc->name));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303024 return;
3025 }
3026
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303027 /* if PD, then return */
3028 if (test_bit(handle, ioc->pd_handles))
3029 return;
3030
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303031 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3032 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303033 if (sas_device && sas_device->starget &&
3034 sas_device->starget->hostdata) {
3035 sas_target_priv_data = sas_device->starget->hostdata;
3036 sas_target_priv_data->deleted = 1;
3037 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3038 "setting delete flag: handle(0x%04x), "
3039 "sas_addr(0x%016llx)\n", ioc->name, handle,
3040 (unsigned long long) sas_device->sas_address));
Kashyap, Desai1278b112010-03-09 17:34:13 +05303041 }
3042 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303043
3044 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3045 if (!smid) {
3046 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3047 if (!delayed_tr)
3048 return;
3049 INIT_LIST_HEAD(&delayed_tr->list);
3050 delayed_tr->handle = handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303051 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3052 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3053 "DELAYED:tr:handle(0x%04x), (open)\n",
3054 ioc->name, handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303055 return;
3056 }
3057
Kashyap, Desai1278b112010-03-09 17:34:13 +05303058 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3059 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3060 ioc->tm_tr_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303061 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3062 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3063 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3064 mpi_request->DevHandle = cpu_to_le16(handle);
3065 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303066 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3067}
3068
3069
3070
3071/**
3072 * _scsih_sas_control_complete - completion routine
3073 * @ioc: per adapter object
3074 * @smid: system request message index
3075 * @msix_index: MSIX table index supplied by the OS
3076 * @reply: reply message frame(lower 32bit addr)
3077 * Context: interrupt time.
3078 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003079 * This is the sas iounit control completion routine.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303080 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003081 * handshake protocol with controller firmware.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303082 *
3083 * Return 1 meaning mf should be freed from _base_interrupt
3084 * 0 means the mf is freed from this function.
3085 */
3086static u8
3087_scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3088 u8 msix_index, u32 reply)
3089{
Kashyap, Desai363fa502010-11-13 04:29:20 +05303090#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303091 Mpi2SasIoUnitControlReply_t *mpi_reply =
3092 mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desai363fa502010-11-13 04:29:20 +05303093#endif
Kashyap, Desai1278b112010-03-09 17:34:13 +05303094 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3095 "sc_complete:handle(0x%04x), (open) "
3096 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3097 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3098 le16_to_cpu(mpi_reply->IOCStatus),
3099 le32_to_cpu(mpi_reply->IOCLogInfo)));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303100 return 1;
3101}
3102
3103/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303104 * _scsih_tm_tr_volume_send - send target reset request for volumes
3105 * @ioc: per adapter object
3106 * @handle: device handle
3107 * Context: interrupt time.
3108 *
3109 * This is designed to send muliple task management request at the same
3110 * time to the fifo. If the fifo is full, we will append the request,
3111 * and process it in a future completion.
3112 */
3113static void
3114_scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3115{
3116 Mpi2SCSITaskManagementRequest_t *mpi_request;
3117 u16 smid;
3118 struct _tr_list *delayed_tr;
3119
Eric Moore3cb54692010-07-08 14:44:34 -06003120 if (ioc->shost_recovery || ioc->remove_host ||
3121 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303122 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3123 "progress!\n", __func__, ioc->name));
3124 return;
3125 }
3126
3127 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3128 if (!smid) {
3129 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3130 if (!delayed_tr)
3131 return;
3132 INIT_LIST_HEAD(&delayed_tr->list);
3133 delayed_tr->handle = handle;
3134 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3135 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3136 "DELAYED:tr:handle(0x%04x), (open)\n",
3137 ioc->name, handle));
3138 return;
3139 }
3140
3141 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3142 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3143 ioc->tm_tr_volume_cb_idx));
3144 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3145 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3146 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3147 mpi_request->DevHandle = cpu_to_le16(handle);
3148 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3149 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3150}
3151
3152/**
3153 * _scsih_tm_volume_tr_complete - target reset completion
3154 * @ioc: per adapter object
3155 * @smid: system request message index
3156 * @msix_index: MSIX table index supplied by the OS
3157 * @reply: reply message frame(lower 32bit addr)
3158 * Context: interrupt time.
3159 *
3160 * Return 1 meaning mf should be freed from _base_interrupt
3161 * 0 means the mf is freed from this function.
3162 */
3163static u8
3164_scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3165 u8 msix_index, u32 reply)
3166{
3167 u16 handle;
3168 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3169 Mpi2SCSITaskManagementReply_t *mpi_reply =
3170 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3171
Eric Moore3cb54692010-07-08 14:44:34 -06003172 if (ioc->shost_recovery || ioc->remove_host ||
3173 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303174 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3175 "progress!\n", __func__, ioc->name));
3176 return 1;
3177 }
3178
3179 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3180 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3181 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3182 dewtprintk(ioc, printk("spurious interrupt: "
3183 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3184 le16_to_cpu(mpi_reply->DevHandle), smid));
3185 return 0;
3186 }
3187
3188 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3189 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3190 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3191 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3192 le32_to_cpu(mpi_reply->IOCLogInfo),
3193 le32_to_cpu(mpi_reply->TerminationCount)));
3194
3195 return _scsih_check_for_pending_tm(ioc, smid);
3196}
3197
3198/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303199 * _scsih_tm_tr_complete -
3200 * @ioc: per adapter object
3201 * @smid: system request message index
3202 * @msix_index: MSIX table index supplied by the OS
3203 * @reply: reply message frame(lower 32bit addr)
3204 * Context: interrupt time.
3205 *
3206 * This is the target reset completion routine.
3207 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003208 * handshake protocol with controller firmware.
3209 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303210 *
3211 * Return 1 meaning mf should be freed from _base_interrupt
3212 * 0 means the mf is freed from this function.
3213 */
3214static u8
3215_scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3216 u32 reply)
3217{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303218 u16 handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303219 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303220 Mpi2SCSITaskManagementReply_t *mpi_reply =
3221 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3222 Mpi2SasIoUnitControlRequest_t *mpi_request;
3223 u16 smid_sas_ctrl;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303224
Eric Moore3cb54692010-07-08 14:44:34 -06003225 if (ioc->shost_recovery || ioc->remove_host ||
3226 ioc->pci_error_recovery) {
Kashyap, Desai1278b112010-03-09 17:34:13 +05303227 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3228 "progress!\n", __func__, ioc->name));
3229 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303230 }
3231
Kashyap, Desai1278b112010-03-09 17:34:13 +05303232 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3233 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3234 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3235 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3236 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3237 le16_to_cpu(mpi_reply->DevHandle), smid));
3238 return 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303239 }
3240
Kashyap, Desai1278b112010-03-09 17:34:13 +05303241 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3242 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3243 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3244 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3245 le32_to_cpu(mpi_reply->IOCLogInfo),
3246 le32_to_cpu(mpi_reply->TerminationCount)));
3247
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303248 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3249 if (!smid_sas_ctrl) {
3250 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3251 ioc->name, __func__);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303252 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303253 }
3254
Kashyap, Desai1278b112010-03-09 17:34:13 +05303255 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3256 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3257 ioc->tm_sas_control_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303258 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3259 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3260 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3261 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303262 mpi_request->DevHandle = mpi_request_tm->DevHandle;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303263 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303264
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303265 return _scsih_check_for_pending_tm(ioc, smid);
3266}
3267
3268/**
3269 * _scsih_check_for_pending_tm - check for pending task management
3270 * @ioc: per adapter object
3271 * @smid: system request message index
3272 *
3273 * This will check delayed target reset list, and feed the
3274 * next reqeust.
3275 *
3276 * Return 1 meaning mf should be freed from _base_interrupt
3277 * 0 means the mf is freed from this function.
3278 */
3279static u8
3280_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3281{
3282 struct _tr_list *delayed_tr;
3283
3284 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3285 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3286 struct _tr_list, list);
3287 mpt2sas_base_free_smid(ioc, smid);
3288 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3289 list_del(&delayed_tr->list);
3290 kfree(delayed_tr);
3291 return 0;
3292 }
3293
Kashyap, Desai1278b112010-03-09 17:34:13 +05303294 if (!list_empty(&ioc->delayed_tr_list)) {
3295 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3296 struct _tr_list, list);
3297 mpt2sas_base_free_smid(ioc, smid);
3298 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3299 list_del(&delayed_tr->list);
3300 kfree(delayed_tr);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303301 return 0;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303302 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303303
Kashyap, Desai1278b112010-03-09 17:34:13 +05303304 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303305}
3306
3307/**
Eric Moore635374e2009-03-09 01:21:12 -06003308 * _scsih_check_topo_delete_events - sanity check on topo events
3309 * @ioc: per adapter object
3310 * @event_data: the event data payload
3311 *
3312 * This routine added to better handle cable breaker.
3313 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003314 * This handles the case where driver receives multiple expander
Eric Moore635374e2009-03-09 01:21:12 -06003315 * add and delete events in a single shot. When there is a delete event
3316 * the routine will void any pending add events waiting in the event queue.
3317 *
3318 * Return nothing.
3319 */
3320static void
3321_scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3322 Mpi2EventDataSasTopologyChangeList_t *event_data)
3323{
3324 struct fw_event_work *fw_event;
3325 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3326 u16 expander_handle;
3327 struct _sas_node *sas_expander;
3328 unsigned long flags;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303329 int i, reason_code;
3330 u16 handle;
3331
3332 for (i = 0 ; i < event_data->NumEntries; i++) {
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303333 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3334 if (!handle)
3335 continue;
3336 reason_code = event_data->PHY[i].PhyStatus &
3337 MPI2_EVENT_SAS_TOPO_RC_MASK;
3338 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3339 _scsih_tm_tr_send(ioc, handle);
3340 }
Eric Moore635374e2009-03-09 01:21:12 -06003341
3342 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3343 if (expander_handle < ioc->sas_hba.num_phys) {
3344 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3345 return;
3346 }
3347
3348 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3349 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
3350 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3351 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3352 expander_handle);
3353 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3354 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3355 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3356 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3357
3358 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3359 return;
3360
3361 /* mark ignore flag for pending events */
3362 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3363 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3364 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3365 fw_event->ignore)
3366 continue;
3367 local_event_data = fw_event->event_data;
3368 if (local_event_data->ExpStatus ==
3369 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3370 local_event_data->ExpStatus ==
3371 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3372 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3373 expander_handle) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303374 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06003375 "setting ignoring flag\n", ioc->name));
3376 fw_event->ignore = 1;
3377 }
3378 }
3379 }
3380 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3381}
3382
3383/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303384 * _scsih_set_volume_delete_flag - setting volume delete flag
3385 * @ioc: per adapter object
3386 * @handle: device handle
3387 *
3388 * This
3389 * Return nothing.
3390 */
3391static void
3392_scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3393{
3394 struct _raid_device *raid_device;
3395 struct MPT2SAS_TARGET *sas_target_priv_data;
3396 unsigned long flags;
3397
3398 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3399 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3400 if (raid_device && raid_device->starget &&
3401 raid_device->starget->hostdata) {
3402 sas_target_priv_data =
3403 raid_device->starget->hostdata;
3404 sas_target_priv_data->deleted = 1;
3405 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3406 "setting delete flag: handle(0x%04x), "
3407 "wwid(0x%016llx)\n", ioc->name, handle,
3408 (unsigned long long) raid_device->wwid));
3409 }
3410 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3411}
3412
3413/**
3414 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3415 * @handle: input handle
3416 * @a: handle for volume a
3417 * @b: handle for volume b
3418 *
3419 * IR firmware only supports two raid volumes. The purpose of this
3420 * routine is to set the volume handle in either a or b. When the given
3421 * input handle is non-zero, or when a and b have not been set before.
3422 */
3423static void
3424_scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3425{
3426 if (!handle || handle == *a || handle == *b)
3427 return;
3428 if (!*a)
3429 *a = handle;
3430 else if (!*b)
3431 *b = handle;
3432}
3433
3434/**
3435 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3436 * @ioc: per adapter object
3437 * @event_data: the event data payload
3438 * Context: interrupt time.
3439 *
3440 * This routine will send target reset to volume, followed by target
3441 * resets to the PDs. This is called when a PD has been removed, or
3442 * volume has been deleted or removed. When the target reset is sent
3443 * to volume, the PD target resets need to be queued to start upon
3444 * completion of the volume target reset.
3445 *
3446 * Return nothing.
3447 */
3448static void
3449_scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3450 Mpi2EventDataIrConfigChangeList_t *event_data)
3451{
3452 Mpi2EventIrConfigElement_t *element;
3453 int i;
3454 u16 handle, volume_handle, a, b;
3455 struct _tr_list *delayed_tr;
3456
3457 a = 0;
3458 b = 0;
3459
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303460 if (ioc->is_warpdrive)
3461 return;
3462
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303463 /* Volume Resets for Deleted or Removed */
3464 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3465 for (i = 0; i < event_data->NumElements; i++, element++) {
3466 if (element->ReasonCode ==
3467 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3468 element->ReasonCode ==
3469 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3470 volume_handle = le16_to_cpu(element->VolDevHandle);
3471 _scsih_set_volume_delete_flag(ioc, volume_handle);
3472 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3473 }
3474 }
3475
3476 /* Volume Resets for UNHIDE events */
3477 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3478 for (i = 0; i < event_data->NumElements; i++, element++) {
3479 if (le32_to_cpu(event_data->Flags) &
3480 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3481 continue;
3482 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3483 volume_handle = le16_to_cpu(element->VolDevHandle);
3484 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3485 }
3486 }
3487
3488 if (a)
3489 _scsih_tm_tr_volume_send(ioc, a);
3490 if (b)
3491 _scsih_tm_tr_volume_send(ioc, b);
3492
3493 /* PD target resets */
3494 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3495 for (i = 0; i < event_data->NumElements; i++, element++) {
3496 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3497 continue;
3498 handle = le16_to_cpu(element->PhysDiskDevHandle);
3499 volume_handle = le16_to_cpu(element->VolDevHandle);
3500 clear_bit(handle, ioc->pd_handles);
3501 if (!volume_handle)
3502 _scsih_tm_tr_send(ioc, handle);
3503 else if (volume_handle == a || volume_handle == b) {
3504 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3505 BUG_ON(!delayed_tr);
3506 INIT_LIST_HEAD(&delayed_tr->list);
3507 delayed_tr->handle = handle;
3508 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3509 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3510 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3511 handle));
3512 } else
3513 _scsih_tm_tr_send(ioc, handle);
3514 }
3515}
3516
3517
3518/**
3519 * _scsih_check_volume_delete_events - set delete flag for volumes
3520 * @ioc: per adapter object
3521 * @event_data: the event data payload
3522 * Context: interrupt time.
3523 *
3524 * This will handle the case when the cable connected to entire volume is
3525 * pulled. We will take care of setting the deleted flag so normal IO will
3526 * not be sent.
3527 *
3528 * Return nothing.
3529 */
3530static void
3531_scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3532 Mpi2EventDataIrVolume_t *event_data)
3533{
3534 u32 state;
3535
3536 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3537 return;
3538 state = le32_to_cpu(event_data->NewValue);
3539 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3540 MPI2_RAID_VOL_STATE_FAILED)
3541 _scsih_set_volume_delete_flag(ioc,
3542 le16_to_cpu(event_data->VolDevHandle));
3543}
3544
3545/**
Eric Moore635374e2009-03-09 01:21:12 -06003546 * _scsih_flush_running_cmds - completing outstanding commands.
3547 * @ioc: per adapter object
3548 *
3549 * The flushing out of all pending scmd commands following host reset,
3550 * where all IO is dropped to the floor.
3551 *
3552 * Return nothing.
3553 */
3554static void
3555_scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3556{
3557 struct scsi_cmnd *scmd;
3558 u16 smid;
3559 u16 count = 0;
3560
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303561 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05303562 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003563 if (!scmd)
3564 continue;
3565 count++;
3566 mpt2sas_base_free_smid(ioc, smid);
3567 scsi_dma_unmap(scmd);
Eric Moore3cb54692010-07-08 14:44:34 -06003568 if (ioc->pci_error_recovery)
3569 scmd->result = DID_NO_CONNECT << 16;
3570 else
3571 scmd->result = DID_RESET << 16;
Eric Moore635374e2009-03-09 01:21:12 -06003572 scmd->scsi_done(scmd);
3573 }
3574 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3575 ioc->name, count));
3576}
3577
3578/**
Eric Moore3c621b32009-05-18 12:59:41 -06003579 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3580 * @scmd: pointer to scsi command object
3581 * @mpi_request: pointer to the SCSI_IO reqest message frame
3582 *
3583 * Supporting protection 1 and 3.
3584 *
3585 * Returns nothing
3586 */
3587static void
3588_scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3589{
3590 u16 eedp_flags;
3591 unsigned char prot_op = scsi_get_prot_op(scmd);
3592 unsigned char prot_type = scsi_get_prot_type(scmd);
3593
Eric Moored334aa72010-04-22 10:47:40 -06003594 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
Eric Moore3c621b32009-05-18 12:59:41 -06003595 return;
3596
3597 if (prot_op == SCSI_PROT_READ_STRIP)
3598 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3599 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3600 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3601 else
3602 return;
3603
Eric Moore3c621b32009-05-18 12:59:41 -06003604 switch (prot_type) {
3605 case SCSI_PROT_DIF_TYPE1:
Martin K. Petersen756aca72011-05-18 00:45:22 -04003606 case SCSI_PROT_DIF_TYPE2:
Eric Moore3c621b32009-05-18 12:59:41 -06003607
3608 /*
3609 * enable ref/guard checking
3610 * auto increment ref tag
3611 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303612 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
Eric Moore3c621b32009-05-18 12:59:41 -06003613 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3614 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3615 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3616 cpu_to_be32(scsi_get_lba(scmd));
Eric Moored334aa72010-04-22 10:47:40 -06003617 break;
Eric Moore3c621b32009-05-18 12:59:41 -06003618
Eric Moore3c621b32009-05-18 12:59:41 -06003619 case SCSI_PROT_DIF_TYPE3:
3620
3621 /*
3622 * enable guard checking
3623 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303624 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
Eric Moore3c621b32009-05-18 12:59:41 -06003625 break;
3626 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05303627 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3628 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
Eric Moore3c621b32009-05-18 12:59:41 -06003629}
3630
3631/**
3632 * _scsih_eedp_error_handling - return sense code for EEDP errors
3633 * @scmd: pointer to scsi command object
3634 * @ioc_status: ioc status
3635 *
3636 * Returns nothing
3637 */
3638static void
3639_scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3640{
3641 u8 ascq;
3642 u8 sk;
3643 u8 host_byte;
3644
3645 switch (ioc_status) {
3646 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3647 ascq = 0x01;
3648 break;
3649 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3650 ascq = 0x02;
3651 break;
3652 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3653 ascq = 0x03;
3654 break;
3655 default:
3656 ascq = 0x00;
3657 break;
3658 }
3659
3660 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
3661 sk = ILLEGAL_REQUEST;
3662 host_byte = DID_ABORT;
3663 } else {
3664 sk = ABORTED_COMMAND;
3665 host_byte = DID_OK;
3666 }
3667
3668 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
3669 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
3670 SAM_STAT_CHECK_CONDITION;
3671}
3672
3673/**
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303674 * _scsih_scsi_direct_io_get - returns direct io flag
3675 * @ioc: per adapter object
3676 * @smid: system request message index
3677 *
3678 * Returns the smid stored scmd pointer.
3679 */
3680static inline u8
3681_scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3682{
3683 return ioc->scsi_lookup[smid - 1].direct_io;
3684}
3685
3686/**
3687 * _scsih_scsi_direct_io_set - sets direct io flag
3688 * @ioc: per adapter object
3689 * @smid: system request message index
3690 * @direct_io: Zero or non-zero value to set in the direct_io flag
3691 *
3692 * Returns Nothing.
3693 */
3694static inline void
3695_scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3696{
3697 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3698}
3699
3700
3701/**
3702 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3703 * @ioc: per adapter object
3704 * @scmd: pointer to scsi command object
3705 * @raid_device: pointer to raid device data structure
3706 * @mpi_request: pointer to the SCSI_IO reqest message frame
3707 * @smid: system request message index
3708 *
3709 * Returns nothing
3710 */
3711static void
3712_scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3713 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3714 u16 smid)
3715{
3716 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3717 u32 stripe_sz, stripe_exp;
3718 u8 num_pds, *cdb_ptr, *tmp_ptr, *lba_ptr1, *lba_ptr2;
3719 u8 cdb0 = scmd->cmnd[0];
3720
3721 /*
3722 * Try Direct I/O to RAID memeber disks
3723 */
3724 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3725 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3726 cdb_ptr = mpi_request->CDB.CDB32;
3727
3728 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3729 | cdb_ptr[5])) {
3730 io_size = scsi_bufflen(scmd) >> 9;
3731 /* get virtual lba */
3732 lba_ptr1 = lba_ptr2 = (cdb0 < READ_16) ? &cdb_ptr[2] :
3733 &cdb_ptr[6];
3734 tmp_ptr = (u8 *)&v_lba + 3;
3735 *tmp_ptr-- = *lba_ptr1++;
3736 *tmp_ptr-- = *lba_ptr1++;
3737 *tmp_ptr-- = *lba_ptr1++;
3738 *tmp_ptr = *lba_ptr1;
3739
3740 if (((u64)v_lba + (u64)io_size - 1) <=
3741 (u32)raid_device->max_lba) {
3742 stripe_sz = raid_device->stripe_sz;
3743 stripe_exp = raid_device->stripe_exponent;
3744 stripe_off = v_lba & (stripe_sz - 1);
3745
3746 /* Check whether IO falls within a stripe */
3747 if ((stripe_off + io_size) <= stripe_sz) {
3748 num_pds = raid_device->num_pds;
3749 p_lba = v_lba >> stripe_exp;
3750 stripe_unit = p_lba / num_pds;
3751 column = p_lba % num_pds;
3752 p_lba = (stripe_unit << stripe_exp) +
3753 stripe_off;
3754 mpi_request->DevHandle =
3755 cpu_to_le16(raid_device->
3756 pd_handle[column]);
3757 tmp_ptr = (u8 *)&p_lba + 3;
3758 *lba_ptr2++ = *tmp_ptr--;
3759 *lba_ptr2++ = *tmp_ptr--;
3760 *lba_ptr2++ = *tmp_ptr--;
3761 *lba_ptr2 = *tmp_ptr;
3762 /*
3763 * WD: To indicate this I/O is directI/O
3764 */
3765 _scsih_scsi_direct_io_set(ioc, smid, 1);
3766 }
3767 }
3768 }
3769 }
3770}
3771
3772/**
Eric Moored5d135b2009-05-18 13:02:08 -06003773 * _scsih_qcmd - main scsi request entry point
Eric Moore635374e2009-03-09 01:21:12 -06003774 * @scmd: pointer to scsi command object
3775 * @done: function pointer to be invoked on completion
3776 *
3777 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3778 *
3779 * Returns 0 on success. If there's a failure, return either:
3780 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3781 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3782 */
3783static int
Jeff Garzikf2812332010-11-16 02:10:29 -05003784_scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
Eric Moore635374e2009-03-09 01:21:12 -06003785{
3786 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3787 struct MPT2SAS_DEVICE *sas_device_priv_data;
3788 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303789 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06003790 Mpi2SCSIIORequest_t *mpi_request;
3791 u32 mpi_control;
3792 u16 smid;
Eric Moore635374e2009-03-09 01:21:12 -06003793
3794 scmd->scsi_done = done;
3795 sas_device_priv_data = scmd->device->hostdata;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303796 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Eric Moore635374e2009-03-09 01:21:12 -06003797 scmd->result = DID_NO_CONNECT << 16;
3798 scmd->scsi_done(scmd);
3799 return 0;
3800 }
3801
Kashyap, Desai78215782011-06-14 10:57:08 +05303802 if (ioc->pci_error_recovery || ioc->remove_host) {
Eric Moore3cb54692010-07-08 14:44:34 -06003803 scmd->result = DID_NO_CONNECT << 16;
3804 scmd->scsi_done(scmd);
3805 return 0;
3806 }
3807
Eric Moore635374e2009-03-09 01:21:12 -06003808 sas_target_priv_data = sas_device_priv_data->sas_target;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303809 /* invalid device handle */
3810 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
Eric Moore635374e2009-03-09 01:21:12 -06003811 scmd->result = DID_NO_CONNECT << 16;
3812 scmd->scsi_done(scmd);
3813 return 0;
3814 }
3815
Kashyap, Desai130b9582010-04-08 17:54:32 +05303816 /* host recovery or link resets sent via IOCTLs */
3817 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
Eric Moore635374e2009-03-09 01:21:12 -06003818 return SCSI_MLQUEUE_HOST_BUSY;
Uwe Kleine-König65155b32010-06-11 12:17:01 +02003819 /* device busy with task management */
Kashyap, Desai130b9582010-04-08 17:54:32 +05303820 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3821 return SCSI_MLQUEUE_DEVICE_BUSY;
3822 /* device has been deleted */
3823 else if (sas_target_priv_data->deleted) {
3824 scmd->result = DID_NO_CONNECT << 16;
3825 scmd->scsi_done(scmd);
3826 return 0;
3827 }
Eric Moore635374e2009-03-09 01:21:12 -06003828
3829 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3830 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3831 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3832 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3833 else
3834 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3835
3836 /* set tags */
3837 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3838 if (scmd->device->tagged_supported) {
3839 if (scmd->device->ordered_tags)
3840 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3841 else
3842 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3843 } else
3844/* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3845/* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3846 */
3847 mpi_control |= (0x500);
3848
3849 } else
3850 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303851 /* Make sure Device is not raid volume.
3852 * We do not expose raid functionality to upper layer for warpdrive.
3853 */
3854 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Eric Moored334aa72010-04-22 10:47:40 -06003855 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
Eric Moore635374e2009-03-09 01:21:12 -06003856 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3857
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303858 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06003859 if (!smid) {
3860 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3861 ioc->name, __func__);
3862 goto out;
3863 }
3864 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3865 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
Eric Moore3c621b32009-05-18 12:59:41 -06003866 _scsih_setup_eedp(scmd, mpi_request);
Eric Moored334aa72010-04-22 10:47:40 -06003867 if (scmd->cmd_len == 32)
3868 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
Eric Moore635374e2009-03-09 01:21:12 -06003869 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3870 if (sas_device_priv_data->sas_target->flags &
3871 MPT_TARGET_FLAGS_RAID_COMPONENT)
3872 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3873 else
3874 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3875 mpi_request->DevHandle =
3876 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3877 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3878 mpi_request->Control = cpu_to_le32(mpi_control);
3879 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3880 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3881 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3882 mpi_request->SenseBufferLowAddress =
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05303883 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003884 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3885 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3886 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303887 mpi_request->VF_ID = 0; /* TODO */
3888 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06003889 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3890 mpi_request->LUN);
3891 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3892
3893 if (!mpi_request->DataLength) {
3894 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3895 } else {
3896 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3897 mpt2sas_base_free_smid(ioc, smid);
3898 goto out;
3899 }
3900 }
3901
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303902 raid_device = sas_target_priv_data->raid_device;
3903 if (raid_device && raid_device->direct_io_enabled)
3904 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3905 smid);
3906
Kashyap, Desai58287fd2010-03-17 16:27:25 +05303907 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
3908 mpt2sas_base_put_smid_scsi_io(ioc, smid,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303909 le16_to_cpu(mpi_request->DevHandle));
Kashyap, Desai58287fd2010-03-17 16:27:25 +05303910 else
3911 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003912 return 0;
3913
3914 out:
3915 return SCSI_MLQUEUE_HOST_BUSY;
3916}
3917
Jeff Garzikf2812332010-11-16 02:10:29 -05003918static DEF_SCSI_QCMD(_scsih_qcmd)
3919
Eric Moore635374e2009-03-09 01:21:12 -06003920/**
3921 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3922 * @sense_buffer: sense data returned by target
3923 * @data: normalized skey/asc/ascq
3924 *
3925 * Return nothing.
3926 */
3927static void
3928_scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3929{
3930 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3931 /* descriptor format */
3932 data->skey = sense_buffer[1] & 0x0F;
3933 data->asc = sense_buffer[2];
3934 data->ascq = sense_buffer[3];
3935 } else {
3936 /* fixed format */
3937 data->skey = sense_buffer[2] & 0x0F;
3938 data->asc = sense_buffer[12];
3939 data->ascq = sense_buffer[13];
3940 }
3941}
3942
3943#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3944/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003945 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
Eric Moore635374e2009-03-09 01:21:12 -06003946 * @ioc: per adapter object
3947 * @scmd: pointer to scsi command object
3948 * @mpi_reply: reply mf payload returned from firmware
3949 *
3950 * scsi_status - SCSI Status code returned from target device
3951 * scsi_state - state info associated with SCSI_IO determined by ioc
3952 * ioc_status - ioc supplied status info
3953 *
3954 * Return nothing.
3955 */
3956static void
3957_scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3958 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3959{
3960 u32 response_info;
3961 u8 *response_bytes;
3962 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3963 MPI2_IOCSTATUS_MASK;
3964 u8 scsi_state = mpi_reply->SCSIState;
3965 u8 scsi_status = mpi_reply->SCSIStatus;
3966 char *desc_ioc_state = NULL;
3967 char *desc_scsi_status = NULL;
3968 char *desc_scsi_state = ioc->tmp_string;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05303969 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05303970 struct _sas_device *sas_device = NULL;
3971 unsigned long flags;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05303972 struct scsi_target *starget = scmd->device->sdev_target;
3973 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303974 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05303975
3976 if (!priv_target)
3977 return;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05303978
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303979 if (ioc->hide_ir_msg)
3980 device_str = "WarpDrive";
3981 else
3982 device_str = "volume";
3983
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05303984 if (log_info == 0x31170000)
3985 return;
Eric Moore635374e2009-03-09 01:21:12 -06003986
3987 switch (ioc_status) {
3988 case MPI2_IOCSTATUS_SUCCESS:
3989 desc_ioc_state = "success";
3990 break;
3991 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3992 desc_ioc_state = "invalid function";
3993 break;
3994 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3995 desc_ioc_state = "scsi recovered error";
3996 break;
3997 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
3998 desc_ioc_state = "scsi invalid dev handle";
3999 break;
4000 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4001 desc_ioc_state = "scsi device not there";
4002 break;
4003 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4004 desc_ioc_state = "scsi data overrun";
4005 break;
4006 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4007 desc_ioc_state = "scsi data underrun";
4008 break;
4009 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4010 desc_ioc_state = "scsi io data error";
4011 break;
4012 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4013 desc_ioc_state = "scsi protocol error";
4014 break;
4015 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4016 desc_ioc_state = "scsi task terminated";
4017 break;
4018 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4019 desc_ioc_state = "scsi residual mismatch";
4020 break;
4021 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4022 desc_ioc_state = "scsi task mgmt failed";
4023 break;
4024 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4025 desc_ioc_state = "scsi ioc terminated";
4026 break;
4027 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4028 desc_ioc_state = "scsi ext terminated";
4029 break;
Eric Moore3c621b32009-05-18 12:59:41 -06004030 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4031 desc_ioc_state = "eedp guard error";
4032 break;
4033 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4034 desc_ioc_state = "eedp ref tag error";
4035 break;
4036 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4037 desc_ioc_state = "eedp app tag error";
4038 break;
Eric Moore635374e2009-03-09 01:21:12 -06004039 default:
4040 desc_ioc_state = "unknown";
4041 break;
4042 }
4043
4044 switch (scsi_status) {
4045 case MPI2_SCSI_STATUS_GOOD:
4046 desc_scsi_status = "good";
4047 break;
4048 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4049 desc_scsi_status = "check condition";
4050 break;
4051 case MPI2_SCSI_STATUS_CONDITION_MET:
4052 desc_scsi_status = "condition met";
4053 break;
4054 case MPI2_SCSI_STATUS_BUSY:
4055 desc_scsi_status = "busy";
4056 break;
4057 case MPI2_SCSI_STATUS_INTERMEDIATE:
4058 desc_scsi_status = "intermediate";
4059 break;
4060 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4061 desc_scsi_status = "intermediate condmet";
4062 break;
4063 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4064 desc_scsi_status = "reservation conflict";
4065 break;
4066 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4067 desc_scsi_status = "command terminated";
4068 break;
4069 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4070 desc_scsi_status = "task set full";
4071 break;
4072 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4073 desc_scsi_status = "aca active";
4074 break;
4075 case MPI2_SCSI_STATUS_TASK_ABORTED:
4076 desc_scsi_status = "task aborted";
4077 break;
4078 default:
4079 desc_scsi_status = "unknown";
4080 break;
4081 }
4082
4083 desc_scsi_state[0] = '\0';
4084 if (!scsi_state)
4085 desc_scsi_state = " ";
4086 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4087 strcat(desc_scsi_state, "response info ");
4088 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4089 strcat(desc_scsi_state, "state terminated ");
4090 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4091 strcat(desc_scsi_state, "no status ");
4092 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4093 strcat(desc_scsi_state, "autosense failed ");
4094 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4095 strcat(desc_scsi_state, "autosense valid ");
4096
4097 scsi_print_command(scmd);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304098
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304099 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304100 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4101 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304102 } else {
4103 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4104 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4105 priv_target->sas_address);
4106 if (sas_device) {
4107 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4108 "phy(%d)\n", ioc->name, sas_device->sas_address,
4109 sas_device->phy);
4110 printk(MPT2SAS_WARN_FMT
4111 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4112 ioc->name, sas_device->enclosure_logical_id,
4113 sas_device->slot);
4114 }
4115 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304116 }
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304117
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304118 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4119 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4120 desc_ioc_state, ioc_status, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004121 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4122 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4123 scsi_get_resid(scmd));
4124 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4125 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4126 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4127 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4128 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4129 scsi_status, desc_scsi_state, scsi_state);
4130
4131 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4132 struct sense_info data;
4133 _scsih_normalize_sense(scmd->sense_buffer, &data);
4134 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304135 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4136 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
Eric Moore635374e2009-03-09 01:21:12 -06004137 }
4138
4139 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4140 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4141 response_bytes = (u8 *)&response_info;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304142 _scsih_response_code(ioc, response_bytes[0]);
Eric Moore635374e2009-03-09 01:21:12 -06004143 }
4144}
4145#endif
4146
4147/**
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304148 * _scsih_turn_on_fault_led - illuminate Fault LED
Eric Moore635374e2009-03-09 01:21:12 -06004149 * @ioc: per adapter object
4150 * @handle: device handle
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304151 * Context: process
4152 *
4153 * Return nothing.
4154 */
4155static void
4156_scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4157{
4158 Mpi2SepReply_t mpi_reply;
4159 Mpi2SepRequest_t mpi_request;
4160
4161 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4162 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4163 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4164 mpi_request.SlotStatus =
4165 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4166 mpi_request.DevHandle = cpu_to_le16(handle);
4167 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4168 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4169 &mpi_request)) != 0) {
4170 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4171 __FILE__, __LINE__, __func__);
4172 return;
4173 }
4174
4175 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4176 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4177 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4178 le16_to_cpu(mpi_reply.IOCStatus),
4179 le32_to_cpu(mpi_reply.IOCLogInfo)));
4180 return;
4181 }
4182}
4183
4184/**
4185 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4186 * @ioc: per adapter object
4187 * @handle: device handle
4188 * Context: interrupt.
4189 *
4190 * Return nothing.
4191 */
4192static void
4193_scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4194{
4195 struct fw_event_work *fw_event;
4196
4197 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4198 if (!fw_event)
4199 return;
4200 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4201 fw_event->device_handle = handle;
4202 fw_event->ioc = ioc;
4203 _scsih_fw_event_add(ioc, fw_event);
4204}
4205
4206/**
4207 * _scsih_smart_predicted_fault - process smart errors
4208 * @ioc: per adapter object
4209 * @handle: device handle
4210 * Context: interrupt.
Eric Moore635374e2009-03-09 01:21:12 -06004211 *
4212 * Return nothing.
4213 */
4214static void
4215_scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4216{
Eric Moore635374e2009-03-09 01:21:12 -06004217 struct scsi_target *starget;
4218 struct MPT2SAS_TARGET *sas_target_priv_data;
4219 Mpi2EventNotificationReply_t *event_reply;
4220 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4221 struct _sas_device *sas_device;
4222 ssize_t sz;
4223 unsigned long flags;
4224
4225 /* only handle non-raid devices */
4226 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4227 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4228 if (!sas_device) {
4229 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4230 return;
4231 }
4232 starget = sas_device->starget;
4233 sas_target_priv_data = starget->hostdata;
4234
4235 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4236 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4237 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4238 return;
4239 }
4240 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4241 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4242
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304243 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4244 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06004245
4246 /* insert into event log */
4247 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4248 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4249 event_reply = kzalloc(sz, GFP_KERNEL);
4250 if (!event_reply) {
4251 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4252 ioc->name, __FILE__, __LINE__, __func__);
4253 return;
4254 }
4255
4256 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4257 event_reply->Event =
4258 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4259 event_reply->MsgLength = sz/4;
4260 event_reply->EventDataLength =
4261 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4262 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4263 event_reply->EventData;
4264 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4265 event_data->ASC = 0x5D;
4266 event_data->DevHandle = cpu_to_le16(handle);
4267 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4268 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4269 kfree(event_reply);
4270}
4271
4272/**
Eric Moored5d135b2009-05-18 13:02:08 -06004273 * _scsih_io_done - scsi request callback
Eric Moore635374e2009-03-09 01:21:12 -06004274 * @ioc: per adapter object
4275 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304276 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06004277 * @reply: reply message frame(lower 32bit addr)
4278 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304279 * Callback handler when using _scsih_qcmd.
Eric Moore635374e2009-03-09 01:21:12 -06004280 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304281 * Return 1 meaning mf should be freed from _base_interrupt
4282 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06004283 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304284static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304285_scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06004286{
4287 Mpi2SCSIIORequest_t *mpi_request;
4288 Mpi2SCSIIOReply_t *mpi_reply;
4289 struct scsi_cmnd *scmd;
4290 u16 ioc_status;
4291 u32 xfer_cnt;
4292 u8 scsi_state;
4293 u8 scsi_status;
4294 u32 log_info;
4295 struct MPT2SAS_DEVICE *sas_device_priv_data;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304296 u32 response_code = 0;
Kashyap, Desai82a45252011-07-05 12:40:23 +05304297 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06004298
4299 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05304300 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004301 if (scmd == NULL)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304302 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004303
4304 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4305
4306 if (mpi_reply == NULL) {
4307 scmd->result = DID_OK << 16;
4308 goto out;
4309 }
4310
4311 sas_device_priv_data = scmd->device->hostdata;
4312 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4313 sas_device_priv_data->sas_target->deleted) {
4314 scmd->result = DID_NO_CONNECT << 16;
4315 goto out;
4316 }
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304317 /*
4318 * WARPDRIVE: If direct_io is set then it is directIO,
4319 * the failed direct I/O should be redirected to volume
4320 */
4321 if (_scsih_scsi_direct_io_get(ioc, smid)) {
Kashyap, Desai82a45252011-07-05 12:40:23 +05304322 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4323 ioc->scsi_lookup[smid - 1].scmd = scmd;
4324 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304325 _scsih_scsi_direct_io_set(ioc, smid, 0);
4326 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4327 mpi_request->DevHandle =
4328 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4329 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4330 sas_device_priv_data->sas_target->handle);
4331 return 0;
4332 }
4333
Eric Moore635374e2009-03-09 01:21:12 -06004334
4335 /* turning off TLR */
Kashyap, Desai9982f592009-09-23 17:23:07 +05304336 scsi_state = mpi_reply->SCSIState;
4337 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4338 response_code =
4339 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
Eric Moore635374e2009-03-09 01:21:12 -06004340 if (!sas_device_priv_data->tlr_snoop_check) {
4341 sas_device_priv_data->tlr_snoop_check++;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304342 /* Make sure Device is not raid volume.
4343 * We do not expose raid functionality to upper layer for warpdrive.
4344 */
4345 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Kashyap, Desai3ed21522010-02-17 16:08:36 +05304346 sas_is_tlr_enabled(scmd->device) &&
Kashyap, Desai84f0b042009-12-16 18:56:28 +05304347 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4348 sas_disable_tlr(scmd->device);
4349 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4350 }
Eric Moore635374e2009-03-09 01:21:12 -06004351 }
4352
4353 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4354 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4355 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4356 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4357 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4358 else
4359 log_info = 0;
4360 ioc_status &= MPI2_IOCSTATUS_MASK;
Eric Moore635374e2009-03-09 01:21:12 -06004361 scsi_status = mpi_reply->SCSIStatus;
4362
4363 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4364 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4365 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4366 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4367 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4368 }
4369
4370 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4371 struct sense_info data;
4372 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4373 smid);
Eric Moore0d04df92009-04-21 15:38:43 -06004374 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
Eric Moore635374e2009-03-09 01:21:12 -06004375 le32_to_cpu(mpi_reply->SenseCount));
Eric Moore0d04df92009-04-21 15:38:43 -06004376 memcpy(scmd->sense_buffer, sense_data, sz);
Eric Moore635374e2009-03-09 01:21:12 -06004377 _scsih_normalize_sense(scmd->sense_buffer, &data);
4378 /* failure prediction threshold exceeded */
4379 if (data.asc == 0x5D)
4380 _scsih_smart_predicted_fault(ioc,
4381 le16_to_cpu(mpi_reply->DevHandle));
4382 }
4383
4384 switch (ioc_status) {
4385 case MPI2_IOCSTATUS_BUSY:
4386 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4387 scmd->result = SAM_STAT_BUSY;
4388 break;
4389
4390 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4391 scmd->result = DID_NO_CONNECT << 16;
4392 break;
4393
4394 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4395 if (sas_device_priv_data->block) {
Kashyap, Desaie4e7c7e2009-09-23 17:33:14 +05304396 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4397 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06004398 }
Eric Moore635374e2009-03-09 01:21:12 -06004399 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4400 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4401 scmd->result = DID_RESET << 16;
4402 break;
4403
4404 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4405 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4406 scmd->result = DID_SOFT_ERROR << 16;
4407 else
4408 scmd->result = (DID_OK << 16) | scsi_status;
4409 break;
4410
4411 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4412 scmd->result = (DID_OK << 16) | scsi_status;
4413
4414 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4415 break;
4416
4417 if (xfer_cnt < scmd->underflow) {
4418 if (scsi_status == SAM_STAT_BUSY)
4419 scmd->result = SAM_STAT_BUSY;
4420 else
4421 scmd->result = DID_SOFT_ERROR << 16;
4422 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4423 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4424 scmd->result = DID_SOFT_ERROR << 16;
4425 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4426 scmd->result = DID_RESET << 16;
4427 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4428 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4429 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4430 scmd->result = (DRIVER_SENSE << 24) |
4431 SAM_STAT_CHECK_CONDITION;
4432 scmd->sense_buffer[0] = 0x70;
4433 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4434 scmd->sense_buffer[12] = 0x20;
4435 scmd->sense_buffer[13] = 0;
4436 }
4437 break;
4438
4439 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4440 scsi_set_resid(scmd, 0);
4441 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4442 case MPI2_IOCSTATUS_SUCCESS:
4443 scmd->result = (DID_OK << 16) | scsi_status;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304444 if (response_code ==
4445 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4446 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4447 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
Eric Moore635374e2009-03-09 01:21:12 -06004448 scmd->result = DID_SOFT_ERROR << 16;
4449 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4450 scmd->result = DID_RESET << 16;
4451 break;
4452
Eric Moore3c621b32009-05-18 12:59:41 -06004453 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4454 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4455 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4456 _scsih_eedp_error_handling(scmd, ioc_status);
4457 break;
Eric Moore635374e2009-03-09 01:21:12 -06004458 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4459 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4460 case MPI2_IOCSTATUS_INVALID_SGL:
4461 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4462 case MPI2_IOCSTATUS_INVALID_FIELD:
4463 case MPI2_IOCSTATUS_INVALID_STATE:
4464 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4465 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4466 default:
4467 scmd->result = DID_SOFT_ERROR << 16;
4468 break;
4469
4470 }
4471
4472#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4473 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4474 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4475#endif
4476
4477 out:
4478 scsi_dma_unmap(scmd);
4479 scmd->scsi_done(scmd);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304480 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004481}
4482
4483/**
Eric Moore635374e2009-03-09 01:21:12 -06004484 * _scsih_sas_host_refresh - refreshing sas host object contents
4485 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06004486 * Context: user
4487 *
4488 * During port enable, fw will send topology events for every device. Its
4489 * possible that the handles may change from the previous setting, so this
4490 * code keeping handles updating if changed.
4491 *
4492 * Return nothing.
4493 */
4494static void
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304495_scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06004496{
4497 u16 sz;
4498 u16 ioc_status;
4499 int i;
4500 Mpi2ConfigReply_t mpi_reply;
4501 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304502 u16 attached_handle;
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304503 u8 link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06004504
4505 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4506 "updating handles for sas_host(0x%016llx)\n",
4507 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4508
4509 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4510 * sizeof(Mpi2SasIOUnit0PhyData_t));
4511 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4512 if (!sas_iounit_pg0) {
4513 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4514 ioc->name, __FILE__, __LINE__, __func__);
4515 return;
4516 }
Eric Moore635374e2009-03-09 01:21:12 -06004517
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304518 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4519 sas_iounit_pg0, sz)) != 0)
4520 goto out;
4521 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4522 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4523 goto out;
4524 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304525 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304526 if (i == 0)
4527 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4528 PhyData[0].ControllerDevHandle);
4529 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4530 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4531 AttachedDevHandle);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304532 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4533 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304534 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304535 attached_handle, i, link_rate);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304536 }
Eric Moore635374e2009-03-09 01:21:12 -06004537 out:
4538 kfree(sas_iounit_pg0);
4539}
4540
4541/**
4542 * _scsih_sas_host_add - create sas host object
4543 * @ioc: per adapter object
4544 *
4545 * Creating host side data object, stored in ioc->sas_hba
4546 *
4547 * Return nothing.
4548 */
4549static void
4550_scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4551{
4552 int i;
4553 Mpi2ConfigReply_t mpi_reply;
4554 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4555 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4556 Mpi2SasPhyPage0_t phy_pg0;
4557 Mpi2SasDevicePage0_t sas_device_pg0;
4558 Mpi2SasEnclosurePage0_t enclosure_pg0;
4559 u16 ioc_status;
4560 u16 sz;
4561 u16 device_missing_delay;
4562
4563 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4564 if (!ioc->sas_hba.num_phys) {
4565 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4566 ioc->name, __FILE__, __LINE__, __func__);
4567 return;
4568 }
4569
4570 /* sas_iounit page 0 */
4571 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4572 sizeof(Mpi2SasIOUnit0PhyData_t));
4573 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4574 if (!sas_iounit_pg0) {
4575 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4576 ioc->name, __FILE__, __LINE__, __func__);
4577 return;
4578 }
4579 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4580 sas_iounit_pg0, sz))) {
4581 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4582 ioc->name, __FILE__, __LINE__, __func__);
4583 goto out;
4584 }
4585 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4586 MPI2_IOCSTATUS_MASK;
4587 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4588 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4589 ioc->name, __FILE__, __LINE__, __func__);
4590 goto out;
4591 }
4592
4593 /* sas_iounit page 1 */
4594 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4595 sizeof(Mpi2SasIOUnit1PhyData_t));
4596 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4597 if (!sas_iounit_pg1) {
4598 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4599 ioc->name, __FILE__, __LINE__, __func__);
4600 goto out;
4601 }
4602 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4603 sas_iounit_pg1, sz))) {
4604 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4605 ioc->name, __FILE__, __LINE__, __func__);
4606 goto out;
4607 }
4608 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4609 MPI2_IOCSTATUS_MASK;
4610 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4611 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4612 ioc->name, __FILE__, __LINE__, __func__);
4613 goto out;
4614 }
4615
4616 ioc->io_missing_delay =
4617 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4618 device_missing_delay =
4619 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4620 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4621 ioc->device_missing_delay = (device_missing_delay &
4622 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4623 else
4624 ioc->device_missing_delay = device_missing_delay &
4625 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4626
4627 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4628 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4629 sizeof(struct _sas_phy), GFP_KERNEL);
4630 if (!ioc->sas_hba.phy) {
4631 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4632 ioc->name, __FILE__, __LINE__, __func__);
4633 goto out;
4634 }
4635 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4636 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4637 i))) {
4638 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4639 ioc->name, __FILE__, __LINE__, __func__);
4640 goto out;
4641 }
4642 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4643 MPI2_IOCSTATUS_MASK;
4644 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4645 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4646 ioc->name, __FILE__, __LINE__, __func__);
4647 goto out;
4648 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304649
4650 if (i == 0)
4651 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4652 PhyData[0].ControllerDevHandle);
4653 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
Eric Moore635374e2009-03-09 01:21:12 -06004654 ioc->sas_hba.phy[i].phy_id = i;
4655 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4656 phy_pg0, ioc->sas_hba.parent_dev);
4657 }
4658 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304659 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06004660 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4661 ioc->name, __FILE__, __LINE__, __func__);
4662 goto out;
4663 }
Eric Moore635374e2009-03-09 01:21:12 -06004664 ioc->sas_hba.enclosure_handle =
4665 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4666 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4667 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4668 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4669 (unsigned long long) ioc->sas_hba.sas_address,
4670 ioc->sas_hba.num_phys) ;
4671
4672 if (ioc->sas_hba.enclosure_handle) {
4673 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4674 &enclosure_pg0,
4675 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4676 ioc->sas_hba.enclosure_handle))) {
4677 ioc->sas_hba.enclosure_logical_id =
4678 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4679 }
4680 }
4681
4682 out:
4683 kfree(sas_iounit_pg1);
4684 kfree(sas_iounit_pg0);
4685}
4686
4687/**
4688 * _scsih_expander_add - creating expander object
4689 * @ioc: per adapter object
4690 * @handle: expander handle
4691 *
4692 * Creating expander object, stored in ioc->sas_expander_list.
4693 *
4694 * Return 0 for success, else error.
4695 */
4696static int
4697_scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4698{
4699 struct _sas_node *sas_expander;
4700 Mpi2ConfigReply_t mpi_reply;
4701 Mpi2ExpanderPage0_t expander_pg0;
4702 Mpi2ExpanderPage1_t expander_pg1;
4703 Mpi2SasEnclosurePage0_t enclosure_pg0;
4704 u32 ioc_status;
4705 u16 parent_handle;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05304706 u64 sas_address, sas_address_parent = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004707 int i;
4708 unsigned long flags;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304709 struct _sas_port *mpt2sas_port = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06004710 int rc = 0;
4711
4712 if (!handle)
4713 return -1;
4714
Eric Moore3cb54692010-07-08 14:44:34 -06004715 if (ioc->shost_recovery || ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304716 return -1;
4717
Eric Moore635374e2009-03-09 01:21:12 -06004718 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4719 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4720 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4721 ioc->name, __FILE__, __LINE__, __func__);
4722 return -1;
4723 }
4724
4725 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4726 MPI2_IOCSTATUS_MASK;
4727 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4728 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4729 ioc->name, __FILE__, __LINE__, __func__);
4730 return -1;
4731 }
4732
4733 /* handle out of order topology events */
4734 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304735 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4736 != 0) {
4737 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4738 ioc->name, __FILE__, __LINE__, __func__);
4739 return -1;
4740 }
4741 if (sas_address_parent != ioc->sas_hba.sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06004742 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304743 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4744 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004745 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4746 if (!sas_expander) {
4747 rc = _scsih_expander_add(ioc, parent_handle);
4748 if (rc != 0)
4749 return rc;
4750 }
4751 }
4752
Eric Moore635374e2009-03-09 01:21:12 -06004753 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304754 sas_address = le64_to_cpu(expander_pg0.SASAddress);
Eric Moore635374e2009-03-09 01:21:12 -06004755 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4756 sas_address);
4757 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4758
4759 if (sas_expander)
4760 return 0;
4761
4762 sas_expander = kzalloc(sizeof(struct _sas_node),
4763 GFP_KERNEL);
4764 if (!sas_expander) {
4765 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4766 ioc->name, __FILE__, __LINE__, __func__);
4767 return -1;
4768 }
4769
4770 sas_expander->handle = handle;
4771 sas_expander->num_phys = expander_pg0.NumPhys;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304772 sas_expander->sas_address_parent = sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06004773 sas_expander->sas_address = sas_address;
4774
4775 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4776 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304777 handle, parent_handle, (unsigned long long)
Eric Moore635374e2009-03-09 01:21:12 -06004778 sas_expander->sas_address, sas_expander->num_phys);
4779
4780 if (!sas_expander->num_phys)
4781 goto out_fail;
4782 sas_expander->phy = kcalloc(sas_expander->num_phys,
4783 sizeof(struct _sas_phy), GFP_KERNEL);
4784 if (!sas_expander->phy) {
4785 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4786 ioc->name, __FILE__, __LINE__, __func__);
4787 rc = -1;
4788 goto out_fail;
4789 }
4790
4791 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4792 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304793 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004794 if (!mpt2sas_port) {
4795 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4796 ioc->name, __FILE__, __LINE__, __func__);
4797 rc = -1;
4798 goto out_fail;
4799 }
4800 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4801
4802 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4803 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4804 &expander_pg1, i, handle))) {
4805 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4806 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai20f58952009-08-07 19:34:26 +05304807 rc = -1;
4808 goto out_fail;
Eric Moore635374e2009-03-09 01:21:12 -06004809 }
4810 sas_expander->phy[i].handle = handle;
4811 sas_expander->phy[i].phy_id = i;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304812
4813 if ((mpt2sas_transport_add_expander_phy(ioc,
4814 &sas_expander->phy[i], expander_pg1,
4815 sas_expander->parent_dev))) {
4816 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4817 ioc->name, __FILE__, __LINE__, __func__);
4818 rc = -1;
4819 goto out_fail;
4820 }
Eric Moore635374e2009-03-09 01:21:12 -06004821 }
4822
4823 if (sas_expander->enclosure_handle) {
4824 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4825 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4826 sas_expander->enclosure_handle))) {
4827 sas_expander->enclosure_logical_id =
4828 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4829 }
4830 }
4831
4832 _scsih_expander_node_add(ioc, sas_expander);
4833 return 0;
4834
4835 out_fail:
4836
Kashyap, Desai20f58952009-08-07 19:34:26 +05304837 if (mpt2sas_port)
4838 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304839 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004840 kfree(sas_expander);
4841 return rc;
4842}
4843
4844/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05304845 * _scsih_done - scsih callback handler.
4846 * @ioc: per adapter object
4847 * @smid: system request message index
4848 * @msix_index: MSIX table index supplied by the OS
4849 * @reply: reply message frame(lower 32bit addr)
4850 *
4851 * Callback handler when sending internal generated message frames.
4852 * The callback index passed is `ioc->scsih_cb_idx`
4853 *
4854 * Return 1 meaning mf should be freed from _base_interrupt
4855 * 0 means the mf is freed from this function.
4856 */
4857static u8
4858_scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4859{
4860 MPI2DefaultReply_t *mpi_reply;
4861
4862 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4863 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
4864 return 1;
4865 if (ioc->scsih_cmds.smid != smid)
4866 return 1;
4867 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
4868 if (mpi_reply) {
4869 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4870 mpi_reply->MsgLength*4);
4871 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
4872 }
4873 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
4874 complete(&ioc->scsih_cmds.done);
4875 return 1;
4876}
4877
4878/**
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304879 * mpt2sas_expander_remove - removing expander object
Eric Moore635374e2009-03-09 01:21:12 -06004880 * @ioc: per adapter object
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304881 * @sas_address: expander sas_address
Eric Moore635374e2009-03-09 01:21:12 -06004882 *
4883 * Return nothing.
4884 */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304885void
4886mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06004887{
4888 struct _sas_node *sas_expander;
4889 unsigned long flags;
4890
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304891 if (ioc->shost_recovery)
4892 return;
4893
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);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304897 if (!sas_expander) {
4898 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4899 return;
4900 }
4901 list_del(&sas_expander->list);
Eric Moore635374e2009-03-09 01:21:12 -06004902 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4903 _scsih_expander_node_remove(ioc, sas_expander);
4904}
4905
4906/**
Kashyap, Desaib4344272010-03-17 16:24:14 +05304907 * _scsih_check_access_status - check access flags
4908 * @ioc: per adapter object
4909 * @sas_address: sas address
4910 * @handle: sas device handle
4911 * @access_flags: errors returned during discovery of the device
4912 *
4913 * Return 0 for success, else failure
4914 */
4915static u8
4916_scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
4917 u16 handle, u8 access_status)
4918{
4919 u8 rc = 1;
4920 char *desc = NULL;
4921
4922 switch (access_status) {
4923 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4924 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4925 rc = 0;
4926 break;
4927 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4928 desc = "sata capability failed";
4929 break;
4930 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4931 desc = "sata affiliation conflict";
4932 break;
4933 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4934 desc = "route not addressable";
4935 break;
4936 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4937 desc = "smp error not addressable";
4938 break;
4939 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4940 desc = "device blocked";
4941 break;
4942 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4943 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4944 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4945 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4946 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4947 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4948 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4949 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4950 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4951 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4952 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4953 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4954 desc = "sata initialization failed";
4955 break;
4956 default:
4957 desc = "unknown";
4958 break;
4959 }
4960
4961 if (!rc)
4962 return 0;
4963
4964 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
4965 "handle(0x%04x)\n", ioc->name, desc,
4966 (unsigned long long)sas_address, handle);
4967 return rc;
4968}
4969
4970static void
4971_scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4972{
4973 Mpi2ConfigReply_t mpi_reply;
4974 Mpi2SasDevicePage0_t sas_device_pg0;
4975 struct _sas_device *sas_device;
4976 u32 ioc_status;
4977 unsigned long flags;
4978 u64 sas_address;
4979 struct scsi_target *starget;
4980 struct MPT2SAS_TARGET *sas_target_priv_data;
4981 u32 device_info;
4982
4983 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4984 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
4985 return;
4986
4987 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4988 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4989 return;
4990
4991 /* check if this is end device */
4992 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
4993 if (!(_scsih_is_end_device(device_info)))
4994 return;
4995
4996 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4997 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4998 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4999 sas_address);
5000
5001 if (!sas_device) {
5002 printk(MPT2SAS_ERR_FMT "device is not present "
5003 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5004 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5005 return;
5006 }
5007
5008 if (unlikely(sas_device->handle != handle)) {
5009 starget = sas_device->starget;
5010 sas_target_priv_data = starget->hostdata;
5011 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5012 " to (0x%04x)!!!\n", sas_device->handle, handle);
5013 sas_target_priv_data->handle = handle;
5014 sas_device->handle = handle;
5015 }
5016 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5017
5018 /* check if device is present */
5019 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5020 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5021 printk(MPT2SAS_ERR_FMT "device is not present "
5022 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5023 return;
5024 }
5025
5026 /* check if there were any issues with discovery */
5027 if (_scsih_check_access_status(ioc, sas_address, handle,
5028 sas_device_pg0.AccessStatus))
5029 return;
5030 _scsih_ublock_io_device(ioc, handle);
5031
5032}
5033
5034/**
Eric Moore635374e2009-03-09 01:21:12 -06005035 * _scsih_add_device - creating sas device object
5036 * @ioc: per adapter object
5037 * @handle: sas device handle
5038 * @phy_num: phy number end device attached to
5039 * @is_pd: is this hidden raid component
5040 *
5041 * Creating end device object, stored in ioc->sas_device_list.
5042 *
5043 * Returns 0 for success, non-zero for failure.
5044 */
5045static int
5046_scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5047{
5048 Mpi2ConfigReply_t mpi_reply;
5049 Mpi2SasDevicePage0_t sas_device_pg0;
5050 Mpi2SasEnclosurePage0_t enclosure_pg0;
5051 struct _sas_device *sas_device;
5052 u32 ioc_status;
5053 __le64 sas_address;
5054 u32 device_info;
5055 unsigned long flags;
5056
5057 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5058 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5059 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5060 ioc->name, __FILE__, __LINE__, __func__);
5061 return -1;
5062 }
5063
5064 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5065 MPI2_IOCSTATUS_MASK;
5066 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5067 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5068 ioc->name, __FILE__, __LINE__, __func__);
5069 return -1;
5070 }
5071
Kashyap, Desaib4344272010-03-17 16:24:14 +05305072 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5073
Eric Moore635374e2009-03-09 01:21:12 -06005074 /* check if device is present */
5075 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5076 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5077 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5078 ioc->name, __FILE__, __LINE__, __func__);
5079 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5080 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5081 return -1;
5082 }
5083
Kashyap, Desaib4344272010-03-17 16:24:14 +05305084 /* check if there were any issues with discovery */
5085 if (_scsih_check_access_status(ioc, sas_address, handle,
5086 sas_device_pg0.AccessStatus))
Eric Moore635374e2009-03-09 01:21:12 -06005087 return -1;
Eric Moore635374e2009-03-09 01:21:12 -06005088
5089 /* check if this is end device */
5090 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5091 if (!(_scsih_is_end_device(device_info))) {
5092 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5093 ioc->name, __FILE__, __LINE__, __func__);
5094 return -1;
5095 }
5096
Eric Moore635374e2009-03-09 01:21:12 -06005097
5098 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5099 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5100 sas_address);
5101 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5102
Kashyap, Desaib4344272010-03-17 16:24:14 +05305103 if (sas_device)
Eric Moore635374e2009-03-09 01:21:12 -06005104 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06005105
5106 sas_device = kzalloc(sizeof(struct _sas_device),
5107 GFP_KERNEL);
5108 if (!sas_device) {
5109 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5110 ioc->name, __FILE__, __LINE__, __func__);
5111 return -1;
5112 }
5113
5114 sas_device->handle = handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305115 if (_scsih_get_sas_address(ioc, le16_to_cpu
5116 (sas_device_pg0.ParentDevHandle),
5117 &sas_device->sas_address_parent) != 0)
5118 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5119 ioc->name, __FILE__, __LINE__, __func__);
Eric Moore635374e2009-03-09 01:21:12 -06005120 sas_device->enclosure_handle =
5121 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5122 sas_device->slot =
5123 le16_to_cpu(sas_device_pg0.Slot);
5124 sas_device->device_info = device_info;
5125 sas_device->sas_address = sas_address;
Kashyap, Desai7fbae672010-06-17 13:45:17 +05305126 sas_device->phy = sas_device_pg0.PhyNum;
Eric Moore635374e2009-03-09 01:21:12 -06005127
5128 /* get enclosure_logical_id */
Kashyap, Desai15052c92009-08-07 19:33:17 +05305129 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5130 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5131 sas_device->enclosure_handle)))
Eric Moore635374e2009-03-09 01:21:12 -06005132 sas_device->enclosure_logical_id =
5133 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
Eric Moore635374e2009-03-09 01:21:12 -06005134
5135 /* get device name */
5136 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5137
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305138 if (ioc->wait_for_discovery_to_complete)
Eric Moore635374e2009-03-09 01:21:12 -06005139 _scsih_sas_device_init_add(ioc, sas_device);
5140 else
5141 _scsih_sas_device_add(ioc, sas_device);
5142
5143 return 0;
5144}
5145
5146/**
Kashyap, Desai1278b112010-03-09 17:34:13 +05305147 * _scsih_remove_device - removing sas device object
5148 * @ioc: per adapter object
5149 * @sas_device_delete: the sas_device object
5150 *
5151 * Return nothing.
5152 */
5153static void
5154_scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5155 struct _sas_device *sas_device)
5156{
5157 struct _sas_device sas_device_backup;
5158 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05305159
Kashyap, Desai1278b112010-03-09 17:34:13 +05305160 if (!sas_device)
5161 return;
Eric Moore635374e2009-03-09 01:21:12 -06005162
Kashyap, Desai1278b112010-03-09 17:34:13 +05305163 memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device));
Eric Moore635374e2009-03-09 01:21:12 -06005164 _scsih_sas_device_remove(ioc, sas_device);
5165
Kashyap, Desai1278b112010-03-09 17:34:13 +05305166 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5167 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5168 sas_device_backup.handle, (unsigned long long)
5169 sas_device_backup.sas_address));
5170
5171 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
5172 sas_target_priv_data = sas_device_backup.starget->hostdata;
5173 sas_target_priv_data->deleted = 1;
5174 }
5175
Kashyap, Desai1278b112010-03-09 17:34:13 +05305176 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5177
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05305178 if (!ioc->hide_drives)
5179 mpt2sas_transport_port_remove(ioc,
5180 sas_device_backup.sas_address,
5181 sas_device_backup.sas_address_parent);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305182
5183 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5184 "(0x%016llx)\n", ioc->name, sas_device_backup.handle,
5185 (unsigned long long) sas_device_backup.sas_address);
5186
5187 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5188 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5189 sas_device_backup.handle, (unsigned long long)
5190 sas_device_backup.sas_address));
Eric Moore635374e2009-03-09 01:21:12 -06005191}
5192
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305193/**
5194 * mpt2sas_device_remove - removing device object
5195 * @ioc: per adapter object
5196 * @sas_address: expander sas_address
5197 *
5198 * Return nothing.
5199 */
5200void
5201mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5202{
5203 struct _sas_device *sas_device;
5204 unsigned long flags;
5205
5206 if (ioc->shost_recovery)
5207 return;
5208
5209 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5210 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5211 sas_address);
5212 if (!sas_device) {
5213 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5214 return;
5215 }
5216 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5217 _scsih_remove_device(ioc, sas_device);
5218}
5219
Eric Moore635374e2009-03-09 01:21:12 -06005220#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5221/**
5222 * _scsih_sas_topology_change_event_debug - debug for topology event
5223 * @ioc: per adapter object
5224 * @event_data: event data payload
5225 * Context: user.
5226 */
5227static void
5228_scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5229 Mpi2EventDataSasTopologyChangeList_t *event_data)
5230{
5231 int i;
5232 u16 handle;
5233 u16 reason_code;
5234 u8 phy_number;
5235 char *status_str = NULL;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305236 u8 link_rate, prev_link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06005237
5238 switch (event_data->ExpStatus) {
5239 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5240 status_str = "add";
5241 break;
5242 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5243 status_str = "remove";
5244 break;
5245 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305246 case 0:
Eric Moore635374e2009-03-09 01:21:12 -06005247 status_str = "responding";
5248 break;
5249 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5250 status_str = "remove delay";
5251 break;
5252 default:
5253 status_str = "unknown status";
5254 break;
5255 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305256 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
Eric Moore635374e2009-03-09 01:21:12 -06005257 ioc->name, status_str);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305258 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
Eric Moore635374e2009-03-09 01:21:12 -06005259 "start_phy(%02d), count(%d)\n",
5260 le16_to_cpu(event_data->ExpanderDevHandle),
5261 le16_to_cpu(event_data->EnclosureHandle),
5262 event_data->StartPhyNum, event_data->NumEntries);
5263 for (i = 0; i < event_data->NumEntries; i++) {
5264 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5265 if (!handle)
5266 continue;
5267 phy_number = event_data->StartPhyNum + i;
5268 reason_code = event_data->PHY[i].PhyStatus &
5269 MPI2_EVENT_SAS_TOPO_RC_MASK;
5270 switch (reason_code) {
5271 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305272 status_str = "target add";
Eric Moore635374e2009-03-09 01:21:12 -06005273 break;
5274 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305275 status_str = "target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005276 break;
5277 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305278 status_str = "delay target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005279 break;
5280 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305281 status_str = "link rate change";
Eric Moore635374e2009-03-09 01:21:12 -06005282 break;
5283 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305284 status_str = "target responding";
Eric Moore635374e2009-03-09 01:21:12 -06005285 break;
5286 default:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305287 status_str = "unknown";
Eric Moore635374e2009-03-09 01:21:12 -06005288 break;
5289 }
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305290 link_rate = event_data->PHY[i].LinkRate >> 4;
5291 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305292 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305293 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5294 handle, status_str, link_rate, prev_link_rate);
5295
Eric Moore635374e2009-03-09 01:21:12 -06005296 }
5297}
5298#endif
5299
5300/**
5301 * _scsih_sas_topology_change_event - handle topology changes
5302 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305303 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005304 * Context: user.
5305 *
5306 */
5307static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305308_scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
Eric Moore635374e2009-03-09 01:21:12 -06005309 struct fw_event_work *fw_event)
5310{
5311 int i;
5312 u16 parent_handle, handle;
5313 u16 reason_code;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305314 u8 phy_number, max_phys;
Eric Moore635374e2009-03-09 01:21:12 -06005315 struct _sas_node *sas_expander;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305316 struct _sas_device *sas_device;
5317 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06005318 unsigned long flags;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305319 u8 link_rate, prev_link_rate;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305320 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06005321
5322#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5323 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5324 _scsih_sas_topology_change_event_debug(ioc, event_data);
5325#endif
5326
Eric Moore3cb54692010-07-08 14:44:34 -06005327 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305328 return;
5329
Eric Moore635374e2009-03-09 01:21:12 -06005330 if (!ioc->sas_hba.num_phys)
5331 _scsih_sas_host_add(ioc);
5332 else
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305333 _scsih_sas_host_refresh(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005334
5335 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305336 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
Eric Moore635374e2009-03-09 01:21:12 -06005337 "event\n", ioc->name));
5338 return;
5339 }
5340
5341 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5342
5343 /* handle expander add */
5344 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5345 if (_scsih_expander_add(ioc, parent_handle) != 0)
5346 return;
5347
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305348 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5349 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5350 parent_handle);
5351 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305352 if (sas_expander) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305353 sas_address = sas_expander->sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305354 max_phys = sas_expander->num_phys;
5355 } else if (parent_handle < ioc->sas_hba.num_phys) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305356 sas_address = ioc->sas_hba.sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305357 max_phys = ioc->sas_hba.num_phys;
5358 } else
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305359 return;
5360
Eric Moore635374e2009-03-09 01:21:12 -06005361 /* handle siblings events */
5362 for (i = 0; i < event_data->NumEntries; i++) {
5363 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305364 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
Eric Moore635374e2009-03-09 01:21:12 -06005365 "expander event\n", ioc->name));
5366 return;
5367 }
Eric Moore3cb54692010-07-08 14:44:34 -06005368 if (ioc->shost_recovery || ioc->remove_host ||
5369 ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305370 return;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305371 phy_number = event_data->StartPhyNum + i;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305372 if (phy_number >= max_phys)
5373 continue;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305374 reason_code = event_data->PHY[i].PhyStatus &
5375 MPI2_EVENT_SAS_TOPO_RC_MASK;
5376 if ((event_data->PHY[i].PhyStatus &
5377 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5378 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
Eric Moore635374e2009-03-09 01:21:12 -06005379 continue;
5380 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5381 if (!handle)
5382 continue;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305383 link_rate = event_data->PHY[i].LinkRate >> 4;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305384 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Eric Moore635374e2009-03-09 01:21:12 -06005385 switch (reason_code) {
5386 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305387
5388 if (link_rate == prev_link_rate)
5389 break;
5390
5391 mpt2sas_transport_update_links(ioc, sas_address,
5392 handle, phy_number, link_rate);
5393
Kashyap, Desaib4344272010-03-17 16:24:14 +05305394 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5395 break;
5396
5397 _scsih_check_device(ioc, handle);
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305398 break;
Eric Moore635374e2009-03-09 01:21:12 -06005399 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305400
5401 mpt2sas_transport_update_links(ioc, sas_address,
5402 handle, phy_number, link_rate);
5403
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305404 _scsih_add_device(ioc, handle, phy_number, 0);
Eric Moore635374e2009-03-09 01:21:12 -06005405 break;
5406 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305407
5408 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5409 sas_device = _scsih_sas_device_find_by_handle(ioc,
5410 handle);
5411 if (!sas_device) {
5412 spin_unlock_irqrestore(&ioc->sas_device_lock,
5413 flags);
5414 break;
5415 }
5416 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5417 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06005418 break;
5419 }
5420 }
5421
5422 /* handle expander removal */
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305423 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5424 sas_expander)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305425 mpt2sas_expander_remove(ioc, sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06005426
5427}
5428
5429#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5430/**
5431 * _scsih_sas_device_status_change_event_debug - debug for device event
5432 * @event_data: event data payload
5433 * Context: user.
5434 *
5435 * Return nothing.
5436 */
5437static void
5438_scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5439 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5440{
5441 char *reason_str = NULL;
5442
5443 switch (event_data->ReasonCode) {
5444 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5445 reason_str = "smart data";
5446 break;
5447 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5448 reason_str = "unsupported device discovered";
5449 break;
5450 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5451 reason_str = "internal device reset";
5452 break;
5453 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5454 reason_str = "internal task abort";
5455 break;
5456 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5457 reason_str = "internal task abort set";
5458 break;
5459 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5460 reason_str = "internal clear task set";
5461 break;
5462 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5463 reason_str = "internal query task";
5464 break;
5465 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5466 reason_str = "sata init failure";
5467 break;
5468 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5469 reason_str = "internal device reset complete";
5470 break;
5471 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5472 reason_str = "internal task abort complete";
5473 break;
5474 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5475 reason_str = "internal async notification";
5476 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05305477 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5478 reason_str = "expander reduced functionality";
5479 break;
5480 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5481 reason_str = "expander reduced functionality complete";
5482 break;
Eric Moore635374e2009-03-09 01:21:12 -06005483 default:
5484 reason_str = "unknown reason";
5485 break;
5486 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305487 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305488 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5489 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5490 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5491 le16_to_cpu(event_data->TaskTag));
Eric Moore635374e2009-03-09 01:21:12 -06005492 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305493 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005494 event_data->ASC, event_data->ASCQ);
5495 printk(KERN_INFO "\n");
5496}
5497#endif
5498
5499/**
5500 * _scsih_sas_device_status_change_event - handle device status change
5501 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305502 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005503 * Context: user.
5504 *
5505 * Return nothing.
5506 */
5507static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305508_scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5509 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005510{
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305511 struct MPT2SAS_TARGET *target_priv_data;
5512 struct _sas_device *sas_device;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05305513 u64 sas_address;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305514 unsigned long flags;
5515 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5516 fw_event->event_data;
5517
Eric Moore635374e2009-03-09 01:21:12 -06005518#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5519 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305520 _scsih_sas_device_status_change_event_debug(ioc,
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305521 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005522#endif
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305523
Kashyap, Desaiefe82a12011-01-04 11:34:17 +05305524 /* In MPI Revision K (0xC), the internal device reset complete was
5525 * implemented, so avoid setting tm_busy flag for older firmware.
5526 */
5527 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5528 return;
5529
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305530 if (event_data->ReasonCode !=
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305531 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305532 event_data->ReasonCode !=
5533 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305534 return;
5535
5536 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5537 sas_address = le64_to_cpu(event_data->SASAddress);
5538 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5539 sas_address);
5540 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5541
5542 if (!sas_device || !sas_device->starget)
5543 return;
5544
5545 target_priv_data = sas_device->starget->hostdata;
5546 if (!target_priv_data)
5547 return;
5548
5549 if (event_data->ReasonCode ==
5550 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5551 target_priv_data->tm_busy = 1;
5552 else
5553 target_priv_data->tm_busy = 0;
Eric Moore635374e2009-03-09 01:21:12 -06005554}
5555
5556#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5557/**
5558 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5559 * @ioc: per adapter object
5560 * @event_data: event data payload
5561 * Context: user.
5562 *
5563 * Return nothing.
5564 */
5565static void
5566_scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5567 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5568{
5569 char *reason_str = NULL;
5570
5571 switch (event_data->ReasonCode) {
5572 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5573 reason_str = "enclosure add";
5574 break;
5575 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5576 reason_str = "enclosure remove";
5577 break;
5578 default:
5579 reason_str = "unknown reason";
5580 break;
5581 }
5582
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305583 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
Eric Moore635374e2009-03-09 01:21:12 -06005584 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5585 " number slots(%d)\n", ioc->name, reason_str,
5586 le16_to_cpu(event_data->EnclosureHandle),
5587 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5588 le16_to_cpu(event_data->StartSlot));
5589}
5590#endif
5591
5592/**
5593 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5594 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305595 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005596 * Context: user.
5597 *
5598 * Return nothing.
5599 */
5600static void
5601_scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305602 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005603{
5604#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5605 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5606 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305607 fw_event->event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005608#endif
5609}
5610
5611/**
5612 * _scsih_sas_broadcast_primative_event - handle broadcast events
5613 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305614 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005615 * Context: user.
5616 *
5617 * Return nothing.
5618 */
5619static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305620_scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
5621 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005622{
5623 struct scsi_cmnd *scmd;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305624 struct scsi_device *sdev;
Eric Moore635374e2009-03-09 01:21:12 -06005625 u16 smid, handle;
5626 u32 lun;
5627 struct MPT2SAS_DEVICE *sas_device_priv_data;
5628 u32 termination_count;
5629 u32 query_count;
5630 Mpi2SCSITaskManagementReply_t *mpi_reply;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305631 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
Kashyap, Desai463217b2009-10-05 15:53:06 +05305632 u16 ioc_status;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305633 unsigned long flags;
5634 int r;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305635 u8 max_retries = 0;
5636 u8 task_abort_retries;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305637
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305638 mutex_lock(&ioc->tm_cmds.mutex);
5639 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), "
5640 "width(%d)\n", ioc->name, __func__, event_data->PhyNum,
5641 event_data->PortWidth));
5642
5643 _scsih_block_io_all_device(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005644
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305645 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305646 mpi_reply = ioc->tm_cmds.reply;
5647broadcast_aen_retry:
5648
5649 /* sanity checks for retrying this loop */
5650 if (max_retries++ == 5) {
5651 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5652 ioc->name, __func__));
5653 goto out;
5654 } else if (max_retries > 1)
5655 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5656 ioc->name, __func__, max_retries - 1));
5657
Eric Moore635374e2009-03-09 01:21:12 -06005658 termination_count = 0;
5659 query_count = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305660 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305661 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305662 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06005663 scmd = _scsih_scsi_lookup_get(ioc, smid);
5664 if (!scmd)
5665 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305666 sdev = scmd->device;
5667 sas_device_priv_data = sdev->hostdata;
Eric Moore635374e2009-03-09 01:21:12 -06005668 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5669 continue;
5670 /* skip hidden raid components */
5671 if (sas_device_priv_data->sas_target->flags &
5672 MPT_TARGET_FLAGS_RAID_COMPONENT)
5673 continue;
5674 /* skip volumes */
5675 if (sas_device_priv_data->sas_target->flags &
5676 MPT_TARGET_FLAGS_VOLUME)
5677 continue;
5678
5679 handle = sas_device_priv_data->sas_target->handle;
5680 lun = sas_device_priv_data->lun;
5681 query_count++;
5682
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305683 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305684 goto out;
5685
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305686 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305687 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5688 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0,
5689 TM_MUTEX_OFF);
5690 if (r == FAILED) {
5691 sdev_printk(KERN_WARNING, sdev,
5692 "mpt2sas_scsih_issue_tm: FAILED when sending "
5693 "QUERY_TASK: scmd(%p)\n", scmd);
5694 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5695 goto broadcast_aen_retry;
5696 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05305697 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5698 & MPI2_IOCSTATUS_MASK;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305699 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5700 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5701 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5702 scmd);
5703 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5704 goto broadcast_aen_retry;
5705 }
5706
5707 /* see if IO is still owned by IOC and target */
5708 if (mpi_reply->ResponseCode ==
Eric Moore635374e2009-03-09 01:21:12 -06005709 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5710 mpi_reply->ResponseCode ==
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305711 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305712 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005713 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305714 }
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305715 task_abort_retries = 0;
5716 tm_retry:
5717 if (task_abort_retries++ == 60) {
5718 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5719 "%s: ABORT_TASK: giving up\n", ioc->name,
5720 __func__));
5721 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5722 goto broadcast_aen_retry;
5723 }
5724
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305725 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305726 goto out_no_lock;
5727
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305728 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5729 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305730 scmd->serial_number, TM_MUTEX_OFF);
5731 if (r == FAILED) {
5732 sdev_printk(KERN_WARNING, sdev,
5733 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305734 "scmd(%p)\n", scmd);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305735 goto tm_retry;
5736 }
5737
5738 if (task_abort_retries > 1)
5739 sdev_printk(KERN_WARNING, sdev,
5740 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5741 " scmd(%p)\n",
5742 task_abort_retries - 1, scmd);
5743
Eric Moore635374e2009-03-09 01:21:12 -06005744 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305745 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005746 }
Eric Moore635374e2009-03-09 01:21:12 -06005747
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305748 if (ioc->broadcast_aen_pending) {
5749 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5750 " pending AEN\n", ioc->name, __func__));
5751 ioc->broadcast_aen_pending = 0;
5752 goto broadcast_aen_retry;
5753 }
5754
5755 out:
5756 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5757 out_no_lock:
5758
5759 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06005760 "%s - exit, query_count = %d termination_count = %d\n",
5761 ioc->name, __func__, query_count, termination_count));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305762
5763 ioc->broadcast_aen_busy = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305764 if (!ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305765 _scsih_ublock_io_all_device(ioc);
5766 mutex_unlock(&ioc->tm_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06005767}
5768
5769/**
5770 * _scsih_sas_discovery_event - handle discovery events
5771 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305772 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005773 * Context: user.
5774 *
5775 * Return nothing.
5776 */
5777static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305778_scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5779 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005780{
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305781 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5782
Eric Moore635374e2009-03-09 01:21:12 -06005783#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5784 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305785 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005786 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5787 "start" : "stop");
5788 if (event_data->DiscoveryStatus)
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305789 printk("discovery_status(0x%08x)",
5790 le32_to_cpu(event_data->DiscoveryStatus));
Eric Moore635374e2009-03-09 01:21:12 -06005791 printk("\n");
5792 }
5793#endif
5794
5795 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5796 !ioc->sas_hba.num_phys)
5797 _scsih_sas_host_add(ioc);
5798}
5799
5800/**
5801 * _scsih_reprobe_lun - reprobing lun
5802 * @sdev: scsi device struct
5803 * @no_uld_attach: sdev->no_uld_attach flag setting
5804 *
5805 **/
5806static void
5807_scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5808{
5809 int rc;
5810
5811 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5812 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5813 sdev->no_uld_attach ? "hidding" : "exposing");
5814 rc = scsi_device_reprobe(sdev);
5815}
5816
5817/**
5818 * _scsih_reprobe_target - reprobing target
5819 * @starget: scsi target struct
5820 * @no_uld_attach: sdev->no_uld_attach flag setting
5821 *
5822 * Note: no_uld_attach flag determines whether the disk device is attached
5823 * to block layer. A value of `1` means to not attach.
5824 **/
5825static void
5826_scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
5827{
5828 struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
5829
5830 if (no_uld_attach)
5831 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
5832 else
5833 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5834
5835 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
5836 _scsih_reprobe_lun);
5837}
5838/**
5839 * _scsih_sas_volume_add - add new volume
5840 * @ioc: per adapter object
5841 * @element: IR config element data
5842 * Context: user.
5843 *
5844 * Return nothing.
5845 */
5846static void
5847_scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
5848 Mpi2EventIrConfigElement_t *element)
5849{
5850 struct _raid_device *raid_device;
5851 unsigned long flags;
5852 u64 wwid;
5853 u16 handle = le16_to_cpu(element->VolDevHandle);
5854 int rc;
5855
Eric Moore635374e2009-03-09 01:21:12 -06005856 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
5857 if (!wwid) {
5858 printk(MPT2SAS_ERR_FMT
5859 "failure at %s:%d/%s()!\n", ioc->name,
5860 __FILE__, __LINE__, __func__);
5861 return;
5862 }
5863
5864 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5865 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5866 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5867
5868 if (raid_device)
5869 return;
5870
5871 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5872 if (!raid_device) {
5873 printk(MPT2SAS_ERR_FMT
5874 "failure at %s:%d/%s()!\n", ioc->name,
5875 __FILE__, __LINE__, __func__);
5876 return;
5877 }
5878
5879 raid_device->id = ioc->sas_id++;
5880 raid_device->channel = RAID_CHANNEL;
5881 raid_device->handle = handle;
5882 raid_device->wwid = wwid;
5883 _scsih_raid_device_add(ioc, raid_device);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305884 if (!ioc->wait_for_discovery_to_complete) {
Eric Moore635374e2009-03-09 01:21:12 -06005885 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5886 raid_device->id, 0);
5887 if (rc)
5888 _scsih_raid_device_remove(ioc, raid_device);
5889 } else
5890 _scsih_determine_boot_device(ioc, raid_device, 1);
5891}
5892
5893/**
5894 * _scsih_sas_volume_delete - delete volume
5895 * @ioc: per adapter object
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05305896 * @handle: volume device handle
Eric Moore635374e2009-03-09 01:21:12 -06005897 * Context: user.
5898 *
5899 * Return nothing.
5900 */
5901static void
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05305902_scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Eric Moore635374e2009-03-09 01:21:12 -06005903{
5904 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06005905 unsigned long flags;
5906 struct MPT2SAS_TARGET *sas_target_priv_data;
5907
Eric Moore635374e2009-03-09 01:21:12 -06005908 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5909 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5910 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5911 if (!raid_device)
5912 return;
5913 if (raid_device->starget) {
5914 sas_target_priv_data = raid_device->starget->hostdata;
5915 sas_target_priv_data->deleted = 1;
5916 scsi_remove_target(&raid_device->starget->dev);
5917 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05305918 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
5919 "(0x%016llx)\n", ioc->name, raid_device->handle,
5920 (unsigned long long) raid_device->wwid);
Eric Moore635374e2009-03-09 01:21:12 -06005921 _scsih_raid_device_remove(ioc, raid_device);
5922}
5923
5924/**
5925 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5926 * @ioc: per adapter object
5927 * @element: IR config element data
5928 * Context: user.
5929 *
5930 * Return nothing.
5931 */
5932static void
5933_scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
5934 Mpi2EventIrConfigElement_t *element)
5935{
5936 struct _sas_device *sas_device;
5937 unsigned long flags;
5938 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5939
5940 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5941 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5942 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5943 if (!sas_device)
5944 return;
5945
5946 /* exposing raid component */
5947 sas_device->volume_handle = 0;
5948 sas_device->volume_wwid = 0;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05305949 clear_bit(handle, ioc->pd_handles);
Eric Moore635374e2009-03-09 01:21:12 -06005950 _scsih_reprobe_target(sas_device->starget, 0);
5951}
5952
5953/**
5954 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5955 * @ioc: per adapter object
5956 * @element: IR config element data
5957 * Context: user.
5958 *
5959 * Return nothing.
5960 */
5961static void
5962_scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
5963 Mpi2EventIrConfigElement_t *element)
5964{
5965 struct _sas_device *sas_device;
5966 unsigned long flags;
5967 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5968
5969 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5970 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5971 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5972 if (!sas_device)
5973 return;
5974
5975 /* hiding raid component */
5976 mpt2sas_config_get_volume_handle(ioc, handle,
5977 &sas_device->volume_handle);
5978 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
5979 &sas_device->volume_wwid);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05305980 set_bit(handle, ioc->pd_handles);
Eric Moore635374e2009-03-09 01:21:12 -06005981 _scsih_reprobe_target(sas_device->starget, 1);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05305982
Eric Moore635374e2009-03-09 01:21:12 -06005983}
5984
5985/**
5986 * _scsih_sas_pd_delete - delete pd component
5987 * @ioc: per adapter object
5988 * @element: IR config element data
5989 * Context: user.
5990 *
5991 * Return nothing.
5992 */
5993static void
5994_scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
5995 Mpi2EventIrConfigElement_t *element)
5996{
5997 struct _sas_device *sas_device;
5998 unsigned long flags;
5999 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6000
6001 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6002 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6003 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6004 if (!sas_device)
6005 return;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306006 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06006007}
6008
6009/**
6010 * _scsih_sas_pd_add - remove pd component
6011 * @ioc: per adapter object
6012 * @element: IR config element data
6013 * Context: user.
6014 *
6015 * Return nothing.
6016 */
6017static void
6018_scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6019 Mpi2EventIrConfigElement_t *element)
6020{
6021 struct _sas_device *sas_device;
6022 unsigned long flags;
6023 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306024 Mpi2ConfigReply_t mpi_reply;
6025 Mpi2SasDevicePage0_t sas_device_pg0;
6026 u32 ioc_status;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306027 u64 sas_address;
6028 u16 parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006029
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306030 set_bit(handle, ioc->pd_handles);
6031
Eric Moore635374e2009-03-09 01:21:12 -06006032 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6033 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6034 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306035 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306036 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306037
6038 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6039 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6040 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6041 ioc->name, __FILE__, __LINE__, __func__);
6042 return;
6043 }
6044
6045 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6046 MPI2_IOCSTATUS_MASK;
6047 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6048 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6049 ioc->name, __FILE__, __LINE__, __func__);
6050 return;
6051 }
6052
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306053 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6054 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6055 mpt2sas_transport_update_links(ioc, sas_address, handle,
6056 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306057
6058 _scsih_add_device(ioc, handle, 0, 1);
Eric Moore635374e2009-03-09 01:21:12 -06006059}
6060
6061#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6062/**
6063 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6064 * @ioc: per adapter object
6065 * @event_data: event data payload
6066 * Context: user.
6067 *
6068 * Return nothing.
6069 */
6070static void
6071_scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6072 Mpi2EventDataIrConfigChangeList_t *event_data)
6073{
6074 Mpi2EventIrConfigElement_t *element;
6075 u8 element_type;
6076 int i;
6077 char *reason_str = NULL, *element_str = NULL;
6078
6079 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6080
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306081 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06006082 ioc->name, (le32_to_cpu(event_data->Flags) &
6083 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6084 "foreign" : "native", event_data->NumElements);
6085 for (i = 0; i < event_data->NumElements; i++, element++) {
6086 switch (element->ReasonCode) {
6087 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6088 reason_str = "add";
6089 break;
6090 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6091 reason_str = "remove";
6092 break;
6093 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6094 reason_str = "no change";
6095 break;
6096 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6097 reason_str = "hide";
6098 break;
6099 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6100 reason_str = "unhide";
6101 break;
6102 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6103 reason_str = "volume_created";
6104 break;
6105 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6106 reason_str = "volume_deleted";
6107 break;
6108 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6109 reason_str = "pd_created";
6110 break;
6111 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6112 reason_str = "pd_deleted";
6113 break;
6114 default:
6115 reason_str = "unknown reason";
6116 break;
6117 }
6118 element_type = le16_to_cpu(element->ElementFlags) &
6119 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6120 switch (element_type) {
6121 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6122 element_str = "volume";
6123 break;
6124 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6125 element_str = "phys disk";
6126 break;
6127 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6128 element_str = "hot spare";
6129 break;
6130 default:
6131 element_str = "unknown element";
6132 break;
6133 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306134 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
Eric Moore635374e2009-03-09 01:21:12 -06006135 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6136 reason_str, le16_to_cpu(element->VolDevHandle),
6137 le16_to_cpu(element->PhysDiskDevHandle),
6138 element->PhysDiskNum);
6139 }
6140}
6141#endif
6142
6143/**
6144 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6145 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306146 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006147 * Context: user.
6148 *
6149 * Return nothing.
6150 */
6151static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306152_scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6153 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006154{
6155 Mpi2EventIrConfigElement_t *element;
6156 int i;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306157 u8 foreign_config;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306158 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006159
6160#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306161 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6162 && !ioc->hide_ir_msg)
Eric Moore635374e2009-03-09 01:21:12 -06006163 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6164
6165#endif
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306166
6167 if (ioc->shost_recovery)
6168 return;
6169
Kashyap, Desai62727a72009-08-07 19:35:18 +05306170 foreign_config = (le32_to_cpu(event_data->Flags) &
6171 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
Eric Moore635374e2009-03-09 01:21:12 -06006172
6173 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6174 for (i = 0; i < event_data->NumElements; i++, element++) {
6175
6176 switch (element->ReasonCode) {
6177 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6178 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306179 if (!foreign_config)
6180 _scsih_sas_volume_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006181 break;
6182 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6183 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306184 if (!foreign_config)
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306185 _scsih_sas_volume_delete(ioc,
6186 le16_to_cpu(element->VolDevHandle));
Eric Moore635374e2009-03-09 01:21:12 -06006187 break;
6188 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306189 if (!ioc->is_warpdrive)
6190 _scsih_sas_pd_hide(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006191 break;
6192 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306193 if (!ioc->is_warpdrive)
6194 _scsih_sas_pd_expose(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006195 break;
6196 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306197 if (!ioc->is_warpdrive)
6198 _scsih_sas_pd_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006199 break;
6200 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306201 if (!ioc->is_warpdrive)
6202 _scsih_sas_pd_delete(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006203 break;
6204 }
6205 }
6206}
6207
6208/**
6209 * _scsih_sas_ir_volume_event - IR volume event
6210 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306211 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006212 * Context: user.
6213 *
6214 * Return nothing.
6215 */
6216static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306217_scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6218 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006219{
6220 u64 wwid;
6221 unsigned long flags;
6222 struct _raid_device *raid_device;
6223 u16 handle;
6224 u32 state;
6225 int rc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306226 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006227
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306228 if (ioc->shost_recovery)
6229 return;
6230
Eric Moore635374e2009-03-09 01:21:12 -06006231 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6232 return;
6233
6234 handle = le16_to_cpu(event_data->VolDevHandle);
6235 state = le32_to_cpu(event_data->NewValue);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306236 if (!ioc->hide_ir_msg)
6237 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6238 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6239 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006240
Eric Moore635374e2009-03-09 01:21:12 -06006241 switch (state) {
6242 case MPI2_RAID_VOL_STATE_MISSING:
6243 case MPI2_RAID_VOL_STATE_FAILED:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306244 _scsih_sas_volume_delete(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006245 break;
6246
6247 case MPI2_RAID_VOL_STATE_ONLINE:
6248 case MPI2_RAID_VOL_STATE_DEGRADED:
6249 case MPI2_RAID_VOL_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306250
6251 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6252 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6253 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6254
Eric Moore635374e2009-03-09 01:21:12 -06006255 if (raid_device)
6256 break;
6257
6258 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6259 if (!wwid) {
6260 printk(MPT2SAS_ERR_FMT
6261 "failure at %s:%d/%s()!\n", ioc->name,
6262 __FILE__, __LINE__, __func__);
6263 break;
6264 }
6265
6266 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6267 if (!raid_device) {
6268 printk(MPT2SAS_ERR_FMT
6269 "failure at %s:%d/%s()!\n", ioc->name,
6270 __FILE__, __LINE__, __func__);
6271 break;
6272 }
6273
6274 raid_device->id = ioc->sas_id++;
6275 raid_device->channel = RAID_CHANNEL;
6276 raid_device->handle = handle;
6277 raid_device->wwid = wwid;
6278 _scsih_raid_device_add(ioc, raid_device);
6279 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6280 raid_device->id, 0);
6281 if (rc)
6282 _scsih_raid_device_remove(ioc, raid_device);
6283 break;
6284
6285 case MPI2_RAID_VOL_STATE_INITIALIZING:
6286 default:
6287 break;
6288 }
6289}
6290
6291/**
6292 * _scsih_sas_ir_physical_disk_event - PD event
6293 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306294 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006295 * Context: user.
6296 *
6297 * Return nothing.
6298 */
6299static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306300_scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6301 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006302{
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306303 u16 handle, parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006304 u32 state;
6305 struct _sas_device *sas_device;
6306 unsigned long flags;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306307 Mpi2ConfigReply_t mpi_reply;
6308 Mpi2SasDevicePage0_t sas_device_pg0;
6309 u32 ioc_status;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306310 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306311 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006312
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306313 if (ioc->shost_recovery)
6314 return;
6315
Eric Moore635374e2009-03-09 01:21:12 -06006316 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6317 return;
6318
6319 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6320 state = le32_to_cpu(event_data->NewValue);
6321
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306322 if (!ioc->hide_ir_msg)
6323 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6324 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6325 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006326
Eric Moore635374e2009-03-09 01:21:12 -06006327 switch (state) {
Eric Moore635374e2009-03-09 01:21:12 -06006328 case MPI2_RAID_PD_STATE_ONLINE:
6329 case MPI2_RAID_PD_STATE_DEGRADED:
6330 case MPI2_RAID_PD_STATE_REBUILDING:
6331 case MPI2_RAID_PD_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306332 case MPI2_RAID_PD_STATE_HOT_SPARE:
6333
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306334 if (!ioc->is_warpdrive)
6335 set_bit(handle, ioc->pd_handles);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306336
6337 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6338 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6339 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6340
6341 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306342 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306343
6344 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6345 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6346 handle))) {
6347 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6348 ioc->name, __FILE__, __LINE__, __func__);
6349 return;
6350 }
6351
6352 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6353 MPI2_IOCSTATUS_MASK;
6354 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6355 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6356 ioc->name, __FILE__, __LINE__, __func__);
6357 return;
6358 }
6359
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306360 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6361 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6362 mpt2sas_transport_update_links(ioc, sas_address, handle,
6363 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306364
6365 _scsih_add_device(ioc, handle, 0, 1);
6366
Eric Moore635374e2009-03-09 01:21:12 -06006367 break;
6368
Kashyap, Desai62727a72009-08-07 19:35:18 +05306369 case MPI2_RAID_PD_STATE_OFFLINE:
Eric Moore635374e2009-03-09 01:21:12 -06006370 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6371 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
Eric Moore635374e2009-03-09 01:21:12 -06006372 default:
6373 break;
6374 }
6375}
6376
6377#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6378/**
6379 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6380 * @ioc: per adapter object
6381 * @event_data: event data payload
6382 * Context: user.
6383 *
6384 * Return nothing.
6385 */
6386static void
6387_scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6388 Mpi2EventDataIrOperationStatus_t *event_data)
6389{
6390 char *reason_str = NULL;
6391
6392 switch (event_data->RAIDOperation) {
6393 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6394 reason_str = "resync";
6395 break;
6396 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6397 reason_str = "online capacity expansion";
6398 break;
6399 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6400 reason_str = "consistency check";
6401 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306402 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6403 reason_str = "background init";
6404 break;
6405 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6406 reason_str = "make data consistent";
Eric Moore635374e2009-03-09 01:21:12 -06006407 break;
6408 }
6409
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306410 if (!reason_str)
6411 return;
6412
Eric Moore635374e2009-03-09 01:21:12 -06006413 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6414 "\thandle(0x%04x), percent complete(%d)\n",
6415 ioc->name, reason_str,
6416 le16_to_cpu(event_data->VolDevHandle),
6417 event_data->PercentComplete);
6418}
6419#endif
6420
6421/**
6422 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6423 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306424 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006425 * Context: user.
6426 *
6427 * Return nothing.
6428 */
6429static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306430_scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6431 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006432{
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306433 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6434 static struct _raid_device *raid_device;
6435 unsigned long flags;
6436 u16 handle;
6437
Eric Moore635374e2009-03-09 01:21:12 -06006438#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306439 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6440 && !ioc->hide_ir_msg)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306441 _scsih_sas_ir_operation_status_event_debug(ioc,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306442 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06006443#endif
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306444
6445 /* code added for raid transport support */
6446 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6447
6448 handle = le16_to_cpu(event_data->VolDevHandle);
6449
6450 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6451 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6452 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6453
6454 if (!raid_device)
6455 return;
6456
6457 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC)
6458 raid_device->percent_complete =
6459 event_data->PercentComplete;
6460 }
Eric Moore635374e2009-03-09 01:21:12 -06006461}
6462
6463/**
Kashyap, Desai14695852010-03-30 10:52:44 +05306464 * _scsih_prep_device_scan - initialize parameters prior to device scan
6465 * @ioc: per adapter object
6466 *
6467 * Set the deleted flag prior to device scan. If the device is found during
6468 * the scan, then we clear the deleted flag.
6469 */
6470static void
6471_scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6472{
6473 struct MPT2SAS_DEVICE *sas_device_priv_data;
6474 struct scsi_device *sdev;
6475
6476 shost_for_each_device(sdev, ioc->shost) {
6477 sas_device_priv_data = sdev->hostdata;
6478 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6479 sas_device_priv_data->sas_target->deleted = 1;
6480 }
6481}
6482
6483/**
Eric Moore635374e2009-03-09 01:21:12 -06006484 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6485 * @ioc: per adapter object
6486 * @sas_address: sas address
6487 * @slot: enclosure slot id
6488 * @handle: device handle
6489 *
6490 * After host reset, find out whether devices are still responding.
6491 * Used in _scsi_remove_unresponsive_sas_devices.
6492 *
6493 * Return nothing.
6494 */
6495static void
6496_scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6497 u16 slot, u16 handle)
6498{
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306499 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006500 struct scsi_target *starget;
6501 struct _sas_device *sas_device;
6502 unsigned long flags;
6503
6504 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6505 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6506 if (sas_device->sas_address == sas_address &&
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306507 sas_device->slot == slot) {
Eric Moore635374e2009-03-09 01:21:12 -06006508 sas_device->responding = 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05306509 starget = sas_device->starget;
Kashyap, Desai14695852010-03-30 10:52:44 +05306510 if (starget && starget->hostdata) {
6511 sas_target_priv_data = starget->hostdata;
6512 sas_target_priv_data->tm_busy = 0;
6513 sas_target_priv_data->deleted = 0;
6514 } else
6515 sas_target_priv_data = NULL;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306516 if (starget)
6517 starget_printk(KERN_INFO, starget,
6518 "handle(0x%04x), sas_addr(0x%016llx), "
6519 "enclosure logical id(0x%016llx), "
6520 "slot(%d)\n", handle,
6521 (unsigned long long)sas_device->sas_address,
6522 (unsigned long long)
6523 sas_device->enclosure_logical_id,
6524 sas_device->slot);
Eric Moore635374e2009-03-09 01:21:12 -06006525 if (sas_device->handle == handle)
6526 goto out;
6527 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6528 sas_device->handle);
6529 sas_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306530 if (sas_target_priv_data)
6531 sas_target_priv_data->handle = handle;
Eric Moore635374e2009-03-09 01:21:12 -06006532 goto out;
6533 }
6534 }
6535 out:
6536 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6537}
6538
6539/**
6540 * _scsih_search_responding_sas_devices -
6541 * @ioc: per adapter object
6542 *
6543 * After host reset, find out whether devices are still responding.
6544 * If not remove.
6545 *
6546 * Return nothing.
6547 */
6548static void
6549_scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6550{
6551 Mpi2SasDevicePage0_t sas_device_pg0;
6552 Mpi2ConfigReply_t mpi_reply;
6553 u16 ioc_status;
6554 __le64 sas_address;
6555 u16 handle;
6556 u32 device_info;
6557 u16 slot;
6558
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306559 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006560
6561 if (list_empty(&ioc->sas_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306562 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006563
6564 handle = 0xFFFF;
6565 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6566 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6567 handle))) {
6568 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6569 MPI2_IOCSTATUS_MASK;
6570 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6571 break;
6572 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6573 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6574 if (!(_scsih_is_end_device(device_info)))
6575 continue;
6576 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6577 slot = le16_to_cpu(sas_device_pg0.Slot);
6578 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6579 handle);
6580 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306581out:
6582 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6583 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006584}
6585
6586/**
6587 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6588 * @ioc: per adapter object
6589 * @wwid: world wide identifier for raid volume
6590 * @handle: device handle
6591 *
6592 * After host reset, find out whether devices are still responding.
6593 * Used in _scsi_remove_unresponsive_raid_devices.
6594 *
6595 * Return nothing.
6596 */
6597static void
6598_scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6599 u16 handle)
6600{
6601 struct MPT2SAS_TARGET *sas_target_priv_data;
6602 struct scsi_target *starget;
6603 struct _raid_device *raid_device;
6604 unsigned long flags;
6605
6606 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6607 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6608 if (raid_device->wwid == wwid && raid_device->starget) {
Kashyap, Desai14695852010-03-30 10:52:44 +05306609 starget = raid_device->starget;
6610 if (starget && starget->hostdata) {
6611 sas_target_priv_data = starget->hostdata;
6612 sas_target_priv_data->deleted = 0;
6613 } else
6614 sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006615 raid_device->responding = 1;
6616 starget_printk(KERN_INFO, raid_device->starget,
6617 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6618 (unsigned long long)raid_device->wwid);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306619 /*
6620 * WARPDRIVE: The handles of the PDs might have changed
6621 * across the host reset so re-initialize the
6622 * required data for Direct IO
6623 */
6624 _scsih_init_warpdrive_properties(ioc, raid_device);
Eric Moore635374e2009-03-09 01:21:12 -06006625 if (raid_device->handle == handle)
6626 goto out;
6627 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6628 raid_device->handle);
6629 raid_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306630 if (sas_target_priv_data)
6631 sas_target_priv_data->handle = handle;
Eric Moore635374e2009-03-09 01:21:12 -06006632 goto out;
6633 }
6634 }
6635 out:
6636 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6637}
6638
6639/**
6640 * _scsih_search_responding_raid_devices -
6641 * @ioc: per adapter object
6642 *
6643 * After host reset, find out whether devices are still responding.
6644 * If not remove.
6645 *
6646 * Return nothing.
6647 */
6648static void
6649_scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6650{
6651 Mpi2RaidVolPage1_t volume_pg1;
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306652 Mpi2RaidVolPage0_t volume_pg0;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306653 Mpi2RaidPhysDiskPage0_t pd_pg0;
Eric Moore635374e2009-03-09 01:21:12 -06006654 Mpi2ConfigReply_t mpi_reply;
6655 u16 ioc_status;
6656 u16 handle;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306657 u8 phys_disk_num;
Eric Moore635374e2009-03-09 01:21:12 -06006658
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306659 if (!ioc->ir_firmware)
6660 return;
6661
6662 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6663 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006664
6665 if (list_empty(&ioc->raid_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306666 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006667
6668 handle = 0xFFFF;
6669 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6670 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6671 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6672 MPI2_IOCSTATUS_MASK;
6673 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6674 break;
6675 handle = le16_to_cpu(volume_pg1.DevHandle);
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306676
6677 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6678 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6679 sizeof(Mpi2RaidVolPage0_t)))
6680 continue;
6681
6682 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6683 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6684 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6685 _scsih_mark_responding_raid_device(ioc,
6686 le64_to_cpu(volume_pg1.WWID), handle);
Eric Moore635374e2009-03-09 01:21:12 -06006687 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306688
6689 /* refresh the pd_handles */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306690 if (!ioc->is_warpdrive) {
6691 phys_disk_num = 0xFF;
6692 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6693 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6694 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6695 phys_disk_num))) {
6696 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6697 MPI2_IOCSTATUS_MASK;
6698 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6699 break;
6700 phys_disk_num = pd_pg0.PhysDiskNum;
6701 handle = le16_to_cpu(pd_pg0.DevHandle);
6702 set_bit(handle, ioc->pd_handles);
6703 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306704 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306705out:
6706 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6707 "complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006708}
6709
6710/**
6711 * _scsih_mark_responding_expander - mark a expander as responding
6712 * @ioc: per adapter object
6713 * @sas_address: sas address
6714 * @handle:
6715 *
6716 * After host reset, find out whether devices are still responding.
6717 * Used in _scsi_remove_unresponsive_expanders.
6718 *
6719 * Return nothing.
6720 */
6721static void
6722_scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6723 u16 handle)
6724{
6725 struct _sas_node *sas_expander;
6726 unsigned long flags;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306727 int i;
Eric Moore635374e2009-03-09 01:21:12 -06006728
6729 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6730 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306731 if (sas_expander->sas_address != sas_address)
6732 continue;
6733 sas_expander->responding = 1;
6734 if (sas_expander->handle == handle)
Eric Moore635374e2009-03-09 01:21:12 -06006735 goto out;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306736 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6737 " from(0x%04x) to (0x%04x)!!!\n",
6738 (unsigned long long)sas_expander->sas_address,
6739 sas_expander->handle, handle);
6740 sas_expander->handle = handle;
6741 for (i = 0 ; i < sas_expander->num_phys ; i++)
6742 sas_expander->phy[i].handle = handle;
6743 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006744 }
6745 out:
6746 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6747}
6748
6749/**
6750 * _scsih_search_responding_expanders -
6751 * @ioc: per adapter object
6752 *
6753 * After host reset, find out whether devices are still responding.
6754 * If not remove.
6755 *
6756 * Return nothing.
6757 */
6758static void
6759_scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6760{
6761 Mpi2ExpanderPage0_t expander_pg0;
6762 Mpi2ConfigReply_t mpi_reply;
6763 u16 ioc_status;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05306764 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006765 u16 handle;
6766
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306767 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006768
6769 if (list_empty(&ioc->sas_expander_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306770 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006771
6772 handle = 0xFFFF;
6773 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6774 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6775
6776 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6777 MPI2_IOCSTATUS_MASK;
6778 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6779 break;
6780
6781 handle = le16_to_cpu(expander_pg0.DevHandle);
6782 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6783 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6784 "sas_addr(0x%016llx)\n", handle,
6785 (unsigned long long)sas_address);
6786 _scsih_mark_responding_expander(ioc, sas_address, handle);
6787 }
6788
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306789 out:
6790 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006791}
6792
6793/**
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306794 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
Eric Moore635374e2009-03-09 01:21:12 -06006795 * @ioc: per adapter object
6796 *
6797 * Return nothing.
6798 */
6799static void
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306800_scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06006801{
6802 struct _sas_device *sas_device, *sas_device_next;
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05306803 struct _sas_node *sas_expander;
Eric Moore635374e2009-03-09 01:21:12 -06006804 struct _raid_device *raid_device, *raid_device_next;
Eric Moore635374e2009-03-09 01:21:12 -06006805
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306806 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
6807 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006808
6809 list_for_each_entry_safe(sas_device, sas_device_next,
6810 &ioc->sas_device_list, list) {
6811 if (sas_device->responding) {
6812 sas_device->responding = 0;
6813 continue;
6814 }
6815 if (sas_device->starget)
6816 starget_printk(KERN_INFO, sas_device->starget,
6817 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6818 "enclosure logical id(0x%016llx), slot(%d)\n",
6819 sas_device->handle,
6820 (unsigned long long)sas_device->sas_address,
6821 (unsigned long long)
6822 sas_device->enclosure_logical_id,
6823 sas_device->slot);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306824 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06006825 }
6826
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306827 if (!ioc->ir_firmware)
6828 goto retry_expander_search;
6829
Eric Moore635374e2009-03-09 01:21:12 -06006830 list_for_each_entry_safe(raid_device, raid_device_next,
6831 &ioc->raid_device_list, list) {
6832 if (raid_device->responding) {
6833 raid_device->responding = 0;
6834 continue;
6835 }
6836 if (raid_device->starget) {
6837 starget_printk(KERN_INFO, raid_device->starget,
6838 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6839 raid_device->handle,
6840 (unsigned long long)raid_device->wwid);
6841 scsi_remove_target(&raid_device->starget->dev);
6842 }
6843 _scsih_raid_device_remove(ioc, raid_device);
6844 }
6845
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05306846 retry_expander_search:
6847 sas_expander = NULL;
6848 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
Eric Moore635374e2009-03-09 01:21:12 -06006849 if (sas_expander->responding) {
6850 sas_expander->responding = 0;
6851 continue;
6852 }
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05306853 mpt2sas_expander_remove(ioc, sas_expander->sas_address);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05306854 goto retry_expander_search;
6855 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306856 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
6857 ioc->name);
6858 /* unblock devices */
6859 _scsih_ublock_io_all_device(ioc);
6860}
6861
6862static void
6863_scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
6864 struct _sas_node *sas_expander, u16 handle)
6865{
6866 Mpi2ExpanderPage1_t expander_pg1;
6867 Mpi2ConfigReply_t mpi_reply;
6868 int i;
6869
6870 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6871 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
6872 &expander_pg1, i, handle))) {
6873 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6874 ioc->name, __FILE__, __LINE__, __func__);
6875 return;
6876 }
6877
6878 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
6879 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6880 expander_pg1.NegotiatedLinkRate >> 4);
6881 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05306882}
6883
6884/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306885 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306886 * @ioc: per adapter object
6887 *
6888 * Return nothing.
6889 */
6890static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306891_scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306892{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306893 Mpi2ExpanderPage0_t expander_pg0;
6894 Mpi2SasDevicePage0_t sas_device_pg0;
6895 Mpi2RaidVolPage1_t volume_pg1;
6896 Mpi2RaidVolPage0_t volume_pg0;
6897 Mpi2RaidPhysDiskPage0_t pd_pg0;
6898 Mpi2EventIrConfigElement_t element;
6899 Mpi2ConfigReply_t mpi_reply;
6900 u8 phys_disk_num;
6901 u16 ioc_status;
6902 u16 handle, parent_handle;
6903 u64 sas_address;
6904 struct _sas_device *sas_device;
6905 struct _sas_node *expander_device;
6906 static struct _raid_device *raid_device;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306907
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306908 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306909
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306910 _scsih_sas_host_refresh(ioc);
6911
6912 /* expanders */
6913 handle = 0xFFFF;
6914 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6915 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6916 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6917 MPI2_IOCSTATUS_MASK;
6918 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6919 break;
6920 handle = le16_to_cpu(expander_pg0.DevHandle);
6921 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
6922 ioc, le64_to_cpu(expander_pg0.SASAddress));
6923 if (expander_device)
6924 _scsih_refresh_expander_links(ioc, expander_device,
6925 handle);
6926 else
6927 _scsih_expander_add(ioc, handle);
6928 }
6929
6930 if (!ioc->ir_firmware)
6931 goto skip_to_sas;
6932
6933 /* phys disk */
6934 phys_disk_num = 0xFF;
6935 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6936 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6937 phys_disk_num))) {
6938 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6939 MPI2_IOCSTATUS_MASK;
6940 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6941 break;
6942 phys_disk_num = pd_pg0.PhysDiskNum;
6943 handle = le16_to_cpu(pd_pg0.DevHandle);
6944 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6945 if (sas_device)
6946 continue;
6947 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6948 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6949 handle) != 0)
6950 continue;
6951 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6952 if (!_scsih_get_sas_address(ioc, parent_handle,
6953 &sas_address)) {
6954 mpt2sas_transport_update_links(ioc, sas_address,
6955 handle, sas_device_pg0.PhyNum,
6956 MPI2_SAS_NEG_LINK_RATE_1_5);
6957 set_bit(handle, ioc->pd_handles);
6958 _scsih_add_device(ioc, handle, 0, 1);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306959 }
6960 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306961
6962 /* volumes */
6963 handle = 0xFFFF;
6964 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6965 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6966 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6967 MPI2_IOCSTATUS_MASK;
6968 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6969 break;
6970 handle = le16_to_cpu(volume_pg1.DevHandle);
6971 raid_device = _scsih_raid_device_find_by_wwid(ioc,
6972 le64_to_cpu(volume_pg1.WWID));
6973 if (raid_device)
6974 continue;
6975 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6976 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6977 sizeof(Mpi2RaidVolPage0_t)))
6978 continue;
6979 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6980 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6981 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
6982 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
6983 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
6984 element.VolDevHandle = volume_pg1.DevHandle;
6985 _scsih_sas_volume_add(ioc, &element);
6986 }
6987 }
6988
6989 skip_to_sas:
6990
6991 /* sas devices */
6992 handle = 0xFFFF;
6993 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6994 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6995 handle))) {
6996 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6997 MPI2_IOCSTATUS_MASK;
6998 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6999 break;
7000 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7001 if (!(_scsih_is_end_device(
7002 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7003 continue;
7004 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7005 le64_to_cpu(sas_device_pg0.SASAddress));
7006 if (sas_device)
7007 continue;
7008 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7009 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7010 mpt2sas_transport_update_links(ioc, sas_address, handle,
7011 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7012 _scsih_add_device(ioc, handle, 0, 0);
7013 }
7014 }
7015
7016 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307017}
7018
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307019
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307020/**
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307021 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7022 * @ioc: per adapter object
7023 * @reset_phase: phase
7024 *
7025 * The handler for doing any required cleanup or initialization.
7026 *
7027 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7028 * MPT2_IOC_DONE_RESET
7029 *
7030 * Return nothing.
7031 */
7032void
7033mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7034{
7035 switch (reset_phase) {
7036 case MPT2_IOC_PRE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307037 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307038 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307039 break;
7040 case MPT2_IOC_AFTER_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307041 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307042 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307043 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7044 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7045 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7046 complete(&ioc->scsih_cmds.done);
7047 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307048 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7049 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7050 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7051 complete(&ioc->tm_cmds.done);
7052 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307053 _scsih_fw_event_cleanup_queue(ioc);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307054 _scsih_flush_running_cmds(ioc);
7055 break;
7056 case MPT2_IOC_DONE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307057 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307058 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307059 _scsih_sas_host_refresh(ioc);
Kashyap, Desai14695852010-03-30 10:52:44 +05307060 _scsih_prep_device_scan(ioc);
7061 _scsih_search_responding_sas_devices(ioc);
7062 _scsih_search_responding_raid_devices(ioc);
7063 _scsih_search_responding_expanders(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307064 _scsih_error_recovery_delete_devices(ioc);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307065 break;
Eric Moore635374e2009-03-09 01:21:12 -06007066 }
7067}
7068
7069/**
7070 * _firmware_event_work - delayed task for processing firmware events
7071 * @ioc: per adapter object
7072 * @work: equal to the fw_event_work object
7073 * Context: user.
7074 *
7075 * Return nothing.
7076 */
7077static void
7078_firmware_event_work(struct work_struct *work)
7079{
7080 struct fw_event_work *fw_event = container_of(work,
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307081 struct fw_event_work, delayed_work.work);
Eric Moore635374e2009-03-09 01:21:12 -06007082 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7083
Eric Moore635374e2009-03-09 01:21:12 -06007084 /* the queue is being flushed so ignore this event */
Eric Moore3cb54692010-07-08 14:44:34 -06007085 if (ioc->remove_host || fw_event->cancel_pending_work ||
7086 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06007087 _scsih_fw_event_free(ioc, fw_event);
7088 return;
7089 }
Eric Moore635374e2009-03-09 01:21:12 -06007090
Eric Moore635374e2009-03-09 01:21:12 -06007091 switch (fw_event->event) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307092 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7093 while (scsi_host_in_recovery(ioc->shost))
7094 ssleep(1);
7095 _scsih_remove_unresponding_sas_devices(ioc);
7096 _scsih_scan_for_devices_after_reset(ioc);
7097 break;
7098 case MPT2SAS_PORT_ENABLE_COMPLETE:
7099 if (!ioc->is_driver_loading && ioc->shost_recovery) {
7100 _scsih_prep_device_scan(ioc);
7101 _scsih_search_responding_sas_devices(ioc);
7102 _scsih_search_responding_raid_devices(ioc);
7103 _scsih_search_responding_expanders(ioc);
7104 }
7105
7106 if (ioc->start_scan)
7107 ioc->start_scan = 0;
7108 else
7109 complete(&ioc->port_enable_done);
7110
7111
7112
7113 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7114 "from worker thread\n", ioc->name));
7115 break;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05307116 case MPT2SAS_TURN_ON_FAULT_LED:
7117 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
7118 break;
Eric Moore635374e2009-03-09 01:21:12 -06007119 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307120 _scsih_sas_topology_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007121 break;
7122 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307123 _scsih_sas_device_status_change_event(ioc,
7124 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007125 break;
7126 case MPI2_EVENT_SAS_DISCOVERY:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307127 _scsih_sas_discovery_event(ioc,
7128 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007129 break;
7130 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307131 _scsih_sas_broadcast_primative_event(ioc,
7132 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007133 break;
7134 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7135 _scsih_sas_enclosure_dev_status_change_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307136 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007137 break;
7138 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307139 _scsih_sas_ir_config_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007140 break;
7141 case MPI2_EVENT_IR_VOLUME:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307142 _scsih_sas_ir_volume_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007143 break;
7144 case MPI2_EVENT_IR_PHYSICAL_DISK:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307145 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007146 break;
7147 case MPI2_EVENT_IR_OPERATION_STATUS:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307148 _scsih_sas_ir_operation_status_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007149 break;
Eric Moore635374e2009-03-09 01:21:12 -06007150 }
7151 _scsih_fw_event_free(ioc, fw_event);
7152}
7153
7154/**
7155 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7156 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307157 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06007158 * @reply: reply message frame(lower 32bit addr)
7159 * Context: interrupt.
7160 *
7161 * This function merely adds a new work task into ioc->firmware_event_thread.
7162 * The tasks are worked from _firmware_event_work in user context.
7163 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307164 * Return 1 meaning mf should be freed from _base_interrupt
7165 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06007166 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307167u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307168mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7169 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06007170{
7171 struct fw_event_work *fw_event;
7172 Mpi2EventNotificationReply_t *mpi_reply;
Eric Moore635374e2009-03-09 01:21:12 -06007173 u16 event;
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307174 u16 sz;
Eric Moore635374e2009-03-09 01:21:12 -06007175
7176 /* events turned off due to host reset or driver unloading */
Eric Moore3cb54692010-07-08 14:44:34 -06007177 if (ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307178 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007179
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307180 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Eric Moore635374e2009-03-09 01:21:12 -06007181 event = le16_to_cpu(mpi_reply->Event);
7182
7183 switch (event) {
7184 /* handle these */
7185 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7186 {
7187 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7188 (Mpi2EventDataSasBroadcastPrimitive_t *)
7189 mpi_reply->EventData;
7190
7191 if (baen_data->Primitive !=
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307192 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307193 return 1;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307194
7195 if (ioc->broadcast_aen_busy) {
7196 ioc->broadcast_aen_pending++;
7197 return 1;
7198 } else
7199 ioc->broadcast_aen_busy = 1;
Eric Moore635374e2009-03-09 01:21:12 -06007200 break;
7201 }
7202
7203 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7204 _scsih_check_topo_delete_events(ioc,
7205 (Mpi2EventDataSasTopologyChangeList_t *)
7206 mpi_reply->EventData);
7207 break;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307208 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7209 _scsih_check_ir_config_unhide_events(ioc,
7210 (Mpi2EventDataIrConfigChangeList_t *)
7211 mpi_reply->EventData);
7212 break;
7213 case MPI2_EVENT_IR_VOLUME:
7214 _scsih_check_volume_delete_events(ioc,
7215 (Mpi2EventDataIrVolume_t *)
7216 mpi_reply->EventData);
7217 break;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307218 case MPI2_EVENT_LOG_ENTRY_ADDED:
7219 {
7220 Mpi2EventDataLogEntryAdded_t *log_entry;
7221 u32 *log_code;
7222
7223 if (!ioc->is_warpdrive)
7224 break;
7225
7226 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7227 mpi_reply->EventData;
7228 log_code = (u32 *)log_entry->LogData;
7229
7230 if (le16_to_cpu(log_entry->LogEntryQualifier)
7231 != MPT2_WARPDRIVE_LOGENTRY)
7232 break;
7233
7234 switch (le32_to_cpu(*log_code)) {
7235 case MPT2_WARPDRIVE_LC_SSDT:
7236 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7237 "IO Throttling has occurred in the WarpDrive "
7238 "subsystem. Check WarpDrive documentation for "
7239 "additional details.\n", ioc->name);
7240 break;
7241 case MPT2_WARPDRIVE_LC_SSDLW:
7242 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7243 "Program/Erase Cycles for the WarpDrive subsystem "
7244 "in degraded range. Check WarpDrive documentation "
7245 "for additional details.\n", ioc->name);
7246 break;
7247 case MPT2_WARPDRIVE_LC_SSDLF:
7248 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7249 "There are no Program/Erase Cycles for the "
7250 "WarpDrive subsystem. The storage device will be "
7251 "in read-only mode. Check WarpDrive documentation "
7252 "for additional details.\n", ioc->name);
7253 break;
7254 case MPT2_WARPDRIVE_LC_BRMF:
7255 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7256 "The Backup Rail Monitor has failed on the "
7257 "WarpDrive subsystem. Check WarpDrive "
7258 "documentation for additional details.\n",
7259 ioc->name);
7260 break;
7261 }
7262
7263 break;
7264 }
Eric Moore635374e2009-03-09 01:21:12 -06007265 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7266 case MPI2_EVENT_IR_OPERATION_STATUS:
7267 case MPI2_EVENT_SAS_DISCOVERY:
7268 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
Eric Moore635374e2009-03-09 01:21:12 -06007269 case MPI2_EVENT_IR_PHYSICAL_DISK:
Eric Moore635374e2009-03-09 01:21:12 -06007270 break;
7271
7272 default: /* ignore the rest */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307273 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007274 }
7275
7276 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
7277 if (!fw_event) {
7278 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7279 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307280 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007281 }
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307282 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7283 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06007284 if (!fw_event->event_data) {
7285 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7286 ioc->name, __FILE__, __LINE__, __func__);
7287 kfree(fw_event);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307288 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007289 }
7290
7291 memcpy(fw_event->event_data, mpi_reply->EventData,
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307292 sz);
Eric Moore635374e2009-03-09 01:21:12 -06007293 fw_event->ioc = ioc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307294 fw_event->VF_ID = mpi_reply->VF_ID;
7295 fw_event->VP_ID = mpi_reply->VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -06007296 fw_event->event = event;
7297 _scsih_fw_event_add(ioc, fw_event);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307298 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007299}
7300
7301/* shost template */
7302static struct scsi_host_template scsih_driver_template = {
7303 .module = THIS_MODULE,
7304 .name = "Fusion MPT SAS Host",
7305 .proc_name = MPT2SAS_DRIVER_NAME,
Eric Moored5d135b2009-05-18 13:02:08 -06007306 .queuecommand = _scsih_qcmd,
7307 .target_alloc = _scsih_target_alloc,
7308 .slave_alloc = _scsih_slave_alloc,
7309 .slave_configure = _scsih_slave_configure,
7310 .target_destroy = _scsih_target_destroy,
7311 .slave_destroy = _scsih_slave_destroy,
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307312 .scan_finished = _scsih_scan_finished,
7313 .scan_start = _scsih_scan_start,
Eric Moored5d135b2009-05-18 13:02:08 -06007314 .change_queue_depth = _scsih_change_queue_depth,
7315 .change_queue_type = _scsih_change_queue_type,
7316 .eh_abort_handler = _scsih_abort,
7317 .eh_device_reset_handler = _scsih_dev_reset,
7318 .eh_target_reset_handler = _scsih_target_reset,
7319 .eh_host_reset_handler = _scsih_host_reset,
7320 .bios_param = _scsih_bios_param,
Eric Moore635374e2009-03-09 01:21:12 -06007321 .can_queue = 1,
7322 .this_id = -1,
7323 .sg_tablesize = MPT2SAS_SG_DEPTH,
7324 .max_sectors = 8192,
7325 .cmd_per_lun = 7,
7326 .use_clustering = ENABLE_CLUSTERING,
7327 .shost_attrs = mpt2sas_host_attrs,
7328 .sdev_attrs = mpt2sas_dev_attrs,
7329};
7330
7331/**
7332 * _scsih_expander_node_remove - removing expander device from list.
7333 * @ioc: per adapter object
7334 * @sas_expander: the sas_device object
7335 * Context: Calling function should acquire ioc->sas_node_lock.
7336 *
7337 * Removing object and freeing associated memory from the
7338 * ioc->sas_expander_list.
7339 *
7340 * Return nothing.
7341 */
7342static void
7343_scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7344 struct _sas_node *sas_expander)
7345{
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307346 struct _sas_port *mpt2sas_port, *next;
Eric Moore635374e2009-03-09 01:21:12 -06007347
7348 /* remove sibling ports attached to this expander */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307349 list_for_each_entry_safe(mpt2sas_port, next,
Eric Moore635374e2009-03-09 01:21:12 -06007350 &sas_expander->sas_port_list, port_list) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307351 if (ioc->shost_recovery)
7352 return;
Eric Moore635374e2009-03-09 01:21:12 -06007353 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307354 SAS_END_DEVICE)
7355 mpt2sas_device_remove(ioc,
7356 mpt2sas_port->remote_identify.sas_address);
7357 else if (mpt2sas_port->remote_identify.device_type ==
7358 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06007359 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307360 SAS_FANOUT_EXPANDER_DEVICE)
7361 mpt2sas_expander_remove(ioc,
7362 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007363 }
7364
7365 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307366 sas_expander->sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007367
7368 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7369 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7370 sas_expander->handle, (unsigned long long)
7371 sas_expander->sas_address);
7372
Eric Moore635374e2009-03-09 01:21:12 -06007373 kfree(sas_expander->phy);
7374 kfree(sas_expander);
7375}
7376
7377/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05307378 * _scsih_ir_shutdown - IR shutdown notification
7379 * @ioc: per adapter object
7380 *
7381 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7382 * the host system is shutting down.
7383 *
7384 * Return nothing.
7385 */
7386static void
7387_scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7388{
7389 Mpi2RaidActionRequest_t *mpi_request;
7390 Mpi2RaidActionReply_t *mpi_reply;
7391 u16 smid;
7392
7393 /* is IR firmware build loaded ? */
7394 if (!ioc->ir_firmware)
7395 return;
7396
7397 /* are there any volumes ? */
7398 if (list_empty(&ioc->raid_device_list))
7399 return;
7400
7401 mutex_lock(&ioc->scsih_cmds.mutex);
7402
7403 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7404 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7405 ioc->name, __func__);
7406 goto out;
7407 }
7408 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7409
7410 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7411 if (!smid) {
7412 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7413 ioc->name, __func__);
7414 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7415 goto out;
7416 }
7417
7418 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7419 ioc->scsih_cmds.smid = smid;
7420 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7421
7422 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7423 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7424
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307425 if (!ioc->hide_ir_msg)
7426 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307427 init_completion(&ioc->scsih_cmds.done);
7428 mpt2sas_base_put_smid_default(ioc, smid);
7429 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7430
7431 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7432 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7433 ioc->name, __func__);
7434 goto out;
7435 }
7436
7437 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7438 mpi_reply = ioc->scsih_cmds.reply;
7439
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307440 if (!ioc->hide_ir_msg)
7441 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7442 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7443 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7444 le32_to_cpu(mpi_reply->IOCLogInfo));
Kashyap, Desai744090d2009-10-05 15:56:56 +05307445 }
7446
7447 out:
7448 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7449 mutex_unlock(&ioc->scsih_cmds.mutex);
7450}
7451
7452/**
7453 * _scsih_shutdown - routine call during system shutdown
7454 * @pdev: PCI device struct
7455 *
7456 * Return nothing.
7457 */
7458static void
7459_scsih_shutdown(struct pci_dev *pdev)
7460{
7461 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7462 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307463 struct workqueue_struct *wq;
7464 unsigned long flags;
7465
7466 ioc->remove_host = 1;
7467 _scsih_fw_event_cleanup_queue(ioc);
7468
7469 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7470 wq = ioc->firmware_event_thread;
7471 ioc->firmware_event_thread = NULL;
7472 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7473 if (wq)
7474 destroy_workqueue(wq);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307475
7476 _scsih_ir_shutdown(ioc);
7477 mpt2sas_base_detach(ioc);
7478}
7479
7480/**
Eric Moored5d135b2009-05-18 13:02:08 -06007481 * _scsih_remove - detach and remove add host
Eric Moore635374e2009-03-09 01:21:12 -06007482 * @pdev: PCI device struct
7483 *
Kashyap, Desai744090d2009-10-05 15:56:56 +05307484 * Routine called when unloading the driver.
Eric Moore635374e2009-03-09 01:21:12 -06007485 * Return nothing.
7486 */
7487static void __devexit
Eric Moored5d135b2009-05-18 13:02:08 -06007488_scsih_remove(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06007489{
7490 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7491 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307492 struct _sas_port *mpt2sas_port, *next_port;
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307493 struct _raid_device *raid_device, *next;
7494 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06007495 struct workqueue_struct *wq;
7496 unsigned long flags;
7497
7498 ioc->remove_host = 1;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307499 _scsih_fw_event_cleanup_queue(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007500
7501 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7502 wq = ioc->firmware_event_thread;
7503 ioc->firmware_event_thread = NULL;
7504 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7505 if (wq)
7506 destroy_workqueue(wq);
7507
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307508 /* release all the volumes */
Kashyap, Desai3a9c9132011-01-04 11:40:23 +05307509 _scsih_ir_shutdown(ioc);
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307510 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7511 list) {
7512 if (raid_device->starget) {
7513 sas_target_priv_data =
7514 raid_device->starget->hostdata;
7515 sas_target_priv_data->deleted = 1;
7516 scsi_remove_target(&raid_device->starget->dev);
7517 }
7518 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7519 "(0x%016llx)\n", ioc->name, raid_device->handle,
7520 (unsigned long long) raid_device->wwid);
7521 _scsih_raid_device_remove(ioc, raid_device);
7522 }
7523
Eric Moore635374e2009-03-09 01:21:12 -06007524 /* free ports attached to the sas_host */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307525 list_for_each_entry_safe(mpt2sas_port, next_port,
Eric Moore635374e2009-03-09 01:21:12 -06007526 &ioc->sas_hba.sas_port_list, port_list) {
7527 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307528 SAS_END_DEVICE)
7529 mpt2sas_device_remove(ioc,
Eric Moore635374e2009-03-09 01:21:12 -06007530 mpt2sas_port->remote_identify.sas_address);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307531 else if (mpt2sas_port->remote_identify.device_type ==
7532 SAS_EDGE_EXPANDER_DEVICE ||
7533 mpt2sas_port->remote_identify.device_type ==
7534 SAS_FANOUT_EXPANDER_DEVICE)
7535 mpt2sas_expander_remove(ioc,
7536 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007537 }
7538
7539 /* free phys attached to the sas_host */
7540 if (ioc->sas_hba.num_phys) {
7541 kfree(ioc->sas_hba.phy);
7542 ioc->sas_hba.phy = NULL;
7543 ioc->sas_hba.num_phys = 0;
7544 }
7545
7546 sas_remove_host(shost);
kashyap.desai@lsi.com9ae89b02011-08-04 16:47:50 +05307547 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007548 list_del(&ioc->list);
7549 scsi_remove_host(shost);
7550 scsi_host_put(shost);
7551}
7552
7553/**
7554 * _scsih_probe_boot_devices - reports 1st device
7555 * @ioc: per adapter object
7556 *
7557 * If specified in bios page 2, this routine reports the 1st
7558 * device scsi-ml or sas transport for persistent boot device
7559 * purposes. Please refer to function _scsih_determine_boot_device()
7560 */
7561static void
7562_scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7563{
7564 u8 is_raid;
7565 void *device;
7566 struct _sas_device *sas_device;
7567 struct _raid_device *raid_device;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307568 u16 handle;
7569 u64 sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007570 u64 sas_address;
7571 unsigned long flags;
7572 int rc;
7573
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307574 /* no Bios, return immediately */
7575 if (!ioc->bios_pg3.BiosVersion)
7576 return;
7577
Eric Moore635374e2009-03-09 01:21:12 -06007578 device = NULL;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307579 is_raid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007580 if (ioc->req_boot_device.device) {
7581 device = ioc->req_boot_device.device;
7582 is_raid = ioc->req_boot_device.is_raid;
7583 } else if (ioc->req_alt_boot_device.device) {
7584 device = ioc->req_alt_boot_device.device;
7585 is_raid = ioc->req_alt_boot_device.is_raid;
7586 } else if (ioc->current_boot_device.device) {
7587 device = ioc->current_boot_device.device;
7588 is_raid = ioc->current_boot_device.is_raid;
7589 }
7590
7591 if (!device)
7592 return;
7593
7594 if (is_raid) {
7595 raid_device = device;
7596 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7597 raid_device->id, 0);
7598 if (rc)
7599 _scsih_raid_device_remove(ioc, raid_device);
7600 } else {
7601 sas_device = device;
7602 handle = sas_device->handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307603 sas_address_parent = sas_device->sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007604 sas_address = sas_device->sas_address;
7605 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7606 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7607 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307608
7609 if (ioc->hide_drives)
7610 return;
Eric Moore635374e2009-03-09 01:21:12 -06007611 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307612 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -06007613 _scsih_sas_device_remove(ioc, sas_device);
7614 } else if (!sas_device->starget) {
7615 mpt2sas_transport_port_remove(ioc, sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307616 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007617 _scsih_sas_device_remove(ioc, sas_device);
7618 }
7619 }
7620}
7621
7622/**
7623 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7624 * @ioc: per adapter object
7625 *
7626 * Called during initial loading of the driver.
7627 */
7628static void
7629_scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7630{
7631 struct _raid_device *raid_device, *raid_next;
7632 int rc;
7633
7634 list_for_each_entry_safe(raid_device, raid_next,
7635 &ioc->raid_device_list, list) {
7636 if (raid_device->starget)
7637 continue;
7638 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7639 raid_device->id, 0);
7640 if (rc)
7641 _scsih_raid_device_remove(ioc, raid_device);
7642 }
7643}
7644
7645/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307646 * _scsih_probe_sas - reporting sas devices to sas transport
Eric Moore635374e2009-03-09 01:21:12 -06007647 * @ioc: per adapter object
7648 *
7649 * Called during initial loading of the driver.
7650 */
7651static void
7652_scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7653{
7654 struct _sas_device *sas_device, *next;
7655 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007656
7657 /* SAS Device List */
7658 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7659 list) {
Eric Moore635374e2009-03-09 01:21:12 -06007660
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307661 if (ioc->hide_drives)
7662 continue;
7663
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307664 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7665 sas_device->sas_address_parent)) {
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307666 list_del(&sas_device->list);
7667 kfree(sas_device);
7668 continue;
Eric Moore635374e2009-03-09 01:21:12 -06007669 } else if (!sas_device->starget) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307670 mpt2sas_transport_port_remove(ioc,
7671 sas_device->sas_address,
7672 sas_device->sas_address_parent);
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307673 list_del(&sas_device->list);
7674 kfree(sas_device);
7675 continue;
7676
Eric Moore635374e2009-03-09 01:21:12 -06007677 }
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307678 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7679 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7680 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007681 }
7682}
7683
7684/**
7685 * _scsih_probe_devices - probing for devices
7686 * @ioc: per adapter object
7687 *
7688 * Called during initial loading of the driver.
7689 */
7690static void
7691_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7692{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307693 u16 volume_mapping_flags;
Eric Moore635374e2009-03-09 01:21:12 -06007694
7695 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7696 return; /* return when IOC doesn't support initiator mode */
7697
7698 _scsih_probe_boot_devices(ioc);
7699
7700 if (ioc->ir_firmware) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307701 volume_mapping_flags =
7702 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7703 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7704 if (volume_mapping_flags ==
7705 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
Eric Moore635374e2009-03-09 01:21:12 -06007706 _scsih_probe_raid(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307707 _scsih_probe_sas(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007708 } else {
Eric Moore635374e2009-03-09 01:21:12 -06007709 _scsih_probe_sas(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307710 _scsih_probe_raid(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007711 }
7712 } else
7713 _scsih_probe_sas(ioc);
7714}
7715
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307716
7717/**
7718 * _scsih_scan_start - scsi lld callback for .scan_start
7719 * @shost: SCSI host pointer
7720 *
7721 * The shost has the ability to discover targets on its own instead
7722 * of scanning the entire bus. In our implemention, we will kick off
7723 * firmware discovery.
7724 */
7725static void
7726_scsih_scan_start(struct Scsi_Host *shost)
7727{
7728 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7729 int rc;
7730
7731 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7732 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
7733
7734 ioc->start_scan = 1;
7735 rc = mpt2sas_port_enable(ioc);
7736
7737 if (rc != 0)
7738 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
7739}
7740
7741/**
7742 * _scsih_scan_finished - scsi lld callback for .scan_finished
7743 * @shost: SCSI host pointer
7744 * @time: elapsed time of the scan in jiffies
7745 *
7746 * This function will be called periodically until it returns 1 with the
7747 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7748 * we wait for firmware discovery to complete, then return 1.
7749 */
7750static int
7751_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7752{
7753 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7754
7755 if (time >= (300 * HZ)) {
7756 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7757 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
7758 "(timeout=300s)\n", ioc->name);
7759 ioc->is_driver_loading = 0;
7760 return 1;
7761 }
7762
7763 if (ioc->start_scan)
7764 return 0;
7765
7766 if (ioc->start_scan_failed) {
7767 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
7768 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
7769 ioc->is_driver_loading = 0;
7770 ioc->wait_for_discovery_to_complete = 0;
7771 ioc->remove_host = 1;
7772 return 1;
7773 }
7774
7775 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
7776 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7777
7778 if (ioc->wait_for_discovery_to_complete) {
7779 ioc->wait_for_discovery_to_complete = 0;
7780 _scsih_probe_devices(ioc);
7781 }
7782 mpt2sas_base_start_watchdog(ioc);
7783 ioc->is_driver_loading = 0;
7784 return 1;
7785}
7786
7787
Eric Moore635374e2009-03-09 01:21:12 -06007788/**
Eric Moored5d135b2009-05-18 13:02:08 -06007789 * _scsih_probe - attach and add scsi host
Eric Moore635374e2009-03-09 01:21:12 -06007790 * @pdev: PCI device struct
7791 * @id: pci device id
7792 *
7793 * Returns 0 success, anything else error.
7794 */
7795static int
Eric Moored5d135b2009-05-18 13:02:08 -06007796_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
Eric Moore635374e2009-03-09 01:21:12 -06007797{
7798 struct MPT2SAS_ADAPTER *ioc;
7799 struct Scsi_Host *shost;
7800
7801 shost = scsi_host_alloc(&scsih_driver_template,
7802 sizeof(struct MPT2SAS_ADAPTER));
7803 if (!shost)
7804 return -ENODEV;
7805
7806 /* init local params */
7807 ioc = shost_priv(shost);
7808 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
7809 INIT_LIST_HEAD(&ioc->list);
Eric Mooreba33fad2009-03-15 21:37:18 -06007810 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -06007811 ioc->shost = shost;
7812 ioc->id = mpt_ids++;
7813 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
7814 ioc->pdev = pdev;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307815 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
7816 ioc->is_warpdrive = 1;
7817 ioc->hide_ir_msg = 1;
7818 } else
7819 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
Eric Moore635374e2009-03-09 01:21:12 -06007820 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7821 ioc->tm_cb_idx = tm_cb_idx;
7822 ioc->ctl_cb_idx = ctl_cb_idx;
7823 ioc->base_cb_idx = base_cb_idx;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307824 ioc->port_enable_cb_idx = port_enable_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06007825 ioc->transport_cb_idx = transport_cb_idx;
Kashyap, Desai744090d2009-10-05 15:56:56 +05307826 ioc->scsih_cb_idx = scsih_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06007827 ioc->config_cb_idx = config_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307828 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307829 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307830 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06007831 ioc->logging_level = logging_level;
7832 /* misc semaphores and spin locks */
Kashyap, Desaid2742132010-06-17 13:28:55 +05307833 mutex_init(&ioc->reset_in_progress_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06007834 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7835 spin_lock_init(&ioc->scsi_lookup_lock);
7836 spin_lock_init(&ioc->sas_device_lock);
7837 spin_lock_init(&ioc->sas_node_lock);
7838 spin_lock_init(&ioc->fw_event_lock);
7839 spin_lock_init(&ioc->raid_device_lock);
7840
7841 INIT_LIST_HEAD(&ioc->sas_device_list);
7842 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7843 INIT_LIST_HEAD(&ioc->sas_expander_list);
7844 INIT_LIST_HEAD(&ioc->fw_event_list);
7845 INIT_LIST_HEAD(&ioc->raid_device_list);
7846 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307847 INIT_LIST_HEAD(&ioc->delayed_tr_list);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307848 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
Eric Moore635374e2009-03-09 01:21:12 -06007849
7850 /* init shost parameters */
Eric Moored334aa72010-04-22 10:47:40 -06007851 shost->max_cmd_len = 32;
Eric Moore635374e2009-03-09 01:21:12 -06007852 shost->max_lun = max_lun;
7853 shost->transportt = mpt2sas_transport_template;
7854 shost->unique_id = ioc->id;
7855
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05307856 if (max_sectors != 0xFFFF) {
7857 if (max_sectors < 64) {
7858 shost->max_sectors = 64;
7859 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7860 "for max_sectors, range is 64 to 8192. Assigning "
7861 "value of 64.\n", ioc->name, max_sectors);
7862 } else if (max_sectors > 8192) {
7863 shost->max_sectors = 8192;
7864 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7865 "for max_sectors, range is 64 to 8192. Assigning "
7866 "default value of 8192.\n", ioc->name,
7867 max_sectors);
7868 } else {
7869 shost->max_sectors = max_sectors & 0xFFFE;
7870 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
7871 "set to %d\n", ioc->name, shost->max_sectors);
7872 }
7873 }
7874
Eric Moore635374e2009-03-09 01:21:12 -06007875 if ((scsi_add_host(shost, &pdev->dev))) {
7876 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7877 ioc->name, __FILE__, __LINE__, __func__);
7878 list_del(&ioc->list);
7879 goto out_add_shost_fail;
7880 }
7881
Eric Moore3c621b32009-05-18 12:59:41 -06007882 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
Eric Moored334aa72010-04-22 10:47:40 -06007883 | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307884 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
Eric Moore3c621b32009-05-18 12:59:41 -06007885
Eric Moore635374e2009-03-09 01:21:12 -06007886 /* event thread */
7887 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7888 "fw_event%d", ioc->id);
7889 ioc->firmware_event_thread = create_singlethread_workqueue(
7890 ioc->firmware_event_name);
7891 if (!ioc->firmware_event_thread) {
7892 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7893 ioc->name, __FILE__, __LINE__, __func__);
7894 goto out_thread_fail;
7895 }
7896
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307897 ioc->is_driver_loading = 1;
Eric Moore635374e2009-03-09 01:21:12 -06007898 if ((mpt2sas_base_attach(ioc))) {
7899 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7900 ioc->name, __FILE__, __LINE__, __func__);
7901 goto out_attach_fail;
7902 }
7903
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307904 scsi_scan_host(shost);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307905 if (ioc->is_warpdrive) {
7906 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
7907 ioc->hide_drives = 0;
7908 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
7909 ioc->hide_drives = 1;
7910 else {
7911 if (_scsih_get_num_volumes(ioc))
7912 ioc->hide_drives = 1;
7913 else
7914 ioc->hide_drives = 0;
7915 }
7916 } else
7917 ioc->hide_drives = 0;
7918
Eric Moore635374e2009-03-09 01:21:12 -06007919 _scsih_probe_devices(ioc);
7920 return 0;
7921
7922 out_attach_fail:
7923 destroy_workqueue(ioc->firmware_event_thread);
7924 out_thread_fail:
7925 list_del(&ioc->list);
7926 scsi_remove_host(shost);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307927 scsi_host_put(shost);
Eric Moore635374e2009-03-09 01:21:12 -06007928 out_add_shost_fail:
7929 return -ENODEV;
7930}
7931
7932#ifdef CONFIG_PM
7933/**
Eric Moored5d135b2009-05-18 13:02:08 -06007934 * _scsih_suspend - power management suspend main entry point
Eric Moore635374e2009-03-09 01:21:12 -06007935 * @pdev: PCI device struct
7936 * @state: PM state change to (usually PCI_D3)
7937 *
7938 * Returns 0 success, anything else error.
7939 */
7940static int
Eric Moored5d135b2009-05-18 13:02:08 -06007941_scsih_suspend(struct pci_dev *pdev, pm_message_t state)
Eric Moore635374e2009-03-09 01:21:12 -06007942{
7943 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7944 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05307945 pci_power_t device_state;
Eric Moore635374e2009-03-09 01:21:12 -06007946
Kashyap, Desaie4750c92009-08-07 19:37:59 +05307947 mpt2sas_base_stop_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007948 scsi_block_requests(shost);
7949 device_state = pci_choose_state(pdev, state);
7950 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
7951 "operating state [D%d]\n", ioc->name, pdev,
7952 pci_name(pdev), device_state);
7953
7954 mpt2sas_base_free_resources(ioc);
7955 pci_save_state(pdev);
7956 pci_disable_device(pdev);
7957 pci_set_power_state(pdev, device_state);
7958 return 0;
7959}
7960
7961/**
Eric Moored5d135b2009-05-18 13:02:08 -06007962 * _scsih_resume - power management resume main entry point
Eric Moore635374e2009-03-09 01:21:12 -06007963 * @pdev: PCI device struct
7964 *
7965 * Returns 0 success, anything else error.
7966 */
7967static int
Eric Moored5d135b2009-05-18 13:02:08 -06007968_scsih_resume(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06007969{
7970 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7971 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05307972 pci_power_t device_state = pdev->current_state;
Eric Moore635374e2009-03-09 01:21:12 -06007973 int r;
7974
7975 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
7976 "operating state [D%d]\n", ioc->name, pdev,
7977 pci_name(pdev), device_state);
7978
7979 pci_set_power_state(pdev, PCI_D0);
7980 pci_enable_wake(pdev, PCI_D0, 0);
7981 pci_restore_state(pdev);
7982 ioc->pdev = pdev;
7983 r = mpt2sas_base_map_resources(ioc);
7984 if (r)
7985 return r;
7986
7987 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
7988 scsi_unblock_requests(shost);
Kashyap, Desaie4750c92009-08-07 19:37:59 +05307989 mpt2sas_base_start_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007990 return 0;
7991}
7992#endif /* CONFIG_PM */
7993
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05307994/**
7995 * _scsih_pci_error_detected - Called when a PCI error is detected.
7996 * @pdev: PCI device struct
7997 * @state: PCI channel state
7998 *
7999 * Description: Called when a PCI error is detected.
8000 *
8001 * Return value:
8002 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8003 */
8004static pci_ers_result_t
8005_scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8006{
8007 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8008 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8009
8010 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8011 ioc->name, state);
8012
8013 switch (state) {
8014 case pci_channel_io_normal:
8015 return PCI_ERS_RESULT_CAN_RECOVER;
8016 case pci_channel_io_frozen:
Eric Moore3cb54692010-07-08 14:44:34 -06008017 /* Fatal error, prepare for slot reset */
8018 ioc->pci_error_recovery = 1;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308019 scsi_block_requests(ioc->shost);
8020 mpt2sas_base_stop_watchdog(ioc);
8021 mpt2sas_base_free_resources(ioc);
8022 return PCI_ERS_RESULT_NEED_RESET;
8023 case pci_channel_io_perm_failure:
Eric Moore3cb54692010-07-08 14:44:34 -06008024 /* Permanent error, prepare for device removal */
8025 ioc->pci_error_recovery = 1;
8026 mpt2sas_base_stop_watchdog(ioc);
8027 _scsih_flush_running_cmds(ioc);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308028 return PCI_ERS_RESULT_DISCONNECT;
8029 }
8030 return PCI_ERS_RESULT_NEED_RESET;
8031}
8032
8033/**
8034 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8035 * @pdev: PCI device struct
8036 *
8037 * Description: This routine is called by the pci error recovery
8038 * code after the PCI slot has been reset, just before we
8039 * should resume normal operations.
8040 */
8041static pci_ers_result_t
8042_scsih_pci_slot_reset(struct pci_dev *pdev)
8043{
8044 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8045 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8046 int rc;
8047
8048 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8049 ioc->name);
8050
Eric Moore3cb54692010-07-08 14:44:34 -06008051 ioc->pci_error_recovery = 0;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308052 ioc->pdev = pdev;
Eric Moore3cb54692010-07-08 14:44:34 -06008053 pci_restore_state(pdev);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308054 rc = mpt2sas_base_map_resources(ioc);
8055 if (rc)
8056 return PCI_ERS_RESULT_DISCONNECT;
8057
8058
8059 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8060 FORCE_BIG_HAMMER);
8061
8062 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8063 (rc == 0) ? "success" : "failed");
8064
8065 if (!rc)
8066 return PCI_ERS_RESULT_RECOVERED;
8067 else
8068 return PCI_ERS_RESULT_DISCONNECT;
8069}
8070
8071/**
8072 * _scsih_pci_resume() - resume normal ops after PCI reset
8073 * @pdev: pointer to PCI device
8074 *
8075 * Called when the error recovery driver tells us that its
8076 * OK to resume normal operation. Use completion to allow
8077 * halted scsi ops to resume.
8078 */
8079static void
8080_scsih_pci_resume(struct pci_dev *pdev)
8081{
8082 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8083 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8084
8085 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8086
8087 pci_cleanup_aer_uncorrect_error_status(pdev);
8088 mpt2sas_base_start_watchdog(ioc);
8089 scsi_unblock_requests(ioc->shost);
8090}
8091
8092/**
8093 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8094 * @pdev: pointer to PCI device
8095 */
8096static pci_ers_result_t
8097_scsih_pci_mmio_enabled(struct pci_dev *pdev)
8098{
8099 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8100 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8101
8102 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8103 ioc->name);
8104
8105 /* TODO - dump whatever for debugging purposes */
8106
8107 /* Request a slot reset. */
8108 return PCI_ERS_RESULT_NEED_RESET;
8109}
8110
8111static struct pci_error_handlers _scsih_err_handler = {
8112 .error_detected = _scsih_pci_error_detected,
8113 .mmio_enabled = _scsih_pci_mmio_enabled,
8114 .slot_reset = _scsih_pci_slot_reset,
8115 .resume = _scsih_pci_resume,
8116};
Eric Moore635374e2009-03-09 01:21:12 -06008117
8118static struct pci_driver scsih_driver = {
8119 .name = MPT2SAS_DRIVER_NAME,
8120 .id_table = scsih_pci_table,
Eric Moored5d135b2009-05-18 13:02:08 -06008121 .probe = _scsih_probe,
8122 .remove = __devexit_p(_scsih_remove),
Kashyap, Desai744090d2009-10-05 15:56:56 +05308123 .shutdown = _scsih_shutdown,
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308124 .err_handler = &_scsih_err_handler,
Eric Moore635374e2009-03-09 01:21:12 -06008125#ifdef CONFIG_PM
Eric Moored5d135b2009-05-18 13:02:08 -06008126 .suspend = _scsih_suspend,
8127 .resume = _scsih_resume,
Eric Moore635374e2009-03-09 01:21:12 -06008128#endif
8129};
8130
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308131/* raid transport support */
8132static struct raid_function_template mpt2sas_raid_functions = {
8133 .cookie = &scsih_driver_template,
8134 .is_raid = _scsih_is_raid,
8135 .get_resync = _scsih_get_resync,
8136 .get_state = _scsih_get_state,
8137};
Eric Moore635374e2009-03-09 01:21:12 -06008138
8139/**
Eric Moored5d135b2009-05-18 13:02:08 -06008140 * _scsih_init - main entry point for this driver.
Eric Moore635374e2009-03-09 01:21:12 -06008141 *
8142 * Returns 0 success, anything else error.
8143 */
8144static int __init
Eric Moored5d135b2009-05-18 13:02:08 -06008145_scsih_init(void)
Eric Moore635374e2009-03-09 01:21:12 -06008146{
8147 int error;
8148
8149 mpt_ids = 0;
8150 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8151 MPT2SAS_DRIVER_VERSION);
8152
8153 mpt2sas_transport_template =
8154 sas_attach_transport(&mpt2sas_transport_functions);
8155 if (!mpt2sas_transport_template)
8156 return -ENODEV;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308157 /* raid transport support */
8158 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8159 if (!mpt2sas_raid_template) {
8160 sas_release_transport(mpt2sas_transport_template);
8161 return -ENODEV;
8162 }
Eric Moore635374e2009-03-09 01:21:12 -06008163
8164 mpt2sas_base_initialize_callback_handler();
8165
8166 /* queuecommand callback hander */
Eric Moored5d135b2009-05-18 13:02:08 -06008167 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
Eric Moore635374e2009-03-09 01:21:12 -06008168
Uwe Kleine-König65155b32010-06-11 12:17:01 +02008169 /* task management callback handler */
Eric Moored5d135b2009-05-18 13:02:08 -06008170 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
Eric Moore635374e2009-03-09 01:21:12 -06008171
8172 /* base internal commands callback handler */
8173 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308174 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8175 mpt2sas_port_enable_done);
Eric Moore635374e2009-03-09 01:21:12 -06008176
8177 /* transport internal commands callback handler */
8178 transport_cb_idx = mpt2sas_base_register_callback_handler(
8179 mpt2sas_transport_done);
8180
Kashyap, Desai744090d2009-10-05 15:56:56 +05308181 /* scsih internal commands callback handler */
8182 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8183
Eric Moore635374e2009-03-09 01:21:12 -06008184 /* configuration page API internal commands callback handler */
8185 config_cb_idx = mpt2sas_base_register_callback_handler(
8186 mpt2sas_config_done);
8187
8188 /* ctl module callback handler */
8189 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8190
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308191 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8192 _scsih_tm_tr_complete);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308193
8194 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8195 _scsih_tm_volume_tr_complete);
8196
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308197 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8198 _scsih_sas_control_complete);
8199
Eric Moore635374e2009-03-09 01:21:12 -06008200 mpt2sas_ctl_init();
8201
8202 error = pci_register_driver(&scsih_driver);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308203 if (error) {
8204 /* raid transport support */
8205 raid_class_release(mpt2sas_raid_template);
Eric Moore635374e2009-03-09 01:21:12 -06008206 sas_release_transport(mpt2sas_transport_template);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308207 }
Eric Moore635374e2009-03-09 01:21:12 -06008208
8209 return error;
8210}
8211
8212/**
Eric Moored5d135b2009-05-18 13:02:08 -06008213 * _scsih_exit - exit point for this driver (when it is a module).
Eric Moore635374e2009-03-09 01:21:12 -06008214 *
8215 * Returns 0 success, anything else error.
8216 */
8217static void __exit
Eric Moored5d135b2009-05-18 13:02:08 -06008218_scsih_exit(void)
Eric Moore635374e2009-03-09 01:21:12 -06008219{
8220 printk(KERN_INFO "mpt2sas version %s unloading\n",
8221 MPT2SAS_DRIVER_VERSION);
8222
8223 pci_unregister_driver(&scsih_driver);
8224
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308225 mpt2sas_ctl_exit();
8226
Eric Moore635374e2009-03-09 01:21:12 -06008227 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8228 mpt2sas_base_release_callback_handler(tm_cb_idx);
8229 mpt2sas_base_release_callback_handler(base_cb_idx);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308230 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008231 mpt2sas_base_release_callback_handler(transport_cb_idx);
Kashyap, Desai744090d2009-10-05 15:56:56 +05308232 mpt2sas_base_release_callback_handler(scsih_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008233 mpt2sas_base_release_callback_handler(config_cb_idx);
8234 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8235
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308236 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308237 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308238 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8239
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308240 /* raid transport support */
8241 raid_class_release(mpt2sas_raid_template);
8242 sas_release_transport(mpt2sas_transport_template);
8243
Eric Moore635374e2009-03-09 01:21:12 -06008244}
8245
Eric Moored5d135b2009-05-18 13:02:08 -06008246module_init(_scsih_init);
8247module_exit(_scsih_exit);