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_firmware_event_work(struct work_struct *work);
99 static void mptsas_send_sas_event(struct fw_event_work *fw_event);
100 static void mptsas_send_raid_event(struct fw_event_work *fw_event);
101 static void mptsas_send_ir2_event(struct fw_event_work *fw_event);
102 static void mptsas_parse_device_info(struct sas_identify *identify,
103 struct mptsas_devinfo *device_info);
104 static inline void mptsas_set_rphy(MPT_ADAPTER *ioc,
105 struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy);
106 static struct mptsas_phyinfo *mptsas_find_phyinfo_by_sas_address
107 (MPT_ADAPTER *ioc, u64 sas_address);
108 static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc,
109 struct mptsas_devinfo *device_info, u32 form, u32 form_specific);
110 static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc,
111 struct mptsas_enclosure *enclosure, u32 form, u32 form_specific);
112 static int mptsas_add_end_device(MPT_ADAPTER *ioc,
113 struct mptsas_phyinfo *phy_info);
114 static void mptsas_del_end_device(MPT_ADAPTER *ioc,
115 struct mptsas_phyinfo *phy_info);
116 static void mptsas_send_link_status_event(struct fw_event_work *fw_event);
117 static struct mptsas_portinfo *mptsas_find_portinfo_by_sas_address
118 (MPT_ADAPTER *ioc, u64 sas_address);
119 static void mptsas_expander_delete(MPT_ADAPTER *ioc,
120 struct mptsas_portinfo *port_info, u8 force);
121 static void mptsas_send_expander_event(struct fw_event_work *fw_event);
122 static void mptsas_not_responding_devices(MPT_ADAPTER *ioc);
123 static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc);
125 static void mptsas_print_phy_data(MPT_ADAPTER *ioc,
126 MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
128 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
129 "---- IO UNIT PAGE 0 ------------\n", ioc->name));
130 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
131 ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle)));
132 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n",
133 ioc->name, le16_to_cpu(phy_data->ControllerDevHandle)));
134 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n",
135 ioc->name, phy_data->Port));
136 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n",
137 ioc->name, phy_data->PortFlags));
138 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n",
139 ioc->name, phy_data->PhyFlags));
140 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
141 ioc->name, phy_data->NegotiatedLinkRate));
142 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
143 "Controller PHY Device Info=0x%X\n", ioc->name,
144 le32_to_cpu(phy_data->ControllerPhyDeviceInfo)));
145 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n",
146 ioc->name, le32_to_cpu(phy_data->DiscoveryStatus)));
149 static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0)
153 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
155 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
156 "---- SAS PHY PAGE 0 ------------\n", ioc->name));
157 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
158 "Attached Device Handle=0x%X\n", ioc->name,
159 le16_to_cpu(pg0->AttachedDevHandle)));
160 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
161 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
162 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
163 "Attached PHY Identifier=0x%X\n", ioc->name,
164 pg0->AttachedPhyIdentifier));
165 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n",
166 ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo)));
167 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
168 ioc->name, pg0->ProgrammedLinkRate));
169 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n",
170 ioc->name, pg0->ChangeCount));
171 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n",
172 ioc->name, le32_to_cpu(pg0->PhyInfo)));
175 static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1)
177 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
178 "---- SAS PHY PAGE 1 ------------\n", ioc->name));
179 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n",
180 ioc->name, pg1->InvalidDwordCount));
181 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
182 "Running Disparity Error Count=0x%x\n", ioc->name,
183 pg1->RunningDisparityErrorCount));
184 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
185 "Loss Dword Synch Count=0x%x\n", ioc->name,
186 pg1->LossDwordSynchCount));
187 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
188 "PHY Reset Problem Count=0x%x\n\n", ioc->name,
189 pg1->PhyResetProblemCount));
192 static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0)
196 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
198 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
199 "---- SAS DEVICE PAGE 0 ---------\n", ioc->name));
200 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
201 ioc->name, le16_to_cpu(pg0->DevHandle)));
202 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n",
203 ioc->name, le16_to_cpu(pg0->ParentDevHandle)));
204 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n",
205 ioc->name, le16_to_cpu(pg0->EnclosureHandle)));
206 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n",
207 ioc->name, le16_to_cpu(pg0->Slot)));
208 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
209 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
210 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n",
211 ioc->name, pg0->TargetID));
212 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n",
213 ioc->name, pg0->Bus));
214 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n",
215 ioc->name, pg0->PhyNum));
216 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n",
217 ioc->name, le16_to_cpu(pg0->AccessStatus)));
218 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n",
219 ioc->name, le32_to_cpu(pg0->DeviceInfo)));
220 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n",
221 ioc->name, le16_to_cpu(pg0->Flags)));
222 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n",
223 ioc->name, pg0->PhysicalPort));
226 static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1)
228 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
229 "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name));
230 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n",
231 ioc->name, pg1->PhysicalPort));
232 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n",
233 ioc->name, pg1->PhyIdentifier));
234 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
235 ioc->name, pg1->NegotiatedLinkRate));
236 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
237 ioc->name, pg1->ProgrammedLinkRate));
238 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n",
239 ioc->name, pg1->HwLinkRate));
240 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n",
241 ioc->name, le16_to_cpu(pg1->OwnerDevHandle)));
242 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
243 "Attached Device Handle=0x%X\n\n", ioc->name,
244 le16_to_cpu(pg1->AttachedDevHandle)));
247 /* inhibit sas firmware event handling */
249 mptsas_fw_event_off(MPT_ADAPTER *ioc)
253 spin_lock_irqsave(&ioc->fw_event_lock, flags);
254 ioc->fw_events_off = 1;
255 ioc->sas_discovery_quiesce_io = 0;
256 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
260 /* enable sas firmware event handling */
262 mptsas_fw_event_on(MPT_ADAPTER *ioc)
266 spin_lock_irqsave(&ioc->fw_event_lock, flags);
267 ioc->fw_events_off = 0;
268 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
271 /* queue a sas firmware event */
273 mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
278 spin_lock_irqsave(&ioc->fw_event_lock, flags);
279 list_add_tail(&fw_event->list, &ioc->fw_event_list);
280 INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work);
281 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)\n",
282 ioc->name, __func__, fw_event));
283 queue_delayed_work(ioc->fw_event_q, &fw_event->work,
285 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
288 /* free memory assoicated to a sas firmware event */
290 mptsas_free_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event)
294 spin_lock_irqsave(&ioc->fw_event_lock, flags);
295 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: kfree (fw_event=0x%p)\n",
296 ioc->name, __func__, fw_event));
297 list_del(&fw_event->list);
299 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
302 /* walk the firmware event queue, and either stop or wait for
303 * outstanding events to complete */
305 mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc)
307 struct fw_event_work *fw_event, *next;
308 struct mptsas_target_reset_event *target_reset_list, *n;
310 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
312 /* flush the target_reset_list */
313 if (!list_empty(&hd->target_reset_list)) {
314 list_for_each_entry_safe(target_reset_list, n,
315 &hd->target_reset_list, list) {
316 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
317 "%s: removing target reset for id=%d\n",
319 target_reset_list->sas_event_data.TargetID));
320 list_del(&target_reset_list->list);
321 kfree(target_reset_list);
325 if (list_empty(&ioc->fw_event_list) ||
326 !ioc->fw_event_q || in_interrupt())
330 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
331 if (cancel_delayed_work(&fw_event->work))
332 mptsas_free_fw_event(ioc, fw_event);
337 flush_workqueue(ioc->fw_event_q);
341 static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
343 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
344 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
347 static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
349 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
350 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
354 * mptsas_find_portinfo_by_handle
356 * This function should be called with the sas_topology_mutex already held
358 static struct mptsas_portinfo *
359 mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
361 struct mptsas_portinfo *port_info, *rc=NULL;
364 list_for_each_entry(port_info, &ioc->sas_topology, list)
365 for (i = 0; i < port_info->num_phys; i++)
366 if (port_info->phy_info[i].identify.handle == handle) {
375 * mptsas_find_portinfo_by_sas_address -
376 * @ioc: Pointer to MPT_ADAPTER structure
379 * This function should be called with the sas_topology_mutex already held
382 static struct mptsas_portinfo *
383 mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
385 struct mptsas_portinfo *port_info, *rc = NULL;
388 if (sas_address >= ioc->hba_port_sas_addr &&
389 sas_address < (ioc->hba_port_sas_addr +
390 ioc->hba_port_num_phy))
391 return ioc->hba_port_info;
393 mutex_lock(&ioc->sas_topology_mutex);
394 list_for_each_entry(port_info, &ioc->sas_topology, list)
395 for (i = 0; i < port_info->num_phys; i++)
396 if (port_info->phy_info[i].identify.sas_address ==
402 mutex_unlock(&ioc->sas_topology_mutex);
407 * Returns true if there is a scsi end device
410 mptsas_is_end_device(struct mptsas_devinfo * attached)
412 if ((attached->sas_address) &&
413 (attached->device_info &
414 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
415 ((attached->device_info &
416 MPI_SAS_DEVICE_INFO_SSP_TARGET) |
417 (attached->device_info &
418 MPI_SAS_DEVICE_INFO_STP_TARGET) |
419 (attached->device_info &
420 MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
428 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
430 struct mptsas_portinfo *port_info;
431 struct mptsas_phyinfo *phy_info;
437 port_info = port_details->port_info;
438 phy_info = port_info->phy_info;
440 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d "
441 "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
442 port_details->num_phys, (unsigned long long)
443 port_details->phy_bitmask));
445 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
446 if(phy_info->port_details != port_details)
448 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
449 mptsas_set_rphy(ioc, phy_info, NULL);
450 phy_info->port_details = NULL;
455 static inline struct sas_rphy *
456 mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
458 if (phy_info->port_details)
459 return phy_info->port_details->rphy;
465 mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
467 if (phy_info->port_details) {
468 phy_info->port_details->rphy = rphy;
469 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
474 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
475 &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
476 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
477 ioc->name, rphy, rphy->dev.release));
481 static inline struct sas_port *
482 mptsas_get_port(struct mptsas_phyinfo *phy_info)
484 if (phy_info->port_details)
485 return phy_info->port_details->port;
491 mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port)
493 if (phy_info->port_details)
494 phy_info->port_details->port = port;
497 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
498 &port->dev, MYIOC_s_FMT "add:", ioc->name));
499 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n",
500 ioc->name, port, port->dev.release));
504 static inline struct scsi_target *
505 mptsas_get_starget(struct mptsas_phyinfo *phy_info)
507 if (phy_info->port_details)
508 return phy_info->port_details->starget;
514 mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
517 if (phy_info->port_details)
518 phy_info->port_details->starget = starget;
522 * mptsas_add_device_component -
523 * @ioc: Pointer to MPT_ADAPTER structure
524 * @channel: fw mapped id's
531 mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id,
532 u64 sas_address, u32 device_info, u16 slot, u64 enclosure_logical_id)
534 struct mptsas_device_info *sas_info, *next;
535 struct scsi_device *sdev;
536 struct scsi_target *starget;
537 struct sas_rphy *rphy;
540 * Delete all matching devices out of the list
542 mutex_lock(&ioc->sas_device_info_mutex);
543 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
545 if ((sas_info->sas_address == sas_address ||
546 (sas_info->fw.channel == channel &&
547 sas_info->fw.id == id))) {
548 list_del(&sas_info->list);
553 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
558 * Set Firmware mapping
560 sas_info->fw.id = id;
561 sas_info->fw.channel = channel;
563 sas_info->sas_address = sas_address;
564 sas_info->device_info = device_info;
565 sas_info->slot = slot;
566 sas_info->enclosure_logical_id = enclosure_logical_id;
567 INIT_LIST_HEAD(&sas_info->list);
568 list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
573 shost_for_each_device(sdev, ioc->sh) {
574 starget = scsi_target(sdev);
575 rphy = dev_to_rphy(starget->dev.parent);
576 if (rphy->identify.sas_address == sas_address) {
577 sas_info->os.id = starget->id;
578 sas_info->os.channel = starget->channel;
583 mutex_unlock(&ioc->sas_device_info_mutex);
588 * mptsas_add_device_component_by_fw -
589 * @ioc: Pointer to MPT_ADAPTER structure
590 * @channel: fw mapped id's
595 mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id)
597 struct mptsas_devinfo sas_device;
598 struct mptsas_enclosure enclosure_info;
601 rc = mptsas_sas_device_pg0(ioc, &sas_device,
602 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
603 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
604 (channel << 8) + id);
608 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
609 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
610 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
611 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
612 sas_device.handle_enclosure);
614 mptsas_add_device_component(ioc, sas_device.channel,
615 sas_device.id, sas_device.sas_address, sas_device.device_info,
616 sas_device.slot, enclosure_info.enclosure_logical_id);
620 * mptsas_add_device_component_starget -
621 * @ioc: Pointer to MPT_ADAPTER structure
626 mptsas_add_device_component_starget(MPT_ADAPTER *ioc,
627 struct scsi_target *starget)
630 struct sas_rphy *rphy;
631 struct mptsas_phyinfo *phy_info = NULL;
632 struct mptsas_enclosure enclosure_info;
634 rphy = dev_to_rphy(starget->dev.parent);
635 vtarget = starget->hostdata;
636 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
637 rphy->identify.sas_address);
641 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
642 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
643 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
644 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
645 phy_info->attached.handle_enclosure);
647 mptsas_add_device_component(ioc, phy_info->attached.channel,
648 phy_info->attached.id, phy_info->attached.sas_address,
649 phy_info->attached.device_info,
650 phy_info->attached.slot, enclosure_info.enclosure_logical_id);
654 * mptsas_del_device_components - Cleaning the list
655 * @ioc: Pointer to MPT_ADAPTER structure
659 mptsas_del_device_components(MPT_ADAPTER *ioc)
661 struct mptsas_device_info *sas_info, *next;
663 mutex_lock(&ioc->sas_device_info_mutex);
664 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
666 list_del(&sas_info->list);
669 mutex_unlock(&ioc->sas_device_info_mutex);
674 * mptsas_setup_wide_ports
676 * Updates for new and existing narrow/wide port configuration
677 * in the sas_topology
680 mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
682 struct mptsas_portinfo_details * port_details;
683 struct mptsas_phyinfo *phy_info, *phy_info_cmp;
687 mutex_lock(&ioc->sas_topology_mutex);
689 phy_info = port_info->phy_info;
690 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
691 if (phy_info->attached.handle)
693 port_details = phy_info->port_details;
696 if (port_details->num_phys < 2)
699 * Removing a phy from a port, letting the last
700 * phy be removed by firmware events.
702 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
703 "%s: [%p]: deleting phy = %d\n",
704 ioc->name, __func__, port_details, i));
705 port_details->num_phys--;
706 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
707 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
708 sas_port_delete_phy(port_details->port, phy_info->phy);
709 phy_info->port_details = NULL;
713 * Populate and refresh the tree
715 phy_info = port_info->phy_info;
716 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
717 sas_address = phy_info->attached.sas_address;
718 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
719 ioc->name, i, (unsigned long long)sas_address));
722 port_details = phy_info->port_details;
727 port_details = kzalloc(sizeof(*port_details),
731 port_details->num_phys = 1;
732 port_details->port_info = port_info;
733 if (phy_info->phy_id < 64 )
734 port_details->phy_bitmask |=
735 (1 << phy_info->phy_id);
736 phy_info->sas_port_add_phy=1;
737 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
738 "phy_id=%d sas_address=0x%018llX\n",
739 ioc->name, i, (unsigned long long)sas_address));
740 phy_info->port_details = port_details;
743 if (i == port_info->num_phys - 1)
745 phy_info_cmp = &port_info->phy_info[i + 1];
746 for (j = i + 1 ; j < port_info->num_phys ; j++,
748 if (!phy_info_cmp->attached.sas_address)
750 if (sas_address != phy_info_cmp->attached.sas_address)
752 if (phy_info_cmp->port_details == port_details )
754 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
755 "\t\tphy_id=%d sas_address=0x%018llX\n",
756 ioc->name, j, (unsigned long long)
757 phy_info_cmp->attached.sas_address));
758 if (phy_info_cmp->port_details) {
760 mptsas_get_rphy(phy_info_cmp);
762 mptsas_get_port(phy_info_cmp);
763 port_details->starget =
764 mptsas_get_starget(phy_info_cmp);
765 port_details->num_phys =
766 phy_info_cmp->port_details->num_phys;
767 if (!phy_info_cmp->port_details->num_phys)
768 kfree(phy_info_cmp->port_details);
770 phy_info_cmp->sas_port_add_phy=1;
772 * Adding a phy to a port
774 phy_info_cmp->port_details = port_details;
775 if (phy_info_cmp->phy_id < 64 )
776 port_details->phy_bitmask |=
777 (1 << phy_info_cmp->phy_id);
778 port_details->num_phys++;
784 for (i = 0; i < port_info->num_phys; i++) {
785 port_details = port_info->phy_info[i].port_details;
788 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
789 "%s: [%p]: phy_id=%02d num_phys=%02d "
790 "bitmask=0x%016llX\n", ioc->name, __func__,
791 port_details, i, port_details->num_phys,
792 (unsigned long long)port_details->phy_bitmask));
793 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
794 ioc->name, port_details->port, port_details->rphy));
796 dsaswideprintk(ioc, printk("\n"));
797 mutex_unlock(&ioc->sas_topology_mutex);
801 * csmisas_find_vtarget
809 mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
811 struct scsi_device *sdev;
813 VirtTarget *vtarget = NULL;
815 shost_for_each_device(sdev, ioc->sh) {
816 vdevice = sdev->hostdata;
817 if ((vdevice == NULL) ||
818 (vdevice->vtarget == NULL))
820 if (vdevice->vtarget->id == id &&
821 vdevice->vtarget->channel == channel)
822 vtarget = vdevice->vtarget;
828 mptsas_queue_device_delete(MPT_ADAPTER *ioc,
829 MpiEventDataSasDeviceStatusChange_t *sas_event_data)
831 struct fw_event_work *fw_event;
834 sz = offsetof(struct fw_event_work, event_data) +
835 sizeof(MpiEventDataSasDeviceStatusChange_t);
836 fw_event = kzalloc(sz, GFP_ATOMIC);
838 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
839 ioc->name, __func__, __LINE__);
842 memcpy(fw_event->event_data, sas_event_data,
843 sizeof(MpiEventDataSasDeviceStatusChange_t));
844 fw_event->event = MPI_EVENT_SAS_DEVICE_STATUS_CHANGE;
846 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
850 mptsas_queue_rescan(MPT_ADAPTER *ioc)
852 struct fw_event_work *fw_event;
855 sz = offsetof(struct fw_event_work, event_data);
856 fw_event = kzalloc(sz, GFP_ATOMIC);
858 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
859 ioc->name, __func__, __LINE__);
862 fw_event->event = -1;
864 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
869 * mptsas_target_reset
871 * Issues TARGET_RESET to end device using handshaking method
877 * Returns (1) success
882 mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
885 SCSITaskMgmt_t *pScsiTm;
886 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0)
890 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
892 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
893 "%s, no msg frames @%d!!\n", ioc->name,
894 __func__, __LINE__));
898 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
901 /* Format the Request
903 pScsiTm = (SCSITaskMgmt_t *) mf;
904 memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
905 pScsiTm->TargetID = id;
906 pScsiTm->Bus = channel;
907 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
908 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
909 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
911 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
913 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
914 "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
915 ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id));
917 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
923 mpt_clear_taskmgmt_in_progress_flag(ioc);
928 * mptsas_target_reset_queue
930 * Receive request for TARGET_RESET after recieving an firmware
931 * event NOT_RESPONDING_EVENT, then put command in link list
932 * and queue if task_queue already in use.
939 mptsas_target_reset_queue(MPT_ADAPTER *ioc,
940 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
942 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
943 VirtTarget *vtarget = NULL;
944 struct mptsas_target_reset_event *target_reset_list;
947 id = sas_event_data->TargetID;
948 channel = sas_event_data->Bus;
950 if (!(vtarget = mptsas_find_vtarget(ioc, channel, id)))
953 vtarget->deleted = 1; /* block IO */
955 target_reset_list = kzalloc(sizeof(*target_reset_list),
957 if (!target_reset_list) {
958 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
959 "%s, failed to allocate mem @%d..!!\n",
960 ioc->name, __func__, __LINE__));
964 memcpy(&target_reset_list->sas_event_data, sas_event_data,
965 sizeof(*sas_event_data));
966 list_add_tail(&target_reset_list->list, &hd->target_reset_list);
968 target_reset_list->time_count = jiffies;
970 if (mptsas_target_reset(ioc, channel, id)) {
971 target_reset_list->target_reset_issued = 1;
976 * mptsas_taskmgmt_complete - Completion for TARGET_RESET after
977 * NOT_RESPONDING_EVENT, enable work queue to finish off removing device
978 * from upper layers. then send next TARGET_RESET in the queue.
979 * @ioc: Pointer to MPT_ADAPTER structure
983 mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
985 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
986 struct list_head *head = &hd->target_reset_list;
988 struct mptsas_target_reset_event *target_reset_list;
989 SCSITaskMgmtReply_t *pScsiTmReply;
991 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: "
992 "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
994 pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
996 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
997 "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
998 "\ttask_type = 0x%02X, iocstatus = 0x%04X "
999 "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
1000 "term_cmnds = %d\n", ioc->name,
1001 pScsiTmReply->Bus, pScsiTmReply->TargetID,
1002 pScsiTmReply->TaskType,
1003 le16_to_cpu(pScsiTmReply->IOCStatus),
1004 le32_to_cpu(pScsiTmReply->IOCLogInfo),
1005 pScsiTmReply->ResponseCode,
1006 le32_to_cpu(pScsiTmReply->TerminationCount)));
1008 if (pScsiTmReply->ResponseCode)
1009 mptscsih_taskmgmt_response_code(ioc,
1010 pScsiTmReply->ResponseCode);
1013 if (pScsiTmReply && (pScsiTmReply->TaskType ==
1014 MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
1015 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) {
1016 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1017 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
1018 memcpy(ioc->taskmgmt_cmds.reply, mr,
1019 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
1020 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
1021 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
1022 complete(&ioc->taskmgmt_cmds.done);
1028 mpt_clear_taskmgmt_in_progress_flag(ioc);
1030 if (list_empty(head))
1033 target_reset_list = list_entry(head->next,
1034 struct mptsas_target_reset_event, list);
1036 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1037 "TaskMgmt: completed (%d seconds)\n",
1038 ioc->name, jiffies_to_msecs(jiffies -
1039 target_reset_list->time_count)/1000));
1041 id = pScsiTmReply->TargetID;
1042 channel = pScsiTmReply->Bus;
1043 target_reset_list->time_count = jiffies;
1046 * retry target reset
1048 if (!target_reset_list->target_reset_issued) {
1049 if (mptsas_target_reset(ioc, channel, id))
1050 target_reset_list->target_reset_issued = 1;
1055 * enable work queue to remove device from upper layers
1057 list_del(&target_reset_list->list);
1058 if ((mptsas_find_vtarget(ioc, channel, id)) && !ioc->fw_events_off)
1059 mptsas_queue_device_delete(ioc,
1060 &target_reset_list->sas_event_data);
1064 * issue target reset to next device in the queue
1067 head = &hd->target_reset_list;
1068 if (list_empty(head))
1071 target_reset_list = list_entry(head->next, struct mptsas_target_reset_event,
1074 id = target_reset_list->sas_event_data.TargetID;
1075 channel = target_reset_list->sas_event_data.Bus;
1076 target_reset_list->time_count = jiffies;
1078 if (mptsas_target_reset(ioc, channel, id))
1079 target_reset_list->target_reset_issued = 1;
1085 * mptscsih_ioc_reset
1092 mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1097 rc = mptscsih_ioc_reset(ioc, reset_phase);
1098 if ((ioc->bus_type != SAS) || (!rc))
1101 hd = shost_priv(ioc->sh);
1105 switch (reset_phase) {
1106 case MPT_IOC_SETUP_RESET:
1107 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1108 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
1109 mptsas_fw_event_off(ioc);
1111 case MPT_IOC_PRE_RESET:
1112 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1113 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
1115 case MPT_IOC_POST_RESET:
1116 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1117 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
1118 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
1119 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET;
1120 complete(&ioc->sas_mgmt.done);
1122 mptsas_cleanup_fw_event_q(ioc);
1123 mptsas_queue_rescan(ioc);
1124 mptsas_fw_event_on(ioc);
1136 * enum device_state -
1137 * @DEVICE_RETRY: need to retry the TUR
1138 * @DEVICE_ERROR: TUR return error, don't add device
1139 * @DEVICE_READY: device can be added
1149 mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
1150 u32 form, u32 form_specific)
1152 ConfigExtendedPageHeader_t hdr;
1154 SasEnclosurePage0_t *buffer;
1155 dma_addr_t dma_handle;
1157 __le64 le_identifier;
1159 memset(&hdr, 0, sizeof(hdr));
1160 hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
1162 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1163 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
1165 cfg.cfghdr.ehdr = &hdr;
1167 cfg.pageAddr = form + form_specific;
1168 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1169 cfg.dir = 0; /* read */
1172 error = mpt_config(ioc, &cfg);
1175 if (!hdr.ExtPageLength) {
1180 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1187 cfg.physAddr = dma_handle;
1188 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1190 error = mpt_config(ioc, &cfg);
1192 goto out_free_consistent;
1194 /* save config data */
1195 memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
1196 enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
1197 enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
1198 enclosure->flags = le16_to_cpu(buffer->Flags);
1199 enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
1200 enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
1201 enclosure->start_id = buffer->StartTargetID;
1202 enclosure->start_channel = buffer->StartBus;
1203 enclosure->sep_id = buffer->SEPTargetID;
1204 enclosure->sep_channel = buffer->SEPBus;
1206 out_free_consistent:
1207 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1208 buffer, dma_handle);
1214 * mptsas_add_end_device - report a new end device to sas transport layer
1215 * @ioc: Pointer to MPT_ADAPTER structure
1216 * @phy_info: decribes attached device
1218 * return (0) success (1) failure
1222 mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1224 struct sas_rphy *rphy;
1225 struct sas_port *port;
1226 struct sas_identify identify;
1231 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1232 "%s: exit at line=%d\n", ioc->name,
1233 __func__, __LINE__));
1237 fw_id = phy_info->attached.id;
1239 if (mptsas_get_rphy(phy_info)) {
1240 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1241 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1242 __func__, fw_id, __LINE__));
1246 port = mptsas_get_port(phy_info);
1248 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1249 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1250 __func__, fw_id, __LINE__));
1254 if (phy_info->attached.device_info &
1255 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1257 if (phy_info->attached.device_info &
1258 MPI_SAS_DEVICE_INFO_STP_TARGET)
1260 if (phy_info->attached.device_info &
1261 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1264 printk(MYIOC_s_INFO_FMT "attaching %s device: fw_channel %d, fw_id %d,"
1265 " phy %d, sas_addr 0x%llx\n", ioc->name, ds,
1266 phy_info->attached.channel, phy_info->attached.id,
1267 phy_info->attached.phy_id, (unsigned long long)
1268 phy_info->attached.sas_address);
1270 mptsas_parse_device_info(&identify, &phy_info->attached);
1271 rphy = sas_end_device_alloc(port);
1273 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1274 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1275 __func__, fw_id, __LINE__));
1276 return 5; /* non-fatal: an rphy can be added later */
1279 rphy->identify = identify;
1280 if (sas_rphy_add(rphy)) {
1281 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1282 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1283 __func__, fw_id, __LINE__));
1284 sas_rphy_free(rphy);
1287 mptsas_set_rphy(ioc, phy_info, rphy);
1292 * mptsas_del_end_device - report a deleted end device to sas transport
1294 * @ioc: Pointer to MPT_ADAPTER structure
1295 * @phy_info: decribes attached device
1299 mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1301 struct sas_rphy *rphy;
1302 struct sas_port *port;
1303 struct mptsas_portinfo *port_info;
1304 struct mptsas_phyinfo *phy_info_parent;
1313 fw_id = phy_info->attached.id;
1314 sas_address = phy_info->attached.sas_address;
1316 if (!phy_info->port_details) {
1317 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1318 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1319 __func__, fw_id, __LINE__));
1322 rphy = mptsas_get_rphy(phy_info);
1324 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1325 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1326 __func__, fw_id, __LINE__));
1330 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_INITIATOR
1331 || phy_info->attached.device_info
1332 & MPI_SAS_DEVICE_INFO_SMP_INITIATOR
1333 || phy_info->attached.device_info
1334 & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1336 if (phy_info->attached.device_info &
1337 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1339 if (phy_info->attached.device_info &
1340 MPI_SAS_DEVICE_INFO_STP_TARGET)
1342 if (phy_info->attached.device_info &
1343 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1346 dev_printk(KERN_DEBUG, &rphy->dev, MYIOC_s_FMT
1347 "removing %s device: fw_channel %d, fw_id %d, phy %d,"
1348 "sas_addr 0x%llx\n", ioc->name, ds, phy_info->attached.channel,
1349 phy_info->attached.id, phy_info->attached.phy_id,
1350 (unsigned long long) sas_address);
1352 port = mptsas_get_port(phy_info);
1354 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1355 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1356 __func__, fw_id, __LINE__));
1359 port_info = phy_info->portinfo;
1360 phy_info_parent = port_info->phy_info;
1361 for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) {
1362 if (!phy_info_parent->phy)
1364 if (phy_info_parent->attached.sas_address !=
1367 dev_printk(KERN_DEBUG, &phy_info_parent->phy->dev,
1368 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n",
1369 ioc->name, phy_info_parent->phy_id,
1370 phy_info_parent->phy);
1371 sas_port_delete_phy(port, phy_info_parent->phy);
1374 dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
1375 "delete port %d, sas_addr (0x%llx)\n", ioc->name,
1376 port->port_identifier, (unsigned long long)sas_address);
1377 sas_port_delete(port);
1378 mptsas_set_port(ioc, phy_info, NULL);
1379 mptsas_port_delete(ioc, phy_info->port_details);
1382 struct mptsas_phyinfo *
1383 mptsas_refreshing_device_handles(MPT_ADAPTER *ioc,
1384 struct mptsas_devinfo *sas_device)
1386 struct mptsas_phyinfo *phy_info;
1387 struct mptsas_portinfo *port_info;
1390 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
1391 sas_device->sas_address);
1394 port_info = phy_info->portinfo;
1397 mutex_lock(&ioc->sas_topology_mutex);
1398 for (i = 0; i < port_info->num_phys; i++) {
1399 if (port_info->phy_info[i].attached.sas_address !=
1400 sas_device->sas_address)
1402 port_info->phy_info[i].attached.channel = sas_device->channel;
1403 port_info->phy_info[i].attached.id = sas_device->id;
1404 port_info->phy_info[i].attached.sas_address =
1405 sas_device->sas_address;
1406 port_info->phy_info[i].attached.handle = sas_device->handle;
1407 port_info->phy_info[i].attached.handle_parent =
1408 sas_device->handle_parent;
1409 port_info->phy_info[i].attached.handle_enclosure =
1410 sas_device->handle_enclosure;
1412 mutex_unlock(&ioc->sas_topology_mutex);
1418 * mptsas_firmware_event_work - work thread for processing fw events
1419 * @work: work queue payload containing info describing the event
1424 mptsas_firmware_event_work(struct work_struct *work)
1426 struct fw_event_work *fw_event =
1427 container_of(work, struct fw_event_work, work.work);
1428 MPT_ADAPTER *ioc = fw_event->ioc;
1430 /* special rescan topology handling */
1431 if (fw_event->event == -1) {
1432 if (ioc->in_rescan) {
1433 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1434 "%s: rescan ignored as it is in progress\n",
1435 ioc->name, __func__));
1438 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rescan after "
1439 "reset\n", ioc->name, __func__));
1441 mptsas_not_responding_devices(ioc);
1442 mptsas_scan_sas_topology(ioc);
1444 mptsas_free_fw_event(ioc, fw_event);
1448 /* events handling turned off during host reset */
1449 if (ioc->fw_events_off) {
1450 mptsas_free_fw_event(ioc, fw_event);
1454 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_event=(0x%p), "
1455 "event = (0x%02x)\n", ioc->name, __func__, fw_event,
1456 (fw_event->event & 0xFF)));
1458 switch (fw_event->event) {
1459 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
1460 mptsas_send_sas_event(fw_event);
1462 case MPI_EVENT_INTEGRATED_RAID:
1463 mptsas_send_raid_event(fw_event);
1466 mptsas_send_ir2_event(fw_event);
1468 case MPI_EVENT_PERSISTENT_TABLE_FULL:
1469 mptbase_sas_persist_operation(ioc,
1470 MPI_SAS_OP_CLEAR_NOT_PRESENT);
1471 mptsas_free_fw_event(ioc, fw_event);
1473 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
1474 mptsas_send_expander_event(fw_event);
1476 case MPI_EVENT_SAS_PHY_LINK_STATUS:
1477 mptsas_send_link_status_event(fw_event);
1485 mptsas_slave_configure(struct scsi_device *sdev)
1487 struct Scsi_Host *host = sdev->host;
1488 MPT_SCSI_HOST *hd = shost_priv(host);
1489 MPT_ADAPTER *ioc = hd->ioc;
1491 if (sdev->channel == MPTSAS_RAID_CHANNEL)
1494 sas_read_port_mode_page(sdev);
1496 mptsas_add_device_component_starget(ioc, scsi_target(sdev));
1499 return mptscsih_slave_configure(sdev);
1503 mptsas_target_alloc(struct scsi_target *starget)
1505 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1506 MPT_SCSI_HOST *hd = shost_priv(host);
1507 VirtTarget *vtarget;
1509 struct sas_rphy *rphy;
1510 struct mptsas_portinfo *p;
1512 MPT_ADAPTER *ioc = hd->ioc;
1514 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
1518 vtarget->starget = starget;
1519 vtarget->ioc_id = ioc->id;
1520 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
1525 * RAID volumes placed beyond the last expected port.
1527 if (starget->channel == MPTSAS_RAID_CHANNEL) {
1528 for (i=0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
1529 if (id == ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID)
1530 channel = ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus;
1534 rphy = dev_to_rphy(starget->dev.parent);
1535 mutex_lock(&ioc->sas_topology_mutex);
1536 list_for_each_entry(p, &ioc->sas_topology, list) {
1537 for (i = 0; i < p->num_phys; i++) {
1538 if (p->phy_info[i].attached.sas_address !=
1539 rphy->identify.sas_address)
1541 id = p->phy_info[i].attached.id;
1542 channel = p->phy_info[i].attached.channel;
1543 mptsas_set_starget(&p->phy_info[i], starget);
1546 * Exposing hidden raid components
1548 if (mptscsih_is_phys_disk(ioc, channel, id)) {
1549 id = mptscsih_raid_id_to_num(ioc,
1552 MPT_TARGET_FLAGS_RAID_COMPONENT;
1553 p->phy_info[i].attached.phys_disk_num = id;
1555 mutex_unlock(&ioc->sas_topology_mutex);
1559 mutex_unlock(&ioc->sas_topology_mutex);
1566 vtarget->channel = channel;
1567 starget->hostdata = vtarget;
1572 mptsas_target_destroy(struct scsi_target *starget)
1574 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1575 MPT_SCSI_HOST *hd = shost_priv(host);
1576 struct sas_rphy *rphy;
1577 struct mptsas_portinfo *p;
1579 MPT_ADAPTER *ioc = hd->ioc;
1580 VirtTarget *vtarget;
1582 if (!starget->hostdata)
1585 vtarget = starget->hostdata;
1588 if (starget->channel == MPTSAS_RAID_CHANNEL)
1591 rphy = dev_to_rphy(starget->dev.parent);
1592 list_for_each_entry(p, &ioc->sas_topology, list) {
1593 for (i = 0; i < p->num_phys; i++) {
1594 if (p->phy_info[i].attached.sas_address !=
1595 rphy->identify.sas_address)
1598 starget_printk(KERN_INFO, starget, MYIOC_s_FMT
1599 "delete device: fw_channel %d, fw_id %d, phy %d, "
1600 "sas_addr 0x%llx\n", ioc->name,
1601 p->phy_info[i].attached.channel,
1602 p->phy_info[i].attached.id,
1603 p->phy_info[i].attached.phy_id, (unsigned long long)
1604 p->phy_info[i].attached.sas_address);
1606 mptsas_set_starget(&p->phy_info[i], NULL);
1611 vtarget->starget = NULL;
1612 kfree(starget->hostdata);
1613 starget->hostdata = NULL;
1618 mptsas_slave_alloc(struct scsi_device *sdev)
1620 struct Scsi_Host *host = sdev->host;
1621 MPT_SCSI_HOST *hd = shost_priv(host);
1622 struct sas_rphy *rphy;
1623 struct mptsas_portinfo *p;
1624 VirtDevice *vdevice;
1625 struct scsi_target *starget;
1627 MPT_ADAPTER *ioc = hd->ioc;
1629 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
1631 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
1632 ioc->name, sizeof(VirtDevice));
1635 starget = scsi_target(sdev);
1636 vdevice->vtarget = starget->hostdata;
1638 if (sdev->channel == MPTSAS_RAID_CHANNEL)
1641 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
1642 mutex_lock(&ioc->sas_topology_mutex);
1643 list_for_each_entry(p, &ioc->sas_topology, list) {
1644 for (i = 0; i < p->num_phys; i++) {
1645 if (p->phy_info[i].attached.sas_address !=
1646 rphy->identify.sas_address)
1648 vdevice->lun = sdev->lun;
1650 * Exposing hidden raid components
1652 if (mptscsih_is_phys_disk(ioc,
1653 p->phy_info[i].attached.channel,
1654 p->phy_info[i].attached.id))
1655 sdev->no_uld_attach = 1;
1656 mutex_unlock(&ioc->sas_topology_mutex);
1660 mutex_unlock(&ioc->sas_topology_mutex);
1666 vdevice->vtarget->num_luns++;
1667 sdev->hostdata = vdevice;
1672 mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1676 VirtDevice *vdevice = SCpnt->device->hostdata;
1678 if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
1679 SCpnt->result = DID_NO_CONNECT << 16;
1684 hd = shost_priv(SCpnt->device->host);
1687 if (ioc->sas_discovery_quiesce_io)
1688 return SCSI_MLQUEUE_HOST_BUSY;
1690 // scsi_print_command(SCpnt);
1692 return mptscsih_qcmd(SCpnt,done);
1696 static struct scsi_host_template mptsas_driver_template = {
1697 .module = THIS_MODULE,
1698 .proc_name = "mptsas",
1699 .proc_info = mptscsih_proc_info,
1700 .name = "MPT SPI Host",
1701 .info = mptscsih_info,
1702 .queuecommand = mptsas_qcmd,
1703 .target_alloc = mptsas_target_alloc,
1704 .slave_alloc = mptsas_slave_alloc,
1705 .slave_configure = mptsas_slave_configure,
1706 .target_destroy = mptsas_target_destroy,
1707 .slave_destroy = mptscsih_slave_destroy,
1708 .change_queue_depth = mptscsih_change_queue_depth,
1709 .eh_abort_handler = mptscsih_abort,
1710 .eh_device_reset_handler = mptscsih_dev_reset,
1711 .eh_bus_reset_handler = mptscsih_bus_reset,
1712 .eh_host_reset_handler = mptscsih_host_reset,
1713 .bios_param = mptscsih_bios_param,
1714 .can_queue = MPT_FC_CAN_QUEUE,
1716 .sg_tablesize = MPT_SCSI_SG_DEPTH,
1717 .max_sectors = 8192,
1719 .use_clustering = ENABLE_CLUSTERING,
1720 .shost_attrs = mptscsih_host_attrs,
1723 static int mptsas_get_linkerrors(struct sas_phy *phy)
1725 MPT_ADAPTER *ioc = phy_to_ioc(phy);
1726 ConfigExtendedPageHeader_t hdr;
1728 SasPhyPage1_t *buffer;
1729 dma_addr_t dma_handle;
1732 /* FIXME: only have link errors on local phys */
1733 if (!scsi_is_sas_phy_local(phy))
1736 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
1737 hdr.ExtPageLength = 0;
1738 hdr.PageNumber = 1 /* page number 1*/;
1741 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1742 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
1744 cfg.cfghdr.ehdr = &hdr;
1746 cfg.pageAddr = phy->identify.phy_identifier;
1747 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1748 cfg.dir = 0; /* read */
1751 error = mpt_config(ioc, &cfg);
1754 if (!hdr.ExtPageLength)
1757 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1762 cfg.physAddr = dma_handle;
1763 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1765 error = mpt_config(ioc, &cfg);
1767 goto out_free_consistent;
1769 mptsas_print_phy_pg1(ioc, buffer);
1771 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
1772 phy->running_disparity_error_count =
1773 le32_to_cpu(buffer->RunningDisparityErrorCount);
1774 phy->loss_of_dword_sync_count =
1775 le32_to_cpu(buffer->LossDwordSynchCount);
1776 phy->phy_reset_problem_count =
1777 le32_to_cpu(buffer->PhyResetProblemCount);
1779 out_free_consistent:
1780 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1781 buffer, dma_handle);
1785 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
1786 MPT_FRAME_HDR *reply)
1788 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1789 if (reply != NULL) {
1790 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID;
1791 memcpy(ioc->sas_mgmt.reply, reply,
1792 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
1794 complete(&ioc->sas_mgmt.done);
1798 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
1800 MPT_ADAPTER *ioc = phy_to_ioc(phy);
1801 SasIoUnitControlRequest_t *req;
1802 SasIoUnitControlReply_t *reply;
1805 unsigned long timeleft;
1806 int error = -ERESTARTSYS;
1808 /* FIXME: fusion doesn't allow non-local phy reset */
1809 if (!scsi_is_sas_phy_local(phy))
1812 /* not implemented for expanders */
1813 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
1816 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
1819 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
1825 hdr = (MPIHeader_t *) mf;
1826 req = (SasIoUnitControlRequest_t *)mf;
1827 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
1828 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
1829 req->MsgContext = hdr->MsgContext;
1830 req->Operation = hard_reset ?
1831 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
1832 req->PhyNum = phy->identify.phy_identifier;
1834 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
1836 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
1839 /* On timeout reset the board */
1840 mpt_free_msg_frame(ioc, mf);
1841 mpt_HardResetHandler(ioc, CAN_SLEEP);
1846 /* a reply frame is expected */
1847 if ((ioc->sas_mgmt.status &
1848 MPT_MGMT_STATUS_RF_VALID) == 0) {
1853 /* process the completed Reply Message Frame */
1854 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
1855 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
1856 printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
1857 ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo);
1865 mutex_unlock(&ioc->sas_mgmt.mutex);
1871 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
1873 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
1875 struct mptsas_portinfo *p;
1876 struct mptsas_enclosure enclosure_info;
1877 u64 enclosure_handle;
1879 mutex_lock(&ioc->sas_topology_mutex);
1880 list_for_each_entry(p, &ioc->sas_topology, list) {
1881 for (i = 0; i < p->num_phys; i++) {
1882 if (p->phy_info[i].attached.sas_address ==
1883 rphy->identify.sas_address) {
1884 enclosure_handle = p->phy_info[i].
1885 attached.handle_enclosure;
1890 mutex_unlock(&ioc->sas_topology_mutex);
1894 mutex_unlock(&ioc->sas_topology_mutex);
1895 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
1896 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
1897 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
1898 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
1900 *identifier = enclosure_info.enclosure_logical_id;
1905 mptsas_get_bay_identifier(struct sas_rphy *rphy)
1907 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
1908 struct mptsas_portinfo *p;
1911 mutex_lock(&ioc->sas_topology_mutex);
1912 list_for_each_entry(p, &ioc->sas_topology, list) {
1913 for (i = 0; i < p->num_phys; i++) {
1914 if (p->phy_info[i].attached.sas_address ==
1915 rphy->identify.sas_address) {
1916 rc = p->phy_info[i].attached.slot;
1923 mutex_unlock(&ioc->sas_topology_mutex);
1927 static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1928 struct request *req)
1930 MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
1932 SmpPassthroughRequest_t *smpreq;
1933 struct request *rsp = req->next_rq;
1936 unsigned long timeleft;
1938 dma_addr_t dma_addr_in = 0;
1939 dma_addr_t dma_addr_out = 0;
1940 u64 sas_address = 0;
1943 printk(MYIOC_s_ERR_FMT "%s: the smp response space is missing\n",
1944 ioc->name, __func__);
1948 /* do we need to support multiple segments? */
1949 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
1950 printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n",
1951 ioc->name, __func__, req->bio->bi_vcnt, req->data_len,
1952 rsp->bio->bi_vcnt, rsp->data_len);
1956 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
1960 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
1966 smpreq = (SmpPassthroughRequest_t *)mf;
1967 memset(smpreq, 0, sizeof(*smpreq));
1969 smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4);
1970 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
1973 sas_address = rphy->identify.sas_address;
1975 struct mptsas_portinfo *port_info;
1977 mutex_lock(&ioc->sas_topology_mutex);
1978 port_info = ioc->hba_port_info;
1979 if (port_info && port_info->phy_info)
1981 port_info->phy_info[0].phy->identify.sas_address;
1982 mutex_unlock(&ioc->sas_topology_mutex);
1985 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
1988 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
1991 flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
1992 MPI_SGE_FLAGS_END_OF_BUFFER |
1993 MPI_SGE_FLAGS_DIRECTION)
1994 << MPI_SGE_FLAGS_SHIFT;
1995 flagsLength |= (req->data_len - 4);
1997 dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
1998 req->data_len, PCI_DMA_BIDIRECTIONAL);
2001 ioc->add_sge(psge, flagsLength, dma_addr_out);
2002 psge += (sizeof(u32) + sizeof(dma_addr_t));
2005 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
2006 flagsLength |= rsp->data_len + 4;
2007 dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio),
2008 rsp->data_len, PCI_DMA_BIDIRECTIONAL);
2011 ioc->add_sge(psge, flagsLength, dma_addr_in);
2013 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2015 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
2017 printk(MYIOC_s_ERR_FMT "%s: smp timeout!\n", ioc->name, __func__);
2018 /* On timeout reset the board */
2019 mpt_HardResetHandler(ioc, CAN_SLEEP);
2025 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
2026 SmpPassthroughReply_t *smprep;
2028 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
2029 memcpy(req->sense, smprep, sizeof(*smprep));
2030 req->sense_len = sizeof(*smprep);
2032 rsp->data_len -= smprep->ResponseDataLength;
2034 printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
2035 ioc->name, __func__);
2040 pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len,
2041 PCI_DMA_BIDIRECTIONAL);
2043 pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len,
2044 PCI_DMA_BIDIRECTIONAL);
2047 mpt_free_msg_frame(ioc, mf);
2049 mutex_unlock(&ioc->sas_mgmt.mutex);
2054 static struct sas_function_template mptsas_transport_functions = {
2055 .get_linkerrors = mptsas_get_linkerrors,
2056 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
2057 .get_bay_identifier = mptsas_get_bay_identifier,
2058 .phy_reset = mptsas_phy_reset,
2059 .smp_handler = mptsas_smp_handler,
2062 static struct scsi_transport_template *mptsas_transport_template;
2065 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
2067 ConfigExtendedPageHeader_t hdr;
2069 SasIOUnitPage0_t *buffer;
2070 dma_addr_t dma_handle;
2073 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
2074 hdr.ExtPageLength = 0;
2078 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2079 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2081 cfg.cfghdr.ehdr = &hdr;
2084 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2085 cfg.dir = 0; /* read */
2088 error = mpt_config(ioc, &cfg);
2091 if (!hdr.ExtPageLength) {
2096 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2103 cfg.physAddr = dma_handle;
2104 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2106 error = mpt_config(ioc, &cfg);
2108 goto out_free_consistent;
2110 port_info->num_phys = buffer->NumPhys;
2111 port_info->phy_info = kcalloc(port_info->num_phys,
2112 sizeof(*port_info->phy_info),GFP_KERNEL);
2113 if (!port_info->phy_info) {
2115 goto out_free_consistent;
2118 ioc->nvdata_version_persistent =
2119 le16_to_cpu(buffer->NvdataVersionPersistent);
2120 ioc->nvdata_version_default =
2121 le16_to_cpu(buffer->NvdataVersionDefault);
2123 for (i = 0; i < port_info->num_phys; i++) {
2124 mptsas_print_phy_data(ioc, &buffer->PhyData[i]);
2125 port_info->phy_info[i].phy_id = i;
2126 port_info->phy_info[i].port_id =
2127 buffer->PhyData[i].Port;
2128 port_info->phy_info[i].negotiated_link_rate =
2129 buffer->PhyData[i].NegotiatedLinkRate;
2130 port_info->phy_info[i].portinfo = port_info;
2131 port_info->phy_info[i].handle =
2132 le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
2135 out_free_consistent:
2136 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2137 buffer, dma_handle);
2143 mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
2145 ConfigExtendedPageHeader_t hdr;
2147 SasIOUnitPage1_t *buffer;
2148 dma_addr_t dma_handle;
2150 u16 device_missing_delay;
2152 memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
2153 memset(&cfg, 0, sizeof(CONFIGPARMS));
2155 cfg.cfghdr.ehdr = &hdr;
2156 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2158 cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2159 cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2160 cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION;
2161 cfg.cfghdr.ehdr->PageNumber = 1;
2163 error = mpt_config(ioc, &cfg);
2166 if (!hdr.ExtPageLength) {
2171 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2178 cfg.physAddr = dma_handle;
2179 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2181 error = mpt_config(ioc, &cfg);
2183 goto out_free_consistent;
2185 ioc->io_missing_delay =
2186 le16_to_cpu(buffer->IODeviceMissingDelay);
2187 device_missing_delay = le16_to_cpu(buffer->ReportDeviceMissingDelay);
2188 ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ?
2189 (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 :
2190 device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2192 out_free_consistent:
2193 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2194 buffer, dma_handle);
2200 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2201 u32 form, u32 form_specific)
2203 ConfigExtendedPageHeader_t hdr;
2205 SasPhyPage0_t *buffer;
2206 dma_addr_t dma_handle;
2209 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
2210 hdr.ExtPageLength = 0;
2214 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2215 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
2217 cfg.cfghdr.ehdr = &hdr;
2218 cfg.dir = 0; /* read */
2221 /* Get Phy Pg 0 for each Phy. */
2223 cfg.pageAddr = form + form_specific;
2224 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2226 error = mpt_config(ioc, &cfg);
2230 if (!hdr.ExtPageLength) {
2235 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2242 cfg.physAddr = dma_handle;
2243 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2245 error = mpt_config(ioc, &cfg);
2247 goto out_free_consistent;
2249 mptsas_print_phy_pg0(ioc, buffer);
2251 phy_info->hw_link_rate = buffer->HwLinkRate;
2252 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2253 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2254 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2256 out_free_consistent:
2257 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2258 buffer, dma_handle);
2264 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
2265 u32 form, u32 form_specific)
2267 ConfigExtendedPageHeader_t hdr;
2269 SasDevicePage0_t *buffer;
2270 dma_addr_t dma_handle;
2274 if (ioc->sas_discovery_runtime &&
2275 mptsas_is_end_device(device_info))
2278 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
2279 hdr.ExtPageLength = 0;
2283 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2284 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
2286 cfg.cfghdr.ehdr = &hdr;
2287 cfg.pageAddr = form + form_specific;
2289 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2290 cfg.dir = 0; /* read */
2293 memset(device_info, 0, sizeof(struct mptsas_devinfo));
2294 error = mpt_config(ioc, &cfg);
2297 if (!hdr.ExtPageLength) {
2302 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2309 cfg.physAddr = dma_handle;
2310 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2312 error = mpt_config(ioc, &cfg);
2314 goto out_free_consistent;
2316 mptsas_print_device_pg0(ioc, buffer);
2318 device_info->handle = le16_to_cpu(buffer->DevHandle);
2319 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
2320 device_info->handle_enclosure =
2321 le16_to_cpu(buffer->EnclosureHandle);
2322 device_info->slot = le16_to_cpu(buffer->Slot);
2323 device_info->phy_id = buffer->PhyNum;
2324 device_info->port_id = buffer->PhysicalPort;
2325 device_info->id = buffer->TargetID;
2326 device_info->phys_disk_num = ~0;
2327 device_info->channel = buffer->Bus;
2328 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
2329 device_info->sas_address = le64_to_cpu(sas_address);
2330 device_info->device_info =
2331 le32_to_cpu(buffer->DeviceInfo);
2333 out_free_consistent:
2334 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2335 buffer, dma_handle);
2341 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
2342 u32 form, u32 form_specific)
2344 ConfigExtendedPageHeader_t hdr;
2346 SasExpanderPage0_t *buffer;
2347 dma_addr_t dma_handle;
2350 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
2351 hdr.ExtPageLength = 0;
2355 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2356 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2358 cfg.cfghdr.ehdr = &hdr;
2360 cfg.pageAddr = form + form_specific;
2361 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2362 cfg.dir = 0; /* read */
2365 memset(port_info, 0, sizeof(struct mptsas_portinfo));
2366 error = mpt_config(ioc, &cfg);
2370 if (!hdr.ExtPageLength) {
2375 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2382 cfg.physAddr = dma_handle;
2383 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2385 error = mpt_config(ioc, &cfg);
2387 goto out_free_consistent;
2389 if (!buffer->NumPhys) {
2391 goto out_free_consistent;
2394 /* save config data */
2395 port_info->num_phys = buffer->NumPhys;
2396 port_info->phy_info = kcalloc(port_info->num_phys,
2397 sizeof(*port_info->phy_info),GFP_KERNEL);
2398 if (!port_info->phy_info) {
2400 goto out_free_consistent;
2403 for (i = 0; i < port_info->num_phys; i++) {
2404 port_info->phy_info[i].portinfo = port_info;
2405 port_info->phy_info[i].handle =
2406 le16_to_cpu(buffer->DevHandle);
2409 out_free_consistent:
2410 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2411 buffer, dma_handle);
2417 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2418 u32 form, u32 form_specific)
2420 ConfigExtendedPageHeader_t hdr;
2422 SasExpanderPage1_t *buffer;
2423 dma_addr_t dma_handle;
2426 if (ioc->sas_discovery_runtime &&
2427 mptsas_is_end_device(&phy_info->attached))
2430 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
2431 hdr.ExtPageLength = 0;
2435 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2436 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2438 cfg.cfghdr.ehdr = &hdr;
2440 cfg.pageAddr = form + form_specific;
2441 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2442 cfg.dir = 0; /* read */
2445 error = mpt_config(ioc, &cfg);
2449 if (!hdr.ExtPageLength) {
2454 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2461 cfg.physAddr = dma_handle;
2462 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2464 error = mpt_config(ioc, &cfg);
2466 goto out_free_consistent;
2469 mptsas_print_expander_pg1(ioc, buffer);
2471 /* save config data */
2472 phy_info->phy_id = buffer->PhyIdentifier;
2473 phy_info->port_id = buffer->PhysicalPort;
2474 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
2475 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2476 phy_info->hw_link_rate = buffer->HwLinkRate;
2477 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2478 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2480 out_free_consistent:
2481 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2482 buffer, dma_handle);
2488 mptsas_parse_device_info(struct sas_identify *identify,
2489 struct mptsas_devinfo *device_info)
2493 identify->sas_address = device_info->sas_address;
2494 identify->phy_identifier = device_info->phy_id;
2497 * Fill in Phy Initiator Port Protocol.
2498 * Bits 6:3, more than one bit can be set, fall through cases.
2500 protocols = device_info->device_info & 0x78;
2501 identify->initiator_port_protocols = 0;
2502 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
2503 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
2504 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
2505 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
2506 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
2507 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
2508 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
2509 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
2512 * Fill in Phy Target Port Protocol.
2513 * Bits 10:7, more than one bit can be set, fall through cases.
2515 protocols = device_info->device_info & 0x780;
2516 identify->target_port_protocols = 0;
2517 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
2518 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
2519 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
2520 identify->target_port_protocols |= SAS_PROTOCOL_STP;
2521 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
2522 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
2523 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
2524 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
2527 * Fill in Attached device type.
2529 switch (device_info->device_info &
2530 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
2531 case MPI_SAS_DEVICE_INFO_NO_DEVICE:
2532 identify->device_type = SAS_PHY_UNUSED;
2534 case MPI_SAS_DEVICE_INFO_END_DEVICE:
2535 identify->device_type = SAS_END_DEVICE;
2537 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
2538 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
2540 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
2541 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
2546 static int mptsas_probe_one_phy(struct device *dev,
2547 struct mptsas_phyinfo *phy_info, int index, int local)
2550 struct sas_phy *phy;
2551 struct sas_port *port;
2559 if (!phy_info->phy) {
2560 phy = sas_phy_alloc(dev, index);
2566 phy = phy_info->phy;
2568 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
2571 * Set Negotiated link rate.
2573 switch (phy_info->negotiated_link_rate) {
2574 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
2575 phy->negotiated_linkrate = SAS_PHY_DISABLED;
2577 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
2578 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
2580 case MPI_SAS_IOUNIT0_RATE_1_5:
2581 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
2583 case MPI_SAS_IOUNIT0_RATE_3_0:
2584 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
2586 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
2587 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
2589 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
2594 * Set Max hardware link rate.
2596 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
2597 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
2598 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
2600 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
2601 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
2608 * Set Max programmed link rate.
2610 switch (phy_info->programmed_link_rate &
2611 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
2612 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
2613 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
2615 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
2616 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
2623 * Set Min hardware link rate.
2625 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
2626 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
2627 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
2629 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
2630 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
2637 * Set Min programmed link rate.
2639 switch (phy_info->programmed_link_rate &
2640 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
2641 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
2642 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
2644 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
2645 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
2651 if (!phy_info->phy) {
2653 error = sas_phy_add(phy);
2658 phy_info->phy = phy;
2661 if (!phy_info->attached.handle ||
2662 !phy_info->port_details)
2665 port = mptsas_get_port(phy_info);
2666 ioc = phy_to_ioc(phy_info->phy);
2668 if (phy_info->sas_port_add_phy) {
2671 port = sas_port_alloc_num(dev);
2676 error = sas_port_add(port);
2678 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2679 "%s: exit at line=%d\n", ioc->name,
2680 __func__, __LINE__));
2683 mptsas_set_port(ioc, phy_info, port);
2684 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2685 "sas_port_alloc: port=%p dev=%p port_id=%d\n",
2686 ioc->name, port, dev, port->port_identifier));
2688 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_port_add_phy: phy_id=%d\n",
2689 ioc->name, phy_info->phy_id));
2690 sas_port_add_phy(port, phy_info->phy);
2691 phy_info->sas_port_add_phy = 0;
2694 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
2696 struct sas_rphy *rphy;
2697 struct device *parent;
2698 struct sas_identify identify;
2700 parent = dev->parent->parent;
2702 * Let the hotplug_work thread handle processing
2703 * the adding/removing of devices that occur
2704 * after start of day.
2706 if (ioc->sas_discovery_runtime &&
2707 mptsas_is_end_device(&phy_info->attached))
2710 mptsas_parse_device_info(&identify, &phy_info->attached);
2711 if (scsi_is_host_device(parent)) {
2712 struct mptsas_portinfo *port_info;
2715 port_info = ioc->hba_port_info;
2717 for (i = 0; i < port_info->num_phys; i++)
2718 if (port_info->phy_info[i].identify.sas_address ==
2719 identify.sas_address) {
2720 sas_port_mark_backlink(port);
2724 } else if (scsi_is_sas_rphy(parent)) {
2725 struct sas_rphy *parent_rphy = dev_to_rphy(parent);
2726 if (identify.sas_address ==
2727 parent_rphy->identify.sas_address) {
2728 sas_port_mark_backlink(port);
2733 switch (identify.device_type) {
2734 case SAS_END_DEVICE:
2735 rphy = sas_end_device_alloc(port);
2737 case SAS_EDGE_EXPANDER_DEVICE:
2738 case SAS_FANOUT_EXPANDER_DEVICE:
2739 rphy = sas_expander_alloc(port, identify.device_type);
2746 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2747 "%s: exit at line=%d\n", ioc->name,
2748 __func__, __LINE__));
2752 rphy->identify = identify;
2753 error = sas_rphy_add(rphy);
2755 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2756 "%s: exit at line=%d\n", ioc->name,
2757 __func__, __LINE__));
2758 sas_rphy_free(rphy);
2761 mptsas_set_rphy(ioc, phy_info, rphy);
2769 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
2771 struct mptsas_portinfo *port_info, *hba;
2772 int error = -ENOMEM, i;
2774 hba = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
2778 error = mptsas_sas_io_unit_pg0(ioc, hba);
2780 goto out_free_port_info;
2782 mptsas_sas_io_unit_pg1(ioc);
2783 mutex_lock(&ioc->sas_topology_mutex);
2784 port_info = ioc->hba_port_info;
2786 ioc->hba_port_info = port_info = hba;
2787 ioc->hba_port_num_phy = port_info->num_phys;
2788 list_add_tail(&port_info->list, &ioc->sas_topology);
2790 for (i = 0; i < hba->num_phys; i++) {
2791 port_info->phy_info[i].negotiated_link_rate =
2792 hba->phy_info[i].negotiated_link_rate;
2793 port_info->phy_info[i].handle =
2794 hba->phy_info[i].handle;
2795 port_info->phy_info[i].port_id =
2796 hba->phy_info[i].port_id;
2798 kfree(hba->phy_info);
2802 mutex_unlock(&ioc->sas_topology_mutex);
2803 #if defined(CPQ_CIM)
2804 ioc->num_ports = port_info->num_phys;
2806 for (i = 0; i < port_info->num_phys; i++) {
2807 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
2808 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
2809 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
2810 port_info->phy_info[i].identify.handle =
2811 port_info->phy_info[i].handle;
2812 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
2813 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2814 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2815 port_info->phy_info[i].identify.handle);
2816 if (!ioc->hba_port_sas_addr)
2817 ioc->hba_port_sas_addr =
2818 port_info->phy_info[i].identify.sas_address;
2819 port_info->phy_info[i].identify.phy_id =
2820 port_info->phy_info[i].phy_id = i;
2821 if (port_info->phy_info[i].attached.handle)
2822 mptsas_sas_device_pg0(ioc,
2823 &port_info->phy_info[i].attached,
2824 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2825 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2826 port_info->phy_info[i].attached.handle);
2829 mptsas_setup_wide_ports(ioc, port_info);
2831 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
2832 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
2833 &port_info->phy_info[i], ioc->sas_index, 1);
2844 mptsas_expander_refresh(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
2846 struct mptsas_portinfo *parent;
2847 struct device *parent_dev;
2848 struct sas_rphy *rphy;
2850 u64 sas_address; /* expander sas address */
2853 handle = port_info->phy_info[0].handle;
2854 sas_address = port_info->phy_info[0].identify.sas_address;
2855 for (i = 0; i < port_info->num_phys; i++) {
2856 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
2857 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
2858 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + handle);
2860 mptsas_sas_device_pg0(ioc,
2861 &port_info->phy_info[i].identify,
2862 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2863 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2864 port_info->phy_info[i].identify.handle);
2865 port_info->phy_info[i].identify.phy_id =
2866 port_info->phy_info[i].phy_id;
2868 if (port_info->phy_info[i].attached.handle) {
2869 mptsas_sas_device_pg0(ioc,
2870 &port_info->phy_info[i].attached,
2871 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
2872 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2873 port_info->phy_info[i].attached.handle);
2874 port_info->phy_info[i].attached.phy_id =
2875 port_info->phy_info[i].phy_id;
2879 mutex_lock(&ioc->sas_topology_mutex);
2880 parent = mptsas_find_portinfo_by_handle(ioc,
2881 port_info->phy_info[0].identify.handle_parent);
2883 mutex_unlock(&ioc->sas_topology_mutex);
2886 for (i = 0, parent_dev = NULL; i < parent->num_phys && !parent_dev;
2888 if (parent->phy_info[i].attached.sas_address == sas_address) {
2889 rphy = mptsas_get_rphy(&parent->phy_info[i]);
2890 parent_dev = &rphy->dev;
2893 mutex_unlock(&ioc->sas_topology_mutex);
2895 mptsas_setup_wide_ports(ioc, port_info);
2896 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
2897 mptsas_probe_one_phy(parent_dev, &port_info->phy_info[i],
2902 mptsas_expander_event_add(MPT_ADAPTER *ioc,
2903 MpiEventDataSasExpanderStatusChange_t *expander_data)
2905 struct mptsas_portinfo *port_info;
2909 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
2912 port_info->num_phys = (expander_data->NumPhys) ?
2913 expander_data->NumPhys : 1;
2914 port_info->phy_info = kcalloc(port_info->num_phys,
2915 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
2916 if (!port_info->phy_info)
2918 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
2919 for (i = 0; i < port_info->num_phys; i++) {
2920 port_info->phy_info[i].portinfo = port_info;
2921 port_info->phy_info[i].handle =
2922 le16_to_cpu(expander_data->DevHandle);
2923 port_info->phy_info[i].identify.sas_address =
2924 le64_to_cpu(sas_address);
2925 port_info->phy_info[i].identify.handle_parent =
2926 le16_to_cpu(expander_data->ParentDevHandle);
2929 mutex_lock(&ioc->sas_topology_mutex);
2930 list_add_tail(&port_info->list, &ioc->sas_topology);
2931 mutex_unlock(&ioc->sas_topology_mutex);
2933 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
2934 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
2935 (unsigned long long)sas_address);
2937 mptsas_expander_refresh(ioc, port_info);
2941 * mptsas_delete_expander_siblings - remove siblings attached to expander
2942 * @ioc: Pointer to MPT_ADAPTER structure
2943 * @parent: the parent port_info object
2944 * @expander: the expander port_info object
2947 mptsas_delete_expander_siblings(MPT_ADAPTER *ioc, struct mptsas_portinfo
2948 *parent, struct mptsas_portinfo *expander)
2950 struct mptsas_phyinfo *phy_info;
2951 struct mptsas_portinfo *port_info;
2952 struct sas_rphy *rphy;
2955 phy_info = expander->phy_info;
2956 for (i = 0; i < expander->num_phys; i++, phy_info++) {
2957 rphy = mptsas_get_rphy(phy_info);
2960 if (rphy->identify.device_type == SAS_END_DEVICE)
2961 mptsas_del_end_device(ioc, phy_info);
2964 phy_info = expander->phy_info;
2965 for (i = 0; i < expander->num_phys; i++, phy_info++) {
2966 rphy = mptsas_get_rphy(phy_info);
2969 if (rphy->identify.device_type ==
2970 MPI_SAS_DEVICE_INFO_EDGE_EXPANDER ||
2971 rphy->identify.device_type ==
2972 MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
2973 port_info = mptsas_find_portinfo_by_sas_address(ioc,
2974 rphy->identify.sas_address);
2977 if (port_info == parent) /* backlink rphy */
2980 Delete this expander even if the expdevpage is exists
2981 because the parent expander is already deleted
2983 mptsas_expander_delete(ioc, port_info, 1);
2990 * mptsas_expander_delete - remove this expander
2991 * @ioc: Pointer to MPT_ADAPTER structure
2992 * @port_info: expander port_info struct
2993 * @force: Flag to forcefully delete the expander
2997 static void mptsas_expander_delete(MPT_ADAPTER *ioc,
2998 struct mptsas_portinfo *port_info, u8 force)
3001 struct mptsas_portinfo *parent;
3003 u64 expander_sas_address;
3004 struct mptsas_phyinfo *phy_info;
3005 struct mptsas_portinfo buffer;
3006 struct mptsas_portinfo_details *port_details;
3007 struct sas_port *port;
3012 /* see if expander is still there before deleting */
3013 mptsas_sas_expander_pg0(ioc, &buffer,
3014 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
3015 MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
3016 port_info->phy_info[0].identify.handle);
3018 if (buffer.num_phys) {
3019 kfree(buffer.phy_info);
3026 * Obtain the port_info instance to the parent port
3028 port_details = NULL;
3029 expander_sas_address =
3030 port_info->phy_info[0].identify.sas_address;
3031 parent = mptsas_find_portinfo_by_handle(ioc,
3032 port_info->phy_info[0].identify.handle_parent);
3033 mptsas_delete_expander_siblings(ioc, parent, port_info);
3038 * Delete rphys in the parent that point
3041 phy_info = parent->phy_info;
3043 for (i = 0; i < parent->num_phys; i++, phy_info++) {
3046 if (phy_info->attached.sas_address !=
3047 expander_sas_address)
3050 port = mptsas_get_port(phy_info);
3051 port_details = phy_info->port_details;
3053 dev_printk(KERN_DEBUG, &phy_info->phy->dev,
3054 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", ioc->name,
3055 phy_info->phy_id, phy_info->phy);
3056 sas_port_delete_phy(port, phy_info->phy);
3059 dev_printk(KERN_DEBUG, &port->dev,
3060 MYIOC_s_FMT "delete port %d, sas_addr (0x%llx)\n",
3061 ioc->name, port->port_identifier,
3062 (unsigned long long)expander_sas_address);
3063 sas_port_delete(port);
3064 mptsas_port_delete(ioc, port_details);
3068 printk(MYIOC_s_INFO_FMT "delete expander: num_phys %d, "
3069 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3070 (unsigned long long)expander_sas_address);
3075 list_del(&port_info->list);
3076 kfree(port_info->phy_info);
3082 * mptsas_send_expander_event - expanders events
3083 * @ioc: Pointer to MPT_ADAPTER structure
3084 * @expander_data: event data
3087 * This function handles adding, removing, and refreshing
3088 * device handles within the expander objects.
3091 mptsas_send_expander_event(struct fw_event_work *fw_event)
3094 MpiEventDataSasExpanderStatusChange_t *expander_data;
3095 struct mptsas_portinfo *port_info;
3099 ioc = fw_event->ioc;
3100 expander_data = (MpiEventDataSasExpanderStatusChange_t *)
3101 fw_event->event_data;
3102 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
3103 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3105 if (expander_data->ReasonCode == MPI_EVENT_SAS_EXP_RC_ADDED) {
3107 for (i = 0; i < port_info->num_phys; i++) {
3108 port_info->phy_info[i].portinfo = port_info;
3109 port_info->phy_info[i].handle =
3110 le16_to_cpu(expander_data->DevHandle);
3111 port_info->phy_info[i].identify.sas_address =
3112 le64_to_cpu(sas_address);
3113 port_info->phy_info[i].identify.handle_parent =
3114 le16_to_cpu(expander_data->ParentDevHandle);
3116 mptsas_expander_refresh(ioc, port_info);
3117 } else if (!port_info && expander_data->NumPhys)
3118 mptsas_expander_event_add(ioc, expander_data);
3119 } else if (expander_data->ReasonCode ==
3120 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING)
3121 mptsas_expander_delete(ioc, port_info, 0);
3123 mptsas_free_fw_event(ioc, fw_event);
3128 * mptsas_expander_add -
3129 * @ioc: Pointer to MPT_ADAPTER structure
3133 struct mptsas_portinfo *
3134 mptsas_expander_add(MPT_ADAPTER *ioc, u16 handle)
3136 struct mptsas_portinfo buffer, *port_info;
3139 if ((mptsas_sas_expander_pg0(ioc, &buffer,
3140 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
3141 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)))
3144 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_ATOMIC);
3146 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3147 "%s: exit at line=%d\n", ioc->name,
3148 __func__, __LINE__));
3151 port_info->num_phys = buffer.num_phys;
3152 port_info->phy_info = buffer.phy_info;
3153 for (i = 0; i < port_info->num_phys; i++)
3154 port_info->phy_info[i].portinfo = port_info;
3155 mutex_lock(&ioc->sas_topology_mutex);
3156 list_add_tail(&port_info->list, &ioc->sas_topology);
3157 mutex_unlock(&ioc->sas_topology_mutex);
3158 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3159 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3160 (unsigned long long)buffer.phy_info[0].identify.sas_address);
3161 mptsas_expander_refresh(ioc, port_info);
3166 mptsas_send_link_status_event(struct fw_event_work *fw_event)
3169 MpiEventDataSasPhyLinkStatus_t *link_data;
3170 struct mptsas_portinfo *port_info;
3171 struct mptsas_phyinfo *phy_info = NULL;
3176 ioc = fw_event->ioc;
3177 link_data = (MpiEventDataSasPhyLinkStatus_t *)fw_event->event_data;
3179 memcpy(&sas_address, &link_data->SASAddress, sizeof(__le64));
3180 sas_address = le64_to_cpu(sas_address);
3181 link_rate = link_data->LinkRates >> 4;
3182 phy_num = link_data->PhyNum;
3184 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3186 phy_info = &port_info->phy_info[phy_num];
3188 phy_info->negotiated_link_rate = link_rate;
3191 if (link_rate == MPI_SAS_IOUNIT0_RATE_1_5 ||
3192 link_rate == MPI_SAS_IOUNIT0_RATE_3_0) {
3195 if (ioc->old_sas_discovery_protocal) {
3196 port_info = mptsas_expander_add(ioc,
3197 le16_to_cpu(link_data->DevHandle));
3204 if (port_info == ioc->hba_port_info)
3205 mptsas_probe_hba_phys(ioc);
3207 mptsas_expander_refresh(ioc, port_info);
3208 } else if (phy_info && phy_info->phy) {
3209 if (link_rate == MPI_SAS_IOUNIT0_RATE_PHY_DISABLED)
3210 phy_info->phy->negotiated_linkrate =
3212 else if (link_rate ==
3213 MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION)
3214 phy_info->phy->negotiated_linkrate =
3215 SAS_LINK_RATE_FAILED;
3217 phy_info->phy->negotiated_linkrate =
3218 SAS_LINK_RATE_UNKNOWN;
3221 mptsas_free_fw_event(ioc, fw_event);
3225 mptsas_not_responding_devices(MPT_ADAPTER *ioc)
3227 struct mptsas_portinfo buffer, *port_info;
3228 struct mptsas_device_info *sas_info;
3229 struct mptsas_devinfo sas_device;
3231 VirtTarget *vtarget = NULL;
3232 struct mptsas_phyinfo *phy_info;
3234 int retval, retry_count;
3235 unsigned long flags;
3237 mpt_findImVolumes(ioc);
3239 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
3240 if (ioc->ioc_reset_in_progress) {
3241 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3242 "%s: exiting due to a parallel reset \n", ioc->name,
3244 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3247 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3249 /* devices, logical volumes */
3250 mutex_lock(&ioc->sas_device_info_mutex);
3252 list_for_each_entry(sas_info, &ioc->sas_device_info_list, list) {
3253 sas_device.handle = 0;
3256 retval = mptsas_sas_device_pg0(ioc, &sas_device,
3257 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID
3258 << MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3259 (sas_info->fw.channel << 8) +
3262 if (sas_device.handle)
3264 if (retval == -EBUSY) {
3265 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
3266 if (ioc->ioc_reset_in_progress) {
3268 printk(MYIOC_s_DEBUG_FMT
3269 "%s: exiting due to reset\n",
3270 ioc->name, __func__));
3271 spin_unlock_irqrestore
3272 (&ioc->taskmgmt_lock, flags);
3273 mutex_unlock(&ioc->sas_device_info_mutex);
3276 spin_unlock_irqrestore(&ioc->taskmgmt_lock,
3280 if (retval && (retval != -ENODEV)) {
3281 if (retry_count < 10) {
3285 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3286 "%s: Config page retry exceeded retry "
3287 "count deleting device 0x%llx\n",
3288 ioc->name, __func__,
3289 sas_info->sas_address));
3294 vtarget = mptsas_find_vtarget(ioc,
3295 sas_info->fw.channel, sas_info->fw.id);
3297 vtarget->deleted = 1;
3298 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3299 sas_info->sas_address);
3301 mptsas_del_end_device(ioc, phy_info);
3302 goto redo_device_scan;
3305 mutex_unlock(&ioc->sas_device_info_mutex);
3308 mutex_lock(&ioc->sas_topology_mutex);
3310 list_for_each_entry(port_info, &ioc->sas_topology, list) {
3312 if (port_info->phy_info &&
3313 (!(port_info->phy_info[0].identify.device_info &
3314 MPI_SAS_DEVICE_INFO_SMP_TARGET)))
3318 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3319 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
3320 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle) &&
3323 handle = buffer.phy_info[0].handle;
3324 if (buffer.phy_info[0].identify.sas_address ==
3325 port_info->phy_info[0].identify.sas_address) {
3328 kfree(buffer.phy_info);
3331 if (!found_expander) {
3332 mptsas_expander_delete(ioc, port_info, 0);
3333 goto redo_expander_scan;
3336 mutex_lock(&ioc->sas_topology_mutex);
3340 * mptsas_probe_expanders - adding expanders
3341 * @ioc: Pointer to MPT_ADAPTER structure
3345 mptsas_probe_expanders(MPT_ADAPTER *ioc)
3347 struct mptsas_portinfo buffer, *port_info;
3352 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3353 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
3354 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)) {
3356 handle = buffer.phy_info[0].handle;
3357 port_info = mptsas_find_portinfo_by_sas_address(ioc,
3358 buffer.phy_info[0].identify.sas_address);
3361 /* refreshing handles */
3362 for (i = 0; i < buffer.num_phys; i++) {
3363 port_info->phy_info[i].handle = handle;
3364 port_info->phy_info[i].identify.handle_parent =
3365 buffer.phy_info[0].identify.handle_parent;
3367 mptsas_expander_refresh(ioc, port_info);
3368 kfree(buffer.phy_info);
3372 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
3374 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3375 "%s: exit at line=%d\n", ioc->name,
3376 __func__, __LINE__));
3379 port_info->num_phys = buffer.num_phys;
3380 port_info->phy_info = buffer.phy_info;
3381 for (i = 0; i < port_info->num_phys; i++)
3382 port_info->phy_info[i].portinfo = port_info;
3383 mutex_lock(&ioc->sas_topology_mutex);
3384 list_add_tail(&port_info->list, &ioc->sas_topology);
3385 mutex_unlock(&ioc->sas_topology_mutex);
3386 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3387 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3388 (unsigned long long)buffer.phy_info[0].identify.sas_address);
3389 mptsas_expander_refresh(ioc, port_info);
3394 mptsas_probe_devices(MPT_ADAPTER *ioc)
3397 struct mptsas_devinfo sas_device;
3398 struct mptsas_phyinfo *phy_info;
3401 while (!(mptsas_sas_device_pg0(ioc, &sas_device,
3402 MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
3404 handle = sas_device.handle;
3406 if ((sas_device.device_info &
3407 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
3408 MPI_SAS_DEVICE_INFO_STP_TARGET |
3409 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0)
3412 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
3416 if (mptsas_get_rphy(phy_info))
3419 mptsas_add_end_device(ioc, phy_info);
3424 * Start of day discovery
3427 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
3429 struct scsi_device *sdev;
3432 mptsas_probe_hba_phys(ioc);
3433 mptsas_probe_expanders(ioc);
3434 mptsas_probe_devices(ioc);
3437 Reporting RAID volumes.
3439 if (!ioc->ir_firmware || !ioc->raid_data.pIocPg2 ||
3440 !ioc->raid_data.pIocPg2->NumActiveVolumes)
3442 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
3443 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
3444 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
3446 scsi_device_put(sdev);
3449 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
3450 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
3451 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID);
3452 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
3453 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
3457 static struct mptsas_phyinfo *
3458 mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
3460 struct mptsas_portinfo *port_info;
3461 struct mptsas_phyinfo *phy_info = NULL;
3464 mutex_lock(&ioc->sas_topology_mutex);
3465 list_for_each_entry(port_info, &ioc->sas_topology, list) {
3466 for (i = 0; i < port_info->num_phys; i++) {
3467 if (!mptsas_is_end_device(
3468 &port_info->phy_info[i].attached))
3470 if (port_info->phy_info[i].attached.sas_address
3473 phy_info = &port_info->phy_info[i];
3477 mutex_unlock(&ioc->sas_topology_mutex);
3482 static struct mptsas_phyinfo *
3483 mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
3485 struct mptsas_portinfo *port_info;
3486 struct mptsas_phyinfo *phy_info = NULL;
3489 mutex_lock(&ioc->sas_topology_mutex);
3490 list_for_each_entry(port_info, &ioc->sas_topology, list) {
3491 for (i = 0; i < port_info->num_phys; i++) {
3492 if (!mptsas_is_end_device(
3493 &port_info->phy_info[i].attached))
3495 if (port_info->phy_info[i].attached.phys_disk_num == ~0)
3497 if (port_info->phy_info[i].attached.phys_disk_num != id)
3499 if (port_info->phy_info[i].attached.channel != channel)
3501 phy_info = &port_info->phy_info[i];
3505 mutex_unlock(&ioc->sas_topology_mutex);
3510 mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
3514 sdev->no_uld_attach = data ? 1 : 0;
3515 rc = scsi_device_reprobe(sdev);
3519 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
3521 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
3522 mptsas_reprobe_lun);
3526 mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
3529 ConfigPageHeader_t hdr;
3530 dma_addr_t dma_handle;
3531 pRaidVolumePage0_t buffer = NULL;
3532 RaidPhysDiskPage0_t phys_disk;
3534 struct mptsas_phyinfo *phy_info;
3535 struct mptsas_devinfo sas_device;
3537 memset(&cfg, 0 , sizeof(CONFIGPARMS));
3538 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
3539 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
3540 cfg.pageAddr = (channel << 8) + id;
3541 cfg.cfghdr.hdr = &hdr;
3542 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3544 if (mpt_config(ioc, &cfg) != 0)
3547 if (!hdr.PageLength)
3550 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
3556 cfg.physAddr = dma_handle;
3557 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
3559 if (mpt_config(ioc, &cfg) != 0)
3562 if (!(buffer->VolumeStatus.Flags &
3563 MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
3566 if (!buffer->NumPhysDisks)
3569 for (i = 0; i < buffer->NumPhysDisks; i++) {
3571 if (mpt_raid_phys_disk_pg0(ioc,
3572 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
3575 if (mptsas_sas_device_pg0(ioc, &sas_device,
3576 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
3577 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3578 (phys_disk.PhysDiskBus << 8) +
3579 phys_disk.PhysDiskID))
3582 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3583 sas_device.sas_address);
3584 mptsas_add_end_device(ioc, phy_info);
3589 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
3593 * Work queue thread to handle SAS hotplug events
3596 mptsas_hotplug_work(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
3597 struct mptsas_hotplug_event *hot_plug_info)
3599 struct mptsas_phyinfo *phy_info;
3600 struct scsi_target * starget;
3601 struct mptsas_devinfo sas_device;
3602 VirtTarget *vtarget;
3605 switch (hot_plug_info->event_type) {
3607 case MPTSAS_ADD_PHYSDISK:
3609 if (!ioc->raid_data.pIocPg2)
3612 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
3613 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID ==
3614 hot_plug_info->id) {
3615 printk(MYIOC_s_WARN_FMT "firmware bug: unable "
3616 "to add hidden disk - target_id matchs "
3617 "volume_id\n", ioc->name);
3618 mptsas_free_fw_event(ioc, fw_event);
3622 mpt_findImVolumes(ioc);
3624 case MPTSAS_ADD_DEVICE:
3625 memset(&sas_device, 0, sizeof(struct mptsas_devinfo));
3626 mptsas_sas_device_pg0(ioc, &sas_device,
3627 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
3628 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3629 (hot_plug_info->channel << 8) +
3632 if (!sas_device.handle)
3635 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
3639 if (mptsas_get_rphy(phy_info))
3642 mptsas_add_end_device(ioc, phy_info);
3645 case MPTSAS_DEL_DEVICE:
3646 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3647 hot_plug_info->sas_address);
3648 mptsas_del_end_device(ioc, phy_info);
3651 case MPTSAS_DEL_PHYSDISK:
3653 mpt_findImVolumes(ioc);
3655 phy_info = mptsas_find_phyinfo_by_phys_disk_num(
3656 ioc, hot_plug_info->channel,
3657 hot_plug_info->phys_disk_num);
3658 mptsas_del_end_device(ioc, phy_info);
3661 case MPTSAS_ADD_PHYSDISK_REPROBE:
3663 if (mptsas_sas_device_pg0(ioc, &sas_device,
3664 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
3665 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3666 (hot_plug_info->channel << 8) + hot_plug_info->id)) {
3667 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3668 "%s: fw_id=%d exit at line=%d\n", ioc->name,
3669 __func__, hot_plug_info->id, __LINE__));
3673 phy_info = mptsas_find_phyinfo_by_sas_address(
3674 ioc, sas_device.sas_address);
3677 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3678 "%s: fw_id=%d exit at line=%d\n", ioc->name,
3679 __func__, hot_plug_info->id, __LINE__));
3683 starget = mptsas_get_starget(phy_info);
3685 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3686 "%s: fw_id=%d exit at line=%d\n", ioc->name,
3687 __func__, hot_plug_info->id, __LINE__));
3691 vtarget = starget->hostdata;
3693 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3694 "%s: fw_id=%d exit at line=%d\n", ioc->name,
3695 __func__, hot_plug_info->id, __LINE__));
3699 mpt_findImVolumes(ioc);
3701 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Hidding: "
3702 "fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
3703 ioc->name, hot_plug_info->channel, hot_plug_info->id,
3704 hot_plug_info->phys_disk_num, (unsigned long long)
3705 sas_device.sas_address);
3707 vtarget->id = hot_plug_info->phys_disk_num;
3708 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
3709 phy_info->attached.phys_disk_num = hot_plug_info->phys_disk_num;
3710 mptsas_reprobe_target(starget, 1);
3713 case MPTSAS_DEL_PHYSDISK_REPROBE:
3715 if (mptsas_sas_device_pg0(ioc, &sas_device,
3716 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
3717 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3718 (hot_plug_info->channel << 8) + hot_plug_info->id)) {
3719 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3720 "%s: fw_id=%d exit at line=%d\n",
3721 ioc->name, __func__,
3722 hot_plug_info->id, __LINE__));
3726 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3727 sas_device.sas_address);
3729 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3730 "%s: fw_id=%d exit at line=%d\n", ioc->name,
3731 __func__, hot_plug_info->id, __LINE__));
3735 starget = mptsas_get_starget(phy_info);
3737 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3738 "%s: fw_id=%d exit at line=%d\n", ioc->name,
3739 __func__, hot_plug_info->id, __LINE__));
3743 vtarget = starget->hostdata;
3745 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3746 "%s: fw_id=%d exit at line=%d\n", ioc->name,
3747 __func__, hot_plug_info->id, __LINE__));
3751 if (!(vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)) {
3752 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3753 "%s: fw_id=%d exit at line=%d\n", ioc->name,
3754 __func__, hot_plug_info->id, __LINE__));
3758 mpt_findImVolumes(ioc);
3760 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Exposing:"
3761 " fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
3762 ioc->name, hot_plug_info->channel, hot_plug_info->id,
3763 hot_plug_info->phys_disk_num, (unsigned long long)
3764 sas_device.sas_address);
3766 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
3767 vtarget->id = hot_plug_info->id;
3768 phy_info->attached.phys_disk_num = ~0;
3769 mptsas_reprobe_target(starget, 0);
3770 mptsas_add_device_component_by_fw(ioc,
3771 hot_plug_info->channel, hot_plug_info->id);
3774 case MPTSAS_ADD_RAID:
3776 mpt_findImVolumes(ioc);
3777 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
3778 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
3780 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
3781 hot_plug_info->id, 0);
3784 case MPTSAS_DEL_RAID:
3786 mpt_findImVolumes(ioc);
3787 printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
3788 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
3790 scsi_remove_device(hot_plug_info->sdev);
3791 scsi_device_put(hot_plug_info->sdev);
3794 case MPTSAS_ADD_INACTIVE_VOLUME:
3796 mpt_findImVolumes(ioc);
3797 mptsas_adding_inactive_raid_components(ioc,
3798 hot_plug_info->channel, hot_plug_info->id);
3805 mptsas_free_fw_event(ioc, fw_event);
3809 mptsas_send_sas_event(struct fw_event_work *fw_event)
3812 struct mptsas_hotplug_event hot_plug_info;
3813 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
3817 ioc = fw_event->ioc;
3818 sas_event_data = (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)
3819 fw_event->event_data;
3820 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
3823 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
3824 MPI_SAS_DEVICE_INFO_STP_TARGET |
3825 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) {
3826 mptsas_free_fw_event(ioc, fw_event);
3830 if (sas_event_data->ReasonCode ==
3831 MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED) {
3832 mptbase_sas_persist_operation(ioc,
3833 MPI_SAS_OP_CLEAR_NOT_PRESENT);
3834 mptsas_free_fw_event(ioc, fw_event);
3838 switch (sas_event_data->ReasonCode) {
3839 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
3840 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
3841 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
3842 hot_plug_info.handle = le16_to_cpu(sas_event_data->DevHandle);
3843 hot_plug_info.channel = sas_event_data->Bus;
3844 hot_plug_info.id = sas_event_data->TargetID;
3845 hot_plug_info.phy_id = sas_event_data->PhyNum;
3846 memcpy(&sas_address, &sas_event_data->SASAddress,
3848 hot_plug_info.sas_address = le64_to_cpu(sas_address);
3849 hot_plug_info.device_info = device_info;
3850 if (sas_event_data->ReasonCode &
3851 MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
3852 hot_plug_info.event_type = MPTSAS_ADD_DEVICE;
3854 hot_plug_info.event_type = MPTSAS_DEL_DEVICE;
3855 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
3858 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
3859 mptbase_sas_persist_operation(ioc,
3860 MPI_SAS_OP_CLEAR_NOT_PRESENT);
3861 mptsas_free_fw_event(ioc, fw_event);
3864 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
3866 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
3869 mptsas_free_fw_event(ioc, fw_event);
3875 mptsas_send_raid_event(struct fw_event_work *fw_event)
3878 EVENT_DATA_RAID *raid_event_data;
3879 struct mptsas_hotplug_event hot_plug_info;
3882 struct scsi_device *sdev = NULL;
3883 VirtDevice *vdevice = NULL;
3884 RaidPhysDiskPage0_t phys_disk;
3886 ioc = fw_event->ioc;
3887 raid_event_data = (EVENT_DATA_RAID *)fw_event->event_data;
3888 status = le32_to_cpu(raid_event_data->SettingsStatus);
3889 state = (status >> 8) & 0xff;
3891 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
3892 hot_plug_info.id = raid_event_data->VolumeID;
3893 hot_plug_info.channel = raid_event_data->VolumeBus;
3894 hot_plug_info.phys_disk_num = raid_event_data->PhysDiskNum;
3896 if (raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_DELETED ||
3897 raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_CREATED ||
3898 raid_event_data->ReasonCode ==
3899 MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED) {
3900 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
3901 hot_plug_info.id, 0);
3902 hot_plug_info.sdev = sdev;
3904 vdevice = sdev->hostdata;
3907 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
3908 "ReasonCode=%02x\n", ioc->name, __func__,
3909 raid_event_data->ReasonCode));
3911 switch (raid_event_data->ReasonCode) {
3912 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
3913 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK_REPROBE;
3915 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
3916 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK_REPROBE;
3918 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
3920 case MPI_PD_STATE_ONLINE:
3921 case MPI_PD_STATE_NOT_COMPATIBLE:
3922 mpt_raid_phys_disk_pg0(ioc,
3923 raid_event_data->PhysDiskNum, &phys_disk);
3924 hot_plug_info.id = phys_disk.PhysDiskID;
3925 hot_plug_info.channel = phys_disk.PhysDiskBus;
3926 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
3928 case MPI_PD_STATE_FAILED:
3929 case MPI_PD_STATE_MISSING:
3930 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
3931 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
3932 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
3933 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
3939 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
3942 vdevice->vtarget->deleted = 1; /* block IO */
3943 hot_plug_info.event_type = MPTSAS_DEL_RAID;
3945 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
3947 scsi_device_put(sdev);
3950 hot_plug_info.event_type = MPTSAS_ADD_RAID;
3952 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
3953 if (!(status & MPI_RAIDVOL0_STATUS_FLAG_ENABLED)) {
3956 vdevice->vtarget->deleted = 1; /* block IO */
3957 hot_plug_info.event_type = MPTSAS_DEL_RAID;
3961 case MPI_RAIDVOL0_STATUS_STATE_FAILED:
3962 case MPI_RAIDVOL0_STATUS_STATE_MISSING:
3965 vdevice->vtarget->deleted = 1; /* block IO */
3966 hot_plug_info.event_type = MPTSAS_DEL_RAID;
3968 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
3969 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
3971 scsi_device_put(sdev);
3974 hot_plug_info.event_type = MPTSAS_ADD_RAID;
3984 if (hot_plug_info.event_type != MPTSAS_IGNORE_EVENT)
3985 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
3987 mptsas_free_fw_event(ioc, fw_event);
3991 * mptsas_send_ir2_event - handle exposing hidden disk when
3992 * an inactive raid volume is added
3994 * @ioc: Pointer to MPT_ADAPTER structure
3999 mptsas_send_ir2_event(struct fw_event_work *fw_event)
4002 struct mptsas_hotplug_event hot_plug_info;
4003 MPI_EVENT_DATA_IR2 *ir2_data;
4006 ioc = fw_event->ioc;
4007 ir2_data = (MPI_EVENT_DATA_IR2 *)fw_event->event_data;
4008 reasonCode = ir2_data->ReasonCode;
4010 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
4011 "ReasonCode=%02x\n", ioc->name, __func__, reasonCode));
4013 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4014 hot_plug_info.id = ir2_data->TargetID;
4015 hot_plug_info.channel = ir2_data->Bus;
4016 switch (reasonCode) {
4017 case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
4018 hot_plug_info.event_type = MPTSAS_ADD_INACTIVE_VOLUME;
4021 mptsas_free_fw_event(ioc, fw_event);
4024 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4028 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
4030 u32 event = le32_to_cpu(reply->Event);
4031 int sz, event_data_sz;
4032 struct fw_event_work *fw_event;
4033 unsigned long delay;
4035 /* events turned off due to host reset or driver unloading */
4036 if (ioc->fw_events_off)
4039 delay = msecs_to_jiffies(1);
4041 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
4043 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data =
4044 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data;
4046 if (sas_event_data->ReasonCode ==
4047 MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING) {
4048 mptsas_target_reset_queue(ioc, sas_event_data);
4053 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
4055 MpiEventDataSasExpanderStatusChange_t *expander_data =
4056 (MpiEventDataSasExpanderStatusChange_t *)reply->Data;
4058 if (ioc->old_sas_discovery_protocal)
4061 if (expander_data->ReasonCode ==
4062 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING &&
4063 ioc->device_missing_delay)
4064 delay = HZ * ioc->device_missing_delay;
4067 case MPI_EVENT_SAS_DISCOVERY:
4069 u32 discovery_status;
4070 EventDataSasDiscovery_t *discovery_data =
4071 (EventDataSasDiscovery_t *)reply->Data;
4073 discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus);
4074 ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0;
4075 if (ioc->old_sas_discovery_protocal && !discovery_status)
4076 mptsas_queue_rescan(ioc);
4079 case MPI_EVENT_INTEGRATED_RAID:
4080 case MPI_EVENT_PERSISTENT_TABLE_FULL:
4082 case MPI_EVENT_SAS_PHY_LINK_STATUS:
4083 case MPI_EVENT_QUEUE_FULL:
4089 event_data_sz = ((reply->MsgLength * 4) -
4090 offsetof(EventNotificationReply_t, Data));
4091 sz = offsetof(struct fw_event_work, event_data) + event_data_sz;
4092 fw_event = kzalloc(sz, GFP_ATOMIC);
4094 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", ioc->name,
4095 __func__, __LINE__);
4098 memcpy(fw_event->event_data, reply->Data, event_data_sz);
4099 fw_event->event = event;
4100 fw_event->ioc = ioc;
4101 mptsas_add_fw_event(ioc, fw_event, delay);
4106 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
4108 struct Scsi_Host *sh;
4111 unsigned long flags;
4119 r = mpt_attach(pdev,id);
4123 ioc = pci_get_drvdata(pdev);
4124 mptsas_fw_event_off(ioc);
4125 ioc->DoneCtx = mptsasDoneCtx;
4126 ioc->TaskCtx = mptsasTaskCtx;
4127 ioc->InternalCtx = mptsasInternalCtx;
4129 /* Added sanity check on readiness of the MPT adapter.
4131 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
4132 printk(MYIOC_s_WARN_FMT
4133 "Skipping because it's not operational!\n",
4136 goto out_mptsas_probe;
4140 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
4143 goto out_mptsas_probe;
4146 /* Sanity check - ensure at least 1 port is INITIATOR capable
4149 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
4150 if (ioc->pfacts[ii].ProtocolFlags &
4151 MPI_PORTFACTS_PROTOCOL_INITIATOR)
4156 printk(MYIOC_s_WARN_FMT
4157 "Skipping ioc=%p because SCSI Initiator mode "
4158 "is NOT enabled!\n", ioc->name, ioc);
4162 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
4164 printk(MYIOC_s_WARN_FMT
4165 "Unable to register controller with SCSI subsystem\n",
4168 goto out_mptsas_probe;
4171 spin_lock_irqsave(&ioc->FreeQlock, flags);
4173 /* Attach the SCSI Host to the IOC structure
4181 /* set 16 byte cdb's */
4182 sh->max_cmd_len = 16;
4184 sh->max_id = ioc->pfacts[0].PortSCSIID;
4185 sh->max_lun = max_lun;
4187 sh->transportt = mptsas_transport_template;
4191 sh->unique_id = ioc->id;
4193 INIT_LIST_HEAD(&ioc->sas_topology);
4194 mutex_init(&ioc->sas_topology_mutex);
4195 mutex_init(&ioc->sas_discovery_mutex);
4196 mutex_init(&ioc->sas_mgmt.mutex);
4197 init_completion(&ioc->sas_mgmt.done);
4199 /* Verify that we won't exceed the maximum
4200 * number of chain buffers
4201 * We can optimize: ZZ = req_sz/sizeof(SGE)
4203 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
4204 * + (req_sz - 64)/sizeof(SGE)
4205 * A slightly different algorithm is required for
4208 scale = ioc->req_sz/ioc->SGE_size;
4209 if (ioc->sg_addr_size == sizeof(u64)) {
4210 numSGE = (scale - 1) *
4211 (ioc->facts.MaxChainDepth-1) + scale +
4212 (ioc->req_sz - 60) / ioc->SGE_size;
4214 numSGE = 1 + (scale - 1) *
4215 (ioc->facts.MaxChainDepth-1) + scale +
4216 (ioc->req_sz - 64) / ioc->SGE_size;
4219 if (numSGE < sh->sg_tablesize) {
4220 /* Reset this value */
4221 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4222 "Resetting sg_tablesize to %d from %d\n",
4223 ioc->name, numSGE, sh->sg_tablesize));
4224 sh->sg_tablesize = numSGE;
4227 hd = shost_priv(sh);
4230 /* SCSI needs scsi_cmnd lookup table!
4231 * (with size equal to req_depth*PtrSz!)
4233 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
4234 if (!ioc->ScsiLookup) {
4236 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4237 goto out_mptsas_probe;
4239 spin_lock_init(&ioc->scsi_lookup_lock);
4241 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
4242 ioc->name, ioc->ScsiLookup));
4244 /* Clear the TM flags
4246 hd->abortSCpnt = NULL;
4248 /* Clear the pointer used to store
4249 * single-threaded commands, i.e., those
4250 * issued during a bus scan, dv and
4251 * configuration pages.
4255 /* Initialize this SCSI Hosts' timers
4256 * To use, set the timer expires field
4259 init_timer(&hd->timer);
4260 hd->timer.data = (unsigned long) hd;
4261 hd->timer.function = mptscsih_timer_expired;
4263 ioc->sas_data.ptClear = mpt_pt_clear;
4265 hd->last_queue_full = 0;
4266 INIT_LIST_HEAD(&hd->target_reset_list);
4267 INIT_LIST_HEAD(&ioc->sas_device_info_list);
4268 mutex_init(&ioc->sas_device_info_mutex);
4270 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4272 if (ioc->sas_data.ptClear==1) {
4273 mptbase_sas_persist_operation(
4274 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
4277 error = scsi_add_host(sh, &ioc->pcidev->dev);
4279 dprintk(ioc, printk(MYIOC_s_ERR_FMT
4280 "scsi_add_host failed\n", ioc->name));
4281 goto out_mptsas_probe;
4284 /* older firmware doesn't support expander events */
4285 if ((ioc->facts.HeaderVersion >> 8) < 0xE)
4286 ioc->old_sas_discovery_protocal = 1;
4287 mptsas_scan_sas_topology(ioc);
4288 mptsas_fw_event_on(ioc);
4293 mptscsih_remove(pdev);
4298 mptsas_shutdown(struct pci_dev *pdev)
4300 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
4302 mptsas_fw_event_off(ioc);
4303 mptsas_cleanup_fw_event_q(ioc);
4306 static void __devexit mptsas_remove(struct pci_dev *pdev)
4308 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
4309 struct mptsas_portinfo *p, *n;
4312 mptsas_shutdown(pdev);
4314 mptsas_del_device_components(ioc);
4316 ioc->sas_discovery_ignore_events = 1;
4317 sas_remove_host(ioc->sh);
4319 mutex_lock(&ioc->sas_topology_mutex);
4320 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
4322 for (i = 0 ; i < p->num_phys ; i++)
4323 mptsas_port_delete(ioc, p->phy_info[i].port_details);
4328 mutex_unlock(&ioc->sas_topology_mutex);
4329 ioc->hba_port_info = NULL;
4330 mptscsih_remove(pdev);
4333 static struct pci_device_id mptsas_pci_table[] = {
4334 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
4335 PCI_ANY_ID, PCI_ANY_ID },
4336 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
4337 PCI_ANY_ID, PCI_ANY_ID },
4338 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
4339 PCI_ANY_ID, PCI_ANY_ID },
4340 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
4341 PCI_ANY_ID, PCI_ANY_ID },
4342 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
4343 PCI_ANY_ID, PCI_ANY_ID },
4344 {0} /* Terminating entry */
4346 MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
4349 static struct pci_driver mptsas_driver = {
4351 .id_table = mptsas_pci_table,
4352 .probe = mptsas_probe,
4353 .remove = __devexit_p(mptsas_remove),
4354 .shutdown = mptsas_shutdown,
4356 .suspend = mptscsih_suspend,
4357 .resume = mptscsih_resume,
4366 show_mptmod_ver(my_NAME, my_VERSION);
4368 mptsas_transport_template =
4369 sas_attach_transport(&mptsas_transport_functions);
4370 if (!mptsas_transport_template)
4373 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
4374 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER);
4376 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
4377 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
4378 mptsasDeviceResetCtx =
4379 mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER);
4381 mpt_event_register(mptsasDoneCtx, mptsas_event_process);
4382 mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset);
4384 error = pci_register_driver(&mptsas_driver);
4386 sas_release_transport(mptsas_transport_template);
4394 pci_unregister_driver(&mptsas_driver);
4395 sas_release_transport(mptsas_transport_template);
4397 mpt_reset_deregister(mptsasDoneCtx);
4398 mpt_event_deregister(mptsasDoneCtx);
4400 mpt_deregister(mptsasMgmtCtx);
4401 mpt_deregister(mptsasInternalCtx);
4402 mpt_deregister(mptsasTaskCtx);
4403 mpt_deregister(mptsasDoneCtx);
4404 mpt_deregister(mptsasDeviceResetCtx);
4407 module_init(mptsas_init);
4408 module_exit(mptsas_exit);