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 struct Scsi_Host *host = sdev->host;
370 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
373 * RAID volumes placed beyond the last expected port.
374 * Ignore sending sas mode pages in that case..
376 if (sdev->channel < hd->ioc->num_ports)
377 sas_read_port_mode_page(sdev);
379 return mptscsih_slave_configure(sdev);
383 * This is pretty ugly. We will be able to seriously clean it up
384 * once the DV code in mptscsih goes away and we can properly
385 * implement ->target_alloc.
388 mptsas_slave_alloc(struct scsi_device *sdev)
390 struct Scsi_Host *host = sdev->host;
391 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
392 struct sas_rphy *rphy;
393 struct mptsas_portinfo *p;
396 struct scsi_target *starget;
400 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
402 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
403 hd->ioc->name, sizeof(VirtDevice));
406 sdev->hostdata = vdev;
407 starget = scsi_target(sdev);
408 vtarget = starget->hostdata;
409 vtarget->ioc_id = hd->ioc->id;
410 vdev->vtarget = vtarget;
411 if (vtarget->num_luns == 0) {
412 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES|MPT_TARGET_FLAGS_VALID_INQUIRY;
413 hd->Targets[sdev->id] = vtarget;
417 RAID volumes placed beyond the last expected port.
419 if (sdev->channel == hd->ioc->num_ports) {
420 target_id = sdev->id;
426 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
427 mutex_lock(&hd->ioc->sas_topology_mutex);
428 list_for_each_entry(p, &hd->ioc->sas_topology, list) {
429 for (i = 0; i < p->num_phys; i++) {
430 if (p->phy_info[i].attached.sas_address ==
431 rphy->identify.sas_address) {
432 target_id = p->phy_info[i].attached.id;
433 vtarget->bus_id = p->phy_info[i].attached.channel;
434 vdev->lun = sdev->lun;
435 p->phy_info[i].starget = sdev->sdev_target;
437 * Exposing hidden disk (RAID)
439 if (mptscsih_is_phys_disk(hd->ioc, target_id)) {
440 target_id = mptscsih_raid_id_to_num(hd,
442 vdev->vtarget->tflags |=
443 MPT_TARGET_FLAGS_RAID_COMPONENT;
444 sdev->no_uld_attach = 1;
446 mutex_unlock(&hd->ioc->sas_topology_mutex);
451 mutex_unlock(&hd->ioc->sas_topology_mutex);
457 vtarget->target_id = target_id;
463 mptsas_slave_destroy(struct scsi_device *sdev)
465 struct Scsi_Host *host = sdev->host;
466 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
470 * Issue target reset to flush firmware outstanding commands.
472 vdev = sdev->hostdata;
473 if (vdev->configured_lun){
474 if (mptscsih_TMHandler(hd,
475 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
476 vdev->vtarget->bus_id,
477 vdev->vtarget->target_id,
478 0, 0, 5 /* 5 second timeout */)
481 /* The TM request failed!
484 printk(MYIOC_s_WARN_FMT
485 "Error processing TaskMgmt id=%d TARGET_RESET\n",
487 vdev->vtarget->target_id);
490 hd->tmState = TM_STATE_NONE;
493 mptscsih_slave_destroy(sdev);
496 static struct scsi_host_template mptsas_driver_template = {
497 .module = THIS_MODULE,
498 .proc_name = "mptsas",
499 .proc_info = mptscsih_proc_info,
500 .name = "MPT SPI Host",
501 .info = mptscsih_info,
502 .queuecommand = mptscsih_qcmd,
503 .target_alloc = mptscsih_target_alloc,
504 .slave_alloc = mptsas_slave_alloc,
505 .slave_configure = mptsas_slave_configure,
506 .target_destroy = mptscsih_target_destroy,
507 .slave_destroy = mptsas_slave_destroy,
508 .change_queue_depth = mptscsih_change_queue_depth,
509 .eh_abort_handler = mptscsih_abort,
510 .eh_device_reset_handler = mptscsih_dev_reset,
511 .eh_bus_reset_handler = mptscsih_bus_reset,
512 .eh_host_reset_handler = mptscsih_host_reset,
513 .bios_param = mptscsih_bios_param,
514 .can_queue = MPT_FC_CAN_QUEUE,
516 .sg_tablesize = MPT_SCSI_SG_DEPTH,
519 .use_clustering = ENABLE_CLUSTERING,
522 static int mptsas_get_linkerrors(struct sas_phy *phy)
524 MPT_ADAPTER *ioc = phy_to_ioc(phy);
525 ConfigExtendedPageHeader_t hdr;
527 SasPhyPage1_t *buffer;
528 dma_addr_t dma_handle;
531 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
532 hdr.ExtPageLength = 0;
533 hdr.PageNumber = 1 /* page number 1*/;
536 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
537 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
539 cfg.cfghdr.ehdr = &hdr;
541 cfg.pageAddr = phy->identify.phy_identifier;
542 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
543 cfg.dir = 0; /* read */
546 error = mpt_config(ioc, &cfg);
549 if (!hdr.ExtPageLength)
552 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
557 cfg.physAddr = dma_handle;
558 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
560 error = mpt_config(ioc, &cfg);
562 goto out_free_consistent;
564 mptsas_print_phy_pg1(buffer);
566 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
567 phy->running_disparity_error_count =
568 le32_to_cpu(buffer->RunningDisparityErrorCount);
569 phy->loss_of_dword_sync_count =
570 le32_to_cpu(buffer->LossDwordSynchCount);
571 phy->phy_reset_problem_count =
572 le32_to_cpu(buffer->PhyResetProblemCount);
575 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
580 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
581 MPT_FRAME_HDR *reply)
583 ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_COMMAND_GOOD;
585 ioc->sas_mgmt.status |= MPT_SAS_MGMT_STATUS_RF_VALID;
586 memcpy(ioc->sas_mgmt.reply, reply,
587 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
589 complete(&ioc->sas_mgmt.done);
593 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
595 MPT_ADAPTER *ioc = phy_to_ioc(phy);
596 SasIoUnitControlRequest_t *req;
597 SasIoUnitControlReply_t *reply;
600 unsigned long timeleft;
601 int error = -ERESTARTSYS;
603 /* not implemented for expanders */
604 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
607 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
610 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
616 hdr = (MPIHeader_t *) mf;
617 req = (SasIoUnitControlRequest_t *)mf;
618 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
619 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
620 req->MsgContext = hdr->MsgContext;
621 req->Operation = hard_reset ?
622 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
623 req->PhyNum = phy->identify.phy_identifier;
625 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
627 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
630 /* On timeout reset the board */
631 mpt_free_msg_frame(ioc, mf);
632 mpt_HardResetHandler(ioc, CAN_SLEEP);
637 /* a reply frame is expected */
638 if ((ioc->sas_mgmt.status &
639 MPT_IOCTL_STATUS_RF_VALID) == 0) {
644 /* process the completed Reply Message Frame */
645 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
646 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
647 printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
658 mutex_unlock(&ioc->sas_mgmt.mutex);
664 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
666 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
668 struct mptsas_portinfo *p;
669 struct mptsas_enclosure enclosure_info;
670 u64 enclosure_handle;
672 mutex_lock(&ioc->sas_topology_mutex);
673 list_for_each_entry(p, &ioc->sas_topology, list) {
674 for (i = 0; i < p->num_phys; i++) {
675 if (p->phy_info[i].attached.sas_address ==
676 rphy->identify.sas_address) {
677 enclosure_handle = p->phy_info[i].
678 attached.handle_enclosure;
683 mutex_unlock(&ioc->sas_topology_mutex);
687 mutex_unlock(&ioc->sas_topology_mutex);
688 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
689 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
690 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
691 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
693 *identifier = enclosure_info.enclosure_logical_id;
698 mptsas_get_bay_identifier(struct sas_rphy *rphy)
700 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
701 struct mptsas_portinfo *p;
704 mutex_lock(&ioc->sas_topology_mutex);
705 list_for_each_entry(p, &ioc->sas_topology, list) {
706 for (i = 0; i < p->num_phys; i++) {
707 if (p->phy_info[i].attached.sas_address ==
708 rphy->identify.sas_address) {
709 rc = p->phy_info[i].attached.slot;
716 mutex_unlock(&ioc->sas_topology_mutex);
720 static struct sas_function_template mptsas_transport_functions = {
721 .get_linkerrors = mptsas_get_linkerrors,
722 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
723 .get_bay_identifier = mptsas_get_bay_identifier,
724 .phy_reset = mptsas_phy_reset,
727 static struct scsi_transport_template *mptsas_transport_template;
730 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
732 ConfigExtendedPageHeader_t hdr;
734 SasIOUnitPage0_t *buffer;
735 dma_addr_t dma_handle;
738 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
739 hdr.ExtPageLength = 0;
743 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
744 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
746 cfg.cfghdr.ehdr = &hdr;
749 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
750 cfg.dir = 0; /* read */
753 error = mpt_config(ioc, &cfg);
756 if (!hdr.ExtPageLength) {
761 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
768 cfg.physAddr = dma_handle;
769 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
771 error = mpt_config(ioc, &cfg);
773 goto out_free_consistent;
775 port_info->num_phys = buffer->NumPhys;
776 port_info->phy_info = kcalloc(port_info->num_phys,
777 sizeof(struct mptsas_phyinfo),GFP_KERNEL);
778 if (!port_info->phy_info) {
780 goto out_free_consistent;
783 if (port_info->num_phys)
785 le16_to_cpu(buffer->PhyData[0].ControllerDevHandle);
786 for (i = 0; i < port_info->num_phys; i++) {
787 mptsas_print_phy_data(&buffer->PhyData[i]);
788 port_info->phy_info[i].phy_id = i;
789 port_info->phy_info[i].port_id =
790 buffer->PhyData[i].Port;
791 port_info->phy_info[i].negotiated_link_rate =
792 buffer->PhyData[i].NegotiatedLinkRate;
796 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
803 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
804 u32 form, u32 form_specific)
806 ConfigExtendedPageHeader_t hdr;
808 SasPhyPage0_t *buffer;
809 dma_addr_t dma_handle;
812 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
813 hdr.ExtPageLength = 0;
817 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
818 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
820 cfg.cfghdr.ehdr = &hdr;
821 cfg.dir = 0; /* read */
824 /* Get Phy Pg 0 for each Phy. */
826 cfg.pageAddr = form + form_specific;
827 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
829 error = mpt_config(ioc, &cfg);
833 if (!hdr.ExtPageLength) {
838 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
845 cfg.physAddr = dma_handle;
846 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
848 error = mpt_config(ioc, &cfg);
850 goto out_free_consistent;
852 mptsas_print_phy_pg0(buffer);
854 phy_info->hw_link_rate = buffer->HwLinkRate;
855 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
856 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
857 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
860 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
867 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
868 u32 form, u32 form_specific)
870 ConfigExtendedPageHeader_t hdr;
872 SasDevicePage0_t *buffer;
873 dma_addr_t dma_handle;
877 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
878 hdr.ExtPageLength = 0;
882 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
883 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
885 cfg.cfghdr.ehdr = &hdr;
886 cfg.pageAddr = form + form_specific;
888 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
889 cfg.dir = 0; /* read */
892 memset(device_info, 0, sizeof(struct mptsas_devinfo));
893 error = mpt_config(ioc, &cfg);
896 if (!hdr.ExtPageLength) {
901 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
908 cfg.physAddr = dma_handle;
909 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
911 error = mpt_config(ioc, &cfg);
913 goto out_free_consistent;
915 mptsas_print_device_pg0(buffer);
917 device_info->handle = le16_to_cpu(buffer->DevHandle);
918 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
919 device_info->handle_enclosure =
920 le16_to_cpu(buffer->EnclosureHandle);
921 device_info->slot = le16_to_cpu(buffer->Slot);
922 device_info->phy_id = buffer->PhyNum;
923 device_info->port_id = buffer->PhysicalPort;
924 device_info->id = buffer->TargetID;
925 device_info->channel = buffer->Bus;
926 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
927 device_info->sas_address = le64_to_cpu(sas_address);
928 device_info->device_info =
929 le32_to_cpu(buffer->DeviceInfo);
932 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
939 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
940 u32 form, u32 form_specific)
942 ConfigExtendedPageHeader_t hdr;
944 SasExpanderPage0_t *buffer;
945 dma_addr_t dma_handle;
948 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
949 hdr.ExtPageLength = 0;
953 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
954 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
956 cfg.cfghdr.ehdr = &hdr;
958 cfg.pageAddr = form + form_specific;
959 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
960 cfg.dir = 0; /* read */
963 memset(port_info, 0, sizeof(struct mptsas_portinfo));
964 error = mpt_config(ioc, &cfg);
968 if (!hdr.ExtPageLength) {
973 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
980 cfg.physAddr = dma_handle;
981 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
983 error = mpt_config(ioc, &cfg);
985 goto out_free_consistent;
987 /* save config data */
988 port_info->num_phys = buffer->NumPhys;
989 port_info->handle = le16_to_cpu(buffer->DevHandle);
990 port_info->phy_info = kcalloc(port_info->num_phys,
991 sizeof(struct mptsas_phyinfo),GFP_KERNEL);
992 if (!port_info->phy_info) {
994 goto out_free_consistent;
998 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1005 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
1006 u32 form, u32 form_specific)
1008 ConfigExtendedPageHeader_t hdr;
1010 SasExpanderPage1_t *buffer;
1011 dma_addr_t dma_handle;
1014 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
1015 hdr.ExtPageLength = 0;
1019 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1020 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
1022 cfg.cfghdr.ehdr = &hdr;
1024 cfg.pageAddr = form + form_specific;
1025 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1026 cfg.dir = 0; /* read */
1029 error = mpt_config(ioc, &cfg);
1033 if (!hdr.ExtPageLength) {
1038 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1045 cfg.physAddr = dma_handle;
1046 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1048 error = mpt_config(ioc, &cfg);
1050 goto out_free_consistent;
1053 mptsas_print_expander_pg1(buffer);
1055 /* save config data */
1056 phy_info->phy_id = buffer->PhyIdentifier;
1057 phy_info->port_id = buffer->PhysicalPort;
1058 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
1059 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
1060 phy_info->hw_link_rate = buffer->HwLinkRate;
1061 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
1062 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
1064 out_free_consistent:
1065 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1066 buffer, dma_handle);
1072 * Returns true if there is a scsi end device
1075 mptsas_is_end_device(struct mptsas_devinfo * attached)
1077 if ((attached->handle) &&
1078 (attached->device_info &
1079 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
1080 ((attached->device_info &
1081 MPI_SAS_DEVICE_INFO_SSP_TARGET) |
1082 (attached->device_info &
1083 MPI_SAS_DEVICE_INFO_STP_TARGET) |
1084 (attached->device_info &
1085 MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
1092 mptsas_parse_device_info(struct sas_identify *identify,
1093 struct mptsas_devinfo *device_info)
1097 identify->sas_address = device_info->sas_address;
1098 identify->phy_identifier = device_info->phy_id;
1101 * Fill in Phy Initiator Port Protocol.
1102 * Bits 6:3, more than one bit can be set, fall through cases.
1104 protocols = device_info->device_info & 0x78;
1105 identify->initiator_port_protocols = 0;
1106 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
1107 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
1108 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1109 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
1110 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
1111 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
1112 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
1113 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
1116 * Fill in Phy Target Port Protocol.
1117 * Bits 10:7, more than one bit can be set, fall through cases.
1119 protocols = device_info->device_info & 0x780;
1120 identify->target_port_protocols = 0;
1121 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1122 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
1123 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
1124 identify->target_port_protocols |= SAS_PROTOCOL_STP;
1125 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
1126 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
1127 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1128 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
1131 * Fill in Attached device type.
1133 switch (device_info->device_info &
1134 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
1135 case MPI_SAS_DEVICE_INFO_NO_DEVICE:
1136 identify->device_type = SAS_PHY_UNUSED;
1138 case MPI_SAS_DEVICE_INFO_END_DEVICE:
1139 identify->device_type = SAS_END_DEVICE;
1141 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
1142 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
1144 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
1145 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
1150 static int mptsas_probe_one_phy(struct device *dev,
1151 struct mptsas_phyinfo *phy_info, int index, int local)
1154 struct sas_phy *phy;
1160 if (!phy_info->phy) {
1161 phy = sas_phy_alloc(dev, index);
1165 phy = phy_info->phy;
1167 phy->port_identifier = phy_info->port_id;
1168 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
1171 * Set Negotiated link rate.
1173 switch (phy_info->negotiated_link_rate) {
1174 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
1175 phy->negotiated_linkrate = SAS_PHY_DISABLED;
1177 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
1178 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
1180 case MPI_SAS_IOUNIT0_RATE_1_5:
1181 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
1183 case MPI_SAS_IOUNIT0_RATE_3_0:
1184 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
1186 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
1187 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
1189 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
1194 * Set Max hardware link rate.
1196 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
1197 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
1198 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
1200 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
1201 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
1208 * Set Max programmed link rate.
1210 switch (phy_info->programmed_link_rate &
1211 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
1212 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
1213 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
1215 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
1216 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
1223 * Set Min hardware link rate.
1225 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
1226 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
1227 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
1229 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
1230 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
1237 * Set Min programmed link rate.
1239 switch (phy_info->programmed_link_rate &
1240 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
1241 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
1242 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
1244 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
1245 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
1251 if (!phy_info->phy) {
1254 phy->local_attached = 1;
1256 error = sas_phy_add(phy);
1261 phy_info->phy = phy;
1264 if ((phy_info->attached.handle) &&
1265 (!phy_info->rphy)) {
1267 struct sas_rphy *rphy;
1268 struct sas_identify identify;
1270 ioc = phy_to_ioc(phy_info->phy);
1273 * Let the hotplug_work thread handle processing
1274 * the adding/removing of devices that occur
1275 * after start of day.
1277 if (ioc->sas_discovery_runtime &&
1278 mptsas_is_end_device(&phy_info->attached))
1281 mptsas_parse_device_info(&identify, &phy_info->attached);
1282 switch (identify.device_type) {
1283 case SAS_END_DEVICE:
1284 rphy = sas_end_device_alloc(phy);
1286 case SAS_EDGE_EXPANDER_DEVICE:
1287 case SAS_FANOUT_EXPANDER_DEVICE:
1288 rphy = sas_expander_alloc(phy, identify.device_type);
1295 return 0; /* non-fatal: an rphy can be added later */
1297 rphy->identify = identify;
1299 error = sas_rphy_add(rphy);
1301 sas_rphy_free(rphy);
1305 phy_info->rphy = rphy;
1312 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1314 struct mptsas_portinfo *port_info, *hba;
1315 u32 handle = 0xFFFF;
1316 int error = -ENOMEM, i;
1318 hba = kzalloc(sizeof(*port_info), GFP_KERNEL);
1322 error = mptsas_sas_io_unit_pg0(ioc, hba);
1324 goto out_free_port_info;
1326 mutex_lock(&ioc->sas_topology_mutex);
1327 port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle);
1330 list_add_tail(&port_info->list, &ioc->sas_topology);
1332 port_info->handle = hba->handle;
1333 for (i = 0; i < hba->num_phys; i++)
1334 port_info->phy_info[i].negotiated_link_rate =
1335 hba->phy_info[i].negotiated_link_rate;
1337 kfree(hba->phy_info);
1341 mutex_unlock(&ioc->sas_topology_mutex);
1342 ioc->num_ports = port_info->num_phys;
1344 for (i = 0; i < port_info->num_phys; i++) {
1345 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
1346 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
1347 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
1349 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
1350 (MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE <<
1351 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), handle);
1352 port_info->phy_info[i].identify.phy_id =
1353 port_info->phy_info[i].phy_id;
1354 handle = port_info->phy_info[i].identify.handle;
1356 if (port_info->phy_info[i].attached.handle) {
1357 mptsas_sas_device_pg0(ioc,
1358 &port_info->phy_info[i].attached,
1359 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1360 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1361 port_info->phy_info[i].attached.handle);
1364 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
1365 &port_info->phy_info[i], ioc->sas_index, 1);
1379 mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1381 struct mptsas_portinfo *port_info, *p, *ex;
1382 int error = -ENOMEM, i, j;
1384 ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
1388 error = mptsas_sas_expander_pg0(ioc, ex,
1389 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
1390 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle);
1392 goto out_free_port_info;
1394 *handle = ex->handle;
1396 mutex_lock(&ioc->sas_topology_mutex);
1397 port_info = mptsas_find_portinfo_by_handle(ioc, *handle);
1400 list_add_tail(&port_info->list, &ioc->sas_topology);
1402 port_info->handle = ex->handle;
1404 kfree(ex->phy_info);
1408 mutex_unlock(&ioc->sas_topology_mutex);
1410 for (i = 0; i < port_info->num_phys; i++) {
1411 struct device *parent;
1413 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
1414 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
1415 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
1417 if (port_info->phy_info[i].identify.handle) {
1418 mptsas_sas_device_pg0(ioc,
1419 &port_info->phy_info[i].identify,
1420 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1421 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1422 port_info->phy_info[i].identify.handle);
1423 port_info->phy_info[i].identify.phy_id =
1424 port_info->phy_info[i].phy_id;
1427 if (port_info->phy_info[i].attached.handle) {
1428 mptsas_sas_device_pg0(ioc,
1429 &port_info->phy_info[i].attached,
1430 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1431 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1432 port_info->phy_info[i].attached.handle);
1433 port_info->phy_info[i].attached.phy_id =
1434 port_info->phy_info[i].phy_id;
1438 * If we find a parent port handle this expander is
1439 * attached to another expander, else it hangs of the
1442 parent = &ioc->sh->shost_gendev;
1443 mutex_lock(&ioc->sas_topology_mutex);
1444 list_for_each_entry(p, &ioc->sas_topology, list) {
1445 for (j = 0; j < p->num_phys; j++) {
1446 if (port_info->phy_info[i].identify.handle ==
1447 p->phy_info[j].attached.handle)
1448 parent = &p->phy_info[j].rphy->dev;
1451 mutex_unlock(&ioc->sas_topology_mutex);
1453 mptsas_probe_one_phy(parent, &port_info->phy_info[i],
1463 kfree(ex->phy_info);
1471 * mptsas_delete_expander_phys
1474 * This will traverse topology, and remove expanders
1475 * that are no longer present
1478 mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1480 struct mptsas_portinfo buffer;
1481 struct mptsas_portinfo *port_info, *n, *parent;
1484 mutex_lock(&ioc->sas_topology_mutex);
1485 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
1487 if (port_info->phy_info &&
1488 (!(port_info->phy_info[0].identify.device_info &
1489 MPI_SAS_DEVICE_INFO_SMP_TARGET)))
1492 if (mptsas_sas_expander_pg0(ioc, &buffer,
1493 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
1494 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) {
1497 * Obtain the port_info instance to the parent port
1499 parent = mptsas_find_portinfo_by_handle(ioc,
1500 port_info->phy_info[0].identify.handle_parent);
1506 * Delete rphys in the parent that point
1507 * to this expander. The transport layer will
1508 * cleanup all the children.
1510 for (i = 0; i < parent->num_phys; i++) {
1511 if ((!parent->phy_info[i].rphy) ||
1512 (parent->phy_info[i].attached.sas_address !=
1513 port_info->phy_info[i].identify.sas_address))
1515 sas_rphy_delete(parent->phy_info[i].rphy);
1516 memset(&parent->phy_info[i].attached, 0,
1517 sizeof(struct mptsas_devinfo));
1518 parent->phy_info[i].rphy = NULL;
1519 parent->phy_info[i].starget = NULL;
1522 list_del(&port_info->list);
1523 if (port_info->phy_info)
1524 kfree(port_info->phy_info);
1528 * Free this memory allocated from inside
1529 * mptsas_sas_expander_pg0
1531 if (buffer.phy_info)
1532 kfree(buffer.phy_info);
1534 mutex_unlock(&ioc->sas_topology_mutex);
1538 * Start of day discovery
1541 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
1543 u32 handle = 0xFFFF;
1546 mutex_lock(&ioc->sas_discovery_mutex);
1547 mptsas_probe_hba_phys(ioc);
1548 while (!mptsas_probe_expander_phys(ioc, &handle))
1551 Reporting RAID volumes.
1553 if (!ioc->raid_data.pIocPg2)
1555 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
1557 for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1558 scsi_add_device(ioc->sh, ioc->num_ports,
1559 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
1562 mutex_unlock(&ioc->sas_discovery_mutex);
1566 * Work queue thread to handle Runtime discovery
1567 * Mere purpose is the hot add/delete of expanders
1570 mptscsih_discovery_work(void * arg)
1572 struct mptsas_discovery_event *ev = arg;
1573 MPT_ADAPTER *ioc = ev->ioc;
1574 u32 handle = 0xFFFF;
1576 mutex_lock(&ioc->sas_discovery_mutex);
1577 ioc->sas_discovery_runtime=1;
1578 mptsas_delete_expander_phys(ioc);
1579 mptsas_probe_hba_phys(ioc);
1580 while (!mptsas_probe_expander_phys(ioc, &handle))
1583 ioc->sas_discovery_runtime=0;
1584 mutex_unlock(&ioc->sas_discovery_mutex);
1587 static struct mptsas_phyinfo *
1588 mptsas_find_phyinfo_by_parent(MPT_ADAPTER *ioc, u16 parent_handle, u8 phy_id)
1590 struct mptsas_portinfo *port_info;
1591 struct mptsas_devinfo device_info;
1592 struct mptsas_phyinfo *phy_info = NULL;
1596 * Retrieve the parent sas_address
1598 error = mptsas_sas_device_pg0(ioc, &device_info,
1599 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1600 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
1606 * The phy_info structures are never deallocated during lifetime of
1607 * a host, so the code below is safe without additional refcounting.
1609 mutex_lock(&ioc->sas_topology_mutex);
1610 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1611 for (i = 0; i < port_info->num_phys; i++) {
1612 if (port_info->phy_info[i].identify.sas_address ==
1613 device_info.sas_address &&
1614 port_info->phy_info[i].phy_id == phy_id) {
1615 phy_info = &port_info->phy_info[i];
1620 mutex_unlock(&ioc->sas_topology_mutex);
1625 static struct mptsas_phyinfo *
1626 mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
1628 struct mptsas_portinfo *port_info;
1629 struct mptsas_phyinfo *phy_info = NULL;
1633 * The phy_info structures are never deallocated during lifetime of
1634 * a host, so the code below is safe without additional refcounting.
1636 mutex_lock(&ioc->sas_topology_mutex);
1637 list_for_each_entry(port_info, &ioc->sas_topology, list) {
1638 for (i = 0; i < port_info->num_phys; i++)
1639 if (mptsas_is_end_device(&port_info->phy_info[i].attached))
1640 if (port_info->phy_info[i].attached.id == id) {
1641 phy_info = &port_info->phy_info[i];
1645 mutex_unlock(&ioc->sas_topology_mutex);
1651 * Work queue thread to clear the persitency table
1654 mptscsih_sas_persist_clear_table(void * arg)
1656 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
1658 mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT);
1662 mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
1664 sdev->no_uld_attach = data ? 1 : 0;
1665 scsi_device_reprobe(sdev);
1669 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
1671 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
1672 mptsas_reprobe_lun);
1677 * Work queue thread to handle SAS hotplug events
1680 mptsas_hotplug_work(void *arg)
1682 struct mptsas_hotplug_event *ev = arg;
1683 MPT_ADAPTER *ioc = ev->ioc;
1684 struct mptsas_phyinfo *phy_info;
1685 struct sas_rphy *rphy;
1686 struct scsi_device *sdev;
1687 struct sas_identify identify;
1689 struct mptsas_devinfo sas_device;
1690 VirtTarget *vtarget;
1692 mutex_lock(&ioc->sas_discovery_mutex);
1694 switch (ev->event_type) {
1695 case MPTSAS_DEL_DEVICE:
1697 phy_info = mptsas_find_phyinfo_by_target(ioc, ev->id);
1700 * Sanity checks, for non-existing phys and remote rphys.
1704 if (!phy_info->rphy)
1706 if (phy_info->starget) {
1707 vtarget = phy_info->starget->hostdata;
1712 * Handling RAID components
1714 if (ev->phys_disk_num_valid) {
1715 vtarget->target_id = ev->phys_disk_num;
1716 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
1717 mptsas_reprobe_target(vtarget->starget, 1);
1722 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1724 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_STP_TARGET)
1726 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1729 printk(MYIOC_s_INFO_FMT
1730 "removing %s device, channel %d, id %d, phy %d\n",
1731 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
1733 sas_rphy_delete(phy_info->rphy);
1734 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
1735 phy_info->rphy = NULL;
1736 phy_info->starget = NULL;
1738 case MPTSAS_ADD_DEVICE:
1741 * Refresh sas device pg0 data
1743 if (mptsas_sas_device_pg0(ioc, &sas_device,
1744 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
1745 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id))
1748 phy_info = mptsas_find_phyinfo_by_parent(ioc,
1749 sas_device.handle_parent, sas_device.phy_id);
1752 u32 handle = 0xFFFF;
1755 * Its possible when an expander has been hot added
1756 * containing attached devices, the sas firmware
1757 * may send a RC_ADDED event prior to the
1758 * DISCOVERY STOP event. If that occurs, our
1759 * view of the topology in the driver in respect to this
1760 * expander might of not been setup, and we hit this
1762 * Therefore, this code kicks off discovery to
1764 * Then again, we check whether the parent phy has
1767 ioc->sas_discovery_runtime=1;
1768 mptsas_delete_expander_phys(ioc);
1769 mptsas_probe_hba_phys(ioc);
1770 while (!mptsas_probe_expander_phys(ioc, &handle))
1772 ioc->sas_discovery_runtime=0;
1774 phy_info = mptsas_find_phyinfo_by_parent(ioc,
1775 sas_device.handle_parent, sas_device.phy_id);
1780 if (phy_info->starget) {
1781 vtarget = phy_info->starget->hostdata;
1786 * Handling RAID components
1788 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1789 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
1790 vtarget->target_id = ev->id;
1791 mptsas_reprobe_target(phy_info->starget, 0);
1799 memcpy(&phy_info->attached, &sas_device,
1800 sizeof(struct mptsas_devinfo));
1802 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1804 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_STP_TARGET)
1806 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1809 printk(MYIOC_s_INFO_FMT
1810 "attaching %s device, channel %d, id %d, phy %d\n",
1811 ioc->name, ds, ev->channel, ev->id, ev->phy_id);
1813 mptsas_parse_device_info(&identify, &phy_info->attached);
1814 switch (identify.device_type) {
1815 case SAS_END_DEVICE:
1816 rphy = sas_end_device_alloc(phy_info->phy);
1818 case SAS_EDGE_EXPANDER_DEVICE:
1819 case SAS_FANOUT_EXPANDER_DEVICE:
1820 rphy = sas_expander_alloc(phy_info->phy, identify.device_type);
1827 break; /* non-fatal: an rphy can be added later */
1829 rphy->identify = identify;
1830 if (sas_rphy_add(rphy)) {
1831 sas_rphy_free(rphy);
1835 phy_info->rphy = rphy;
1837 case MPTSAS_ADD_RAID:
1838 sdev = scsi_device_lookup(
1844 scsi_device_put(sdev);
1847 printk(MYIOC_s_INFO_FMT
1848 "attaching raid volume, channel %d, id %d\n",
1849 ioc->name, ioc->num_ports, ev->id);
1850 scsi_add_device(ioc->sh,
1854 mpt_findImVolumes(ioc);
1856 case MPTSAS_DEL_RAID:
1857 sdev = scsi_device_lookup(
1864 printk(MYIOC_s_INFO_FMT
1865 "removing raid volume, channel %d, id %d\n",
1866 ioc->name, ioc->num_ports, ev->id);
1867 scsi_remove_device(sdev);
1868 scsi_device_put(sdev);
1869 mpt_findImVolumes(ioc);
1874 mutex_unlock(&ioc->sas_discovery_mutex);
1878 mptscsih_send_sas_event(MPT_ADAPTER *ioc,
1879 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1881 struct mptsas_hotplug_event *ev;
1882 u32 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
1886 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
1887 MPI_SAS_DEVICE_INFO_STP_TARGET |
1888 MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0)
1891 switch (sas_event_data->ReasonCode) {
1892 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
1893 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
1894 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
1896 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1900 INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
1902 ev->handle = le16_to_cpu(sas_event_data->DevHandle);
1904 le16_to_cpu(sas_event_data->ParentDevHandle);
1905 ev->channel = sas_event_data->Bus;
1906 ev->id = sas_event_data->TargetID;
1907 ev->phy_id = sas_event_data->PhyNum;
1908 memcpy(&sas_address, &sas_event_data->SASAddress,
1910 ev->sas_address = le64_to_cpu(sas_address);
1911 ev->device_info = device_info;
1913 if (sas_event_data->ReasonCode &
1914 MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
1915 ev->event_type = MPTSAS_ADD_DEVICE;
1917 ev->event_type = MPTSAS_DEL_DEVICE;
1918 schedule_work(&ev->work);
1920 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
1922 * Persistent table is full.
1924 INIT_WORK(&ioc->mptscsih_persistTask,
1925 mptscsih_sas_persist_clear_table,
1927 schedule_work(&ioc->mptscsih_persistTask);
1929 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
1931 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
1939 mptscsih_send_raid_event(MPT_ADAPTER *ioc,
1940 EVENT_DATA_RAID *raid_event_data)
1942 struct mptsas_hotplug_event *ev;
1943 RAID_VOL0_STATUS * volumeStatus;
1945 if (ioc->bus_type != SAS)
1948 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
1950 printk(KERN_WARNING "mptsas: lost hotplug event\n");
1954 memset(ev,0,sizeof(struct mptsas_hotplug_event));
1955 INIT_WORK(&ev->work, mptsas_hotplug_work, ev);
1957 ev->id = raid_event_data->VolumeID;
1959 switch (raid_event_data->ReasonCode) {
1960 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
1961 ev->event_type = MPTSAS_ADD_DEVICE;
1963 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
1964 ioc->raid_data.isRaid = 1;
1965 ev->phys_disk_num_valid = 1;
1966 ev->phys_disk_num = raid_event_data->PhysDiskNum;
1967 ev->event_type = MPTSAS_DEL_DEVICE;
1969 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
1970 ev->event_type = MPTSAS_DEL_RAID;
1972 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
1973 ev->event_type = MPTSAS_ADD_RAID;
1975 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
1976 volumeStatus = (RAID_VOL0_STATUS *) &
1977 raid_event_data->SettingsStatus;
1978 ev->event_type = (volumeStatus->State ==
1979 MPI_RAIDVOL0_STATUS_STATE_FAILED) ?
1980 MPTSAS_DEL_RAID : MPTSAS_ADD_RAID;
1985 schedule_work(&ev->work);
1989 mptscsih_send_discovery(MPT_ADAPTER *ioc,
1990 EVENT_DATA_SAS_DISCOVERY *discovery_data)
1992 struct mptsas_discovery_event *ev;
1997 * This flag will be non-zero when firmware
1998 * kicks off discovery, and return to zero
1999 * once its completed.
2001 if (discovery_data->DiscoveryStatus)
2004 ev = kmalloc(sizeof(*ev), GFP_ATOMIC);
2007 memset(ev,0,sizeof(struct mptsas_discovery_event));
2008 INIT_WORK(&ev->work, mptscsih_discovery_work, ev);
2010 schedule_work(&ev->work);
2015 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
2018 u8 event = le32_to_cpu(reply->Event) & 0xFF;
2024 * sas_discovery_ignore_events
2026 * This flag is to prevent anymore processing of
2027 * sas events once mptsas_remove function is called.
2029 if (ioc->sas_discovery_ignore_events) {
2030 rc = mptscsih_event_process(ioc, reply);
2035 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
2036 mptscsih_send_sas_event(ioc,
2037 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
2039 case MPI_EVENT_INTEGRATED_RAID:
2040 mptscsih_send_raid_event(ioc,
2041 (EVENT_DATA_RAID *)reply->Data);
2043 case MPI_EVENT_PERSISTENT_TABLE_FULL:
2044 INIT_WORK(&ioc->mptscsih_persistTask,
2045 mptscsih_sas_persist_clear_table,
2047 schedule_work(&ioc->mptscsih_persistTask);
2049 case MPI_EVENT_SAS_DISCOVERY:
2050 mptscsih_send_discovery(ioc,
2051 (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
2054 rc = mptscsih_event_process(ioc, reply);
2063 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2065 struct Scsi_Host *sh;
2068 unsigned long flags;
2076 r = mpt_attach(pdev,id);
2080 ioc = pci_get_drvdata(pdev);
2081 ioc->DoneCtx = mptsasDoneCtx;
2082 ioc->TaskCtx = mptsasTaskCtx;
2083 ioc->InternalCtx = mptsasInternalCtx;
2085 /* Added sanity check on readiness of the MPT adapter.
2087 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
2088 printk(MYIOC_s_WARN_FMT
2089 "Skipping because it's not operational!\n",
2092 goto out_mptsas_probe;
2096 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
2099 goto out_mptsas_probe;
2102 /* Sanity check - ensure at least 1 port is INITIATOR capable
2105 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
2106 if (ioc->pfacts[ii].ProtocolFlags &
2107 MPI_PORTFACTS_PROTOCOL_INITIATOR)
2112 printk(MYIOC_s_WARN_FMT
2113 "Skipping ioc=%p because SCSI Initiator mode "
2114 "is NOT enabled!\n", ioc->name, ioc);
2118 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
2120 printk(MYIOC_s_WARN_FMT
2121 "Unable to register controller with SCSI subsystem\n",
2124 goto out_mptsas_probe;
2127 spin_lock_irqsave(&ioc->FreeQlock, flags);
2129 /* Attach the SCSI Host to the IOC structure
2137 /* set 16 byte cdb's */
2138 sh->max_cmd_len = 16;
2140 sh->max_id = ioc->pfacts->MaxDevices + 1;
2142 sh->transportt = mptsas_transport_template;
2144 sh->max_lun = MPT_LAST_LUN + 1;
2145 sh->max_channel = 0;
2146 sh->this_id = ioc->pfacts[0].PortSCSIID;
2150 sh->unique_id = ioc->id;
2152 INIT_LIST_HEAD(&ioc->sas_topology);
2153 mutex_init(&ioc->sas_topology_mutex);
2154 mutex_init(&ioc->sas_discovery_mutex);
2155 mutex_init(&ioc->sas_mgmt.mutex);
2156 init_completion(&ioc->sas_mgmt.done);
2158 /* Verify that we won't exceed the maximum
2159 * number of chain buffers
2160 * We can optimize: ZZ = req_sz/sizeof(SGE)
2162 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
2163 * + (req_sz - 64)/sizeof(SGE)
2164 * A slightly different algorithm is required for
2167 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
2168 if (sizeof(dma_addr_t) == sizeof(u64)) {
2169 numSGE = (scale - 1) *
2170 (ioc->facts.MaxChainDepth-1) + scale +
2171 (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
2174 numSGE = 1 + (scale - 1) *
2175 (ioc->facts.MaxChainDepth-1) + scale +
2176 (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
2180 if (numSGE < sh->sg_tablesize) {
2181 /* Reset this value */
2182 dprintk((MYIOC_s_INFO_FMT
2183 "Resetting sg_tablesize to %d from %d\n",
2184 ioc->name, numSGE, sh->sg_tablesize));
2185 sh->sg_tablesize = numSGE;
2188 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
2190 hd = (MPT_SCSI_HOST *) sh->hostdata;
2193 /* SCSI needs scsi_cmnd lookup table!
2194 * (with size equal to req_depth*PtrSz!)
2196 hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
2197 if (!hd->ScsiLookup) {
2199 goto out_mptsas_probe;
2202 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
2203 ioc->name, hd->ScsiLookup));
2205 /* Allocate memory for the device structures.
2206 * A non-Null pointer at an offset
2207 * indicates a device exists.
2208 * max_id = 1 + maximum id (hosts.h)
2210 hd->Targets = kcalloc(sh->max_id, sizeof(void *), GFP_ATOMIC);
2213 goto out_mptsas_probe;
2216 dprintk((KERN_INFO " vtarget @ %p\n", hd->Targets));
2218 /* Clear the TM flags
2221 hd->tmState = TM_STATE_NONE;
2222 hd->resetPending = 0;
2223 hd->abortSCpnt = NULL;
2225 /* Clear the pointer used to store
2226 * single-threaded commands, i.e., those
2227 * issued during a bus scan, dv and
2228 * configuration pages.
2232 /* Initialize this SCSI Hosts' timers
2233 * To use, set the timer expires field
2236 init_timer(&hd->timer);
2237 hd->timer.data = (unsigned long) hd;
2238 hd->timer.function = mptscsih_timer_expired;
2240 hd->mpt_pq_filter = mpt_pq_filter;
2241 ioc->sas_data.ptClear = mpt_pt_clear;
2243 if (ioc->sas_data.ptClear==1) {
2244 mptbase_sas_persist_operation(
2245 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
2248 ddvprintk((MYIOC_s_INFO_FMT
2249 "mpt_pq_filter %x mpt_pq_filter %x\n",
2254 init_waitqueue_head(&hd->scandv_waitq);
2255 hd->scandv_wait_done = 0;
2256 hd->last_queue_full = 0;
2258 error = scsi_add_host(sh, &ioc->pcidev->dev);
2260 dprintk((KERN_ERR MYNAM
2261 "scsi_add_host failed\n"));
2262 goto out_mptsas_probe;
2265 mptsas_scan_sas_topology(ioc);
2271 mptscsih_remove(pdev);
2275 static void __devexit mptsas_remove(struct pci_dev *pdev)
2277 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2278 struct mptsas_portinfo *p, *n;
2280 ioc->sas_discovery_ignore_events=1;
2281 sas_remove_host(ioc->sh);
2283 mutex_lock(&ioc->sas_topology_mutex);
2284 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
2290 mutex_unlock(&ioc->sas_topology_mutex);
2292 mptscsih_remove(pdev);
2295 static struct pci_device_id mptsas_pci_table[] = {
2296 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064,
2297 PCI_ANY_ID, PCI_ANY_ID },
2298 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066,
2299 PCI_ANY_ID, PCI_ANY_ID },
2300 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068,
2301 PCI_ANY_ID, PCI_ANY_ID },
2302 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064E,
2303 PCI_ANY_ID, PCI_ANY_ID },
2304 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1066E,
2305 PCI_ANY_ID, PCI_ANY_ID },
2306 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1068E,
2307 PCI_ANY_ID, PCI_ANY_ID },
2308 {0} /* Terminating entry */
2310 MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
2313 static struct pci_driver mptsas_driver = {
2315 .id_table = mptsas_pci_table,
2316 .probe = mptsas_probe,
2317 .remove = __devexit_p(mptsas_remove),
2318 .shutdown = mptscsih_shutdown,
2320 .suspend = mptscsih_suspend,
2321 .resume = mptscsih_resume,
2328 show_mptmod_ver(my_NAME, my_VERSION);
2330 mptsas_transport_template =
2331 sas_attach_transport(&mptsas_transport_functions);
2332 if (!mptsas_transport_template)
2335 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
2336 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER);
2338 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
2339 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
2341 if (mpt_event_register(mptsasDoneCtx, mptsas_event_process) == 0) {
2342 devtverboseprintk((KERN_INFO MYNAM
2343 ": Registered for IOC event notifications\n"));
2346 if (mpt_reset_register(mptsasDoneCtx, mptscsih_ioc_reset) == 0) {
2347 dprintk((KERN_INFO MYNAM
2348 ": Registered for IOC reset notifications\n"));
2351 return pci_register_driver(&mptsas_driver);
2357 pci_unregister_driver(&mptsas_driver);
2358 sas_release_transport(mptsas_transport_template);
2360 mpt_reset_deregister(mptsasDoneCtx);
2361 mpt_event_deregister(mptsasDoneCtx);
2363 mpt_deregister(mptsasMgmtCtx);
2364 mpt_deregister(mptsasInternalCtx);
2365 mpt_deregister(mptsasTaskCtx);
2366 mpt_deregister(mptsasDoneCtx);
2369 module_init(mptsas_init);
2370 module_exit(mptsas_exit);