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 mptsas_slave_configure(struct scsi_device *sdev)
369 sas_read_port_mode_page(sdev);
371 return mptscsih_slave_configure(sdev);
375 * This is pretty ugly. We will be able to seriously clean it up
376 * once the DV code in mptscsih goes away and we can properly
377 * implement ->target_alloc.
380 mptsas_slave_alloc(struct scsi_device *sdev)
382 struct Scsi_Host *host = sdev->host;
383 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
384 struct sas_rphy *rphy;
385 struct mptsas_portinfo *p;
388 struct scsi_target *starget;
392 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
394 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
395 hd->ioc->name, sizeof(VirtDevice));
398 sdev->hostdata = vdev;
399 starget = scsi_target(sdev);
400 vtarget = starget->hostdata;
401 vtarget->ioc_id = hd->ioc->id;
402 vdev->vtarget = vtarget;
403 if (vtarget->num_luns == 0) {
404 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES|MPT_TARGET_FLAGS_VALID_INQUIRY;
405 hd->Targets[sdev->id] = vtarget;
409 RAID volumes placed beyond the last expected port.
411 if (sdev->channel == hd->ioc->num_ports) {
412 target_id = sdev->id;
418 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
419 mutex_lock(&hd->ioc->sas_topology_mutex);
420 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
421 for (i = 0; i < p->num_phys; i++) {
422 if (p->phy_info[i].attached.sas_address ==
423 rphy->identify.sas_address) {
424 target_id = p->phy_info[i].attached.id;
425 vtarget->bus_id = p->phy_info[i].attached.channel;
426 vdev->lun = sdev->lun;
427 p->phy_info[i].starget = sdev->sdev_target;
429 * Exposing hidden disk (RAID)
431 if (mptscsih_is_phys_disk(hd->ioc, target_id)) {
432 target_id = mptscsih_raid_id_to_num(hd,
434 vdev->vtarget->tflags |=
435 MPT_TARGET_FLAGS_RAID_COMPONENT;
436 sdev->no_uld_attach = 1;
438 mutex_unlock(&hd->ioc->sas_topology_mutex);
443 mutex_unlock(&hd->ioc->sas_topology_mutex);
449 vtarget->target_id = target_id;
455 mptsas_slave_destroy(struct scsi_device *sdev)
457 struct Scsi_Host *host = sdev->host;
458 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
462 * Issue target reset to flush firmware outstanding commands.
464 vdev = sdev->hostdata;
465 if (vdev->configured_lun){
466 if (mptscsih_TMHandler(hd,
467 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
468 vdev->vtarget->bus_id,
469 vdev->vtarget->target_id,
470 0, 0, 5 /* 5 second timeout */)
473 /* The TM request failed!
476 printk(MYIOC_s_WARN_FMT
477 "Error processing TaskMgmt id=%d TARGET_RESET\n",
479 vdev->vtarget->target_id);
482 hd->tmState = TM_STATE_NONE;
485 mptscsih_slave_destroy(sdev);
488 static struct scsi_host_template mptsas_driver_template = {
489 .module = THIS_MODULE,
490 .proc_name = "mptsas",
491 .proc_info = mptscsih_proc_info,
492 .name = "MPT SPI Host",
493 .info = mptscsih_info,
494 .queuecommand = mptscsih_qcmd,
495 .target_alloc = mptscsih_target_alloc,
496 .slave_alloc = mptsas_slave_alloc,
497 .slave_configure = mptsas_slave_configure,
498 .target_destroy = mptscsih_target_destroy,
499 .slave_destroy = mptsas_slave_destroy,
500 .change_queue_depth = mptscsih_change_queue_depth,
501 .eh_abort_handler = mptscsih_abort,
502 .eh_device_reset_handler = mptscsih_dev_reset,
503 .eh_bus_reset_handler = mptscsih_bus_reset,
504 .eh_host_reset_handler = mptscsih_host_reset,
505 .bios_param = mptscsih_bios_param,
506 .can_queue = MPT_FC_CAN_QUEUE,
508 .sg_tablesize = MPT_SCSI_SG_DEPTH,
511 .use_clustering = ENABLE_CLUSTERING,
514 static int mptsas_get_linkerrors(struct sas_phy *phy)
516 MPT_ADAPTER *ioc = phy_to_ioc(phy);
517 ConfigExtendedPageHeader_t hdr;
519 SasPhyPage1_t *buffer;
520 dma_addr_t dma_handle;
523 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
524 hdr.ExtPageLength = 0;
525 hdr.PageNumber = 1 /* page number 1*/;
528 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
529 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
531 cfg.cfghdr.ehdr = &hdr;
533 cfg.pageAddr = phy->identify.phy_identifier;
534 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
535 cfg.dir = 0; /* read */
538 error = mpt_config(ioc, &cfg);
541 if (!hdr.ExtPageLength)
544 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
549 cfg.physAddr = dma_handle;
550 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
552 error = mpt_config(ioc, &cfg);
554 goto out_free_consistent;
556 mptsas_print_phy_pg1(buffer);
558 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
559 phy->running_disparity_error_count =
560 le32_to_cpu(buffer->RunningDisparityErrorCount);
561 phy->loss_of_dword_sync_count =
562 le32_to_cpu(buffer->LossDwordSynchCount);
563 phy->phy_reset_problem_count =
564 le32_to_cpu(buffer->PhyResetProblemCount);
567 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
572 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
573 MPT_FRAME_HDR *reply)
575 ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_COMMAND_GOOD;
577 ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_RF_VALID;
578 memcpy(ioc->sas_mgmt.reply, reply,
579 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
581 complete(&ioc->sas_mgmt.done);
585 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
587 MPT_ADAPTER *ioc = phy_to_ioc(phy);
588 SasIoUnitControlRequest_t *req;
589 SasIoUnitControlReply_t *reply;
592 unsigned long timeleft;
593 int error = -ERESTARTSYS;
595 /* not implemented for expanders */
596 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
599 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
602 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
608 hdr = (MPIHeader_t *) mf;
609 req = (SasIoUnitControlRequest_t *)mf;
610 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
611 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
612 req->MsgContext = hdr->MsgContext;
613 req->Operation = hard_reset ?
614 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
615 req->PhyNum = phy->identify.phy_identifier;
617 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
619 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
622 /* On timeout reset the board */
623 mpt_free_msg_frame(ioc, mf);
624 mpt_HardResetHandler(ioc, CAN_SLEEP);
629 /* a reply frame is expected */
630 if ((ioc->sas_mgmt.status &
631 MPT_IOCTL_STATUS_RF_VALID) == 0) {
636 /* process the completed Reply Message Frame */
637 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
638 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
639 printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
650 mutex_unlock(&ioc->sas_mgmt.mutex);
656 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
658 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
660 struct mptsas_portinfo *p;
661 struct mptsas_enclosure enclosure_info;
662 u64 enclosure_handle;
664 mutex_lock(&ioc->sas_topology_mutex);
665 list_for_each_entry(p, &ioc->sas_topology, list) {
666 for (i = 0; i < p->num_phys; i++) {
667 if (p->phy_info[i].attached.sas_address ==
668 rphy->identify.sas_address) {
669 enclosure_handle = p->phy_info[i].
670 attached.handle_enclosure;
675 mutex_unlock(&ioc->sas_topology_mutex);
679 mutex_unlock(&ioc->sas_topology_mutex);
680 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
681 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
682 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
683 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
685 *identifier = enclosure_info.enclosure_logical_id;
690 mptsas_get_bay_identifier(struct sas_rphy *rphy)
692 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
693 struct mptsas_portinfo *p;
696 mutex_lock(&ioc->sas_topology_mutex);
697 list_for_each_entry(p, &ioc->sas_topology, list) {
698 for (i = 0; i < p->num_phys; i++) {
699 if (p->phy_info[i].attached.sas_address ==
700 rphy->identify.sas_address) {
701 rc = p->phy_info[i].attached.slot;
708 mutex_unlock(&ioc->sas_topology_mutex);
712 static struct sas_function_template mptsas_transport_functions = {
713 .get_linkerrors = mptsas_get_linkerrors,
714 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
715 .get_bay_identifier = mptsas_get_bay_identifier,
716 .phy_reset = mptsas_phy_reset,
719 static struct scsi_transport_template *mptsas_transport_template;
722 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
724 ConfigExtendedPageHeader_t hdr;
726 SasIOUnitPage0_t *buffer;
727 dma_addr_t dma_handle;
730 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
731 hdr.ExtPageLength = 0;
735 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
736 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
738 cfg.cfghdr.ehdr = &hdr;
741 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
742 cfg.dir = 0; /* read */
745 error = mpt_config(ioc, &cfg);
748 if (!hdr.ExtPageLength) {
753 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
760 cfg.physAddr = dma_handle;
761 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
763 error = mpt_config(ioc, &cfg);
765 goto out_free_consistent;
767 port_info->num_phys = buffer->NumPhys;
768 port_info->phy_info = kcalloc(port_info->num_phys,
769 sizeof(struct mptsas_phyinfo),GFP_KERNEL);
770 if (!port_info->phy_info) {
772 goto out_free_consistent;
775 if (port_info->num_phys)
777 le16_to_cpu(buffer->PhyData[0].ControllerDevHandle);
778 for (i = 0; i < port_info->num_phys; i++) {
779 mptsas_print_phy_data(&buffer->PhyData[i]);
780 port_info->phy_info[i].phy_id = i;
781 port_info->phy_info[i].port_id =
782 buffer->PhyData[i].Port;
783 port_info->phy_info[i].negotiated_link_rate =
784 buffer->PhyData[i].NegotiatedLinkRate;
788 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
795 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
796 u32 form, u32 form_specific)
798 ConfigExtendedPageHeader_t hdr;
800 SasPhyPage0_t *buffer;
801 dma_addr_t dma_handle;
804 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
805 hdr.ExtPageLength = 0;
809 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
810 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
812 cfg.cfghdr.ehdr = &hdr;
813 cfg.dir = 0; /* read */
816 /* Get Phy Pg 0 for each Phy. */
818 cfg.pageAddr = form + form_specific;
819 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
821 error = mpt_config(ioc, &cfg);
825 if (!hdr.ExtPageLength) {
830 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
837 cfg.physAddr = dma_handle;
838 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
840 error = mpt_config(ioc, &cfg);
842 goto out_free_consistent;
844 mptsas_print_phy_pg0(buffer);
846 phy_info->hw_link_rate = buffer->HwLinkRate;
847 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
848 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
849 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
852 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
859 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
860 u32 form, u32 form_specific)
862 ConfigExtendedPageHeader_t hdr;
864 SasDevicePage0_t *buffer;
865 dma_addr_t dma_handle;
869 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
870 hdr.ExtPageLength = 0;
874 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
875 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
877 cfg.cfghdr.ehdr = &hdr;
878 cfg.pageAddr = form + form_specific;
880 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
881 cfg.dir = 0; /* read */
884 memset(device_info, 0, sizeof(struct mptsas_devinfo));
885 error = mpt_config(ioc, &cfg);
888 if (!hdr.ExtPageLength) {
893 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
900 cfg.physAddr = dma_handle;
901 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
903 error = mpt_config(ioc, &cfg);
905 goto out_free_consistent;
907 mptsas_print_device_pg0(buffer);
909 device_info->handle = le16_to_cpu(buffer->DevHandle);
910 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
911 device_info->handle_enclosure =
912 le16_to_cpu(buffer->EnclosureHandle);
913 device_info->slot = le16_to_cpu(buffer->Slot);
914 device_info->phy_id = buffer->PhyNum;
915 device_info->port_id = buffer->PhysicalPort;
916 device_info->id = buffer->TargetID;
917 device_info->channel = buffer->Bus;
918 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
919 device_info->sas_address = le64_to_cpu(sas_address);
920 device_info->device_info =
921 le32_to_cpu(buffer->DeviceInfo);
924 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
931 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
932 u32 form, u32 form_specific)
934 ConfigExtendedPageHeader_t hdr;
936 SasExpanderPage0_t *buffer;
937 dma_addr_t dma_handle;
940 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
941 hdr.ExtPageLength = 0;
945 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
946 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
948 cfg.cfghdr.ehdr = &hdr;
950 cfg.pageAddr = form + form_specific;
951 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
952 cfg.dir = 0; /* read */
955 memset(port_info, 0, sizeof(struct mptsas_portinfo));
956 error = mpt_config(ioc, &cfg);
960 if (!hdr.ExtPageLength) {
965 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
972 cfg.physAddr = dma_handle;
973 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
975 error = mpt_config(ioc, &cfg);
977 goto out_free_consistent;
979 /* save config data */
980 port_info->num_phys = buffer->NumPhys;
981 port_info->handle = le16_to_cpu(buffer->DevHandle);
982 port_info->phy_info = kcalloc(port_info->num_phys,
983 sizeof(struct mptsas_phyinfo),GFP_KERNEL);
984 if (!port_info->phy_info) {
986 goto out_free_consistent;
990 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
997 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
998 u32 form, u32 form_specific)
1000 ConfigExtendedPageHeader_t hdr;
1002 SasExpanderPage1_t *buffer;
1003 dma_addr_t dma_handle;
1006 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
1007 hdr.ExtPageLength = 0;
1011 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1012 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
1014 cfg.cfghdr.ehdr = &hdr;
1016 cfg.pageAddr = form + form_specific;
1017 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1018 cfg.dir = 0; /* read */
1021 error = mpt_config(ioc, &cfg);
1025 if (!hdr.ExtPageLength) {
1030 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1037 cfg.physAddr = dma_handle;
1038 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1040 error = mpt_config(ioc, &cfg);
1042 goto out_free_consistent;
1045 mptsas_print_expander_pg1(buffer);
1047 /* save config data */
1048 phy_info->phy_id = buffer->PhyIdentifier;
1049 phy_info->port_id = buffer->PhysicalPort;
1050 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
1051 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
1052 phy_info->hw_link_rate = buffer->HwLinkRate;
1053 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
1054 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
1056 out_free_consistent:
1057 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1058 buffer, dma_handle);
1064 * Returns true if there is a scsi end device
1067 mptsas_is_end_device(struct mptsas_devinfo * attached)
1069 if ((attached->handle) &&
1070 (attached->device_info &
1071 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
1072 ((attached->device_info &
1073 MPI_SAS_DEVICE_INFO_SSP_TARGET) |
1074 (attached->device_info &
1075 MPI_SAS_DEVICE_INFO_STP_TARGET) |
1076 (attached->device_info &
1077 MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
1084 mptsas_parse_device_info(struct sas_identify *identify,
1085 struct mptsas_devinfo *device_info)
1089 identify->sas_address = device_info->sas_address;
1090 identify->phy_identifier = device_info->phy_id;
1093 * Fill in Phy Initiator Port Protocol.
1094 * Bits 6:3, more than one bit can be set, fall through cases.
1096 protocols = device_info->device_info & 0x78;
1097 identify->initiator_port_protocols = 0;
1098 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
1099 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
1100 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1101 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
1102 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
1103 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
1104 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
1105 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
1108 * Fill in Phy Target Port Protocol.
1109 * Bits 10:7, more than one bit can be set, fall through cases.
1111 protocols = device_info->device_info & 0x780;
1112 identify->target_port_protocols = 0;
1113 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1114 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
1115 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
1116 identify->target_port_protocols |= SAS_PROTOCOL_STP;
1117 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
1118 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
1119 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1120 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
1123 * Fill in Attached device type.
1125 switch (device_info->device_info &
1126 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
1127 case MPI_SAS_DEVICE_INFO_NO_DEVICE:
1128 identify->device_type = SAS_PHY_UNUSED;
1130 case MPI_SAS_DEVICE_INFO_END_DEVICE:
1131 identify->device_type = SAS_END_DEVICE;
1133 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
1134 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
1136 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
1137 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
1142 static int mptsas_probe_one_phy(struct device *dev,
1143 struct mptsas_phyinfo *phy_info, int index, int local)
1146 struct sas_phy *phy;
1152 if (!phy_info->phy) {
1153 phy = sas_phy_alloc(dev, index);
1157 phy = phy_info->phy;
1159 phy->port_identifier = phy_info->port_id;
1160 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
1163 * Set Negotiated link rate.
1165 switch (phy_info->negotiated_link_rate) {
1166 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
1167 phy->negotiated_linkrate = SAS_PHY_DISABLED;
1169 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
1170 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
1172 case MPI_SAS_IOUNIT0_RATE_1_5:
1173 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
1175 case MPI_SAS_IOUNIT0_RATE_3_0:
1176 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
1178 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
1179 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
1181 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
1186 * Set Max hardware link rate.
1188 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
1189 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
1190 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
1192 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
1193 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
1200 * Set Max programmed link rate.
1202 switch (phy_info->programmed_link_rate &
1203 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
1204 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
1205 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
1207 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
1208 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
1215 * Set Min hardware link rate.
1217 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
1218 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
1219 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
1221 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
1222 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
1229 * Set Min programmed link rate.
1231 switch (phy_info->programmed_link_rate &
1232 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
1233 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
1234 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
1236 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
1237 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
1243 if (!phy_info->phy) {
1246 phy->local_attached = 1;
1248 error = sas_phy_add(phy);
1253 phy_info->phy = phy;
1256 if ((phy_info->attached.handle) &&
1257 (!phy_info->rphy)) {
1259 struct sas_rphy *rphy;
1260 struct sas_identify identify;
1262 ioc = phy_to_ioc(phy_info->phy);
1265 * Let the hotplug_work thread handle processing
1266 * the adding/removing of devices that occur
1267 * after start of day.
1269 if (ioc->sas_discovery_runtime &&
1270 mptsas_is_end_device(&phy_info->attached))
1273 mptsas_parse_device_info(&identify, &phy_info->attached);
1274 switch (identify.device_type) {
1275 case SAS_END_DEVICE:
1276 rphy = sas_end_device_alloc(phy);
1278 case SAS_EDGE_EXPANDER_DEVICE:
1279 case SAS_FANOUT_EXPANDER_DEVICE:
1280 rphy = sas_expander_alloc(phy, identify.device_type);
1287 return 0; /* non-fatal: an rphy can be added later */
1289 rphy->identify = identify;
1291 error = sas_rphy_add(rphy);
1293 sas_rphy_free(rphy);
1297 phy_info->rphy = rphy;
1304 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1306 struct mptsas_portinfo *port_info, *hba;
1307 u32 handle = 0xFFFF;
1308 int error = -ENOMEM, i;
1310 hba = kzalloc(sizeof(*port_info), GFP_KERNEL);
1314 error = mptsas_sas_io_unit_pg0(ioc, hba);
1316 goto out_free_port_info;
1318 mutex_lock(&ioc->sas_topology_mutex);
1319 port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle);
1322 list_add_tail(&port_info->list, &ioc->sas_topology);
1324 port_info->handle = hba->handle;
1325 for (i = 0; i < hba->num_phys; i++)
1326 port_info->phy_info[i].negotiated_link_rate =
1327 hba->phy_info[i].negotiated_link_rate;
1329 kfree(hba->phy_info);
1333 mutex_unlock(&ioc->sas_topology_mutex);
1334 ioc->num_ports = port_info->num_phys;
1336 for (i = 0; i < port_info->num_phys; i++) {
1337 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
1338 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
1339 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
1341 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
1342 (MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE <<
1343 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), handle);
1344 port_info->phy_info[i].identify.phy_id =
1345 port_info->phy_info[i].phy_id;
1346 handle = port_info->phy_info[i].identify.handle;
1348 if (port_info->phy_info[i].attached.handle) {
1349 mptsas_sas_device_pg0(ioc,
1350 &port_info->phy_info[i].attached,
1351 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1352 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1353 port_info->phy_info[i].attached.handle);
1356 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
1357 &port_info->phy_info[i], ioc->sas_index, 1);
1371 mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1373 struct mptsas_portinfo *port_info, *p, *ex;
1374 int error = -ENOMEM, i, j;
1376 ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
1380 error = mptsas_sas_expander_pg0(ioc, ex,
1381 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
1382 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle);
1384 goto out_free_port_info;
1386 *handle = ex->handle;
1388 mutex_lock(&ioc->sas_topology_mutex);
1389 port_info = mptsas_find_portinfo_by_handle(ioc, *handle);
1392 list_add_tail(&port_info->list, &ioc->sas_topology);
1394 port_info->handle = ex->handle;
1396 kfree(ex->phy_info);
1400 mutex_unlock(&ioc->sas_topology_mutex);
1402 for (i = 0; i < port_info->num_phys; i++) {
1403 struct device *parent;
1405 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
1406 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
1407 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
1409 if (port_info->phy_info[i].identify.handle) {
1410 mptsas_sas_device_pg0(ioc,
1411 &port_info->phy_info[i].identify,
1412 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1413 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1414 port_info->phy_info[i].identify.handle);
1415 port_info->phy_info[i].identify.phy_id =
1416 port_info->phy_info[i].phy_id;
1419 if (port_info->phy_info[i].attached.handle) {
1420 mptsas_sas_device_pg0(ioc,
1421 &port_info->phy_info[i].attached,
1422 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1423 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1424 port_info->phy_info[i].attached.handle);
1425 port_info->phy_info[i].attached.phy_id =
1426 port_info->phy_info[i].phy_id;
1430 * If we find a parent port handle this expander is
1431 * attached to another expander, else it hangs of the
1434 parent = &ioc->sh->shost_gendev;
1435 mutex_lock(&ioc->sas_topology_mutex);
1436 list_for_each_entry(p, &ioc->sas_topology, list) {
1437 for (j = 0; j < p->num_phys; j++) {
1438 if (port_info->phy_info[i].identify.handle ==
1439 p->phy_info[j].attached.handle)
1440 parent = &p->phy_info[j].rphy->dev;
1443 mutex_unlock(&ioc->sas_topology_mutex);
1445 mptsas_probe_one_phy(parent, &port_info->phy_info[i],
1455 kfree(ex->phy_info);
1463 * mptsas_delete_expander_phys
1466 * This will traverse topology, and remove expanders
1467 * that are no longer present
1470 mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1472 struct mptsas_portinfo buffer;
1473 struct mptsas_portinfo *port_info, *n, *parent;
1476 mutex_lock(&ioc->sas_topology_mutex);
1477 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
1479 if (port_info->phy_info &&
1480 (!(port_info->phy_info[0].identify.device_info &
1481 MPI_SAS_DEVICE_INFO_SMP_TARGET)))
1484 if (mptsas_sas_expander_pg0(ioc, &buffer,
1485 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
1486 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) {
1489 * Obtain the port_info instance to the parent port
1491 parent = mptsas_find_portinfo_by_handle(ioc,
1492 port_info->phy_info[0].identify.handle_parent);
1498 * Delete rphys in the parent that point
1499 * to this expander. The transport layer will
1500 * cleanup all the children.
1502 for (i = 0; i < parent->num_phys; i++) {
1503 if ((!parent->phy_info[i].rphy) ||
1504 (parent->phy_info[i].attached.sas_address !=
1505 port_info->phy_info[i].identify.sas_address))
1507 sas_rphy_delete(parent->phy_info[i].rphy);
1508 memset(&parent->phy_info[i].attached, 0,
1509 sizeof(struct mptsas_devinfo));
1510 parent->phy_info[i].rphy = NULL;
1511 parent->phy_info[i].starget = NULL;
1514 list_del(&port_info->list);
1515 if (port_info->phy_info)
1516 kfree(port_info->phy_info);
1520 * Free this memory allocated from inside
1521 * mptsas_sas_expander_pg0
1523 if (buffer.phy_info)
1524 kfree(buffer.phy_info);
1526 mutex_unlock(&ioc->sas_topology_mutex);
1530 * Start of day discovery
1533 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
1535 u32 handle = 0xFFFF;
1538 mutex_lock(&ioc->sas_discovery_mutex);
1539 mptsas_probe_hba_phys(ioc);
1540 while (!mptsas_probe_expander_phys(ioc, &handle))
1543 Reporting RAID volumes.
1545 if (!ioc->raid_data.pIocPg2)
1547 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
1549 for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1550 scsi_add_device(ioc->sh, ioc->num_ports,
1551 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
1554 mutex_unlock(&ioc->sas_discovery_mutex);
1558 * Work queue thread to handle Runtime discovery
1559 * Mere purpose is the hot add/delete of expanders
1562 mptscsih_discovery_work(void * arg)
1564 struct mptsas_discovery_event *ev = arg;
1565 MPT_ADAPTER *ioc = ev->ioc;
1566 u32 handle = 0xFFFF;
1568 mutex_lock(&ioc->sas_discovery_mutex);
1569 ioc->sas_discovery_runtime=1;
1570 mptsas_delete_expander_phys(ioc);
1571 mptsas_probe_hba_phys(ioc);
1572 while (!mptsas_probe_expander_phys(ioc, &handle))
1575 ioc->sas_discovery_runtime=0;
1576 mutex_unlock(&ioc->sas_discovery_mutex);
1579 static struct mptsas_phyinfo *
1580 mptsas_find_phyinfo_by_parent(MPT_ADAPTER *ioc, u16 parent_handle, u8 phy_id)
1582 struct mptsas_portinfo *port_info;
1583 struct mptsas_devinfo device_info;
1584 struct mptsas_phyinfo *phy_info = NULL;
1588 * Retrieve the parent sas_address
1590 error = mptsas_sas_device_pg0(ioc, &device_info,
1591 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1592 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1598 * The phy_info structures are never deallocated during lifetime of
1599 * a host, so the code below is safe without additional refcounting.
1601 mutex_lock(&ioc->sas_topology_mutex);
1602 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1603 for (i = 0; i < port_info->num_phys; i++) {
1604 if (port_info->phy_info[i].identify.sas_address ==
1605 device_info.sas_address &&
1606 port_info->phy_info[i].phy_id == phy_id) {
1607 phy_info = &port_info->phy_info[i];
1612 mutex_unlock(&ioc->sas_topology_mutex);
1617 static struct mptsas_phyinfo *
1618 mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
1620 struct mptsas_portinfo *port_info;
1621 struct mptsas_phyinfo *phy_info = NULL;
1625 * The phy_info structures are never deallocated during lifetime of
1626 * a host, so the code below is safe without additional refcounting.
1628 mutex_lock(&ioc->sas_topology_mutex);
1629 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1630 for (i = 0; i < port_info->num_phys; i++)
1631 if (mptsas_is_end_device(&port_info->phy_info[i].attached))
1632 if (port_info->phy_info[i].attached.id == id) {
1633 phy_info = &port_info->phy_info[i];
1637 mutex_unlock(&ioc->sas_topology_mutex);
1643 * Work queue thread to clear the persitency table
1646 mptscsih_sas_persist_clear_table(void * arg)
1648 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
1650 mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT);
1654 mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
1656 sdev->no_uld_attach = data ? 1 : 0;
1657 scsi_device_reprobe(sdev);
1661 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
1663 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
1664 mptsas_reprobe_lun);
1669 * Work queue thread to handle SAS hotplug events
1672 mptsas_hotplug_work(void *arg)
1674 struct mptsas_hotplug_event *ev = arg;
1675 MPT_ADAPTER *ioc = ev->ioc;
1676 struct mptsas_phyinfo *phy_info;
1677 struct sas_rphy *rphy;
1678 struct scsi_device *sdev;
1679 struct sas_identify identify;
1681 struct mptsas_devinfo sas_device;
1682 VirtTarget *vtarget;
1684 mutex_lock(&ioc->sas_discovery_mutex);
1686 switch (ev->event_type) {
1687 case MPTSAS_DEL_DEVICE:
1689 phy_info = mptsas_find_phyinfo_by_target(ioc, ev->id);
1692 * Sanity checks, for non-existing phys and remote rphys.
1696 if (!phy_info->rphy)
1698 if (phy_info->starget) {
1699 vtarget = phy_info->starget->hostdata;
1704 * Handling RAID components
1706 if (ev->phys_disk_num_valid) {
1707 vtarget->target_id = ev->phys_disk_num;
1708 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
1709 mptsas_reprobe_target(vtarget->starget, 1);
1714 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1716 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_STP_TARGET)
1718 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1721 printk(MYIOC_s_INFO_FMT
1722 "removing %s device, channel %d, id %d, phy %d\n",
1723 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
1725 sas_rphy_delete(phy_info->rphy);
1726 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
1727 phy_info->rphy = NULL;
1728 phy_info->starget = NULL;
1730 case MPTSAS_ADD_DEVICE:
1733 * Refresh sas device pg0 data
1735 if (mptsas_sas_device_pg0(ioc, &sas_device,
1736 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
1737 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id))
1740 phy_info = mptsas_find_phyinfo_by_parent(ioc,
1741 sas_device.handle_parent, sas_device.phy_id);
1744 u32 handle = 0xFFFF;
1747 * Its possible when an expander has been hot added
1748 * containing attached devices, the sas firmware
1749 * may send a RC_ADDED event prior to the
1750 * DISCOVERY STOP event. If that occurs, our
1751 * view of the topology in the driver in respect to this
1752 * expander might of not been setup, and we hit this
1754 * Therefore, this code kicks off discovery to
1756 * Then again, we check whether the parent phy has
1759 ioc->sas_discovery_runtime=1;
1760 mptsas_delete_expander_phys(ioc);
1761 mptsas_probe_hba_phys(ioc);
1762 while (!mptsas_probe_expander_phys(ioc, &handle))
1764 ioc->sas_discovery_runtime=0;
1766 phy_info = mptsas_find_phyinfo_by_parent(ioc,
1767 sas_device.handle_parent, sas_device.phy_id);
1772 if (phy_info->starget) {
1773 vtarget = phy_info->starget->hostdata;
1778 * Handling RAID components
1780 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1781 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
1782 vtarget->target_id = ev->id;
1783 mptsas_reprobe_target(phy_info->starget, 0);
1791 memcpy(&phy_info->attached, &sas_device,
1792 sizeof(struct mptsas_devinfo));
1794 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1796 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_STP_TARGET)
1798 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1801 printk(MYIOC_s_INFO_FMT
1802 "attaching %s device, channel %d, id %d, phy %d\n",
1803 ioc->name, ds, ev->channel, ev->id, ev->phy_id);
1805 mptsas_parse_device_info(&identify, &phy_info->attached);
1806 switch (identify.device_type) {
1807 case SAS_END_DEVICE:
1808 rphy = sas_end_device_alloc(phy_info->phy);
1810 case SAS_EDGE_EXPANDER_DEVICE:
1811 case SAS_FANOUT_EXPANDER_DEVICE:
1812 rphy = sas_expander_alloc(phy_info->phy, identify.device_type);
1819 break; /* non-fatal: an rphy can be added later */
1821 rphy->identify = identify;
1822 if (sas_rphy_add(rphy)) {
1823 sas_rphy_free(rphy);
1827 phy_info->rphy = rphy;
1829 case MPTSAS_ADD_RAID:
1830 sdev = scsi_device_lookup(
1836 scsi_device_put(sdev);
1839 printk(MYIOC_s_INFO_FMT
1840 "attaching raid volume, channel %d, id %d\n",
1841 ioc->name, ioc->num_ports, ev->id);
1842 scsi_add_device(ioc->sh,
1846 mpt_findImVolumes(ioc);
1848 case MPTSAS_DEL_RAID:
1849 sdev = scsi_device_lookup(
1856 printk(MYIOC_s_INFO_FMT
1857 "removing raid volume, channel %d, id %d\n",
1858 ioc->name, ioc->num_ports, ev->id);
1859 scsi_remove_device(sdev);
1860 scsi_device_put(sdev);
1861 mpt_findImVolumes(ioc);
1866 mutex_unlock(&ioc->sas_discovery_mutex);
1870 mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1871 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1873 struct mptsas_hotplug_event *ev;
1874 u32 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
1878 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
1879 MPI_SAS_DEVICE_INFO_STP_TARGET |
1880 MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0)
1883 switch (sas_event_data->ReasonCode) {
1884 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
1885 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
1886 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
1888 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1892 INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
1894 ev->handle = le16_to_cpu(sas_event_data->DevHandle);
1896 le16_to_cpu(sas_event_data->ParentDevHandle);
1897 ev->channel = sas_event_data->Bus;
1898 ev->id = sas_event_data->TargetID;
1899 ev->phy_id = sas_event_data->PhyNum;
1900 memcpy(&sas_address, &sas_event_data->SASAddress,
1902 ev->sas_address = le64_to_cpu(sas_address);
1903 ev->device_info = device_info;
1905 if (sas_event_data->ReasonCode &
1906 MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
1907 ev->event_type = MPTSAS_ADD_DEVICE;
1909 ev->event_type = MPTSAS_DEL_DEVICE;
1910 schedule_work(&ev->work);
1912 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
1914 * Persistent table is full.
1916 INIT_WORK(&ioc->mptscsih_persistTask,
1917 mptscsih_sas_persist_clear_table,
1919 schedule_work(&ioc->mptscsih_persistTask);
1921 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
1923 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
1931 mptscsih_send_raid_event(MPT_ADAPTER *ioc,
1932 EVENT_DATA_RAID *raid_event_data)
1934 struct mptsas_hotplug_event *ev;
1935 RAID_VOL0_STATUS * volumeStatus;
1937 if (ioc->bus_type != SAS)
1940 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
1942 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1946 memset(ev,0,sizeof(struct mptsas_hotplug_event));
1947 INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
1949 ev->id = raid_event_data->VolumeID;
1951 switch (raid_event_data->ReasonCode) {
1952 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
1953 ev->event_type = MPTSAS_ADD_DEVICE;
1955 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
1956 ioc->raid_data.isRaid = 1;
1957 ev->phys_disk_num_valid = 1;
1958 ev->phys_disk_num = raid_event_data->PhysDiskNum;
1959 ev->event_type = MPTSAS_DEL_DEVICE;
1961 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
1962 ev->event_type = MPTSAS_DEL_RAID;
1964 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
1965 ev->event_type = MPTSAS_ADD_RAID;
1967 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
1968 volumeStatus = (RAID_VOL0_STATUS *) &
1969 raid_event_data->SettingsStatus;
1970 ev->event_type = (volumeStatus->State ==
1971 MPI_RAIDVOL0_STATUS_STATE_FAILED) ?
1972 MPTSAS_DEL_RAID : MPTSAS_ADD_RAID;
1977 schedule_work(&ev->work);
1981 mptscsih_send_discovery(MPT_ADAPTER *ioc,
1982 EVENT_DATA_SAS_DISCOVERY *discovery_data)
1984 struct mptsas_discovery_event *ev;
1989 * This flag will be non-zero when firmware
1990 * kicks off discovery, and return to zero
1991 * once its completed.
1993 if (discovery_data->DiscoveryStatus)
1996 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
1999 memset(ev,0,sizeof(struct mptsas_discovery_event));
2000 INIT_WORK(&ev->work, mptscsih_discovery_work, ev);
2002 schedule_work(&ev->work);
2007 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
2010 u8 event = le32_to_cpu(reply->Event) & 0xFF;
2016 * sas_discovery_ignore_events
2018 * This flag is to prevent anymore processing of
2019 * sas events once mptsas_remove function is called.
2021 if (ioc->sas_discovery_ignore_events) {
2022 rc = mptscsih_event_process(ioc, reply);
2027 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
2028 mptscsih_send_sas_event(ioc,
2029 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
2031 case MPI_EVENT_INTEGRATED_RAID:
2032 mptscsih_send_raid_event(ioc,
2033 (EVENT_DATA_RAID *)reply->Data);
2035 case MPI_EVENT_PERSISTENT_TABLE_FULL:
2036 INIT_WORK(&ioc->mptscsih_persistTask,
2037 mptscsih_sas_persist_clear_table,
2039 schedule_work(&ioc->mptscsih_persistTask);
2041 case MPI_EVENT_SAS_DISCOVERY:
2042 mptscsih_send_discovery(ioc,
2043 (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
2046 rc = mptscsih_event_process(ioc, reply);
2055 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2057 struct Scsi_Host *sh;
2060 unsigned long flags;
2068 r = mpt_attach(pdev,id);
2072 ioc = pci_get_drvdata(pdev);
2073 ioc->DoneCtx = mptsasDoneCtx;
2074 ioc->TaskCtx = mptsasTaskCtx;
2075 ioc->InternalCtx = mptsasInternalCtx;
2077 /* Added sanity check on readiness of the MPT adapter.
2079 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
2080 printk(MYIOC_s_WARN_FMT
2081 "Skipping because it's not operational!\n",
2084 goto out_mptsas_probe;
2088 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
2091 goto out_mptsas_probe;
2094 /* Sanity check - ensure at least 1 port is INITIATOR capable
2097 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
2098 if (ioc->pfacts[ii].ProtocolFlags &
2099 MPI_PORTFACTS_PROTOCOL_INITIATOR)
2104 printk(MYIOC_s_WARN_FMT
2105 "Skipping ioc=%p because SCSI Initiator mode "
2106 "is NOT enabled!\n", ioc->name, ioc);
2110 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
2112 printk(MYIOC_s_WARN_FMT
2113 "Unable to register controller with SCSI subsystem\n",
2116 goto out_mptsas_probe;
2119 spin_lock_irqsave(&ioc->FreeQlock, flags);
2121 /* Attach the SCSI Host to the IOC structure
2129 /* set 16 byte cdb's */
2130 sh->max_cmd_len = 16;
2132 sh->max_id = ioc->pfacts->MaxDevices + 1;
2134 sh->transportt = mptsas_transport_template;
2136 sh->max_lun = MPT_LAST_LUN + 1;
2137 sh->max_channel = 0;
2138 sh->this_id = ioc->pfacts[0].PortSCSIID;
2142 sh->unique_id = ioc->id;
2144 INIT_LIST_HEAD(&ioc->sas_topology);
2145 mutex_init(&ioc->sas_topology_mutex);
2146 mutex_init(&ioc->sas_discovery_mutex);
2147 mutex_init(&ioc->sas_mgmt.mutex);
2148 init_completion(&ioc->sas_mgmt.done);
2150 /* Verify that we won't exceed the maximum
2151 * number of chain buffers
2152 * We can optimize: ZZ = req_sz/sizeof(SGE)
2154 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
2155 * + (req_sz - 64)/sizeof(SGE)
2156 * A slightly different algorithm is required for
2159 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
2160 if (sizeof(dma_addr_t) == sizeof(u64)) {
2161 numSGE = (scale - 1) *
2162 (ioc->facts.MaxChainDepth-1) + scale +
2163 (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
2166 numSGE = 1 + (scale - 1) *
2167 (ioc->facts.MaxChainDepth-1) + scale +
2168 (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
2172 if (numSGE < sh->sg_tablesize) {
2173 /* Reset this value */
2174 dprintk((MYIOC_s_INFO_FMT
2175 "Resetting sg_tablesize to %d from %d\n",
2176 ioc->name, numSGE, sh->sg_tablesize));
2177 sh->sg_tablesize = numSGE;
2180 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
2182 hd = (MPT_SCSI_HOST *) sh->hostdata;
2185 /* SCSI needs scsi_cmnd lookup table!
2186 * (with size equal to req_depth*PtrSz!)
2188 hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
2189 if (!hd->ScsiLookup) {
2191 goto out_mptsas_probe;
2194 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
2195 ioc->name, hd->ScsiLookup));
2197 /* Allocate memory for the device structures.
2198 * A non-Null pointer at an offset
2199 * indicates a device exists.
2200 * max_id = 1 + maximum id (hosts.h)
2202 hd->Targets = kcalloc(sh->max_id, sizeof(void *), GFP_ATOMIC);
2205 goto out_mptsas_probe;
2208 dprintk((KERN_INFO " vtarget @ %p\n", hd->Targets));
2210 /* Clear the TM flags
2213 hd->tmState = TM_STATE_NONE;
2214 hd->resetPending = 0;
2215 hd->abortSCpnt = NULL;
2217 /* Clear the pointer used to store
2218 * single-threaded commands, i.e., those
2219 * issued during a bus scan, dv and
2220 * configuration pages.
2224 /* Initialize this SCSI Hosts' timers
2225 * To use, set the timer expires field
2228 init_timer(&hd->timer);
2229 hd->timer.data = (unsigned long) hd;
2230 hd->timer.function = mptscsih_timer_expired;
2232 hd->mpt_pq_filter = mpt_pq_filter;
2233 ioc->sas_data.ptClear = mpt_pt_clear;
2235 if (ioc->sas_data.ptClear==1) {
2236 mptbase_sas_persist_operation(
2237 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
2240 ddvprintk((MYIOC_s_INFO_FMT
2241 "mpt_pq_filter %x mpt_pq_filter %x\n",
2246 init_waitqueue_head(&hd->scandv_waitq);
2247 hd->scandv_wait_done = 0;
2248 hd->last_queue_full = 0;
2250 error = scsi_add_host(sh, &ioc->pcidev->dev);
2252 dprintk((KERN_ERR MYNAM
2253 "scsi_add_host failed\n"));
2254 goto out_mptsas_probe;
2257 mptsas_scan_sas_topology(ioc);
2263 mptscsih_remove(pdev);
2267 static void __devexit mptsas_remove(struct pci_dev *pdev)
2269 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2270 struct mptsas_portinfo *p, *n;
2272 ioc->sas_discovery_ignore_events=1;
2273 sas_remove_host(ioc->sh);
2275 mutex_lock(&ioc->sas_topology_mutex);
2276 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
2282 mutex_unlock(&ioc->sas_topology_mutex);
2284 mptscsih_remove(pdev);
2287 static struct pci_device_id mptsas_pci_table[] = {
2288 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064,
2289 PCI_ANY_ID, PCI_ANY_ID },
2290 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066,
2291 PCI_ANY_ID, PCI_ANY_ID },
2292 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068,
2293 PCI_ANY_ID, PCI_ANY_ID },
2294 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064E,
2295 PCI_ANY_ID, PCI_ANY_ID },
2296 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066E,
2297 PCI_ANY_ID, PCI_ANY_ID },
2298 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068E,
2299 PCI_ANY_ID, PCI_ANY_ID },
2300 {0} /* Terminating entry */
2302 MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
2305 static struct pci_driver mptsas_driver = {
2307 .id_table = mptsas_pci_table,
2308 .probe = mptsas_probe,
2309 .remove = __devexit_p(mptsas_remove),
2310 .shutdown = mptscsih_shutdown,
2312 .suspend = mptscsih_suspend,
2313 .resume = mptscsih_resume,
2320 show_mptmod_ver(my_NAME, my_VERSION);
2322 mptsas_transport_template =
2323 sas_attach_transport(&mptsas_transport_functions);
2324 if (!mptsas_transport_template)
2327 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
2328 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER);
2330 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
2331 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
2333 if (mpt_event_register(mptsasDoneCtx, mptsas_event_process) == 0) {
2334 devtverboseprintk((KERN_INFO MYNAM
2335 ": Registered for IOC event notifications\n"));
2338 if (mpt_reset_register(mptsasDoneCtx, mptscsih_ioc_reset) == 0) {
2339 dprintk((KERN_INFO MYNAM
2340 ": Registered for IOC reset notifications\n"));
2343 return pci_register_driver(&mptsas_driver);
2349 pci_unregister_driver(&mptsas_driver);
2350 sas_release_transport(mptsas_transport_template);
2352 mpt_reset_deregister(mptsasDoneCtx);
2353 mpt_event_deregister(mptsasDoneCtx);
2355 mpt_deregister(mptsasMgmtCtx);
2356 mpt_deregister(mptsasInternalCtx);
2357 mpt_deregister(mptsasTaskCtx);
2358 mpt_deregister(mptsasDoneCtx);
2361 module_init(mptsas_init);
2362 module_exit(mptsas_exit);