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-2005 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com)
8 * Copyright (c) 2005-2006 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>
54 #include <scsi/scsi_cmnd.h>
55 #include <scsi/scsi_device.h>
56 #include <scsi/scsi_host.h>
57 #include <scsi/scsi_transport_sas.h>
63 #define my_NAME "Fusion MPT SAS Host driver"
64 #define my_VERSION MPT_LINUX_VERSION_COMMON
65 #define MYNAM "mptsas"
67 MODULE_AUTHOR(MODULEAUTHOR);
68 MODULE_DESCRIPTION(my_NAME);
69 MODULE_LICENSE("GPL");
71 static int mpt_pq_filter;
72 module_param(mpt_pq_filter, int, 0);
73 MODULE_PARM_DESC(mpt_pq_filter,
74 "Enable peripheral qualifier filter: enable=1 "
77 static int mpt_pt_clear;
78 module_param(mpt_pt_clear, int, 0);
79 MODULE_PARM_DESC(mpt_pt_clear,
80 "Clear persistency table: enable=1 "
81 "(default=MPTSCSIH_PT_CLEAR=0)");
83 static int mptsasDoneCtx = -1;
84 static int mptsasTaskCtx = -1;
85 static int mptsasInternalCtx = -1; /* Used only for internal commands */
86 static int mptsasMgmtCtx = -1;
89 enum mptsas_hotplug_action {
96 struct mptsas_hotplug_event {
97 struct work_struct work;
99 enum mptsas_hotplug_action event_type;
108 u8 phys_disk_num_valid;
111 struct mptsas_discovery_event {
112 struct work_struct work;
117 * SAS topology structures
119 * The MPT Fusion firmware interface spreads information about the
120 * SAS topology over many manufacture pages, thus we need some data
121 * structure to collect it and process it for the SAS transport class.
124 struct mptsas_devinfo {
125 u16 handle; /* unique id to address this device */
126 u16 handle_parent; /* unique id to address parent device */
127 u16 handle_enclosure; /* enclosure identifier of the enclosure */
128 u16 slot; /* physical slot in enclosure */
129 u8 phy_id; /* phy number of parent device */
130 u8 port_id; /* sas physical port this device
132 u8 id; /* logical target id of this device */
133 u8 channel; /* logical bus number of this device */
134 u64 sas_address; /* WWN of this device,
135 SATA is assigned by HBA,expander */
136 u32 device_info; /* bitfield detailed info about this device */
139 struct mptsas_phyinfo {
140 u8 phy_id; /* phy index */
141 u8 port_id; /* port number this phy is part of */
142 u8 negotiated_link_rate; /* nego'd link rate for this phy */
143 u8 hw_link_rate; /* hardware max/min phys link rate */
144 u8 programmed_link_rate; /* programmed max/min phy link rate */
145 struct mptsas_devinfo identify; /* point to phy device info */
146 struct mptsas_devinfo attached; /* point to attached device info */
148 struct sas_rphy *rphy;
149 struct scsi_target *starget;
152 struct mptsas_portinfo {
153 struct list_head list;
154 u16 handle; /* unique id to address this */
155 u8 num_phys; /* number of phys */
156 struct mptsas_phyinfo *phy_info;
159 struct mptsas_enclosure {
160 u64 enclosure_logical_id; /* The WWN for the enclosure */
161 u16 enclosure_handle; /* unique id to address this */
162 u16 flags; /* details enclosure management */
163 u16 num_slot; /* num slots */
164 u16 start_slot; /* first slot */
165 u8 start_id; /* starting logical target id */
166 u8 start_channel; /* starting logical channel id */
167 u8 sep_id; /* SEP device logical target id */
168 u8 sep_channel; /* SEP channel logical channel id */
172 static void mptsas_print_phy_data(MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
174 printk("---- IO UNIT PAGE 0 ------------\n");
175 printk("Handle=0x%X\n",
176 le16_to_cpu(phy_data->AttachedDeviceHandle));
177 printk("Controller Handle=0x%X\n",
178 le16_to_cpu(phy_data->ControllerDevHandle));
179 printk("Port=0x%X\n", phy_data->Port);
180 printk("Port Flags=0x%X\n", phy_data->PortFlags);
181 printk("PHY Flags=0x%X\n", phy_data->PhyFlags);
182 printk("Negotiated Link Rate=0x%X\n", phy_data->NegotiatedLinkRate);
183 printk("Controller PHY Device Info=0x%X\n",
184 le32_to_cpu(phy_data->ControllerPhyDeviceInfo));
185 printk("DiscoveryStatus=0x%X\n",
186 le32_to_cpu(phy_data->DiscoveryStatus));
190 static void mptsas_print_phy_pg0(SasPhyPage0_t *pg0)
194 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
196 printk("---- SAS PHY PAGE 0 ------------\n");
197 printk("Attached Device Handle=0x%X\n",
198 le16_to_cpu(pg0->AttachedDevHandle));
199 printk("SAS Address=0x%llX\n",
200 (unsigned long long)le64_to_cpu(sas_address));
201 printk("Attached PHY Identifier=0x%X\n", pg0->AttachedPhyIdentifier);
202 printk("Attached Device Info=0x%X\n",
203 le32_to_cpu(pg0->AttachedDeviceInfo));
204 printk("Programmed Link Rate=0x%X\n", pg0->ProgrammedLinkRate);
205 printk("Change Count=0x%X\n", pg0->ChangeCount);
206 printk("PHY Info=0x%X\n", le32_to_cpu(pg0->PhyInfo));
210 static void mptsas_print_phy_pg1(SasPhyPage1_t *pg1)
212 printk("---- SAS PHY PAGE 1 ------------\n");
213 printk("Invalid Dword Count=0x%x\n", pg1->InvalidDwordCount);
214 printk("Running Disparity Error Count=0x%x\n",
215 pg1->RunningDisparityErrorCount);
216 printk("Loss Dword Synch Count=0x%x\n", pg1->LossDwordSynchCount);
217 printk("PHY Reset Problem Count=0x%x\n", pg1->PhyResetProblemCount);
221 static void mptsas_print_device_pg0(SasDevicePage0_t *pg0)
225 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
227 printk("---- SAS DEVICE PAGE 0 ---------\n");
228 printk("Handle=0x%X\n" ,le16_to_cpu(pg0->DevHandle));
229 printk("Parent Handle=0x%X\n" ,le16_to_cpu(pg0->ParentDevHandle));
230 printk("Enclosure Handle=0x%X\n", le16_to_cpu(pg0->EnclosureHandle));
231 printk("Slot=0x%X\n", le16_to_cpu(pg0->Slot));
232 printk("SAS Address=0x%llX\n", le64_to_cpu(sas_address));
233 printk("Target ID=0x%X\n", pg0->TargetID);
234 printk("Bus=0x%X\n", pg0->Bus);
235 /* The PhyNum field specifies the PHY number of the parent
236 * device this device is linked to
238 printk("Parent Phy Num=0x%X\n", pg0->PhyNum);
239 printk("Access Status=0x%X\n", le16_to_cpu(pg0->AccessStatus));
240 printk("Device Info=0x%X\n", le32_to_cpu(pg0->DeviceInfo));
241 printk("Flags=0x%X\n", le16_to_cpu(pg0->Flags));
242 printk("Physical Port=0x%X\n", pg0->PhysicalPort);
246 static void mptsas_print_expander_pg1(SasExpanderPage1_t *pg1)
248 printk("---- SAS EXPANDER PAGE 1 ------------\n");
250 printk("Physical Port=0x%X\n", pg1->PhysicalPort);
251 printk("PHY Identifier=0x%X\n", pg1->PhyIdentifier);
252 printk("Negotiated Link Rate=0x%X\n", pg1->NegotiatedLinkRate);
253 printk("Programmed Link Rate=0x%X\n", pg1->ProgrammedLinkRate);
254 printk("Hardware Link Rate=0x%X\n", pg1->HwLinkRate);
255 printk("Owner Device Handle=0x%X\n",
256 le16_to_cpu(pg1->OwnerDevHandle));
257 printk("Attached Device Handle=0x%X\n",
258 le16_to_cpu(pg1->AttachedDevHandle));
261 #define mptsas_print_phy_data(phy_data) do { } while (0)
262 #define mptsas_print_phy_pg0(pg0) do { } while (0)
263 #define mptsas_print_phy_pg1(pg1) do { } while (0)
264 #define mptsas_print_device_pg0(pg0) do { } while (0)
265 #define mptsas_print_expander_pg1(pg1) do { } while (0)
268 static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
270 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
271 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
274 static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
276 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
277 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
281 * mptsas_find_portinfo_by_handle
283 * This function should be called with the sas_topology_mutex already held
285 static struct mptsas_portinfo *
286 mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
288 struct mptsas_portinfo *port_info, *rc=NULL;
291 list_for_each_entry(port_info, &ioc->sas_topology, list)
292 for (i = 0; i < port_info->num_phys; i++)
293 if (port_info->phy_info[i].identify.handle == handle) {
302 mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
303 u32 form, u32 form_specific)
305 ConfigExtendedPageHeader_t hdr;
307 SasEnclosurePage0_t *buffer;
308 dma_addr_t dma_handle;
310 __le64 le_identifier;
312 memset(&hdr, 0, sizeof(hdr));
313 hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
315 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
316 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
318 cfg.cfghdr.ehdr = &hdr;
320 cfg.pageAddr = form + form_specific;
321 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
322 cfg.dir = 0; /* read */
325 error = mpt_config(ioc, &cfg);
328 if (!hdr.ExtPageLength) {
333 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
340 cfg.physAddr = dma_handle;
341 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
343 error = mpt_config(ioc, &cfg);
345 goto out_free_consistent;
347 /* save config data */
348 memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
349 enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
350 enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
351 enclosure->flags = le16_to_cpu(buffer->Flags);
352 enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
353 enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
354 enclosure->start_id = buffer->StartTargetID;
355 enclosure->start_channel = buffer->StartBus;
356 enclosure->sep_id = buffer->SEPTargetID;
357 enclosure->sep_channel = buffer->SEPBus;
360 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
367 * This is pretty ugly. We will be able to seriously clean it up
368 * once the DV code in mptscsih goes away and we can properly
369 * implement ->target_alloc.
372 mptsas_slave_alloc(struct scsi_device *sdev)
374 struct Scsi_Host *host = sdev->host;
375 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
376 struct sas_rphy *rphy;
377 struct mptsas_portinfo *p;
380 struct scsi_target *starget;
384 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
386 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
387 hd->ioc->name, sizeof(VirtDevice));
390 sdev->hostdata = vdev;
391 starget = scsi_target(sdev);
392 vtarget = starget->hostdata;
393 vtarget->ioc_id = hd->ioc->id;
394 vdev->vtarget = vtarget;
395 if (vtarget->num_luns == 0) {
396 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES|MPT_TARGET_FLAGS_VALID_INQUIRY;
397 hd->Targets[sdev->id] = vtarget;
401 RAID volumes placed beyond the last expected port.
403 if (sdev->channel == hd->ioc->num_ports) {
404 target_id = sdev->id;
410 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
411 mutex_lock(&hd->ioc->sas_topology_mutex);
412 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
413 for (i = 0; i < p->num_phys; i++) {
414 if (p->phy_info[i].attached.sas_address ==
415 rphy->identify.sas_address) {
416 target_id = p->phy_info[i].attached.id;
417 vtarget->bus_id = p->phy_info[i].attached.channel;
418 vdev->lun = sdev->lun;
419 p->phy_info[i].starget = sdev->sdev_target;
421 * Exposing hidden disk (RAID)
423 if (mptscsih_is_phys_disk(hd->ioc, target_id)) {
424 target_id = mptscsih_raid_id_to_num(hd,
426 vdev->vtarget->tflags |=
427 MPT_TARGET_FLAGS_RAID_COMPONENT;
428 sdev->no_uld_attach = 1;
430 mutex_unlock(&hd->ioc->sas_topology_mutex);
435 mutex_unlock(&hd->ioc->sas_topology_mutex);
441 vtarget->target_id = target_id;
447 mptsas_slave_destroy(struct scsi_device *sdev)
449 struct Scsi_Host *host = sdev->host;
450 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
454 * Issue target reset to flush firmware outstanding commands.
456 vdev = sdev->hostdata;
457 if (vdev->configured_lun){
458 if (mptscsih_TMHandler(hd,
459 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
460 vdev->vtarget->bus_id,
461 vdev->vtarget->target_id,
462 0, 0, 5 /* 5 second timeout */)
465 /* The TM request failed!
468 printk(MYIOC_s_WARN_FMT
469 "Error processing TaskMgmt id=%d TARGET_RESET\n",
471 vdev->vtarget->target_id);
474 hd->tmState = TM_STATE_NONE;
477 mptscsih_slave_destroy(sdev);
480 static struct scsi_host_template mptsas_driver_template = {
481 .module = THIS_MODULE,
482 .proc_name = "mptsas",
483 .proc_info = mptscsih_proc_info,
484 .name = "MPT SPI Host",
485 .info = mptscsih_info,
486 .queuecommand = mptscsih_qcmd,
487 .target_alloc = mptscsih_target_alloc,
488 .slave_alloc = mptsas_slave_alloc,
489 .slave_configure = mptscsih_slave_configure,
490 .target_destroy = mptscsih_target_destroy,
491 .slave_destroy = mptsas_slave_destroy,
492 .change_queue_depth = mptscsih_change_queue_depth,
493 .eh_abort_handler = mptscsih_abort,
494 .eh_device_reset_handler = mptscsih_dev_reset,
495 .eh_bus_reset_handler = mptscsih_bus_reset,
496 .eh_host_reset_handler = mptscsih_host_reset,
497 .bios_param = mptscsih_bios_param,
498 .can_queue = MPT_FC_CAN_QUEUE,
500 .sg_tablesize = MPT_SCSI_SG_DEPTH,
503 .use_clustering = ENABLE_CLUSTERING,
506 static int mptsas_get_linkerrors(struct sas_phy *phy)
508 MPT_ADAPTER *ioc = phy_to_ioc(phy);
509 ConfigExtendedPageHeader_t hdr;
511 SasPhyPage1_t *buffer;
512 dma_addr_t dma_handle;
515 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
516 hdr.ExtPageLength = 0;
517 hdr.PageNumber = 1 /* page number 1*/;
520 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
521 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
523 cfg.cfghdr.ehdr = &hdr;
525 cfg.pageAddr = phy->identify.phy_identifier;
526 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
527 cfg.dir = 0; /* read */
530 error = mpt_config(ioc, &cfg);
533 if (!hdr.ExtPageLength)
536 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
541 cfg.physAddr = dma_handle;
542 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
544 error = mpt_config(ioc, &cfg);
546 goto out_free_consistent;
548 mptsas_print_phy_pg1(buffer);
550 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
551 phy->running_disparity_error_count =
552 le32_to_cpu(buffer->RunningDisparityErrorCount);
553 phy->loss_of_dword_sync_count =
554 le32_to_cpu(buffer->LossDwordSynchCount);
555 phy->phy_reset_problem_count =
556 le32_to_cpu(buffer->PhyResetProblemCount);
559 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
564 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
565 MPT_FRAME_HDR *reply)
567 ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_COMMAND_GOOD;
569 ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_RF_VALID;
570 memcpy(ioc->sas_mgmt.reply, reply,
571 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
573 complete(&ioc->sas_mgmt.done);
577 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
579 MPT_ADAPTER *ioc = phy_to_ioc(phy);
580 SasIoUnitControlRequest_t *req;
581 SasIoUnitControlReply_t *reply;
584 unsigned long timeleft;
585 int error = -ERESTARTSYS;
587 /* not implemented for expanders */
588 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
591 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
594 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
600 hdr = (MPIHeader_t *) mf;
601 req = (SasIoUnitControlRequest_t *)mf;
602 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
603 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
604 req->MsgContext = hdr->MsgContext;
605 req->Operation = hard_reset ?
606 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
607 req->PhyNum = phy->identify.phy_identifier;
609 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
611 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
614 /* On timeout reset the board */
615 mpt_free_msg_frame(ioc, mf);
616 mpt_HardResetHandler(ioc, CAN_SLEEP);
621 /* a reply frame is expected */
622 if ((ioc->sas_mgmt.status &
623 MPT_IOCTL_STATUS_RF_VALID) == 0) {
628 /* process the completed Reply Message Frame */
629 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
630 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
631 printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
642 mutex_unlock(&ioc->sas_mgmt.mutex);
648 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
650 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
652 struct mptsas_portinfo *p;
653 struct mptsas_enclosure enclosure_info;
654 u64 enclosure_handle;
656 mutex_lock(&ioc->sas_topology_mutex);
657 list_for_each_entry(p, &ioc->sas_topology, list) {
658 for (i = 0; i < p->num_phys; i++) {
659 if (p->phy_info[i].attached.sas_address ==
660 rphy->identify.sas_address) {
661 enclosure_handle = p->phy_info[i].
662 attached.handle_enclosure;
667 mutex_unlock(&ioc->sas_topology_mutex);
671 mutex_unlock(&ioc->sas_topology_mutex);
672 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
673 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
674 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
675 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
677 *identifier = enclosure_info.enclosure_logical_id;
682 mptsas_get_bay_identifier(struct sas_rphy *rphy)
684 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
685 struct mptsas_portinfo *p;
688 mutex_lock(&ioc->sas_topology_mutex);
689 list_for_each_entry(p, &ioc->sas_topology, list) {
690 for (i = 0; i < p->num_phys; i++) {
691 if (p->phy_info[i].attached.sas_address ==
692 rphy->identify.sas_address) {
693 rc = p->phy_info[i].attached.slot;
700 mutex_unlock(&ioc->sas_topology_mutex);
704 static struct sas_function_template mptsas_transport_functions = {
705 .get_linkerrors = mptsas_get_linkerrors,
706 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
707 .get_bay_identifier = mptsas_get_bay_identifier,
708 .phy_reset = mptsas_phy_reset,
711 static struct scsi_transport_template *mptsas_transport_template;
714 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
716 ConfigExtendedPageHeader_t hdr;
718 SasIOUnitPage0_t *buffer;
719 dma_addr_t dma_handle;
722 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
723 hdr.ExtPageLength = 0;
727 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
728 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
730 cfg.cfghdr.ehdr = &hdr;
733 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
734 cfg.dir = 0; /* read */
737 error = mpt_config(ioc, &cfg);
740 if (!hdr.ExtPageLength) {
745 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
752 cfg.physAddr = dma_handle;
753 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
755 error = mpt_config(ioc, &cfg);
757 goto out_free_consistent;
759 port_info->num_phys = buffer->NumPhys;
760 port_info->phy_info = kcalloc(port_info->num_phys,
761 sizeof(struct mptsas_phyinfo),GFP_KERNEL);
762 if (!port_info->phy_info) {
764 goto out_free_consistent;
767 if (port_info->num_phys)
769 le16_to_cpu(buffer->PhyData[0].ControllerDevHandle);
770 for (i = 0; i < port_info->num_phys; i++) {
771 mptsas_print_phy_data(&buffer->PhyData[i]);
772 port_info->phy_info[i].phy_id = i;
773 port_info->phy_info[i].port_id =
774 buffer->PhyData[i].Port;
775 port_info->phy_info[i].negotiated_link_rate =
776 buffer->PhyData[i].NegotiatedLinkRate;
780 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
787 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
788 u32 form, u32 form_specific)
790 ConfigExtendedPageHeader_t hdr;
792 SasPhyPage0_t *buffer;
793 dma_addr_t dma_handle;
796 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
797 hdr.ExtPageLength = 0;
801 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
802 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
804 cfg.cfghdr.ehdr = &hdr;
805 cfg.dir = 0; /* read */
808 /* Get Phy Pg 0 for each Phy. */
810 cfg.pageAddr = form + form_specific;
811 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
813 error = mpt_config(ioc, &cfg);
817 if (!hdr.ExtPageLength) {
822 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
829 cfg.physAddr = dma_handle;
830 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
832 error = mpt_config(ioc, &cfg);
834 goto out_free_consistent;
836 mptsas_print_phy_pg0(buffer);
838 phy_info->hw_link_rate = buffer->HwLinkRate;
839 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
840 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
841 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
844 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
851 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
852 u32 form, u32 form_specific)
854 ConfigExtendedPageHeader_t hdr;
856 SasDevicePage0_t *buffer;
857 dma_addr_t dma_handle;
861 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
862 hdr.ExtPageLength = 0;
866 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
867 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
869 cfg.cfghdr.ehdr = &hdr;
870 cfg.pageAddr = form + form_specific;
872 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
873 cfg.dir = 0; /* read */
876 memset(device_info, 0, sizeof(struct mptsas_devinfo));
877 error = mpt_config(ioc, &cfg);
880 if (!hdr.ExtPageLength) {
885 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
892 cfg.physAddr = dma_handle;
893 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
895 error = mpt_config(ioc, &cfg);
897 goto out_free_consistent;
899 mptsas_print_device_pg0(buffer);
901 device_info->handle = le16_to_cpu(buffer->DevHandle);
902 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
903 device_info->handle_enclosure =
904 le16_to_cpu(buffer->EnclosureHandle);
905 device_info->slot = le16_to_cpu(buffer->Slot);
906 device_info->phy_id = buffer->PhyNum;
907 device_info->port_id = buffer->PhysicalPort;
908 device_info->id = buffer->TargetID;
909 device_info->channel = buffer->Bus;
910 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
911 device_info->sas_address = le64_to_cpu(sas_address);
912 device_info->device_info =
913 le32_to_cpu(buffer->DeviceInfo);
916 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
923 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
924 u32 form, u32 form_specific)
926 ConfigExtendedPageHeader_t hdr;
928 SasExpanderPage0_t *buffer;
929 dma_addr_t dma_handle;
932 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
933 hdr.ExtPageLength = 0;
937 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
938 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
940 cfg.cfghdr.ehdr = &hdr;
942 cfg.pageAddr = form + form_specific;
943 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
944 cfg.dir = 0; /* read */
947 memset(port_info, 0, sizeof(struct mptsas_portinfo));
948 error = mpt_config(ioc, &cfg);
952 if (!hdr.ExtPageLength) {
957 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
964 cfg.physAddr = dma_handle;
965 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
967 error = mpt_config(ioc, &cfg);
969 goto out_free_consistent;
971 /* save config data */
972 port_info->num_phys = buffer->NumPhys;
973 port_info->handle = le16_to_cpu(buffer->DevHandle);
974 port_info->phy_info = kcalloc(port_info->num_phys,
975 sizeof(struct mptsas_phyinfo),GFP_KERNEL);
976 if (!port_info->phy_info) {
978 goto out_free_consistent;
982 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
989 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
990 u32 form, u32 form_specific)
992 ConfigExtendedPageHeader_t hdr;
994 SasExpanderPage1_t *buffer;
995 dma_addr_t dma_handle;
998 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
999 hdr.ExtPageLength = 0;
1003 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1004 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
1006 cfg.cfghdr.ehdr = &hdr;
1008 cfg.pageAddr = form + form_specific;
1009 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1010 cfg.dir = 0; /* read */
1013 error = mpt_config(ioc, &cfg);
1017 if (!hdr.ExtPageLength) {
1022 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1029 cfg.physAddr = dma_handle;
1030 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1032 error = mpt_config(ioc, &cfg);
1034 goto out_free_consistent;
1037 mptsas_print_expander_pg1(buffer);
1039 /* save config data */
1040 phy_info->phy_id = buffer->PhyIdentifier;
1041 phy_info->port_id = buffer->PhysicalPort;
1042 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
1043 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
1044 phy_info->hw_link_rate = buffer->HwLinkRate;
1045 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
1046 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
1048 out_free_consistent:
1049 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1050 buffer, dma_handle);
1056 * Returns true if there is a scsi end device
1059 mptsas_is_end_device(struct mptsas_devinfo * attached)
1061 if ((attached->handle) &&
1062 (attached->device_info &
1063 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
1064 ((attached->device_info &
1065 MPI_SAS_DEVICE_INFO_SSP_TARGET) |
1066 (attached->device_info &
1067 MPI_SAS_DEVICE_INFO_STP_TARGET) |
1068 (attached->device_info &
1069 MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
1076 mptsas_parse_device_info(struct sas_identify *identify,
1077 struct mptsas_devinfo *device_info)
1081 identify->sas_address = device_info->sas_address;
1082 identify->phy_identifier = device_info->phy_id;
1085 * Fill in Phy Initiator Port Protocol.
1086 * Bits 6:3, more than one bit can be set, fall through cases.
1088 protocols = device_info->device_info & 0x78;
1089 identify->initiator_port_protocols = 0;
1090 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
1091 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
1092 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1093 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
1094 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
1095 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
1096 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
1097 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
1100 * Fill in Phy Target Port Protocol.
1101 * Bits 10:7, more than one bit can be set, fall through cases.
1103 protocols = device_info->device_info & 0x780;
1104 identify->target_port_protocols = 0;
1105 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1106 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
1107 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
1108 identify->target_port_protocols |= SAS_PROTOCOL_STP;
1109 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
1110 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
1111 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1112 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
1115 * Fill in Attached device type.
1117 switch (device_info->device_info &
1118 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
1119 case MPI_SAS_DEVICE_INFO_NO_DEVICE:
1120 identify->device_type = SAS_PHY_UNUSED;
1122 case MPI_SAS_DEVICE_INFO_END_DEVICE:
1123 identify->device_type = SAS_END_DEVICE;
1125 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
1126 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
1128 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
1129 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
1134 static int mptsas_probe_one_phy(struct device *dev,
1135 struct mptsas_phyinfo *phy_info, int index, int local)
1138 struct sas_phy *phy;
1144 if (!phy_info->phy) {
1145 phy = sas_phy_alloc(dev, index);
1149 phy = phy_info->phy;
1151 phy->port_identifier = phy_info->port_id;
1152 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
1155 * Set Negotiated link rate.
1157 switch (phy_info->negotiated_link_rate) {
1158 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
1159 phy->negotiated_linkrate = SAS_PHY_DISABLED;
1161 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
1162 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
1164 case MPI_SAS_IOUNIT0_RATE_1_5:
1165 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
1167 case MPI_SAS_IOUNIT0_RATE_3_0:
1168 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
1170 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
1171 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
1173 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
1178 * Set Max hardware link rate.
1180 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
1181 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
1182 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
1184 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
1185 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
1192 * Set Max programmed link rate.
1194 switch (phy_info->programmed_link_rate &
1195 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
1196 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
1197 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
1199 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
1200 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
1207 * Set Min hardware link rate.
1209 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
1210 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
1211 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
1213 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
1214 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
1221 * Set Min programmed link rate.
1223 switch (phy_info->programmed_link_rate &
1224 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
1225 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
1226 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
1228 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
1229 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
1235 if (!phy_info->phy) {
1238 phy->local_attached = 1;
1240 error = sas_phy_add(phy);
1245 phy_info->phy = phy;
1248 if ((phy_info->attached.handle) &&
1249 (!phy_info->rphy)) {
1251 struct sas_rphy *rphy;
1253 ioc = phy_to_ioc(phy_info->phy);
1256 * Let the hotplug_work thread handle processing
1257 * the adding/removing of devices that occur
1258 * after start of day.
1260 if (ioc->sas_discovery_runtime &&
1261 mptsas_is_end_device(&phy_info->attached))
1264 rphy = sas_rphy_alloc(phy);
1266 return 0; /* non-fatal: an rphy can be added later */
1268 mptsas_parse_device_info(&rphy->identify, &phy_info->attached);
1269 error = sas_rphy_add(rphy);
1271 sas_rphy_free(rphy);
1275 phy_info->rphy = rphy;
1282 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1284 struct mptsas_portinfo *port_info, *hba;
1285 u32 handle = 0xFFFF;
1286 int error = -ENOMEM, i;
1288 hba = kzalloc(sizeof(*port_info), GFP_KERNEL);
1292 error = mptsas_sas_io_unit_pg0(ioc, hba);
1294 goto out_free_port_info;
1296 mutex_lock(&ioc->sas_topology_mutex);
1297 port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle);
1300 list_add_tail(&port_info->list, &ioc->sas_topology);
1302 port_info->handle = hba->handle;
1303 for (i = 0; i < hba->num_phys; i++)
1304 port_info->phy_info[i].negotiated_link_rate =
1305 hba->phy_info[i].negotiated_link_rate;
1307 kfree(hba->phy_info);
1311 mutex_unlock(&ioc->sas_topology_mutex);
1312 ioc->num_ports = port_info->num_phys;
1314 for (i = 0; i < port_info->num_phys; i++) {
1315 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
1316 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
1317 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
1319 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
1320 (MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE <<
1321 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), handle);
1322 port_info->phy_info[i].identify.phy_id =
1323 port_info->phy_info[i].phy_id;
1324 handle = port_info->phy_info[i].identify.handle;
1326 if (port_info->phy_info[i].attached.handle) {
1327 mptsas_sas_device_pg0(ioc,
1328 &port_info->phy_info[i].attached,
1329 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1330 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1331 port_info->phy_info[i].attached.handle);
1334 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
1335 &port_info->phy_info[i], ioc->sas_index, 1);
1349 mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1351 struct mptsas_portinfo *port_info, *p, *ex;
1352 int error = -ENOMEM, i, j;
1354 ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
1358 error = mptsas_sas_expander_pg0(ioc, ex,
1359 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
1360 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle);
1362 goto out_free_port_info;
1364 *handle = ex->handle;
1366 mutex_lock(&ioc->sas_topology_mutex);
1367 port_info = mptsas_find_portinfo_by_handle(ioc, *handle);
1370 list_add_tail(&port_info->list, &ioc->sas_topology);
1372 port_info->handle = ex->handle;
1374 kfree(ex->phy_info);
1378 mutex_unlock(&ioc->sas_topology_mutex);
1380 for (i = 0; i < port_info->num_phys; i++) {
1381 struct device *parent;
1383 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
1384 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
1385 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
1387 if (port_info->phy_info[i].identify.handle) {
1388 mptsas_sas_device_pg0(ioc,
1389 &port_info->phy_info[i].identify,
1390 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1391 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1392 port_info->phy_info[i].identify.handle);
1393 port_info->phy_info[i].identify.phy_id =
1394 port_info->phy_info[i].phy_id;
1397 if (port_info->phy_info[i].attached.handle) {
1398 mptsas_sas_device_pg0(ioc,
1399 &port_info->phy_info[i].attached,
1400 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1401 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1402 port_info->phy_info[i].attached.handle);
1403 port_info->phy_info[i].attached.phy_id =
1404 port_info->phy_info[i].phy_id;
1408 * If we find a parent port handle this expander is
1409 * attached to another expander, else it hangs of the
1412 parent = &ioc->sh->shost_gendev;
1413 mutex_lock(&ioc->sas_topology_mutex);
1414 list_for_each_entry(p, &ioc->sas_topology, list) {
1415 for (j = 0; j < p->num_phys; j++) {
1416 if (port_info->phy_info[i].identify.handle ==
1417 p->phy_info[j].attached.handle)
1418 parent = &p->phy_info[j].rphy->dev;
1421 mutex_unlock(&ioc->sas_topology_mutex);
1423 mptsas_probe_one_phy(parent, &port_info->phy_info[i],
1433 kfree(ex->phy_info);
1441 * mptsas_delete_expander_phys
1444 * This will traverse topology, and remove expanders
1445 * that are no longer present
1448 mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1450 struct mptsas_portinfo buffer;
1451 struct mptsas_portinfo *port_info, *n, *parent;
1454 mutex_lock(&ioc->sas_topology_mutex);
1455 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
1457 if (port_info->phy_info &&
1458 (!(port_info->phy_info[0].identify.device_info &
1459 MPI_SAS_DEVICE_INFO_SMP_TARGET)))
1462 if (mptsas_sas_expander_pg0(ioc, &buffer,
1463 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
1464 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) {
1467 * Obtain the port_info instance to the parent port
1469 parent = mptsas_find_portinfo_by_handle(ioc,
1470 port_info->phy_info[0].identify.handle_parent);
1476 * Delete rphys in the parent that point
1477 * to this expander. The transport layer will
1478 * cleanup all the children.
1480 for (i = 0; i < parent->num_phys; i++) {
1481 if ((!parent->phy_info[i].rphy) ||
1482 (parent->phy_info[i].attached.sas_address !=
1483 port_info->phy_info[i].identify.sas_address))
1485 sas_rphy_delete(parent->phy_info[i].rphy);
1486 memset(&parent->phy_info[i].attached, 0,
1487 sizeof(struct mptsas_devinfo));
1488 parent->phy_info[i].rphy = NULL;
1489 parent->phy_info[i].starget = NULL;
1492 list_del(&port_info->list);
1493 if (port_info->phy_info)
1494 kfree(port_info->phy_info);
1498 * Free this memory allocated from inside
1499 * mptsas_sas_expander_pg0
1501 if (buffer.phy_info)
1502 kfree(buffer.phy_info);
1504 mutex_unlock(&ioc->sas_topology_mutex);
1508 * Start of day discovery
1511 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
1513 u32 handle = 0xFFFF;
1516 mutex_lock(&ioc->sas_discovery_mutex);
1517 mptsas_probe_hba_phys(ioc);
1518 while (!mptsas_probe_expander_phys(ioc, &handle))
1521 Reporting RAID volumes.
1523 if (!ioc->raid_data.pIocPg2)
1525 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
1527 for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1528 scsi_add_device(ioc->sh, ioc->num_ports,
1529 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
1532 mutex_unlock(&ioc->sas_discovery_mutex);
1536 * Work queue thread to handle Runtime discovery
1537 * Mere purpose is the hot add/delete of expanders
1540 mptscsih_discovery_work(void * arg)
1542 struct mptsas_discovery_event *ev = arg;
1543 MPT_ADAPTER *ioc = ev->ioc;
1544 u32 handle = 0xFFFF;
1546 mutex_lock(&ioc->sas_discovery_mutex);
1547 ioc->sas_discovery_runtime=1;
1548 mptsas_delete_expander_phys(ioc);
1549 mptsas_probe_hba_phys(ioc);
1550 while (!mptsas_probe_expander_phys(ioc, &handle))
1553 ioc->sas_discovery_runtime=0;
1554 mutex_unlock(&ioc->sas_discovery_mutex);
1557 static struct mptsas_phyinfo *
1558 mptsas_find_phyinfo_by_parent(MPT_ADAPTER *ioc, u16 parent_handle, u8 phy_id)
1560 struct mptsas_portinfo *port_info;
1561 struct mptsas_devinfo device_info;
1562 struct mptsas_phyinfo *phy_info = NULL;
1566 * Retrieve the parent sas_address
1568 error = mptsas_sas_device_pg0(ioc, &device_info,
1569 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1570 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1576 * The phy_info structures are never deallocated during lifetime of
1577 * a host, so the code below is safe without additional refcounting.
1579 mutex_lock(&ioc->sas_topology_mutex);
1580 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1581 for (i = 0; i < port_info->num_phys; i++) {
1582 if (port_info->phy_info[i].identify.sas_address ==
1583 device_info.sas_address &&
1584 port_info->phy_info[i].phy_id == phy_id) {
1585 phy_info = &port_info->phy_info[i];
1590 mutex_unlock(&ioc->sas_topology_mutex);
1595 static struct mptsas_phyinfo *
1596 mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
1598 struct mptsas_portinfo *port_info;
1599 struct mptsas_phyinfo *phy_info = NULL;
1603 * The phy_info structures are never deallocated during lifetime of
1604 * a host, so the code below is safe without additional refcounting.
1606 mutex_lock(&ioc->sas_topology_mutex);
1607 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1608 for (i = 0; i < port_info->num_phys; i++)
1609 if (mptsas_is_end_device(&port_info->phy_info[i].attached))
1610 if (port_info->phy_info[i].attached.id == id) {
1611 phy_info = &port_info->phy_info[i];
1615 mutex_unlock(&ioc->sas_topology_mutex);
1621 * Work queue thread to clear the persitency table
1624 mptscsih_sas_persist_clear_table(void * arg)
1626 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
1628 mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT);
1632 mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
1634 sdev->no_uld_attach = data ? 1 : 0;
1635 scsi_device_reprobe(sdev);
1639 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
1641 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
1642 mptsas_reprobe_lun);
1647 * Work queue thread to handle SAS hotplug events
1650 mptsas_hotplug_work(void *arg)
1652 struct mptsas_hotplug_event *ev = arg;
1653 MPT_ADAPTER *ioc = ev->ioc;
1654 struct mptsas_phyinfo *phy_info;
1655 struct sas_rphy *rphy;
1656 struct scsi_device *sdev;
1658 struct mptsas_devinfo sas_device;
1659 VirtTarget *vtarget;
1661 mutex_lock(&ioc->sas_discovery_mutex);
1663 switch (ev->event_type) {
1664 case MPTSAS_DEL_DEVICE:
1666 phy_info = mptsas_find_phyinfo_by_target(ioc, ev->id);
1669 * Sanity checks, for non-existing phys and remote rphys.
1673 if (!phy_info->rphy)
1675 if (phy_info->starget) {
1676 vtarget = phy_info->starget->hostdata;
1681 * Handling RAID components
1683 if (ev->phys_disk_num_valid) {
1684 vtarget->target_id = ev->phys_disk_num;
1685 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
1686 mptsas_reprobe_target(vtarget->starget, 1);
1691 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1693 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_STP_TARGET)
1695 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1698 printk(MYIOC_s_INFO_FMT
1699 "removing %s device, channel %d, id %d, phy %d\n",
1700 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
1702 sas_rphy_delete(phy_info->rphy);
1703 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
1704 phy_info->rphy = NULL;
1705 phy_info->starget = NULL;
1707 case MPTSAS_ADD_DEVICE:
1710 * Refresh sas device pg0 data
1712 if (mptsas_sas_device_pg0(ioc, &sas_device,
1713 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
1714 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id))
1717 phy_info = mptsas_find_phyinfo_by_parent(ioc,
1718 sas_device.handle_parent, sas_device.phy_id);
1721 u32 handle = 0xFFFF;
1724 * Its possible when an expander has been hot added
1725 * containing attached devices, the sas firmware
1726 * may send a RC_ADDED event prior to the
1727 * DISCOVERY STOP event. If that occurs, our
1728 * view of the topology in the driver in respect to this
1729 * expander might of not been setup, and we hit this
1731 * Therefore, this code kicks off discovery to
1733 * Then again, we check whether the parent phy has
1736 ioc->sas_discovery_runtime=1;
1737 mptsas_delete_expander_phys(ioc);
1738 mptsas_probe_hba_phys(ioc);
1739 while (!mptsas_probe_expander_phys(ioc, &handle))
1741 ioc->sas_discovery_runtime=0;
1743 phy_info = mptsas_find_phyinfo_by_parent(ioc,
1744 sas_device.handle_parent, sas_device.phy_id);
1749 if (phy_info->starget) {
1750 vtarget = phy_info->starget->hostdata;
1755 * Handling RAID components
1757 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1758 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
1759 vtarget->target_id = ev->id;
1760 mptsas_reprobe_target(phy_info->starget, 0);
1768 memcpy(&phy_info->attached, &sas_device,
1769 sizeof(struct mptsas_devinfo));
1771 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1773 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_STP_TARGET)
1775 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1778 printk(MYIOC_s_INFO_FMT
1779 "attaching %s device, channel %d, id %d, phy %d\n",
1780 ioc->name, ds, ev->channel, ev->id, ev->phy_id);
1782 rphy = sas_rphy_alloc(phy_info->phy);
1784 break; /* non-fatal: an rphy can be added later */
1786 mptsas_parse_device_info(&rphy->identify, &phy_info->attached);
1787 if (sas_rphy_add(rphy)) {
1788 sas_rphy_free(rphy);
1792 phy_info->rphy = rphy;
1794 case MPTSAS_ADD_RAID:
1795 sdev = scsi_device_lookup(
1801 scsi_device_put(sdev);
1804 printk(MYIOC_s_INFO_FMT
1805 "attaching raid volume, channel %d, id %d\n",
1806 ioc->name, ioc->num_ports, ev->id);
1807 scsi_add_device(ioc->sh,
1811 mpt_findImVolumes(ioc);
1813 case MPTSAS_DEL_RAID:
1814 sdev = scsi_device_lookup(
1821 printk(MYIOC_s_INFO_FMT
1822 "removing raid volume, channel %d, id %d\n",
1823 ioc->name, ioc->num_ports, ev->id);
1824 scsi_remove_device(sdev);
1825 scsi_device_put(sdev);
1826 mpt_findImVolumes(ioc);
1831 mutex_unlock(&ioc->sas_discovery_mutex);
1835 mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1836 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1838 struct mptsas_hotplug_event *ev;
1839 u32 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
1843 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
1844 MPI_SAS_DEVICE_INFO_STP_TARGET |
1845 MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0)
1848 switch (sas_event_data->ReasonCode) {
1849 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
1850 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
1851 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
1853 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1857 INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
1859 ev->handle = le16_to_cpu(sas_event_data->DevHandle);
1861 le16_to_cpu(sas_event_data->ParentDevHandle);
1862 ev->channel = sas_event_data->Bus;
1863 ev->id = sas_event_data->TargetID;
1864 ev->phy_id = sas_event_data->PhyNum;
1865 memcpy(&sas_address, &sas_event_data->SASAddress,
1867 ev->sas_address = le64_to_cpu(sas_address);
1868 ev->device_info = device_info;
1870 if (sas_event_data->ReasonCode &
1871 MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
1872 ev->event_type = MPTSAS_ADD_DEVICE;
1874 ev->event_type = MPTSAS_DEL_DEVICE;
1875 schedule_work(&ev->work);
1877 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
1879 * Persistent table is full.
1881 INIT_WORK(&ioc->mptscsih_persistTask,
1882 mptscsih_sas_persist_clear_table,
1884 schedule_work(&ioc->mptscsih_persistTask);
1886 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
1888 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
1896 mptscsih_send_raid_event(MPT_ADAPTER *ioc,
1897 EVENT_DATA_RAID *raid_event_data)
1899 struct mptsas_hotplug_event *ev;
1900 RAID_VOL0_STATUS * volumeStatus;
1902 if (ioc->bus_type != SAS)
1905 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
1907 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1911 memset(ev,0,sizeof(struct mptsas_hotplug_event));
1912 INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
1914 ev->id = raid_event_data->VolumeID;
1916 switch (raid_event_data->ReasonCode) {
1917 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
1918 ev->event_type = MPTSAS_ADD_DEVICE;
1920 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
1921 ioc->raid_data.isRaid = 1;
1922 ev->phys_disk_num_valid = 1;
1923 ev->phys_disk_num = raid_event_data->PhysDiskNum;
1924 ev->event_type = MPTSAS_DEL_DEVICE;
1926 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
1927 ev->event_type = MPTSAS_DEL_RAID;
1929 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
1930 ev->event_type = MPTSAS_ADD_RAID;
1932 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
1933 volumeStatus = (RAID_VOL0_STATUS *) &
1934 raid_event_data->SettingsStatus;
1935 ev->event_type = (volumeStatus->State ==
1936 MPI_RAIDVOL0_STATUS_STATE_FAILED) ?
1937 MPTSAS_DEL_RAID : MPTSAS_ADD_RAID;
1942 schedule_work(&ev->work);
1946 mptscsih_send_discovery(MPT_ADAPTER *ioc,
1947 EVENT_DATA_SAS_DISCOVERY *discovery_data)
1949 struct mptsas_discovery_event *ev;
1954 * This flag will be non-zero when firmware
1955 * kicks off discovery, and return to zero
1956 * once its completed.
1958 if (discovery_data->DiscoveryStatus)
1961 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
1964 memset(ev,0,sizeof(struct mptsas_discovery_event));
1965 INIT_WORK(&ev->work, mptscsih_discovery_work, ev);
1967 schedule_work(&ev->work);
1972 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
1975 u8 event = le32_to_cpu(reply->Event) & 0xFF;
1981 * sas_discovery_ignore_events
1983 * This flag is to prevent anymore processing of
1984 * sas events once mptsas_remove function is called.
1986 if (ioc->sas_discovery_ignore_events) {
1987 rc = mptscsih_event_process(ioc, reply);
1992 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
1993 mptscsih_send_sas_event(ioc,
1994 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
1996 case MPI_EVENT_INTEGRATED_RAID:
1997 mptscsih_send_raid_event(ioc,
1998 (EVENT_DATA_RAID *)reply->Data);
2000 case MPI_EVENT_PERSISTENT_TABLE_FULL:
2001 INIT_WORK(&ioc->mptscsih_persistTask,
2002 mptscsih_sas_persist_clear_table,
2004 schedule_work(&ioc->mptscsih_persistTask);
2006 case MPI_EVENT_SAS_DISCOVERY:
2007 mptscsih_send_discovery(ioc,
2008 (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
2011 rc = mptscsih_event_process(ioc, reply);
2020 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2022 struct Scsi_Host *sh;
2025 unsigned long flags;
2033 r = mpt_attach(pdev,id);
2037 ioc = pci_get_drvdata(pdev);
2038 ioc->DoneCtx = mptsasDoneCtx;
2039 ioc->TaskCtx = mptsasTaskCtx;
2040 ioc->InternalCtx = mptsasInternalCtx;
2042 /* Added sanity check on readiness of the MPT adapter.
2044 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
2045 printk(MYIOC_s_WARN_FMT
2046 "Skipping because it's not operational!\n",
2049 goto out_mptsas_probe;
2053 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
2056 goto out_mptsas_probe;
2059 /* Sanity check - ensure at least 1 port is INITIATOR capable
2062 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
2063 if (ioc->pfacts[ii].ProtocolFlags &
2064 MPI_PORTFACTS_PROTOCOL_INITIATOR)
2069 printk(MYIOC_s_WARN_FMT
2070 "Skipping ioc=%p because SCSI Initiator mode "
2071 "is NOT enabled!\n", ioc->name, ioc);
2075 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
2077 printk(MYIOC_s_WARN_FMT
2078 "Unable to register controller with SCSI subsystem\n",
2081 goto out_mptsas_probe;
2084 spin_lock_irqsave(&ioc->FreeQlock, flags);
2086 /* Attach the SCSI Host to the IOC structure
2094 /* set 16 byte cdb's */
2095 sh->max_cmd_len = 16;
2097 sh->max_id = ioc->pfacts->MaxDevices + 1;
2099 sh->transportt = mptsas_transport_template;
2101 sh->max_lun = MPT_LAST_LUN + 1;
2102 sh->max_channel = 0;
2103 sh->this_id = ioc->pfacts[0].PortSCSIID;
2107 sh->unique_id = ioc->id;
2109 INIT_LIST_HEAD(&ioc->sas_topology);
2110 mutex_init(&ioc->sas_topology_mutex);
2111 mutex_init(&ioc->sas_discovery_mutex);
2112 mutex_init(&ioc->sas_mgmt.mutex);
2113 init_completion(&ioc->sas_mgmt.done);
2115 /* Verify that we won't exceed the maximum
2116 * number of chain buffers
2117 * We can optimize: ZZ = req_sz/sizeof(SGE)
2119 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
2120 * + (req_sz - 64)/sizeof(SGE)
2121 * A slightly different algorithm is required for
2124 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
2125 if (sizeof(dma_addr_t) == sizeof(u64)) {
2126 numSGE = (scale - 1) *
2127 (ioc->facts.MaxChainDepth-1) + scale +
2128 (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
2131 numSGE = 1 + (scale - 1) *
2132 (ioc->facts.MaxChainDepth-1) + scale +
2133 (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
2137 if (numSGE < sh->sg_tablesize) {
2138 /* Reset this value */
2139 dprintk((MYIOC_s_INFO_FMT
2140 "Resetting sg_tablesize to %d from %d\n",
2141 ioc->name, numSGE, sh->sg_tablesize));
2142 sh->sg_tablesize = numSGE;
2145 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
2147 hd = (MPT_SCSI_HOST *) sh->hostdata;
2150 /* SCSI needs scsi_cmnd lookup table!
2151 * (with size equal to req_depth*PtrSz!)
2153 hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
2154 if (!hd->ScsiLookup) {
2156 goto out_mptsas_probe;
2159 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
2160 ioc->name, hd->ScsiLookup));
2162 /* Allocate memory for the device structures.
2163 * A non-Null pointer at an offset
2164 * indicates a device exists.
2165 * max_id = 1 + maximum id (hosts.h)
2167 hd->Targets = kcalloc(sh->max_id, sizeof(void *), GFP_ATOMIC);
2170 goto out_mptsas_probe;
2173 dprintk((KERN_INFO " vtarget @ %p\n", hd->Targets));
2175 /* Clear the TM flags
2178 hd->tmState = TM_STATE_NONE;
2179 hd->resetPending = 0;
2180 hd->abortSCpnt = NULL;
2182 /* Clear the pointer used to store
2183 * single-threaded commands, i.e., those
2184 * issued during a bus scan, dv and
2185 * configuration pages.
2189 /* Initialize this SCSI Hosts' timers
2190 * To use, set the timer expires field
2193 init_timer(&hd->timer);
2194 hd->timer.data = (unsigned long) hd;
2195 hd->timer.function = mptscsih_timer_expired;
2197 hd->mpt_pq_filter = mpt_pq_filter;
2198 ioc->sas_data.ptClear = mpt_pt_clear;
2200 if (ioc->sas_data.ptClear==1) {
2201 mptbase_sas_persist_operation(
2202 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
2205 ddvprintk((MYIOC_s_INFO_FMT
2206 "mpt_pq_filter %x mpt_pq_filter %x\n",
2211 init_waitqueue_head(&hd->scandv_waitq);
2212 hd->scandv_wait_done = 0;
2213 hd->last_queue_full = 0;
2215 error = scsi_add_host(sh, &ioc->pcidev->dev);
2217 dprintk((KERN_ERR MYNAM
2218 "scsi_add_host failed\n"));
2219 goto out_mptsas_probe;
2222 mptsas_scan_sas_topology(ioc);
2228 mptscsih_remove(pdev);
2232 static void __devexit mptsas_remove(struct pci_dev *pdev)
2234 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2235 struct mptsas_portinfo *p, *n;
2237 ioc->sas_discovery_ignore_events=1;
2238 sas_remove_host(ioc->sh);
2240 mutex_lock(&ioc->sas_topology_mutex);
2241 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
2247 mutex_unlock(&ioc->sas_topology_mutex);
2249 mptscsih_remove(pdev);
2252 static struct pci_device_id mptsas_pci_table[] = {
2253 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064,
2254 PCI_ANY_ID, PCI_ANY_ID },
2255 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066,
2256 PCI_ANY_ID, PCI_ANY_ID },
2257 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068,
2258 PCI_ANY_ID, PCI_ANY_ID },
2259 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064E,
2260 PCI_ANY_ID, PCI_ANY_ID },
2261 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066E,
2262 PCI_ANY_ID, PCI_ANY_ID },
2263 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068E,
2264 PCI_ANY_ID, PCI_ANY_ID },
2265 {0} /* Terminating entry */
2267 MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
2270 static struct pci_driver mptsas_driver = {
2272 .id_table = mptsas_pci_table,
2273 .probe = mptsas_probe,
2274 .remove = __devexit_p(mptsas_remove),
2275 .shutdown = mptscsih_shutdown,
2277 .suspend = mptscsih_suspend,
2278 .resume = mptscsih_resume,
2285 show_mptmod_ver(my_NAME, my_VERSION);
2287 mptsas_transport_template =
2288 sas_attach_transport(&mptsas_transport_functions);
2289 if (!mptsas_transport_template)
2292 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
2293 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER);
2295 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
2296 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
2298 if (mpt_event_register(mptsasDoneCtx, mptsas_event_process) == 0) {
2299 devtverboseprintk((KERN_INFO MYNAM
2300 ": Registered for IOC event notifications\n"));
2303 if (mpt_reset_register(mptsasDoneCtx, mptscsih_ioc_reset) == 0) {
2304 dprintk((KERN_INFO MYNAM
2305 ": Registered for IOC reset notifications\n"));
2308 return pci_register_driver(&mptsas_driver);
2314 pci_unregister_driver(&mptsas_driver);
2315 sas_release_transport(mptsas_transport_template);
2317 mpt_reset_deregister(mptsasDoneCtx);
2318 mpt_event_deregister(mptsasDoneCtx);
2320 mpt_deregister(mptsasMgmtCtx);
2321 mpt_deregister(mptsasInternalCtx);
2322 mpt_deregister(mptsasTaskCtx);
2323 mpt_deregister(mptsasDoneCtx);
2326 module_init(mptsas_init);
2327 module_exit(mptsas_exit);