blob: cd89f42440fe9dabb0efc46adf114b620cfbd177 [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;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530391 *sas_address = 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530392
393 if (handle <= ioc->sas_hba.num_phys) {
394 *sas_address = ioc->sas_hba.sas_address;
395 return 0;
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530396 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530397
398 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
399 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530400 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
401 __FILE__, __LINE__, __func__);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530402 return -ENXIO;
403 }
404
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530405 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
406 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
407 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
408 return 0;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530409 }
410
nagalakshmi.nandigama@lsi.com24f09b52011-10-19 15:36:47 +0530411 /* we hit this becuase the given parent handle doesn't exist */
412 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
413 return -ENXIO;
414 /* else error case */
415 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
416 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
417 __FILE__, __LINE__, __func__);
418 return -EIO;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530419}
420
421/**
Eric Moore635374e2009-03-09 01:21:12 -0600422 * _scsih_determine_boot_device - determine boot device.
423 * @ioc: per adapter object
424 * @device: either sas_device or raid_device object
425 * @is_raid: [flag] 1 = raid object, 0 = sas object
426 *
427 * Determines whether this device should be first reported device to
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300428 * to scsi-ml or sas transport, this purpose is for persistent boot device.
Eric Moore635374e2009-03-09 01:21:12 -0600429 * There are primary, alternate, and current entries in bios page 2. The order
430 * priority is primary, alternate, then current. This routine saves
431 * the corresponding device object and is_raid flag in the ioc object.
432 * The saved data to be used later in _scsih_probe_boot_devices().
433 */
434static void
435_scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
436 void *device, u8 is_raid)
437{
438 struct _sas_device *sas_device;
439 struct _raid_device *raid_device;
440 u64 sas_address;
441 u64 device_name;
442 u64 enclosure_logical_id;
443 u16 slot;
444
445 /* only process this function when driver loads */
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530446 if (!ioc->is_driver_loading)
447 return;
448
449 /* no Bios, return immediately */
450 if (!ioc->bios_pg3.BiosVersion)
Eric Moore635374e2009-03-09 01:21:12 -0600451 return;
452
453 if (!is_raid) {
454 sas_device = device;
455 sas_address = sas_device->sas_address;
456 device_name = sas_device->device_name;
457 enclosure_logical_id = sas_device->enclosure_logical_id;
458 slot = sas_device->slot;
459 } else {
460 raid_device = device;
461 sas_address = raid_device->wwid;
462 device_name = 0;
463 enclosure_logical_id = 0;
464 slot = 0;
465 }
466
467 if (!ioc->req_boot_device.device) {
468 if (_scsih_is_boot_device(sas_address, device_name,
469 enclosure_logical_id, slot,
470 (ioc->bios_pg2.ReqBootDeviceForm &
471 MPI2_BIOSPAGE2_FORM_MASK),
472 &ioc->bios_pg2.RequestedBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530473 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600474 "%s: req_boot_device(0x%016llx)\n",
475 ioc->name, __func__,
476 (unsigned long long)sas_address));
477 ioc->req_boot_device.device = device;
478 ioc->req_boot_device.is_raid = is_raid;
479 }
480 }
481
482 if (!ioc->req_alt_boot_device.device) {
483 if (_scsih_is_boot_device(sas_address, device_name,
484 enclosure_logical_id, slot,
485 (ioc->bios_pg2.ReqAltBootDeviceForm &
486 MPI2_BIOSPAGE2_FORM_MASK),
487 &ioc->bios_pg2.RequestedAltBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530488 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600489 "%s: req_alt_boot_device(0x%016llx)\n",
490 ioc->name, __func__,
491 (unsigned long long)sas_address));
492 ioc->req_alt_boot_device.device = device;
493 ioc->req_alt_boot_device.is_raid = is_raid;
494 }
495 }
496
497 if (!ioc->current_boot_device.device) {
498 if (_scsih_is_boot_device(sas_address, device_name,
499 enclosure_logical_id, slot,
500 (ioc->bios_pg2.CurrentBootDeviceForm &
501 MPI2_BIOSPAGE2_FORM_MASK),
502 &ioc->bios_pg2.CurrentBootDevice)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530503 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -0600504 "%s: current_boot_device(0x%016llx)\n",
505 ioc->name, __func__,
506 (unsigned long long)sas_address));
507 ioc->current_boot_device.device = device;
508 ioc->current_boot_device.is_raid = is_raid;
509 }
510 }
511}
512
513/**
514 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
515 * @ioc: per adapter object
516 * @sas_address: sas address
517 * Context: Calling function should acquire ioc->sas_device_lock
518 *
519 * This searches for sas_device based on sas_address, then return sas_device
520 * object.
521 */
522struct _sas_device *
523mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
524 u64 sas_address)
525{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530526 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600527
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530528 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
529 if (sas_device->sas_address == sas_address)
530 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600531
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530532 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
533 if (sas_device->sas_address == sas_address)
534 return sas_device;
535
536 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600537}
538
539/**
540 * _scsih_sas_device_find_by_handle - sas device search
541 * @ioc: per adapter object
542 * @handle: sas device handle (assigned by firmware)
543 * Context: Calling function should acquire ioc->sas_device_lock
544 *
545 * This searches for sas_device based on sas_address, then return sas_device
546 * object.
547 */
548static struct _sas_device *
549_scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
550{
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530551 struct _sas_device *sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600552
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530553 list_for_each_entry(sas_device, &ioc->sas_device_list, list)
554 if (sas_device->handle == handle)
555 return sas_device;
Eric Moore635374e2009-03-09 01:21:12 -0600556
Kashyap, Desaicd9843f2010-03-09 16:32:17 +0530557 list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
558 if (sas_device->handle == handle)
559 return sas_device;
560
561 return NULL;
Eric Moore635374e2009-03-09 01:21:12 -0600562}
563
564/**
565 * _scsih_sas_device_remove - remove sas_device from list.
566 * @ioc: per adapter object
567 * @sas_device: the sas_device object
568 * Context: This function will acquire ioc->sas_device_lock.
569 *
570 * Removing object and freeing associated memory from the ioc->sas_device_list.
571 */
572static void
573_scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
574 struct _sas_device *sas_device)
575{
576 unsigned long flags;
577
Kashyap, Desai980ead32010-04-08 17:55:22 +0530578 if (!sas_device)
579 return;
580
Eric Moore635374e2009-03-09 01:21:12 -0600581 spin_lock_irqsave(&ioc->sas_device_lock, flags);
Kashyap, Desai980ead32010-04-08 17:55:22 +0530582 if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
583 sas_device->sas_address)) {
584 list_del(&sas_device->list);
585 kfree(sas_device);
586 }
Eric Moore635374e2009-03-09 01:21:12 -0600587 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
588}
589
590/**
591 * _scsih_sas_device_add - insert sas_device to the list.
592 * @ioc: per adapter object
593 * @sas_device: the sas_device object
594 * Context: This function will acquire ioc->sas_device_lock.
595 *
596 * Adding new object to the ioc->sas_device_list.
597 */
598static void
599_scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
600 struct _sas_device *sas_device)
601{
602 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -0600603
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530604 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600605 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
606 sas_device->handle, (unsigned long long)sas_device->sas_address));
607
608 spin_lock_irqsave(&ioc->sas_device_lock, flags);
609 list_add_tail(&sas_device->list, &ioc->sas_device_list);
610 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
611
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530612 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
613 sas_device->sas_address_parent))
Eric Moore635374e2009-03-09 01:21:12 -0600614 _scsih_sas_device_remove(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -0600615}
616
617/**
618 * _scsih_sas_device_init_add - insert sas_device to the list.
619 * @ioc: per adapter object
620 * @sas_device: the sas_device object
621 * Context: This function will acquire ioc->sas_device_lock.
622 *
623 * Adding new object at driver load time to the ioc->sas_device_init_list.
624 */
625static void
626_scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
627 struct _sas_device *sas_device)
628{
629 unsigned long flags;
630
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530631 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600632 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
633 sas_device->handle, (unsigned long long)sas_device->sas_address));
634
635 spin_lock_irqsave(&ioc->sas_device_lock, flags);
636 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
637 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
638 _scsih_determine_boot_device(ioc, sas_device, 0);
639}
640
641/**
Eric Moore635374e2009-03-09 01:21:12 -0600642 * _scsih_raid_device_find_by_id - raid device search
643 * @ioc: per adapter object
644 * @id: sas device target id
645 * @channel: sas device channel
646 * Context: Calling function should acquire ioc->raid_device_lock
647 *
648 * This searches for raid_device based on target id, then return raid_device
649 * object.
650 */
651static struct _raid_device *
652_scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
653{
654 struct _raid_device *raid_device, *r;
655
656 r = NULL;
657 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
658 if (raid_device->id == id && raid_device->channel == channel) {
659 r = raid_device;
660 goto out;
661 }
662 }
663
664 out:
665 return r;
666}
667
668/**
669 * _scsih_raid_device_find_by_handle - raid device search
670 * @ioc: per adapter object
671 * @handle: sas device handle (assigned by firmware)
672 * Context: Calling function should acquire ioc->raid_device_lock
673 *
674 * This searches for raid_device based on handle, then return raid_device
675 * object.
676 */
677static struct _raid_device *
678_scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
679{
680 struct _raid_device *raid_device, *r;
681
682 r = NULL;
683 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
684 if (raid_device->handle != handle)
685 continue;
686 r = raid_device;
687 goto out;
688 }
689
690 out:
691 return r;
692}
693
694/**
695 * _scsih_raid_device_find_by_wwid - raid device search
696 * @ioc: per adapter object
697 * @handle: sas device handle (assigned by firmware)
698 * Context: Calling function should acquire ioc->raid_device_lock
699 *
700 * This searches for raid_device based on wwid, then return raid_device
701 * object.
702 */
703static struct _raid_device *
704_scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
705{
706 struct _raid_device *raid_device, *r;
707
708 r = NULL;
709 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
710 if (raid_device->wwid != wwid)
711 continue;
712 r = raid_device;
713 goto out;
714 }
715
716 out:
717 return r;
718}
719
720/**
721 * _scsih_raid_device_add - add raid_device object
722 * @ioc: per adapter object
723 * @raid_device: raid_device object
724 *
725 * This is added to the raid_device_list link list.
726 */
727static void
728_scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
729 struct _raid_device *raid_device)
730{
731 unsigned long flags;
732
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530733 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600734 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
735 raid_device->handle, (unsigned long long)raid_device->wwid));
736
737 spin_lock_irqsave(&ioc->raid_device_lock, flags);
738 list_add_tail(&raid_device->list, &ioc->raid_device_list);
739 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
740}
741
742/**
743 * _scsih_raid_device_remove - delete raid_device object
744 * @ioc: per adapter object
745 * @raid_device: raid_device object
746 *
747 * This is removed from the raid_device_list link list.
748 */
749static void
750_scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
751 struct _raid_device *raid_device)
752{
753 unsigned long flags;
754
755 spin_lock_irqsave(&ioc->raid_device_lock, flags);
756 list_del(&raid_device->list);
757 memset(raid_device, 0, sizeof(struct _raid_device));
758 kfree(raid_device);
759 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
760}
761
762/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530763 * mpt2sas_scsih_expander_find_by_handle - expander device search
764 * @ioc: per adapter object
765 * @handle: expander handle (assigned by firmware)
766 * Context: Calling function should acquire ioc->sas_device_lock
767 *
768 * This searches for expander device based on handle, then returns the
769 * sas_node object.
770 */
771struct _sas_node *
772mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
773{
774 struct _sas_node *sas_expander, *r;
775
776 r = NULL;
777 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
778 if (sas_expander->handle != handle)
779 continue;
780 r = sas_expander;
781 goto out;
782 }
783 out:
784 return r;
785}
786
787/**
Eric Moore635374e2009-03-09 01:21:12 -0600788 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
789 * @ioc: per adapter object
790 * @sas_address: sas address
791 * Context: Calling function should acquire ioc->sas_node_lock.
792 *
793 * This searches for expander device based on sas_address, then returns the
794 * sas_node object.
795 */
796struct _sas_node *
797mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
798 u64 sas_address)
799{
800 struct _sas_node *sas_expander, *r;
801
802 r = NULL;
803 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
804 if (sas_expander->sas_address != sas_address)
805 continue;
806 r = sas_expander;
807 goto out;
808 }
809 out:
810 return r;
811}
812
813/**
814 * _scsih_expander_node_add - insert expander device to the list.
815 * @ioc: per adapter object
816 * @sas_expander: the sas_device object
817 * Context: This function will acquire ioc->sas_node_lock.
818 *
819 * Adding new object to the ioc->sas_expander_list.
820 *
821 * Return nothing.
822 */
823static void
824_scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
825 struct _sas_node *sas_expander)
826{
827 unsigned long flags;
828
829 spin_lock_irqsave(&ioc->sas_node_lock, flags);
830 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
831 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
832}
833
834/**
835 * _scsih_is_end_device - determines if device is an end device
836 * @device_info: bitfield providing information about the device.
837 * Context: none
838 *
839 * Returns 1 if end device.
840 */
841static int
842_scsih_is_end_device(u32 device_info)
843{
844 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
845 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
846 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
847 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
848 return 1;
849 else
850 return 0;
851}
852
853/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530854 * _scsih_scsi_lookup_get - returns scmd entry
Eric Moore635374e2009-03-09 01:21:12 -0600855 * @ioc: per adapter object
856 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -0600857 *
858 * Returns the smid stored scmd pointer.
859 */
860static struct scsi_cmnd *
861_scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
862{
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530863 return ioc->scsi_lookup[smid - 1].scmd;
Eric Moore635374e2009-03-09 01:21:12 -0600864}
865
866/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530867 * _scsih_scsi_lookup_get_clear - returns scmd entry
868 * @ioc: per adapter object
869 * @smid: system request message index
870 *
871 * Returns the smid stored scmd pointer.
872 * Then will derefrence the stored scmd pointer.
873 */
874static inline struct scsi_cmnd *
875_scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
876{
877 unsigned long flags;
878 struct scsi_cmnd *scmd;
879
880 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
881 scmd = ioc->scsi_lookup[smid - 1].scmd;
882 ioc->scsi_lookup[smid - 1].scmd = NULL;
883 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
884
885 return scmd;
886}
887
888/**
Eric Moore635374e2009-03-09 01:21:12 -0600889 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
890 * @ioc: per adapter object
891 * @smid: system request message index
892 * @scmd: pointer to scsi command object
893 * Context: This function will acquire ioc->scsi_lookup_lock.
894 *
895 * This will search for a scmd pointer in the scsi_lookup array,
896 * returning the revelent smid. A returned value of zero means invalid.
897 */
898static u16
899_scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
900 *scmd)
901{
902 u16 smid;
903 unsigned long flags;
904 int i;
905
906 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
907 smid = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530908 for (i = 0; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600909 if (ioc->scsi_lookup[i].scmd == scmd) {
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530910 smid = ioc->scsi_lookup[i].smid;
Eric Moore635374e2009-03-09 01:21:12 -0600911 goto out;
912 }
913 }
914 out:
915 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
916 return smid;
917}
918
919/**
920 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
921 * @ioc: per adapter object
922 * @id: target id
923 * @channel: channel
924 * Context: This function will acquire ioc->scsi_lookup_lock.
925 *
926 * This will search for a matching channel:id in the scsi_lookup array,
927 * returning 1 if found.
928 */
929static u8
930_scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
931 int channel)
932{
933 u8 found;
934 unsigned long flags;
935 int i;
936
937 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
938 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530939 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600940 if (ioc->scsi_lookup[i].scmd &&
941 (ioc->scsi_lookup[i].scmd->device->id == id &&
942 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
943 found = 1;
944 goto out;
945 }
946 }
947 out:
948 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
949 return found;
950}
951
952/**
Eric Moore993e0da2009-05-18 13:00:45 -0600953 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
954 * @ioc: per adapter object
955 * @id: target id
956 * @lun: lun number
957 * @channel: channel
958 * Context: This function will acquire ioc->scsi_lookup_lock.
959 *
960 * This will search for a matching channel:id:lun in the scsi_lookup array,
961 * returning 1 if found.
962 */
963static u8
964_scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
965 unsigned int lun, int channel)
966{
967 u8 found;
968 unsigned long flags;
969 int i;
970
971 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
972 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530973 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore993e0da2009-05-18 13:00:45 -0600974 if (ioc->scsi_lookup[i].scmd &&
975 (ioc->scsi_lookup[i].scmd->device->id == id &&
976 ioc->scsi_lookup[i].scmd->device->channel == channel &&
977 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
978 found = 1;
979 goto out;
980 }
981 }
982 out:
983 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
984 return found;
985}
986
987/**
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530988 * _scsih_get_chain_buffer_tracker - obtain chain tracker
Eric Moore635374e2009-03-09 01:21:12 -0600989 * @ioc: per adapter object
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530990 * @smid: smid associated to an IO request
Eric Moore635374e2009-03-09 01:21:12 -0600991 *
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530992 * Returns chain tracker(from ioc->free_chain_list)
Eric Moore635374e2009-03-09 01:21:12 -0600993 */
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530994static struct chain_tracker *
995_scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
Eric Moore635374e2009-03-09 01:21:12 -0600996{
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530997 struct chain_tracker *chain_req;
998 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -0600999
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301000 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1001 if (list_empty(&ioc->free_chain_list)) {
1002 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1003 printk(MPT2SAS_WARN_FMT "chain buffers not available\n",
1004 ioc->name);
1005 return NULL;
1006 }
1007 chain_req = list_entry(ioc->free_chain_list.next,
1008 struct chain_tracker, tracker_list);
1009 list_del_init(&chain_req->tracker_list);
1010 list_add_tail(&chain_req->tracker_list,
1011 &ioc->scsi_lookup[smid - 1].chain_list);
1012 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1013 return chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001014}
1015
1016/**
1017 * _scsih_build_scatter_gather - main sg creation routine
1018 * @ioc: per adapter object
1019 * @scmd: scsi command
1020 * @smid: system request message index
1021 * Context: none.
1022 *
1023 * The main routine that builds scatter gather table from a given
1024 * scsi request sent via the .queuecommand main handler.
1025 *
1026 * Returns 0 success, anything else error
1027 */
1028static int
1029_scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1030 struct scsi_cmnd *scmd, u16 smid)
1031{
1032 Mpi2SCSIIORequest_t *mpi_request;
1033 dma_addr_t chain_dma;
1034 struct scatterlist *sg_scmd;
1035 void *sg_local, *chain;
1036 u32 chain_offset;
1037 u32 chain_length;
1038 u32 chain_flags;
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001039 int sges_left;
Eric Moore635374e2009-03-09 01:21:12 -06001040 u32 sges_in_segment;
1041 u32 sgl_flags;
1042 u32 sgl_flags_last_element;
1043 u32 sgl_flags_end_buffer;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301044 struct chain_tracker *chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001045
1046 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1047
1048 /* init scatter gather flags */
1049 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1050 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1051 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1052 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1053 << MPI2_SGE_FLAGS_SHIFT;
1054 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1055 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1056 << MPI2_SGE_FLAGS_SHIFT;
1057 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1058
1059 sg_scmd = scsi_sglist(scmd);
1060 sges_left = scsi_dma_map(scmd);
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001061 if (sges_left < 0) {
Eric Moore635374e2009-03-09 01:21:12 -06001062 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1063 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1064 return -ENOMEM;
1065 }
1066
1067 sg_local = &mpi_request->SGL;
1068 sges_in_segment = ioc->max_sges_in_main_message;
1069 if (sges_left <= sges_in_segment)
1070 goto fill_in_last_segment;
1071
1072 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1073 (sges_in_segment * ioc->sge_size))/4;
1074
1075 /* fill in main message segment when there is a chain following */
1076 while (sges_in_segment) {
1077 if (sges_in_segment == 1)
1078 ioc->base_add_sg_single(sg_local,
1079 sgl_flags_last_element | sg_dma_len(sg_scmd),
1080 sg_dma_address(sg_scmd));
1081 else
1082 ioc->base_add_sg_single(sg_local, sgl_flags |
1083 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1084 sg_scmd = sg_next(sg_scmd);
1085 sg_local += ioc->sge_size;
1086 sges_left--;
1087 sges_in_segment--;
1088 }
1089
1090 /* initializing the chain flags and pointers */
1091 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301092 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1093 if (!chain_req)
1094 return -1;
1095 chain = chain_req->chain_buffer;
1096 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001097 do {
1098 sges_in_segment = (sges_left <=
1099 ioc->max_sges_in_chain_message) ? sges_left :
1100 ioc->max_sges_in_chain_message;
1101 chain_offset = (sges_left == sges_in_segment) ?
1102 0 : (sges_in_segment * ioc->sge_size)/4;
1103 chain_length = sges_in_segment * ioc->sge_size;
1104 if (chain_offset) {
1105 chain_offset = chain_offset <<
1106 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1107 chain_length += ioc->sge_size;
1108 }
1109 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1110 chain_length, chain_dma);
1111 sg_local = chain;
1112 if (!chain_offset)
1113 goto fill_in_last_segment;
1114
1115 /* fill in chain segments */
1116 while (sges_in_segment) {
1117 if (sges_in_segment == 1)
1118 ioc->base_add_sg_single(sg_local,
1119 sgl_flags_last_element |
1120 sg_dma_len(sg_scmd),
1121 sg_dma_address(sg_scmd));
1122 else
1123 ioc->base_add_sg_single(sg_local, sgl_flags |
1124 sg_dma_len(sg_scmd),
1125 sg_dma_address(sg_scmd));
1126 sg_scmd = sg_next(sg_scmd);
1127 sg_local += ioc->sge_size;
1128 sges_left--;
1129 sges_in_segment--;
1130 }
1131
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301132 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1133 if (!chain_req)
1134 return -1;
1135 chain = chain_req->chain_buffer;
1136 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001137 } while (1);
1138
1139
1140 fill_in_last_segment:
1141
1142 /* fill the last segment */
1143 while (sges_left) {
1144 if (sges_left == 1)
1145 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1146 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1147 else
1148 ioc->base_add_sg_single(sg_local, sgl_flags |
1149 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1150 sg_scmd = sg_next(sg_scmd);
1151 sg_local += ioc->sge_size;
1152 sges_left--;
1153 }
1154
1155 return 0;
1156}
1157
1158/**
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301159 * _scsih_adjust_queue_depth - setting device queue depth
Eric Moore635374e2009-03-09 01:21:12 -06001160 * @sdev: scsi device struct
1161 * @qdepth: requested queue depth
1162 *
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301163 *
1164 * Returns nothing
Eric Moore635374e2009-03-09 01:21:12 -06001165 */
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301166static void
1167_scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
Eric Moore635374e2009-03-09 01:21:12 -06001168{
1169 struct Scsi_Host *shost = sdev->host;
1170 int max_depth;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301171 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1172 struct MPT2SAS_DEVICE *sas_device_priv_data;
1173 struct MPT2SAS_TARGET *sas_target_priv_data;
1174 struct _sas_device *sas_device;
1175 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001176
1177 max_depth = shost->can_queue;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301178
1179 /* limit max device queue for SATA to 32 */
1180 sas_device_priv_data = sdev->hostdata;
1181 if (!sas_device_priv_data)
1182 goto not_sata;
1183 sas_target_priv_data = sas_device_priv_data->sas_target;
1184 if (!sas_target_priv_data)
1185 goto not_sata;
1186 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1187 goto not_sata;
1188 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1189 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1190 sas_device_priv_data->sas_target->sas_address);
1191 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1192 if (sas_device && sas_device->device_info &
1193 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1194 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
1195
1196 not_sata:
1197
Eric Moore635374e2009-03-09 01:21:12 -06001198 if (!sdev->tagged_supported)
1199 max_depth = 1;
1200 if (qdepth > max_depth)
1201 qdepth = max_depth;
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301202 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1203}
1204
1205/**
1206 * _scsih_change_queue_depth - setting device queue depth
1207 * @sdev: scsi device struct
1208 * @qdepth: requested queue depth
1209 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1210 * (see include/scsi/scsi_host.h for definition)
1211 *
1212 * Returns queue depth.
1213 */
1214static int
1215_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1216{
1217 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1218 _scsih_adjust_queue_depth(sdev, qdepth);
1219 else if (reason == SCSI_QDEPTH_QFULL)
1220 scsi_track_queue_full(sdev, qdepth);
1221 else
1222 return -EOPNOTSUPP;
Eric Moore635374e2009-03-09 01:21:12 -06001223
1224 if (sdev->inquiry_len > 7)
1225 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1226 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1227 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1228 sdev->ordered_tags, sdev->scsi_level,
1229 (sdev->inquiry[7] & 2) >> 1);
1230
1231 return sdev->queue_depth;
1232}
1233
1234/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301235 * _scsih_change_queue_type - changing device queue tag type
Eric Moore635374e2009-03-09 01:21:12 -06001236 * @sdev: scsi device struct
1237 * @tag_type: requested tag type
1238 *
1239 * Returns queue tag type.
1240 */
1241static int
Eric Moored5d135b2009-05-18 13:02:08 -06001242_scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
Eric Moore635374e2009-03-09 01:21:12 -06001243{
1244 if (sdev->tagged_supported) {
1245 scsi_set_tag_type(sdev, tag_type);
1246 if (tag_type)
1247 scsi_activate_tcq(sdev, sdev->queue_depth);
1248 else
1249 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1250 } else
1251 tag_type = 0;
1252
1253 return tag_type;
1254}
1255
1256/**
Eric Moored5d135b2009-05-18 13:02:08 -06001257 * _scsih_target_alloc - target add routine
Eric Moore635374e2009-03-09 01:21:12 -06001258 * @starget: scsi target struct
1259 *
1260 * Returns 0 if ok. Any other return is assumed to be an error and
1261 * the device is ignored.
1262 */
1263static int
Eric Moored5d135b2009-05-18 13:02:08 -06001264_scsih_target_alloc(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001265{
1266 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1267 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1268 struct MPT2SAS_TARGET *sas_target_priv_data;
1269 struct _sas_device *sas_device;
1270 struct _raid_device *raid_device;
1271 unsigned long flags;
1272 struct sas_rphy *rphy;
1273
1274 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1275 if (!sas_target_priv_data)
1276 return -ENOMEM;
1277
1278 starget->hostdata = sas_target_priv_data;
1279 sas_target_priv_data->starget = starget;
1280 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1281
1282 /* RAID volumes */
1283 if (starget->channel == RAID_CHANNEL) {
1284 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1285 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1286 starget->channel);
1287 if (raid_device) {
1288 sas_target_priv_data->handle = raid_device->handle;
1289 sas_target_priv_data->sas_address = raid_device->wwid;
1290 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301291 sas_target_priv_data->raid_device = raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001292 raid_device->starget = starget;
1293 }
1294 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1295 return 0;
1296 }
1297
1298 /* sas/sata devices */
1299 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1300 rphy = dev_to_rphy(starget->dev.parent);
1301 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1302 rphy->identify.sas_address);
1303
1304 if (sas_device) {
1305 sas_target_priv_data->handle = sas_device->handle;
1306 sas_target_priv_data->sas_address = sas_device->sas_address;
1307 sas_device->starget = starget;
1308 sas_device->id = starget->id;
1309 sas_device->channel = starget->channel;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05301310 if (test_bit(sas_device->handle, ioc->pd_handles))
Eric Moore635374e2009-03-09 01:21:12 -06001311 sas_target_priv_data->flags |=
1312 MPT_TARGET_FLAGS_RAID_COMPONENT;
1313 }
1314 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1315
1316 return 0;
1317}
1318
1319/**
Eric Moored5d135b2009-05-18 13:02:08 -06001320 * _scsih_target_destroy - target destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001321 * @starget: scsi target struct
1322 *
1323 * Returns nothing.
1324 */
1325static void
Eric Moored5d135b2009-05-18 13:02:08 -06001326_scsih_target_destroy(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001327{
1328 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1329 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1330 struct MPT2SAS_TARGET *sas_target_priv_data;
1331 struct _sas_device *sas_device;
1332 struct _raid_device *raid_device;
1333 unsigned long flags;
1334 struct sas_rphy *rphy;
1335
1336 sas_target_priv_data = starget->hostdata;
1337 if (!sas_target_priv_data)
1338 return;
1339
1340 if (starget->channel == RAID_CHANNEL) {
1341 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1342 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1343 starget->channel);
1344 if (raid_device) {
1345 raid_device->starget = NULL;
1346 raid_device->sdev = NULL;
1347 }
1348 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1349 goto out;
1350 }
1351
1352 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1353 rphy = dev_to_rphy(starget->dev.parent);
1354 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1355 rphy->identify.sas_address);
Eric Moore8901cbb2009-04-21 15:41:32 -06001356 if (sas_device && (sas_device->starget == starget) &&
1357 (sas_device->id == starget->id) &&
1358 (sas_device->channel == starget->channel))
Eric Moore635374e2009-03-09 01:21:12 -06001359 sas_device->starget = NULL;
1360
1361 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1362
1363 out:
1364 kfree(sas_target_priv_data);
1365 starget->hostdata = NULL;
1366}
1367
1368/**
Eric Moored5d135b2009-05-18 13:02:08 -06001369 * _scsih_slave_alloc - device add routine
Eric Moore635374e2009-03-09 01:21:12 -06001370 * @sdev: scsi device struct
1371 *
1372 * Returns 0 if ok. Any other return is assumed to be an error and
1373 * the device is ignored.
1374 */
1375static int
Eric Moored5d135b2009-05-18 13:02:08 -06001376_scsih_slave_alloc(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001377{
1378 struct Scsi_Host *shost;
1379 struct MPT2SAS_ADAPTER *ioc;
1380 struct MPT2SAS_TARGET *sas_target_priv_data;
1381 struct MPT2SAS_DEVICE *sas_device_priv_data;
1382 struct scsi_target *starget;
1383 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001384 unsigned long flags;
1385
1386 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1387 if (!sas_device_priv_data)
1388 return -ENOMEM;
1389
1390 sas_device_priv_data->lun = sdev->lun;
1391 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1392
1393 starget = scsi_target(sdev);
1394 sas_target_priv_data = starget->hostdata;
1395 sas_target_priv_data->num_luns++;
1396 sas_device_priv_data->sas_target = sas_target_priv_data;
1397 sdev->hostdata = sas_device_priv_data;
1398 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1399 sdev->no_uld_attach = 1;
1400
1401 shost = dev_to_shost(&starget->dev);
1402 ioc = shost_priv(shost);
1403 if (starget->channel == RAID_CHANNEL) {
1404 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1405 raid_device = _scsih_raid_device_find_by_id(ioc,
1406 starget->id, starget->channel);
1407 if (raid_device)
1408 raid_device->sdev = sdev; /* raid is single lun */
1409 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06001410 }
1411
Eric Moore635374e2009-03-09 01:21:12 -06001412 return 0;
1413}
1414
1415/**
Eric Moored5d135b2009-05-18 13:02:08 -06001416 * _scsih_slave_destroy - device destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001417 * @sdev: scsi device struct
1418 *
1419 * Returns nothing.
1420 */
1421static void
Eric Moored5d135b2009-05-18 13:02:08 -06001422_scsih_slave_destroy(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001423{
1424 struct MPT2SAS_TARGET *sas_target_priv_data;
1425 struct scsi_target *starget;
1426
1427 if (!sdev->hostdata)
1428 return;
1429
1430 starget = scsi_target(sdev);
1431 sas_target_priv_data = starget->hostdata;
1432 sas_target_priv_data->num_luns--;
1433 kfree(sdev->hostdata);
1434 sdev->hostdata = NULL;
1435}
1436
1437/**
Eric Moored5d135b2009-05-18 13:02:08 -06001438 * _scsih_display_sata_capabilities - sata capabilities
Eric Moore635374e2009-03-09 01:21:12 -06001439 * @ioc: per adapter object
1440 * @sas_device: the sas_device object
1441 * @sdev: scsi device struct
1442 */
1443static void
Eric Moored5d135b2009-05-18 13:02:08 -06001444_scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
Eric Moore635374e2009-03-09 01:21:12 -06001445 struct _sas_device *sas_device, struct scsi_device *sdev)
1446{
1447 Mpi2ConfigReply_t mpi_reply;
1448 Mpi2SasDevicePage0_t sas_device_pg0;
1449 u32 ioc_status;
1450 u16 flags;
1451 u32 device_info;
1452
1453 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1454 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
1455 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1456 ioc->name, __FILE__, __LINE__, __func__);
1457 return;
1458 }
1459
1460 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1461 MPI2_IOCSTATUS_MASK;
1462 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1463 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1464 ioc->name, __FILE__, __LINE__, __func__);
1465 return;
1466 }
1467
1468 flags = le16_to_cpu(sas_device_pg0.Flags);
Kashyap, Desaie94f6742010-03-17 16:24:52 +05301469 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
Eric Moore635374e2009-03-09 01:21:12 -06001470
1471 sdev_printk(KERN_INFO, sdev,
1472 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1473 "sw_preserve(%s)\n",
1474 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1475 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1476 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1477 "n",
1478 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1479 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1480 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1481}
1482
1483/**
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301484 * _scsih_is_raid - return boolean indicating device is raid volume
1485 * @dev the device struct object
1486 */
1487static int
1488_scsih_is_raid(struct device *dev)
1489{
1490 struct scsi_device *sdev = to_scsi_device(dev);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301491 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301492
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301493 if (ioc->is_warpdrive)
1494 return 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301495 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1496}
1497
1498/**
1499 * _scsih_get_resync - get raid volume resync percent complete
1500 * @dev the device struct object
1501 */
1502static void
1503_scsih_get_resync(struct device *dev)
1504{
1505 struct scsi_device *sdev = to_scsi_device(dev);
1506 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1507 static struct _raid_device *raid_device;
1508 unsigned long flags;
1509 Mpi2RaidVolPage0_t vol_pg0;
1510 Mpi2ConfigReply_t mpi_reply;
1511 u32 volume_status_flags;
1512 u8 percent_complete = 0;
1513
1514 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1515 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1516 sdev->channel);
1517 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1518
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301519 if (!raid_device || ioc->is_warpdrive)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301520 goto out;
1521
1522 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1523 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1524 sizeof(Mpi2RaidVolPage0_t))) {
1525 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1526 ioc->name, __FILE__, __LINE__, __func__);
1527 goto out;
1528 }
1529
1530 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1531 if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
1532 percent_complete = raid_device->percent_complete;
1533 out:
1534 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1535}
1536
1537/**
1538 * _scsih_get_state - get raid volume level
1539 * @dev the device struct object
1540 */
1541static void
1542_scsih_get_state(struct device *dev)
1543{
1544 struct scsi_device *sdev = to_scsi_device(dev);
1545 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1546 static struct _raid_device *raid_device;
1547 unsigned long flags;
1548 Mpi2RaidVolPage0_t vol_pg0;
1549 Mpi2ConfigReply_t mpi_reply;
1550 u32 volstate;
1551 enum raid_state state = RAID_STATE_UNKNOWN;
1552
1553 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1554 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1555 sdev->channel);
1556 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1557
1558 if (!raid_device)
1559 goto out;
1560
1561 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1562 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1563 sizeof(Mpi2RaidVolPage0_t))) {
1564 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1565 ioc->name, __FILE__, __LINE__, __func__);
1566 goto out;
1567 }
1568
1569 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1570 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1571 state = RAID_STATE_RESYNCING;
1572 goto out;
1573 }
1574
1575 switch (vol_pg0.VolumeState) {
1576 case MPI2_RAID_VOL_STATE_OPTIMAL:
1577 case MPI2_RAID_VOL_STATE_ONLINE:
1578 state = RAID_STATE_ACTIVE;
1579 break;
1580 case MPI2_RAID_VOL_STATE_DEGRADED:
1581 state = RAID_STATE_DEGRADED;
1582 break;
1583 case MPI2_RAID_VOL_STATE_FAILED:
1584 case MPI2_RAID_VOL_STATE_MISSING:
1585 state = RAID_STATE_OFFLINE;
1586 break;
1587 }
1588 out:
1589 raid_set_state(mpt2sas_raid_template, dev, state);
1590}
1591
1592/**
1593 * _scsih_set_level - set raid level
1594 * @sdev: scsi device struct
1595 * @raid_device: raid_device object
1596 */
1597static void
1598_scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device)
1599{
1600 enum raid_level level = RAID_LEVEL_UNKNOWN;
1601
1602 switch (raid_device->volume_type) {
1603 case MPI2_RAID_VOL_TYPE_RAID0:
1604 level = RAID_LEVEL_0;
1605 break;
1606 case MPI2_RAID_VOL_TYPE_RAID10:
1607 level = RAID_LEVEL_10;
1608 break;
1609 case MPI2_RAID_VOL_TYPE_RAID1E:
1610 level = RAID_LEVEL_1E;
1611 break;
1612 case MPI2_RAID_VOL_TYPE_RAID1:
1613 level = RAID_LEVEL_1;
1614 break;
1615 }
1616
1617 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1618}
1619
1620/**
Eric Moore635374e2009-03-09 01:21:12 -06001621 * _scsih_get_volume_capabilities - volume capabilities
1622 * @ioc: per adapter object
1623 * @sas_device: the raid_device object
1624 */
1625static void
1626_scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1627 struct _raid_device *raid_device)
1628{
1629 Mpi2RaidVolPage0_t *vol_pg0;
1630 Mpi2RaidPhysDiskPage0_t pd_pg0;
1631 Mpi2SasDevicePage0_t sas_device_pg0;
1632 Mpi2ConfigReply_t mpi_reply;
1633 u16 sz;
1634 u8 num_pds;
1635
1636 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1637 &num_pds)) || !num_pds) {
1638 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1639 ioc->name, __FILE__, __LINE__, __func__);
1640 return;
1641 }
1642
1643 raid_device->num_pds = num_pds;
1644 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1645 sizeof(Mpi2RaidVol0PhysDisk_t));
1646 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1647 if (!vol_pg0) {
1648 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1649 ioc->name, __FILE__, __LINE__, __func__);
1650 return;
1651 }
1652
1653 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1654 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1655 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1656 ioc->name, __FILE__, __LINE__, __func__);
1657 kfree(vol_pg0);
1658 return;
1659 }
1660
1661 raid_device->volume_type = vol_pg0->VolumeType;
1662
1663 /* figure out what the underlying devices are by
1664 * obtaining the device_info bits for the 1st device
1665 */
1666 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1667 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1668 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1669 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1670 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1671 le16_to_cpu(pd_pg0.DevHandle)))) {
1672 raid_device->device_info =
1673 le32_to_cpu(sas_device_pg0.DeviceInfo);
1674 }
1675 }
1676
1677 kfree(vol_pg0);
1678}
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301679/**
1680 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1681 * @ioc: per adapter object
1682 */
1683static void
1684_scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1685{
1686 Mpi2RaidVolPage1_t vol_pg1;
1687 Mpi2ConfigReply_t mpi_reply;
1688 struct _raid_device *raid_device;
1689 u16 handle;
1690 u16 ioc_status;
1691
1692 handle = 0xFFFF;
1693 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1694 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1695 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1696 MPI2_IOCSTATUS_MASK;
1697 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1698 break;
1699 handle = le16_to_cpu(vol_pg1.DevHandle);
1700 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1701 if (raid_device)
1702 raid_device->direct_io_enabled = 0;
1703 }
1704 return;
1705}
1706
1707
1708/**
1709 * _scsih_get_num_volumes - Get number of volumes in the ioc
1710 * @ioc: per adapter object
1711 */
1712static u8
1713_scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1714{
1715 Mpi2RaidVolPage1_t vol_pg1;
1716 Mpi2ConfigReply_t mpi_reply;
1717 u16 handle;
1718 u8 vol_cnt = 0;
1719 u16 ioc_status;
1720
1721 handle = 0xFFFF;
1722 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1723 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1724 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1725 MPI2_IOCSTATUS_MASK;
1726 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1727 break;
1728 vol_cnt++;
1729 handle = le16_to_cpu(vol_pg1.DevHandle);
1730 }
1731 return vol_cnt;
1732}
1733
1734
1735/**
1736 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1737 * @ioc: per adapter object
1738 * @raid_device: the raid_device object
1739 */
1740static void
1741_scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1742 struct _raid_device *raid_device)
1743{
1744 Mpi2RaidVolPage0_t *vol_pg0;
1745 Mpi2RaidPhysDiskPage0_t pd_pg0;
1746 Mpi2ConfigReply_t mpi_reply;
1747 u16 sz;
1748 u8 num_pds, count;
1749 u64 mb = 1024 * 1024;
1750 u64 tb_2 = 2 * mb * mb;
1751 u64 capacity;
1752 u32 stripe_sz;
1753 u8 i, stripe_exp;
1754
1755 if (!ioc->is_warpdrive)
1756 return;
1757
1758 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1759 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1760 "globally as drives are exposed\n", ioc->name);
1761 return;
1762 }
1763 if (_scsih_get_num_volumes(ioc) > 1) {
1764 _scsih_disable_ddio(ioc);
1765 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1766 "globally as number of drives > 1\n", ioc->name);
1767 return;
1768 }
1769 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1770 &num_pds)) || !num_pds) {
1771 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1772 "Failure in computing number of drives\n", ioc->name);
1773 return;
1774 }
1775
1776 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1777 sizeof(Mpi2RaidVol0PhysDisk_t));
1778 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1779 if (!vol_pg0) {
1780 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1781 "Memory allocation failure for RVPG0\n", ioc->name);
1782 return;
1783 }
1784
1785 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1786 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1787 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1788 "Failure in retrieving RVPG0\n", ioc->name);
1789 kfree(vol_pg0);
1790 return;
1791 }
1792
1793 /*
1794 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1795 * assumed for WARPDRIVE, disable direct I/O
1796 */
1797 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1798 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1799 "for the drive with handle(0x%04x): num_mem=%d, "
1800 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1801 num_pds, MPT_MAX_WARPDRIVE_PDS);
1802 kfree(vol_pg0);
1803 return;
1804 }
1805 for (count = 0; count < num_pds; count++) {
1806 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1807 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1808 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1809 pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) {
1810 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1811 "disabled for the drive with handle(0x%04x) member"
1812 "handle retrieval failed for member number=%d\n",
1813 ioc->name, raid_device->handle,
1814 vol_pg0->PhysDisk[count].PhysDiskNum);
1815 goto out_error;
1816 }
1817 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1818 }
1819
1820 /*
1821 * Assumption for WD: Direct I/O is not supported if the volume is
1822 * not RAID0, if the stripe size is not 64KB, if the block size is
1823 * not 512 and if the volume size is >2TB
1824 */
1825 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0 ||
1826 le16_to_cpu(vol_pg0->BlockSize) != 512) {
1827 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1828 "for the drive with handle(0x%04x): type=%d, "
1829 "s_sz=%uK, blk_size=%u\n", ioc->name,
1830 raid_device->handle, raid_device->volume_type,
1831 le32_to_cpu(vol_pg0->StripeSize)/2,
1832 le16_to_cpu(vol_pg0->BlockSize));
1833 goto out_error;
1834 }
1835
1836 capacity = (u64) le16_to_cpu(vol_pg0->BlockSize) *
1837 (le64_to_cpu(vol_pg0->MaxLBA) + 1);
1838
1839 if (capacity > tb_2) {
1840 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1841 "for the drive with handle(0x%04x) since drive sz > 2TB\n",
1842 ioc->name, raid_device->handle);
1843 goto out_error;
1844 }
1845
1846 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1847 stripe_exp = 0;
1848 for (i = 0; i < 32; i++) {
1849 if (stripe_sz & 1)
1850 break;
1851 stripe_exp++;
1852 stripe_sz >>= 1;
1853 }
1854 if (i == 32) {
1855 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1856 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
1857 ioc->name, raid_device->handle,
1858 le32_to_cpu(vol_pg0->StripeSize)/2);
1859 goto out_error;
1860 }
1861 raid_device->stripe_exponent = stripe_exp;
1862 raid_device->direct_io_enabled = 1;
1863
1864 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1865 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1866 /*
1867 * WARPDRIVE: Though the following fields are not used for direct IO,
1868 * stored for future purpose:
1869 */
1870 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1871 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1872 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1873
1874
1875 kfree(vol_pg0);
1876 return;
1877
1878out_error:
1879 raid_device->direct_io_enabled = 0;
1880 for (count = 0; count < num_pds; count++)
1881 raid_device->pd_handle[count] = 0;
1882 kfree(vol_pg0);
1883 return;
1884}
Eric Moore635374e2009-03-09 01:21:12 -06001885
1886/**
Kashyap, Desai84f0b042009-12-16 18:56:28 +05301887 * _scsih_enable_tlr - setting TLR flags
1888 * @ioc: per adapter object
1889 * @sdev: scsi device struct
1890 *
1891 * Enabling Transaction Layer Retries for tape devices when
1892 * vpd page 0x90 is present
1893 *
1894 */
1895static void
1896_scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1897{
1898 /* only for TAPE */
1899 if (sdev->type != TYPE_TAPE)
1900 return;
1901
1902 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1903 return;
1904
1905 sas_enable_tlr(sdev);
1906 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1907 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1908 return;
1909
1910}
1911
1912/**
Eric Moored5d135b2009-05-18 13:02:08 -06001913 * _scsih_slave_configure - device configure routine.
Eric Moore635374e2009-03-09 01:21:12 -06001914 * @sdev: scsi device struct
1915 *
1916 * Returns 0 if ok. Any other return is assumed to be an error and
1917 * the device is ignored.
1918 */
1919static int
Eric Moored5d135b2009-05-18 13:02:08 -06001920_scsih_slave_configure(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001921{
1922 struct Scsi_Host *shost = sdev->host;
1923 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1924 struct MPT2SAS_DEVICE *sas_device_priv_data;
1925 struct MPT2SAS_TARGET *sas_target_priv_data;
1926 struct _sas_device *sas_device;
1927 struct _raid_device *raid_device;
1928 unsigned long flags;
1929 int qdepth;
1930 u8 ssp_target = 0;
1931 char *ds = "";
1932 char *r_level = "";
1933
1934 qdepth = 1;
1935 sas_device_priv_data = sdev->hostdata;
1936 sas_device_priv_data->configured_lun = 1;
1937 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1938 sas_target_priv_data = sas_device_priv_data->sas_target;
1939
1940 /* raid volume handling */
1941 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1942
1943 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1944 raid_device = _scsih_raid_device_find_by_handle(ioc,
1945 sas_target_priv_data->handle);
1946 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1947 if (!raid_device) {
1948 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1949 ioc->name, __FILE__, __LINE__, __func__);
1950 return 0;
1951 }
1952
1953 _scsih_get_volume_capabilities(ioc, raid_device);
1954
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301955 /*
1956 * WARPDRIVE: Initialize the required data for Direct IO
1957 */
1958 _scsih_init_warpdrive_properties(ioc, raid_device);
1959
Eric Moore635374e2009-03-09 01:21:12 -06001960 /* RAID Queue Depth Support
1961 * IS volume = underlying qdepth of drive type, either
1962 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1963 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1964 */
1965 if (raid_device->device_info &
1966 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1967 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1968 ds = "SSP";
1969 } else {
1970 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1971 if (raid_device->device_info &
1972 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1973 ds = "SATA";
1974 else
1975 ds = "STP";
1976 }
1977
1978 switch (raid_device->volume_type) {
1979 case MPI2_RAID_VOL_TYPE_RAID0:
1980 r_level = "RAID0";
1981 break;
1982 case MPI2_RAID_VOL_TYPE_RAID1E:
1983 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
Kashyap, Desaied79f122009-08-20 13:23:49 +05301984 if (ioc->manu_pg10.OEMIdentifier &&
Kashyap, Desaic97951e2011-06-14 10:54:56 +05301985 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
Kashyap, Desaied79f122009-08-20 13:23:49 +05301986 MFG10_GF0_R10_DISPLAY) &&
1987 !(raid_device->num_pds % 2))
1988 r_level = "RAID10";
1989 else
1990 r_level = "RAID1E";
Eric Moore635374e2009-03-09 01:21:12 -06001991 break;
1992 case MPI2_RAID_VOL_TYPE_RAID1:
1993 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1994 r_level = "RAID1";
1995 break;
1996 case MPI2_RAID_VOL_TYPE_RAID10:
1997 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1998 r_level = "RAID10";
1999 break;
2000 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2001 default:
2002 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2003 r_level = "RAIDX";
2004 break;
2005 }
2006
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302007 if (!ioc->hide_ir_msg)
2008 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2009 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2010 r_level, raid_device->handle,
2011 (unsigned long long)raid_device->wwid,
2012 raid_device->num_pds, ds);
Mike Christiee881a172009-10-15 17:46:39 -07002013 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05302014 /* raid transport support */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302015 if (!ioc->is_warpdrive)
2016 _scsih_set_level(sdev, raid_device);
Eric Moore635374e2009-03-09 01:21:12 -06002017 return 0;
2018 }
2019
2020 /* non-raid handling */
2021 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2022 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2023 sas_device_priv_data->sas_target->sas_address);
2024 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2025 if (sas_device) {
2026 if (sas_target_priv_data->flags &
2027 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2028 mpt2sas_config_get_volume_handle(ioc,
2029 sas_device->handle, &sas_device->volume_handle);
2030 mpt2sas_config_get_volume_wwid(ioc,
2031 sas_device->volume_handle,
2032 &sas_device->volume_wwid);
2033 }
2034 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2035 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2036 ssp_target = 1;
2037 ds = "SSP";
2038 } else {
2039 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2040 if (sas_device->device_info &
2041 MPI2_SAS_DEVICE_INFO_STP_TARGET)
2042 ds = "STP";
2043 else if (sas_device->device_info &
2044 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2045 ds = "SATA";
2046 }
2047
2048 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
Kashyap, Desai7fbae672010-06-17 13:45:17 +05302049 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
Eric Moore635374e2009-03-09 01:21:12 -06002050 ds, sas_device->handle,
2051 (unsigned long long)sas_device->sas_address,
Kashyap, Desai7fbae672010-06-17 13:45:17 +05302052 sas_device->phy,
Eric Moore635374e2009-03-09 01:21:12 -06002053 (unsigned long long)sas_device->device_name);
2054 sdev_printk(KERN_INFO, sdev, "%s: "
2055 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2056 (unsigned long long) sas_device->enclosure_logical_id,
2057 sas_device->slot);
2058
2059 if (!ssp_target)
Eric Moored5d135b2009-05-18 13:02:08 -06002060 _scsih_display_sata_capabilities(ioc, sas_device, sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002061 }
2062
Mike Christiee881a172009-10-15 17:46:39 -07002063 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Eric Moore635374e2009-03-09 01:21:12 -06002064
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302065 if (ssp_target) {
Eric Moore635374e2009-03-09 01:21:12 -06002066 sas_read_port_mode_page(sdev);
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302067 _scsih_enable_tlr(ioc, sdev);
2068 }
Eric Moore635374e2009-03-09 01:21:12 -06002069 return 0;
2070}
2071
2072/**
Eric Moored5d135b2009-05-18 13:02:08 -06002073 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
Eric Moore635374e2009-03-09 01:21:12 -06002074 * @sdev: scsi device struct
2075 * @bdev: pointer to block device context
2076 * @capacity: device size (in 512 byte sectors)
2077 * @params: three element array to place output:
2078 * params[0] number of heads (max 255)
2079 * params[1] number of sectors (max 63)
2080 * params[2] number of cylinders
2081 *
2082 * Return nothing.
2083 */
2084static int
Eric Moored5d135b2009-05-18 13:02:08 -06002085_scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
Eric Moore635374e2009-03-09 01:21:12 -06002086 sector_t capacity, int params[])
2087{
2088 int heads;
2089 int sectors;
2090 sector_t cylinders;
2091 ulong dummy;
2092
2093 heads = 64;
2094 sectors = 32;
2095
2096 dummy = heads * sectors;
2097 cylinders = capacity;
2098 sector_div(cylinders, dummy);
2099
2100 /*
2101 * Handle extended translation size for logical drives
2102 * > 1Gb
2103 */
2104 if ((ulong)capacity >= 0x200000) {
2105 heads = 255;
2106 sectors = 63;
2107 dummy = heads * sectors;
2108 cylinders = capacity;
2109 sector_div(cylinders, dummy);
2110 }
2111
2112 /* return result */
2113 params[0] = heads;
2114 params[1] = sectors;
2115 params[2] = cylinders;
2116
2117 return 0;
2118}
2119
2120/**
2121 * _scsih_response_code - translation of device response code
2122 * @ioc: per adapter object
2123 * @response_code: response code returned by the device
2124 *
2125 * Return nothing.
2126 */
2127static void
2128_scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2129{
2130 char *desc;
2131
2132 switch (response_code) {
2133 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2134 desc = "task management request completed";
2135 break;
2136 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2137 desc = "invalid frame";
2138 break;
2139 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2140 desc = "task management request not supported";
2141 break;
2142 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2143 desc = "task management request failed";
2144 break;
2145 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2146 desc = "task management request succeeded";
2147 break;
2148 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2149 desc = "invalid lun";
2150 break;
2151 case 0xA:
2152 desc = "overlapped tag attempted";
2153 break;
2154 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2155 desc = "task queued, however not sent to target";
2156 break;
2157 default:
2158 desc = "unknown";
2159 break;
2160 }
2161 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2162 ioc->name, response_code, desc);
2163}
2164
2165/**
Eric Moored5d135b2009-05-18 13:02:08 -06002166 * _scsih_tm_done - tm completion routine
Eric Moore635374e2009-03-09 01:21:12 -06002167 * @ioc: per adapter object
2168 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302169 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002170 * @reply: reply message frame(lower 32bit addr)
2171 * Context: none.
2172 *
2173 * The callback handler when using scsih_issue_tm.
2174 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302175 * Return 1 meaning mf should be freed from _base_interrupt
2176 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06002177 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302178static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302179_scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06002180{
2181 MPI2DefaultReply_t *mpi_reply;
2182
2183 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302184 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002185 if (ioc->tm_cmds.smid != smid)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302186 return 1;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05302187 mpt2sas_base_flush_reply_queues(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06002188 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2189 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2190 if (mpi_reply) {
2191 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2192 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2193 }
2194 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2195 complete(&ioc->tm_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302196 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002197}
2198
2199/**
2200 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2201 * @ioc: per adapter object
2202 * @handle: device handle
2203 *
2204 * During taskmangement request, we need to freeze the device queue.
2205 */
2206void
2207mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2208{
2209 struct MPT2SAS_DEVICE *sas_device_priv_data;
2210 struct scsi_device *sdev;
2211 u8 skip = 0;
2212
2213 shost_for_each_device(sdev, ioc->shost) {
2214 if (skip)
2215 continue;
2216 sas_device_priv_data = sdev->hostdata;
2217 if (!sas_device_priv_data)
2218 continue;
2219 if (sas_device_priv_data->sas_target->handle == handle) {
2220 sas_device_priv_data->sas_target->tm_busy = 1;
2221 skip = 1;
2222 ioc->ignore_loginfos = 1;
2223 }
2224 }
2225}
2226
2227/**
2228 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2229 * @ioc: per adapter object
2230 * @handle: device handle
2231 *
2232 * During taskmangement request, we need to freeze the device queue.
2233 */
2234void
2235mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2236{
2237 struct MPT2SAS_DEVICE *sas_device_priv_data;
2238 struct scsi_device *sdev;
2239 u8 skip = 0;
2240
2241 shost_for_each_device(sdev, ioc->shost) {
2242 if (skip)
2243 continue;
2244 sas_device_priv_data = sdev->hostdata;
2245 if (!sas_device_priv_data)
2246 continue;
2247 if (sas_device_priv_data->sas_target->handle == handle) {
2248 sas_device_priv_data->sas_target->tm_busy = 0;
2249 skip = 1;
2250 ioc->ignore_loginfos = 0;
2251 }
2252 }
2253}
2254
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302255
Eric Moore635374e2009-03-09 01:21:12 -06002256/**
2257 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2258 * @ioc: per adapter struct
2259 * @device_handle: device handle
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302260 * @channel: the channel assigned by the OS
2261 * @id: the id assigned by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002262 * @lun: lun number
2263 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2264 * @smid_task: smid assigned to the task
2265 * @timeout: timeout in seconds
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302266 * @serial_number: the serial_number from scmd
2267 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302268 * Context: user
Eric Moore635374e2009-03-09 01:21:12 -06002269 *
2270 * A generic API for sending task management requests to firmware.
2271 *
Eric Moore635374e2009-03-09 01:21:12 -06002272 * The callback index is set inside `ioc->tm_cb_idx`.
2273 *
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302274 * Return SUCCESS or FAILED.
Eric Moore635374e2009-03-09 01:21:12 -06002275 */
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302276int
2277mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2278 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302279 unsigned long serial_number, enum mutex_type m_type)
Eric Moore635374e2009-03-09 01:21:12 -06002280{
2281 Mpi2SCSITaskManagementRequest_t *mpi_request;
2282 Mpi2SCSITaskManagementReply_t *mpi_reply;
2283 u16 smid = 0;
2284 u32 ioc_state;
2285 unsigned long timeleft;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302286 struct scsiio_tracker *scsi_lookup = NULL;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302287 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06002288
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302289 if (m_type == TM_MUTEX_ON)
2290 mutex_lock(&ioc->tm_cmds.mutex);
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302291 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2292 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2293 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302294 rc = FAILED;
2295 goto err_out;
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302296 }
2297
Eric Moore3cb54692010-07-08 14:44:34 -06002298 if (ioc->shost_recovery || ioc->remove_host ||
2299 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06002300 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2301 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302302 rc = FAILED;
2303 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002304 }
Eric Moore635374e2009-03-09 01:21:12 -06002305
2306 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2307 if (ioc_state & MPI2_DOORBELL_USED) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302308 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
Eric Moore635374e2009-03-09 01:21:12 -06002309 "active!\n", ioc->name));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302310 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302311 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302312 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302313 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002314 }
2315
2316 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2317 mpt2sas_base_fault_info(ioc, ioc_state &
2318 MPI2_DOORBELL_DATA_MASK);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302319 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302320 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302321 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302322 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002323 }
2324
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302325 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06002326 if (!smid) {
2327 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2328 ioc->name, __func__);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302329 rc = FAILED;
2330 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002331 }
2332
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302333 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2334 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2335
Eric Moore635374e2009-03-09 01:21:12 -06002336 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302337 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2338 smid_task));
Eric Moore635374e2009-03-09 01:21:12 -06002339 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2340 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2341 ioc->tm_cmds.smid = smid;
2342 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302343 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
Eric Moore635374e2009-03-09 01:21:12 -06002344 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2345 mpi_request->DevHandle = cpu_to_le16(handle);
2346 mpi_request->TaskType = type;
2347 mpi_request->TaskMID = cpu_to_le16(smid_task);
2348 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2349 mpt2sas_scsih_set_tm_flag(ioc, handle);
Kashyap, Desai5b768582009-08-20 13:24:31 +05302350 init_completion(&ioc->tm_cmds.done);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302351 mpt2sas_base_put_smid_hi_priority(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06002352 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
Eric Moore635374e2009-03-09 01:21:12 -06002353 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2354 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2355 ioc->name, __func__);
2356 _debug_dump_mf(mpi_request,
2357 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302358 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302359 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302360 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302361 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302362 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2363 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2364 goto err_out;
2365 }
Eric Moore635374e2009-03-09 01:21:12 -06002366 }
2367
2368 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2369 mpi_reply = ioc->tm_cmds.reply;
2370 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2371 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2372 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2373 le32_to_cpu(mpi_reply->IOCLogInfo),
2374 le32_to_cpu(mpi_reply->TerminationCount)));
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302375 if (ioc->logging_level & MPT_DEBUG_TM) {
Eric Moore635374e2009-03-09 01:21:12 -06002376 _scsih_response_code(ioc, mpi_reply->ResponseCode);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302377 if (mpi_reply->IOCStatus)
2378 _debug_dump_mf(mpi_request,
2379 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2380 }
Eric Moore635374e2009-03-09 01:21:12 -06002381 }
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302382
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302383 switch (type) {
2384 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302385 rc = SUCCESS;
2386 if (scsi_lookup->scmd == NULL)
2387 break;
2388 rc = FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302389 break;
2390
2391 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2392 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2393 rc = FAILED;
2394 else
2395 rc = SUCCESS;
2396 break;
2397
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302398 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302399 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2400 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2401 rc = FAILED;
2402 else
2403 rc = SUCCESS;
2404 break;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302405 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2406 rc = SUCCESS;
2407 break;
2408 default:
2409 rc = FAILED;
2410 break;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302411 }
2412
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302413 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2414 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302415 if (m_type == TM_MUTEX_ON)
2416 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302417
2418 return rc;
2419
2420 err_out:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302421 if (m_type == TM_MUTEX_ON)
2422 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302423 return rc;
Eric Moore635374e2009-03-09 01:21:12 -06002424}
2425
2426/**
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302427 * _scsih_tm_display_info - displays info about the device
2428 * @ioc: per adapter struct
2429 * @scmd: pointer to scsi command object
2430 *
2431 * Called by task management callback handlers.
2432 */
2433static void
2434_scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2435{
2436 struct scsi_target *starget = scmd->device->sdev_target;
2437 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2438 struct _sas_device *sas_device = NULL;
2439 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302440 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302441
2442 if (!priv_target)
2443 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302444 if (ioc->hide_ir_msg)
2445 device_str = "WarpDrive";
2446 else
2447 device_str = "volume";
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302448
2449 scsi_print_command(scmd);
2450 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302451 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2452 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2453 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302454 } else {
2455 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2456 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2457 priv_target->sas_address);
2458 if (sas_device) {
2459 if (priv_target->flags &
2460 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2461 starget_printk(KERN_INFO, starget,
2462 "volume handle(0x%04x), "
2463 "volume wwid(0x%016llx)\n",
2464 sas_device->volume_handle,
2465 (unsigned long long)sas_device->volume_wwid);
2466 }
2467 starget_printk(KERN_INFO, starget,
2468 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2469 sas_device->handle,
2470 (unsigned long long)sas_device->sas_address,
2471 sas_device->phy);
2472 starget_printk(KERN_INFO, starget,
2473 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2474 (unsigned long long)sas_device->enclosure_logical_id,
2475 sas_device->slot);
2476 }
2477 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2478 }
2479}
2480
2481/**
Eric Moored5d135b2009-05-18 13:02:08 -06002482 * _scsih_abort - eh threads main abort routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302483 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002484 *
2485 * Returns SUCCESS if command aborted else FAILED
2486 */
2487static int
Eric Moored5d135b2009-05-18 13:02:08 -06002488_scsih_abort(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002489{
2490 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2491 struct MPT2SAS_DEVICE *sas_device_priv_data;
2492 u16 smid;
2493 u16 handle;
2494 int r;
Eric Moore635374e2009-03-09 01:21:12 -06002495
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302496 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2497 "scmd(%p)\n", scmd);
2498 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002499
2500 sas_device_priv_data = scmd->device->hostdata;
2501 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302502 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2503 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002504 scmd->result = DID_NO_CONNECT << 16;
2505 scmd->scsi_done(scmd);
2506 r = SUCCESS;
2507 goto out;
2508 }
2509
2510 /* search for the command */
2511 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2512 if (!smid) {
2513 scmd->result = DID_RESET << 16;
2514 r = SUCCESS;
2515 goto out;
2516 }
2517
2518 /* for hidden raid components and volumes this is not supported */
2519 if (sas_device_priv_data->sas_target->flags &
2520 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2521 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2522 scmd->result = DID_RESET << 16;
2523 r = FAILED;
2524 goto out;
2525 }
2526
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302527 mpt2sas_halt_firmware(ioc);
2528
Eric Moore635374e2009-03-09 01:21:12 -06002529 handle = sas_device_priv_data->sas_target->handle;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302530 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2531 scmd->device->id, scmd->device->lun,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302532 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
2533 scmd->serial_number, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002534
2535 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302536 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2537 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002538 return r;
2539}
2540
Eric Moore635374e2009-03-09 01:21:12 -06002541/**
Eric Moored5d135b2009-05-18 13:02:08 -06002542 * _scsih_dev_reset - eh threads main device reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302543 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002544 *
2545 * Returns SUCCESS if command aborted else FAILED
2546 */
2547static int
Eric Moored5d135b2009-05-18 13:02:08 -06002548_scsih_dev_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002549{
2550 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2551 struct MPT2SAS_DEVICE *sas_device_priv_data;
2552 struct _sas_device *sas_device;
2553 unsigned long flags;
2554 u16 handle;
2555 int r;
2556
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302557 struct scsi_target *starget = scmd->device->sdev_target;
2558
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302559 starget_printk(KERN_INFO, starget, "attempting device reset! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302560 "scmd(%p)\n", scmd);
2561 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002562
2563 sas_device_priv_data = scmd->device->hostdata;
2564 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302565 starget_printk(KERN_INFO, starget, "device been deleted! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302566 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002567 scmd->result = DID_NO_CONNECT << 16;
2568 scmd->scsi_done(scmd);
2569 r = SUCCESS;
2570 goto out;
2571 }
2572
2573 /* for hidden raid components obtain the volume_handle */
2574 handle = 0;
2575 if (sas_device_priv_data->sas_target->flags &
2576 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2577 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2578 sas_device = _scsih_sas_device_find_by_handle(ioc,
2579 sas_device_priv_data->sas_target->handle);
2580 if (sas_device)
2581 handle = sas_device->volume_handle;
2582 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2583 } else
2584 handle = sas_device_priv_data->sas_target->handle;
2585
2586 if (!handle) {
2587 scmd->result = DID_RESET << 16;
2588 r = FAILED;
2589 goto out;
2590 }
2591
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302592 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2593 scmd->device->id, scmd->device->lun,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302594 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0,
2595 TM_MUTEX_ON);
Eric Moore993e0da2009-05-18 13:00:45 -06002596
2597 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302598 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2599 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002600 return r;
2601}
2602
2603/**
Eric Moored5d135b2009-05-18 13:02:08 -06002604 * _scsih_target_reset - eh threads main target reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302605 * @scmd: pointer to scsi command object
Eric Moore993e0da2009-05-18 13:00:45 -06002606 *
2607 * Returns SUCCESS if command aborted else FAILED
2608 */
2609static int
Eric Moored5d135b2009-05-18 13:02:08 -06002610_scsih_target_reset(struct scsi_cmnd *scmd)
Eric Moore993e0da2009-05-18 13:00:45 -06002611{
2612 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2613 struct MPT2SAS_DEVICE *sas_device_priv_data;
2614 struct _sas_device *sas_device;
2615 unsigned long flags;
2616 u16 handle;
2617 int r;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302618 struct scsi_target *starget = scmd->device->sdev_target;
Eric Moore993e0da2009-05-18 13:00:45 -06002619
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302620 starget_printk(KERN_INFO, starget, "attempting target reset! "
2621 "scmd(%p)\n", scmd);
2622 _scsih_tm_display_info(ioc, scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002623
2624 sas_device_priv_data = scmd->device->hostdata;
2625 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302626 starget_printk(KERN_INFO, starget, "target been deleted! "
2627 "scmd(%p)\n", scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002628 scmd->result = DID_NO_CONNECT << 16;
2629 scmd->scsi_done(scmd);
2630 r = SUCCESS;
2631 goto out;
2632 }
2633
2634 /* for hidden raid components obtain the volume_handle */
2635 handle = 0;
2636 if (sas_device_priv_data->sas_target->flags &
2637 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2638 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2639 sas_device = _scsih_sas_device_find_by_handle(ioc,
2640 sas_device_priv_data->sas_target->handle);
2641 if (sas_device)
2642 handle = sas_device->volume_handle;
2643 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2644 } else
2645 handle = sas_device_priv_data->sas_target->handle;
2646
2647 if (!handle) {
2648 scmd->result = DID_RESET << 16;
2649 r = FAILED;
2650 goto out;
2651 }
2652
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302653 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2654 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302655 30, 0, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002656
2657 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302658 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2659 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002660 return r;
2661}
2662
2663/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302664 * _scsih_host_reset - eh threads main host reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302665 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002666 *
2667 * Returns SUCCESS if command aborted else FAILED
2668 */
2669static int
Eric Moored5d135b2009-05-18 13:02:08 -06002670_scsih_host_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002671{
2672 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2673 int r, retval;
2674
2675 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2676 ioc->name, scmd);
2677 scsi_print_command(scmd);
2678
2679 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2680 FORCE_BIG_HAMMER);
2681 r = (retval < 0) ? FAILED : SUCCESS;
2682 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2683 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2684
2685 return r;
2686}
2687
2688/**
2689 * _scsih_fw_event_add - insert and queue up fw_event
2690 * @ioc: per adapter object
2691 * @fw_event: object describing the event
2692 * Context: This function will acquire ioc->fw_event_lock.
2693 *
2694 * This adds the firmware event object into link list, then queues it up to
2695 * be processed from user context.
2696 *
2697 * Return nothing.
2698 */
2699static void
2700_scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2701{
2702 unsigned long flags;
2703
2704 if (ioc->firmware_event_thread == NULL)
2705 return;
2706
2707 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2708 list_add_tail(&fw_event->list, &ioc->fw_event_list);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302709 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2710 queue_delayed_work(ioc->firmware_event_thread,
2711 &fw_event->delayed_work, 0);
Eric Moore635374e2009-03-09 01:21:12 -06002712 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2713}
2714
2715/**
2716 * _scsih_fw_event_free - delete fw_event
2717 * @ioc: per adapter object
2718 * @fw_event: object describing the event
2719 * Context: This function will acquire ioc->fw_event_lock.
2720 *
2721 * This removes firmware event object from link list, frees associated memory.
2722 *
2723 * Return nothing.
2724 */
2725static void
2726_scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2727 *fw_event)
2728{
2729 unsigned long flags;
2730
2731 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2732 list_del(&fw_event->list);
2733 kfree(fw_event->event_data);
2734 kfree(fw_event);
2735 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2736}
2737
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302738
Eric Moore635374e2009-03-09 01:21:12 -06002739/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302740 * _scsih_error_recovery_delete_devices - remove devices not responding
Eric Moore635374e2009-03-09 01:21:12 -06002741 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06002742 *
2743 * Return nothing.
2744 */
2745static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302746_scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06002747{
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302748 struct fw_event_work *fw_event;
2749
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302750 if (ioc->is_driver_loading)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302751 return;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302752 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2753 fw_event->ioc = ioc;
2754 _scsih_fw_event_add(ioc, fw_event);
2755}
2756
2757/**
2758 * mpt2sas_port_enable_complete - port enable completed (fake event)
2759 * @ioc: per adapter object
2760 *
2761 * Return nothing.
2762 */
2763void
2764mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2765{
2766 struct fw_event_work *fw_event;
2767
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302768 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2769 if (!fw_event)
2770 return;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302771 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302772 fw_event->ioc = ioc;
2773 _scsih_fw_event_add(ioc, fw_event);
2774}
2775
2776/**
2777 * _scsih_fw_event_cleanup_queue - cleanup event queue
2778 * @ioc: per adapter object
2779 *
2780 * Walk the firmware event queue, either killing timers, or waiting
2781 * for outstanding events to complete
2782 *
2783 * Return nothing.
2784 */
2785static void
2786_scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2787{
2788 struct fw_event_work *fw_event, *next;
2789
2790 if (list_empty(&ioc->fw_event_list) ||
2791 !ioc->firmware_event_thread || in_interrupt())
Eric Moore635374e2009-03-09 01:21:12 -06002792 return;
2793
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302794 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2795 if (cancel_delayed_work(&fw_event->delayed_work)) {
2796 _scsih_fw_event_free(ioc, fw_event);
2797 continue;
2798 }
2799 fw_event->cancel_pending_work = 1;
2800 }
Eric Moore635374e2009-03-09 01:21:12 -06002801}
2802
Eric Moore635374e2009-03-09 01:21:12 -06002803/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302804 * _scsih_ublock_io_all_device - unblock every device
2805 * @ioc: per adapter object
2806 *
2807 * change the device state from block to running
2808 */
2809static void
2810_scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2811{
2812 struct MPT2SAS_DEVICE *sas_device_priv_data;
2813 struct scsi_device *sdev;
2814
2815 shost_for_each_device(sdev, ioc->shost) {
2816 sas_device_priv_data = sdev->hostdata;
2817 if (!sas_device_priv_data)
2818 continue;
2819 if (!sas_device_priv_data->block)
2820 continue;
2821 sas_device_priv_data->block = 0;
2822 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2823 "handle(0x%04x)\n",
2824 sas_device_priv_data->sas_target->handle));
2825 scsi_internal_device_unblock(sdev);
2826 }
2827}
2828/**
Eric Moore635374e2009-03-09 01:21:12 -06002829 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2830 * @ioc: per adapter object
2831 * @handle: device handle
2832 *
2833 * During device pull we need to appropiately set the sdev state.
2834 */
2835static void
2836_scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2837{
2838 struct MPT2SAS_DEVICE *sas_device_priv_data;
2839 struct scsi_device *sdev;
2840
2841 shost_for_each_device(sdev, ioc->shost) {
2842 sas_device_priv_data = sdev->hostdata;
2843 if (!sas_device_priv_data)
2844 continue;
2845 if (!sas_device_priv_data->block)
2846 continue;
2847 if (sas_device_priv_data->sas_target->handle == handle) {
2848 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2849 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2850 "handle(0x%04x)\n", ioc->name, handle));
2851 sas_device_priv_data->block = 0;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05302852 scsi_internal_device_unblock(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002853 }
2854 }
2855}
2856
2857/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302858 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2859 * @ioc: per adapter object
2860 * @handle: device handle
2861 *
2862 * During device pull we need to appropiately set the sdev state.
2863 */
2864static void
2865_scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2866{
2867 struct MPT2SAS_DEVICE *sas_device_priv_data;
2868 struct scsi_device *sdev;
2869
2870 shost_for_each_device(sdev, ioc->shost) {
2871 sas_device_priv_data = sdev->hostdata;
2872 if (!sas_device_priv_data)
2873 continue;
2874 if (sas_device_priv_data->block)
2875 continue;
2876 sas_device_priv_data->block = 1;
2877 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2878 "handle(0x%04x)\n",
2879 sas_device_priv_data->sas_target->handle));
2880 scsi_internal_device_block(sdev);
2881 }
2882}
2883
2884
2885/**
Eric Moore635374e2009-03-09 01:21:12 -06002886 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2887 * @ioc: per adapter object
2888 * @handle: device handle
2889 *
2890 * During device pull we need to appropiately set the sdev state.
2891 */
2892static void
2893_scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2894{
2895 struct MPT2SAS_DEVICE *sas_device_priv_data;
2896 struct scsi_device *sdev;
2897
2898 shost_for_each_device(sdev, ioc->shost) {
2899 sas_device_priv_data = sdev->hostdata;
2900 if (!sas_device_priv_data)
2901 continue;
2902 if (sas_device_priv_data->block)
2903 continue;
2904 if (sas_device_priv_data->sas_target->handle == handle) {
2905 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2906 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2907 "handle(0x%04x)\n", ioc->name, handle));
2908 sas_device_priv_data->block = 1;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05302909 scsi_internal_device_block(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002910 }
2911 }
2912}
2913
2914/**
2915 * _scsih_block_io_to_children_attached_to_ex
2916 * @ioc: per adapter object
2917 * @sas_expander: the sas_device object
2918 *
2919 * This routine set sdev state to SDEV_BLOCK for all devices
2920 * attached to this expander. This function called when expander is
2921 * pulled.
2922 */
2923static void
2924_scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2925 struct _sas_node *sas_expander)
2926{
2927 struct _sas_port *mpt2sas_port;
2928 struct _sas_device *sas_device;
2929 struct _sas_node *expander_sibling;
2930 unsigned long flags;
2931
2932 if (!sas_expander)
2933 return;
2934
2935 list_for_each_entry(mpt2sas_port,
2936 &sas_expander->sas_port_list, port_list) {
2937 if (mpt2sas_port->remote_identify.device_type ==
2938 SAS_END_DEVICE) {
2939 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2940 sas_device =
2941 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2942 mpt2sas_port->remote_identify.sas_address);
2943 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2944 if (!sas_device)
2945 continue;
2946 _scsih_block_io_device(ioc, sas_device->handle);
2947 }
2948 }
2949
2950 list_for_each_entry(mpt2sas_port,
2951 &sas_expander->sas_port_list, port_list) {
2952
2953 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05302954 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06002955 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05302956 SAS_FANOUT_EXPANDER_DEVICE) {
Eric Moore635374e2009-03-09 01:21:12 -06002957
2958 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2959 expander_sibling =
2960 mpt2sas_scsih_expander_find_by_sas_address(
2961 ioc, mpt2sas_port->remote_identify.sas_address);
2962 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2963 _scsih_block_io_to_children_attached_to_ex(ioc,
2964 expander_sibling);
2965 }
2966 }
2967}
2968
2969/**
2970 * _scsih_block_io_to_children_attached_directly
2971 * @ioc: per adapter object
2972 * @event_data: topology change event data
2973 *
2974 * This routine set sdev state to SDEV_BLOCK for all devices
2975 * direct attached during device pull.
2976 */
2977static void
2978_scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
2979 Mpi2EventDataSasTopologyChangeList_t *event_data)
2980{
2981 int i;
2982 u16 handle;
2983 u16 reason_code;
2984 u8 phy_number;
2985
2986 for (i = 0; i < event_data->NumEntries; i++) {
2987 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2988 if (!handle)
2989 continue;
2990 phy_number = event_data->StartPhyNum + i;
2991 reason_code = event_data->PHY[i].PhyStatus &
2992 MPI2_EVENT_SAS_TOPO_RC_MASK;
2993 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2994 _scsih_block_io_device(ioc, handle);
2995 }
2996}
2997
2998/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302999 * _scsih_tm_tr_send - send task management request
3000 * @ioc: per adapter object
3001 * @handle: device handle
3002 * Context: interrupt time.
3003 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003004 * This code is to initiate the device removal handshake protocol
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303005 * with controller firmware. This function will issue target reset
3006 * using high priority request queue. It will send a sas iounit
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003007 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303008 *
3009 * This is designed to send muliple task management request at the same
3010 * time to the fifo. If the fifo is full, we will append the request,
3011 * and process it in a future completion.
3012 */
3013static void
3014_scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3015{
3016 Mpi2SCSITaskManagementRequest_t *mpi_request;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303017 u16 smid;
3018 struct _sas_device *sas_device;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303019 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303020 unsigned long flags;
3021 struct _tr_list *delayed_tr;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303022 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303023
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303024 if (ioc->remove_host) {
3025 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3026 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3027 return;
3028 } else if (ioc->pci_error_recovery) {
3029 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3030 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3031 handle));
3032 return;
3033 }
3034 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3035 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3036 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3037 "operational: handle(0x%04x)\n", __func__, ioc->name,
3038 handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303039 return;
3040 }
3041
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303042 /* if PD, then return */
3043 if (test_bit(handle, ioc->pd_handles))
3044 return;
3045
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303046 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3047 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303048 if (sas_device && sas_device->starget &&
3049 sas_device->starget->hostdata) {
3050 sas_target_priv_data = sas_device->starget->hostdata;
3051 sas_target_priv_data->deleted = 1;
3052 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3053 "setting delete flag: handle(0x%04x), "
3054 "sas_addr(0x%016llx)\n", ioc->name, handle,
3055 (unsigned long long) sas_device->sas_address));
Kashyap, Desai1278b112010-03-09 17:34:13 +05303056 }
3057 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303058
3059 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3060 if (!smid) {
3061 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3062 if (!delayed_tr)
3063 return;
3064 INIT_LIST_HEAD(&delayed_tr->list);
3065 delayed_tr->handle = handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303066 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3067 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3068 "DELAYED:tr:handle(0x%04x), (open)\n",
3069 ioc->name, handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303070 return;
3071 }
3072
Kashyap, Desai1278b112010-03-09 17:34:13 +05303073 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3074 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3075 ioc->tm_tr_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303076 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3077 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3078 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3079 mpi_request->DevHandle = cpu_to_le16(handle);
3080 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303081 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3082}
3083
3084
3085
3086/**
3087 * _scsih_sas_control_complete - completion routine
3088 * @ioc: per adapter object
3089 * @smid: system request message index
3090 * @msix_index: MSIX table index supplied by the OS
3091 * @reply: reply message frame(lower 32bit addr)
3092 * Context: interrupt time.
3093 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003094 * This is the sas iounit control completion routine.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303095 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003096 * handshake protocol with controller firmware.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303097 *
3098 * Return 1 meaning mf should be freed from _base_interrupt
3099 * 0 means the mf is freed from this function.
3100 */
3101static u8
3102_scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3103 u8 msix_index, u32 reply)
3104{
Kashyap, Desai363fa502010-11-13 04:29:20 +05303105#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303106 Mpi2SasIoUnitControlReply_t *mpi_reply =
3107 mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desai363fa502010-11-13 04:29:20 +05303108#endif
Kashyap, Desai1278b112010-03-09 17:34:13 +05303109 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3110 "sc_complete:handle(0x%04x), (open) "
3111 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3112 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3113 le16_to_cpu(mpi_reply->IOCStatus),
3114 le32_to_cpu(mpi_reply->IOCLogInfo)));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303115 return 1;
3116}
3117
3118/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303119 * _scsih_tm_tr_volume_send - send target reset request for volumes
3120 * @ioc: per adapter object
3121 * @handle: device handle
3122 * Context: interrupt time.
3123 *
3124 * This is designed to send muliple task management request at the same
3125 * time to the fifo. If the fifo is full, we will append the request,
3126 * and process it in a future completion.
3127 */
3128static void
3129_scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3130{
3131 Mpi2SCSITaskManagementRequest_t *mpi_request;
3132 u16 smid;
3133 struct _tr_list *delayed_tr;
3134
Eric Moore3cb54692010-07-08 14:44:34 -06003135 if (ioc->shost_recovery || ioc->remove_host ||
3136 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303137 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3138 "progress!\n", __func__, ioc->name));
3139 return;
3140 }
3141
3142 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3143 if (!smid) {
3144 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3145 if (!delayed_tr)
3146 return;
3147 INIT_LIST_HEAD(&delayed_tr->list);
3148 delayed_tr->handle = handle;
3149 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3150 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3151 "DELAYED:tr:handle(0x%04x), (open)\n",
3152 ioc->name, handle));
3153 return;
3154 }
3155
3156 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3157 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3158 ioc->tm_tr_volume_cb_idx));
3159 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3160 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3161 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3162 mpi_request->DevHandle = cpu_to_le16(handle);
3163 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3164 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3165}
3166
3167/**
3168 * _scsih_tm_volume_tr_complete - target reset completion
3169 * @ioc: per adapter object
3170 * @smid: system request message index
3171 * @msix_index: MSIX table index supplied by the OS
3172 * @reply: reply message frame(lower 32bit addr)
3173 * Context: interrupt time.
3174 *
3175 * Return 1 meaning mf should be freed from _base_interrupt
3176 * 0 means the mf is freed from this function.
3177 */
3178static u8
3179_scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3180 u8 msix_index, u32 reply)
3181{
3182 u16 handle;
3183 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3184 Mpi2SCSITaskManagementReply_t *mpi_reply =
3185 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3186
Eric Moore3cb54692010-07-08 14:44:34 -06003187 if (ioc->shost_recovery || ioc->remove_host ||
3188 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303189 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3190 "progress!\n", __func__, ioc->name));
3191 return 1;
3192 }
3193
3194 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3195 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3196 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3197 dewtprintk(ioc, printk("spurious interrupt: "
3198 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3199 le16_to_cpu(mpi_reply->DevHandle), smid));
3200 return 0;
3201 }
3202
3203 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3204 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3205 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3206 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3207 le32_to_cpu(mpi_reply->IOCLogInfo),
3208 le32_to_cpu(mpi_reply->TerminationCount)));
3209
3210 return _scsih_check_for_pending_tm(ioc, smid);
3211}
3212
3213/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303214 * _scsih_tm_tr_complete -
3215 * @ioc: per adapter object
3216 * @smid: system request message index
3217 * @msix_index: MSIX table index supplied by the OS
3218 * @reply: reply message frame(lower 32bit addr)
3219 * Context: interrupt time.
3220 *
3221 * This is the target reset completion routine.
3222 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003223 * handshake protocol with controller firmware.
3224 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303225 *
3226 * Return 1 meaning mf should be freed from _base_interrupt
3227 * 0 means the mf is freed from this function.
3228 */
3229static u8
3230_scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3231 u32 reply)
3232{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303233 u16 handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303234 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303235 Mpi2SCSITaskManagementReply_t *mpi_reply =
3236 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3237 Mpi2SasIoUnitControlRequest_t *mpi_request;
3238 u16 smid_sas_ctrl;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303239 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303240
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303241 if (ioc->remove_host) {
3242 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3243 "removed\n", __func__, ioc->name));
3244 return 1;
3245 } else if (ioc->pci_error_recovery) {
3246 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3247 "error recovery\n", __func__, ioc->name));
3248 return 1;
3249 }
3250 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3251 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3252 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3253 "operational\n", __func__, ioc->name));
Kashyap, Desai1278b112010-03-09 17:34:13 +05303254 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303255 }
3256
Kashyap, Desai1278b112010-03-09 17:34:13 +05303257 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3258 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3259 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3260 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3261 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3262 le16_to_cpu(mpi_reply->DevHandle), smid));
3263 return 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303264 }
3265
Kashyap, Desai1278b112010-03-09 17:34:13 +05303266 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3267 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3268 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3269 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3270 le32_to_cpu(mpi_reply->IOCLogInfo),
3271 le32_to_cpu(mpi_reply->TerminationCount)));
3272
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303273 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3274 if (!smid_sas_ctrl) {
3275 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3276 ioc->name, __func__);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303277 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303278 }
3279
Kashyap, Desai1278b112010-03-09 17:34:13 +05303280 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3281 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3282 ioc->tm_sas_control_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303283 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3284 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3285 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3286 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303287 mpi_request->DevHandle = mpi_request_tm->DevHandle;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303288 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303289
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303290 return _scsih_check_for_pending_tm(ioc, smid);
3291}
3292
3293/**
3294 * _scsih_check_for_pending_tm - check for pending task management
3295 * @ioc: per adapter object
3296 * @smid: system request message index
3297 *
3298 * This will check delayed target reset list, and feed the
3299 * next reqeust.
3300 *
3301 * Return 1 meaning mf should be freed from _base_interrupt
3302 * 0 means the mf is freed from this function.
3303 */
3304static u8
3305_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3306{
3307 struct _tr_list *delayed_tr;
3308
3309 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3310 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3311 struct _tr_list, list);
3312 mpt2sas_base_free_smid(ioc, smid);
3313 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3314 list_del(&delayed_tr->list);
3315 kfree(delayed_tr);
3316 return 0;
3317 }
3318
Kashyap, Desai1278b112010-03-09 17:34:13 +05303319 if (!list_empty(&ioc->delayed_tr_list)) {
3320 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3321 struct _tr_list, list);
3322 mpt2sas_base_free_smid(ioc, smid);
3323 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3324 list_del(&delayed_tr->list);
3325 kfree(delayed_tr);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303326 return 0;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303327 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303328
Kashyap, Desai1278b112010-03-09 17:34:13 +05303329 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303330}
3331
3332/**
Eric Moore635374e2009-03-09 01:21:12 -06003333 * _scsih_check_topo_delete_events - sanity check on topo events
3334 * @ioc: per adapter object
3335 * @event_data: the event data payload
3336 *
3337 * This routine added to better handle cable breaker.
3338 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003339 * This handles the case where driver receives multiple expander
Eric Moore635374e2009-03-09 01:21:12 -06003340 * add and delete events in a single shot. When there is a delete event
3341 * the routine will void any pending add events waiting in the event queue.
3342 *
3343 * Return nothing.
3344 */
3345static void
3346_scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3347 Mpi2EventDataSasTopologyChangeList_t *event_data)
3348{
3349 struct fw_event_work *fw_event;
3350 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3351 u16 expander_handle;
3352 struct _sas_node *sas_expander;
3353 unsigned long flags;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303354 int i, reason_code;
3355 u16 handle;
3356
3357 for (i = 0 ; i < event_data->NumEntries; i++) {
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303358 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3359 if (!handle)
3360 continue;
3361 reason_code = event_data->PHY[i].PhyStatus &
3362 MPI2_EVENT_SAS_TOPO_RC_MASK;
3363 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3364 _scsih_tm_tr_send(ioc, handle);
3365 }
Eric Moore635374e2009-03-09 01:21:12 -06003366
3367 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3368 if (expander_handle < ioc->sas_hba.num_phys) {
3369 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3370 return;
3371 }
3372
3373 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
3374 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
3375 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3376 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3377 expander_handle);
3378 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3379 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
3380 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3381 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3382
3383 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3384 return;
3385
3386 /* mark ignore flag for pending events */
3387 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3388 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3389 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3390 fw_event->ignore)
3391 continue;
3392 local_event_data = fw_event->event_data;
3393 if (local_event_data->ExpStatus ==
3394 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3395 local_event_data->ExpStatus ==
3396 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3397 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3398 expander_handle) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303399 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06003400 "setting ignoring flag\n", ioc->name));
3401 fw_event->ignore = 1;
3402 }
3403 }
3404 }
3405 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3406}
3407
3408/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303409 * _scsih_set_volume_delete_flag - setting volume delete flag
3410 * @ioc: per adapter object
3411 * @handle: device handle
3412 *
3413 * This
3414 * Return nothing.
3415 */
3416static void
3417_scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3418{
3419 struct _raid_device *raid_device;
3420 struct MPT2SAS_TARGET *sas_target_priv_data;
3421 unsigned long flags;
3422
3423 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3424 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3425 if (raid_device && raid_device->starget &&
3426 raid_device->starget->hostdata) {
3427 sas_target_priv_data =
3428 raid_device->starget->hostdata;
3429 sas_target_priv_data->deleted = 1;
3430 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3431 "setting delete flag: handle(0x%04x), "
3432 "wwid(0x%016llx)\n", ioc->name, handle,
3433 (unsigned long long) raid_device->wwid));
3434 }
3435 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3436}
3437
3438/**
3439 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3440 * @handle: input handle
3441 * @a: handle for volume a
3442 * @b: handle for volume b
3443 *
3444 * IR firmware only supports two raid volumes. The purpose of this
3445 * routine is to set the volume handle in either a or b. When the given
3446 * input handle is non-zero, or when a and b have not been set before.
3447 */
3448static void
3449_scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3450{
3451 if (!handle || handle == *a || handle == *b)
3452 return;
3453 if (!*a)
3454 *a = handle;
3455 else if (!*b)
3456 *b = handle;
3457}
3458
3459/**
3460 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3461 * @ioc: per adapter object
3462 * @event_data: the event data payload
3463 * Context: interrupt time.
3464 *
3465 * This routine will send target reset to volume, followed by target
3466 * resets to the PDs. This is called when a PD has been removed, or
3467 * volume has been deleted or removed. When the target reset is sent
3468 * to volume, the PD target resets need to be queued to start upon
3469 * completion of the volume target reset.
3470 *
3471 * Return nothing.
3472 */
3473static void
3474_scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3475 Mpi2EventDataIrConfigChangeList_t *event_data)
3476{
3477 Mpi2EventIrConfigElement_t *element;
3478 int i;
3479 u16 handle, volume_handle, a, b;
3480 struct _tr_list *delayed_tr;
3481
3482 a = 0;
3483 b = 0;
3484
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303485 if (ioc->is_warpdrive)
3486 return;
3487
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303488 /* Volume Resets for Deleted or Removed */
3489 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3490 for (i = 0; i < event_data->NumElements; i++, element++) {
3491 if (element->ReasonCode ==
3492 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3493 element->ReasonCode ==
3494 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3495 volume_handle = le16_to_cpu(element->VolDevHandle);
3496 _scsih_set_volume_delete_flag(ioc, volume_handle);
3497 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3498 }
3499 }
3500
3501 /* Volume Resets for UNHIDE events */
3502 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3503 for (i = 0; i < event_data->NumElements; i++, element++) {
3504 if (le32_to_cpu(event_data->Flags) &
3505 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3506 continue;
3507 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3508 volume_handle = le16_to_cpu(element->VolDevHandle);
3509 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3510 }
3511 }
3512
3513 if (a)
3514 _scsih_tm_tr_volume_send(ioc, a);
3515 if (b)
3516 _scsih_tm_tr_volume_send(ioc, b);
3517
3518 /* PD target resets */
3519 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3520 for (i = 0; i < event_data->NumElements; i++, element++) {
3521 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3522 continue;
3523 handle = le16_to_cpu(element->PhysDiskDevHandle);
3524 volume_handle = le16_to_cpu(element->VolDevHandle);
3525 clear_bit(handle, ioc->pd_handles);
3526 if (!volume_handle)
3527 _scsih_tm_tr_send(ioc, handle);
3528 else if (volume_handle == a || volume_handle == b) {
3529 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3530 BUG_ON(!delayed_tr);
3531 INIT_LIST_HEAD(&delayed_tr->list);
3532 delayed_tr->handle = handle;
3533 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3534 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3535 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3536 handle));
3537 } else
3538 _scsih_tm_tr_send(ioc, handle);
3539 }
3540}
3541
3542
3543/**
3544 * _scsih_check_volume_delete_events - set delete flag for volumes
3545 * @ioc: per adapter object
3546 * @event_data: the event data payload
3547 * Context: interrupt time.
3548 *
3549 * This will handle the case when the cable connected to entire volume is
3550 * pulled. We will take care of setting the deleted flag so normal IO will
3551 * not be sent.
3552 *
3553 * Return nothing.
3554 */
3555static void
3556_scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3557 Mpi2EventDataIrVolume_t *event_data)
3558{
3559 u32 state;
3560
3561 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3562 return;
3563 state = le32_to_cpu(event_data->NewValue);
3564 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3565 MPI2_RAID_VOL_STATE_FAILED)
3566 _scsih_set_volume_delete_flag(ioc,
3567 le16_to_cpu(event_data->VolDevHandle));
3568}
3569
3570/**
Eric Moore635374e2009-03-09 01:21:12 -06003571 * _scsih_flush_running_cmds - completing outstanding commands.
3572 * @ioc: per adapter object
3573 *
3574 * The flushing out of all pending scmd commands following host reset,
3575 * where all IO is dropped to the floor.
3576 *
3577 * Return nothing.
3578 */
3579static void
3580_scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3581{
3582 struct scsi_cmnd *scmd;
3583 u16 smid;
3584 u16 count = 0;
3585
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303586 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05303587 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003588 if (!scmd)
3589 continue;
3590 count++;
3591 mpt2sas_base_free_smid(ioc, smid);
3592 scsi_dma_unmap(scmd);
Eric Moore3cb54692010-07-08 14:44:34 -06003593 if (ioc->pci_error_recovery)
3594 scmd->result = DID_NO_CONNECT << 16;
3595 else
3596 scmd->result = DID_RESET << 16;
Eric Moore635374e2009-03-09 01:21:12 -06003597 scmd->scsi_done(scmd);
3598 }
3599 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3600 ioc->name, count));
3601}
3602
3603/**
Eric Moore3c621b32009-05-18 12:59:41 -06003604 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3605 * @scmd: pointer to scsi command object
3606 * @mpi_request: pointer to the SCSI_IO reqest message frame
3607 *
3608 * Supporting protection 1 and 3.
3609 *
3610 * Returns nothing
3611 */
3612static void
3613_scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3614{
3615 u16 eedp_flags;
3616 unsigned char prot_op = scsi_get_prot_op(scmd);
3617 unsigned char prot_type = scsi_get_prot_type(scmd);
3618
Eric Moored334aa72010-04-22 10:47:40 -06003619 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
Eric Moore3c621b32009-05-18 12:59:41 -06003620 return;
3621
3622 if (prot_op == SCSI_PROT_READ_STRIP)
3623 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3624 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3625 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3626 else
3627 return;
3628
Eric Moore3c621b32009-05-18 12:59:41 -06003629 switch (prot_type) {
3630 case SCSI_PROT_DIF_TYPE1:
Martin K. Petersen756aca72011-05-18 00:45:22 -04003631 case SCSI_PROT_DIF_TYPE2:
Eric Moore3c621b32009-05-18 12:59:41 -06003632
3633 /*
3634 * enable ref/guard checking
3635 * auto increment ref tag
3636 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303637 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
Eric Moore3c621b32009-05-18 12:59:41 -06003638 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3639 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3640 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3641 cpu_to_be32(scsi_get_lba(scmd));
Eric Moored334aa72010-04-22 10:47:40 -06003642 break;
Eric Moore3c621b32009-05-18 12:59:41 -06003643
Eric Moore3c621b32009-05-18 12:59:41 -06003644 case SCSI_PROT_DIF_TYPE3:
3645
3646 /*
3647 * enable guard checking
3648 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303649 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
Eric Moore3c621b32009-05-18 12:59:41 -06003650 break;
3651 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05303652 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3653 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
Eric Moore3c621b32009-05-18 12:59:41 -06003654}
3655
3656/**
3657 * _scsih_eedp_error_handling - return sense code for EEDP errors
3658 * @scmd: pointer to scsi command object
3659 * @ioc_status: ioc status
3660 *
3661 * Returns nothing
3662 */
3663static void
3664_scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3665{
3666 u8 ascq;
3667 u8 sk;
3668 u8 host_byte;
3669
3670 switch (ioc_status) {
3671 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3672 ascq = 0x01;
3673 break;
3674 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3675 ascq = 0x02;
3676 break;
3677 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3678 ascq = 0x03;
3679 break;
3680 default:
3681 ascq = 0x00;
3682 break;
3683 }
3684
3685 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
3686 sk = ILLEGAL_REQUEST;
3687 host_byte = DID_ABORT;
3688 } else {
3689 sk = ABORTED_COMMAND;
3690 host_byte = DID_OK;
3691 }
3692
3693 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
3694 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
3695 SAM_STAT_CHECK_CONDITION;
3696}
3697
3698/**
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303699 * _scsih_scsi_direct_io_get - returns direct io flag
3700 * @ioc: per adapter object
3701 * @smid: system request message index
3702 *
3703 * Returns the smid stored scmd pointer.
3704 */
3705static inline u8
3706_scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3707{
3708 return ioc->scsi_lookup[smid - 1].direct_io;
3709}
3710
3711/**
3712 * _scsih_scsi_direct_io_set - sets direct io flag
3713 * @ioc: per adapter object
3714 * @smid: system request message index
3715 * @direct_io: Zero or non-zero value to set in the direct_io flag
3716 *
3717 * Returns Nothing.
3718 */
3719static inline void
3720_scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3721{
3722 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3723}
3724
3725
3726/**
3727 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3728 * @ioc: per adapter object
3729 * @scmd: pointer to scsi command object
3730 * @raid_device: pointer to raid device data structure
3731 * @mpi_request: pointer to the SCSI_IO reqest message frame
3732 * @smid: system request message index
3733 *
3734 * Returns nothing
3735 */
3736static void
3737_scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3738 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3739 u16 smid)
3740{
3741 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3742 u32 stripe_sz, stripe_exp;
3743 u8 num_pds, *cdb_ptr, *tmp_ptr, *lba_ptr1, *lba_ptr2;
3744 u8 cdb0 = scmd->cmnd[0];
3745
3746 /*
3747 * Try Direct I/O to RAID memeber disks
3748 */
3749 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3750 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3751 cdb_ptr = mpi_request->CDB.CDB32;
3752
3753 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3754 | cdb_ptr[5])) {
3755 io_size = scsi_bufflen(scmd) >> 9;
3756 /* get virtual lba */
3757 lba_ptr1 = lba_ptr2 = (cdb0 < READ_16) ? &cdb_ptr[2] :
3758 &cdb_ptr[6];
3759 tmp_ptr = (u8 *)&v_lba + 3;
3760 *tmp_ptr-- = *lba_ptr1++;
3761 *tmp_ptr-- = *lba_ptr1++;
3762 *tmp_ptr-- = *lba_ptr1++;
3763 *tmp_ptr = *lba_ptr1;
3764
3765 if (((u64)v_lba + (u64)io_size - 1) <=
3766 (u32)raid_device->max_lba) {
3767 stripe_sz = raid_device->stripe_sz;
3768 stripe_exp = raid_device->stripe_exponent;
3769 stripe_off = v_lba & (stripe_sz - 1);
3770
3771 /* Check whether IO falls within a stripe */
3772 if ((stripe_off + io_size) <= stripe_sz) {
3773 num_pds = raid_device->num_pds;
3774 p_lba = v_lba >> stripe_exp;
3775 stripe_unit = p_lba / num_pds;
3776 column = p_lba % num_pds;
3777 p_lba = (stripe_unit << stripe_exp) +
3778 stripe_off;
3779 mpi_request->DevHandle =
3780 cpu_to_le16(raid_device->
3781 pd_handle[column]);
3782 tmp_ptr = (u8 *)&p_lba + 3;
3783 *lba_ptr2++ = *tmp_ptr--;
3784 *lba_ptr2++ = *tmp_ptr--;
3785 *lba_ptr2++ = *tmp_ptr--;
3786 *lba_ptr2 = *tmp_ptr;
3787 /*
3788 * WD: To indicate this I/O is directI/O
3789 */
3790 _scsih_scsi_direct_io_set(ioc, smid, 1);
3791 }
3792 }
3793 }
3794 }
3795}
3796
3797/**
Eric Moored5d135b2009-05-18 13:02:08 -06003798 * _scsih_qcmd - main scsi request entry point
Eric Moore635374e2009-03-09 01:21:12 -06003799 * @scmd: pointer to scsi command object
3800 * @done: function pointer to be invoked on completion
3801 *
3802 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3803 *
3804 * Returns 0 on success. If there's a failure, return either:
3805 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3806 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3807 */
3808static int
Jeff Garzikf2812332010-11-16 02:10:29 -05003809_scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
Eric Moore635374e2009-03-09 01:21:12 -06003810{
3811 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3812 struct MPT2SAS_DEVICE *sas_device_priv_data;
3813 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303814 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06003815 Mpi2SCSIIORequest_t *mpi_request;
3816 u32 mpi_control;
3817 u16 smid;
Eric Moore635374e2009-03-09 01:21:12 -06003818
3819 scmd->scsi_done = done;
3820 sas_device_priv_data = scmd->device->hostdata;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303821 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Eric Moore635374e2009-03-09 01:21:12 -06003822 scmd->result = DID_NO_CONNECT << 16;
3823 scmd->scsi_done(scmd);
3824 return 0;
3825 }
3826
Kashyap, Desai78215782011-06-14 10:57:08 +05303827 if (ioc->pci_error_recovery || ioc->remove_host) {
Eric Moore3cb54692010-07-08 14:44:34 -06003828 scmd->result = DID_NO_CONNECT << 16;
3829 scmd->scsi_done(scmd);
3830 return 0;
3831 }
3832
Eric Moore635374e2009-03-09 01:21:12 -06003833 sas_target_priv_data = sas_device_priv_data->sas_target;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303834 /* invalid device handle */
3835 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
Eric Moore635374e2009-03-09 01:21:12 -06003836 scmd->result = DID_NO_CONNECT << 16;
3837 scmd->scsi_done(scmd);
3838 return 0;
3839 }
3840
Kashyap, Desai130b9582010-04-08 17:54:32 +05303841 /* host recovery or link resets sent via IOCTLs */
3842 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
Eric Moore635374e2009-03-09 01:21:12 -06003843 return SCSI_MLQUEUE_HOST_BUSY;
Uwe Kleine-König65155b32010-06-11 12:17:01 +02003844 /* device busy with task management */
Kashyap, Desai130b9582010-04-08 17:54:32 +05303845 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3846 return SCSI_MLQUEUE_DEVICE_BUSY;
3847 /* device has been deleted */
3848 else if (sas_target_priv_data->deleted) {
3849 scmd->result = DID_NO_CONNECT << 16;
3850 scmd->scsi_done(scmd);
3851 return 0;
3852 }
Eric Moore635374e2009-03-09 01:21:12 -06003853
3854 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3855 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3856 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3857 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3858 else
3859 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3860
3861 /* set tags */
3862 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3863 if (scmd->device->tagged_supported) {
3864 if (scmd->device->ordered_tags)
3865 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3866 else
3867 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3868 } else
3869/* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3870/* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3871 */
3872 mpi_control |= (0x500);
3873
3874 } else
3875 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303876 /* Make sure Device is not raid volume.
3877 * We do not expose raid functionality to upper layer for warpdrive.
3878 */
3879 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Eric Moored334aa72010-04-22 10:47:40 -06003880 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
Eric Moore635374e2009-03-09 01:21:12 -06003881 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3882
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303883 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06003884 if (!smid) {
3885 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3886 ioc->name, __func__);
3887 goto out;
3888 }
3889 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3890 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
Eric Moore3c621b32009-05-18 12:59:41 -06003891 _scsih_setup_eedp(scmd, mpi_request);
Eric Moored334aa72010-04-22 10:47:40 -06003892 if (scmd->cmd_len == 32)
3893 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
Eric Moore635374e2009-03-09 01:21:12 -06003894 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3895 if (sas_device_priv_data->sas_target->flags &
3896 MPT_TARGET_FLAGS_RAID_COMPONENT)
3897 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3898 else
3899 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3900 mpi_request->DevHandle =
3901 cpu_to_le16(sas_device_priv_data->sas_target->handle);
3902 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3903 mpi_request->Control = cpu_to_le32(mpi_control);
3904 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
3905 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
3906 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3907 mpi_request->SenseBufferLowAddress =
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05303908 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003909 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
3910 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
3911 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303912 mpi_request->VF_ID = 0; /* TODO */
3913 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06003914 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
3915 mpi_request->LUN);
3916 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
3917
3918 if (!mpi_request->DataLength) {
3919 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
3920 } else {
3921 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
3922 mpt2sas_base_free_smid(ioc, smid);
3923 goto out;
3924 }
3925 }
3926
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303927 raid_device = sas_target_priv_data->raid_device;
3928 if (raid_device && raid_device->direct_io_enabled)
3929 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
3930 smid);
3931
Kashyap, Desai58287fd2010-03-17 16:27:25 +05303932 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
3933 mpt2sas_base_put_smid_scsi_io(ioc, smid,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303934 le16_to_cpu(mpi_request->DevHandle));
Kashyap, Desai58287fd2010-03-17 16:27:25 +05303935 else
3936 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003937 return 0;
3938
3939 out:
3940 return SCSI_MLQUEUE_HOST_BUSY;
3941}
3942
Jeff Garzikf2812332010-11-16 02:10:29 -05003943static DEF_SCSI_QCMD(_scsih_qcmd)
3944
Eric Moore635374e2009-03-09 01:21:12 -06003945/**
3946 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
3947 * @sense_buffer: sense data returned by target
3948 * @data: normalized skey/asc/ascq
3949 *
3950 * Return nothing.
3951 */
3952static void
3953_scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
3954{
3955 if ((sense_buffer[0] & 0x7F) >= 0x72) {
3956 /* descriptor format */
3957 data->skey = sense_buffer[1] & 0x0F;
3958 data->asc = sense_buffer[2];
3959 data->ascq = sense_buffer[3];
3960 } else {
3961 /* fixed format */
3962 data->skey = sense_buffer[2] & 0x0F;
3963 data->asc = sense_buffer[12];
3964 data->ascq = sense_buffer[13];
3965 }
3966}
3967
3968#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3969/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003970 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
Eric Moore635374e2009-03-09 01:21:12 -06003971 * @ioc: per adapter object
3972 * @scmd: pointer to scsi command object
3973 * @mpi_reply: reply mf payload returned from firmware
3974 *
3975 * scsi_status - SCSI Status code returned from target device
3976 * scsi_state - state info associated with SCSI_IO determined by ioc
3977 * ioc_status - ioc supplied status info
3978 *
3979 * Return nothing.
3980 */
3981static void
3982_scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3983 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
3984{
3985 u32 response_info;
3986 u8 *response_bytes;
3987 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
3988 MPI2_IOCSTATUS_MASK;
3989 u8 scsi_state = mpi_reply->SCSIState;
3990 u8 scsi_status = mpi_reply->SCSIStatus;
3991 char *desc_ioc_state = NULL;
3992 char *desc_scsi_status = NULL;
3993 char *desc_scsi_state = ioc->tmp_string;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05303994 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05303995 struct _sas_device *sas_device = NULL;
3996 unsigned long flags;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05303997 struct scsi_target *starget = scmd->device->sdev_target;
3998 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303999 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304000
4001 if (!priv_target)
4002 return;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304003
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304004 if (ioc->hide_ir_msg)
4005 device_str = "WarpDrive";
4006 else
4007 device_str = "volume";
4008
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304009 if (log_info == 0x31170000)
4010 return;
Eric Moore635374e2009-03-09 01:21:12 -06004011
4012 switch (ioc_status) {
4013 case MPI2_IOCSTATUS_SUCCESS:
4014 desc_ioc_state = "success";
4015 break;
4016 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4017 desc_ioc_state = "invalid function";
4018 break;
4019 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4020 desc_ioc_state = "scsi recovered error";
4021 break;
4022 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4023 desc_ioc_state = "scsi invalid dev handle";
4024 break;
4025 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4026 desc_ioc_state = "scsi device not there";
4027 break;
4028 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4029 desc_ioc_state = "scsi data overrun";
4030 break;
4031 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4032 desc_ioc_state = "scsi data underrun";
4033 break;
4034 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4035 desc_ioc_state = "scsi io data error";
4036 break;
4037 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4038 desc_ioc_state = "scsi protocol error";
4039 break;
4040 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4041 desc_ioc_state = "scsi task terminated";
4042 break;
4043 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4044 desc_ioc_state = "scsi residual mismatch";
4045 break;
4046 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4047 desc_ioc_state = "scsi task mgmt failed";
4048 break;
4049 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4050 desc_ioc_state = "scsi ioc terminated";
4051 break;
4052 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4053 desc_ioc_state = "scsi ext terminated";
4054 break;
Eric Moore3c621b32009-05-18 12:59:41 -06004055 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4056 desc_ioc_state = "eedp guard error";
4057 break;
4058 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4059 desc_ioc_state = "eedp ref tag error";
4060 break;
4061 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4062 desc_ioc_state = "eedp app tag error";
4063 break;
Eric Moore635374e2009-03-09 01:21:12 -06004064 default:
4065 desc_ioc_state = "unknown";
4066 break;
4067 }
4068
4069 switch (scsi_status) {
4070 case MPI2_SCSI_STATUS_GOOD:
4071 desc_scsi_status = "good";
4072 break;
4073 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4074 desc_scsi_status = "check condition";
4075 break;
4076 case MPI2_SCSI_STATUS_CONDITION_MET:
4077 desc_scsi_status = "condition met";
4078 break;
4079 case MPI2_SCSI_STATUS_BUSY:
4080 desc_scsi_status = "busy";
4081 break;
4082 case MPI2_SCSI_STATUS_INTERMEDIATE:
4083 desc_scsi_status = "intermediate";
4084 break;
4085 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4086 desc_scsi_status = "intermediate condmet";
4087 break;
4088 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4089 desc_scsi_status = "reservation conflict";
4090 break;
4091 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4092 desc_scsi_status = "command terminated";
4093 break;
4094 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4095 desc_scsi_status = "task set full";
4096 break;
4097 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4098 desc_scsi_status = "aca active";
4099 break;
4100 case MPI2_SCSI_STATUS_TASK_ABORTED:
4101 desc_scsi_status = "task aborted";
4102 break;
4103 default:
4104 desc_scsi_status = "unknown";
4105 break;
4106 }
4107
4108 desc_scsi_state[0] = '\0';
4109 if (!scsi_state)
4110 desc_scsi_state = " ";
4111 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4112 strcat(desc_scsi_state, "response info ");
4113 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4114 strcat(desc_scsi_state, "state terminated ");
4115 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4116 strcat(desc_scsi_state, "no status ");
4117 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4118 strcat(desc_scsi_state, "autosense failed ");
4119 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4120 strcat(desc_scsi_state, "autosense valid ");
4121
4122 scsi_print_command(scmd);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304123
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304124 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304125 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4126 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304127 } else {
4128 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4129 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4130 priv_target->sas_address);
4131 if (sas_device) {
4132 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4133 "phy(%d)\n", ioc->name, sas_device->sas_address,
4134 sas_device->phy);
4135 printk(MPT2SAS_WARN_FMT
4136 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4137 ioc->name, sas_device->enclosure_logical_id,
4138 sas_device->slot);
4139 }
4140 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304141 }
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304142
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304143 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4144 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4145 desc_ioc_state, ioc_status, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004146 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4147 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4148 scsi_get_resid(scmd));
4149 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4150 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4151 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4152 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4153 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4154 scsi_status, desc_scsi_state, scsi_state);
4155
4156 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4157 struct sense_info data;
4158 _scsih_normalize_sense(scmd->sense_buffer, &data);
4159 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304160 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4161 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
Eric Moore635374e2009-03-09 01:21:12 -06004162 }
4163
4164 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4165 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4166 response_bytes = (u8 *)&response_info;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304167 _scsih_response_code(ioc, response_bytes[0]);
Eric Moore635374e2009-03-09 01:21:12 -06004168 }
4169}
4170#endif
4171
4172/**
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304173 * _scsih_turn_on_fault_led - illuminate Fault LED
Eric Moore635374e2009-03-09 01:21:12 -06004174 * @ioc: per adapter object
4175 * @handle: device handle
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304176 * Context: process
4177 *
4178 * Return nothing.
4179 */
4180static void
4181_scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4182{
4183 Mpi2SepReply_t mpi_reply;
4184 Mpi2SepRequest_t mpi_request;
4185
4186 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4187 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4188 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4189 mpi_request.SlotStatus =
4190 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4191 mpi_request.DevHandle = cpu_to_le16(handle);
4192 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4193 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4194 &mpi_request)) != 0) {
4195 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4196 __FILE__, __LINE__, __func__);
4197 return;
4198 }
4199
4200 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4201 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4202 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4203 le16_to_cpu(mpi_reply.IOCStatus),
4204 le32_to_cpu(mpi_reply.IOCLogInfo)));
4205 return;
4206 }
4207}
4208
4209/**
4210 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4211 * @ioc: per adapter object
4212 * @handle: device handle
4213 * Context: interrupt.
4214 *
4215 * Return nothing.
4216 */
4217static void
4218_scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4219{
4220 struct fw_event_work *fw_event;
4221
4222 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4223 if (!fw_event)
4224 return;
4225 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4226 fw_event->device_handle = handle;
4227 fw_event->ioc = ioc;
4228 _scsih_fw_event_add(ioc, fw_event);
4229}
4230
4231/**
4232 * _scsih_smart_predicted_fault - process smart errors
4233 * @ioc: per adapter object
4234 * @handle: device handle
4235 * Context: interrupt.
Eric Moore635374e2009-03-09 01:21:12 -06004236 *
4237 * Return nothing.
4238 */
4239static void
4240_scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4241{
Eric Moore635374e2009-03-09 01:21:12 -06004242 struct scsi_target *starget;
4243 struct MPT2SAS_TARGET *sas_target_priv_data;
4244 Mpi2EventNotificationReply_t *event_reply;
4245 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4246 struct _sas_device *sas_device;
4247 ssize_t sz;
4248 unsigned long flags;
4249
4250 /* only handle non-raid devices */
4251 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4252 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4253 if (!sas_device) {
4254 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4255 return;
4256 }
4257 starget = sas_device->starget;
4258 sas_target_priv_data = starget->hostdata;
4259
4260 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4261 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4262 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4263 return;
4264 }
4265 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4266 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4267
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304268 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4269 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06004270
4271 /* insert into event log */
4272 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4273 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
4274 event_reply = kzalloc(sz, GFP_KERNEL);
4275 if (!event_reply) {
4276 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4277 ioc->name, __FILE__, __LINE__, __func__);
4278 return;
4279 }
4280
4281 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4282 event_reply->Event =
4283 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4284 event_reply->MsgLength = sz/4;
4285 event_reply->EventDataLength =
4286 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4287 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4288 event_reply->EventData;
4289 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4290 event_data->ASC = 0x5D;
4291 event_data->DevHandle = cpu_to_le16(handle);
4292 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4293 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4294 kfree(event_reply);
4295}
4296
4297/**
Eric Moored5d135b2009-05-18 13:02:08 -06004298 * _scsih_io_done - scsi request callback
Eric Moore635374e2009-03-09 01:21:12 -06004299 * @ioc: per adapter object
4300 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304301 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06004302 * @reply: reply message frame(lower 32bit addr)
4303 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304304 * Callback handler when using _scsih_qcmd.
Eric Moore635374e2009-03-09 01:21:12 -06004305 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304306 * Return 1 meaning mf should be freed from _base_interrupt
4307 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06004308 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304309static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304310_scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06004311{
4312 Mpi2SCSIIORequest_t *mpi_request;
4313 Mpi2SCSIIOReply_t *mpi_reply;
4314 struct scsi_cmnd *scmd;
4315 u16 ioc_status;
4316 u32 xfer_cnt;
4317 u8 scsi_state;
4318 u8 scsi_status;
4319 u32 log_info;
4320 struct MPT2SAS_DEVICE *sas_device_priv_data;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304321 u32 response_code = 0;
Kashyap, Desai82a45252011-07-05 12:40:23 +05304322 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06004323
4324 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05304325 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004326 if (scmd == NULL)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304327 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004328
4329 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4330
4331 if (mpi_reply == NULL) {
4332 scmd->result = DID_OK << 16;
4333 goto out;
4334 }
4335
4336 sas_device_priv_data = scmd->device->hostdata;
4337 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4338 sas_device_priv_data->sas_target->deleted) {
4339 scmd->result = DID_NO_CONNECT << 16;
4340 goto out;
4341 }
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304342 /*
4343 * WARPDRIVE: If direct_io is set then it is directIO,
4344 * the failed direct I/O should be redirected to volume
4345 */
4346 if (_scsih_scsi_direct_io_get(ioc, smid)) {
Kashyap, Desai82a45252011-07-05 12:40:23 +05304347 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4348 ioc->scsi_lookup[smid - 1].scmd = scmd;
4349 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304350 _scsih_scsi_direct_io_set(ioc, smid, 0);
4351 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4352 mpi_request->DevHandle =
4353 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4354 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4355 sas_device_priv_data->sas_target->handle);
4356 return 0;
4357 }
4358
Eric Moore635374e2009-03-09 01:21:12 -06004359
4360 /* turning off TLR */
Kashyap, Desai9982f592009-09-23 17:23:07 +05304361 scsi_state = mpi_reply->SCSIState;
4362 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4363 response_code =
4364 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
Eric Moore635374e2009-03-09 01:21:12 -06004365 if (!sas_device_priv_data->tlr_snoop_check) {
4366 sas_device_priv_data->tlr_snoop_check++;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304367 /* Make sure Device is not raid volume.
4368 * We do not expose raid functionality to upper layer for warpdrive.
4369 */
4370 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Kashyap, Desai3ed21522010-02-17 16:08:36 +05304371 sas_is_tlr_enabled(scmd->device) &&
Kashyap, Desai84f0b042009-12-16 18:56:28 +05304372 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4373 sas_disable_tlr(scmd->device);
4374 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4375 }
Eric Moore635374e2009-03-09 01:21:12 -06004376 }
4377
4378 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4379 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
4380 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
4381 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4382 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4383 else
4384 log_info = 0;
4385 ioc_status &= MPI2_IOCSTATUS_MASK;
Eric Moore635374e2009-03-09 01:21:12 -06004386 scsi_status = mpi_reply->SCSIStatus;
4387
4388 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4389 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4390 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4391 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4392 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4393 }
4394
4395 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4396 struct sense_info data;
4397 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4398 smid);
Eric Moore0d04df92009-04-21 15:38:43 -06004399 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
Eric Moore635374e2009-03-09 01:21:12 -06004400 le32_to_cpu(mpi_reply->SenseCount));
Eric Moore0d04df92009-04-21 15:38:43 -06004401 memcpy(scmd->sense_buffer, sense_data, sz);
Eric Moore635374e2009-03-09 01:21:12 -06004402 _scsih_normalize_sense(scmd->sense_buffer, &data);
4403 /* failure prediction threshold exceeded */
4404 if (data.asc == 0x5D)
4405 _scsih_smart_predicted_fault(ioc,
4406 le16_to_cpu(mpi_reply->DevHandle));
4407 }
4408
4409 switch (ioc_status) {
4410 case MPI2_IOCSTATUS_BUSY:
4411 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4412 scmd->result = SAM_STAT_BUSY;
4413 break;
4414
4415 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4416 scmd->result = DID_NO_CONNECT << 16;
4417 break;
4418
4419 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4420 if (sas_device_priv_data->block) {
Kashyap, Desaie4e7c7e2009-09-23 17:33:14 +05304421 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4422 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06004423 }
Eric Moore635374e2009-03-09 01:21:12 -06004424 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4425 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4426 scmd->result = DID_RESET << 16;
4427 break;
4428
4429 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4430 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4431 scmd->result = DID_SOFT_ERROR << 16;
4432 else
4433 scmd->result = (DID_OK << 16) | scsi_status;
4434 break;
4435
4436 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4437 scmd->result = (DID_OK << 16) | scsi_status;
4438
4439 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4440 break;
4441
4442 if (xfer_cnt < scmd->underflow) {
4443 if (scsi_status == SAM_STAT_BUSY)
4444 scmd->result = SAM_STAT_BUSY;
4445 else
4446 scmd->result = DID_SOFT_ERROR << 16;
4447 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4448 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4449 scmd->result = DID_SOFT_ERROR << 16;
4450 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4451 scmd->result = DID_RESET << 16;
4452 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4453 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4454 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4455 scmd->result = (DRIVER_SENSE << 24) |
4456 SAM_STAT_CHECK_CONDITION;
4457 scmd->sense_buffer[0] = 0x70;
4458 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4459 scmd->sense_buffer[12] = 0x20;
4460 scmd->sense_buffer[13] = 0;
4461 }
4462 break;
4463
4464 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4465 scsi_set_resid(scmd, 0);
4466 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4467 case MPI2_IOCSTATUS_SUCCESS:
4468 scmd->result = (DID_OK << 16) | scsi_status;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304469 if (response_code ==
4470 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4471 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4472 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
Eric Moore635374e2009-03-09 01:21:12 -06004473 scmd->result = DID_SOFT_ERROR << 16;
4474 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4475 scmd->result = DID_RESET << 16;
4476 break;
4477
Eric Moore3c621b32009-05-18 12:59:41 -06004478 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4479 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4480 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4481 _scsih_eedp_error_handling(scmd, ioc_status);
4482 break;
Eric Moore635374e2009-03-09 01:21:12 -06004483 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4484 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4485 case MPI2_IOCSTATUS_INVALID_SGL:
4486 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4487 case MPI2_IOCSTATUS_INVALID_FIELD:
4488 case MPI2_IOCSTATUS_INVALID_STATE:
4489 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4490 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4491 default:
4492 scmd->result = DID_SOFT_ERROR << 16;
4493 break;
4494
4495 }
4496
4497#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4498 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4499 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4500#endif
4501
4502 out:
4503 scsi_dma_unmap(scmd);
4504 scmd->scsi_done(scmd);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304505 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004506}
4507
4508/**
Eric Moore635374e2009-03-09 01:21:12 -06004509 * _scsih_sas_host_refresh - refreshing sas host object contents
4510 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06004511 * Context: user
4512 *
4513 * During port enable, fw will send topology events for every device. Its
4514 * possible that the handles may change from the previous setting, so this
4515 * code keeping handles updating if changed.
4516 *
4517 * Return nothing.
4518 */
4519static void
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304520_scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06004521{
4522 u16 sz;
4523 u16 ioc_status;
4524 int i;
4525 Mpi2ConfigReply_t mpi_reply;
4526 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304527 u16 attached_handle;
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304528 u8 link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06004529
4530 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4531 "updating handles for sas_host(0x%016llx)\n",
4532 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4533
4534 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4535 * sizeof(Mpi2SasIOUnit0PhyData_t));
4536 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4537 if (!sas_iounit_pg0) {
4538 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4539 ioc->name, __FILE__, __LINE__, __func__);
4540 return;
4541 }
Eric Moore635374e2009-03-09 01:21:12 -06004542
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304543 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4544 sas_iounit_pg0, sz)) != 0)
4545 goto out;
4546 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4547 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4548 goto out;
4549 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304550 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304551 if (i == 0)
4552 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4553 PhyData[0].ControllerDevHandle);
4554 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4555 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4556 AttachedDevHandle);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304557 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4558 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304559 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304560 attached_handle, i, link_rate);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304561 }
Eric Moore635374e2009-03-09 01:21:12 -06004562 out:
4563 kfree(sas_iounit_pg0);
4564}
4565
4566/**
4567 * _scsih_sas_host_add - create sas host object
4568 * @ioc: per adapter object
4569 *
4570 * Creating host side data object, stored in ioc->sas_hba
4571 *
4572 * Return nothing.
4573 */
4574static void
4575_scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4576{
4577 int i;
4578 Mpi2ConfigReply_t mpi_reply;
4579 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4580 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4581 Mpi2SasPhyPage0_t phy_pg0;
4582 Mpi2SasDevicePage0_t sas_device_pg0;
4583 Mpi2SasEnclosurePage0_t enclosure_pg0;
4584 u16 ioc_status;
4585 u16 sz;
4586 u16 device_missing_delay;
4587
4588 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4589 if (!ioc->sas_hba.num_phys) {
4590 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4591 ioc->name, __FILE__, __LINE__, __func__);
4592 return;
4593 }
4594
4595 /* sas_iounit page 0 */
4596 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4597 sizeof(Mpi2SasIOUnit0PhyData_t));
4598 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4599 if (!sas_iounit_pg0) {
4600 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4601 ioc->name, __FILE__, __LINE__, __func__);
4602 return;
4603 }
4604 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4605 sas_iounit_pg0, sz))) {
4606 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4607 ioc->name, __FILE__, __LINE__, __func__);
4608 goto out;
4609 }
4610 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4611 MPI2_IOCSTATUS_MASK;
4612 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4613 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4614 ioc->name, __FILE__, __LINE__, __func__);
4615 goto out;
4616 }
4617
4618 /* sas_iounit page 1 */
4619 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4620 sizeof(Mpi2SasIOUnit1PhyData_t));
4621 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4622 if (!sas_iounit_pg1) {
4623 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4624 ioc->name, __FILE__, __LINE__, __func__);
4625 goto out;
4626 }
4627 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4628 sas_iounit_pg1, sz))) {
4629 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4630 ioc->name, __FILE__, __LINE__, __func__);
4631 goto out;
4632 }
4633 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4634 MPI2_IOCSTATUS_MASK;
4635 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4636 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4637 ioc->name, __FILE__, __LINE__, __func__);
4638 goto out;
4639 }
4640
4641 ioc->io_missing_delay =
4642 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4643 device_missing_delay =
4644 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4645 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4646 ioc->device_missing_delay = (device_missing_delay &
4647 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4648 else
4649 ioc->device_missing_delay = device_missing_delay &
4650 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4651
4652 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4653 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4654 sizeof(struct _sas_phy), GFP_KERNEL);
4655 if (!ioc->sas_hba.phy) {
4656 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4657 ioc->name, __FILE__, __LINE__, __func__);
4658 goto out;
4659 }
4660 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4661 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4662 i))) {
4663 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4664 ioc->name, __FILE__, __LINE__, __func__);
4665 goto out;
4666 }
4667 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4668 MPI2_IOCSTATUS_MASK;
4669 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4670 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4671 ioc->name, __FILE__, __LINE__, __func__);
4672 goto out;
4673 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304674
4675 if (i == 0)
4676 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4677 PhyData[0].ControllerDevHandle);
4678 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
Eric Moore635374e2009-03-09 01:21:12 -06004679 ioc->sas_hba.phy[i].phy_id = i;
4680 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4681 phy_pg0, ioc->sas_hba.parent_dev);
4682 }
4683 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304684 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06004685 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4686 ioc->name, __FILE__, __LINE__, __func__);
4687 goto out;
4688 }
Eric Moore635374e2009-03-09 01:21:12 -06004689 ioc->sas_hba.enclosure_handle =
4690 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4691 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4692 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4693 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4694 (unsigned long long) ioc->sas_hba.sas_address,
4695 ioc->sas_hba.num_phys) ;
4696
4697 if (ioc->sas_hba.enclosure_handle) {
4698 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4699 &enclosure_pg0,
4700 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4701 ioc->sas_hba.enclosure_handle))) {
4702 ioc->sas_hba.enclosure_logical_id =
4703 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4704 }
4705 }
4706
4707 out:
4708 kfree(sas_iounit_pg1);
4709 kfree(sas_iounit_pg0);
4710}
4711
4712/**
4713 * _scsih_expander_add - creating expander object
4714 * @ioc: per adapter object
4715 * @handle: expander handle
4716 *
4717 * Creating expander object, stored in ioc->sas_expander_list.
4718 *
4719 * Return 0 for success, else error.
4720 */
4721static int
4722_scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4723{
4724 struct _sas_node *sas_expander;
4725 Mpi2ConfigReply_t mpi_reply;
4726 Mpi2ExpanderPage0_t expander_pg0;
4727 Mpi2ExpanderPage1_t expander_pg1;
4728 Mpi2SasEnclosurePage0_t enclosure_pg0;
4729 u32 ioc_status;
4730 u16 parent_handle;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05304731 u64 sas_address, sas_address_parent = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004732 int i;
4733 unsigned long flags;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304734 struct _sas_port *mpt2sas_port = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06004735 int rc = 0;
4736
4737 if (!handle)
4738 return -1;
4739
Eric Moore3cb54692010-07-08 14:44:34 -06004740 if (ioc->shost_recovery || ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304741 return -1;
4742
Eric Moore635374e2009-03-09 01:21:12 -06004743 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4744 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4745 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4746 ioc->name, __FILE__, __LINE__, __func__);
4747 return -1;
4748 }
4749
4750 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4751 MPI2_IOCSTATUS_MASK;
4752 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4753 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4754 ioc->name, __FILE__, __LINE__, __func__);
4755 return -1;
4756 }
4757
4758 /* handle out of order topology events */
4759 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304760 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4761 != 0) {
4762 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4763 ioc->name, __FILE__, __LINE__, __func__);
4764 return -1;
4765 }
4766 if (sas_address_parent != ioc->sas_hba.sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06004767 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304768 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4769 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004770 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4771 if (!sas_expander) {
4772 rc = _scsih_expander_add(ioc, parent_handle);
4773 if (rc != 0)
4774 return rc;
4775 }
4776 }
4777
Eric Moore635374e2009-03-09 01:21:12 -06004778 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304779 sas_address = le64_to_cpu(expander_pg0.SASAddress);
Eric Moore635374e2009-03-09 01:21:12 -06004780 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4781 sas_address);
4782 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4783
4784 if (sas_expander)
4785 return 0;
4786
4787 sas_expander = kzalloc(sizeof(struct _sas_node),
4788 GFP_KERNEL);
4789 if (!sas_expander) {
4790 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4791 ioc->name, __FILE__, __LINE__, __func__);
4792 return -1;
4793 }
4794
4795 sas_expander->handle = handle;
4796 sas_expander->num_phys = expander_pg0.NumPhys;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304797 sas_expander->sas_address_parent = sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06004798 sas_expander->sas_address = sas_address;
4799
4800 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4801 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304802 handle, parent_handle, (unsigned long long)
Eric Moore635374e2009-03-09 01:21:12 -06004803 sas_expander->sas_address, sas_expander->num_phys);
4804
4805 if (!sas_expander->num_phys)
4806 goto out_fail;
4807 sas_expander->phy = kcalloc(sas_expander->num_phys,
4808 sizeof(struct _sas_phy), GFP_KERNEL);
4809 if (!sas_expander->phy) {
4810 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4811 ioc->name, __FILE__, __LINE__, __func__);
4812 rc = -1;
4813 goto out_fail;
4814 }
4815
4816 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4817 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304818 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004819 if (!mpt2sas_port) {
4820 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4821 ioc->name, __FILE__, __LINE__, __func__);
4822 rc = -1;
4823 goto out_fail;
4824 }
4825 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4826
4827 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4828 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4829 &expander_pg1, i, handle))) {
4830 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4831 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai20f58952009-08-07 19:34:26 +05304832 rc = -1;
4833 goto out_fail;
Eric Moore635374e2009-03-09 01:21:12 -06004834 }
4835 sas_expander->phy[i].handle = handle;
4836 sas_expander->phy[i].phy_id = i;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304837
4838 if ((mpt2sas_transport_add_expander_phy(ioc,
4839 &sas_expander->phy[i], expander_pg1,
4840 sas_expander->parent_dev))) {
4841 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4842 ioc->name, __FILE__, __LINE__, __func__);
4843 rc = -1;
4844 goto out_fail;
4845 }
Eric Moore635374e2009-03-09 01:21:12 -06004846 }
4847
4848 if (sas_expander->enclosure_handle) {
4849 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4850 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4851 sas_expander->enclosure_handle))) {
4852 sas_expander->enclosure_logical_id =
4853 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4854 }
4855 }
4856
4857 _scsih_expander_node_add(ioc, sas_expander);
4858 return 0;
4859
4860 out_fail:
4861
Kashyap, Desai20f58952009-08-07 19:34:26 +05304862 if (mpt2sas_port)
4863 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304864 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004865 kfree(sas_expander);
4866 return rc;
4867}
4868
4869/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05304870 * _scsih_done - scsih callback handler.
4871 * @ioc: per adapter object
4872 * @smid: system request message index
4873 * @msix_index: MSIX table index supplied by the OS
4874 * @reply: reply message frame(lower 32bit addr)
4875 *
4876 * Callback handler when sending internal generated message frames.
4877 * The callback index passed is `ioc->scsih_cb_idx`
4878 *
4879 * Return 1 meaning mf should be freed from _base_interrupt
4880 * 0 means the mf is freed from this function.
4881 */
4882static u8
4883_scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4884{
4885 MPI2DefaultReply_t *mpi_reply;
4886
4887 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
4888 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
4889 return 1;
4890 if (ioc->scsih_cmds.smid != smid)
4891 return 1;
4892 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
4893 if (mpi_reply) {
4894 memcpy(ioc->scsih_cmds.reply, mpi_reply,
4895 mpi_reply->MsgLength*4);
4896 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
4897 }
4898 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
4899 complete(&ioc->scsih_cmds.done);
4900 return 1;
4901}
4902
4903/**
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304904 * mpt2sas_expander_remove - removing expander object
Eric Moore635374e2009-03-09 01:21:12 -06004905 * @ioc: per adapter object
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304906 * @sas_address: expander sas_address
Eric Moore635374e2009-03-09 01:21:12 -06004907 *
4908 * Return nothing.
4909 */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304910void
4911mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06004912{
4913 struct _sas_node *sas_expander;
4914 unsigned long flags;
4915
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304916 if (ioc->shost_recovery)
4917 return;
4918
Eric Moore635374e2009-03-09 01:21:12 -06004919 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304920 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4921 sas_address);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304922 if (!sas_expander) {
4923 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4924 return;
4925 }
4926 list_del(&sas_expander->list);
Eric Moore635374e2009-03-09 01:21:12 -06004927 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4928 _scsih_expander_node_remove(ioc, sas_expander);
4929}
4930
4931/**
Kashyap, Desaib4344272010-03-17 16:24:14 +05304932 * _scsih_check_access_status - check access flags
4933 * @ioc: per adapter object
4934 * @sas_address: sas address
4935 * @handle: sas device handle
4936 * @access_flags: errors returned during discovery of the device
4937 *
4938 * Return 0 for success, else failure
4939 */
4940static u8
4941_scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
4942 u16 handle, u8 access_status)
4943{
4944 u8 rc = 1;
4945 char *desc = NULL;
4946
4947 switch (access_status) {
4948 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
4949 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
4950 rc = 0;
4951 break;
4952 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
4953 desc = "sata capability failed";
4954 break;
4955 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
4956 desc = "sata affiliation conflict";
4957 break;
4958 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
4959 desc = "route not addressable";
4960 break;
4961 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
4962 desc = "smp error not addressable";
4963 break;
4964 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
4965 desc = "device blocked";
4966 break;
4967 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
4968 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
4969 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
4970 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
4971 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
4972 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
4973 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
4974 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
4975 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
4976 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
4977 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
4978 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
4979 desc = "sata initialization failed";
4980 break;
4981 default:
4982 desc = "unknown";
4983 break;
4984 }
4985
4986 if (!rc)
4987 return 0;
4988
4989 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
4990 "handle(0x%04x)\n", ioc->name, desc,
4991 (unsigned long long)sas_address, handle);
4992 return rc;
4993}
4994
4995static void
4996_scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4997{
4998 Mpi2ConfigReply_t mpi_reply;
4999 Mpi2SasDevicePage0_t sas_device_pg0;
5000 struct _sas_device *sas_device;
5001 u32 ioc_status;
5002 unsigned long flags;
5003 u64 sas_address;
5004 struct scsi_target *starget;
5005 struct MPT2SAS_TARGET *sas_target_priv_data;
5006 u32 device_info;
5007
5008 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5009 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5010 return;
5011
5012 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5013 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5014 return;
5015
5016 /* check if this is end device */
5017 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5018 if (!(_scsih_is_end_device(device_info)))
5019 return;
5020
5021 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5022 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5023 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5024 sas_address);
5025
5026 if (!sas_device) {
5027 printk(MPT2SAS_ERR_FMT "device is not present "
5028 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5029 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5030 return;
5031 }
5032
5033 if (unlikely(sas_device->handle != handle)) {
5034 starget = sas_device->starget;
5035 sas_target_priv_data = starget->hostdata;
5036 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5037 " to (0x%04x)!!!\n", sas_device->handle, handle);
5038 sas_target_priv_data->handle = handle;
5039 sas_device->handle = handle;
5040 }
5041 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5042
5043 /* check if device is present */
5044 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5045 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5046 printk(MPT2SAS_ERR_FMT "device is not present "
5047 "handle(0x%04x), flags!!!\n", ioc->name, handle);
5048 return;
5049 }
5050
5051 /* check if there were any issues with discovery */
5052 if (_scsih_check_access_status(ioc, sas_address, handle,
5053 sas_device_pg0.AccessStatus))
5054 return;
5055 _scsih_ublock_io_device(ioc, handle);
5056
5057}
5058
5059/**
Eric Moore635374e2009-03-09 01:21:12 -06005060 * _scsih_add_device - creating sas device object
5061 * @ioc: per adapter object
5062 * @handle: sas device handle
5063 * @phy_num: phy number end device attached to
5064 * @is_pd: is this hidden raid component
5065 *
5066 * Creating end device object, stored in ioc->sas_device_list.
5067 *
5068 * Returns 0 for success, non-zero for failure.
5069 */
5070static int
5071_scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5072{
5073 Mpi2ConfigReply_t mpi_reply;
5074 Mpi2SasDevicePage0_t sas_device_pg0;
5075 Mpi2SasEnclosurePage0_t enclosure_pg0;
5076 struct _sas_device *sas_device;
5077 u32 ioc_status;
5078 __le64 sas_address;
5079 u32 device_info;
5080 unsigned long flags;
5081
5082 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5083 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5084 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5085 ioc->name, __FILE__, __LINE__, __func__);
5086 return -1;
5087 }
5088
5089 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5090 MPI2_IOCSTATUS_MASK;
5091 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5092 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5093 ioc->name, __FILE__, __LINE__, __func__);
5094 return -1;
5095 }
5096
Kashyap, Desaib4344272010-03-17 16:24:14 +05305097 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5098
Eric Moore635374e2009-03-09 01:21:12 -06005099 /* check if device is present */
5100 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5101 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5102 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5103 ioc->name, __FILE__, __LINE__, __func__);
5104 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5105 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5106 return -1;
5107 }
5108
Kashyap, Desaib4344272010-03-17 16:24:14 +05305109 /* check if there were any issues with discovery */
5110 if (_scsih_check_access_status(ioc, sas_address, handle,
5111 sas_device_pg0.AccessStatus))
Eric Moore635374e2009-03-09 01:21:12 -06005112 return -1;
Eric Moore635374e2009-03-09 01:21:12 -06005113
5114 /* check if this is end device */
5115 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5116 if (!(_scsih_is_end_device(device_info))) {
5117 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5118 ioc->name, __FILE__, __LINE__, __func__);
5119 return -1;
5120 }
5121
Eric Moore635374e2009-03-09 01:21:12 -06005122
5123 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5124 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5125 sas_address);
5126 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5127
Kashyap, Desaib4344272010-03-17 16:24:14 +05305128 if (sas_device)
Eric Moore635374e2009-03-09 01:21:12 -06005129 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06005130
5131 sas_device = kzalloc(sizeof(struct _sas_device),
5132 GFP_KERNEL);
5133 if (!sas_device) {
5134 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5135 ioc->name, __FILE__, __LINE__, __func__);
5136 return -1;
5137 }
5138
5139 sas_device->handle = handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305140 if (_scsih_get_sas_address(ioc, le16_to_cpu
5141 (sas_device_pg0.ParentDevHandle),
5142 &sas_device->sas_address_parent) != 0)
5143 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5144 ioc->name, __FILE__, __LINE__, __func__);
Eric Moore635374e2009-03-09 01:21:12 -06005145 sas_device->enclosure_handle =
5146 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5147 sas_device->slot =
5148 le16_to_cpu(sas_device_pg0.Slot);
5149 sas_device->device_info = device_info;
5150 sas_device->sas_address = sas_address;
Kashyap, Desai7fbae672010-06-17 13:45:17 +05305151 sas_device->phy = sas_device_pg0.PhyNum;
Eric Moore635374e2009-03-09 01:21:12 -06005152
5153 /* get enclosure_logical_id */
Kashyap, Desai15052c92009-08-07 19:33:17 +05305154 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5155 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5156 sas_device->enclosure_handle)))
Eric Moore635374e2009-03-09 01:21:12 -06005157 sas_device->enclosure_logical_id =
5158 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
Eric Moore635374e2009-03-09 01:21:12 -06005159
5160 /* get device name */
5161 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5162
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305163 if (ioc->wait_for_discovery_to_complete)
Eric Moore635374e2009-03-09 01:21:12 -06005164 _scsih_sas_device_init_add(ioc, sas_device);
5165 else
5166 _scsih_sas_device_add(ioc, sas_device);
5167
5168 return 0;
5169}
5170
5171/**
Kashyap, Desai1278b112010-03-09 17:34:13 +05305172 * _scsih_remove_device - removing sas device object
5173 * @ioc: per adapter object
5174 * @sas_device_delete: the sas_device object
5175 *
5176 * Return nothing.
5177 */
5178static void
5179_scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5180 struct _sas_device *sas_device)
5181{
5182 struct _sas_device sas_device_backup;
5183 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05305184
Kashyap, Desai1278b112010-03-09 17:34:13 +05305185 if (!sas_device)
5186 return;
Eric Moore635374e2009-03-09 01:21:12 -06005187
Kashyap, Desai1278b112010-03-09 17:34:13 +05305188 memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device));
Eric Moore635374e2009-03-09 01:21:12 -06005189 _scsih_sas_device_remove(ioc, sas_device);
5190
Kashyap, Desai1278b112010-03-09 17:34:13 +05305191 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5192 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5193 sas_device_backup.handle, (unsigned long long)
5194 sas_device_backup.sas_address));
5195
5196 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
5197 sas_target_priv_data = sas_device_backup.starget->hostdata;
5198 sas_target_priv_data->deleted = 1;
5199 }
5200
Kashyap, Desai1278b112010-03-09 17:34:13 +05305201 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5202
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05305203 if (!ioc->hide_drives)
5204 mpt2sas_transport_port_remove(ioc,
5205 sas_device_backup.sas_address,
5206 sas_device_backup.sas_address_parent);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305207
5208 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
5209 "(0x%016llx)\n", ioc->name, sas_device_backup.handle,
5210 (unsigned long long) sas_device_backup.sas_address);
5211
5212 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5213 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
5214 sas_device_backup.handle, (unsigned long long)
5215 sas_device_backup.sas_address));
Eric Moore635374e2009-03-09 01:21:12 -06005216}
5217
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305218/**
5219 * mpt2sas_device_remove - removing device object
5220 * @ioc: per adapter object
5221 * @sas_address: expander sas_address
5222 *
5223 * Return nothing.
5224 */
5225void
5226mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
5227{
5228 struct _sas_device *sas_device;
5229 unsigned long flags;
5230
5231 if (ioc->shost_recovery)
5232 return;
5233
5234 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5235 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5236 sas_address);
5237 if (!sas_device) {
5238 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5239 return;
5240 }
5241 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5242 _scsih_remove_device(ioc, sas_device);
5243}
5244
Eric Moore635374e2009-03-09 01:21:12 -06005245#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5246/**
5247 * _scsih_sas_topology_change_event_debug - debug for topology event
5248 * @ioc: per adapter object
5249 * @event_data: event data payload
5250 * Context: user.
5251 */
5252static void
5253_scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5254 Mpi2EventDataSasTopologyChangeList_t *event_data)
5255{
5256 int i;
5257 u16 handle;
5258 u16 reason_code;
5259 u8 phy_number;
5260 char *status_str = NULL;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305261 u8 link_rate, prev_link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06005262
5263 switch (event_data->ExpStatus) {
5264 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5265 status_str = "add";
5266 break;
5267 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5268 status_str = "remove";
5269 break;
5270 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305271 case 0:
Eric Moore635374e2009-03-09 01:21:12 -06005272 status_str = "responding";
5273 break;
5274 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5275 status_str = "remove delay";
5276 break;
5277 default:
5278 status_str = "unknown status";
5279 break;
5280 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305281 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
Eric Moore635374e2009-03-09 01:21:12 -06005282 ioc->name, status_str);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305283 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
Eric Moore635374e2009-03-09 01:21:12 -06005284 "start_phy(%02d), count(%d)\n",
5285 le16_to_cpu(event_data->ExpanderDevHandle),
5286 le16_to_cpu(event_data->EnclosureHandle),
5287 event_data->StartPhyNum, event_data->NumEntries);
5288 for (i = 0; i < event_data->NumEntries; i++) {
5289 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5290 if (!handle)
5291 continue;
5292 phy_number = event_data->StartPhyNum + i;
5293 reason_code = event_data->PHY[i].PhyStatus &
5294 MPI2_EVENT_SAS_TOPO_RC_MASK;
5295 switch (reason_code) {
5296 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305297 status_str = "target add";
Eric Moore635374e2009-03-09 01:21:12 -06005298 break;
5299 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305300 status_str = "target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005301 break;
5302 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305303 status_str = "delay target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005304 break;
5305 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305306 status_str = "link rate change";
Eric Moore635374e2009-03-09 01:21:12 -06005307 break;
5308 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305309 status_str = "target responding";
Eric Moore635374e2009-03-09 01:21:12 -06005310 break;
5311 default:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305312 status_str = "unknown";
Eric Moore635374e2009-03-09 01:21:12 -06005313 break;
5314 }
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305315 link_rate = event_data->PHY[i].LinkRate >> 4;
5316 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305317 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305318 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5319 handle, status_str, link_rate, prev_link_rate);
5320
Eric Moore635374e2009-03-09 01:21:12 -06005321 }
5322}
5323#endif
5324
5325/**
5326 * _scsih_sas_topology_change_event - handle topology changes
5327 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305328 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005329 * Context: user.
5330 *
5331 */
5332static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305333_scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
Eric Moore635374e2009-03-09 01:21:12 -06005334 struct fw_event_work *fw_event)
5335{
5336 int i;
5337 u16 parent_handle, handle;
5338 u16 reason_code;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305339 u8 phy_number, max_phys;
Eric Moore635374e2009-03-09 01:21:12 -06005340 struct _sas_node *sas_expander;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305341 struct _sas_device *sas_device;
5342 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06005343 unsigned long flags;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305344 u8 link_rate, prev_link_rate;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305345 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06005346
5347#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5348 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5349 _scsih_sas_topology_change_event_debug(ioc, event_data);
5350#endif
5351
Eric Moore3cb54692010-07-08 14:44:34 -06005352 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305353 return;
5354
Eric Moore635374e2009-03-09 01:21:12 -06005355 if (!ioc->sas_hba.num_phys)
5356 _scsih_sas_host_add(ioc);
5357 else
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305358 _scsih_sas_host_refresh(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005359
5360 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305361 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
Eric Moore635374e2009-03-09 01:21:12 -06005362 "event\n", ioc->name));
5363 return;
5364 }
5365
5366 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5367
5368 /* handle expander add */
5369 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5370 if (_scsih_expander_add(ioc, parent_handle) != 0)
5371 return;
5372
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305373 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5374 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5375 parent_handle);
5376 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305377 if (sas_expander) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305378 sas_address = sas_expander->sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305379 max_phys = sas_expander->num_phys;
5380 } else if (parent_handle < ioc->sas_hba.num_phys) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305381 sas_address = ioc->sas_hba.sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305382 max_phys = ioc->sas_hba.num_phys;
5383 } else
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305384 return;
5385
Eric Moore635374e2009-03-09 01:21:12 -06005386 /* handle siblings events */
5387 for (i = 0; i < event_data->NumEntries; i++) {
5388 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305389 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
Eric Moore635374e2009-03-09 01:21:12 -06005390 "expander event\n", ioc->name));
5391 return;
5392 }
Eric Moore3cb54692010-07-08 14:44:34 -06005393 if (ioc->shost_recovery || ioc->remove_host ||
5394 ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305395 return;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305396 phy_number = event_data->StartPhyNum + i;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305397 if (phy_number >= max_phys)
5398 continue;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305399 reason_code = event_data->PHY[i].PhyStatus &
5400 MPI2_EVENT_SAS_TOPO_RC_MASK;
5401 if ((event_data->PHY[i].PhyStatus &
5402 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5403 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
Eric Moore635374e2009-03-09 01:21:12 -06005404 continue;
5405 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5406 if (!handle)
5407 continue;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305408 link_rate = event_data->PHY[i].LinkRate >> 4;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305409 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Eric Moore635374e2009-03-09 01:21:12 -06005410 switch (reason_code) {
5411 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305412
5413 if (link_rate == prev_link_rate)
5414 break;
5415
5416 mpt2sas_transport_update_links(ioc, sas_address,
5417 handle, phy_number, link_rate);
5418
Kashyap, Desaib4344272010-03-17 16:24:14 +05305419 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5420 break;
5421
5422 _scsih_check_device(ioc, handle);
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305423 break;
Eric Moore635374e2009-03-09 01:21:12 -06005424 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305425
5426 mpt2sas_transport_update_links(ioc, sas_address,
5427 handle, phy_number, link_rate);
5428
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305429 _scsih_add_device(ioc, handle, phy_number, 0);
Eric Moore635374e2009-03-09 01:21:12 -06005430 break;
5431 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305432
5433 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5434 sas_device = _scsih_sas_device_find_by_handle(ioc,
5435 handle);
5436 if (!sas_device) {
5437 spin_unlock_irqrestore(&ioc->sas_device_lock,
5438 flags);
5439 break;
5440 }
5441 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5442 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06005443 break;
5444 }
5445 }
5446
5447 /* handle expander removal */
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305448 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5449 sas_expander)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305450 mpt2sas_expander_remove(ioc, sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06005451
5452}
5453
5454#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5455/**
5456 * _scsih_sas_device_status_change_event_debug - debug for device event
5457 * @event_data: event data payload
5458 * Context: user.
5459 *
5460 * Return nothing.
5461 */
5462static void
5463_scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5464 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5465{
5466 char *reason_str = NULL;
5467
5468 switch (event_data->ReasonCode) {
5469 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5470 reason_str = "smart data";
5471 break;
5472 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5473 reason_str = "unsupported device discovered";
5474 break;
5475 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5476 reason_str = "internal device reset";
5477 break;
5478 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5479 reason_str = "internal task abort";
5480 break;
5481 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5482 reason_str = "internal task abort set";
5483 break;
5484 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5485 reason_str = "internal clear task set";
5486 break;
5487 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5488 reason_str = "internal query task";
5489 break;
5490 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5491 reason_str = "sata init failure";
5492 break;
5493 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5494 reason_str = "internal device reset complete";
5495 break;
5496 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5497 reason_str = "internal task abort complete";
5498 break;
5499 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5500 reason_str = "internal async notification";
5501 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05305502 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5503 reason_str = "expander reduced functionality";
5504 break;
5505 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5506 reason_str = "expander reduced functionality complete";
5507 break;
Eric Moore635374e2009-03-09 01:21:12 -06005508 default:
5509 reason_str = "unknown reason";
5510 break;
5511 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305512 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305513 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5514 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5515 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5516 le16_to_cpu(event_data->TaskTag));
Eric Moore635374e2009-03-09 01:21:12 -06005517 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305518 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005519 event_data->ASC, event_data->ASCQ);
5520 printk(KERN_INFO "\n");
5521}
5522#endif
5523
5524/**
5525 * _scsih_sas_device_status_change_event - handle device status change
5526 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305527 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005528 * Context: user.
5529 *
5530 * Return nothing.
5531 */
5532static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305533_scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5534 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005535{
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305536 struct MPT2SAS_TARGET *target_priv_data;
5537 struct _sas_device *sas_device;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05305538 u64 sas_address;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305539 unsigned long flags;
5540 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5541 fw_event->event_data;
5542
Eric Moore635374e2009-03-09 01:21:12 -06005543#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5544 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305545 _scsih_sas_device_status_change_event_debug(ioc,
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305546 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005547#endif
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305548
Kashyap, Desaiefe82a12011-01-04 11:34:17 +05305549 /* In MPI Revision K (0xC), the internal device reset complete was
5550 * implemented, so avoid setting tm_busy flag for older firmware.
5551 */
5552 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5553 return;
5554
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305555 if (event_data->ReasonCode !=
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305556 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305557 event_data->ReasonCode !=
5558 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305559 return;
5560
5561 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5562 sas_address = le64_to_cpu(event_data->SASAddress);
5563 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5564 sas_address);
5565 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5566
5567 if (!sas_device || !sas_device->starget)
5568 return;
5569
5570 target_priv_data = sas_device->starget->hostdata;
5571 if (!target_priv_data)
5572 return;
5573
5574 if (event_data->ReasonCode ==
5575 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5576 target_priv_data->tm_busy = 1;
5577 else
5578 target_priv_data->tm_busy = 0;
Eric Moore635374e2009-03-09 01:21:12 -06005579}
5580
5581#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5582/**
5583 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5584 * @ioc: per adapter object
5585 * @event_data: event data payload
5586 * Context: user.
5587 *
5588 * Return nothing.
5589 */
5590static void
5591_scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5592 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5593{
5594 char *reason_str = NULL;
5595
5596 switch (event_data->ReasonCode) {
5597 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5598 reason_str = "enclosure add";
5599 break;
5600 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5601 reason_str = "enclosure remove";
5602 break;
5603 default:
5604 reason_str = "unknown reason";
5605 break;
5606 }
5607
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305608 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
Eric Moore635374e2009-03-09 01:21:12 -06005609 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5610 " number slots(%d)\n", ioc->name, reason_str,
5611 le16_to_cpu(event_data->EnclosureHandle),
5612 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5613 le16_to_cpu(event_data->StartSlot));
5614}
5615#endif
5616
5617/**
5618 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5619 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305620 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005621 * Context: user.
5622 *
5623 * Return nothing.
5624 */
5625static void
5626_scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305627 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005628{
5629#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5630 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5631 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305632 fw_event->event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005633#endif
5634}
5635
5636/**
5637 * _scsih_sas_broadcast_primative_event - handle broadcast events
5638 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305639 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005640 * Context: user.
5641 *
5642 * Return nothing.
5643 */
5644static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305645_scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
5646 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005647{
5648 struct scsi_cmnd *scmd;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305649 struct scsi_device *sdev;
Eric Moore635374e2009-03-09 01:21:12 -06005650 u16 smid, handle;
5651 u32 lun;
5652 struct MPT2SAS_DEVICE *sas_device_priv_data;
5653 u32 termination_count;
5654 u32 query_count;
5655 Mpi2SCSITaskManagementReply_t *mpi_reply;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305656 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
Kashyap, Desai463217b2009-10-05 15:53:06 +05305657 u16 ioc_status;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305658 unsigned long flags;
5659 int r;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305660 u8 max_retries = 0;
5661 u8 task_abort_retries;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305662
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305663 mutex_lock(&ioc->tm_cmds.mutex);
5664 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), "
5665 "width(%d)\n", ioc->name, __func__, event_data->PhyNum,
5666 event_data->PortWidth));
5667
5668 _scsih_block_io_all_device(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005669
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305670 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305671 mpi_reply = ioc->tm_cmds.reply;
5672broadcast_aen_retry:
5673
5674 /* sanity checks for retrying this loop */
5675 if (max_retries++ == 5) {
5676 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5677 ioc->name, __func__));
5678 goto out;
5679 } else if (max_retries > 1)
5680 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5681 ioc->name, __func__, max_retries - 1));
5682
Eric Moore635374e2009-03-09 01:21:12 -06005683 termination_count = 0;
5684 query_count = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305685 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305686 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305687 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06005688 scmd = _scsih_scsi_lookup_get(ioc, smid);
5689 if (!scmd)
5690 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305691 sdev = scmd->device;
5692 sas_device_priv_data = sdev->hostdata;
Eric Moore635374e2009-03-09 01:21:12 -06005693 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5694 continue;
5695 /* skip hidden raid components */
5696 if (sas_device_priv_data->sas_target->flags &
5697 MPT_TARGET_FLAGS_RAID_COMPONENT)
5698 continue;
5699 /* skip volumes */
5700 if (sas_device_priv_data->sas_target->flags &
5701 MPT_TARGET_FLAGS_VOLUME)
5702 continue;
5703
5704 handle = sas_device_priv_data->sas_target->handle;
5705 lun = sas_device_priv_data->lun;
5706 query_count++;
5707
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305708 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305709 goto out;
5710
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305711 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305712 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5713 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0,
5714 TM_MUTEX_OFF);
5715 if (r == FAILED) {
5716 sdev_printk(KERN_WARNING, sdev,
5717 "mpt2sas_scsih_issue_tm: FAILED when sending "
5718 "QUERY_TASK: scmd(%p)\n", scmd);
5719 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5720 goto broadcast_aen_retry;
5721 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05305722 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5723 & MPI2_IOCSTATUS_MASK;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305724 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5725 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5726 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5727 scmd);
5728 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5729 goto broadcast_aen_retry;
5730 }
5731
5732 /* see if IO is still owned by IOC and target */
5733 if (mpi_reply->ResponseCode ==
Eric Moore635374e2009-03-09 01:21:12 -06005734 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5735 mpi_reply->ResponseCode ==
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305736 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305737 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005738 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305739 }
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305740 task_abort_retries = 0;
5741 tm_retry:
5742 if (task_abort_retries++ == 60) {
5743 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5744 "%s: ABORT_TASK: giving up\n", ioc->name,
5745 __func__));
5746 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5747 goto broadcast_aen_retry;
5748 }
5749
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305750 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305751 goto out_no_lock;
5752
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305753 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5754 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305755 scmd->serial_number, TM_MUTEX_OFF);
5756 if (r == FAILED) {
5757 sdev_printk(KERN_WARNING, sdev,
5758 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305759 "scmd(%p)\n", scmd);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305760 goto tm_retry;
5761 }
5762
5763 if (task_abort_retries > 1)
5764 sdev_printk(KERN_WARNING, sdev,
5765 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5766 " scmd(%p)\n",
5767 task_abort_retries - 1, scmd);
5768
Eric Moore635374e2009-03-09 01:21:12 -06005769 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305770 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005771 }
Eric Moore635374e2009-03-09 01:21:12 -06005772
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305773 if (ioc->broadcast_aen_pending) {
5774 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5775 " pending AEN\n", ioc->name, __func__));
5776 ioc->broadcast_aen_pending = 0;
5777 goto broadcast_aen_retry;
5778 }
5779
5780 out:
5781 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5782 out_no_lock:
5783
5784 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06005785 "%s - exit, query_count = %d termination_count = %d\n",
5786 ioc->name, __func__, query_count, termination_count));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305787
5788 ioc->broadcast_aen_busy = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305789 if (!ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305790 _scsih_ublock_io_all_device(ioc);
5791 mutex_unlock(&ioc->tm_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06005792}
5793
5794/**
5795 * _scsih_sas_discovery_event - handle discovery events
5796 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305797 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005798 * Context: user.
5799 *
5800 * Return nothing.
5801 */
5802static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305803_scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5804 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005805{
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305806 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5807
Eric Moore635374e2009-03-09 01:21:12 -06005808#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5809 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305810 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005811 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5812 "start" : "stop");
5813 if (event_data->DiscoveryStatus)
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305814 printk("discovery_status(0x%08x)",
5815 le32_to_cpu(event_data->DiscoveryStatus));
Eric Moore635374e2009-03-09 01:21:12 -06005816 printk("\n");
5817 }
5818#endif
5819
5820 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5821 !ioc->sas_hba.num_phys)
5822 _scsih_sas_host_add(ioc);
5823}
5824
5825/**
5826 * _scsih_reprobe_lun - reprobing lun
5827 * @sdev: scsi device struct
5828 * @no_uld_attach: sdev->no_uld_attach flag setting
5829 *
5830 **/
5831static void
5832_scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5833{
5834 int rc;
5835
5836 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5837 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5838 sdev->no_uld_attach ? "hidding" : "exposing");
5839 rc = scsi_device_reprobe(sdev);
5840}
5841
5842/**
5843 * _scsih_reprobe_target - reprobing target
5844 * @starget: scsi target struct
5845 * @no_uld_attach: sdev->no_uld_attach flag setting
5846 *
5847 * Note: no_uld_attach flag determines whether the disk device is attached
5848 * to block layer. A value of `1` means to not attach.
5849 **/
5850static void
5851_scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
5852{
5853 struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
5854
5855 if (no_uld_attach)
5856 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
5857 else
5858 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
5859
5860 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
5861 _scsih_reprobe_lun);
5862}
5863/**
5864 * _scsih_sas_volume_add - add new volume
5865 * @ioc: per adapter object
5866 * @element: IR config element data
5867 * Context: user.
5868 *
5869 * Return nothing.
5870 */
5871static void
5872_scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
5873 Mpi2EventIrConfigElement_t *element)
5874{
5875 struct _raid_device *raid_device;
5876 unsigned long flags;
5877 u64 wwid;
5878 u16 handle = le16_to_cpu(element->VolDevHandle);
5879 int rc;
5880
Eric Moore635374e2009-03-09 01:21:12 -06005881 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
5882 if (!wwid) {
5883 printk(MPT2SAS_ERR_FMT
5884 "failure at %s:%d/%s()!\n", ioc->name,
5885 __FILE__, __LINE__, __func__);
5886 return;
5887 }
5888
5889 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5890 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
5891 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5892
5893 if (raid_device)
5894 return;
5895
5896 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
5897 if (!raid_device) {
5898 printk(MPT2SAS_ERR_FMT
5899 "failure at %s:%d/%s()!\n", ioc->name,
5900 __FILE__, __LINE__, __func__);
5901 return;
5902 }
5903
5904 raid_device->id = ioc->sas_id++;
5905 raid_device->channel = RAID_CHANNEL;
5906 raid_device->handle = handle;
5907 raid_device->wwid = wwid;
5908 _scsih_raid_device_add(ioc, raid_device);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305909 if (!ioc->wait_for_discovery_to_complete) {
Eric Moore635374e2009-03-09 01:21:12 -06005910 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5911 raid_device->id, 0);
5912 if (rc)
5913 _scsih_raid_device_remove(ioc, raid_device);
5914 } else
5915 _scsih_determine_boot_device(ioc, raid_device, 1);
5916}
5917
5918/**
5919 * _scsih_sas_volume_delete - delete volume
5920 * @ioc: per adapter object
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05305921 * @handle: volume device handle
Eric Moore635374e2009-03-09 01:21:12 -06005922 * Context: user.
5923 *
5924 * Return nothing.
5925 */
5926static void
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05305927_scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Eric Moore635374e2009-03-09 01:21:12 -06005928{
5929 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06005930 unsigned long flags;
5931 struct MPT2SAS_TARGET *sas_target_priv_data;
5932
Eric Moore635374e2009-03-09 01:21:12 -06005933 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5934 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5935 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5936 if (!raid_device)
5937 return;
5938 if (raid_device->starget) {
5939 sas_target_priv_data = raid_device->starget->hostdata;
5940 sas_target_priv_data->deleted = 1;
5941 scsi_remove_target(&raid_device->starget->dev);
5942 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05305943 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
5944 "(0x%016llx)\n", ioc->name, raid_device->handle,
5945 (unsigned long long) raid_device->wwid);
Eric Moore635374e2009-03-09 01:21:12 -06005946 _scsih_raid_device_remove(ioc, raid_device);
5947}
5948
5949/**
5950 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
5951 * @ioc: per adapter object
5952 * @element: IR config element data
5953 * Context: user.
5954 *
5955 * Return nothing.
5956 */
5957static void
5958_scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
5959 Mpi2EventIrConfigElement_t *element)
5960{
5961 struct _sas_device *sas_device;
5962 unsigned long flags;
5963 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5964
5965 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5966 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5967 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5968 if (!sas_device)
5969 return;
5970
5971 /* exposing raid component */
5972 sas_device->volume_handle = 0;
5973 sas_device->volume_wwid = 0;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05305974 clear_bit(handle, ioc->pd_handles);
Eric Moore635374e2009-03-09 01:21:12 -06005975 _scsih_reprobe_target(sas_device->starget, 0);
5976}
5977
5978/**
5979 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
5980 * @ioc: per adapter object
5981 * @element: IR config element data
5982 * Context: user.
5983 *
5984 * Return nothing.
5985 */
5986static void
5987_scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
5988 Mpi2EventIrConfigElement_t *element)
5989{
5990 struct _sas_device *sas_device;
5991 unsigned long flags;
5992 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
5993
5994 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5995 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5996 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5997 if (!sas_device)
5998 return;
5999
6000 /* hiding raid component */
6001 mpt2sas_config_get_volume_handle(ioc, handle,
6002 &sas_device->volume_handle);
6003 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
6004 &sas_device->volume_wwid);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306005 set_bit(handle, ioc->pd_handles);
Eric Moore635374e2009-03-09 01:21:12 -06006006 _scsih_reprobe_target(sas_device->starget, 1);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306007
Eric Moore635374e2009-03-09 01:21:12 -06006008}
6009
6010/**
6011 * _scsih_sas_pd_delete - delete pd component
6012 * @ioc: per adapter object
6013 * @element: IR config element data
6014 * Context: user.
6015 *
6016 * Return nothing.
6017 */
6018static void
6019_scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6020 Mpi2EventIrConfigElement_t *element)
6021{
6022 struct _sas_device *sas_device;
6023 unsigned long flags;
6024 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6025
6026 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6027 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6028 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6029 if (!sas_device)
6030 return;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306031 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06006032}
6033
6034/**
6035 * _scsih_sas_pd_add - remove pd component
6036 * @ioc: per adapter object
6037 * @element: IR config element data
6038 * Context: user.
6039 *
6040 * Return nothing.
6041 */
6042static void
6043_scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6044 Mpi2EventIrConfigElement_t *element)
6045{
6046 struct _sas_device *sas_device;
6047 unsigned long flags;
6048 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306049 Mpi2ConfigReply_t mpi_reply;
6050 Mpi2SasDevicePage0_t sas_device_pg0;
6051 u32 ioc_status;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306052 u64 sas_address;
6053 u16 parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006054
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306055 set_bit(handle, ioc->pd_handles);
6056
Eric Moore635374e2009-03-09 01:21:12 -06006057 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6058 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6059 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306060 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306061 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306062
6063 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6064 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6065 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6066 ioc->name, __FILE__, __LINE__, __func__);
6067 return;
6068 }
6069
6070 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6071 MPI2_IOCSTATUS_MASK;
6072 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6073 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6074 ioc->name, __FILE__, __LINE__, __func__);
6075 return;
6076 }
6077
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306078 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6079 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6080 mpt2sas_transport_update_links(ioc, sas_address, handle,
6081 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306082
6083 _scsih_add_device(ioc, handle, 0, 1);
Eric Moore635374e2009-03-09 01:21:12 -06006084}
6085
6086#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6087/**
6088 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6089 * @ioc: per adapter object
6090 * @event_data: event data payload
6091 * Context: user.
6092 *
6093 * Return nothing.
6094 */
6095static void
6096_scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6097 Mpi2EventDataIrConfigChangeList_t *event_data)
6098{
6099 Mpi2EventIrConfigElement_t *element;
6100 u8 element_type;
6101 int i;
6102 char *reason_str = NULL, *element_str = NULL;
6103
6104 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6105
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306106 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06006107 ioc->name, (le32_to_cpu(event_data->Flags) &
6108 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6109 "foreign" : "native", event_data->NumElements);
6110 for (i = 0; i < event_data->NumElements; i++, element++) {
6111 switch (element->ReasonCode) {
6112 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6113 reason_str = "add";
6114 break;
6115 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6116 reason_str = "remove";
6117 break;
6118 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6119 reason_str = "no change";
6120 break;
6121 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6122 reason_str = "hide";
6123 break;
6124 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6125 reason_str = "unhide";
6126 break;
6127 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6128 reason_str = "volume_created";
6129 break;
6130 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6131 reason_str = "volume_deleted";
6132 break;
6133 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6134 reason_str = "pd_created";
6135 break;
6136 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6137 reason_str = "pd_deleted";
6138 break;
6139 default:
6140 reason_str = "unknown reason";
6141 break;
6142 }
6143 element_type = le16_to_cpu(element->ElementFlags) &
6144 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6145 switch (element_type) {
6146 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6147 element_str = "volume";
6148 break;
6149 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6150 element_str = "phys disk";
6151 break;
6152 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6153 element_str = "hot spare";
6154 break;
6155 default:
6156 element_str = "unknown element";
6157 break;
6158 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306159 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
Eric Moore635374e2009-03-09 01:21:12 -06006160 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6161 reason_str, le16_to_cpu(element->VolDevHandle),
6162 le16_to_cpu(element->PhysDiskDevHandle),
6163 element->PhysDiskNum);
6164 }
6165}
6166#endif
6167
6168/**
6169 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6170 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306171 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006172 * Context: user.
6173 *
6174 * Return nothing.
6175 */
6176static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306177_scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6178 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006179{
6180 Mpi2EventIrConfigElement_t *element;
6181 int i;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306182 u8 foreign_config;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306183 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006184
6185#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306186 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6187 && !ioc->hide_ir_msg)
Eric Moore635374e2009-03-09 01:21:12 -06006188 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6189
6190#endif
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306191
6192 if (ioc->shost_recovery)
6193 return;
6194
Kashyap, Desai62727a72009-08-07 19:35:18 +05306195 foreign_config = (le32_to_cpu(event_data->Flags) &
6196 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
Eric Moore635374e2009-03-09 01:21:12 -06006197
6198 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6199 for (i = 0; i < event_data->NumElements; i++, element++) {
6200
6201 switch (element->ReasonCode) {
6202 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6203 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306204 if (!foreign_config)
6205 _scsih_sas_volume_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006206 break;
6207 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6208 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306209 if (!foreign_config)
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306210 _scsih_sas_volume_delete(ioc,
6211 le16_to_cpu(element->VolDevHandle));
Eric Moore635374e2009-03-09 01:21:12 -06006212 break;
6213 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306214 if (!ioc->is_warpdrive)
6215 _scsih_sas_pd_hide(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006216 break;
6217 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306218 if (!ioc->is_warpdrive)
6219 _scsih_sas_pd_expose(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006220 break;
6221 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306222 if (!ioc->is_warpdrive)
6223 _scsih_sas_pd_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006224 break;
6225 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306226 if (!ioc->is_warpdrive)
6227 _scsih_sas_pd_delete(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006228 break;
6229 }
6230 }
6231}
6232
6233/**
6234 * _scsih_sas_ir_volume_event - IR volume event
6235 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306236 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006237 * Context: user.
6238 *
6239 * Return nothing.
6240 */
6241static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306242_scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6243 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006244{
6245 u64 wwid;
6246 unsigned long flags;
6247 struct _raid_device *raid_device;
6248 u16 handle;
6249 u32 state;
6250 int rc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306251 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006252
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306253 if (ioc->shost_recovery)
6254 return;
6255
Eric Moore635374e2009-03-09 01:21:12 -06006256 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6257 return;
6258
6259 handle = le16_to_cpu(event_data->VolDevHandle);
6260 state = le32_to_cpu(event_data->NewValue);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306261 if (!ioc->hide_ir_msg)
6262 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6263 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6264 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006265
Eric Moore635374e2009-03-09 01:21:12 -06006266 switch (state) {
6267 case MPI2_RAID_VOL_STATE_MISSING:
6268 case MPI2_RAID_VOL_STATE_FAILED:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306269 _scsih_sas_volume_delete(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006270 break;
6271
6272 case MPI2_RAID_VOL_STATE_ONLINE:
6273 case MPI2_RAID_VOL_STATE_DEGRADED:
6274 case MPI2_RAID_VOL_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306275
6276 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6277 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6278 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6279
Eric Moore635374e2009-03-09 01:21:12 -06006280 if (raid_device)
6281 break;
6282
6283 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6284 if (!wwid) {
6285 printk(MPT2SAS_ERR_FMT
6286 "failure at %s:%d/%s()!\n", ioc->name,
6287 __FILE__, __LINE__, __func__);
6288 break;
6289 }
6290
6291 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6292 if (!raid_device) {
6293 printk(MPT2SAS_ERR_FMT
6294 "failure at %s:%d/%s()!\n", ioc->name,
6295 __FILE__, __LINE__, __func__);
6296 break;
6297 }
6298
6299 raid_device->id = ioc->sas_id++;
6300 raid_device->channel = RAID_CHANNEL;
6301 raid_device->handle = handle;
6302 raid_device->wwid = wwid;
6303 _scsih_raid_device_add(ioc, raid_device);
6304 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6305 raid_device->id, 0);
6306 if (rc)
6307 _scsih_raid_device_remove(ioc, raid_device);
6308 break;
6309
6310 case MPI2_RAID_VOL_STATE_INITIALIZING:
6311 default:
6312 break;
6313 }
6314}
6315
6316/**
6317 * _scsih_sas_ir_physical_disk_event - PD event
6318 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306319 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006320 * Context: user.
6321 *
6322 * Return nothing.
6323 */
6324static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306325_scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6326 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006327{
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306328 u16 handle, parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006329 u32 state;
6330 struct _sas_device *sas_device;
6331 unsigned long flags;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306332 Mpi2ConfigReply_t mpi_reply;
6333 Mpi2SasDevicePage0_t sas_device_pg0;
6334 u32 ioc_status;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306335 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306336 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006337
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306338 if (ioc->shost_recovery)
6339 return;
6340
Eric Moore635374e2009-03-09 01:21:12 -06006341 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6342 return;
6343
6344 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6345 state = le32_to_cpu(event_data->NewValue);
6346
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306347 if (!ioc->hide_ir_msg)
6348 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6349 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6350 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006351
Eric Moore635374e2009-03-09 01:21:12 -06006352 switch (state) {
Eric Moore635374e2009-03-09 01:21:12 -06006353 case MPI2_RAID_PD_STATE_ONLINE:
6354 case MPI2_RAID_PD_STATE_DEGRADED:
6355 case MPI2_RAID_PD_STATE_REBUILDING:
6356 case MPI2_RAID_PD_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306357 case MPI2_RAID_PD_STATE_HOT_SPARE:
6358
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306359 if (!ioc->is_warpdrive)
6360 set_bit(handle, ioc->pd_handles);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306361
6362 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6363 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6364 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6365
6366 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306367 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306368
6369 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6370 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6371 handle))) {
6372 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6373 ioc->name, __FILE__, __LINE__, __func__);
6374 return;
6375 }
6376
6377 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6378 MPI2_IOCSTATUS_MASK;
6379 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6380 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6381 ioc->name, __FILE__, __LINE__, __func__);
6382 return;
6383 }
6384
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306385 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6386 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6387 mpt2sas_transport_update_links(ioc, sas_address, handle,
6388 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306389
6390 _scsih_add_device(ioc, handle, 0, 1);
6391
Eric Moore635374e2009-03-09 01:21:12 -06006392 break;
6393
Kashyap, Desai62727a72009-08-07 19:35:18 +05306394 case MPI2_RAID_PD_STATE_OFFLINE:
Eric Moore635374e2009-03-09 01:21:12 -06006395 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6396 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
Eric Moore635374e2009-03-09 01:21:12 -06006397 default:
6398 break;
6399 }
6400}
6401
6402#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6403/**
6404 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6405 * @ioc: per adapter object
6406 * @event_data: event data payload
6407 * Context: user.
6408 *
6409 * Return nothing.
6410 */
6411static void
6412_scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6413 Mpi2EventDataIrOperationStatus_t *event_data)
6414{
6415 char *reason_str = NULL;
6416
6417 switch (event_data->RAIDOperation) {
6418 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6419 reason_str = "resync";
6420 break;
6421 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6422 reason_str = "online capacity expansion";
6423 break;
6424 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6425 reason_str = "consistency check";
6426 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306427 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6428 reason_str = "background init";
6429 break;
6430 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6431 reason_str = "make data consistent";
Eric Moore635374e2009-03-09 01:21:12 -06006432 break;
6433 }
6434
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306435 if (!reason_str)
6436 return;
6437
Eric Moore635374e2009-03-09 01:21:12 -06006438 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6439 "\thandle(0x%04x), percent complete(%d)\n",
6440 ioc->name, reason_str,
6441 le16_to_cpu(event_data->VolDevHandle),
6442 event_data->PercentComplete);
6443}
6444#endif
6445
6446/**
6447 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6448 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306449 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006450 * Context: user.
6451 *
6452 * Return nothing.
6453 */
6454static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306455_scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6456 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006457{
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306458 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6459 static struct _raid_device *raid_device;
6460 unsigned long flags;
6461 u16 handle;
6462
Eric Moore635374e2009-03-09 01:21:12 -06006463#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306464 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6465 && !ioc->hide_ir_msg)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306466 _scsih_sas_ir_operation_status_event_debug(ioc,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306467 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06006468#endif
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306469
6470 /* code added for raid transport support */
6471 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6472
6473 handle = le16_to_cpu(event_data->VolDevHandle);
6474
6475 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6476 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6477 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6478
6479 if (!raid_device)
6480 return;
6481
6482 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC)
6483 raid_device->percent_complete =
6484 event_data->PercentComplete;
6485 }
Eric Moore635374e2009-03-09 01:21:12 -06006486}
6487
6488/**
Kashyap, Desai14695852010-03-30 10:52:44 +05306489 * _scsih_prep_device_scan - initialize parameters prior to device scan
6490 * @ioc: per adapter object
6491 *
6492 * Set the deleted flag prior to device scan. If the device is found during
6493 * the scan, then we clear the deleted flag.
6494 */
6495static void
6496_scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6497{
6498 struct MPT2SAS_DEVICE *sas_device_priv_data;
6499 struct scsi_device *sdev;
6500
6501 shost_for_each_device(sdev, ioc->shost) {
6502 sas_device_priv_data = sdev->hostdata;
6503 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6504 sas_device_priv_data->sas_target->deleted = 1;
6505 }
6506}
6507
6508/**
Eric Moore635374e2009-03-09 01:21:12 -06006509 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6510 * @ioc: per adapter object
6511 * @sas_address: sas address
6512 * @slot: enclosure slot id
6513 * @handle: device handle
6514 *
6515 * After host reset, find out whether devices are still responding.
6516 * Used in _scsi_remove_unresponsive_sas_devices.
6517 *
6518 * Return nothing.
6519 */
6520static void
6521_scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6522 u16 slot, u16 handle)
6523{
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306524 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006525 struct scsi_target *starget;
6526 struct _sas_device *sas_device;
6527 unsigned long flags;
6528
6529 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6530 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6531 if (sas_device->sas_address == sas_address &&
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306532 sas_device->slot == slot) {
Eric Moore635374e2009-03-09 01:21:12 -06006533 sas_device->responding = 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05306534 starget = sas_device->starget;
Kashyap, Desai14695852010-03-30 10:52:44 +05306535 if (starget && starget->hostdata) {
6536 sas_target_priv_data = starget->hostdata;
6537 sas_target_priv_data->tm_busy = 0;
6538 sas_target_priv_data->deleted = 0;
6539 } else
6540 sas_target_priv_data = NULL;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306541 if (starget)
6542 starget_printk(KERN_INFO, starget,
6543 "handle(0x%04x), sas_addr(0x%016llx), "
6544 "enclosure logical id(0x%016llx), "
6545 "slot(%d)\n", handle,
6546 (unsigned long long)sas_device->sas_address,
6547 (unsigned long long)
6548 sas_device->enclosure_logical_id,
6549 sas_device->slot);
Eric Moore635374e2009-03-09 01:21:12 -06006550 if (sas_device->handle == handle)
6551 goto out;
6552 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6553 sas_device->handle);
6554 sas_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306555 if (sas_target_priv_data)
6556 sas_target_priv_data->handle = handle;
Eric Moore635374e2009-03-09 01:21:12 -06006557 goto out;
6558 }
6559 }
6560 out:
6561 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6562}
6563
6564/**
6565 * _scsih_search_responding_sas_devices -
6566 * @ioc: per adapter object
6567 *
6568 * After host reset, find out whether devices are still responding.
6569 * If not remove.
6570 *
6571 * Return nothing.
6572 */
6573static void
6574_scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6575{
6576 Mpi2SasDevicePage0_t sas_device_pg0;
6577 Mpi2ConfigReply_t mpi_reply;
6578 u16 ioc_status;
6579 __le64 sas_address;
6580 u16 handle;
6581 u32 device_info;
6582 u16 slot;
6583
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306584 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006585
6586 if (list_empty(&ioc->sas_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306587 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006588
6589 handle = 0xFFFF;
6590 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6591 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6592 handle))) {
6593 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6594 MPI2_IOCSTATUS_MASK;
6595 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6596 break;
6597 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6598 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6599 if (!(_scsih_is_end_device(device_info)))
6600 continue;
6601 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6602 slot = le16_to_cpu(sas_device_pg0.Slot);
6603 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6604 handle);
6605 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306606out:
6607 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6608 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006609}
6610
6611/**
6612 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6613 * @ioc: per adapter object
6614 * @wwid: world wide identifier for raid volume
6615 * @handle: device handle
6616 *
6617 * After host reset, find out whether devices are still responding.
6618 * Used in _scsi_remove_unresponsive_raid_devices.
6619 *
6620 * Return nothing.
6621 */
6622static void
6623_scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6624 u16 handle)
6625{
6626 struct MPT2SAS_TARGET *sas_target_priv_data;
6627 struct scsi_target *starget;
6628 struct _raid_device *raid_device;
6629 unsigned long flags;
6630
6631 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6632 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6633 if (raid_device->wwid == wwid && raid_device->starget) {
Kashyap, Desai14695852010-03-30 10:52:44 +05306634 starget = raid_device->starget;
6635 if (starget && starget->hostdata) {
6636 sas_target_priv_data = starget->hostdata;
6637 sas_target_priv_data->deleted = 0;
6638 } else
6639 sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006640 raid_device->responding = 1;
6641 starget_printk(KERN_INFO, raid_device->starget,
6642 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6643 (unsigned long long)raid_device->wwid);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306644 /*
6645 * WARPDRIVE: The handles of the PDs might have changed
6646 * across the host reset so re-initialize the
6647 * required data for Direct IO
6648 */
6649 _scsih_init_warpdrive_properties(ioc, raid_device);
Eric Moore635374e2009-03-09 01:21:12 -06006650 if (raid_device->handle == handle)
6651 goto out;
6652 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6653 raid_device->handle);
6654 raid_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306655 if (sas_target_priv_data)
6656 sas_target_priv_data->handle = handle;
Eric Moore635374e2009-03-09 01:21:12 -06006657 goto out;
6658 }
6659 }
6660 out:
6661 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6662}
6663
6664/**
6665 * _scsih_search_responding_raid_devices -
6666 * @ioc: per adapter object
6667 *
6668 * After host reset, find out whether devices are still responding.
6669 * If not remove.
6670 *
6671 * Return nothing.
6672 */
6673static void
6674_scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6675{
6676 Mpi2RaidVolPage1_t volume_pg1;
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306677 Mpi2RaidVolPage0_t volume_pg0;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306678 Mpi2RaidPhysDiskPage0_t pd_pg0;
Eric Moore635374e2009-03-09 01:21:12 -06006679 Mpi2ConfigReply_t mpi_reply;
6680 u16 ioc_status;
6681 u16 handle;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306682 u8 phys_disk_num;
Eric Moore635374e2009-03-09 01:21:12 -06006683
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306684 if (!ioc->ir_firmware)
6685 return;
6686
6687 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6688 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006689
6690 if (list_empty(&ioc->raid_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306691 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006692
6693 handle = 0xFFFF;
6694 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6695 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
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 handle = le16_to_cpu(volume_pg1.DevHandle);
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306701
6702 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6703 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6704 sizeof(Mpi2RaidVolPage0_t)))
6705 continue;
6706
6707 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6708 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6709 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6710 _scsih_mark_responding_raid_device(ioc,
6711 le64_to_cpu(volume_pg1.WWID), handle);
Eric Moore635374e2009-03-09 01:21:12 -06006712 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306713
6714 /* refresh the pd_handles */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306715 if (!ioc->is_warpdrive) {
6716 phys_disk_num = 0xFF;
6717 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6718 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6719 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6720 phys_disk_num))) {
6721 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6722 MPI2_IOCSTATUS_MASK;
6723 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6724 break;
6725 phys_disk_num = pd_pg0.PhysDiskNum;
6726 handle = le16_to_cpu(pd_pg0.DevHandle);
6727 set_bit(handle, ioc->pd_handles);
6728 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306729 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306730out:
6731 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6732 "complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006733}
6734
6735/**
6736 * _scsih_mark_responding_expander - mark a expander as responding
6737 * @ioc: per adapter object
6738 * @sas_address: sas address
6739 * @handle:
6740 *
6741 * After host reset, find out whether devices are still responding.
6742 * Used in _scsi_remove_unresponsive_expanders.
6743 *
6744 * Return nothing.
6745 */
6746static void
6747_scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6748 u16 handle)
6749{
6750 struct _sas_node *sas_expander;
6751 unsigned long flags;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306752 int i;
Eric Moore635374e2009-03-09 01:21:12 -06006753
6754 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6755 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306756 if (sas_expander->sas_address != sas_address)
6757 continue;
6758 sas_expander->responding = 1;
6759 if (sas_expander->handle == handle)
Eric Moore635374e2009-03-09 01:21:12 -06006760 goto out;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306761 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6762 " from(0x%04x) to (0x%04x)!!!\n",
6763 (unsigned long long)sas_expander->sas_address,
6764 sas_expander->handle, handle);
6765 sas_expander->handle = handle;
6766 for (i = 0 ; i < sas_expander->num_phys ; i++)
6767 sas_expander->phy[i].handle = handle;
6768 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006769 }
6770 out:
6771 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6772}
6773
6774/**
6775 * _scsih_search_responding_expanders -
6776 * @ioc: per adapter object
6777 *
6778 * After host reset, find out whether devices are still responding.
6779 * If not remove.
6780 *
6781 * Return nothing.
6782 */
6783static void
6784_scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6785{
6786 Mpi2ExpanderPage0_t expander_pg0;
6787 Mpi2ConfigReply_t mpi_reply;
6788 u16 ioc_status;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05306789 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006790 u16 handle;
6791
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306792 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006793
6794 if (list_empty(&ioc->sas_expander_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306795 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006796
6797 handle = 0xFFFF;
6798 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6799 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6800
6801 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6802 MPI2_IOCSTATUS_MASK;
6803 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6804 break;
6805
6806 handle = le16_to_cpu(expander_pg0.DevHandle);
6807 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6808 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6809 "sas_addr(0x%016llx)\n", handle,
6810 (unsigned long long)sas_address);
6811 _scsih_mark_responding_expander(ioc, sas_address, handle);
6812 }
6813
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306814 out:
6815 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006816}
6817
6818/**
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306819 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
Eric Moore635374e2009-03-09 01:21:12 -06006820 * @ioc: per adapter object
6821 *
6822 * Return nothing.
6823 */
6824static void
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306825_scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06006826{
6827 struct _sas_device *sas_device, *sas_device_next;
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05306828 struct _sas_node *sas_expander;
Eric Moore635374e2009-03-09 01:21:12 -06006829 struct _raid_device *raid_device, *raid_device_next;
Eric Moore635374e2009-03-09 01:21:12 -06006830
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306831 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
6832 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006833
6834 list_for_each_entry_safe(sas_device, sas_device_next,
6835 &ioc->sas_device_list, list) {
6836 if (sas_device->responding) {
6837 sas_device->responding = 0;
6838 continue;
6839 }
6840 if (sas_device->starget)
6841 starget_printk(KERN_INFO, sas_device->starget,
6842 "removing: handle(0x%04x), sas_addr(0x%016llx), "
6843 "enclosure logical id(0x%016llx), slot(%d)\n",
6844 sas_device->handle,
6845 (unsigned long long)sas_device->sas_address,
6846 (unsigned long long)
6847 sas_device->enclosure_logical_id,
6848 sas_device->slot);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306849 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06006850 }
6851
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306852 if (!ioc->ir_firmware)
6853 goto retry_expander_search;
6854
Eric Moore635374e2009-03-09 01:21:12 -06006855 list_for_each_entry_safe(raid_device, raid_device_next,
6856 &ioc->raid_device_list, list) {
6857 if (raid_device->responding) {
6858 raid_device->responding = 0;
6859 continue;
6860 }
6861 if (raid_device->starget) {
6862 starget_printk(KERN_INFO, raid_device->starget,
6863 "removing: handle(0x%04x), wwid(0x%016llx)\n",
6864 raid_device->handle,
6865 (unsigned long long)raid_device->wwid);
6866 scsi_remove_target(&raid_device->starget->dev);
6867 }
6868 _scsih_raid_device_remove(ioc, raid_device);
6869 }
6870
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05306871 retry_expander_search:
6872 sas_expander = NULL;
6873 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
Eric Moore635374e2009-03-09 01:21:12 -06006874 if (sas_expander->responding) {
6875 sas_expander->responding = 0;
6876 continue;
6877 }
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05306878 mpt2sas_expander_remove(ioc, sas_expander->sas_address);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05306879 goto retry_expander_search;
6880 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306881 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
6882 ioc->name);
6883 /* unblock devices */
6884 _scsih_ublock_io_all_device(ioc);
6885}
6886
6887static void
6888_scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
6889 struct _sas_node *sas_expander, u16 handle)
6890{
6891 Mpi2ExpanderPage1_t expander_pg1;
6892 Mpi2ConfigReply_t mpi_reply;
6893 int i;
6894
6895 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6896 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
6897 &expander_pg1, i, handle))) {
6898 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6899 ioc->name, __FILE__, __LINE__, __func__);
6900 return;
6901 }
6902
6903 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
6904 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6905 expander_pg1.NegotiatedLinkRate >> 4);
6906 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05306907}
6908
6909/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306910 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306911 * @ioc: per adapter object
6912 *
6913 * Return nothing.
6914 */
6915static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306916_scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306917{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306918 Mpi2ExpanderPage0_t expander_pg0;
6919 Mpi2SasDevicePage0_t sas_device_pg0;
6920 Mpi2RaidVolPage1_t volume_pg1;
6921 Mpi2RaidVolPage0_t volume_pg0;
6922 Mpi2RaidPhysDiskPage0_t pd_pg0;
6923 Mpi2EventIrConfigElement_t element;
6924 Mpi2ConfigReply_t mpi_reply;
6925 u8 phys_disk_num;
6926 u16 ioc_status;
6927 u16 handle, parent_handle;
6928 u64 sas_address;
6929 struct _sas_device *sas_device;
6930 struct _sas_node *expander_device;
6931 static struct _raid_device *raid_device;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306932
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306933 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306934
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306935 _scsih_sas_host_refresh(ioc);
6936
6937 /* expanders */
6938 handle = 0xFFFF;
6939 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6940 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6941 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6942 MPI2_IOCSTATUS_MASK;
6943 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6944 break;
6945 handle = le16_to_cpu(expander_pg0.DevHandle);
6946 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
6947 ioc, le64_to_cpu(expander_pg0.SASAddress));
6948 if (expander_device)
6949 _scsih_refresh_expander_links(ioc, expander_device,
6950 handle);
6951 else
6952 _scsih_expander_add(ioc, handle);
6953 }
6954
6955 if (!ioc->ir_firmware)
6956 goto skip_to_sas;
6957
6958 /* phys disk */
6959 phys_disk_num = 0xFF;
6960 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6961 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6962 phys_disk_num))) {
6963 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6964 MPI2_IOCSTATUS_MASK;
6965 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6966 break;
6967 phys_disk_num = pd_pg0.PhysDiskNum;
6968 handle = le16_to_cpu(pd_pg0.DevHandle);
6969 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6970 if (sas_device)
6971 continue;
6972 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6973 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6974 handle) != 0)
6975 continue;
6976 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6977 if (!_scsih_get_sas_address(ioc, parent_handle,
6978 &sas_address)) {
6979 mpt2sas_transport_update_links(ioc, sas_address,
6980 handle, sas_device_pg0.PhyNum,
6981 MPI2_SAS_NEG_LINK_RATE_1_5);
6982 set_bit(handle, ioc->pd_handles);
6983 _scsih_add_device(ioc, handle, 0, 1);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306984 }
6985 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306986
6987 /* volumes */
6988 handle = 0xFFFF;
6989 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6990 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6991 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6992 MPI2_IOCSTATUS_MASK;
6993 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6994 break;
6995 handle = le16_to_cpu(volume_pg1.DevHandle);
6996 raid_device = _scsih_raid_device_find_by_wwid(ioc,
6997 le64_to_cpu(volume_pg1.WWID));
6998 if (raid_device)
6999 continue;
7000 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7001 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7002 sizeof(Mpi2RaidVolPage0_t)))
7003 continue;
7004 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7005 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7006 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7007 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7008 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7009 element.VolDevHandle = volume_pg1.DevHandle;
7010 _scsih_sas_volume_add(ioc, &element);
7011 }
7012 }
7013
7014 skip_to_sas:
7015
7016 /* sas devices */
7017 handle = 0xFFFF;
7018 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7019 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7020 handle))) {
7021 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7022 MPI2_IOCSTATUS_MASK;
7023 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7024 break;
7025 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7026 if (!(_scsih_is_end_device(
7027 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7028 continue;
7029 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7030 le64_to_cpu(sas_device_pg0.SASAddress));
7031 if (sas_device)
7032 continue;
7033 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7034 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7035 mpt2sas_transport_update_links(ioc, sas_address, handle,
7036 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7037 _scsih_add_device(ioc, handle, 0, 0);
7038 }
7039 }
7040
7041 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307042}
7043
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307044
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307045/**
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307046 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7047 * @ioc: per adapter object
7048 * @reset_phase: phase
7049 *
7050 * The handler for doing any required cleanup or initialization.
7051 *
7052 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7053 * MPT2_IOC_DONE_RESET
7054 *
7055 * Return nothing.
7056 */
7057void
7058mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7059{
7060 switch (reset_phase) {
7061 case MPT2_IOC_PRE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307062 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307063 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307064 break;
7065 case MPT2_IOC_AFTER_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307066 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307067 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307068 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7069 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7070 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7071 complete(&ioc->scsih_cmds.done);
7072 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307073 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7074 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7075 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7076 complete(&ioc->tm_cmds.done);
7077 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307078 _scsih_fw_event_cleanup_queue(ioc);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307079 _scsih_flush_running_cmds(ioc);
7080 break;
7081 case MPT2_IOC_DONE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307082 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307083 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307084 _scsih_sas_host_refresh(ioc);
Kashyap, Desai14695852010-03-30 10:52:44 +05307085 _scsih_prep_device_scan(ioc);
7086 _scsih_search_responding_sas_devices(ioc);
7087 _scsih_search_responding_raid_devices(ioc);
7088 _scsih_search_responding_expanders(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307089 _scsih_error_recovery_delete_devices(ioc);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307090 break;
Eric Moore635374e2009-03-09 01:21:12 -06007091 }
7092}
7093
7094/**
7095 * _firmware_event_work - delayed task for processing firmware events
7096 * @ioc: per adapter object
7097 * @work: equal to the fw_event_work object
7098 * Context: user.
7099 *
7100 * Return nothing.
7101 */
7102static void
7103_firmware_event_work(struct work_struct *work)
7104{
7105 struct fw_event_work *fw_event = container_of(work,
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307106 struct fw_event_work, delayed_work.work);
Eric Moore635374e2009-03-09 01:21:12 -06007107 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7108
Eric Moore635374e2009-03-09 01:21:12 -06007109 /* the queue is being flushed so ignore this event */
Eric Moore3cb54692010-07-08 14:44:34 -06007110 if (ioc->remove_host || fw_event->cancel_pending_work ||
7111 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06007112 _scsih_fw_event_free(ioc, fw_event);
7113 return;
7114 }
Eric Moore635374e2009-03-09 01:21:12 -06007115
Eric Moore635374e2009-03-09 01:21:12 -06007116 switch (fw_event->event) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307117 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
7118 while (scsi_host_in_recovery(ioc->shost))
7119 ssleep(1);
7120 _scsih_remove_unresponding_sas_devices(ioc);
7121 _scsih_scan_for_devices_after_reset(ioc);
7122 break;
7123 case MPT2SAS_PORT_ENABLE_COMPLETE:
7124 if (!ioc->is_driver_loading && ioc->shost_recovery) {
7125 _scsih_prep_device_scan(ioc);
7126 _scsih_search_responding_sas_devices(ioc);
7127 _scsih_search_responding_raid_devices(ioc);
7128 _scsih_search_responding_expanders(ioc);
7129 }
7130
7131 if (ioc->start_scan)
7132 ioc->start_scan = 0;
7133 else
7134 complete(&ioc->port_enable_done);
7135
7136
7137
7138 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7139 "from worker thread\n", ioc->name));
7140 break;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05307141 case MPT2SAS_TURN_ON_FAULT_LED:
7142 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
7143 break;
Eric Moore635374e2009-03-09 01:21:12 -06007144 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307145 _scsih_sas_topology_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007146 break;
7147 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307148 _scsih_sas_device_status_change_event(ioc,
7149 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007150 break;
7151 case MPI2_EVENT_SAS_DISCOVERY:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307152 _scsih_sas_discovery_event(ioc,
7153 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007154 break;
7155 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307156 _scsih_sas_broadcast_primative_event(ioc,
7157 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007158 break;
7159 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7160 _scsih_sas_enclosure_dev_status_change_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307161 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007162 break;
7163 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307164 _scsih_sas_ir_config_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007165 break;
7166 case MPI2_EVENT_IR_VOLUME:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307167 _scsih_sas_ir_volume_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007168 break;
7169 case MPI2_EVENT_IR_PHYSICAL_DISK:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307170 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007171 break;
7172 case MPI2_EVENT_IR_OPERATION_STATUS:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307173 _scsih_sas_ir_operation_status_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007174 break;
Eric Moore635374e2009-03-09 01:21:12 -06007175 }
7176 _scsih_fw_event_free(ioc, fw_event);
7177}
7178
7179/**
7180 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7181 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307182 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06007183 * @reply: reply message frame(lower 32bit addr)
7184 * Context: interrupt.
7185 *
7186 * This function merely adds a new work task into ioc->firmware_event_thread.
7187 * The tasks are worked from _firmware_event_work in user context.
7188 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307189 * Return 1 meaning mf should be freed from _base_interrupt
7190 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06007191 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307192u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307193mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7194 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06007195{
7196 struct fw_event_work *fw_event;
7197 Mpi2EventNotificationReply_t *mpi_reply;
Eric Moore635374e2009-03-09 01:21:12 -06007198 u16 event;
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307199 u16 sz;
Eric Moore635374e2009-03-09 01:21:12 -06007200
7201 /* events turned off due to host reset or driver unloading */
Eric Moore3cb54692010-07-08 14:44:34 -06007202 if (ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307203 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007204
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307205 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Eric Moore635374e2009-03-09 01:21:12 -06007206 event = le16_to_cpu(mpi_reply->Event);
7207
7208 switch (event) {
7209 /* handle these */
7210 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7211 {
7212 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7213 (Mpi2EventDataSasBroadcastPrimitive_t *)
7214 mpi_reply->EventData;
7215
7216 if (baen_data->Primitive !=
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307217 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307218 return 1;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307219
7220 if (ioc->broadcast_aen_busy) {
7221 ioc->broadcast_aen_pending++;
7222 return 1;
7223 } else
7224 ioc->broadcast_aen_busy = 1;
Eric Moore635374e2009-03-09 01:21:12 -06007225 break;
7226 }
7227
7228 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7229 _scsih_check_topo_delete_events(ioc,
7230 (Mpi2EventDataSasTopologyChangeList_t *)
7231 mpi_reply->EventData);
7232 break;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307233 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7234 _scsih_check_ir_config_unhide_events(ioc,
7235 (Mpi2EventDataIrConfigChangeList_t *)
7236 mpi_reply->EventData);
7237 break;
7238 case MPI2_EVENT_IR_VOLUME:
7239 _scsih_check_volume_delete_events(ioc,
7240 (Mpi2EventDataIrVolume_t *)
7241 mpi_reply->EventData);
7242 break;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307243 case MPI2_EVENT_LOG_ENTRY_ADDED:
7244 {
7245 Mpi2EventDataLogEntryAdded_t *log_entry;
7246 u32 *log_code;
7247
7248 if (!ioc->is_warpdrive)
7249 break;
7250
7251 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7252 mpi_reply->EventData;
7253 log_code = (u32 *)log_entry->LogData;
7254
7255 if (le16_to_cpu(log_entry->LogEntryQualifier)
7256 != MPT2_WARPDRIVE_LOGENTRY)
7257 break;
7258
7259 switch (le32_to_cpu(*log_code)) {
7260 case MPT2_WARPDRIVE_LC_SSDT:
7261 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7262 "IO Throttling has occurred in the WarpDrive "
7263 "subsystem. Check WarpDrive documentation for "
7264 "additional details.\n", ioc->name);
7265 break;
7266 case MPT2_WARPDRIVE_LC_SSDLW:
7267 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7268 "Program/Erase Cycles for the WarpDrive subsystem "
7269 "in degraded range. Check WarpDrive documentation "
7270 "for additional details.\n", ioc->name);
7271 break;
7272 case MPT2_WARPDRIVE_LC_SSDLF:
7273 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7274 "There are no Program/Erase Cycles for the "
7275 "WarpDrive subsystem. The storage device will be "
7276 "in read-only mode. Check WarpDrive documentation "
7277 "for additional details.\n", ioc->name);
7278 break;
7279 case MPT2_WARPDRIVE_LC_BRMF:
7280 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7281 "The Backup Rail Monitor has failed on the "
7282 "WarpDrive subsystem. Check WarpDrive "
7283 "documentation for additional details.\n",
7284 ioc->name);
7285 break;
7286 }
7287
7288 break;
7289 }
Eric Moore635374e2009-03-09 01:21:12 -06007290 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7291 case MPI2_EVENT_IR_OPERATION_STATUS:
7292 case MPI2_EVENT_SAS_DISCOVERY:
7293 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
Eric Moore635374e2009-03-09 01:21:12 -06007294 case MPI2_EVENT_IR_PHYSICAL_DISK:
Eric Moore635374e2009-03-09 01:21:12 -06007295 break;
7296
7297 default: /* ignore the rest */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307298 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007299 }
7300
7301 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
7302 if (!fw_event) {
7303 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7304 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307305 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007306 }
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307307 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7308 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06007309 if (!fw_event->event_data) {
7310 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7311 ioc->name, __FILE__, __LINE__, __func__);
7312 kfree(fw_event);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307313 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007314 }
7315
7316 memcpy(fw_event->event_data, mpi_reply->EventData,
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307317 sz);
Eric Moore635374e2009-03-09 01:21:12 -06007318 fw_event->ioc = ioc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307319 fw_event->VF_ID = mpi_reply->VF_ID;
7320 fw_event->VP_ID = mpi_reply->VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -06007321 fw_event->event = event;
7322 _scsih_fw_event_add(ioc, fw_event);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307323 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007324}
7325
7326/* shost template */
7327static struct scsi_host_template scsih_driver_template = {
7328 .module = THIS_MODULE,
7329 .name = "Fusion MPT SAS Host",
7330 .proc_name = MPT2SAS_DRIVER_NAME,
Eric Moored5d135b2009-05-18 13:02:08 -06007331 .queuecommand = _scsih_qcmd,
7332 .target_alloc = _scsih_target_alloc,
7333 .slave_alloc = _scsih_slave_alloc,
7334 .slave_configure = _scsih_slave_configure,
7335 .target_destroy = _scsih_target_destroy,
7336 .slave_destroy = _scsih_slave_destroy,
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307337 .scan_finished = _scsih_scan_finished,
7338 .scan_start = _scsih_scan_start,
Eric Moored5d135b2009-05-18 13:02:08 -06007339 .change_queue_depth = _scsih_change_queue_depth,
7340 .change_queue_type = _scsih_change_queue_type,
7341 .eh_abort_handler = _scsih_abort,
7342 .eh_device_reset_handler = _scsih_dev_reset,
7343 .eh_target_reset_handler = _scsih_target_reset,
7344 .eh_host_reset_handler = _scsih_host_reset,
7345 .bios_param = _scsih_bios_param,
Eric Moore635374e2009-03-09 01:21:12 -06007346 .can_queue = 1,
7347 .this_id = -1,
7348 .sg_tablesize = MPT2SAS_SG_DEPTH,
7349 .max_sectors = 8192,
7350 .cmd_per_lun = 7,
7351 .use_clustering = ENABLE_CLUSTERING,
7352 .shost_attrs = mpt2sas_host_attrs,
7353 .sdev_attrs = mpt2sas_dev_attrs,
7354};
7355
7356/**
7357 * _scsih_expander_node_remove - removing expander device from list.
7358 * @ioc: per adapter object
7359 * @sas_expander: the sas_device object
7360 * Context: Calling function should acquire ioc->sas_node_lock.
7361 *
7362 * Removing object and freeing associated memory from the
7363 * ioc->sas_expander_list.
7364 *
7365 * Return nothing.
7366 */
7367static void
7368_scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7369 struct _sas_node *sas_expander)
7370{
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307371 struct _sas_port *mpt2sas_port, *next;
Eric Moore635374e2009-03-09 01:21:12 -06007372
7373 /* remove sibling ports attached to this expander */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307374 list_for_each_entry_safe(mpt2sas_port, next,
Eric Moore635374e2009-03-09 01:21:12 -06007375 &sas_expander->sas_port_list, port_list) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307376 if (ioc->shost_recovery)
7377 return;
Eric Moore635374e2009-03-09 01:21:12 -06007378 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307379 SAS_END_DEVICE)
7380 mpt2sas_device_remove(ioc,
7381 mpt2sas_port->remote_identify.sas_address);
7382 else if (mpt2sas_port->remote_identify.device_type ==
7383 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06007384 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307385 SAS_FANOUT_EXPANDER_DEVICE)
7386 mpt2sas_expander_remove(ioc,
7387 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007388 }
7389
7390 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307391 sas_expander->sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007392
7393 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7394 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7395 sas_expander->handle, (unsigned long long)
7396 sas_expander->sas_address);
7397
Eric Moore635374e2009-03-09 01:21:12 -06007398 kfree(sas_expander->phy);
7399 kfree(sas_expander);
7400}
7401
7402/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05307403 * _scsih_ir_shutdown - IR shutdown notification
7404 * @ioc: per adapter object
7405 *
7406 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7407 * the host system is shutting down.
7408 *
7409 * Return nothing.
7410 */
7411static void
7412_scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7413{
7414 Mpi2RaidActionRequest_t *mpi_request;
7415 Mpi2RaidActionReply_t *mpi_reply;
7416 u16 smid;
7417
7418 /* is IR firmware build loaded ? */
7419 if (!ioc->ir_firmware)
7420 return;
7421
7422 /* are there any volumes ? */
7423 if (list_empty(&ioc->raid_device_list))
7424 return;
7425
7426 mutex_lock(&ioc->scsih_cmds.mutex);
7427
7428 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7429 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7430 ioc->name, __func__);
7431 goto out;
7432 }
7433 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7434
7435 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7436 if (!smid) {
7437 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7438 ioc->name, __func__);
7439 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7440 goto out;
7441 }
7442
7443 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7444 ioc->scsih_cmds.smid = smid;
7445 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7446
7447 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7448 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7449
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307450 if (!ioc->hide_ir_msg)
7451 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307452 init_completion(&ioc->scsih_cmds.done);
7453 mpt2sas_base_put_smid_default(ioc, smid);
7454 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7455
7456 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7457 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7458 ioc->name, __func__);
7459 goto out;
7460 }
7461
7462 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7463 mpi_reply = ioc->scsih_cmds.reply;
7464
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307465 if (!ioc->hide_ir_msg)
7466 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7467 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7468 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7469 le32_to_cpu(mpi_reply->IOCLogInfo));
Kashyap, Desai744090d2009-10-05 15:56:56 +05307470 }
7471
7472 out:
7473 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7474 mutex_unlock(&ioc->scsih_cmds.mutex);
7475}
7476
7477/**
7478 * _scsih_shutdown - routine call during system shutdown
7479 * @pdev: PCI device struct
7480 *
7481 * Return nothing.
7482 */
7483static void
7484_scsih_shutdown(struct pci_dev *pdev)
7485{
7486 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7487 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307488 struct workqueue_struct *wq;
7489 unsigned long flags;
7490
7491 ioc->remove_host = 1;
7492 _scsih_fw_event_cleanup_queue(ioc);
7493
7494 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7495 wq = ioc->firmware_event_thread;
7496 ioc->firmware_event_thread = NULL;
7497 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7498 if (wq)
7499 destroy_workqueue(wq);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307500
7501 _scsih_ir_shutdown(ioc);
7502 mpt2sas_base_detach(ioc);
7503}
7504
7505/**
Eric Moored5d135b2009-05-18 13:02:08 -06007506 * _scsih_remove - detach and remove add host
Eric Moore635374e2009-03-09 01:21:12 -06007507 * @pdev: PCI device struct
7508 *
Kashyap, Desai744090d2009-10-05 15:56:56 +05307509 * Routine called when unloading the driver.
Eric Moore635374e2009-03-09 01:21:12 -06007510 * Return nothing.
7511 */
7512static void __devexit
Eric Moored5d135b2009-05-18 13:02:08 -06007513_scsih_remove(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06007514{
7515 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7516 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307517 struct _sas_port *mpt2sas_port, *next_port;
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307518 struct _raid_device *raid_device, *next;
7519 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06007520 struct workqueue_struct *wq;
7521 unsigned long flags;
7522
7523 ioc->remove_host = 1;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307524 _scsih_fw_event_cleanup_queue(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007525
7526 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7527 wq = ioc->firmware_event_thread;
7528 ioc->firmware_event_thread = NULL;
7529 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7530 if (wq)
7531 destroy_workqueue(wq);
7532
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307533 /* release all the volumes */
Kashyap, Desai3a9c9132011-01-04 11:40:23 +05307534 _scsih_ir_shutdown(ioc);
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307535 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7536 list) {
7537 if (raid_device->starget) {
7538 sas_target_priv_data =
7539 raid_device->starget->hostdata;
7540 sas_target_priv_data->deleted = 1;
7541 scsi_remove_target(&raid_device->starget->dev);
7542 }
7543 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7544 "(0x%016llx)\n", ioc->name, raid_device->handle,
7545 (unsigned long long) raid_device->wwid);
7546 _scsih_raid_device_remove(ioc, raid_device);
7547 }
7548
Eric Moore635374e2009-03-09 01:21:12 -06007549 /* free ports attached to the sas_host */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307550 list_for_each_entry_safe(mpt2sas_port, next_port,
Eric Moore635374e2009-03-09 01:21:12 -06007551 &ioc->sas_hba.sas_port_list, port_list) {
7552 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307553 SAS_END_DEVICE)
7554 mpt2sas_device_remove(ioc,
Eric Moore635374e2009-03-09 01:21:12 -06007555 mpt2sas_port->remote_identify.sas_address);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307556 else if (mpt2sas_port->remote_identify.device_type ==
7557 SAS_EDGE_EXPANDER_DEVICE ||
7558 mpt2sas_port->remote_identify.device_type ==
7559 SAS_FANOUT_EXPANDER_DEVICE)
7560 mpt2sas_expander_remove(ioc,
7561 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007562 }
7563
7564 /* free phys attached to the sas_host */
7565 if (ioc->sas_hba.num_phys) {
7566 kfree(ioc->sas_hba.phy);
7567 ioc->sas_hba.phy = NULL;
7568 ioc->sas_hba.num_phys = 0;
7569 }
7570
7571 sas_remove_host(shost);
kashyap.desai@lsi.com9ae89b02011-08-04 16:47:50 +05307572 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007573 list_del(&ioc->list);
7574 scsi_remove_host(shost);
7575 scsi_host_put(shost);
7576}
7577
7578/**
7579 * _scsih_probe_boot_devices - reports 1st device
7580 * @ioc: per adapter object
7581 *
7582 * If specified in bios page 2, this routine reports the 1st
7583 * device scsi-ml or sas transport for persistent boot device
7584 * purposes. Please refer to function _scsih_determine_boot_device()
7585 */
7586static void
7587_scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7588{
7589 u8 is_raid;
7590 void *device;
7591 struct _sas_device *sas_device;
7592 struct _raid_device *raid_device;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307593 u16 handle;
7594 u64 sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007595 u64 sas_address;
7596 unsigned long flags;
7597 int rc;
7598
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307599 /* no Bios, return immediately */
7600 if (!ioc->bios_pg3.BiosVersion)
7601 return;
7602
Eric Moore635374e2009-03-09 01:21:12 -06007603 device = NULL;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307604 is_raid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007605 if (ioc->req_boot_device.device) {
7606 device = ioc->req_boot_device.device;
7607 is_raid = ioc->req_boot_device.is_raid;
7608 } else if (ioc->req_alt_boot_device.device) {
7609 device = ioc->req_alt_boot_device.device;
7610 is_raid = ioc->req_alt_boot_device.is_raid;
7611 } else if (ioc->current_boot_device.device) {
7612 device = ioc->current_boot_device.device;
7613 is_raid = ioc->current_boot_device.is_raid;
7614 }
7615
7616 if (!device)
7617 return;
7618
7619 if (is_raid) {
7620 raid_device = device;
7621 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7622 raid_device->id, 0);
7623 if (rc)
7624 _scsih_raid_device_remove(ioc, raid_device);
7625 } else {
7626 sas_device = device;
7627 handle = sas_device->handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307628 sas_address_parent = sas_device->sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007629 sas_address = sas_device->sas_address;
7630 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7631 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7632 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307633
7634 if (ioc->hide_drives)
7635 return;
Eric Moore635374e2009-03-09 01:21:12 -06007636 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307637 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -06007638 _scsih_sas_device_remove(ioc, sas_device);
7639 } else if (!sas_device->starget) {
7640 mpt2sas_transport_port_remove(ioc, sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307641 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007642 _scsih_sas_device_remove(ioc, sas_device);
7643 }
7644 }
7645}
7646
7647/**
7648 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7649 * @ioc: per adapter object
7650 *
7651 * Called during initial loading of the driver.
7652 */
7653static void
7654_scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7655{
7656 struct _raid_device *raid_device, *raid_next;
7657 int rc;
7658
7659 list_for_each_entry_safe(raid_device, raid_next,
7660 &ioc->raid_device_list, list) {
7661 if (raid_device->starget)
7662 continue;
7663 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7664 raid_device->id, 0);
7665 if (rc)
7666 _scsih_raid_device_remove(ioc, raid_device);
7667 }
7668}
7669
7670/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307671 * _scsih_probe_sas - reporting sas devices to sas transport
Eric Moore635374e2009-03-09 01:21:12 -06007672 * @ioc: per adapter object
7673 *
7674 * Called during initial loading of the driver.
7675 */
7676static void
7677_scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7678{
7679 struct _sas_device *sas_device, *next;
7680 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007681
7682 /* SAS Device List */
7683 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7684 list) {
Eric Moore635374e2009-03-09 01:21:12 -06007685
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307686 if (ioc->hide_drives)
7687 continue;
7688
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307689 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7690 sas_device->sas_address_parent)) {
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307691 list_del(&sas_device->list);
7692 kfree(sas_device);
7693 continue;
Eric Moore635374e2009-03-09 01:21:12 -06007694 } else if (!sas_device->starget) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307695 mpt2sas_transport_port_remove(ioc,
7696 sas_device->sas_address,
7697 sas_device->sas_address_parent);
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307698 list_del(&sas_device->list);
7699 kfree(sas_device);
7700 continue;
7701
Eric Moore635374e2009-03-09 01:21:12 -06007702 }
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307703 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7704 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7705 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007706 }
7707}
7708
7709/**
7710 * _scsih_probe_devices - probing for devices
7711 * @ioc: per adapter object
7712 *
7713 * Called during initial loading of the driver.
7714 */
7715static void
7716_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7717{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307718 u16 volume_mapping_flags;
Eric Moore635374e2009-03-09 01:21:12 -06007719
7720 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7721 return; /* return when IOC doesn't support initiator mode */
7722
7723 _scsih_probe_boot_devices(ioc);
7724
7725 if (ioc->ir_firmware) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307726 volume_mapping_flags =
7727 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7728 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7729 if (volume_mapping_flags ==
7730 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
Eric Moore635374e2009-03-09 01:21:12 -06007731 _scsih_probe_raid(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307732 _scsih_probe_sas(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007733 } else {
Eric Moore635374e2009-03-09 01:21:12 -06007734 _scsih_probe_sas(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307735 _scsih_probe_raid(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007736 }
7737 } else
7738 _scsih_probe_sas(ioc);
7739}
7740
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307741
7742/**
7743 * _scsih_scan_start - scsi lld callback for .scan_start
7744 * @shost: SCSI host pointer
7745 *
7746 * The shost has the ability to discover targets on its own instead
7747 * of scanning the entire bus. In our implemention, we will kick off
7748 * firmware discovery.
7749 */
7750static void
7751_scsih_scan_start(struct Scsi_Host *shost)
7752{
7753 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7754 int rc;
7755
7756 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7757 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
7758
7759 ioc->start_scan = 1;
7760 rc = mpt2sas_port_enable(ioc);
7761
7762 if (rc != 0)
7763 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
7764}
7765
7766/**
7767 * _scsih_scan_finished - scsi lld callback for .scan_finished
7768 * @shost: SCSI host pointer
7769 * @time: elapsed time of the scan in jiffies
7770 *
7771 * This function will be called periodically until it returns 1 with the
7772 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7773 * we wait for firmware discovery to complete, then return 1.
7774 */
7775static int
7776_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7777{
7778 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7779
7780 if (time >= (300 * HZ)) {
7781 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7782 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
7783 "(timeout=300s)\n", ioc->name);
7784 ioc->is_driver_loading = 0;
7785 return 1;
7786 }
7787
7788 if (ioc->start_scan)
7789 return 0;
7790
7791 if (ioc->start_scan_failed) {
7792 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
7793 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
7794 ioc->is_driver_loading = 0;
7795 ioc->wait_for_discovery_to_complete = 0;
7796 ioc->remove_host = 1;
7797 return 1;
7798 }
7799
7800 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
7801 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7802
7803 if (ioc->wait_for_discovery_to_complete) {
7804 ioc->wait_for_discovery_to_complete = 0;
7805 _scsih_probe_devices(ioc);
7806 }
7807 mpt2sas_base_start_watchdog(ioc);
7808 ioc->is_driver_loading = 0;
7809 return 1;
7810}
7811
7812
Eric Moore635374e2009-03-09 01:21:12 -06007813/**
Eric Moored5d135b2009-05-18 13:02:08 -06007814 * _scsih_probe - attach and add scsi host
Eric Moore635374e2009-03-09 01:21:12 -06007815 * @pdev: PCI device struct
7816 * @id: pci device id
7817 *
7818 * Returns 0 success, anything else error.
7819 */
7820static int
Eric Moored5d135b2009-05-18 13:02:08 -06007821_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
Eric Moore635374e2009-03-09 01:21:12 -06007822{
7823 struct MPT2SAS_ADAPTER *ioc;
7824 struct Scsi_Host *shost;
7825
7826 shost = scsi_host_alloc(&scsih_driver_template,
7827 sizeof(struct MPT2SAS_ADAPTER));
7828 if (!shost)
7829 return -ENODEV;
7830
7831 /* init local params */
7832 ioc = shost_priv(shost);
7833 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
7834 INIT_LIST_HEAD(&ioc->list);
Eric Mooreba33fad2009-03-15 21:37:18 -06007835 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -06007836 ioc->shost = shost;
7837 ioc->id = mpt_ids++;
7838 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
7839 ioc->pdev = pdev;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307840 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
7841 ioc->is_warpdrive = 1;
7842 ioc->hide_ir_msg = 1;
7843 } else
7844 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
Eric Moore635374e2009-03-09 01:21:12 -06007845 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7846 ioc->tm_cb_idx = tm_cb_idx;
7847 ioc->ctl_cb_idx = ctl_cb_idx;
7848 ioc->base_cb_idx = base_cb_idx;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307849 ioc->port_enable_cb_idx = port_enable_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06007850 ioc->transport_cb_idx = transport_cb_idx;
Kashyap, Desai744090d2009-10-05 15:56:56 +05307851 ioc->scsih_cb_idx = scsih_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06007852 ioc->config_cb_idx = config_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307853 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307854 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307855 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06007856 ioc->logging_level = logging_level;
7857 /* misc semaphores and spin locks */
Kashyap, Desaid2742132010-06-17 13:28:55 +05307858 mutex_init(&ioc->reset_in_progress_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06007859 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
7860 spin_lock_init(&ioc->scsi_lookup_lock);
7861 spin_lock_init(&ioc->sas_device_lock);
7862 spin_lock_init(&ioc->sas_node_lock);
7863 spin_lock_init(&ioc->fw_event_lock);
7864 spin_lock_init(&ioc->raid_device_lock);
7865
7866 INIT_LIST_HEAD(&ioc->sas_device_list);
7867 INIT_LIST_HEAD(&ioc->sas_device_init_list);
7868 INIT_LIST_HEAD(&ioc->sas_expander_list);
7869 INIT_LIST_HEAD(&ioc->fw_event_list);
7870 INIT_LIST_HEAD(&ioc->raid_device_list);
7871 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307872 INIT_LIST_HEAD(&ioc->delayed_tr_list);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307873 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
Eric Moore635374e2009-03-09 01:21:12 -06007874
7875 /* init shost parameters */
Eric Moored334aa72010-04-22 10:47:40 -06007876 shost->max_cmd_len = 32;
Eric Moore635374e2009-03-09 01:21:12 -06007877 shost->max_lun = max_lun;
7878 shost->transportt = mpt2sas_transport_template;
7879 shost->unique_id = ioc->id;
7880
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05307881 if (max_sectors != 0xFFFF) {
7882 if (max_sectors < 64) {
7883 shost->max_sectors = 64;
7884 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7885 "for max_sectors, range is 64 to 8192. Assigning "
7886 "value of 64.\n", ioc->name, max_sectors);
7887 } else if (max_sectors > 8192) {
7888 shost->max_sectors = 8192;
7889 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
7890 "for max_sectors, range is 64 to 8192. Assigning "
7891 "default value of 8192.\n", ioc->name,
7892 max_sectors);
7893 } else {
7894 shost->max_sectors = max_sectors & 0xFFFE;
7895 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
7896 "set to %d\n", ioc->name, shost->max_sectors);
7897 }
7898 }
7899
Eric Moore635374e2009-03-09 01:21:12 -06007900 if ((scsi_add_host(shost, &pdev->dev))) {
7901 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7902 ioc->name, __FILE__, __LINE__, __func__);
7903 list_del(&ioc->list);
7904 goto out_add_shost_fail;
7905 }
7906
Eric Moore3c621b32009-05-18 12:59:41 -06007907 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
Eric Moored334aa72010-04-22 10:47:40 -06007908 | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307909 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
Eric Moore3c621b32009-05-18 12:59:41 -06007910
Eric Moore635374e2009-03-09 01:21:12 -06007911 /* event thread */
7912 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
7913 "fw_event%d", ioc->id);
7914 ioc->firmware_event_thread = create_singlethread_workqueue(
7915 ioc->firmware_event_name);
7916 if (!ioc->firmware_event_thread) {
7917 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7918 ioc->name, __FILE__, __LINE__, __func__);
7919 goto out_thread_fail;
7920 }
7921
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307922 ioc->is_driver_loading = 1;
Eric Moore635374e2009-03-09 01:21:12 -06007923 if ((mpt2sas_base_attach(ioc))) {
7924 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7925 ioc->name, __FILE__, __LINE__, __func__);
7926 goto out_attach_fail;
7927 }
7928
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307929 scsi_scan_host(shost);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307930 if (ioc->is_warpdrive) {
7931 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
7932 ioc->hide_drives = 0;
7933 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
7934 ioc->hide_drives = 1;
7935 else {
7936 if (_scsih_get_num_volumes(ioc))
7937 ioc->hide_drives = 1;
7938 else
7939 ioc->hide_drives = 0;
7940 }
7941 } else
7942 ioc->hide_drives = 0;
7943
Eric Moore635374e2009-03-09 01:21:12 -06007944 _scsih_probe_devices(ioc);
7945 return 0;
7946
7947 out_attach_fail:
7948 destroy_workqueue(ioc->firmware_event_thread);
7949 out_thread_fail:
7950 list_del(&ioc->list);
7951 scsi_remove_host(shost);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307952 scsi_host_put(shost);
Eric Moore635374e2009-03-09 01:21:12 -06007953 out_add_shost_fail:
7954 return -ENODEV;
7955}
7956
7957#ifdef CONFIG_PM
7958/**
Eric Moored5d135b2009-05-18 13:02:08 -06007959 * _scsih_suspend - power management suspend main entry point
Eric Moore635374e2009-03-09 01:21:12 -06007960 * @pdev: PCI device struct
7961 * @state: PM state change to (usually PCI_D3)
7962 *
7963 * Returns 0 success, anything else error.
7964 */
7965static int
Eric Moored5d135b2009-05-18 13:02:08 -06007966_scsih_suspend(struct pci_dev *pdev, pm_message_t state)
Eric Moore635374e2009-03-09 01:21:12 -06007967{
7968 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7969 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05307970 pci_power_t device_state;
Eric Moore635374e2009-03-09 01:21:12 -06007971
Kashyap, Desaie4750c92009-08-07 19:37:59 +05307972 mpt2sas_base_stop_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007973 scsi_block_requests(shost);
7974 device_state = pci_choose_state(pdev, state);
7975 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
7976 "operating state [D%d]\n", ioc->name, pdev,
7977 pci_name(pdev), device_state);
7978
7979 mpt2sas_base_free_resources(ioc);
7980 pci_save_state(pdev);
7981 pci_disable_device(pdev);
7982 pci_set_power_state(pdev, device_state);
7983 return 0;
7984}
7985
7986/**
Eric Moored5d135b2009-05-18 13:02:08 -06007987 * _scsih_resume - power management resume main entry point
Eric Moore635374e2009-03-09 01:21:12 -06007988 * @pdev: PCI device struct
7989 *
7990 * Returns 0 success, anything else error.
7991 */
7992static int
Eric Moored5d135b2009-05-18 13:02:08 -06007993_scsih_resume(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06007994{
7995 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7996 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05307997 pci_power_t device_state = pdev->current_state;
Eric Moore635374e2009-03-09 01:21:12 -06007998 int r;
7999
8000 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8001 "operating state [D%d]\n", ioc->name, pdev,
8002 pci_name(pdev), device_state);
8003
8004 pci_set_power_state(pdev, PCI_D0);
8005 pci_enable_wake(pdev, PCI_D0, 0);
8006 pci_restore_state(pdev);
8007 ioc->pdev = pdev;
8008 r = mpt2sas_base_map_resources(ioc);
8009 if (r)
8010 return r;
8011
8012 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8013 scsi_unblock_requests(shost);
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308014 mpt2sas_base_start_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008015 return 0;
8016}
8017#endif /* CONFIG_PM */
8018
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308019/**
8020 * _scsih_pci_error_detected - Called when a PCI error is detected.
8021 * @pdev: PCI device struct
8022 * @state: PCI channel state
8023 *
8024 * Description: Called when a PCI error is detected.
8025 *
8026 * Return value:
8027 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8028 */
8029static pci_ers_result_t
8030_scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8031{
8032 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8033 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8034
8035 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8036 ioc->name, state);
8037
8038 switch (state) {
8039 case pci_channel_io_normal:
8040 return PCI_ERS_RESULT_CAN_RECOVER;
8041 case pci_channel_io_frozen:
Eric Moore3cb54692010-07-08 14:44:34 -06008042 /* Fatal error, prepare for slot reset */
8043 ioc->pci_error_recovery = 1;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308044 scsi_block_requests(ioc->shost);
8045 mpt2sas_base_stop_watchdog(ioc);
8046 mpt2sas_base_free_resources(ioc);
8047 return PCI_ERS_RESULT_NEED_RESET;
8048 case pci_channel_io_perm_failure:
Eric Moore3cb54692010-07-08 14:44:34 -06008049 /* Permanent error, prepare for device removal */
8050 ioc->pci_error_recovery = 1;
8051 mpt2sas_base_stop_watchdog(ioc);
8052 _scsih_flush_running_cmds(ioc);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308053 return PCI_ERS_RESULT_DISCONNECT;
8054 }
8055 return PCI_ERS_RESULT_NEED_RESET;
8056}
8057
8058/**
8059 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8060 * @pdev: PCI device struct
8061 *
8062 * Description: This routine is called by the pci error recovery
8063 * code after the PCI slot has been reset, just before we
8064 * should resume normal operations.
8065 */
8066static pci_ers_result_t
8067_scsih_pci_slot_reset(struct pci_dev *pdev)
8068{
8069 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8070 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8071 int rc;
8072
8073 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8074 ioc->name);
8075
Eric Moore3cb54692010-07-08 14:44:34 -06008076 ioc->pci_error_recovery = 0;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308077 ioc->pdev = pdev;
Eric Moore3cb54692010-07-08 14:44:34 -06008078 pci_restore_state(pdev);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308079 rc = mpt2sas_base_map_resources(ioc);
8080 if (rc)
8081 return PCI_ERS_RESULT_DISCONNECT;
8082
8083
8084 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8085 FORCE_BIG_HAMMER);
8086
8087 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8088 (rc == 0) ? "success" : "failed");
8089
8090 if (!rc)
8091 return PCI_ERS_RESULT_RECOVERED;
8092 else
8093 return PCI_ERS_RESULT_DISCONNECT;
8094}
8095
8096/**
8097 * _scsih_pci_resume() - resume normal ops after PCI reset
8098 * @pdev: pointer to PCI device
8099 *
8100 * Called when the error recovery driver tells us that its
8101 * OK to resume normal operation. Use completion to allow
8102 * halted scsi ops to resume.
8103 */
8104static void
8105_scsih_pci_resume(struct pci_dev *pdev)
8106{
8107 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8108 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8109
8110 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8111
8112 pci_cleanup_aer_uncorrect_error_status(pdev);
8113 mpt2sas_base_start_watchdog(ioc);
8114 scsi_unblock_requests(ioc->shost);
8115}
8116
8117/**
8118 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8119 * @pdev: pointer to PCI device
8120 */
8121static pci_ers_result_t
8122_scsih_pci_mmio_enabled(struct pci_dev *pdev)
8123{
8124 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8125 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8126
8127 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8128 ioc->name);
8129
8130 /* TODO - dump whatever for debugging purposes */
8131
8132 /* Request a slot reset. */
8133 return PCI_ERS_RESULT_NEED_RESET;
8134}
8135
8136static struct pci_error_handlers _scsih_err_handler = {
8137 .error_detected = _scsih_pci_error_detected,
8138 .mmio_enabled = _scsih_pci_mmio_enabled,
8139 .slot_reset = _scsih_pci_slot_reset,
8140 .resume = _scsih_pci_resume,
8141};
Eric Moore635374e2009-03-09 01:21:12 -06008142
8143static struct pci_driver scsih_driver = {
8144 .name = MPT2SAS_DRIVER_NAME,
8145 .id_table = scsih_pci_table,
Eric Moored5d135b2009-05-18 13:02:08 -06008146 .probe = _scsih_probe,
8147 .remove = __devexit_p(_scsih_remove),
Kashyap, Desai744090d2009-10-05 15:56:56 +05308148 .shutdown = _scsih_shutdown,
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308149 .err_handler = &_scsih_err_handler,
Eric Moore635374e2009-03-09 01:21:12 -06008150#ifdef CONFIG_PM
Eric Moored5d135b2009-05-18 13:02:08 -06008151 .suspend = _scsih_suspend,
8152 .resume = _scsih_resume,
Eric Moore635374e2009-03-09 01:21:12 -06008153#endif
8154};
8155
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308156/* raid transport support */
8157static struct raid_function_template mpt2sas_raid_functions = {
8158 .cookie = &scsih_driver_template,
8159 .is_raid = _scsih_is_raid,
8160 .get_resync = _scsih_get_resync,
8161 .get_state = _scsih_get_state,
8162};
Eric Moore635374e2009-03-09 01:21:12 -06008163
8164/**
Eric Moored5d135b2009-05-18 13:02:08 -06008165 * _scsih_init - main entry point for this driver.
Eric Moore635374e2009-03-09 01:21:12 -06008166 *
8167 * Returns 0 success, anything else error.
8168 */
8169static int __init
Eric Moored5d135b2009-05-18 13:02:08 -06008170_scsih_init(void)
Eric Moore635374e2009-03-09 01:21:12 -06008171{
8172 int error;
8173
8174 mpt_ids = 0;
8175 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8176 MPT2SAS_DRIVER_VERSION);
8177
8178 mpt2sas_transport_template =
8179 sas_attach_transport(&mpt2sas_transport_functions);
8180 if (!mpt2sas_transport_template)
8181 return -ENODEV;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308182 /* raid transport support */
8183 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8184 if (!mpt2sas_raid_template) {
8185 sas_release_transport(mpt2sas_transport_template);
8186 return -ENODEV;
8187 }
Eric Moore635374e2009-03-09 01:21:12 -06008188
8189 mpt2sas_base_initialize_callback_handler();
8190
8191 /* queuecommand callback hander */
Eric Moored5d135b2009-05-18 13:02:08 -06008192 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
Eric Moore635374e2009-03-09 01:21:12 -06008193
Uwe Kleine-König65155b32010-06-11 12:17:01 +02008194 /* task management callback handler */
Eric Moored5d135b2009-05-18 13:02:08 -06008195 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
Eric Moore635374e2009-03-09 01:21:12 -06008196
8197 /* base internal commands callback handler */
8198 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308199 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8200 mpt2sas_port_enable_done);
Eric Moore635374e2009-03-09 01:21:12 -06008201
8202 /* transport internal commands callback handler */
8203 transport_cb_idx = mpt2sas_base_register_callback_handler(
8204 mpt2sas_transport_done);
8205
Kashyap, Desai744090d2009-10-05 15:56:56 +05308206 /* scsih internal commands callback handler */
8207 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8208
Eric Moore635374e2009-03-09 01:21:12 -06008209 /* configuration page API internal commands callback handler */
8210 config_cb_idx = mpt2sas_base_register_callback_handler(
8211 mpt2sas_config_done);
8212
8213 /* ctl module callback handler */
8214 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8215
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308216 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8217 _scsih_tm_tr_complete);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308218
8219 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8220 _scsih_tm_volume_tr_complete);
8221
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308222 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8223 _scsih_sas_control_complete);
8224
Eric Moore635374e2009-03-09 01:21:12 -06008225 mpt2sas_ctl_init();
8226
8227 error = pci_register_driver(&scsih_driver);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308228 if (error) {
8229 /* raid transport support */
8230 raid_class_release(mpt2sas_raid_template);
Eric Moore635374e2009-03-09 01:21:12 -06008231 sas_release_transport(mpt2sas_transport_template);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308232 }
Eric Moore635374e2009-03-09 01:21:12 -06008233
8234 return error;
8235}
8236
8237/**
Eric Moored5d135b2009-05-18 13:02:08 -06008238 * _scsih_exit - exit point for this driver (when it is a module).
Eric Moore635374e2009-03-09 01:21:12 -06008239 *
8240 * Returns 0 success, anything else error.
8241 */
8242static void __exit
Eric Moored5d135b2009-05-18 13:02:08 -06008243_scsih_exit(void)
Eric Moore635374e2009-03-09 01:21:12 -06008244{
8245 printk(KERN_INFO "mpt2sas version %s unloading\n",
8246 MPT2SAS_DRIVER_VERSION);
8247
8248 pci_unregister_driver(&scsih_driver);
8249
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308250 mpt2sas_ctl_exit();
8251
Eric Moore635374e2009-03-09 01:21:12 -06008252 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8253 mpt2sas_base_release_callback_handler(tm_cb_idx);
8254 mpt2sas_base_release_callback_handler(base_cb_idx);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308255 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008256 mpt2sas_base_release_callback_handler(transport_cb_idx);
Kashyap, Desai744090d2009-10-05 15:56:56 +05308257 mpt2sas_base_release_callback_handler(scsih_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008258 mpt2sas_base_release_callback_handler(config_cb_idx);
8259 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8260
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308261 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308262 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308263 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8264
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308265 /* raid transport support */
8266 raid_class_release(mpt2sas_raid_template);
8267 sas_release_transport(mpt2sas_transport_template);
8268
Eric Moore635374e2009-03-09 01:21:12 -06008269}
8270
Eric Moored5d135b2009-05-18 13:02:08 -06008271module_init(_scsih_init);
8272module_exit(_scsih_exit);