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;
556 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0)
560 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
562 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
563 "%s, no msg frames @%d!!\n", ioc->name,
564 __func__, __LINE__));
568 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
571 /* Format the Request
573 pScsiTm = (SCSITaskMgmt_t *) mf;
574 memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
575 pScsiTm->TargetID = id;
576 pScsiTm->Bus = channel;
577 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
578 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
579 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
581 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
583 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
584 "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
585 ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id));
587 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
593 mpt_clear_taskmgmt_in_progress_flag(ioc);
598 * mptsas_target_reset_queue
600 * Receive request for TARGET_RESET after recieving an firmware
601 * event NOT_RESPONDING_EVENT, then put command in link list
602 * and queue if task_queue already in use.
609 mptsas_target_reset_queue(MPT_ADAPTER *ioc,
610 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
612 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
613 VirtTarget *vtarget = NULL;
614 struct mptsas_target_reset_event *target_reset_list;
617 id = sas_event_data->TargetID;
618 channel = sas_event_data->Bus;
620 if (!(vtarget = mptsas_find_vtarget(ioc, channel, id)))
623 vtarget->deleted = 1; /* block IO */
625 target_reset_list = kzalloc(sizeof(*target_reset_list),
627 if (!target_reset_list) {
628 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
629 "%s, failed to allocate mem @%d..!!\n",
630 ioc->name, __func__, __LINE__));
634 memcpy(&target_reset_list->sas_event_data, sas_event_data,
635 sizeof(*sas_event_data));
636 list_add_tail(&target_reset_list->list, &hd->target_reset_list);
638 target_reset_list->time_count = jiffies;
640 if (mptsas_target_reset(ioc, channel, id)) {
641 target_reset_list->target_reset_issued = 1;
646 * mptsas_taskmgmt_complete - Completion for TARGET_RESET after
647 * NOT_RESPONDING_EVENT, enable work queue to finish off removing device
648 * from upper layers. then send next TARGET_RESET in the queue.
649 * @ioc: Pointer to MPT_ADAPTER structure
653 mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
655 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
656 struct list_head *head = &hd->target_reset_list;
657 struct mptsas_hotplug_event *ev;
658 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
661 struct mptsas_target_reset_event *target_reset_list;
662 SCSITaskMgmtReply_t *pScsiTmReply;
664 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: "
665 "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
667 pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
669 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
670 "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
671 "\ttask_type = 0x%02X, iocstatus = 0x%04X "
672 "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
673 "term_cmnds = %d\n", ioc->name,
674 pScsiTmReply->Bus, pScsiTmReply->TargetID,
675 pScsiTmReply->TaskType,
676 le16_to_cpu(pScsiTmReply->IOCStatus),
677 le32_to_cpu(pScsiTmReply->IOCLogInfo),
678 pScsiTmReply->ResponseCode,
679 le32_to_cpu(pScsiTmReply->TerminationCount)));
681 if (pScsiTmReply->ResponseCode)
682 mptscsih_taskmgmt_response_code(ioc,
683 pScsiTmReply->ResponseCode);
686 if (pScsiTmReply && (pScsiTmReply->TaskType ==
687 MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
688 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) {
689 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
690 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
691 memcpy(ioc->taskmgmt_cmds.reply, mr,
692 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
693 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
694 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
695 complete(&ioc->taskmgmt_cmds.done);
701 mpt_clear_taskmgmt_in_progress_flag(ioc);
703 if (list_empty(head))
706 target_reset_list = list_entry(head->next,
707 struct mptsas_target_reset_event, list);
709 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
710 "TaskMgmt: completed (%d seconds)\n",
711 ioc->name, jiffies_to_msecs(jiffies -
712 target_reset_list->time_count)/1000));
714 sas_event_data = &target_reset_list->sas_event_data;
715 id = pScsiTmReply->TargetID;
716 channel = pScsiTmReply->Bus;
717 target_reset_list->time_count = jiffies;
722 if (!target_reset_list->target_reset_issued) {
723 if (mptsas_target_reset(ioc, channel, id))
724 target_reset_list->target_reset_issued = 1;
729 * enable work queue to remove device from upper layers
731 list_del(&target_reset_list->list);
733 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
735 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n",
736 ioc->name,__func__, __LINE__));
740 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
743 INIT_WORK(&ev->work, mptsas_hotplug_work);
745 ev->handle = le16_to_cpu(sas_event_data->DevHandle);
747 le16_to_cpu(sas_event_data->ParentDevHandle);
748 ev->channel = channel;
750 ev->phy_id = sas_event_data->PhyNum;
751 memcpy(&sas_address, &sas_event_data->SASAddress,
753 ev->sas_address = le64_to_cpu(sas_address);
754 ev->device_info = le32_to_cpu(sas_event_data->DeviceInfo);
755 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
756 "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
757 ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id));
759 ev->event_type = MPTSAS_DEL_DEVICE;
760 schedule_work(&ev->work);
761 kfree(target_reset_list);
765 mpt_clear_taskmgmt_in_progress_flag(ioc);
770 * issue target reset to next device in the queue
773 head = &hd->target_reset_list;
774 if (list_empty(head))
777 target_reset_list = list_entry(head->next, struct mptsas_target_reset_event,
780 id = target_reset_list->sas_event_data.TargetID;
781 channel = target_reset_list->sas_event_data.Bus;
782 target_reset_list->time_count = jiffies;
784 if (mptsas_target_reset(ioc, channel, id))
785 target_reset_list->target_reset_issued = 1;
798 mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
801 struct mptsas_target_reset_event *target_reset_list, *n;
804 rc = mptscsih_ioc_reset(ioc, reset_phase);
806 if (ioc->bus_type != SAS)
809 if (reset_phase != MPT_IOC_POST_RESET)
812 if (!ioc->sh || !ioc->sh->hostdata)
814 hd = shost_priv(ioc->sh);
818 if (list_empty(&hd->target_reset_list))
821 /* flush the target_reset_list */
822 list_for_each_entry_safe(target_reset_list, n,
823 &hd->target_reset_list, list) {
824 list_del(&target_reset_list->list);
825 kfree(target_reset_list);
833 mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
834 u32 form, u32 form_specific)
836 ConfigExtendedPageHeader_t hdr;
838 SasEnclosurePage0_t *buffer;
839 dma_addr_t dma_handle;
841 __le64 le_identifier;
843 memset(&hdr, 0, sizeof(hdr));
844 hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
846 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
847 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
849 cfg.cfghdr.ehdr = &hdr;
851 cfg.pageAddr = form + form_specific;
852 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
853 cfg.dir = 0; /* read */
856 error = mpt_config(ioc, &cfg);
859 if (!hdr.ExtPageLength) {
864 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
871 cfg.physAddr = dma_handle;
872 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
874 error = mpt_config(ioc, &cfg);
876 goto out_free_consistent;
878 /* save config data */
879 memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
880 enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
881 enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
882 enclosure->flags = le16_to_cpu(buffer->Flags);
883 enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
884 enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
885 enclosure->start_id = buffer->StartTargetID;
886 enclosure->start_channel = buffer->StartBus;
887 enclosure->sep_id = buffer->SEPTargetID;
888 enclosure->sep_channel = buffer->SEPBus;
891 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
898 mptsas_slave_configure(struct scsi_device *sdev)
901 if (sdev->channel == MPTSAS_RAID_CHANNEL)
904 sas_read_port_mode_page(sdev);
907 return mptscsih_slave_configure(sdev);
911 mptsas_target_alloc(struct scsi_target *starget)
913 struct Scsi_Host *host = dev_to_shost(&starget->dev);
914 MPT_SCSI_HOST *hd = shost_priv(host);
917 struct sas_rphy *rphy;
918 struct mptsas_portinfo *p;
920 MPT_ADAPTER *ioc = hd->ioc;
922 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
926 vtarget->starget = starget;
927 vtarget->ioc_id = ioc->id;
928 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
933 * RAID volumes placed beyond the last expected port.
935 if (starget->channel == MPTSAS_RAID_CHANNEL) {
936 for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
937 if (id == ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID)
938 channel = ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus;
942 rphy = dev_to_rphy(starget->dev.parent);
943 mutex_lock(&ioc->sas_topology_mutex);
944 list_for_each_entry(p, &ioc->sas_topology, list) {
945 for (i = 0; i < p->num_phys; i++) {
946 if (p->phy_info[i].attached.sas_address !=
947 rphy->identify.sas_address)
949 id = p->phy_info[i].attached.id;
950 channel = p->phy_info[i].attached.channel;
951 mptsas_set_starget(&p->phy_info[i], starget);
954 * Exposing hidden raid components
956 if (mptscsih_is_phys_disk(ioc, channel, id)) {
957 id = mptscsih_raid_id_to_num(ioc,
960 MPT_TARGET_FLAGS_RAID_COMPONENT;
961 p->phy_info[i].attached.phys_disk_num = id;
963 mutex_unlock(&ioc->sas_topology_mutex);
967 mutex_unlock(&ioc->sas_topology_mutex);
974 vtarget->channel = channel;
975 starget->hostdata = vtarget;
980 mptsas_target_destroy(struct scsi_target *starget)
982 struct Scsi_Host *host = dev_to_shost(&starget->dev);
983 MPT_SCSI_HOST *hd = shost_priv(host);
984 struct sas_rphy *rphy;
985 struct mptsas_portinfo *p;
987 MPT_ADAPTER *ioc = hd->ioc;
989 if (!starget->hostdata)
992 if (starget->channel == MPTSAS_RAID_CHANNEL)
995 rphy = dev_to_rphy(starget->dev.parent);
996 list_for_each_entry(p, &ioc->sas_topology, list) {
997 for (i = 0; i < p->num_phys; i++) {
998 if (p->phy_info[i].attached.sas_address !=
999 rphy->identify.sas_address)
1001 mptsas_set_starget(&p->phy_info[i], NULL);
1007 kfree(starget->hostdata);
1008 starget->hostdata = NULL;
1013 mptsas_slave_alloc(struct scsi_device *sdev)
1015 struct Scsi_Host *host = sdev->host;
1016 MPT_SCSI_HOST *hd = shost_priv(host);
1017 struct sas_rphy *rphy;
1018 struct mptsas_portinfo *p;
1019 VirtDevice *vdevice;
1020 struct scsi_target *starget;
1022 MPT_ADAPTER *ioc = hd->ioc;
1024 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
1026 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
1027 ioc->name, sizeof(VirtDevice));
1030 starget = scsi_target(sdev);
1031 vdevice->vtarget = starget->hostdata;
1033 if (sdev->channel == MPTSAS_RAID_CHANNEL)
1036 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
1037 mutex_lock(&ioc->sas_topology_mutex);
1038 list_for_each_entry(p, &ioc->sas_topology, list) {
1039 for (i = 0; i < p->num_phys; i++) {
1040 if (p->phy_info[i].attached.sas_address !=
1041 rphy->identify.sas_address)
1043 vdevice->lun = sdev->lun;
1045 * Exposing hidden raid components
1047 if (mptscsih_is_phys_disk(ioc,
1048 p->phy_info[i].attached.channel,
1049 p->phy_info[i].attached.id))
1050 sdev->no_uld_attach = 1;
1051 mutex_unlock(&ioc->sas_topology_mutex);
1055 mutex_unlock(&ioc->sas_topology_mutex);
1061 vdevice->vtarget->num_luns++;
1062 sdev->hostdata = vdevice;
1067 mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1071 VirtDevice *vdevice = SCpnt->device->hostdata;
1073 if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
1074 SCpnt->result = DID_NO_CONNECT << 16;
1079 hd = shost_priv(SCpnt->device->host);
1082 if (ioc->sas_discovery_quiesce_io)
1083 return SCSI_MLQUEUE_HOST_BUSY;
1085 // scsi_print_command(SCpnt);
1087 return mptscsih_qcmd(SCpnt,done);
1091 static struct scsi_host_template mptsas_driver_template = {
1092 .module = THIS_MODULE,
1093 .proc_name = "mptsas",
1094 .proc_info = mptscsih_proc_info,
1095 .name = "MPT SPI Host",
1096 .info = mptscsih_info,
1097 .queuecommand = mptsas_qcmd,
1098 .target_alloc = mptsas_target_alloc,
1099 .slave_alloc = mptsas_slave_alloc,
1100 .slave_configure = mptsas_slave_configure,
1101 .target_destroy = mptsas_target_destroy,
1102 .slave_destroy = mptscsih_slave_destroy,
1103 .change_queue_depth = mptscsih_change_queue_depth,
1104 .eh_abort_handler = mptscsih_abort,
1105 .eh_device_reset_handler = mptscsih_dev_reset,
1106 .eh_bus_reset_handler = mptscsih_bus_reset,
1107 .eh_host_reset_handler = mptscsih_host_reset,
1108 .bios_param = mptscsih_bios_param,
1109 .can_queue = MPT_FC_CAN_QUEUE,
1111 .sg_tablesize = MPT_SCSI_SG_DEPTH,
1112 .max_sectors = 8192,
1114 .use_clustering = ENABLE_CLUSTERING,
1115 .shost_attrs = mptscsih_host_attrs,
1118 static int mptsas_get_linkerrors(struct sas_phy *phy)
1120 MPT_ADAPTER *ioc = phy_to_ioc(phy);
1121 ConfigExtendedPageHeader_t hdr;
1123 SasPhyPage1_t *buffer;
1124 dma_addr_t dma_handle;
1127 /* FIXME: only have link errors on local phys */
1128 if (!scsi_is_sas_phy_local(phy))
1131 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
1132 hdr.ExtPageLength = 0;
1133 hdr.PageNumber = 1 /* page number 1*/;
1136 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1137 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
1139 cfg.cfghdr.ehdr = &hdr;
1141 cfg.pageAddr = phy->identify.phy_identifier;
1142 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1143 cfg.dir = 0; /* read */
1146 error = mpt_config(ioc, &cfg);
1149 if (!hdr.ExtPageLength)
1152 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1157 cfg.physAddr = dma_handle;
1158 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1160 error = mpt_config(ioc, &cfg);
1162 goto out_free_consistent;
1164 mptsas_print_phy_pg1(ioc, buffer);
1166 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
1167 phy->running_disparity_error_count =
1168 le32_to_cpu(buffer->RunningDisparityErrorCount);
1169 phy->loss_of_dword_sync_count =
1170 le32_to_cpu(buffer->LossDwordSynchCount);
1171 phy->phy_reset_problem_count =
1172 le32_to_cpu(buffer->PhyResetProblemCount);
1174 out_free_consistent:
1175 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1176 buffer, dma_handle);
1180 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
1181 MPT_FRAME_HDR *reply)
1183 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1184 if (reply != NULL) {
1185 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID;
1186 memcpy(ioc->sas_mgmt.reply, reply,
1187 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
1189 complete(&ioc->sas_mgmt.done);
1193 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
1195 MPT_ADAPTER *ioc = phy_to_ioc(phy);
1196 SasIoUnitControlRequest_t *req;
1197 SasIoUnitControlReply_t *reply;
1200 unsigned long timeleft;
1201 int error = -ERESTARTSYS;
1203 /* FIXME: fusion doesn't allow non-local phy reset */
1204 if (!scsi_is_sas_phy_local(phy))
1207 /* not implemented for expanders */
1208 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
1211 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
1214 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
1220 hdr = (MPIHeader_t *) mf;
1221 req = (SasIoUnitControlRequest_t *)mf;
1222 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
1223 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
1224 req->MsgContext = hdr->MsgContext;
1225 req->Operation = hard_reset ?
1226 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
1227 req->PhyNum = phy->identify.phy_identifier;
1229 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
1231 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
1234 /* On timeout reset the board */
1235 mpt_free_msg_frame(ioc, mf);
1236 mpt_HardResetHandler(ioc, CAN_SLEEP);
1241 /* a reply frame is expected */
1242 if ((ioc->sas_mgmt.status &
1243 MPT_MGMT_STATUS_RF_VALID) == 0) {
1248 /* process the completed Reply Message Frame */
1249 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
1250 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
1251 printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
1252 ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo);
1260 mutex_unlock(&ioc->sas_mgmt.mutex);
1266 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
1268 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
1270 struct mptsas_portinfo *p;
1271 struct mptsas_enclosure enclosure_info;
1272 u64 enclosure_handle;
1274 mutex_lock(&ioc->sas_topology_mutex);
1275 list_for_each_entry(p, &ioc->sas_topology, list) {
1276 for (i = 0; i < p->num_phys; i++) {
1277 if (p->phy_info[i].attached.sas_address ==
1278 rphy->identify.sas_address) {
1279 enclosure_handle = p->phy_info[i].
1280 attached.handle_enclosure;
1285 mutex_unlock(&ioc->sas_topology_mutex);
1289 mutex_unlock(&ioc->sas_topology_mutex);
1290 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
1291 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
1292 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
1293 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
1295 *identifier = enclosure_info.enclosure_logical_id;
1300 mptsas_get_bay_identifier(struct sas_rphy *rphy)
1302 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
1303 struct mptsas_portinfo *p;
1306 mutex_lock(&ioc->sas_topology_mutex);
1307 list_for_each_entry(p, &ioc->sas_topology, list) {
1308 for (i = 0; i < p->num_phys; i++) {
1309 if (p->phy_info[i].attached.sas_address ==
1310 rphy->identify.sas_address) {
1311 rc = p->phy_info[i].attached.slot;
1318 mutex_unlock(&ioc->sas_topology_mutex);
1322 static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1323 struct request *req)
1325 MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
1327 SmpPassthroughRequest_t *smpreq;
1328 struct request *rsp = req->next_rq;
1331 unsigned long timeleft;
1333 dma_addr_t dma_addr_in = 0;
1334 dma_addr_t dma_addr_out = 0;
1335 u64 sas_address = 0;
1338 printk(MYIOC_s_ERR_FMT "%s: the smp response space is missing\n",
1339 ioc->name, __func__);
1343 /* do we need to support multiple segments? */
1344 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
1345 printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n",
1346 ioc->name, __func__, req->bio->bi_vcnt, req->data_len,
1347 rsp->bio->bi_vcnt, rsp->data_len);
1351 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
1355 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
1361 smpreq = (SmpPassthroughRequest_t *)mf;
1362 memset(smpreq, 0, sizeof(*smpreq));
1364 smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4);
1365 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
1368 sas_address = rphy->identify.sas_address;
1370 struct mptsas_portinfo *port_info;
1372 mutex_lock(&ioc->sas_topology_mutex);
1373 port_info = mptsas_get_hba_portinfo(ioc);
1374 if (port_info && port_info->phy_info)
1376 port_info->phy_info[0].phy->identify.sas_address;
1377 mutex_unlock(&ioc->sas_topology_mutex);
1380 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
1383 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
1386 flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
1387 MPI_SGE_FLAGS_END_OF_BUFFER |
1388 MPI_SGE_FLAGS_DIRECTION)
1389 << MPI_SGE_FLAGS_SHIFT;
1390 flagsLength |= (req->data_len - 4);
1392 dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
1393 req->data_len, PCI_DMA_BIDIRECTIONAL);
1396 ioc->add_sge(psge, flagsLength, dma_addr_out);
1397 psge += (sizeof(u32) + sizeof(dma_addr_t));
1400 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
1401 flagsLength |= rsp->data_len + 4;
1402 dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio),
1403 rsp->data_len, PCI_DMA_BIDIRECTIONAL);
1406 ioc->add_sge(psge, flagsLength, dma_addr_in);
1408 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
1410 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
1412 printk(MYIOC_s_ERR_FMT "%s: smp timeout!\n", ioc->name, __func__);
1413 /* On timeout reset the board */
1414 mpt_HardResetHandler(ioc, CAN_SLEEP);
1420 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
1421 SmpPassthroughReply_t *smprep;
1423 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
1424 memcpy(req->sense, smprep, sizeof(*smprep));
1425 req->sense_len = sizeof(*smprep);
1427 rsp->data_len -= smprep->ResponseDataLength;
1429 printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
1430 ioc->name, __func__);
1435 pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len,
1436 PCI_DMA_BIDIRECTIONAL);
1438 pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len,
1439 PCI_DMA_BIDIRECTIONAL);
1442 mpt_free_msg_frame(ioc, mf);
1444 mutex_unlock(&ioc->sas_mgmt.mutex);
1449 static struct sas_function_template mptsas_transport_functions = {
1450 .get_linkerrors = mptsas_get_linkerrors,
1451 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
1452 .get_bay_identifier = mptsas_get_bay_identifier,
1453 .phy_reset = mptsas_phy_reset,
1454 .smp_handler = mptsas_smp_handler,
1457 static struct scsi_transport_template *mptsas_transport_template;
1460 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
1462 ConfigExtendedPageHeader_t hdr;
1464 SasIOUnitPage0_t *buffer;
1465 dma_addr_t dma_handle;
1468 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
1469 hdr.ExtPageLength = 0;
1473 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1474 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
1476 cfg.cfghdr.ehdr = &hdr;
1479 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1480 cfg.dir = 0; /* read */
1483 error = mpt_config(ioc, &cfg);
1486 if (!hdr.ExtPageLength) {
1491 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1498 cfg.physAddr = dma_handle;
1499 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1501 error = mpt_config(ioc, &cfg);
1503 goto out_free_consistent;
1505 port_info->num_phys = buffer->NumPhys;
1506 port_info->phy_info = kcalloc(port_info->num_phys,
1507 sizeof(*port_info->phy_info),GFP_KERNEL);
1508 if (!port_info->phy_info) {
1510 goto out_free_consistent;
1513 ioc->nvdata_version_persistent =
1514 le16_to_cpu(buffer->NvdataVersionPersistent);
1515 ioc->nvdata_version_default =
1516 le16_to_cpu(buffer->NvdataVersionDefault);
1518 for (i = 0; i < port_info->num_phys; i++) {
1519 mptsas_print_phy_data(ioc, &buffer->PhyData[i]);
1520 port_info->phy_info[i].phy_id = i;
1521 port_info->phy_info[i].port_id =
1522 buffer->PhyData[i].Port;
1523 port_info->phy_info[i].negotiated_link_rate =
1524 buffer->PhyData[i].NegotiatedLinkRate;
1525 port_info->phy_info[i].portinfo = port_info;
1526 port_info->phy_info[i].handle =
1527 le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
1530 out_free_consistent:
1531 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1532 buffer, dma_handle);
1538 mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
1540 ConfigExtendedPageHeader_t hdr;
1542 SasIOUnitPage1_t *buffer;
1543 dma_addr_t dma_handle;
1545 u16 device_missing_delay;
1547 memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
1548 memset(&cfg, 0, sizeof(CONFIGPARMS));
1550 cfg.cfghdr.ehdr = &hdr;
1551 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1553 cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1554 cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
1555 cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION;
1556 cfg.cfghdr.ehdr->PageNumber = 1;
1558 error = mpt_config(ioc, &cfg);
1561 if (!hdr.ExtPageLength) {
1566 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1573 cfg.physAddr = dma_handle;
1574 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1576 error = mpt_config(ioc, &cfg);
1578 goto out_free_consistent;
1580 ioc->io_missing_delay =
1581 le16_to_cpu(buffer->IODeviceMissingDelay);
1582 device_missing_delay = le16_to_cpu(buffer->ReportDeviceMissingDelay);
1583 ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ?
1584 (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 :
1585 device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
1587 out_free_consistent:
1588 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1589 buffer, dma_handle);
1595 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
1596 u32 form, u32 form_specific)
1598 ConfigExtendedPageHeader_t hdr;
1600 SasPhyPage0_t *buffer;
1601 dma_addr_t dma_handle;
1604 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
1605 hdr.ExtPageLength = 0;
1609 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1610 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
1612 cfg.cfghdr.ehdr = &hdr;
1613 cfg.dir = 0; /* read */
1616 /* Get Phy Pg 0 for each Phy. */
1618 cfg.pageAddr = form + form_specific;
1619 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1621 error = mpt_config(ioc, &cfg);
1625 if (!hdr.ExtPageLength) {
1630 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1637 cfg.physAddr = dma_handle;
1638 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1640 error = mpt_config(ioc, &cfg);
1642 goto out_free_consistent;
1644 mptsas_print_phy_pg0(ioc, buffer);
1646 phy_info->hw_link_rate = buffer->HwLinkRate;
1647 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
1648 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
1649 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
1651 out_free_consistent:
1652 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1653 buffer, dma_handle);
1659 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
1660 u32 form, u32 form_specific)
1662 ConfigExtendedPageHeader_t hdr;
1664 SasDevicePage0_t *buffer;
1665 dma_addr_t dma_handle;
1669 if (ioc->sas_discovery_runtime &&
1670 mptsas_is_end_device(device_info))
1673 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
1674 hdr.ExtPageLength = 0;
1678 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1679 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
1681 cfg.cfghdr.ehdr = &hdr;
1682 cfg.pageAddr = form + form_specific;
1684 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1685 cfg.dir = 0; /* read */
1688 memset(device_info, 0, sizeof(struct mptsas_devinfo));
1689 error = mpt_config(ioc, &cfg);
1692 if (!hdr.ExtPageLength) {
1697 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1704 cfg.physAddr = dma_handle;
1705 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1707 error = mpt_config(ioc, &cfg);
1709 goto out_free_consistent;
1711 mptsas_print_device_pg0(ioc, buffer);
1713 device_info->handle = le16_to_cpu(buffer->DevHandle);
1714 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
1715 device_info->handle_enclosure =
1716 le16_to_cpu(buffer->EnclosureHandle);
1717 device_info->slot = le16_to_cpu(buffer->Slot);
1718 device_info->phy_id = buffer->PhyNum;
1719 device_info->port_id = buffer->PhysicalPort;
1720 device_info->id = buffer->TargetID;
1721 device_info->phys_disk_num = ~0;
1722 device_info->channel = buffer->Bus;
1723 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
1724 device_info->sas_address = le64_to_cpu(sas_address);
1725 device_info->device_info =
1726 le32_to_cpu(buffer->DeviceInfo);
1728 out_free_consistent:
1729 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1730 buffer, dma_handle);
1736 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
1737 u32 form, u32 form_specific)
1739 ConfigExtendedPageHeader_t hdr;
1741 SasExpanderPage0_t *buffer;
1742 dma_addr_t dma_handle;
1745 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
1746 hdr.ExtPageLength = 0;
1750 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1751 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
1753 cfg.cfghdr.ehdr = &hdr;
1755 cfg.pageAddr = form + form_specific;
1756 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1757 cfg.dir = 0; /* read */
1760 memset(port_info, 0, sizeof(struct mptsas_portinfo));
1761 error = mpt_config(ioc, &cfg);
1765 if (!hdr.ExtPageLength) {
1770 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1777 cfg.physAddr = dma_handle;
1778 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1780 error = mpt_config(ioc, &cfg);
1782 goto out_free_consistent;
1784 if (!buffer->NumPhys) {
1786 goto out_free_consistent;
1789 /* save config data */
1790 port_info->num_phys = buffer->NumPhys;
1791 port_info->phy_info = kcalloc(port_info->num_phys,
1792 sizeof(*port_info->phy_info),GFP_KERNEL);
1793 if (!port_info->phy_info) {
1795 goto out_free_consistent;
1798 for (i = 0; i < port_info->num_phys; i++) {
1799 port_info->phy_info[i].portinfo = port_info;
1800 port_info->phy_info[i].handle =
1801 le16_to_cpu(buffer->DevHandle);
1804 out_free_consistent:
1805 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1806 buffer, dma_handle);
1812 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
1813 u32 form, u32 form_specific)
1815 ConfigExtendedPageHeader_t hdr;
1817 SasExpanderPage1_t *buffer;
1818 dma_addr_t dma_handle;
1821 if (ioc->sas_discovery_runtime &&
1822 mptsas_is_end_device(&phy_info->attached))
1825 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
1826 hdr.ExtPageLength = 0;
1830 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1831 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
1833 cfg.cfghdr.ehdr = &hdr;
1835 cfg.pageAddr = form + form_specific;
1836 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1837 cfg.dir = 0; /* read */
1840 error = mpt_config(ioc, &cfg);
1844 if (!hdr.ExtPageLength) {
1849 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1856 cfg.physAddr = dma_handle;
1857 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1859 error = mpt_config(ioc, &cfg);
1861 goto out_free_consistent;
1864 mptsas_print_expander_pg1(ioc, buffer);
1866 /* save config data */
1867 phy_info->phy_id = buffer->PhyIdentifier;
1868 phy_info->port_id = buffer->PhysicalPort;
1869 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
1870 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
1871 phy_info->hw_link_rate = buffer->HwLinkRate;
1872 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
1873 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
1875 out_free_consistent:
1876 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1877 buffer, dma_handle);
1883 mptsas_parse_device_info(struct sas_identify *identify,
1884 struct mptsas_devinfo *device_info)
1888 identify->sas_address = device_info->sas_address;
1889 identify->phy_identifier = device_info->phy_id;
1892 * Fill in Phy Initiator Port Protocol.
1893 * Bits 6:3, more than one bit can be set, fall through cases.
1895 protocols = device_info->device_info & 0x78;
1896 identify->initiator_port_protocols = 0;
1897 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
1898 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
1899 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1900 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
1901 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
1902 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
1903 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
1904 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
1907 * Fill in Phy Target Port Protocol.
1908 * Bits 10:7, more than one bit can be set, fall through cases.
1910 protocols = device_info->device_info & 0x780;
1911 identify->target_port_protocols = 0;
1912 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
1913 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
1914 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
1915 identify->target_port_protocols |= SAS_PROTOCOL_STP;
1916 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
1917 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
1918 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1919 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
1922 * Fill in Attached device type.
1924 switch (device_info->device_info &
1925 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
1926 case MPI_SAS_DEVICE_INFO_NO_DEVICE:
1927 identify->device_type = SAS_PHY_UNUSED;
1929 case MPI_SAS_DEVICE_INFO_END_DEVICE:
1930 identify->device_type = SAS_END_DEVICE;
1932 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
1933 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
1935 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
1936 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
1941 static int mptsas_probe_one_phy(struct device *dev,
1942 struct mptsas_phyinfo *phy_info, int index, int local)
1945 struct sas_phy *phy;
1946 struct sas_port *port;
1954 if (!phy_info->phy) {
1955 phy = sas_phy_alloc(dev, index);
1961 phy = phy_info->phy;
1963 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
1966 * Set Negotiated link rate.
1968 switch (phy_info->negotiated_link_rate) {
1969 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
1970 phy->negotiated_linkrate = SAS_PHY_DISABLED;
1972 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
1973 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
1975 case MPI_SAS_IOUNIT0_RATE_1_5:
1976 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
1978 case MPI_SAS_IOUNIT0_RATE_3_0:
1979 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
1981 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
1982 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
1984 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
1989 * Set Max hardware link rate.
1991 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
1992 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
1993 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
1995 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
1996 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
2003 * Set Max programmed link rate.
2005 switch (phy_info->programmed_link_rate &
2006 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
2007 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
2008 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
2010 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
2011 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
2018 * Set Min hardware link rate.
2020 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
2021 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
2022 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
2024 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
2025 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
2032 * Set Min programmed link rate.
2034 switch (phy_info->programmed_link_rate &
2035 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
2036 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
2037 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
2039 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
2040 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
2046 if (!phy_info->phy) {
2048 error = sas_phy_add(phy);
2053 phy_info->phy = phy;
2056 if (!phy_info->attached.handle ||
2057 !phy_info->port_details)
2060 port = mptsas_get_port(phy_info);
2061 ioc = phy_to_ioc(phy_info->phy);
2063 if (phy_info->sas_port_add_phy) {
2066 port = sas_port_alloc_num(dev);
2071 error = sas_port_add(port);
2073 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2074 "%s: exit at line=%d\n", ioc->name,
2075 __func__, __LINE__));
2078 mptsas_set_port(ioc, phy_info, port);
2079 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2080 "sas_port_alloc: port=%p dev=%p port_id=%d\n",
2081 ioc->name, port, dev, port->port_identifier));
2083 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_port_add_phy: phy_id=%d\n",
2084 ioc->name, phy_info->phy_id));
2085 sas_port_add_phy(port, phy_info->phy);
2086 phy_info->sas_port_add_phy = 0;
2089 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
2091 struct sas_rphy *rphy;
2092 struct device *parent;
2093 struct sas_identify identify;
2095 parent = dev->parent->parent;
2097 * Let the hotplug_work thread handle processing
2098 * the adding/removing of devices that occur
2099 * after start of day.
2101 if (ioc->sas_discovery_runtime &&
2102 mptsas_is_end_device(&phy_info->attached))
2105 mptsas_parse_device_info(&identify, &phy_info->attached);
2106 if (scsi_is_host_device(parent)) {
2107 struct mptsas_portinfo *port_info;
2110 mutex_lock(&ioc->sas_topology_mutex);
2111 port_info = mptsas_get_hba_portinfo(ioc);
2112 mutex_unlock(&ioc->sas_topology_mutex);
2114 for (i = 0; i < port_info->num_phys; i++)
2115 if (port_info->phy_info[i].identify.sas_address ==
2116 identify.sas_address) {
2117 sas_port_mark_backlink(port);
2121 } else if (scsi_is_sas_rphy(parent)) {
2122 struct sas_rphy *parent_rphy = dev_to_rphy(parent);
2123 if (identify.sas_address ==
2124 parent_rphy->identify.sas_address) {
2125 sas_port_mark_backlink(port);
2130 switch (identify.device_type) {
2131 case SAS_END_DEVICE:
2132 rphy = sas_end_device_alloc(port);
2134 case SAS_EDGE_EXPANDER_DEVICE:
2135 case SAS_FANOUT_EXPANDER_DEVICE:
2136 rphy = sas_expander_alloc(port, identify.device_type);
2143 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2144 "%s: exit at line=%d\n", ioc->name,
2145 __func__, __LINE__));
2149 rphy->identify = identify;
2150 error = sas_rphy_add(rphy);
2152 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2153 "%s: exit at line=%d\n", ioc->name,
2154 __func__, __LINE__));
2155 sas_rphy_free(rphy);
2158 mptsas_set_rphy(ioc, phy_info, rphy);
2166 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
2168 struct mptsas_portinfo *port_info, *hba;
2169 int error = -ENOMEM, i;
2171 hba = kzalloc(sizeof(*port_info), GFP_KERNEL);
2175 error = mptsas_sas_io_unit_pg0(ioc, hba);
2177 goto out_free_port_info;
2179 mptsas_sas_io_unit_pg1(ioc);
2180 mutex_lock(&ioc->sas_topology_mutex);
2181 port_info = mptsas_get_hba_portinfo(ioc);
2184 list_add_tail(&port_info->list, &ioc->sas_topology);
2186 for (i = 0; i < hba->num_phys; i++) {
2187 port_info->phy_info[i].negotiated_link_rate =
2188 hba->phy_info[i].negotiated_link_rate;
2189 port_info->phy_info[i].handle =
2190 hba->phy_info[i].handle;
2191 port_info->phy_info[i].port_id =
2192 hba->phy_info[i].port_id;
2194 kfree(hba->phy_info);
2198 mutex_unlock(&ioc->sas_topology_mutex);
2199 for (i = 0; i < port_info->num_phys; i++) {
2200 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
2201 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
2202 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
2204 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
2205 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2206 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2207 port_info->phy_info[i].handle);
2208 port_info->phy_info[i].identify.phy_id =
2209 port_info->phy_info[i].phy_id = i;
2210 if (port_info->phy_info[i].attached.handle)
2211 mptsas_sas_device_pg0(ioc,
2212 &port_info->phy_info[i].attached,
2213 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2214 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2215 port_info->phy_info[i].attached.handle);
2218 mptsas_setup_wide_ports(ioc, port_info);
2220 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
2221 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
2222 &port_info->phy_info[i], ioc->sas_index, 1);
2233 mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
2235 struct mptsas_portinfo *port_info, *p, *ex;
2236 struct device *parent;
2237 struct sas_rphy *rphy;
2238 int error = -ENOMEM, i, j;
2240 ex = kzalloc(sizeof(*port_info), GFP_KERNEL);
2244 error = mptsas_sas_expander_pg0(ioc, ex,
2245 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
2246 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle);
2248 goto out_free_port_info;
2250 *handle = ex->phy_info[0].handle;
2252 mutex_lock(&ioc->sas_topology_mutex);
2253 port_info = mptsas_find_portinfo_by_handle(ioc, *handle);
2256 list_add_tail(&port_info->list, &ioc->sas_topology);
2258 for (i = 0; i < ex->num_phys; i++) {
2259 port_info->phy_info[i].handle =
2260 ex->phy_info[i].handle;
2261 port_info->phy_info[i].port_id =
2262 ex->phy_info[i].port_id;
2264 kfree(ex->phy_info);
2268 mutex_unlock(&ioc->sas_topology_mutex);
2270 for (i = 0; i < port_info->num_phys; i++) {
2271 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
2272 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
2273 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + *handle);
2275 if (port_info->phy_info[i].identify.handle) {
2276 mptsas_sas_device_pg0(ioc,
2277 &port_info->phy_info[i].identify,
2278 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2279 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2280 port_info->phy_info[i].identify.handle);
2281 port_info->phy_info[i].identify.phy_id =
2282 port_info->phy_info[i].phy_id;
2285 if (port_info->phy_info[i].attached.handle) {
2286 mptsas_sas_device_pg0(ioc,
2287 &port_info->phy_info[i].attached,
2288 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2289 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2290 port_info->phy_info[i].attached.handle);
2291 port_info->phy_info[i].attached.phy_id =
2292 port_info->phy_info[i].phy_id;
2296 parent = &ioc->sh->shost_gendev;
2297 for (i = 0; i < port_info->num_phys; i++) {
2298 mutex_lock(&ioc->sas_topology_mutex);
2299 list_for_each_entry(p, &ioc->sas_topology, list) {
2300 for (j = 0; j < p->num_phys; j++) {
2301 if (port_info->phy_info[i].identify.handle !=
2302 p->phy_info[j].attached.handle)
2304 rphy = mptsas_get_rphy(&p->phy_info[j]);
2305 parent = &rphy->dev;
2308 mutex_unlock(&ioc->sas_topology_mutex);
2311 mptsas_setup_wide_ports(ioc, port_info);
2313 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
2314 mptsas_probe_one_phy(parent, &port_info->phy_info[i],
2321 kfree(ex->phy_info);
2329 * mptsas_delete_expander_phys
2332 * This will traverse topology, and remove expanders
2333 * that are no longer present
2336 mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
2338 struct mptsas_portinfo buffer;
2339 struct mptsas_portinfo *port_info, *n, *parent;
2340 struct mptsas_phyinfo *phy_info;
2341 struct sas_port * port;
2343 u64 expander_sas_address;
2345 mutex_lock(&ioc->sas_topology_mutex);
2346 list_for_each_entry_safe(port_info, n, &ioc->sas_topology, list) {
2348 if (!(port_info->phy_info[0].identify.device_info &
2349 MPI_SAS_DEVICE_INFO_SMP_TARGET))
2352 if (mptsas_sas_expander_pg0(ioc, &buffer,
2353 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
2354 MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
2355 port_info->phy_info[0].handle)) {
2358 * Obtain the port_info instance to the parent port
2360 parent = mptsas_find_portinfo_by_handle(ioc,
2361 port_info->phy_info[0].identify.handle_parent);
2366 expander_sas_address =
2367 port_info->phy_info[0].identify.sas_address;
2370 * Delete rphys in the parent that point
2371 * to this expander. The transport layer will
2372 * cleanup all the children.
2374 phy_info = parent->phy_info;
2375 for (i = 0; i < parent->num_phys; i++, phy_info++) {
2376 port = mptsas_get_port(phy_info);
2379 if (phy_info->attached.sas_address !=
2380 expander_sas_address)
2383 dev_printk(KERN_DEBUG, &port->dev,
2384 MYIOC_s_FMT "delete port (%d)\n", ioc->name,
2385 port->port_identifier));
2386 sas_port_delete(port);
2387 mptsas_port_delete(ioc, phy_info->port_details);
2391 phy_info = port_info->phy_info;
2392 for (i = 0; i < port_info->num_phys; i++, phy_info++)
2393 mptsas_port_delete(ioc, phy_info->port_details);
2395 list_del(&port_info->list);
2396 kfree(port_info->phy_info);
2400 * Free this memory allocated from inside
2401 * mptsas_sas_expander_pg0
2403 kfree(buffer.phy_info);
2405 mutex_unlock(&ioc->sas_topology_mutex);
2409 * Start of day discovery
2412 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
2414 u32 handle = 0xFFFF;
2417 mutex_lock(&ioc->sas_discovery_mutex);
2418 mptsas_probe_hba_phys(ioc);
2419 while (!mptsas_probe_expander_phys(ioc, &handle))
2422 Reporting RAID volumes.
2424 if (!ioc->ir_firmware)
2426 if (!ioc->raid_data.pIocPg2)
2428 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
2430 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
2431 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
2432 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
2435 mutex_unlock(&ioc->sas_discovery_mutex);
2439 * Work queue thread to handle Runtime discovery
2440 * Mere purpose is the hot add/delete of expanders
2444 __mptsas_discovery_work(MPT_ADAPTER *ioc)
2446 u32 handle = 0xFFFF;
2448 ioc->sas_discovery_runtime=1;
2449 mptsas_delete_expander_phys(ioc);
2450 mptsas_probe_hba_phys(ioc);
2451 while (!mptsas_probe_expander_phys(ioc, &handle))
2453 ioc->sas_discovery_runtime=0;
2457 * Work queue thread to handle Runtime discovery
2458 * Mere purpose is the hot add/delete of expanders
2462 mptsas_discovery_work(struct work_struct *work)
2464 struct mptsas_discovery_event *ev =
2465 container_of(work, struct mptsas_discovery_event, work);
2466 MPT_ADAPTER *ioc = ev->ioc;
2468 mutex_lock(&ioc->sas_discovery_mutex);
2469 __mptsas_discovery_work(ioc);
2470 mutex_unlock(&ioc->sas_discovery_mutex);
2474 static struct mptsas_phyinfo *
2475 mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
2477 struct mptsas_portinfo *port_info;
2478 struct mptsas_phyinfo *phy_info = NULL;
2481 mutex_lock(&ioc->sas_topology_mutex);
2482 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2483 for (i = 0; i < port_info->num_phys; i++) {
2484 if (!mptsas_is_end_device(
2485 &port_info->phy_info[i].attached))
2487 if (port_info->phy_info[i].attached.sas_address
2490 phy_info = &port_info->phy_info[i];
2494 mutex_unlock(&ioc->sas_topology_mutex);
2498 static struct mptsas_phyinfo *
2499 mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u8 channel, u8 id)
2501 struct mptsas_portinfo *port_info;
2502 struct mptsas_phyinfo *phy_info = NULL;
2505 mutex_lock(&ioc->sas_topology_mutex);
2506 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2507 for (i = 0; i < port_info->num_phys; i++) {
2508 if (!mptsas_is_end_device(
2509 &port_info->phy_info[i].attached))
2511 if (port_info->phy_info[i].attached.id != 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);
2523 static struct mptsas_phyinfo *
2524 mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
2526 struct mptsas_portinfo *port_info;
2527 struct mptsas_phyinfo *phy_info = NULL;
2530 mutex_lock(&ioc->sas_topology_mutex);
2531 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2532 for (i = 0; i < port_info->num_phys; i++) {
2533 if (!mptsas_is_end_device(
2534 &port_info->phy_info[i].attached))
2536 if (port_info->phy_info[i].attached.phys_disk_num == ~0)
2538 if (port_info->phy_info[i].attached.phys_disk_num != id)
2540 if (port_info->phy_info[i].attached.channel != channel)
2542 phy_info = &port_info->phy_info[i];
2546 mutex_unlock(&ioc->sas_topology_mutex);
2551 * Work queue thread to clear the persitency table
2554 mptsas_persist_clear_table(struct work_struct *work)
2556 MPT_ADAPTER *ioc = container_of(work, MPT_ADAPTER, sas_persist_task);
2558 mptbase_sas_persist_operation(ioc, MPI_SAS_OP_CLEAR_NOT_PRESENT);
2562 mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
2566 sdev->no_uld_attach = data ? 1 : 0;
2567 rc = scsi_device_reprobe(sdev);
2571 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
2573 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
2574 mptsas_reprobe_lun);
2578 mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
2581 ConfigPageHeader_t hdr;
2582 dma_addr_t dma_handle;
2583 pRaidVolumePage0_t buffer = NULL;
2584 RaidPhysDiskPage0_t phys_disk;
2586 struct mptsas_hotplug_event *ev;
2588 memset(&cfg, 0 , sizeof(CONFIGPARMS));
2589 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
2590 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
2591 cfg.pageAddr = (channel << 8) + id;
2592 cfg.cfghdr.hdr = &hdr;
2593 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2595 if (mpt_config(ioc, &cfg) != 0)
2598 if (!hdr.PageLength)
2601 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
2607 cfg.physAddr = dma_handle;
2608 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2610 if (mpt_config(ioc, &cfg) != 0)
2613 if (!(buffer->VolumeStatus.Flags &
2614 MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
2617 if (!buffer->NumPhysDisks)
2620 for (i = 0; i < buffer->NumPhysDisks; i++) {
2622 if (mpt_raid_phys_disk_pg0(ioc,
2623 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
2626 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2628 printk(MYIOC_s_WARN_FMT "mptsas: lost hotplug event\n", ioc->name);
2632 INIT_WORK(&ev->work, mptsas_hotplug_work);
2634 ev->id = phys_disk.PhysDiskID;
2635 ev->channel = phys_disk.PhysDiskBus;
2636 ev->phys_disk_num_valid = 1;
2637 ev->phys_disk_num = phys_disk.PhysDiskNum;
2638 ev->event_type = MPTSAS_ADD_DEVICE;
2639 schedule_work(&ev->work);
2644 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
2648 * Work queue thread to handle SAS hotplug events
2651 mptsas_hotplug_work(struct work_struct *work)
2653 struct mptsas_hotplug_event *ev =
2654 container_of(work, struct mptsas_hotplug_event, work);
2656 MPT_ADAPTER *ioc = ev->ioc;
2657 struct mptsas_phyinfo *phy_info;
2658 struct sas_rphy *rphy;
2659 struct sas_port *port;
2660 struct scsi_device *sdev;
2661 struct scsi_target * starget;
2662 struct sas_identify identify;
2664 struct mptsas_devinfo sas_device;
2665 VirtTarget *vtarget;
2666 VirtDevice *vdevice;
2668 mutex_lock(&ioc->sas_discovery_mutex);
2669 switch (ev->event_type) {
2670 case MPTSAS_DEL_DEVICE:
2673 if (ev->phys_disk_num_valid) {
2674 if (ev->hidden_raid_component){
2675 if (mptsas_sas_device_pg0(ioc, &sas_device,
2676 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
2677 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2678 (ev->channel << 8) + ev->id)) {
2679 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2680 "%s: exit at line=%d\n", ioc->name,
2681 __func__, __LINE__));
2684 phy_info = mptsas_find_phyinfo_by_sas_address(
2685 ioc, sas_device.sas_address);
2687 phy_info = mptsas_find_phyinfo_by_phys_disk_num(
2688 ioc, ev->channel, ev->phys_disk_num);
2692 phy_info = mptsas_find_phyinfo_by_target(ioc,
2693 ev->channel, ev->id);
2696 * Sanity checks, for non-existing phys and remote rphys.
2699 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2700 "%s: exit at line=%d\n", ioc->name,
2701 __func__, __LINE__));
2704 if (!phy_info->port_details) {
2705 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2706 "%s: exit at line=%d\n", ioc->name,
2707 __func__, __LINE__));
2710 rphy = mptsas_get_rphy(phy_info);
2712 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2713 "%s: exit at line=%d\n", ioc->name,
2714 __func__, __LINE__));
2718 port = mptsas_get_port(phy_info);
2720 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2721 "%s: exit at line=%d\n", ioc->name,
2722 __func__, __LINE__));
2726 starget = mptsas_get_starget(phy_info);
2728 vtarget = starget->hostdata;
2731 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2732 "%s: exit at line=%d\n", ioc->name,
2733 __func__, __LINE__));
2738 * Handling RAID components
2740 if (ev->phys_disk_num_valid &&
2741 ev->hidden_raid_component) {
2742 printk(MYIOC_s_INFO_FMT
2743 "RAID Hidding: channel=%d, id=%d, "
2744 "physdsk %d \n", ioc->name, ev->channel,
2745 ev->id, ev->phys_disk_num);
2746 vtarget->id = ev->phys_disk_num;
2748 MPT_TARGET_FLAGS_RAID_COMPONENT;
2749 mptsas_reprobe_target(starget, 1);
2750 phy_info->attached.phys_disk_num =
2756 if (phy_info->attached.device_info &
2757 MPI_SAS_DEVICE_INFO_SSP_TARGET)
2759 if (phy_info->attached.device_info &
2760 MPI_SAS_DEVICE_INFO_STP_TARGET)
2762 if (phy_info->attached.device_info &
2763 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
2766 printk(MYIOC_s_INFO_FMT
2767 "removing %s device, channel %d, id %d, phy %d\n",
2768 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
2769 dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
2770 "delete port (%d)\n", ioc->name, port->port_identifier);
2771 sas_port_delete(port);
2772 mptsas_port_delete(ioc, phy_info->port_details);
2774 case MPTSAS_ADD_DEVICE:
2776 if (ev->phys_disk_num_valid)
2777 mpt_findImVolumes(ioc);
2780 * Refresh sas device pg0 data
2782 if (mptsas_sas_device_pg0(ioc, &sas_device,
2783 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
2784 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2785 (ev->channel << 8) + ev->id)) {
2786 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2787 "%s: exit at line=%d\n", ioc->name,
2788 __func__, __LINE__));
2792 __mptsas_discovery_work(ioc);
2794 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
2795 sas_device.sas_address);
2797 if (!phy_info || !phy_info->port_details) {
2798 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2799 "%s: exit at line=%d\n", ioc->name,
2800 __func__, __LINE__));
2804 starget = mptsas_get_starget(phy_info);
2805 if (starget && (!ev->hidden_raid_component)){
2807 vtarget = starget->hostdata;
2810 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2811 "%s: exit at line=%d\n", ioc->name,
2812 __func__, __LINE__));
2816 * Handling RAID components
2818 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2819 printk(MYIOC_s_INFO_FMT
2820 "RAID Exposing: channel=%d, id=%d, "
2821 "physdsk %d \n", ioc->name, ev->channel,
2822 ev->id, ev->phys_disk_num);
2824 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
2825 vtarget->id = ev->id;
2826 mptsas_reprobe_target(starget, 0);
2827 phy_info->attached.phys_disk_num = ~0;
2832 if (mptsas_get_rphy(phy_info)) {
2833 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2834 "%s: exit at line=%d\n", ioc->name,
2835 __func__, __LINE__));
2836 if (ev->channel) printk("%d\n", __LINE__);
2840 port = mptsas_get_port(phy_info);
2842 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2843 "%s: exit at line=%d\n", ioc->name,
2844 __func__, __LINE__));
2847 memcpy(&phy_info->attached, &sas_device,
2848 sizeof(struct mptsas_devinfo));
2850 if (phy_info->attached.device_info &
2851 MPI_SAS_DEVICE_INFO_SSP_TARGET)
2853 if (phy_info->attached.device_info &
2854 MPI_SAS_DEVICE_INFO_STP_TARGET)
2856 if (phy_info->attached.device_info &
2857 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
2860 printk(MYIOC_s_INFO_FMT
2861 "attaching %s device, channel %d, id %d, phy %d\n",
2862 ioc->name, ds, ev->channel, ev->id, ev->phy_id);
2864 mptsas_parse_device_info(&identify, &phy_info->attached);
2865 rphy = sas_end_device_alloc(port);
2867 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2868 "%s: exit at line=%d\n", ioc->name,
2869 __func__, __LINE__));
2870 break; /* non-fatal: an rphy can be added later */
2873 rphy->identify = identify;
2874 if (sas_rphy_add(rphy)) {
2875 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2876 "%s: exit at line=%d\n", ioc->name,
2877 __func__, __LINE__));
2878 sas_rphy_free(rphy);
2881 mptsas_set_rphy(ioc, phy_info, rphy);
2883 case MPTSAS_ADD_RAID:
2884 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
2887 scsi_device_put(sdev);
2890 printk(MYIOC_s_INFO_FMT
2891 "attaching raid volume, channel %d, id %d\n",
2892 ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
2893 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, ev->id, 0);
2894 mpt_findImVolumes(ioc);
2896 case MPTSAS_DEL_RAID:
2897 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
2901 printk(MYIOC_s_INFO_FMT
2902 "removing raid volume, channel %d, id %d\n",
2903 ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
2904 vdevice = sdev->hostdata;
2905 scsi_remove_device(sdev);
2906 scsi_device_put(sdev);
2907 mpt_findImVolumes(ioc);
2909 case MPTSAS_ADD_INACTIVE_VOLUME:
2910 mptsas_adding_inactive_raid_components(ioc,
2911 ev->channel, ev->id);
2913 case MPTSAS_IGNORE_EVENT:
2918 mutex_unlock(&ioc->sas_discovery_mutex);
2923 mptsas_send_sas_event(MPT_ADAPTER *ioc,
2924 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
2926 struct mptsas_hotplug_event *ev;
2927 u32 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
2931 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
2932 MPI_SAS_DEVICE_INFO_STP_TARGET |
2933 MPI_SAS_DEVICE_INFO_SATA_DEVICE )) == 0)
2936 switch (sas_event_data->ReasonCode) {
2937 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
2939 mptsas_target_reset_queue(ioc, sas_event_data);
2942 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
2943 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2945 printk(MYIOC_s_WARN_FMT "lost hotplug event\n", ioc->name);
2949 INIT_WORK(&ev->work, mptsas_hotplug_work);
2951 ev->handle = le16_to_cpu(sas_event_data->DevHandle);
2953 le16_to_cpu(sas_event_data->ParentDevHandle);
2954 ev->channel = sas_event_data->Bus;
2955 ev->id = sas_event_data->TargetID;
2956 ev->phy_id = sas_event_data->PhyNum;
2957 memcpy(&sas_address, &sas_event_data->SASAddress,
2959 ev->sas_address = le64_to_cpu(sas_address);
2960 ev->device_info = device_info;
2962 if (sas_event_data->ReasonCode &
2963 MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
2964 ev->event_type = MPTSAS_ADD_DEVICE;
2966 ev->event_type = MPTSAS_DEL_DEVICE;
2967 schedule_work(&ev->work);
2969 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
2971 * Persistent table is full.
2973 INIT_WORK(&ioc->sas_persist_task,
2974 mptsas_persist_clear_table);
2975 schedule_work(&ioc->sas_persist_task);
2978 * TODO, handle other events
2980 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
2981 case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
2982 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
2983 case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
2984 case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
2985 case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
2986 case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
2992 mptsas_send_raid_event(MPT_ADAPTER *ioc,
2993 EVENT_DATA_RAID *raid_event_data)
2995 struct mptsas_hotplug_event *ev;
2996 int status = le32_to_cpu(raid_event_data->SettingsStatus);
2997 int state = (status >> 8) & 0xff;
2999 if (ioc->bus_type != SAS)
3002 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
3004 printk(MYIOC_s_WARN_FMT "lost hotplug event\n", ioc->name);
3008 INIT_WORK(&ev->work, mptsas_hotplug_work);
3010 ev->id = raid_event_data->VolumeID;
3011 ev->channel = raid_event_data->VolumeBus;
3012 ev->event_type = MPTSAS_IGNORE_EVENT;
3014 switch (raid_event_data->ReasonCode) {
3015 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
3016 ev->phys_disk_num_valid = 1;
3017 ev->phys_disk_num = raid_event_data->PhysDiskNum;
3018 ev->event_type = MPTSAS_ADD_DEVICE;
3020 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
3021 ev->phys_disk_num_valid = 1;
3022 ev->phys_disk_num = raid_event_data->PhysDiskNum;
3023 ev->hidden_raid_component = 1;
3024 ev->event_type = MPTSAS_DEL_DEVICE;
3026 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
3028 case MPI_PD_STATE_ONLINE:
3029 case MPI_PD_STATE_NOT_COMPATIBLE:
3030 ev->phys_disk_num_valid = 1;
3031 ev->phys_disk_num = raid_event_data->PhysDiskNum;
3032 ev->hidden_raid_component = 1;
3033 ev->event_type = MPTSAS_ADD_DEVICE;
3035 case MPI_PD_STATE_MISSING:
3036 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
3037 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
3038 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
3039 ev->phys_disk_num_valid = 1;
3040 ev->phys_disk_num = raid_event_data->PhysDiskNum;
3041 ev->event_type = MPTSAS_DEL_DEVICE;
3047 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
3048 ev->event_type = MPTSAS_DEL_RAID;
3050 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
3051 ev->event_type = MPTSAS_ADD_RAID;
3053 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
3055 case MPI_RAIDVOL0_STATUS_STATE_FAILED:
3056 case MPI_RAIDVOL0_STATUS_STATE_MISSING:
3057 ev->event_type = MPTSAS_DEL_RAID;
3059 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
3060 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
3061 ev->event_type = MPTSAS_ADD_RAID;
3070 schedule_work(&ev->work);
3074 mptsas_send_discovery_event(MPT_ADAPTER *ioc,
3075 EVENT_DATA_SAS_DISCOVERY *discovery_data)
3077 struct mptsas_discovery_event *ev;
3078 u32 discovery_status;
3083 * This flag will be non-zero when firmware
3084 * kicks off discovery, and return to zero
3085 * once its completed.
3087 discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus);
3088 ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0;
3089 if (discovery_status)
3092 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
3095 INIT_WORK(&ev->work, mptsas_discovery_work);
3097 schedule_work(&ev->work);
3101 * mptsas_send_ir2_event - handle exposing hidden disk when
3102 * an inactive raid volume is added
3104 * @ioc: Pointer to MPT_ADAPTER structure
3109 mptsas_send_ir2_event(MPT_ADAPTER *ioc, PTR_MPI_EVENT_DATA_IR2 ir2_data)
3111 struct mptsas_hotplug_event *ev;
3113 if (ir2_data->ReasonCode !=
3114 MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED)
3117 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
3121 INIT_WORK(&ev->work, mptsas_hotplug_work);
3123 ev->id = ir2_data->TargetID;
3124 ev->channel = ir2_data->Bus;
3125 ev->event_type = MPTSAS_ADD_INACTIVE_VOLUME;
3127 schedule_work(&ev->work);
3131 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
3134 u8 event = le32_to_cpu(reply->Event) & 0xFF;
3140 * sas_discovery_ignore_events
3142 * This flag is to prevent anymore processing of
3143 * sas events once mptsas_remove function is called.
3145 if (ioc->sas_discovery_ignore_events) {
3146 rc = mptscsih_event_process(ioc, reply);
3151 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
3152 mptsas_send_sas_event(ioc,
3153 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data);
3155 case MPI_EVENT_INTEGRATED_RAID:
3156 mptsas_send_raid_event(ioc,
3157 (EVENT_DATA_RAID *)reply->Data);
3159 case MPI_EVENT_PERSISTENT_TABLE_FULL:
3160 INIT_WORK(&ioc->sas_persist_task,
3161 mptsas_persist_clear_table);
3162 schedule_work(&ioc->sas_persist_task);
3164 case MPI_EVENT_SAS_DISCOVERY:
3165 mptsas_send_discovery_event(ioc,
3166 (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
3169 mptsas_send_ir2_event(ioc,
3170 (PTR_MPI_EVENT_DATA_IR2)reply->Data);
3173 rc = mptscsih_event_process(ioc, reply);
3182 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
3184 struct Scsi_Host *sh;
3187 unsigned long flags;
3195 r = mpt_attach(pdev,id);
3199 ioc = pci_get_drvdata(pdev);
3200 ioc->DoneCtx = mptsasDoneCtx;
3201 ioc->TaskCtx = mptsasTaskCtx;
3202 ioc->InternalCtx = mptsasInternalCtx;
3204 /* Added sanity check on readiness of the MPT adapter.
3206 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
3207 printk(MYIOC_s_WARN_FMT
3208 "Skipping because it's not operational!\n",
3211 goto out_mptsas_probe;
3215 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
3218 goto out_mptsas_probe;
3221 /* Sanity check - ensure at least 1 port is INITIATOR capable
3224 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
3225 if (ioc->pfacts[ii].ProtocolFlags &
3226 MPI_PORTFACTS_PROTOCOL_INITIATOR)
3231 printk(MYIOC_s_WARN_FMT
3232 "Skipping ioc=%p because SCSI Initiator mode "
3233 "is NOT enabled!\n", ioc->name, ioc);
3237 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
3239 printk(MYIOC_s_WARN_FMT
3240 "Unable to register controller with SCSI subsystem\n",
3243 goto out_mptsas_probe;
3246 spin_lock_irqsave(&ioc->FreeQlock, flags);
3248 /* Attach the SCSI Host to the IOC structure
3256 /* set 16 byte cdb's */
3257 sh->max_cmd_len = 16;
3259 sh->max_id = ioc->pfacts[0].PortSCSIID;
3260 sh->max_lun = max_lun;
3262 sh->transportt = mptsas_transport_template;
3266 sh->unique_id = ioc->id;
3268 INIT_LIST_HEAD(&ioc->sas_topology);
3269 mutex_init(&ioc->sas_topology_mutex);
3270 mutex_init(&ioc->sas_discovery_mutex);
3271 mutex_init(&ioc->sas_mgmt.mutex);
3272 init_completion(&ioc->sas_mgmt.done);
3274 /* Verify that we won't exceed the maximum
3275 * number of chain buffers
3276 * We can optimize: ZZ = req_sz/sizeof(SGE)
3278 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
3279 * + (req_sz - 64)/sizeof(SGE)
3280 * A slightly different algorithm is required for
3283 scale = ioc->req_sz/ioc->SGE_size;
3284 if (ioc->sg_addr_size == sizeof(u64)) {
3285 numSGE = (scale - 1) *
3286 (ioc->facts.MaxChainDepth-1) + scale +
3287 (ioc->req_sz - 60) / ioc->SGE_size;
3289 numSGE = 1 + (scale - 1) *
3290 (ioc->facts.MaxChainDepth-1) + scale +
3291 (ioc->req_sz - 64) / ioc->SGE_size;
3294 if (numSGE < sh->sg_tablesize) {
3295 /* Reset this value */
3296 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3297 "Resetting sg_tablesize to %d from %d\n",
3298 ioc->name, numSGE, sh->sg_tablesize));
3299 sh->sg_tablesize = numSGE;
3302 hd = shost_priv(sh);
3305 /* SCSI needs scsi_cmnd lookup table!
3306 * (with size equal to req_depth*PtrSz!)
3308 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
3309 if (!ioc->ScsiLookup) {
3311 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
3312 goto out_mptsas_probe;
3314 spin_lock_init(&ioc->scsi_lookup_lock);
3316 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
3317 ioc->name, ioc->ScsiLookup));
3319 /* Clear the TM flags
3321 hd->abortSCpnt = NULL;
3323 /* Clear the pointer used to store
3324 * single-threaded commands, i.e., those
3325 * issued during a bus scan, dv and
3326 * configuration pages.
3330 /* Initialize this SCSI Hosts' timers
3331 * To use, set the timer expires field
3334 init_timer(&hd->timer);
3335 hd->timer.data = (unsigned long) hd;
3336 hd->timer.function = mptscsih_timer_expired;
3338 ioc->sas_data.ptClear = mpt_pt_clear;
3340 hd->last_queue_full = 0;
3341 INIT_LIST_HEAD(&hd->target_reset_list);
3342 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
3344 if (ioc->sas_data.ptClear==1) {
3345 mptbase_sas_persist_operation(
3346 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
3349 error = scsi_add_host(sh, &ioc->pcidev->dev);
3351 dprintk(ioc, printk(MYIOC_s_ERR_FMT
3352 "scsi_add_host failed\n", ioc->name));
3353 goto out_mptsas_probe;
3356 mptsas_scan_sas_topology(ioc);
3362 mptscsih_remove(pdev);
3367 mptsas_shutdown(struct pci_dev *pdev)
3369 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
3371 ioc->sas_discovery_quiesce_io = 0;
3374 static void __devexit mptsas_remove(struct pci_dev *pdev)
3376 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
3377 struct mptsas_portinfo *p, *n;
3380 mptsas_shutdown(pdev);
3382 ioc->sas_discovery_ignore_events = 1;
3383 sas_remove_host(ioc->sh);
3385 mutex_lock(&ioc->sas_topology_mutex);
3386 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
3388 for (i = 0 ; i < p->num_phys ; i++)
3389 mptsas_port_delete(ioc, p->phy_info[i].port_details);
3393 mutex_unlock(&ioc->sas_topology_mutex);
3395 mptscsih_remove(pdev);
3398 static struct pci_device_id mptsas_pci_table[] = {
3399 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
3400 PCI_ANY_ID, PCI_ANY_ID },
3401 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
3402 PCI_ANY_ID, PCI_ANY_ID },
3403 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
3404 PCI_ANY_ID, PCI_ANY_ID },
3405 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
3406 PCI_ANY_ID, PCI_ANY_ID },
3407 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
3408 PCI_ANY_ID, PCI_ANY_ID },
3409 {0} /* Terminating entry */
3411 MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
3414 static struct pci_driver mptsas_driver = {
3416 .id_table = mptsas_pci_table,
3417 .probe = mptsas_probe,
3418 .remove = __devexit_p(mptsas_remove),
3419 .shutdown = mptsas_shutdown,
3421 .suspend = mptscsih_suspend,
3422 .resume = mptscsih_resume,
3431 show_mptmod_ver(my_NAME, my_VERSION);
3433 mptsas_transport_template =
3434 sas_attach_transport(&mptsas_transport_functions);
3435 if (!mptsas_transport_template)
3438 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
3439 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER);
3441 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
3442 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
3443 mptsasDeviceResetCtx =
3444 mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER);
3446 mpt_event_register(mptsasDoneCtx, mptsas_event_process);
3447 mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset);
3449 error = pci_register_driver(&mptsas_driver);
3451 sas_release_transport(mptsas_transport_template);
3459 pci_unregister_driver(&mptsas_driver);
3460 sas_release_transport(mptsas_transport_template);
3462 mpt_reset_deregister(mptsasDoneCtx);
3463 mpt_event_deregister(mptsasDoneCtx);
3465 mpt_deregister(mptsasMgmtCtx);
3466 mpt_deregister(mptsasInternalCtx);
3467 mpt_deregister(mptsasTaskCtx);
3468 mpt_deregister(mptsasDoneCtx);
3469 mpt_deregister(mptsasDeviceResetCtx);
3472 module_init(mptsas_init);
3473 module_exit(mptsas_exit);