2 * Scsi Host Layer for MPT (Message Passing Technology) based controllers
4 * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
5 * Copyright (C) 2007-2009 LSI Corporation
6 * (mailto:DL-MPTFusionLinux@lsi.com)
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.
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.
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.
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
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,
44 #include <linux/version.h>
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/init.h>
48 #include <linux/errno.h>
49 #include <linux/blkdev.h>
50 #include <linux/sched.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h>
53 #include <linux/pci.h>
54 #include <linux/interrupt.h>
56 #include "mpt2sas_base.h"
58 MODULE_AUTHOR(MPT2SAS_AUTHOR);
59 MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
60 MODULE_LICENSE("GPL");
61 MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
63 #define RAID_CHANNEL 1
66 static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
67 struct _sas_node *sas_expander);
68 static void _firmware_event_work(struct work_struct *work);
70 /* global parameters */
71 LIST_HEAD(mpt2sas_ioc_list);
73 /* local parameters */
74 static u8 scsi_io_cb_idx = -1;
75 static u8 tm_cb_idx = -1;
76 static u8 ctl_cb_idx = -1;
77 static u8 base_cb_idx = -1;
78 static u8 transport_cb_idx = -1;
79 static u8 config_cb_idx = -1;
82 static u8 tm_tr_cb_idx = -1 ;
83 static u8 tm_sas_control_cb_idx = -1;
85 /* command line options */
86 static u32 logging_level;
87 MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
90 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
91 #define MPT2SAS_MAX_LUN (16895)
92 static int max_lun = MPT2SAS_MAX_LUN;
93 module_param(max_lun, int, 0);
94 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
97 * struct sense_info - common structure for obtaining sense keys
99 * @asc: additional sense code
100 * @ascq: additional sense code qualifier
110 * struct fw_event_work - firmware event struct
111 * @list: link list framework
112 * @work: work object (ioc->fault_reset_work_q)
113 * @ioc: per adapter object
114 * @VF_ID: virtual function id
115 * @VP_ID: virtual port id
116 * @host_reset_handling: handling events during host reset
117 * @ignore: flag meaning this event has been marked to ignore
118 * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
119 * @event_data: reply event data payload follows
121 * This object stored on ioc->fw_event_list.
123 struct fw_event_work {
124 struct list_head list;
125 struct work_struct work;
126 struct MPT2SAS_ADAPTER *ioc;
129 u8 host_reset_handling;
136 * struct _scsi_io_transfer - scsi io transfer
137 * @handle: sas device handle (assigned by firmware)
138 * @is_raid: flag set for hidden raid components
139 * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
140 * @data_length: data transfer length
141 * @data_dma: dma pointer to data
144 * @cdb_length: cdb length
146 * @timeout: timeout for this command
147 * @VF_ID: virtual function id
148 * @VP_ID: virtual port id
149 * @valid_reply: flag set for reply message
150 * @sense_length: sense length
151 * @ioc_status: ioc status
152 * @scsi_state: scsi state
153 * @scsi_status: scsi staus
154 * @log_info: log information
155 * @transfer_length: data length transfer when there is a reply message
157 * Used for sending internal scsi commands to devices within this module.
158 * Refer to _scsi_send_scsi_io().
160 struct _scsi_io_transfer {
163 enum dma_data_direction dir;
166 u8 sense[SCSI_SENSE_BUFFERSIZE];
174 /* the following bits are only valid when 'valid_reply = 1' */
184 * The pci device ids are defined in mpi/mpi2_cnfg.h.
186 static struct pci_device_id scsih_pci_table[] = {
187 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
188 PCI_ANY_ID, PCI_ANY_ID },
190 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
191 PCI_ANY_ID, PCI_ANY_ID },
192 /* Liberator ~ 2108 */
193 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
194 PCI_ANY_ID, PCI_ANY_ID },
195 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
196 PCI_ANY_ID, PCI_ANY_ID },
197 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
198 PCI_ANY_ID, PCI_ANY_ID },
200 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
201 PCI_ANY_ID, PCI_ANY_ID },
202 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
203 PCI_ANY_ID, PCI_ANY_ID },
204 /* Thunderbolt ~ 2208 */
205 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
206 PCI_ANY_ID, PCI_ANY_ID },
207 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
208 PCI_ANY_ID, PCI_ANY_ID },
209 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
210 PCI_ANY_ID, PCI_ANY_ID },
211 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
212 PCI_ANY_ID, PCI_ANY_ID },
213 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
214 PCI_ANY_ID, PCI_ANY_ID },
215 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
216 PCI_ANY_ID, PCI_ANY_ID },
217 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_7,
218 PCI_ANY_ID, PCI_ANY_ID },
219 { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_8,
220 PCI_ANY_ID, PCI_ANY_ID },
221 {0} /* Terminating entry */
223 MODULE_DEVICE_TABLE(pci, scsih_pci_table);
226 * _scsih_set_debug_level - global setting of ioc->logging_level.
228 * Note: The logging levels are defined in mpt2sas_debug.h.
231 _scsih_set_debug_level(const char *val, struct kernel_param *kp)
233 int ret = param_set_int(val, kp);
234 struct MPT2SAS_ADAPTER *ioc;
239 printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
240 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
241 ioc->logging_level = logging_level;
244 module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
245 &logging_level, 0644);
248 * _scsih_srch_boot_sas_address - search based on sas_address
249 * @sas_address: sas address
250 * @boot_device: boot device object from bios page 2
252 * Returns 1 when there's a match, 0 means no match.
255 _scsih_srch_boot_sas_address(u64 sas_address,
256 Mpi2BootDeviceSasWwid_t *boot_device)
258 return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
262 * _scsih_srch_boot_device_name - search based on device name
263 * @device_name: device name specified in INDENTIFY fram
264 * @boot_device: boot device object from bios page 2
266 * Returns 1 when there's a match, 0 means no match.
269 _scsih_srch_boot_device_name(u64 device_name,
270 Mpi2BootDeviceDeviceName_t *boot_device)
272 return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
276 * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
277 * @enclosure_logical_id: enclosure logical id
278 * @slot_number: slot number
279 * @boot_device: boot device object from bios page 2
281 * Returns 1 when there's a match, 0 means no match.
284 _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
285 Mpi2BootDeviceEnclosureSlot_t *boot_device)
287 return (enclosure_logical_id == le64_to_cpu(boot_device->
288 EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
289 SlotNumber)) ? 1 : 0;
293 * _scsih_is_boot_device - search for matching boot device.
294 * @sas_address: sas address
295 * @device_name: device name specified in INDENTIFY fram
296 * @enclosure_logical_id: enclosure logical id
297 * @slot_number: slot number
298 * @form: specifies boot device form
299 * @boot_device: boot device object from bios page 2
301 * Returns 1 when there's a match, 0 means no match.
304 _scsih_is_boot_device(u64 sas_address, u64 device_name,
305 u64 enclosure_logical_id, u16 slot, u8 form,
306 Mpi2BiosPage2BootDevice_t *boot_device)
311 case MPI2_BIOSPAGE2_FORM_SAS_WWID:
314 rc = _scsih_srch_boot_sas_address(
315 sas_address, &boot_device->SasWwid);
317 case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
318 if (!enclosure_logical_id)
320 rc = _scsih_srch_boot_encl_slot(
321 enclosure_logical_id,
322 slot, &boot_device->EnclosureSlot);
324 case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
327 rc = _scsih_srch_boot_device_name(
328 device_name, &boot_device->DeviceName);
330 case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
338 * _scsih_determine_boot_device - determine boot device.
339 * @ioc: per adapter object
340 * @device: either sas_device or raid_device object
341 * @is_raid: [flag] 1 = raid object, 0 = sas object
343 * Determines whether this device should be first reported device to
344 * to scsi-ml or sas transport, this purpose is for persistant boot device.
345 * There are primary, alternate, and current entries in bios page 2. The order
346 * priority is primary, alternate, then current. This routine saves
347 * the corresponding device object and is_raid flag in the ioc object.
348 * The saved data to be used later in _scsih_probe_boot_devices().
351 _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
352 void *device, u8 is_raid)
354 struct _sas_device *sas_device;
355 struct _raid_device *raid_device;
358 u64 enclosure_logical_id;
361 /* only process this function when driver loads */
362 if (!ioc->wait_for_port_enable_to_complete)
367 sas_address = sas_device->sas_address;
368 device_name = sas_device->device_name;
369 enclosure_logical_id = sas_device->enclosure_logical_id;
370 slot = sas_device->slot;
372 raid_device = device;
373 sas_address = raid_device->wwid;
375 enclosure_logical_id = 0;
379 if (!ioc->req_boot_device.device) {
380 if (_scsih_is_boot_device(sas_address, device_name,
381 enclosure_logical_id, slot,
382 (ioc->bios_pg2.ReqBootDeviceForm &
383 MPI2_BIOSPAGE2_FORM_MASK),
384 &ioc->bios_pg2.RequestedBootDevice)) {
385 dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
386 "%s: req_boot_device(0x%016llx)\n",
388 (unsigned long long)sas_address));
389 ioc->req_boot_device.device = device;
390 ioc->req_boot_device.is_raid = is_raid;
394 if (!ioc->req_alt_boot_device.device) {
395 if (_scsih_is_boot_device(sas_address, device_name,
396 enclosure_logical_id, slot,
397 (ioc->bios_pg2.ReqAltBootDeviceForm &
398 MPI2_BIOSPAGE2_FORM_MASK),
399 &ioc->bios_pg2.RequestedAltBootDevice)) {
400 dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
401 "%s: req_alt_boot_device(0x%016llx)\n",
403 (unsigned long long)sas_address));
404 ioc->req_alt_boot_device.device = device;
405 ioc->req_alt_boot_device.is_raid = is_raid;
409 if (!ioc->current_boot_device.device) {
410 if (_scsih_is_boot_device(sas_address, device_name,
411 enclosure_logical_id, slot,
412 (ioc->bios_pg2.CurrentBootDeviceForm &
413 MPI2_BIOSPAGE2_FORM_MASK),
414 &ioc->bios_pg2.CurrentBootDevice)) {
415 dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
416 "%s: current_boot_device(0x%016llx)\n",
418 (unsigned long long)sas_address));
419 ioc->current_boot_device.device = device;
420 ioc->current_boot_device.is_raid = is_raid;
426 * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
427 * @ioc: per adapter object
428 * @sas_address: sas address
429 * Context: Calling function should acquire ioc->sas_device_lock
431 * This searches for sas_device based on sas_address, then return sas_device
435 mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
438 struct _sas_device *sas_device, *r;
441 /* check the sas_device_init_list */
442 list_for_each_entry(sas_device, &ioc->sas_device_init_list,
444 if (sas_device->sas_address != sas_address)
450 /* then check the sas_device_list */
451 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
452 if (sas_device->sas_address != sas_address)
462 * _scsih_sas_device_find_by_handle - sas device search
463 * @ioc: per adapter object
464 * @handle: sas device handle (assigned by firmware)
465 * Context: Calling function should acquire ioc->sas_device_lock
467 * This searches for sas_device based on sas_address, then return sas_device
470 static struct _sas_device *
471 _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
473 struct _sas_device *sas_device, *r;
476 if (ioc->wait_for_port_enable_to_complete) {
477 list_for_each_entry(sas_device, &ioc->sas_device_init_list,
479 if (sas_device->handle != handle)
485 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
486 if (sas_device->handle != handle)
498 * _scsih_sas_device_remove - remove sas_device from list.
499 * @ioc: per adapter object
500 * @sas_device: the sas_device object
501 * Context: This function will acquire ioc->sas_device_lock.
503 * Removing object and freeing associated memory from the ioc->sas_device_list.
506 _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
507 struct _sas_device *sas_device)
511 spin_lock_irqsave(&ioc->sas_device_lock, flags);
512 list_del(&sas_device->list);
513 memset(sas_device, 0, sizeof(struct _sas_device));
515 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
519 * _scsih_sas_device_add - insert sas_device to the list.
520 * @ioc: per adapter object
521 * @sas_device: the sas_device object
522 * Context: This function will acquire ioc->sas_device_lock.
524 * Adding new object to the ioc->sas_device_list.
527 _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
528 struct _sas_device *sas_device)
531 u16 handle, parent_handle;
534 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
535 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
536 sas_device->handle, (unsigned long long)sas_device->sas_address));
538 spin_lock_irqsave(&ioc->sas_device_lock, flags);
539 list_add_tail(&sas_device->list, &ioc->sas_device_list);
540 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
542 handle = sas_device->handle;
543 parent_handle = sas_device->parent_handle;
544 sas_address = sas_device->sas_address;
545 if (!mpt2sas_transport_port_add(ioc, handle, parent_handle))
546 _scsih_sas_device_remove(ioc, sas_device);
550 * _scsih_sas_device_init_add - insert sas_device to the list.
551 * @ioc: per adapter object
552 * @sas_device: the sas_device object
553 * Context: This function will acquire ioc->sas_device_lock.
555 * Adding new object at driver load time to the ioc->sas_device_init_list.
558 _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
559 struct _sas_device *sas_device)
563 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
564 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
565 sas_device->handle, (unsigned long long)sas_device->sas_address));
567 spin_lock_irqsave(&ioc->sas_device_lock, flags);
568 list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
569 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
570 _scsih_determine_boot_device(ioc, sas_device, 0);
574 * mpt2sas_scsih_expander_find_by_handle - expander device search
575 * @ioc: per adapter object
576 * @handle: expander handle (assigned by firmware)
577 * Context: Calling function should acquire ioc->sas_device_lock
579 * This searches for expander device based on handle, then returns the
583 mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
585 struct _sas_node *sas_expander, *r;
588 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
589 if (sas_expander->handle != handle)
599 * _scsih_raid_device_find_by_id - raid device search
600 * @ioc: per adapter object
601 * @id: sas device target id
602 * @channel: sas device channel
603 * Context: Calling function should acquire ioc->raid_device_lock
605 * This searches for raid_device based on target id, then return raid_device
608 static struct _raid_device *
609 _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
611 struct _raid_device *raid_device, *r;
614 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
615 if (raid_device->id == id && raid_device->channel == channel) {
626 * _scsih_raid_device_find_by_handle - raid device search
627 * @ioc: per adapter object
628 * @handle: sas device handle (assigned by firmware)
629 * Context: Calling function should acquire ioc->raid_device_lock
631 * This searches for raid_device based on handle, then return raid_device
634 static struct _raid_device *
635 _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
637 struct _raid_device *raid_device, *r;
640 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
641 if (raid_device->handle != handle)
652 * _scsih_raid_device_find_by_wwid - raid device search
653 * @ioc: per adapter object
654 * @handle: sas device handle (assigned by firmware)
655 * Context: Calling function should acquire ioc->raid_device_lock
657 * This searches for raid_device based on wwid, then return raid_device
660 static struct _raid_device *
661 _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
663 struct _raid_device *raid_device, *r;
666 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
667 if (raid_device->wwid != wwid)
678 * _scsih_raid_device_add - add raid_device object
679 * @ioc: per adapter object
680 * @raid_device: raid_device object
682 * This is added to the raid_device_list link list.
685 _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
686 struct _raid_device *raid_device)
690 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
691 "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
692 raid_device->handle, (unsigned long long)raid_device->wwid));
694 spin_lock_irqsave(&ioc->raid_device_lock, flags);
695 list_add_tail(&raid_device->list, &ioc->raid_device_list);
696 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
700 * _scsih_raid_device_remove - delete raid_device object
701 * @ioc: per adapter object
702 * @raid_device: raid_device object
704 * This is removed from the raid_device_list link list.
707 _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
708 struct _raid_device *raid_device)
712 spin_lock_irqsave(&ioc->raid_device_lock, flags);
713 list_del(&raid_device->list);
714 memset(raid_device, 0, sizeof(struct _raid_device));
716 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
720 * mpt2sas_scsih_expander_find_by_sas_address - expander device search
721 * @ioc: per adapter object
722 * @sas_address: sas address
723 * Context: Calling function should acquire ioc->sas_node_lock.
725 * This searches for expander device based on sas_address, then returns the
729 mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
732 struct _sas_node *sas_expander, *r;
735 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
736 if (sas_expander->sas_address != sas_address)
746 * _scsih_expander_node_add - insert expander device to the list.
747 * @ioc: per adapter object
748 * @sas_expander: the sas_device object
749 * Context: This function will acquire ioc->sas_node_lock.
751 * Adding new object to the ioc->sas_expander_list.
756 _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
757 struct _sas_node *sas_expander)
761 spin_lock_irqsave(&ioc->sas_node_lock, flags);
762 list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
763 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
767 * _scsih_is_end_device - determines if device is an end device
768 * @device_info: bitfield providing information about the device.
771 * Returns 1 if end device.
774 _scsih_is_end_device(u32 device_info)
776 if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
777 ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
778 (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
779 (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
786 * mptscsih_get_scsi_lookup - returns scmd entry
787 * @ioc: per adapter object
788 * @smid: system request message index
790 * Returns the smid stored scmd pointer.
792 static struct scsi_cmnd *
793 _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
795 return ioc->scsi_lookup[smid - 1].scmd;
799 * _scsih_scsi_lookup_find_by_scmd - scmd lookup
800 * @ioc: per adapter object
801 * @smid: system request message index
802 * @scmd: pointer to scsi command object
803 * Context: This function will acquire ioc->scsi_lookup_lock.
805 * This will search for a scmd pointer in the scsi_lookup array,
806 * returning the revelent smid. A returned value of zero means invalid.
809 _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
816 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
818 for (i = 0; i < ioc->scsiio_depth; i++) {
819 if (ioc->scsi_lookup[i].scmd == scmd) {
820 smid = ioc->scsi_lookup[i].smid;
825 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
830 * _scsih_scsi_lookup_find_by_target - search for matching channel:id
831 * @ioc: per adapter object
834 * Context: This function will acquire ioc->scsi_lookup_lock.
836 * This will search for a matching channel:id in the scsi_lookup array,
837 * returning 1 if found.
840 _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
847 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
849 for (i = 0 ; i < ioc->scsiio_depth; i++) {
850 if (ioc->scsi_lookup[i].scmd &&
851 (ioc->scsi_lookup[i].scmd->device->id == id &&
852 ioc->scsi_lookup[i].scmd->device->channel == channel)) {
858 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
863 * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
864 * @ioc: per adapter object
868 * Context: This function will acquire ioc->scsi_lookup_lock.
870 * This will search for a matching channel:id:lun in the scsi_lookup array,
871 * returning 1 if found.
874 _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
875 unsigned int lun, int channel)
881 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
883 for (i = 0 ; i < ioc->scsiio_depth; i++) {
884 if (ioc->scsi_lookup[i].scmd &&
885 (ioc->scsi_lookup[i].scmd->device->id == id &&
886 ioc->scsi_lookup[i].scmd->device->channel == channel &&
887 ioc->scsi_lookup[i].scmd->device->lun == lun)) {
893 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
898 * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
899 * @ioc: per adapter object
900 * @smid: system request message index
902 * Returns phys pointer to chain buffer.
905 _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
907 return ioc->chain_dma + ((smid - 1) * (ioc->request_sz *
908 ioc->chains_needed_per_io));
912 * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
913 * @ioc: per adapter object
914 * @smid: system request message index
916 * Returns virt pointer to chain buffer.
919 _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
921 return (void *)(ioc->chain + ((smid - 1) * (ioc->request_sz *
922 ioc->chains_needed_per_io)));
926 * _scsih_build_scatter_gather - main sg creation routine
927 * @ioc: per adapter object
928 * @scmd: scsi command
929 * @smid: system request message index
932 * The main routine that builds scatter gather table from a given
933 * scsi request sent via the .queuecommand main handler.
935 * Returns 0 success, anything else error
938 _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
939 struct scsi_cmnd *scmd, u16 smid)
941 Mpi2SCSIIORequest_t *mpi_request;
942 dma_addr_t chain_dma;
943 struct scatterlist *sg_scmd;
944 void *sg_local, *chain;
951 u32 sgl_flags_last_element;
952 u32 sgl_flags_end_buffer;
954 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
956 /* init scatter gather flags */
957 sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
958 if (scmd->sc_data_direction == DMA_TO_DEVICE)
959 sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
960 sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
961 << MPI2_SGE_FLAGS_SHIFT;
962 sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
963 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
964 << MPI2_SGE_FLAGS_SHIFT;
965 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
967 sg_scmd = scsi_sglist(scmd);
968 sges_left = scsi_dma_map(scmd);
970 sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
971 " failed: request for %d bytes!\n", scsi_bufflen(scmd));
975 sg_local = &mpi_request->SGL;
976 sges_in_segment = ioc->max_sges_in_main_message;
977 if (sges_left <= sges_in_segment)
978 goto fill_in_last_segment;
980 mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
981 (sges_in_segment * ioc->sge_size))/4;
983 /* fill in main message segment when there is a chain following */
984 while (sges_in_segment) {
985 if (sges_in_segment == 1)
986 ioc->base_add_sg_single(sg_local,
987 sgl_flags_last_element | sg_dma_len(sg_scmd),
988 sg_dma_address(sg_scmd));
990 ioc->base_add_sg_single(sg_local, sgl_flags |
991 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
992 sg_scmd = sg_next(sg_scmd);
993 sg_local += ioc->sge_size;
998 /* initializing the chain flags and pointers */
999 chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
1000 chain = _scsih_get_chain_buffer(ioc, smid);
1001 chain_dma = _scsih_get_chain_buffer_dma(ioc, smid);
1003 sges_in_segment = (sges_left <=
1004 ioc->max_sges_in_chain_message) ? sges_left :
1005 ioc->max_sges_in_chain_message;
1006 chain_offset = (sges_left == sges_in_segment) ?
1007 0 : (sges_in_segment * ioc->sge_size)/4;
1008 chain_length = sges_in_segment * ioc->sge_size;
1010 chain_offset = chain_offset <<
1011 MPI2_SGE_CHAIN_OFFSET_SHIFT;
1012 chain_length += ioc->sge_size;
1014 ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
1015 chain_length, chain_dma);
1018 goto fill_in_last_segment;
1020 /* fill in chain segments */
1021 while (sges_in_segment) {
1022 if (sges_in_segment == 1)
1023 ioc->base_add_sg_single(sg_local,
1024 sgl_flags_last_element |
1025 sg_dma_len(sg_scmd),
1026 sg_dma_address(sg_scmd));
1028 ioc->base_add_sg_single(sg_local, sgl_flags |
1029 sg_dma_len(sg_scmd),
1030 sg_dma_address(sg_scmd));
1031 sg_scmd = sg_next(sg_scmd);
1032 sg_local += ioc->sge_size;
1037 chain_dma += ioc->request_sz;
1038 chain += ioc->request_sz;
1042 fill_in_last_segment:
1044 /* fill the last segment */
1047 ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
1048 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1050 ioc->base_add_sg_single(sg_local, sgl_flags |
1051 sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
1052 sg_scmd = sg_next(sg_scmd);
1053 sg_local += ioc->sge_size;
1061 * _scsih_change_queue_depth - setting device queue depth
1062 * @sdev: scsi device struct
1063 * @qdepth: requested queue depth
1065 * Returns queue depth.
1068 _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1070 struct Scsi_Host *shost = sdev->host;
1074 max_depth = shost->can_queue;
1075 if (!sdev->tagged_supported)
1077 if (qdepth > max_depth)
1079 tag_type = (qdepth == 1) ? 0 : MSG_SIMPLE_TAG;
1080 scsi_adjust_queue_depth(sdev, tag_type, qdepth);
1082 if (sdev->inquiry_len > 7)
1083 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1084 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1085 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1086 sdev->ordered_tags, sdev->scsi_level,
1087 (sdev->inquiry[7] & 2) >> 1);
1089 return sdev->queue_depth;
1093 * _scsih_change_queue_type - changing device queue tag type
1094 * @sdev: scsi device struct
1095 * @tag_type: requested tag type
1097 * Returns queue tag type.
1100 _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1102 if (sdev->tagged_supported) {
1103 scsi_set_tag_type(sdev, tag_type);
1105 scsi_activate_tcq(sdev, sdev->queue_depth);
1107 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1115 * _scsih_target_alloc - target add routine
1116 * @starget: scsi target struct
1118 * Returns 0 if ok. Any other return is assumed to be an error and
1119 * the device is ignored.
1122 _scsih_target_alloc(struct scsi_target *starget)
1124 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1125 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1126 struct MPT2SAS_TARGET *sas_target_priv_data;
1127 struct _sas_device *sas_device;
1128 struct _raid_device *raid_device;
1129 unsigned long flags;
1130 struct sas_rphy *rphy;
1132 sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
1133 if (!sas_target_priv_data)
1136 starget->hostdata = sas_target_priv_data;
1137 sas_target_priv_data->starget = starget;
1138 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
1141 if (starget->channel == RAID_CHANNEL) {
1142 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1143 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1146 sas_target_priv_data->handle = raid_device->handle;
1147 sas_target_priv_data->sas_address = raid_device->wwid;
1148 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1149 raid_device->starget = starget;
1151 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1155 /* sas/sata devices */
1156 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1157 rphy = dev_to_rphy(starget->dev.parent);
1158 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1159 rphy->identify.sas_address);
1162 sas_target_priv_data->handle = sas_device->handle;
1163 sas_target_priv_data->sas_address = sas_device->sas_address;
1164 sas_device->starget = starget;
1165 sas_device->id = starget->id;
1166 sas_device->channel = starget->channel;
1167 if (sas_device->hidden_raid_component)
1168 sas_target_priv_data->flags |=
1169 MPT_TARGET_FLAGS_RAID_COMPONENT;
1171 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1177 * _scsih_target_destroy - target destroy routine
1178 * @starget: scsi target struct
1183 _scsih_target_destroy(struct scsi_target *starget)
1185 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1186 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1187 struct MPT2SAS_TARGET *sas_target_priv_data;
1188 struct _sas_device *sas_device;
1189 struct _raid_device *raid_device;
1190 unsigned long flags;
1191 struct sas_rphy *rphy;
1193 sas_target_priv_data = starget->hostdata;
1194 if (!sas_target_priv_data)
1197 if (starget->channel == RAID_CHANNEL) {
1198 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1199 raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
1202 raid_device->starget = NULL;
1203 raid_device->sdev = NULL;
1205 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1209 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1210 rphy = dev_to_rphy(starget->dev.parent);
1211 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1212 rphy->identify.sas_address);
1213 if (sas_device && (sas_device->starget == starget) &&
1214 (sas_device->id == starget->id) &&
1215 (sas_device->channel == starget->channel))
1216 sas_device->starget = NULL;
1218 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1221 kfree(sas_target_priv_data);
1222 starget->hostdata = NULL;
1226 * _scsih_slave_alloc - device add routine
1227 * @sdev: scsi device struct
1229 * Returns 0 if ok. Any other return is assumed to be an error and
1230 * the device is ignored.
1233 _scsih_slave_alloc(struct scsi_device *sdev)
1235 struct Scsi_Host *shost;
1236 struct MPT2SAS_ADAPTER *ioc;
1237 struct MPT2SAS_TARGET *sas_target_priv_data;
1238 struct MPT2SAS_DEVICE *sas_device_priv_data;
1239 struct scsi_target *starget;
1240 struct _raid_device *raid_device;
1241 struct _sas_device *sas_device;
1242 unsigned long flags;
1244 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
1245 if (!sas_device_priv_data)
1248 sas_device_priv_data->lun = sdev->lun;
1249 sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
1251 starget = scsi_target(sdev);
1252 sas_target_priv_data = starget->hostdata;
1253 sas_target_priv_data->num_luns++;
1254 sas_device_priv_data->sas_target = sas_target_priv_data;
1255 sdev->hostdata = sas_device_priv_data;
1256 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
1257 sdev->no_uld_attach = 1;
1259 shost = dev_to_shost(&starget->dev);
1260 ioc = shost_priv(shost);
1261 if (starget->channel == RAID_CHANNEL) {
1262 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1263 raid_device = _scsih_raid_device_find_by_id(ioc,
1264 starget->id, starget->channel);
1266 raid_device->sdev = sdev; /* raid is single lun */
1267 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1269 /* set TLR bit for SSP devices */
1270 if (!(ioc->facts.IOCCapabilities &
1271 MPI2_IOCFACTS_CAPABILITY_TLR))
1273 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1274 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1275 sas_device_priv_data->sas_target->sas_address);
1276 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1277 if (sas_device && sas_device->device_info &
1278 MPI2_SAS_DEVICE_INFO_SSP_TARGET)
1279 sas_device_priv_data->flags |= MPT_DEVICE_TLR_ON;
1287 * _scsih_slave_destroy - device destroy routine
1288 * @sdev: scsi device struct
1293 _scsih_slave_destroy(struct scsi_device *sdev)
1295 struct MPT2SAS_TARGET *sas_target_priv_data;
1296 struct scsi_target *starget;
1298 if (!sdev->hostdata)
1301 starget = scsi_target(sdev);
1302 sas_target_priv_data = starget->hostdata;
1303 sas_target_priv_data->num_luns--;
1304 kfree(sdev->hostdata);
1305 sdev->hostdata = NULL;
1309 * _scsih_display_sata_capabilities - sata capabilities
1310 * @ioc: per adapter object
1311 * @sas_device: the sas_device object
1312 * @sdev: scsi device struct
1315 _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1316 struct _sas_device *sas_device, struct scsi_device *sdev)
1318 Mpi2ConfigReply_t mpi_reply;
1319 Mpi2SasDevicePage0_t sas_device_pg0;
1324 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
1325 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
1326 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1327 ioc->name, __FILE__, __LINE__, __func__);
1331 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1332 MPI2_IOCSTATUS_MASK;
1333 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1334 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1335 ioc->name, __FILE__, __LINE__, __func__);
1339 flags = le16_to_cpu(sas_device_pg0.Flags);
1340 device_info = le16_to_cpu(sas_device_pg0.DeviceInfo);
1342 sdev_printk(KERN_INFO, sdev,
1343 "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
1344 "sw_preserve(%s)\n",
1345 (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
1346 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
1347 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
1349 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
1350 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
1351 (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
1355 * _scsih_get_volume_capabilities - volume capabilities
1356 * @ioc: per adapter object
1357 * @sas_device: the raid_device object
1360 _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1361 struct _raid_device *raid_device)
1363 Mpi2RaidVolPage0_t *vol_pg0;
1364 Mpi2RaidPhysDiskPage0_t pd_pg0;
1365 Mpi2SasDevicePage0_t sas_device_pg0;
1366 Mpi2ConfigReply_t mpi_reply;
1370 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1371 &num_pds)) || !num_pds) {
1372 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1373 ioc->name, __FILE__, __LINE__, __func__);
1377 raid_device->num_pds = num_pds;
1378 sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
1379 sizeof(Mpi2RaidVol0PhysDisk_t));
1380 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1382 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1383 ioc->name, __FILE__, __LINE__, __func__);
1387 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1388 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1389 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1390 ioc->name, __FILE__, __LINE__, __func__);
1395 raid_device->volume_type = vol_pg0->VolumeType;
1397 /* figure out what the underlying devices are by
1398 * obtaining the device_info bits for the 1st device
1400 if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
1401 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
1402 vol_pg0->PhysDisk[0].PhysDiskNum))) {
1403 if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
1404 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
1405 le16_to_cpu(pd_pg0.DevHandle)))) {
1406 raid_device->device_info =
1407 le32_to_cpu(sas_device_pg0.DeviceInfo);
1415 * _scsih_slave_configure - device configure routine.
1416 * @sdev: scsi device struct
1418 * Returns 0 if ok. Any other return is assumed to be an error and
1419 * the device is ignored.
1422 _scsih_slave_configure(struct scsi_device *sdev)
1424 struct Scsi_Host *shost = sdev->host;
1425 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
1426 struct MPT2SAS_DEVICE *sas_device_priv_data;
1427 struct MPT2SAS_TARGET *sas_target_priv_data;
1428 struct _sas_device *sas_device;
1429 struct _raid_device *raid_device;
1430 unsigned long flags;
1437 sas_device_priv_data = sdev->hostdata;
1438 sas_device_priv_data->configured_lun = 1;
1439 sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
1440 sas_target_priv_data = sas_device_priv_data->sas_target;
1442 /* raid volume handling */
1443 if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
1445 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1446 raid_device = _scsih_raid_device_find_by_handle(ioc,
1447 sas_target_priv_data->handle);
1448 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1450 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1451 ioc->name, __FILE__, __LINE__, __func__);
1455 _scsih_get_volume_capabilities(ioc, raid_device);
1457 /* RAID Queue Depth Support
1458 * IS volume = underlying qdepth of drive type, either
1459 * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
1460 * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
1462 if (raid_device->device_info &
1463 MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1464 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1467 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1468 if (raid_device->device_info &
1469 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1475 switch (raid_device->volume_type) {
1476 case MPI2_RAID_VOL_TYPE_RAID0:
1479 case MPI2_RAID_VOL_TYPE_RAID1E:
1480 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1481 if (ioc->manu_pg10.OEMIdentifier &&
1482 (ioc->manu_pg10.GenericFlags0 &
1483 MFG10_GF0_R10_DISPLAY) &&
1484 !(raid_device->num_pds % 2))
1489 case MPI2_RAID_VOL_TYPE_RAID1:
1490 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1493 case MPI2_RAID_VOL_TYPE_RAID10:
1494 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1497 case MPI2_RAID_VOL_TYPE_UNKNOWN:
1499 qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
1504 sdev_printk(KERN_INFO, sdev, "%s: "
1505 "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
1506 r_level, raid_device->handle,
1507 (unsigned long long)raid_device->wwid,
1508 raid_device->num_pds, ds);
1509 _scsih_change_queue_depth(sdev, qdepth);
1513 /* non-raid handling */
1514 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1515 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1516 sas_device_priv_data->sas_target->sas_address);
1517 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1519 if (sas_target_priv_data->flags &
1520 MPT_TARGET_FLAGS_RAID_COMPONENT) {
1521 mpt2sas_config_get_volume_handle(ioc,
1522 sas_device->handle, &sas_device->volume_handle);
1523 mpt2sas_config_get_volume_wwid(ioc,
1524 sas_device->volume_handle,
1525 &sas_device->volume_wwid);
1527 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
1528 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
1532 qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
1533 if (sas_device->device_info &
1534 MPI2_SAS_DEVICE_INFO_STP_TARGET)
1536 else if (sas_device->device_info &
1537 MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
1541 sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
1542 "sas_addr(0x%016llx), device_name(0x%016llx)\n",
1543 ds, sas_device->handle,
1544 (unsigned long long)sas_device->sas_address,
1545 (unsigned long long)sas_device->device_name);
1546 sdev_printk(KERN_INFO, sdev, "%s: "
1547 "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
1548 (unsigned long long) sas_device->enclosure_logical_id,
1552 _scsih_display_sata_capabilities(ioc, sas_device, sdev);
1555 _scsih_change_queue_depth(sdev, qdepth);
1558 sas_read_port_mode_page(sdev);
1563 * _scsih_bios_param - fetch head, sector, cylinder info for a disk
1564 * @sdev: scsi device struct
1565 * @bdev: pointer to block device context
1566 * @capacity: device size (in 512 byte sectors)
1567 * @params: three element array to place output:
1568 * params[0] number of heads (max 255)
1569 * params[1] number of sectors (max 63)
1570 * params[2] number of cylinders
1575 _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1576 sector_t capacity, int params[])
1586 dummy = heads * sectors;
1587 cylinders = capacity;
1588 sector_div(cylinders, dummy);
1591 * Handle extended translation size for logical drives
1594 if ((ulong)capacity >= 0x200000) {
1597 dummy = heads * sectors;
1598 cylinders = capacity;
1599 sector_div(cylinders, dummy);
1604 params[1] = sectors;
1605 params[2] = cylinders;
1611 * _scsih_response_code - translation of device response code
1612 * @ioc: per adapter object
1613 * @response_code: response code returned by the device
1618 _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
1622 switch (response_code) {
1623 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
1624 desc = "task management request completed";
1626 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
1627 desc = "invalid frame";
1629 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1630 desc = "task management request not supported";
1632 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
1633 desc = "task management request failed";
1635 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1636 desc = "task management request succeeded";
1638 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1639 desc = "invalid lun";
1642 desc = "overlapped tag attempted";
1644 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1645 desc = "task queued, however not sent to target";
1651 printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
1652 ioc->name, response_code, desc);
1656 * _scsih_tm_done - tm completion routine
1657 * @ioc: per adapter object
1658 * @smid: system request message index
1659 * @msix_index: MSIX table index supplied by the OS
1660 * @reply: reply message frame(lower 32bit addr)
1663 * The callback handler when using scsih_issue_tm.
1665 * Return 1 meaning mf should be freed from _base_interrupt
1666 * 0 means the mf is freed from this function.
1669 _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
1671 MPI2DefaultReply_t *mpi_reply;
1673 if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
1675 if (ioc->tm_cmds.smid != smid)
1677 ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
1678 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
1680 memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
1681 ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
1683 ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
1684 complete(&ioc->tm_cmds.done);
1689 * mpt2sas_scsih_set_tm_flag - set per target tm_busy
1690 * @ioc: per adapter object
1691 * @handle: device handle
1693 * During taskmangement request, we need to freeze the device queue.
1696 mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
1698 struct MPT2SAS_DEVICE *sas_device_priv_data;
1699 struct scsi_device *sdev;
1702 shost_for_each_device(sdev, ioc->shost) {
1705 sas_device_priv_data = sdev->hostdata;
1706 if (!sas_device_priv_data)
1708 if (sas_device_priv_data->sas_target->handle == handle) {
1709 sas_device_priv_data->sas_target->tm_busy = 1;
1711 ioc->ignore_loginfos = 1;
1717 * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
1718 * @ioc: per adapter object
1719 * @handle: device handle
1721 * During taskmangement request, we need to freeze the device queue.
1724 mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
1726 struct MPT2SAS_DEVICE *sas_device_priv_data;
1727 struct scsi_device *sdev;
1730 shost_for_each_device(sdev, ioc->shost) {
1733 sas_device_priv_data = sdev->hostdata;
1734 if (!sas_device_priv_data)
1736 if (sas_device_priv_data->sas_target->handle == handle) {
1737 sas_device_priv_data->sas_target->tm_busy = 0;
1739 ioc->ignore_loginfos = 0;
1745 * mpt2sas_scsih_issue_tm - main routine for sending tm requests
1746 * @ioc: per adapter struct
1747 * @device_handle: device handle
1749 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
1750 * @smid_task: smid assigned to the task
1751 * @timeout: timeout in seconds
1752 * Context: The calling function needs to acquire the tm_cmds.mutex
1754 * A generic API for sending task management requests to firmware.
1756 * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
1759 * The callback index is set inside `ioc->tm_cb_idx`.
1764 mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint lun,
1765 u8 type, u16 smid_task, ulong timeout)
1767 Mpi2SCSITaskManagementRequest_t *mpi_request;
1768 Mpi2SCSITaskManagementReply_t *mpi_reply;
1771 unsigned long timeleft;
1773 if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
1774 printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
1775 __func__, ioc->name);
1779 if (ioc->shost_recovery) {
1780 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
1781 __func__, ioc->name);
1785 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
1786 if (ioc_state & MPI2_DOORBELL_USED) {
1787 dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "unexpected doorbell "
1788 "active!\n", ioc->name));
1789 goto issue_host_reset;
1792 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
1793 mpt2sas_base_fault_info(ioc, ioc_state &
1794 MPI2_DOORBELL_DATA_MASK);
1795 goto issue_host_reset;
1798 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
1800 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
1801 ioc->name, __func__);
1805 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
1806 " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
1808 ioc->tm_cmds.status = MPT2_CMD_PENDING;
1809 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
1810 ioc->tm_cmds.smid = smid;
1811 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
1812 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
1813 mpi_request->DevHandle = cpu_to_le16(handle);
1814 mpi_request->TaskType = type;
1815 mpi_request->TaskMID = cpu_to_le16(smid_task);
1816 mpi_request->VP_ID = 0; /* TODO */
1817 mpi_request->VF_ID = 0;
1818 int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
1819 mpt2sas_scsih_set_tm_flag(ioc, handle);
1820 init_completion(&ioc->tm_cmds.done);
1821 mpt2sas_base_put_smid_hi_priority(ioc, smid);
1822 timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
1823 mpt2sas_scsih_clear_tm_flag(ioc, handle);
1824 if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
1825 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
1826 ioc->name, __func__);
1827 _debug_dump_mf(mpi_request,
1828 sizeof(Mpi2SCSITaskManagementRequest_t)/4);
1829 if (!(ioc->tm_cmds.status & MPT2_CMD_RESET))
1830 goto issue_host_reset;
1833 if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
1834 mpi_reply = ioc->tm_cmds.reply;
1835 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
1836 "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
1837 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
1838 le32_to_cpu(mpi_reply->IOCLogInfo),
1839 le32_to_cpu(mpi_reply->TerminationCount)));
1840 if (ioc->logging_level & MPT_DEBUG_TM)
1841 _scsih_response_code(ioc, mpi_reply->ResponseCode);
1845 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, FORCE_BIG_HAMMER);
1849 * _scsih_abort - eh threads main abort routine
1850 * @sdev: scsi device struct
1852 * Returns SUCCESS if command aborted else FAILED
1855 _scsih_abort(struct scsi_cmnd *scmd)
1857 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1858 struct MPT2SAS_DEVICE *sas_device_priv_data;
1862 struct scsi_cmnd *scmd_lookup;
1864 printk(MPT2SAS_INFO_FMT "attempting task abort! scmd(%p)\n",
1866 scsi_print_command(scmd);
1868 sas_device_priv_data = scmd->device->hostdata;
1869 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
1870 printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
1872 scmd->result = DID_NO_CONNECT << 16;
1873 scmd->scsi_done(scmd);
1878 /* search for the command */
1879 smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
1881 scmd->result = DID_RESET << 16;
1886 /* for hidden raid components and volumes this is not supported */
1887 if (sas_device_priv_data->sas_target->flags &
1888 MPT_TARGET_FLAGS_RAID_COMPONENT ||
1889 sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
1890 scmd->result = DID_RESET << 16;
1895 mutex_lock(&ioc->tm_cmds.mutex);
1896 handle = sas_device_priv_data->sas_target->handle;
1897 mpt2sas_scsih_issue_tm(ioc, handle, sas_device_priv_data->lun,
1898 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30);
1900 /* sanity check - see whether command actually completed */
1901 scmd_lookup = _scsih_scsi_lookup_get(ioc, smid);
1902 if (scmd_lookup && (scmd_lookup->serial_number == scmd->serial_number))
1906 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
1907 mutex_unlock(&ioc->tm_cmds.mutex);
1910 printk(MPT2SAS_INFO_FMT "task abort: %s scmd(%p)\n",
1911 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
1916 * _scsih_dev_reset - eh threads main device reset routine
1917 * @sdev: scsi device struct
1919 * Returns SUCCESS if command aborted else FAILED
1922 _scsih_dev_reset(struct scsi_cmnd *scmd)
1924 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1925 struct MPT2SAS_DEVICE *sas_device_priv_data;
1926 struct _sas_device *sas_device;
1927 unsigned long flags;
1931 printk(MPT2SAS_INFO_FMT "attempting device reset! scmd(%p)\n",
1933 scsi_print_command(scmd);
1935 sas_device_priv_data = scmd->device->hostdata;
1936 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
1937 printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
1939 scmd->result = DID_NO_CONNECT << 16;
1940 scmd->scsi_done(scmd);
1945 /* for hidden raid components obtain the volume_handle */
1947 if (sas_device_priv_data->sas_target->flags &
1948 MPT_TARGET_FLAGS_RAID_COMPONENT) {
1949 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1950 sas_device = _scsih_sas_device_find_by_handle(ioc,
1951 sas_device_priv_data->sas_target->handle);
1953 handle = sas_device->volume_handle;
1954 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1956 handle = sas_device_priv_data->sas_target->handle;
1959 scmd->result = DID_RESET << 16;
1964 mutex_lock(&ioc->tm_cmds.mutex);
1965 mpt2sas_scsih_issue_tm(ioc, handle, 0,
1966 MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, scmd->device->lun,
1970 * sanity check see whether all commands to this device been
1973 if (_scsih_scsi_lookup_find_by_lun(ioc, scmd->device->id,
1974 scmd->device->lun, scmd->device->channel))
1978 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
1979 mutex_unlock(&ioc->tm_cmds.mutex);
1982 printk(MPT2SAS_INFO_FMT "device reset: %s scmd(%p)\n",
1983 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
1988 * _scsih_target_reset - eh threads main target reset routine
1989 * @sdev: scsi device struct
1991 * Returns SUCCESS if command aborted else FAILED
1994 _scsih_target_reset(struct scsi_cmnd *scmd)
1996 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
1997 struct MPT2SAS_DEVICE *sas_device_priv_data;
1998 struct _sas_device *sas_device;
1999 unsigned long flags;
2003 printk(MPT2SAS_INFO_FMT "attempting target reset! scmd(%p)\n",
2005 scsi_print_command(scmd);
2007 sas_device_priv_data = scmd->device->hostdata;
2008 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
2009 printk(MPT2SAS_INFO_FMT "target been deleted! scmd(%p)\n",
2011 scmd->result = DID_NO_CONNECT << 16;
2012 scmd->scsi_done(scmd);
2017 /* for hidden raid components obtain the volume_handle */
2019 if (sas_device_priv_data->sas_target->flags &
2020 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2021 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2022 sas_device = _scsih_sas_device_find_by_handle(ioc,
2023 sas_device_priv_data->sas_target->handle);
2025 handle = sas_device->volume_handle;
2026 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2028 handle = sas_device_priv_data->sas_target->handle;
2031 scmd->result = DID_RESET << 16;
2036 mutex_lock(&ioc->tm_cmds.mutex);
2037 mpt2sas_scsih_issue_tm(ioc, handle, 0,
2038 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30);
2041 * sanity check see whether all commands to this target been
2044 if (_scsih_scsi_lookup_find_by_target(ioc, scmd->device->id,
2045 scmd->device->channel))
2049 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
2050 mutex_unlock(&ioc->tm_cmds.mutex);
2053 printk(MPT2SAS_INFO_FMT "target reset: %s scmd(%p)\n",
2054 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2059 * _scsih_host_reset - eh threads main host reset routine
2060 * @sdev: scsi device struct
2062 * Returns SUCCESS if command aborted else FAILED
2065 _scsih_host_reset(struct scsi_cmnd *scmd)
2067 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2070 printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
2072 scsi_print_command(scmd);
2074 retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2076 r = (retval < 0) ? FAILED : SUCCESS;
2077 printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
2078 ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
2084 * _scsih_fw_event_add - insert and queue up fw_event
2085 * @ioc: per adapter object
2086 * @fw_event: object describing the event
2087 * Context: This function will acquire ioc->fw_event_lock.
2089 * This adds the firmware event object into link list, then queues it up to
2090 * be processed from user context.
2095 _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
2097 unsigned long flags;
2099 if (ioc->firmware_event_thread == NULL)
2102 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2103 list_add_tail(&fw_event->list, &ioc->fw_event_list);
2104 INIT_WORK(&fw_event->work, _firmware_event_work);
2105 queue_work(ioc->firmware_event_thread, &fw_event->work);
2106 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2110 * _scsih_fw_event_free - delete fw_event
2111 * @ioc: per adapter object
2112 * @fw_event: object describing the event
2113 * Context: This function will acquire ioc->fw_event_lock.
2115 * This removes firmware event object from link list, frees associated memory.
2120 _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2123 unsigned long flags;
2125 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2126 list_del(&fw_event->list);
2127 kfree(fw_event->event_data);
2129 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2133 * _scsih_fw_event_add - requeue an event
2134 * @ioc: per adapter object
2135 * @fw_event: object describing the event
2136 * Context: This function will acquire ioc->fw_event_lock.
2141 _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2142 *fw_event, unsigned long delay)
2144 unsigned long flags;
2145 if (ioc->firmware_event_thread == NULL)
2148 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2149 queue_work(ioc->firmware_event_thread, &fw_event->work);
2150 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2154 * _scsih_fw_event_off - turn flag off preventing event handling
2155 * @ioc: per adapter object
2157 * Used to prevent handling of firmware events during adapter reset
2163 _scsih_fw_event_off(struct MPT2SAS_ADAPTER *ioc)
2165 unsigned long flags;
2167 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2168 ioc->fw_events_off = 1;
2169 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2174 * _scsih_fw_event_on - turn flag on allowing firmware event handling
2175 * @ioc: per adapter object
2180 _scsih_fw_event_on(struct MPT2SAS_ADAPTER *ioc)
2182 unsigned long flags;
2184 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2185 ioc->fw_events_off = 0;
2186 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2190 * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
2191 * @ioc: per adapter object
2192 * @handle: device handle
2194 * During device pull we need to appropiately set the sdev state.
2197 _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2199 struct MPT2SAS_DEVICE *sas_device_priv_data;
2200 struct scsi_device *sdev;
2202 shost_for_each_device(sdev, ioc->shost) {
2203 sas_device_priv_data = sdev->hostdata;
2204 if (!sas_device_priv_data)
2206 if (!sas_device_priv_data->block)
2208 if (sas_device_priv_data->sas_target->handle == handle) {
2209 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2210 MPT2SAS_INFO_FMT "SDEV_RUNNING: "
2211 "handle(0x%04x)\n", ioc->name, handle));
2212 sas_device_priv_data->block = 0;
2213 scsi_internal_device_unblock(sdev);
2219 * _scsih_block_io_device - set the device state to SDEV_BLOCK
2220 * @ioc: per adapter object
2221 * @handle: device handle
2223 * During device pull we need to appropiately set the sdev state.
2226 _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2228 struct MPT2SAS_DEVICE *sas_device_priv_data;
2229 struct scsi_device *sdev;
2231 shost_for_each_device(sdev, ioc->shost) {
2232 sas_device_priv_data = sdev->hostdata;
2233 if (!sas_device_priv_data)
2235 if (sas_device_priv_data->block)
2237 if (sas_device_priv_data->sas_target->handle == handle) {
2238 dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
2239 MPT2SAS_INFO_FMT "SDEV_BLOCK: "
2240 "handle(0x%04x)\n", ioc->name, handle));
2241 sas_device_priv_data->block = 1;
2242 scsi_internal_device_block(sdev);
2248 * _scsih_block_io_to_children_attached_to_ex
2249 * @ioc: per adapter object
2250 * @sas_expander: the sas_device object
2252 * This routine set sdev state to SDEV_BLOCK for all devices
2253 * attached to this expander. This function called when expander is
2257 _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
2258 struct _sas_node *sas_expander)
2260 struct _sas_port *mpt2sas_port;
2261 struct _sas_device *sas_device;
2262 struct _sas_node *expander_sibling;
2263 unsigned long flags;
2268 list_for_each_entry(mpt2sas_port,
2269 &sas_expander->sas_port_list, port_list) {
2270 if (mpt2sas_port->remote_identify.device_type ==
2272 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2274 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
2275 mpt2sas_port->remote_identify.sas_address);
2276 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2279 _scsih_block_io_device(ioc, sas_device->handle);
2283 list_for_each_entry(mpt2sas_port,
2284 &sas_expander->sas_port_list, port_list) {
2286 if (mpt2sas_port->remote_identify.device_type ==
2287 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
2288 mpt2sas_port->remote_identify.device_type ==
2289 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
2291 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2293 mpt2sas_scsih_expander_find_by_sas_address(
2294 ioc, mpt2sas_port->remote_identify.sas_address);
2295 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2296 _scsih_block_io_to_children_attached_to_ex(ioc,
2303 * _scsih_block_io_to_children_attached_directly
2304 * @ioc: per adapter object
2305 * @event_data: topology change event data
2307 * This routine set sdev state to SDEV_BLOCK for all devices
2308 * direct attached during device pull.
2311 _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
2312 Mpi2EventDataSasTopologyChangeList_t *event_data)
2320 for (i = 0; i < event_data->NumEntries; i++) {
2321 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2324 phy_number = event_data->StartPhyNum + i;
2325 reason_code = event_data->PHY[i].PhyStatus &
2326 MPI2_EVENT_SAS_TOPO_RC_MASK;
2327 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
2328 _scsih_block_io_device(ioc, handle);
2329 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED) {
2330 link_rate = event_data->PHY[i].LinkRate >> 4;
2331 if (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)
2332 _scsih_ublock_io_device(ioc, handle);
2338 * _scsih_tm_tr_send - send task management request
2339 * @ioc: per adapter object
2340 * @handle: device handle
2341 * Context: interrupt time.
2343 * This code is to initiate the device removal handshake protocal
2344 * with controller firmware. This function will issue target reset
2345 * using high priority request queue. It will send a sas iounit
2346 * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
2348 * This is designed to send muliple task management request at the same
2349 * time to the fifo. If the fifo is full, we will append the request,
2350 * and process it in a future completion.
2353 _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2355 Mpi2SCSITaskManagementRequest_t *mpi_request;
2356 struct MPT2SAS_TARGET *sas_target_priv_data;
2358 struct _sas_device *sas_device;
2359 unsigned long flags;
2360 struct _tr_list *delayed_tr;
2362 if (ioc->shost_recovery) {
2363 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2364 __func__, ioc->name);
2368 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2369 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2371 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2372 printk(MPT2SAS_ERR_FMT "%s: failed finding sas_device\n",
2373 ioc->name, __func__);
2376 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2378 /* skip is hidden raid component */
2379 if (sas_device->hidden_raid_component)
2382 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
2384 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
2387 INIT_LIST_HEAD(&delayed_tr->list);
2388 delayed_tr->handle = handle;
2389 delayed_tr->state = MPT2SAS_REQ_SAS_CNTRL;
2390 list_add_tail(&delayed_tr->list,
2391 &ioc->delayed_tr_list);
2392 if (sas_device->starget)
2393 dewtprintk(ioc, starget_printk(KERN_INFO,
2394 sas_device->starget, "DELAYED:tr:handle(0x%04x), "
2395 "(open)\n", sas_device->handle));
2399 if (sas_device->starget && sas_device->starget->hostdata) {
2400 sas_target_priv_data = sas_device->starget->hostdata;
2401 sas_target_priv_data->tm_busy = 1;
2402 dewtprintk(ioc, starget_printk(KERN_INFO, sas_device->starget,
2403 "tr:handle(0x%04x), (open)\n", sas_device->handle));
2406 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2407 memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
2408 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
2409 mpi_request->DevHandle = cpu_to_le16(handle);
2410 mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
2411 sas_device->state |= MPTSAS_STATE_TR_SEND;
2412 sas_device->state |= MPT2SAS_REQ_SAS_CNTRL;
2413 mpt2sas_base_put_smid_hi_priority(ioc, smid);
2419 * _scsih_sas_control_complete - completion routine
2420 * @ioc: per adapter object
2421 * @smid: system request message index
2422 * @msix_index: MSIX table index supplied by the OS
2423 * @reply: reply message frame(lower 32bit addr)
2424 * Context: interrupt time.
2426 * This is the sas iounit controll completion routine.
2427 * This code is part of the code to initiate the device removal
2428 * handshake protocal with controller firmware.
2430 * Return 1 meaning mf should be freed from _base_interrupt
2431 * 0 means the mf is freed from this function.
2434 _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
2435 u8 msix_index, u32 reply)
2437 unsigned long flags;
2439 struct _sas_device *sas_device;
2440 Mpi2SasIoUnitControlReply_t *mpi_reply =
2441 mpt2sas_base_get_reply_virt_addr(ioc, reply);
2443 handle = le16_to_cpu(mpi_reply->DevHandle);
2445 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2446 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2448 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2449 printk(MPT2SAS_ERR_FMT "%s: failed finding sas_device\n",
2450 ioc->name, __func__);
2453 sas_device->state |= MPTSAS_STATE_CNTRL_COMPLETE;
2454 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2456 if (sas_device->starget)
2457 dewtprintk(ioc, starget_printk(KERN_INFO, sas_device->starget,
2458 "sc_complete:handle(0x%04x), "
2459 "ioc_status(0x%04x), loginfo(0x%08x)\n",
2460 handle, le16_to_cpu(mpi_reply->IOCStatus),
2461 le32_to_cpu(mpi_reply->IOCLogInfo)));
2466 * _scsih_tm_tr_complete -
2467 * @ioc: per adapter object
2468 * @smid: system request message index
2469 * @msix_index: MSIX table index supplied by the OS
2470 * @reply: reply message frame(lower 32bit addr)
2471 * Context: interrupt time.
2473 * This is the target reset completion routine.
2474 * This code is part of the code to initiate the device removal
2475 * handshake protocal with controller firmware.
2476 * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
2478 * Return 1 meaning mf should be freed from _base_interrupt
2479 * 0 means the mf is freed from this function.
2482 _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
2485 unsigned long flags;
2487 struct _sas_device *sas_device;
2488 Mpi2SCSITaskManagementReply_t *mpi_reply =
2489 mpt2sas_base_get_reply_virt_addr(ioc, reply);
2490 Mpi2SasIoUnitControlRequest_t *mpi_request;
2492 struct MPT2SAS_TARGET *sas_target_priv_data;
2493 struct _tr_list *delayed_tr;
2496 handle = le16_to_cpu(mpi_reply->DevHandle);
2497 spin_lock_irqsave(&ioc->sas_device_lock, flags);
2498 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
2500 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2501 printk(MPT2SAS_ERR_FMT "%s: failed finding sas_device\n",
2502 ioc->name, __func__);
2505 sas_device->state |= MPTSAS_STATE_TR_COMPLETE;
2506 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
2508 if (sas_device->starget)
2509 dewtprintk(ioc, starget_printk(KERN_INFO, sas_device->starget,
2510 "tr_complete:handle(0x%04x), (%s) ioc_status(0x%04x), "
2511 "loginfo(0x%08x), completed(%d)\n",
2512 sas_device->handle, (sas_device->state &
2513 MPT2SAS_REQ_SAS_CNTRL) ? "open" : "active",
2514 le16_to_cpu(mpi_reply->IOCStatus),
2515 le32_to_cpu(mpi_reply->IOCLogInfo),
2516 le32_to_cpu(mpi_reply->TerminationCount)));
2518 if (sas_device->starget && sas_device->starget->hostdata) {
2519 sas_target_priv_data = sas_device->starget->hostdata;
2520 sas_target_priv_data->tm_busy = 0;
2523 if (!list_empty(&ioc->delayed_tr_list)) {
2524 delayed_tr = list_entry(ioc->delayed_tr_list.next,
2525 struct _tr_list, list);
2526 mpt2sas_base_free_smid(ioc, smid);
2527 if (delayed_tr->state & MPT2SAS_REQ_SAS_CNTRL)
2528 _scsih_tm_tr_send(ioc, delayed_tr->handle);
2529 list_del(&delayed_tr->list);
2531 rc = 0; /* tells base_interrupt not to free mf */
2536 if (!(sas_device->state & MPT2SAS_REQ_SAS_CNTRL))
2539 if (ioc->shost_recovery) {
2540 printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
2541 __func__, ioc->name);
2545 smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
2546 if (!smid_sas_ctrl) {
2547 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2548 ioc->name, __func__);
2552 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
2553 memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
2554 mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
2555 mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
2556 mpi_request->DevHandle = mpi_reply->DevHandle;
2557 sas_device->state |= MPTSAS_STATE_CNTRL_SEND;
2558 mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
2563 * _scsih_check_topo_delete_events - sanity check on topo events
2564 * @ioc: per adapter object
2565 * @event_data: the event data payload
2567 * This routine added to better handle cable breaker.
2569 * This handles the case where driver recieves multiple expander
2570 * add and delete events in a single shot. When there is a delete event
2571 * the routine will void any pending add events waiting in the event queue.
2576 _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
2577 Mpi2EventDataSasTopologyChangeList_t *event_data)
2579 struct fw_event_work *fw_event;
2580 Mpi2EventDataSasTopologyChangeList_t *local_event_data;
2581 u16 expander_handle;
2582 struct _sas_node *sas_expander;
2583 unsigned long flags;
2587 for (i = 0 ; i < event_data->NumEntries; i++) {
2588 if (event_data->PHY[i].PhyStatus &
2589 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT)
2591 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
2594 reason_code = event_data->PHY[i].PhyStatus &
2595 MPI2_EVENT_SAS_TOPO_RC_MASK;
2596 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
2597 _scsih_tm_tr_send(ioc, handle);
2600 expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
2601 if (expander_handle < ioc->sas_hba.num_phys) {
2602 _scsih_block_io_to_children_attached_directly(ioc, event_data);
2606 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
2607 || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
2608 spin_lock_irqsave(&ioc->sas_node_lock, flags);
2609 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
2611 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
2612 _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
2613 } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
2614 _scsih_block_io_to_children_attached_directly(ioc, event_data);
2616 if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
2619 /* mark ignore flag for pending events */
2620 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2621 list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
2622 if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
2625 local_event_data = fw_event->event_data;
2626 if (local_event_data->ExpStatus ==
2627 MPI2_EVENT_SAS_TOPO_ES_ADDED ||
2628 local_event_data->ExpStatus ==
2629 MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
2630 if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
2632 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT
2633 "setting ignoring flag\n", ioc->name));
2634 fw_event->ignore = 1;
2638 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2642 * _scsih_flush_running_cmds - completing outstanding commands.
2643 * @ioc: per adapter object
2645 * The flushing out of all pending scmd commands following host reset,
2646 * where all IO is dropped to the floor.
2651 _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
2653 struct scsi_cmnd *scmd;
2657 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
2658 scmd = _scsih_scsi_lookup_get(ioc, smid);
2662 mpt2sas_base_free_smid(ioc, smid);
2663 scsi_dma_unmap(scmd);
2664 scmd->result = DID_RESET << 16;
2665 scmd->scsi_done(scmd);
2667 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
2672 * _scsih_setup_eedp - setup MPI request for EEDP transfer
2673 * @scmd: pointer to scsi command object
2674 * @mpi_request: pointer to the SCSI_IO reqest message frame
2676 * Supporting protection 1 and 3.
2681 _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
2684 unsigned char prot_op = scsi_get_prot_op(scmd);
2685 unsigned char prot_type = scsi_get_prot_type(scmd);
2687 if (prot_type == SCSI_PROT_DIF_TYPE0 ||
2688 prot_type == SCSI_PROT_DIF_TYPE2 ||
2689 prot_op == SCSI_PROT_NORMAL)
2692 if (prot_op == SCSI_PROT_READ_STRIP)
2693 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
2694 else if (prot_op == SCSI_PROT_WRITE_INSERT)
2695 eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
2699 mpi_request->EEDPBlockSize = scmd->device->sector_size;
2701 switch (prot_type) {
2702 case SCSI_PROT_DIF_TYPE1:
2705 * enable ref/guard checking
2706 * auto increment ref tag
2708 mpi_request->EEDPFlags = eedp_flags |
2709 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
2710 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
2711 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
2712 mpi_request->CDB.EEDP32.PrimaryReferenceTag =
2713 cpu_to_be32(scsi_get_lba(scmd));
2717 case SCSI_PROT_DIF_TYPE3:
2720 * enable guard checking
2722 mpi_request->EEDPFlags = eedp_flags |
2723 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
2730 * _scsih_eedp_error_handling - return sense code for EEDP errors
2731 * @scmd: pointer to scsi command object
2732 * @ioc_status: ioc status
2737 _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
2743 switch (ioc_status) {
2744 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
2747 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
2750 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
2758 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
2759 sk = ILLEGAL_REQUEST;
2760 host_byte = DID_ABORT;
2762 sk = ABORTED_COMMAND;
2766 scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
2767 scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
2768 SAM_STAT_CHECK_CONDITION;
2772 * _scsih_qcmd - main scsi request entry point
2773 * @scmd: pointer to scsi command object
2774 * @done: function pointer to be invoked on completion
2776 * The callback index is set inside `ioc->scsi_io_cb_idx`.
2778 * Returns 0 on success. If there's a failure, return either:
2779 * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
2780 * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
2783 _scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
2785 struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
2786 struct MPT2SAS_DEVICE *sas_device_priv_data;
2787 struct MPT2SAS_TARGET *sas_target_priv_data;
2788 Mpi2SCSIIORequest_t *mpi_request;
2792 scmd->scsi_done = done;
2793 sas_device_priv_data = scmd->device->hostdata;
2794 if (!sas_device_priv_data) {
2795 scmd->result = DID_NO_CONNECT << 16;
2796 scmd->scsi_done(scmd);
2800 sas_target_priv_data = sas_device_priv_data->sas_target;
2801 if (!sas_target_priv_data || sas_target_priv_data->handle ==
2802 MPT2SAS_INVALID_DEVICE_HANDLE || sas_target_priv_data->deleted) {
2803 scmd->result = DID_NO_CONNECT << 16;
2804 scmd->scsi_done(scmd);
2808 /* see if we are busy with task managment stuff */
2809 if (sas_target_priv_data->tm_busy)
2810 return SCSI_MLQUEUE_DEVICE_BUSY;
2811 else if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
2812 return SCSI_MLQUEUE_HOST_BUSY;
2814 if (scmd->sc_data_direction == DMA_FROM_DEVICE)
2815 mpi_control = MPI2_SCSIIO_CONTROL_READ;
2816 else if (scmd->sc_data_direction == DMA_TO_DEVICE)
2817 mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
2819 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
2822 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
2823 if (scmd->device->tagged_supported) {
2824 if (scmd->device->ordered_tags)
2825 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
2827 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
2829 /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
2830 /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
2832 mpi_control |= (0x500);
2835 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
2837 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON))
2838 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
2840 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
2842 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
2843 ioc->name, __func__);
2846 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
2847 memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
2848 _scsih_setup_eedp(scmd, mpi_request);
2849 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2850 if (sas_device_priv_data->sas_target->flags &
2851 MPT_TARGET_FLAGS_RAID_COMPONENT)
2852 mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
2854 mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2855 mpi_request->DevHandle =
2856 cpu_to_le16(sas_device_priv_data->sas_target->handle);
2857 mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
2858 mpi_request->Control = cpu_to_le32(mpi_control);
2859 mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
2860 mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
2861 mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
2862 mpi_request->SenseBufferLowAddress =
2863 (u32)mpt2sas_base_get_sense_buffer_dma(ioc, smid);
2864 mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
2865 mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
2866 MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
2867 mpi_request->VF_ID = 0; /* TODO */
2868 mpi_request->VP_ID = 0;
2869 int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
2871 memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
2873 if (!mpi_request->DataLength) {
2874 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
2876 if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
2877 mpt2sas_base_free_smid(ioc, smid);
2882 mpt2sas_base_put_smid_scsi_io(ioc, smid,
2883 sas_device_priv_data->sas_target->handle);
2887 return SCSI_MLQUEUE_HOST_BUSY;
2891 * _scsih_normalize_sense - normalize descriptor and fixed format sense data
2892 * @sense_buffer: sense data returned by target
2893 * @data: normalized skey/asc/ascq
2898 _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
2900 if ((sense_buffer[0] & 0x7F) >= 0x72) {
2901 /* descriptor format */
2902 data->skey = sense_buffer[1] & 0x0F;
2903 data->asc = sense_buffer[2];
2904 data->ascq = sense_buffer[3];
2907 data->skey = sense_buffer[2] & 0x0F;
2908 data->asc = sense_buffer[12];
2909 data->ascq = sense_buffer[13];
2913 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
2915 * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
2916 * @ioc: per adapter object
2917 * @scmd: pointer to scsi command object
2918 * @mpi_reply: reply mf payload returned from firmware
2920 * scsi_status - SCSI Status code returned from target device
2921 * scsi_state - state info associated with SCSI_IO determined by ioc
2922 * ioc_status - ioc supplied status info
2927 _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
2928 Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
2932 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
2933 MPI2_IOCSTATUS_MASK;
2934 u8 scsi_state = mpi_reply->SCSIState;
2935 u8 scsi_status = mpi_reply->SCSIStatus;
2936 char *desc_ioc_state = NULL;
2937 char *desc_scsi_status = NULL;
2938 char *desc_scsi_state = ioc->tmp_string;
2939 u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
2941 if (log_info == 0x31170000)
2944 switch (ioc_status) {
2945 case MPI2_IOCSTATUS_SUCCESS:
2946 desc_ioc_state = "success";
2948 case MPI2_IOCSTATUS_INVALID_FUNCTION:
2949 desc_ioc_state = "invalid function";
2951 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
2952 desc_ioc_state = "scsi recovered error";
2954 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
2955 desc_ioc_state = "scsi invalid dev handle";
2957 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
2958 desc_ioc_state = "scsi device not there";
2960 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
2961 desc_ioc_state = "scsi data overrun";
2963 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
2964 desc_ioc_state = "scsi data underrun";
2966 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
2967 desc_ioc_state = "scsi io data error";
2969 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
2970 desc_ioc_state = "scsi protocol error";
2972 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
2973 desc_ioc_state = "scsi task terminated";
2975 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
2976 desc_ioc_state = "scsi residual mismatch";
2978 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
2979 desc_ioc_state = "scsi task mgmt failed";
2981 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
2982 desc_ioc_state = "scsi ioc terminated";
2984 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
2985 desc_ioc_state = "scsi ext terminated";
2987 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
2988 desc_ioc_state = "eedp guard error";
2990 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
2991 desc_ioc_state = "eedp ref tag error";
2993 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
2994 desc_ioc_state = "eedp app tag error";
2997 desc_ioc_state = "unknown";
3001 switch (scsi_status) {
3002 case MPI2_SCSI_STATUS_GOOD:
3003 desc_scsi_status = "good";
3005 case MPI2_SCSI_STATUS_CHECK_CONDITION:
3006 desc_scsi_status = "check condition";
3008 case MPI2_SCSI_STATUS_CONDITION_MET:
3009 desc_scsi_status = "condition met";
3011 case MPI2_SCSI_STATUS_BUSY:
3012 desc_scsi_status = "busy";
3014 case MPI2_SCSI_STATUS_INTERMEDIATE:
3015 desc_scsi_status = "intermediate";
3017 case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
3018 desc_scsi_status = "intermediate condmet";
3020 case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
3021 desc_scsi_status = "reservation conflict";
3023 case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
3024 desc_scsi_status = "command terminated";
3026 case MPI2_SCSI_STATUS_TASK_SET_FULL:
3027 desc_scsi_status = "task set full";
3029 case MPI2_SCSI_STATUS_ACA_ACTIVE:
3030 desc_scsi_status = "aca active";
3032 case MPI2_SCSI_STATUS_TASK_ABORTED:
3033 desc_scsi_status = "task aborted";
3036 desc_scsi_status = "unknown";
3040 desc_scsi_state[0] = '\0';
3042 desc_scsi_state = " ";
3043 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
3044 strcat(desc_scsi_state, "response info ");
3045 if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3046 strcat(desc_scsi_state, "state terminated ");
3047 if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
3048 strcat(desc_scsi_state, "no status ");
3049 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
3050 strcat(desc_scsi_state, "autosense failed ");
3051 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
3052 strcat(desc_scsi_state, "autosense valid ");
3054 scsi_print_command(scmd);
3055 printk(MPT2SAS_WARN_FMT "\tdev handle(0x%04x), "
3056 "ioc_status(%s)(0x%04x), smid(%d)\n", ioc->name,
3057 le16_to_cpu(mpi_reply->DevHandle), desc_ioc_state,
3059 printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
3060 "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
3061 scsi_get_resid(scmd));
3062 printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
3063 "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
3064 le32_to_cpu(mpi_reply->TransferCount), scmd->result);
3065 printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
3066 "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
3067 scsi_status, desc_scsi_state, scsi_state);
3069 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3070 struct sense_info data;
3071 _scsih_normalize_sense(scmd->sense_buffer, &data);
3072 printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
3073 "[0x%02x,0x%02x,0x%02x]\n", ioc->name, data.skey,
3074 data.asc, data.ascq);
3077 if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
3078 response_info = le32_to_cpu(mpi_reply->ResponseInfo);
3079 response_bytes = (u8 *)&response_info;
3080 _scsih_response_code(ioc, response_bytes[3]);
3086 * _scsih_smart_predicted_fault - illuminate Fault LED
3087 * @ioc: per adapter object
3088 * @handle: device handle
3093 _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3095 Mpi2SepReply_t mpi_reply;
3096 Mpi2SepRequest_t mpi_request;
3097 struct scsi_target *starget;
3098 struct MPT2SAS_TARGET *sas_target_priv_data;
3099 Mpi2EventNotificationReply_t *event_reply;
3100 Mpi2EventDataSasDeviceStatusChange_t *event_data;
3101 struct _sas_device *sas_device;
3103 unsigned long flags;
3105 /* only handle non-raid devices */
3106 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3107 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3109 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3112 starget = sas_device->starget;
3113 sas_target_priv_data = starget->hostdata;
3115 if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
3116 ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
3117 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3120 starget_printk(KERN_WARNING, starget, "predicted fault\n");
3121 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3123 if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) {
3124 memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
3125 mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
3126 mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
3127 mpi_request.SlotStatus =
3128 MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT;
3129 mpi_request.DevHandle = cpu_to_le16(handle);
3130 mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
3131 if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
3132 &mpi_request)) != 0) {
3133 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3134 ioc->name, __FILE__, __LINE__, __func__);
3138 if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
3139 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
3140 "enclosure_processor: ioc_status (0x%04x), "
3141 "loginfo(0x%08x)\n", ioc->name,
3142 le16_to_cpu(mpi_reply.IOCStatus),
3143 le32_to_cpu(mpi_reply.IOCLogInfo)));
3148 /* insert into event log */
3149 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
3150 sizeof(Mpi2EventDataSasDeviceStatusChange_t);
3151 event_reply = kzalloc(sz, GFP_KERNEL);
3153 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3154 ioc->name, __FILE__, __LINE__, __func__);
3158 event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
3159 event_reply->Event =
3160 cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
3161 event_reply->MsgLength = sz/4;
3162 event_reply->EventDataLength =
3163 cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
3164 event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
3165 event_reply->EventData;
3166 event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
3167 event_data->ASC = 0x5D;
3168 event_data->DevHandle = cpu_to_le16(handle);
3169 event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
3170 mpt2sas_ctl_add_to_event_log(ioc, event_reply);
3175 * _scsih_io_done - scsi request callback
3176 * @ioc: per adapter object
3177 * @smid: system request message index
3178 * @msix_index: MSIX table index supplied by the OS
3179 * @reply: reply message frame(lower 32bit addr)
3181 * Callback handler when using _scsih_qcmd.
3183 * Return 1 meaning mf should be freed from _base_interrupt
3184 * 0 means the mf is freed from this function.
3187 _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
3189 Mpi2SCSIIORequest_t *mpi_request;
3190 Mpi2SCSIIOReply_t *mpi_reply;
3191 struct scsi_cmnd *scmd;
3197 struct MPT2SAS_DEVICE *sas_device_priv_data;
3200 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
3201 scmd = _scsih_scsi_lookup_get(ioc, smid);
3205 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3207 if (mpi_reply == NULL) {
3208 scmd->result = DID_OK << 16;
3212 sas_device_priv_data = scmd->device->hostdata;
3213 if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
3214 sas_device_priv_data->sas_target->deleted) {
3215 scmd->result = DID_NO_CONNECT << 16;
3219 /* turning off TLR */
3220 if (!sas_device_priv_data->tlr_snoop_check) {
3221 sas_device_priv_data->tlr_snoop_check++;
3222 if (sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) {
3223 response_code = (le32_to_cpu(mpi_reply->ResponseInfo)
3225 if (response_code ==
3226 MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
3227 sas_device_priv_data->flags &=
3232 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
3233 scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
3234 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
3235 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
3236 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
3239 ioc_status &= MPI2_IOCSTATUS_MASK;
3240 scsi_state = mpi_reply->SCSIState;
3241 scsi_status = mpi_reply->SCSIStatus;
3243 if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
3244 (scsi_status == MPI2_SCSI_STATUS_BUSY ||
3245 scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
3246 scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
3247 ioc_status = MPI2_IOCSTATUS_SUCCESS;
3250 if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
3251 struct sense_info data;
3252 const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
3254 u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
3255 le32_to_cpu(mpi_reply->SenseCount));
3256 memcpy(scmd->sense_buffer, sense_data, sz);
3257 _scsih_normalize_sense(scmd->sense_buffer, &data);
3258 /* failure prediction threshold exceeded */
3259 if (data.asc == 0x5D)
3260 _scsih_smart_predicted_fault(ioc,
3261 le16_to_cpu(mpi_reply->DevHandle));
3264 switch (ioc_status) {
3265 case MPI2_IOCSTATUS_BUSY:
3266 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
3267 scmd->result = SAM_STAT_BUSY;
3270 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
3271 scmd->result = DID_NO_CONNECT << 16;
3274 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
3275 if (sas_device_priv_data->block) {
3276 scmd->result = (DID_BUS_BUSY << 16);
3280 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
3281 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
3282 scmd->result = DID_RESET << 16;
3285 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
3286 if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
3287 scmd->result = DID_SOFT_ERROR << 16;
3289 scmd->result = (DID_OK << 16) | scsi_status;
3292 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
3293 scmd->result = (DID_OK << 16) | scsi_status;
3295 if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
3298 if (xfer_cnt < scmd->underflow) {
3299 if (scsi_status == SAM_STAT_BUSY)
3300 scmd->result = SAM_STAT_BUSY;
3302 scmd->result = DID_SOFT_ERROR << 16;
3303 } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
3304 MPI2_SCSI_STATE_NO_SCSI_STATUS))
3305 scmd->result = DID_SOFT_ERROR << 16;
3306 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3307 scmd->result = DID_RESET << 16;
3308 else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
3309 mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
3310 mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
3311 scmd->result = (DRIVER_SENSE << 24) |
3312 SAM_STAT_CHECK_CONDITION;
3313 scmd->sense_buffer[0] = 0x70;
3314 scmd->sense_buffer[2] = ILLEGAL_REQUEST;
3315 scmd->sense_buffer[12] = 0x20;
3316 scmd->sense_buffer[13] = 0;
3320 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
3321 scsi_set_resid(scmd, 0);
3322 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
3323 case MPI2_IOCSTATUS_SUCCESS:
3324 scmd->result = (DID_OK << 16) | scsi_status;
3325 if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
3326 MPI2_SCSI_STATE_NO_SCSI_STATUS))
3327 scmd->result = DID_SOFT_ERROR << 16;
3328 else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
3329 scmd->result = DID_RESET << 16;
3332 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
3333 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
3334 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
3335 _scsih_eedp_error_handling(scmd, ioc_status);
3337 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
3338 case MPI2_IOCSTATUS_INVALID_FUNCTION:
3339 case MPI2_IOCSTATUS_INVALID_SGL:
3340 case MPI2_IOCSTATUS_INTERNAL_ERROR:
3341 case MPI2_IOCSTATUS_INVALID_FIELD:
3342 case MPI2_IOCSTATUS_INVALID_STATE:
3343 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
3344 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
3346 scmd->result = DID_SOFT_ERROR << 16;
3351 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3352 if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
3353 _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
3357 scsi_dma_unmap(scmd);
3358 scmd->scsi_done(scmd);
3363 * _scsih_sas_host_refresh - refreshing sas host object contents
3364 * @ioc: per adapter object
3365 * @update: update link information
3368 * During port enable, fw will send topology events for every device. Its
3369 * possible that the handles may change from the previous setting, so this
3370 * code keeping handles updating if changed.
3375 _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc, u8 update)
3380 Mpi2ConfigReply_t mpi_reply;
3381 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
3383 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
3384 "updating handles for sas_host(0x%016llx)\n",
3385 ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
3387 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
3388 * sizeof(Mpi2SasIOUnit0PhyData_t));
3389 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
3390 if (!sas_iounit_pg0) {
3391 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3392 ioc->name, __FILE__, __LINE__, __func__);
3395 if (!(mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
3396 sas_iounit_pg0, sz))) {
3397 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3398 MPI2_IOCSTATUS_MASK;
3399 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3401 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
3402 ioc->sas_hba.phy[i].handle =
3403 le16_to_cpu(sas_iounit_pg0->PhyData[i].
3404 ControllerDevHandle);
3406 mpt2sas_transport_update_links(
3408 ioc->sas_hba.phy[i].handle,
3409 le16_to_cpu(sas_iounit_pg0->PhyData[i].
3410 AttachedDevHandle), i,
3411 sas_iounit_pg0->PhyData[i].
3412 NegotiatedLinkRate >> 4);
3417 kfree(sas_iounit_pg0);
3421 * _scsih_sas_host_add - create sas host object
3422 * @ioc: per adapter object
3424 * Creating host side data object, stored in ioc->sas_hba
3429 _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
3432 Mpi2ConfigReply_t mpi_reply;
3433 Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
3434 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
3435 Mpi2SasPhyPage0_t phy_pg0;
3436 Mpi2SasDevicePage0_t sas_device_pg0;
3437 Mpi2SasEnclosurePage0_t enclosure_pg0;
3440 u16 device_missing_delay;
3442 mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
3443 if (!ioc->sas_hba.num_phys) {
3444 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3445 ioc->name, __FILE__, __LINE__, __func__);
3449 /* sas_iounit page 0 */
3450 sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
3451 sizeof(Mpi2SasIOUnit0PhyData_t));
3452 sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
3453 if (!sas_iounit_pg0) {
3454 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3455 ioc->name, __FILE__, __LINE__, __func__);
3458 if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
3459 sas_iounit_pg0, sz))) {
3460 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3461 ioc->name, __FILE__, __LINE__, __func__);
3464 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3465 MPI2_IOCSTATUS_MASK;
3466 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3467 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3468 ioc->name, __FILE__, __LINE__, __func__);
3472 /* sas_iounit page 1 */
3473 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
3474 sizeof(Mpi2SasIOUnit1PhyData_t));
3475 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
3476 if (!sas_iounit_pg1) {
3477 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3478 ioc->name, __FILE__, __LINE__, __func__);
3481 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
3482 sas_iounit_pg1, sz))) {
3483 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3484 ioc->name, __FILE__, __LINE__, __func__);
3487 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3488 MPI2_IOCSTATUS_MASK;
3489 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3490 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3491 ioc->name, __FILE__, __LINE__, __func__);
3495 ioc->io_missing_delay =
3496 le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
3497 device_missing_delay =
3498 le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
3499 if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
3500 ioc->device_missing_delay = (device_missing_delay &
3501 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
3503 ioc->device_missing_delay = device_missing_delay &
3504 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
3506 ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
3507 ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
3508 sizeof(struct _sas_phy), GFP_KERNEL);
3509 if (!ioc->sas_hba.phy) {
3510 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3511 ioc->name, __FILE__, __LINE__, __func__);
3514 for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
3515 if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
3517 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3518 ioc->name, __FILE__, __LINE__, __func__);
3521 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3522 MPI2_IOCSTATUS_MASK;
3523 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3524 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3525 ioc->name, __FILE__, __LINE__, __func__);
3528 ioc->sas_hba.phy[i].handle =
3529 le16_to_cpu(sas_iounit_pg0->PhyData[i].ControllerDevHandle);
3530 ioc->sas_hba.phy[i].phy_id = i;
3531 mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
3532 phy_pg0, ioc->sas_hba.parent_dev);
3534 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
3535 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.phy[0].handle))) {
3536 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3537 ioc->name, __FILE__, __LINE__, __func__);
3540 ioc->sas_hba.handle = le16_to_cpu(sas_device_pg0.DevHandle);
3541 ioc->sas_hba.enclosure_handle =
3542 le16_to_cpu(sas_device_pg0.EnclosureHandle);
3543 ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
3544 printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
3545 "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
3546 (unsigned long long) ioc->sas_hba.sas_address,
3547 ioc->sas_hba.num_phys) ;
3549 if (ioc->sas_hba.enclosure_handle) {
3550 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
3552 MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3553 ioc->sas_hba.enclosure_handle))) {
3554 ioc->sas_hba.enclosure_logical_id =
3555 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3560 kfree(sas_iounit_pg1);
3561 kfree(sas_iounit_pg0);
3565 * _scsih_expander_add - creating expander object
3566 * @ioc: per adapter object
3567 * @handle: expander handle
3569 * Creating expander object, stored in ioc->sas_expander_list.
3571 * Return 0 for success, else error.
3574 _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3576 struct _sas_node *sas_expander;
3577 Mpi2ConfigReply_t mpi_reply;
3578 Mpi2ExpanderPage0_t expander_pg0;
3579 Mpi2ExpanderPage1_t expander_pg1;
3580 Mpi2SasEnclosurePage0_t enclosure_pg0;
3585 unsigned long flags;
3586 struct _sas_port *mpt2sas_port = NULL;
3592 if (ioc->shost_recovery)
3595 if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
3596 MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
3597 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3598 ioc->name, __FILE__, __LINE__, __func__);
3602 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3603 MPI2_IOCSTATUS_MASK;
3604 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3605 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3606 ioc->name, __FILE__, __LINE__, __func__);
3610 /* handle out of order topology events */
3611 parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
3612 if (parent_handle >= ioc->sas_hba.num_phys) {
3613 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3614 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
3616 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3617 if (!sas_expander) {
3618 rc = _scsih_expander_add(ioc, parent_handle);
3624 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3625 sas_address = le64_to_cpu(expander_pg0.SASAddress);
3626 sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
3628 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3633 sas_expander = kzalloc(sizeof(struct _sas_node),
3635 if (!sas_expander) {
3636 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3637 ioc->name, __FILE__, __LINE__, __func__);
3641 sas_expander->handle = handle;
3642 sas_expander->num_phys = expander_pg0.NumPhys;
3643 sas_expander->parent_handle = parent_handle;
3644 sas_expander->enclosure_handle =
3645 le16_to_cpu(expander_pg0.EnclosureHandle);
3646 sas_expander->sas_address = sas_address;
3648 printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
3649 " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
3650 handle, sas_expander->parent_handle, (unsigned long long)
3651 sas_expander->sas_address, sas_expander->num_phys);
3653 if (!sas_expander->num_phys)
3655 sas_expander->phy = kcalloc(sas_expander->num_phys,
3656 sizeof(struct _sas_phy), GFP_KERNEL);
3657 if (!sas_expander->phy) {
3658 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3659 ioc->name, __FILE__, __LINE__, __func__);
3664 INIT_LIST_HEAD(&sas_expander->sas_port_list);
3665 mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
3666 sas_expander->parent_handle);
3667 if (!mpt2sas_port) {
3668 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3669 ioc->name, __FILE__, __LINE__, __func__);
3673 sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
3675 for (i = 0 ; i < sas_expander->num_phys ; i++) {
3676 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
3677 &expander_pg1, i, handle))) {
3678 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3679 ioc->name, __FILE__, __LINE__, __func__);
3683 sas_expander->phy[i].handle = handle;
3684 sas_expander->phy[i].phy_id = i;
3686 if ((mpt2sas_transport_add_expander_phy(ioc,
3687 &sas_expander->phy[i], expander_pg1,
3688 sas_expander->parent_dev))) {
3689 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3690 ioc->name, __FILE__, __LINE__, __func__);
3696 if (sas_expander->enclosure_handle) {
3697 if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
3698 &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3699 sas_expander->enclosure_handle))) {
3700 sas_expander->enclosure_logical_id =
3701 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3705 _scsih_expander_node_add(ioc, sas_expander);
3711 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
3712 sas_expander->parent_handle);
3713 kfree(sas_expander);
3718 * _scsih_expander_remove - removing expander object
3719 * @ioc: per adapter object
3720 * @handle: expander handle
3725 _scsih_expander_remove(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3727 struct _sas_node *sas_expander;
3728 unsigned long flags;
3730 if (ioc->shost_recovery)
3733 spin_lock_irqsave(&ioc->sas_node_lock, flags);
3734 sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc, handle);
3735 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
3736 _scsih_expander_node_remove(ioc, sas_expander);
3740 * _scsih_add_device - creating sas device object
3741 * @ioc: per adapter object
3742 * @handle: sas device handle
3743 * @phy_num: phy number end device attached to
3744 * @is_pd: is this hidden raid component
3746 * Creating end device object, stored in ioc->sas_device_list.
3748 * Returns 0 for success, non-zero for failure.
3751 _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
3753 Mpi2ConfigReply_t mpi_reply;
3754 Mpi2SasDevicePage0_t sas_device_pg0;
3755 Mpi2SasEnclosurePage0_t enclosure_pg0;
3756 struct _sas_device *sas_device;
3760 unsigned long flags;
3762 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
3763 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
3764 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3765 ioc->name, __FILE__, __LINE__, __func__);
3769 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
3770 MPI2_IOCSTATUS_MASK;
3771 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3772 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3773 ioc->name, __FILE__, __LINE__, __func__);
3777 /* check if device is present */
3778 if (!(le16_to_cpu(sas_device_pg0.Flags) &
3779 MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
3780 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3781 ioc->name, __FILE__, __LINE__, __func__);
3782 printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
3783 ioc->name, le16_to_cpu(sas_device_pg0.Flags));
3787 /* check if there were any issus with discovery */
3788 if (sas_device_pg0.AccessStatus ==
3789 MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED) {
3790 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3791 ioc->name, __FILE__, __LINE__, __func__);
3792 printk(MPT2SAS_ERR_FMT "AccessStatus = 0x%02x\n",
3793 ioc->name, sas_device_pg0.AccessStatus);
3797 /* check if this is end device */
3798 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
3799 if (!(_scsih_is_end_device(device_info))) {
3800 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3801 ioc->name, __FILE__, __LINE__, __func__);
3805 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
3807 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3808 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
3810 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3813 _scsih_ublock_io_device(ioc, handle);
3817 sas_device = kzalloc(sizeof(struct _sas_device),
3820 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3821 ioc->name, __FILE__, __LINE__, __func__);
3825 sas_device->handle = handle;
3826 sas_device->parent_handle =
3827 le16_to_cpu(sas_device_pg0.ParentDevHandle);
3828 sas_device->enclosure_handle =
3829 le16_to_cpu(sas_device_pg0.EnclosureHandle);
3831 le16_to_cpu(sas_device_pg0.Slot);
3832 sas_device->device_info = device_info;
3833 sas_device->sas_address = sas_address;
3834 sas_device->hidden_raid_component = is_pd;
3836 /* get enclosure_logical_id */
3837 if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
3838 ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
3839 sas_device->enclosure_handle)))
3840 sas_device->enclosure_logical_id =
3841 le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
3843 /* get device name */
3844 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
3846 if (ioc->wait_for_port_enable_to_complete)
3847 _scsih_sas_device_init_add(ioc, sas_device);
3849 _scsih_sas_device_add(ioc, sas_device);
3855 * _scsih_remove_device - removing sas device object
3856 * @ioc: per adapter object
3857 * @handle: sas device handle
3862 _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
3864 struct MPT2SAS_TARGET *sas_target_priv_data;
3865 struct _sas_device *sas_device;
3866 unsigned long flags;
3867 Mpi2SasIoUnitControlReply_t mpi_reply;
3868 Mpi2SasIoUnitControlRequest_t mpi_request;
3871 /* lookup sas_device */
3872 spin_lock_irqsave(&ioc->sas_device_lock, flags);
3873 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
3875 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3879 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: handle"
3880 "(0x%04x)\n", ioc->name, __func__, handle));
3882 if (sas_device->starget && sas_device->starget->hostdata) {
3883 sas_target_priv_data = sas_device->starget->hostdata;
3884 sas_target_priv_data->deleted = 1;
3886 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3888 if (ioc->remove_host)
3891 if ((sas_device->state & MPTSAS_STATE_TR_COMPLETE)) {
3892 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "\tskip "
3893 "target_reset handle(0x%04x)\n", ioc->name, handle));
3897 /* Target Reset to flush out all the outstanding IO */
3898 device_handle = (sas_device->hidden_raid_component) ?
3899 sas_device->volume_handle : handle;
3900 if (device_handle) {
3901 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset: "
3902 "handle(0x%04x)\n", ioc->name, device_handle));
3903 mutex_lock(&ioc->tm_cmds.mutex);
3904 mpt2sas_scsih_issue_tm(ioc, device_handle, 0,
3905 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10);
3906 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
3907 mutex_unlock(&ioc->tm_cmds.mutex);
3908 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset "
3909 "done: handle(0x%04x)\n", ioc->name, device_handle));
3910 if (ioc->shost_recovery)
3915 if ((sas_device->state & MPTSAS_STATE_CNTRL_COMPLETE)) {
3916 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "\tskip "
3917 "sas_cntrl handle(0x%04x)\n", ioc->name, handle));
3921 /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
3922 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: handle"
3923 "(0x%04x)\n", ioc->name, handle));
3924 memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
3925 mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
3926 mpi_request.Operation = MPI2_SAS_OP_REMOVE_DEVICE;
3927 mpi_request.DevHandle = handle;
3928 mpi_request.VF_ID = 0; /* TODO */
3929 mpi_request.VP_ID = 0;
3930 if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply,
3931 &mpi_request)) != 0) {
3932 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
3933 ioc->name, __FILE__, __LINE__, __func__);
3936 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: ioc_status"
3937 "(0x%04x), loginfo(0x%08x)\n", ioc->name,
3938 le16_to_cpu(mpi_reply.IOCStatus),
3939 le32_to_cpu(mpi_reply.IOCLogInfo)));
3943 _scsih_ublock_io_device(ioc, handle);
3945 mpt2sas_transport_port_remove(ioc, sas_device->sas_address,
3946 sas_device->parent_handle);
3948 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
3949 "(0x%016llx)\n", ioc->name, sas_device->handle,
3950 (unsigned long long) sas_device->sas_address);
3951 _scsih_sas_device_remove(ioc, sas_device);
3953 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: handle"
3954 "(0x%04x)\n", ioc->name, __func__, handle));
3957 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
3959 * _scsih_sas_topology_change_event_debug - debug for topology event
3960 * @ioc: per adapter object
3961 * @event_data: event data payload
3965 _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
3966 Mpi2EventDataSasTopologyChangeList_t *event_data)
3972 char *status_str = NULL;
3975 switch (event_data->ExpStatus) {
3976 case MPI2_EVENT_SAS_TOPO_ES_ADDED:
3979 case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
3980 status_str = "remove";
3982 case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
3983 status_str = "responding";
3985 case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
3986 status_str = "remove delay";
3989 status_str = "unknown status";
3992 printk(MPT2SAS_DEBUG_FMT "sas topology change: (%s)\n",
3993 ioc->name, status_str);
3994 printk(KERN_DEBUG "\thandle(0x%04x), enclosure_handle(0x%04x) "
3995 "start_phy(%02d), count(%d)\n",
3996 le16_to_cpu(event_data->ExpanderDevHandle),
3997 le16_to_cpu(event_data->EnclosureHandle),
3998 event_data->StartPhyNum, event_data->NumEntries);
3999 for (i = 0; i < event_data->NumEntries; i++) {
4000 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
4003 phy_number = event_data->StartPhyNum + i;
4004 reason_code = event_data->PHY[i].PhyStatus &
4005 MPI2_EVENT_SAS_TOPO_RC_MASK;
4006 switch (reason_code) {
4007 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
4008 snprintf(link_rate, 25, ": add, link(0x%02x)",
4009 (event_data->PHY[i].LinkRate >> 4));
4010 status_str = link_rate;
4012 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
4013 status_str = ": remove";
4015 case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
4016 status_str = ": remove_delay";
4018 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
4019 snprintf(link_rate, 25, ": link(0x%02x)",
4020 (event_data->PHY[i].LinkRate >> 4));
4021 status_str = link_rate;
4023 case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
4024 status_str = ": responding";
4027 status_str = ": unknown";
4030 printk(KERN_DEBUG "\tphy(%02d), attached_handle(0x%04x)%s\n",
4031 phy_number, handle, status_str);
4037 * _scsih_sas_topology_change_event - handle topology changes
4038 * @ioc: per adapter object
4039 * @fw_event: The fw_event_work object
4044 _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
4045 struct fw_event_work *fw_event)
4048 u16 parent_handle, handle;
4051 struct _sas_node *sas_expander;
4052 unsigned long flags;
4054 Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
4056 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4057 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4058 _scsih_sas_topology_change_event_debug(ioc, event_data);
4061 if (!ioc->sas_hba.num_phys)
4062 _scsih_sas_host_add(ioc);
4064 _scsih_sas_host_refresh(ioc, 0);
4066 if (fw_event->ignore) {
4067 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring expander "
4068 "event\n", ioc->name));
4072 parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
4074 /* handle expander add */
4075 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
4076 if (_scsih_expander_add(ioc, parent_handle) != 0)
4079 /* handle siblings events */
4080 for (i = 0; i < event_data->NumEntries; i++) {
4081 if (fw_event->ignore) {
4082 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring "
4083 "expander event\n", ioc->name));
4086 if (ioc->shost_recovery)
4088 phy_number = event_data->StartPhyNum + i;
4089 reason_code = event_data->PHY[i].PhyStatus &
4090 MPI2_EVENT_SAS_TOPO_RC_MASK;
4091 if ((event_data->PHY[i].PhyStatus &
4092 MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
4093 MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
4095 handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
4098 link_rate_ = event_data->PHY[i].LinkRate >> 4;
4099 switch (reason_code) {
4100 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
4101 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
4102 if (!parent_handle) {
4103 if (phy_number < ioc->sas_hba.num_phys)
4104 mpt2sas_transport_update_links(
4106 ioc->sas_hba.phy[phy_number].handle,
4107 handle, phy_number, link_rate_);
4109 spin_lock_irqsave(&ioc->sas_node_lock, flags);
4111 mpt2sas_scsih_expander_find_by_handle(ioc,
4113 spin_unlock_irqrestore(&ioc->sas_node_lock,
4116 if (phy_number < sas_expander->num_phys)
4117 mpt2sas_transport_update_links(
4120 phy[phy_number].handle,
4125 if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED) {
4126 if (link_rate_ < MPI2_SAS_NEG_LINK_RATE_1_5)
4128 _scsih_add_device(ioc, handle, phy_number, 0);
4131 case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
4132 _scsih_remove_device(ioc, handle);
4137 /* handle expander removal */
4138 if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
4139 _scsih_expander_remove(ioc, parent_handle);
4143 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4145 * _scsih_sas_device_status_change_event_debug - debug for device event
4146 * @event_data: event data payload
4152 _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
4153 Mpi2EventDataSasDeviceStatusChange_t *event_data)
4155 char *reason_str = NULL;
4157 switch (event_data->ReasonCode) {
4158 case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
4159 reason_str = "smart data";
4161 case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
4162 reason_str = "unsupported device discovered";
4164 case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
4165 reason_str = "internal device reset";
4167 case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
4168 reason_str = "internal task abort";
4170 case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
4171 reason_str = "internal task abort set";
4173 case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
4174 reason_str = "internal clear task set";
4176 case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
4177 reason_str = "internal query task";
4179 case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
4180 reason_str = "sata init failure";
4182 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
4183 reason_str = "internal device reset complete";
4185 case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
4186 reason_str = "internal task abort complete";
4188 case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
4189 reason_str = "internal async notification";
4192 reason_str = "unknown reason";
4195 printk(MPT2SAS_DEBUG_FMT "device status change: (%s)\n"
4196 "\thandle(0x%04x), sas address(0x%016llx)", ioc->name,
4197 reason_str, le16_to_cpu(event_data->DevHandle),
4198 (unsigned long long)le64_to_cpu(event_data->SASAddress));
4199 if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
4200 printk(MPT2SAS_DEBUG_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
4201 event_data->ASC, event_data->ASCQ);
4202 printk(KERN_INFO "\n");
4207 * _scsih_sas_device_status_change_event - handle device status change
4208 * @ioc: per adapter object
4209 * @fw_event: The fw_event_work object
4215 _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
4216 struct fw_event_work *fw_event)
4218 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4219 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4220 _scsih_sas_device_status_change_event_debug(ioc,
4221 fw_event->event_data);
4225 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4227 * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
4228 * @ioc: per adapter object
4229 * @event_data: event data payload
4235 _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
4236 Mpi2EventDataSasEnclDevStatusChange_t *event_data)
4238 char *reason_str = NULL;
4240 switch (event_data->ReasonCode) {
4241 case MPI2_EVENT_SAS_ENCL_RC_ADDED:
4242 reason_str = "enclosure add";
4244 case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
4245 reason_str = "enclosure remove";
4248 reason_str = "unknown reason";
4252 printk(MPT2SAS_DEBUG_FMT "enclosure status change: (%s)\n"
4253 "\thandle(0x%04x), enclosure logical id(0x%016llx)"
4254 " number slots(%d)\n", ioc->name, reason_str,
4255 le16_to_cpu(event_data->EnclosureHandle),
4256 (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
4257 le16_to_cpu(event_data->StartSlot));
4262 * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
4263 * @ioc: per adapter object
4264 * @fw_event: The fw_event_work object
4270 _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
4271 struct fw_event_work *fw_event)
4273 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4274 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4275 _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
4276 fw_event->event_data);
4281 * _scsih_sas_broadcast_primative_event - handle broadcast events
4282 * @ioc: per adapter object
4283 * @fw_event: The fw_event_work object
4289 _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
4290 struct fw_event_work *fw_event)
4292 struct scsi_cmnd *scmd;
4295 struct MPT2SAS_DEVICE *sas_device_priv_data;
4296 u32 termination_count;
4298 Mpi2SCSITaskManagementReply_t *mpi_reply;
4299 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4300 Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
4302 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "broadcast primative: "
4303 "phy number(%d), width(%d)\n", ioc->name, event_data->PhyNum,
4304 event_data->PortWidth));
4305 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
4308 mutex_lock(&ioc->tm_cmds.mutex);
4309 termination_count = 0;
4311 mpi_reply = ioc->tm_cmds.reply;
4312 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
4313 scmd = _scsih_scsi_lookup_get(ioc, smid);
4316 sas_device_priv_data = scmd->device->hostdata;
4317 if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
4319 /* skip hidden raid components */
4320 if (sas_device_priv_data->sas_target->flags &
4321 MPT_TARGET_FLAGS_RAID_COMPONENT)
4324 if (sas_device_priv_data->sas_target->flags &
4325 MPT_TARGET_FLAGS_VOLUME)
4328 handle = sas_device_priv_data->sas_target->handle;
4329 lun = sas_device_priv_data->lun;
4332 mpt2sas_scsih_issue_tm(ioc, handle, lun,
4333 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30);
4334 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4336 if ((mpi_reply->IOCStatus == MPI2_IOCSTATUS_SUCCESS) &&
4337 (mpi_reply->ResponseCode ==
4338 MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
4339 mpi_reply->ResponseCode ==
4340 MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC))
4343 mpt2sas_scsih_issue_tm(ioc, handle, lun,
4344 MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, 0, 30);
4345 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4346 termination_count += le32_to_cpu(mpi_reply->TerminationCount);
4348 ioc->broadcast_aen_busy = 0;
4349 mutex_unlock(&ioc->tm_cmds.mutex);
4351 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT
4352 "%s - exit, query_count = %d termination_count = %d\n",
4353 ioc->name, __func__, query_count, termination_count));
4357 * _scsih_sas_discovery_event - handle discovery events
4358 * @ioc: per adapter object
4359 * @fw_event: The fw_event_work object
4365 _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
4366 struct fw_event_work *fw_event)
4368 Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
4370 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4371 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
4372 printk(MPT2SAS_DEBUG_FMT "discovery event: (%s)", ioc->name,
4373 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
4375 if (event_data->DiscoveryStatus)
4376 printk("discovery_status(0x%08x)",
4377 le32_to_cpu(event_data->DiscoveryStatus));
4382 if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
4383 !ioc->sas_hba.num_phys)
4384 _scsih_sas_host_add(ioc);
4388 * _scsih_reprobe_lun - reprobing lun
4389 * @sdev: scsi device struct
4390 * @no_uld_attach: sdev->no_uld_attach flag setting
4394 _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
4398 sdev->no_uld_attach = no_uld_attach ? 1 : 0;
4399 sdev_printk(KERN_INFO, sdev, "%s raid component\n",
4400 sdev->no_uld_attach ? "hidding" : "exposing");
4401 rc = scsi_device_reprobe(sdev);
4405 * _scsih_reprobe_target - reprobing target
4406 * @starget: scsi target struct
4407 * @no_uld_attach: sdev->no_uld_attach flag setting
4409 * Note: no_uld_attach flag determines whether the disk device is attached
4410 * to block layer. A value of `1` means to not attach.
4413 _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
4415 struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
4418 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
4420 sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
4422 starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
4423 _scsih_reprobe_lun);
4426 * _scsih_sas_volume_add - add new volume
4427 * @ioc: per adapter object
4428 * @element: IR config element data
4434 _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
4435 Mpi2EventIrConfigElement_t *element)
4437 struct _raid_device *raid_device;
4438 unsigned long flags;
4440 u16 handle = le16_to_cpu(element->VolDevHandle);
4443 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
4445 printk(MPT2SAS_ERR_FMT
4446 "failure at %s:%d/%s()!\n", ioc->name,
4447 __FILE__, __LINE__, __func__);
4451 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4452 raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
4453 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4458 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
4460 printk(MPT2SAS_ERR_FMT
4461 "failure at %s:%d/%s()!\n", ioc->name,
4462 __FILE__, __LINE__, __func__);
4466 raid_device->id = ioc->sas_id++;
4467 raid_device->channel = RAID_CHANNEL;
4468 raid_device->handle = handle;
4469 raid_device->wwid = wwid;
4470 _scsih_raid_device_add(ioc, raid_device);
4471 if (!ioc->wait_for_port_enable_to_complete) {
4472 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
4473 raid_device->id, 0);
4475 _scsih_raid_device_remove(ioc, raid_device);
4477 _scsih_determine_boot_device(ioc, raid_device, 1);
4481 * _scsih_sas_volume_delete - delete volume
4482 * @ioc: per adapter object
4483 * @element: IR config element data
4489 _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc,
4490 Mpi2EventIrConfigElement_t *element)
4492 struct _raid_device *raid_device;
4493 u16 handle = le16_to_cpu(element->VolDevHandle);
4494 unsigned long flags;
4495 struct MPT2SAS_TARGET *sas_target_priv_data;
4497 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4498 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
4499 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4502 if (raid_device->starget) {
4503 sas_target_priv_data = raid_device->starget->hostdata;
4504 sas_target_priv_data->deleted = 1;
4505 scsi_remove_target(&raid_device->starget->dev);
4507 _scsih_raid_device_remove(ioc, raid_device);
4511 * _scsih_sas_pd_expose - expose pd component to /dev/sdX
4512 * @ioc: per adapter object
4513 * @element: IR config element data
4519 _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
4520 Mpi2EventIrConfigElement_t *element)
4522 struct _sas_device *sas_device;
4523 unsigned long flags;
4524 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4526 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4527 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4528 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4532 /* exposing raid component */
4533 sas_device->volume_handle = 0;
4534 sas_device->volume_wwid = 0;
4535 sas_device->hidden_raid_component = 0;
4536 _scsih_reprobe_target(sas_device->starget, 0);
4540 * _scsih_sas_pd_hide - hide pd component from /dev/sdX
4541 * @ioc: per adapter object
4542 * @element: IR config element data
4548 _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
4549 Mpi2EventIrConfigElement_t *element)
4551 struct _sas_device *sas_device;
4552 unsigned long flags;
4553 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4555 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4556 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4557 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4561 /* hiding raid component */
4562 mpt2sas_config_get_volume_handle(ioc, handle,
4563 &sas_device->volume_handle);
4564 mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
4565 &sas_device->volume_wwid);
4566 sas_device->hidden_raid_component = 1;
4567 _scsih_reprobe_target(sas_device->starget, 1);
4571 * _scsih_sas_pd_delete - delete pd component
4572 * @ioc: per adapter object
4573 * @element: IR config element data
4579 _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
4580 Mpi2EventIrConfigElement_t *element)
4582 struct _sas_device *sas_device;
4583 unsigned long flags;
4584 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4586 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4587 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4588 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4591 _scsih_remove_device(ioc, handle);
4595 * _scsih_sas_pd_add - remove pd component
4596 * @ioc: per adapter object
4597 * @element: IR config element data
4603 _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
4604 Mpi2EventIrConfigElement_t *element)
4606 struct _sas_device *sas_device;
4607 unsigned long flags;
4608 u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
4609 Mpi2ConfigReply_t mpi_reply;
4610 Mpi2SasDevicePage0_t sas_device_pg0;
4613 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4614 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4615 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4617 sas_device->hidden_raid_component = 1;
4621 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
4622 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
4623 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4624 ioc->name, __FILE__, __LINE__, __func__);
4628 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4629 MPI2_IOCSTATUS_MASK;
4630 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4631 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4632 ioc->name, __FILE__, __LINE__, __func__);
4636 mpt2sas_transport_update_links(ioc,
4637 le16_to_cpu(sas_device_pg0.ParentDevHandle),
4638 handle, sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
4640 _scsih_add_device(ioc, handle, 0, 1);
4643 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4645 * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
4646 * @ioc: per adapter object
4647 * @event_data: event data payload
4653 _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
4654 Mpi2EventDataIrConfigChangeList_t *event_data)
4656 Mpi2EventIrConfigElement_t *element;
4659 char *reason_str = NULL, *element_str = NULL;
4661 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4663 printk(MPT2SAS_DEBUG_FMT "raid config change: (%s), elements(%d)\n",
4664 ioc->name, (le32_to_cpu(event_data->Flags) &
4665 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
4666 "foreign" : "native", event_data->NumElements);
4667 for (i = 0; i < event_data->NumElements; i++, element++) {
4668 switch (element->ReasonCode) {
4669 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
4672 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
4673 reason_str = "remove";
4675 case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
4676 reason_str = "no change";
4678 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
4679 reason_str = "hide";
4681 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
4682 reason_str = "unhide";
4684 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
4685 reason_str = "volume_created";
4687 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
4688 reason_str = "volume_deleted";
4690 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
4691 reason_str = "pd_created";
4693 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
4694 reason_str = "pd_deleted";
4697 reason_str = "unknown reason";
4700 element_type = le16_to_cpu(element->ElementFlags) &
4701 MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
4702 switch (element_type) {
4703 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
4704 element_str = "volume";
4706 case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
4707 element_str = "phys disk";
4709 case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
4710 element_str = "hot spare";
4713 element_str = "unknown element";
4716 printk(KERN_DEBUG "\t(%s:%s), vol handle(0x%04x), "
4717 "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
4718 reason_str, le16_to_cpu(element->VolDevHandle),
4719 le16_to_cpu(element->PhysDiskDevHandle),
4720 element->PhysDiskNum);
4726 * _scsih_sas_ir_config_change_event - handle ir configuration change events
4727 * @ioc: per adapter object
4728 * @fw_event: The fw_event_work object
4734 _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
4735 struct fw_event_work *fw_event)
4737 Mpi2EventIrConfigElement_t *element;
4740 Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
4742 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4743 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4744 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
4747 foreign_config = (le32_to_cpu(event_data->Flags) &
4748 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
4750 element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
4751 for (i = 0; i < event_data->NumElements; i++, element++) {
4753 switch (element->ReasonCode) {
4754 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
4755 case MPI2_EVENT_IR_CHANGE_RC_ADDED:
4756 if (!foreign_config)
4757 _scsih_sas_volume_add(ioc, element);
4759 case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
4760 case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
4761 if (!foreign_config)
4762 _scsih_sas_volume_delete(ioc, element);
4764 case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
4765 _scsih_sas_pd_hide(ioc, element);
4767 case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
4768 _scsih_sas_pd_expose(ioc, element);
4770 case MPI2_EVENT_IR_CHANGE_RC_HIDE:
4771 _scsih_sas_pd_add(ioc, element);
4773 case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
4774 _scsih_sas_pd_delete(ioc, element);
4781 * _scsih_sas_ir_volume_event - IR volume event
4782 * @ioc: per adapter object
4783 * @fw_event: The fw_event_work object
4789 _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
4790 struct fw_event_work *fw_event)
4793 unsigned long flags;
4794 struct _raid_device *raid_device;
4798 struct MPT2SAS_TARGET *sas_target_priv_data;
4799 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
4801 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
4804 handle = le16_to_cpu(event_data->VolDevHandle);
4805 state = le32_to_cpu(event_data->NewValue);
4806 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
4807 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
4808 le32_to_cpu(event_data->PreviousValue), state));
4810 spin_lock_irqsave(&ioc->raid_device_lock, flags);
4811 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
4812 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
4815 case MPI2_RAID_VOL_STATE_MISSING:
4816 case MPI2_RAID_VOL_STATE_FAILED:
4819 if (raid_device->starget) {
4820 sas_target_priv_data = raid_device->starget->hostdata;
4821 sas_target_priv_data->deleted = 1;
4822 scsi_remove_target(&raid_device->starget->dev);
4824 _scsih_raid_device_remove(ioc, raid_device);
4827 case MPI2_RAID_VOL_STATE_ONLINE:
4828 case MPI2_RAID_VOL_STATE_DEGRADED:
4829 case MPI2_RAID_VOL_STATE_OPTIMAL:
4833 mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
4835 printk(MPT2SAS_ERR_FMT
4836 "failure at %s:%d/%s()!\n", ioc->name,
4837 __FILE__, __LINE__, __func__);
4841 raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
4843 printk(MPT2SAS_ERR_FMT
4844 "failure at %s:%d/%s()!\n", ioc->name,
4845 __FILE__, __LINE__, __func__);
4849 raid_device->id = ioc->sas_id++;
4850 raid_device->channel = RAID_CHANNEL;
4851 raid_device->handle = handle;
4852 raid_device->wwid = wwid;
4853 _scsih_raid_device_add(ioc, raid_device);
4854 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
4855 raid_device->id, 0);
4857 _scsih_raid_device_remove(ioc, raid_device);
4860 case MPI2_RAID_VOL_STATE_INITIALIZING:
4867 * _scsih_sas_ir_physical_disk_event - PD event
4868 * @ioc: per adapter object
4869 * @fw_event: The fw_event_work object
4875 _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
4876 struct fw_event_work *fw_event)
4880 struct _sas_device *sas_device;
4881 unsigned long flags;
4882 Mpi2ConfigReply_t mpi_reply;
4883 Mpi2SasDevicePage0_t sas_device_pg0;
4885 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
4887 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
4890 handle = le16_to_cpu(event_data->PhysDiskDevHandle);
4891 state = le32_to_cpu(event_data->NewValue);
4893 dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
4894 "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
4895 le32_to_cpu(event_data->PreviousValue), state));
4897 spin_lock_irqsave(&ioc->sas_device_lock, flags);
4898 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
4899 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
4902 case MPI2_RAID_PD_STATE_ONLINE:
4903 case MPI2_RAID_PD_STATE_DEGRADED:
4904 case MPI2_RAID_PD_STATE_REBUILDING:
4905 case MPI2_RAID_PD_STATE_OPTIMAL:
4907 sas_device->hidden_raid_component = 1;
4911 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
4912 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
4914 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4915 ioc->name, __FILE__, __LINE__, __func__);
4919 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
4920 MPI2_IOCSTATUS_MASK;
4921 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
4922 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
4923 ioc->name, __FILE__, __LINE__, __func__);
4927 mpt2sas_transport_update_links(ioc,
4928 le16_to_cpu(sas_device_pg0.ParentDevHandle),
4929 handle, sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
4931 _scsih_add_device(ioc, handle, 0, 1);
4935 case MPI2_RAID_PD_STATE_OFFLINE:
4936 case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
4937 case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
4938 case MPI2_RAID_PD_STATE_HOT_SPARE:
4944 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4946 * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
4947 * @ioc: per adapter object
4948 * @event_data: event data payload
4954 _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
4955 Mpi2EventDataIrOperationStatus_t *event_data)
4957 char *reason_str = NULL;
4959 switch (event_data->RAIDOperation) {
4960 case MPI2_EVENT_IR_RAIDOP_RESYNC:
4961 reason_str = "resync";
4963 case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
4964 reason_str = "online capacity expansion";
4966 case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
4967 reason_str = "consistency check";
4970 reason_str = "unknown reason";
4974 printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
4975 "\thandle(0x%04x), percent complete(%d)\n",
4976 ioc->name, reason_str,
4977 le16_to_cpu(event_data->VolDevHandle),
4978 event_data->PercentComplete);
4983 * _scsih_sas_ir_operation_status_event - handle RAID operation events
4984 * @ioc: per adapter object
4985 * @fw_event: The fw_event_work object
4991 _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
4992 struct fw_event_work *fw_event)
4994 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
4995 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
4996 _scsih_sas_ir_operation_status_event_debug(ioc,
4997 fw_event->event_data);
5002 * _scsih_task_set_full - handle task set full
5003 * @ioc: per adapter object
5004 * @fw_event: The fw_event_work object
5007 * Throttle back qdepth.
5010 _scsih_task_set_full(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
5013 unsigned long flags;
5014 struct _sas_device *sas_device;
5015 static struct _raid_device *raid_device;
5016 struct scsi_device *sdev;
5022 Mpi2EventDataTaskSetFull_t *event_data = fw_event->event_data;
5024 current_depth = le16_to_cpu(event_data->CurrentDepth);
5025 handle = le16_to_cpu(event_data->DevHandle);
5026 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5027 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
5029 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5032 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5033 id = sas_device->id;
5034 channel = sas_device->channel;
5035 sas_address = sas_device->sas_address;
5037 /* if hidden raid component, then change to volume characteristics */
5038 if (sas_device->hidden_raid_component && sas_device->volume_handle) {
5039 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5040 raid_device = _scsih_raid_device_find_by_handle(
5041 ioc, sas_device->volume_handle);
5042 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5044 id = raid_device->id;
5045 channel = raid_device->channel;
5046 handle = raid_device->handle;
5047 sas_address = raid_device->wwid;
5051 if (ioc->logging_level & MPT_DEBUG_TASK_SET_FULL)
5052 starget_printk(KERN_DEBUG, sas_device->starget, "task set "
5053 "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
5054 handle, (unsigned long long)sas_address, current_depth);
5056 shost_for_each_device(sdev, ioc->shost) {
5057 if (sdev->id == id && sdev->channel == channel) {
5058 if (current_depth > sdev->queue_depth) {
5059 if (ioc->logging_level &
5060 MPT_DEBUG_TASK_SET_FULL)
5061 sdev_printk(KERN_INFO, sdev, "strange "
5062 "observation, the queue depth is"
5063 " (%d) meanwhile fw queue depth "
5064 "is (%d)\n", sdev->queue_depth,
5068 depth = scsi_track_queue_full(sdev,
5071 sdev_printk(KERN_INFO, sdev, "Queue depth "
5072 "reduced to (%d)\n", depth);
5074 sdev_printk(KERN_INFO, sdev, "Tagged Command "
5075 "Queueing is being disabled\n");
5076 else if (depth == 0)
5077 if (ioc->logging_level &
5078 MPT_DEBUG_TASK_SET_FULL)
5079 sdev_printk(KERN_INFO, sdev,
5080 "Queue depth not changed yet\n");
5086 * _scsih_mark_responding_sas_device - mark a sas_devices as responding
5087 * @ioc: per adapter object
5088 * @sas_address: sas address
5089 * @slot: enclosure slot id
5090 * @handle: device handle
5092 * After host reset, find out whether devices are still responding.
5093 * Used in _scsi_remove_unresponsive_sas_devices.
5098 _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5099 u16 slot, u16 handle)
5101 struct MPT2SAS_TARGET *sas_target_priv_data;
5102 struct scsi_target *starget;
5103 struct _sas_device *sas_device;
5104 unsigned long flags;
5106 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5107 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
5108 if (sas_device->sas_address == sas_address &&
5109 sas_device->slot == slot && sas_device->starget) {
5110 sas_device->responding = 1;
5111 sas_device->state = 0;
5112 starget = sas_device->starget;
5113 sas_target_priv_data = starget->hostdata;
5114 sas_target_priv_data->tm_busy = 0;
5115 starget_printk(KERN_INFO, sas_device->starget,
5116 "handle(0x%04x), sas_addr(0x%016llx), enclosure "
5117 "logical id(0x%016llx), slot(%d)\n", handle,
5118 (unsigned long long)sas_device->sas_address,
5119 (unsigned long long)
5120 sas_device->enclosure_logical_id,
5122 if (sas_device->handle == handle)
5124 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
5125 sas_device->handle);
5126 sas_device->handle = handle;
5127 sas_target_priv_data->handle = handle;
5132 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5136 * _scsih_search_responding_sas_devices -
5137 * @ioc: per adapter object
5139 * After host reset, find out whether devices are still responding.
5145 _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
5147 Mpi2SasDevicePage0_t sas_device_pg0;
5148 Mpi2ConfigReply_t mpi_reply;
5155 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
5157 if (list_empty(&ioc->sas_device_list))
5161 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
5162 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
5164 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5165 MPI2_IOCSTATUS_MASK;
5166 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
5168 handle = le16_to_cpu(sas_device_pg0.DevHandle);
5169 device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
5170 if (!(_scsih_is_end_device(device_info)))
5172 sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
5173 slot = le16_to_cpu(sas_device_pg0.Slot);
5174 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
5180 * _scsih_mark_responding_raid_device - mark a raid_device as responding
5181 * @ioc: per adapter object
5182 * @wwid: world wide identifier for raid volume
5183 * @handle: device handle
5185 * After host reset, find out whether devices are still responding.
5186 * Used in _scsi_remove_unresponsive_raid_devices.
5191 _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
5194 struct MPT2SAS_TARGET *sas_target_priv_data;
5195 struct scsi_target *starget;
5196 struct _raid_device *raid_device;
5197 unsigned long flags;
5199 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5200 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
5201 if (raid_device->wwid == wwid && raid_device->starget) {
5202 raid_device->responding = 1;
5203 starget_printk(KERN_INFO, raid_device->starget,
5204 "handle(0x%04x), wwid(0x%016llx)\n", handle,
5205 (unsigned long long)raid_device->wwid);
5206 if (raid_device->handle == handle)
5208 printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
5209 raid_device->handle);
5210 raid_device->handle = handle;
5211 starget = raid_device->starget;
5212 sas_target_priv_data = starget->hostdata;
5213 sas_target_priv_data->handle = handle;
5218 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5222 * _scsih_search_responding_raid_devices -
5223 * @ioc: per adapter object
5225 * After host reset, find out whether devices are still responding.
5231 _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
5233 Mpi2RaidVolPage1_t volume_pg1;
5234 Mpi2ConfigReply_t mpi_reply;
5238 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
5240 if (list_empty(&ioc->raid_device_list))
5244 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
5245 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
5246 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5247 MPI2_IOCSTATUS_MASK;
5248 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
5250 handle = le16_to_cpu(volume_pg1.DevHandle);
5251 _scsih_mark_responding_raid_device(ioc,
5252 le64_to_cpu(volume_pg1.WWID), handle);
5257 * _scsih_mark_responding_expander - mark a expander as responding
5258 * @ioc: per adapter object
5259 * @sas_address: sas address
5262 * After host reset, find out whether devices are still responding.
5263 * Used in _scsi_remove_unresponsive_expanders.
5268 _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
5271 struct _sas_node *sas_expander;
5272 unsigned long flags;
5274 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5275 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
5276 if (sas_expander->sas_address == sas_address) {
5277 sas_expander->responding = 1;
5278 if (sas_expander->handle != handle) {
5279 printk(KERN_INFO "old handle(0x%04x)\n",
5280 sas_expander->handle);
5281 sas_expander->handle = handle;
5287 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5291 * _scsih_search_responding_expanders -
5292 * @ioc: per adapter object
5294 * After host reset, find out whether devices are still responding.
5300 _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
5302 Mpi2ExpanderPage0_t expander_pg0;
5303 Mpi2ConfigReply_t mpi_reply;
5308 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
5310 if (list_empty(&ioc->sas_expander_list))
5314 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
5315 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
5317 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
5318 MPI2_IOCSTATUS_MASK;
5319 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
5322 handle = le16_to_cpu(expander_pg0.DevHandle);
5323 sas_address = le64_to_cpu(expander_pg0.SASAddress);
5324 printk(KERN_INFO "\texpander present: handle(0x%04x), "
5325 "sas_addr(0x%016llx)\n", handle,
5326 (unsigned long long)sas_address);
5327 _scsih_mark_responding_expander(ioc, sas_address, handle);
5333 * _scsih_remove_unresponding_devices - removing unresponding devices
5334 * @ioc: per adapter object
5339 _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER *ioc)
5341 struct _sas_device *sas_device, *sas_device_next;
5342 struct _sas_node *sas_expander;
5343 struct _raid_device *raid_device, *raid_device_next;
5346 list_for_each_entry_safe(sas_device, sas_device_next,
5347 &ioc->sas_device_list, list) {
5348 if (sas_device->responding) {
5349 sas_device->responding = 0;
5352 if (sas_device->starget)
5353 starget_printk(KERN_INFO, sas_device->starget,
5354 "removing: handle(0x%04x), sas_addr(0x%016llx), "
5355 "enclosure logical id(0x%016llx), slot(%d)\n",
5357 (unsigned long long)sas_device->sas_address,
5358 (unsigned long long)
5359 sas_device->enclosure_logical_id,
5361 _scsih_remove_device(ioc, sas_device->handle);
5364 list_for_each_entry_safe(raid_device, raid_device_next,
5365 &ioc->raid_device_list, list) {
5366 if (raid_device->responding) {
5367 raid_device->responding = 0;
5370 if (raid_device->starget) {
5371 starget_printk(KERN_INFO, raid_device->starget,
5372 "removing: handle(0x%04x), wwid(0x%016llx)\n",
5373 raid_device->handle,
5374 (unsigned long long)raid_device->wwid);
5375 scsi_remove_target(&raid_device->starget->dev);
5377 _scsih_raid_device_remove(ioc, raid_device);
5380 retry_expander_search:
5381 sas_expander = NULL;
5382 list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
5383 if (sas_expander->responding) {
5384 sas_expander->responding = 0;
5387 _scsih_expander_remove(ioc, sas_expander->handle);
5388 goto retry_expander_search;
5393 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
5394 * @ioc: per adapter object
5395 * @reset_phase: phase
5397 * The handler for doing any required cleanup or initialization.
5399 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
5400 * MPT2_IOC_DONE_RESET
5405 mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
5407 switch (reset_phase) {
5408 case MPT2_IOC_PRE_RESET:
5409 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
5410 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
5411 _scsih_fw_event_off(ioc);
5413 case MPT2_IOC_AFTER_RESET:
5414 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
5415 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
5416 if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
5417 ioc->tm_cmds.status |= MPT2_CMD_RESET;
5418 mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
5419 complete(&ioc->tm_cmds.done);
5421 _scsih_fw_event_on(ioc);
5422 _scsih_flush_running_cmds(ioc);
5424 case MPT2_IOC_DONE_RESET:
5425 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
5426 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
5427 _scsih_sas_host_refresh(ioc, 0);
5428 _scsih_search_responding_sas_devices(ioc);
5429 _scsih_search_responding_raid_devices(ioc);
5430 _scsih_search_responding_expanders(ioc);
5432 case MPT2_IOC_RUNNING:
5433 dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
5434 "MPT2_IOC_RUNNING\n", ioc->name, __func__));
5435 _scsih_remove_unresponding_devices(ioc);
5441 * _firmware_event_work - delayed task for processing firmware events
5442 * @ioc: per adapter object
5443 * @work: equal to the fw_event_work object
5449 _firmware_event_work(struct work_struct *work)
5451 struct fw_event_work *fw_event = container_of(work,
5452 struct fw_event_work, work);
5453 unsigned long flags;
5454 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
5456 /* the queue is being flushed so ignore this event */
5457 spin_lock_irqsave(&ioc->fw_event_lock, flags);
5458 if (ioc->fw_events_off || ioc->remove_host) {
5459 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5460 _scsih_fw_event_free(ioc, fw_event);
5463 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5465 if (ioc->shost_recovery) {
5466 _scsih_fw_event_requeue(ioc, fw_event, 1000);
5470 switch (fw_event->event) {
5471 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
5472 _scsih_sas_topology_change_event(ioc, fw_event);
5474 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
5475 _scsih_sas_device_status_change_event(ioc,
5478 case MPI2_EVENT_SAS_DISCOVERY:
5479 _scsih_sas_discovery_event(ioc,
5482 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
5483 _scsih_sas_broadcast_primative_event(ioc,
5486 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
5487 _scsih_sas_enclosure_dev_status_change_event(ioc,
5490 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
5491 _scsih_sas_ir_config_change_event(ioc, fw_event);
5493 case MPI2_EVENT_IR_VOLUME:
5494 _scsih_sas_ir_volume_event(ioc, fw_event);
5496 case MPI2_EVENT_IR_PHYSICAL_DISK:
5497 _scsih_sas_ir_physical_disk_event(ioc, fw_event);
5499 case MPI2_EVENT_IR_OPERATION_STATUS:
5500 _scsih_sas_ir_operation_status_event(ioc, fw_event);
5502 case MPI2_EVENT_TASK_SET_FULL:
5503 _scsih_task_set_full(ioc, fw_event);
5506 _scsih_fw_event_free(ioc, fw_event);
5510 * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
5511 * @ioc: per adapter object
5512 * @msix_index: MSIX table index supplied by the OS
5513 * @reply: reply message frame(lower 32bit addr)
5514 * Context: interrupt.
5516 * This function merely adds a new work task into ioc->firmware_event_thread.
5517 * The tasks are worked from _firmware_event_work in user context.
5519 * Return 1 meaning mf should be freed from _base_interrupt
5520 * 0 means the mf is freed from this function.
5523 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
5526 struct fw_event_work *fw_event;
5527 Mpi2EventNotificationReply_t *mpi_reply;
5528 unsigned long flags;
5531 /* events turned off due to host reset or driver unloading */
5532 spin_lock_irqsave(&ioc->fw_event_lock, flags);
5533 if (ioc->fw_events_off || ioc->remove_host) {
5534 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5537 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5539 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
5540 event = le16_to_cpu(mpi_reply->Event);
5544 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
5546 Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
5547 (Mpi2EventDataSasBroadcastPrimitive_t *)
5548 mpi_reply->EventData;
5550 if (baen_data->Primitive !=
5551 MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT ||
5552 ioc->broadcast_aen_busy)
5554 ioc->broadcast_aen_busy = 1;
5558 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
5559 _scsih_check_topo_delete_events(ioc,
5560 (Mpi2EventDataSasTopologyChangeList_t *)
5561 mpi_reply->EventData);
5564 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
5565 case MPI2_EVENT_IR_OPERATION_STATUS:
5566 case MPI2_EVENT_SAS_DISCOVERY:
5567 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
5568 case MPI2_EVENT_IR_VOLUME:
5569 case MPI2_EVENT_IR_PHYSICAL_DISK:
5570 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
5571 case MPI2_EVENT_TASK_SET_FULL:
5574 default: /* ignore the rest */
5578 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
5580 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5581 ioc->name, __FILE__, __LINE__, __func__);
5584 fw_event->event_data =
5585 kzalloc(mpi_reply->EventDataLength*4, GFP_ATOMIC);
5586 if (!fw_event->event_data) {
5587 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
5588 ioc->name, __FILE__, __LINE__, __func__);
5593 memcpy(fw_event->event_data, mpi_reply->EventData,
5594 mpi_reply->EventDataLength*4);
5595 fw_event->ioc = ioc;
5596 fw_event->VF_ID = mpi_reply->VF_ID;
5597 fw_event->VP_ID = mpi_reply->VP_ID;
5598 fw_event->event = event;
5599 _scsih_fw_event_add(ioc, fw_event);
5603 /* shost template */
5604 static struct scsi_host_template scsih_driver_template = {
5605 .module = THIS_MODULE,
5606 .name = "Fusion MPT SAS Host",
5607 .proc_name = MPT2SAS_DRIVER_NAME,
5608 .queuecommand = _scsih_qcmd,
5609 .target_alloc = _scsih_target_alloc,
5610 .slave_alloc = _scsih_slave_alloc,
5611 .slave_configure = _scsih_slave_configure,
5612 .target_destroy = _scsih_target_destroy,
5613 .slave_destroy = _scsih_slave_destroy,
5614 .change_queue_depth = _scsih_change_queue_depth,
5615 .change_queue_type = _scsih_change_queue_type,
5616 .eh_abort_handler = _scsih_abort,
5617 .eh_device_reset_handler = _scsih_dev_reset,
5618 .eh_target_reset_handler = _scsih_target_reset,
5619 .eh_host_reset_handler = _scsih_host_reset,
5620 .bios_param = _scsih_bios_param,
5623 .sg_tablesize = MPT2SAS_SG_DEPTH,
5624 .max_sectors = 8192,
5626 .use_clustering = ENABLE_CLUSTERING,
5627 .shost_attrs = mpt2sas_host_attrs,
5628 .sdev_attrs = mpt2sas_dev_attrs,
5632 * _scsih_expander_node_remove - removing expander device from list.
5633 * @ioc: per adapter object
5634 * @sas_expander: the sas_device object
5635 * Context: Calling function should acquire ioc->sas_node_lock.
5637 * Removing object and freeing associated memory from the
5638 * ioc->sas_expander_list.
5643 _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
5644 struct _sas_node *sas_expander)
5646 struct _sas_port *mpt2sas_port;
5647 struct _sas_device *sas_device;
5648 struct _sas_node *expander_sibling;
5649 unsigned long flags;
5654 /* remove sibling ports attached to this expander */
5655 retry_device_search:
5656 list_for_each_entry(mpt2sas_port,
5657 &sas_expander->sas_port_list, port_list) {
5658 if (mpt2sas_port->remote_identify.device_type ==
5660 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5662 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5663 mpt2sas_port->remote_identify.sas_address);
5664 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5667 _scsih_remove_device(ioc, sas_device->handle);
5668 if (ioc->shost_recovery)
5670 goto retry_device_search;
5674 retry_expander_search:
5675 list_for_each_entry(mpt2sas_port,
5676 &sas_expander->sas_port_list, port_list) {
5678 if (mpt2sas_port->remote_identify.device_type ==
5679 MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
5680 mpt2sas_port->remote_identify.device_type ==
5681 MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
5683 spin_lock_irqsave(&ioc->sas_node_lock, flags);
5685 mpt2sas_scsih_expander_find_by_sas_address(
5686 ioc, mpt2sas_port->remote_identify.sas_address);
5687 spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
5688 if (!expander_sibling)
5690 _scsih_expander_remove(ioc, expander_sibling->handle);
5691 if (ioc->shost_recovery)
5693 goto retry_expander_search;
5697 mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
5698 sas_expander->parent_handle);
5700 printk(MPT2SAS_INFO_FMT "expander_remove: handle"
5701 "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
5702 sas_expander->handle, (unsigned long long)
5703 sas_expander->sas_address);
5705 list_del(&sas_expander->list);
5706 kfree(sas_expander->phy);
5707 kfree(sas_expander);
5711 * _scsih_remove - detach and remove add host
5712 * @pdev: PCI device struct
5716 static void __devexit
5717 _scsih_remove(struct pci_dev *pdev)
5719 struct Scsi_Host *shost = pci_get_drvdata(pdev);
5720 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
5721 struct _sas_port *mpt2sas_port;
5722 struct _sas_device *sas_device;
5723 struct _sas_node *expander_sibling;
5724 struct _raid_device *raid_device, *next;
5725 struct MPT2SAS_TARGET *sas_target_priv_data;
5726 struct workqueue_struct *wq;
5727 unsigned long flags;
5729 ioc->remove_host = 1;
5730 _scsih_fw_event_off(ioc);
5732 spin_lock_irqsave(&ioc->fw_event_lock, flags);
5733 wq = ioc->firmware_event_thread;
5734 ioc->firmware_event_thread = NULL;
5735 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
5737 destroy_workqueue(wq);
5739 /* release all the volumes */
5740 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
5742 if (raid_device->starget) {
5743 sas_target_priv_data =
5744 raid_device->starget->hostdata;
5745 sas_target_priv_data->deleted = 1;
5746 scsi_remove_target(&raid_device->starget->dev);
5748 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
5749 "(0x%016llx)\n", ioc->name, raid_device->handle,
5750 (unsigned long long) raid_device->wwid);
5751 _scsih_raid_device_remove(ioc, raid_device);
5754 /* free ports attached to the sas_host */
5756 list_for_each_entry(mpt2sas_port,
5757 &ioc->sas_hba.sas_port_list, port_list) {
5758 if (mpt2sas_port->remote_identify.device_type ==
5761 mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
5762 mpt2sas_port->remote_identify.sas_address);
5764 _scsih_remove_device(ioc, sas_device->handle);
5769 mpt2sas_scsih_expander_find_by_sas_address(ioc,
5770 mpt2sas_port->remote_identify.sas_address);
5771 if (expander_sibling) {
5772 _scsih_expander_remove(ioc,
5773 expander_sibling->handle);
5779 /* free phys attached to the sas_host */
5780 if (ioc->sas_hba.num_phys) {
5781 kfree(ioc->sas_hba.phy);
5782 ioc->sas_hba.phy = NULL;
5783 ioc->sas_hba.num_phys = 0;
5786 sas_remove_host(shost);
5787 mpt2sas_base_detach(ioc);
5788 list_del(&ioc->list);
5789 scsi_remove_host(shost);
5790 scsi_host_put(shost);
5794 * _scsih_probe_boot_devices - reports 1st device
5795 * @ioc: per adapter object
5797 * If specified in bios page 2, this routine reports the 1st
5798 * device scsi-ml or sas transport for persistent boot device
5799 * purposes. Please refer to function _scsih_determine_boot_device()
5802 _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
5806 struct _sas_device *sas_device;
5807 struct _raid_device *raid_device;
5808 u16 handle, parent_handle;
5810 unsigned long flags;
5814 if (ioc->req_boot_device.device) {
5815 device = ioc->req_boot_device.device;
5816 is_raid = ioc->req_boot_device.is_raid;
5817 } else if (ioc->req_alt_boot_device.device) {
5818 device = ioc->req_alt_boot_device.device;
5819 is_raid = ioc->req_alt_boot_device.is_raid;
5820 } else if (ioc->current_boot_device.device) {
5821 device = ioc->current_boot_device.device;
5822 is_raid = ioc->current_boot_device.is_raid;
5829 raid_device = device;
5830 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5831 raid_device->id, 0);
5833 _scsih_raid_device_remove(ioc, raid_device);
5835 sas_device = device;
5836 handle = sas_device->handle;
5837 parent_handle = sas_device->parent_handle;
5838 sas_address = sas_device->sas_address;
5839 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5840 list_move_tail(&sas_device->list, &ioc->sas_device_list);
5841 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5842 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
5843 sas_device->parent_handle)) {
5844 _scsih_sas_device_remove(ioc, sas_device);
5845 } else if (!sas_device->starget) {
5846 mpt2sas_transport_port_remove(ioc, sas_address,
5848 _scsih_sas_device_remove(ioc, sas_device);
5854 * _scsih_probe_raid - reporting raid volumes to scsi-ml
5855 * @ioc: per adapter object
5857 * Called during initial loading of the driver.
5860 _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
5862 struct _raid_device *raid_device, *raid_next;
5865 list_for_each_entry_safe(raid_device, raid_next,
5866 &ioc->raid_device_list, list) {
5867 if (raid_device->starget)
5869 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5870 raid_device->id, 0);
5872 _scsih_raid_device_remove(ioc, raid_device);
5877 * _scsih_probe_sas - reporting sas devices to sas transport
5878 * @ioc: per adapter object
5880 * Called during initial loading of the driver.
5883 _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
5885 struct _sas_device *sas_device, *next;
5886 unsigned long flags;
5887 u16 handle, parent_handle;
5890 /* SAS Device List */
5891 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
5893 spin_lock_irqsave(&ioc->sas_device_lock, flags);
5894 list_move_tail(&sas_device->list, &ioc->sas_device_list);
5895 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
5897 handle = sas_device->handle;
5898 parent_handle = sas_device->parent_handle;
5899 sas_address = sas_device->sas_address;
5900 if (!mpt2sas_transport_port_add(ioc, handle, parent_handle)) {
5901 _scsih_sas_device_remove(ioc, sas_device);
5902 } else if (!sas_device->starget) {
5903 mpt2sas_transport_port_remove(ioc, sas_address,
5905 _scsih_sas_device_remove(ioc, sas_device);
5911 * _scsih_probe_devices - probing for devices
5912 * @ioc: per adapter object
5914 * Called during initial loading of the driver.
5917 _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
5919 u16 volume_mapping_flags =
5920 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
5921 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
5923 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
5924 return; /* return when IOC doesn't support initiator mode */
5926 _scsih_probe_boot_devices(ioc);
5928 if (ioc->ir_firmware) {
5929 if ((volume_mapping_flags &
5930 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) {
5931 _scsih_probe_sas(ioc);
5932 _scsih_probe_raid(ioc);
5934 _scsih_probe_raid(ioc);
5935 _scsih_probe_sas(ioc);
5938 _scsih_probe_sas(ioc);
5942 * _scsih_probe - attach and add scsi host
5943 * @pdev: PCI device struct
5944 * @id: pci device id
5946 * Returns 0 success, anything else error.
5949 _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
5951 struct MPT2SAS_ADAPTER *ioc;
5952 struct Scsi_Host *shost;
5954 shost = scsi_host_alloc(&scsih_driver_template,
5955 sizeof(struct MPT2SAS_ADAPTER));
5959 /* init local params */
5960 ioc = shost_priv(shost);
5961 memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
5962 INIT_LIST_HEAD(&ioc->list);
5963 list_add_tail(&ioc->list, &mpt2sas_ioc_list);
5965 ioc->id = mpt_ids++;
5966 sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
5968 ioc->scsi_io_cb_idx = scsi_io_cb_idx;
5969 ioc->tm_cb_idx = tm_cb_idx;
5970 ioc->ctl_cb_idx = ctl_cb_idx;
5971 ioc->base_cb_idx = base_cb_idx;
5972 ioc->transport_cb_idx = transport_cb_idx;
5973 ioc->config_cb_idx = config_cb_idx;
5974 ioc->tm_tr_cb_idx = tm_tr_cb_idx;
5975 ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
5976 ioc->logging_level = logging_level;
5977 /* misc semaphores and spin locks */
5978 spin_lock_init(&ioc->ioc_reset_in_progress_lock);
5979 spin_lock_init(&ioc->scsi_lookup_lock);
5980 spin_lock_init(&ioc->sas_device_lock);
5981 spin_lock_init(&ioc->sas_node_lock);
5982 spin_lock_init(&ioc->fw_event_lock);
5983 spin_lock_init(&ioc->raid_device_lock);
5985 INIT_LIST_HEAD(&ioc->sas_device_list);
5986 INIT_LIST_HEAD(&ioc->sas_device_init_list);
5987 INIT_LIST_HEAD(&ioc->sas_expander_list);
5988 INIT_LIST_HEAD(&ioc->fw_event_list);
5989 INIT_LIST_HEAD(&ioc->raid_device_list);
5990 INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
5991 INIT_LIST_HEAD(&ioc->delayed_tr_list);
5993 /* init shost parameters */
5994 shost->max_cmd_len = 16;
5995 shost->max_lun = max_lun;
5996 shost->transportt = mpt2sas_transport_template;
5997 shost->unique_id = ioc->id;
5999 if ((scsi_add_host(shost, &pdev->dev))) {
6000 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6001 ioc->name, __FILE__, __LINE__, __func__);
6002 list_del(&ioc->list);
6003 goto out_add_shost_fail;
6006 scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
6007 | SHOST_DIF_TYPE3_PROTECTION);
6008 scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
6011 snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
6012 "fw_event%d", ioc->id);
6013 ioc->firmware_event_thread = create_singlethread_workqueue(
6014 ioc->firmware_event_name);
6015 if (!ioc->firmware_event_thread) {
6016 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6017 ioc->name, __FILE__, __LINE__, __func__);
6018 goto out_thread_fail;
6021 ioc->wait_for_port_enable_to_complete = 1;
6022 if ((mpt2sas_base_attach(ioc))) {
6023 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6024 ioc->name, __FILE__, __LINE__, __func__);
6025 goto out_attach_fail;
6028 ioc->wait_for_port_enable_to_complete = 0;
6029 _scsih_probe_devices(ioc);
6033 destroy_workqueue(ioc->firmware_event_thread);
6035 list_del(&ioc->list);
6036 scsi_remove_host(shost);
6043 * _scsih_suspend - power management suspend main entry point
6044 * @pdev: PCI device struct
6045 * @state: PM state change to (usually PCI_D3)
6047 * Returns 0 success, anything else error.
6050 _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
6052 struct Scsi_Host *shost = pci_get_drvdata(pdev);
6053 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
6056 mpt2sas_base_stop_watchdog(ioc);
6057 flush_scheduled_work();
6058 scsi_block_requests(shost);
6059 device_state = pci_choose_state(pdev, state);
6060 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
6061 "operating state [D%d]\n", ioc->name, pdev,
6062 pci_name(pdev), device_state);
6064 mpt2sas_base_free_resources(ioc);
6065 pci_save_state(pdev);
6066 pci_disable_device(pdev);
6067 pci_set_power_state(pdev, device_state);
6072 * _scsih_resume - power management resume main entry point
6073 * @pdev: PCI device struct
6075 * Returns 0 success, anything else error.
6078 _scsih_resume(struct pci_dev *pdev)
6080 struct Scsi_Host *shost = pci_get_drvdata(pdev);
6081 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
6082 u32 device_state = pdev->current_state;
6085 printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
6086 "operating state [D%d]\n", ioc->name, pdev,
6087 pci_name(pdev), device_state);
6089 pci_set_power_state(pdev, PCI_D0);
6090 pci_enable_wake(pdev, PCI_D0, 0);
6091 pci_restore_state(pdev);
6093 r = mpt2sas_base_map_resources(ioc);
6097 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
6098 scsi_unblock_requests(shost);
6099 mpt2sas_base_start_watchdog(ioc);
6102 #endif /* CONFIG_PM */
6105 static struct pci_driver scsih_driver = {
6106 .name = MPT2SAS_DRIVER_NAME,
6107 .id_table = scsih_pci_table,
6108 .probe = _scsih_probe,
6109 .remove = __devexit_p(_scsih_remove),
6111 .suspend = _scsih_suspend,
6112 .resume = _scsih_resume,
6118 * _scsih_init - main entry point for this driver.
6120 * Returns 0 success, anything else error.
6128 printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
6129 MPT2SAS_DRIVER_VERSION);
6131 mpt2sas_transport_template =
6132 sas_attach_transport(&mpt2sas_transport_functions);
6133 if (!mpt2sas_transport_template)
6136 mpt2sas_base_initialize_callback_handler();
6138 /* queuecommand callback hander */
6139 scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
6141 /* task managment callback handler */
6142 tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
6144 /* base internal commands callback handler */
6145 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
6147 /* transport internal commands callback handler */
6148 transport_cb_idx = mpt2sas_base_register_callback_handler(
6149 mpt2sas_transport_done);
6151 /* configuration page API internal commands callback handler */
6152 config_cb_idx = mpt2sas_base_register_callback_handler(
6153 mpt2sas_config_done);
6155 /* ctl module callback handler */
6156 ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
6158 tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
6159 _scsih_tm_tr_complete);
6160 tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
6161 _scsih_sas_control_complete);
6165 error = pci_register_driver(&scsih_driver);
6167 sas_release_transport(mpt2sas_transport_template);
6173 * _scsih_exit - exit point for this driver (when it is a module).
6175 * Returns 0 success, anything else error.
6180 printk(KERN_INFO "mpt2sas version %s unloading\n",
6181 MPT2SAS_DRIVER_VERSION);
6183 pci_unregister_driver(&scsih_driver);
6185 sas_release_transport(mpt2sas_transport_template);
6186 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
6187 mpt2sas_base_release_callback_handler(tm_cb_idx);
6188 mpt2sas_base_release_callback_handler(base_cb_idx);
6189 mpt2sas_base_release_callback_handler(transport_cb_idx);
6190 mpt2sas_base_release_callback_handler(config_cb_idx);
6191 mpt2sas_base_release_callback_handler(ctl_cb_idx);
6193 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
6194 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
6199 module_init(_scsih_init);
6200 module_exit(_scsih_exit);