2 * linux/drivers/message/fusion/mptsas.c
3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com)
8 * Copyright (c) 2005-2007 Dell
10 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; version 2 of the License.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
26 solely responsible for determining the appropriateness of using and
27 distributing the Program and assumes all risks associated with its
28 exercise of rights under this Agreement, including but not limited to
29 the risks and costs of program errors, damage to or loss of data,
30 programs or equipment, and unavailability or interruption of operations.
32 DISCLAIMER OF LIABILITY
33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
37 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
38 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
39 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
41 You should have received a copy of the GNU General Public License
42 along with this program; if not, write to the Free Software
43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
47 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/init.h>
50 #include <linux/errno.h>
51 #include <linux/sched.h>
52 #include <linux/workqueue.h>
53 #include <linux/delay.h> /* for mdelay */
55 #include <scsi/scsi.h>
56 #include <scsi/scsi_cmnd.h>
57 #include <scsi/scsi_device.h>
58 #include <scsi/scsi_host.h>
59 #include <scsi/scsi_transport_sas.h>
60 #include <scsi/scsi_dbg.h>
66 #define my_NAME "Fusion MPT SAS Host driver"
67 #define my_VERSION MPT_LINUX_VERSION_COMMON
68 #define MYNAM "mptsas"
71 * Reserved channel for integrated raid
73 #define MPTSAS_RAID_CHANNEL 1
75 MODULE_AUTHOR(MODULEAUTHOR);
76 MODULE_DESCRIPTION(my_NAME);
77 MODULE_LICENSE("GPL");
78 MODULE_VERSION(my_VERSION);
80 static int mpt_pt_clear;
81 module_param(mpt_pt_clear, int, 0);
82 MODULE_PARM_DESC(mpt_pt_clear,
83 " Clear persistency table: enable=1 "
84 "(default=MPTSCSIH_PT_CLEAR=0)");
86 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
87 #define MPTSAS_MAX_LUN (16895)
88 static int max_lun = MPTSAS_MAX_LUN;
89 module_param(max_lun, int, 0);
90 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
92 static int mptsasDoneCtx = -1;
93 static int mptsasTaskCtx = -1;
94 static int mptsasInternalCtx = -1; /* Used only for internal commands */
95 static int mptsasMgmtCtx = -1;
97 static void mptsas_hotplug_work(struct work_struct *work);
99 enum mptsas_hotplug_action {
104 MPTSAS_ADD_INACTIVE_VOLUME,
108 struct mptsas_hotplug_event {
109 struct work_struct work;
111 enum mptsas_hotplug_action event_type;
119 u8 phys_disk_num_valid; /* hrc (hidden raid component) */
120 u8 phys_disk_num; /* hrc - unique index*/
121 u8 hidden_raid_component; /* hrc - don't expose*/
124 struct mptsas_discovery_event {
125 struct work_struct work;
130 * SAS topology structures
132 * The MPT Fusion firmware interface spreads information about the
133 * SAS topology over many manufacture pages, thus we need some data
134 * structure to collect it and process it for the SAS transport class.
137 struct mptsas_devinfo {
138 u16 handle; /* unique id to address this device */
139 u16 handle_parent; /* unique id to address parent device */
140 u16 handle_enclosure; /* enclosure identifier of the enclosure */
141 u16 slot; /* physical slot in enclosure */
142 u8 phy_id; /* phy number of parent device */
143 u8 port_id; /* sas physical port this device
145 u8 id; /* logical target id of this device */
146 u32 phys_disk_num; /* phys disk id, for csmi-ioctls */
147 u8 channel; /* logical bus number of this device */
148 u64 sas_address; /* WWN of this device,
149 SATA is assigned by HBA,expander */
150 u32 device_info; /* bitfield detailed info about this device */
154 * Specific details on ports, wide/narrow
156 struct mptsas_portinfo_details{
157 u16 num_phys; /* number of phys belong to this port */
158 u64 phy_bitmask; /* TODO, extend support for 255 phys */
159 struct sas_rphy *rphy; /* transport layer rphy object */
160 struct sas_port *port; /* transport layer port object */
161 struct scsi_target *starget;
162 struct mptsas_portinfo *port_info;
165 struct mptsas_phyinfo {
166 u8 phy_id; /* phy index */
167 u8 port_id; /* firmware port identifier */
168 u8 negotiated_link_rate; /* nego'd link rate for this phy */
169 u8 hw_link_rate; /* hardware max/min phys link rate */
170 u8 programmed_link_rate; /* programmed max/min phy link rate */
171 u8 sas_port_add_phy; /* flag to request sas_port_add_phy*/
172 struct mptsas_devinfo identify; /* point to phy device info */
173 struct mptsas_devinfo attached; /* point to attached device info */
174 struct sas_phy *phy; /* transport layer phy object */
175 struct mptsas_portinfo *portinfo;
176 struct mptsas_portinfo_details * port_details;
179 struct mptsas_portinfo {
180 struct list_head list;
181 u16 handle; /* unique id to address this */
182 u16 num_phys; /* number of phys */
183 struct mptsas_phyinfo *phy_info;
186 struct mptsas_enclosure {
187 u64 enclosure_logical_id; /* The WWN for the enclosure */
188 u16 enclosure_handle; /* unique id to address this */
189 u16 flags; /* details enclosure management */
190 u16 num_slot; /* num slots */
191 u16 start_slot; /* first slot */
192 u8 start_id; /* starting logical target id */
193 u8 start_channel; /* starting logical channel id */
194 u8 sep_id; /* SEP device logical target id */
195 u8 sep_channel; /* SEP channel logical channel id */
199 static void mptsas_print_phy_data(MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
201 printk("---- IO UNIT PAGE 0 ------------\n");
202 printk("Handle=0x%X\n",
203 le16_to_cpu(phy_data->AttachedDeviceHandle));
204 printk("Controller Handle=0x%X\n",
205 le16_to_cpu(phy_data->ControllerDevHandle));
206 printk("Port=0x%X\n", phy_data->Port);
207 printk("Port Flags=0x%X\n", phy_data->PortFlags);
208 printk("PHY Flags=0x%X\n", phy_data->PhyFlags);
209 printk("Negotiated Link Rate=0x%X\n", phy_data->NegotiatedLinkRate);
210 printk("Controller PHY Device Info=0x%X\n",
211 le32_to_cpu(phy_data->ControllerPhyDeviceInfo));
212 printk("DiscoveryStatus=0x%X\n",
213 le32_to_cpu(phy_data->DiscoveryStatus));
217 static void mptsas_print_phy_pg0(SasPhyPage0_t *pg0)
221 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
223 printk("---- SAS PHY PAGE 0 ------------\n");
224 printk("Attached Device Handle=0x%X\n",
225 le16_to_cpu(pg0->AttachedDevHandle));
226 printk("SAS Address=0x%llX\n",
227 (unsigned long long)le64_to_cpu(sas_address));
228 printk("Attached PHY Identifier=0x%X\n", pg0->AttachedPhyIdentifier);
229 printk("Attached Device Info=0x%X\n",
230 le32_to_cpu(pg0->AttachedDeviceInfo));
231 printk("Programmed Link Rate=0x%X\n", pg0->ProgrammedLinkRate);
232 printk("Change Count=0x%X\n", pg0->ChangeCount);
233 printk("PHY Info=0x%X\n", le32_to_cpu(pg0->PhyInfo));
237 static void mptsas_print_phy_pg1(SasPhyPage1_t *pg1)
239 printk("---- SAS PHY PAGE 1 ------------\n");
240 printk("Invalid Dword Count=0x%x\n", pg1->InvalidDwordCount);
241 printk("Running Disparity Error Count=0x%x\n",
242 pg1->RunningDisparityErrorCount);
243 printk("Loss Dword Synch Count=0x%x\n", pg1->LossDwordSynchCount);
244 printk("PHY Reset Problem Count=0x%x\n", pg1->PhyResetProblemCount);
248 static void mptsas_print_device_pg0(SasDevicePage0_t *pg0)
252 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
254 printk("---- SAS DEVICE PAGE 0 ---------\n");
255 printk("Handle=0x%X\n" ,le16_to_cpu(pg0->DevHandle));
256 printk("Parent Handle=0x%X\n" ,le16_to_cpu(pg0->ParentDevHandle));
257 printk("Enclosure Handle=0x%X\n", le16_to_cpu(pg0->EnclosureHandle));
258 printk("Slot=0x%X\n", le16_to_cpu(pg0->Slot));
259 printk("SAS Address=0x%llX\n", (unsigned long long)
260 le64_to_cpu(sas_address));
261 printk("Target ID=0x%X\n", pg0->TargetID);
262 printk("Bus=0x%X\n", pg0->Bus);
263 /* The PhyNum field specifies the PHY number of the parent
264 * device this device is linked to
266 printk("Parent Phy Num=0x%X\n", pg0->PhyNum);
267 printk("Access Status=0x%X\n", le16_to_cpu(pg0->AccessStatus));
268 printk("Device Info=0x%X\n", le32_to_cpu(pg0->DeviceInfo));
269 printk("Flags=0x%X\n", le16_to_cpu(pg0->Flags));
270 printk("Physical Port=0x%X\n", pg0->PhysicalPort);
274 static void mptsas_print_expander_pg1(SasExpanderPage1_t *pg1)
276 printk("---- SAS EXPANDER PAGE 1 ------------\n");
278 printk("Physical Port=0x%X\n", pg1->PhysicalPort);
279 printk("PHY Identifier=0x%X\n", pg1->PhyIdentifier);
280 printk("Negotiated Link Rate=0x%X\n", pg1->NegotiatedLinkRate);
281 printk("Programmed Link Rate=0x%X\n", pg1->ProgrammedLinkRate);
282 printk("Hardware Link Rate=0x%X\n", pg1->HwLinkRate);
283 printk("Owner Device Handle=0x%X\n",
284 le16_to_cpu(pg1->OwnerDevHandle));
285 printk("Attached Device Handle=0x%X\n",
286 le16_to_cpu(pg1->AttachedDevHandle));
289 #define mptsas_print_phy_data(phy_data) do { } while (0)
290 #define mptsas_print_phy_pg0(pg0) do { } while (0)
291 #define mptsas_print_phy_pg1(pg1) do { } while (0)
292 #define mptsas_print_device_pg0(pg0) do { } while (0)
293 #define mptsas_print_expander_pg1(pg1) do { } while (0)
296 static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
298 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
299 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
302 static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
304 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
305 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
309 * mptsas_find_portinfo_by_handle
311 * This function should be called with the sas_topology_mutex already held
313 static struct mptsas_portinfo *
314 mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
316 struct mptsas_portinfo *port_info, *rc=NULL;
319 list_for_each_entry(port_info, &ioc->sas_topology, list)
320 for (i = 0; i < port_info->num_phys; i++)
321 if (port_info->phy_info[i].identify.handle == handle) {
330 * Returns true if there is a scsi end device
333 mptsas_is_end_device(struct mptsas_devinfo * attached)
335 if ((attached->sas_address) &&
336 (attached->device_info &
337 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
338 ((attached->device_info &
339 MPI_SAS_DEVICE_INFO_SSP_TARGET) |
340 (attached->device_info &
341 MPI_SAS_DEVICE_INFO_STP_TARGET) |
342 (attached->device_info &
343 MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
351 mptsas_port_delete(struct mptsas_portinfo_details * port_details)
353 struct mptsas_portinfo *port_info;
354 struct mptsas_phyinfo *phy_info;
360 port_info = port_details->port_info;
361 phy_info = port_info->phy_info;
363 dsaswideprintk((KERN_DEBUG "%s: [%p]: num_phys=%02d "
364 "bitmask=0x%016llX\n", __FUNCTION__, port_details,
365 port_details->num_phys, (unsigned long long)
366 port_details->phy_bitmask));
368 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
369 if(phy_info->port_details != port_details)
371 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
372 phy_info->port_details = NULL;
377 static inline struct sas_rphy *
378 mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
380 if (phy_info->port_details)
381 return phy_info->port_details->rphy;
387 mptsas_set_rphy(struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
389 if (phy_info->port_details) {
390 phy_info->port_details->rphy = rphy;
391 dsaswideprintk((KERN_DEBUG "sas_rphy_add: rphy=%p\n", rphy));
394 #ifdef MPT_DEBUG_SAS_WIDE
396 dev_printk(KERN_DEBUG, &rphy->dev, "add:");
397 printk("rphy=%p release=%p\n",
398 rphy, rphy->dev.release);
403 static inline struct sas_port *
404 mptsas_get_port(struct mptsas_phyinfo *phy_info)
406 if (phy_info->port_details)
407 return phy_info->port_details->port;
413 mptsas_set_port(struct mptsas_phyinfo *phy_info, struct sas_port *port)
415 if (phy_info->port_details)
416 phy_info->port_details->port = port;
418 #ifdef MPT_DEBUG_SAS_WIDE
420 dev_printk(KERN_DEBUG, &port->dev, "add: ");
421 printk("port=%p release=%p\n",
422 port, port->dev.release);
427 static inline struct scsi_target *
428 mptsas_get_starget(struct mptsas_phyinfo *phy_info)
430 if (phy_info->port_details)
431 return phy_info->port_details->starget;
437 mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
440 if (phy_info->port_details)
441 phy_info->port_details->starget = starget;
446 * mptsas_setup_wide_ports
448 * Updates for new and existing narrow/wide port configuration
449 * in the sas_topology
452 mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
454 struct mptsas_portinfo_details * port_details;
455 struct mptsas_phyinfo *phy_info, *phy_info_cmp;
459 mutex_lock(&ioc->sas_topology_mutex);
461 phy_info = port_info->phy_info;
462 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
463 if (phy_info->attached.handle)
465 port_details = phy_info->port_details;
468 if (port_details->num_phys < 2)
471 * Removing a phy from a port, letting the last
472 * phy be removed by firmware events.
474 dsaswideprintk((KERN_DEBUG
475 "%s: [%p]: deleting phy = %d\n",
476 __FUNCTION__, port_details, i));
477 port_details->num_phys--;
478 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
479 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
480 sas_port_delete_phy(port_details->port, phy_info->phy);
481 phy_info->port_details = NULL;
485 * Populate and refresh the tree
487 phy_info = port_info->phy_info;
488 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
489 sas_address = phy_info->attached.sas_address;
490 dsaswideprintk((KERN_DEBUG "phy_id=%d sas_address=0x%018llX\n",
491 i, (unsigned long long)sas_address));
494 port_details = phy_info->port_details;
499 port_details = kzalloc(sizeof(*port_details),
503 port_details->num_phys = 1;
504 port_details->port_info = port_info;
505 if (phy_info->phy_id < 64 )
506 port_details->phy_bitmask |=
507 (1 << phy_info->phy_id);
508 phy_info->sas_port_add_phy=1;
509 dsaswideprintk((KERN_DEBUG "\t\tForming port\n\t\t"
510 "phy_id=%d sas_address=0x%018llX\n",
511 i, (unsigned long long)sas_address));
512 phy_info->port_details = port_details;
515 if (i == port_info->num_phys - 1)
517 phy_info_cmp = &port_info->phy_info[i + 1];
518 for (j = i + 1 ; j < port_info->num_phys ; j++,
520 if (!phy_info_cmp->attached.sas_address)
522 if (sas_address != phy_info_cmp->attached.sas_address)
524 if (phy_info_cmp->port_details == port_details )
526 dsaswideprintk((KERN_DEBUG
527 "\t\tphy_id=%d sas_address=0x%018llX\n",
528 j, (unsigned long long)
529 phy_info_cmp->attached.sas_address));
530 if (phy_info_cmp->port_details) {
532 mptsas_get_rphy(phy_info_cmp);
534 mptsas_get_port(phy_info_cmp);
535 port_details->starget =
536 mptsas_get_starget(phy_info_cmp);
537 port_details->num_phys =
538 phy_info_cmp->port_details->num_phys;
539 if (!phy_info_cmp->port_details->num_phys)
540 kfree(phy_info_cmp->port_details);
542 phy_info_cmp->sas_port_add_phy=1;
544 * Adding a phy to a port
546 phy_info_cmp->port_details = port_details;
547 if (phy_info_cmp->phy_id < 64 )
548 port_details->phy_bitmask |=
549 (1 << phy_info_cmp->phy_id);
550 port_details->num_phys++;
556 #ifdef MPT_DEBUG_SAS_WIDE
557 for (i = 0; i < port_info->num_phys; i++) {
558 port_details = port_info->phy_info[i].port_details;
561 dsaswideprintk((KERN_DEBUG
562 "%s: [%p]: phy_id=%02d num_phys=%02d "
563 "bitmask=0x%016llX\n", __FUNCTION__,
564 port_details, i, port_details->num_phys,
565 (unsigned long long)port_details->phy_bitmask));
566 dsaswideprintk((KERN_DEBUG"\t\tport = %p rphy=%p\n",
567 port_details->port, port_details->rphy));
569 dsaswideprintk((KERN_DEBUG"\n"));
571 mutex_unlock(&ioc->sas_topology_mutex);
575 mptsas_target_reset(MPT_ADAPTER *ioc, VirtTarget * vtarget)
577 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
579 if (mptscsih_TMHandler(hd,
580 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
581 vtarget->channel, vtarget->id, 0, 0, 5) < 0) {
583 hd->tmState = TM_STATE_NONE;
584 printk(MYIOC_s_WARN_FMT
585 "Error processing TaskMgmt id=%d TARGET_RESET\n",
586 ioc->name, vtarget->id);
591 mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
592 u32 form, u32 form_specific)
594 ConfigExtendedPageHeader_t hdr;
596 SasEnclosurePage0_t *buffer;
597 dma_addr_t dma_handle;
599 __le64 le_identifier;
601 memset(&hdr, 0, sizeof(hdr));
602 hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
604 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
605 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
607 cfg.cfghdr.ehdr = &hdr;
609 cfg.pageAddr = form + form_specific;
610 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
611 cfg.dir = 0; /* read */
614 error = mpt_config(ioc, &cfg);
617 if (!hdr.ExtPageLength) {
622 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
629 cfg.physAddr = dma_handle;
630 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
632 error = mpt_config(ioc, &cfg);
634 goto out_free_consistent;
636 /* save config data */
637 memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
638 enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
639 enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
640 enclosure->flags = le16_to_cpu(buffer->Flags);
641 enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
642 enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
643 enclosure->start_id = buffer->StartTargetID;
644 enclosure->start_channel = buffer->StartBus;
645 enclosure->sep_id = buffer->SEPTargetID;
646 enclosure->sep_channel = buffer->SEPBus;
649 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
656 mptsas_slave_configure(struct scsi_device *sdev)
659 if (sdev->channel == MPTSAS_RAID_CHANNEL)
662 sas_read_port_mode_page(sdev);
665 return mptscsih_slave_configure(sdev);
669 mptsas_target_alloc(struct scsi_target *starget)
671 struct Scsi_Host *host = dev_to_shost(&starget->dev);
672 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
675 struct sas_rphy *rphy;
676 struct mptsas_portinfo *p;
679 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
683 vtarget->starget = starget;
684 vtarget->ioc_id = hd->ioc->id;
685 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
690 * RAID volumes placed beyond the last expected port.
692 if (starget->channel == MPTSAS_RAID_CHANNEL) {
693 for (i=0; i < hd->ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
694 if (id == hd->ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID)
695 channel = hd->ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus;
699 rphy = dev_to_rphy(starget->dev.parent);
700 mutex_lock(&hd->ioc->sas_topology_mutex);
701 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
702 for (i = 0; i < p->num_phys; i++) {
703 if (p->phy_info[i].attached.sas_address !=
704 rphy->identify.sas_address)
706 id = p->phy_info[i].attached.id;
707 channel = p->phy_info[i].attached.channel;
708 mptsas_set_starget(&p->phy_info[i], starget);
711 * Exposing hidden raid components
713 if (mptscsih_is_phys_disk(hd->ioc, channel, id)) {
714 id = mptscsih_raid_id_to_num(hd->ioc,
717 MPT_TARGET_FLAGS_RAID_COMPONENT;
718 p->phy_info[i].attached.phys_disk_num = id;
720 mutex_unlock(&hd->ioc->sas_topology_mutex);
724 mutex_unlock(&hd->ioc->sas_topology_mutex);
731 vtarget->channel = channel;
732 starget->hostdata = vtarget;
737 mptsas_target_destroy(struct scsi_target *starget)
739 struct Scsi_Host *host = dev_to_shost(&starget->dev);
740 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
741 struct sas_rphy *rphy;
742 struct mptsas_portinfo *p;
745 if (!starget->hostdata)
748 if (starget->channel == MPTSAS_RAID_CHANNEL)
751 rphy = dev_to_rphy(starget->dev.parent);
752 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
753 for (i = 0; i < p->num_phys; i++) {
754 if (p->phy_info[i].attached.sas_address !=
755 rphy->identify.sas_address)
757 mptsas_set_starget(&p->phy_info[i], NULL);
763 kfree(starget->hostdata);
764 starget->hostdata = NULL;
769 mptsas_slave_alloc(struct scsi_device *sdev)
771 struct Scsi_Host *host = sdev->host;
772 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
773 struct sas_rphy *rphy;
774 struct mptsas_portinfo *p;
776 struct scsi_target *starget;
779 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
781 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
782 hd->ioc->name, sizeof(VirtDevice));
785 starget = scsi_target(sdev);
786 vdev->vtarget = starget->hostdata;
788 if (sdev->channel == MPTSAS_RAID_CHANNEL)
791 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
792 mutex_lock(&hd->ioc->sas_topology_mutex);
793 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
794 for (i = 0; i < p->num_phys; i++) {
795 if (p->phy_info[i].attached.sas_address !=
796 rphy->identify.sas_address)
798 vdev->lun = sdev->lun;
800 * Exposing hidden raid components
802 if (mptscsih_is_phys_disk(hd->ioc,
803 p->phy_info[i].attached.channel,
804 p->phy_info[i].attached.id))
805 sdev->no_uld_attach = 1;
806 mutex_unlock(&hd->ioc->sas_topology_mutex);
810 mutex_unlock(&hd->ioc->sas_topology_mutex);
816 vdev->vtarget->num_luns++;
817 sdev->hostdata = vdev;
822 mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
824 VirtDevice *vdev = SCpnt->device->hostdata;
826 if (!vdev || !vdev->vtarget || vdev->vtarget->deleted) {
827 SCpnt->result = DID_NO_CONNECT << 16;
832 // scsi_print_command(SCpnt);
834 return mptscsih_qcmd(SCpnt,done);
838 static struct scsi_host_template mptsas_driver_template = {
839 .module = THIS_MODULE,
840 .proc_name = "mptsas",
841 .proc_info = mptscsih_proc_info,
842 .name = "MPT SPI Host",
843 .info = mptscsih_info,
844 .queuecommand = mptsas_qcmd,
845 .target_alloc = mptsas_target_alloc,
846 .slave_alloc = mptsas_slave_alloc,
847 .slave_configure = mptsas_slave_configure,
848 .target_destroy = mptsas_target_destroy,
849 .slave_destroy = mptscsih_slave_destroy,
850 .change_queue_depth = mptscsih_change_queue_depth,
851 .eh_abort_handler = mptscsih_abort,
852 .eh_device_reset_handler = mptscsih_dev_reset,
853 .eh_bus_reset_handler = mptscsih_bus_reset,
854 .eh_host_reset_handler = mptscsih_host_reset,
855 .bios_param = mptscsih_bios_param,
856 .can_queue = MPT_FC_CAN_QUEUE,
858 .sg_tablesize = MPT_SCSI_SG_DEPTH,
861 .use_clustering = ENABLE_CLUSTERING,
864 static int mptsas_get_linkerrors(struct sas_phy *phy)
866 MPT_ADAPTER *ioc = phy_to_ioc(phy);
867 ConfigExtendedPageHeader_t hdr;
869 SasPhyPage1_t *buffer;
870 dma_addr_t dma_handle;
873 /* FIXME: only have link errors on local phys */
874 if (!scsi_is_sas_phy_local(phy))
877 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
878 hdr.ExtPageLength = 0;
879 hdr.PageNumber = 1 /* page number 1*/;
882 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
883 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
885 cfg.cfghdr.ehdr = &hdr;
887 cfg.pageAddr = phy->identify.phy_identifier;
888 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
889 cfg.dir = 0; /* read */
892 error = mpt_config(ioc, &cfg);
895 if (!hdr.ExtPageLength)
898 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
903 cfg.physAddr = dma_handle;
904 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
906 error = mpt_config(ioc, &cfg);
908 goto out_free_consistent;
910 mptsas_print_phy_pg1(buffer);
912 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
913 phy->running_disparity_error_count =
914 le32_to_cpu(buffer->RunningDisparityErrorCount);
915 phy->loss_of_dword_sync_count =
916 le32_to_cpu(buffer->LossDwordSynchCount);
917 phy->phy_reset_problem_count =
918 le32_to_cpu(buffer->PhyResetProblemCount);
921 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
926 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
927 MPT_FRAME_HDR *reply)
929 ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_COMMAND_GOOD;
931 ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_RF_VALID;
932 memcpy(ioc->sas_mgmt.reply, reply,
933 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
935 complete(&ioc->sas_mgmt.done);
939 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
941 MPT_ADAPTER *ioc = phy_to_ioc(phy);
942 SasIoUnitControlRequest_t *req;
943 SasIoUnitControlReply_t *reply;
946 unsigned long timeleft;
947 int error = -ERESTARTSYS;
949 /* FIXME: fusion doesn't allow non-local phy reset */
950 if (!scsi_is_sas_phy_local(phy))
953 /* not implemented for expanders */
954 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
957 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
960 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
966 hdr = (MPIHeader_t *) mf;
967 req = (SasIoUnitControlRequest_t *)mf;
968 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
969 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
970 req->MsgContext = hdr->MsgContext;
971 req->Operation = hard_reset ?
972 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
973 req->PhyNum = phy->identify.phy_identifier;
975 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
977 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
980 /* On timeout reset the board */
981 mpt_free_msg_frame(ioc, mf);
982 mpt_HardResetHandler(ioc, CAN_SLEEP);
987 /* a reply frame is expected */
988 if ((ioc->sas_mgmt.status &
989 MPT_IOCTL_STATUS_RF_VALID) == 0) {
994 /* process the completed Reply Message Frame */
995 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
996 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
997 printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
1008 mutex_unlock(&ioc->sas_mgmt.mutex);
1014 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
1016 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
1018 struct mptsas_portinfo *p;
1019 struct mptsas_enclosure enclosure_info;
1020 u64 enclosure_handle;
1022 mutex_lock(&ioc->sas_topology_mutex);
1023 list_for_each_entry(p, &ioc->sas_topology, list) {
1024 for (i = 0; i < p->num_phys; i++) {
1025 if (p->phy_info[i].attached.sas_address ==
1026 rphy->identify.sas_address) {
1027 enclosure_handle = p->phy_info[i].
1028 attached.handle_enclosure;
1033 mutex_unlock(&ioc->sas_topology_mutex);
1037 mutex_unlock(&ioc->sas_topology_mutex);
1038 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
1039 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
1040 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
1041 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
1043 *identifier = enclosure_info.enclosure_logical_id;
1048 mptsas_get_bay_identifier(struct sas_rphy *rphy)
1050 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
1051 struct mptsas_portinfo *p;
1054 mutex_lock(&ioc->sas_topology_mutex);
1055 list_for_each_entry(p, &ioc->sas_topology, list) {
1056 for (i = 0; i < p->num_phys; i++) {
1057 if (p->phy_info[i].attached.sas_address ==
1058 rphy->identify.sas_address) {
1059 rc = p->phy_info[i].attached.slot;
1066 mutex_unlock(&ioc->sas_topology_mutex);
1070 static struct sas_function_template mptsas_transport_functions = {
1071 .get_linkerrors = mptsas_get_linkerrors,
1072 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
1073 .get_bay_identifier = mptsas_get_bay_identifier,
1074 .phy_reset = mptsas_phy_reset,
1077 static struct scsi_transport_template *mptsas_transport_template;
1080 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
1082 ConfigExtendedPageHeader_t hdr;
1084 SasIOUnitPage0_t *buffer;
1085 dma_addr_t dma_handle;
1088 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
1089 hdr.ExtPageLength = 0;
1093 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1094 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
1096 cfg.cfghdr.ehdr = &hdr;
1099 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1100 cfg.dir = 0; /* read */
1103 error = mpt_config(ioc, &cfg);
1106 if (!hdr.ExtPageLength) {
1111 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1118 cfg.physAddr = dma_handle;
1119 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1121 error = mpt_config(ioc, &cfg);
1123 goto out_free_consistent;
1125 port_info->num_phys = buffer->NumPhys;
1126 port_info->phy_info = kcalloc(port_info->num_phys,
1127 sizeof(*port_info->phy_info),GFP_KERNEL);
1128 if (!port_info->phy_info) {
1130 goto out_free_consistent;
1133 if (port_info->num_phys)
1135 le16_to_cpu(buffer->PhyData[0].ControllerDevHandle);
1136 for (i = 0; i < port_info->num_phys; i++) {
1137 mptsas_print_phy_data(&buffer->PhyData[i]);
1138 port_info->phy_info[i].phy_id = i;
1139 port_info->phy_info[i].port_id =
1140 buffer->PhyData[i].Port;
1141 port_info->phy_info[i].negotiated_link_rate =
1142 buffer->PhyData[i].NegotiatedLinkRate;
1143 port_info->phy_info[i].portinfo = port_info;
1146 out_free_consistent:
1147 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1148 buffer, dma_handle);
1154 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
1155 u32 form, u32 form_specific)
1157 ConfigExtendedPageHeader_t hdr;
1159 SasPhyPage0_t *buffer;
1160 dma_addr_t dma_handle;
1163 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
1164 hdr.ExtPageLength = 0;
1168 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1169 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
1171 cfg.cfghdr.ehdr = &hdr;
1172 cfg.dir = 0; /* read */
1175 /* Get Phy Pg 0 for each Phy. */
1177 cfg.pageAddr = form + form_specific;
1178 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1180 error = mpt_config(ioc, &cfg);
1184 if (!hdr.ExtPageLength) {
1189 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1196 cfg.physAddr = dma_handle;
1197 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1199 error = mpt_config(ioc, &cfg);
1201 goto out_free_consistent;
1203 mptsas_print_phy_pg0(buffer);
1205 phy_info->hw_link_rate = buffer->HwLinkRate;
1206 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
1207 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
1208 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
1210 out_free_consistent:
1211 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1212 buffer, dma_handle);
1218 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
1219 u32 form, u32 form_specific)
1221 ConfigExtendedPageHeader_t hdr;
1223 SasDevicePage0_t *buffer;
1224 dma_addr_t dma_handle;
1228 if (ioc->sas_discovery_runtime &&
1229 mptsas_is_end_device(device_info))
1232 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
1233 hdr.ExtPageLength = 0;
1237 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1238 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
1240 cfg.cfghdr.ehdr = &hdr;
1241 cfg.pageAddr = form + form_specific;
1243 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1244 cfg.dir = 0; /* read */
1247 memset(device_info, 0, sizeof(struct mptsas_devinfo));
1248 error = mpt_config(ioc, &cfg);
1251 if (!hdr.ExtPageLength) {
1256 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1263 cfg.physAddr = dma_handle;
1264 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1266 error = mpt_config(ioc, &cfg);
1268 goto out_free_consistent;
1270 mptsas_print_device_pg0(buffer);
1272 device_info->handle = le16_to_cpu(buffer->DevHandle);
1273 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
1274 device_info->handle_enclosure =
1275 le16_to_cpu(buffer->EnclosureHandle);
1276 device_info->slot = le16_to_cpu(buffer->Slot);
1277 device_info->phy_id = buffer->PhyNum;
1278 device_info->port_id = buffer->PhysicalPort;
1279 device_info->id = buffer->TargetID;
1280 device_info->phys_disk_num = ~0;
1281 device_info->channel = buffer->Bus;
1282 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
1283 device_info->sas_address = le64_to_cpu(sas_address);
1284 device_info->device_info =
1285 le32_to_cpu(buffer->DeviceInfo);
1287 out_free_consistent:
1288 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1289 buffer, dma_handle);
1295 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
1296 u32 form, u32 form_specific)
1298 ConfigExtendedPageHeader_t hdr;
1300 SasExpanderPage0_t *buffer;
1301 dma_addr_t dma_handle;
1304 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
1305 hdr.ExtPageLength = 0;
1309 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1310 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
1312 cfg.cfghdr.ehdr = &hdr;
1314 cfg.pageAddr = form + form_specific;
1315 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1316 cfg.dir = 0; /* read */
1319 memset(port_info, 0, sizeof(struct mptsas_portinfo));
1320 error = mpt_config(ioc, &cfg);
1324 if (!hdr.ExtPageLength) {
1329 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1336 cfg.physAddr = dma_handle;
1337 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1339 error = mpt_config(ioc, &cfg);
1341 goto out_free_consistent;
1343 /* save config data */
1344 port_info->num_phys = buffer->NumPhys;
1345 port_info->handle = le16_to_cpu(buffer->DevHandle);
1346 port_info->phy_info = kcalloc(port_info->num_phys,
1347 sizeof(*port_info->phy_info),GFP_KERNEL);
1348 if (!port_info->phy_info) {
1350 goto out_free_consistent;
1353 for (i = 0; i < port_info->num_phys; i++)
1354 port_info->phy_info[i].portinfo = port_info;
1356 out_free_consistent:
1357 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1358 buffer, dma_handle);
1364 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
1365 u32 form, u32 form_specific)
1367 ConfigExtendedPageHeader_t hdr;
1369 SasExpanderPage1_t *buffer;
1370 dma_addr_t dma_handle;
1373 if (ioc->sas_discovery_runtime &&
1374 mptsas_is_end_device(&phy_info->attached))
1377 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
1378 hdr.ExtPageLength = 0;
1382 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1383 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
1385 cfg.cfghdr.ehdr = &hdr;
1387 cfg.pageAddr = form + form_specific;
1388 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1389 cfg.dir = 0; /* read */
1392 error = mpt_config(ioc, &cfg);
1396 if (!hdr.ExtPageLength) {
1401 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1408 cfg.physAddr = dma_handle;
1409 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1411 error = mpt_config(ioc, &cfg);
1413 goto out_free_consistent;
1416 mptsas_print_expander_pg1(buffer);
1418 /* save config data */
1419 phy_info->phy_id = buffer->PhyIdentifier;
1420 phy_info->port_id = buffer->PhysicalPort;
1421 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
1422 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
1423 phy_info->hw_link_rate = buffer->HwLinkRate;
1424 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
1425 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
1427 out_free_consistent:
1428 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1429 buffer, dma_handle);
1435 mptsas_parse_device_info(struct sas_identify *identify,
1436 struct mptsas_devinfo *device_info)
1440 identify->sas_address = device_info->sas_address;
1441 identify->phy_identifier = device_info->phy_id;
1444 * Fill in Phy Initiator Port Protocol.
1445 * Bits 6:3, more than one bit can be set, fall through cases.
1447 protocols = device_info->device_info & 0x78;
1448 identify->initiator_port_protocols = 0;
1449 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
1450 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
1451 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1452 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
1453 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
1454 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
1455 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
1456 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
1459 * Fill in Phy Target Port Protocol.
1460 * Bits 10:7, more than one bit can be set, fall through cases.
1462 protocols = device_info->device_info & 0x780;
1463 identify->target_port_protocols = 0;
1464 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1465 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
1466 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
1467 identify->target_port_protocols |= SAS_PROTOCOL_STP;
1468 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
1469 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
1470 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1471 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
1474 * Fill in Attached device type.
1476 switch (device_info->device_info &
1477 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
1478 case MPI_SAS_DEVICE_INFO_NO_DEVICE:
1479 identify->device_type = SAS_PHY_UNUSED;
1481 case MPI_SAS_DEVICE_INFO_END_DEVICE:
1482 identify->device_type = SAS_END_DEVICE;
1484 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
1485 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
1487 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
1488 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
1493 static int mptsas_probe_one_phy(struct device *dev,
1494 struct mptsas_phyinfo *phy_info, int index, int local)
1497 struct sas_phy *phy;
1498 struct sas_port *port;
1506 if (!phy_info->phy) {
1507 phy = sas_phy_alloc(dev, index);
1513 phy = phy_info->phy;
1515 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
1518 * Set Negotiated link rate.
1520 switch (phy_info->negotiated_link_rate) {
1521 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
1522 phy->negotiated_linkrate = SAS_PHY_DISABLED;
1524 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
1525 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
1527 case MPI_SAS_IOUNIT0_RATE_1_5:
1528 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
1530 case MPI_SAS_IOUNIT0_RATE_3_0:
1531 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
1533 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
1534 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
1536 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
1541 * Set Max hardware link rate.
1543 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
1544 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
1545 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
1547 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
1548 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
1555 * Set Max programmed link rate.
1557 switch (phy_info->programmed_link_rate &
1558 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
1559 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
1560 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
1562 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
1563 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
1570 * Set Min hardware link rate.
1572 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
1573 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
1574 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
1576 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
1577 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
1584 * Set Min programmed link rate.
1586 switch (phy_info->programmed_link_rate &
1587 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
1588 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
1589 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
1591 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
1592 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
1598 if (!phy_info->phy) {
1600 error = sas_phy_add(phy);
1605 phy_info->phy = phy;
1608 if (!phy_info->attached.handle ||
1609 !phy_info->port_details)
1612 port = mptsas_get_port(phy_info);
1613 ioc = phy_to_ioc(phy_info->phy);
1615 if (phy_info->sas_port_add_phy) {
1618 port = sas_port_alloc_num(dev);
1623 error = sas_port_add(port);
1625 dfailprintk((MYIOC_s_ERR_FMT
1626 "%s: exit at line=%d\n", ioc->name,
1627 __FUNCTION__, __LINE__));
1630 mptsas_set_port(phy_info, port);
1631 dsaswideprintk((KERN_DEBUG
1632 "sas_port_alloc: port=%p dev=%p port_id=%d\n",
1633 port, dev, port->port_identifier));
1635 dsaswideprintk((KERN_DEBUG "sas_port_add_phy: phy_id=%d\n",
1637 sas_port_add_phy(port, phy_info->phy);
1638 phy_info->sas_port_add_phy = 0;
1641 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
1643 struct sas_rphy *rphy;
1644 struct device *parent;
1645 struct sas_identify identify;
1647 parent = dev->parent->parent;
1649 * Let the hotplug_work thread handle processing
1650 * the adding/removing of devices that occur
1651 * after start of day.
1653 if (ioc->sas_discovery_runtime &&
1654 mptsas_is_end_device(&phy_info->attached))
1657 mptsas_parse_device_info(&identify, &phy_info->attached);
1658 if (scsi_is_host_device(parent)) {
1659 struct mptsas_portinfo *port_info;
1662 mutex_lock(&ioc->sas_topology_mutex);
1663 port_info = mptsas_find_portinfo_by_handle(ioc,
1665 mutex_unlock(&ioc->sas_topology_mutex);
1667 for (i = 0; i < port_info->num_phys; i++)
1668 if (port_info->phy_info[i].identify.sas_address ==
1669 identify.sas_address) {
1670 sas_port_mark_backlink(port);
1674 } else if (scsi_is_sas_rphy(parent)) {
1675 struct sas_rphy *parent_rphy = dev_to_rphy(parent);
1676 if (identify.sas_address ==
1677 parent_rphy->identify.sas_address) {
1678 sas_port_mark_backlink(port);
1683 switch (identify.device_type) {
1684 case SAS_END_DEVICE:
1685 rphy = sas_end_device_alloc(port);
1687 case SAS_EDGE_EXPANDER_DEVICE:
1688 case SAS_FANOUT_EXPANDER_DEVICE:
1689 rphy = sas_expander_alloc(port, identify.device_type);
1696 dfailprintk((MYIOC_s_ERR_FMT
1697 "%s: exit at line=%d\n", ioc->name,
1698 __FUNCTION__, __LINE__));
1702 rphy->identify = identify;
1703 error = sas_rphy_add(rphy);
1705 dfailprintk((MYIOC_s_ERR_FMT
1706 "%s: exit at line=%d\n", ioc->name,
1707 __FUNCTION__, __LINE__));
1708 sas_rphy_free(rphy);
1711 mptsas_set_rphy(phy_info, rphy);
1719 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1721 struct mptsas_portinfo *port_info, *hba;
1722 u32 handle = 0xFFFF;
1723 int error = -ENOMEM, i;
1725 hba = kzalloc(sizeof(*port_info), GFP_KERNEL);
1729 error = mptsas_sas_io_unit_pg0(ioc, hba);
1731 goto out_free_port_info;
1733 mutex_lock(&ioc->sas_topology_mutex);
1734 ioc->handle = hba->handle;
1735 port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle);
1738 list_add_tail(&port_info->list, &ioc->sas_topology);
1740 port_info->handle = hba->handle;
1741 for (i = 0; i < hba->num_phys; i++)
1742 port_info->phy_info[i].negotiated_link_rate =
1743 hba->phy_info[i].negotiated_link_rate;
1744 kfree(hba->phy_info);
1748 mutex_unlock(&ioc->sas_topology_mutex);
1750 for (i = 0; i < port_info->num_phys; i++) {
1751 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
1752 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
1753 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
1755 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
1756 (MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE <<
1757 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), handle);
1758 port_info->phy_info[i].identify.phy_id =
1759 port_info->phy_info[i].phy_id;
1760 handle = port_info->phy_info[i].identify.handle;
1762 if (port_info->phy_info[i].attached.handle)
1763 mptsas_sas_device_pg0(ioc,
1764 &port_info->phy_info[i].attached,
1765 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1766 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1767 port_info->phy_info[i].attached.handle);
1770 mptsas_setup_wide_ports(ioc, port_info);
1772 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
1773 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
1774 &port_info->phy_info[i], ioc->sas_index, 1);
1785 mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1787 struct mptsas_portinfo *port_info, *p, *ex;
1788 struct device *parent;
1789 struct sas_rphy *rphy;
1790 int error = -ENOMEM, i, j;
1792 ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
1796 error = mptsas_sas_expander_pg0(ioc, ex,
1797 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
1798 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle);
1800 goto out_free_port_info;
1802 *handle = ex->handle;
1804 mutex_lock(&ioc->sas_topology_mutex);
1805 port_info = mptsas_find_portinfo_by_handle(ioc, *handle);
1808 list_add_tail(&port_info->list, &ioc->sas_topology);
1810 port_info->handle = ex->handle;
1811 kfree(ex->phy_info);
1815 mutex_unlock(&ioc->sas_topology_mutex);
1817 for (i = 0; i < port_info->num_phys; i++) {
1818 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
1819 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
1820 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
1822 if (port_info->phy_info[i].identify.handle) {
1823 mptsas_sas_device_pg0(ioc,
1824 &port_info->phy_info[i].identify,
1825 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1826 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1827 port_info->phy_info[i].identify.handle);
1828 port_info->phy_info[i].identify.phy_id =
1829 port_info->phy_info[i].phy_id;
1832 if (port_info->phy_info[i].attached.handle) {
1833 mptsas_sas_device_pg0(ioc,
1834 &port_info->phy_info[i].attached,
1835 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1836 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1837 port_info->phy_info[i].attached.handle);
1838 port_info->phy_info[i].attached.phy_id =
1839 port_info->phy_info[i].phy_id;
1843 parent = &ioc->sh->shost_gendev;
1844 for (i = 0; i < port_info->num_phys; i++) {
1845 mutex_lock(&ioc->sas_topology_mutex);
1846 list_for_each_entry(p, &ioc->sas_topology, list) {
1847 for (j = 0; j < p->num_phys; j++) {
1848 if (port_info->phy_info[i].identify.handle !=
1849 p->phy_info[j].attached.handle)
1851 rphy = mptsas_get_rphy(&p->phy_info[j]);
1852 parent = &rphy->dev;
1855 mutex_unlock(&ioc->sas_topology_mutex);
1858 mptsas_setup_wide_ports(ioc, port_info);
1860 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
1861 mptsas_probe_one_phy(parent, &port_info->phy_info[i],
1868 kfree(ex->phy_info);
1876 * mptsas_delete_expander_phys
1879 * This will traverse topology, and remove expanders
1880 * that are no longer present
1883 mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1885 struct mptsas_portinfo buffer;
1886 struct mptsas_portinfo *port_info, *n, *parent;
1887 struct mptsas_phyinfo *phy_info;
1888 struct scsi_target * starget;
1889 VirtTarget * vtarget;
1890 struct sas_port * port;
1892 u64 expander_sas_address;
1894 mutex_lock(&ioc->sas_topology_mutex);
1895 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
1897 if (port_info->phy_info &&
1898 (!(port_info->phy_info[0].identify.device_info &
1899 MPI_SAS_DEVICE_INFO_SMP_TARGET)))
1902 if (mptsas_sas_expander_pg0(ioc, &buffer,
1903 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
1904 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) {
1907 * Issue target reset to all child end devices
1908 * then mark them deleted to prevent further
1911 phy_info = port_info->phy_info;
1912 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
1913 starget = mptsas_get_starget(phy_info);
1916 vtarget = starget->hostdata;
1917 if(vtarget->deleted)
1919 vtarget->deleted = 1;
1920 mptsas_target_reset(ioc, vtarget);
1921 sas_port_delete(mptsas_get_port(phy_info));
1922 mptsas_port_delete(phy_info->port_details);
1926 * Obtain the port_info instance to the parent port
1928 parent = mptsas_find_portinfo_by_handle(ioc,
1929 port_info->phy_info[0].identify.handle_parent);
1934 expander_sas_address =
1935 port_info->phy_info[0].identify.sas_address;
1938 * Delete rphys in the parent that point
1939 * to this expander. The transport layer will
1940 * cleanup all the children.
1942 phy_info = parent->phy_info;
1943 for (i = 0; i < parent->num_phys; i++, phy_info++) {
1944 port = mptsas_get_port(phy_info);
1947 if (phy_info->attached.sas_address !=
1948 expander_sas_address)
1950 #ifdef MPT_DEBUG_SAS_WIDE
1951 dev_printk(KERN_DEBUG, &port->dev,
1952 "delete port (%d)\n", port->port_identifier);
1954 sas_port_delete(port);
1955 mptsas_port_delete(phy_info->port_details);
1959 phy_info = port_info->phy_info;
1960 for (i = 0; i < port_info->num_phys; i++, phy_info++)
1961 mptsas_port_delete(phy_info->port_details);
1963 list_del(&port_info->list);
1964 kfree(port_info->phy_info);
1968 * Free this memory allocated from inside
1969 * mptsas_sas_expander_pg0
1971 kfree(buffer.phy_info);
1973 mutex_unlock(&ioc->sas_topology_mutex);
1977 * Start of day discovery
1980 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
1982 u32 handle = 0xFFFF;
1985 mutex_lock(&ioc->sas_discovery_mutex);
1986 mptsas_probe_hba_phys(ioc);
1987 while (!mptsas_probe_expander_phys(ioc, &handle))
1990 Reporting RAID volumes.
1992 if (!ioc->ir_firmware)
1994 if (!ioc->raid_data.pIocPg2)
1996 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
1998 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1999 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
2000 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
2003 mutex_unlock(&ioc->sas_discovery_mutex);
2007 * Work queue thread to handle Runtime discovery
2008 * Mere purpose is the hot add/delete of expanders
2012 __mptsas_discovery_work(MPT_ADAPTER *ioc)
2014 u32 handle = 0xFFFF;
2016 ioc->sas_discovery_runtime=1;
2017 mptsas_delete_expander_phys(ioc);
2018 mptsas_probe_hba_phys(ioc);
2019 while (!mptsas_probe_expander_phys(ioc, &handle))
2021 ioc->sas_discovery_runtime=0;
2025 * Work queue thread to handle Runtime discovery
2026 * Mere purpose is the hot add/delete of expanders
2030 mptsas_discovery_work(struct work_struct *work)
2032 struct mptsas_discovery_event *ev =
2033 container_of(work, struct mptsas_discovery_event, work);
2034 MPT_ADAPTER *ioc = ev->ioc;
2036 mutex_lock(&ioc->sas_discovery_mutex);
2037 __mptsas_discovery_work(ioc);
2038 mutex_unlock(&ioc->sas_discovery_mutex);
2042 static struct mptsas_phyinfo *
2043 mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
2045 struct mptsas_portinfo *port_info;
2046 struct mptsas_phyinfo *phy_info = NULL;
2049 mutex_lock(&ioc->sas_topology_mutex);
2050 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2051 for (i = 0; i < port_info->num_phys; i++) {
2052 if (!mptsas_is_end_device(
2053 &port_info->phy_info[i].attached))
2055 if (port_info->phy_info[i].attached.sas_address
2058 phy_info = &port_info->phy_info[i];
2062 mutex_unlock(&ioc->sas_topology_mutex);
2066 static struct mptsas_phyinfo *
2067 mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u8 channel, u8 id)
2069 struct mptsas_portinfo *port_info;
2070 struct mptsas_phyinfo *phy_info = NULL;
2073 mutex_lock(&ioc->sas_topology_mutex);
2074 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2075 for (i = 0; i < port_info->num_phys; i++) {
2076 if (!mptsas_is_end_device(
2077 &port_info->phy_info[i].attached))
2079 if (port_info->phy_info[i].attached.id != id)
2081 if (port_info->phy_info[i].attached.channel != channel)
2083 phy_info = &port_info->phy_info[i];
2087 mutex_unlock(&ioc->sas_topology_mutex);
2091 static struct mptsas_phyinfo *
2092 mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
2094 struct mptsas_portinfo *port_info;
2095 struct mptsas_phyinfo *phy_info = NULL;
2098 mutex_lock(&ioc->sas_topology_mutex);
2099 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2100 for (i = 0; i < port_info->num_phys; i++) {
2101 if (!mptsas_is_end_device(
2102 &port_info->phy_info[i].attached))
2104 if (port_info->phy_info[i].attached.phys_disk_num == ~0)
2106 if (port_info->phy_info[i].attached.phys_disk_num != id)
2108 if (port_info->phy_info[i].attached.channel != channel)
2110 phy_info = &port_info->phy_info[i];
2114 mutex_unlock(&ioc->sas_topology_mutex);
2119 * Work queue thread to clear the persitency table
2122 mptsas_persist_clear_table(struct work_struct *work)
2124 MPT_ADAPTER *ioc = container_of(work, MPT_ADAPTER, sas_persist_task);
2126 mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT);
2130 mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
2134 sdev->no_uld_attach = data ? 1 : 0;
2135 rc = scsi_device_reprobe(sdev);
2139 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
2141 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
2142 mptsas_reprobe_lun);
2146 mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
2149 ConfigPageHeader_t hdr;
2150 dma_addr_t dma_handle;
2151 pRaidVolumePage0_t buffer = NULL;
2152 RaidPhysDiskPage0_t phys_disk;
2154 struct mptsas_hotplug_event *ev;
2156 memset(&cfg, 0 , sizeof(CONFIGPARMS));
2157 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
2158 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
2159 cfg.pageAddr = (channel << 8) + id;
2160 cfg.cfghdr.hdr = &hdr;
2161 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2163 if (mpt_config(ioc, &cfg) != 0)
2166 if (!hdr.PageLength)
2169 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
2175 cfg.physAddr = dma_handle;
2176 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2178 if (mpt_config(ioc, &cfg) != 0)
2181 if (!(buffer->VolumeStatus.Flags &
2182 MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
2185 if (!buffer->NumPhysDisks)
2188 for (i = 0; i < buffer->NumPhysDisks; i++) {
2190 if (mpt_raid_phys_disk_pg0(ioc,
2191 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
2194 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2196 printk(KERN_WARNING "mptsas: lost hotplug event\n");
2200 INIT_WORK(&ev->work, mptsas_hotplug_work);
2202 ev->id = phys_disk.PhysDiskID;
2203 ev->channel = phys_disk.PhysDiskBus;
2204 ev->phys_disk_num_valid = 1;
2205 ev->phys_disk_num = phys_disk.PhysDiskNum;
2206 ev->event_type = MPTSAS_ADD_DEVICE;
2207 schedule_work(&ev->work);
2212 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
2216 * Work queue thread to handle SAS hotplug events
2219 mptsas_hotplug_work(struct work_struct *work)
2221 struct mptsas_hotplug_event *ev =
2222 container_of(work, struct mptsas_hotplug_event, work);
2224 MPT_ADAPTER *ioc = ev->ioc;
2225 struct mptsas_phyinfo *phy_info;
2226 struct sas_rphy *rphy;
2227 struct sas_port *port;
2228 struct scsi_device *sdev;
2229 struct scsi_target * starget;
2230 struct sas_identify identify;
2232 struct mptsas_devinfo sas_device;
2233 VirtTarget *vtarget;
2234 VirtDevice *vdevice;
2236 mutex_lock(&ioc->sas_discovery_mutex);
2237 switch (ev->event_type) {
2238 case MPTSAS_DEL_DEVICE:
2241 if (ev->phys_disk_num_valid) {
2242 if (ev->hidden_raid_component){
2243 if (mptsas_sas_device_pg0(ioc, &sas_device,
2244 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
2245 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2246 (ev->channel << 8) + ev->id)) {
2247 dfailprintk((MYIOC_s_ERR_FMT
2248 "%s: exit at line=%d\n", ioc->name,
2249 __FUNCTION__, __LINE__));
2252 phy_info = mptsas_find_phyinfo_by_sas_address(
2253 ioc, sas_device.sas_address);
2255 phy_info = mptsas_find_phyinfo_by_phys_disk_num(
2256 ioc, ev->channel, ev->phys_disk_num);
2260 phy_info = mptsas_find_phyinfo_by_target(ioc,
2261 ev->channel, ev->id);
2264 * Sanity checks, for non-existing phys and remote rphys.
2267 dfailprintk((MYIOC_s_ERR_FMT
2268 "%s: exit at line=%d\n", ioc->name,
2269 __FUNCTION__, __LINE__));
2272 if (!phy_info->port_details) {
2273 dfailprintk((MYIOC_s_ERR_FMT
2274 "%s: exit at line=%d\n", ioc->name,
2275 __FUNCTION__, __LINE__));
2278 rphy = mptsas_get_rphy(phy_info);
2280 dfailprintk((MYIOC_s_ERR_FMT
2281 "%s: exit at line=%d\n", ioc->name,
2282 __FUNCTION__, __LINE__));
2286 port = mptsas_get_port(phy_info);
2288 dfailprintk((MYIOC_s_ERR_FMT
2289 "%s: exit at line=%d\n", ioc->name,
2290 __FUNCTION__, __LINE__));
2294 starget = mptsas_get_starget(phy_info);
2296 vtarget = starget->hostdata;
2299 dfailprintk((MYIOC_s_ERR_FMT
2300 "%s: exit at line=%d\n", ioc->name,
2301 __FUNCTION__, __LINE__));
2306 * Handling RAID components
2308 if (ev->phys_disk_num_valid &&
2309 ev->hidden_raid_component) {
2310 printk(MYIOC_s_INFO_FMT
2311 "RAID Hidding: channel=%d, id=%d, "
2312 "physdsk %d \n", ioc->name, ev->channel,
2313 ev->id, ev->phys_disk_num);
2314 vtarget->id = ev->phys_disk_num;
2316 MPT_TARGET_FLAGS_RAID_COMPONENT;
2317 mptsas_reprobe_target(starget, 1);
2318 phy_info->attached.phys_disk_num =
2323 vtarget->deleted = 1;
2324 mptsas_target_reset(ioc, vtarget);
2327 if (phy_info->attached.device_info &
2328 MPI_SAS_DEVICE_INFO_SSP_TARGET)
2330 if (phy_info->attached.device_info &
2331 MPI_SAS_DEVICE_INFO_STP_TARGET)
2333 if (phy_info->attached.device_info &
2334 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
2337 printk(MYIOC_s_INFO_FMT
2338 "removing %s device, channel %d, id %d, phy %d\n",
2339 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
2340 #ifdef MPT_DEBUG_SAS_WIDE
2341 dev_printk(KERN_DEBUG, &port->dev,
2342 "delete port (%d)\n", port->port_identifier);
2344 sas_port_delete(port);
2345 mptsas_port_delete(phy_info->port_details);
2347 case MPTSAS_ADD_DEVICE:
2349 if (ev->phys_disk_num_valid)
2350 mpt_findImVolumes(ioc);
2353 * Refresh sas device pg0 data
2355 if (mptsas_sas_device_pg0(ioc, &sas_device,
2356 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
2357 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2358 (ev->channel << 8) + ev->id)) {
2359 dfailprintk((MYIOC_s_ERR_FMT
2360 "%s: exit at line=%d\n", ioc->name,
2361 __FUNCTION__, __LINE__));
2365 __mptsas_discovery_work(ioc);
2367 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
2368 sas_device.sas_address);
2370 if (!phy_info || !phy_info->port_details) {
2371 dfailprintk((MYIOC_s_ERR_FMT
2372 "%s: exit at line=%d\n", ioc->name,
2373 __FUNCTION__, __LINE__));
2377 starget = mptsas_get_starget(phy_info);
2378 if (starget && (!ev->hidden_raid_component)){
2380 vtarget = starget->hostdata;
2383 dfailprintk((MYIOC_s_ERR_FMT
2384 "%s: exit at line=%d\n", ioc->name,
2385 __FUNCTION__, __LINE__));
2389 * Handling RAID components
2391 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2392 printk(MYIOC_s_INFO_FMT
2393 "RAID Exposing: channel=%d, id=%d, "
2394 "physdsk %d \n", ioc->name, ev->channel,
2395 ev->id, ev->phys_disk_num);
2397 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
2398 vtarget->id = ev->id;
2399 mptsas_reprobe_target(starget, 0);
2400 phy_info->attached.phys_disk_num = ~0;
2405 if (mptsas_get_rphy(phy_info)) {
2406 dfailprintk((MYIOC_s_ERR_FMT
2407 "%s: exit at line=%d\n", ioc->name,
2408 __FUNCTION__, __LINE__));
2409 if (ev->channel) printk("%d\n", __LINE__);
2413 port = mptsas_get_port(phy_info);
2415 dfailprintk((MYIOC_s_ERR_FMT
2416 "%s: exit at line=%d\n", ioc->name,
2417 __FUNCTION__, __LINE__));
2420 memcpy(&phy_info->attached, &sas_device,
2421 sizeof(struct mptsas_devinfo));
2423 if (phy_info->attached.device_info &
2424 MPI_SAS_DEVICE_INFO_SSP_TARGET)
2426 if (phy_info->attached.device_info &
2427 MPI_SAS_DEVICE_INFO_STP_TARGET)
2429 if (phy_info->attached.device_info &
2430 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
2433 printk(MYIOC_s_INFO_FMT
2434 "attaching %s device, channel %d, id %d, phy %d\n",
2435 ioc->name, ds, ev->channel, ev->id, ev->phy_id);
2437 mptsas_parse_device_info(&identify, &phy_info->attached);
2438 rphy = sas_end_device_alloc(port);
2440 dfailprintk((MYIOC_s_ERR_FMT
2441 "%s: exit at line=%d\n", ioc->name,
2442 __FUNCTION__, __LINE__));
2443 break; /* non-fatal: an rphy can be added later */
2446 rphy->identify = identify;
2447 if (sas_rphy_add(rphy)) {
2448 dfailprintk((MYIOC_s_ERR_FMT
2449 "%s: exit at line=%d\n", ioc->name,
2450 __FUNCTION__, __LINE__));
2451 sas_rphy_free(rphy);
2454 mptsas_set_rphy(phy_info, rphy);
2456 case MPTSAS_ADD_RAID:
2457 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
2460 scsi_device_put(sdev);
2463 printk(MYIOC_s_INFO_FMT
2464 "attaching raid volume, channel %d, id %d\n",
2465 ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
2466 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, ev->id, 0);
2467 mpt_findImVolumes(ioc);
2469 case MPTSAS_DEL_RAID:
2470 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
2474 printk(MYIOC_s_INFO_FMT
2475 "removing raid volume, channel %d, id %d\n",
2476 ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
2477 vdevice->vtarget->deleted = 1;
2478 mptsas_target_reset(ioc, vdevice->vtarget);
2479 vdevice = sdev->hostdata;
2480 scsi_remove_device(sdev);
2481 scsi_device_put(sdev);
2482 mpt_findImVolumes(ioc);
2484 case MPTSAS_ADD_INACTIVE_VOLUME:
2485 mptsas_adding_inactive_raid_components(ioc,
2486 ev->channel, ev->id);
2488 case MPTSAS_IGNORE_EVENT:
2493 mutex_unlock(&ioc->sas_discovery_mutex);
2498 mptsas_send_sas_event(MPT_ADAPTER *ioc,
2499 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
2501 struct mptsas_hotplug_event *ev;
2502 u32 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
2506 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
2507 MPI_SAS_DEVICE_INFO_STP_TARGET |
2508 MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0)
2511 switch (sas_event_data->ReasonCode) {
2512 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
2513 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
2514 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2516 printk(KERN_WARNING "mptsas: lost hotplug event\n");
2520 INIT_WORK(&ev->work, mptsas_hotplug_work);
2522 ev->handle = le16_to_cpu(sas_event_data->DevHandle);
2524 le16_to_cpu(sas_event_data->ParentDevHandle);
2525 ev->channel = sas_event_data->Bus;
2526 ev->id = sas_event_data->TargetID;
2527 ev->phy_id = sas_event_data->PhyNum;
2528 memcpy(&sas_address, &sas_event_data->SASAddress,
2530 ev->sas_address = le64_to_cpu(sas_address);
2531 ev->device_info = device_info;
2533 if (sas_event_data->ReasonCode &
2534 MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
2535 ev->event_type = MPTSAS_ADD_DEVICE;
2537 ev->event_type = MPTSAS_DEL_DEVICE;
2538 schedule_work(&ev->work);
2540 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
2542 * Persistent table is full.
2544 INIT_WORK(&ioc->sas_persist_task,
2545 mptsas_persist_clear_table);
2546 schedule_work(&ioc->sas_persist_task);
2549 * TODO, handle other events
2551 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
2552 case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
2553 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
2554 case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
2555 case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
2556 case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
2557 case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
2563 mptsas_send_raid_event(MPT_ADAPTER *ioc,
2564 EVENT_DATA_RAID *raid_event_data)
2566 struct mptsas_hotplug_event *ev;
2567 int status = le32_to_cpu(raid_event_data->SettingsStatus);
2568 int state = (status >> 8) & 0xff;
2570 if (ioc->bus_type != SAS)
2573 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2575 printk(KERN_WARNING "mptsas: lost hotplug event\n");
2579 INIT_WORK(&ev->work, mptsas_hotplug_work);
2581 ev->id = raid_event_data->VolumeID;
2582 ev->channel = raid_event_data->VolumeBus;
2583 ev->event_type = MPTSAS_IGNORE_EVENT;
2585 switch (raid_event_data->ReasonCode) {
2586 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
2587 ev->phys_disk_num_valid = 1;
2588 ev->phys_disk_num = raid_event_data->PhysDiskNum;
2589 ev->event_type = MPTSAS_ADD_DEVICE;
2591 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
2592 ev->phys_disk_num_valid = 1;
2593 ev->phys_disk_num = raid_event_data->PhysDiskNum;
2594 ev->hidden_raid_component = 1;
2595 ev->event_type = MPTSAS_DEL_DEVICE;
2597 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
2599 case MPI_PD_STATE_ONLINE:
2600 case MPI_PD_STATE_NOT_COMPATIBLE:
2601 ev->phys_disk_num_valid = 1;
2602 ev->phys_disk_num = raid_event_data->PhysDiskNum;
2603 ev->hidden_raid_component = 1;
2604 ev->event_type = MPTSAS_ADD_DEVICE;
2606 case MPI_PD_STATE_MISSING:
2607 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
2608 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
2609 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
2610 ev->phys_disk_num_valid = 1;
2611 ev->phys_disk_num = raid_event_data->PhysDiskNum;
2612 ev->event_type = MPTSAS_DEL_DEVICE;
2618 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
2619 ev->event_type = MPTSAS_DEL_RAID;
2621 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
2622 ev->event_type = MPTSAS_ADD_RAID;
2624 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
2626 case MPI_RAIDVOL0_STATUS_STATE_FAILED:
2627 case MPI_RAIDVOL0_STATUS_STATE_MISSING:
2628 ev->event_type = MPTSAS_DEL_RAID;
2630 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
2631 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
2632 ev->event_type = MPTSAS_ADD_RAID;
2641 schedule_work(&ev->work);
2645 mptsas_send_discovery_event(MPT_ADAPTER *ioc,
2646 EVENT_DATA_SAS_DISCOVERY *discovery_data)
2648 struct mptsas_discovery_event *ev;
2653 * This flag will be non-zero when firmware
2654 * kicks off discovery, and return to zero
2655 * once its completed.
2657 if (discovery_data->DiscoveryStatus)
2660 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2663 INIT_WORK(&ev->work, mptsas_discovery_work);
2665 schedule_work(&ev->work);
2669 * mptsas_send_ir2_event - handle exposing hidden disk when
2670 * an inactive raid volume is added
2672 * @ioc: Pointer to MPT_ADAPTER structure
2677 mptsas_send_ir2_event(MPT_ADAPTER *ioc, PTR_MPI_EVENT_DATA_IR2 ir2_data)
2679 struct mptsas_hotplug_event *ev;
2681 if (ir2_data->ReasonCode !=
2682 MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED)
2685 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2689 INIT_WORK(&ev->work, mptsas_hotplug_work);
2691 ev->id = ir2_data->TargetID;
2692 ev->channel = ir2_data->Bus;
2693 ev->event_type = MPTSAS_ADD_INACTIVE_VOLUME;
2695 schedule_work(&ev->work);
2699 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
2702 u8 event = le32_to_cpu(reply->Event) & 0xFF;
2708 * sas_discovery_ignore_events
2710 * This flag is to prevent anymore processing of
2711 * sas events once mptsas_remove function is called.
2713 if (ioc->sas_discovery_ignore_events) {
2714 rc = mptscsih_event_process(ioc, reply);
2719 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
2720 mptsas_send_sas_event(ioc,
2721 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
2723 case MPI_EVENT_INTEGRATED_RAID:
2724 mptsas_send_raid_event(ioc,
2725 (EVENT_DATA_RAID *)reply->Data);
2727 case MPI_EVENT_PERSISTENT_TABLE_FULL:
2728 INIT_WORK(&ioc->sas_persist_task,
2729 mptsas_persist_clear_table);
2730 schedule_work(&ioc->sas_persist_task);
2732 case MPI_EVENT_SAS_DISCOVERY:
2733 mptsas_send_discovery_event(ioc,
2734 (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
2737 mptsas_send_ir2_event(ioc,
2738 (PTR_MPI_EVENT_DATA_IR2)reply->Data);
2741 rc = mptscsih_event_process(ioc, reply);
2750 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2752 struct Scsi_Host *sh;
2755 unsigned long flags;
2763 r = mpt_attach(pdev,id);
2767 ioc = pci_get_drvdata(pdev);
2768 ioc->DoneCtx = mptsasDoneCtx;
2769 ioc->TaskCtx = mptsasTaskCtx;
2770 ioc->InternalCtx = mptsasInternalCtx;
2772 /* Added sanity check on readiness of the MPT adapter.
2774 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
2775 printk(MYIOC_s_WARN_FMT
2776 "Skipping because it's not operational!\n",
2779 goto out_mptsas_probe;
2783 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
2786 goto out_mptsas_probe;
2789 /* Sanity check - ensure at least 1 port is INITIATOR capable
2792 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
2793 if (ioc->pfacts[ii].ProtocolFlags &
2794 MPI_PORTFACTS_PROTOCOL_INITIATOR)
2799 printk(MYIOC_s_WARN_FMT
2800 "Skipping ioc=%p because SCSI Initiator mode "
2801 "is NOT enabled!\n", ioc->name, ioc);
2805 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
2807 printk(MYIOC_s_WARN_FMT
2808 "Unable to register controller with SCSI subsystem\n",
2811 goto out_mptsas_probe;
2814 spin_lock_irqsave(&ioc->FreeQlock, flags);
2816 /* Attach the SCSI Host to the IOC structure
2824 /* set 16 byte cdb's */
2825 sh->max_cmd_len = 16;
2827 sh->max_id = ioc->pfacts[0].PortSCSIID;
2828 sh->max_lun = max_lun;
2830 sh->transportt = mptsas_transport_template;
2832 sh->this_id = ioc->pfacts[0].PortSCSIID;
2836 sh->unique_id = ioc->id;
2838 INIT_LIST_HEAD(&ioc->sas_topology);
2839 mutex_init(&ioc->sas_topology_mutex);
2840 mutex_init(&ioc->sas_discovery_mutex);
2841 mutex_init(&ioc->sas_mgmt.mutex);
2842 init_completion(&ioc->sas_mgmt.done);
2844 /* Verify that we won't exceed the maximum
2845 * number of chain buffers
2846 * We can optimize: ZZ = req_sz/sizeof(SGE)
2848 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
2849 * + (req_sz - 64)/sizeof(SGE)
2850 * A slightly different algorithm is required for
2853 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
2854 if (sizeof(dma_addr_t) == sizeof(u64)) {
2855 numSGE = (scale - 1) *
2856 (ioc->facts.MaxChainDepth-1) + scale +
2857 (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
2860 numSGE = 1 + (scale - 1) *
2861 (ioc->facts.MaxChainDepth-1) + scale +
2862 (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
2866 if (numSGE < sh->sg_tablesize) {
2867 /* Reset this value */
2868 dprintk((MYIOC_s_INFO_FMT
2869 "Resetting sg_tablesize to %d from %d\n",
2870 ioc->name, numSGE, sh->sg_tablesize));
2871 sh->sg_tablesize = numSGE;
2874 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
2876 hd = (MPT_SCSI_HOST *) sh->hostdata;
2879 /* SCSI needs scsi_cmnd lookup table!
2880 * (with size equal to req_depth*PtrSz!)
2882 hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
2883 if (!hd->ScsiLookup) {
2885 goto out_mptsas_probe;
2888 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
2889 ioc->name, hd->ScsiLookup));
2891 /* Clear the TM flags
2894 hd->tmState = TM_STATE_NONE;
2895 hd->resetPending = 0;
2896 hd->abortSCpnt = NULL;
2898 /* Clear the pointer used to store
2899 * single-threaded commands, i.e., those
2900 * issued during a bus scan, dv and
2901 * configuration pages.
2905 /* Initialize this SCSI Hosts' timers
2906 * To use, set the timer expires field
2909 init_timer(&hd->timer);
2910 hd->timer.data = (unsigned long) hd;
2911 hd->timer.function = mptscsih_timer_expired;
2913 ioc->sas_data.ptClear = mpt_pt_clear;
2915 if (ioc->sas_data.ptClear==1) {
2916 mptbase_sas_persist_operation(
2917 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
2920 init_waitqueue_head(&hd->scandv_waitq);
2921 hd->scandv_wait_done = 0;
2922 hd->last_queue_full = 0;
2924 error = scsi_add_host(sh, &ioc->pcidev->dev);
2926 dprintk((KERN_ERR MYNAM
2927 "scsi_add_host failed\n"));
2928 goto out_mptsas_probe;
2931 mptsas_scan_sas_topology(ioc);
2937 mptscsih_remove(pdev);
2941 static void __devexit mptsas_remove(struct pci_dev *pdev)
2943 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2944 struct mptsas_portinfo *p, *n;
2947 ioc->sas_discovery_ignore_events = 1;
2948 sas_remove_host(ioc->sh);
2950 mutex_lock(&ioc->sas_topology_mutex);
2951 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
2953 for (i = 0 ; i < p->num_phys ; i++)
2954 mptsas_port_delete(p->phy_info[i].port_details);
2958 mutex_unlock(&ioc->sas_topology_mutex);
2960 mptscsih_remove(pdev);
2963 static struct pci_device_id mptsas_pci_table[] = {
2964 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
2965 PCI_ANY_ID, PCI_ANY_ID },
2966 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
2967 PCI_ANY_ID, PCI_ANY_ID },
2968 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
2969 PCI_ANY_ID, PCI_ANY_ID },
2970 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
2971 PCI_ANY_ID, PCI_ANY_ID },
2972 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
2973 PCI_ANY_ID, PCI_ANY_ID },
2974 {0} /* Terminating entry */
2976 MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
2979 static struct pci_driver mptsas_driver = {
2981 .id_table = mptsas_pci_table,
2982 .probe = mptsas_probe,
2983 .remove = __devexit_p(mptsas_remove),
2984 .shutdown = mptscsih_shutdown,
2986 .suspend = mptscsih_suspend,
2987 .resume = mptscsih_resume,
2994 show_mptmod_ver(my_NAME, my_VERSION);
2996 mptsas_transport_template =
2997 sas_attach_transport(&mptsas_transport_functions);
2998 if (!mptsas_transport_template)
3001 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
3002 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER);
3004 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
3005 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
3007 if (mpt_event_register(mptsasDoneCtx, mptsas_event_process) == 0) {
3008 devtverboseprintk((KERN_INFO MYNAM
3009 ": Registered for IOC event notifications\n"));
3012 if (mpt_reset_register(mptsasDoneCtx, mptscsih_ioc_reset) == 0) {
3013 dprintk((KERN_INFO MYNAM
3014 ": Registered for IOC reset notifications\n"));
3017 return pci_register_driver(&mptsas_driver);
3023 pci_unregister_driver(&mptsas_driver);
3024 sas_release_transport(mptsas_transport_template);
3026 mpt_reset_deregister(mptsasDoneCtx);
3027 mpt_event_deregister(mptsasDoneCtx);
3029 mpt_deregister(mptsasMgmtCtx);
3030 mpt_deregister(mptsasInternalCtx);
3031 mpt_deregister(mptsasTaskCtx);
3032 mpt_deregister(mptsasDoneCtx);
3035 module_init(mptsas_init);
3036 module_exit(mptsas_exit);