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
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/slab.h>
49 #include <linux/init.h>
50 #include <linux/errno.h>
51 #include <linux/jiffies.h>
52 #include <linux/workqueue.h>
53 #include <linux/delay.h> /* for mdelay */
55 #include <scsi/scsi.h>
56 #include <scsi/scsi_cmnd.h>
57 #include <scsi/scsi_device.h>
58 #include <scsi/scsi_host.h>
59 #include <scsi/scsi_transport_sas.h>
60 #include <scsi/scsi_transport.h>
61 #include <scsi/scsi_dbg.h>
68 #define my_NAME "Fusion MPT SAS Host driver"
69 #define my_VERSION MPT_LINUX_VERSION_COMMON
70 #define MYNAM "mptsas"
73 * Reserved channel for integrated raid
75 #define MPTSAS_RAID_CHANNEL 1
77 #define SAS_CONFIG_PAGE_TIMEOUT 30
78 MODULE_AUTHOR(MODULEAUTHOR);
79 MODULE_DESCRIPTION(my_NAME);
80 MODULE_LICENSE("GPL");
81 MODULE_VERSION(my_VERSION);
83 static int mpt_pt_clear;
84 module_param(mpt_pt_clear, int, 0);
85 MODULE_PARM_DESC(mpt_pt_clear,
86 " Clear persistency table: enable=1 "
87 "(default=MPTSCSIH_PT_CLEAR=0)");
89 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
90 #define MPTSAS_MAX_LUN (16895)
91 static int max_lun = MPTSAS_MAX_LUN;
92 module_param(max_lun, int, 0);
93 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
95 static int mpt_loadtime_max_sectors = 8192;
96 module_param(mpt_loadtime_max_sectors, int, 0);
97 MODULE_PARM_DESC(mpt_loadtime_max_sectors,
98 " Maximum sector define for Host Bus Adaptor.Range 64 to 8192 default=8192");
100 static u8 mptsasDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
101 static u8 mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
102 static u8 mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
103 static u8 mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS;
104 static u8 mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS;
106 static void mptsas_firmware_event_work(struct work_struct *work);
107 static void mptsas_send_sas_event(struct fw_event_work *fw_event);
108 static void mptsas_send_raid_event(struct fw_event_work *fw_event);
109 static void mptsas_send_ir2_event(struct fw_event_work *fw_event);
110 static void mptsas_parse_device_info(struct sas_identify *identify,
111 struct mptsas_devinfo *device_info);
112 static inline void mptsas_set_rphy(MPT_ADAPTER *ioc,
113 struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy);
114 static struct mptsas_phyinfo *mptsas_find_phyinfo_by_sas_address
115 (MPT_ADAPTER *ioc, u64 sas_address);
116 static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc,
117 struct mptsas_devinfo *device_info, u32 form, u32 form_specific);
118 static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc,
119 struct mptsas_enclosure *enclosure, u32 form, u32 form_specific);
120 static int mptsas_add_end_device(MPT_ADAPTER *ioc,
121 struct mptsas_phyinfo *phy_info);
122 static void mptsas_del_end_device(MPT_ADAPTER *ioc,
123 struct mptsas_phyinfo *phy_info);
124 static void mptsas_send_link_status_event(struct fw_event_work *fw_event);
125 static struct mptsas_portinfo *mptsas_find_portinfo_by_sas_address
126 (MPT_ADAPTER *ioc, u64 sas_address);
127 static void mptsas_expander_delete(MPT_ADAPTER *ioc,
128 struct mptsas_portinfo *port_info, u8 force);
129 static void mptsas_send_expander_event(struct fw_event_work *fw_event);
130 static void mptsas_not_responding_devices(MPT_ADAPTER *ioc);
131 static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc);
132 static void mptsas_broadcast_primitive_work(struct fw_event_work *fw_event);
133 static void mptsas_handle_queue_full_event(struct fw_event_work *fw_event);
134 static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id);
135 void mptsas_schedule_target_reset(void *ioc);
137 static void mptsas_print_phy_data(MPT_ADAPTER *ioc,
138 MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
140 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
141 "---- IO UNIT PAGE 0 ------------\n", ioc->name));
142 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
143 ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle)));
144 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n",
145 ioc->name, le16_to_cpu(phy_data->ControllerDevHandle)));
146 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n",
147 ioc->name, phy_data->Port));
148 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n",
149 ioc->name, phy_data->PortFlags));
150 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n",
151 ioc->name, phy_data->PhyFlags));
152 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
153 ioc->name, phy_data->NegotiatedLinkRate));
154 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
155 "Controller PHY Device Info=0x%X\n", ioc->name,
156 le32_to_cpu(phy_data->ControllerPhyDeviceInfo)));
157 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n",
158 ioc->name, le32_to_cpu(phy_data->DiscoveryStatus)));
161 static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0)
165 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
167 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
168 "---- SAS PHY PAGE 0 ------------\n", ioc->name));
169 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
170 "Attached Device Handle=0x%X\n", ioc->name,
171 le16_to_cpu(pg0->AttachedDevHandle)));
172 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
173 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
174 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
175 "Attached PHY Identifier=0x%X\n", ioc->name,
176 pg0->AttachedPhyIdentifier));
177 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n",
178 ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo)));
179 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
180 ioc->name, pg0->ProgrammedLinkRate));
181 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n",
182 ioc->name, pg0->ChangeCount));
183 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n",
184 ioc->name, le32_to_cpu(pg0->PhyInfo)));
187 static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1)
189 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
190 "---- SAS PHY PAGE 1 ------------\n", ioc->name));
191 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n",
192 ioc->name, pg1->InvalidDwordCount));
193 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
194 "Running Disparity Error Count=0x%x\n", ioc->name,
195 pg1->RunningDisparityErrorCount));
196 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
197 "Loss Dword Synch Count=0x%x\n", ioc->name,
198 pg1->LossDwordSynchCount));
199 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
200 "PHY Reset Problem Count=0x%x\n\n", ioc->name,
201 pg1->PhyResetProblemCount));
204 static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0)
208 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
210 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
211 "---- SAS DEVICE PAGE 0 ---------\n", ioc->name));
212 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
213 ioc->name, le16_to_cpu(pg0->DevHandle)));
214 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n",
215 ioc->name, le16_to_cpu(pg0->ParentDevHandle)));
216 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n",
217 ioc->name, le16_to_cpu(pg0->EnclosureHandle)));
218 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n",
219 ioc->name, le16_to_cpu(pg0->Slot)));
220 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
221 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
222 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n",
223 ioc->name, pg0->TargetID));
224 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n",
225 ioc->name, pg0->Bus));
226 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n",
227 ioc->name, pg0->PhyNum));
228 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n",
229 ioc->name, le16_to_cpu(pg0->AccessStatus)));
230 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n",
231 ioc->name, le32_to_cpu(pg0->DeviceInfo)));
232 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n",
233 ioc->name, le16_to_cpu(pg0->Flags)));
234 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n",
235 ioc->name, pg0->PhysicalPort));
238 static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1)
240 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
241 "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name));
242 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n",
243 ioc->name, pg1->PhysicalPort));
244 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n",
245 ioc->name, pg1->PhyIdentifier));
246 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
247 ioc->name, pg1->NegotiatedLinkRate));
248 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
249 ioc->name, pg1->ProgrammedLinkRate));
250 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n",
251 ioc->name, pg1->HwLinkRate));
252 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n",
253 ioc->name, le16_to_cpu(pg1->OwnerDevHandle)));
254 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
255 "Attached Device Handle=0x%X\n\n", ioc->name,
256 le16_to_cpu(pg1->AttachedDevHandle)));
259 /* inhibit sas firmware event handling */
261 mptsas_fw_event_off(MPT_ADAPTER *ioc)
265 spin_lock_irqsave(&ioc->fw_event_lock, flags);
266 ioc->fw_events_off = 1;
267 ioc->sas_discovery_quiesce_io = 0;
268 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
272 /* enable sas firmware event handling */
274 mptsas_fw_event_on(MPT_ADAPTER *ioc)
278 spin_lock_irqsave(&ioc->fw_event_lock, flags);
279 ioc->fw_events_off = 0;
280 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
283 /* queue a sas firmware event */
285 mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
290 spin_lock_irqsave(&ioc->fw_event_lock, flags);
291 list_add_tail(&fw_event->list, &ioc->fw_event_list);
293 INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work);
294 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)"
295 "on cpuid %d\n", ioc->name, __func__,
296 fw_event, smp_processor_id()));
297 queue_delayed_work_on(smp_processor_id(), ioc->fw_event_q,
298 &fw_event->work, delay);
299 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
302 /* requeue a sas firmware event */
304 mptsas_requeue_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
308 spin_lock_irqsave(&ioc->fw_event_lock, flags);
309 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: reschedule task "
310 "(fw_event=0x%p)on cpuid %d\n", ioc->name, __func__,
311 fw_event, smp_processor_id()));
313 queue_delayed_work_on(smp_processor_id(), ioc->fw_event_q,
314 &fw_event->work, msecs_to_jiffies(delay));
315 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
318 static void __mptsas_free_fw_event(MPT_ADAPTER *ioc,
319 struct fw_event_work *fw_event)
321 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: kfree (fw_event=0x%p)\n",
322 ioc->name, __func__, fw_event));
323 list_del(&fw_event->list);
327 /* free memory associated to a sas firmware event */
329 mptsas_free_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event)
333 spin_lock_irqsave(&ioc->fw_event_lock, flags);
335 if (!fw_event->users)
336 __mptsas_free_fw_event(ioc, fw_event);
337 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
340 /* walk the firmware event queue, and either stop or wait for
341 * outstanding events to complete */
343 mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc)
345 struct fw_event_work *fw_event;
346 struct mptsas_target_reset_event *target_reset_list, *n;
347 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
350 /* flush the target_reset_list */
351 if (!list_empty(&hd->target_reset_list)) {
352 list_for_each_entry_safe(target_reset_list, n,
353 &hd->target_reset_list, list) {
354 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
355 "%s: removing target reset for id=%d\n",
357 target_reset_list->sas_event_data.TargetID));
358 list_del(&target_reset_list->list);
359 kfree(target_reset_list);
363 if (list_empty(&ioc->fw_event_list) || !ioc->fw_event_q)
366 spin_lock_irqsave(&ioc->fw_event_lock, flags);
368 while (!list_empty(&ioc->fw_event_list)) {
369 bool canceled = false;
371 fw_event = list_first_entry(&ioc->fw_event_list,
372 struct fw_event_work, list);
374 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
375 if (cancel_delayed_work_sync(&fw_event->work))
378 spin_lock_irqsave(&ioc->fw_event_lock, flags);
382 WARN_ON_ONCE(fw_event->users);
383 __mptsas_free_fw_event(ioc, fw_event);
385 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
389 static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
391 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
392 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
395 static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
397 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
398 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
402 * mptsas_find_portinfo_by_handle
404 * This function should be called with the sas_topology_mutex already held
406 static struct mptsas_portinfo *
407 mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
409 struct mptsas_portinfo *port_info, *rc=NULL;
412 list_for_each_entry(port_info, &ioc->sas_topology, list)
413 for (i = 0; i < port_info->num_phys; i++)
414 if (port_info->phy_info[i].identify.handle == handle) {
423 * mptsas_find_portinfo_by_sas_address -
424 * @ioc: Pointer to MPT_ADAPTER structure
427 * This function should be called with the sas_topology_mutex already held
430 static struct mptsas_portinfo *
431 mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
433 struct mptsas_portinfo *port_info, *rc = NULL;
436 if (sas_address >= ioc->hba_port_sas_addr &&
437 sas_address < (ioc->hba_port_sas_addr +
438 ioc->hba_port_num_phy))
439 return ioc->hba_port_info;
441 mutex_lock(&ioc->sas_topology_mutex);
442 list_for_each_entry(port_info, &ioc->sas_topology, list)
443 for (i = 0; i < port_info->num_phys; i++)
444 if (port_info->phy_info[i].identify.sas_address ==
450 mutex_unlock(&ioc->sas_topology_mutex);
455 * Returns true if there is a scsi end device
458 mptsas_is_end_device(struct mptsas_devinfo * attached)
460 if ((attached->sas_address) &&
461 (attached->device_info &
462 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
463 ((attached->device_info &
464 MPI_SAS_DEVICE_INFO_SSP_TARGET) |
465 (attached->device_info &
466 MPI_SAS_DEVICE_INFO_STP_TARGET) |
467 (attached->device_info &
468 MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
476 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
478 struct mptsas_portinfo *port_info;
479 struct mptsas_phyinfo *phy_info;
485 port_info = port_details->port_info;
486 phy_info = port_info->phy_info;
488 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d "
489 "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
490 port_details->num_phys, (unsigned long long)
491 port_details->phy_bitmask));
493 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
494 if(phy_info->port_details != port_details)
496 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
497 mptsas_set_rphy(ioc, phy_info, NULL);
498 phy_info->port_details = NULL;
503 static inline struct sas_rphy *
504 mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
506 if (phy_info->port_details)
507 return phy_info->port_details->rphy;
513 mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
515 if (phy_info->port_details) {
516 phy_info->port_details->rphy = rphy;
517 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
522 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
523 &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
524 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
525 ioc->name, rphy, rphy->dev.release));
529 static inline struct sas_port *
530 mptsas_get_port(struct mptsas_phyinfo *phy_info)
532 if (phy_info->port_details)
533 return phy_info->port_details->port;
539 mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port)
541 if (phy_info->port_details)
542 phy_info->port_details->port = port;
545 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
546 &port->dev, MYIOC_s_FMT "add:", ioc->name));
547 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n",
548 ioc->name, port, port->dev.release));
552 static inline struct scsi_target *
553 mptsas_get_starget(struct mptsas_phyinfo *phy_info)
555 if (phy_info->port_details)
556 return phy_info->port_details->starget;
562 mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
565 if (phy_info->port_details)
566 phy_info->port_details->starget = starget;
570 * mptsas_add_device_component -
571 * @ioc: Pointer to MPT_ADAPTER structure
572 * @channel: fw mapped id's
579 mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id,
580 u64 sas_address, u32 device_info, u16 slot, u64 enclosure_logical_id)
582 struct mptsas_device_info *sas_info, *next;
583 struct scsi_device *sdev;
584 struct scsi_target *starget;
585 struct sas_rphy *rphy;
588 * Delete all matching devices out of the list
590 mutex_lock(&ioc->sas_device_info_mutex);
591 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
593 if (!sas_info->is_logical_volume &&
594 (sas_info->sas_address == sas_address ||
595 (sas_info->fw.channel == channel &&
596 sas_info->fw.id == id))) {
597 list_del(&sas_info->list);
602 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
607 * Set Firmware mapping
609 sas_info->fw.id = id;
610 sas_info->fw.channel = channel;
612 sas_info->sas_address = sas_address;
613 sas_info->device_info = device_info;
614 sas_info->slot = slot;
615 sas_info->enclosure_logical_id = enclosure_logical_id;
616 INIT_LIST_HEAD(&sas_info->list);
617 list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
622 shost_for_each_device(sdev, ioc->sh) {
623 starget = scsi_target(sdev);
624 rphy = dev_to_rphy(starget->dev.parent);
625 if (rphy->identify.sas_address == sas_address) {
626 sas_info->os.id = starget->id;
627 sas_info->os.channel = starget->channel;
632 mutex_unlock(&ioc->sas_device_info_mutex);
637 * mptsas_add_device_component_by_fw -
638 * @ioc: Pointer to MPT_ADAPTER structure
639 * @channel: fw mapped id's
644 mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id)
646 struct mptsas_devinfo sas_device;
647 struct mptsas_enclosure enclosure_info;
650 rc = mptsas_sas_device_pg0(ioc, &sas_device,
651 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
652 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
653 (channel << 8) + id);
657 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
658 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
659 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
660 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
661 sas_device.handle_enclosure);
663 mptsas_add_device_component(ioc, sas_device.channel,
664 sas_device.id, sas_device.sas_address, sas_device.device_info,
665 sas_device.slot, enclosure_info.enclosure_logical_id);
669 * mptsas_add_device_component_starget_ir - Handle Integrated RAID, adding each individual device to list
670 * @ioc: Pointer to MPT_ADAPTER structure
671 * @channel: fw mapped id's
676 mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc,
677 struct scsi_target *starget)
680 ConfigPageHeader_t hdr;
681 dma_addr_t dma_handle;
682 pRaidVolumePage0_t buffer = NULL;
684 RaidPhysDiskPage0_t phys_disk;
685 struct mptsas_device_info *sas_info, *next;
687 memset(&cfg, 0 , sizeof(CONFIGPARMS));
688 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
689 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
690 /* assumption that all volumes on channel = 0 */
691 cfg.pageAddr = starget->id;
692 cfg.cfghdr.hdr = &hdr;
693 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
694 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
696 if (mpt_config(ioc, &cfg) != 0)
702 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
708 cfg.physAddr = dma_handle;
709 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
711 if (mpt_config(ioc, &cfg) != 0)
714 if (!buffer->NumPhysDisks)
718 * Adding entry for hidden components
720 for (i = 0; i < buffer->NumPhysDisks; i++) {
722 if (mpt_raid_phys_disk_pg0(ioc,
723 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
726 mptsas_add_device_component_by_fw(ioc, phys_disk.PhysDiskBus,
727 phys_disk.PhysDiskID);
729 mutex_lock(&ioc->sas_device_info_mutex);
730 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
732 if (!sas_info->is_logical_volume &&
733 (sas_info->fw.channel == phys_disk.PhysDiskBus &&
734 sas_info->fw.id == phys_disk.PhysDiskID)) {
735 sas_info->is_hidden_raid_component = 1;
736 sas_info->volume_id = starget->id;
739 mutex_unlock(&ioc->sas_device_info_mutex);
744 * Delete all matching devices out of the list
746 mutex_lock(&ioc->sas_device_info_mutex);
747 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
749 if (sas_info->is_logical_volume && sas_info->fw.id ==
751 list_del(&sas_info->list);
756 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
758 sas_info->fw.id = starget->id;
759 sas_info->os.id = starget->id;
760 sas_info->os.channel = starget->channel;
761 sas_info->is_logical_volume = 1;
762 INIT_LIST_HEAD(&sas_info->list);
763 list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
765 mutex_unlock(&ioc->sas_device_info_mutex);
769 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
774 * mptsas_add_device_component_starget -
775 * @ioc: Pointer to MPT_ADAPTER structure
780 mptsas_add_device_component_starget(MPT_ADAPTER *ioc,
781 struct scsi_target *starget)
783 struct sas_rphy *rphy;
784 struct mptsas_phyinfo *phy_info = NULL;
785 struct mptsas_enclosure enclosure_info;
787 rphy = dev_to_rphy(starget->dev.parent);
788 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
789 rphy->identify.sas_address);
793 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
794 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
795 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
796 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
797 phy_info->attached.handle_enclosure);
799 mptsas_add_device_component(ioc, phy_info->attached.channel,
800 phy_info->attached.id, phy_info->attached.sas_address,
801 phy_info->attached.device_info,
802 phy_info->attached.slot, enclosure_info.enclosure_logical_id);
806 * mptsas_del_device_component_by_os - Once a device has been removed, we mark the entry in the list as being cached
807 * @ioc: Pointer to MPT_ADAPTER structure
808 * @channel: os mapped id's
813 mptsas_del_device_component_by_os(MPT_ADAPTER *ioc, u8 channel, u8 id)
815 struct mptsas_device_info *sas_info, *next;
820 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
822 if (sas_info->os.channel == channel && sas_info->os.id == id)
823 sas_info->is_cached = 1;
828 * mptsas_del_device_components - Cleaning the list
829 * @ioc: Pointer to MPT_ADAPTER structure
833 mptsas_del_device_components(MPT_ADAPTER *ioc)
835 struct mptsas_device_info *sas_info, *next;
837 mutex_lock(&ioc->sas_device_info_mutex);
838 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
840 list_del(&sas_info->list);
843 mutex_unlock(&ioc->sas_device_info_mutex);
848 * mptsas_setup_wide_ports
850 * Updates for new and existing narrow/wide port configuration
851 * in the sas_topology
854 mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
856 struct mptsas_portinfo_details * port_details;
857 struct mptsas_phyinfo *phy_info, *phy_info_cmp;
861 mutex_lock(&ioc->sas_topology_mutex);
863 phy_info = port_info->phy_info;
864 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
865 if (phy_info->attached.handle)
867 port_details = phy_info->port_details;
870 if (port_details->num_phys < 2)
873 * Removing a phy from a port, letting the last
874 * phy be removed by firmware events.
876 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
877 "%s: [%p]: deleting phy = %d\n",
878 ioc->name, __func__, port_details, i));
879 port_details->num_phys--;
880 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
881 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
883 devtprintk(ioc, dev_printk(KERN_DEBUG,
884 &phy_info->phy->dev, MYIOC_s_FMT
885 "delete phy %d, phy-obj (0x%p)\n", ioc->name,
886 phy_info->phy_id, phy_info->phy));
887 sas_port_delete_phy(port_details->port, phy_info->phy);
889 phy_info->port_details = NULL;
893 * Populate and refresh the tree
895 phy_info = port_info->phy_info;
896 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
897 sas_address = phy_info->attached.sas_address;
898 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
899 ioc->name, i, (unsigned long long)sas_address));
902 port_details = phy_info->port_details;
907 port_details = kzalloc(sizeof(struct
908 mptsas_portinfo_details), GFP_KERNEL);
911 port_details->num_phys = 1;
912 port_details->port_info = port_info;
913 if (phy_info->phy_id < 64 )
914 port_details->phy_bitmask |=
915 (1 << phy_info->phy_id);
916 phy_info->sas_port_add_phy=1;
917 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
918 "phy_id=%d sas_address=0x%018llX\n",
919 ioc->name, i, (unsigned long long)sas_address));
920 phy_info->port_details = port_details;
923 if (i == port_info->num_phys - 1)
925 phy_info_cmp = &port_info->phy_info[i + 1];
926 for (j = i + 1 ; j < port_info->num_phys ; j++,
928 if (!phy_info_cmp->attached.sas_address)
930 if (sas_address != phy_info_cmp->attached.sas_address)
932 if (phy_info_cmp->port_details == port_details )
934 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
935 "\t\tphy_id=%d sas_address=0x%018llX\n",
936 ioc->name, j, (unsigned long long)
937 phy_info_cmp->attached.sas_address));
938 if (phy_info_cmp->port_details) {
940 mptsas_get_rphy(phy_info_cmp);
942 mptsas_get_port(phy_info_cmp);
943 port_details->starget =
944 mptsas_get_starget(phy_info_cmp);
945 port_details->num_phys =
946 phy_info_cmp->port_details->num_phys;
947 if (!phy_info_cmp->port_details->num_phys)
948 kfree(phy_info_cmp->port_details);
950 phy_info_cmp->sas_port_add_phy=1;
952 * Adding a phy to a port
954 phy_info_cmp->port_details = port_details;
955 if (phy_info_cmp->phy_id < 64 )
956 port_details->phy_bitmask |=
957 (1 << phy_info_cmp->phy_id);
958 port_details->num_phys++;
964 for (i = 0; i < port_info->num_phys; i++) {
965 port_details = port_info->phy_info[i].port_details;
968 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
969 "%s: [%p]: phy_id=%02d num_phys=%02d "
970 "bitmask=0x%016llX\n", ioc->name, __func__,
971 port_details, i, port_details->num_phys,
972 (unsigned long long)port_details->phy_bitmask));
973 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
974 ioc->name, port_details->port, port_details->rphy));
976 dsaswideprintk(ioc, printk("\n"));
977 mutex_unlock(&ioc->sas_topology_mutex);
981 * csmisas_find_vtarget
989 mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
991 struct scsi_device *sdev;
993 VirtTarget *vtarget = NULL;
995 shost_for_each_device(sdev, ioc->sh) {
996 vdevice = sdev->hostdata;
997 if ((vdevice == NULL) ||
998 (vdevice->vtarget == NULL))
1000 if ((vdevice->vtarget->tflags &
1001 MPT_TARGET_FLAGS_RAID_COMPONENT ||
1002 vdevice->vtarget->raidVolume))
1004 if (vdevice->vtarget->id == id &&
1005 vdevice->vtarget->channel == channel)
1006 vtarget = vdevice->vtarget;
1012 mptsas_queue_device_delete(MPT_ADAPTER *ioc,
1013 MpiEventDataSasDeviceStatusChange_t *sas_event_data)
1015 struct fw_event_work *fw_event;
1017 fw_event = kzalloc(sizeof(*fw_event) +
1018 sizeof(MpiEventDataSasDeviceStatusChange_t),
1021 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
1022 ioc->name, __func__, __LINE__);
1025 memcpy(fw_event->event_data, sas_event_data,
1026 sizeof(MpiEventDataSasDeviceStatusChange_t));
1027 fw_event->event = MPI_EVENT_SAS_DEVICE_STATUS_CHANGE;
1028 fw_event->ioc = ioc;
1029 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
1033 mptsas_queue_rescan(MPT_ADAPTER *ioc)
1035 struct fw_event_work *fw_event;
1037 fw_event = kzalloc(sizeof(*fw_event), GFP_ATOMIC);
1039 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
1040 ioc->name, __func__, __LINE__);
1043 fw_event->event = -1;
1044 fw_event->ioc = ioc;
1045 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
1050 * mptsas_target_reset
1052 * Issues TARGET_RESET to end device using handshaking method
1058 * Returns (1) success
1063 mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
1066 SCSITaskMgmt_t *pScsiTm;
1067 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0)
1071 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
1073 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
1074 "%s, no msg frames @%d!!\n", ioc->name,
1075 __func__, __LINE__));
1079 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
1082 /* Format the Request
1084 pScsiTm = (SCSITaskMgmt_t *) mf;
1085 memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
1086 pScsiTm->TargetID = id;
1087 pScsiTm->Bus = channel;
1088 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
1089 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
1090 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
1092 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
1094 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1095 "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
1096 ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id));
1098 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
1104 mpt_clear_taskmgmt_in_progress_flag(ioc);
1109 mptsas_block_io_sdev(struct scsi_device *sdev, void *data)
1111 scsi_device_set_state(sdev, SDEV_BLOCK);
1115 mptsas_block_io_starget(struct scsi_target *starget)
1118 starget_for_each_device(starget, NULL, mptsas_block_io_sdev);
1122 * mptsas_target_reset_queue
1124 * Receive request for TARGET_RESET after receiving an firmware
1125 * event NOT_RESPONDING_EVENT, then put command in link list
1126 * and queue if task_queue already in use.
1133 mptsas_target_reset_queue(MPT_ADAPTER *ioc,
1134 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1136 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1137 VirtTarget *vtarget = NULL;
1138 struct mptsas_target_reset_event *target_reset_list;
1141 id = sas_event_data->TargetID;
1142 channel = sas_event_data->Bus;
1144 vtarget = mptsas_find_vtarget(ioc, channel, id);
1146 mptsas_block_io_starget(vtarget->starget);
1147 vtarget->deleted = 1; /* block IO */
1150 target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event),
1152 if (!target_reset_list) {
1153 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
1154 "%s, failed to allocate mem @%d..!!\n",
1155 ioc->name, __func__, __LINE__));
1159 memcpy(&target_reset_list->sas_event_data, sas_event_data,
1160 sizeof(*sas_event_data));
1161 list_add_tail(&target_reset_list->list, &hd->target_reset_list);
1163 target_reset_list->time_count = jiffies;
1165 if (mptsas_target_reset(ioc, channel, id)) {
1166 target_reset_list->target_reset_issued = 1;
1171 * mptsas_schedule_target_reset- send pending target reset
1172 * @iocp: per adapter object
1174 * This function will delete scheduled target reset from the list and
1175 * try to send next target reset. This will be called from completion
1176 * context of any Task management command.
1180 mptsas_schedule_target_reset(void *iocp)
1182 MPT_ADAPTER *ioc = (MPT_ADAPTER *)(iocp);
1183 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1184 struct list_head *head = &hd->target_reset_list;
1185 struct mptsas_target_reset_event *target_reset_list;
1188 * issue target reset to next device in the queue
1191 if (list_empty(head))
1194 target_reset_list = list_entry(head->next,
1195 struct mptsas_target_reset_event, list);
1197 id = target_reset_list->sas_event_data.TargetID;
1198 channel = target_reset_list->sas_event_data.Bus;
1199 target_reset_list->time_count = jiffies;
1201 if (mptsas_target_reset(ioc, channel, id))
1202 target_reset_list->target_reset_issued = 1;
1208 * mptsas_taskmgmt_complete - complete SAS task management function
1209 * @ioc: Pointer to MPT_ADAPTER structure
1211 * Completion for TARGET_RESET after NOT_RESPONDING_EVENT, enable work
1212 * queue to finish off removing device from upper layers. then send next
1213 * TARGET_RESET in the queue.
1216 mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
1218 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1219 struct list_head *head = &hd->target_reset_list;
1221 struct mptsas_target_reset_event *target_reset_list;
1222 SCSITaskMgmtReply_t *pScsiTmReply;
1224 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: "
1225 "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
1227 pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
1231 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1232 "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
1233 "\ttask_type = 0x%02X, iocstatus = 0x%04X "
1234 "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
1235 "term_cmnds = %d\n", ioc->name,
1236 pScsiTmReply->Bus, pScsiTmReply->TargetID,
1237 pScsiTmReply->TaskType,
1238 le16_to_cpu(pScsiTmReply->IOCStatus),
1239 le32_to_cpu(pScsiTmReply->IOCLogInfo),
1240 pScsiTmReply->ResponseCode,
1241 le32_to_cpu(pScsiTmReply->TerminationCount)));
1243 if (pScsiTmReply->ResponseCode)
1244 mptscsih_taskmgmt_response_code(ioc,
1245 pScsiTmReply->ResponseCode);
1247 if (pScsiTmReply->TaskType ==
1248 MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
1249 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET) {
1250 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1251 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
1252 memcpy(ioc->taskmgmt_cmds.reply, mr,
1253 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
1254 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
1255 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
1256 complete(&ioc->taskmgmt_cmds.done);
1262 mpt_clear_taskmgmt_in_progress_flag(ioc);
1264 if (list_empty(head))
1267 target_reset_list = list_entry(head->next,
1268 struct mptsas_target_reset_event, list);
1270 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1271 "TaskMgmt: completed (%d seconds)\n",
1272 ioc->name, jiffies_to_msecs(jiffies -
1273 target_reset_list->time_count)/1000));
1275 id = pScsiTmReply->TargetID;
1276 channel = pScsiTmReply->Bus;
1277 target_reset_list->time_count = jiffies;
1280 * retry target reset
1282 if (!target_reset_list->target_reset_issued) {
1283 if (mptsas_target_reset(ioc, channel, id))
1284 target_reset_list->target_reset_issued = 1;
1289 * enable work queue to remove device from upper layers
1291 list_del(&target_reset_list->list);
1292 if (!ioc->fw_events_off)
1293 mptsas_queue_device_delete(ioc,
1294 &target_reset_list->sas_event_data);
1297 ioc->schedule_target_reset(ioc);
1303 * mptscsih_ioc_reset
1310 mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1315 rc = mptscsih_ioc_reset(ioc, reset_phase);
1316 if ((ioc->bus_type != SAS) || (!rc))
1319 hd = shost_priv(ioc->sh);
1323 switch (reset_phase) {
1324 case MPT_IOC_SETUP_RESET:
1325 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1326 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
1327 mptsas_fw_event_off(ioc);
1329 case MPT_IOC_PRE_RESET:
1330 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1331 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
1333 case MPT_IOC_POST_RESET:
1334 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1335 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
1336 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
1337 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET;
1338 complete(&ioc->sas_mgmt.done);
1340 mptsas_cleanup_fw_event_q(ioc);
1341 mptsas_queue_rescan(ioc);
1353 * enum device_state -
1354 * @DEVICE_RETRY: need to retry the TUR
1355 * @DEVICE_ERROR: TUR return error, don't add device
1356 * @DEVICE_READY: device can be added
1366 mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
1367 u32 form, u32 form_specific)
1369 ConfigExtendedPageHeader_t hdr;
1371 SasEnclosurePage0_t *buffer;
1372 dma_addr_t dma_handle;
1374 __le64 le_identifier;
1376 memset(&hdr, 0, sizeof(hdr));
1377 hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
1379 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1380 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
1382 cfg.cfghdr.ehdr = &hdr;
1384 cfg.pageAddr = form + form_specific;
1385 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1386 cfg.dir = 0; /* read */
1387 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
1389 error = mpt_config(ioc, &cfg);
1392 if (!hdr.ExtPageLength) {
1397 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1404 cfg.physAddr = dma_handle;
1405 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1407 error = mpt_config(ioc, &cfg);
1409 goto out_free_consistent;
1411 /* save config data */
1412 memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
1413 enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
1414 enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
1415 enclosure->flags = le16_to_cpu(buffer->Flags);
1416 enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
1417 enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
1418 enclosure->start_id = buffer->StartTargetID;
1419 enclosure->start_channel = buffer->StartBus;
1420 enclosure->sep_id = buffer->SEPTargetID;
1421 enclosure->sep_channel = buffer->SEPBus;
1423 out_free_consistent:
1424 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1425 buffer, dma_handle);
1431 * mptsas_add_end_device - report a new end device to sas transport layer
1432 * @ioc: Pointer to MPT_ADAPTER structure
1433 * @phy_info: describes attached device
1435 * return (0) success (1) failure
1439 mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1441 struct sas_rphy *rphy;
1442 struct sas_port *port;
1443 struct sas_identify identify;
1448 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1449 "%s: exit at line=%d\n", ioc->name,
1450 __func__, __LINE__));
1454 fw_id = phy_info->attached.id;
1456 if (mptsas_get_rphy(phy_info)) {
1457 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1458 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1459 __func__, fw_id, __LINE__));
1463 port = mptsas_get_port(phy_info);
1465 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1466 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1467 __func__, fw_id, __LINE__));
1471 if (phy_info->attached.device_info &
1472 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1474 if (phy_info->attached.device_info &
1475 MPI_SAS_DEVICE_INFO_STP_TARGET)
1477 if (phy_info->attached.device_info &
1478 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1481 printk(MYIOC_s_INFO_FMT "attaching %s device: fw_channel %d, fw_id %d,"
1482 " phy %d, sas_addr 0x%llx\n", ioc->name, ds,
1483 phy_info->attached.channel, phy_info->attached.id,
1484 phy_info->attached.phy_id, (unsigned long long)
1485 phy_info->attached.sas_address);
1487 mptsas_parse_device_info(&identify, &phy_info->attached);
1488 rphy = sas_end_device_alloc(port);
1490 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1491 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1492 __func__, fw_id, __LINE__));
1493 return 5; /* non-fatal: an rphy can be added later */
1496 rphy->identify = identify;
1497 if (sas_rphy_add(rphy)) {
1498 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1499 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1500 __func__, fw_id, __LINE__));
1501 sas_rphy_free(rphy);
1504 mptsas_set_rphy(ioc, phy_info, rphy);
1509 * mptsas_del_end_device - report a deleted end device to sas transport layer
1510 * @ioc: Pointer to MPT_ADAPTER structure
1511 * @phy_info: describes attached device
1515 mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1517 struct sas_rphy *rphy;
1518 struct sas_port *port;
1519 struct mptsas_portinfo *port_info;
1520 struct mptsas_phyinfo *phy_info_parent;
1529 fw_id = phy_info->attached.id;
1530 sas_address = phy_info->attached.sas_address;
1532 if (!phy_info->port_details) {
1533 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1534 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1535 __func__, fw_id, __LINE__));
1538 rphy = mptsas_get_rphy(phy_info);
1540 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1541 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1542 __func__, fw_id, __LINE__));
1546 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_INITIATOR
1547 || phy_info->attached.device_info
1548 & MPI_SAS_DEVICE_INFO_SMP_INITIATOR
1549 || phy_info->attached.device_info
1550 & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1552 if (phy_info->attached.device_info &
1553 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1555 if (phy_info->attached.device_info &
1556 MPI_SAS_DEVICE_INFO_STP_TARGET)
1558 if (phy_info->attached.device_info &
1559 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1562 dev_printk(KERN_DEBUG, &rphy->dev, MYIOC_s_FMT
1563 "removing %s device: fw_channel %d, fw_id %d, phy %d,"
1564 "sas_addr 0x%llx\n", ioc->name, ds, phy_info->attached.channel,
1565 phy_info->attached.id, phy_info->attached.phy_id,
1566 (unsigned long long) sas_address);
1568 port = mptsas_get_port(phy_info);
1570 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1571 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1572 __func__, fw_id, __LINE__));
1575 port_info = phy_info->portinfo;
1576 phy_info_parent = port_info->phy_info;
1577 for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) {
1578 if (!phy_info_parent->phy)
1580 if (phy_info_parent->attached.sas_address !=
1583 dev_printk(KERN_DEBUG, &phy_info_parent->phy->dev,
1584 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n",
1585 ioc->name, phy_info_parent->phy_id,
1586 phy_info_parent->phy);
1587 sas_port_delete_phy(port, phy_info_parent->phy);
1590 dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
1591 "delete port %d, sas_addr (0x%llx)\n", ioc->name,
1592 port->port_identifier, (unsigned long long)sas_address);
1593 sas_port_delete(port);
1594 mptsas_set_port(ioc, phy_info, NULL);
1595 mptsas_port_delete(ioc, phy_info->port_details);
1598 static struct mptsas_phyinfo *
1599 mptsas_refreshing_device_handles(MPT_ADAPTER *ioc,
1600 struct mptsas_devinfo *sas_device)
1602 struct mptsas_phyinfo *phy_info;
1603 struct mptsas_portinfo *port_info;
1606 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
1607 sas_device->sas_address);
1610 port_info = phy_info->portinfo;
1613 mutex_lock(&ioc->sas_topology_mutex);
1614 for (i = 0; i < port_info->num_phys; i++) {
1615 if (port_info->phy_info[i].attached.sas_address !=
1616 sas_device->sas_address)
1618 port_info->phy_info[i].attached.channel = sas_device->channel;
1619 port_info->phy_info[i].attached.id = sas_device->id;
1620 port_info->phy_info[i].attached.sas_address =
1621 sas_device->sas_address;
1622 port_info->phy_info[i].attached.handle = sas_device->handle;
1623 port_info->phy_info[i].attached.handle_parent =
1624 sas_device->handle_parent;
1625 port_info->phy_info[i].attached.handle_enclosure =
1626 sas_device->handle_enclosure;
1628 mutex_unlock(&ioc->sas_topology_mutex);
1634 * mptsas_firmware_event_work - work thread for processing fw events
1635 * @work: work queue payload containing info describing the event
1640 mptsas_firmware_event_work(struct work_struct *work)
1642 struct fw_event_work *fw_event =
1643 container_of(work, struct fw_event_work, work.work);
1644 MPT_ADAPTER *ioc = fw_event->ioc;
1646 /* special rescan topology handling */
1647 if (fw_event->event == -1) {
1648 if (ioc->in_rescan) {
1649 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1650 "%s: rescan ignored as it is in progress\n",
1651 ioc->name, __func__));
1654 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rescan after "
1655 "reset\n", ioc->name, __func__));
1657 mptsas_not_responding_devices(ioc);
1658 mptsas_scan_sas_topology(ioc);
1660 mptsas_free_fw_event(ioc, fw_event);
1661 mptsas_fw_event_on(ioc);
1665 /* events handling turned off during host reset */
1666 if (ioc->fw_events_off) {
1667 mptsas_free_fw_event(ioc, fw_event);
1671 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_event=(0x%p), "
1672 "event = (0x%02x)\n", ioc->name, __func__, fw_event,
1673 (fw_event->event & 0xFF)));
1675 switch (fw_event->event) {
1676 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
1677 mptsas_send_sas_event(fw_event);
1679 case MPI_EVENT_INTEGRATED_RAID:
1680 mptsas_send_raid_event(fw_event);
1683 mptsas_send_ir2_event(fw_event);
1685 case MPI_EVENT_PERSISTENT_TABLE_FULL:
1686 mptbase_sas_persist_operation(ioc,
1687 MPI_SAS_OP_CLEAR_NOT_PRESENT);
1688 mptsas_free_fw_event(ioc, fw_event);
1690 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
1691 mptsas_broadcast_primitive_work(fw_event);
1693 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
1694 mptsas_send_expander_event(fw_event);
1696 case MPI_EVENT_SAS_PHY_LINK_STATUS:
1697 mptsas_send_link_status_event(fw_event);
1699 case MPI_EVENT_QUEUE_FULL:
1700 mptsas_handle_queue_full_event(fw_event);
1708 mptsas_slave_configure(struct scsi_device *sdev)
1710 struct Scsi_Host *host = sdev->host;
1711 MPT_SCSI_HOST *hd = shost_priv(host);
1712 MPT_ADAPTER *ioc = hd->ioc;
1713 VirtDevice *vdevice = sdev->hostdata;
1715 if (vdevice->vtarget->deleted) {
1716 sdev_printk(KERN_INFO, sdev, "clearing deleted flag\n");
1717 vdevice->vtarget->deleted = 0;
1721 * RAID volumes placed beyond the last expected port.
1722 * Ignore sending sas mode pages in that case..
1724 if (sdev->channel == MPTSAS_RAID_CHANNEL) {
1725 mptsas_add_device_component_starget_ir(ioc, scsi_target(sdev));
1729 sas_read_port_mode_page(sdev);
1731 mptsas_add_device_component_starget(ioc, scsi_target(sdev));
1734 return mptscsih_slave_configure(sdev);
1738 mptsas_target_alloc(struct scsi_target *starget)
1740 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1741 MPT_SCSI_HOST *hd = shost_priv(host);
1742 VirtTarget *vtarget;
1744 struct sas_rphy *rphy;
1745 struct mptsas_portinfo *p;
1747 MPT_ADAPTER *ioc = hd->ioc;
1749 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
1753 vtarget->starget = starget;
1754 vtarget->ioc_id = ioc->id;
1755 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
1760 * RAID volumes placed beyond the last expected port.
1762 if (starget->channel == MPTSAS_RAID_CHANNEL) {
1763 if (!ioc->raid_data.pIocPg2) {
1767 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1768 if (id == ioc->raid_data.pIocPg2->
1769 RaidVolume[i].VolumeID) {
1770 channel = ioc->raid_data.pIocPg2->
1771 RaidVolume[i].VolumeBus;
1774 vtarget->raidVolume = 1;
1778 rphy = dev_to_rphy(starget->dev.parent);
1779 mutex_lock(&ioc->sas_topology_mutex);
1780 list_for_each_entry(p, &ioc->sas_topology, list) {
1781 for (i = 0; i < p->num_phys; i++) {
1782 if (p->phy_info[i].attached.sas_address !=
1783 rphy->identify.sas_address)
1785 id = p->phy_info[i].attached.id;
1786 channel = p->phy_info[i].attached.channel;
1787 mptsas_set_starget(&p->phy_info[i], starget);
1790 * Exposing hidden raid components
1792 if (mptscsih_is_phys_disk(ioc, channel, id)) {
1793 id = mptscsih_raid_id_to_num(ioc,
1796 MPT_TARGET_FLAGS_RAID_COMPONENT;
1797 p->phy_info[i].attached.phys_disk_num = id;
1799 mutex_unlock(&ioc->sas_topology_mutex);
1803 mutex_unlock(&ioc->sas_topology_mutex);
1810 vtarget->channel = channel;
1811 starget->hostdata = vtarget;
1816 mptsas_target_destroy(struct scsi_target *starget)
1818 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1819 MPT_SCSI_HOST *hd = shost_priv(host);
1820 struct sas_rphy *rphy;
1821 struct mptsas_portinfo *p;
1823 MPT_ADAPTER *ioc = hd->ioc;
1824 VirtTarget *vtarget;
1826 if (!starget->hostdata)
1829 vtarget = starget->hostdata;
1831 mptsas_del_device_component_by_os(ioc, starget->channel,
1835 if (starget->channel == MPTSAS_RAID_CHANNEL)
1838 rphy = dev_to_rphy(starget->dev.parent);
1839 list_for_each_entry(p, &ioc->sas_topology, list) {
1840 for (i = 0; i < p->num_phys; i++) {
1841 if (p->phy_info[i].attached.sas_address !=
1842 rphy->identify.sas_address)
1845 starget_printk(KERN_INFO, starget, MYIOC_s_FMT
1846 "delete device: fw_channel %d, fw_id %d, phy %d, "
1847 "sas_addr 0x%llx\n", ioc->name,
1848 p->phy_info[i].attached.channel,
1849 p->phy_info[i].attached.id,
1850 p->phy_info[i].attached.phy_id, (unsigned long long)
1851 p->phy_info[i].attached.sas_address);
1853 mptsas_set_starget(&p->phy_info[i], NULL);
1858 vtarget->starget = NULL;
1859 kfree(starget->hostdata);
1860 starget->hostdata = NULL;
1865 mptsas_slave_alloc(struct scsi_device *sdev)
1867 struct Scsi_Host *host = sdev->host;
1868 MPT_SCSI_HOST *hd = shost_priv(host);
1869 struct sas_rphy *rphy;
1870 struct mptsas_portinfo *p;
1871 VirtDevice *vdevice;
1872 struct scsi_target *starget;
1874 MPT_ADAPTER *ioc = hd->ioc;
1876 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
1878 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
1879 ioc->name, sizeof(VirtDevice));
1882 starget = scsi_target(sdev);
1883 vdevice->vtarget = starget->hostdata;
1885 if (sdev->channel == MPTSAS_RAID_CHANNEL)
1888 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
1889 mutex_lock(&ioc->sas_topology_mutex);
1890 list_for_each_entry(p, &ioc->sas_topology, list) {
1891 for (i = 0; i < p->num_phys; i++) {
1892 if (p->phy_info[i].attached.sas_address !=
1893 rphy->identify.sas_address)
1895 vdevice->lun = sdev->lun;
1897 * Exposing hidden raid components
1899 if (mptscsih_is_phys_disk(ioc,
1900 p->phy_info[i].attached.channel,
1901 p->phy_info[i].attached.id))
1902 sdev->no_uld_attach = 1;
1903 mutex_unlock(&ioc->sas_topology_mutex);
1907 mutex_unlock(&ioc->sas_topology_mutex);
1913 vdevice->vtarget->num_luns++;
1914 sdev->hostdata = vdevice;
1919 mptsas_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt)
1923 VirtDevice *vdevice = SCpnt->device->hostdata;
1925 if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
1926 SCpnt->result = DID_NO_CONNECT << 16;
1927 SCpnt->scsi_done(SCpnt);
1931 hd = shost_priv(shost);
1934 if (ioc->sas_discovery_quiesce_io)
1935 return SCSI_MLQUEUE_HOST_BUSY;
1937 if (ioc->debug_level & MPT_DEBUG_SCSI)
1938 scsi_print_command(SCpnt);
1940 return mptscsih_qcmd(SCpnt);
1944 * mptsas_mptsas_eh_timed_out - resets the scsi_cmnd timeout
1945 * if the device under question is currently in the
1946 * device removal delay.
1947 * @sc: scsi command that the midlayer is about to time out
1950 static enum blk_eh_timer_return mptsas_eh_timed_out(struct scsi_cmnd *sc)
1954 VirtDevice *vdevice;
1955 enum blk_eh_timer_return rc = BLK_EH_DONE;
1957 hd = shost_priv(sc->device->host);
1959 printk(KERN_ERR MYNAM ": %s: Can't locate host! (sc=%p)\n",
1965 if (ioc->bus_type != SAS) {
1966 printk(KERN_ERR MYNAM ": %s: Wrong bus type (sc=%p)\n",
1971 /* In case if IOC is in reset from internal context.
1972 * Do not execute EEH for the same IOC. SML should to reset timer.
1974 if (ioc->ioc_reset_in_progress) {
1975 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT ": %s: ioc is in reset,"
1976 "SML need to reset the timer (sc=%p)\n",
1977 ioc->name, __func__, sc));
1978 rc = BLK_EH_RESET_TIMER;
1980 vdevice = sc->device->hostdata;
1981 if (vdevice && vdevice->vtarget && (vdevice->vtarget->inDMD
1982 || vdevice->vtarget->deleted)) {
1983 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT ": %s: target removed "
1984 "or in device removal delay (sc=%p)\n",
1985 ioc->name, __func__, sc));
1986 rc = BLK_EH_RESET_TIMER;
1995 static struct scsi_host_template mptsas_driver_template = {
1996 .module = THIS_MODULE,
1997 .proc_name = "mptsas",
1998 .show_info = mptscsih_show_info,
1999 .name = "MPT SAS Host",
2000 .info = mptscsih_info,
2001 .queuecommand = mptsas_qcmd,
2002 .target_alloc = mptsas_target_alloc,
2003 .slave_alloc = mptsas_slave_alloc,
2004 .slave_configure = mptsas_slave_configure,
2005 .target_destroy = mptsas_target_destroy,
2006 .slave_destroy = mptscsih_slave_destroy,
2007 .change_queue_depth = mptscsih_change_queue_depth,
2008 .eh_timed_out = mptsas_eh_timed_out,
2009 .eh_abort_handler = mptscsih_abort,
2010 .eh_device_reset_handler = mptscsih_dev_reset,
2011 .eh_host_reset_handler = mptscsih_host_reset,
2012 .bios_param = mptscsih_bios_param,
2013 .can_queue = MPT_SAS_CAN_QUEUE,
2015 .sg_tablesize = MPT_SCSI_SG_DEPTH,
2016 .max_sectors = 8192,
2018 .shost_attrs = mptscsih_host_attrs,
2022 static int mptsas_get_linkerrors(struct sas_phy *phy)
2024 MPT_ADAPTER *ioc = phy_to_ioc(phy);
2025 ConfigExtendedPageHeader_t hdr;
2027 SasPhyPage1_t *buffer;
2028 dma_addr_t dma_handle;
2031 /* FIXME: only have link errors on local phys */
2032 if (!scsi_is_sas_phy_local(phy))
2035 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
2036 hdr.ExtPageLength = 0;
2037 hdr.PageNumber = 1 /* page number 1*/;
2040 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2041 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
2043 cfg.cfghdr.ehdr = &hdr;
2045 cfg.pageAddr = phy->identify.phy_identifier;
2046 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2047 cfg.dir = 0; /* read */
2048 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2050 error = mpt_config(ioc, &cfg);
2053 if (!hdr.ExtPageLength)
2056 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2061 cfg.physAddr = dma_handle;
2062 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2064 error = mpt_config(ioc, &cfg);
2066 goto out_free_consistent;
2068 mptsas_print_phy_pg1(ioc, buffer);
2070 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
2071 phy->running_disparity_error_count =
2072 le32_to_cpu(buffer->RunningDisparityErrorCount);
2073 phy->loss_of_dword_sync_count =
2074 le32_to_cpu(buffer->LossDwordSynchCount);
2075 phy->phy_reset_problem_count =
2076 le32_to_cpu(buffer->PhyResetProblemCount);
2078 out_free_consistent:
2079 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2080 buffer, dma_handle);
2084 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
2085 MPT_FRAME_HDR *reply)
2087 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
2088 if (reply != NULL) {
2089 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID;
2090 memcpy(ioc->sas_mgmt.reply, reply,
2091 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
2094 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
2095 ioc->sas_mgmt.status &= ~MPT_MGMT_STATUS_PENDING;
2096 complete(&ioc->sas_mgmt.done);
2102 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
2104 MPT_ADAPTER *ioc = phy_to_ioc(phy);
2105 SasIoUnitControlRequest_t *req;
2106 SasIoUnitControlReply_t *reply;
2109 unsigned long timeleft;
2110 int error = -ERESTARTSYS;
2112 /* FIXME: fusion doesn't allow non-local phy reset */
2113 if (!scsi_is_sas_phy_local(phy))
2116 /* not implemented for expanders */
2117 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
2120 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
2123 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2129 hdr = (MPIHeader_t *) mf;
2130 req = (SasIoUnitControlRequest_t *)mf;
2131 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
2132 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
2133 req->MsgContext = hdr->MsgContext;
2134 req->Operation = hard_reset ?
2135 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
2136 req->PhyNum = phy->identify.phy_identifier;
2138 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2139 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2141 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
2143 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2145 mpt_free_msg_frame(ioc, mf);
2146 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2149 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
2153 /* a reply frame is expected */
2154 if ((ioc->sas_mgmt.status &
2155 MPT_MGMT_STATUS_RF_VALID) == 0) {
2160 /* process the completed Reply Message Frame */
2161 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
2162 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
2163 printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
2164 ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo);
2172 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2173 mutex_unlock(&ioc->sas_mgmt.mutex);
2179 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
2181 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2183 struct mptsas_portinfo *p;
2184 struct mptsas_enclosure enclosure_info;
2185 u64 enclosure_handle;
2187 mutex_lock(&ioc->sas_topology_mutex);
2188 list_for_each_entry(p, &ioc->sas_topology, list) {
2189 for (i = 0; i < p->num_phys; i++) {
2190 if (p->phy_info[i].attached.sas_address ==
2191 rphy->identify.sas_address) {
2192 enclosure_handle = p->phy_info[i].
2193 attached.handle_enclosure;
2198 mutex_unlock(&ioc->sas_topology_mutex);
2202 mutex_unlock(&ioc->sas_topology_mutex);
2203 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
2204 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
2205 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
2206 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
2208 *identifier = enclosure_info.enclosure_logical_id;
2213 mptsas_get_bay_identifier(struct sas_rphy *rphy)
2215 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2216 struct mptsas_portinfo *p;
2219 mutex_lock(&ioc->sas_topology_mutex);
2220 list_for_each_entry(p, &ioc->sas_topology, list) {
2221 for (i = 0; i < p->num_phys; i++) {
2222 if (p->phy_info[i].attached.sas_address ==
2223 rphy->identify.sas_address) {
2224 rc = p->phy_info[i].attached.slot;
2231 mutex_unlock(&ioc->sas_topology_mutex);
2235 static void mptsas_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
2236 struct sas_rphy *rphy)
2238 MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
2240 SmpPassthroughRequest_t *smpreq;
2242 unsigned long timeleft;
2244 u64 sas_address = 0;
2245 unsigned int reslen = 0;
2248 /* do we need to support multiple segments? */
2249 if (job->request_payload.sg_cnt > 1 ||
2250 job->reply_payload.sg_cnt > 1) {
2251 printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u, rsp %u\n",
2252 ioc->name, __func__, job->request_payload.payload_len,
2253 job->reply_payload.payload_len);
2257 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
2261 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2267 smpreq = (SmpPassthroughRequest_t *)mf;
2268 memset(smpreq, 0, sizeof(*smpreq));
2270 smpreq->RequestDataLength =
2271 cpu_to_le16(job->request_payload.payload_len - 4);
2272 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
2275 sas_address = rphy->identify.sas_address;
2277 struct mptsas_portinfo *port_info;
2279 mutex_lock(&ioc->sas_topology_mutex);
2280 port_info = ioc->hba_port_info;
2281 if (port_info && port_info->phy_info)
2283 port_info->phy_info[0].phy->identify.sas_address;
2284 mutex_unlock(&ioc->sas_topology_mutex);
2287 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
2290 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
2293 flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2294 MPI_SGE_FLAGS_END_OF_BUFFER |
2295 MPI_SGE_FLAGS_DIRECTION)
2296 << MPI_SGE_FLAGS_SHIFT;
2298 if (!dma_map_sg(&ioc->pcidev->dev, job->request_payload.sg_list,
2299 1, PCI_DMA_BIDIRECTIONAL))
2302 flagsLength |= (sg_dma_len(job->request_payload.sg_list) - 4);
2303 ioc->add_sge(psge, flagsLength,
2304 sg_dma_address(job->request_payload.sg_list));
2305 psge += ioc->SGE_size;
2308 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2309 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2310 MPI_SGE_FLAGS_IOC_TO_HOST |
2311 MPI_SGE_FLAGS_END_OF_BUFFER;
2313 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2315 if (!dma_map_sg(&ioc->pcidev->dev, job->reply_payload.sg_list,
2316 1, PCI_DMA_BIDIRECTIONAL))
2318 flagsLength |= sg_dma_len(job->reply_payload.sg_list) + 4;
2319 ioc->add_sge(psge, flagsLength,
2320 sg_dma_address(job->reply_payload.sg_list));
2322 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2323 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2325 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
2326 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2328 mpt_free_msg_frame(ioc, mf);
2330 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2333 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
2338 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
2339 SmpPassthroughReply_t *smprep;
2341 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
2342 memcpy(job->reply, smprep, sizeof(*smprep));
2343 job->reply_len = sizeof(*smprep);
2344 reslen = smprep->ResponseDataLength;
2346 printk(MYIOC_s_ERR_FMT
2347 "%s: smp passthru reply failed to be returned\n",
2348 ioc->name, __func__);
2353 dma_unmap_sg(&ioc->pcidev->dev, job->reply_payload.sg_list, 1,
2354 PCI_DMA_BIDIRECTIONAL);
2356 dma_unmap_sg(&ioc->pcidev->dev, job->request_payload.sg_list, 1,
2357 PCI_DMA_BIDIRECTIONAL);
2360 mpt_free_msg_frame(ioc, mf);
2362 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2363 mutex_unlock(&ioc->sas_mgmt.mutex);
2365 bsg_job_done(job, ret, reslen);
2368 static struct sas_function_template mptsas_transport_functions = {
2369 .get_linkerrors = mptsas_get_linkerrors,
2370 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
2371 .get_bay_identifier = mptsas_get_bay_identifier,
2372 .phy_reset = mptsas_phy_reset,
2373 .smp_handler = mptsas_smp_handler,
2376 static struct scsi_transport_template *mptsas_transport_template;
2379 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
2381 ConfigExtendedPageHeader_t hdr;
2383 SasIOUnitPage0_t *buffer;
2384 dma_addr_t dma_handle;
2387 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
2388 hdr.ExtPageLength = 0;
2392 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2393 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2395 cfg.cfghdr.ehdr = &hdr;
2398 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2399 cfg.dir = 0; /* read */
2400 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2402 error = mpt_config(ioc, &cfg);
2405 if (!hdr.ExtPageLength) {
2410 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2417 cfg.physAddr = dma_handle;
2418 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2420 error = mpt_config(ioc, &cfg);
2422 goto out_free_consistent;
2424 port_info->num_phys = buffer->NumPhys;
2425 port_info->phy_info = kcalloc(port_info->num_phys,
2426 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
2427 if (!port_info->phy_info) {
2429 goto out_free_consistent;
2432 ioc->nvdata_version_persistent =
2433 le16_to_cpu(buffer->NvdataVersionPersistent);
2434 ioc->nvdata_version_default =
2435 le16_to_cpu(buffer->NvdataVersionDefault);
2437 for (i = 0; i < port_info->num_phys; i++) {
2438 mptsas_print_phy_data(ioc, &buffer->PhyData[i]);
2439 port_info->phy_info[i].phy_id = i;
2440 port_info->phy_info[i].port_id =
2441 buffer->PhyData[i].Port;
2442 port_info->phy_info[i].negotiated_link_rate =
2443 buffer->PhyData[i].NegotiatedLinkRate;
2444 port_info->phy_info[i].portinfo = port_info;
2445 port_info->phy_info[i].handle =
2446 le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
2449 out_free_consistent:
2450 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2451 buffer, dma_handle);
2457 mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
2459 ConfigExtendedPageHeader_t hdr;
2461 SasIOUnitPage1_t *buffer;
2462 dma_addr_t dma_handle;
2464 u8 device_missing_delay;
2466 memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
2467 memset(&cfg, 0, sizeof(CONFIGPARMS));
2469 cfg.cfghdr.ehdr = &hdr;
2470 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2471 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2472 cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2473 cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2474 cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION;
2475 cfg.cfghdr.ehdr->PageNumber = 1;
2477 error = mpt_config(ioc, &cfg);
2480 if (!hdr.ExtPageLength) {
2485 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2492 cfg.physAddr = dma_handle;
2493 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2495 error = mpt_config(ioc, &cfg);
2497 goto out_free_consistent;
2499 ioc->io_missing_delay =
2500 le16_to_cpu(buffer->IODeviceMissingDelay);
2501 device_missing_delay = buffer->ReportDeviceMissingDelay;
2502 ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ?
2503 (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 :
2504 device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2506 out_free_consistent:
2507 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2508 buffer, dma_handle);
2514 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2515 u32 form, u32 form_specific)
2517 ConfigExtendedPageHeader_t hdr;
2519 SasPhyPage0_t *buffer;
2520 dma_addr_t dma_handle;
2523 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
2524 hdr.ExtPageLength = 0;
2528 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2529 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
2531 cfg.cfghdr.ehdr = &hdr;
2532 cfg.dir = 0; /* read */
2533 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2535 /* Get Phy Pg 0 for each Phy. */
2537 cfg.pageAddr = form + form_specific;
2538 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2540 error = mpt_config(ioc, &cfg);
2544 if (!hdr.ExtPageLength) {
2549 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2556 cfg.physAddr = dma_handle;
2557 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2559 error = mpt_config(ioc, &cfg);
2561 goto out_free_consistent;
2563 mptsas_print_phy_pg0(ioc, buffer);
2565 phy_info->hw_link_rate = buffer->HwLinkRate;
2566 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2567 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2568 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2570 out_free_consistent:
2571 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2572 buffer, dma_handle);
2578 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
2579 u32 form, u32 form_specific)
2581 ConfigExtendedPageHeader_t hdr;
2583 SasDevicePage0_t *buffer;
2584 dma_addr_t dma_handle;
2588 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
2589 hdr.ExtPageLength = 0;
2593 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2594 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
2596 cfg.cfghdr.ehdr = &hdr;
2597 cfg.pageAddr = form + form_specific;
2599 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2600 cfg.dir = 0; /* read */
2601 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2603 memset(device_info, 0, sizeof(struct mptsas_devinfo));
2604 error = mpt_config(ioc, &cfg);
2607 if (!hdr.ExtPageLength) {
2612 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2619 cfg.physAddr = dma_handle;
2620 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2622 error = mpt_config(ioc, &cfg);
2624 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
2626 goto out_free_consistent;
2630 goto out_free_consistent;
2632 mptsas_print_device_pg0(ioc, buffer);
2634 memset(device_info, 0, sizeof(struct mptsas_devinfo));
2635 device_info->handle = le16_to_cpu(buffer->DevHandle);
2636 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
2637 device_info->handle_enclosure =
2638 le16_to_cpu(buffer->EnclosureHandle);
2639 device_info->slot = le16_to_cpu(buffer->Slot);
2640 device_info->phy_id = buffer->PhyNum;
2641 device_info->port_id = buffer->PhysicalPort;
2642 device_info->id = buffer->TargetID;
2643 device_info->phys_disk_num = ~0;
2644 device_info->channel = buffer->Bus;
2645 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
2646 device_info->sas_address = le64_to_cpu(sas_address);
2647 device_info->device_info =
2648 le32_to_cpu(buffer->DeviceInfo);
2649 device_info->flags = le16_to_cpu(buffer->Flags);
2651 out_free_consistent:
2652 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2653 buffer, dma_handle);
2659 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
2660 u32 form, u32 form_specific)
2662 ConfigExtendedPageHeader_t hdr;
2664 SasExpanderPage0_t *buffer;
2665 dma_addr_t dma_handle;
2669 memset(port_info, 0, sizeof(struct mptsas_portinfo));
2670 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
2671 hdr.ExtPageLength = 0;
2675 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2676 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2678 cfg.cfghdr.ehdr = &hdr;
2680 cfg.pageAddr = form + form_specific;
2681 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2682 cfg.dir = 0; /* read */
2683 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2685 memset(port_info, 0, sizeof(struct mptsas_portinfo));
2686 error = mpt_config(ioc, &cfg);
2690 if (!hdr.ExtPageLength) {
2695 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2702 cfg.physAddr = dma_handle;
2703 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2705 error = mpt_config(ioc, &cfg);
2706 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
2708 goto out_free_consistent;
2712 goto out_free_consistent;
2714 /* save config data */
2715 port_info->num_phys = (buffer->NumPhys) ? buffer->NumPhys : 1;
2716 port_info->phy_info = kcalloc(port_info->num_phys,
2717 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
2718 if (!port_info->phy_info) {
2720 goto out_free_consistent;
2723 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
2724 for (i = 0; i < port_info->num_phys; i++) {
2725 port_info->phy_info[i].portinfo = port_info;
2726 port_info->phy_info[i].handle =
2727 le16_to_cpu(buffer->DevHandle);
2728 port_info->phy_info[i].identify.sas_address =
2729 le64_to_cpu(sas_address);
2730 port_info->phy_info[i].identify.handle_parent =
2731 le16_to_cpu(buffer->ParentDevHandle);
2734 out_free_consistent:
2735 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2736 buffer, dma_handle);
2742 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2743 u32 form, u32 form_specific)
2745 ConfigExtendedPageHeader_t hdr;
2747 SasExpanderPage1_t *buffer;
2748 dma_addr_t dma_handle;
2751 hdr.PageVersion = MPI_SASEXPANDER1_PAGEVERSION;
2752 hdr.ExtPageLength = 0;
2756 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2757 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2759 cfg.cfghdr.ehdr = &hdr;
2761 cfg.pageAddr = form + form_specific;
2762 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2763 cfg.dir = 0; /* read */
2764 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2766 error = mpt_config(ioc, &cfg);
2770 if (!hdr.ExtPageLength) {
2775 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2782 cfg.physAddr = dma_handle;
2783 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2785 error = mpt_config(ioc, &cfg);
2787 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
2789 goto out_free_consistent;
2793 goto out_free_consistent;
2796 mptsas_print_expander_pg1(ioc, buffer);
2798 /* save config data */
2799 phy_info->phy_id = buffer->PhyIdentifier;
2800 phy_info->port_id = buffer->PhysicalPort;
2801 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
2802 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2803 phy_info->hw_link_rate = buffer->HwLinkRate;
2804 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2805 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2807 out_free_consistent:
2808 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2809 buffer, dma_handle);
2814 struct rep_manu_request{
2821 struct rep_manu_reply{
2822 u8 smp_frame_type; /* 0x41 */
2823 u8 function; /* 0x01 */
2826 u16 expander_change_count;
2831 u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN];
2832 u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN];
2833 u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN];
2834 u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN];
2836 u8 component_revision_id;
2838 u8 vendor_specific[8];
2842 * mptsas_exp_repmanufacture_info -
2843 * @ioc: per adapter object
2844 * @sas_address: expander sas address
2845 * @edev: the sas_expander_device object
2847 * Fills in the sas_expander_device object when SMP port is created.
2849 * Returns 0 for success, non-zero for failure.
2852 mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc,
2853 u64 sas_address, struct sas_expander_device *edev)
2856 SmpPassthroughRequest_t *smpreq;
2857 SmpPassthroughReply_t *smprep;
2858 struct rep_manu_reply *manufacture_reply;
2859 struct rep_manu_request *manufacture_request;
2862 unsigned long timeleft;
2864 unsigned long flags;
2865 void *data_out = NULL;
2866 dma_addr_t data_out_dma = 0;
2869 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
2870 if (ioc->ioc_reset_in_progress) {
2871 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2872 printk(MYIOC_s_INFO_FMT "%s: host reset in progress!\n",
2873 __func__, ioc->name);
2876 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2878 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
2882 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2888 smpreq = (SmpPassthroughRequest_t *)mf;
2889 memset(smpreq, 0, sizeof(*smpreq));
2891 sz = sizeof(struct rep_manu_request) + sizeof(struct rep_manu_reply);
2893 data_out = pci_alloc_consistent(ioc->pcidev, sz, &data_out_dma);
2895 printk(KERN_ERR "Memory allocation failure at %s:%d/%s()!\n",
2896 __FILE__, __LINE__, __func__);
2901 manufacture_request = data_out;
2902 manufacture_request->smp_frame_type = 0x40;
2903 manufacture_request->function = 1;
2904 manufacture_request->reserved = 0;
2905 manufacture_request->request_length = 0;
2907 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
2908 smpreq->PhysicalPort = 0xFF;
2909 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
2910 smpreq->RequestDataLength = sizeof(struct rep_manu_request);
2913 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
2915 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2916 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2917 MPI_SGE_FLAGS_HOST_TO_IOC |
2918 MPI_SGE_FLAGS_END_OF_BUFFER;
2919 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2920 flagsLength |= sizeof(struct rep_manu_request);
2922 ioc->add_sge(psge, flagsLength, data_out_dma);
2923 psge += ioc->SGE_size;
2925 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2926 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2927 MPI_SGE_FLAGS_IOC_TO_HOST |
2928 MPI_SGE_FLAGS_END_OF_BUFFER;
2929 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2930 flagsLength |= sizeof(struct rep_manu_reply);
2931 ioc->add_sge(psge, flagsLength, data_out_dma +
2932 sizeof(struct rep_manu_request));
2934 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2935 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2937 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
2938 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2940 mpt_free_msg_frame(ioc, mf);
2942 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2945 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
2951 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
2954 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
2955 if (le16_to_cpu(smprep->ResponseDataLength) !=
2956 sizeof(struct rep_manu_reply))
2959 manufacture_reply = data_out + sizeof(struct rep_manu_request);
2960 strncpy(edev->vendor_id, manufacture_reply->vendor_id,
2961 SAS_EXPANDER_VENDOR_ID_LEN);
2962 strncpy(edev->product_id, manufacture_reply->product_id,
2963 SAS_EXPANDER_PRODUCT_ID_LEN);
2964 strncpy(edev->product_rev, manufacture_reply->product_rev,
2965 SAS_EXPANDER_PRODUCT_REV_LEN);
2966 edev->level = manufacture_reply->sas_format;
2967 if (manufacture_reply->sas_format) {
2968 strncpy(edev->component_vendor_id,
2969 manufacture_reply->component_vendor_id,
2970 SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
2971 tmp = (u8 *)&manufacture_reply->component_id;
2972 edev->component_id = tmp[0] << 8 | tmp[1];
2973 edev->component_revision_id =
2974 manufacture_reply->component_revision_id;
2977 printk(MYIOC_s_ERR_FMT
2978 "%s: smp passthru reply failed to be returned\n",
2979 ioc->name, __func__);
2984 pci_free_consistent(ioc->pcidev, sz, data_out, data_out_dma);
2987 mpt_free_msg_frame(ioc, mf);
2989 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2990 mutex_unlock(&ioc->sas_mgmt.mutex);
2996 mptsas_parse_device_info(struct sas_identify *identify,
2997 struct mptsas_devinfo *device_info)
3001 identify->sas_address = device_info->sas_address;
3002 identify->phy_identifier = device_info->phy_id;
3005 * Fill in Phy Initiator Port Protocol.
3006 * Bits 6:3, more than one bit can be set, fall through cases.
3008 protocols = device_info->device_info & 0x78;
3009 identify->initiator_port_protocols = 0;
3010 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
3011 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
3012 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
3013 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
3014 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
3015 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
3016 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
3017 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
3020 * Fill in Phy Target Port Protocol.
3021 * Bits 10:7, more than one bit can be set, fall through cases.
3023 protocols = device_info->device_info & 0x780;
3024 identify->target_port_protocols = 0;
3025 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
3026 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
3027 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
3028 identify->target_port_protocols |= SAS_PROTOCOL_STP;
3029 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
3030 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
3031 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
3032 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
3035 * Fill in Attached device type.
3037 switch (device_info->device_info &
3038 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
3039 case MPI_SAS_DEVICE_INFO_NO_DEVICE:
3040 identify->device_type = SAS_PHY_UNUSED;
3042 case MPI_SAS_DEVICE_INFO_END_DEVICE:
3043 identify->device_type = SAS_END_DEVICE;
3045 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
3046 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
3048 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
3049 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
3054 static int mptsas_probe_one_phy(struct device *dev,
3055 struct mptsas_phyinfo *phy_info, int index, int local)
3058 struct sas_phy *phy;
3059 struct sas_port *port;
3061 VirtTarget *vtarget;
3068 if (!phy_info->phy) {
3069 phy = sas_phy_alloc(dev, index);
3075 phy = phy_info->phy;
3077 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
3080 * Set Negotiated link rate.
3082 switch (phy_info->negotiated_link_rate) {
3083 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
3084 phy->negotiated_linkrate = SAS_PHY_DISABLED;
3086 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
3087 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
3089 case MPI_SAS_IOUNIT0_RATE_1_5:
3090 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
3092 case MPI_SAS_IOUNIT0_RATE_3_0:
3093 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
3095 case MPI_SAS_IOUNIT0_RATE_6_0:
3096 phy->negotiated_linkrate = SAS_LINK_RATE_6_0_GBPS;
3098 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
3099 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
3101 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
3106 * Set Max hardware link rate.
3108 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
3109 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
3110 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3112 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
3113 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
3120 * Set Max programmed link rate.
3122 switch (phy_info->programmed_link_rate &
3123 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
3124 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
3125 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
3127 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
3128 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
3135 * Set Min hardware link rate.
3137 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
3138 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
3139 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
3141 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
3142 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
3149 * Set Min programmed link rate.
3151 switch (phy_info->programmed_link_rate &
3152 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
3153 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
3154 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
3156 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
3157 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
3163 if (!phy_info->phy) {
3165 error = sas_phy_add(phy);
3170 phy_info->phy = phy;
3173 if (!phy_info->attached.handle ||
3174 !phy_info->port_details)
3177 port = mptsas_get_port(phy_info);
3178 ioc = phy_to_ioc(phy_info->phy);
3180 if (phy_info->sas_port_add_phy) {
3183 port = sas_port_alloc_num(dev);
3188 error = sas_port_add(port);
3190 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3191 "%s: exit at line=%d\n", ioc->name,
3192 __func__, __LINE__));
3195 mptsas_set_port(ioc, phy_info, port);
3196 devtprintk(ioc, dev_printk(KERN_DEBUG, &port->dev,
3197 MYIOC_s_FMT "add port %d, sas_addr (0x%llx)\n",
3198 ioc->name, port->port_identifier,
3199 (unsigned long long)phy_info->
3200 attached.sas_address));
3202 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3203 "sas_port_add_phy: phy_id=%d\n",
3204 ioc->name, phy_info->phy_id));
3205 sas_port_add_phy(port, phy_info->phy);
3206 phy_info->sas_port_add_phy = 0;
3207 devtprintk(ioc, dev_printk(KERN_DEBUG, &phy_info->phy->dev,
3208 MYIOC_s_FMT "add phy %d, phy-obj (0x%p)\n", ioc->name,
3209 phy_info->phy_id, phy_info->phy));
3211 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
3213 struct sas_rphy *rphy;
3214 struct device *parent;
3215 struct sas_identify identify;
3217 parent = dev->parent->parent;
3219 * Let the hotplug_work thread handle processing
3220 * the adding/removing of devices that occur
3221 * after start of day.
3223 if (mptsas_is_end_device(&phy_info->attached) &&
3224 phy_info->attached.handle_parent) {
3228 mptsas_parse_device_info(&identify, &phy_info->attached);
3229 if (scsi_is_host_device(parent)) {
3230 struct mptsas_portinfo *port_info;
3233 port_info = ioc->hba_port_info;
3235 for (i = 0; i < port_info->num_phys; i++)
3236 if (port_info->phy_info[i].identify.sas_address ==
3237 identify.sas_address) {
3238 sas_port_mark_backlink(port);
3242 } else if (scsi_is_sas_rphy(parent)) {
3243 struct sas_rphy *parent_rphy = dev_to_rphy(parent);
3244 if (identify.sas_address ==
3245 parent_rphy->identify.sas_address) {
3246 sas_port_mark_backlink(port);
3251 switch (identify.device_type) {
3252 case SAS_END_DEVICE:
3253 rphy = sas_end_device_alloc(port);
3255 case SAS_EDGE_EXPANDER_DEVICE:
3256 case SAS_FANOUT_EXPANDER_DEVICE:
3257 rphy = sas_expander_alloc(port, identify.device_type);
3264 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3265 "%s: exit at line=%d\n", ioc->name,
3266 __func__, __LINE__));
3270 rphy->identify = identify;
3271 error = sas_rphy_add(rphy);
3273 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3274 "%s: exit at line=%d\n", ioc->name,
3275 __func__, __LINE__));
3276 sas_rphy_free(rphy);
3279 mptsas_set_rphy(ioc, phy_info, rphy);
3280 if (identify.device_type == SAS_EDGE_EXPANDER_DEVICE ||
3281 identify.device_type == SAS_FANOUT_EXPANDER_DEVICE)
3282 mptsas_exp_repmanufacture_info(ioc,
3283 identify.sas_address,
3284 rphy_to_expander_device(rphy));
3287 /* If the device exists,verify it wasn't previously flagged
3288 as a missing device. If so, clear it */
3289 vtarget = mptsas_find_vtarget(ioc,
3290 phy_info->attached.channel,
3291 phy_info->attached.id);
3292 if (vtarget && vtarget->inDMD) {
3293 printk(KERN_INFO "Device returned, unsetting inDMD\n");
3302 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
3304 struct mptsas_portinfo *port_info, *hba;
3305 int error = -ENOMEM, i;
3307 hba = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
3311 error = mptsas_sas_io_unit_pg0(ioc, hba);
3313 goto out_free_port_info;
3315 mptsas_sas_io_unit_pg1(ioc);
3316 mutex_lock(&ioc->sas_topology_mutex);
3317 port_info = ioc->hba_port_info;
3319 ioc->hba_port_info = port_info = hba;
3320 ioc->hba_port_num_phy = port_info->num_phys;
3321 list_add_tail(&port_info->list, &ioc->sas_topology);
3323 for (i = 0; i < hba->num_phys; i++) {
3324 port_info->phy_info[i].negotiated_link_rate =
3325 hba->phy_info[i].negotiated_link_rate;
3326 port_info->phy_info[i].handle =
3327 hba->phy_info[i].handle;
3328 port_info->phy_info[i].port_id =
3329 hba->phy_info[i].port_id;
3331 kfree(hba->phy_info);
3335 mutex_unlock(&ioc->sas_topology_mutex);
3336 #if defined(CPQ_CIM)
3337 ioc->num_ports = port_info->num_phys;
3339 for (i = 0; i < port_info->num_phys; i++) {
3340 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
3341 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
3342 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
3343 port_info->phy_info[i].identify.handle =
3344 port_info->phy_info[i].handle;
3345 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
3346 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3347 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3348 port_info->phy_info[i].identify.handle);
3349 if (!ioc->hba_port_sas_addr)
3350 ioc->hba_port_sas_addr =
3351 port_info->phy_info[i].identify.sas_address;
3352 port_info->phy_info[i].identify.phy_id =
3353 port_info->phy_info[i].phy_id = i;
3354 if (port_info->phy_info[i].attached.handle)
3355 mptsas_sas_device_pg0(ioc,
3356 &port_info->phy_info[i].attached,
3357 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3358 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3359 port_info->phy_info[i].attached.handle);
3362 mptsas_setup_wide_ports(ioc, port_info);
3364 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
3365 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
3366 &port_info->phy_info[i], ioc->sas_index, 1);
3377 mptsas_expander_refresh(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
3379 struct mptsas_portinfo *parent;
3380 struct device *parent_dev;
3381 struct sas_rphy *rphy;
3383 u64 sas_address; /* expander sas address */
3386 handle = port_info->phy_info[0].handle;
3387 sas_address = port_info->phy_info[0].identify.sas_address;
3388 for (i = 0; i < port_info->num_phys; i++) {
3389 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
3390 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
3391 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + handle);
3393 mptsas_sas_device_pg0(ioc,
3394 &port_info->phy_info[i].identify,
3395 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3396 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3397 port_info->phy_info[i].identify.handle);
3398 port_info->phy_info[i].identify.phy_id =
3399 port_info->phy_info[i].phy_id;
3401 if (port_info->phy_info[i].attached.handle) {
3402 mptsas_sas_device_pg0(ioc,
3403 &port_info->phy_info[i].attached,
3404 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3405 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3406 port_info->phy_info[i].attached.handle);
3407 port_info->phy_info[i].attached.phy_id =
3408 port_info->phy_info[i].phy_id;
3412 mutex_lock(&ioc->sas_topology_mutex);
3413 parent = mptsas_find_portinfo_by_handle(ioc,
3414 port_info->phy_info[0].identify.handle_parent);
3416 mutex_unlock(&ioc->sas_topology_mutex);
3419 for (i = 0, parent_dev = NULL; i < parent->num_phys && !parent_dev;
3421 if (parent->phy_info[i].attached.sas_address == sas_address) {
3422 rphy = mptsas_get_rphy(&parent->phy_info[i]);
3423 parent_dev = &rphy->dev;
3426 mutex_unlock(&ioc->sas_topology_mutex);
3428 mptsas_setup_wide_ports(ioc, port_info);
3429 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
3430 mptsas_probe_one_phy(parent_dev, &port_info->phy_info[i],
3435 mptsas_expander_event_add(MPT_ADAPTER *ioc,
3436 MpiEventDataSasExpanderStatusChange_t *expander_data)
3438 struct mptsas_portinfo *port_info;
3442 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
3444 port_info->num_phys = (expander_data->NumPhys) ?
3445 expander_data->NumPhys : 1;
3446 port_info->phy_info = kcalloc(port_info->num_phys,
3447 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
3448 BUG_ON(!port_info->phy_info);
3449 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
3450 for (i = 0; i < port_info->num_phys; i++) {
3451 port_info->phy_info[i].portinfo = port_info;
3452 port_info->phy_info[i].handle =
3453 le16_to_cpu(expander_data->DevHandle);
3454 port_info->phy_info[i].identify.sas_address =
3455 le64_to_cpu(sas_address);
3456 port_info->phy_info[i].identify.handle_parent =
3457 le16_to_cpu(expander_data->ParentDevHandle);
3460 mutex_lock(&ioc->sas_topology_mutex);
3461 list_add_tail(&port_info->list, &ioc->sas_topology);
3462 mutex_unlock(&ioc->sas_topology_mutex);
3464 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3465 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3466 (unsigned long long)sas_address);
3468 mptsas_expander_refresh(ioc, port_info);
3472 * mptsas_delete_expander_siblings - remove siblings attached to expander
3473 * @ioc: Pointer to MPT_ADAPTER structure
3474 * @parent: the parent port_info object
3475 * @expander: the expander port_info object
3478 mptsas_delete_expander_siblings(MPT_ADAPTER *ioc, struct mptsas_portinfo
3479 *parent, struct mptsas_portinfo *expander)
3481 struct mptsas_phyinfo *phy_info;
3482 struct mptsas_portinfo *port_info;
3483 struct sas_rphy *rphy;
3486 phy_info = expander->phy_info;
3487 for (i = 0; i < expander->num_phys; i++, phy_info++) {
3488 rphy = mptsas_get_rphy(phy_info);
3491 if (rphy->identify.device_type == SAS_END_DEVICE)
3492 mptsas_del_end_device(ioc, phy_info);
3495 phy_info = expander->phy_info;
3496 for (i = 0; i < expander->num_phys; i++, phy_info++) {
3497 rphy = mptsas_get_rphy(phy_info);
3500 if (rphy->identify.device_type ==
3501 MPI_SAS_DEVICE_INFO_EDGE_EXPANDER ||
3502 rphy->identify.device_type ==
3503 MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
3504 port_info = mptsas_find_portinfo_by_sas_address(ioc,
3505 rphy->identify.sas_address);
3508 if (port_info == parent) /* backlink rphy */
3511 Delete this expander even if the expdevpage is exists
3512 because the parent expander is already deleted
3514 mptsas_expander_delete(ioc, port_info, 1);
3521 * mptsas_expander_delete - remove this expander
3522 * @ioc: Pointer to MPT_ADAPTER structure
3523 * @port_info: expander port_info struct
3524 * @force: Flag to forcefully delete the expander
3528 static void mptsas_expander_delete(MPT_ADAPTER *ioc,
3529 struct mptsas_portinfo *port_info, u8 force)
3532 struct mptsas_portinfo *parent;
3534 u64 expander_sas_address;
3535 struct mptsas_phyinfo *phy_info;
3536 struct mptsas_portinfo buffer;
3537 struct mptsas_portinfo_details *port_details;
3538 struct sas_port *port;
3543 /* see if expander is still there before deleting */
3544 mptsas_sas_expander_pg0(ioc, &buffer,
3545 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
3546 MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
3547 port_info->phy_info[0].identify.handle);
3549 if (buffer.num_phys) {
3550 kfree(buffer.phy_info);
3557 * Obtain the port_info instance to the parent port
3559 port_details = NULL;
3560 expander_sas_address =
3561 port_info->phy_info[0].identify.sas_address;
3562 parent = mptsas_find_portinfo_by_handle(ioc,
3563 port_info->phy_info[0].identify.handle_parent);
3564 mptsas_delete_expander_siblings(ioc, parent, port_info);
3569 * Delete rphys in the parent that point
3572 phy_info = parent->phy_info;
3574 for (i = 0; i < parent->num_phys; i++, phy_info++) {
3577 if (phy_info->attached.sas_address !=
3578 expander_sas_address)
3581 port = mptsas_get_port(phy_info);
3582 port_details = phy_info->port_details;
3584 dev_printk(KERN_DEBUG, &phy_info->phy->dev,
3585 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", ioc->name,
3586 phy_info->phy_id, phy_info->phy);
3587 sas_port_delete_phy(port, phy_info->phy);
3590 dev_printk(KERN_DEBUG, &port->dev,
3591 MYIOC_s_FMT "delete port %d, sas_addr (0x%llx)\n",
3592 ioc->name, port->port_identifier,
3593 (unsigned long long)expander_sas_address);
3594 sas_port_delete(port);
3595 mptsas_port_delete(ioc, port_details);
3599 printk(MYIOC_s_INFO_FMT "delete expander: num_phys %d, "
3600 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3601 (unsigned long long)expander_sas_address);
3606 list_del(&port_info->list);
3607 kfree(port_info->phy_info);
3613 * mptsas_send_expander_event - expanders events
3614 * @ioc: Pointer to MPT_ADAPTER structure
3615 * @expander_data: event data
3618 * This function handles adding, removing, and refreshing
3619 * device handles within the expander objects.
3622 mptsas_send_expander_event(struct fw_event_work *fw_event)
3625 MpiEventDataSasExpanderStatusChange_t *expander_data;
3626 struct mptsas_portinfo *port_info;
3630 ioc = fw_event->ioc;
3631 expander_data = (MpiEventDataSasExpanderStatusChange_t *)
3632 fw_event->event_data;
3633 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
3634 sas_address = le64_to_cpu(sas_address);
3635 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3637 if (expander_data->ReasonCode == MPI_EVENT_SAS_EXP_RC_ADDED) {
3639 for (i = 0; i < port_info->num_phys; i++) {
3640 port_info->phy_info[i].portinfo = port_info;
3641 port_info->phy_info[i].handle =
3642 le16_to_cpu(expander_data->DevHandle);
3643 port_info->phy_info[i].identify.sas_address =
3644 le64_to_cpu(sas_address);
3645 port_info->phy_info[i].identify.handle_parent =
3646 le16_to_cpu(expander_data->ParentDevHandle);
3648 mptsas_expander_refresh(ioc, port_info);
3649 } else if (!port_info && expander_data->NumPhys)
3650 mptsas_expander_event_add(ioc, expander_data);
3651 } else if (expander_data->ReasonCode ==
3652 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING)
3653 mptsas_expander_delete(ioc, port_info, 0);
3655 mptsas_free_fw_event(ioc, fw_event);
3660 * mptsas_expander_add -
3661 * @ioc: Pointer to MPT_ADAPTER structure
3665 static struct mptsas_portinfo *
3666 mptsas_expander_add(MPT_ADAPTER *ioc, u16 handle)
3668 struct mptsas_portinfo buffer, *port_info;
3671 if ((mptsas_sas_expander_pg0(ioc, &buffer,
3672 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
3673 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)))
3676 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_ATOMIC);
3678 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3679 "%s: exit at line=%d\n", ioc->name,
3680 __func__, __LINE__));
3683 port_info->num_phys = buffer.num_phys;
3684 port_info->phy_info = buffer.phy_info;
3685 for (i = 0; i < port_info->num_phys; i++)
3686 port_info->phy_info[i].portinfo = port_info;
3687 mutex_lock(&ioc->sas_topology_mutex);
3688 list_add_tail(&port_info->list, &ioc->sas_topology);
3689 mutex_unlock(&ioc->sas_topology_mutex);
3690 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3691 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3692 (unsigned long long)buffer.phy_info[0].identify.sas_address);
3693 mptsas_expander_refresh(ioc, port_info);
3698 mptsas_send_link_status_event(struct fw_event_work *fw_event)
3701 MpiEventDataSasPhyLinkStatus_t *link_data;
3702 struct mptsas_portinfo *port_info;
3703 struct mptsas_phyinfo *phy_info = NULL;
3708 ioc = fw_event->ioc;
3709 link_data = (MpiEventDataSasPhyLinkStatus_t *)fw_event->event_data;
3711 memcpy(&sas_address, &link_data->SASAddress, sizeof(__le64));
3712 sas_address = le64_to_cpu(sas_address);
3713 link_rate = link_data->LinkRates >> 4;
3714 phy_num = link_data->PhyNum;
3716 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3718 phy_info = &port_info->phy_info[phy_num];
3720 phy_info->negotiated_link_rate = link_rate;
3723 if (link_rate == MPI_SAS_IOUNIT0_RATE_1_5 ||
3724 link_rate == MPI_SAS_IOUNIT0_RATE_3_0 ||
3725 link_rate == MPI_SAS_IOUNIT0_RATE_6_0) {
3728 if (ioc->old_sas_discovery_protocal) {
3729 port_info = mptsas_expander_add(ioc,
3730 le16_to_cpu(link_data->DevHandle));
3737 if (port_info == ioc->hba_port_info)
3738 mptsas_probe_hba_phys(ioc);
3740 mptsas_expander_refresh(ioc, port_info);
3741 } else if (phy_info && phy_info->phy) {
3742 if (link_rate == MPI_SAS_IOUNIT0_RATE_PHY_DISABLED)
3743 phy_info->phy->negotiated_linkrate =
3745 else if (link_rate ==
3746 MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION)
3747 phy_info->phy->negotiated_linkrate =
3748 SAS_LINK_RATE_FAILED;
3750 phy_info->phy->negotiated_linkrate =
3751 SAS_LINK_RATE_UNKNOWN;
3752 if (ioc->device_missing_delay &&
3753 mptsas_is_end_device(&phy_info->attached)) {
3754 struct scsi_device *sdev;
3755 VirtDevice *vdevice;
3757 id = phy_info->attached.id;
3758 channel = phy_info->attached.channel;
3759 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3760 "Link down for fw_id %d:fw_channel %d\n",
3761 ioc->name, phy_info->attached.id,
3762 phy_info->attached.channel));
3764 shost_for_each_device(sdev, ioc->sh) {
3765 vdevice = sdev->hostdata;
3766 if ((vdevice == NULL) ||
3767 (vdevice->vtarget == NULL))
3769 if ((vdevice->vtarget->tflags &
3770 MPT_TARGET_FLAGS_RAID_COMPONENT ||
3771 vdevice->vtarget->raidVolume))
3773 if (vdevice->vtarget->id == id &&
3774 vdevice->vtarget->channel ==
3777 printk(MYIOC_s_DEBUG_FMT
3778 "SDEV OUTSTANDING CMDS"
3780 scsi_device_busy(sdev)));
3787 mptsas_free_fw_event(ioc, fw_event);
3791 mptsas_not_responding_devices(MPT_ADAPTER *ioc)
3793 struct mptsas_portinfo buffer, *port_info;
3794 struct mptsas_device_info *sas_info;
3795 struct mptsas_devinfo sas_device;
3797 VirtTarget *vtarget = NULL;
3798 struct mptsas_phyinfo *phy_info;
3800 int retval, retry_count;
3801 unsigned long flags;
3803 mpt_findImVolumes(ioc);
3805 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
3806 if (ioc->ioc_reset_in_progress) {
3807 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3808 "%s: exiting due to a parallel reset \n", ioc->name,
3810 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3813 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3815 /* devices, logical volumes */
3816 mutex_lock(&ioc->sas_device_info_mutex);
3818 list_for_each_entry(sas_info, &ioc->sas_device_info_list, list) {
3819 if (sas_info->is_cached)
3821 if (!sas_info->is_logical_volume) {
3822 sas_device.handle = 0;
3825 retval = mptsas_sas_device_pg0(ioc, &sas_device,
3826 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID
3827 << MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3828 (sas_info->fw.channel << 8) +
3831 if (sas_device.handle)
3833 if (retval == -EBUSY) {
3834 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
3835 if (ioc->ioc_reset_in_progress) {
3837 printk(MYIOC_s_DEBUG_FMT
3838 "%s: exiting due to reset\n",
3839 ioc->name, __func__));
3840 spin_unlock_irqrestore
3841 (&ioc->taskmgmt_lock, flags);
3843 sas_device_info_mutex);
3846 spin_unlock_irqrestore(&ioc->taskmgmt_lock,
3850 if (retval && (retval != -ENODEV)) {
3851 if (retry_count < 10) {
3855 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3856 "%s: Config page retry exceeded retry "
3857 "count deleting device 0x%llx\n",
3858 ioc->name, __func__,
3859 sas_info->sas_address));
3864 vtarget = mptsas_find_vtarget(ioc,
3865 sas_info->fw.channel, sas_info->fw.id);
3868 vtarget->deleted = 1;
3870 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3871 sas_info->sas_address);
3873 mptsas_del_end_device(ioc, phy_info);
3874 goto redo_device_scan;
3876 mptsas_volume_delete(ioc, sas_info->fw.id);
3878 mutex_unlock(&ioc->sas_device_info_mutex);
3881 mutex_lock(&ioc->sas_topology_mutex);
3883 list_for_each_entry(port_info, &ioc->sas_topology, list) {
3885 if (!(port_info->phy_info[0].identify.device_info &
3886 MPI_SAS_DEVICE_INFO_SMP_TARGET))
3890 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3891 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
3892 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle) &&
3895 handle = buffer.phy_info[0].handle;
3896 if (buffer.phy_info[0].identify.sas_address ==
3897 port_info->phy_info[0].identify.sas_address) {
3900 kfree(buffer.phy_info);
3903 if (!found_expander) {
3904 mptsas_expander_delete(ioc, port_info, 0);
3905 goto redo_expander_scan;
3908 mutex_unlock(&ioc->sas_topology_mutex);
3912 * mptsas_probe_expanders - adding expanders
3913 * @ioc: Pointer to MPT_ADAPTER structure
3917 mptsas_probe_expanders(MPT_ADAPTER *ioc)
3919 struct mptsas_portinfo buffer, *port_info;
3924 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3925 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
3926 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)) {
3928 handle = buffer.phy_info[0].handle;
3929 port_info = mptsas_find_portinfo_by_sas_address(ioc,
3930 buffer.phy_info[0].identify.sas_address);
3933 /* refreshing handles */
3934 for (i = 0; i < buffer.num_phys; i++) {
3935 port_info->phy_info[i].handle = handle;
3936 port_info->phy_info[i].identify.handle_parent =
3937 buffer.phy_info[0].identify.handle_parent;
3939 mptsas_expander_refresh(ioc, port_info);
3940 kfree(buffer.phy_info);
3944 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
3946 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3947 "%s: exit at line=%d\n", ioc->name,
3948 __func__, __LINE__));
3951 port_info->num_phys = buffer.num_phys;
3952 port_info->phy_info = buffer.phy_info;
3953 for (i = 0; i < port_info->num_phys; i++)
3954 port_info->phy_info[i].portinfo = port_info;
3955 mutex_lock(&ioc->sas_topology_mutex);
3956 list_add_tail(&port_info->list, &ioc->sas_topology);
3957 mutex_unlock(&ioc->sas_topology_mutex);
3958 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3959 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3960 (unsigned long long)buffer.phy_info[0].identify.sas_address);
3961 mptsas_expander_refresh(ioc, port_info);
3966 mptsas_probe_devices(MPT_ADAPTER *ioc)
3969 struct mptsas_devinfo sas_device;
3970 struct mptsas_phyinfo *phy_info;
3973 while (!(mptsas_sas_device_pg0(ioc, &sas_device,
3974 MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
3976 handle = sas_device.handle;
3978 if ((sas_device.device_info &
3979 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
3980 MPI_SAS_DEVICE_INFO_STP_TARGET |
3981 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0)
3984 /* If there is no FW B_T mapping for this device then continue
3986 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)
3987 || !(sas_device.flags &
3988 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED))
3991 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
3995 if (mptsas_get_rphy(phy_info))
3998 mptsas_add_end_device(ioc, phy_info);
4003 * mptsas_scan_sas_topology -
4004 * @ioc: Pointer to MPT_ADAPTER structure
4009 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
4011 struct scsi_device *sdev;
4014 mptsas_probe_hba_phys(ioc);
4015 mptsas_probe_expanders(ioc);
4016 mptsas_probe_devices(ioc);
4019 Reporting RAID volumes.
4021 if (!ioc->ir_firmware || !ioc->raid_data.pIocPg2 ||
4022 !ioc->raid_data.pIocPg2->NumActiveVolumes)
4024 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
4025 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
4026 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
4028 scsi_device_put(sdev);
4031 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
4032 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
4033 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID);
4034 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
4035 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
4041 mptsas_handle_queue_full_event(struct fw_event_work *fw_event)
4044 EventDataQueueFull_t *qfull_data;
4045 struct mptsas_device_info *sas_info;
4046 struct scsi_device *sdev;
4050 int fw_id, fw_channel;
4054 ioc = fw_event->ioc;
4055 qfull_data = (EventDataQueueFull_t *)fw_event->event_data;
4056 fw_id = qfull_data->TargetID;
4057 fw_channel = qfull_data->Bus;
4058 current_depth = le16_to_cpu(qfull_data->CurrentDepth);
4060 /* if hidden raid component, look for the volume id */
4061 mutex_lock(&ioc->sas_device_info_mutex);
4062 if (mptscsih_is_phys_disk(ioc, fw_channel, fw_id)) {
4063 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
4065 if (sas_info->is_cached ||
4066 sas_info->is_logical_volume)
4068 if (sas_info->is_hidden_raid_component &&
4069 (sas_info->fw.channel == fw_channel &&
4070 sas_info->fw.id == fw_id)) {
4071 id = sas_info->volume_id;
4072 channel = MPTSAS_RAID_CHANNEL;
4077 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
4079 if (sas_info->is_cached ||
4080 sas_info->is_hidden_raid_component ||
4081 sas_info->is_logical_volume)
4083 if (sas_info->fw.channel == fw_channel &&
4084 sas_info->fw.id == fw_id) {
4085 id = sas_info->os.id;
4086 channel = sas_info->os.channel;
4094 mutex_unlock(&ioc->sas_device_info_mutex);
4097 shost_for_each_device(sdev, ioc->sh) {
4098 if (sdev->id == id && sdev->channel == channel) {
4099 if (current_depth > sdev->queue_depth) {
4100 sdev_printk(KERN_INFO, sdev,
4101 "strange observation, the queue "
4102 "depth is (%d) meanwhile fw queue "
4103 "depth (%d)\n", sdev->queue_depth,
4107 depth = scsi_track_queue_full(sdev,
4108 sdev->queue_depth - 1);
4110 sdev_printk(KERN_INFO, sdev,
4111 "Queue depth reduced to (%d)\n",
4114 sdev_printk(KERN_INFO, sdev,
4115 "Tagged Command Queueing is being "
4117 else if (depth == 0)
4118 sdev_printk(KERN_DEBUG, sdev,
4119 "Queue depth not changed yet\n");
4124 mptsas_free_fw_event(ioc, fw_event);
4128 static struct mptsas_phyinfo *
4129 mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
4131 struct mptsas_portinfo *port_info;
4132 struct mptsas_phyinfo *phy_info = NULL;
4135 mutex_lock(&ioc->sas_topology_mutex);
4136 list_for_each_entry(port_info, &ioc->sas_topology, list) {
4137 for (i = 0; i < port_info->num_phys; i++) {
4138 if (!mptsas_is_end_device(
4139 &port_info->phy_info[i].attached))
4141 if (port_info->phy_info[i].attached.sas_address
4144 phy_info = &port_info->phy_info[i];
4148 mutex_unlock(&ioc->sas_topology_mutex);
4153 * mptsas_find_phyinfo_by_phys_disk_num -
4154 * @ioc: Pointer to MPT_ADAPTER structure
4160 static struct mptsas_phyinfo *
4161 mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num,
4164 struct mptsas_phyinfo *phy_info = NULL;
4165 struct mptsas_portinfo *port_info;
4166 RaidPhysDiskPage1_t *phys_disk = NULL;
4168 u64 sas_address = 0;
4172 if (!ioc->raid_data.pIocPg3)
4174 /* dual port support */
4175 num_paths = mpt_raid_phys_disk_get_num_paths(ioc, phys_disk_num);
4178 phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
4179 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
4182 mpt_raid_phys_disk_pg1(ioc, phys_disk_num, phys_disk);
4183 for (i = 0; i < num_paths; i++) {
4184 if ((phys_disk->Path[i].Flags & 1) != 0)
4185 /* entry no longer valid */
4187 if ((id == phys_disk->Path[i].PhysDiskID) &&
4188 (channel == phys_disk->Path[i].PhysDiskBus)) {
4189 memcpy(&sas_address, &phys_disk->Path[i].WWID,
4191 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4203 * Extra code to handle RAID0 case, where the sas_address is not updated
4204 * in phys_disk_page_1 when hotswapped
4206 mutex_lock(&ioc->sas_topology_mutex);
4207 list_for_each_entry(port_info, &ioc->sas_topology, list) {
4208 for (i = 0; i < port_info->num_phys && !phy_info; i++) {
4209 if (!mptsas_is_end_device(
4210 &port_info->phy_info[i].attached))
4212 if (port_info->phy_info[i].attached.phys_disk_num == ~0)
4214 if ((port_info->phy_info[i].attached.phys_disk_num ==
4216 (port_info->phy_info[i].attached.id == id) &&
4217 (port_info->phy_info[i].attached.channel ==
4219 phy_info = &port_info->phy_info[i];
4222 mutex_unlock(&ioc->sas_topology_mutex);
4227 mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
4231 sdev->no_uld_attach = data ? 1 : 0;
4232 rc = scsi_device_reprobe(sdev);
4236 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
4238 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
4239 mptsas_reprobe_lun);
4243 mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
4246 ConfigPageHeader_t hdr;
4247 dma_addr_t dma_handle;
4248 pRaidVolumePage0_t buffer = NULL;
4249 RaidPhysDiskPage0_t phys_disk;
4251 struct mptsas_phyinfo *phy_info;
4252 struct mptsas_devinfo sas_device;
4254 memset(&cfg, 0 , sizeof(CONFIGPARMS));
4255 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
4256 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
4257 cfg.pageAddr = (channel << 8) + id;
4258 cfg.cfghdr.hdr = &hdr;
4259 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4260 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
4262 if (mpt_config(ioc, &cfg) != 0)
4265 if (!hdr.PageLength)
4268 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
4274 cfg.physAddr = dma_handle;
4275 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4277 if (mpt_config(ioc, &cfg) != 0)
4280 if (!(buffer->VolumeStatus.Flags &
4281 MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
4284 if (!buffer->NumPhysDisks)
4287 for (i = 0; i < buffer->NumPhysDisks; i++) {
4289 if (mpt_raid_phys_disk_pg0(ioc,
4290 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
4293 if (mptsas_sas_device_pg0(ioc, &sas_device,
4294 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4295 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4296 (phys_disk.PhysDiskBus << 8) +
4297 phys_disk.PhysDiskID))
4300 /* If there is no FW B_T mapping for this device then continue
4302 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)
4303 || !(sas_device.flags &
4304 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED))
4308 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4309 sas_device.sas_address);
4310 mptsas_add_end_device(ioc, phy_info);
4315 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
4319 * Work queue thread to handle SAS hotplug events
4322 mptsas_hotplug_work(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
4323 struct mptsas_hotplug_event *hot_plug_info)
4325 struct mptsas_phyinfo *phy_info;
4326 struct scsi_target * starget;
4327 struct mptsas_devinfo sas_device;
4328 VirtTarget *vtarget;
4330 struct mptsas_portinfo *port_info;
4332 switch (hot_plug_info->event_type) {
4334 case MPTSAS_ADD_PHYSDISK:
4336 if (!ioc->raid_data.pIocPg2)
4339 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
4340 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID ==
4341 hot_plug_info->id) {
4342 printk(MYIOC_s_WARN_FMT "firmware bug: unable "
4343 "to add hidden disk - target_id matches "
4344 "volume_id\n", ioc->name);
4345 mptsas_free_fw_event(ioc, fw_event);
4349 mpt_findImVolumes(ioc);
4352 case MPTSAS_ADD_DEVICE:
4353 memset(&sas_device, 0, sizeof(struct mptsas_devinfo));
4354 mptsas_sas_device_pg0(ioc, &sas_device,
4355 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4356 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4357 (hot_plug_info->channel << 8) +
4360 /* If there is no FW B_T mapping for this device then break
4362 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)
4363 || !(sas_device.flags &
4364 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED))
4367 if (!sas_device.handle)
4370 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
4371 /* Device hot plug */
4373 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4375 "parent handle of device %x\n", ioc->name,
4376 __func__, __LINE__, sas_device.handle_parent));
4377 port_info = mptsas_find_portinfo_by_handle(ioc,
4378 sas_device.handle_parent);
4380 if (port_info == ioc->hba_port_info)
4381 mptsas_probe_hba_phys(ioc);
4383 mptsas_expander_refresh(ioc, port_info);
4385 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4386 "%s %d port info is NULL\n",
4387 ioc->name, __func__, __LINE__));
4390 phy_info = mptsas_refreshing_device_handles
4395 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4396 "%s %d phy info is NULL\n",
4397 ioc->name, __func__, __LINE__));
4401 if (mptsas_get_rphy(phy_info))
4404 mptsas_add_end_device(ioc, phy_info);
4407 case MPTSAS_DEL_DEVICE:
4408 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4409 hot_plug_info->sas_address);
4410 mptsas_del_end_device(ioc, phy_info);
4413 case MPTSAS_DEL_PHYSDISK:
4415 mpt_findImVolumes(ioc);
4417 phy_info = mptsas_find_phyinfo_by_phys_disk_num(
4418 ioc, hot_plug_info->phys_disk_num,
4419 hot_plug_info->channel,
4421 mptsas_del_end_device(ioc, phy_info);
4424 case MPTSAS_ADD_PHYSDISK_REPROBE:
4426 if (mptsas_sas_device_pg0(ioc, &sas_device,
4427 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4428 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4429 (hot_plug_info->channel << 8) + hot_plug_info->id)) {
4430 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4431 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4432 __func__, hot_plug_info->id, __LINE__));
4436 /* If there is no FW B_T mapping for this device then break
4438 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)
4439 || !(sas_device.flags &
4440 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED))
4443 phy_info = mptsas_find_phyinfo_by_sas_address(
4444 ioc, sas_device.sas_address);
4447 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4448 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4449 __func__, hot_plug_info->id, __LINE__));
4453 starget = mptsas_get_starget(phy_info);
4455 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4456 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4457 __func__, hot_plug_info->id, __LINE__));
4461 vtarget = starget->hostdata;
4463 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4464 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4465 __func__, hot_plug_info->id, __LINE__));
4469 mpt_findImVolumes(ioc);
4471 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Hidding: "
4472 "fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
4473 ioc->name, hot_plug_info->channel, hot_plug_info->id,
4474 hot_plug_info->phys_disk_num, (unsigned long long)
4475 sas_device.sas_address);
4477 vtarget->id = hot_plug_info->phys_disk_num;
4478 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
4479 phy_info->attached.phys_disk_num = hot_plug_info->phys_disk_num;
4480 mptsas_reprobe_target(starget, 1);
4483 case MPTSAS_DEL_PHYSDISK_REPROBE:
4485 if (mptsas_sas_device_pg0(ioc, &sas_device,
4486 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4487 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4488 (hot_plug_info->channel << 8) + hot_plug_info->id)) {
4489 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4490 "%s: fw_id=%d exit at line=%d\n",
4491 ioc->name, __func__,
4492 hot_plug_info->id, __LINE__));
4496 /* If there is no FW B_T mapping for this device then break
4498 if (!(sas_device.flags & MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)
4499 || !(sas_device.flags &
4500 MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED))
4503 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4504 sas_device.sas_address);
4506 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4507 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4508 __func__, hot_plug_info->id, __LINE__));
4512 starget = mptsas_get_starget(phy_info);
4514 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4515 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4516 __func__, hot_plug_info->id, __LINE__));
4520 vtarget = starget->hostdata;
4522 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4523 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4524 __func__, hot_plug_info->id, __LINE__));
4528 if (!(vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)) {
4529 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4530 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4531 __func__, hot_plug_info->id, __LINE__));
4535 mpt_findImVolumes(ioc);
4537 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Exposing:"
4538 " fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
4539 ioc->name, hot_plug_info->channel, hot_plug_info->id,
4540 hot_plug_info->phys_disk_num, (unsigned long long)
4541 sas_device.sas_address);
4543 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
4544 vtarget->id = hot_plug_info->id;
4545 phy_info->attached.phys_disk_num = ~0;
4546 mptsas_reprobe_target(starget, 0);
4547 mptsas_add_device_component_by_fw(ioc,
4548 hot_plug_info->channel, hot_plug_info->id);
4551 case MPTSAS_ADD_RAID:
4553 mpt_findImVolumes(ioc);
4554 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
4555 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
4557 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
4558 hot_plug_info->id, 0);
4561 case MPTSAS_DEL_RAID:
4563 mpt_findImVolumes(ioc);
4564 printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
4565 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
4567 scsi_remove_device(hot_plug_info->sdev);
4568 scsi_device_put(hot_plug_info->sdev);
4571 case MPTSAS_ADD_INACTIVE_VOLUME:
4573 mpt_findImVolumes(ioc);
4574 mptsas_adding_inactive_raid_components(ioc,
4575 hot_plug_info->channel, hot_plug_info->id);
4582 mptsas_free_fw_event(ioc, fw_event);
4586 mptsas_send_sas_event(struct fw_event_work *fw_event)
4589 struct mptsas_hotplug_event hot_plug_info;
4590 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
4594 ioc = fw_event->ioc;
4595 sas_event_data = (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)
4596 fw_event->event_data;
4597 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
4600 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
4601 MPI_SAS_DEVICE_INFO_STP_TARGET |
4602 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) {
4603 mptsas_free_fw_event(ioc, fw_event);
4607 if (sas_event_data->ReasonCode ==
4608 MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED) {
4609 mptbase_sas_persist_operation(ioc,
4610 MPI_SAS_OP_CLEAR_NOT_PRESENT);
4611 mptsas_free_fw_event(ioc, fw_event);
4615 switch (sas_event_data->ReasonCode) {
4616 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
4617 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
4618 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4619 hot_plug_info.handle = le16_to_cpu(sas_event_data->DevHandle);
4620 hot_plug_info.channel = sas_event_data->Bus;
4621 hot_plug_info.id = sas_event_data->TargetID;
4622 hot_plug_info.phy_id = sas_event_data->PhyNum;
4623 memcpy(&sas_address, &sas_event_data->SASAddress,
4625 hot_plug_info.sas_address = le64_to_cpu(sas_address);
4626 hot_plug_info.device_info = device_info;
4627 if (sas_event_data->ReasonCode &
4628 MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
4629 hot_plug_info.event_type = MPTSAS_ADD_DEVICE;
4631 hot_plug_info.event_type = MPTSAS_DEL_DEVICE;
4632 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4635 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
4636 mptbase_sas_persist_operation(ioc,
4637 MPI_SAS_OP_CLEAR_NOT_PRESENT);
4638 mptsas_free_fw_event(ioc, fw_event);
4641 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
4643 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
4646 mptsas_free_fw_event(ioc, fw_event);
4652 mptsas_send_raid_event(struct fw_event_work *fw_event)
4655 EVENT_DATA_RAID *raid_event_data;
4656 struct mptsas_hotplug_event hot_plug_info;
4659 struct scsi_device *sdev = NULL;
4660 VirtDevice *vdevice = NULL;
4661 RaidPhysDiskPage0_t phys_disk;
4663 ioc = fw_event->ioc;
4664 raid_event_data = (EVENT_DATA_RAID *)fw_event->event_data;
4665 status = le32_to_cpu(raid_event_data->SettingsStatus);
4666 state = (status >> 8) & 0xff;
4668 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4669 hot_plug_info.id = raid_event_data->VolumeID;
4670 hot_plug_info.channel = raid_event_data->VolumeBus;
4671 hot_plug_info.phys_disk_num = raid_event_data->PhysDiskNum;
4673 if (raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_DELETED ||
4674 raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_CREATED ||
4675 raid_event_data->ReasonCode ==
4676 MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED) {
4677 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
4678 hot_plug_info.id, 0);
4679 hot_plug_info.sdev = sdev;
4681 vdevice = sdev->hostdata;
4684 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
4685 "ReasonCode=%02x\n", ioc->name, __func__,
4686 raid_event_data->ReasonCode));
4688 switch (raid_event_data->ReasonCode) {
4689 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
4690 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK_REPROBE;
4692 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
4693 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK_REPROBE;
4695 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
4697 case MPI_PD_STATE_ONLINE:
4698 case MPI_PD_STATE_NOT_COMPATIBLE:
4699 mpt_raid_phys_disk_pg0(ioc,
4700 raid_event_data->PhysDiskNum, &phys_disk);
4701 hot_plug_info.id = phys_disk.PhysDiskID;
4702 hot_plug_info.channel = phys_disk.PhysDiskBus;
4703 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
4705 case MPI_PD_STATE_FAILED:
4706 case MPI_PD_STATE_MISSING:
4707 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
4708 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
4709 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
4710 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
4716 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
4719 vdevice->vtarget->deleted = 1; /* block IO */
4720 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4722 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
4724 scsi_device_put(sdev);
4727 hot_plug_info.event_type = MPTSAS_ADD_RAID;
4729 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
4730 if (!(status & MPI_RAIDVOL0_STATUS_FLAG_ENABLED)) {
4733 vdevice->vtarget->deleted = 1; /* block IO */
4734 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4738 case MPI_RAIDVOL0_STATUS_STATE_FAILED:
4739 case MPI_RAIDVOL0_STATUS_STATE_MISSING:
4742 vdevice->vtarget->deleted = 1; /* block IO */
4743 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4745 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
4746 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
4748 scsi_device_put(sdev);
4751 hot_plug_info.event_type = MPTSAS_ADD_RAID;
4761 if (hot_plug_info.event_type != MPTSAS_IGNORE_EVENT)
4762 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4764 mptsas_free_fw_event(ioc, fw_event);
4768 * mptsas_issue_tm - send mptsas internal tm request
4769 * @ioc: Pointer to MPT_ADAPTER structure
4770 * @type: Task Management type
4771 * @channel: channel number for task management
4772 * @id: Logical Target ID for reset (if appropriate)
4773 * @lun: Logical unit for reset (if appropriate)
4774 * @task_context: Context for the task to be aborted
4775 * @timeout: timeout for task management control
4777 * return 0 on success and -1 on failure:
4781 mptsas_issue_tm(MPT_ADAPTER *ioc, u8 type, u8 channel, u8 id, u64 lun,
4782 int task_context, ulong timeout, u8 *issue_reset)
4785 SCSITaskMgmt_t *pScsiTm;
4787 unsigned long timeleft;
4790 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
4792 retval = -1; /* return failure */
4793 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt request: no "
4794 "msg frames!!\n", ioc->name));
4798 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request: mr = %p, "
4799 "task_type = 0x%02X,\n\t timeout = %ld, fw_channel = %d, "
4800 "fw_id = %d, lun = %lld,\n\t task_context = 0x%x\n", ioc->name, mf,
4801 type, timeout, channel, id, (unsigned long long)lun,
4804 pScsiTm = (SCSITaskMgmt_t *) mf;
4805 memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t));
4806 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
4807 pScsiTm->TaskType = type;
4808 pScsiTm->MsgFlags = 0;
4809 pScsiTm->TargetID = id;
4810 pScsiTm->Bus = channel;
4811 pScsiTm->ChainOffset = 0;
4812 pScsiTm->Reserved = 0;
4813 pScsiTm->Reserved1 = 0;
4814 pScsiTm->TaskMsgContext = task_context;
4815 int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
4817 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
4818 CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
4820 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
4822 /* Now wait for the command to complete */
4823 timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done,
4825 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
4826 retval = -1; /* return failure */
4827 dtmprintk(ioc, printk(MYIOC_s_ERR_FMT
4828 "TaskMgmt request: TIMED OUT!(mr=%p)\n", ioc->name, mf));
4829 mpt_free_msg_frame(ioc, mf);
4830 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
4836 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
4837 retval = -1; /* return failure */
4838 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4839 "TaskMgmt request: failed with no reply\n", ioc->name));
4844 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
4849 * mptsas_broadcast_primitive_work - Handle broadcast primitives
4850 * @work: work queue payload containing info describing the event
4852 * this will be handled in workqueue context.
4855 mptsas_broadcast_primitive_work(struct fw_event_work *fw_event)
4857 MPT_ADAPTER *ioc = fw_event->ioc;
4859 VirtDevice *vdevice;
4861 struct scsi_cmnd *sc;
4862 SCSITaskMgmtReply_t *pScsiTmReply;
4867 u32 termination_count;
4870 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4871 "%s - enter\n", ioc->name, __func__));
4873 mutex_lock(&ioc->taskmgmt_cmds.mutex);
4874 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
4875 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
4876 mptsas_requeue_fw_event(ioc, fw_event, 1000);
4881 termination_count = 0;
4883 mpt_findImVolumes(ioc);
4884 pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply;
4886 for (ii = 0; ii < ioc->req_depth; ii++) {
4887 if (ioc->fw_events_off)
4889 sc = mptscsih_get_scsi_lookup(ioc, ii);
4892 mf = MPT_INDEX_2_MFPTR(ioc, ii);
4895 task_context = mf->u.frame.hwhdr.msgctxu.MsgContext;
4896 vdevice = sc->device->hostdata;
4897 if (!vdevice || !vdevice->vtarget)
4899 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
4900 continue; /* skip hidden raid components */
4901 if (vdevice->vtarget->raidVolume)
4902 continue; /* skip hidden raid components */
4903 channel = vdevice->vtarget->channel;
4904 id = vdevice->vtarget->id;
4906 if (mptsas_issue_tm(ioc, MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK,
4907 channel, id, (u64)lun, task_context, 30, &issue_reset))
4910 termination_count +=
4911 le32_to_cpu(pScsiTmReply->TerminationCount);
4912 if ((pScsiTmReply->IOCStatus == MPI_IOCSTATUS_SUCCESS) &&
4913 (pScsiTmReply->ResponseCode ==
4914 MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
4915 pScsiTmReply->ResponseCode ==
4916 MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC))
4918 if (mptsas_issue_tm(ioc,
4919 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET,
4920 channel, id, (u64)lun, 0, 30, &issue_reset))
4922 termination_count +=
4923 le32_to_cpu(pScsiTmReply->TerminationCount);
4927 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4928 "%s - exit, query_count = %d termination_count = %d\n",
4929 ioc->name, __func__, query_count, termination_count));
4931 ioc->broadcast_aen_busy = 0;
4932 mpt_clear_taskmgmt_in_progress_flag(ioc);
4933 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
4936 printk(MYIOC_s_WARN_FMT
4937 "Issuing Reset from %s!! doorbell=0x%08x\n",
4938 ioc->name, __func__, mpt_GetIocState(ioc, 0));
4939 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
4941 mptsas_free_fw_event(ioc, fw_event);
4945 * mptsas_send_ir2_event - handle exposing hidden disk when
4946 * an inactive raid volume is added
4948 * @ioc: Pointer to MPT_ADAPTER structure
4953 mptsas_send_ir2_event(struct fw_event_work *fw_event)
4956 struct mptsas_hotplug_event hot_plug_info;
4957 MPI_EVENT_DATA_IR2 *ir2_data;
4959 RaidPhysDiskPage0_t phys_disk;
4961 ioc = fw_event->ioc;
4962 ir2_data = (MPI_EVENT_DATA_IR2 *)fw_event->event_data;
4963 reasonCode = ir2_data->ReasonCode;
4965 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
4966 "ReasonCode=%02x\n", ioc->name, __func__, reasonCode));
4968 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4969 hot_plug_info.id = ir2_data->TargetID;
4970 hot_plug_info.channel = ir2_data->Bus;
4971 switch (reasonCode) {
4972 case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
4973 hot_plug_info.event_type = MPTSAS_ADD_INACTIVE_VOLUME;
4975 case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED:
4976 hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum;
4977 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
4979 case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED:
4980 hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum;
4981 mpt_raid_phys_disk_pg0(ioc,
4982 ir2_data->PhysDiskNum, &phys_disk);
4983 hot_plug_info.id = phys_disk.PhysDiskID;
4984 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
4987 mptsas_free_fw_event(ioc, fw_event);
4990 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4994 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
4996 u32 event = le32_to_cpu(reply->Event);
4998 struct fw_event_work *fw_event;
4999 unsigned long delay;
5001 if (ioc->bus_type != SAS)
5004 /* events turned off due to host reset or driver unloading */
5005 if (ioc->fw_events_off)
5008 delay = msecs_to_jiffies(1);
5010 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
5012 EVENT_DATA_SAS_BROADCAST_PRIMITIVE *broadcast_event_data =
5013 (EVENT_DATA_SAS_BROADCAST_PRIMITIVE *)reply->Data;
5014 if (broadcast_event_data->Primitive !=
5015 MPI_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
5017 if (ioc->broadcast_aen_busy)
5019 ioc->broadcast_aen_busy = 1;
5022 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
5024 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data =
5025 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data;
5027 ioc_stat = le16_to_cpu(reply->IOCStatus);
5029 if (sas_event_data->ReasonCode ==
5030 MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING) {
5031 mptsas_target_reset_queue(ioc, sas_event_data);
5034 if (sas_event_data->ReasonCode ==
5035 MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
5036 ioc->device_missing_delay &&
5037 (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)) {
5038 VirtTarget *vtarget = NULL;
5041 id = sas_event_data->TargetID;
5042 channel = sas_event_data->Bus;
5044 vtarget = mptsas_find_vtarget(ioc, channel, id);
5046 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5047 "LogInfo (0x%x) available for "
5048 "INTERNAL_DEVICE_RESET"
5049 "fw_id %d fw_channel %d\n", ioc->name,
5050 le32_to_cpu(reply->IOCLogInfo),
5052 if (vtarget->raidVolume) {
5053 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5054 "Skipping Raid Volume for inDMD\n",
5057 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5058 "Setting device flag inDMD\n",
5069 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
5071 MpiEventDataSasExpanderStatusChange_t *expander_data =
5072 (MpiEventDataSasExpanderStatusChange_t *)reply->Data;
5074 if (ioc->old_sas_discovery_protocal)
5077 if (expander_data->ReasonCode ==
5078 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING &&
5079 ioc->device_missing_delay)
5080 delay = HZ * ioc->device_missing_delay;
5083 case MPI_EVENT_SAS_DISCOVERY:
5085 u32 discovery_status;
5086 EventDataSasDiscovery_t *discovery_data =
5087 (EventDataSasDiscovery_t *)reply->Data;
5089 discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus);
5090 ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0;
5091 if (ioc->old_sas_discovery_protocal && !discovery_status)
5092 mptsas_queue_rescan(ioc);
5095 case MPI_EVENT_INTEGRATED_RAID:
5096 case MPI_EVENT_PERSISTENT_TABLE_FULL:
5098 case MPI_EVENT_SAS_PHY_LINK_STATUS:
5099 case MPI_EVENT_QUEUE_FULL:
5105 event_data_sz = ((reply->MsgLength * 4) -
5106 offsetof(EventNotificationReply_t, Data));
5107 fw_event = kzalloc(sizeof(*fw_event) + event_data_sz, GFP_ATOMIC);
5109 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", ioc->name,
5110 __func__, __LINE__);
5113 memcpy(fw_event->event_data, reply->Data, event_data_sz);
5114 fw_event->event = event;
5115 fw_event->ioc = ioc;
5116 mptsas_add_fw_event(ioc, fw_event, delay);
5120 /* Delete a volume when no longer listed in ioc pg2
5122 static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id)
5124 struct scsi_device *sdev;
5127 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, id, 0);
5130 if (!ioc->raid_data.pIocPg2)
5132 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
5134 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
5135 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id)
5138 printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
5139 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, id);
5140 scsi_remove_device(sdev);
5142 scsi_device_put(sdev);
5146 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
5148 struct Scsi_Host *sh;
5151 unsigned long flags;
5159 r = mpt_attach(pdev,id);
5163 ioc = pci_get_drvdata(pdev);
5164 mptsas_fw_event_off(ioc);
5165 ioc->DoneCtx = mptsasDoneCtx;
5166 ioc->TaskCtx = mptsasTaskCtx;
5167 ioc->InternalCtx = mptsasInternalCtx;
5168 ioc->schedule_target_reset = &mptsas_schedule_target_reset;
5169 ioc->schedule_dead_ioc_flush_running_cmds =
5170 &mptscsih_flush_running_cmds;
5171 /* Added sanity check on readiness of the MPT adapter.
5173 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
5174 printk(MYIOC_s_WARN_FMT
5175 "Skipping because it's not operational!\n",
5178 goto out_mptsas_probe;
5182 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
5185 goto out_mptsas_probe;
5188 /* Sanity check - ensure at least 1 port is INITIATOR capable
5191 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
5192 if (ioc->pfacts[ii].ProtocolFlags &
5193 MPI_PORTFACTS_PROTOCOL_INITIATOR)
5198 printk(MYIOC_s_WARN_FMT
5199 "Skipping ioc=%p because SCSI Initiator mode "
5200 "is NOT enabled!\n", ioc->name, ioc);
5204 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
5206 printk(MYIOC_s_WARN_FMT
5207 "Unable to register controller with SCSI subsystem\n",
5210 goto out_mptsas_probe;
5213 spin_lock_irqsave(&ioc->FreeQlock, flags);
5215 /* Attach the SCSI Host to the IOC structure
5223 /* set 16 byte cdb's */
5224 sh->max_cmd_len = 16;
5225 sh->can_queue = min_t(int, ioc->req_depth - 10, sh->can_queue);
5227 sh->max_lun = max_lun;
5228 sh->transportt = mptsas_transport_template;
5232 sh->unique_id = ioc->id;
5234 INIT_LIST_HEAD(&ioc->sas_topology);
5235 mutex_init(&ioc->sas_topology_mutex);
5236 mutex_init(&ioc->sas_discovery_mutex);
5237 mutex_init(&ioc->sas_mgmt.mutex);
5238 init_completion(&ioc->sas_mgmt.done);
5240 /* Verify that we won't exceed the maximum
5241 * number of chain buffers
5242 * We can optimize: ZZ = req_sz/sizeof(SGE)
5244 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
5245 * + (req_sz - 64)/sizeof(SGE)
5246 * A slightly different algorithm is required for
5249 scale = ioc->req_sz/ioc->SGE_size;
5250 if (ioc->sg_addr_size == sizeof(u64)) {
5251 numSGE = (scale - 1) *
5252 (ioc->facts.MaxChainDepth-1) + scale +
5253 (ioc->req_sz - 60) / ioc->SGE_size;
5255 numSGE = 1 + (scale - 1) *
5256 (ioc->facts.MaxChainDepth-1) + scale +
5257 (ioc->req_sz - 64) / ioc->SGE_size;
5260 if (numSGE < sh->sg_tablesize) {
5261 /* Reset this value */
5262 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5263 "Resetting sg_tablesize to %d from %d\n",
5264 ioc->name, numSGE, sh->sg_tablesize));
5265 sh->sg_tablesize = numSGE;
5268 if (mpt_loadtime_max_sectors) {
5269 if (mpt_loadtime_max_sectors < 64 ||
5270 mpt_loadtime_max_sectors > 8192) {
5271 printk(MYIOC_s_INFO_FMT "Invalid value passed for"
5272 "mpt_loadtime_max_sectors %d."
5273 "Range from 64 to 8192\n", ioc->name,
5274 mpt_loadtime_max_sectors);
5276 mpt_loadtime_max_sectors &= 0xFFFFFFFE;
5277 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5278 "Resetting max sector to %d from %d\n",
5279 ioc->name, mpt_loadtime_max_sectors, sh->max_sectors));
5280 sh->max_sectors = mpt_loadtime_max_sectors;
5283 hd = shost_priv(sh);
5286 /* SCSI needs scsi_cmnd lookup table!
5287 * (with size equal to req_depth*PtrSz!)
5289 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
5290 if (!ioc->ScsiLookup) {
5292 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
5293 goto out_mptsas_probe;
5295 spin_lock_init(&ioc->scsi_lookup_lock);
5297 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
5298 ioc->name, ioc->ScsiLookup));
5300 ioc->sas_data.ptClear = mpt_pt_clear;
5302 hd->last_queue_full = 0;
5303 INIT_LIST_HEAD(&hd->target_reset_list);
5304 INIT_LIST_HEAD(&ioc->sas_device_info_list);
5305 mutex_init(&ioc->sas_device_info_mutex);
5307 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
5309 if (ioc->sas_data.ptClear==1) {
5310 mptbase_sas_persist_operation(
5311 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
5314 error = scsi_add_host(sh, &ioc->pcidev->dev);
5316 dprintk(ioc, printk(MYIOC_s_ERR_FMT
5317 "scsi_add_host failed\n", ioc->name));
5318 goto out_mptsas_probe;
5321 /* older firmware doesn't support expander events */
5322 if ((ioc->facts.HeaderVersion >> 8) < 0xE)
5323 ioc->old_sas_discovery_protocal = 1;
5324 mptsas_scan_sas_topology(ioc);
5325 mptsas_fw_event_on(ioc);
5330 mptscsih_remove(pdev);
5335 mptsas_shutdown(struct pci_dev *pdev)
5337 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
5339 mptsas_fw_event_off(ioc);
5340 mptsas_cleanup_fw_event_q(ioc);
5343 static void mptsas_remove(struct pci_dev *pdev)
5345 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
5346 struct mptsas_portinfo *p, *n;
5350 printk(MYIOC_s_INFO_FMT "IOC is in Target mode\n", ioc->name);
5355 mptsas_shutdown(pdev);
5357 mptsas_del_device_components(ioc);
5359 ioc->sas_discovery_ignore_events = 1;
5360 sas_remove_host(ioc->sh);
5362 mutex_lock(&ioc->sas_topology_mutex);
5363 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
5365 for (i = 0 ; i < p->num_phys ; i++)
5366 mptsas_port_delete(ioc, p->phy_info[i].port_details);
5371 mutex_unlock(&ioc->sas_topology_mutex);
5372 ioc->hba_port_info = NULL;
5373 mptscsih_remove(pdev);
5376 static struct pci_device_id mptsas_pci_table[] = {
5377 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
5378 PCI_ANY_ID, PCI_ANY_ID },
5379 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
5380 PCI_ANY_ID, PCI_ANY_ID },
5381 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
5382 PCI_ANY_ID, PCI_ANY_ID },
5383 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
5384 PCI_ANY_ID, PCI_ANY_ID },
5385 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
5386 PCI_ANY_ID, PCI_ANY_ID },
5387 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068_820XELP,
5388 PCI_ANY_ID, PCI_ANY_ID },
5389 {0} /* Terminating entry */
5391 MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
5394 static struct pci_driver mptsas_driver = {
5396 .id_table = mptsas_pci_table,
5397 .probe = mptsas_probe,
5398 .remove = mptsas_remove,
5399 .shutdown = mptsas_shutdown,
5401 .suspend = mptscsih_suspend,
5402 .resume = mptscsih_resume,
5411 show_mptmod_ver(my_NAME, my_VERSION);
5413 mptsas_transport_template =
5414 sas_attach_transport(&mptsas_transport_functions);
5415 if (!mptsas_transport_template)
5418 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER,
5419 "mptscsih_io_done");
5420 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER,
5421 "mptscsih_taskmgmt_complete");
5423 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER,
5424 "mptscsih_scandv_complete");
5425 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER,
5426 "mptsas_mgmt_done");
5427 mptsasDeviceResetCtx =
5428 mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER,
5429 "mptsas_taskmgmt_complete");
5431 mpt_event_register(mptsasDoneCtx, mptsas_event_process);
5432 mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset);
5434 error = pci_register_driver(&mptsas_driver);
5436 sas_release_transport(mptsas_transport_template);
5444 pci_unregister_driver(&mptsas_driver);
5445 sas_release_transport(mptsas_transport_template);
5447 mpt_reset_deregister(mptsasDoneCtx);
5448 mpt_event_deregister(mptsasDoneCtx);
5450 mpt_deregister(mptsasMgmtCtx);
5451 mpt_deregister(mptsasInternalCtx);
5452 mpt_deregister(mptsasTaskCtx);
5453 mpt_deregister(mptsasDoneCtx);
5454 mpt_deregister(mptsasDeviceResetCtx);
5457 module_init(mptsas_init);
5458 module_exit(mptsas_exit);