blob: 9a739e6f2712cc478d336df743d41ef450b01958 [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);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +0530102MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 32767 default=32767");
Kashyap, Desaia3e1e552011-06-14 10:56:12 +0530103
Eric Moore635374e2009-03-09 01:21:12 -0600104/* scsi-mid layer global parmeter is max_report_luns, which is 511 */
105#define MPT2SAS_MAX_LUN (16895)
106static int max_lun = MPT2SAS_MAX_LUN;
107module_param(max_lun, int, 0);
108MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
109
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530110/* diag_buffer_enable is bitwise
111 * bit 0 set = TRACE
112 * bit 1 set = SNAPSHOT
113 * bit 2 set = EXTENDED
114 *
115 * Either bit can be set, or both
116 */
117static int diag_buffer_enable = -1;
118module_param(diag_buffer_enable, int, 0);
119MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
120 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
121
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);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530582 list_del(&sas_device->list);
583 kfree(sas_device);
Eric Moore635374e2009-03-09 01:21:12 -0600584 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
585}
586
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530587
Eric Moore635374e2009-03-09 01:21:12 -0600588/**
589 * _scsih_sas_device_add - insert sas_device to the list.
590 * @ioc: per adapter object
591 * @sas_device: the sas_device object
592 * Context: This function will acquire ioc->sas_device_lock.
593 *
594 * Adding new object to the ioc->sas_device_list.
595 */
596static void
597_scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
598 struct _sas_device *sas_device)
599{
600 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -0600601
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530602 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600603 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
604 sas_device->handle, (unsigned long long)sas_device->sas_address));
605
606 spin_lock_irqsave(&ioc->sas_device_lock, flags);
607 list_add_tail(&sas_device->list, &ioc->sas_device_list);
608 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
609
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530610 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +0530611 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -0600612 _scsih_sas_device_remove(ioc, sas_device);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +0530613 } else if (!sas_device->starget) {
614 /* When asyn scanning is enabled, its not possible to remove
615 * devices while scanning is turned on due to an oops in
616 * scsi_sysfs_add_sdev()->add_device()->sysfs_addrm_start()
617 */
618 if (!ioc->is_driver_loading)
619 mpt2sas_transport_port_remove(ioc,
620 sas_device->sas_address,
621 sas_device->sas_address_parent);
622 _scsih_sas_device_remove(ioc, sas_device);
623 }
Eric Moore635374e2009-03-09 01:21:12 -0600624}
625
626/**
627 * _scsih_sas_device_init_add - insert sas_device to the list.
628 * @ioc: per adapter object
629 * @sas_device: the sas_device object
630 * Context: This function will acquire ioc->sas_device_lock.
631 *
632 * Adding new object at driver load time to the ioc->sas_device_init_list.
633 */
634static void
635_scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
636 struct _sas_device *sas_device)
637{
638 unsigned long flags;
639
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530640 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600641 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
642 sas_device->handle, (unsigned long long)sas_device->sas_address));
643
644 spin_lock_irqsave(&ioc->sas_device_lock, flags);
645 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
Eric Moore635374e2009-03-09 01:21:12 -0600646 _scsih_determine_boot_device(ioc, sas_device, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +0530647 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -0600648}
649
650/**
Eric Moore635374e2009-03-09 01:21:12 -0600651 * _scsih_raid_device_find_by_id - raid device search
652 * @ioc: per adapter object
653 * @id: sas device target id
654 * @channel: sas device channel
655 * Context: Calling function should acquire ioc->raid_device_lock
656 *
657 * This searches for raid_device based on target id, then return raid_device
658 * object.
659 */
660static struct _raid_device *
661_scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
662{
663 struct _raid_device *raid_device, *r;
664
665 r = NULL;
666 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
667 if (raid_device->id == id && raid_device->channel == channel) {
668 r = raid_device;
669 goto out;
670 }
671 }
672
673 out:
674 return r;
675}
676
677/**
678 * _scsih_raid_device_find_by_handle - raid device search
679 * @ioc: per adapter object
680 * @handle: sas device handle (assigned by firmware)
681 * Context: Calling function should acquire ioc->raid_device_lock
682 *
683 * This searches for raid_device based on handle, then return raid_device
684 * object.
685 */
686static struct _raid_device *
687_scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
688{
689 struct _raid_device *raid_device, *r;
690
691 r = NULL;
692 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
693 if (raid_device->handle != handle)
694 continue;
695 r = raid_device;
696 goto out;
697 }
698
699 out:
700 return r;
701}
702
703/**
704 * _scsih_raid_device_find_by_wwid - raid device search
705 * @ioc: per adapter object
706 * @handle: sas device handle (assigned by firmware)
707 * Context: Calling function should acquire ioc->raid_device_lock
708 *
709 * This searches for raid_device based on wwid, then return raid_device
710 * object.
711 */
712static struct _raid_device *
713_scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
714{
715 struct _raid_device *raid_device, *r;
716
717 r = NULL;
718 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
719 if (raid_device->wwid != wwid)
720 continue;
721 r = raid_device;
722 goto out;
723 }
724
725 out:
726 return r;
727}
728
729/**
730 * _scsih_raid_device_add - add raid_device object
731 * @ioc: per adapter object
732 * @raid_device: raid_device object
733 *
734 * This is added to the raid_device_list link list.
735 */
736static void
737_scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
738 struct _raid_device *raid_device)
739{
740 unsigned long flags;
741
Kashyap, Desaieabb08a2010-06-17 13:43:57 +0530742 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
Eric Moore635374e2009-03-09 01:21:12 -0600743 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
744 raid_device->handle, (unsigned long long)raid_device->wwid));
745
746 spin_lock_irqsave(&ioc->raid_device_lock, flags);
747 list_add_tail(&raid_device->list, &ioc->raid_device_list);
748 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
749}
750
751/**
752 * _scsih_raid_device_remove - delete raid_device object
753 * @ioc: per adapter object
754 * @raid_device: raid_device object
755 *
Eric Moore635374e2009-03-09 01:21:12 -0600756 */
757static void
758_scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
759 struct _raid_device *raid_device)
760{
761 unsigned long flags;
762
763 spin_lock_irqsave(&ioc->raid_device_lock, flags);
764 list_del(&raid_device->list);
Eric Moore635374e2009-03-09 01:21:12 -0600765 kfree(raid_device);
766 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
767}
768
769/**
Kashyap, Desaic5e039b2009-09-23 17:21:29 +0530770 * mpt2sas_scsih_expander_find_by_handle - expander device search
771 * @ioc: per adapter object
772 * @handle: expander handle (assigned by firmware)
773 * Context: Calling function should acquire ioc->sas_device_lock
774 *
775 * This searches for expander device based on handle, then returns the
776 * sas_node object.
777 */
778struct _sas_node *
779mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
780{
781 struct _sas_node *sas_expander, *r;
782
783 r = NULL;
784 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
785 if (sas_expander->handle != handle)
786 continue;
787 r = sas_expander;
788 goto out;
789 }
790 out:
791 return r;
792}
793
794/**
Eric Moore635374e2009-03-09 01:21:12 -0600795 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
796 * @ioc: per adapter object
797 * @sas_address: sas address
798 * Context: Calling function should acquire ioc->sas_node_lock.
799 *
800 * This searches for expander device based on sas_address, then returns the
801 * sas_node object.
802 */
803struct _sas_node *
804mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
805 u64 sas_address)
806{
807 struct _sas_node *sas_expander, *r;
808
809 r = NULL;
810 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
811 if (sas_expander->sas_address != sas_address)
812 continue;
813 r = sas_expander;
814 goto out;
815 }
816 out:
817 return r;
818}
819
820/**
821 * _scsih_expander_node_add - insert expander device to the list.
822 * @ioc: per adapter object
823 * @sas_expander: the sas_device object
824 * Context: This function will acquire ioc->sas_node_lock.
825 *
826 * Adding new object to the ioc->sas_expander_list.
827 *
828 * Return nothing.
829 */
830static void
831_scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
832 struct _sas_node *sas_expander)
833{
834 unsigned long flags;
835
836 spin_lock_irqsave(&ioc->sas_node_lock, flags);
837 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
838 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
839}
840
841/**
842 * _scsih_is_end_device - determines if device is an end device
843 * @device_info: bitfield providing information about the device.
844 * Context: none
845 *
846 * Returns 1 if end device.
847 */
848static int
849_scsih_is_end_device(u32 device_info)
850{
851 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
852 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
853 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
854 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
855 return 1;
856 else
857 return 0;
858}
859
860/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530861 * _scsih_scsi_lookup_get - returns scmd entry
Eric Moore635374e2009-03-09 01:21:12 -0600862 * @ioc: per adapter object
863 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -0600864 *
865 * Returns the smid stored scmd pointer.
866 */
867static struct scsi_cmnd *
868_scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
869{
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530870 return ioc->scsi_lookup[smid - 1].scmd;
Eric Moore635374e2009-03-09 01:21:12 -0600871}
872
873/**
Kashyap, Desaiec07a052011-01-05 17:54:32 +0530874 * _scsih_scsi_lookup_get_clear - returns scmd entry
875 * @ioc: per adapter object
876 * @smid: system request message index
877 *
878 * Returns the smid stored scmd pointer.
879 * Then will derefrence the stored scmd pointer.
880 */
881static inline struct scsi_cmnd *
882_scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
883{
884 unsigned long flags;
885 struct scsi_cmnd *scmd;
886
887 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
888 scmd = ioc->scsi_lookup[smid - 1].scmd;
889 ioc->scsi_lookup[smid - 1].scmd = NULL;
890 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
891
892 return scmd;
893}
894
895/**
Eric Moore635374e2009-03-09 01:21:12 -0600896 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
897 * @ioc: per adapter object
898 * @smid: system request message index
899 * @scmd: pointer to scsi command object
900 * Context: This function will acquire ioc->scsi_lookup_lock.
901 *
902 * This will search for a scmd pointer in the scsi_lookup array,
903 * returning the revelent smid. A returned value of zero means invalid.
904 */
905static u16
906_scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
907 *scmd)
908{
909 u16 smid;
910 unsigned long flags;
911 int i;
912
913 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
914 smid = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530915 for (i = 0; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600916 if (ioc->scsi_lookup[i].scmd == scmd) {
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530917 smid = ioc->scsi_lookup[i].smid;
Eric Moore635374e2009-03-09 01:21:12 -0600918 goto out;
919 }
920 }
921 out:
922 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
923 return smid;
924}
925
926/**
927 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
928 * @ioc: per adapter object
929 * @id: target id
930 * @channel: channel
931 * Context: This function will acquire ioc->scsi_lookup_lock.
932 *
933 * This will search for a matching channel:id in the scsi_lookup array,
934 * returning 1 if found.
935 */
936static u8
937_scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
938 int channel)
939{
940 u8 found;
941 unsigned long flags;
942 int i;
943
944 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
945 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530946 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore635374e2009-03-09 01:21:12 -0600947 if (ioc->scsi_lookup[i].scmd &&
948 (ioc->scsi_lookup[i].scmd->device->id == id &&
949 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
950 found = 1;
951 goto out;
952 }
953 }
954 out:
955 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
956 return found;
957}
958
959/**
Eric Moore993e0da2009-05-18 13:00:45 -0600960 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
961 * @ioc: per adapter object
962 * @id: target id
963 * @lun: lun number
964 * @channel: channel
965 * Context: This function will acquire ioc->scsi_lookup_lock.
966 *
967 * This will search for a matching channel:id:lun in the scsi_lookup array,
968 * returning 1 if found.
969 */
970static u8
971_scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
972 unsigned int lun, int channel)
973{
974 u8 found;
975 unsigned long flags;
976 int i;
977
978 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
979 found = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530980 for (i = 0 ; i < ioc->scsiio_depth; i++) {
Eric Moore993e0da2009-05-18 13:00:45 -0600981 if (ioc->scsi_lookup[i].scmd &&
982 (ioc->scsi_lookup[i].scmd->device->id == id &&
983 ioc->scsi_lookup[i].scmd->device->channel == channel &&
984 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
985 found = 1;
986 goto out;
987 }
988 }
989 out:
990 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
991 return found;
992}
993
994/**
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530995 * _scsih_get_chain_buffer_tracker - obtain chain tracker
Eric Moore635374e2009-03-09 01:21:12 -0600996 * @ioc: per adapter object
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530997 * @smid: smid associated to an IO request
Eric Moore635374e2009-03-09 01:21:12 -0600998 *
Kashyap, Desai35f805b2010-11-13 04:34:06 +0530999 * Returns chain tracker(from ioc->free_chain_list)
Eric Moore635374e2009-03-09 01:21:12 -06001000 */
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301001static struct chain_tracker *
1002_scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
Eric Moore635374e2009-03-09 01:21:12 -06001003{
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301004 struct chain_tracker *chain_req;
1005 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001006
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301007 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1008 if (list_empty(&ioc->free_chain_list)) {
1009 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
nagalakshmi.nandigama@lsi.comaff132d2011-12-01 07:53:08 +05301010 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT "chain buffers not "
1011 "available\n", ioc->name));
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301012 return NULL;
1013 }
1014 chain_req = list_entry(ioc->free_chain_list.next,
1015 struct chain_tracker, tracker_list);
1016 list_del_init(&chain_req->tracker_list);
1017 list_add_tail(&chain_req->tracker_list,
1018 &ioc->scsi_lookup[smid - 1].chain_list);
1019 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1020 return chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001021}
1022
1023/**
1024 * _scsih_build_scatter_gather - main sg creation routine
1025 * @ioc: per adapter object
1026 * @scmd: scsi command
1027 * @smid: system request message index
1028 * Context: none.
1029 *
1030 * The main routine that builds scatter gather table from a given
1031 * scsi request sent via the .queuecommand main handler.
1032 *
1033 * Returns 0 success, anything else error
1034 */
1035static int
1036_scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1037 struct scsi_cmnd *scmd, u16 smid)
1038{
1039 Mpi2SCSIIORequest_t *mpi_request;
1040 dma_addr_t chain_dma;
1041 struct scatterlist *sg_scmd;
1042 void *sg_local, *chain;
1043 u32 chain_offset;
1044 u32 chain_length;
1045 u32 chain_flags;
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001046 int sges_left;
Eric Moore635374e2009-03-09 01:21:12 -06001047 u32 sges_in_segment;
1048 u32 sgl_flags;
1049 u32 sgl_flags_last_element;
1050 u32 sgl_flags_end_buffer;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301051 struct chain_tracker *chain_req;
Eric Moore635374e2009-03-09 01:21:12 -06001052
1053 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1054
1055 /* init scatter gather flags */
1056 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
1057 if (scmd->sc_data_direction == DMA_TO_DEVICE)
1058 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
1059 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
1060 << MPI2_SGE_FLAGS_SHIFT;
1061 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
1062 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
1063 << MPI2_SGE_FLAGS_SHIFT;
1064 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1065
1066 sg_scmd = scsi_sglist(scmd);
1067 sges_left = scsi_dma_map(scmd);
FUJITA Tomonoribb789d02010-03-09 11:09:50 +09001068 if (sges_left < 0) {
Eric Moore635374e2009-03-09 01:21:12 -06001069 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
1070 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
1071 return -ENOMEM;
1072 }
1073
1074 sg_local = &mpi_request->SGL;
1075 sges_in_segment = ioc->max_sges_in_main_message;
1076 if (sges_left <= sges_in_segment)
1077 goto fill_in_last_segment;
1078
1079 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
1080 (sges_in_segment * ioc->sge_size))/4;
1081
1082 /* fill in main message segment when there is a chain following */
1083 while (sges_in_segment) {
1084 if (sges_in_segment == 1)
1085 ioc->base_add_sg_single(sg_local,
1086 sgl_flags_last_element | sg_dma_len(sg_scmd),
1087 sg_dma_address(sg_scmd));
1088 else
1089 ioc->base_add_sg_single(sg_local, sgl_flags |
1090 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1091 sg_scmd = sg_next(sg_scmd);
1092 sg_local += ioc->sge_size;
1093 sges_left--;
1094 sges_in_segment--;
1095 }
1096
1097 /* initializing the chain flags and pointers */
1098 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301099 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1100 if (!chain_req)
1101 return -1;
1102 chain = chain_req->chain_buffer;
1103 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001104 do {
1105 sges_in_segment = (sges_left <=
1106 ioc->max_sges_in_chain_message) ? sges_left :
1107 ioc->max_sges_in_chain_message;
1108 chain_offset = (sges_left == sges_in_segment) ?
1109 0 : (sges_in_segment * ioc->sge_size)/4;
1110 chain_length = sges_in_segment * ioc->sge_size;
1111 if (chain_offset) {
1112 chain_offset = chain_offset <<
1113 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1114 chain_length += ioc->sge_size;
1115 }
1116 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1117 chain_length, chain_dma);
1118 sg_local = chain;
1119 if (!chain_offset)
1120 goto fill_in_last_segment;
1121
1122 /* fill in chain segments */
1123 while (sges_in_segment) {
1124 if (sges_in_segment == 1)
1125 ioc->base_add_sg_single(sg_local,
1126 sgl_flags_last_element |
1127 sg_dma_len(sg_scmd),
1128 sg_dma_address(sg_scmd));
1129 else
1130 ioc->base_add_sg_single(sg_local, sgl_flags |
1131 sg_dma_len(sg_scmd),
1132 sg_dma_address(sg_scmd));
1133 sg_scmd = sg_next(sg_scmd);
1134 sg_local += ioc->sge_size;
1135 sges_left--;
1136 sges_in_segment--;
1137 }
1138
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301139 chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
1140 if (!chain_req)
1141 return -1;
1142 chain = chain_req->chain_buffer;
1143 chain_dma = chain_req->chain_buffer_dma;
Eric Moore635374e2009-03-09 01:21:12 -06001144 } while (1);
1145
1146
1147 fill_in_last_segment:
1148
1149 /* fill the last segment */
1150 while (sges_left) {
1151 if (sges_left == 1)
1152 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1153 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1154 else
1155 ioc->base_add_sg_single(sg_local, sgl_flags |
1156 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1157 sg_scmd = sg_next(sg_scmd);
1158 sg_local += ioc->sge_size;
1159 sges_left--;
1160 }
1161
1162 return 0;
1163}
1164
1165/**
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301166 * _scsih_adjust_queue_depth - setting device queue depth
Eric Moore635374e2009-03-09 01:21:12 -06001167 * @sdev: scsi device struct
1168 * @qdepth: requested queue depth
1169 *
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301170 *
1171 * Returns nothing
Eric Moore635374e2009-03-09 01:21:12 -06001172 */
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301173static void
1174_scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
Eric Moore635374e2009-03-09 01:21:12 -06001175{
1176 struct Scsi_Host *shost = sdev->host;
1177 int max_depth;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301178 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1179 struct MPT2SAS_DEVICE *sas_device_priv_data;
1180 struct MPT2SAS_TARGET *sas_target_priv_data;
1181 struct _sas_device *sas_device;
1182 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001183
1184 max_depth = shost->can_queue;
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301185
1186 /* limit max device queue for SATA to 32 */
1187 sas_device_priv_data = sdev->hostdata;
1188 if (!sas_device_priv_data)
1189 goto not_sata;
1190 sas_target_priv_data = sas_device_priv_data->sas_target;
1191 if (!sas_target_priv_data)
1192 goto not_sata;
1193 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
1194 goto not_sata;
1195 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1196 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1197 sas_device_priv_data->sas_target->sas_address);
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301198 if (sas_device && sas_device->device_info &
1199 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1200 max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301201 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaie0077d62009-09-23 17:30:22 +05301202
1203 not_sata:
1204
Eric Moore635374e2009-03-09 01:21:12 -06001205 if (!sdev->tagged_supported)
1206 max_depth = 1;
1207 if (qdepth > max_depth)
1208 qdepth = max_depth;
Kashyap, Desaia93c6b42010-11-13 04:39:11 +05301209 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1210}
1211
1212/**
1213 * _scsih_change_queue_depth - setting device queue depth
1214 * @sdev: scsi device struct
1215 * @qdepth: requested queue depth
1216 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1217 * (see include/scsi/scsi_host.h for definition)
1218 *
1219 * Returns queue depth.
1220 */
1221static int
1222_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1223{
1224 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1225 _scsih_adjust_queue_depth(sdev, qdepth);
1226 else if (reason == SCSI_QDEPTH_QFULL)
1227 scsi_track_queue_full(sdev, qdepth);
1228 else
1229 return -EOPNOTSUPP;
Eric Moore635374e2009-03-09 01:21:12 -06001230
1231 if (sdev->inquiry_len > 7)
1232 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1233 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1234 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1235 sdev->ordered_tags, sdev->scsi_level,
1236 (sdev->inquiry[7] & 2) >> 1);
1237
1238 return sdev->queue_depth;
1239}
1240
1241/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301242 * _scsih_change_queue_type - changing device queue tag type
Eric Moore635374e2009-03-09 01:21:12 -06001243 * @sdev: scsi device struct
1244 * @tag_type: requested tag type
1245 *
1246 * Returns queue tag type.
1247 */
1248static int
Eric Moored5d135b2009-05-18 13:02:08 -06001249_scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
Eric Moore635374e2009-03-09 01:21:12 -06001250{
1251 if (sdev->tagged_supported) {
1252 scsi_set_tag_type(sdev, tag_type);
1253 if (tag_type)
1254 scsi_activate_tcq(sdev, sdev->queue_depth);
1255 else
1256 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1257 } else
1258 tag_type = 0;
1259
1260 return tag_type;
1261}
1262
1263/**
Eric Moored5d135b2009-05-18 13:02:08 -06001264 * _scsih_target_alloc - target add routine
Eric Moore635374e2009-03-09 01:21:12 -06001265 * @starget: scsi target struct
1266 *
1267 * Returns 0 if ok. Any other return is assumed to be an error and
1268 * the device is ignored.
1269 */
1270static int
Eric Moored5d135b2009-05-18 13:02:08 -06001271_scsih_target_alloc(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001272{
1273 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1274 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1275 struct MPT2SAS_TARGET *sas_target_priv_data;
1276 struct _sas_device *sas_device;
1277 struct _raid_device *raid_device;
1278 unsigned long flags;
1279 struct sas_rphy *rphy;
1280
1281 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1282 if (!sas_target_priv_data)
1283 return -ENOMEM;
1284
1285 starget->hostdata = sas_target_priv_data;
1286 sas_target_priv_data->starget = starget;
1287 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1288
1289 /* RAID volumes */
1290 if (starget->channel == RAID_CHANNEL) {
1291 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1292 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1293 starget->channel);
1294 if (raid_device) {
1295 sas_target_priv_data->handle = raid_device->handle;
1296 sas_target_priv_data->sas_address = raid_device->wwid;
1297 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301298 if (ioc->is_warpdrive)
1299 sas_target_priv_data->raid_device = raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001300 raid_device->starget = starget;
1301 }
1302 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1303 return 0;
1304 }
1305
1306 /* sas/sata devices */
1307 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1308 rphy = dev_to_rphy(starget->dev.parent);
1309 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1310 rphy->identify.sas_address);
1311
1312 if (sas_device) {
1313 sas_target_priv_data->handle = sas_device->handle;
1314 sas_target_priv_data->sas_address = sas_device->sas_address;
1315 sas_device->starget = starget;
1316 sas_device->id = starget->id;
1317 sas_device->channel = starget->channel;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05301318 if (test_bit(sas_device->handle, ioc->pd_handles))
Eric Moore635374e2009-03-09 01:21:12 -06001319 sas_target_priv_data->flags |=
1320 MPT_TARGET_FLAGS_RAID_COMPONENT;
1321 }
1322 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1323
1324 return 0;
1325}
1326
1327/**
Eric Moored5d135b2009-05-18 13:02:08 -06001328 * _scsih_target_destroy - target destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001329 * @starget: scsi target struct
1330 *
1331 * Returns nothing.
1332 */
1333static void
Eric Moored5d135b2009-05-18 13:02:08 -06001334_scsih_target_destroy(struct scsi_target *starget)
Eric Moore635374e2009-03-09 01:21:12 -06001335{
1336 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1337 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1338 struct MPT2SAS_TARGET *sas_target_priv_data;
1339 struct _sas_device *sas_device;
1340 struct _raid_device *raid_device;
1341 unsigned long flags;
1342 struct sas_rphy *rphy;
1343
1344 sas_target_priv_data = starget->hostdata;
1345 if (!sas_target_priv_data)
1346 return;
1347
1348 if (starget->channel == RAID_CHANNEL) {
1349 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1350 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1351 starget->channel);
1352 if (raid_device) {
1353 raid_device->starget = NULL;
1354 raid_device->sdev = NULL;
1355 }
1356 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1357 goto out;
1358 }
1359
1360 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1361 rphy = dev_to_rphy(starget->dev.parent);
1362 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1363 rphy->identify.sas_address);
Eric Moore8901cbb2009-04-21 15:41:32 -06001364 if (sas_device && (sas_device->starget == starget) &&
1365 (sas_device->id == starget->id) &&
1366 (sas_device->channel == starget->channel))
Eric Moore635374e2009-03-09 01:21:12 -06001367 sas_device->starget = NULL;
1368
1369 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1370
1371 out:
1372 kfree(sas_target_priv_data);
1373 starget->hostdata = NULL;
1374}
1375
1376/**
Eric Moored5d135b2009-05-18 13:02:08 -06001377 * _scsih_slave_alloc - device add routine
Eric Moore635374e2009-03-09 01:21:12 -06001378 * @sdev: scsi device struct
1379 *
1380 * Returns 0 if ok. Any other return is assumed to be an error and
1381 * the device is ignored.
1382 */
1383static int
Eric Moored5d135b2009-05-18 13:02:08 -06001384_scsih_slave_alloc(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001385{
1386 struct Scsi_Host *shost;
1387 struct MPT2SAS_ADAPTER *ioc;
1388 struct MPT2SAS_TARGET *sas_target_priv_data;
1389 struct MPT2SAS_DEVICE *sas_device_priv_data;
1390 struct scsi_target *starget;
1391 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06001392 unsigned long flags;
1393
1394 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1395 if (!sas_device_priv_data)
1396 return -ENOMEM;
1397
1398 sas_device_priv_data->lun = sdev->lun;
1399 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1400
1401 starget = scsi_target(sdev);
1402 sas_target_priv_data = starget->hostdata;
1403 sas_target_priv_data->num_luns++;
1404 sas_device_priv_data->sas_target = sas_target_priv_data;
1405 sdev->hostdata = sas_device_priv_data;
1406 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1407 sdev->no_uld_attach = 1;
1408
1409 shost = dev_to_shost(&starget->dev);
1410 ioc = shost_priv(shost);
1411 if (starget->channel == RAID_CHANNEL) {
1412 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1413 raid_device = _scsih_raid_device_find_by_id(ioc,
1414 starget->id, starget->channel);
1415 if (raid_device)
1416 raid_device->sdev = sdev; /* raid is single lun */
1417 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06001418 }
1419
Eric Moore635374e2009-03-09 01:21:12 -06001420 return 0;
1421}
1422
1423/**
Eric Moored5d135b2009-05-18 13:02:08 -06001424 * _scsih_slave_destroy - device destroy routine
Eric Moore635374e2009-03-09 01:21:12 -06001425 * @sdev: scsi device struct
1426 *
1427 * Returns nothing.
1428 */
1429static void
Eric Moored5d135b2009-05-18 13:02:08 -06001430_scsih_slave_destroy(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001431{
1432 struct MPT2SAS_TARGET *sas_target_priv_data;
1433 struct scsi_target *starget;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301434 struct Scsi_Host *shost;
1435 struct MPT2SAS_ADAPTER *ioc;
1436 struct _sas_device *sas_device;
1437 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06001438
1439 if (!sdev->hostdata)
1440 return;
1441
1442 starget = scsi_target(sdev);
1443 sas_target_priv_data = starget->hostdata;
1444 sas_target_priv_data->num_luns--;
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301445
1446 shost = dev_to_shost(&starget->dev);
1447 ioc = shost_priv(shost);
1448
1449 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1450 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1451 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1452 sas_target_priv_data->sas_address);
nagalakshmi.nandigama@lsi.com23edb6e2011-12-01 07:43:50 +05301453 if (sas_device && !sas_target_priv_data->num_luns)
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05301454 sas_device->starget = NULL;
1455 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1456 }
1457
Eric Moore635374e2009-03-09 01:21:12 -06001458 kfree(sdev->hostdata);
1459 sdev->hostdata = NULL;
1460}
1461
1462/**
Eric Moored5d135b2009-05-18 13:02:08 -06001463 * _scsih_display_sata_capabilities - sata capabilities
Eric Moore635374e2009-03-09 01:21:12 -06001464 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301465 * @handle: device handle
Eric Moore635374e2009-03-09 01:21:12 -06001466 * @sdev: scsi device struct
1467 */
1468static void
Eric Moored5d135b2009-05-18 13:02:08 -06001469_scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301470 u16 handle, struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001471{
1472 Mpi2ConfigReply_t mpi_reply;
1473 Mpi2SasDevicePage0_t sas_device_pg0;
1474 u32 ioc_status;
1475 u16 flags;
1476 u32 device_info;
1477
1478 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301479 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06001480 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1481 ioc->name, __FILE__, __LINE__, __func__);
1482 return;
1483 }
1484
1485 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1486 MPI2_IOCSTATUS_MASK;
1487 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1488 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1489 ioc->name, __FILE__, __LINE__, __func__);
1490 return;
1491 }
1492
1493 flags = le16_to_cpu(sas_device_pg0.Flags);
Kashyap, Desaie94f6742010-03-17 16:24:52 +05301494 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
Eric Moore635374e2009-03-09 01:21:12 -06001495
1496 sdev_printk(KERN_INFO, sdev,
1497 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1498 "sw_preserve(%s)\n",
1499 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1500 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1501 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1502 "n",
1503 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1504 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1505 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1506}
1507
1508/**
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301509 * _scsih_is_raid - return boolean indicating device is raid volume
1510 * @dev the device struct object
1511 */
1512static int
1513_scsih_is_raid(struct device *dev)
1514{
1515 struct scsi_device *sdev = to_scsi_device(dev);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301516 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301517
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301518 if (ioc->is_warpdrive)
1519 return 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301520 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1521}
1522
1523/**
1524 * _scsih_get_resync - get raid volume resync percent complete
1525 * @dev the device struct object
1526 */
1527static void
1528_scsih_get_resync(struct device *dev)
1529{
1530 struct scsi_device *sdev = to_scsi_device(dev);
1531 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1532 static struct _raid_device *raid_device;
1533 unsigned long flags;
1534 Mpi2RaidVolPage0_t vol_pg0;
1535 Mpi2ConfigReply_t mpi_reply;
1536 u32 volume_status_flags;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301537 u8 percent_complete;
1538 u16 handle;
1539
1540 percent_complete = 0;
1541 handle = 0;
1542 if (ioc->is_warpdrive)
1543 goto out;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301544
1545 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1546 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1547 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301548 if (raid_device) {
1549 handle = raid_device->handle;
1550 percent_complete = raid_device->percent_complete;
1551 }
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301552 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1553
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301554 if (!handle)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301555 goto out;
1556
1557 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301558 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301559 sizeof(Mpi2RaidVolPage0_t))) {
1560 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1561 ioc->name, __FILE__, __LINE__, __func__);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301562 percent_complete = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301563 goto out;
1564 }
1565
1566 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301567 if (!(volume_status_flags &
1568 MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS))
1569 percent_complete = 0;
1570
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301571 out:
1572 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1573}
1574
1575/**
1576 * _scsih_get_state - get raid volume level
1577 * @dev the device struct object
1578 */
1579static void
1580_scsih_get_state(struct device *dev)
1581{
1582 struct scsi_device *sdev = to_scsi_device(dev);
1583 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1584 static struct _raid_device *raid_device;
1585 unsigned long flags;
1586 Mpi2RaidVolPage0_t vol_pg0;
1587 Mpi2ConfigReply_t mpi_reply;
1588 u32 volstate;
1589 enum raid_state state = RAID_STATE_UNKNOWN;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301590 u16 handle = 0;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301591
1592 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1593 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1594 sdev->channel);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301595 if (raid_device)
1596 handle = raid_device->handle;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301597 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1598
1599 if (!raid_device)
1600 goto out;
1601
1602 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301603 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301604 sizeof(Mpi2RaidVolPage0_t))) {
1605 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1606 ioc->name, __FILE__, __LINE__, __func__);
1607 goto out;
1608 }
1609
1610 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1611 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1612 state = RAID_STATE_RESYNCING;
1613 goto out;
1614 }
1615
1616 switch (vol_pg0.VolumeState) {
1617 case MPI2_RAID_VOL_STATE_OPTIMAL:
1618 case MPI2_RAID_VOL_STATE_ONLINE:
1619 state = RAID_STATE_ACTIVE;
1620 break;
1621 case MPI2_RAID_VOL_STATE_DEGRADED:
1622 state = RAID_STATE_DEGRADED;
1623 break;
1624 case MPI2_RAID_VOL_STATE_FAILED:
1625 case MPI2_RAID_VOL_STATE_MISSING:
1626 state = RAID_STATE_OFFLINE;
1627 break;
1628 }
1629 out:
1630 raid_set_state(mpt2sas_raid_template, dev, state);
1631}
1632
1633/**
1634 * _scsih_set_level - set raid level
1635 * @sdev: scsi device struct
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301636 * @volume_type: volume type
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301637 */
1638static void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301639_scsih_set_level(struct scsi_device *sdev, u8 volume_type)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301640{
1641 enum raid_level level = RAID_LEVEL_UNKNOWN;
1642
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301643 switch (volume_type) {
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05301644 case MPI2_RAID_VOL_TYPE_RAID0:
1645 level = RAID_LEVEL_0;
1646 break;
1647 case MPI2_RAID_VOL_TYPE_RAID10:
1648 level = RAID_LEVEL_10;
1649 break;
1650 case MPI2_RAID_VOL_TYPE_RAID1E:
1651 level = RAID_LEVEL_1E;
1652 break;
1653 case MPI2_RAID_VOL_TYPE_RAID1:
1654 level = RAID_LEVEL_1;
1655 break;
1656 }
1657
1658 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1659}
1660
1661/**
Eric Moore635374e2009-03-09 01:21:12 -06001662 * _scsih_get_volume_capabilities - volume capabilities
1663 * @ioc: per adapter object
1664 * @sas_device: the raid_device object
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301665 *
1666 * Returns 0 for success, else 1
Eric Moore635374e2009-03-09 01:21:12 -06001667 */
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301668static int
Eric Moore635374e2009-03-09 01:21:12 -06001669_scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1670 struct _raid_device *raid_device)
1671{
1672 Mpi2RaidVolPage0_t *vol_pg0;
1673 Mpi2RaidPhysDiskPage0_t pd_pg0;
1674 Mpi2SasDevicePage0_t sas_device_pg0;
1675 Mpi2ConfigReply_t mpi_reply;
1676 u16 sz;
1677 u8 num_pds;
1678
1679 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1680 &num_pds)) || !num_pds) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301681 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1682 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1683 __func__));
1684 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001685 }
1686
1687 raid_device->num_pds = num_pds;
1688 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1689 sizeof(Mpi2RaidVol0PhysDisk_t));
1690 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1691 if (!vol_pg0) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301692 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1693 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1694 __func__));
1695 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001696 }
1697
1698 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1699 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301700 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1701 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1702 __func__));
Eric Moore635374e2009-03-09 01:21:12 -06001703 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301704 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06001705 }
1706
1707 raid_device->volume_type = vol_pg0->VolumeType;
1708
1709 /* figure out what the underlying devices are by
1710 * obtaining the device_info bits for the 1st device
1711 */
1712 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1713 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1714 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1715 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1716 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1717 le16_to_cpu(pd_pg0.DevHandle)))) {
1718 raid_device->device_info =
1719 le32_to_cpu(sas_device_pg0.DeviceInfo);
1720 }
1721 }
1722
1723 kfree(vol_pg0);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05301724 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06001725}
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301726/**
1727 * _scsih_disable_ddio - Disable direct I/O for all the volumes
1728 * @ioc: per adapter object
1729 */
1730static void
1731_scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
1732{
1733 Mpi2RaidVolPage1_t vol_pg1;
1734 Mpi2ConfigReply_t mpi_reply;
1735 struct _raid_device *raid_device;
1736 u16 handle;
1737 u16 ioc_status;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301738 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301739
1740 handle = 0xFFFF;
1741 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1742 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1743 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1744 MPI2_IOCSTATUS_MASK;
1745 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1746 break;
1747 handle = le16_to_cpu(vol_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301748 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301749 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
1750 if (raid_device)
1751 raid_device->direct_io_enabled = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301752 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301753 }
1754 return;
1755}
1756
1757
1758/**
1759 * _scsih_get_num_volumes - Get number of volumes in the ioc
1760 * @ioc: per adapter object
1761 */
1762static u8
1763_scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
1764{
1765 Mpi2RaidVolPage1_t vol_pg1;
1766 Mpi2ConfigReply_t mpi_reply;
1767 u16 handle;
1768 u8 vol_cnt = 0;
1769 u16 ioc_status;
1770
1771 handle = 0xFFFF;
1772 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
1773 &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
1774 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1775 MPI2_IOCSTATUS_MASK;
1776 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
1777 break;
1778 vol_cnt++;
1779 handle = le16_to_cpu(vol_pg1.DevHandle);
1780 }
1781 return vol_cnt;
1782}
1783
1784
1785/**
1786 * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
1787 * @ioc: per adapter object
1788 * @raid_device: the raid_device object
1789 */
1790static void
1791_scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
1792 struct _raid_device *raid_device)
1793{
1794 Mpi2RaidVolPage0_t *vol_pg0;
1795 Mpi2RaidPhysDiskPage0_t pd_pg0;
1796 Mpi2ConfigReply_t mpi_reply;
1797 u16 sz;
1798 u8 num_pds, count;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301799 unsigned long stripe_sz, block_sz;
1800 u8 stripe_exp, block_exp;
1801 u64 dev_max_lba;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301802
1803 if (!ioc->is_warpdrive)
1804 return;
1805
1806 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
1807 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1808 "globally as drives are exposed\n", ioc->name);
1809 return;
1810 }
1811 if (_scsih_get_num_volumes(ioc) > 1) {
1812 _scsih_disable_ddio(ioc);
1813 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1814 "globally as number of drives > 1\n", ioc->name);
1815 return;
1816 }
1817 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1818 &num_pds)) || !num_pds) {
1819 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1820 "Failure in computing number of drives\n", ioc->name);
1821 return;
1822 }
1823
1824 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1825 sizeof(Mpi2RaidVol0PhysDisk_t));
1826 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1827 if (!vol_pg0) {
1828 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1829 "Memory allocation failure for RVPG0\n", ioc->name);
1830 return;
1831 }
1832
1833 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1834 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1835 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1836 "Failure in retrieving RVPG0\n", ioc->name);
1837 kfree(vol_pg0);
1838 return;
1839 }
1840
1841 /*
1842 * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
1843 * assumed for WARPDRIVE, disable direct I/O
1844 */
1845 if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
1846 printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
1847 "for the drive with handle(0x%04x): num_mem=%d, "
1848 "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
1849 num_pds, MPT_MAX_WARPDRIVE_PDS);
1850 kfree(vol_pg0);
1851 return;
1852 }
1853 for (count = 0; count < num_pds; count++) {
1854 if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1855 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1856 vol_pg0->PhysDisk[count].PhysDiskNum) ||
1857 pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) {
1858 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1859 "disabled for the drive with handle(0x%04x) member"
1860 "handle retrieval failed for member number=%d\n",
1861 ioc->name, raid_device->handle,
1862 vol_pg0->PhysDisk[count].PhysDiskNum);
1863 goto out_error;
1864 }
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301865 /* Disable direct I/O if member drive lba exceeds 4 bytes */
1866 dev_max_lba = le64_to_cpu(pd_pg0.DeviceMaxLBA);
1867 if (dev_max_lba >> 32) {
1868 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
1869 "disabled for the drive with handle(0x%04x) member"
1870 "handle (0x%04x) unsupported max lba 0x%016llx\n",
1871 ioc->name, raid_device->handle,
1872 le16_to_cpu(pd_pg0.DevHandle),
1873 (unsigned long long)dev_max_lba);
1874 goto out_error;
1875 }
1876
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301877 raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
1878 }
1879
1880 /*
1881 * Assumption for WD: Direct I/O is not supported if the volume is
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301882 * not RAID0
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301883 */
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301884 if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301885 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1886 "for the drive with handle(0x%04x): type=%d, "
1887 "s_sz=%uK, blk_size=%u\n", ioc->name,
1888 raid_device->handle, raid_device->volume_type,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301889 (le32_to_cpu(vol_pg0->StripeSize) *
1890 le16_to_cpu(vol_pg0->BlockSize)) / 1024,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301891 le16_to_cpu(vol_pg0->BlockSize));
1892 goto out_error;
1893 }
1894
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301895 stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301896 stripe_exp = find_first_bit(&stripe_sz, 32);
1897 if (stripe_exp == 32) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301898 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301899 "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301900 ioc->name, raid_device->handle,
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301901 (le32_to_cpu(vol_pg0->StripeSize) *
1902 le16_to_cpu(vol_pg0->BlockSize)) / 1024);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301903 goto out_error;
1904 }
1905 raid_device->stripe_exponent = stripe_exp;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05301906 block_sz = le16_to_cpu(vol_pg0->BlockSize);
1907 block_exp = find_first_bit(&block_sz, 16);
1908 if (block_exp == 16) {
1909 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
1910 "for the drive with handle(0x%04x) invalid block sz %u\n",
1911 ioc->name, raid_device->handle,
1912 le16_to_cpu(vol_pg0->BlockSize));
1913 goto out_error;
1914 }
1915 raid_device->block_exponent = block_exp;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301916 raid_device->direct_io_enabled = 1;
1917
1918 printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
1919 " with handle(0x%04x)\n", ioc->name, raid_device->handle);
1920 /*
1921 * WARPDRIVE: Though the following fields are not used for direct IO,
1922 * stored for future purpose:
1923 */
1924 raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
1925 raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
1926 raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
1927
1928
1929 kfree(vol_pg0);
1930 return;
1931
1932out_error:
1933 raid_device->direct_io_enabled = 0;
1934 for (count = 0; count < num_pds; count++)
1935 raid_device->pd_handle[count] = 0;
1936 kfree(vol_pg0);
1937 return;
1938}
Eric Moore635374e2009-03-09 01:21:12 -06001939
1940/**
Kashyap, Desai84f0b042009-12-16 18:56:28 +05301941 * _scsih_enable_tlr - setting TLR flags
1942 * @ioc: per adapter object
1943 * @sdev: scsi device struct
1944 *
1945 * Enabling Transaction Layer Retries for tape devices when
1946 * vpd page 0x90 is present
1947 *
1948 */
1949static void
1950_scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1951{
1952 /* only for TAPE */
1953 if (sdev->type != TYPE_TAPE)
1954 return;
1955
1956 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1957 return;
1958
1959 sas_enable_tlr(sdev);
1960 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1961 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1962 return;
1963
1964}
1965
1966/**
Eric Moored5d135b2009-05-18 13:02:08 -06001967 * _scsih_slave_configure - device configure routine.
Eric Moore635374e2009-03-09 01:21:12 -06001968 * @sdev: scsi device struct
1969 *
1970 * Returns 0 if ok. Any other return is assumed to be an error and
1971 * the device is ignored.
1972 */
1973static int
Eric Moored5d135b2009-05-18 13:02:08 -06001974_scsih_slave_configure(struct scsi_device *sdev)
Eric Moore635374e2009-03-09 01:21:12 -06001975{
1976 struct Scsi_Host *shost = sdev->host;
1977 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1978 struct MPT2SAS_DEVICE *sas_device_priv_data;
1979 struct MPT2SAS_TARGET *sas_target_priv_data;
1980 struct _sas_device *sas_device;
1981 struct _raid_device *raid_device;
1982 unsigned long flags;
1983 int qdepth;
1984 u8 ssp_target = 0;
1985 char *ds = "";
1986 char *r_level = "";
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301987 u16 handle, volume_handle = 0;
1988 u64 volume_wwid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06001989
1990 qdepth = 1;
1991 sas_device_priv_data = sdev->hostdata;
1992 sas_device_priv_data->configured_lun = 1;
1993 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1994 sas_target_priv_data = sas_device_priv_data->sas_target;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05301995 handle = sas_target_priv_data->handle;
Eric Moore635374e2009-03-09 01:21:12 -06001996
1997 /* raid volume handling */
1998 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1999
2000 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302001 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06002002 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
2003 if (!raid_device) {
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302004 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2005 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2006 __LINE__, __func__));
2007 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002008 }
2009
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302010 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
2011 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2012 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2013 __LINE__, __func__));
2014 return 1;
2015 }
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302016 /*
2017 * WARPDRIVE: Initialize the required data for Direct IO
2018 */
2019 _scsih_init_warpdrive_properties(ioc, raid_device);
2020
Eric Moore635374e2009-03-09 01:21:12 -06002021 /* RAID Queue Depth Support
2022 * IS volume = underlying qdepth of drive type, either
2023 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
2024 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
2025 */
2026 if (raid_device->device_info &
2027 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2028 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2029 ds = "SSP";
2030 } else {
2031 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2032 if (raid_device->device_info &
2033 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2034 ds = "SATA";
2035 else
2036 ds = "STP";
2037 }
2038
2039 switch (raid_device->volume_type) {
2040 case MPI2_RAID_VOL_TYPE_RAID0:
2041 r_level = "RAID0";
2042 break;
2043 case MPI2_RAID_VOL_TYPE_RAID1E:
2044 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
Kashyap, Desaied79f122009-08-20 13:23:49 +05302045 if (ioc->manu_pg10.OEMIdentifier &&
Kashyap, Desaic97951e2011-06-14 10:54:56 +05302046 (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
Kashyap, Desaied79f122009-08-20 13:23:49 +05302047 MFG10_GF0_R10_DISPLAY) &&
2048 !(raid_device->num_pds % 2))
2049 r_level = "RAID10";
2050 else
2051 r_level = "RAID1E";
Eric Moore635374e2009-03-09 01:21:12 -06002052 break;
2053 case MPI2_RAID_VOL_TYPE_RAID1:
2054 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2055 r_level = "RAID1";
2056 break;
2057 case MPI2_RAID_VOL_TYPE_RAID10:
2058 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2059 r_level = "RAID10";
2060 break;
2061 case MPI2_RAID_VOL_TYPE_UNKNOWN:
2062 default:
2063 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
2064 r_level = "RAIDX";
2065 break;
2066 }
2067
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302068 if (!ioc->hide_ir_msg)
2069 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2070 "wwid(0x%016llx), pd_count(%d), type(%s)\n",
2071 r_level, raid_device->handle,
2072 (unsigned long long)raid_device->wwid,
2073 raid_device->num_pds, ds);
Mike Christiee881a172009-10-15 17:46:39 -07002074 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05302075 /* raid transport support */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302076 if (!ioc->is_warpdrive)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302077 _scsih_set_level(sdev, raid_device->volume_type);
Eric Moore635374e2009-03-09 01:21:12 -06002078 return 0;
2079 }
2080
2081 /* non-raid handling */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302082 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2083 if (mpt2sas_config_get_volume_handle(ioc, handle,
2084 &volume_handle)) {
2085 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2086 "failure at %s:%d/%s()!\n", ioc->name,
2087 __FILE__, __LINE__, __func__));
2088 return 1;
2089 }
2090 if (volume_handle && mpt2sas_config_get_volume_wwid(ioc,
2091 volume_handle, &volume_wwid)) {
2092 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2093 "failure at %s:%d/%s()!\n", ioc->name,
2094 __FILE__, __LINE__, __func__));
2095 return 1;
2096 }
2097 }
2098
Eric Moore635374e2009-03-09 01:21:12 -06002099 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2100 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2101 sas_device_priv_data->sas_target->sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302102 if (!sas_device) {
2103 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302104 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302105 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
2106 __LINE__, __func__));
nagalakshmi.nandigama@lsi.com6faace22011-10-19 15:37:37 +05302107 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002108 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05302109 sas_device->volume_handle = volume_handle;
2110 sas_device->volume_wwid = volume_wwid;
2111 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2112 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
2113 ssp_target = 1;
2114 ds = "SSP";
2115 } else {
2116 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
2117 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET)
2118 ds = "STP";
2119 else if (sas_device->device_info &
2120 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
2121 ds = "SATA";
2122 }
2123 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
2124 "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
2125 ds, sas_device->handle,
2126 (unsigned long long)sas_device->sas_address,
2127 sas_device->phy,
2128 (unsigned long long)sas_device->device_name);
2129 sdev_printk(KERN_INFO, sdev, "%s: "
2130 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
2131 (unsigned long long) sas_device->enclosure_logical_id,
2132 sas_device->slot);
2133
2134 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2135 if (!ssp_target)
2136 _scsih_display_sata_capabilities(ioc, handle, sdev);
2137
Eric Moore635374e2009-03-09 01:21:12 -06002138
Mike Christiee881a172009-10-15 17:46:39 -07002139 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
Eric Moore635374e2009-03-09 01:21:12 -06002140
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302141 if (ssp_target) {
Eric Moore635374e2009-03-09 01:21:12 -06002142 sas_read_port_mode_page(sdev);
Kashyap, Desai84f0b042009-12-16 18:56:28 +05302143 _scsih_enable_tlr(ioc, sdev);
2144 }
Eric Moore635374e2009-03-09 01:21:12 -06002145 return 0;
2146}
2147
2148/**
Eric Moored5d135b2009-05-18 13:02:08 -06002149 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
Eric Moore635374e2009-03-09 01:21:12 -06002150 * @sdev: scsi device struct
2151 * @bdev: pointer to block device context
2152 * @capacity: device size (in 512 byte sectors)
2153 * @params: three element array to place output:
2154 * params[0] number of heads (max 255)
2155 * params[1] number of sectors (max 63)
2156 * params[2] number of cylinders
2157 *
2158 * Return nothing.
2159 */
2160static int
Eric Moored5d135b2009-05-18 13:02:08 -06002161_scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
Eric Moore635374e2009-03-09 01:21:12 -06002162 sector_t capacity, int params[])
2163{
2164 int heads;
2165 int sectors;
2166 sector_t cylinders;
2167 ulong dummy;
2168
2169 heads = 64;
2170 sectors = 32;
2171
2172 dummy = heads * sectors;
2173 cylinders = capacity;
2174 sector_div(cylinders, dummy);
2175
2176 /*
2177 * Handle extended translation size for logical drives
2178 * > 1Gb
2179 */
2180 if ((ulong)capacity >= 0x200000) {
2181 heads = 255;
2182 sectors = 63;
2183 dummy = heads * sectors;
2184 cylinders = capacity;
2185 sector_div(cylinders, dummy);
2186 }
2187
2188 /* return result */
2189 params[0] = heads;
2190 params[1] = sectors;
2191 params[2] = cylinders;
2192
2193 return 0;
2194}
2195
2196/**
2197 * _scsih_response_code - translation of device response code
2198 * @ioc: per adapter object
2199 * @response_code: response code returned by the device
2200 *
2201 * Return nothing.
2202 */
2203static void
2204_scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
2205{
2206 char *desc;
2207
2208 switch (response_code) {
2209 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
2210 desc = "task management request completed";
2211 break;
2212 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
2213 desc = "invalid frame";
2214 break;
2215 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2216 desc = "task management request not supported";
2217 break;
2218 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
2219 desc = "task management request failed";
2220 break;
2221 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2222 desc = "task management request succeeded";
2223 break;
2224 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2225 desc = "invalid lun";
2226 break;
2227 case 0xA:
2228 desc = "overlapped tag attempted";
2229 break;
2230 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2231 desc = "task queued, however not sent to target";
2232 break;
2233 default:
2234 desc = "unknown";
2235 break;
2236 }
2237 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
2238 ioc->name, response_code, desc);
2239}
2240
2241/**
Eric Moored5d135b2009-05-18 13:02:08 -06002242 * _scsih_tm_done - tm completion routine
Eric Moore635374e2009-03-09 01:21:12 -06002243 * @ioc: per adapter object
2244 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302245 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002246 * @reply: reply message frame(lower 32bit addr)
2247 * Context: none.
2248 *
2249 * The callback handler when using scsih_issue_tm.
2250 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302251 * Return 1 meaning mf should be freed from _base_interrupt
2252 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06002253 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302254static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302255_scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06002256{
2257 MPI2DefaultReply_t *mpi_reply;
2258
2259 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302260 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002261 if (ioc->tm_cmds.smid != smid)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302262 return 1;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05302263 mpt2sas_base_flush_reply_queues(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06002264 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
2265 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
2266 if (mpi_reply) {
2267 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
2268 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
2269 }
2270 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
2271 complete(&ioc->tm_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05302272 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06002273}
2274
2275/**
2276 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
2277 * @ioc: per adapter object
2278 * @handle: device handle
2279 *
2280 * During taskmangement request, we need to freeze the device queue.
2281 */
2282void
2283mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2284{
2285 struct MPT2SAS_DEVICE *sas_device_priv_data;
2286 struct scsi_device *sdev;
2287 u8 skip = 0;
2288
2289 shost_for_each_device(sdev, ioc->shost) {
2290 if (skip)
2291 continue;
2292 sas_device_priv_data = sdev->hostdata;
2293 if (!sas_device_priv_data)
2294 continue;
2295 if (sas_device_priv_data->sas_target->handle == handle) {
2296 sas_device_priv_data->sas_target->tm_busy = 1;
2297 skip = 1;
2298 ioc->ignore_loginfos = 1;
2299 }
2300 }
2301}
2302
2303/**
2304 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
2305 * @ioc: per adapter object
2306 * @handle: device handle
2307 *
2308 * During taskmangement request, we need to freeze the device queue.
2309 */
2310void
2311mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2312{
2313 struct MPT2SAS_DEVICE *sas_device_priv_data;
2314 struct scsi_device *sdev;
2315 u8 skip = 0;
2316
2317 shost_for_each_device(sdev, ioc->shost) {
2318 if (skip)
2319 continue;
2320 sas_device_priv_data = sdev->hostdata;
2321 if (!sas_device_priv_data)
2322 continue;
2323 if (sas_device_priv_data->sas_target->handle == handle) {
2324 sas_device_priv_data->sas_target->tm_busy = 0;
2325 skip = 1;
2326 ioc->ignore_loginfos = 0;
2327 }
2328 }
2329}
2330
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302331
Eric Moore635374e2009-03-09 01:21:12 -06002332/**
2333 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
2334 * @ioc: per adapter struct
2335 * @device_handle: device handle
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302336 * @channel: the channel assigned by the OS
2337 * @id: the id assigned by the OS
Eric Moore635374e2009-03-09 01:21:12 -06002338 * @lun: lun number
2339 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
2340 * @smid_task: smid assigned to the task
2341 * @timeout: timeout in seconds
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302342 * @serial_number: the serial_number from scmd
2343 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302344 * Context: user
Eric Moore635374e2009-03-09 01:21:12 -06002345 *
2346 * A generic API for sending task management requests to firmware.
2347 *
Eric Moore635374e2009-03-09 01:21:12 -06002348 * The callback index is set inside `ioc->tm_cb_idx`.
2349 *
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302350 * Return SUCCESS or FAILED.
Eric Moore635374e2009-03-09 01:21:12 -06002351 */
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302352int
2353mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
2354 uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302355 unsigned long serial_number, enum mutex_type m_type)
Eric Moore635374e2009-03-09 01:21:12 -06002356{
2357 Mpi2SCSITaskManagementRequest_t *mpi_request;
2358 Mpi2SCSITaskManagementReply_t *mpi_reply;
2359 u16 smid = 0;
2360 u32 ioc_state;
2361 unsigned long timeleft;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302362 struct scsiio_tracker *scsi_lookup = NULL;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302363 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06002364
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302365 if (m_type == TM_MUTEX_ON)
2366 mutex_lock(&ioc->tm_cmds.mutex);
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302367 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
2368 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
2369 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302370 rc = FAILED;
2371 goto err_out;
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05302372 }
2373
Eric Moore3cb54692010-07-08 14:44:34 -06002374 if (ioc->shost_recovery || ioc->remove_host ||
2375 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06002376 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2377 __func__, ioc->name);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302378 rc = FAILED;
2379 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002380 }
Eric Moore635374e2009-03-09 01:21:12 -06002381
2382 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
2383 if (ioc_state & MPI2_DOORBELL_USED) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302384 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
Eric Moore635374e2009-03-09 01:21:12 -06002385 "active!\n", ioc->name));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302386 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302387 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302388 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302389 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002390 }
2391
2392 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
2393 mpt2sas_base_fault_info(ioc, ioc_state &
2394 MPI2_DOORBELL_DATA_MASK);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302395 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302396 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302397 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302398 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002399 }
2400
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302401 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06002402 if (!smid) {
2403 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2404 ioc->name, __func__);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302405 rc = FAILED;
2406 goto err_out;
Eric Moore635374e2009-03-09 01:21:12 -06002407 }
2408
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302409 if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2410 scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
2411
Eric Moore635374e2009-03-09 01:21:12 -06002412 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302413 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
2414 smid_task));
Eric Moore635374e2009-03-09 01:21:12 -06002415 ioc->tm_cmds.status = MPT2_CMD_PENDING;
2416 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2417 ioc->tm_cmds.smid = smid;
2418 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302419 memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
Eric Moore635374e2009-03-09 01:21:12 -06002420 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2421 mpi_request->DevHandle = cpu_to_le16(handle);
2422 mpi_request->TaskType = type;
2423 mpi_request->TaskMID = cpu_to_le16(smid_task);
2424 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
2425 mpt2sas_scsih_set_tm_flag(ioc, handle);
Kashyap, Desai5b768582009-08-20 13:24:31 +05302426 init_completion(&ioc->tm_cmds.done);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05302427 mpt2sas_base_put_smid_hi_priority(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06002428 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
Eric Moore635374e2009-03-09 01:21:12 -06002429 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
2430 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
2431 ioc->name, __func__);
2432 _debug_dump_mf(mpi_request,
2433 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302434 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302435 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302436 FORCE_BIG_HAMMER);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302437 rc = (!rc) ? SUCCESS : FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302438 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2439 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2440 goto err_out;
2441 }
Eric Moore635374e2009-03-09 01:21:12 -06002442 }
2443
2444 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
2445 mpi_reply = ioc->tm_cmds.reply;
2446 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
2447 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
2448 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
2449 le32_to_cpu(mpi_reply->IOCLogInfo),
2450 le32_to_cpu(mpi_reply->TerminationCount)));
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302451 if (ioc->logging_level & MPT_DEBUG_TM) {
Eric Moore635374e2009-03-09 01:21:12 -06002452 _scsih_response_code(ioc, mpi_reply->ResponseCode);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302453 if (mpi_reply->IOCStatus)
2454 _debug_dump_mf(mpi_request,
2455 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
2456 }
Eric Moore635374e2009-03-09 01:21:12 -06002457 }
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302458
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302459 switch (type) {
2460 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302461 rc = SUCCESS;
2462 if (scsi_lookup->scmd == NULL)
2463 break;
2464 rc = FAILED;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302465 break;
2466
2467 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2468 if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
2469 rc = FAILED;
2470 else
2471 rc = SUCCESS;
2472 break;
2473
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302474 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302475 case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
2476 if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
2477 rc = FAILED;
2478 else
2479 rc = SUCCESS;
2480 break;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302481 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
2482 rc = SUCCESS;
2483 break;
2484 default:
2485 rc = FAILED;
2486 break;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302487 }
2488
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302489 mpt2sas_scsih_clear_tm_flag(ioc, handle);
2490 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302491 if (m_type == TM_MUTEX_ON)
2492 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302493
2494 return rc;
2495
2496 err_out:
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302497 if (m_type == TM_MUTEX_ON)
2498 mutex_unlock(&ioc->tm_cmds.mutex);
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302499 return rc;
Eric Moore635374e2009-03-09 01:21:12 -06002500}
2501
2502/**
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302503 * _scsih_tm_display_info - displays info about the device
2504 * @ioc: per adapter struct
2505 * @scmd: pointer to scsi command object
2506 *
2507 * Called by task management callback handlers.
2508 */
2509static void
2510_scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
2511{
2512 struct scsi_target *starget = scmd->device->sdev_target;
2513 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
2514 struct _sas_device *sas_device = NULL;
2515 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302516 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302517
2518 if (!priv_target)
2519 return;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302520 if (ioc->hide_ir_msg)
2521 device_str = "WarpDrive";
2522 else
2523 device_str = "volume";
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302524
2525 scsi_print_command(scmd);
2526 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302527 starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
2528 "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
2529 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302530 } else {
2531 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2532 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2533 priv_target->sas_address);
2534 if (sas_device) {
2535 if (priv_target->flags &
2536 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2537 starget_printk(KERN_INFO, starget,
2538 "volume handle(0x%04x), "
2539 "volume wwid(0x%016llx)\n",
2540 sas_device->volume_handle,
2541 (unsigned long long)sas_device->volume_wwid);
2542 }
2543 starget_printk(KERN_INFO, starget,
2544 "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
2545 sas_device->handle,
2546 (unsigned long long)sas_device->sas_address,
2547 sas_device->phy);
2548 starget_printk(KERN_INFO, starget,
2549 "enclosure_logical_id(0x%016llx), slot(%d)\n",
2550 (unsigned long long)sas_device->enclosure_logical_id,
2551 sas_device->slot);
2552 }
2553 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2554 }
2555}
2556
2557/**
Eric Moored5d135b2009-05-18 13:02:08 -06002558 * _scsih_abort - eh threads main abort routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302559 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002560 *
2561 * Returns SUCCESS if command aborted else FAILED
2562 */
2563static int
Eric Moored5d135b2009-05-18 13:02:08 -06002564_scsih_abort(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002565{
2566 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2567 struct MPT2SAS_DEVICE *sas_device_priv_data;
2568 u16 smid;
2569 u16 handle;
2570 int r;
Eric Moore635374e2009-03-09 01:21:12 -06002571
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302572 sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
2573 "scmd(%p)\n", scmd);
2574 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002575
2576 sas_device_priv_data = scmd->device->hostdata;
2577 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302578 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
2579 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002580 scmd->result = DID_NO_CONNECT << 16;
2581 scmd->scsi_done(scmd);
2582 r = SUCCESS;
2583 goto out;
2584 }
2585
2586 /* search for the command */
2587 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
2588 if (!smid) {
2589 scmd->result = DID_RESET << 16;
2590 r = SUCCESS;
2591 goto out;
2592 }
2593
2594 /* for hidden raid components and volumes this is not supported */
2595 if (sas_device_priv_data->sas_target->flags &
2596 MPT_TARGET_FLAGS_RAID_COMPONENT ||
2597 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
2598 scmd->result = DID_RESET << 16;
2599 r = FAILED;
2600 goto out;
2601 }
2602
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05302603 mpt2sas_halt_firmware(ioc);
2604
Eric Moore635374e2009-03-09 01:21:12 -06002605 handle = sas_device_priv_data->sas_target->handle;
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302606 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2607 scmd->device->id, scmd->device->lun,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302608 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
2609 scmd->serial_number, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002610
2611 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302612 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
2613 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002614 return r;
2615}
2616
Eric Moore635374e2009-03-09 01:21:12 -06002617/**
Eric Moored5d135b2009-05-18 13:02:08 -06002618 * _scsih_dev_reset - eh threads main device reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302619 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002620 *
2621 * Returns SUCCESS if command aborted else FAILED
2622 */
2623static int
Eric Moored5d135b2009-05-18 13:02:08 -06002624_scsih_dev_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002625{
2626 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2627 struct MPT2SAS_DEVICE *sas_device_priv_data;
2628 struct _sas_device *sas_device;
2629 unsigned long flags;
2630 u16 handle;
2631 int r;
2632
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302633 struct scsi_target *starget = scmd->device->sdev_target;
2634
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302635 starget_printk(KERN_INFO, starget, "attempting device reset! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302636 "scmd(%p)\n", scmd);
2637 _scsih_tm_display_info(ioc, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002638
2639 sas_device_priv_data = scmd->device->hostdata;
2640 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai37aaa782010-11-13 04:41:32 +05302641 starget_printk(KERN_INFO, starget, "device been deleted! "
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302642 "scmd(%p)\n", scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002643 scmd->result = DID_NO_CONNECT << 16;
2644 scmd->scsi_done(scmd);
2645 r = SUCCESS;
2646 goto out;
2647 }
2648
2649 /* for hidden raid components obtain the volume_handle */
2650 handle = 0;
2651 if (sas_device_priv_data->sas_target->flags &
2652 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2653 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2654 sas_device = _scsih_sas_device_find_by_handle(ioc,
2655 sas_device_priv_data->sas_target->handle);
2656 if (sas_device)
2657 handle = sas_device->volume_handle;
2658 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2659 } else
2660 handle = sas_device_priv_data->sas_target->handle;
2661
2662 if (!handle) {
2663 scmd->result = DID_RESET << 16;
2664 r = FAILED;
2665 goto out;
2666 }
2667
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302668 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2669 scmd->device->id, scmd->device->lun,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302670 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0,
2671 TM_MUTEX_ON);
Eric Moore993e0da2009-05-18 13:00:45 -06002672
2673 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302674 sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
2675 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002676 return r;
2677}
2678
2679/**
Eric Moored5d135b2009-05-18 13:02:08 -06002680 * _scsih_target_reset - eh threads main target reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302681 * @scmd: pointer to scsi command object
Eric Moore993e0da2009-05-18 13:00:45 -06002682 *
2683 * Returns SUCCESS if command aborted else FAILED
2684 */
2685static int
Eric Moored5d135b2009-05-18 13:02:08 -06002686_scsih_target_reset(struct scsi_cmnd *scmd)
Eric Moore993e0da2009-05-18 13:00:45 -06002687{
2688 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2689 struct MPT2SAS_DEVICE *sas_device_priv_data;
2690 struct _sas_device *sas_device;
2691 unsigned long flags;
2692 u16 handle;
2693 int r;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302694 struct scsi_target *starget = scmd->device->sdev_target;
Eric Moore993e0da2009-05-18 13:00:45 -06002695
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302696 starget_printk(KERN_INFO, starget, "attempting target reset! "
2697 "scmd(%p)\n", scmd);
2698 _scsih_tm_display_info(ioc, scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002699
2700 sas_device_priv_data = scmd->device->hostdata;
2701 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302702 starget_printk(KERN_INFO, starget, "target been deleted! "
2703 "scmd(%p)\n", scmd);
Eric Moore993e0da2009-05-18 13:00:45 -06002704 scmd->result = DID_NO_CONNECT << 16;
2705 scmd->scsi_done(scmd);
2706 r = SUCCESS;
2707 goto out;
2708 }
2709
2710 /* for hidden raid components obtain the volume_handle */
2711 handle = 0;
2712 if (sas_device_priv_data->sas_target->flags &
2713 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2714 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2715 sas_device = _scsih_sas_device_find_by_handle(ioc,
2716 sas_device_priv_data->sas_target->handle);
2717 if (sas_device)
2718 handle = sas_device->volume_handle;
2719 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2720 } else
2721 handle = sas_device_priv_data->sas_target->handle;
2722
2723 if (!handle) {
2724 scmd->result = DID_RESET << 16;
2725 r = FAILED;
2726 goto out;
2727 }
2728
Kashyap, Desai8ed9a032010-03-17 16:25:59 +05302729 r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
2730 scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302731 30, 0, TM_MUTEX_ON);
Eric Moore635374e2009-03-09 01:21:12 -06002732
2733 out:
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302734 starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
2735 ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
Eric Moore635374e2009-03-09 01:21:12 -06002736 return r;
2737}
2738
2739/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302740 * _scsih_host_reset - eh threads main host reset routine
Kashyap, Desai8e864a82010-06-17 13:48:46 +05302741 * @scmd: pointer to scsi command object
Eric Moore635374e2009-03-09 01:21:12 -06002742 *
2743 * Returns SUCCESS if command aborted else FAILED
2744 */
2745static int
Eric Moored5d135b2009-05-18 13:02:08 -06002746_scsih_host_reset(struct scsi_cmnd *scmd)
Eric Moore635374e2009-03-09 01:21:12 -06002747{
2748 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2749 int r, retval;
2750
2751 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2752 ioc->name, scmd);
2753 scsi_print_command(scmd);
2754
2755 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2756 FORCE_BIG_HAMMER);
2757 r = (retval < 0) ? FAILED : SUCCESS;
2758 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2759 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2760
2761 return r;
2762}
2763
2764/**
2765 * _scsih_fw_event_add - insert and queue up fw_event
2766 * @ioc: per adapter object
2767 * @fw_event: object describing the event
2768 * Context: This function will acquire ioc->fw_event_lock.
2769 *
2770 * This adds the firmware event object into link list, then queues it up to
2771 * be processed from user context.
2772 *
2773 * Return nothing.
2774 */
2775static void
2776_scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2777{
2778 unsigned long flags;
2779
2780 if (ioc->firmware_event_thread == NULL)
2781 return;
2782
2783 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2784 list_add_tail(&fw_event->list, &ioc->fw_event_list);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302785 INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
2786 queue_delayed_work(ioc->firmware_event_thread,
2787 &fw_event->delayed_work, 0);
Eric Moore635374e2009-03-09 01:21:12 -06002788 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2789}
2790
2791/**
2792 * _scsih_fw_event_free - delete fw_event
2793 * @ioc: per adapter object
2794 * @fw_event: object describing the event
2795 * Context: This function will acquire ioc->fw_event_lock.
2796 *
2797 * This removes firmware event object from link list, frees associated memory.
2798 *
2799 * Return nothing.
2800 */
2801static void
2802_scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2803 *fw_event)
2804{
2805 unsigned long flags;
2806
2807 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2808 list_del(&fw_event->list);
2809 kfree(fw_event->event_data);
2810 kfree(fw_event);
2811 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2812}
2813
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302814
Eric Moore635374e2009-03-09 01:21:12 -06002815/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302816 * _scsih_error_recovery_delete_devices - remove devices not responding
Eric Moore635374e2009-03-09 01:21:12 -06002817 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06002818 *
2819 * Return nothing.
2820 */
2821static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302822_scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06002823{
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302824 struct fw_event_work *fw_event;
2825
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302826 if (ioc->is_driver_loading)
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302827 return;
Dan Carpenter181a9d72011-11-04 21:25:01 +03002828
2829 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2830 if (!fw_event)
2831 return;
2832
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302833 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2834 fw_event->ioc = ioc;
2835 _scsih_fw_event_add(ioc, fw_event);
2836}
2837
2838/**
2839 * mpt2sas_port_enable_complete - port enable completed (fake event)
2840 * @ioc: per adapter object
2841 *
2842 * Return nothing.
2843 */
2844void
2845mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2846{
2847 struct fw_event_work *fw_event;
2848
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302849 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2850 if (!fw_event)
2851 return;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05302852 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302853 fw_event->ioc = ioc;
2854 _scsih_fw_event_add(ioc, fw_event);
2855}
2856
2857/**
2858 * _scsih_fw_event_cleanup_queue - cleanup event queue
2859 * @ioc: per adapter object
2860 *
2861 * Walk the firmware event queue, either killing timers, or waiting
2862 * for outstanding events to complete
2863 *
2864 * Return nothing.
2865 */
2866static void
2867_scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
2868{
2869 struct fw_event_work *fw_event, *next;
2870
2871 if (list_empty(&ioc->fw_event_list) ||
2872 !ioc->firmware_event_thread || in_interrupt())
Eric Moore635374e2009-03-09 01:21:12 -06002873 return;
2874
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05302875 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
2876 if (cancel_delayed_work(&fw_event->delayed_work)) {
2877 _scsih_fw_event_free(ioc, fw_event);
2878 continue;
2879 }
2880 fw_event->cancel_pending_work = 1;
2881 }
Eric Moore635374e2009-03-09 01:21:12 -06002882}
2883
Eric Moore635374e2009-03-09 01:21:12 -06002884/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302885 * _scsih_ublock_io_all_device - unblock every device
2886 * @ioc: per adapter object
2887 *
2888 * change the device state from block to running
2889 */
2890static void
2891_scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2892{
2893 struct MPT2SAS_DEVICE *sas_device_priv_data;
2894 struct scsi_device *sdev;
2895
2896 shost_for_each_device(sdev, ioc->shost) {
2897 sas_device_priv_data = sdev->hostdata;
2898 if (!sas_device_priv_data)
2899 continue;
2900 if (!sas_device_priv_data->block)
2901 continue;
2902 sas_device_priv_data->block = 0;
2903 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
2904 "handle(0x%04x)\n",
2905 sas_device_priv_data->sas_target->handle));
2906 scsi_internal_device_unblock(sdev);
2907 }
2908}
2909/**
Eric Moore635374e2009-03-09 01:21:12 -06002910 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2911 * @ioc: per adapter object
2912 * @handle: device handle
2913 *
2914 * During device pull we need to appropiately set the sdev state.
2915 */
2916static void
2917_scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2918{
2919 struct MPT2SAS_DEVICE *sas_device_priv_data;
2920 struct scsi_device *sdev;
2921
2922 shost_for_each_device(sdev, ioc->shost) {
2923 sas_device_priv_data = sdev->hostdata;
2924 if (!sas_device_priv_data)
2925 continue;
2926 if (!sas_device_priv_data->block)
2927 continue;
2928 if (sas_device_priv_data->sas_target->handle == handle) {
2929 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2930 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2931 "handle(0x%04x)\n", ioc->name, handle));
2932 sas_device_priv_data->block = 0;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05302933 scsi_internal_device_unblock(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002934 }
2935 }
2936}
2937
2938/**
Kashyap, Desaif93213d2011-06-14 10:56:43 +05302939 * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
2940 * @ioc: per adapter object
2941 * @handle: device handle
2942 *
2943 * During device pull we need to appropiately set the sdev state.
2944 */
2945static void
2946_scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
2947{
2948 struct MPT2SAS_DEVICE *sas_device_priv_data;
2949 struct scsi_device *sdev;
2950
2951 shost_for_each_device(sdev, ioc->shost) {
2952 sas_device_priv_data = sdev->hostdata;
2953 if (!sas_device_priv_data)
2954 continue;
2955 if (sas_device_priv_data->block)
2956 continue;
2957 sas_device_priv_data->block = 1;
2958 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
2959 "handle(0x%04x)\n",
2960 sas_device_priv_data->sas_target->handle));
2961 scsi_internal_device_block(sdev);
2962 }
2963}
2964
2965
2966/**
Eric Moore635374e2009-03-09 01:21:12 -06002967 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2968 * @ioc: per adapter object
2969 * @handle: device handle
2970 *
2971 * During device pull we need to appropiately set the sdev state.
2972 */
2973static void
2974_scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2975{
2976 struct MPT2SAS_DEVICE *sas_device_priv_data;
2977 struct scsi_device *sdev;
2978
2979 shost_for_each_device(sdev, ioc->shost) {
2980 sas_device_priv_data = sdev->hostdata;
2981 if (!sas_device_priv_data)
2982 continue;
2983 if (sas_device_priv_data->block)
2984 continue;
2985 if (sas_device_priv_data->sas_target->handle == handle) {
2986 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2987 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2988 "handle(0x%04x)\n", ioc->name, handle));
2989 sas_device_priv_data->block = 1;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05302990 scsi_internal_device_block(sdev);
Eric Moore635374e2009-03-09 01:21:12 -06002991 }
2992 }
2993}
2994
2995/**
2996 * _scsih_block_io_to_children_attached_to_ex
2997 * @ioc: per adapter object
2998 * @sas_expander: the sas_device object
2999 *
3000 * This routine set sdev state to SDEV_BLOCK for all devices
3001 * attached to this expander. This function called when expander is
3002 * pulled.
3003 */
3004static void
3005_scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
3006 struct _sas_node *sas_expander)
3007{
3008 struct _sas_port *mpt2sas_port;
3009 struct _sas_device *sas_device;
3010 struct _sas_node *expander_sibling;
3011 unsigned long flags;
3012
3013 if (!sas_expander)
3014 return;
3015
3016 list_for_each_entry(mpt2sas_port,
3017 &sas_expander->sas_port_list, port_list) {
3018 if (mpt2sas_port->remote_identify.device_type ==
3019 SAS_END_DEVICE) {
3020 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3021 sas_device =
3022 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3023 mpt2sas_port->remote_identify.sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303024 if (sas_device)
3025 set_bit(sas_device->handle,
3026 ioc->blocking_handles);
Eric Moore635374e2009-03-09 01:21:12 -06003027 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06003028 }
3029 }
3030
3031 list_for_each_entry(mpt2sas_port,
3032 &sas_expander->sas_port_list, port_list) {
3033
3034 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303035 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06003036 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05303037 SAS_FANOUT_EXPANDER_DEVICE) {
Eric Moore635374e2009-03-09 01:21:12 -06003038 expander_sibling =
3039 mpt2sas_scsih_expander_find_by_sas_address(
3040 ioc, mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06003041 _scsih_block_io_to_children_attached_to_ex(ioc,
3042 expander_sibling);
3043 }
3044 }
3045}
3046
3047/**
3048 * _scsih_block_io_to_children_attached_directly
3049 * @ioc: per adapter object
3050 * @event_data: topology change event data
3051 *
3052 * This routine set sdev state to SDEV_BLOCK for all devices
3053 * direct attached during device pull.
3054 */
3055static void
3056_scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
3057 Mpi2EventDataSasTopologyChangeList_t *event_data)
3058{
3059 int i;
3060 u16 handle;
3061 u16 reason_code;
3062 u8 phy_number;
3063
3064 for (i = 0; i < event_data->NumEntries; i++) {
3065 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3066 if (!handle)
3067 continue;
3068 phy_number = event_data->StartPhyNum + i;
3069 reason_code = event_data->PHY[i].PhyStatus &
3070 MPI2_EVENT_SAS_TOPO_RC_MASK;
3071 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
3072 _scsih_block_io_device(ioc, handle);
3073 }
3074}
3075
3076/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303077 * _scsih_tm_tr_send - send task management request
3078 * @ioc: per adapter object
3079 * @handle: device handle
3080 * Context: interrupt time.
3081 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003082 * This code is to initiate the device removal handshake protocol
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303083 * with controller firmware. This function will issue target reset
3084 * using high priority request queue. It will send a sas iounit
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003085 * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303086 *
3087 * This is designed to send muliple task management request at the same
3088 * time to the fifo. If the fifo is full, we will append the request,
3089 * and process it in a future completion.
3090 */
3091static void
3092_scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3093{
3094 Mpi2SCSITaskManagementRequest_t *mpi_request;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303095 u16 smid;
3096 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303097 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3098 u64 sas_address = 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303099 unsigned long flags;
3100 struct _tr_list *delayed_tr;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303101 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303102
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303103 if (ioc->remove_host) {
3104 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3105 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
3106 return;
3107 } else if (ioc->pci_error_recovery) {
3108 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3109 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3110 handle));
3111 return;
3112 }
3113 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3114 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3115 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3116 "operational: handle(0x%04x)\n", __func__, ioc->name,
3117 handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303118 return;
3119 }
3120
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303121 /* if PD, then return */
3122 if (test_bit(handle, ioc->pd_handles))
3123 return;
3124
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303125 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3126 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303127 if (sas_device && sas_device->starget &&
3128 sas_device->starget->hostdata) {
3129 sas_target_priv_data = sas_device->starget->hostdata;
3130 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303131 sas_address = sas_device->sas_address;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303132 }
3133 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303134
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303135 if (sas_target_priv_data) {
3136 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3137 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3138 (unsigned long long)sas_address));
3139 _scsih_ublock_io_device(ioc, handle);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05303140 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
nagalakshmi.nandigama@lsi.comf3db0322011-10-19 15:37:14 +05303141 }
3142
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303143 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3144 if (!smid) {
3145 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3146 if (!delayed_tr)
3147 return;
3148 INIT_LIST_HEAD(&delayed_tr->list);
3149 delayed_tr->handle = handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303150 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3151 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3152 "DELAYED:tr:handle(0x%04x), (open)\n",
3153 ioc->name, handle));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303154 return;
3155 }
3156
Kashyap, Desai1278b112010-03-09 17:34:13 +05303157 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3158 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3159 ioc->tm_tr_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303160 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3161 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3162 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3163 mpi_request->DevHandle = cpu_to_le16(handle);
3164 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303165 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3166}
3167
3168
3169
3170/**
3171 * _scsih_sas_control_complete - completion routine
3172 * @ioc: per adapter object
3173 * @smid: system request message index
3174 * @msix_index: MSIX table index supplied by the OS
3175 * @reply: reply message frame(lower 32bit addr)
3176 * Context: interrupt time.
3177 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003178 * This is the sas iounit control completion routine.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303179 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003180 * handshake protocol with controller firmware.
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303181 *
3182 * Return 1 meaning mf should be freed from _base_interrupt
3183 * 0 means the mf is freed from this function.
3184 */
3185static u8
3186_scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3187 u8 msix_index, u32 reply)
3188{
Kashyap, Desai363fa50f2010-11-13 04:29:20 +05303189#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303190 Mpi2SasIoUnitControlReply_t *mpi_reply =
3191 mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desai363fa50f2010-11-13 04:29:20 +05303192#endif
Kashyap, Desai1278b112010-03-09 17:34:13 +05303193 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3194 "sc_complete:handle(0x%04x), (open) "
3195 "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
3196 ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
3197 le16_to_cpu(mpi_reply->IOCStatus),
3198 le32_to_cpu(mpi_reply->IOCLogInfo)));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303199 return 1;
3200}
3201
3202/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303203 * _scsih_tm_tr_volume_send - send target reset request for volumes
3204 * @ioc: per adapter object
3205 * @handle: device handle
3206 * Context: interrupt time.
3207 *
3208 * This is designed to send muliple task management request at the same
3209 * time to the fifo. If the fifo is full, we will append the request,
3210 * and process it in a future completion.
3211 */
3212static void
3213_scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3214{
3215 Mpi2SCSITaskManagementRequest_t *mpi_request;
3216 u16 smid;
3217 struct _tr_list *delayed_tr;
3218
Eric Moore3cb54692010-07-08 14:44:34 -06003219 if (ioc->shost_recovery || ioc->remove_host ||
3220 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303221 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3222 "progress!\n", __func__, ioc->name));
3223 return;
3224 }
3225
3226 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
3227 if (!smid) {
3228 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3229 if (!delayed_tr)
3230 return;
3231 INIT_LIST_HEAD(&delayed_tr->list);
3232 delayed_tr->handle = handle;
3233 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
3234 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3235 "DELAYED:tr:handle(0x%04x), (open)\n",
3236 ioc->name, handle));
3237 return;
3238 }
3239
3240 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
3241 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
3242 ioc->tm_tr_volume_cb_idx));
3243 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3244 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
3245 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3246 mpi_request->DevHandle = cpu_to_le16(handle);
3247 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
3248 mpt2sas_base_put_smid_hi_priority(ioc, smid);
3249}
3250
3251/**
3252 * _scsih_tm_volume_tr_complete - target reset completion
3253 * @ioc: per adapter object
3254 * @smid: system request message index
3255 * @msix_index: MSIX table index supplied by the OS
3256 * @reply: reply message frame(lower 32bit addr)
3257 * Context: interrupt time.
3258 *
3259 * Return 1 meaning mf should be freed from _base_interrupt
3260 * 0 means the mf is freed from this function.
3261 */
3262static u8
3263_scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
3264 u8 msix_index, u32 reply)
3265{
3266 u16 handle;
3267 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
3268 Mpi2SCSITaskManagementReply_t *mpi_reply =
3269 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3270
Eric Moore3cb54692010-07-08 14:44:34 -06003271 if (ioc->shost_recovery || ioc->remove_host ||
3272 ioc->pci_error_recovery) {
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303273 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
3274 "progress!\n", __func__, ioc->name));
3275 return 1;
3276 }
3277
3278 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3279 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3280 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3281 dewtprintk(ioc, printk("spurious interrupt: "
3282 "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
3283 le16_to_cpu(mpi_reply->DevHandle), smid));
3284 return 0;
3285 }
3286
3287 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3288 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3289 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3290 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3291 le32_to_cpu(mpi_reply->IOCLogInfo),
3292 le32_to_cpu(mpi_reply->TerminationCount)));
3293
3294 return _scsih_check_for_pending_tm(ioc, smid);
3295}
3296
3297/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303298 * _scsih_tm_tr_complete -
3299 * @ioc: per adapter object
3300 * @smid: system request message index
3301 * @msix_index: MSIX table index supplied by the OS
3302 * @reply: reply message frame(lower 32bit addr)
3303 * Context: interrupt time.
3304 *
3305 * This is the target reset completion routine.
3306 * This code is part of the code to initiate the device removal
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003307 * handshake protocol with controller firmware.
3308 * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303309 *
3310 * Return 1 meaning mf should be freed from _base_interrupt
3311 * 0 means the mf is freed from this function.
3312 */
3313static u8
3314_scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3315 u32 reply)
3316{
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303317 u16 handle;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303318 Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303319 Mpi2SCSITaskManagementReply_t *mpi_reply =
3320 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3321 Mpi2SasIoUnitControlRequest_t *mpi_request;
3322 u16 smid_sas_ctrl;
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303323 u32 ioc_state;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303324
nagalakshmi.nandigama@lsi.comf881cea2011-10-19 15:37:00 +05303325 if (ioc->remove_host) {
3326 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3327 "removed\n", __func__, ioc->name));
3328 return 1;
3329 } else if (ioc->pci_error_recovery) {
3330 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3331 "error recovery\n", __func__, ioc->name));
3332 return 1;
3333 }
3334 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3335 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3336 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3337 "operational\n", __func__, ioc->name));
Kashyap, Desai1278b112010-03-09 17:34:13 +05303338 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303339 }
3340
Kashyap, Desai1278b112010-03-09 17:34:13 +05303341 mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
3342 handle = le16_to_cpu(mpi_request_tm->DevHandle);
3343 if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
3344 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
3345 "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
3346 le16_to_cpu(mpi_reply->DevHandle), smid));
3347 return 0;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303348 }
3349
Kashyap, Desai1278b112010-03-09 17:34:13 +05303350 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3351 "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
3352 "loginfo(0x%08x), completed(%d)\n", ioc->name,
3353 handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
3354 le32_to_cpu(mpi_reply->IOCLogInfo),
3355 le32_to_cpu(mpi_reply->TerminationCount)));
3356
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303357 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
3358 if (!smid_sas_ctrl) {
3359 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3360 ioc->name, __func__);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303361 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303362 }
3363
Kashyap, Desai1278b112010-03-09 17:34:13 +05303364 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
3365 "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
3366 ioc->tm_sas_control_cb_idx));
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303367 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
3368 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3369 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3370 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303371 mpi_request->DevHandle = mpi_request_tm->DevHandle;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303372 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
Kashyap, Desai1278b112010-03-09 17:34:13 +05303373
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303374 return _scsih_check_for_pending_tm(ioc, smid);
3375}
3376
3377/**
3378 * _scsih_check_for_pending_tm - check for pending task management
3379 * @ioc: per adapter object
3380 * @smid: system request message index
3381 *
3382 * This will check delayed target reset list, and feed the
3383 * next reqeust.
3384 *
3385 * Return 1 meaning mf should be freed from _base_interrupt
3386 * 0 means the mf is freed from this function.
3387 */
3388static u8
3389_scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3390{
3391 struct _tr_list *delayed_tr;
3392
3393 if (!list_empty(&ioc->delayed_tr_volume_list)) {
3394 delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
3395 struct _tr_list, list);
3396 mpt2sas_base_free_smid(ioc, smid);
3397 _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
3398 list_del(&delayed_tr->list);
3399 kfree(delayed_tr);
3400 return 0;
3401 }
3402
Kashyap, Desai1278b112010-03-09 17:34:13 +05303403 if (!list_empty(&ioc->delayed_tr_list)) {
3404 delayed_tr = list_entry(ioc->delayed_tr_list.next,
3405 struct _tr_list, list);
3406 mpt2sas_base_free_smid(ioc, smid);
3407 _scsih_tm_tr_send(ioc, delayed_tr->handle);
3408 list_del(&delayed_tr->list);
3409 kfree(delayed_tr);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303410 return 0;
Kashyap, Desai1278b112010-03-09 17:34:13 +05303411 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303412
Kashyap, Desai1278b112010-03-09 17:34:13 +05303413 return 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303414}
3415
3416/**
Eric Moore635374e2009-03-09 01:21:12 -06003417 * _scsih_check_topo_delete_events - sanity check on topo events
3418 * @ioc: per adapter object
3419 * @event_data: the event data payload
3420 *
3421 * This routine added to better handle cable breaker.
3422 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003423 * This handles the case where driver receives multiple expander
Eric Moore635374e2009-03-09 01:21:12 -06003424 * add and delete events in a single shot. When there is a delete event
3425 * the routine will void any pending add events waiting in the event queue.
3426 *
3427 * Return nothing.
3428 */
3429static void
3430_scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
3431 Mpi2EventDataSasTopologyChangeList_t *event_data)
3432{
3433 struct fw_event_work *fw_event;
3434 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
3435 u16 expander_handle;
3436 struct _sas_node *sas_expander;
3437 unsigned long flags;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303438 int i, reason_code;
3439 u16 handle;
3440
3441 for (i = 0 ; i < event_data->NumEntries; i++) {
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05303442 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
3443 if (!handle)
3444 continue;
3445 reason_code = event_data->PHY[i].PhyStatus &
3446 MPI2_EVENT_SAS_TOPO_RC_MASK;
3447 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
3448 _scsih_tm_tr_send(ioc, handle);
3449 }
Eric Moore635374e2009-03-09 01:21:12 -06003450
3451 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
3452 if (expander_handle < ioc->sas_hba.num_phys) {
3453 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3454 return;
3455 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303456 if (event_data->ExpStatus ==
3457 MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING) {
3458 /* put expander attached devices into blocking state */
Eric Moore635374e2009-03-09 01:21:12 -06003459 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3460 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3461 expander_handle);
Eric Moore635374e2009-03-09 01:21:12 -06003462 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05303463 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3464 do {
3465 handle = find_first_bit(ioc->blocking_handles,
3466 ioc->facts.MaxDevHandle);
3467 if (handle < ioc->facts.MaxDevHandle)
3468 _scsih_block_io_device(ioc, handle);
3469 } while (test_and_clear_bit(handle, ioc->blocking_handles));
Eric Moore635374e2009-03-09 01:21:12 -06003470 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
3471 _scsih_block_io_to_children_attached_directly(ioc, event_data);
3472
3473 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
3474 return;
3475
3476 /* mark ignore flag for pending events */
3477 spin_lock_irqsave(&ioc->fw_event_lock, flags);
3478 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
3479 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
3480 fw_event->ignore)
3481 continue;
3482 local_event_data = fw_event->event_data;
3483 if (local_event_data->ExpStatus ==
3484 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
3485 local_event_data->ExpStatus ==
3486 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
3487 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
3488 expander_handle) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303489 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06003490 "setting ignoring flag\n", ioc->name));
3491 fw_event->ignore = 1;
3492 }
3493 }
3494 }
3495 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
3496}
3497
3498/**
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303499 * _scsih_set_volume_delete_flag - setting volume delete flag
3500 * @ioc: per adapter object
3501 * @handle: device handle
3502 *
3503 * This
3504 * Return nothing.
3505 */
3506static void
3507_scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3508{
3509 struct _raid_device *raid_device;
3510 struct MPT2SAS_TARGET *sas_target_priv_data;
3511 unsigned long flags;
3512
3513 spin_lock_irqsave(&ioc->raid_device_lock, flags);
3514 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
3515 if (raid_device && raid_device->starget &&
3516 raid_device->starget->hostdata) {
3517 sas_target_priv_data =
3518 raid_device->starget->hostdata;
3519 sas_target_priv_data->deleted = 1;
3520 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3521 "setting delete flag: handle(0x%04x), "
3522 "wwid(0x%016llx)\n", ioc->name, handle,
3523 (unsigned long long) raid_device->wwid));
3524 }
3525 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
3526}
3527
3528/**
3529 * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
3530 * @handle: input handle
3531 * @a: handle for volume a
3532 * @b: handle for volume b
3533 *
3534 * IR firmware only supports two raid volumes. The purpose of this
3535 * routine is to set the volume handle in either a or b. When the given
3536 * input handle is non-zero, or when a and b have not been set before.
3537 */
3538static void
3539_scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
3540{
3541 if (!handle || handle == *a || handle == *b)
3542 return;
3543 if (!*a)
3544 *a = handle;
3545 else if (!*b)
3546 *b = handle;
3547}
3548
3549/**
3550 * _scsih_check_ir_config_unhide_events - check for UNHIDE events
3551 * @ioc: per adapter object
3552 * @event_data: the event data payload
3553 * Context: interrupt time.
3554 *
3555 * This routine will send target reset to volume, followed by target
3556 * resets to the PDs. This is called when a PD has been removed, or
3557 * volume has been deleted or removed. When the target reset is sent
3558 * to volume, the PD target resets need to be queued to start upon
3559 * completion of the volume target reset.
3560 *
3561 * Return nothing.
3562 */
3563static void
3564_scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
3565 Mpi2EventDataIrConfigChangeList_t *event_data)
3566{
3567 Mpi2EventIrConfigElement_t *element;
3568 int i;
3569 u16 handle, volume_handle, a, b;
3570 struct _tr_list *delayed_tr;
3571
3572 a = 0;
3573 b = 0;
3574
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303575 if (ioc->is_warpdrive)
3576 return;
3577
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05303578 /* Volume Resets for Deleted or Removed */
3579 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3580 for (i = 0; i < event_data->NumElements; i++, element++) {
3581 if (element->ReasonCode ==
3582 MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
3583 element->ReasonCode ==
3584 MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
3585 volume_handle = le16_to_cpu(element->VolDevHandle);
3586 _scsih_set_volume_delete_flag(ioc, volume_handle);
3587 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3588 }
3589 }
3590
3591 /* Volume Resets for UNHIDE events */
3592 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3593 for (i = 0; i < event_data->NumElements; i++, element++) {
3594 if (le32_to_cpu(event_data->Flags) &
3595 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
3596 continue;
3597 if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
3598 volume_handle = le16_to_cpu(element->VolDevHandle);
3599 _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
3600 }
3601 }
3602
3603 if (a)
3604 _scsih_tm_tr_volume_send(ioc, a);
3605 if (b)
3606 _scsih_tm_tr_volume_send(ioc, b);
3607
3608 /* PD target resets */
3609 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
3610 for (i = 0; i < event_data->NumElements; i++, element++) {
3611 if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
3612 continue;
3613 handle = le16_to_cpu(element->PhysDiskDevHandle);
3614 volume_handle = le16_to_cpu(element->VolDevHandle);
3615 clear_bit(handle, ioc->pd_handles);
3616 if (!volume_handle)
3617 _scsih_tm_tr_send(ioc, handle);
3618 else if (volume_handle == a || volume_handle == b) {
3619 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
3620 BUG_ON(!delayed_tr);
3621 INIT_LIST_HEAD(&delayed_tr->list);
3622 delayed_tr->handle = handle;
3623 list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
3624 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3625 "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
3626 handle));
3627 } else
3628 _scsih_tm_tr_send(ioc, handle);
3629 }
3630}
3631
3632
3633/**
3634 * _scsih_check_volume_delete_events - set delete flag for volumes
3635 * @ioc: per adapter object
3636 * @event_data: the event data payload
3637 * Context: interrupt time.
3638 *
3639 * This will handle the case when the cable connected to entire volume is
3640 * pulled. We will take care of setting the deleted flag so normal IO will
3641 * not be sent.
3642 *
3643 * Return nothing.
3644 */
3645static void
3646_scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
3647 Mpi2EventDataIrVolume_t *event_data)
3648{
3649 u32 state;
3650
3651 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
3652 return;
3653 state = le32_to_cpu(event_data->NewValue);
3654 if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
3655 MPI2_RAID_VOL_STATE_FAILED)
3656 _scsih_set_volume_delete_flag(ioc,
3657 le16_to_cpu(event_data->VolDevHandle));
3658}
3659
3660/**
Eric Moore635374e2009-03-09 01:21:12 -06003661 * _scsih_flush_running_cmds - completing outstanding commands.
3662 * @ioc: per adapter object
3663 *
3664 * The flushing out of all pending scmd commands following host reset,
3665 * where all IO is dropped to the floor.
3666 *
3667 * Return nothing.
3668 */
3669static void
3670_scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
3671{
3672 struct scsi_cmnd *scmd;
3673 u16 smid;
3674 u16 count = 0;
3675
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303676 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05303677 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003678 if (!scmd)
3679 continue;
3680 count++;
3681 mpt2sas_base_free_smid(ioc, smid);
3682 scsi_dma_unmap(scmd);
Eric Moore3cb54692010-07-08 14:44:34 -06003683 if (ioc->pci_error_recovery)
3684 scmd->result = DID_NO_CONNECT << 16;
3685 else
3686 scmd->result = DID_RESET << 16;
Eric Moore635374e2009-03-09 01:21:12 -06003687 scmd->scsi_done(scmd);
3688 }
3689 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
3690 ioc->name, count));
3691}
3692
3693/**
Eric Moore3c621b32009-05-18 12:59:41 -06003694 * _scsih_setup_eedp - setup MPI request for EEDP transfer
3695 * @scmd: pointer to scsi command object
3696 * @mpi_request: pointer to the SCSI_IO reqest message frame
3697 *
3698 * Supporting protection 1 and 3.
3699 *
3700 * Returns nothing
3701 */
3702static void
3703_scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
3704{
3705 u16 eedp_flags;
3706 unsigned char prot_op = scsi_get_prot_op(scmd);
3707 unsigned char prot_type = scsi_get_prot_type(scmd);
3708
Eric Moored334aa72010-04-22 10:47:40 -06003709 if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
Eric Moore3c621b32009-05-18 12:59:41 -06003710 return;
3711
3712 if (prot_op == SCSI_PROT_READ_STRIP)
3713 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
3714 else if (prot_op == SCSI_PROT_WRITE_INSERT)
3715 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
3716 else
3717 return;
3718
Eric Moore3c621b32009-05-18 12:59:41 -06003719 switch (prot_type) {
3720 case SCSI_PROT_DIF_TYPE1:
Martin K. Petersen756aca72011-05-18 00:45:22 -04003721 case SCSI_PROT_DIF_TYPE2:
Eric Moore3c621b32009-05-18 12:59:41 -06003722
3723 /*
3724 * enable ref/guard checking
3725 * auto increment ref tag
3726 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303727 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
Eric Moore3c621b32009-05-18 12:59:41 -06003728 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
3729 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
3730 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
3731 cpu_to_be32(scsi_get_lba(scmd));
Eric Moored334aa72010-04-22 10:47:40 -06003732 break;
Eric Moore3c621b32009-05-18 12:59:41 -06003733
Eric Moore3c621b32009-05-18 12:59:41 -06003734 case SCSI_PROT_DIF_TYPE3:
3735
3736 /*
3737 * enable guard checking
3738 */
Kashyap, Desai463217b2009-10-05 15:53:06 +05303739 eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
Eric Moore3c621b32009-05-18 12:59:41 -06003740 break;
3741 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05303742 mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
3743 mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
Eric Moore3c621b32009-05-18 12:59:41 -06003744}
3745
3746/**
3747 * _scsih_eedp_error_handling - return sense code for EEDP errors
3748 * @scmd: pointer to scsi command object
3749 * @ioc_status: ioc status
3750 *
3751 * Returns nothing
3752 */
3753static void
3754_scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
3755{
3756 u8 ascq;
3757 u8 sk;
3758 u8 host_byte;
3759
3760 switch (ioc_status) {
3761 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3762 ascq = 0x01;
3763 break;
3764 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3765 ascq = 0x02;
3766 break;
3767 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3768 ascq = 0x03;
3769 break;
3770 default:
3771 ascq = 0x00;
3772 break;
3773 }
3774
3775 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
3776 sk = ILLEGAL_REQUEST;
3777 host_byte = DID_ABORT;
3778 } else {
3779 sk = ABORTED_COMMAND;
3780 host_byte = DID_OK;
3781 }
3782
3783 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
3784 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
3785 SAM_STAT_CHECK_CONDITION;
3786}
3787
3788/**
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303789 * _scsih_scsi_direct_io_get - returns direct io flag
3790 * @ioc: per adapter object
3791 * @smid: system request message index
3792 *
3793 * Returns the smid stored scmd pointer.
3794 */
3795static inline u8
3796_scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
3797{
3798 return ioc->scsi_lookup[smid - 1].direct_io;
3799}
3800
3801/**
3802 * _scsih_scsi_direct_io_set - sets direct io flag
3803 * @ioc: per adapter object
3804 * @smid: system request message index
3805 * @direct_io: Zero or non-zero value to set in the direct_io flag
3806 *
3807 * Returns Nothing.
3808 */
3809static inline void
3810_scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
3811{
3812 ioc->scsi_lookup[smid - 1].direct_io = direct_io;
3813}
3814
3815
3816/**
3817 * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
3818 * @ioc: per adapter object
3819 * @scmd: pointer to scsi command object
3820 * @raid_device: pointer to raid device data structure
3821 * @mpi_request: pointer to the SCSI_IO reqest message frame
3822 * @smid: system request message index
3823 *
3824 * Returns nothing
3825 */
3826static void
3827_scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
3828 struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
3829 u16 smid)
3830{
3831 u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
3832 u32 stripe_sz, stripe_exp;
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303833 u8 num_pds, *cdb_ptr, i;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303834 u8 cdb0 = scmd->cmnd[0];
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303835 u64 v_llba;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303836
3837 /*
3838 * Try Direct I/O to RAID memeber disks
3839 */
3840 if (cdb0 == READ_16 || cdb0 == READ_10 ||
3841 cdb0 == WRITE_16 || cdb0 == WRITE_10) {
3842 cdb_ptr = mpi_request->CDB.CDB32;
3843
3844 if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
3845 | cdb_ptr[5])) {
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303846 io_size = scsi_bufflen(scmd) >>
3847 raid_device->block_exponent;
3848 i = (cdb0 < READ_16) ? 2 : 6;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303849 /* get virtual lba */
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303850 v_lba = be32_to_cpu(*(__be32 *)(&cdb_ptr[i]));
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303851
3852 if (((u64)v_lba + (u64)io_size - 1) <=
3853 (u32)raid_device->max_lba) {
3854 stripe_sz = raid_device->stripe_sz;
3855 stripe_exp = raid_device->stripe_exponent;
3856 stripe_off = v_lba & (stripe_sz - 1);
3857
3858 /* Check whether IO falls within a stripe */
3859 if ((stripe_off + io_size) <= stripe_sz) {
3860 num_pds = raid_device->num_pds;
3861 p_lba = v_lba >> stripe_exp;
3862 stripe_unit = p_lba / num_pds;
3863 column = p_lba % num_pds;
3864 p_lba = (stripe_unit << stripe_exp) +
3865 stripe_off;
3866 mpi_request->DevHandle =
3867 cpu_to_le16(raid_device->
3868 pd_handle[column]);
nagalakshmi.nandigama@lsi.comba96bd02011-12-01 07:51:55 +05303869 (*(__be32 *)(&cdb_ptr[i])) =
3870 cpu_to_be32(p_lba);
3871 /*
3872 * WD: To indicate this I/O is directI/O
3873 */
3874 _scsih_scsi_direct_io_set(ioc, smid, 1);
3875 }
3876 }
3877 } else {
3878 io_size = scsi_bufflen(scmd) >>
3879 raid_device->block_exponent;
3880 /* get virtual lba */
3881 v_llba = be64_to_cpu(*(__be64 *)(&cdb_ptr[2]));
3882
3883 if ((v_llba + (u64)io_size - 1) <=
3884 raid_device->max_lba) {
3885 stripe_sz = raid_device->stripe_sz;
3886 stripe_exp = raid_device->stripe_exponent;
3887 stripe_off = (u32) (v_llba & (stripe_sz - 1));
3888
3889 /* Check whether IO falls within a stripe */
3890 if ((stripe_off + io_size) <= stripe_sz) {
3891 num_pds = raid_device->num_pds;
3892 p_lba = (u32)(v_llba >> stripe_exp);
3893 stripe_unit = p_lba / num_pds;
3894 column = p_lba % num_pds;
3895 p_lba = (stripe_unit << stripe_exp) +
3896 stripe_off;
3897 mpi_request->DevHandle =
3898 cpu_to_le16(raid_device->
3899 pd_handle[column]);
3900 (*(__be64 *)(&cdb_ptr[2])) =
3901 cpu_to_be64((u64)p_lba);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303902 /*
3903 * WD: To indicate this I/O is directI/O
3904 */
3905 _scsih_scsi_direct_io_set(ioc, smid, 1);
3906 }
3907 }
3908 }
3909 }
3910}
3911
3912/**
Eric Moored5d135b2009-05-18 13:02:08 -06003913 * _scsih_qcmd - main scsi request entry point
Eric Moore635374e2009-03-09 01:21:12 -06003914 * @scmd: pointer to scsi command object
3915 * @done: function pointer to be invoked on completion
3916 *
3917 * The callback index is set inside `ioc->scsi_io_cb_idx`.
3918 *
3919 * Returns 0 on success. If there's a failure, return either:
3920 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
3921 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
3922 */
3923static int
Jeff Garzikf2812332010-11-16 02:10:29 -05003924_scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
Eric Moore635374e2009-03-09 01:21:12 -06003925{
3926 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
3927 struct MPT2SAS_DEVICE *sas_device_priv_data;
3928 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303929 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06003930 Mpi2SCSIIORequest_t *mpi_request;
3931 u32 mpi_control;
3932 u16 smid;
Eric Moore635374e2009-03-09 01:21:12 -06003933
3934 scmd->scsi_done = done;
3935 sas_device_priv_data = scmd->device->hostdata;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303936 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
Eric Moore635374e2009-03-09 01:21:12 -06003937 scmd->result = DID_NO_CONNECT << 16;
3938 scmd->scsi_done(scmd);
3939 return 0;
3940 }
3941
Kashyap, Desai78215782011-06-14 10:57:08 +05303942 if (ioc->pci_error_recovery || ioc->remove_host) {
Eric Moore3cb54692010-07-08 14:44:34 -06003943 scmd->result = DID_NO_CONNECT << 16;
3944 scmd->scsi_done(scmd);
3945 return 0;
3946 }
3947
Eric Moore635374e2009-03-09 01:21:12 -06003948 sas_target_priv_data = sas_device_priv_data->sas_target;
Kashyap, Desai130b9582010-04-08 17:54:32 +05303949 /* invalid device handle */
3950 if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
Eric Moore635374e2009-03-09 01:21:12 -06003951 scmd->result = DID_NO_CONNECT << 16;
3952 scmd->scsi_done(scmd);
3953 return 0;
3954 }
3955
Kashyap, Desai130b9582010-04-08 17:54:32 +05303956 /* host recovery or link resets sent via IOCTLs */
3957 if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
Eric Moore635374e2009-03-09 01:21:12 -06003958 return SCSI_MLQUEUE_HOST_BUSY;
Uwe Kleine-König65155b32010-06-11 12:17:01 +02003959 /* device busy with task management */
Kashyap, Desai130b9582010-04-08 17:54:32 +05303960 else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
3961 return SCSI_MLQUEUE_DEVICE_BUSY;
3962 /* device has been deleted */
3963 else if (sas_target_priv_data->deleted) {
3964 scmd->result = DID_NO_CONNECT << 16;
3965 scmd->scsi_done(scmd);
3966 return 0;
3967 }
Eric Moore635374e2009-03-09 01:21:12 -06003968
3969 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
3970 mpi_control = MPI2_SCSIIO_CONTROL_READ;
3971 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
3972 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
3973 else
3974 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3975
3976 /* set tags */
3977 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
3978 if (scmd->device->tagged_supported) {
3979 if (scmd->device->ordered_tags)
3980 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3981 else
3982 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3983 } else
3984/* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
3985/* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
3986 */
3987 mpi_control |= (0x500);
3988
3989 } else
3990 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05303991 /* Make sure Device is not raid volume.
3992 * We do not expose raid functionality to upper layer for warpdrive.
3993 */
3994 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Eric Moored334aa72010-04-22 10:47:40 -06003995 sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
Eric Moore635374e2009-03-09 01:21:12 -06003996 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
3997
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05303998 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
Eric Moore635374e2009-03-09 01:21:12 -06003999 if (!smid) {
4000 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
4001 ioc->name, __func__);
4002 goto out;
4003 }
4004 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4005 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
Eric Moore3c621b32009-05-18 12:59:41 -06004006 _scsih_setup_eedp(scmd, mpi_request);
Eric Moored334aa72010-04-22 10:47:40 -06004007 if (scmd->cmd_len == 32)
4008 mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
Eric Moore635374e2009-03-09 01:21:12 -06004009 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4010 if (sas_device_priv_data->sas_target->flags &
4011 MPT_TARGET_FLAGS_RAID_COMPONENT)
4012 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4013 else
4014 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
4015 mpi_request->DevHandle =
4016 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4017 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
4018 mpi_request->Control = cpu_to_le32(mpi_control);
4019 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
4020 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
4021 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
4022 mpi_request->SenseBufferLowAddress =
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05304023 mpt2sas_base_get_sense_buffer_dma(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004024 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
4025 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
4026 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304027 mpi_request->VF_ID = 0; /* TODO */
4028 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004029 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
4030 mpi_request->LUN);
4031 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4032
4033 if (!mpi_request->DataLength) {
4034 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
4035 } else {
4036 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
4037 mpt2sas_base_free_smid(ioc, smid);
4038 goto out;
4039 }
4040 }
4041
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304042 raid_device = sas_target_priv_data->raid_device;
4043 if (raid_device && raid_device->direct_io_enabled)
4044 _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
4045 smid);
4046
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304047 if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
4048 mpt2sas_base_put_smid_scsi_io(ioc, smid,
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304049 le16_to_cpu(mpi_request->DevHandle));
Kashyap, Desai58287fd2010-03-17 16:27:25 +05304050 else
4051 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004052 return 0;
4053
4054 out:
4055 return SCSI_MLQUEUE_HOST_BUSY;
4056}
4057
Jeff Garzikf2812332010-11-16 02:10:29 -05004058static DEF_SCSI_QCMD(_scsih_qcmd)
4059
Eric Moore635374e2009-03-09 01:21:12 -06004060/**
4061 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
4062 * @sense_buffer: sense data returned by target
4063 * @data: normalized skey/asc/ascq
4064 *
4065 * Return nothing.
4066 */
4067static void
4068_scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
4069{
4070 if ((sense_buffer[0] & 0x7F) >= 0x72) {
4071 /* descriptor format */
4072 data->skey = sense_buffer[1] & 0x0F;
4073 data->asc = sense_buffer[2];
4074 data->ascq = sense_buffer[3];
4075 } else {
4076 /* fixed format */
4077 data->skey = sense_buffer[2] & 0x0F;
4078 data->asc = sense_buffer[12];
4079 data->ascq = sense_buffer[13];
4080 }
4081}
4082
4083#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4084/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004085 * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
Eric Moore635374e2009-03-09 01:21:12 -06004086 * @ioc: per adapter object
4087 * @scmd: pointer to scsi command object
4088 * @mpi_reply: reply mf payload returned from firmware
4089 *
4090 * scsi_status - SCSI Status code returned from target device
4091 * scsi_state - state info associated with SCSI_IO determined by ioc
4092 * ioc_status - ioc supplied status info
4093 *
4094 * Return nothing.
4095 */
4096static void
4097_scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
4098 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
4099{
4100 u32 response_info;
4101 u8 *response_bytes;
4102 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
4103 MPI2_IOCSTATUS_MASK;
4104 u8 scsi_state = mpi_reply->SCSIState;
4105 u8 scsi_status = mpi_reply->SCSIStatus;
4106 char *desc_ioc_state = NULL;
4107 char *desc_scsi_status = NULL;
4108 char *desc_scsi_state = ioc->tmp_string;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304109 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304110 struct _sas_device *sas_device = NULL;
4111 unsigned long flags;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304112 struct scsi_target *starget = scmd->device->sdev_target;
4113 struct MPT2SAS_TARGET *priv_target = starget->hostdata;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304114 char *device_str = NULL;
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304115
4116 if (!priv_target)
4117 return;
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304118
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304119 if (ioc->hide_ir_msg)
4120 device_str = "WarpDrive";
4121 else
4122 device_str = "volume";
4123
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +05304124 if (log_info == 0x31170000)
4125 return;
Eric Moore635374e2009-03-09 01:21:12 -06004126
4127 switch (ioc_status) {
4128 case MPI2_IOCSTATUS_SUCCESS:
4129 desc_ioc_state = "success";
4130 break;
4131 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4132 desc_ioc_state = "invalid function";
4133 break;
4134 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4135 desc_ioc_state = "scsi recovered error";
4136 break;
4137 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
4138 desc_ioc_state = "scsi invalid dev handle";
4139 break;
4140 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4141 desc_ioc_state = "scsi device not there";
4142 break;
4143 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4144 desc_ioc_state = "scsi data overrun";
4145 break;
4146 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4147 desc_ioc_state = "scsi data underrun";
4148 break;
4149 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4150 desc_ioc_state = "scsi io data error";
4151 break;
4152 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4153 desc_ioc_state = "scsi protocol error";
4154 break;
4155 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4156 desc_ioc_state = "scsi task terminated";
4157 break;
4158 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4159 desc_ioc_state = "scsi residual mismatch";
4160 break;
4161 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4162 desc_ioc_state = "scsi task mgmt failed";
4163 break;
4164 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4165 desc_ioc_state = "scsi ioc terminated";
4166 break;
4167 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4168 desc_ioc_state = "scsi ext terminated";
4169 break;
Eric Moore3c621b32009-05-18 12:59:41 -06004170 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4171 desc_ioc_state = "eedp guard error";
4172 break;
4173 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4174 desc_ioc_state = "eedp ref tag error";
4175 break;
4176 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4177 desc_ioc_state = "eedp app tag error";
4178 break;
Eric Moore635374e2009-03-09 01:21:12 -06004179 default:
4180 desc_ioc_state = "unknown";
4181 break;
4182 }
4183
4184 switch (scsi_status) {
4185 case MPI2_SCSI_STATUS_GOOD:
4186 desc_scsi_status = "good";
4187 break;
4188 case MPI2_SCSI_STATUS_CHECK_CONDITION:
4189 desc_scsi_status = "check condition";
4190 break;
4191 case MPI2_SCSI_STATUS_CONDITION_MET:
4192 desc_scsi_status = "condition met";
4193 break;
4194 case MPI2_SCSI_STATUS_BUSY:
4195 desc_scsi_status = "busy";
4196 break;
4197 case MPI2_SCSI_STATUS_INTERMEDIATE:
4198 desc_scsi_status = "intermediate";
4199 break;
4200 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
4201 desc_scsi_status = "intermediate condmet";
4202 break;
4203 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
4204 desc_scsi_status = "reservation conflict";
4205 break;
4206 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
4207 desc_scsi_status = "command terminated";
4208 break;
4209 case MPI2_SCSI_STATUS_TASK_SET_FULL:
4210 desc_scsi_status = "task set full";
4211 break;
4212 case MPI2_SCSI_STATUS_ACA_ACTIVE:
4213 desc_scsi_status = "aca active";
4214 break;
4215 case MPI2_SCSI_STATUS_TASK_ABORTED:
4216 desc_scsi_status = "task aborted";
4217 break;
4218 default:
4219 desc_scsi_status = "unknown";
4220 break;
4221 }
4222
4223 desc_scsi_state[0] = '\0';
4224 if (!scsi_state)
4225 desc_scsi_state = " ";
4226 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4227 strcat(desc_scsi_state, "response info ");
4228 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4229 strcat(desc_scsi_state, "state terminated ");
4230 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
4231 strcat(desc_scsi_state, "no status ");
4232 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
4233 strcat(desc_scsi_state, "autosense failed ");
4234 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
4235 strcat(desc_scsi_state, "autosense valid ");
4236
4237 scsi_print_command(scmd);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304238
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304239 if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304240 printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
4241 device_str, (unsigned long long)priv_target->sas_address);
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304242 } else {
4243 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4244 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
4245 priv_target->sas_address);
4246 if (sas_device) {
4247 printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
4248 "phy(%d)\n", ioc->name, sas_device->sas_address,
4249 sas_device->phy);
4250 printk(MPT2SAS_WARN_FMT
4251 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
4252 ioc->name, sas_device->enclosure_logical_id,
4253 sas_device->slot);
4254 }
4255 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304256 }
Kashyap, Desai7fbae672010-06-17 13:45:17 +05304257
Kashyap, Desai8e864a82010-06-17 13:48:46 +05304258 printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
4259 "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
4260 desc_ioc_state, ioc_status, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004261 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
4262 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
4263 scsi_get_resid(scmd));
4264 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
4265 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
4266 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
4267 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
4268 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
4269 scsi_status, desc_scsi_state, scsi_state);
4270
4271 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4272 struct sense_info data;
4273 _scsih_normalize_sense(scmd->sense_buffer, &data);
4274 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304275 "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
4276 data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
Eric Moore635374e2009-03-09 01:21:12 -06004277 }
4278
4279 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
4280 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
4281 response_bytes = (u8 *)&response_info;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304282 _scsih_response_code(ioc, response_bytes[0]);
Eric Moore635374e2009-03-09 01:21:12 -06004283 }
4284}
4285#endif
4286
4287/**
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304288 * _scsih_turn_on_fault_led - illuminate Fault LED
Eric Moore635374e2009-03-09 01:21:12 -06004289 * @ioc: per adapter object
4290 * @handle: device handle
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304291 * Context: process
4292 *
4293 * Return nothing.
4294 */
4295static void
4296_scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4297{
4298 Mpi2SepReply_t mpi_reply;
4299 Mpi2SepRequest_t mpi_request;
4300
4301 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
4302 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
4303 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
4304 mpi_request.SlotStatus =
4305 cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
4306 mpi_request.DevHandle = cpu_to_le16(handle);
4307 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
4308 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
4309 &mpi_request)) != 0) {
4310 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
4311 __FILE__, __LINE__, __func__);
4312 return;
4313 }
4314
4315 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
4316 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
4317 "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
4318 le16_to_cpu(mpi_reply.IOCStatus),
4319 le32_to_cpu(mpi_reply.IOCLogInfo)));
4320 return;
4321 }
4322}
4323
4324/**
4325 * _scsih_send_event_to_turn_on_fault_led - fire delayed event
4326 * @ioc: per adapter object
4327 * @handle: device handle
4328 * Context: interrupt.
4329 *
4330 * Return nothing.
4331 */
4332static void
4333_scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4334{
4335 struct fw_event_work *fw_event;
4336
4337 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
4338 if (!fw_event)
4339 return;
4340 fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
4341 fw_event->device_handle = handle;
4342 fw_event->ioc = ioc;
4343 _scsih_fw_event_add(ioc, fw_event);
4344}
4345
4346/**
4347 * _scsih_smart_predicted_fault - process smart errors
4348 * @ioc: per adapter object
4349 * @handle: device handle
4350 * Context: interrupt.
Eric Moore635374e2009-03-09 01:21:12 -06004351 *
4352 * Return nothing.
4353 */
4354static void
4355_scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4356{
Eric Moore635374e2009-03-09 01:21:12 -06004357 struct scsi_target *starget;
4358 struct MPT2SAS_TARGET *sas_target_priv_data;
4359 Mpi2EventNotificationReply_t *event_reply;
4360 Mpi2EventDataSasDeviceStatusChange_t *event_data;
4361 struct _sas_device *sas_device;
4362 ssize_t sz;
4363 unsigned long flags;
4364
4365 /* only handle non-raid devices */
4366 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4367 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4368 if (!sas_device) {
4369 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4370 return;
4371 }
4372 starget = sas_device->starget;
4373 sas_target_priv_data = starget->hostdata;
4374
4375 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
4376 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
4377 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4378 return;
4379 }
4380 starget_printk(KERN_WARNING, starget, "predicted fault\n");
4381 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4382
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05304383 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
4384 _scsih_send_event_to_turn_on_fault_led(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06004385
4386 /* insert into event log */
4387 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
4388 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
Anton Blanchardf6a290b42011-11-07 22:05:21 +11004389 event_reply = kzalloc(sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06004390 if (!event_reply) {
4391 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4392 ioc->name, __FILE__, __LINE__, __func__);
4393 return;
4394 }
4395
4396 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
4397 event_reply->Event =
4398 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4399 event_reply->MsgLength = sz/4;
4400 event_reply->EventDataLength =
4401 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
4402 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
4403 event_reply->EventData;
4404 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
4405 event_data->ASC = 0x5D;
4406 event_data->DevHandle = cpu_to_le16(handle);
4407 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
4408 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
4409 kfree(event_reply);
4410}
4411
4412/**
Eric Moored5d135b2009-05-18 13:02:08 -06004413 * _scsih_io_done - scsi request callback
Eric Moore635374e2009-03-09 01:21:12 -06004414 * @ioc: per adapter object
4415 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304416 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06004417 * @reply: reply message frame(lower 32bit addr)
4418 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304419 * Callback handler when using _scsih_qcmd.
Eric Moore635374e2009-03-09 01:21:12 -06004420 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304421 * Return 1 meaning mf should be freed from _base_interrupt
4422 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06004423 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304424static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304425_scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06004426{
4427 Mpi2SCSIIORequest_t *mpi_request;
4428 Mpi2SCSIIOReply_t *mpi_reply;
4429 struct scsi_cmnd *scmd;
4430 u16 ioc_status;
4431 u32 xfer_cnt;
4432 u8 scsi_state;
4433 u8 scsi_status;
4434 u32 log_info;
4435 struct MPT2SAS_DEVICE *sas_device_priv_data;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304436 u32 response_code = 0;
Kashyap, Desai82a45252011-07-05 12:40:23 +05304437 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06004438
4439 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05304440 scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06004441 if (scmd == NULL)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304442 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004443
4444 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
4445
4446 if (mpi_reply == NULL) {
4447 scmd->result = DID_OK << 16;
4448 goto out;
4449 }
4450
4451 sas_device_priv_data = scmd->device->hostdata;
4452 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
4453 sas_device_priv_data->sas_target->deleted) {
4454 scmd->result = DID_NO_CONNECT << 16;
4455 goto out;
4456 }
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304457 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304458 /*
4459 * WARPDRIVE: If direct_io is set then it is directIO,
4460 * the failed direct I/O should be redirected to volume
4461 */
nagalakshmi.nandigama@lsi.com4da7af92011-12-01 07:53:02 +05304462 if (_scsih_scsi_direct_io_get(ioc, smid) &&
4463 ((ioc_status & MPI2_IOCSTATUS_MASK)
4464 != MPI2_IOCSTATUS_SCSI_TASK_TERMINATED)) {
Kashyap, Desai82a45252011-07-05 12:40:23 +05304465 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4466 ioc->scsi_lookup[smid - 1].scmd = scmd;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304467 _scsih_scsi_direct_io_set(ioc, smid, 0);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05304468 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304469 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
4470 mpi_request->DevHandle =
4471 cpu_to_le16(sas_device_priv_data->sas_target->handle);
4472 mpt2sas_base_put_smid_scsi_io(ioc, smid,
4473 sas_device_priv_data->sas_target->handle);
4474 return 0;
4475 }
4476
Eric Moore635374e2009-03-09 01:21:12 -06004477
4478 /* turning off TLR */
Kashyap, Desai9982f592009-09-23 17:23:07 +05304479 scsi_state = mpi_reply->SCSIState;
4480 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
4481 response_code =
4482 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
Eric Moore635374e2009-03-09 01:21:12 -06004483 if (!sas_device_priv_data->tlr_snoop_check) {
4484 sas_device_priv_data->tlr_snoop_check++;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304485 /* Make sure Device is not raid volume.
4486 * We do not expose raid functionality to upper layer for warpdrive.
4487 */
4488 if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
Kashyap, Desai3ed21522010-02-17 16:08:36 +05304489 sas_is_tlr_enabled(scmd->device) &&
Kashyap, Desai84f0b042009-12-16 18:56:28 +05304490 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
4491 sas_disable_tlr(scmd->device);
4492 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
4493 }
Eric Moore635374e2009-03-09 01:21:12 -06004494 }
4495
4496 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
4497 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
Eric Moore635374e2009-03-09 01:21:12 -06004498 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
4499 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
4500 else
4501 log_info = 0;
4502 ioc_status &= MPI2_IOCSTATUS_MASK;
Eric Moore635374e2009-03-09 01:21:12 -06004503 scsi_status = mpi_reply->SCSIStatus;
4504
4505 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
4506 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
4507 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
4508 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
4509 ioc_status = MPI2_IOCSTATUS_SUCCESS;
4510 }
4511
4512 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
4513 struct sense_info data;
4514 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
4515 smid);
Eric Moore0d04df92009-04-21 15:38:43 -06004516 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
Eric Moore635374e2009-03-09 01:21:12 -06004517 le32_to_cpu(mpi_reply->SenseCount));
Eric Moore0d04df92009-04-21 15:38:43 -06004518 memcpy(scmd->sense_buffer, sense_data, sz);
Eric Moore635374e2009-03-09 01:21:12 -06004519 _scsih_normalize_sense(scmd->sense_buffer, &data);
4520 /* failure prediction threshold exceeded */
4521 if (data.asc == 0x5D)
4522 _scsih_smart_predicted_fault(ioc,
4523 le16_to_cpu(mpi_reply->DevHandle));
4524 }
4525
4526 switch (ioc_status) {
4527 case MPI2_IOCSTATUS_BUSY:
4528 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
4529 scmd->result = SAM_STAT_BUSY;
4530 break;
4531
4532 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
4533 scmd->result = DID_NO_CONNECT << 16;
4534 break;
4535
4536 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
4537 if (sas_device_priv_data->block) {
Kashyap, Desaie4e7c7e2009-09-23 17:33:14 +05304538 scmd->result = DID_TRANSPORT_DISRUPTED << 16;
4539 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06004540 }
nagalakshmi.nandigama@lsi.com3ade1ca2011-12-01 07:42:40 +05304541 scmd->result = DID_SOFT_ERROR << 16;
4542 break;
Eric Moore635374e2009-03-09 01:21:12 -06004543 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
4544 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
4545 scmd->result = DID_RESET << 16;
4546 break;
4547
4548 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
4549 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
4550 scmd->result = DID_SOFT_ERROR << 16;
4551 else
4552 scmd->result = (DID_OK << 16) | scsi_status;
4553 break;
4554
4555 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
4556 scmd->result = (DID_OK << 16) | scsi_status;
4557
4558 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
4559 break;
4560
4561 if (xfer_cnt < scmd->underflow) {
4562 if (scsi_status == SAM_STAT_BUSY)
4563 scmd->result = SAM_STAT_BUSY;
4564 else
4565 scmd->result = DID_SOFT_ERROR << 16;
4566 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4567 MPI2_SCSI_STATE_NO_SCSI_STATUS))
4568 scmd->result = DID_SOFT_ERROR << 16;
4569 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4570 scmd->result = DID_RESET << 16;
4571 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
4572 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
4573 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
4574 scmd->result = (DRIVER_SENSE << 24) |
4575 SAM_STAT_CHECK_CONDITION;
4576 scmd->sense_buffer[0] = 0x70;
4577 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
4578 scmd->sense_buffer[12] = 0x20;
4579 scmd->sense_buffer[13] = 0;
4580 }
4581 break;
4582
4583 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
4584 scsi_set_resid(scmd, 0);
4585 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
4586 case MPI2_IOCSTATUS_SUCCESS:
4587 scmd->result = (DID_OK << 16) | scsi_status;
Kashyap, Desai9982f592009-09-23 17:23:07 +05304588 if (response_code ==
4589 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
4590 (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
4591 MPI2_SCSI_STATE_NO_SCSI_STATUS)))
Eric Moore635374e2009-03-09 01:21:12 -06004592 scmd->result = DID_SOFT_ERROR << 16;
4593 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
4594 scmd->result = DID_RESET << 16;
4595 break;
4596
Eric Moore3c621b32009-05-18 12:59:41 -06004597 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
4598 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
4599 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
4600 _scsih_eedp_error_handling(scmd, ioc_status);
4601 break;
Eric Moore635374e2009-03-09 01:21:12 -06004602 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
4603 case MPI2_IOCSTATUS_INVALID_FUNCTION:
4604 case MPI2_IOCSTATUS_INVALID_SGL:
4605 case MPI2_IOCSTATUS_INTERNAL_ERROR:
4606 case MPI2_IOCSTATUS_INVALID_FIELD:
4607 case MPI2_IOCSTATUS_INVALID_STATE:
4608 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
4609 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
4610 default:
4611 scmd->result = DID_SOFT_ERROR << 16;
4612 break;
4613
4614 }
4615
4616#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4617 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
4618 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
4619#endif
4620
4621 out:
4622 scsi_dma_unmap(scmd);
4623 scmd->scsi_done(scmd);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304624 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06004625}
4626
4627/**
Eric Moore635374e2009-03-09 01:21:12 -06004628 * _scsih_sas_host_refresh - refreshing sas host object contents
4629 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06004630 * Context: user
4631 *
4632 * During port enable, fw will send topology events for every device. Its
4633 * possible that the handles may change from the previous setting, so this
4634 * code keeping handles updating if changed.
4635 *
4636 * Return nothing.
4637 */
4638static void
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304639_scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06004640{
4641 u16 sz;
4642 u16 ioc_status;
4643 int i;
4644 Mpi2ConfigReply_t mpi_reply;
4645 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304646 u16 attached_handle;
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304647 u8 link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06004648
4649 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
4650 "updating handles for sas_host(0x%016llx)\n",
4651 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
4652
4653 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
4654 * sizeof(Mpi2SasIOUnit0PhyData_t));
4655 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4656 if (!sas_iounit_pg0) {
4657 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4658 ioc->name, __FILE__, __LINE__, __func__);
4659 return;
4660 }
Eric Moore635374e2009-03-09 01:21:12 -06004661
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304662 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4663 sas_iounit_pg0, sz)) != 0)
4664 goto out;
4665 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
4666 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
4667 goto out;
4668 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304669 link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304670 if (i == 0)
4671 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4672 PhyData[0].ControllerDevHandle);
4673 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
4674 attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
4675 AttachedDevHandle);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304676 if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
4677 link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304678 mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05304679 attached_handle, i, link_rate);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304680 }
Eric Moore635374e2009-03-09 01:21:12 -06004681 out:
4682 kfree(sas_iounit_pg0);
4683}
4684
4685/**
4686 * _scsih_sas_host_add - create sas host object
4687 * @ioc: per adapter object
4688 *
4689 * Creating host side data object, stored in ioc->sas_hba
4690 *
4691 * Return nothing.
4692 */
4693static void
4694_scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
4695{
4696 int i;
4697 Mpi2ConfigReply_t mpi_reply;
4698 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
4699 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
4700 Mpi2SasPhyPage0_t phy_pg0;
4701 Mpi2SasDevicePage0_t sas_device_pg0;
4702 Mpi2SasEnclosurePage0_t enclosure_pg0;
4703 u16 ioc_status;
4704 u16 sz;
4705 u16 device_missing_delay;
4706
4707 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
4708 if (!ioc->sas_hba.num_phys) {
4709 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4710 ioc->name, __FILE__, __LINE__, __func__);
4711 return;
4712 }
4713
4714 /* sas_iounit page 0 */
4715 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
4716 sizeof(Mpi2SasIOUnit0PhyData_t));
4717 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
4718 if (!sas_iounit_pg0) {
4719 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4720 ioc->name, __FILE__, __LINE__, __func__);
4721 return;
4722 }
4723 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
4724 sas_iounit_pg0, sz))) {
4725 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4726 ioc->name, __FILE__, __LINE__, __func__);
4727 goto out;
4728 }
4729 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4730 MPI2_IOCSTATUS_MASK;
4731 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4732 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4733 ioc->name, __FILE__, __LINE__, __func__);
4734 goto out;
4735 }
4736
4737 /* sas_iounit page 1 */
4738 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
4739 sizeof(Mpi2SasIOUnit1PhyData_t));
4740 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
4741 if (!sas_iounit_pg1) {
4742 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4743 ioc->name, __FILE__, __LINE__, __func__);
4744 goto out;
4745 }
4746 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
4747 sas_iounit_pg1, sz))) {
4748 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4749 ioc->name, __FILE__, __LINE__, __func__);
4750 goto out;
4751 }
4752 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4753 MPI2_IOCSTATUS_MASK;
4754 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4755 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4756 ioc->name, __FILE__, __LINE__, __func__);
4757 goto out;
4758 }
4759
4760 ioc->io_missing_delay =
4761 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
4762 device_missing_delay =
4763 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
4764 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
4765 ioc->device_missing_delay = (device_missing_delay &
4766 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
4767 else
4768 ioc->device_missing_delay = device_missing_delay &
4769 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
4770
4771 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
4772 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
4773 sizeof(struct _sas_phy), GFP_KERNEL);
4774 if (!ioc->sas_hba.phy) {
4775 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4776 ioc->name, __FILE__, __LINE__, __func__);
4777 goto out;
4778 }
4779 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
4780 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
4781 i))) {
4782 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4783 ioc->name, __FILE__, __LINE__, __func__);
4784 goto out;
4785 }
4786 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4787 MPI2_IOCSTATUS_MASK;
4788 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4789 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4790 ioc->name, __FILE__, __LINE__, __func__);
4791 goto out;
4792 }
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304793
4794 if (i == 0)
4795 ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
4796 PhyData[0].ControllerDevHandle);
4797 ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
Eric Moore635374e2009-03-09 01:21:12 -06004798 ioc->sas_hba.phy[i].phy_id = i;
4799 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
4800 phy_pg0, ioc->sas_hba.parent_dev);
4801 }
4802 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304803 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
Eric Moore635374e2009-03-09 01:21:12 -06004804 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4805 ioc->name, __FILE__, __LINE__, __func__);
4806 goto out;
4807 }
Eric Moore635374e2009-03-09 01:21:12 -06004808 ioc->sas_hba.enclosure_handle =
4809 le16_to_cpu(sas_device_pg0.EnclosureHandle);
4810 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
4811 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
4812 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
4813 (unsigned long long) ioc->sas_hba.sas_address,
4814 ioc->sas_hba.num_phys) ;
4815
4816 if (ioc->sas_hba.enclosure_handle) {
4817 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4818 &enclosure_pg0,
4819 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4820 ioc->sas_hba.enclosure_handle))) {
4821 ioc->sas_hba.enclosure_logical_id =
4822 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4823 }
4824 }
4825
4826 out:
4827 kfree(sas_iounit_pg1);
4828 kfree(sas_iounit_pg0);
4829}
4830
4831/**
4832 * _scsih_expander_add - creating expander object
4833 * @ioc: per adapter object
4834 * @handle: expander handle
4835 *
4836 * Creating expander object, stored in ioc->sas_expander_list.
4837 *
4838 * Return 0 for success, else error.
4839 */
4840static int
4841_scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
4842{
4843 struct _sas_node *sas_expander;
4844 Mpi2ConfigReply_t mpi_reply;
4845 Mpi2ExpanderPage0_t expander_pg0;
4846 Mpi2ExpanderPage1_t expander_pg1;
4847 Mpi2SasEnclosurePage0_t enclosure_pg0;
4848 u32 ioc_status;
4849 u16 parent_handle;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05304850 u64 sas_address, sas_address_parent = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004851 int i;
4852 unsigned long flags;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304853 struct _sas_port *mpt2sas_port = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06004854 int rc = 0;
4855
4856 if (!handle)
4857 return -1;
4858
Eric Moore3cb54692010-07-08 14:44:34 -06004859 if (ioc->shost_recovery || ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304860 return -1;
4861
Eric Moore635374e2009-03-09 01:21:12 -06004862 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
4863 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
4864 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4865 ioc->name, __FILE__, __LINE__, __func__);
4866 return -1;
4867 }
4868
4869 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4870 MPI2_IOCSTATUS_MASK;
4871 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4872 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4873 ioc->name, __FILE__, __LINE__, __func__);
4874 return -1;
4875 }
4876
4877 /* handle out of order topology events */
4878 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304879 if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
4880 != 0) {
4881 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4882 ioc->name, __FILE__, __LINE__, __func__);
4883 return -1;
4884 }
4885 if (sas_address_parent != ioc->sas_hba.sas_address) {
Eric Moore635374e2009-03-09 01:21:12 -06004886 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304887 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4888 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004889 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4890 if (!sas_expander) {
4891 rc = _scsih_expander_add(ioc, parent_handle);
4892 if (rc != 0)
4893 return rc;
4894 }
4895 }
4896
Eric Moore635374e2009-03-09 01:21:12 -06004897 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304898 sas_address = le64_to_cpu(expander_pg0.SASAddress);
Eric Moore635374e2009-03-09 01:21:12 -06004899 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
4900 sas_address);
4901 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
4902
4903 if (sas_expander)
4904 return 0;
4905
4906 sas_expander = kzalloc(sizeof(struct _sas_node),
4907 GFP_KERNEL);
4908 if (!sas_expander) {
4909 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4910 ioc->name, __FILE__, __LINE__, __func__);
4911 return -1;
4912 }
4913
4914 sas_expander->handle = handle;
4915 sas_expander->num_phys = expander_pg0.NumPhys;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304916 sas_expander->sas_address_parent = sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06004917 sas_expander->sas_address = sas_address;
4918
4919 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
4920 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304921 handle, parent_handle, (unsigned long long)
Eric Moore635374e2009-03-09 01:21:12 -06004922 sas_expander->sas_address, sas_expander->num_phys);
4923
4924 if (!sas_expander->num_phys)
4925 goto out_fail;
4926 sas_expander->phy = kcalloc(sas_expander->num_phys,
4927 sizeof(struct _sas_phy), GFP_KERNEL);
4928 if (!sas_expander->phy) {
4929 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4930 ioc->name, __FILE__, __LINE__, __func__);
4931 rc = -1;
4932 goto out_fail;
4933 }
4934
4935 INIT_LIST_HEAD(&sas_expander->sas_port_list);
4936 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304937 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004938 if (!mpt2sas_port) {
4939 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4940 ioc->name, __FILE__, __LINE__, __func__);
4941 rc = -1;
4942 goto out_fail;
4943 }
4944 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
4945
4946 for (i = 0 ; i < sas_expander->num_phys ; i++) {
4947 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
4948 &expander_pg1, i, handle))) {
4949 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4950 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai20f58952009-08-07 19:34:26 +05304951 rc = -1;
4952 goto out_fail;
Eric Moore635374e2009-03-09 01:21:12 -06004953 }
4954 sas_expander->phy[i].handle = handle;
4955 sas_expander->phy[i].phy_id = i;
Kashyap, Desai20f58952009-08-07 19:34:26 +05304956
4957 if ((mpt2sas_transport_add_expander_phy(ioc,
4958 &sas_expander->phy[i], expander_pg1,
4959 sas_expander->parent_dev))) {
4960 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4961 ioc->name, __FILE__, __LINE__, __func__);
4962 rc = -1;
4963 goto out_fail;
4964 }
Eric Moore635374e2009-03-09 01:21:12 -06004965 }
4966
4967 if (sas_expander->enclosure_handle) {
4968 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
4969 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
4970 sas_expander->enclosure_handle))) {
4971 sas_expander->enclosure_logical_id =
4972 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
4973 }
4974 }
4975
4976 _scsih_expander_node_add(ioc, sas_expander);
4977 return 0;
4978
4979 out_fail:
4980
Kashyap, Desai20f58952009-08-07 19:34:26 +05304981 if (mpt2sas_port)
4982 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05304983 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06004984 kfree(sas_expander);
4985 return rc;
4986}
4987
4988/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05304989 * _scsih_done - scsih callback handler.
4990 * @ioc: per adapter object
4991 * @smid: system request message index
4992 * @msix_index: MSIX table index supplied by the OS
4993 * @reply: reply message frame(lower 32bit addr)
4994 *
4995 * Callback handler when sending internal generated message frames.
4996 * The callback index passed is `ioc->scsih_cb_idx`
4997 *
4998 * Return 1 meaning mf should be freed from _base_interrupt
4999 * 0 means the mf is freed from this function.
5000 */
5001static u8
5002_scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
5003{
5004 MPI2DefaultReply_t *mpi_reply;
5005
5006 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5007 if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
5008 return 1;
5009 if (ioc->scsih_cmds.smid != smid)
5010 return 1;
5011 ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
5012 if (mpi_reply) {
5013 memcpy(ioc->scsih_cmds.reply, mpi_reply,
5014 mpi_reply->MsgLength*4);
5015 ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
5016 }
5017 ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
5018 complete(&ioc->scsih_cmds.done);
5019 return 1;
5020}
5021
5022/**
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305023 * mpt2sas_expander_remove - removing expander object
Eric Moore635374e2009-03-09 01:21:12 -06005024 * @ioc: per adapter object
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305025 * @sas_address: expander sas_address
Eric Moore635374e2009-03-09 01:21:12 -06005026 *
5027 * Return nothing.
5028 */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305029void
5030mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
Eric Moore635374e2009-03-09 01:21:12 -06005031{
5032 struct _sas_node *sas_expander;
5033 unsigned long flags;
5034
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305035 if (ioc->shost_recovery)
5036 return;
5037
Eric Moore635374e2009-03-09 01:21:12 -06005038 spin_lock_irqsave(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305039 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
5040 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305041 if (sas_expander)
5042 list_del(&sas_expander->list);
Eric Moore635374e2009-03-09 01:21:12 -06005043 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305044 if (sas_expander)
5045 _scsih_expander_node_remove(ioc, sas_expander);
Eric Moore635374e2009-03-09 01:21:12 -06005046}
5047
5048/**
Kashyap, Desaib4344272010-03-17 16:24:14 +05305049 * _scsih_check_access_status - check access flags
5050 * @ioc: per adapter object
5051 * @sas_address: sas address
5052 * @handle: sas device handle
5053 * @access_flags: errors returned during discovery of the device
5054 *
5055 * Return 0 for success, else failure
5056 */
5057static u8
5058_scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5059 u16 handle, u8 access_status)
5060{
5061 u8 rc = 1;
5062 char *desc = NULL;
5063
5064 switch (access_status) {
5065 case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
5066 case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
5067 rc = 0;
5068 break;
5069 case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
5070 desc = "sata capability failed";
5071 break;
5072 case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
5073 desc = "sata affiliation conflict";
5074 break;
5075 case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
5076 desc = "route not addressable";
5077 break;
5078 case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
5079 desc = "smp error not addressable";
5080 break;
5081 case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
5082 desc = "device blocked";
5083 break;
5084 case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
5085 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
5086 case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
5087 case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
5088 case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
5089 case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
5090 case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
5091 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
5092 case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
5093 case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
5094 case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
5095 case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
5096 desc = "sata initialization failed";
5097 break;
5098 default:
5099 desc = "unknown";
5100 break;
5101 }
5102
5103 if (!rc)
5104 return 0;
5105
5106 printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
5107 "handle(0x%04x)\n", ioc->name, desc,
5108 (unsigned long long)sas_address, handle);
5109 return rc;
5110}
5111
5112static void
5113_scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5114{
5115 Mpi2ConfigReply_t mpi_reply;
5116 Mpi2SasDevicePage0_t sas_device_pg0;
5117 struct _sas_device *sas_device;
5118 u32 ioc_status;
5119 unsigned long flags;
5120 u64 sas_address;
5121 struct scsi_target *starget;
5122 struct MPT2SAS_TARGET *sas_target_priv_data;
5123 u32 device_info;
5124
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305125
Kashyap, Desaib4344272010-03-17 16:24:14 +05305126 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5127 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
5128 return;
5129
5130 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
5131 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
5132 return;
5133
5134 /* check if this is end device */
5135 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5136 if (!(_scsih_is_end_device(device_info)))
5137 return;
5138
5139 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5140 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5141 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5142 sas_address);
5143
5144 if (!sas_device) {
5145 printk(MPT2SAS_ERR_FMT "device is not present "
5146 "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
5147 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5148 return;
5149 }
5150
5151 if (unlikely(sas_device->handle != handle)) {
5152 starget = sas_device->starget;
5153 sas_target_priv_data = starget->hostdata;
5154 starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
5155 " to (0x%04x)!!!\n", sas_device->handle, handle);
5156 sas_target_priv_data->handle = handle;
5157 sas_device->handle = handle;
5158 }
Kashyap, Desaib4344272010-03-17 16:24:14 +05305159
5160 /* check if device is present */
5161 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5162 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5163 printk(MPT2SAS_ERR_FMT "device is not present "
5164 "handle(0x%04x), flags!!!\n", ioc->name, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305165 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305166 return;
5167 }
5168
5169 /* check if there were any issues with discovery */
5170 if (_scsih_check_access_status(ioc, sas_address, handle,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305171 sas_device_pg0.AccessStatus)) {
5172 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305173 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305174 }
5175 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaib4344272010-03-17 16:24:14 +05305176 _scsih_ublock_io_device(ioc, handle);
5177
5178}
5179
5180/**
Eric Moore635374e2009-03-09 01:21:12 -06005181 * _scsih_add_device - creating sas device object
5182 * @ioc: per adapter object
5183 * @handle: sas device handle
5184 * @phy_num: phy number end device attached to
5185 * @is_pd: is this hidden raid component
5186 *
5187 * Creating end device object, stored in ioc->sas_device_list.
5188 *
5189 * Returns 0 for success, non-zero for failure.
5190 */
5191static int
5192_scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5193{
5194 Mpi2ConfigReply_t mpi_reply;
5195 Mpi2SasDevicePage0_t sas_device_pg0;
5196 Mpi2SasEnclosurePage0_t enclosure_pg0;
5197 struct _sas_device *sas_device;
5198 u32 ioc_status;
5199 __le64 sas_address;
5200 u32 device_info;
5201 unsigned long flags;
5202
5203 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
5204 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
5205 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5206 ioc->name, __FILE__, __LINE__, __func__);
5207 return -1;
5208 }
5209
5210 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5211 MPI2_IOCSTATUS_MASK;
5212 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5213 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5214 ioc->name, __FILE__, __LINE__, __func__);
5215 return -1;
5216 }
5217
Kashyap, Desaib4344272010-03-17 16:24:14 +05305218 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5219
Eric Moore635374e2009-03-09 01:21:12 -06005220 /* check if device is present */
5221 if (!(le16_to_cpu(sas_device_pg0.Flags) &
5222 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
5223 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5224 ioc->name, __FILE__, __LINE__, __func__);
5225 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
5226 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
5227 return -1;
5228 }
5229
Kashyap, Desaib4344272010-03-17 16:24:14 +05305230 /* check if there were any issues with discovery */
5231 if (_scsih_check_access_status(ioc, sas_address, handle,
5232 sas_device_pg0.AccessStatus))
Eric Moore635374e2009-03-09 01:21:12 -06005233 return -1;
Eric Moore635374e2009-03-09 01:21:12 -06005234
5235 /* check if this is end device */
5236 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5237 if (!(_scsih_is_end_device(device_info))) {
5238 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5239 ioc->name, __FILE__, __LINE__, __func__);
5240 return -1;
5241 }
5242
Eric Moore635374e2009-03-09 01:21:12 -06005243
5244 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5245 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5246 sas_address);
5247 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5248
Kashyap, Desaib4344272010-03-17 16:24:14 +05305249 if (sas_device)
Eric Moore635374e2009-03-09 01:21:12 -06005250 return 0;
Eric Moore635374e2009-03-09 01:21:12 -06005251
5252 sas_device = kzalloc(sizeof(struct _sas_device),
5253 GFP_KERNEL);
5254 if (!sas_device) {
5255 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5256 ioc->name, __FILE__, __LINE__, __func__);
5257 return -1;
5258 }
5259
5260 sas_device->handle = handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305261 if (_scsih_get_sas_address(ioc, le16_to_cpu
5262 (sas_device_pg0.ParentDevHandle),
5263 &sas_device->sas_address_parent) != 0)
5264 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5265 ioc->name, __FILE__, __LINE__, __func__);
Eric Moore635374e2009-03-09 01:21:12 -06005266 sas_device->enclosure_handle =
5267 le16_to_cpu(sas_device_pg0.EnclosureHandle);
5268 sas_device->slot =
5269 le16_to_cpu(sas_device_pg0.Slot);
5270 sas_device->device_info = device_info;
5271 sas_device->sas_address = sas_address;
Kashyap, Desai7fbae672010-06-17 13:45:17 +05305272 sas_device->phy = sas_device_pg0.PhyNum;
Eric Moore635374e2009-03-09 01:21:12 -06005273
5274 /* get enclosure_logical_id */
Kashyap, Desai15052c92009-08-07 19:33:17 +05305275 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
5276 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
5277 sas_device->enclosure_handle)))
Eric Moore635374e2009-03-09 01:21:12 -06005278 sas_device->enclosure_logical_id =
5279 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
Eric Moore635374e2009-03-09 01:21:12 -06005280
5281 /* get device name */
5282 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5283
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305284 if (ioc->wait_for_discovery_to_complete)
Eric Moore635374e2009-03-09 01:21:12 -06005285 _scsih_sas_device_init_add(ioc, sas_device);
5286 else
5287 _scsih_sas_device_add(ioc, sas_device);
5288
5289 return 0;
5290}
5291
5292/**
Kashyap, Desai1278b112010-03-09 17:34:13 +05305293 * _scsih_remove_device - removing sas device object
5294 * @ioc: per adapter object
5295 * @sas_device_delete: the sas_device object
5296 *
5297 * Return nothing.
5298 */
5299static void
5300_scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5301 struct _sas_device *sas_device)
5302{
Kashyap, Desai1278b112010-03-09 17:34:13 +05305303 struct MPT2SAS_TARGET *sas_target_priv_data;
Kashyap, Desai34a03be2009-08-20 13:23:19 +05305304
Kashyap, Desai1278b112010-03-09 17:34:13 +05305305 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
5306 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305307 sas_device->handle, (unsigned long long)
5308 sas_device->sas_address));
Kashyap, Desai1278b112010-03-09 17:34:13 +05305309
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305310 if (sas_device->starget && sas_device->starget->hostdata) {
5311 sas_target_priv_data = sas_device->starget->hostdata;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305312 sas_target_priv_data->deleted = 1;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305313 _scsih_ublock_io_device(ioc, sas_device->handle);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305314 sas_target_priv_data->handle =
5315 MPT2SAS_INVALID_DEVICE_HANDLE;
Kashyap, Desai1278b112010-03-09 17:34:13 +05305316 }
5317
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05305318 if (!ioc->hide_drives)
5319 mpt2sas_transport_port_remove(ioc,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305320 sas_device->sas_address,
5321 sas_device->sas_address_parent);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305322
5323 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305324 "(0x%016llx)\n", ioc->name, sas_device->handle,
5325 (unsigned long long) sas_device->sas_address);
Kashyap, Desai1278b112010-03-09 17:34:13 +05305326
5327 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
5328 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305329 sas_device->handle, (unsigned long long)
5330 sas_device->sas_address));
5331 kfree(sas_device);
5332}
5333/**
5334 * _scsih_device_remove_by_handle - removing device object by handle
5335 * @ioc: per adapter object
5336 * @handle: device handle
5337 *
5338 * Return nothing.
5339 */
5340static void
5341_scsih_device_remove_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
5342{
5343 struct _sas_device *sas_device;
5344 unsigned long flags;
5345
5346 if (ioc->shost_recovery)
5347 return;
5348
5349 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5350 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5351 if (sas_device)
5352 list_del(&sas_device->list);
5353 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5354 if (sas_device)
5355 _scsih_remove_device(ioc, sas_device);
Eric Moore635374e2009-03-09 01:21:12 -06005356}
5357
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305358/**
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305359 * mpt2sas_device_remove_by_sas_address - removing device object by sas address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305360 * @ioc: per adapter object
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305361 * @sas_address: device sas_address
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305362 *
5363 * Return nothing.
5364 */
5365void
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305366mpt2sas_device_remove_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
5367 u64 sas_address)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305368{
5369 struct _sas_device *sas_device;
5370 unsigned long flags;
5371
5372 if (ioc->shost_recovery)
5373 return;
5374
5375 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5376 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5377 sas_address);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305378 if (sas_device)
5379 list_del(&sas_device->list);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305380 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305381 if (sas_device)
5382 _scsih_remove_device(ioc, sas_device);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305383}
Eric Moore635374e2009-03-09 01:21:12 -06005384#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5385/**
5386 * _scsih_sas_topology_change_event_debug - debug for topology event
5387 * @ioc: per adapter object
5388 * @event_data: event data payload
5389 * Context: user.
5390 */
5391static void
5392_scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5393 Mpi2EventDataSasTopologyChangeList_t *event_data)
5394{
5395 int i;
5396 u16 handle;
5397 u16 reason_code;
5398 u8 phy_number;
5399 char *status_str = NULL;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305400 u8 link_rate, prev_link_rate;
Eric Moore635374e2009-03-09 01:21:12 -06005401
5402 switch (event_data->ExpStatus) {
5403 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
5404 status_str = "add";
5405 break;
5406 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
5407 status_str = "remove";
5408 break;
5409 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305410 case 0:
Eric Moore635374e2009-03-09 01:21:12 -06005411 status_str = "responding";
5412 break;
5413 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
5414 status_str = "remove delay";
5415 break;
5416 default:
5417 status_str = "unknown status";
5418 break;
5419 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305420 printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
Eric Moore635374e2009-03-09 01:21:12 -06005421 ioc->name, status_str);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305422 printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
Eric Moore635374e2009-03-09 01:21:12 -06005423 "start_phy(%02d), count(%d)\n",
5424 le16_to_cpu(event_data->ExpanderDevHandle),
5425 le16_to_cpu(event_data->EnclosureHandle),
5426 event_data->StartPhyNum, event_data->NumEntries);
5427 for (i = 0; i < event_data->NumEntries; i++) {
5428 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5429 if (!handle)
5430 continue;
5431 phy_number = event_data->StartPhyNum + i;
5432 reason_code = event_data->PHY[i].PhyStatus &
5433 MPI2_EVENT_SAS_TOPO_RC_MASK;
5434 switch (reason_code) {
5435 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305436 status_str = "target add";
Eric Moore635374e2009-03-09 01:21:12 -06005437 break;
5438 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305439 status_str = "target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005440 break;
5441 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305442 status_str = "delay target remove";
Eric Moore635374e2009-03-09 01:21:12 -06005443 break;
5444 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305445 status_str = "link rate change";
Eric Moore635374e2009-03-09 01:21:12 -06005446 break;
5447 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305448 status_str = "target responding";
Eric Moore635374e2009-03-09 01:21:12 -06005449 break;
5450 default:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305451 status_str = "unknown";
Eric Moore635374e2009-03-09 01:21:12 -06005452 break;
5453 }
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305454 link_rate = event_data->PHY[i].LinkRate >> 4;
5455 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305456 printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305457 " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
5458 handle, status_str, link_rate, prev_link_rate);
5459
Eric Moore635374e2009-03-09 01:21:12 -06005460 }
5461}
5462#endif
5463
5464/**
5465 * _scsih_sas_topology_change_event - handle topology changes
5466 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305467 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005468 * Context: user.
5469 *
5470 */
5471static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305472_scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
Eric Moore635374e2009-03-09 01:21:12 -06005473 struct fw_event_work *fw_event)
5474{
5475 int i;
5476 u16 parent_handle, handle;
5477 u16 reason_code;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305478 u8 phy_number, max_phys;
Eric Moore635374e2009-03-09 01:21:12 -06005479 struct _sas_node *sas_expander;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305480 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06005481 unsigned long flags;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305482 u8 link_rate, prev_link_rate;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305483 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06005484
5485#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5486 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5487 _scsih_sas_topology_change_event_debug(ioc, event_data);
5488#endif
5489
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305490 if (ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305491 return;
5492
Eric Moore635374e2009-03-09 01:21:12 -06005493 if (!ioc->sas_hba.num_phys)
5494 _scsih_sas_host_add(ioc);
5495 else
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305496 _scsih_sas_host_refresh(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005497
5498 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305499 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
Eric Moore635374e2009-03-09 01:21:12 -06005500 "event\n", ioc->name));
5501 return;
5502 }
5503
5504 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
5505
5506 /* handle expander add */
5507 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
5508 if (_scsih_expander_add(ioc, parent_handle) != 0)
5509 return;
5510
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305511 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5512 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
5513 parent_handle);
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305514 if (sas_expander) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305515 sas_address = sas_expander->sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305516 max_phys = sas_expander->num_phys;
5517 } else if (parent_handle < ioc->sas_hba.num_phys) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305518 sas_address = ioc->sas_hba.sas_address;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305519 max_phys = ioc->sas_hba.num_phys;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305520 } else {
5521 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305522 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305523 }
5524 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305525
Eric Moore635374e2009-03-09 01:21:12 -06005526 /* handle siblings events */
5527 for (i = 0; i < event_data->NumEntries; i++) {
5528 if (fw_event->ignore) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305529 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
Eric Moore635374e2009-03-09 01:21:12 -06005530 "expander event\n", ioc->name));
5531 return;
5532 }
Eric Moore3cb54692010-07-08 14:44:34 -06005533 if (ioc->shost_recovery || ioc->remove_host ||
5534 ioc->pci_error_recovery)
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05305535 return;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305536 phy_number = event_data->StartPhyNum + i;
Kashyap, Desaib41c09d2010-11-13 04:40:51 +05305537 if (phy_number >= max_phys)
5538 continue;
Kashyap, Desai308609c2009-09-14 11:07:23 +05305539 reason_code = event_data->PHY[i].PhyStatus &
5540 MPI2_EVENT_SAS_TOPO_RC_MASK;
5541 if ((event_data->PHY[i].PhyStatus &
5542 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
5543 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
Eric Moore635374e2009-03-09 01:21:12 -06005544 continue;
5545 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
5546 if (!handle)
5547 continue;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305548 link_rate = event_data->PHY[i].LinkRate >> 4;
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305549 prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
Eric Moore635374e2009-03-09 01:21:12 -06005550 switch (reason_code) {
5551 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305552
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305553 if (ioc->shost_recovery)
5554 break;
5555
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305556 if (link_rate == prev_link_rate)
5557 break;
5558
5559 mpt2sas_transport_update_links(ioc, sas_address,
5560 handle, phy_number, link_rate);
5561
Kashyap, Desaib4344272010-03-17 16:24:14 +05305562 if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
5563 break;
5564
5565 _scsih_check_device(ioc, handle);
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305566 break;
Eric Moore635374e2009-03-09 01:21:12 -06005567 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305568
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05305569 if (ioc->shost_recovery)
5570 break;
5571
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305572 mpt2sas_transport_update_links(ioc, sas_address,
5573 handle, phy_number, link_rate);
5574
Kashyap, Desaie7d59c12009-09-23 17:36:52 +05305575 _scsih_add_device(ioc, handle, phy_number, 0);
Eric Moore635374e2009-03-09 01:21:12 -06005576 break;
5577 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305578
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305579 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06005580 break;
5581 }
5582 }
5583
5584 /* handle expander removal */
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05305585 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
5586 sas_expander)
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05305587 mpt2sas_expander_remove(ioc, sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06005588
5589}
5590
5591#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5592/**
5593 * _scsih_sas_device_status_change_event_debug - debug for device event
5594 * @event_data: event data payload
5595 * Context: user.
5596 *
5597 * Return nothing.
5598 */
5599static void
5600_scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5601 Mpi2EventDataSasDeviceStatusChange_t *event_data)
5602{
5603 char *reason_str = NULL;
5604
5605 switch (event_data->ReasonCode) {
5606 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5607 reason_str = "smart data";
5608 break;
5609 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5610 reason_str = "unsupported device discovered";
5611 break;
5612 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5613 reason_str = "internal device reset";
5614 break;
5615 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5616 reason_str = "internal task abort";
5617 break;
5618 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5619 reason_str = "internal task abort set";
5620 break;
5621 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5622 reason_str = "internal clear task set";
5623 break;
5624 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5625 reason_str = "internal query task";
5626 break;
5627 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
5628 reason_str = "sata init failure";
5629 break;
5630 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
5631 reason_str = "internal device reset complete";
5632 break;
5633 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
5634 reason_str = "internal task abort complete";
5635 break;
5636 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
5637 reason_str = "internal async notification";
5638 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05305639 case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
5640 reason_str = "expander reduced functionality";
5641 break;
5642 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
5643 reason_str = "expander reduced functionality complete";
5644 break;
Eric Moore635374e2009-03-09 01:21:12 -06005645 default:
5646 reason_str = "unknown reason";
5647 break;
5648 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305649 printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305650 "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
5651 ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
5652 (unsigned long long)le64_to_cpu(event_data->SASAddress),
5653 le16_to_cpu(event_data->TaskTag));
Eric Moore635374e2009-03-09 01:21:12 -06005654 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305655 printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005656 event_data->ASC, event_data->ASCQ);
5657 printk(KERN_INFO "\n");
5658}
5659#endif
5660
5661/**
5662 * _scsih_sas_device_status_change_event - handle device status change
5663 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305664 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005665 * Context: user.
5666 *
5667 * Return nothing.
5668 */
5669static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305670_scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
5671 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005672{
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305673 struct MPT2SAS_TARGET *target_priv_data;
5674 struct _sas_device *sas_device;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05305675 u64 sas_address;
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305676 unsigned long flags;
5677 Mpi2EventDataSasDeviceStatusChange_t *event_data =
5678 fw_event->event_data;
5679
Eric Moore635374e2009-03-09 01:21:12 -06005680#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5681 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305682 _scsih_sas_device_status_change_event_debug(ioc,
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305683 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005684#endif
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305685
Kashyap, Desaiefe82a12011-01-04 11:34:17 +05305686 /* In MPI Revision K (0xC), the internal device reset complete was
5687 * implemented, so avoid setting tm_busy flag for older firmware.
5688 */
5689 if ((ioc->facts.HeaderVersion >> 8) < 0xC)
5690 return;
5691
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305692 if (event_data->ReasonCode !=
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305693 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
Kashyap, Desaif891dcf2010-03-17 16:22:21 +05305694 event_data->ReasonCode !=
5695 MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305696 return;
5697
5698 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5699 sas_address = le64_to_cpu(event_data->SASAddress);
5700 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5701 sas_address);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305702
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305703 if (!sas_device || !sas_device->starget) {
5704 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305705 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305706 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305707
5708 target_priv_data = sas_device->starget->hostdata;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305709 if (!target_priv_data) {
5710 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305711 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305712 }
Kashyap, Desai8ffc4572009-09-23 17:35:41 +05305713
5714 if (event_data->ReasonCode ==
5715 MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
5716 target_priv_data->tm_busy = 1;
5717 else
5718 target_priv_data->tm_busy = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05305719 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005720}
5721
5722#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5723/**
5724 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
5725 * @ioc: per adapter object
5726 * @event_data: event data payload
5727 * Context: user.
5728 *
5729 * Return nothing.
5730 */
5731static void
5732_scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
5733 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
5734{
5735 char *reason_str = NULL;
5736
5737 switch (event_data->ReasonCode) {
5738 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
5739 reason_str = "enclosure add";
5740 break;
5741 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
5742 reason_str = "enclosure remove";
5743 break;
5744 default:
5745 reason_str = "unknown reason";
5746 break;
5747 }
5748
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305749 printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
Eric Moore635374e2009-03-09 01:21:12 -06005750 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
5751 " number slots(%d)\n", ioc->name, reason_str,
5752 le16_to_cpu(event_data->EnclosureHandle),
5753 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
5754 le16_to_cpu(event_data->StartSlot));
5755}
5756#endif
5757
5758/**
5759 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
5760 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305761 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005762 * Context: user.
5763 *
5764 * Return nothing.
5765 */
5766static void
5767_scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305768 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005769{
5770#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5771 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5772 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305773 fw_event->event_data);
Eric Moore635374e2009-03-09 01:21:12 -06005774#endif
5775}
5776
5777/**
Andrew Mortona78e21d2012-02-08 12:52:22 -08005778 * _scsih_sas_broadcast_primitive_event - handle broadcast events
Eric Moore635374e2009-03-09 01:21:12 -06005779 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305780 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005781 * Context: user.
5782 *
5783 * Return nothing.
5784 */
5785static void
Andrew Mortona78e21d2012-02-08 12:52:22 -08005786_scsih_sas_broadcast_primitive_event(struct MPT2SAS_ADAPTER *ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305787 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005788{
5789 struct scsi_cmnd *scmd;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305790 struct scsi_device *sdev;
Eric Moore635374e2009-03-09 01:21:12 -06005791 u16 smid, handle;
5792 u32 lun;
5793 struct MPT2SAS_DEVICE *sas_device_priv_data;
5794 u32 termination_count;
5795 u32 query_count;
5796 Mpi2SCSITaskManagementReply_t *mpi_reply;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305797 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
Kashyap, Desai463217b2009-10-05 15:53:06 +05305798 u16 ioc_status;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305799 unsigned long flags;
5800 int r;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305801 u8 max_retries = 0;
5802 u8 task_abort_retries;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305803
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305804 mutex_lock(&ioc->tm_cmds.mutex);
5805 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), "
5806 "width(%d)\n", ioc->name, __func__, event_data->PhyNum,
5807 event_data->PortWidth));
5808
5809 _scsih_block_io_all_device(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06005810
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305811 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305812 mpi_reply = ioc->tm_cmds.reply;
5813broadcast_aen_retry:
5814
5815 /* sanity checks for retrying this loop */
5816 if (max_retries++ == 5) {
5817 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
5818 ioc->name, __func__));
5819 goto out;
5820 } else if (max_retries > 1)
5821 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
5822 ioc->name, __func__, max_retries - 1));
5823
Eric Moore635374e2009-03-09 01:21:12 -06005824 termination_count = 0;
5825 query_count = 0;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305826 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305827 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305828 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06005829 scmd = _scsih_scsi_lookup_get(ioc, smid);
5830 if (!scmd)
5831 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305832 sdev = scmd->device;
5833 sas_device_priv_data = sdev->hostdata;
Eric Moore635374e2009-03-09 01:21:12 -06005834 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
5835 continue;
5836 /* skip hidden raid components */
5837 if (sas_device_priv_data->sas_target->flags &
5838 MPT_TARGET_FLAGS_RAID_COMPONENT)
5839 continue;
5840 /* skip volumes */
5841 if (sas_device_priv_data->sas_target->flags &
5842 MPT_TARGET_FLAGS_VOLUME)
5843 continue;
5844
5845 handle = sas_device_priv_data->sas_target->handle;
5846 lun = sas_device_priv_data->lun;
5847 query_count++;
5848
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305849 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305850 goto out;
5851
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305852 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305853 r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
5854 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0,
5855 TM_MUTEX_OFF);
5856 if (r == FAILED) {
5857 sdev_printk(KERN_WARNING, sdev,
5858 "mpt2sas_scsih_issue_tm: FAILED when sending "
5859 "QUERY_TASK: scmd(%p)\n", scmd);
5860 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5861 goto broadcast_aen_retry;
5862 }
Kashyap, Desai463217b2009-10-05 15:53:06 +05305863 ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
5864 & MPI2_IOCSTATUS_MASK;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305865 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
5866 sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
5867 "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
5868 scmd);
5869 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5870 goto broadcast_aen_retry;
5871 }
5872
5873 /* see if IO is still owned by IOC and target */
5874 if (mpi_reply->ResponseCode ==
Eric Moore635374e2009-03-09 01:21:12 -06005875 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
5876 mpi_reply->ResponseCode ==
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305877 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305878 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005879 continue;
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305880 }
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305881 task_abort_retries = 0;
5882 tm_retry:
5883 if (task_abort_retries++ == 60) {
5884 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
5885 "%s: ABORT_TASK: giving up\n", ioc->name,
5886 __func__));
5887 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
5888 goto broadcast_aen_retry;
5889 }
5890
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305891 if (ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305892 goto out_no_lock;
5893
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305894 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
5895 sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305896 scmd->serial_number, TM_MUTEX_OFF);
5897 if (r == FAILED) {
5898 sdev_printk(KERN_WARNING, sdev,
5899 "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305900 "scmd(%p)\n", scmd);
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305901 goto tm_retry;
5902 }
5903
5904 if (task_abort_retries > 1)
5905 sdev_printk(KERN_WARNING, sdev,
5906 "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
5907 " scmd(%p)\n",
5908 task_abort_retries - 1, scmd);
5909
Eric Moore635374e2009-03-09 01:21:12 -06005910 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
Kashyap, Desaiec07a052011-01-05 17:54:32 +05305911 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06005912 }
Eric Moore635374e2009-03-09 01:21:12 -06005913
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305914 if (ioc->broadcast_aen_pending) {
5915 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
5916 " pending AEN\n", ioc->name, __func__));
5917 ioc->broadcast_aen_pending = 0;
5918 goto broadcast_aen_retry;
5919 }
5920
5921 out:
5922 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
5923 out_no_lock:
5924
5925 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06005926 "%s - exit, query_count = %d termination_count = %d\n",
5927 ioc->name, __func__, query_count, termination_count));
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305928
5929 ioc->broadcast_aen_busy = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05305930 if (!ioc->shost_recovery)
Kashyap, Desaif93213d2011-06-14 10:56:43 +05305931 _scsih_ublock_io_all_device(ioc);
5932 mutex_unlock(&ioc->tm_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06005933}
5934
5935/**
5936 * _scsih_sas_discovery_event - handle discovery events
5937 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305938 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06005939 * Context: user.
5940 *
5941 * Return nothing.
5942 */
5943static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305944_scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
5945 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06005946{
Kashyap, Desai7b936b02009-09-25 11:44:41 +05305947 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
5948
Eric Moore635374e2009-03-09 01:21:12 -06005949#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5950 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05305951 printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06005952 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
5953 "start" : "stop");
5954 if (event_data->DiscoveryStatus)
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05305955 printk("discovery_status(0x%08x)",
5956 le32_to_cpu(event_data->DiscoveryStatus));
Eric Moore635374e2009-03-09 01:21:12 -06005957 printk("\n");
5958 }
5959#endif
5960
5961 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
5962 !ioc->sas_hba.num_phys)
5963 _scsih_sas_host_add(ioc);
5964}
5965
5966/**
5967 * _scsih_reprobe_lun - reprobing lun
5968 * @sdev: scsi device struct
5969 * @no_uld_attach: sdev->no_uld_attach flag setting
5970 *
5971 **/
5972static void
5973_scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5974{
5975 int rc;
5976
5977 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
5978 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
5979 sdev->no_uld_attach ? "hidding" : "exposing");
5980 rc = scsi_device_reprobe(sdev);
5981}
5982
5983/**
Eric Moore635374e2009-03-09 01:21:12 -06005984 * _scsih_sas_volume_add - add new volume
5985 * @ioc: per adapter object
5986 * @element: IR config element data
5987 * Context: user.
5988 *
5989 * Return nothing.
5990 */
5991static void
5992_scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
5993 Mpi2EventIrConfigElement_t *element)
5994{
5995 struct _raid_device *raid_device;
5996 unsigned long flags;
5997 u64 wwid;
5998 u16 handle = le16_to_cpu(element->VolDevHandle);
5999 int rc;
6000
Eric Moore635374e2009-03-09 01:21:12 -06006001 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6002 if (!wwid) {
6003 printk(MPT2SAS_ERR_FMT
6004 "failure at %s:%d/%s()!\n", ioc->name,
6005 __FILE__, __LINE__, __func__);
6006 return;
6007 }
6008
6009 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6010 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
6011 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6012
6013 if (raid_device)
6014 return;
6015
6016 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6017 if (!raid_device) {
6018 printk(MPT2SAS_ERR_FMT
6019 "failure at %s:%d/%s()!\n", ioc->name,
6020 __FILE__, __LINE__, __func__);
6021 return;
6022 }
6023
6024 raid_device->id = ioc->sas_id++;
6025 raid_device->channel = RAID_CHANNEL;
6026 raid_device->handle = handle;
6027 raid_device->wwid = wwid;
6028 _scsih_raid_device_add(ioc, raid_device);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306029 if (!ioc->wait_for_discovery_to_complete) {
Eric Moore635374e2009-03-09 01:21:12 -06006030 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6031 raid_device->id, 0);
6032 if (rc)
6033 _scsih_raid_device_remove(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306034 } else {
6035 spin_lock_irqsave(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006036 _scsih_determine_boot_device(ioc, raid_device, 1);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306037 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6038 }
Eric Moore635374e2009-03-09 01:21:12 -06006039}
6040
6041/**
6042 * _scsih_sas_volume_delete - delete volume
6043 * @ioc: per adapter object
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306044 * @handle: volume device handle
Eric Moore635374e2009-03-09 01:21:12 -06006045 * Context: user.
6046 *
6047 * Return nothing.
6048 */
6049static void
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306050_scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
Eric Moore635374e2009-03-09 01:21:12 -06006051{
6052 struct _raid_device *raid_device;
Eric Moore635374e2009-03-09 01:21:12 -06006053 unsigned long flags;
6054 struct MPT2SAS_TARGET *sas_target_priv_data;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306055 struct scsi_target *starget = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006056
Eric Moore635374e2009-03-09 01:21:12 -06006057 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6058 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306059 if (raid_device) {
6060 if (raid_device->starget) {
6061 starget = raid_device->starget;
6062 sas_target_priv_data = starget->hostdata;
6063 sas_target_priv_data->deleted = 1;
6064 }
6065 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6066 "(0x%016llx)\n", ioc->name, raid_device->handle,
6067 (unsigned long long) raid_device->wwid);
6068 list_del(&raid_device->list);
6069 kfree(raid_device);
Eric Moore635374e2009-03-09 01:21:12 -06006070 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306071 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6072 if (starget)
6073 scsi_remove_target(&starget->dev);
Eric Moore635374e2009-03-09 01:21:12 -06006074}
6075
6076/**
6077 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
6078 * @ioc: per adapter object
6079 * @element: IR config element data
6080 * Context: user.
6081 *
6082 * Return nothing.
6083 */
6084static void
6085_scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
6086 Mpi2EventIrConfigElement_t *element)
6087{
6088 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306089 struct scsi_target *starget = NULL;
6090 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006091 unsigned long flags;
6092 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6093
6094 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6095 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306096 if (sas_device) {
6097 sas_device->volume_handle = 0;
6098 sas_device->volume_wwid = 0;
6099 clear_bit(handle, ioc->pd_handles);
6100 if (sas_device->starget && sas_device->starget->hostdata) {
6101 starget = sas_device->starget;
6102 sas_target_priv_data = starget->hostdata;
6103 sas_target_priv_data->flags &=
6104 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
6105 }
6106 }
Eric Moore635374e2009-03-09 01:21:12 -06006107 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6108 if (!sas_device)
6109 return;
6110
6111 /* exposing raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306112 if (starget)
6113 starget_for_each_device(starget, NULL, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006114}
6115
6116/**
6117 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
6118 * @ioc: per adapter object
6119 * @element: IR config element data
6120 * Context: user.
6121 *
6122 * Return nothing.
6123 */
6124static void
6125_scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
6126 Mpi2EventIrConfigElement_t *element)
6127{
6128 struct _sas_device *sas_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306129 struct scsi_target *starget = NULL;
6130 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06006131 unsigned long flags;
6132 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306133 u16 volume_handle = 0;
6134 u64 volume_wwid = 0;
6135
6136 mpt2sas_config_get_volume_handle(ioc, handle, &volume_handle);
6137 if (volume_handle)
6138 mpt2sas_config_get_volume_wwid(ioc, volume_handle,
6139 &volume_wwid);
Eric Moore635374e2009-03-09 01:21:12 -06006140
6141 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6142 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306143 if (sas_device) {
6144 set_bit(handle, ioc->pd_handles);
6145 if (sas_device->starget && sas_device->starget->hostdata) {
6146 starget = sas_device->starget;
6147 sas_target_priv_data = starget->hostdata;
6148 sas_target_priv_data->flags |=
6149 MPT_TARGET_FLAGS_RAID_COMPONENT;
6150 sas_device->volume_handle = volume_handle;
6151 sas_device->volume_wwid = volume_wwid;
6152 }
6153 }
Eric Moore635374e2009-03-09 01:21:12 -06006154 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6155 if (!sas_device)
6156 return;
6157
6158 /* hiding raid component */
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306159 if (starget)
6160 starget_for_each_device(starget, (void *)1, _scsih_reprobe_lun);
Eric Moore635374e2009-03-09 01:21:12 -06006161}
6162
6163/**
6164 * _scsih_sas_pd_delete - delete pd component
6165 * @ioc: per adapter object
6166 * @element: IR config element data
6167 * Context: user.
6168 *
6169 * Return nothing.
6170 */
6171static void
6172_scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
6173 Mpi2EventIrConfigElement_t *element)
6174{
Eric Moore635374e2009-03-09 01:21:12 -06006175 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
6176
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306177 _scsih_device_remove_by_handle(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006178}
6179
6180/**
6181 * _scsih_sas_pd_add - remove pd component
6182 * @ioc: per adapter object
6183 * @element: IR config element data
6184 * Context: user.
6185 *
6186 * Return nothing.
6187 */
6188static void
6189_scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
6190 Mpi2EventIrConfigElement_t *element)
6191{
6192 struct _sas_device *sas_device;
6193 unsigned long flags;
6194 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306195 Mpi2ConfigReply_t mpi_reply;
6196 Mpi2SasDevicePage0_t sas_device_pg0;
6197 u32 ioc_status;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306198 u64 sas_address;
6199 u16 parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006200
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306201 set_bit(handle, ioc->pd_handles);
6202
Eric Moore635374e2009-03-09 01:21:12 -06006203 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6204 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6205 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306206 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306207 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306208
6209 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
6210 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
6211 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6212 ioc->name, __FILE__, __LINE__, __func__);
6213 return;
6214 }
6215
6216 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6217 MPI2_IOCSTATUS_MASK;
6218 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6219 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6220 ioc->name, __FILE__, __LINE__, __func__);
6221 return;
6222 }
6223
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306224 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6225 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6226 mpt2sas_transport_update_links(ioc, sas_address, handle,
6227 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306228
6229 _scsih_add_device(ioc, handle, 0, 1);
Eric Moore635374e2009-03-09 01:21:12 -06006230}
6231
6232#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6233/**
6234 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
6235 * @ioc: per adapter object
6236 * @event_data: event data payload
6237 * Context: user.
6238 *
6239 * Return nothing.
6240 */
6241static void
6242_scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
6243 Mpi2EventDataIrConfigChangeList_t *event_data)
6244{
6245 Mpi2EventIrConfigElement_t *element;
6246 u8 element_type;
6247 int i;
6248 char *reason_str = NULL, *element_str = NULL;
6249
6250 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6251
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306252 printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
Eric Moore635374e2009-03-09 01:21:12 -06006253 ioc->name, (le32_to_cpu(event_data->Flags) &
6254 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
6255 "foreign" : "native", event_data->NumElements);
6256 for (i = 0; i < event_data->NumElements; i++, element++) {
6257 switch (element->ReasonCode) {
6258 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
6259 reason_str = "add";
6260 break;
6261 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
6262 reason_str = "remove";
6263 break;
6264 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
6265 reason_str = "no change";
6266 break;
6267 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
6268 reason_str = "hide";
6269 break;
6270 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
6271 reason_str = "unhide";
6272 break;
6273 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6274 reason_str = "volume_created";
6275 break;
6276 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6277 reason_str = "volume_deleted";
6278 break;
6279 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
6280 reason_str = "pd_created";
6281 break;
6282 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
6283 reason_str = "pd_deleted";
6284 break;
6285 default:
6286 reason_str = "unknown reason";
6287 break;
6288 }
6289 element_type = le16_to_cpu(element->ElementFlags) &
6290 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
6291 switch (element_type) {
6292 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
6293 element_str = "volume";
6294 break;
6295 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
6296 element_str = "phys disk";
6297 break;
6298 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
6299 element_str = "hot spare";
6300 break;
6301 default:
6302 element_str = "unknown element";
6303 break;
6304 }
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05306305 printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
Eric Moore635374e2009-03-09 01:21:12 -06006306 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
6307 reason_str, le16_to_cpu(element->VolDevHandle),
6308 le16_to_cpu(element->PhysDiskDevHandle),
6309 element->PhysDiskNum);
6310 }
6311}
6312#endif
6313
6314/**
6315 * _scsih_sas_ir_config_change_event - handle ir configuration change events
6316 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306317 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006318 * Context: user.
6319 *
6320 * Return nothing.
6321 */
6322static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306323_scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6324 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006325{
6326 Mpi2EventIrConfigElement_t *element;
6327 int i;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306328 u8 foreign_config;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306329 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006330
6331#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306332 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6333 && !ioc->hide_ir_msg)
Eric Moore635374e2009-03-09 01:21:12 -06006334 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6335
6336#endif
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306337
6338 if (ioc->shost_recovery)
6339 return;
6340
Kashyap, Desai62727a72009-08-07 19:35:18 +05306341 foreign_config = (le32_to_cpu(event_data->Flags) &
6342 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
Eric Moore635374e2009-03-09 01:21:12 -06006343
6344 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
6345 for (i = 0; i < event_data->NumElements; i++, element++) {
6346
6347 switch (element->ReasonCode) {
6348 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
6349 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306350 if (!foreign_config)
6351 _scsih_sas_volume_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006352 break;
6353 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
6354 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
Kashyap, Desai62727a72009-08-07 19:35:18 +05306355 if (!foreign_config)
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306356 _scsih_sas_volume_delete(ioc,
6357 le16_to_cpu(element->VolDevHandle));
Eric Moore635374e2009-03-09 01:21:12 -06006358 break;
6359 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306360 if (!ioc->is_warpdrive)
6361 _scsih_sas_pd_hide(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006362 break;
6363 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306364 if (!ioc->is_warpdrive)
6365 _scsih_sas_pd_expose(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006366 break;
6367 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306368 if (!ioc->is_warpdrive)
6369 _scsih_sas_pd_add(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006370 break;
6371 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306372 if (!ioc->is_warpdrive)
6373 _scsih_sas_pd_delete(ioc, element);
Eric Moore635374e2009-03-09 01:21:12 -06006374 break;
6375 }
6376 }
6377}
6378
6379/**
6380 * _scsih_sas_ir_volume_event - IR volume event
6381 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306382 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006383 * Context: user.
6384 *
6385 * Return nothing.
6386 */
6387static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306388_scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6389 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006390{
6391 u64 wwid;
6392 unsigned long flags;
6393 struct _raid_device *raid_device;
6394 u16 handle;
6395 u32 state;
6396 int rc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306397 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
Eric Moore635374e2009-03-09 01:21:12 -06006398
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306399 if (ioc->shost_recovery)
6400 return;
6401
Eric Moore635374e2009-03-09 01:21:12 -06006402 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6403 return;
6404
6405 handle = le16_to_cpu(event_data->VolDevHandle);
6406 state = le32_to_cpu(event_data->NewValue);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306407 if (!ioc->hide_ir_msg)
6408 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6409 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6410 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006411
Eric Moore635374e2009-03-09 01:21:12 -06006412 switch (state) {
6413 case MPI2_RAID_VOL_STATE_MISSING:
6414 case MPI2_RAID_VOL_STATE_FAILED:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306415 _scsih_sas_volume_delete(ioc, handle);
Eric Moore635374e2009-03-09 01:21:12 -06006416 break;
6417
6418 case MPI2_RAID_VOL_STATE_ONLINE:
6419 case MPI2_RAID_VOL_STATE_DEGRADED:
6420 case MPI2_RAID_VOL_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306421
6422 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6423 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
6424 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6425
Eric Moore635374e2009-03-09 01:21:12 -06006426 if (raid_device)
6427 break;
6428
6429 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
6430 if (!wwid) {
6431 printk(MPT2SAS_ERR_FMT
6432 "failure at %s:%d/%s()!\n", ioc->name,
6433 __FILE__, __LINE__, __func__);
6434 break;
6435 }
6436
6437 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
6438 if (!raid_device) {
6439 printk(MPT2SAS_ERR_FMT
6440 "failure at %s:%d/%s()!\n", ioc->name,
6441 __FILE__, __LINE__, __func__);
6442 break;
6443 }
6444
6445 raid_device->id = ioc->sas_id++;
6446 raid_device->channel = RAID_CHANNEL;
6447 raid_device->handle = handle;
6448 raid_device->wwid = wwid;
6449 _scsih_raid_device_add(ioc, raid_device);
6450 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
6451 raid_device->id, 0);
6452 if (rc)
6453 _scsih_raid_device_remove(ioc, raid_device);
6454 break;
6455
6456 case MPI2_RAID_VOL_STATE_INITIALIZING:
6457 default:
6458 break;
6459 }
6460}
6461
6462/**
6463 * _scsih_sas_ir_physical_disk_event - PD event
6464 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306465 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006466 * Context: user.
6467 *
6468 * Return nothing.
6469 */
6470static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306471_scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6472 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006473{
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306474 u16 handle, parent_handle;
Eric Moore635374e2009-03-09 01:21:12 -06006475 u32 state;
6476 struct _sas_device *sas_device;
6477 unsigned long flags;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306478 Mpi2ConfigReply_t mpi_reply;
6479 Mpi2SasDevicePage0_t sas_device_pg0;
6480 u32 ioc_status;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306481 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306482 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006483
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306484 if (ioc->shost_recovery)
6485 return;
6486
Eric Moore635374e2009-03-09 01:21:12 -06006487 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6488 return;
6489
6490 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
6491 state = le32_to_cpu(event_data->NewValue);
6492
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306493 if (!ioc->hide_ir_msg)
6494 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
6495 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
6496 le32_to_cpu(event_data->PreviousValue), state));
Eric Moore635374e2009-03-09 01:21:12 -06006497
Eric Moore635374e2009-03-09 01:21:12 -06006498 switch (state) {
Eric Moore635374e2009-03-09 01:21:12 -06006499 case MPI2_RAID_PD_STATE_ONLINE:
6500 case MPI2_RAID_PD_STATE_DEGRADED:
6501 case MPI2_RAID_PD_STATE_REBUILDING:
6502 case MPI2_RAID_PD_STATE_OPTIMAL:
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306503 case MPI2_RAID_PD_STATE_HOT_SPARE:
6504
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306505 if (!ioc->is_warpdrive)
6506 set_bit(handle, ioc->pd_handles);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306507
6508 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6509 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
6510 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6511
6512 if (sas_device)
Kashyap, Desai62727a72009-08-07 19:35:18 +05306513 return;
Kashyap, Desai62727a72009-08-07 19:35:18 +05306514
6515 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6516 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
6517 handle))) {
6518 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6519 ioc->name, __FILE__, __LINE__, __func__);
6520 return;
6521 }
6522
6523 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6524 MPI2_IOCSTATUS_MASK;
6525 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
6526 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6527 ioc->name, __FILE__, __LINE__, __func__);
6528 return;
6529 }
6530
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306531 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
6532 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
6533 mpt2sas_transport_update_links(ioc, sas_address, handle,
6534 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
Kashyap, Desai62727a72009-08-07 19:35:18 +05306535
6536 _scsih_add_device(ioc, handle, 0, 1);
6537
Eric Moore635374e2009-03-09 01:21:12 -06006538 break;
6539
Kashyap, Desai62727a72009-08-07 19:35:18 +05306540 case MPI2_RAID_PD_STATE_OFFLINE:
Eric Moore635374e2009-03-09 01:21:12 -06006541 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
6542 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
Eric Moore635374e2009-03-09 01:21:12 -06006543 default:
6544 break;
6545 }
6546}
6547
6548#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
6549/**
6550 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
6551 * @ioc: per adapter object
6552 * @event_data: event data payload
6553 * Context: user.
6554 *
6555 * Return nothing.
6556 */
6557static void
6558_scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
6559 Mpi2EventDataIrOperationStatus_t *event_data)
6560{
6561 char *reason_str = NULL;
6562
6563 switch (event_data->RAIDOperation) {
6564 case MPI2_EVENT_IR_RAIDOP_RESYNC:
6565 reason_str = "resync";
6566 break;
6567 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
6568 reason_str = "online capacity expansion";
6569 break;
6570 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
6571 reason_str = "consistency check";
6572 break;
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306573 case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
6574 reason_str = "background init";
6575 break;
6576 case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
6577 reason_str = "make data consistent";
Eric Moore635374e2009-03-09 01:21:12 -06006578 break;
6579 }
6580
Kashyap, Desaiec6c2b42009-09-23 17:31:01 +05306581 if (!reason_str)
6582 return;
6583
Eric Moore635374e2009-03-09 01:21:12 -06006584 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
6585 "\thandle(0x%04x), percent complete(%d)\n",
6586 ioc->name, reason_str,
6587 le16_to_cpu(event_data->VolDevHandle),
6588 event_data->PercentComplete);
6589}
6590#endif
6591
6592/**
6593 * _scsih_sas_ir_operation_status_event - handle RAID operation events
6594 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306595 * @fw_event: The fw_event_work object
Eric Moore635374e2009-03-09 01:21:12 -06006596 * Context: user.
6597 *
6598 * Return nothing.
6599 */
6600static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306601_scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
6602 struct fw_event_work *fw_event)
Eric Moore635374e2009-03-09 01:21:12 -06006603{
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306604 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
6605 static struct _raid_device *raid_device;
6606 unsigned long flags;
6607 u16 handle;
6608
Eric Moore635374e2009-03-09 01:21:12 -06006609#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306610 if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
6611 && !ioc->hide_ir_msg)
Kashyap, Desai7b936b02009-09-25 11:44:41 +05306612 _scsih_sas_ir_operation_status_event_debug(ioc,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306613 event_data);
Eric Moore635374e2009-03-09 01:21:12 -06006614#endif
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306615
6616 /* code added for raid transport support */
6617 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
6618
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306619 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306620 handle = le16_to_cpu(event_data->VolDevHandle);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306621 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306622 if (raid_device)
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306623 raid_device->percent_complete =
6624 event_data->PercentComplete;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306625 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05306626 }
Eric Moore635374e2009-03-09 01:21:12 -06006627}
6628
6629/**
Kashyap, Desai14695852010-03-30 10:52:44 +05306630 * _scsih_prep_device_scan - initialize parameters prior to device scan
6631 * @ioc: per adapter object
6632 *
6633 * Set the deleted flag prior to device scan. If the device is found during
6634 * the scan, then we clear the deleted flag.
6635 */
6636static void
6637_scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
6638{
6639 struct MPT2SAS_DEVICE *sas_device_priv_data;
6640 struct scsi_device *sdev;
6641
6642 shost_for_each_device(sdev, ioc->shost) {
6643 sas_device_priv_data = sdev->hostdata;
6644 if (sas_device_priv_data && sas_device_priv_data->sas_target)
6645 sas_device_priv_data->sas_target->deleted = 1;
6646 }
6647}
6648
6649/**
Eric Moore635374e2009-03-09 01:21:12 -06006650 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
6651 * @ioc: per adapter object
6652 * @sas_address: sas address
6653 * @slot: enclosure slot id
6654 * @handle: device handle
6655 *
6656 * After host reset, find out whether devices are still responding.
6657 * Used in _scsi_remove_unresponsive_sas_devices.
6658 *
6659 * Return nothing.
6660 */
6661static void
6662_scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6663 u16 slot, u16 handle)
6664{
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306665 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006666 struct scsi_target *starget;
6667 struct _sas_device *sas_device;
6668 unsigned long flags;
6669
6670 spin_lock_irqsave(&ioc->sas_device_lock, flags);
6671 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
6672 if (sas_device->sas_address == sas_address &&
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306673 sas_device->slot == slot) {
Eric Moore635374e2009-03-09 01:21:12 -06006674 sas_device->responding = 1;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05306675 starget = sas_device->starget;
Kashyap, Desai14695852010-03-30 10:52:44 +05306676 if (starget && starget->hostdata) {
6677 sas_target_priv_data = starget->hostdata;
6678 sas_target_priv_data->tm_busy = 0;
6679 sas_target_priv_data->deleted = 0;
6680 } else
6681 sas_target_priv_data = NULL;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306682 if (starget)
6683 starget_printk(KERN_INFO, starget,
6684 "handle(0x%04x), sas_addr(0x%016llx), "
6685 "enclosure logical id(0x%016llx), "
6686 "slot(%d)\n", handle,
6687 (unsigned long long)sas_device->sas_address,
6688 (unsigned long long)
6689 sas_device->enclosure_logical_id,
6690 sas_device->slot);
Eric Moore635374e2009-03-09 01:21:12 -06006691 if (sas_device->handle == handle)
6692 goto out;
6693 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6694 sas_device->handle);
6695 sas_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306696 if (sas_target_priv_data)
6697 sas_target_priv_data->handle = handle;
Eric Moore635374e2009-03-09 01:21:12 -06006698 goto out;
6699 }
6700 }
6701 out:
6702 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
6703}
6704
6705/**
6706 * _scsih_search_responding_sas_devices -
6707 * @ioc: per adapter object
6708 *
6709 * After host reset, find out whether devices are still responding.
6710 * If not remove.
6711 *
6712 * Return nothing.
6713 */
6714static void
6715_scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6716{
6717 Mpi2SasDevicePage0_t sas_device_pg0;
6718 Mpi2ConfigReply_t mpi_reply;
6719 u16 ioc_status;
6720 __le64 sas_address;
6721 u16 handle;
6722 u32 device_info;
6723 u16 slot;
6724
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306725 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006726
6727 if (list_empty(&ioc->sas_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306728 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006729
6730 handle = 0xFFFF;
6731 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
6732 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
6733 handle))) {
6734 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6735 MPI2_IOCSTATUS_MASK;
6736 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6737 break;
6738 handle = le16_to_cpu(sas_device_pg0.DevHandle);
6739 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
6740 if (!(_scsih_is_end_device(device_info)))
6741 continue;
6742 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
6743 slot = le16_to_cpu(sas_device_pg0.Slot);
6744 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6745 handle);
6746 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306747out:
6748 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6749 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006750}
6751
6752/**
6753 * _scsih_mark_responding_raid_device - mark a raid_device as responding
6754 * @ioc: per adapter object
6755 * @wwid: world wide identifier for raid volume
6756 * @handle: device handle
6757 *
6758 * After host reset, find out whether devices are still responding.
6759 * Used in _scsi_remove_unresponsive_raid_devices.
6760 *
6761 * Return nothing.
6762 */
6763static void
6764_scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
6765 u16 handle)
6766{
6767 struct MPT2SAS_TARGET *sas_target_priv_data;
6768 struct scsi_target *starget;
6769 struct _raid_device *raid_device;
6770 unsigned long flags;
6771
6772 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6773 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
6774 if (raid_device->wwid == wwid && raid_device->starget) {
Kashyap, Desai14695852010-03-30 10:52:44 +05306775 starget = raid_device->starget;
6776 if (starget && starget->hostdata) {
6777 sas_target_priv_data = starget->hostdata;
6778 sas_target_priv_data->deleted = 0;
6779 } else
6780 sas_target_priv_data = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06006781 raid_device->responding = 1;
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306782 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06006783 starget_printk(KERN_INFO, raid_device->starget,
6784 "handle(0x%04x), wwid(0x%016llx)\n", handle,
6785 (unsigned long long)raid_device->wwid);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306786 /*
6787 * WARPDRIVE: The handles of the PDs might have changed
6788 * across the host reset so re-initialize the
6789 * required data for Direct IO
6790 */
6791 _scsih_init_warpdrive_properties(ioc, raid_device);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306792 spin_lock_irqsave(&ioc->raid_device_lock, flags);
6793 if (raid_device->handle == handle) {
6794 spin_unlock_irqrestore(&ioc->raid_device_lock,
6795 flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306796 return;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306797 }
Eric Moore635374e2009-03-09 01:21:12 -06006798 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
6799 raid_device->handle);
6800 raid_device->handle = handle;
Kashyap, Desai14695852010-03-30 10:52:44 +05306801 if (sas_target_priv_data)
6802 sas_target_priv_data->handle = handle;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306803 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306804 return;
Eric Moore635374e2009-03-09 01:21:12 -06006805 }
6806 }
nagalakshmi.nandigama@lsi.com30c43282011-12-01 07:52:56 +05306807
Eric Moore635374e2009-03-09 01:21:12 -06006808 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
6809}
6810
6811/**
6812 * _scsih_search_responding_raid_devices -
6813 * @ioc: per adapter object
6814 *
6815 * After host reset, find out whether devices are still responding.
6816 * If not remove.
6817 *
6818 * Return nothing.
6819 */
6820static void
6821_scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6822{
6823 Mpi2RaidVolPage1_t volume_pg1;
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306824 Mpi2RaidVolPage0_t volume_pg0;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306825 Mpi2RaidPhysDiskPage0_t pd_pg0;
Eric Moore635374e2009-03-09 01:21:12 -06006826 Mpi2ConfigReply_t mpi_reply;
6827 u16 ioc_status;
6828 u16 handle;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306829 u8 phys_disk_num;
Eric Moore635374e2009-03-09 01:21:12 -06006830
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306831 if (!ioc->ir_firmware)
6832 return;
6833
6834 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6835 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006836
6837 if (list_empty(&ioc->raid_device_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306838 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006839
6840 handle = 0xFFFF;
6841 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6842 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6843 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6844 MPI2_IOCSTATUS_MASK;
6845 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6846 break;
6847 handle = le16_to_cpu(volume_pg1.DevHandle);
Kashyap, Desaid417d1c2010-06-17 13:48:10 +05306848
6849 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
6850 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
6851 sizeof(Mpi2RaidVolPage0_t)))
6852 continue;
6853
6854 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
6855 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
6856 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
6857 _scsih_mark_responding_raid_device(ioc,
6858 le64_to_cpu(volume_pg1.WWID), handle);
Eric Moore635374e2009-03-09 01:21:12 -06006859 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306860
6861 /* refresh the pd_handles */
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05306862 if (!ioc->is_warpdrive) {
6863 phys_disk_num = 0xFF;
6864 memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
6865 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
6866 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
6867 phys_disk_num))) {
6868 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6869 MPI2_IOCSTATUS_MASK;
6870 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6871 break;
6872 phys_disk_num = pd_pg0.PhysDiskNum;
6873 handle = le16_to_cpu(pd_pg0.DevHandle);
6874 set_bit(handle, ioc->pd_handles);
6875 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05306876 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306877out:
6878 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6879 "complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006880}
6881
6882/**
6883 * _scsih_mark_responding_expander - mark a expander as responding
6884 * @ioc: per adapter object
6885 * @sas_address: sas address
6886 * @handle:
6887 *
6888 * After host reset, find out whether devices are still responding.
6889 * Used in _scsi_remove_unresponsive_expanders.
6890 *
6891 * Return nothing.
6892 */
6893static void
6894_scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
6895 u16 handle)
6896{
6897 struct _sas_node *sas_expander;
6898 unsigned long flags;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306899 int i;
Eric Moore635374e2009-03-09 01:21:12 -06006900
6901 spin_lock_irqsave(&ioc->sas_node_lock, flags);
6902 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306903 if (sas_expander->sas_address != sas_address)
6904 continue;
6905 sas_expander->responding = 1;
6906 if (sas_expander->handle == handle)
Eric Moore635374e2009-03-09 01:21:12 -06006907 goto out;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05306908 printk(KERN_INFO "\texpander(0x%016llx): handle changed"
6909 " from(0x%04x) to (0x%04x)!!!\n",
6910 (unsigned long long)sas_expander->sas_address,
6911 sas_expander->handle, handle);
6912 sas_expander->handle = handle;
6913 for (i = 0 ; i < sas_expander->num_phys ; i++)
6914 sas_expander->phy[i].handle = handle;
6915 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006916 }
6917 out:
6918 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
6919}
6920
6921/**
6922 * _scsih_search_responding_expanders -
6923 * @ioc: per adapter object
6924 *
6925 * After host reset, find out whether devices are still responding.
6926 * If not remove.
6927 *
6928 * Return nothing.
6929 */
6930static void
6931_scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6932{
6933 Mpi2ExpanderPage0_t expander_pg0;
6934 Mpi2ConfigReply_t mpi_reply;
6935 u16 ioc_status;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05306936 u64 sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06006937 u16 handle;
6938
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306939 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006940
6941 if (list_empty(&ioc->sas_expander_list))
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306942 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06006943
6944 handle = 0xFFFF;
6945 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6946 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6947
6948 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6949 MPI2_IOCSTATUS_MASK;
6950 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6951 break;
6952
6953 handle = le16_to_cpu(expander_pg0.DevHandle);
6954 sas_address = le64_to_cpu(expander_pg0.SASAddress);
6955 printk(KERN_INFO "\texpander present: handle(0x%04x), "
6956 "sas_addr(0x%016llx)\n", handle,
6957 (unsigned long long)sas_address);
6958 _scsih_mark_responding_expander(ioc, sas_address, handle);
6959 }
6960
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306961 out:
6962 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006963}
6964
6965/**
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306966 * _scsih_remove_unresponding_sas_devices - removing unresponding devices
Eric Moore635374e2009-03-09 01:21:12 -06006967 * @ioc: per adapter object
6968 *
6969 * Return nothing.
6970 */
6971static void
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05306972_scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
Eric Moore635374e2009-03-09 01:21:12 -06006973{
6974 struct _sas_device *sas_device, *sas_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306975 struct _sas_node *sas_expander, *sas_expander_next;
Eric Moore635374e2009-03-09 01:21:12 -06006976 struct _raid_device *raid_device, *raid_device_next;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306977 struct list_head tmp_list;
6978 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06006979
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05306980 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
6981 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006982
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306983 /* removing unresponding end devices */
6984 printk(MPT2SAS_INFO_FMT "removing unresponding devices: end-devices\n",
6985 ioc->name);
Eric Moore635374e2009-03-09 01:21:12 -06006986 list_for_each_entry_safe(sas_device, sas_device_next,
6987 &ioc->sas_device_list, list) {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306988 if (!sas_device->responding)
6989 _scsih_device_remove_by_handle(ioc,
6990 sas_device->handle);
6991 else
Eric Moore635374e2009-03-09 01:21:12 -06006992 sas_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06006993 }
6994
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05306995 /* removing unresponding volumes */
6996 if (ioc->ir_firmware) {
6997 printk(MPT2SAS_INFO_FMT "removing unresponding devices: "
6998 "volumes\n", ioc->name);
6999 list_for_each_entry_safe(raid_device, raid_device_next,
7000 &ioc->raid_device_list, list) {
7001 if (!raid_device->responding)
7002 _scsih_sas_volume_delete(ioc,
7003 raid_device->handle);
7004 else
7005 raid_device->responding = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007006 }
Eric Moore635374e2009-03-09 01:21:12 -06007007 }
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307008 /* removing unresponding expanders */
7009 printk(MPT2SAS_INFO_FMT "removing unresponding devices: expanders\n",
7010 ioc->name);
7011 spin_lock_irqsave(&ioc->sas_node_lock, flags);
7012 INIT_LIST_HEAD(&tmp_list);
7013 list_for_each_entry_safe(sas_expander, sas_expander_next,
7014 &ioc->sas_expander_list, list) {
7015 if (!sas_expander->responding)
7016 list_move_tail(&sas_expander->list, &tmp_list);
7017 else
Eric Moore635374e2009-03-09 01:21:12 -06007018 sas_expander->responding = 0;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307019 }
7020 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
7021 list_for_each_entry_safe(sas_expander, sas_expander_next, &tmp_list,
7022 list) {
7023 list_del(&sas_expander->list);
7024 _scsih_expander_node_remove(ioc, sas_expander);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307025 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307026 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
7027 ioc->name);
7028 /* unblock devices */
7029 _scsih_ublock_io_all_device(ioc);
7030}
7031
7032static void
7033_scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
7034 struct _sas_node *sas_expander, u16 handle)
7035{
7036 Mpi2ExpanderPage1_t expander_pg1;
7037 Mpi2ConfigReply_t mpi_reply;
7038 int i;
7039
7040 for (i = 0 ; i < sas_expander->num_phys ; i++) {
7041 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
7042 &expander_pg1, i, handle))) {
7043 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7044 ioc->name, __FILE__, __LINE__, __func__);
7045 return;
7046 }
7047
7048 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
7049 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
7050 expander_pg1.NegotiatedLinkRate >> 4);
7051 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307052}
7053
7054/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307055 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307056 * @ioc: per adapter object
7057 *
7058 * Return nothing.
7059 */
7060static void
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307061_scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307062{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307063 Mpi2ExpanderPage0_t expander_pg0;
7064 Mpi2SasDevicePage0_t sas_device_pg0;
7065 Mpi2RaidVolPage1_t volume_pg1;
7066 Mpi2RaidVolPage0_t volume_pg0;
7067 Mpi2RaidPhysDiskPage0_t pd_pg0;
7068 Mpi2EventIrConfigElement_t element;
7069 Mpi2ConfigReply_t mpi_reply;
7070 u8 phys_disk_num;
7071 u16 ioc_status;
7072 u16 handle, parent_handle;
7073 u64 sas_address;
7074 struct _sas_device *sas_device;
7075 struct _sas_node *expander_device;
7076 static struct _raid_device *raid_device;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307077 unsigned long flags;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307078
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307079 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307080
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307081 _scsih_sas_host_refresh(ioc);
7082
7083 /* expanders */
7084 handle = 0xFFFF;
7085 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
7086 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
7087 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7088 MPI2_IOCSTATUS_MASK;
7089 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7090 break;
7091 handle = le16_to_cpu(expander_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307092 spin_lock_irqsave(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307093 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
7094 ioc, le64_to_cpu(expander_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307095 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307096 if (expander_device)
7097 _scsih_refresh_expander_links(ioc, expander_device,
7098 handle);
7099 else
7100 _scsih_expander_add(ioc, handle);
7101 }
7102
7103 if (!ioc->ir_firmware)
7104 goto skip_to_sas;
7105
7106 /* phys disk */
7107 phys_disk_num = 0xFF;
7108 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7109 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7110 phys_disk_num))) {
7111 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7112 MPI2_IOCSTATUS_MASK;
7113 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7114 break;
7115 phys_disk_num = pd_pg0.PhysDiskNum;
7116 handle = le16_to_cpu(pd_pg0.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307117 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307118 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307119 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307120 if (sas_device)
7121 continue;
7122 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7123 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7124 handle) != 0)
7125 continue;
7126 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7127 if (!_scsih_get_sas_address(ioc, parent_handle,
7128 &sas_address)) {
7129 mpt2sas_transport_update_links(ioc, sas_address,
7130 handle, sas_device_pg0.PhyNum,
7131 MPI2_SAS_NEG_LINK_RATE_1_5);
7132 set_bit(handle, ioc->pd_handles);
7133 _scsih_add_device(ioc, handle, 0, 1);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307134 }
7135 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307136
7137 /* volumes */
7138 handle = 0xFFFF;
7139 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
7140 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
7141 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7142 MPI2_IOCSTATUS_MASK;
7143 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7144 break;
7145 handle = le16_to_cpu(volume_pg1.DevHandle);
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307146 spin_lock_irqsave(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307147 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7148 le64_to_cpu(volume_pg1.WWID));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307149 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307150 if (raid_device)
7151 continue;
7152 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7153 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7154 sizeof(Mpi2RaidVolPage0_t)))
7155 continue;
7156 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7157 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7158 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7159 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7160 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7161 element.VolDevHandle = volume_pg1.DevHandle;
7162 _scsih_sas_volume_add(ioc, &element);
7163 }
7164 }
7165
7166 skip_to_sas:
7167
7168 /* sas devices */
7169 handle = 0xFFFF;
7170 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7171 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7172 handle))) {
7173 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7174 MPI2_IOCSTATUS_MASK;
7175 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7176 break;
7177 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7178 if (!(_scsih_is_end_device(
7179 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7180 continue;
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307181 spin_lock_irqsave(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307182 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7183 le64_to_cpu(sas_device_pg0.SASAddress));
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307184 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307185 if (sas_device)
7186 continue;
7187 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7188 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7189 mpt2sas_transport_update_links(ioc, sas_address, handle,
7190 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7191 _scsih_add_device(ioc, handle, 0, 0);
7192 }
7193 }
7194
7195 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307196}
7197
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307198
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307199/**
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307200 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
7201 * @ioc: per adapter object
7202 * @reset_phase: phase
7203 *
7204 * The handler for doing any required cleanup or initialization.
7205 *
7206 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
7207 * MPT2_IOC_DONE_RESET
7208 *
7209 * Return nothing.
7210 */
7211void
7212mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
7213{
7214 switch (reset_phase) {
7215 case MPT2_IOC_PRE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307216 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307217 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307218 break;
7219 case MPT2_IOC_AFTER_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307220 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307221 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307222 if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
7223 ioc->scsih_cmds.status |= MPT2_CMD_RESET;
7224 mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
7225 complete(&ioc->scsih_cmds.done);
7226 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307227 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
7228 ioc->tm_cmds.status |= MPT2_CMD_RESET;
7229 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
7230 complete(&ioc->tm_cmds.done);
7231 }
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307232 _scsih_fw_event_cleanup_queue(ioc);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307233 _scsih_flush_running_cmds(ioc);
7234 break;
7235 case MPT2_IOC_DONE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05307236 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307237 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307238 _scsih_sas_host_refresh(ioc);
Kashyap, Desai14695852010-03-30 10:52:44 +05307239 _scsih_prep_device_scan(ioc);
7240 _scsih_search_responding_sas_devices(ioc);
7241 _scsih_search_responding_raid_devices(ioc);
7242 _scsih_search_responding_expanders(ioc);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307243 if (!ioc->is_driver_loading) {
7244 _scsih_prep_device_scan(ioc);
7245 _scsih_search_responding_sas_devices(ioc);
7246 _scsih_search_responding_raid_devices(ioc);
7247 _scsih_search_responding_expanders(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307248 _scsih_error_recovery_delete_devices(ioc);
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307249 }
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05307250 break;
Eric Moore635374e2009-03-09 01:21:12 -06007251 }
7252}
7253
7254/**
7255 * _firmware_event_work - delayed task for processing firmware events
7256 * @ioc: per adapter object
7257 * @work: equal to the fw_event_work object
7258 * Context: user.
7259 *
7260 * Return nothing.
7261 */
7262static void
7263_firmware_event_work(struct work_struct *work)
7264{
7265 struct fw_event_work *fw_event = container_of(work,
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307266 struct fw_event_work, delayed_work.work);
Eric Moore635374e2009-03-09 01:21:12 -06007267 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
7268
Eric Moore635374e2009-03-09 01:21:12 -06007269 /* the queue is being flushed so ignore this event */
Eric Moore3cb54692010-07-08 14:44:34 -06007270 if (ioc->remove_host || fw_event->cancel_pending_work ||
7271 ioc->pci_error_recovery) {
Eric Moore635374e2009-03-09 01:21:12 -06007272 _scsih_fw_event_free(ioc, fw_event);
7273 return;
7274 }
Eric Moore635374e2009-03-09 01:21:12 -06007275
Eric Moore635374e2009-03-09 01:21:12 -06007276 switch (fw_event->event) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307277 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307278 while (scsi_host_in_recovery(ioc->shost) || ioc->shost_recovery)
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307279 ssleep(1);
7280 _scsih_remove_unresponding_sas_devices(ioc);
7281 _scsih_scan_for_devices_after_reset(ioc);
7282 break;
7283 case MPT2SAS_PORT_ENABLE_COMPLETE:
nagalakshmi.nandigama@lsi.com918134e2011-10-19 15:37:24 +05307284 ioc->start_scan = 0;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307285
7286
7287
7288 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7289 "from worker thread\n", ioc->name));
7290 break;
Kashyap, Desai3ace8e02011-05-04 16:35:58 +05307291 case MPT2SAS_TURN_ON_FAULT_LED:
7292 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
7293 break;
Eric Moore635374e2009-03-09 01:21:12 -06007294 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307295 _scsih_sas_topology_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007296 break;
7297 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307298 _scsih_sas_device_status_change_event(ioc,
7299 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007300 break;
7301 case MPI2_EVENT_SAS_DISCOVERY:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307302 _scsih_sas_discovery_event(ioc,
7303 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007304 break;
7305 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
Andrew Mortona78e21d2012-02-08 12:52:22 -08007306 _scsih_sas_broadcast_primitive_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307307 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007308 break;
7309 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
7310 _scsih_sas_enclosure_dev_status_change_event(ioc,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307311 fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007312 break;
7313 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307314 _scsih_sas_ir_config_change_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007315 break;
7316 case MPI2_EVENT_IR_VOLUME:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307317 _scsih_sas_ir_volume_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007318 break;
7319 case MPI2_EVENT_IR_PHYSICAL_DISK:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307320 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007321 break;
7322 case MPI2_EVENT_IR_OPERATION_STATUS:
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307323 _scsih_sas_ir_operation_status_event(ioc, fw_event);
Eric Moore635374e2009-03-09 01:21:12 -06007324 break;
Eric Moore635374e2009-03-09 01:21:12 -06007325 }
7326 _scsih_fw_event_free(ioc, fw_event);
7327}
7328
7329/**
7330 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
7331 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307332 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -06007333 * @reply: reply message frame(lower 32bit addr)
7334 * Context: interrupt.
7335 *
7336 * This function merely adds a new work task into ioc->firmware_event_thread.
7337 * The tasks are worked from _firmware_event_work in user context.
7338 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307339 * Return 1 meaning mf should be freed from _base_interrupt
7340 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -06007341 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307342u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307343mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
7344 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -06007345{
7346 struct fw_event_work *fw_event;
7347 Mpi2EventNotificationReply_t *mpi_reply;
Eric Moore635374e2009-03-09 01:21:12 -06007348 u16 event;
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307349 u16 sz;
Eric Moore635374e2009-03-09 01:21:12 -06007350
7351 /* events turned off due to host reset or driver unloading */
Eric Moore3cb54692010-07-08 14:44:34 -06007352 if (ioc->remove_host || ioc->pci_error_recovery)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307353 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007354
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307355 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
Eric Moore635374e2009-03-09 01:21:12 -06007356 event = le16_to_cpu(mpi_reply->Event);
7357
7358 switch (event) {
7359 /* handle these */
7360 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
7361 {
7362 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
7363 (Mpi2EventDataSasBroadcastPrimitive_t *)
7364 mpi_reply->EventData;
7365
7366 if (baen_data->Primitive !=
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307367 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307368 return 1;
Kashyap, Desaif93213d2011-06-14 10:56:43 +05307369
7370 if (ioc->broadcast_aen_busy) {
7371 ioc->broadcast_aen_pending++;
7372 return 1;
7373 } else
7374 ioc->broadcast_aen_busy = 1;
Eric Moore635374e2009-03-09 01:21:12 -06007375 break;
7376 }
7377
7378 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
7379 _scsih_check_topo_delete_events(ioc,
7380 (Mpi2EventDataSasTopologyChangeList_t *)
7381 mpi_reply->EventData);
7382 break;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05307383 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
7384 _scsih_check_ir_config_unhide_events(ioc,
7385 (Mpi2EventDataIrConfigChangeList_t *)
7386 mpi_reply->EventData);
7387 break;
7388 case MPI2_EVENT_IR_VOLUME:
7389 _scsih_check_volume_delete_events(ioc,
7390 (Mpi2EventDataIrVolume_t *)
7391 mpi_reply->EventData);
7392 break;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307393 case MPI2_EVENT_LOG_ENTRY_ADDED:
7394 {
7395 Mpi2EventDataLogEntryAdded_t *log_entry;
7396 u32 *log_code;
7397
7398 if (!ioc->is_warpdrive)
7399 break;
7400
7401 log_entry = (Mpi2EventDataLogEntryAdded_t *)
7402 mpi_reply->EventData;
7403 log_code = (u32 *)log_entry->LogData;
7404
7405 if (le16_to_cpu(log_entry->LogEntryQualifier)
7406 != MPT2_WARPDRIVE_LOGENTRY)
7407 break;
7408
7409 switch (le32_to_cpu(*log_code)) {
7410 case MPT2_WARPDRIVE_LC_SSDT:
7411 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7412 "IO Throttling has occurred in the WarpDrive "
7413 "subsystem. Check WarpDrive documentation for "
7414 "additional details.\n", ioc->name);
7415 break;
7416 case MPT2_WARPDRIVE_LC_SSDLW:
7417 printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
7418 "Program/Erase Cycles for the WarpDrive subsystem "
7419 "in degraded range. Check WarpDrive documentation "
7420 "for additional details.\n", ioc->name);
7421 break;
7422 case MPT2_WARPDRIVE_LC_SSDLF:
7423 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7424 "There are no Program/Erase Cycles for the "
7425 "WarpDrive subsystem. The storage device will be "
7426 "in read-only mode. Check WarpDrive documentation "
7427 "for additional details.\n", ioc->name);
7428 break;
7429 case MPT2_WARPDRIVE_LC_BRMF:
7430 printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
7431 "The Backup Rail Monitor has failed on the "
7432 "WarpDrive subsystem. Check WarpDrive "
7433 "documentation for additional details.\n",
7434 ioc->name);
7435 break;
7436 }
7437
7438 break;
7439 }
Eric Moore635374e2009-03-09 01:21:12 -06007440 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
7441 case MPI2_EVENT_IR_OPERATION_STATUS:
7442 case MPI2_EVENT_SAS_DISCOVERY:
7443 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
Eric Moore635374e2009-03-09 01:21:12 -06007444 case MPI2_EVENT_IR_PHYSICAL_DISK:
Eric Moore635374e2009-03-09 01:21:12 -06007445 break;
7446
7447 default: /* ignore the rest */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307448 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007449 }
7450
7451 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
7452 if (!fw_event) {
7453 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7454 ioc->name, __FILE__, __LINE__, __func__);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307455 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007456 }
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307457 sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
7458 fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
Eric Moore635374e2009-03-09 01:21:12 -06007459 if (!fw_event->event_data) {
7460 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7461 ioc->name, __FILE__, __LINE__, __func__);
7462 kfree(fw_event);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307463 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007464 }
7465
7466 memcpy(fw_event->event_data, mpi_reply->EventData,
Kashyap, Desaie94f6742010-03-17 16:24:52 +05307467 sz);
Eric Moore635374e2009-03-09 01:21:12 -06007468 fw_event->ioc = ioc;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05307469 fw_event->VF_ID = mpi_reply->VF_ID;
7470 fw_event->VP_ID = mpi_reply->VP_ID;
Eric Moore635374e2009-03-09 01:21:12 -06007471 fw_event->event = event;
7472 _scsih_fw_event_add(ioc, fw_event);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307473 return 1;
Eric Moore635374e2009-03-09 01:21:12 -06007474}
7475
7476/* shost template */
7477static struct scsi_host_template scsih_driver_template = {
7478 .module = THIS_MODULE,
7479 .name = "Fusion MPT SAS Host",
7480 .proc_name = MPT2SAS_DRIVER_NAME,
Eric Moored5d135b2009-05-18 13:02:08 -06007481 .queuecommand = _scsih_qcmd,
7482 .target_alloc = _scsih_target_alloc,
7483 .slave_alloc = _scsih_slave_alloc,
7484 .slave_configure = _scsih_slave_configure,
7485 .target_destroy = _scsih_target_destroy,
7486 .slave_destroy = _scsih_slave_destroy,
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307487 .scan_finished = _scsih_scan_finished,
7488 .scan_start = _scsih_scan_start,
Eric Moored5d135b2009-05-18 13:02:08 -06007489 .change_queue_depth = _scsih_change_queue_depth,
7490 .change_queue_type = _scsih_change_queue_type,
7491 .eh_abort_handler = _scsih_abort,
7492 .eh_device_reset_handler = _scsih_dev_reset,
7493 .eh_target_reset_handler = _scsih_target_reset,
7494 .eh_host_reset_handler = _scsih_host_reset,
7495 .bios_param = _scsih_bios_param,
Eric Moore635374e2009-03-09 01:21:12 -06007496 .can_queue = 1,
7497 .this_id = -1,
7498 .sg_tablesize = MPT2SAS_SG_DEPTH,
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05307499 .max_sectors = 32767,
Eric Moore635374e2009-03-09 01:21:12 -06007500 .cmd_per_lun = 7,
7501 .use_clustering = ENABLE_CLUSTERING,
7502 .shost_attrs = mpt2sas_host_attrs,
7503 .sdev_attrs = mpt2sas_dev_attrs,
7504};
7505
7506/**
7507 * _scsih_expander_node_remove - removing expander device from list.
7508 * @ioc: per adapter object
7509 * @sas_expander: the sas_device object
7510 * Context: Calling function should acquire ioc->sas_node_lock.
7511 *
7512 * Removing object and freeing associated memory from the
7513 * ioc->sas_expander_list.
7514 *
7515 * Return nothing.
7516 */
7517static void
7518_scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
7519 struct _sas_node *sas_expander)
7520{
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307521 struct _sas_port *mpt2sas_port, *next;
Eric Moore635374e2009-03-09 01:21:12 -06007522
7523 /* remove sibling ports attached to this expander */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307524 list_for_each_entry_safe(mpt2sas_port, next,
Eric Moore635374e2009-03-09 01:21:12 -06007525 &sas_expander->sas_port_list, port_list) {
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307526 if (ioc->shost_recovery)
7527 return;
Eric Moore635374e2009-03-09 01:21:12 -06007528 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307529 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307530 mpt2sas_device_remove_by_sas_address(ioc,
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307531 mpt2sas_port->remote_identify.sas_address);
7532 else if (mpt2sas_port->remote_identify.device_type ==
7533 SAS_EDGE_EXPANDER_DEVICE ||
Eric Moore635374e2009-03-09 01:21:12 -06007534 mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307535 SAS_FANOUT_EXPANDER_DEVICE)
7536 mpt2sas_expander_remove(ioc,
7537 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007538 }
7539
7540 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307541 sas_expander->sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007542
7543 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
7544 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
7545 sas_expander->handle, (unsigned long long)
7546 sas_expander->sas_address);
7547
Eric Moore635374e2009-03-09 01:21:12 -06007548 kfree(sas_expander->phy);
7549 kfree(sas_expander);
7550}
7551
7552/**
Kashyap, Desai744090d2009-10-05 15:56:56 +05307553 * _scsih_ir_shutdown - IR shutdown notification
7554 * @ioc: per adapter object
7555 *
7556 * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
7557 * the host system is shutting down.
7558 *
7559 * Return nothing.
7560 */
7561static void
7562_scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
7563{
7564 Mpi2RaidActionRequest_t *mpi_request;
7565 Mpi2RaidActionReply_t *mpi_reply;
7566 u16 smid;
7567
7568 /* is IR firmware build loaded ? */
7569 if (!ioc->ir_firmware)
7570 return;
7571
7572 /* are there any volumes ? */
7573 if (list_empty(&ioc->raid_device_list))
7574 return;
7575
7576 mutex_lock(&ioc->scsih_cmds.mutex);
7577
7578 if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
7579 printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
7580 ioc->name, __func__);
7581 goto out;
7582 }
7583 ioc->scsih_cmds.status = MPT2_CMD_PENDING;
7584
7585 smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
7586 if (!smid) {
7587 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
7588 ioc->name, __func__);
7589 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7590 goto out;
7591 }
7592
7593 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
7594 ioc->scsih_cmds.smid = smid;
7595 memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
7596
7597 mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
7598 mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
7599
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307600 if (!ioc->hide_ir_msg)
7601 printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307602 init_completion(&ioc->scsih_cmds.done);
7603 mpt2sas_base_put_smid_default(ioc, smid);
7604 wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
7605
7606 if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
7607 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
7608 ioc->name, __func__);
7609 goto out;
7610 }
7611
7612 if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
7613 mpi_reply = ioc->scsih_cmds.reply;
7614
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307615 if (!ioc->hide_ir_msg)
7616 printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
7617 "ioc_status(0x%04x), loginfo(0x%08x)\n",
7618 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
7619 le32_to_cpu(mpi_reply->IOCLogInfo));
Kashyap, Desai744090d2009-10-05 15:56:56 +05307620 }
7621
7622 out:
7623 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
7624 mutex_unlock(&ioc->scsih_cmds.mutex);
7625}
7626
7627/**
7628 * _scsih_shutdown - routine call during system shutdown
7629 * @pdev: PCI device struct
7630 *
7631 * Return nothing.
7632 */
7633static void
7634_scsih_shutdown(struct pci_dev *pdev)
7635{
7636 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7637 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307638 struct workqueue_struct *wq;
7639 unsigned long flags;
7640
7641 ioc->remove_host = 1;
7642 _scsih_fw_event_cleanup_queue(ioc);
7643
7644 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7645 wq = ioc->firmware_event_thread;
7646 ioc->firmware_event_thread = NULL;
7647 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7648 if (wq)
7649 destroy_workqueue(wq);
Kashyap, Desai744090d2009-10-05 15:56:56 +05307650
7651 _scsih_ir_shutdown(ioc);
7652 mpt2sas_base_detach(ioc);
7653}
7654
7655/**
Eric Moored5d135b2009-05-18 13:02:08 -06007656 * _scsih_remove - detach and remove add host
Eric Moore635374e2009-03-09 01:21:12 -06007657 * @pdev: PCI device struct
7658 *
Kashyap, Desai744090d2009-10-05 15:56:56 +05307659 * Routine called when unloading the driver.
Eric Moore635374e2009-03-09 01:21:12 -06007660 * Return nothing.
7661 */
7662static void __devexit
Eric Moored5d135b2009-05-18 13:02:08 -06007663_scsih_remove(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06007664{
7665 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7666 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307667 struct _sas_port *mpt2sas_port, *next_port;
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307668 struct _raid_device *raid_device, *next;
7669 struct MPT2SAS_TARGET *sas_target_priv_data;
Eric Moore635374e2009-03-09 01:21:12 -06007670 struct workqueue_struct *wq;
7671 unsigned long flags;
7672
7673 ioc->remove_host = 1;
Kashyap, Desaif1c35e62010-03-09 16:31:43 +05307674 _scsih_fw_event_cleanup_queue(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007675
7676 spin_lock_irqsave(&ioc->fw_event_lock, flags);
7677 wq = ioc->firmware_event_thread;
7678 ioc->firmware_event_thread = NULL;
7679 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
7680 if (wq)
7681 destroy_workqueue(wq);
7682
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307683 /* release all the volumes */
Kashyap, Desai3a9c9132011-01-04 11:40:23 +05307684 _scsih_ir_shutdown(ioc);
Kashyap, Desaid7384b22009-12-16 18:50:06 +05307685 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
7686 list) {
7687 if (raid_device->starget) {
7688 sas_target_priv_data =
7689 raid_device->starget->hostdata;
7690 sas_target_priv_data->deleted = 1;
7691 scsi_remove_target(&raid_device->starget->dev);
7692 }
7693 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
7694 "(0x%016llx)\n", ioc->name, raid_device->handle,
7695 (unsigned long long) raid_device->wwid);
7696 _scsih_raid_device_remove(ioc, raid_device);
7697 }
7698
Eric Moore635374e2009-03-09 01:21:12 -06007699 /* free ports attached to the sas_host */
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307700 list_for_each_entry_safe(mpt2sas_port, next_port,
Eric Moore635374e2009-03-09 01:21:12 -06007701 &ioc->sas_hba.sas_port_list, port_list) {
7702 if (mpt2sas_port->remote_identify.device_type ==
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307703 SAS_END_DEVICE)
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307704 mpt2sas_device_remove_by_sas_address(ioc,
Eric Moore635374e2009-03-09 01:21:12 -06007705 mpt2sas_port->remote_identify.sas_address);
Kashyap, Desai7f6f7942010-11-13 04:35:30 +05307706 else if (mpt2sas_port->remote_identify.device_type ==
7707 SAS_EDGE_EXPANDER_DEVICE ||
7708 mpt2sas_port->remote_identify.device_type ==
7709 SAS_FANOUT_EXPANDER_DEVICE)
7710 mpt2sas_expander_remove(ioc,
7711 mpt2sas_port->remote_identify.sas_address);
Eric Moore635374e2009-03-09 01:21:12 -06007712 }
7713
7714 /* free phys attached to the sas_host */
7715 if (ioc->sas_hba.num_phys) {
7716 kfree(ioc->sas_hba.phy);
7717 ioc->sas_hba.phy = NULL;
7718 ioc->sas_hba.num_phys = 0;
7719 }
7720
7721 sas_remove_host(shost);
kashyap.desai@lsi.com9ae89b02011-08-04 16:47:50 +05307722 mpt2sas_base_detach(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007723 list_del(&ioc->list);
7724 scsi_remove_host(shost);
7725 scsi_host_put(shost);
7726}
7727
7728/**
7729 * _scsih_probe_boot_devices - reports 1st device
7730 * @ioc: per adapter object
7731 *
7732 * If specified in bios page 2, this routine reports the 1st
7733 * device scsi-ml or sas transport for persistent boot device
7734 * purposes. Please refer to function _scsih_determine_boot_device()
7735 */
7736static void
7737_scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7738{
7739 u8 is_raid;
7740 void *device;
7741 struct _sas_device *sas_device;
7742 struct _raid_device *raid_device;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307743 u16 handle;
7744 u64 sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007745 u64 sas_address;
7746 unsigned long flags;
7747 int rc;
7748
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307749 /* no Bios, return immediately */
7750 if (!ioc->bios_pg3.BiosVersion)
7751 return;
7752
Eric Moore635374e2009-03-09 01:21:12 -06007753 device = NULL;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307754 is_raid = 0;
Eric Moore635374e2009-03-09 01:21:12 -06007755 if (ioc->req_boot_device.device) {
7756 device = ioc->req_boot_device.device;
7757 is_raid = ioc->req_boot_device.is_raid;
7758 } else if (ioc->req_alt_boot_device.device) {
7759 device = ioc->req_alt_boot_device.device;
7760 is_raid = ioc->req_alt_boot_device.is_raid;
7761 } else if (ioc->current_boot_device.device) {
7762 device = ioc->current_boot_device.device;
7763 is_raid = ioc->current_boot_device.is_raid;
7764 }
7765
7766 if (!device)
7767 return;
7768
7769 if (is_raid) {
7770 raid_device = device;
7771 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7772 raid_device->id, 0);
7773 if (rc)
7774 _scsih_raid_device_remove(ioc, raid_device);
7775 } else {
nagalakshmi.nandigama@lsi.com09da0b32012-03-20 12:06:50 +05307776 spin_lock_irqsave(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007777 sas_device = device;
7778 handle = sas_device->handle;
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307779 sas_address_parent = sas_device->sas_address_parent;
Eric Moore635374e2009-03-09 01:21:12 -06007780 sas_address = sas_device->sas_address;
Eric Moore635374e2009-03-09 01:21:12 -06007781 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7782 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307783
7784 if (ioc->hide_drives)
7785 return;
Eric Moore635374e2009-03-09 01:21:12 -06007786 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307787 sas_device->sas_address_parent)) {
Eric Moore635374e2009-03-09 01:21:12 -06007788 _scsih_sas_device_remove(ioc, sas_device);
7789 } else if (!sas_device->starget) {
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307790 if (!ioc->is_driver_loading)
7791 mpt2sas_transport_port_remove(ioc, sas_address,
7792 sas_address_parent);
Eric Moore635374e2009-03-09 01:21:12 -06007793 _scsih_sas_device_remove(ioc, sas_device);
7794 }
7795 }
7796}
7797
7798/**
7799 * _scsih_probe_raid - reporting raid volumes to scsi-ml
7800 * @ioc: per adapter object
7801 *
7802 * Called during initial loading of the driver.
7803 */
7804static void
7805_scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
7806{
7807 struct _raid_device *raid_device, *raid_next;
7808 int rc;
7809
7810 list_for_each_entry_safe(raid_device, raid_next,
7811 &ioc->raid_device_list, list) {
7812 if (raid_device->starget)
7813 continue;
7814 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
7815 raid_device->id, 0);
7816 if (rc)
7817 _scsih_raid_device_remove(ioc, raid_device);
7818 }
7819}
7820
7821/**
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05307822 * _scsih_probe_sas - reporting sas devices to sas transport
Eric Moore635374e2009-03-09 01:21:12 -06007823 * @ioc: per adapter object
7824 *
7825 * Called during initial loading of the driver.
7826 */
7827static void
7828_scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7829{
7830 struct _sas_device *sas_device, *next;
7831 unsigned long flags;
Eric Moore635374e2009-03-09 01:21:12 -06007832
7833 /* SAS Device List */
7834 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7835 list) {
Eric Moore635374e2009-03-09 01:21:12 -06007836
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307837 if (ioc->hide_drives)
7838 continue;
7839
Kashyap, Desaic5e039b2009-09-23 17:21:29 +05307840 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7841 sas_device->sas_address_parent)) {
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307842 list_del(&sas_device->list);
7843 kfree(sas_device);
7844 continue;
Eric Moore635374e2009-03-09 01:21:12 -06007845 } else if (!sas_device->starget) {
nagalakshmi.nandigama@lsi.com35116db2011-10-21 10:08:07 +05307846 if (!ioc->is_driver_loading)
7847 mpt2sas_transport_port_remove(ioc,
7848 sas_device->sas_address,
7849 sas_device->sas_address_parent);
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307850 list_del(&sas_device->list);
7851 kfree(sas_device);
7852 continue;
7853
Eric Moore635374e2009-03-09 01:21:12 -06007854 }
nagalakshmi.nandigama@lsi.com0167ac62011-10-21 10:06:33 +05307855 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7856 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7857 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06007858 }
7859}
7860
7861/**
7862 * _scsih_probe_devices - probing for devices
7863 * @ioc: per adapter object
7864 *
7865 * Called during initial loading of the driver.
7866 */
7867static void
7868_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7869{
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307870 u16 volume_mapping_flags;
Eric Moore635374e2009-03-09 01:21:12 -06007871
7872 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7873 return; /* return when IOC doesn't support initiator mode */
7874
7875 _scsih_probe_boot_devices(ioc);
7876
7877 if (ioc->ir_firmware) {
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307878 volume_mapping_flags =
7879 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7880 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7881 if (volume_mapping_flags ==
7882 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
Eric Moore635374e2009-03-09 01:21:12 -06007883 _scsih_probe_raid(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307884 _scsih_probe_sas(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007885 } else {
Eric Moore635374e2009-03-09 01:21:12 -06007886 _scsih_probe_sas(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307887 _scsih_probe_raid(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06007888 }
7889 } else
7890 _scsih_probe_sas(ioc);
7891}
7892
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05307893
7894/**
7895 * _scsih_scan_start - scsi lld callback for .scan_start
7896 * @shost: SCSI host pointer
7897 *
7898 * The shost has the ability to discover targets on its own instead
7899 * of scanning the entire bus. In our implemention, we will kick off
7900 * firmware discovery.
7901 */
7902static void
7903_scsih_scan_start(struct Scsi_Host *shost)
7904{
7905 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7906 int rc;
7907
7908 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7909 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
7910
7911 ioc->start_scan = 1;
7912 rc = mpt2sas_port_enable(ioc);
7913
7914 if (rc != 0)
7915 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
7916}
7917
7918/**
7919 * _scsih_scan_finished - scsi lld callback for .scan_finished
7920 * @shost: SCSI host pointer
7921 * @time: elapsed time of the scan in jiffies
7922 *
7923 * This function will be called periodically until it returns 1 with the
7924 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7925 * we wait for firmware discovery to complete, then return 1.
7926 */
7927static int
7928_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7929{
7930 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7931
7932 if (time >= (300 * HZ)) {
7933 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7934 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
7935 "(timeout=300s)\n", ioc->name);
7936 ioc->is_driver_loading = 0;
7937 return 1;
7938 }
7939
7940 if (ioc->start_scan)
7941 return 0;
7942
7943 if (ioc->start_scan_failed) {
7944 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
7945 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
7946 ioc->is_driver_loading = 0;
7947 ioc->wait_for_discovery_to_complete = 0;
7948 ioc->remove_host = 1;
7949 return 1;
7950 }
7951
7952 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
7953 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7954
7955 if (ioc->wait_for_discovery_to_complete) {
7956 ioc->wait_for_discovery_to_complete = 0;
7957 _scsih_probe_devices(ioc);
7958 }
7959 mpt2sas_base_start_watchdog(ioc);
7960 ioc->is_driver_loading = 0;
7961 return 1;
7962}
7963
7964
Eric Moore635374e2009-03-09 01:21:12 -06007965/**
Eric Moored5d135b2009-05-18 13:02:08 -06007966 * _scsih_probe - attach and add scsi host
Eric Moore635374e2009-03-09 01:21:12 -06007967 * @pdev: PCI device struct
7968 * @id: pci device id
7969 *
7970 * Returns 0 success, anything else error.
7971 */
7972static int
Eric Moored5d135b2009-05-18 13:02:08 -06007973_scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
Eric Moore635374e2009-03-09 01:21:12 -06007974{
7975 struct MPT2SAS_ADAPTER *ioc;
7976 struct Scsi_Host *shost;
7977
7978 shost = scsi_host_alloc(&scsih_driver_template,
7979 sizeof(struct MPT2SAS_ADAPTER));
7980 if (!shost)
7981 return -ENODEV;
7982
7983 /* init local params */
7984 ioc = shost_priv(shost);
7985 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
7986 INIT_LIST_HEAD(&ioc->list);
Eric Mooreba33fad2009-03-15 21:37:18 -06007987 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
Eric Moore635374e2009-03-09 01:21:12 -06007988 ioc->shost = shost;
7989 ioc->id = mpt_ids++;
7990 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
7991 ioc->pdev = pdev;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05307992 if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
7993 ioc->is_warpdrive = 1;
7994 ioc->hide_ir_msg = 1;
7995 } else
7996 ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
Eric Moore635374e2009-03-09 01:21:12 -06007997 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
7998 ioc->tm_cb_idx = tm_cb_idx;
7999 ioc->ctl_cb_idx = ctl_cb_idx;
8000 ioc->base_cb_idx = base_cb_idx;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308001 ioc->port_enable_cb_idx = port_enable_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008002 ioc->transport_cb_idx = transport_cb_idx;
Kashyap, Desai744090d2009-10-05 15:56:56 +05308003 ioc->scsih_cb_idx = scsih_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008004 ioc->config_cb_idx = config_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308005 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308006 ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308007 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
Eric Moore635374e2009-03-09 01:21:12 -06008008 ioc->logging_level = logging_level;
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +05308009 ioc->schedule_dead_ioc_flush_running_cmds = &_scsih_flush_running_cmds;
Eric Moore635374e2009-03-09 01:21:12 -06008010 /* misc semaphores and spin locks */
Kashyap, Desaid2742132010-06-17 13:28:55 +05308011 mutex_init(&ioc->reset_in_progress_mutex);
Eric Moore635374e2009-03-09 01:21:12 -06008012 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
8013 spin_lock_init(&ioc->scsi_lookup_lock);
8014 spin_lock_init(&ioc->sas_device_lock);
8015 spin_lock_init(&ioc->sas_node_lock);
8016 spin_lock_init(&ioc->fw_event_lock);
8017 spin_lock_init(&ioc->raid_device_lock);
8018
8019 INIT_LIST_HEAD(&ioc->sas_device_list);
8020 INIT_LIST_HEAD(&ioc->sas_device_init_list);
8021 INIT_LIST_HEAD(&ioc->sas_expander_list);
8022 INIT_LIST_HEAD(&ioc->fw_event_list);
8023 INIT_LIST_HEAD(&ioc->raid_device_list);
8024 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308025 INIT_LIST_HEAD(&ioc->delayed_tr_list);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308026 INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
Eric Moore635374e2009-03-09 01:21:12 -06008027
8028 /* init shost parameters */
Eric Moored334aa72010-04-22 10:47:40 -06008029 shost->max_cmd_len = 32;
Eric Moore635374e2009-03-09 01:21:12 -06008030 shost->max_lun = max_lun;
8031 shost->transportt = mpt2sas_transport_template;
8032 shost->unique_id = ioc->id;
8033
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308034 if (max_sectors != 0xFFFF) {
8035 if (max_sectors < 64) {
8036 shost->max_sectors = 64;
8037 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8038 "for max_sectors, range is 64 to 8192. Assigning "
8039 "value of 64.\n", ioc->name, max_sectors);
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308040 } else if (max_sectors > 32767) {
8041 shost->max_sectors = 32767;
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308042 printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
8043 "for max_sectors, range is 64 to 8192. Assigning "
nagalakshmi.nandigama@lsi.com9ac49d32011-12-01 07:52:08 +05308044 "default value of 32767.\n", ioc->name,
Kashyap, Desaia3e1e552011-06-14 10:56:12 +05308045 max_sectors);
8046 } else {
8047 shost->max_sectors = max_sectors & 0xFFFE;
8048 printk(MPT2SAS_INFO_FMT "The max_sectors value is "
8049 "set to %d\n", ioc->name, shost->max_sectors);
8050 }
8051 }
8052
Eric Moore635374e2009-03-09 01:21:12 -06008053 if ((scsi_add_host(shost, &pdev->dev))) {
8054 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8055 ioc->name, __FILE__, __LINE__, __func__);
8056 list_del(&ioc->list);
8057 goto out_add_shost_fail;
8058 }
8059
Eric Moore3c621b32009-05-18 12:59:41 -06008060 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
Eric Moored334aa72010-04-22 10:47:40 -06008061 | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308062 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
Eric Moore3c621b32009-05-18 12:59:41 -06008063
Eric Moore635374e2009-03-09 01:21:12 -06008064 /* event thread */
8065 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
8066 "fw_event%d", ioc->id);
8067 ioc->firmware_event_thread = create_singlethread_workqueue(
8068 ioc->firmware_event_name);
8069 if (!ioc->firmware_event_thread) {
8070 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8071 ioc->name, __FILE__, __LINE__, __func__);
8072 goto out_thread_fail;
8073 }
8074
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308075 ioc->is_driver_loading = 1;
Eric Moore635374e2009-03-09 01:21:12 -06008076 if ((mpt2sas_base_attach(ioc))) {
8077 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
8078 ioc->name, __FILE__, __LINE__, __func__);
8079 goto out_attach_fail;
8080 }
8081
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308082 if (ioc->is_warpdrive) {
8083 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
8084 ioc->hide_drives = 0;
8085 else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
8086 ioc->hide_drives = 1;
8087 else {
8088 if (_scsih_get_num_volumes(ioc))
8089 ioc->hide_drives = 1;
8090 else
8091 ioc->hide_drives = 0;
8092 }
8093 } else
8094 ioc->hide_drives = 0;
nagalakshmi.nandigama@lsi.com2cb6fc82011-12-13 09:29:15 +05308095 scsi_scan_host(shost);
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05308096
Eric Moore635374e2009-03-09 01:21:12 -06008097 return 0;
8098
8099 out_attach_fail:
8100 destroy_workqueue(ioc->firmware_event_thread);
8101 out_thread_fail:
8102 list_del(&ioc->list);
8103 scsi_remove_host(shost);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308104 scsi_host_put(shost);
Eric Moore635374e2009-03-09 01:21:12 -06008105 out_add_shost_fail:
8106 return -ENODEV;
8107}
8108
8109#ifdef CONFIG_PM
8110/**
Eric Moored5d135b2009-05-18 13:02:08 -06008111 * _scsih_suspend - power management suspend main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008112 * @pdev: PCI device struct
8113 * @state: PM state change to (usually PCI_D3)
8114 *
8115 * Returns 0 success, anything else error.
8116 */
8117static int
Eric Moored5d135b2009-05-18 13:02:08 -06008118_scsih_suspend(struct pci_dev *pdev, pm_message_t state)
Eric Moore635374e2009-03-09 01:21:12 -06008119{
8120 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8121 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308122 pci_power_t device_state;
Eric Moore635374e2009-03-09 01:21:12 -06008123
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308124 mpt2sas_base_stop_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008125 scsi_block_requests(shost);
8126 device_state = pci_choose_state(pdev, state);
8127 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
8128 "operating state [D%d]\n", ioc->name, pdev,
8129 pci_name(pdev), device_state);
8130
8131 mpt2sas_base_free_resources(ioc);
8132 pci_save_state(pdev);
8133 pci_disable_device(pdev);
8134 pci_set_power_state(pdev, device_state);
8135 return 0;
8136}
8137
8138/**
Eric Moored5d135b2009-05-18 13:02:08 -06008139 * _scsih_resume - power management resume main entry point
Eric Moore635374e2009-03-09 01:21:12 -06008140 * @pdev: PCI device struct
8141 *
8142 * Returns 0 success, anything else error.
8143 */
8144static int
Eric Moored5d135b2009-05-18 13:02:08 -06008145_scsih_resume(struct pci_dev *pdev)
Eric Moore635374e2009-03-09 01:21:12 -06008146{
8147 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8148 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
Kashyap, Desaic97951e2011-06-14 10:54:56 +05308149 pci_power_t device_state = pdev->current_state;
Eric Moore635374e2009-03-09 01:21:12 -06008150 int r;
8151
8152 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
8153 "operating state [D%d]\n", ioc->name, pdev,
8154 pci_name(pdev), device_state);
8155
8156 pci_set_power_state(pdev, PCI_D0);
8157 pci_enable_wake(pdev, PCI_D0, 0);
8158 pci_restore_state(pdev);
8159 ioc->pdev = pdev;
8160 r = mpt2sas_base_map_resources(ioc);
8161 if (r)
8162 return r;
8163
8164 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
8165 scsi_unblock_requests(shost);
Kashyap, Desaie4750c92009-08-07 19:37:59 +05308166 mpt2sas_base_start_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06008167 return 0;
8168}
8169#endif /* CONFIG_PM */
8170
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308171/**
8172 * _scsih_pci_error_detected - Called when a PCI error is detected.
8173 * @pdev: PCI device struct
8174 * @state: PCI channel state
8175 *
8176 * Description: Called when a PCI error is detected.
8177 *
8178 * Return value:
8179 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8180 */
8181static pci_ers_result_t
8182_scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
8183{
8184 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8185 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8186
8187 printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
8188 ioc->name, state);
8189
8190 switch (state) {
8191 case pci_channel_io_normal:
8192 return PCI_ERS_RESULT_CAN_RECOVER;
8193 case pci_channel_io_frozen:
Eric Moore3cb54692010-07-08 14:44:34 -06008194 /* Fatal error, prepare for slot reset */
8195 ioc->pci_error_recovery = 1;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308196 scsi_block_requests(ioc->shost);
8197 mpt2sas_base_stop_watchdog(ioc);
8198 mpt2sas_base_free_resources(ioc);
8199 return PCI_ERS_RESULT_NEED_RESET;
8200 case pci_channel_io_perm_failure:
Eric Moore3cb54692010-07-08 14:44:34 -06008201 /* Permanent error, prepare for device removal */
8202 ioc->pci_error_recovery = 1;
8203 mpt2sas_base_stop_watchdog(ioc);
8204 _scsih_flush_running_cmds(ioc);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308205 return PCI_ERS_RESULT_DISCONNECT;
8206 }
8207 return PCI_ERS_RESULT_NEED_RESET;
8208}
8209
8210/**
8211 * _scsih_pci_slot_reset - Called when PCI slot has been reset.
8212 * @pdev: PCI device struct
8213 *
8214 * Description: This routine is called by the pci error recovery
8215 * code after the PCI slot has been reset, just before we
8216 * should resume normal operations.
8217 */
8218static pci_ers_result_t
8219_scsih_pci_slot_reset(struct pci_dev *pdev)
8220{
8221 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8222 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8223 int rc;
8224
8225 printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
8226 ioc->name);
8227
Eric Moore3cb54692010-07-08 14:44:34 -06008228 ioc->pci_error_recovery = 0;
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308229 ioc->pdev = pdev;
Eric Moore3cb54692010-07-08 14:44:34 -06008230 pci_restore_state(pdev);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308231 rc = mpt2sas_base_map_resources(ioc);
8232 if (rc)
8233 return PCI_ERS_RESULT_DISCONNECT;
8234
8235
8236 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
8237 FORCE_BIG_HAMMER);
8238
8239 printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
8240 (rc == 0) ? "success" : "failed");
8241
8242 if (!rc)
8243 return PCI_ERS_RESULT_RECOVERED;
8244 else
8245 return PCI_ERS_RESULT_DISCONNECT;
8246}
8247
8248/**
8249 * _scsih_pci_resume() - resume normal ops after PCI reset
8250 * @pdev: pointer to PCI device
8251 *
8252 * Called when the error recovery driver tells us that its
8253 * OK to resume normal operation. Use completion to allow
8254 * halted scsi ops to resume.
8255 */
8256static void
8257_scsih_pci_resume(struct pci_dev *pdev)
8258{
8259 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8260 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8261
8262 printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
8263
8264 pci_cleanup_aer_uncorrect_error_status(pdev);
8265 mpt2sas_base_start_watchdog(ioc);
8266 scsi_unblock_requests(ioc->shost);
8267}
8268
8269/**
8270 * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
8271 * @pdev: pointer to PCI device
8272 */
8273static pci_ers_result_t
8274_scsih_pci_mmio_enabled(struct pci_dev *pdev)
8275{
8276 struct Scsi_Host *shost = pci_get_drvdata(pdev);
8277 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
8278
8279 printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
8280 ioc->name);
8281
8282 /* TODO - dump whatever for debugging purposes */
8283
8284 /* Request a slot reset. */
8285 return PCI_ERS_RESULT_NEED_RESET;
8286}
8287
8288static struct pci_error_handlers _scsih_err_handler = {
8289 .error_detected = _scsih_pci_error_detected,
8290 .mmio_enabled = _scsih_pci_mmio_enabled,
8291 .slot_reset = _scsih_pci_slot_reset,
8292 .resume = _scsih_pci_resume,
8293};
Eric Moore635374e2009-03-09 01:21:12 -06008294
8295static struct pci_driver scsih_driver = {
8296 .name = MPT2SAS_DRIVER_NAME,
8297 .id_table = scsih_pci_table,
Eric Moored5d135b2009-05-18 13:02:08 -06008298 .probe = _scsih_probe,
8299 .remove = __devexit_p(_scsih_remove),
Kashyap, Desai744090d2009-10-05 15:56:56 +05308300 .shutdown = _scsih_shutdown,
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05308301 .err_handler = &_scsih_err_handler,
Eric Moore635374e2009-03-09 01:21:12 -06008302#ifdef CONFIG_PM
Eric Moored5d135b2009-05-18 13:02:08 -06008303 .suspend = _scsih_suspend,
8304 .resume = _scsih_resume,
Eric Moore635374e2009-03-09 01:21:12 -06008305#endif
8306};
8307
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308308/* raid transport support */
8309static struct raid_function_template mpt2sas_raid_functions = {
8310 .cookie = &scsih_driver_template,
8311 .is_raid = _scsih_is_raid,
8312 .get_resync = _scsih_get_resync,
8313 .get_state = _scsih_get_state,
8314};
Eric Moore635374e2009-03-09 01:21:12 -06008315
8316/**
Eric Moored5d135b2009-05-18 13:02:08 -06008317 * _scsih_init - main entry point for this driver.
Eric Moore635374e2009-03-09 01:21:12 -06008318 *
8319 * Returns 0 success, anything else error.
8320 */
8321static int __init
Eric Moored5d135b2009-05-18 13:02:08 -06008322_scsih_init(void)
Eric Moore635374e2009-03-09 01:21:12 -06008323{
8324 int error;
8325
8326 mpt_ids = 0;
8327 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
8328 MPT2SAS_DRIVER_VERSION);
8329
8330 mpt2sas_transport_template =
8331 sas_attach_transport(&mpt2sas_transport_functions);
8332 if (!mpt2sas_transport_template)
8333 return -ENODEV;
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308334 /* raid transport support */
8335 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
8336 if (!mpt2sas_raid_template) {
8337 sas_release_transport(mpt2sas_transport_template);
8338 return -ENODEV;
8339 }
Eric Moore635374e2009-03-09 01:21:12 -06008340
8341 mpt2sas_base_initialize_callback_handler();
8342
8343 /* queuecommand callback hander */
Eric Moored5d135b2009-05-18 13:02:08 -06008344 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
Eric Moore635374e2009-03-09 01:21:12 -06008345
Uwe Kleine-König65155b32010-06-11 12:17:01 +02008346 /* task management callback handler */
Eric Moored5d135b2009-05-18 13:02:08 -06008347 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
Eric Moore635374e2009-03-09 01:21:12 -06008348
8349 /* base internal commands callback handler */
8350 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308351 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8352 mpt2sas_port_enable_done);
Eric Moore635374e2009-03-09 01:21:12 -06008353
8354 /* transport internal commands callback handler */
8355 transport_cb_idx = mpt2sas_base_register_callback_handler(
8356 mpt2sas_transport_done);
8357
Kashyap, Desai744090d2009-10-05 15:56:56 +05308358 /* scsih internal commands callback handler */
8359 scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
8360
Eric Moore635374e2009-03-09 01:21:12 -06008361 /* configuration page API internal commands callback handler */
8362 config_cb_idx = mpt2sas_base_register_callback_handler(
8363 mpt2sas_config_done);
8364
8365 /* ctl module callback handler */
8366 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
8367
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308368 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
8369 _scsih_tm_tr_complete);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308370
8371 tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
8372 _scsih_tm_volume_tr_complete);
8373
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308374 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
8375 _scsih_sas_control_complete);
8376
Eric Moore635374e2009-03-09 01:21:12 -06008377 mpt2sas_ctl_init();
8378
8379 error = pci_register_driver(&scsih_driver);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308380 if (error) {
8381 /* raid transport support */
8382 raid_class_release(mpt2sas_raid_template);
Eric Moore635374e2009-03-09 01:21:12 -06008383 sas_release_transport(mpt2sas_transport_template);
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308384 }
Eric Moore635374e2009-03-09 01:21:12 -06008385
8386 return error;
8387}
8388
8389/**
Eric Moored5d135b2009-05-18 13:02:08 -06008390 * _scsih_exit - exit point for this driver (when it is a module).
Eric Moore635374e2009-03-09 01:21:12 -06008391 *
8392 * Returns 0 success, anything else error.
8393 */
8394static void __exit
Eric Moored5d135b2009-05-18 13:02:08 -06008395_scsih_exit(void)
Eric Moore635374e2009-03-09 01:21:12 -06008396{
8397 printk(KERN_INFO "mpt2sas version %s unloading\n",
8398 MPT2SAS_DRIVER_VERSION);
8399
8400 pci_unregister_driver(&scsih_driver);
8401
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308402 mpt2sas_ctl_exit();
8403
Eric Moore635374e2009-03-09 01:21:12 -06008404 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
8405 mpt2sas_base_release_callback_handler(tm_cb_idx);
8406 mpt2sas_base_release_callback_handler(base_cb_idx);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05308407 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008408 mpt2sas_base_release_callback_handler(transport_cb_idx);
Kashyap, Desai744090d2009-10-05 15:56:56 +05308409 mpt2sas_base_release_callback_handler(scsih_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06008410 mpt2sas_base_release_callback_handler(config_cb_idx);
8411 mpt2sas_base_release_callback_handler(ctl_cb_idx);
8412
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308413 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05308414 mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05308415 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
8416
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +05308417 /* raid transport support */
8418 raid_class_release(mpt2sas_raid_template);
8419 sas_release_transport(mpt2sas_transport_template);
8420
Eric Moore635374e2009-03-09 01:21:12 -06008421}
8422
Eric Moored5d135b2009-05-18 13:02:08 -06008423module_init(_scsih_init);
8424module_exit(_scsih_exit);