2 * linux/drivers/message/fusion/mptsas.c
3 * For use with LSI PCI chip/adapter(s)
4 * running LSI Fusion MPT (Message Passing Technology) firmware.
6 * Copyright (c) 1999-2008 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com)
9 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; version 2 of the License.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
21 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25 solely responsible for determining the appropriateness of using and
26 distributing the Program and assumes all risks associated with its
27 exercise of rights under this Agreement, including but not limited to
28 the risks and costs of program errors, damage to or loss of data,
29 programs or equipment, and unavailability or interruption of operations.
31 DISCLAIMER OF LIABILITY
32 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 You should have received a copy of the GNU General Public License
41 along with this program; if not, write to the Free Software
42 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
46 #include <linux/module.h>
47 #include <linux/kernel.h>
48 #include <linux/init.h>
49 #include <linux/errno.h>
50 #include <linux/jiffies.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h> /* for mdelay */
54 #include <scsi/scsi.h>
55 #include <scsi/scsi_cmnd.h>
56 #include <scsi/scsi_device.h>
57 #include <scsi/scsi_host.h>
58 #include <scsi/scsi_transport_sas.h>
59 #include <scsi/scsi_dbg.h>
66 #define my_NAME "Fusion MPT SAS Host driver"
67 #define my_VERSION MPT_LINUX_VERSION_COMMON
68 #define MYNAM "mptsas"
71 * Reserved channel for integrated raid
73 #define MPTSAS_RAID_CHANNEL 1
75 MODULE_AUTHOR(MODULEAUTHOR);
76 MODULE_DESCRIPTION(my_NAME);
77 MODULE_LICENSE("GPL");
78 MODULE_VERSION(my_VERSION);
80 static int mpt_pt_clear;
81 module_param(mpt_pt_clear, int, 0);
82 MODULE_PARM_DESC(mpt_pt_clear,
83 " Clear persistency table: enable=1 "
84 "(default=MPTSCSIH_PT_CLEAR=0)");
86 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
87 #define MPTSAS_MAX_LUN (16895)
88 static int max_lun = MPTSAS_MAX_LUN;
89 module_param(max_lun, int, 0);
90 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
92 static u8 mptsasDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
93 static u8 mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
94 static u8 mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
95 static u8 mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS;
96 static u8 mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS;
98 static void mptsas_hotplug_work(struct work_struct *work);
100 static void mptsas_print_phy_data(MPT_ADAPTER *ioc,
101 MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
103 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
104 "---- IO UNIT PAGE 0 ------------\n", ioc->name));
105 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
106 ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle)));
107 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n",
108 ioc->name, le16_to_cpu(phy_data->ControllerDevHandle)));
109 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n",
110 ioc->name, phy_data->Port));
111 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n",
112 ioc->name, phy_data->PortFlags));
113 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n",
114 ioc->name, phy_data->PhyFlags));
115 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
116 ioc->name, phy_data->NegotiatedLinkRate));
117 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
118 "Controller PHY Device Info=0x%X\n", ioc->name,
119 le32_to_cpu(phy_data->ControllerPhyDeviceInfo)));
120 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n",
121 ioc->name, le32_to_cpu(phy_data->DiscoveryStatus)));
124 static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0)
128 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
130 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
131 "---- SAS PHY PAGE 0 ------------\n", ioc->name));
132 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
133 "Attached Device Handle=0x%X\n", ioc->name,
134 le16_to_cpu(pg0->AttachedDevHandle)));
135 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
136 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
137 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
138 "Attached PHY Identifier=0x%X\n", ioc->name,
139 pg0->AttachedPhyIdentifier));
140 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n",
141 ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo)));
142 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
143 ioc->name, pg0->ProgrammedLinkRate));
144 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n",
145 ioc->name, pg0->ChangeCount));
146 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n",
147 ioc->name, le32_to_cpu(pg0->PhyInfo)));
150 static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1)
152 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
153 "---- SAS PHY PAGE 1 ------------\n", ioc->name));
154 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n",
155 ioc->name, pg1->InvalidDwordCount));
156 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
157 "Running Disparity Error Count=0x%x\n", ioc->name,
158 pg1->RunningDisparityErrorCount));
159 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
160 "Loss Dword Synch Count=0x%x\n", ioc->name,
161 pg1->LossDwordSynchCount));
162 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
163 "PHY Reset Problem Count=0x%x\n\n", ioc->name,
164 pg1->PhyResetProblemCount));
167 static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0)
171 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
173 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
174 "---- SAS DEVICE PAGE 0 ---------\n", ioc->name));
175 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
176 ioc->name, le16_to_cpu(pg0->DevHandle)));
177 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n",
178 ioc->name, le16_to_cpu(pg0->ParentDevHandle)));
179 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n",
180 ioc->name, le16_to_cpu(pg0->EnclosureHandle)));
181 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n",
182 ioc->name, le16_to_cpu(pg0->Slot)));
183 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
184 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
185 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n",
186 ioc->name, pg0->TargetID));
187 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n",
188 ioc->name, pg0->Bus));
189 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n",
190 ioc->name, pg0->PhyNum));
191 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n",
192 ioc->name, le16_to_cpu(pg0->AccessStatus)));
193 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n",
194 ioc->name, le32_to_cpu(pg0->DeviceInfo)));
195 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n",
196 ioc->name, le16_to_cpu(pg0->Flags)));
197 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n",
198 ioc->name, pg0->PhysicalPort));
201 static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1)
203 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
204 "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name));
205 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n",
206 ioc->name, pg1->PhysicalPort));
207 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n",
208 ioc->name, pg1->PhyIdentifier));
209 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
210 ioc->name, pg1->NegotiatedLinkRate));
211 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
212 ioc->name, pg1->ProgrammedLinkRate));
213 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n",
214 ioc->name, pg1->HwLinkRate));
215 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n",
216 ioc->name, le16_to_cpu(pg1->OwnerDevHandle)));
217 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
218 "Attached Device Handle=0x%X\n\n", ioc->name,
219 le16_to_cpu(pg1->AttachedDevHandle)));
222 static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
224 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
225 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
228 static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
230 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
231 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
234 static struct mptsas_portinfo *
235 mptsas_get_hba_portinfo(MPT_ADAPTER *ioc)
237 struct list_head *head = &ioc->sas_topology;
238 struct mptsas_portinfo *pi = NULL;
240 /* always the first entry on sas_topology list */
242 if (!list_empty(head))
243 pi = list_entry(head->next, struct mptsas_portinfo, list);
249 * mptsas_find_portinfo_by_handle
251 * This function should be called with the sas_topology_mutex already held
253 static struct mptsas_portinfo *
254 mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
256 struct mptsas_portinfo *port_info, *rc=NULL;
259 list_for_each_entry(port_info, &ioc->sas_topology, list)
260 for (i = 0; i < port_info->num_phys; i++)
261 if (port_info->phy_info[i].identify.handle == handle) {
270 * Returns true if there is a scsi end device
273 mptsas_is_end_device(struct mptsas_devinfo * attached)
275 if ((attached->sas_address) &&
276 (attached->device_info &
277 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
278 ((attached->device_info &
279 MPI_SAS_DEVICE_INFO_SSP_TARGET) |
280 (attached->device_info &
281 MPI_SAS_DEVICE_INFO_STP_TARGET) |
282 (attached->device_info &
283 MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
291 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
293 struct mptsas_portinfo *port_info;
294 struct mptsas_phyinfo *phy_info;
300 port_info = port_details->port_info;
301 phy_info = port_info->phy_info;
303 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d "
304 "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
305 port_details->num_phys, (unsigned long long)
306 port_details->phy_bitmask));
308 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
309 if(phy_info->port_details != port_details)
311 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
312 phy_info->port_details = NULL;
317 static inline struct sas_rphy *
318 mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
320 if (phy_info->port_details)
321 return phy_info->port_details->rphy;
327 mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
329 if (phy_info->port_details) {
330 phy_info->port_details->rphy = rphy;
331 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
336 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
337 &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
338 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
339 ioc->name, rphy, rphy->dev.release));
343 static inline struct sas_port *
344 mptsas_get_port(struct mptsas_phyinfo *phy_info)
346 if (phy_info->port_details)
347 return phy_info->port_details->port;
353 mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port)
355 if (phy_info->port_details)
356 phy_info->port_details->port = port;
359 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
360 &port->dev, MYIOC_s_FMT "add:", ioc->name));
361 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n",
362 ioc->name, port, port->dev.release));
366 static inline struct scsi_target *
367 mptsas_get_starget(struct mptsas_phyinfo *phy_info)
369 if (phy_info->port_details)
370 return phy_info->port_details->starget;
376 mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
379 if (phy_info->port_details)
380 phy_info->port_details->starget = starget;
385 * mptsas_setup_wide_ports
387 * Updates for new and existing narrow/wide port configuration
388 * in the sas_topology
391 mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
393 struct mptsas_portinfo_details * port_details;
394 struct mptsas_phyinfo *phy_info, *phy_info_cmp;
398 mutex_lock(&ioc->sas_topology_mutex);
400 phy_info = port_info->phy_info;
401 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
402 if (phy_info->attached.handle)
404 port_details = phy_info->port_details;
407 if (port_details->num_phys < 2)
410 * Removing a phy from a port, letting the last
411 * phy be removed by firmware events.
413 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
414 "%s: [%p]: deleting phy = %d\n",
415 ioc->name, __func__, port_details, i));
416 port_details->num_phys--;
417 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
418 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
419 sas_port_delete_phy(port_details->port, phy_info->phy);
420 phy_info->port_details = NULL;
424 * Populate and refresh the tree
426 phy_info = port_info->phy_info;
427 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
428 sas_address = phy_info->attached.sas_address;
429 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
430 ioc->name, i, (unsigned long long)sas_address));
433 port_details = phy_info->port_details;
438 port_details = kzalloc(sizeof(*port_details),
442 port_details->num_phys = 1;
443 port_details->port_info = port_info;
444 if (phy_info->phy_id < 64 )
445 port_details->phy_bitmask |=
446 (1 << phy_info->phy_id);
447 phy_info->sas_port_add_phy=1;
448 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
449 "phy_id=%d sas_address=0x%018llX\n",
450 ioc->name, i, (unsigned long long)sas_address));
451 phy_info->port_details = port_details;
454 if (i == port_info->num_phys - 1)
456 phy_info_cmp = &port_info->phy_info[i + 1];
457 for (j = i + 1 ; j < port_info->num_phys ; j++,
459 if (!phy_info_cmp->attached.sas_address)
461 if (sas_address != phy_info_cmp->attached.sas_address)
463 if (phy_info_cmp->port_details == port_details )
465 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
466 "\t\tphy_id=%d sas_address=0x%018llX\n",
467 ioc->name, j, (unsigned long long)
468 phy_info_cmp->attached.sas_address));
469 if (phy_info_cmp->port_details) {
471 mptsas_get_rphy(phy_info_cmp);
473 mptsas_get_port(phy_info_cmp);
474 port_details->starget =
475 mptsas_get_starget(phy_info_cmp);
476 port_details->num_phys =
477 phy_info_cmp->port_details->num_phys;
478 if (!phy_info_cmp->port_details->num_phys)
479 kfree(phy_info_cmp->port_details);
481 phy_info_cmp->sas_port_add_phy=1;
483 * Adding a phy to a port
485 phy_info_cmp->port_details = port_details;
486 if (phy_info_cmp->phy_id < 64 )
487 port_details->phy_bitmask |=
488 (1 << phy_info_cmp->phy_id);
489 port_details->num_phys++;
495 for (i = 0; i < port_info->num_phys; i++) {
496 port_details = port_info->phy_info[i].port_details;
499 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
500 "%s: [%p]: phy_id=%02d num_phys=%02d "
501 "bitmask=0x%016llX\n", ioc->name, __func__,
502 port_details, i, port_details->num_phys,
503 (unsigned long long)port_details->phy_bitmask));
504 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
505 ioc->name, port_details->port, port_details->rphy));
507 dsaswideprintk(ioc, printk("\n"));
508 mutex_unlock(&ioc->sas_topology_mutex);
512 * csmisas_find_vtarget
520 mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
522 struct scsi_device *sdev;
524 VirtTarget *vtarget = NULL;
526 shost_for_each_device(sdev, ioc->sh) {
527 vdevice = sdev->hostdata;
528 if ((vdevice == NULL) ||
529 (vdevice->vtarget == NULL))
531 if (vdevice->vtarget->id == id &&
532 vdevice->vtarget->channel == channel)
533 vtarget = vdevice->vtarget;
539 * mptsas_target_reset
541 * Issues TARGET_RESET to end device using handshaking method
547 * Returns (1) success
552 mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
555 SCSITaskMgmt_t *pScsiTm;
557 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
559 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
560 "%s, no msg frames @%d!!\n",
561 ioc->name, __func__, __LINE__));
565 /* Format the Request
567 pScsiTm = (SCSITaskMgmt_t *) mf;
568 memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
569 pScsiTm->TargetID = id;
570 pScsiTm->Bus = channel;
571 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
572 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
573 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
575 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
577 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
583 * mptsas_target_reset_queue
585 * Receive request for TARGET_RESET after recieving an firmware
586 * event NOT_RESPONDING_EVENT, then put command in link list
587 * and queue if task_queue already in use.
594 mptsas_target_reset_queue(MPT_ADAPTER *ioc,
595 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
597 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
598 VirtTarget *vtarget = NULL;
599 struct mptsas_target_reset_event *target_reset_list;
602 id = sas_event_data->TargetID;
603 channel = sas_event_data->Bus;
605 if (!(vtarget = mptsas_find_vtarget(ioc, channel, id)))
608 vtarget->deleted = 1; /* block IO */
610 target_reset_list = kzalloc(sizeof(*target_reset_list),
612 if (!target_reset_list) {
613 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
614 "%s, failed to allocate mem @%d..!!\n",
615 ioc->name, __func__, __LINE__));
619 memcpy(&target_reset_list->sas_event_data, sas_event_data,
620 sizeof(*sas_event_data));
621 list_add_tail(&target_reset_list->list, &hd->target_reset_list);
623 target_reset_list->time_count = jiffies;
625 if (mptsas_target_reset(ioc, channel, id)) {
626 target_reset_list->target_reset_issued = 1;
631 * mptsas_taskmgmt_complete - Completion for TARGET_RESET after
632 * NOT_RESPONDING_EVENT, enable work queue to finish off removing device
633 * from upper layers. then send next TARGET_RESET in the queue.
634 * @ioc: Pointer to MPT_ADAPTER structure
638 mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
640 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
641 struct list_head *head = &hd->target_reset_list;
642 struct mptsas_hotplug_event *ev;
643 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
646 struct mptsas_target_reset_event *target_reset_list;
647 SCSITaskMgmtReply_t *pScsiTmReply;
649 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: "
650 "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
652 pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
654 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
655 "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
656 "\ttask_type = 0x%02X, iocstatus = 0x%04X "
657 "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
658 "term_cmnds = %d\n", ioc->name,
659 pScsiTmReply->Bus, pScsiTmReply->TargetID,
660 pScsiTmReply->TaskType,
661 le16_to_cpu(pScsiTmReply->IOCStatus),
662 le32_to_cpu(pScsiTmReply->IOCLogInfo),
663 pScsiTmReply->ResponseCode,
664 le32_to_cpu(pScsiTmReply->TerminationCount)));
666 if (pScsiTmReply->ResponseCode)
667 mptscsih_taskmgmt_response_code(ioc,
668 pScsiTmReply->ResponseCode);
671 if (pScsiTmReply && (pScsiTmReply->TaskType ==
672 MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
673 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) {
674 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
675 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
676 memcpy(ioc->taskmgmt_cmds.reply, mr,
677 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
678 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
679 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
680 complete(&ioc->taskmgmt_cmds.done);
686 mpt_clear_taskmgmt_in_progress_flag(ioc);
688 if (list_empty(head))
691 target_reset_list = list_entry(head->next,
692 struct mptsas_target_reset_event, list);
694 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
695 "TaskMgmt: completed (%d seconds)\n",
696 ioc->name, jiffies_to_msecs(jiffies -
697 target_reset_list->time_count)/1000));
699 sas_event_data = &target_reset_list->sas_event_data;
700 id = pScsiTmReply->TargetID;
701 channel = pScsiTmReply->Bus;
702 target_reset_list->time_count = jiffies;
707 if (!target_reset_list->target_reset_issued) {
708 if (mptsas_target_reset(ioc, channel, id))
709 target_reset_list->target_reset_issued = 1;
714 * enable work queue to remove device from upper layers
716 list_del(&target_reset_list->list);
718 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
720 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n",
721 ioc->name,__func__, __LINE__));
725 INIT_WORK(&ev->work, mptsas_hotplug_work);
727 ev->handle = le16_to_cpu(sas_event_data->DevHandle);
729 le16_to_cpu(sas_event_data->ParentDevHandle);
730 ev->channel = channel;
732 ev->phy_id = sas_event_data->PhyNum;
733 memcpy(&sas_address, &sas_event_data->SASAddress,
735 ev->sas_address = le64_to_cpu(sas_address);
736 ev->device_info = le32_to_cpu(sas_event_data->DeviceInfo);
737 ev->event_type = MPTSAS_DEL_DEVICE;
738 schedule_work(&ev->work);
739 kfree(target_reset_list);
743 * issue target reset to next device in the queue
746 head = &hd->target_reset_list;
747 if (list_empty(head))
750 target_reset_list = list_entry(head->next, struct mptsas_target_reset_event,
753 id = target_reset_list->sas_event_data.TargetID;
754 channel = target_reset_list->sas_event_data.Bus;
755 target_reset_list->time_count = jiffies;
757 if (mptsas_target_reset(ioc, channel, id))
758 target_reset_list->target_reset_issued = 1;
771 mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
774 struct mptsas_target_reset_event *target_reset_list, *n;
777 rc = mptscsih_ioc_reset(ioc, reset_phase);
779 if (ioc->bus_type != SAS)
782 if (reset_phase != MPT_IOC_POST_RESET)
785 if (!ioc->sh || !ioc->sh->hostdata)
787 hd = shost_priv(ioc->sh);
791 if (list_empty(&hd->target_reset_list))
794 /* flush the target_reset_list */
795 list_for_each_entry_safe(target_reset_list, n,
796 &hd->target_reset_list, list) {
797 list_del(&target_reset_list->list);
798 kfree(target_reset_list);
806 mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
807 u32 form, u32 form_specific)
809 ConfigExtendedPageHeader_t hdr;
811 SasEnclosurePage0_t *buffer;
812 dma_addr_t dma_handle;
814 __le64 le_identifier;
816 memset(&hdr, 0, sizeof(hdr));
817 hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
819 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
820 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
822 cfg.cfghdr.ehdr = &hdr;
824 cfg.pageAddr = form + form_specific;
825 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
826 cfg.dir = 0; /* read */
829 error = mpt_config(ioc, &cfg);
832 if (!hdr.ExtPageLength) {
837 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
844 cfg.physAddr = dma_handle;
845 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
847 error = mpt_config(ioc, &cfg);
849 goto out_free_consistent;
851 /* save config data */
852 memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
853 enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
854 enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
855 enclosure->flags = le16_to_cpu(buffer->Flags);
856 enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
857 enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
858 enclosure->start_id = buffer->StartTargetID;
859 enclosure->start_channel = buffer->StartBus;
860 enclosure->sep_id = buffer->SEPTargetID;
861 enclosure->sep_channel = buffer->SEPBus;
864 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
871 mptsas_slave_configure(struct scsi_device *sdev)
874 if (sdev->channel == MPTSAS_RAID_CHANNEL)
877 sas_read_port_mode_page(sdev);
880 return mptscsih_slave_configure(sdev);
884 mptsas_target_alloc(struct scsi_target *starget)
886 struct Scsi_Host *host = dev_to_shost(&starget->dev);
887 MPT_SCSI_HOST *hd = shost_priv(host);
890 struct sas_rphy *rphy;
891 struct mptsas_portinfo *p;
893 MPT_ADAPTER *ioc = hd->ioc;
895 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
899 vtarget->starget = starget;
900 vtarget->ioc_id = ioc->id;
901 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
906 * RAID volumes placed beyond the last expected port.
908 if (starget->channel == MPTSAS_RAID_CHANNEL) {
909 for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
910 if (id == ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID)
911 channel = ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus;
915 rphy = dev_to_rphy(starget->dev.parent);
916 mutex_lock(&ioc->sas_topology_mutex);
917 list_for_each_entry(p, &ioc->sas_topology, list) {
918 for (i = 0; i < p->num_phys; i++) {
919 if (p->phy_info[i].attached.sas_address !=
920 rphy->identify.sas_address)
922 id = p->phy_info[i].attached.id;
923 channel = p->phy_info[i].attached.channel;
924 mptsas_set_starget(&p->phy_info[i], starget);
927 * Exposing hidden raid components
929 if (mptscsih_is_phys_disk(ioc, channel, id)) {
930 id = mptscsih_raid_id_to_num(ioc,
933 MPT_TARGET_FLAGS_RAID_COMPONENT;
934 p->phy_info[i].attached.phys_disk_num = id;
936 mutex_unlock(&ioc->sas_topology_mutex);
940 mutex_unlock(&ioc->sas_topology_mutex);
947 vtarget->channel = channel;
948 starget->hostdata = vtarget;
953 mptsas_target_destroy(struct scsi_target *starget)
955 struct Scsi_Host *host = dev_to_shost(&starget->dev);
956 MPT_SCSI_HOST *hd = shost_priv(host);
957 struct sas_rphy *rphy;
958 struct mptsas_portinfo *p;
960 MPT_ADAPTER *ioc = hd->ioc;
962 if (!starget->hostdata)
965 if (starget->channel == MPTSAS_RAID_CHANNEL)
968 rphy = dev_to_rphy(starget->dev.parent);
969 list_for_each_entry(p, &ioc->sas_topology, list) {
970 for (i = 0; i < p->num_phys; i++) {
971 if (p->phy_info[i].attached.sas_address !=
972 rphy->identify.sas_address)
974 mptsas_set_starget(&p->phy_info[i], NULL);
980 kfree(starget->hostdata);
981 starget->hostdata = NULL;
986 mptsas_slave_alloc(struct scsi_device *sdev)
988 struct Scsi_Host *host = sdev->host;
989 MPT_SCSI_HOST *hd = shost_priv(host);
990 struct sas_rphy *rphy;
991 struct mptsas_portinfo *p;
993 struct scsi_target *starget;
995 MPT_ADAPTER *ioc = hd->ioc;
997 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
999 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
1000 ioc->name, sizeof(VirtDevice));
1003 starget = scsi_target(sdev);
1004 vdevice->vtarget = starget->hostdata;
1006 if (sdev->channel == MPTSAS_RAID_CHANNEL)
1009 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
1010 mutex_lock(&ioc->sas_topology_mutex);
1011 list_for_each_entry(p, &ioc->sas_topology, list) {
1012 for (i = 0; i < p->num_phys; i++) {
1013 if (p->phy_info[i].attached.sas_address !=
1014 rphy->identify.sas_address)
1016 vdevice->lun = sdev->lun;
1018 * Exposing hidden raid components
1020 if (mptscsih_is_phys_disk(ioc,
1021 p->phy_info[i].attached.channel,
1022 p->phy_info[i].attached.id))
1023 sdev->no_uld_attach = 1;
1024 mutex_unlock(&ioc->sas_topology_mutex);
1028 mutex_unlock(&ioc->sas_topology_mutex);
1034 vdevice->vtarget->num_luns++;
1035 sdev->hostdata = vdevice;
1040 mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1044 VirtDevice *vdevice = SCpnt->device->hostdata;
1046 if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
1047 SCpnt->result = DID_NO_CONNECT << 16;
1052 hd = shost_priv(SCpnt->device->host);
1055 if (ioc->sas_discovery_quiesce_io)
1056 return SCSI_MLQUEUE_HOST_BUSY;
1058 // scsi_print_command(SCpnt);
1060 return mptscsih_qcmd(SCpnt,done);
1064 static struct scsi_host_template mptsas_driver_template = {
1065 .module = THIS_MODULE,
1066 .proc_name = "mptsas",
1067 .proc_info = mptscsih_proc_info,
1068 .name = "MPT SPI Host",
1069 .info = mptscsih_info,
1070 .queuecommand = mptsas_qcmd,
1071 .target_alloc = mptsas_target_alloc,
1072 .slave_alloc = mptsas_slave_alloc,
1073 .slave_configure = mptsas_slave_configure,
1074 .target_destroy = mptsas_target_destroy,
1075 .slave_destroy = mptscsih_slave_destroy,
1076 .change_queue_depth = mptscsih_change_queue_depth,
1077 .eh_abort_handler = mptscsih_abort,
1078 .eh_device_reset_handler = mptscsih_dev_reset,
1079 .eh_bus_reset_handler = mptscsih_bus_reset,
1080 .eh_host_reset_handler = mptscsih_host_reset,
1081 .bios_param = mptscsih_bios_param,
1082 .can_queue = MPT_FC_CAN_QUEUE,
1084 .sg_tablesize = MPT_SCSI_SG_DEPTH,
1085 .max_sectors = 8192,
1087 .use_clustering = ENABLE_CLUSTERING,
1088 .shost_attrs = mptscsih_host_attrs,
1091 static int mptsas_get_linkerrors(struct sas_phy *phy)
1093 MPT_ADAPTER *ioc = phy_to_ioc(phy);
1094 ConfigExtendedPageHeader_t hdr;
1096 SasPhyPage1_t *buffer;
1097 dma_addr_t dma_handle;
1100 /* FIXME: only have link errors on local phys */
1101 if (!scsi_is_sas_phy_local(phy))
1104 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
1105 hdr.ExtPageLength = 0;
1106 hdr.PageNumber = 1 /* page number 1*/;
1109 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1110 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
1112 cfg.cfghdr.ehdr = &hdr;
1114 cfg.pageAddr = phy->identify.phy_identifier;
1115 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1116 cfg.dir = 0; /* read */
1119 error = mpt_config(ioc, &cfg);
1122 if (!hdr.ExtPageLength)
1125 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1130 cfg.physAddr = dma_handle;
1131 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1133 error = mpt_config(ioc, &cfg);
1135 goto out_free_consistent;
1137 mptsas_print_phy_pg1(ioc, buffer);
1139 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
1140 phy->running_disparity_error_count =
1141 le32_to_cpu(buffer->RunningDisparityErrorCount);
1142 phy->loss_of_dword_sync_count =
1143 le32_to_cpu(buffer->LossDwordSynchCount);
1144 phy->phy_reset_problem_count =
1145 le32_to_cpu(buffer->PhyResetProblemCount);
1147 out_free_consistent:
1148 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1149 buffer, dma_handle);
1153 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
1154 MPT_FRAME_HDR *reply)
1156 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1157 if (reply != NULL) {
1158 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID;
1159 memcpy(ioc->sas_mgmt.reply, reply,
1160 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
1162 complete(&ioc->sas_mgmt.done);
1166 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
1168 MPT_ADAPTER *ioc = phy_to_ioc(phy);
1169 SasIoUnitControlRequest_t *req;
1170 SasIoUnitControlReply_t *reply;
1173 unsigned long timeleft;
1174 int error = -ERESTARTSYS;
1176 /* FIXME: fusion doesn't allow non-local phy reset */
1177 if (!scsi_is_sas_phy_local(phy))
1180 /* not implemented for expanders */
1181 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
1184 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
1187 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
1193 hdr = (MPIHeader_t *) mf;
1194 req = (SasIoUnitControlRequest_t *)mf;
1195 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
1196 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
1197 req->MsgContext = hdr->MsgContext;
1198 req->Operation = hard_reset ?
1199 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
1200 req->PhyNum = phy->identify.phy_identifier;
1202 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
1204 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
1207 /* On timeout reset the board */
1208 mpt_free_msg_frame(ioc, mf);
1209 mpt_HardResetHandler(ioc, CAN_SLEEP);
1214 /* a reply frame is expected */
1215 if ((ioc->sas_mgmt.status &
1216 MPT_MGMT_STATUS_RF_VALID) == 0) {
1221 /* process the completed Reply Message Frame */
1222 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
1223 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
1224 printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
1225 ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo);
1233 mutex_unlock(&ioc->sas_mgmt.mutex);
1239 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
1241 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
1243 struct mptsas_portinfo *p;
1244 struct mptsas_enclosure enclosure_info;
1245 u64 enclosure_handle;
1247 mutex_lock(&ioc->sas_topology_mutex);
1248 list_for_each_entry(p, &ioc->sas_topology, list) {
1249 for (i = 0; i < p->num_phys; i++) {
1250 if (p->phy_info[i].attached.sas_address ==
1251 rphy->identify.sas_address) {
1252 enclosure_handle = p->phy_info[i].
1253 attached.handle_enclosure;
1258 mutex_unlock(&ioc->sas_topology_mutex);
1262 mutex_unlock(&ioc->sas_topology_mutex);
1263 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
1264 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
1265 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
1266 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
1268 *identifier = enclosure_info.enclosure_logical_id;
1273 mptsas_get_bay_identifier(struct sas_rphy *rphy)
1275 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
1276 struct mptsas_portinfo *p;
1279 mutex_lock(&ioc->sas_topology_mutex);
1280 list_for_each_entry(p, &ioc->sas_topology, list) {
1281 for (i = 0; i < p->num_phys; i++) {
1282 if (p->phy_info[i].attached.sas_address ==
1283 rphy->identify.sas_address) {
1284 rc = p->phy_info[i].attached.slot;
1291 mutex_unlock(&ioc->sas_topology_mutex);
1295 static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1296 struct request *req)
1298 MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
1300 SmpPassthroughRequest_t *smpreq;
1301 struct request *rsp = req->next_rq;
1304 unsigned long timeleft;
1306 dma_addr_t dma_addr_in = 0;
1307 dma_addr_t dma_addr_out = 0;
1308 u64 sas_address = 0;
1311 printk(MYIOC_s_ERR_FMT "%s: the smp response space is missing\n",
1312 ioc->name, __func__);
1316 /* do we need to support multiple segments? */
1317 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
1318 printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n",
1319 ioc->name, __func__, req->bio->bi_vcnt, req->data_len,
1320 rsp->bio->bi_vcnt, rsp->data_len);
1324 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
1328 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
1334 smpreq = (SmpPassthroughRequest_t *)mf;
1335 memset(smpreq, 0, sizeof(*smpreq));
1337 smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4);
1338 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
1341 sas_address = rphy->identify.sas_address;
1343 struct mptsas_portinfo *port_info;
1345 mutex_lock(&ioc->sas_topology_mutex);
1346 port_info = mptsas_get_hba_portinfo(ioc);
1347 if (port_info && port_info->phy_info)
1349 port_info->phy_info[0].phy->identify.sas_address;
1350 mutex_unlock(&ioc->sas_topology_mutex);
1353 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
1356 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
1359 flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
1360 MPI_SGE_FLAGS_END_OF_BUFFER |
1361 MPI_SGE_FLAGS_DIRECTION)
1362 << MPI_SGE_FLAGS_SHIFT;
1363 flagsLength |= (req->data_len - 4);
1365 dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
1366 req->data_len, PCI_DMA_BIDIRECTIONAL);
1369 ioc->add_sge(psge, flagsLength, dma_addr_out);
1370 psge += (sizeof(u32) + sizeof(dma_addr_t));
1373 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
1374 flagsLength |= rsp->data_len + 4;
1375 dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio),
1376 rsp->data_len, PCI_DMA_BIDIRECTIONAL);
1379 ioc->add_sge(psge, flagsLength, dma_addr_in);
1381 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
1383 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
1385 printk(MYIOC_s_ERR_FMT "%s: smp timeout!\n", ioc->name, __func__);
1386 /* On timeout reset the board */
1387 mpt_HardResetHandler(ioc, CAN_SLEEP);
1393 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
1394 SmpPassthroughReply_t *smprep;
1396 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
1397 memcpy(req->sense, smprep, sizeof(*smprep));
1398 req->sense_len = sizeof(*smprep);
1400 rsp->data_len -= smprep->ResponseDataLength;
1402 printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
1403 ioc->name, __func__);
1408 pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len,
1409 PCI_DMA_BIDIRECTIONAL);
1411 pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len,
1412 PCI_DMA_BIDIRECTIONAL);
1415 mpt_free_msg_frame(ioc, mf);
1417 mutex_unlock(&ioc->sas_mgmt.mutex);
1422 static struct sas_function_template mptsas_transport_functions = {
1423 .get_linkerrors = mptsas_get_linkerrors,
1424 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
1425 .get_bay_identifier = mptsas_get_bay_identifier,
1426 .phy_reset = mptsas_phy_reset,
1427 .smp_handler = mptsas_smp_handler,
1430 static struct scsi_transport_template *mptsas_transport_template;
1433 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
1435 ConfigExtendedPageHeader_t hdr;
1437 SasIOUnitPage0_t *buffer;
1438 dma_addr_t dma_handle;
1441 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
1442 hdr.ExtPageLength = 0;
1446 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1447 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
1449 cfg.cfghdr.ehdr = &hdr;
1452 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1453 cfg.dir = 0; /* read */
1456 error = mpt_config(ioc, &cfg);
1459 if (!hdr.ExtPageLength) {
1464 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1471 cfg.physAddr = dma_handle;
1472 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1474 error = mpt_config(ioc, &cfg);
1476 goto out_free_consistent;
1478 port_info->num_phys = buffer->NumPhys;
1479 port_info->phy_info = kcalloc(port_info->num_phys,
1480 sizeof(*port_info->phy_info),GFP_KERNEL);
1481 if (!port_info->phy_info) {
1483 goto out_free_consistent;
1486 ioc->nvdata_version_persistent =
1487 le16_to_cpu(buffer->NvdataVersionPersistent);
1488 ioc->nvdata_version_default =
1489 le16_to_cpu(buffer->NvdataVersionDefault);
1491 for (i = 0; i < port_info->num_phys; i++) {
1492 mptsas_print_phy_data(ioc, &buffer->PhyData[i]);
1493 port_info->phy_info[i].phy_id = i;
1494 port_info->phy_info[i].port_id =
1495 buffer->PhyData[i].Port;
1496 port_info->phy_info[i].negotiated_link_rate =
1497 buffer->PhyData[i].NegotiatedLinkRate;
1498 port_info->phy_info[i].portinfo = port_info;
1499 port_info->phy_info[i].handle =
1500 le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
1503 out_free_consistent:
1504 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1505 buffer, dma_handle);
1511 mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
1513 ConfigExtendedPageHeader_t hdr;
1515 SasIOUnitPage1_t *buffer;
1516 dma_addr_t dma_handle;
1518 u16 device_missing_delay;
1520 memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
1521 memset(&cfg, 0, sizeof(CONFIGPARMS));
1523 cfg.cfghdr.ehdr = &hdr;
1524 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1526 cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1527 cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
1528 cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION;
1529 cfg.cfghdr.ehdr->PageNumber = 1;
1531 error = mpt_config(ioc, &cfg);
1534 if (!hdr.ExtPageLength) {
1539 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1546 cfg.physAddr = dma_handle;
1547 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1549 error = mpt_config(ioc, &cfg);
1551 goto out_free_consistent;
1553 ioc->io_missing_delay =
1554 le16_to_cpu(buffer->IODeviceMissingDelay);
1555 device_missing_delay = le16_to_cpu(buffer->ReportDeviceMissingDelay);
1556 ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ?
1557 (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 :
1558 device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
1560 out_free_consistent:
1561 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1562 buffer, dma_handle);
1568 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
1569 u32 form, u32 form_specific)
1571 ConfigExtendedPageHeader_t hdr;
1573 SasPhyPage0_t *buffer;
1574 dma_addr_t dma_handle;
1577 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
1578 hdr.ExtPageLength = 0;
1582 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1583 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
1585 cfg.cfghdr.ehdr = &hdr;
1586 cfg.dir = 0; /* read */
1589 /* Get Phy Pg 0 for each Phy. */
1591 cfg.pageAddr = form + form_specific;
1592 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1594 error = mpt_config(ioc, &cfg);
1598 if (!hdr.ExtPageLength) {
1603 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1610 cfg.physAddr = dma_handle;
1611 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1613 error = mpt_config(ioc, &cfg);
1615 goto out_free_consistent;
1617 mptsas_print_phy_pg0(ioc, buffer);
1619 phy_info->hw_link_rate = buffer->HwLinkRate;
1620 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
1621 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
1622 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
1624 out_free_consistent:
1625 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1626 buffer, dma_handle);
1632 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
1633 u32 form, u32 form_specific)
1635 ConfigExtendedPageHeader_t hdr;
1637 SasDevicePage0_t *buffer;
1638 dma_addr_t dma_handle;
1642 if (ioc->sas_discovery_runtime &&
1643 mptsas_is_end_device(device_info))
1646 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
1647 hdr.ExtPageLength = 0;
1651 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1652 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
1654 cfg.cfghdr.ehdr = &hdr;
1655 cfg.pageAddr = form + form_specific;
1657 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1658 cfg.dir = 0; /* read */
1661 memset(device_info, 0, sizeof(struct mptsas_devinfo));
1662 error = mpt_config(ioc, &cfg);
1665 if (!hdr.ExtPageLength) {
1670 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1677 cfg.physAddr = dma_handle;
1678 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1680 error = mpt_config(ioc, &cfg);
1682 goto out_free_consistent;
1684 mptsas_print_device_pg0(ioc, buffer);
1686 device_info->handle = le16_to_cpu(buffer->DevHandle);
1687 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
1688 device_info->handle_enclosure =
1689 le16_to_cpu(buffer->EnclosureHandle);
1690 device_info->slot = le16_to_cpu(buffer->Slot);
1691 device_info->phy_id = buffer->PhyNum;
1692 device_info->port_id = buffer->PhysicalPort;
1693 device_info->id = buffer->TargetID;
1694 device_info->phys_disk_num = ~0;
1695 device_info->channel = buffer->Bus;
1696 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
1697 device_info->sas_address = le64_to_cpu(sas_address);
1698 device_info->device_info =
1699 le32_to_cpu(buffer->DeviceInfo);
1701 out_free_consistent:
1702 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1703 buffer, dma_handle);
1709 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
1710 u32 form, u32 form_specific)
1712 ConfigExtendedPageHeader_t hdr;
1714 SasExpanderPage0_t *buffer;
1715 dma_addr_t dma_handle;
1718 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
1719 hdr.ExtPageLength = 0;
1723 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1724 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
1726 cfg.cfghdr.ehdr = &hdr;
1728 cfg.pageAddr = form + form_specific;
1729 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1730 cfg.dir = 0; /* read */
1733 memset(port_info, 0, sizeof(struct mptsas_portinfo));
1734 error = mpt_config(ioc, &cfg);
1738 if (!hdr.ExtPageLength) {
1743 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1750 cfg.physAddr = dma_handle;
1751 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1753 error = mpt_config(ioc, &cfg);
1755 goto out_free_consistent;
1757 if (!buffer->NumPhys) {
1759 goto out_free_consistent;
1762 /* save config data */
1763 port_info->num_phys = buffer->NumPhys;
1764 port_info->phy_info = kcalloc(port_info->num_phys,
1765 sizeof(*port_info->phy_info),GFP_KERNEL);
1766 if (!port_info->phy_info) {
1768 goto out_free_consistent;
1771 for (i = 0; i < port_info->num_phys; i++) {
1772 port_info->phy_info[i].portinfo = port_info;
1773 port_info->phy_info[i].handle =
1774 le16_to_cpu(buffer->DevHandle);
1777 out_free_consistent:
1778 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1779 buffer, dma_handle);
1785 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
1786 u32 form, u32 form_specific)
1788 ConfigExtendedPageHeader_t hdr;
1790 SasExpanderPage1_t *buffer;
1791 dma_addr_t dma_handle;
1794 if (ioc->sas_discovery_runtime &&
1795 mptsas_is_end_device(&phy_info->attached))
1798 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
1799 hdr.ExtPageLength = 0;
1803 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1804 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
1806 cfg.cfghdr.ehdr = &hdr;
1808 cfg.pageAddr = form + form_specific;
1809 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1810 cfg.dir = 0; /* read */
1813 error = mpt_config(ioc, &cfg);
1817 if (!hdr.ExtPageLength) {
1822 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1829 cfg.physAddr = dma_handle;
1830 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1832 error = mpt_config(ioc, &cfg);
1834 goto out_free_consistent;
1837 mptsas_print_expander_pg1(ioc, buffer);
1839 /* save config data */
1840 phy_info->phy_id = buffer->PhyIdentifier;
1841 phy_info->port_id = buffer->PhysicalPort;
1842 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
1843 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
1844 phy_info->hw_link_rate = buffer->HwLinkRate;
1845 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
1846 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
1848 out_free_consistent:
1849 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1850 buffer, dma_handle);
1856 mptsas_parse_device_info(struct sas_identify *identify,
1857 struct mptsas_devinfo *device_info)
1861 identify->sas_address = device_info->sas_address;
1862 identify->phy_identifier = device_info->phy_id;
1865 * Fill in Phy Initiator Port Protocol.
1866 * Bits 6:3, more than one bit can be set, fall through cases.
1868 protocols = device_info->device_info & 0x78;
1869 identify->initiator_port_protocols = 0;
1870 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
1871 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
1872 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1873 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
1874 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
1875 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
1876 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
1877 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
1880 * Fill in Phy Target Port Protocol.
1881 * Bits 10:7, more than one bit can be set, fall through cases.
1883 protocols = device_info->device_info & 0x780;
1884 identify->target_port_protocols = 0;
1885 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1886 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
1887 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
1888 identify->target_port_protocols |= SAS_PROTOCOL_STP;
1889 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
1890 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
1891 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1892 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
1895 * Fill in Attached device type.
1897 switch (device_info->device_info &
1898 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
1899 case MPI_SAS_DEVICE_INFO_NO_DEVICE:
1900 identify->device_type = SAS_PHY_UNUSED;
1902 case MPI_SAS_DEVICE_INFO_END_DEVICE:
1903 identify->device_type = SAS_END_DEVICE;
1905 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
1906 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
1908 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
1909 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
1914 static int mptsas_probe_one_phy(struct device *dev,
1915 struct mptsas_phyinfo *phy_info, int index, int local)
1918 struct sas_phy *phy;
1919 struct sas_port *port;
1927 if (!phy_info->phy) {
1928 phy = sas_phy_alloc(dev, index);
1934 phy = phy_info->phy;
1936 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
1939 * Set Negotiated link rate.
1941 switch (phy_info->negotiated_link_rate) {
1942 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
1943 phy->negotiated_linkrate = SAS_PHY_DISABLED;
1945 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
1946 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
1948 case MPI_SAS_IOUNIT0_RATE_1_5:
1949 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
1951 case MPI_SAS_IOUNIT0_RATE_3_0:
1952 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
1954 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
1955 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
1957 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
1962 * Set Max hardware link rate.
1964 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
1965 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
1966 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
1968 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
1969 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
1976 * Set Max programmed link rate.
1978 switch (phy_info->programmed_link_rate &
1979 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
1980 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
1981 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
1983 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
1984 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
1991 * Set Min hardware link rate.
1993 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
1994 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
1995 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
1997 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
1998 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
2005 * Set Min programmed link rate.
2007 switch (phy_info->programmed_link_rate &
2008 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
2009 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
2010 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
2012 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
2013 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
2019 if (!phy_info->phy) {
2021 error = sas_phy_add(phy);
2026 phy_info->phy = phy;
2029 if (!phy_info->attached.handle ||
2030 !phy_info->port_details)
2033 port = mptsas_get_port(phy_info);
2034 ioc = phy_to_ioc(phy_info->phy);
2036 if (phy_info->sas_port_add_phy) {
2039 port = sas_port_alloc_num(dev);
2044 error = sas_port_add(port);
2046 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2047 "%s: exit at line=%d\n", ioc->name,
2048 __func__, __LINE__));
2051 mptsas_set_port(ioc, phy_info, port);
2052 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2053 "sas_port_alloc: port=%p dev=%p port_id=%d\n",
2054 ioc->name, port, dev, port->port_identifier));
2056 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_port_add_phy: phy_id=%d\n",
2057 ioc->name, phy_info->phy_id));
2058 sas_port_add_phy(port, phy_info->phy);
2059 phy_info->sas_port_add_phy = 0;
2062 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
2064 struct sas_rphy *rphy;
2065 struct device *parent;
2066 struct sas_identify identify;
2068 parent = dev->parent->parent;
2070 * Let the hotplug_work thread handle processing
2071 * the adding/removing of devices that occur
2072 * after start of day.
2074 if (ioc->sas_discovery_runtime &&
2075 mptsas_is_end_device(&phy_info->attached))
2078 mptsas_parse_device_info(&identify, &phy_info->attached);
2079 if (scsi_is_host_device(parent)) {
2080 struct mptsas_portinfo *port_info;
2083 mutex_lock(&ioc->sas_topology_mutex);
2084 port_info = mptsas_get_hba_portinfo(ioc);
2085 mutex_unlock(&ioc->sas_topology_mutex);
2087 for (i = 0; i < port_info->num_phys; i++)
2088 if (port_info->phy_info[i].identify.sas_address ==
2089 identify.sas_address) {
2090 sas_port_mark_backlink(port);
2094 } else if (scsi_is_sas_rphy(parent)) {
2095 struct sas_rphy *parent_rphy = dev_to_rphy(parent);
2096 if (identify.sas_address ==
2097 parent_rphy->identify.sas_address) {
2098 sas_port_mark_backlink(port);
2103 switch (identify.device_type) {
2104 case SAS_END_DEVICE:
2105 rphy = sas_end_device_alloc(port);
2107 case SAS_EDGE_EXPANDER_DEVICE:
2108 case SAS_FANOUT_EXPANDER_DEVICE:
2109 rphy = sas_expander_alloc(port, identify.device_type);
2116 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2117 "%s: exit at line=%d\n", ioc->name,
2118 __func__, __LINE__));
2122 rphy->identify = identify;
2123 error = sas_rphy_add(rphy);
2125 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2126 "%s: exit at line=%d\n", ioc->name,
2127 __func__, __LINE__));
2128 sas_rphy_free(rphy);
2131 mptsas_set_rphy(ioc, phy_info, rphy);
2139 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
2141 struct mptsas_portinfo *port_info, *hba;
2142 int error = -ENOMEM, i;
2144 hba = kzalloc(sizeof(*port_info), GFP_KERNEL);
2148 error = mptsas_sas_io_unit_pg0(ioc, hba);
2150 goto out_free_port_info;
2152 mptsas_sas_io_unit_pg1(ioc);
2153 mutex_lock(&ioc->sas_topology_mutex);
2154 port_info = mptsas_get_hba_portinfo(ioc);
2157 list_add_tail(&port_info->list, &ioc->sas_topology);
2159 for (i = 0; i < hba->num_phys; i++) {
2160 port_info->phy_info[i].negotiated_link_rate =
2161 hba->phy_info[i].negotiated_link_rate;
2162 port_info->phy_info[i].handle =
2163 hba->phy_info[i].handle;
2164 port_info->phy_info[i].port_id =
2165 hba->phy_info[i].port_id;
2167 kfree(hba->phy_info);
2171 mutex_unlock(&ioc->sas_topology_mutex);
2172 for (i = 0; i < port_info->num_phys; i++) {
2173 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
2174 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
2175 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
2177 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
2178 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2179 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2180 port_info->phy_info[i].handle);
2181 port_info->phy_info[i].identify.phy_id =
2182 port_info->phy_info[i].phy_id = i;
2183 if (port_info->phy_info[i].attached.handle)
2184 mptsas_sas_device_pg0(ioc,
2185 &port_info->phy_info[i].attached,
2186 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2187 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2188 port_info->phy_info[i].attached.handle);
2191 mptsas_setup_wide_ports(ioc, port_info);
2193 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
2194 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
2195 &port_info->phy_info[i], ioc->sas_index, 1);
2206 mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
2208 struct mptsas_portinfo *port_info, *p, *ex;
2209 struct device *parent;
2210 struct sas_rphy *rphy;
2211 int error = -ENOMEM, i, j;
2213 ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
2217 error = mptsas_sas_expander_pg0(ioc, ex,
2218 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
2219 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle);
2221 goto out_free_port_info;
2223 *handle = ex->phy_info[0].handle;
2225 mutex_lock(&ioc->sas_topology_mutex);
2226 port_info = mptsas_find_portinfo_by_handle(ioc, *handle);
2229 list_add_tail(&port_info->list, &ioc->sas_topology);
2231 for (i = 0; i < ex->num_phys; i++) {
2232 port_info->phy_info[i].handle =
2233 ex->phy_info[i].handle;
2234 port_info->phy_info[i].port_id =
2235 ex->phy_info[i].port_id;
2237 kfree(ex->phy_info);
2241 mutex_unlock(&ioc->sas_topology_mutex);
2243 for (i = 0; i < port_info->num_phys; i++) {
2244 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
2245 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
2246 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
2248 if (port_info->phy_info[i].identify.handle) {
2249 mptsas_sas_device_pg0(ioc,
2250 &port_info->phy_info[i].identify,
2251 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2252 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2253 port_info->phy_info[i].identify.handle);
2254 port_info->phy_info[i].identify.phy_id =
2255 port_info->phy_info[i].phy_id;
2258 if (port_info->phy_info[i].attached.handle) {
2259 mptsas_sas_device_pg0(ioc,
2260 &port_info->phy_info[i].attached,
2261 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2262 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2263 port_info->phy_info[i].attached.handle);
2264 port_info->phy_info[i].attached.phy_id =
2265 port_info->phy_info[i].phy_id;
2269 parent = &ioc->sh->shost_gendev;
2270 for (i = 0; i < port_info->num_phys; i++) {
2271 mutex_lock(&ioc->sas_topology_mutex);
2272 list_for_each_entry(p, &ioc->sas_topology, list) {
2273 for (j = 0; j < p->num_phys; j++) {
2274 if (port_info->phy_info[i].identify.handle !=
2275 p->phy_info[j].attached.handle)
2277 rphy = mptsas_get_rphy(&p->phy_info[j]);
2278 parent = &rphy->dev;
2281 mutex_unlock(&ioc->sas_topology_mutex);
2284 mptsas_setup_wide_ports(ioc, port_info);
2286 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
2287 mptsas_probe_one_phy(parent, &port_info->phy_info[i],
2294 kfree(ex->phy_info);
2302 * mptsas_delete_expander_phys
2305 * This will traverse topology, and remove expanders
2306 * that are no longer present
2309 mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
2311 struct mptsas_portinfo buffer;
2312 struct mptsas_portinfo *port_info, *n, *parent;
2313 struct mptsas_phyinfo *phy_info;
2314 struct sas_port * port;
2316 u64 expander_sas_address;
2318 mutex_lock(&ioc->sas_topology_mutex);
2319 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
2321 if (!(port_info->phy_info[0].identify.device_info &
2322 MPI_SAS_DEVICE_INFO_SMP_TARGET))
2325 if (mptsas_sas_expander_pg0(ioc, &buffer,
2326 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
2327 MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
2328 port_info->phy_info[0].handle)) {
2331 * Obtain the port_info instance to the parent port
2333 parent = mptsas_find_portinfo_by_handle(ioc,
2334 port_info->phy_info[0].identify.handle_parent);
2339 expander_sas_address =
2340 port_info->phy_info[0].identify.sas_address;
2343 * Delete rphys in the parent that point
2344 * to this expander. The transport layer will
2345 * cleanup all the children.
2347 phy_info = parent->phy_info;
2348 for (i = 0; i < parent->num_phys; i++, phy_info++) {
2349 port = mptsas_get_port(phy_info);
2352 if (phy_info->attached.sas_address !=
2353 expander_sas_address)
2356 dev_printk(KERN_DEBUG, &port->dev,
2357 MYIOC_s_FMT "delete port (%d)\n", ioc->name,
2358 port->port_identifier));
2359 sas_port_delete(port);
2360 mptsas_port_delete(ioc, phy_info->port_details);
2364 phy_info = port_info->phy_info;
2365 for (i = 0; i < port_info->num_phys; i++, phy_info++)
2366 mptsas_port_delete(ioc, phy_info->port_details);
2368 list_del(&port_info->list);
2369 kfree(port_info->phy_info);
2373 * Free this memory allocated from inside
2374 * mptsas_sas_expander_pg0
2376 kfree(buffer.phy_info);
2378 mutex_unlock(&ioc->sas_topology_mutex);
2382 * Start of day discovery
2385 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
2387 u32 handle = 0xFFFF;
2390 mutex_lock(&ioc->sas_discovery_mutex);
2391 mptsas_probe_hba_phys(ioc);
2392 while (!mptsas_probe_expander_phys(ioc, &handle))
2395 Reporting RAID volumes.
2397 if (!ioc->ir_firmware)
2399 if (!ioc->raid_data.pIocPg2)
2401 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
2403 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
2404 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
2405 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
2408 mutex_unlock(&ioc->sas_discovery_mutex);
2412 * Work queue thread to handle Runtime discovery
2413 * Mere purpose is the hot add/delete of expanders
2417 __mptsas_discovery_work(MPT_ADAPTER *ioc)
2419 u32 handle = 0xFFFF;
2421 ioc->sas_discovery_runtime=1;
2422 mptsas_delete_expander_phys(ioc);
2423 mptsas_probe_hba_phys(ioc);
2424 while (!mptsas_probe_expander_phys(ioc, &handle))
2426 ioc->sas_discovery_runtime=0;
2430 * Work queue thread to handle Runtime discovery
2431 * Mere purpose is the hot add/delete of expanders
2435 mptsas_discovery_work(struct work_struct *work)
2437 struct mptsas_discovery_event *ev =
2438 container_of(work, struct mptsas_discovery_event, work);
2439 MPT_ADAPTER *ioc = ev->ioc;
2441 mutex_lock(&ioc->sas_discovery_mutex);
2442 __mptsas_discovery_work(ioc);
2443 mutex_unlock(&ioc->sas_discovery_mutex);
2447 static struct mptsas_phyinfo *
2448 mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
2450 struct mptsas_portinfo *port_info;
2451 struct mptsas_phyinfo *phy_info = NULL;
2454 mutex_lock(&ioc->sas_topology_mutex);
2455 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2456 for (i = 0; i < port_info->num_phys; i++) {
2457 if (!mptsas_is_end_device(
2458 &port_info->phy_info[i].attached))
2460 if (port_info->phy_info[i].attached.sas_address
2463 phy_info = &port_info->phy_info[i];
2467 mutex_unlock(&ioc->sas_topology_mutex);
2471 static struct mptsas_phyinfo *
2472 mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u8 channel, u8 id)
2474 struct mptsas_portinfo *port_info;
2475 struct mptsas_phyinfo *phy_info = NULL;
2478 mutex_lock(&ioc->sas_topology_mutex);
2479 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2480 for (i = 0; i < port_info->num_phys; i++) {
2481 if (!mptsas_is_end_device(
2482 &port_info->phy_info[i].attached))
2484 if (port_info->phy_info[i].attached.id != id)
2486 if (port_info->phy_info[i].attached.channel != channel)
2488 phy_info = &port_info->phy_info[i];
2492 mutex_unlock(&ioc->sas_topology_mutex);
2496 static struct mptsas_phyinfo *
2497 mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
2499 struct mptsas_portinfo *port_info;
2500 struct mptsas_phyinfo *phy_info = NULL;
2503 mutex_lock(&ioc->sas_topology_mutex);
2504 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2505 for (i = 0; i < port_info->num_phys; i++) {
2506 if (!mptsas_is_end_device(
2507 &port_info->phy_info[i].attached))
2509 if (port_info->phy_info[i].attached.phys_disk_num == ~0)
2511 if (port_info->phy_info[i].attached.phys_disk_num != id)
2513 if (port_info->phy_info[i].attached.channel != channel)
2515 phy_info = &port_info->phy_info[i];
2519 mutex_unlock(&ioc->sas_topology_mutex);
2524 * Work queue thread to clear the persitency table
2527 mptsas_persist_clear_table(struct work_struct *work)
2529 MPT_ADAPTER *ioc = container_of(work, MPT_ADAPTER, sas_persist_task);
2531 mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT);
2535 mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
2539 sdev->no_uld_attach = data ? 1 : 0;
2540 rc = scsi_device_reprobe(sdev);
2544 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
2546 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
2547 mptsas_reprobe_lun);
2551 mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
2554 ConfigPageHeader_t hdr;
2555 dma_addr_t dma_handle;
2556 pRaidVolumePage0_t buffer = NULL;
2557 RaidPhysDiskPage0_t phys_disk;
2559 struct mptsas_hotplug_event *ev;
2561 memset(&cfg, 0 , sizeof(CONFIGPARMS));
2562 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
2563 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
2564 cfg.pageAddr = (channel << 8) + id;
2565 cfg.cfghdr.hdr = &hdr;
2566 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2568 if (mpt_config(ioc, &cfg) != 0)
2571 if (!hdr.PageLength)
2574 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
2580 cfg.physAddr = dma_handle;
2581 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2583 if (mpt_config(ioc, &cfg) != 0)
2586 if (!(buffer->VolumeStatus.Flags &
2587 MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
2590 if (!buffer->NumPhysDisks)
2593 for (i = 0; i < buffer->NumPhysDisks; i++) {
2595 if (mpt_raid_phys_disk_pg0(ioc,
2596 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
2599 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2601 printk(MYIOC_s_WARN_FMT "mptsas: lost hotplug event\n", ioc->name);
2605 INIT_WORK(&ev->work, mptsas_hotplug_work);
2607 ev->id = phys_disk.PhysDiskID;
2608 ev->channel = phys_disk.PhysDiskBus;
2609 ev->phys_disk_num_valid = 1;
2610 ev->phys_disk_num = phys_disk.PhysDiskNum;
2611 ev->event_type = MPTSAS_ADD_DEVICE;
2612 schedule_work(&ev->work);
2617 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
2621 * Work queue thread to handle SAS hotplug events
2624 mptsas_hotplug_work(struct work_struct *work)
2626 struct mptsas_hotplug_event *ev =
2627 container_of(work, struct mptsas_hotplug_event, work);
2629 MPT_ADAPTER *ioc = ev->ioc;
2630 struct mptsas_phyinfo *phy_info;
2631 struct sas_rphy *rphy;
2632 struct sas_port *port;
2633 struct scsi_device *sdev;
2634 struct scsi_target * starget;
2635 struct sas_identify identify;
2637 struct mptsas_devinfo sas_device;
2638 VirtTarget *vtarget;
2639 VirtDevice *vdevice;
2641 mutex_lock(&ioc->sas_discovery_mutex);
2642 switch (ev->event_type) {
2643 case MPTSAS_DEL_DEVICE:
2646 if (ev->phys_disk_num_valid) {
2647 if (ev->hidden_raid_component){
2648 if (mptsas_sas_device_pg0(ioc, &sas_device,
2649 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
2650 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2651 (ev->channel << 8) + ev->id)) {
2652 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2653 "%s: exit at line=%d\n", ioc->name,
2654 __func__, __LINE__));
2657 phy_info = mptsas_find_phyinfo_by_sas_address(
2658 ioc, sas_device.sas_address);
2660 phy_info = mptsas_find_phyinfo_by_phys_disk_num(
2661 ioc, ev->channel, ev->phys_disk_num);
2665 phy_info = mptsas_find_phyinfo_by_target(ioc,
2666 ev->channel, ev->id);
2669 * Sanity checks, for non-existing phys and remote rphys.
2672 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2673 "%s: exit at line=%d\n", ioc->name,
2674 __func__, __LINE__));
2677 if (!phy_info->port_details) {
2678 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2679 "%s: exit at line=%d\n", ioc->name,
2680 __func__, __LINE__));
2683 rphy = mptsas_get_rphy(phy_info);
2685 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2686 "%s: exit at line=%d\n", ioc->name,
2687 __func__, __LINE__));
2691 port = mptsas_get_port(phy_info);
2693 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2694 "%s: exit at line=%d\n", ioc->name,
2695 __func__, __LINE__));
2699 starget = mptsas_get_starget(phy_info);
2701 vtarget = starget->hostdata;
2704 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2705 "%s: exit at line=%d\n", ioc->name,
2706 __func__, __LINE__));
2711 * Handling RAID components
2713 if (ev->phys_disk_num_valid &&
2714 ev->hidden_raid_component) {
2715 printk(MYIOC_s_INFO_FMT
2716 "RAID Hidding: channel=%d, id=%d, "
2717 "physdsk %d \n", ioc->name, ev->channel,
2718 ev->id, ev->phys_disk_num);
2719 vtarget->id = ev->phys_disk_num;
2721 MPT_TARGET_FLAGS_RAID_COMPONENT;
2722 mptsas_reprobe_target(starget, 1);
2723 phy_info->attached.phys_disk_num =
2729 if (phy_info->attached.device_info &
2730 MPI_SAS_DEVICE_INFO_SSP_TARGET)
2732 if (phy_info->attached.device_info &
2733 MPI_SAS_DEVICE_INFO_STP_TARGET)
2735 if (phy_info->attached.device_info &
2736 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
2739 printk(MYIOC_s_INFO_FMT
2740 "removing %s device, channel %d, id %d, phy %d\n",
2741 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
2742 dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
2743 "delete port (%d)\n", ioc->name, port->port_identifier);
2744 sas_port_delete(port);
2745 mptsas_port_delete(ioc, phy_info->port_details);
2747 case MPTSAS_ADD_DEVICE:
2749 if (ev->phys_disk_num_valid)
2750 mpt_findImVolumes(ioc);
2753 * Refresh sas device pg0 data
2755 if (mptsas_sas_device_pg0(ioc, &sas_device,
2756 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
2757 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2758 (ev->channel << 8) + ev->id)) {
2759 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2760 "%s: exit at line=%d\n", ioc->name,
2761 __func__, __LINE__));
2765 __mptsas_discovery_work(ioc);
2767 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
2768 sas_device.sas_address);
2770 if (!phy_info || !phy_info->port_details) {
2771 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2772 "%s: exit at line=%d\n", ioc->name,
2773 __func__, __LINE__));
2777 starget = mptsas_get_starget(phy_info);
2778 if (starget && (!ev->hidden_raid_component)){
2780 vtarget = starget->hostdata;
2783 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2784 "%s: exit at line=%d\n", ioc->name,
2785 __func__, __LINE__));
2789 * Handling RAID components
2791 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2792 printk(MYIOC_s_INFO_FMT
2793 "RAID Exposing: channel=%d, id=%d, "
2794 "physdsk %d \n", ioc->name, ev->channel,
2795 ev->id, ev->phys_disk_num);
2797 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
2798 vtarget->id = ev->id;
2799 mptsas_reprobe_target(starget, 0);
2800 phy_info->attached.phys_disk_num = ~0;
2805 if (mptsas_get_rphy(phy_info)) {
2806 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2807 "%s: exit at line=%d\n", ioc->name,
2808 __func__, __LINE__));
2809 if (ev->channel) printk("%d\n", __LINE__);
2813 port = mptsas_get_port(phy_info);
2815 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2816 "%s: exit at line=%d\n", ioc->name,
2817 __func__, __LINE__));
2820 memcpy(&phy_info->attached, &sas_device,
2821 sizeof(struct mptsas_devinfo));
2823 if (phy_info->attached.device_info &
2824 MPI_SAS_DEVICE_INFO_SSP_TARGET)
2826 if (phy_info->attached.device_info &
2827 MPI_SAS_DEVICE_INFO_STP_TARGET)
2829 if (phy_info->attached.device_info &
2830 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
2833 printk(MYIOC_s_INFO_FMT
2834 "attaching %s device, channel %d, id %d, phy %d\n",
2835 ioc->name, ds, ev->channel, ev->id, ev->phy_id);
2837 mptsas_parse_device_info(&identify, &phy_info->attached);
2838 rphy = sas_end_device_alloc(port);
2840 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2841 "%s: exit at line=%d\n", ioc->name,
2842 __func__, __LINE__));
2843 break; /* non-fatal: an rphy can be added later */
2846 rphy->identify = identify;
2847 if (sas_rphy_add(rphy)) {
2848 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2849 "%s: exit at line=%d\n", ioc->name,
2850 __func__, __LINE__));
2851 sas_rphy_free(rphy);
2854 mptsas_set_rphy(ioc, phy_info, rphy);
2856 case MPTSAS_ADD_RAID:
2857 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
2860 scsi_device_put(sdev);
2863 printk(MYIOC_s_INFO_FMT
2864 "attaching raid volume, channel %d, id %d\n",
2865 ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
2866 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, ev->id, 0);
2867 mpt_findImVolumes(ioc);
2869 case MPTSAS_DEL_RAID:
2870 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
2874 printk(MYIOC_s_INFO_FMT
2875 "removing raid volume, channel %d, id %d\n",
2876 ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
2877 vdevice = sdev->hostdata;
2878 scsi_remove_device(sdev);
2879 scsi_device_put(sdev);
2880 mpt_findImVolumes(ioc);
2882 case MPTSAS_ADD_INACTIVE_VOLUME:
2883 mptsas_adding_inactive_raid_components(ioc,
2884 ev->channel, ev->id);
2886 case MPTSAS_IGNORE_EVENT:
2891 mutex_unlock(&ioc->sas_discovery_mutex);
2896 mptsas_send_sas_event(MPT_ADAPTER *ioc,
2897 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
2899 struct mptsas_hotplug_event *ev;
2900 u32 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
2904 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
2905 MPI_SAS_DEVICE_INFO_STP_TARGET |
2906 MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0)
2909 switch (sas_event_data->ReasonCode) {
2910 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
2912 mptsas_target_reset_queue(ioc, sas_event_data);
2915 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
2916 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2918 printk(MYIOC_s_WARN_FMT "lost hotplug event\n", ioc->name);
2922 INIT_WORK(&ev->work, mptsas_hotplug_work);
2924 ev->handle = le16_to_cpu(sas_event_data->DevHandle);
2926 le16_to_cpu(sas_event_data->ParentDevHandle);
2927 ev->channel = sas_event_data->Bus;
2928 ev->id = sas_event_data->TargetID;
2929 ev->phy_id = sas_event_data->PhyNum;
2930 memcpy(&sas_address, &sas_event_data->SASAddress,
2932 ev->sas_address = le64_to_cpu(sas_address);
2933 ev->device_info = device_info;
2935 if (sas_event_data->ReasonCode &
2936 MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
2937 ev->event_type = MPTSAS_ADD_DEVICE;
2939 ev->event_type = MPTSAS_DEL_DEVICE;
2940 schedule_work(&ev->work);
2942 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
2944 * Persistent table is full.
2946 INIT_WORK(&ioc->sas_persist_task,
2947 mptsas_persist_clear_table);
2948 schedule_work(&ioc->sas_persist_task);
2951 * TODO, handle other events
2953 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
2954 case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
2955 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
2956 case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
2957 case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
2958 case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
2959 case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
2965 mptsas_send_raid_event(MPT_ADAPTER *ioc,
2966 EVENT_DATA_RAID *raid_event_data)
2968 struct mptsas_hotplug_event *ev;
2969 int status = le32_to_cpu(raid_event_data->SettingsStatus);
2970 int state = (status >> 8) & 0xff;
2972 if (ioc->bus_type != SAS)
2975 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2977 printk(MYIOC_s_WARN_FMT "lost hotplug event\n", ioc->name);
2981 INIT_WORK(&ev->work, mptsas_hotplug_work);
2983 ev->id = raid_event_data->VolumeID;
2984 ev->channel = raid_event_data->VolumeBus;
2985 ev->event_type = MPTSAS_IGNORE_EVENT;
2987 switch (raid_event_data->ReasonCode) {
2988 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
2989 ev->phys_disk_num_valid = 1;
2990 ev->phys_disk_num = raid_event_data->PhysDiskNum;
2991 ev->event_type = MPTSAS_ADD_DEVICE;
2993 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
2994 ev->phys_disk_num_valid = 1;
2995 ev->phys_disk_num = raid_event_data->PhysDiskNum;
2996 ev->hidden_raid_component = 1;
2997 ev->event_type = MPTSAS_DEL_DEVICE;
2999 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
3001 case MPI_PD_STATE_ONLINE:
3002 case MPI_PD_STATE_NOT_COMPATIBLE:
3003 ev->phys_disk_num_valid = 1;
3004 ev->phys_disk_num = raid_event_data->PhysDiskNum;
3005 ev->hidden_raid_component = 1;
3006 ev->event_type = MPTSAS_ADD_DEVICE;
3008 case MPI_PD_STATE_MISSING:
3009 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
3010 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
3011 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
3012 ev->phys_disk_num_valid = 1;
3013 ev->phys_disk_num = raid_event_data->PhysDiskNum;
3014 ev->event_type = MPTSAS_DEL_DEVICE;
3020 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
3021 ev->event_type = MPTSAS_DEL_RAID;
3023 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
3024 ev->event_type = MPTSAS_ADD_RAID;
3026 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
3028 case MPI_RAIDVOL0_STATUS_STATE_FAILED:
3029 case MPI_RAIDVOL0_STATUS_STATE_MISSING:
3030 ev->event_type = MPTSAS_DEL_RAID;
3032 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
3033 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
3034 ev->event_type = MPTSAS_ADD_RAID;
3043 schedule_work(&ev->work);
3047 mptsas_send_discovery_event(MPT_ADAPTER *ioc,
3048 EVENT_DATA_SAS_DISCOVERY *discovery_data)
3050 struct mptsas_discovery_event *ev;
3051 u32 discovery_status;
3056 * This flag will be non-zero when firmware
3057 * kicks off discovery, and return to zero
3058 * once its completed.
3060 discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus);
3061 ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0;
3062 if (discovery_status)
3065 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
3068 INIT_WORK(&ev->work, mptsas_discovery_work);
3070 schedule_work(&ev->work);
3074 * mptsas_send_ir2_event - handle exposing hidden disk when
3075 * an inactive raid volume is added
3077 * @ioc: Pointer to MPT_ADAPTER structure
3082 mptsas_send_ir2_event(MPT_ADAPTER *ioc, PTR_MPI_EVENT_DATA_IR2 ir2_data)
3084 struct mptsas_hotplug_event *ev;
3086 if (ir2_data->ReasonCode !=
3087 MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED)
3090 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
3094 INIT_WORK(&ev->work, mptsas_hotplug_work);
3096 ev->id = ir2_data->TargetID;
3097 ev->channel = ir2_data->Bus;
3098 ev->event_type = MPTSAS_ADD_INACTIVE_VOLUME;
3100 schedule_work(&ev->work);
3104 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
3107 u8 event = le32_to_cpu(reply->Event) & 0xFF;
3113 * sas_discovery_ignore_events
3115 * This flag is to prevent anymore processing of
3116 * sas events once mptsas_remove function is called.
3118 if (ioc->sas_discovery_ignore_events) {
3119 rc = mptscsih_event_process(ioc, reply);
3124 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
3125 mptsas_send_sas_event(ioc,
3126 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
3128 case MPI_EVENT_INTEGRATED_RAID:
3129 mptsas_send_raid_event(ioc,
3130 (EVENT_DATA_RAID *)reply->Data);
3132 case MPI_EVENT_PERSISTENT_TABLE_FULL:
3133 INIT_WORK(&ioc->sas_persist_task,
3134 mptsas_persist_clear_table);
3135 schedule_work(&ioc->sas_persist_task);
3137 case MPI_EVENT_SAS_DISCOVERY:
3138 mptsas_send_discovery_event(ioc,
3139 (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
3142 mptsas_send_ir2_event(ioc,
3143 (PTR_MPI_EVENT_DATA_IR2)reply->Data);
3146 rc = mptscsih_event_process(ioc, reply);
3155 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
3157 struct Scsi_Host *sh;
3160 unsigned long flags;
3168 r = mpt_attach(pdev,id);
3172 ioc = pci_get_drvdata(pdev);
3173 ioc->DoneCtx = mptsasDoneCtx;
3174 ioc->TaskCtx = mptsasTaskCtx;
3175 ioc->InternalCtx = mptsasInternalCtx;
3177 /* Added sanity check on readiness of the MPT adapter.
3179 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
3180 printk(MYIOC_s_WARN_FMT
3181 "Skipping because it's not operational!\n",
3184 goto out_mptsas_probe;
3188 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
3191 goto out_mptsas_probe;
3194 /* Sanity check - ensure at least 1 port is INITIATOR capable
3197 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
3198 if (ioc->pfacts[ii].ProtocolFlags &
3199 MPI_PORTFACTS_PROTOCOL_INITIATOR)
3204 printk(MYIOC_s_WARN_FMT
3205 "Skipping ioc=%p because SCSI Initiator mode "
3206 "is NOT enabled!\n", ioc->name, ioc);
3210 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
3212 printk(MYIOC_s_WARN_FMT
3213 "Unable to register controller with SCSI subsystem\n",
3216 goto out_mptsas_probe;
3219 spin_lock_irqsave(&ioc->FreeQlock, flags);
3221 /* Attach the SCSI Host to the IOC structure
3229 /* set 16 byte cdb's */
3230 sh->max_cmd_len = 16;
3232 sh->max_id = ioc->pfacts[0].PortSCSIID;
3233 sh->max_lun = max_lun;
3235 sh->transportt = mptsas_transport_template;
3239 sh->unique_id = ioc->id;
3241 INIT_LIST_HEAD(&ioc->sas_topology);
3242 mutex_init(&ioc->sas_topology_mutex);
3243 mutex_init(&ioc->sas_discovery_mutex);
3244 mutex_init(&ioc->sas_mgmt.mutex);
3245 init_completion(&ioc->sas_mgmt.done);
3247 /* Verify that we won't exceed the maximum
3248 * number of chain buffers
3249 * We can optimize: ZZ = req_sz/sizeof(SGE)
3251 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
3252 * + (req_sz - 64)/sizeof(SGE)
3253 * A slightly different algorithm is required for
3256 scale = ioc->req_sz/ioc->SGE_size;
3257 if (ioc->sg_addr_size == sizeof(u64)) {
3258 numSGE = (scale - 1) *
3259 (ioc->facts.MaxChainDepth-1) + scale +
3260 (ioc->req_sz - 60) / ioc->SGE_size;
3262 numSGE = 1 + (scale - 1) *
3263 (ioc->facts.MaxChainDepth-1) + scale +
3264 (ioc->req_sz - 64) / ioc->SGE_size;
3267 if (numSGE < sh->sg_tablesize) {
3268 /* Reset this value */
3269 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3270 "Resetting sg_tablesize to %d from %d\n",
3271 ioc->name, numSGE, sh->sg_tablesize));
3272 sh->sg_tablesize = numSGE;
3275 hd = shost_priv(sh);
3278 /* SCSI needs scsi_cmnd lookup table!
3279 * (with size equal to req_depth*PtrSz!)
3281 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
3282 if (!ioc->ScsiLookup) {
3284 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
3285 goto out_mptsas_probe;
3287 spin_lock_init(&ioc->scsi_lookup_lock);
3289 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
3290 ioc->name, ioc->ScsiLookup));
3292 /* Clear the TM flags
3295 hd->tmState = TM_STATE_NONE;
3296 hd->abortSCpnt = NULL;
3298 /* Clear the pointer used to store
3299 * single-threaded commands, i.e., those
3300 * issued during a bus scan, dv and
3301 * configuration pages.
3305 /* Initialize this SCSI Hosts' timers
3306 * To use, set the timer expires field
3309 init_timer(&hd->timer);
3310 hd->timer.data = (unsigned long) hd;
3311 hd->timer.function = mptscsih_timer_expired;
3313 ioc->sas_data.ptClear = mpt_pt_clear;
3315 hd->last_queue_full = 0;
3316 INIT_LIST_HEAD(&hd->target_reset_list);
3317 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
3319 if (ioc->sas_data.ptClear==1) {
3320 mptbase_sas_persist_operation(
3321 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
3324 error = scsi_add_host(sh, &ioc->pcidev->dev);
3326 dprintk(ioc, printk(MYIOC_s_ERR_FMT
3327 "scsi_add_host failed\n", ioc->name));
3328 goto out_mptsas_probe;
3331 mptsas_scan_sas_topology(ioc);
3337 mptscsih_remove(pdev);
3342 mptsas_shutdown(struct pci_dev *pdev)
3344 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
3346 ioc->sas_discovery_quiesce_io = 0;
3349 static void __devexit mptsas_remove(struct pci_dev *pdev)
3351 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
3352 struct mptsas_portinfo *p, *n;
3355 mptsas_shutdown(pdev);
3357 ioc->sas_discovery_ignore_events = 1;
3358 sas_remove_host(ioc->sh);
3360 mutex_lock(&ioc->sas_topology_mutex);
3361 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
3363 for (i = 0 ; i < p->num_phys ; i++)
3364 mptsas_port_delete(ioc, p->phy_info[i].port_details);
3368 mutex_unlock(&ioc->sas_topology_mutex);
3370 mptscsih_remove(pdev);
3373 static struct pci_device_id mptsas_pci_table[] = {
3374 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
3375 PCI_ANY_ID, PCI_ANY_ID },
3376 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
3377 PCI_ANY_ID, PCI_ANY_ID },
3378 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
3379 PCI_ANY_ID, PCI_ANY_ID },
3380 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
3381 PCI_ANY_ID, PCI_ANY_ID },
3382 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
3383 PCI_ANY_ID, PCI_ANY_ID },
3384 {0} /* Terminating entry */
3386 MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
3389 static struct pci_driver mptsas_driver = {
3391 .id_table = mptsas_pci_table,
3392 .probe = mptsas_probe,
3393 .remove = __devexit_p(mptsas_remove),
3394 .shutdown = mptsas_shutdown,
3396 .suspend = mptscsih_suspend,
3397 .resume = mptscsih_resume,
3406 show_mptmod_ver(my_NAME, my_VERSION);
3408 mptsas_transport_template =
3409 sas_attach_transport(&mptsas_transport_functions);
3410 if (!mptsas_transport_template)
3413 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
3414 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER);
3416 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
3417 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
3418 mptsasDeviceResetCtx =
3419 mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER);
3421 mpt_event_register(mptsasDoneCtx, mptsas_event_process);
3422 mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset);
3424 error = pci_register_driver(&mptsas_driver);
3426 sas_release_transport(mptsas_transport_template);
3434 pci_unregister_driver(&mptsas_driver);
3435 sas_release_transport(mptsas_transport_template);
3437 mpt_reset_deregister(mptsasDoneCtx);
3438 mpt_event_deregister(mptsasDoneCtx);
3440 mpt_deregister(mptsasMgmtCtx);
3441 mpt_deregister(mptsasInternalCtx);
3442 mpt_deregister(mptsasTaskCtx);
3443 mpt_deregister(mptsasDoneCtx);
3444 mpt_deregister(mptsasDeviceResetCtx);
3447 module_init(mptsas_init);
3448 module_exit(mptsas_exit);