2 * linux/drivers/message/fusion/mptsas.c
3 * For use with LSI PCI chip/adapter(s)
4 * running LSI Fusion MPT (Message Passing Technology) firmware.
6 * Copyright (c) 1999-2008 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com)
9 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; version 2 of the License.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
21 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25 solely responsible for determining the appropriateness of using and
26 distributing the Program and assumes all risks associated with its
27 exercise of rights under this Agreement, including but not limited to
28 the risks and costs of program errors, damage to or loss of data,
29 programs or equipment, and unavailability or interruption of operations.
31 DISCLAIMER OF LIABILITY
32 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 You should have received a copy of the GNU General Public License
41 along with this program; if not, write to the Free Software
42 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
46 #include <linux/module.h>
47 #include <linux/kernel.h>
48 #include <linux/init.h>
49 #include <linux/errno.h>
50 #include <linux/jiffies.h>
51 #include <linux/workqueue.h>
52 #include <linux/delay.h> /* for mdelay */
54 #include <scsi/scsi.h>
55 #include <scsi/scsi_cmnd.h>
56 #include <scsi/scsi_device.h>
57 #include <scsi/scsi_host.h>
58 #include <scsi/scsi_transport_sas.h>
59 #include <scsi/scsi_dbg.h>
66 #define my_NAME "Fusion MPT SAS Host driver"
67 #define my_VERSION MPT_LINUX_VERSION_COMMON
68 #define MYNAM "mptsas"
71 * Reserved channel for integrated raid
73 #define MPTSAS_RAID_CHANNEL 1
75 MODULE_AUTHOR(MODULEAUTHOR);
76 MODULE_DESCRIPTION(my_NAME);
77 MODULE_LICENSE("GPL");
78 MODULE_VERSION(my_VERSION);
80 static int mpt_pt_clear;
81 module_param(mpt_pt_clear, int, 0);
82 MODULE_PARM_DESC(mpt_pt_clear,
83 " Clear persistency table: enable=1 "
84 "(default=MPTSCSIH_PT_CLEAR=0)");
86 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
87 #define MPTSAS_MAX_LUN (16895)
88 static int max_lun = MPTSAS_MAX_LUN;
89 module_param(max_lun, int, 0);
90 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
92 static u8 mptsasDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
93 static u8 mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
94 static u8 mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
95 static u8 mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS;
96 static u8 mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS;
98 static void mptsas_firmware_event_work(struct work_struct *work);
99 static void mptsas_send_sas_event(struct fw_event_work *fw_event);
100 static void mptsas_send_raid_event(struct fw_event_work *fw_event);
101 static void mptsas_send_ir2_event(struct fw_event_work *fw_event);
102 static void mptsas_parse_device_info(struct sas_identify *identify,
103 struct mptsas_devinfo *device_info);
104 static inline void mptsas_set_rphy(MPT_ADAPTER *ioc,
105 struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy);
106 static struct mptsas_phyinfo *mptsas_find_phyinfo_by_sas_address
107 (MPT_ADAPTER *ioc, u64 sas_address);
108 static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc,
109 struct mptsas_devinfo *device_info, u32 form, u32 form_specific);
110 static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc,
111 struct mptsas_enclosure *enclosure, u32 form, u32 form_specific);
112 static int mptsas_add_end_device(MPT_ADAPTER *ioc,
113 struct mptsas_phyinfo *phy_info);
114 static void mptsas_del_end_device(MPT_ADAPTER *ioc,
115 struct mptsas_phyinfo *phy_info);
116 static void mptsas_send_link_status_event(struct fw_event_work *fw_event);
117 static struct mptsas_portinfo *mptsas_find_portinfo_by_sas_address
118 (MPT_ADAPTER *ioc, u64 sas_address);
119 static void mptsas_expander_delete(MPT_ADAPTER *ioc,
120 struct mptsas_portinfo *port_info, u8 force);
121 static void mptsas_send_expander_event(struct fw_event_work *fw_event);
122 static void mptsas_not_responding_devices(MPT_ADAPTER *ioc);
123 static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc);
124 static void mptsas_handle_queue_full_event(struct fw_event_work *fw_event);
125 static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id);
127 static void mptsas_print_phy_data(MPT_ADAPTER *ioc,
128 MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
130 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
131 "---- IO UNIT PAGE 0 ------------\n", ioc->name));
132 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
133 ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle)));
134 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n",
135 ioc->name, le16_to_cpu(phy_data->ControllerDevHandle)));
136 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n",
137 ioc->name, phy_data->Port));
138 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n",
139 ioc->name, phy_data->PortFlags));
140 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n",
141 ioc->name, phy_data->PhyFlags));
142 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
143 ioc->name, phy_data->NegotiatedLinkRate));
144 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
145 "Controller PHY Device Info=0x%X\n", ioc->name,
146 le32_to_cpu(phy_data->ControllerPhyDeviceInfo)));
147 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n",
148 ioc->name, le32_to_cpu(phy_data->DiscoveryStatus)));
151 static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0)
155 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
157 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
158 "---- SAS PHY PAGE 0 ------------\n", ioc->name));
159 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
160 "Attached Device Handle=0x%X\n", ioc->name,
161 le16_to_cpu(pg0->AttachedDevHandle)));
162 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
163 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
164 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
165 "Attached PHY Identifier=0x%X\n", ioc->name,
166 pg0->AttachedPhyIdentifier));
167 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n",
168 ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo)));
169 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
170 ioc->name, pg0->ProgrammedLinkRate));
171 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n",
172 ioc->name, pg0->ChangeCount));
173 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n",
174 ioc->name, le32_to_cpu(pg0->PhyInfo)));
177 static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1)
179 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
180 "---- SAS PHY PAGE 1 ------------\n", ioc->name));
181 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n",
182 ioc->name, pg1->InvalidDwordCount));
183 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
184 "Running Disparity Error Count=0x%x\n", ioc->name,
185 pg1->RunningDisparityErrorCount));
186 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
187 "Loss Dword Synch Count=0x%x\n", ioc->name,
188 pg1->LossDwordSynchCount));
189 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
190 "PHY Reset Problem Count=0x%x\n\n", ioc->name,
191 pg1->PhyResetProblemCount));
194 static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0)
198 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
200 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
201 "---- SAS DEVICE PAGE 0 ---------\n", ioc->name));
202 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
203 ioc->name, le16_to_cpu(pg0->DevHandle)));
204 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n",
205 ioc->name, le16_to_cpu(pg0->ParentDevHandle)));
206 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n",
207 ioc->name, le16_to_cpu(pg0->EnclosureHandle)));
208 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n",
209 ioc->name, le16_to_cpu(pg0->Slot)));
210 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
211 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
212 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n",
213 ioc->name, pg0->TargetID));
214 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n",
215 ioc->name, pg0->Bus));
216 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n",
217 ioc->name, pg0->PhyNum));
218 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n",
219 ioc->name, le16_to_cpu(pg0->AccessStatus)));
220 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n",
221 ioc->name, le32_to_cpu(pg0->DeviceInfo)));
222 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n",
223 ioc->name, le16_to_cpu(pg0->Flags)));
224 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n",
225 ioc->name, pg0->PhysicalPort));
228 static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1)
230 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
231 "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name));
232 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n",
233 ioc->name, pg1->PhysicalPort));
234 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n",
235 ioc->name, pg1->PhyIdentifier));
236 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
237 ioc->name, pg1->NegotiatedLinkRate));
238 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
239 ioc->name, pg1->ProgrammedLinkRate));
240 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n",
241 ioc->name, pg1->HwLinkRate));
242 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n",
243 ioc->name, le16_to_cpu(pg1->OwnerDevHandle)));
244 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
245 "Attached Device Handle=0x%X\n\n", ioc->name,
246 le16_to_cpu(pg1->AttachedDevHandle)));
249 /* inhibit sas firmware event handling */
251 mptsas_fw_event_off(MPT_ADAPTER *ioc)
255 spin_lock_irqsave(&ioc->fw_event_lock, flags);
256 ioc->fw_events_off = 1;
257 ioc->sas_discovery_quiesce_io = 0;
258 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
262 /* enable sas firmware event handling */
264 mptsas_fw_event_on(MPT_ADAPTER *ioc)
268 spin_lock_irqsave(&ioc->fw_event_lock, flags);
269 ioc->fw_events_off = 0;
270 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
273 /* queue a sas firmware event */
275 mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
280 spin_lock_irqsave(&ioc->fw_event_lock, flags);
281 list_add_tail(&fw_event->list, &ioc->fw_event_list);
282 INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work);
283 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)\n",
284 ioc->name, __func__, fw_event));
285 queue_delayed_work(ioc->fw_event_q, &fw_event->work,
287 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
290 /* free memory assoicated to a sas firmware event */
292 mptsas_free_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event)
296 spin_lock_irqsave(&ioc->fw_event_lock, flags);
297 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: kfree (fw_event=0x%p)\n",
298 ioc->name, __func__, fw_event));
299 list_del(&fw_event->list);
301 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
304 /* walk the firmware event queue, and either stop or wait for
305 * outstanding events to complete */
307 mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc)
309 struct fw_event_work *fw_event, *next;
310 struct mptsas_target_reset_event *target_reset_list, *n;
312 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
314 /* flush the target_reset_list */
315 if (!list_empty(&hd->target_reset_list)) {
316 list_for_each_entry_safe(target_reset_list, n,
317 &hd->target_reset_list, list) {
318 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
319 "%s: removing target reset for id=%d\n",
321 target_reset_list->sas_event_data.TargetID));
322 list_del(&target_reset_list->list);
323 kfree(target_reset_list);
327 if (list_empty(&ioc->fw_event_list) ||
328 !ioc->fw_event_q || in_interrupt())
332 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
333 if (cancel_delayed_work(&fw_event->work))
334 mptsas_free_fw_event(ioc, fw_event);
339 flush_workqueue(ioc->fw_event_q);
343 static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
345 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
346 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
349 static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
351 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
352 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
356 * mptsas_find_portinfo_by_handle
358 * This function should be called with the sas_topology_mutex already held
360 static struct mptsas_portinfo *
361 mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
363 struct mptsas_portinfo *port_info, *rc=NULL;
366 list_for_each_entry(port_info, &ioc->sas_topology, list)
367 for (i = 0; i < port_info->num_phys; i++)
368 if (port_info->phy_info[i].identify.handle == handle) {
377 * mptsas_find_portinfo_by_sas_address -
378 * @ioc: Pointer to MPT_ADAPTER structure
381 * This function should be called with the sas_topology_mutex already held
384 static struct mptsas_portinfo *
385 mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
387 struct mptsas_portinfo *port_info, *rc = NULL;
390 if (sas_address >= ioc->hba_port_sas_addr &&
391 sas_address < (ioc->hba_port_sas_addr +
392 ioc->hba_port_num_phy))
393 return ioc->hba_port_info;
395 mutex_lock(&ioc->sas_topology_mutex);
396 list_for_each_entry(port_info, &ioc->sas_topology, list)
397 for (i = 0; i < port_info->num_phys; i++)
398 if (port_info->phy_info[i].identify.sas_address ==
404 mutex_unlock(&ioc->sas_topology_mutex);
409 * Returns true if there is a scsi end device
412 mptsas_is_end_device(struct mptsas_devinfo * attached)
414 if ((attached->sas_address) &&
415 (attached->device_info &
416 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
417 ((attached->device_info &
418 MPI_SAS_DEVICE_INFO_SSP_TARGET) |
419 (attached->device_info &
420 MPI_SAS_DEVICE_INFO_STP_TARGET) |
421 (attached->device_info &
422 MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
430 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
432 struct mptsas_portinfo *port_info;
433 struct mptsas_phyinfo *phy_info;
439 port_info = port_details->port_info;
440 phy_info = port_info->phy_info;
442 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d "
443 "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
444 port_details->num_phys, (unsigned long long)
445 port_details->phy_bitmask));
447 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
448 if(phy_info->port_details != port_details)
450 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
451 mptsas_set_rphy(ioc, phy_info, NULL);
452 phy_info->port_details = NULL;
457 static inline struct sas_rphy *
458 mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
460 if (phy_info->port_details)
461 return phy_info->port_details->rphy;
467 mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
469 if (phy_info->port_details) {
470 phy_info->port_details->rphy = rphy;
471 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
476 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
477 &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
478 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
479 ioc->name, rphy, rphy->dev.release));
483 static inline struct sas_port *
484 mptsas_get_port(struct mptsas_phyinfo *phy_info)
486 if (phy_info->port_details)
487 return phy_info->port_details->port;
493 mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port)
495 if (phy_info->port_details)
496 phy_info->port_details->port = port;
499 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
500 &port->dev, MYIOC_s_FMT "add:", ioc->name));
501 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n",
502 ioc->name, port, port->dev.release));
506 static inline struct scsi_target *
507 mptsas_get_starget(struct mptsas_phyinfo *phy_info)
509 if (phy_info->port_details)
510 return phy_info->port_details->starget;
516 mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
519 if (phy_info->port_details)
520 phy_info->port_details->starget = starget;
524 * mptsas_add_device_component -
525 * @ioc: Pointer to MPT_ADAPTER structure
526 * @channel: fw mapped id's
533 mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id,
534 u64 sas_address, u32 device_info, u16 slot, u64 enclosure_logical_id)
536 struct mptsas_device_info *sas_info, *next;
537 struct scsi_device *sdev;
538 struct scsi_target *starget;
539 struct sas_rphy *rphy;
542 * Delete all matching devices out of the list
544 mutex_lock(&ioc->sas_device_info_mutex);
545 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
547 if (!sas_info->is_logical_volume &&
548 (sas_info->sas_address == sas_address ||
549 (sas_info->fw.channel == channel &&
550 sas_info->fw.id == id))) {
551 list_del(&sas_info->list);
556 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
561 * Set Firmware mapping
563 sas_info->fw.id = id;
564 sas_info->fw.channel = channel;
566 sas_info->sas_address = sas_address;
567 sas_info->device_info = device_info;
568 sas_info->slot = slot;
569 sas_info->enclosure_logical_id = enclosure_logical_id;
570 INIT_LIST_HEAD(&sas_info->list);
571 list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
576 shost_for_each_device(sdev, ioc->sh) {
577 starget = scsi_target(sdev);
578 rphy = dev_to_rphy(starget->dev.parent);
579 if (rphy->identify.sas_address == sas_address) {
580 sas_info->os.id = starget->id;
581 sas_info->os.channel = starget->channel;
586 mutex_unlock(&ioc->sas_device_info_mutex);
591 * mptsas_add_device_component_by_fw -
592 * @ioc: Pointer to MPT_ADAPTER structure
593 * @channel: fw mapped id's
598 mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id)
600 struct mptsas_devinfo sas_device;
601 struct mptsas_enclosure enclosure_info;
604 rc = mptsas_sas_device_pg0(ioc, &sas_device,
605 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
606 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
607 (channel << 8) + id);
611 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
612 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
613 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
614 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
615 sas_device.handle_enclosure);
617 mptsas_add_device_component(ioc, sas_device.channel,
618 sas_device.id, sas_device.sas_address, sas_device.device_info,
619 sas_device.slot, enclosure_info.enclosure_logical_id);
623 * mptsas_add_device_component_starget_ir - Handle Integrated RAID, adding
624 * each individual device to list
625 * @ioc: Pointer to MPT_ADAPTER structure
626 * @channel: fw mapped id's
631 mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc,
632 struct scsi_target *starget)
635 ConfigPageHeader_t hdr;
636 dma_addr_t dma_handle;
637 pRaidVolumePage0_t buffer = NULL;
639 RaidPhysDiskPage0_t phys_disk;
640 struct mptsas_device_info *sas_info, *next;
642 memset(&cfg, 0 , sizeof(CONFIGPARMS));
643 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
644 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
645 /* assumption that all volumes on channel = 0 */
646 cfg.pageAddr = starget->id;
647 cfg.cfghdr.hdr = &hdr;
648 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
651 if (mpt_config(ioc, &cfg) != 0)
657 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
663 cfg.physAddr = dma_handle;
664 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
666 if (mpt_config(ioc, &cfg) != 0)
669 if (!buffer->NumPhysDisks)
673 * Adding entry for hidden components
675 for (i = 0; i < buffer->NumPhysDisks; i++) {
677 if (mpt_raid_phys_disk_pg0(ioc,
678 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
681 mptsas_add_device_component_by_fw(ioc, phys_disk.PhysDiskBus,
682 phys_disk.PhysDiskID);
684 mutex_lock(&ioc->sas_device_info_mutex);
685 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
687 if (!sas_info->is_logical_volume &&
688 (sas_info->fw.channel == phys_disk.PhysDiskBus &&
689 sas_info->fw.id == phys_disk.PhysDiskID)) {
690 sas_info->is_hidden_raid_component = 1;
691 sas_info->volume_id = starget->id;
694 mutex_unlock(&ioc->sas_device_info_mutex);
699 * Delete all matching devices out of the list
701 mutex_lock(&ioc->sas_device_info_mutex);
702 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
704 if (sas_info->is_logical_volume && sas_info->fw.id ==
706 list_del(&sas_info->list);
711 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
713 sas_info->fw.id = starget->id;
714 sas_info->os.id = starget->id;
715 sas_info->os.channel = starget->channel;
716 sas_info->is_logical_volume = 1;
717 INIT_LIST_HEAD(&sas_info->list);
718 list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
720 mutex_unlock(&ioc->sas_device_info_mutex);
724 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
729 * mptsas_add_device_component_starget -
730 * @ioc: Pointer to MPT_ADAPTER structure
735 mptsas_add_device_component_starget(MPT_ADAPTER *ioc,
736 struct scsi_target *starget)
739 struct sas_rphy *rphy;
740 struct mptsas_phyinfo *phy_info = NULL;
741 struct mptsas_enclosure enclosure_info;
743 rphy = dev_to_rphy(starget->dev.parent);
744 vtarget = starget->hostdata;
745 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
746 rphy->identify.sas_address);
750 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
751 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
752 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
753 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
754 phy_info->attached.handle_enclosure);
756 mptsas_add_device_component(ioc, phy_info->attached.channel,
757 phy_info->attached.id, phy_info->attached.sas_address,
758 phy_info->attached.device_info,
759 phy_info->attached.slot, enclosure_info.enclosure_logical_id);
763 * mptsas_del_device_component_by_os - Once a device has been removed, we
764 * mark the entry in the list as being cached
765 * @ioc: Pointer to MPT_ADAPTER structure
766 * @channel: os mapped id's
771 mptsas_del_device_component_by_os(MPT_ADAPTER *ioc, u8 channel, u8 id)
773 struct mptsas_device_info *sas_info, *next;
778 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
780 if (sas_info->os.channel == channel && sas_info->os.id == id)
781 sas_info->is_cached = 1;
786 * mptsas_del_device_components - Cleaning the list
787 * @ioc: Pointer to MPT_ADAPTER structure
791 mptsas_del_device_components(MPT_ADAPTER *ioc)
793 struct mptsas_device_info *sas_info, *next;
795 mutex_lock(&ioc->sas_device_info_mutex);
796 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
798 list_del(&sas_info->list);
801 mutex_unlock(&ioc->sas_device_info_mutex);
806 * mptsas_setup_wide_ports
808 * Updates for new and existing narrow/wide port configuration
809 * in the sas_topology
812 mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
814 struct mptsas_portinfo_details * port_details;
815 struct mptsas_phyinfo *phy_info, *phy_info_cmp;
819 mutex_lock(&ioc->sas_topology_mutex);
821 phy_info = port_info->phy_info;
822 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
823 if (phy_info->attached.handle)
825 port_details = phy_info->port_details;
828 if (port_details->num_phys < 2)
831 * Removing a phy from a port, letting the last
832 * phy be removed by firmware events.
834 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
835 "%s: [%p]: deleting phy = %d\n",
836 ioc->name, __func__, port_details, i));
837 port_details->num_phys--;
838 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
839 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
840 sas_port_delete_phy(port_details->port, phy_info->phy);
841 phy_info->port_details = NULL;
845 * Populate and refresh the tree
847 phy_info = port_info->phy_info;
848 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
849 sas_address = phy_info->attached.sas_address;
850 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
851 ioc->name, i, (unsigned long long)sas_address));
854 port_details = phy_info->port_details;
859 port_details = kzalloc(sizeof(struct
860 mptsas_portinfo_details), GFP_KERNEL);
863 port_details->num_phys = 1;
864 port_details->port_info = port_info;
865 if (phy_info->phy_id < 64 )
866 port_details->phy_bitmask |=
867 (1 << phy_info->phy_id);
868 phy_info->sas_port_add_phy=1;
869 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
870 "phy_id=%d sas_address=0x%018llX\n",
871 ioc->name, i, (unsigned long long)sas_address));
872 phy_info->port_details = port_details;
875 if (i == port_info->num_phys - 1)
877 phy_info_cmp = &port_info->phy_info[i + 1];
878 for (j = i + 1 ; j < port_info->num_phys ; j++,
880 if (!phy_info_cmp->attached.sas_address)
882 if (sas_address != phy_info_cmp->attached.sas_address)
884 if (phy_info_cmp->port_details == port_details )
886 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
887 "\t\tphy_id=%d sas_address=0x%018llX\n",
888 ioc->name, j, (unsigned long long)
889 phy_info_cmp->attached.sas_address));
890 if (phy_info_cmp->port_details) {
892 mptsas_get_rphy(phy_info_cmp);
894 mptsas_get_port(phy_info_cmp);
895 port_details->starget =
896 mptsas_get_starget(phy_info_cmp);
897 port_details->num_phys =
898 phy_info_cmp->port_details->num_phys;
899 if (!phy_info_cmp->port_details->num_phys)
900 kfree(phy_info_cmp->port_details);
902 phy_info_cmp->sas_port_add_phy=1;
904 * Adding a phy to a port
906 phy_info_cmp->port_details = port_details;
907 if (phy_info_cmp->phy_id < 64 )
908 port_details->phy_bitmask |=
909 (1 << phy_info_cmp->phy_id);
910 port_details->num_phys++;
916 for (i = 0; i < port_info->num_phys; i++) {
917 port_details = port_info->phy_info[i].port_details;
920 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
921 "%s: [%p]: phy_id=%02d num_phys=%02d "
922 "bitmask=0x%016llX\n", ioc->name, __func__,
923 port_details, i, port_details->num_phys,
924 (unsigned long long)port_details->phy_bitmask));
925 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
926 ioc->name, port_details->port, port_details->rphy));
928 dsaswideprintk(ioc, printk("\n"));
929 mutex_unlock(&ioc->sas_topology_mutex);
933 * csmisas_find_vtarget
941 mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
943 struct scsi_device *sdev;
945 VirtTarget *vtarget = NULL;
947 shost_for_each_device(sdev, ioc->sh) {
948 vdevice = sdev->hostdata;
949 if ((vdevice == NULL) ||
950 (vdevice->vtarget == NULL))
952 if ((vdevice->vtarget->tflags &
953 MPT_TARGET_FLAGS_RAID_COMPONENT ||
954 vdevice->vtarget->raidVolume))
956 if (vdevice->vtarget->id == id &&
957 vdevice->vtarget->channel == channel)
958 vtarget = vdevice->vtarget;
964 mptsas_queue_device_delete(MPT_ADAPTER *ioc,
965 MpiEventDataSasDeviceStatusChange_t *sas_event_data)
967 struct fw_event_work *fw_event;
970 sz = offsetof(struct fw_event_work, event_data) +
971 sizeof(MpiEventDataSasDeviceStatusChange_t);
972 fw_event = kzalloc(sz, GFP_ATOMIC);
974 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
975 ioc->name, __func__, __LINE__);
978 memcpy(fw_event->event_data, sas_event_data,
979 sizeof(MpiEventDataSasDeviceStatusChange_t));
980 fw_event->event = MPI_EVENT_SAS_DEVICE_STATUS_CHANGE;
982 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
986 mptsas_queue_rescan(MPT_ADAPTER *ioc)
988 struct fw_event_work *fw_event;
991 sz = offsetof(struct fw_event_work, event_data);
992 fw_event = kzalloc(sz, GFP_ATOMIC);
994 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
995 ioc->name, __func__, __LINE__);
998 fw_event->event = -1;
1000 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
1005 * mptsas_target_reset
1007 * Issues TARGET_RESET to end device using handshaking method
1013 * Returns (1) success
1018 mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
1021 SCSITaskMgmt_t *pScsiTm;
1022 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0)
1026 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
1028 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
1029 "%s, no msg frames @%d!!\n", ioc->name,
1030 __func__, __LINE__));
1034 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
1037 /* Format the Request
1039 pScsiTm = (SCSITaskMgmt_t *) mf;
1040 memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
1041 pScsiTm->TargetID = id;
1042 pScsiTm->Bus = channel;
1043 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
1044 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
1045 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
1047 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
1049 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1050 "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
1051 ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id));
1053 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
1059 mpt_clear_taskmgmt_in_progress_flag(ioc);
1064 * mptsas_target_reset_queue
1066 * Receive request for TARGET_RESET after recieving an firmware
1067 * event NOT_RESPONDING_EVENT, then put command in link list
1068 * and queue if task_queue already in use.
1075 mptsas_target_reset_queue(MPT_ADAPTER *ioc,
1076 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1078 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1079 VirtTarget *vtarget = NULL;
1080 struct mptsas_target_reset_event *target_reset_list;
1083 id = sas_event_data->TargetID;
1084 channel = sas_event_data->Bus;
1086 if (!(vtarget = mptsas_find_vtarget(ioc, channel, id)))
1089 vtarget->deleted = 1; /* block IO */
1091 target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event),
1093 if (!target_reset_list) {
1094 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
1095 "%s, failed to allocate mem @%d..!!\n",
1096 ioc->name, __func__, __LINE__));
1100 memcpy(&target_reset_list->sas_event_data, sas_event_data,
1101 sizeof(*sas_event_data));
1102 list_add_tail(&target_reset_list->list, &hd->target_reset_list);
1104 target_reset_list->time_count = jiffies;
1106 if (mptsas_target_reset(ioc, channel, id)) {
1107 target_reset_list->target_reset_issued = 1;
1112 * mptsas_taskmgmt_complete - Completion for TARGET_RESET after
1113 * NOT_RESPONDING_EVENT, enable work queue to finish off removing device
1114 * from upper layers. then send next TARGET_RESET in the queue.
1115 * @ioc: Pointer to MPT_ADAPTER structure
1119 mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
1121 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1122 struct list_head *head = &hd->target_reset_list;
1124 struct mptsas_target_reset_event *target_reset_list;
1125 SCSITaskMgmtReply_t *pScsiTmReply;
1127 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: "
1128 "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
1130 pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
1132 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1133 "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
1134 "\ttask_type = 0x%02X, iocstatus = 0x%04X "
1135 "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
1136 "term_cmnds = %d\n", ioc->name,
1137 pScsiTmReply->Bus, pScsiTmReply->TargetID,
1138 pScsiTmReply->TaskType,
1139 le16_to_cpu(pScsiTmReply->IOCStatus),
1140 le32_to_cpu(pScsiTmReply->IOCLogInfo),
1141 pScsiTmReply->ResponseCode,
1142 le32_to_cpu(pScsiTmReply->TerminationCount)));
1144 if (pScsiTmReply->ResponseCode)
1145 mptscsih_taskmgmt_response_code(ioc,
1146 pScsiTmReply->ResponseCode);
1149 if (pScsiTmReply && (pScsiTmReply->TaskType ==
1150 MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
1151 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) {
1152 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1153 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
1154 memcpy(ioc->taskmgmt_cmds.reply, mr,
1155 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
1156 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
1157 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
1158 complete(&ioc->taskmgmt_cmds.done);
1164 mpt_clear_taskmgmt_in_progress_flag(ioc);
1166 if (list_empty(head))
1169 target_reset_list = list_entry(head->next,
1170 struct mptsas_target_reset_event, list);
1172 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1173 "TaskMgmt: completed (%d seconds)\n",
1174 ioc->name, jiffies_to_msecs(jiffies -
1175 target_reset_list->time_count)/1000));
1177 id = pScsiTmReply->TargetID;
1178 channel = pScsiTmReply->Bus;
1179 target_reset_list->time_count = jiffies;
1182 * retry target reset
1184 if (!target_reset_list->target_reset_issued) {
1185 if (mptsas_target_reset(ioc, channel, id))
1186 target_reset_list->target_reset_issued = 1;
1191 * enable work queue to remove device from upper layers
1193 list_del(&target_reset_list->list);
1194 if ((mptsas_find_vtarget(ioc, channel, id)) && !ioc->fw_events_off)
1195 mptsas_queue_device_delete(ioc,
1196 &target_reset_list->sas_event_data);
1200 * issue target reset to next device in the queue
1203 head = &hd->target_reset_list;
1204 if (list_empty(head))
1207 target_reset_list = list_entry(head->next, struct mptsas_target_reset_event,
1210 id = target_reset_list->sas_event_data.TargetID;
1211 channel = target_reset_list->sas_event_data.Bus;
1212 target_reset_list->time_count = jiffies;
1214 if (mptsas_target_reset(ioc, channel, id))
1215 target_reset_list->target_reset_issued = 1;
1221 * mptscsih_ioc_reset
1228 mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1233 rc = mptscsih_ioc_reset(ioc, reset_phase);
1234 if ((ioc->bus_type != SAS) || (!rc))
1237 hd = shost_priv(ioc->sh);
1241 switch (reset_phase) {
1242 case MPT_IOC_SETUP_RESET:
1243 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1244 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
1245 mptsas_fw_event_off(ioc);
1247 case MPT_IOC_PRE_RESET:
1248 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1249 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
1251 case MPT_IOC_POST_RESET:
1252 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1253 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
1254 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
1255 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET;
1256 complete(&ioc->sas_mgmt.done);
1258 mptsas_cleanup_fw_event_q(ioc);
1259 mptsas_queue_rescan(ioc);
1260 mptsas_fw_event_on(ioc);
1272 * enum device_state -
1273 * @DEVICE_RETRY: need to retry the TUR
1274 * @DEVICE_ERROR: TUR return error, don't add device
1275 * @DEVICE_READY: device can be added
1285 mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
1286 u32 form, u32 form_specific)
1288 ConfigExtendedPageHeader_t hdr;
1290 SasEnclosurePage0_t *buffer;
1291 dma_addr_t dma_handle;
1293 __le64 le_identifier;
1295 memset(&hdr, 0, sizeof(hdr));
1296 hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
1298 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1299 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
1301 cfg.cfghdr.ehdr = &hdr;
1303 cfg.pageAddr = form + form_specific;
1304 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1305 cfg.dir = 0; /* read */
1308 error = mpt_config(ioc, &cfg);
1311 if (!hdr.ExtPageLength) {
1316 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1323 cfg.physAddr = dma_handle;
1324 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1326 error = mpt_config(ioc, &cfg);
1328 goto out_free_consistent;
1330 /* save config data */
1331 memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
1332 enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
1333 enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
1334 enclosure->flags = le16_to_cpu(buffer->Flags);
1335 enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
1336 enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
1337 enclosure->start_id = buffer->StartTargetID;
1338 enclosure->start_channel = buffer->StartBus;
1339 enclosure->sep_id = buffer->SEPTargetID;
1340 enclosure->sep_channel = buffer->SEPBus;
1342 out_free_consistent:
1343 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1344 buffer, dma_handle);
1350 * mptsas_add_end_device - report a new end device to sas transport layer
1351 * @ioc: Pointer to MPT_ADAPTER structure
1352 * @phy_info: decribes attached device
1354 * return (0) success (1) failure
1358 mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1360 struct sas_rphy *rphy;
1361 struct sas_port *port;
1362 struct sas_identify identify;
1367 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1368 "%s: exit at line=%d\n", ioc->name,
1369 __func__, __LINE__));
1373 fw_id = phy_info->attached.id;
1375 if (mptsas_get_rphy(phy_info)) {
1376 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1377 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1378 __func__, fw_id, __LINE__));
1382 port = mptsas_get_port(phy_info);
1384 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1385 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1386 __func__, fw_id, __LINE__));
1390 if (phy_info->attached.device_info &
1391 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1393 if (phy_info->attached.device_info &
1394 MPI_SAS_DEVICE_INFO_STP_TARGET)
1396 if (phy_info->attached.device_info &
1397 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1400 printk(MYIOC_s_INFO_FMT "attaching %s device: fw_channel %d, fw_id %d,"
1401 " phy %d, sas_addr 0x%llx\n", ioc->name, ds,
1402 phy_info->attached.channel, phy_info->attached.id,
1403 phy_info->attached.phy_id, (unsigned long long)
1404 phy_info->attached.sas_address);
1406 mptsas_parse_device_info(&identify, &phy_info->attached);
1407 rphy = sas_end_device_alloc(port);
1409 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1410 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1411 __func__, fw_id, __LINE__));
1412 return 5; /* non-fatal: an rphy can be added later */
1415 rphy->identify = identify;
1416 if (sas_rphy_add(rphy)) {
1417 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1418 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1419 __func__, fw_id, __LINE__));
1420 sas_rphy_free(rphy);
1423 mptsas_set_rphy(ioc, phy_info, rphy);
1428 * mptsas_del_end_device - report a deleted end device to sas transport
1430 * @ioc: Pointer to MPT_ADAPTER structure
1431 * @phy_info: decribes attached device
1435 mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1437 struct sas_rphy *rphy;
1438 struct sas_port *port;
1439 struct mptsas_portinfo *port_info;
1440 struct mptsas_phyinfo *phy_info_parent;
1449 fw_id = phy_info->attached.id;
1450 sas_address = phy_info->attached.sas_address;
1452 if (!phy_info->port_details) {
1453 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1454 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1455 __func__, fw_id, __LINE__));
1458 rphy = mptsas_get_rphy(phy_info);
1460 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1461 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1462 __func__, fw_id, __LINE__));
1466 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_INITIATOR
1467 || phy_info->attached.device_info
1468 & MPI_SAS_DEVICE_INFO_SMP_INITIATOR
1469 || phy_info->attached.device_info
1470 & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1472 if (phy_info->attached.device_info &
1473 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1475 if (phy_info->attached.device_info &
1476 MPI_SAS_DEVICE_INFO_STP_TARGET)
1478 if (phy_info->attached.device_info &
1479 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1482 dev_printk(KERN_DEBUG, &rphy->dev, MYIOC_s_FMT
1483 "removing %s device: fw_channel %d, fw_id %d, phy %d,"
1484 "sas_addr 0x%llx\n", ioc->name, ds, phy_info->attached.channel,
1485 phy_info->attached.id, phy_info->attached.phy_id,
1486 (unsigned long long) sas_address);
1488 port = mptsas_get_port(phy_info);
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__));
1495 port_info = phy_info->portinfo;
1496 phy_info_parent = port_info->phy_info;
1497 for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) {
1498 if (!phy_info_parent->phy)
1500 if (phy_info_parent->attached.sas_address !=
1503 dev_printk(KERN_DEBUG, &phy_info_parent->phy->dev,
1504 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n",
1505 ioc->name, phy_info_parent->phy_id,
1506 phy_info_parent->phy);
1507 sas_port_delete_phy(port, phy_info_parent->phy);
1510 dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
1511 "delete port %d, sas_addr (0x%llx)\n", ioc->name,
1512 port->port_identifier, (unsigned long long)sas_address);
1513 sas_port_delete(port);
1514 mptsas_set_port(ioc, phy_info, NULL);
1515 mptsas_port_delete(ioc, phy_info->port_details);
1518 struct mptsas_phyinfo *
1519 mptsas_refreshing_device_handles(MPT_ADAPTER *ioc,
1520 struct mptsas_devinfo *sas_device)
1522 struct mptsas_phyinfo *phy_info;
1523 struct mptsas_portinfo *port_info;
1526 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
1527 sas_device->sas_address);
1530 port_info = phy_info->portinfo;
1533 mutex_lock(&ioc->sas_topology_mutex);
1534 for (i = 0; i < port_info->num_phys; i++) {
1535 if (port_info->phy_info[i].attached.sas_address !=
1536 sas_device->sas_address)
1538 port_info->phy_info[i].attached.channel = sas_device->channel;
1539 port_info->phy_info[i].attached.id = sas_device->id;
1540 port_info->phy_info[i].attached.sas_address =
1541 sas_device->sas_address;
1542 port_info->phy_info[i].attached.handle = sas_device->handle;
1543 port_info->phy_info[i].attached.handle_parent =
1544 sas_device->handle_parent;
1545 port_info->phy_info[i].attached.handle_enclosure =
1546 sas_device->handle_enclosure;
1548 mutex_unlock(&ioc->sas_topology_mutex);
1554 * mptsas_firmware_event_work - work thread for processing fw events
1555 * @work: work queue payload containing info describing the event
1560 mptsas_firmware_event_work(struct work_struct *work)
1562 struct fw_event_work *fw_event =
1563 container_of(work, struct fw_event_work, work.work);
1564 MPT_ADAPTER *ioc = fw_event->ioc;
1566 /* special rescan topology handling */
1567 if (fw_event->event == -1) {
1568 if (ioc->in_rescan) {
1569 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1570 "%s: rescan ignored as it is in progress\n",
1571 ioc->name, __func__));
1574 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rescan after "
1575 "reset\n", ioc->name, __func__));
1577 mptsas_not_responding_devices(ioc);
1578 mptsas_scan_sas_topology(ioc);
1580 mptsas_free_fw_event(ioc, fw_event);
1584 /* events handling turned off during host reset */
1585 if (ioc->fw_events_off) {
1586 mptsas_free_fw_event(ioc, fw_event);
1590 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_event=(0x%p), "
1591 "event = (0x%02x)\n", ioc->name, __func__, fw_event,
1592 (fw_event->event & 0xFF)));
1594 switch (fw_event->event) {
1595 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
1596 mptsas_send_sas_event(fw_event);
1598 case MPI_EVENT_INTEGRATED_RAID:
1599 mptsas_send_raid_event(fw_event);
1602 mptsas_send_ir2_event(fw_event);
1604 case MPI_EVENT_PERSISTENT_TABLE_FULL:
1605 mptbase_sas_persist_operation(ioc,
1606 MPI_SAS_OP_CLEAR_NOT_PRESENT);
1607 mptsas_free_fw_event(ioc, fw_event);
1609 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
1610 mptsas_send_expander_event(fw_event);
1612 case MPI_EVENT_SAS_PHY_LINK_STATUS:
1613 mptsas_send_link_status_event(fw_event);
1615 case MPI_EVENT_QUEUE_FULL:
1616 mptsas_handle_queue_full_event(fw_event);
1624 mptsas_slave_configure(struct scsi_device *sdev)
1626 struct Scsi_Host *host = sdev->host;
1627 MPT_SCSI_HOST *hd = shost_priv(host);
1628 MPT_ADAPTER *ioc = hd->ioc;
1629 VirtDevice *vdevice = sdev->hostdata;
1631 if (vdevice->vtarget->deleted) {
1632 sdev_printk(KERN_INFO, sdev, "clearing deleted flag\n");
1633 vdevice->vtarget->deleted = 0;
1637 * RAID volumes placed beyond the last expected port.
1638 * Ignore sending sas mode pages in that case..
1640 if (sdev->channel == MPTSAS_RAID_CHANNEL) {
1641 mptsas_add_device_component_starget_ir(ioc, scsi_target(sdev));
1645 sas_read_port_mode_page(sdev);
1647 mptsas_add_device_component_starget(ioc, scsi_target(sdev));
1650 return mptscsih_slave_configure(sdev);
1654 mptsas_target_alloc(struct scsi_target *starget)
1656 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1657 MPT_SCSI_HOST *hd = shost_priv(host);
1658 VirtTarget *vtarget;
1660 struct sas_rphy *rphy;
1661 struct mptsas_portinfo *p;
1663 MPT_ADAPTER *ioc = hd->ioc;
1665 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
1669 vtarget->starget = starget;
1670 vtarget->ioc_id = ioc->id;
1671 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
1676 * RAID volumes placed beyond the last expected port.
1678 if (starget->channel == MPTSAS_RAID_CHANNEL) {
1679 if (!ioc->raid_data.pIocPg2) {
1683 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1684 if (id == ioc->raid_data.pIocPg2->
1685 RaidVolume[i].VolumeID) {
1686 channel = ioc->raid_data.pIocPg2->
1687 RaidVolume[i].VolumeBus;
1690 vtarget->raidVolume = 1;
1694 rphy = dev_to_rphy(starget->dev.parent);
1695 mutex_lock(&ioc->sas_topology_mutex);
1696 list_for_each_entry(p, &ioc->sas_topology, list) {
1697 for (i = 0; i < p->num_phys; i++) {
1698 if (p->phy_info[i].attached.sas_address !=
1699 rphy->identify.sas_address)
1701 id = p->phy_info[i].attached.id;
1702 channel = p->phy_info[i].attached.channel;
1703 mptsas_set_starget(&p->phy_info[i], starget);
1706 * Exposing hidden raid components
1708 if (mptscsih_is_phys_disk(ioc, channel, id)) {
1709 id = mptscsih_raid_id_to_num(ioc,
1712 MPT_TARGET_FLAGS_RAID_COMPONENT;
1713 p->phy_info[i].attached.phys_disk_num = id;
1715 mutex_unlock(&ioc->sas_topology_mutex);
1719 mutex_unlock(&ioc->sas_topology_mutex);
1726 vtarget->channel = channel;
1727 starget->hostdata = vtarget;
1732 mptsas_target_destroy(struct scsi_target *starget)
1734 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1735 MPT_SCSI_HOST *hd = shost_priv(host);
1736 struct sas_rphy *rphy;
1737 struct mptsas_portinfo *p;
1739 MPT_ADAPTER *ioc = hd->ioc;
1740 VirtTarget *vtarget;
1742 if (!starget->hostdata)
1745 vtarget = starget->hostdata;
1747 mptsas_del_device_component_by_os(ioc, starget->channel,
1751 if (starget->channel == MPTSAS_RAID_CHANNEL)
1754 rphy = dev_to_rphy(starget->dev.parent);
1755 list_for_each_entry(p, &ioc->sas_topology, list) {
1756 for (i = 0; i < p->num_phys; i++) {
1757 if (p->phy_info[i].attached.sas_address !=
1758 rphy->identify.sas_address)
1761 starget_printk(KERN_INFO, starget, MYIOC_s_FMT
1762 "delete device: fw_channel %d, fw_id %d, phy %d, "
1763 "sas_addr 0x%llx\n", ioc->name,
1764 p->phy_info[i].attached.channel,
1765 p->phy_info[i].attached.id,
1766 p->phy_info[i].attached.phy_id, (unsigned long long)
1767 p->phy_info[i].attached.sas_address);
1769 mptsas_set_starget(&p->phy_info[i], NULL);
1774 vtarget->starget = NULL;
1775 kfree(starget->hostdata);
1776 starget->hostdata = NULL;
1781 mptsas_slave_alloc(struct scsi_device *sdev)
1783 struct Scsi_Host *host = sdev->host;
1784 MPT_SCSI_HOST *hd = shost_priv(host);
1785 struct sas_rphy *rphy;
1786 struct mptsas_portinfo *p;
1787 VirtDevice *vdevice;
1788 struct scsi_target *starget;
1790 MPT_ADAPTER *ioc = hd->ioc;
1792 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
1794 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
1795 ioc->name, sizeof(VirtDevice));
1798 starget = scsi_target(sdev);
1799 vdevice->vtarget = starget->hostdata;
1801 if (sdev->channel == MPTSAS_RAID_CHANNEL)
1804 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
1805 mutex_lock(&ioc->sas_topology_mutex);
1806 list_for_each_entry(p, &ioc->sas_topology, list) {
1807 for (i = 0; i < p->num_phys; i++) {
1808 if (p->phy_info[i].attached.sas_address !=
1809 rphy->identify.sas_address)
1811 vdevice->lun = sdev->lun;
1813 * Exposing hidden raid components
1815 if (mptscsih_is_phys_disk(ioc,
1816 p->phy_info[i].attached.channel,
1817 p->phy_info[i].attached.id))
1818 sdev->no_uld_attach = 1;
1819 mutex_unlock(&ioc->sas_topology_mutex);
1823 mutex_unlock(&ioc->sas_topology_mutex);
1829 vdevice->vtarget->num_luns++;
1830 sdev->hostdata = vdevice;
1835 mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1839 VirtDevice *vdevice = SCpnt->device->hostdata;
1841 if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
1842 SCpnt->result = DID_NO_CONNECT << 16;
1847 hd = shost_priv(SCpnt->device->host);
1850 if (ioc->sas_discovery_quiesce_io)
1851 return SCSI_MLQUEUE_HOST_BUSY;
1853 // scsi_print_command(SCpnt);
1855 return mptscsih_qcmd(SCpnt,done);
1859 static struct scsi_host_template mptsas_driver_template = {
1860 .module = THIS_MODULE,
1861 .proc_name = "mptsas",
1862 .proc_info = mptscsih_proc_info,
1863 .name = "MPT SPI Host",
1864 .info = mptscsih_info,
1865 .queuecommand = mptsas_qcmd,
1866 .target_alloc = mptsas_target_alloc,
1867 .slave_alloc = mptsas_slave_alloc,
1868 .slave_configure = mptsas_slave_configure,
1869 .target_destroy = mptsas_target_destroy,
1870 .slave_destroy = mptscsih_slave_destroy,
1871 .change_queue_depth = mptscsih_change_queue_depth,
1872 .eh_abort_handler = mptscsih_abort,
1873 .eh_device_reset_handler = mptscsih_dev_reset,
1874 .eh_bus_reset_handler = mptscsih_bus_reset,
1875 .eh_host_reset_handler = mptscsih_host_reset,
1876 .bios_param = mptscsih_bios_param,
1877 .can_queue = MPT_FC_CAN_QUEUE,
1879 .sg_tablesize = MPT_SCSI_SG_DEPTH,
1880 .max_sectors = 8192,
1882 .use_clustering = ENABLE_CLUSTERING,
1883 .shost_attrs = mptscsih_host_attrs,
1886 static int mptsas_get_linkerrors(struct sas_phy *phy)
1888 MPT_ADAPTER *ioc = phy_to_ioc(phy);
1889 ConfigExtendedPageHeader_t hdr;
1891 SasPhyPage1_t *buffer;
1892 dma_addr_t dma_handle;
1895 /* FIXME: only have link errors on local phys */
1896 if (!scsi_is_sas_phy_local(phy))
1899 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
1900 hdr.ExtPageLength = 0;
1901 hdr.PageNumber = 1 /* page number 1*/;
1904 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1905 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
1907 cfg.cfghdr.ehdr = &hdr;
1909 cfg.pageAddr = phy->identify.phy_identifier;
1910 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1911 cfg.dir = 0; /* read */
1914 error = mpt_config(ioc, &cfg);
1917 if (!hdr.ExtPageLength)
1920 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1925 cfg.physAddr = dma_handle;
1926 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1928 error = mpt_config(ioc, &cfg);
1930 goto out_free_consistent;
1932 mptsas_print_phy_pg1(ioc, buffer);
1934 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
1935 phy->running_disparity_error_count =
1936 le32_to_cpu(buffer->RunningDisparityErrorCount);
1937 phy->loss_of_dword_sync_count =
1938 le32_to_cpu(buffer->LossDwordSynchCount);
1939 phy->phy_reset_problem_count =
1940 le32_to_cpu(buffer->PhyResetProblemCount);
1942 out_free_consistent:
1943 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1944 buffer, dma_handle);
1948 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
1949 MPT_FRAME_HDR *reply)
1951 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1952 if (reply != NULL) {
1953 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID;
1954 memcpy(ioc->sas_mgmt.reply, reply,
1955 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
1958 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
1959 ioc->sas_mgmt.status &= ~MPT_MGMT_STATUS_PENDING;
1960 complete(&ioc->sas_mgmt.done);
1966 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
1968 MPT_ADAPTER *ioc = phy_to_ioc(phy);
1969 SasIoUnitControlRequest_t *req;
1970 SasIoUnitControlReply_t *reply;
1973 unsigned long timeleft;
1974 int error = -ERESTARTSYS;
1976 /* FIXME: fusion doesn't allow non-local phy reset */
1977 if (!scsi_is_sas_phy_local(phy))
1980 /* not implemented for expanders */
1981 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
1984 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
1987 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
1993 hdr = (MPIHeader_t *) mf;
1994 req = (SasIoUnitControlRequest_t *)mf;
1995 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
1996 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
1997 req->MsgContext = hdr->MsgContext;
1998 req->Operation = hard_reset ?
1999 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
2000 req->PhyNum = phy->identify.phy_identifier;
2002 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2003 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2005 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
2008 /* On timeout reset the board */
2009 mpt_free_msg_frame(ioc, mf);
2010 mpt_HardResetHandler(ioc, CAN_SLEEP);
2015 /* a reply frame is expected */
2016 if ((ioc->sas_mgmt.status &
2017 MPT_MGMT_STATUS_RF_VALID) == 0) {
2022 /* process the completed Reply Message Frame */
2023 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
2024 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
2025 printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
2026 ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo);
2034 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2035 mutex_unlock(&ioc->sas_mgmt.mutex);
2041 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
2043 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2045 struct mptsas_portinfo *p;
2046 struct mptsas_enclosure enclosure_info;
2047 u64 enclosure_handle;
2049 mutex_lock(&ioc->sas_topology_mutex);
2050 list_for_each_entry(p, &ioc->sas_topology, list) {
2051 for (i = 0; i < p->num_phys; i++) {
2052 if (p->phy_info[i].attached.sas_address ==
2053 rphy->identify.sas_address) {
2054 enclosure_handle = p->phy_info[i].
2055 attached.handle_enclosure;
2060 mutex_unlock(&ioc->sas_topology_mutex);
2064 mutex_unlock(&ioc->sas_topology_mutex);
2065 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
2066 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
2067 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
2068 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
2070 *identifier = enclosure_info.enclosure_logical_id;
2075 mptsas_get_bay_identifier(struct sas_rphy *rphy)
2077 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2078 struct mptsas_portinfo *p;
2081 mutex_lock(&ioc->sas_topology_mutex);
2082 list_for_each_entry(p, &ioc->sas_topology, list) {
2083 for (i = 0; i < p->num_phys; i++) {
2084 if (p->phy_info[i].attached.sas_address ==
2085 rphy->identify.sas_address) {
2086 rc = p->phy_info[i].attached.slot;
2093 mutex_unlock(&ioc->sas_topology_mutex);
2097 static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
2098 struct request *req)
2100 MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
2102 SmpPassthroughRequest_t *smpreq;
2103 struct request *rsp = req->next_rq;
2106 unsigned long timeleft;
2108 dma_addr_t dma_addr_in = 0;
2109 dma_addr_t dma_addr_out = 0;
2110 u64 sas_address = 0;
2113 printk(MYIOC_s_ERR_FMT "%s: the smp response space is missing\n",
2114 ioc->name, __func__);
2118 /* do we need to support multiple segments? */
2119 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
2120 printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n",
2121 ioc->name, __func__, req->bio->bi_vcnt, req->data_len,
2122 rsp->bio->bi_vcnt, rsp->data_len);
2126 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
2130 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2136 smpreq = (SmpPassthroughRequest_t *)mf;
2137 memset(smpreq, 0, sizeof(*smpreq));
2139 smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4);
2140 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
2143 sas_address = rphy->identify.sas_address;
2145 struct mptsas_portinfo *port_info;
2147 mutex_lock(&ioc->sas_topology_mutex);
2148 port_info = ioc->hba_port_info;
2149 if (port_info && port_info->phy_info)
2151 port_info->phy_info[0].phy->identify.sas_address;
2152 mutex_unlock(&ioc->sas_topology_mutex);
2155 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
2158 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
2161 flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2162 MPI_SGE_FLAGS_END_OF_BUFFER |
2163 MPI_SGE_FLAGS_DIRECTION)
2164 << MPI_SGE_FLAGS_SHIFT;
2165 flagsLength |= (req->data_len - 4);
2167 dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
2168 req->data_len, PCI_DMA_BIDIRECTIONAL);
2171 ioc->add_sge(psge, flagsLength, dma_addr_out);
2172 psge += ioc->SGE_size;
2175 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2176 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2177 MPI_SGE_FLAGS_IOC_TO_HOST |
2178 MPI_SGE_FLAGS_END_OF_BUFFER;
2180 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2181 flagsLength |= rsp->data_len + 4;
2182 dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio),
2183 rsp->data_len, PCI_DMA_BIDIRECTIONAL);
2186 ioc->add_sge(psge, flagsLength, dma_addr_in);
2188 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2189 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2191 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
2193 printk(MYIOC_s_ERR_FMT "%s: smp timeout!\n", ioc->name, __func__);
2194 /* On timeout reset the board */
2195 mpt_HardResetHandler(ioc, CAN_SLEEP);
2201 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
2202 SmpPassthroughReply_t *smprep;
2204 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
2205 memcpy(req->sense, smprep, sizeof(*smprep));
2206 req->sense_len = sizeof(*smprep);
2208 rsp->data_len -= smprep->ResponseDataLength;
2210 printk(MYIOC_s_ERR_FMT
2211 "%s: smp passthru reply failed to be returned\n",
2212 ioc->name, __func__);
2217 pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len,
2218 PCI_DMA_BIDIRECTIONAL);
2220 pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len,
2221 PCI_DMA_BIDIRECTIONAL);
2224 mpt_free_msg_frame(ioc, mf);
2226 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2227 mutex_unlock(&ioc->sas_mgmt.mutex);
2232 static struct sas_function_template mptsas_transport_functions = {
2233 .get_linkerrors = mptsas_get_linkerrors,
2234 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
2235 .get_bay_identifier = mptsas_get_bay_identifier,
2236 .phy_reset = mptsas_phy_reset,
2237 .smp_handler = mptsas_smp_handler,
2240 static struct scsi_transport_template *mptsas_transport_template;
2243 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
2245 ConfigExtendedPageHeader_t hdr;
2247 SasIOUnitPage0_t *buffer;
2248 dma_addr_t dma_handle;
2251 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
2252 hdr.ExtPageLength = 0;
2256 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2257 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2259 cfg.cfghdr.ehdr = &hdr;
2262 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2263 cfg.dir = 0; /* read */
2266 error = mpt_config(ioc, &cfg);
2269 if (!hdr.ExtPageLength) {
2274 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2281 cfg.physAddr = dma_handle;
2282 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2284 error = mpt_config(ioc, &cfg);
2286 goto out_free_consistent;
2288 port_info->num_phys = buffer->NumPhys;
2289 port_info->phy_info = kcalloc(port_info->num_phys,
2290 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
2291 if (!port_info->phy_info) {
2293 goto out_free_consistent;
2296 ioc->nvdata_version_persistent =
2297 le16_to_cpu(buffer->NvdataVersionPersistent);
2298 ioc->nvdata_version_default =
2299 le16_to_cpu(buffer->NvdataVersionDefault);
2301 for (i = 0; i < port_info->num_phys; i++) {
2302 mptsas_print_phy_data(ioc, &buffer->PhyData[i]);
2303 port_info->phy_info[i].phy_id = i;
2304 port_info->phy_info[i].port_id =
2305 buffer->PhyData[i].Port;
2306 port_info->phy_info[i].negotiated_link_rate =
2307 buffer->PhyData[i].NegotiatedLinkRate;
2308 port_info->phy_info[i].portinfo = port_info;
2309 port_info->phy_info[i].handle =
2310 le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
2313 out_free_consistent:
2314 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2315 buffer, dma_handle);
2321 mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
2323 ConfigExtendedPageHeader_t hdr;
2325 SasIOUnitPage1_t *buffer;
2326 dma_addr_t dma_handle;
2328 u16 device_missing_delay;
2330 memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
2331 memset(&cfg, 0, sizeof(CONFIGPARMS));
2333 cfg.cfghdr.ehdr = &hdr;
2334 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2336 cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2337 cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2338 cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION;
2339 cfg.cfghdr.ehdr->PageNumber = 1;
2341 error = mpt_config(ioc, &cfg);
2344 if (!hdr.ExtPageLength) {
2349 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2356 cfg.physAddr = dma_handle;
2357 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2359 error = mpt_config(ioc, &cfg);
2361 goto out_free_consistent;
2363 ioc->io_missing_delay =
2364 le16_to_cpu(buffer->IODeviceMissingDelay);
2365 device_missing_delay = le16_to_cpu(buffer->ReportDeviceMissingDelay);
2366 ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ?
2367 (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 :
2368 device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2370 out_free_consistent:
2371 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2372 buffer, dma_handle);
2378 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2379 u32 form, u32 form_specific)
2381 ConfigExtendedPageHeader_t hdr;
2383 SasPhyPage0_t *buffer;
2384 dma_addr_t dma_handle;
2387 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
2388 hdr.ExtPageLength = 0;
2392 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2393 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
2395 cfg.cfghdr.ehdr = &hdr;
2396 cfg.dir = 0; /* read */
2399 /* Get Phy Pg 0 for each Phy. */
2401 cfg.pageAddr = form + form_specific;
2402 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2404 error = mpt_config(ioc, &cfg);
2408 if (!hdr.ExtPageLength) {
2413 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2420 cfg.physAddr = dma_handle;
2421 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2423 error = mpt_config(ioc, &cfg);
2425 goto out_free_consistent;
2427 mptsas_print_phy_pg0(ioc, buffer);
2429 phy_info->hw_link_rate = buffer->HwLinkRate;
2430 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2431 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2432 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2434 out_free_consistent:
2435 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2436 buffer, dma_handle);
2442 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
2443 u32 form, u32 form_specific)
2445 ConfigExtendedPageHeader_t hdr;
2447 SasDevicePage0_t *buffer;
2448 dma_addr_t dma_handle;
2452 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
2453 hdr.ExtPageLength = 0;
2457 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2458 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
2460 cfg.cfghdr.ehdr = &hdr;
2461 cfg.pageAddr = form + form_specific;
2463 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2464 cfg.dir = 0; /* read */
2467 memset(device_info, 0, sizeof(struct mptsas_devinfo));
2468 error = mpt_config(ioc, &cfg);
2471 if (!hdr.ExtPageLength) {
2476 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2483 cfg.physAddr = dma_handle;
2484 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2486 error = mpt_config(ioc, &cfg);
2488 goto out_free_consistent;
2490 mptsas_print_device_pg0(ioc, buffer);
2492 memset(device_info, 0, sizeof(struct mptsas_devinfo));
2493 device_info->handle = le16_to_cpu(buffer->DevHandle);
2494 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
2495 device_info->handle_enclosure =
2496 le16_to_cpu(buffer->EnclosureHandle);
2497 device_info->slot = le16_to_cpu(buffer->Slot);
2498 device_info->phy_id = buffer->PhyNum;
2499 device_info->port_id = buffer->PhysicalPort;
2500 device_info->id = buffer->TargetID;
2501 device_info->phys_disk_num = ~0;
2502 device_info->channel = buffer->Bus;
2503 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
2504 device_info->sas_address = le64_to_cpu(sas_address);
2505 device_info->device_info =
2506 le32_to_cpu(buffer->DeviceInfo);
2508 out_free_consistent:
2509 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2510 buffer, dma_handle);
2516 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
2517 u32 form, u32 form_specific)
2519 ConfigExtendedPageHeader_t hdr;
2521 SasExpanderPage0_t *buffer;
2522 dma_addr_t dma_handle;
2526 memset(port_info, 0, sizeof(struct mptsas_portinfo));
2527 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
2528 hdr.ExtPageLength = 0;
2532 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2533 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2535 cfg.cfghdr.ehdr = &hdr;
2537 cfg.pageAddr = form + form_specific;
2538 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2539 cfg.dir = 0; /* read */
2542 memset(port_info, 0, sizeof(struct mptsas_portinfo));
2543 error = mpt_config(ioc, &cfg);
2547 if (!hdr.ExtPageLength) {
2552 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2559 cfg.physAddr = dma_handle;
2560 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2562 error = mpt_config(ioc, &cfg);
2564 goto out_free_consistent;
2566 if (!buffer->NumPhys) {
2568 goto out_free_consistent;
2571 /* save config data */
2572 port_info->num_phys = (buffer->NumPhys) ? buffer->NumPhys : 1;
2573 port_info->phy_info = kcalloc(port_info->num_phys,
2574 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
2575 if (!port_info->phy_info) {
2577 goto out_free_consistent;
2580 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
2581 for (i = 0; i < port_info->num_phys; i++) {
2582 port_info->phy_info[i].portinfo = port_info;
2583 port_info->phy_info[i].handle =
2584 le16_to_cpu(buffer->DevHandle);
2585 port_info->phy_info[i].identify.sas_address =
2586 le64_to_cpu(sas_address);
2587 port_info->phy_info[i].identify.handle_parent =
2588 le16_to_cpu(buffer->ParentDevHandle);
2591 out_free_consistent:
2592 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2593 buffer, dma_handle);
2599 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2600 u32 form, u32 form_specific)
2602 ConfigExtendedPageHeader_t hdr;
2604 SasExpanderPage1_t *buffer;
2605 dma_addr_t dma_handle;
2608 hdr.PageVersion = MPI_SASEXPANDER1_PAGEVERSION;
2609 hdr.ExtPageLength = 0;
2613 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2614 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2616 cfg.cfghdr.ehdr = &hdr;
2618 cfg.pageAddr = form + form_specific;
2619 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2620 cfg.dir = 0; /* read */
2623 error = mpt_config(ioc, &cfg);
2627 if (!hdr.ExtPageLength) {
2632 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2639 cfg.physAddr = dma_handle;
2640 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2642 error = mpt_config(ioc, &cfg);
2644 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
2650 goto out_free_consistent;
2653 mptsas_print_expander_pg1(ioc, buffer);
2655 /* save config data */
2656 phy_info->phy_id = buffer->PhyIdentifier;
2657 phy_info->port_id = buffer->PhysicalPort;
2658 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
2659 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2660 phy_info->hw_link_rate = buffer->HwLinkRate;
2661 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2662 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2664 out_free_consistent:
2665 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2666 buffer, dma_handle);
2672 mptsas_parse_device_info(struct sas_identify *identify,
2673 struct mptsas_devinfo *device_info)
2677 identify->sas_address = device_info->sas_address;
2678 identify->phy_identifier = device_info->phy_id;
2681 * Fill in Phy Initiator Port Protocol.
2682 * Bits 6:3, more than one bit can be set, fall through cases.
2684 protocols = device_info->device_info & 0x78;
2685 identify->initiator_port_protocols = 0;
2686 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
2687 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
2688 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
2689 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
2690 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
2691 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
2692 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
2693 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
2696 * Fill in Phy Target Port Protocol.
2697 * Bits 10:7, more than one bit can be set, fall through cases.
2699 protocols = device_info->device_info & 0x780;
2700 identify->target_port_protocols = 0;
2701 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
2702 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
2703 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
2704 identify->target_port_protocols |= SAS_PROTOCOL_STP;
2705 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
2706 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
2707 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
2708 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
2711 * Fill in Attached device type.
2713 switch (device_info->device_info &
2714 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
2715 case MPI_SAS_DEVICE_INFO_NO_DEVICE:
2716 identify->device_type = SAS_PHY_UNUSED;
2718 case MPI_SAS_DEVICE_INFO_END_DEVICE:
2719 identify->device_type = SAS_END_DEVICE;
2721 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
2722 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
2724 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
2725 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
2730 static int mptsas_probe_one_phy(struct device *dev,
2731 struct mptsas_phyinfo *phy_info, int index, int local)
2734 struct sas_phy *phy;
2735 struct sas_port *port;
2743 if (!phy_info->phy) {
2744 phy = sas_phy_alloc(dev, index);
2750 phy = phy_info->phy;
2752 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
2755 * Set Negotiated link rate.
2757 switch (phy_info->negotiated_link_rate) {
2758 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
2759 phy->negotiated_linkrate = SAS_PHY_DISABLED;
2761 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
2762 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
2764 case MPI_SAS_IOUNIT0_RATE_1_5:
2765 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
2767 case MPI_SAS_IOUNIT0_RATE_3_0:
2768 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
2770 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
2771 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
2773 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
2778 * Set Max hardware link rate.
2780 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
2781 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
2782 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
2784 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
2785 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
2792 * Set Max programmed link rate.
2794 switch (phy_info->programmed_link_rate &
2795 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
2796 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
2797 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
2799 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
2800 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
2807 * Set Min hardware link rate.
2809 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
2810 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
2811 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
2813 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
2814 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
2821 * Set Min programmed link rate.
2823 switch (phy_info->programmed_link_rate &
2824 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
2825 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
2826 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
2828 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
2829 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
2835 if (!phy_info->phy) {
2837 error = sas_phy_add(phy);
2842 phy_info->phy = phy;
2845 if (!phy_info->attached.handle ||
2846 !phy_info->port_details)
2849 port = mptsas_get_port(phy_info);
2850 ioc = phy_to_ioc(phy_info->phy);
2852 if (phy_info->sas_port_add_phy) {
2855 port = sas_port_alloc_num(dev);
2860 error = sas_port_add(port);
2862 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2863 "%s: exit at line=%d\n", ioc->name,
2864 __func__, __LINE__));
2867 mptsas_set_port(ioc, phy_info, port);
2868 devtprintk(ioc, dev_printk(KERN_DEBUG, &port->dev,
2869 MYIOC_s_FMT "add port %d, sas_addr (0x%llx)\n",
2870 ioc->name, port->port_identifier,
2871 (unsigned long long)phy_info->
2872 attached.sas_address));
2874 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2875 "sas_port_add_phy: phy_id=%d\n",
2876 ioc->name, phy_info->phy_id));
2877 sas_port_add_phy(port, phy_info->phy);
2878 phy_info->sas_port_add_phy = 0;
2879 devtprintk(ioc, dev_printk(KERN_DEBUG, &phy_info->phy->dev,
2880 MYIOC_s_FMT "add phy %d, phy-obj (0x%p)\n", ioc->name,
2881 phy_info->phy_id, phy_info->phy));
2883 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
2885 struct sas_rphy *rphy;
2886 struct device *parent;
2887 struct sas_identify identify;
2889 parent = dev->parent->parent;
2891 * Let the hotplug_work thread handle processing
2892 * the adding/removing of devices that occur
2893 * after start of day.
2895 if (mptsas_is_end_device(&phy_info->attached) &&
2896 phy_info->attached.handle_parent) {
2900 mptsas_parse_device_info(&identify, &phy_info->attached);
2901 if (scsi_is_host_device(parent)) {
2902 struct mptsas_portinfo *port_info;
2905 port_info = ioc->hba_port_info;
2907 for (i = 0; i < port_info->num_phys; i++)
2908 if (port_info->phy_info[i].identify.sas_address ==
2909 identify.sas_address) {
2910 sas_port_mark_backlink(port);
2914 } else if (scsi_is_sas_rphy(parent)) {
2915 struct sas_rphy *parent_rphy = dev_to_rphy(parent);
2916 if (identify.sas_address ==
2917 parent_rphy->identify.sas_address) {
2918 sas_port_mark_backlink(port);
2923 switch (identify.device_type) {
2924 case SAS_END_DEVICE:
2925 rphy = sas_end_device_alloc(port);
2927 case SAS_EDGE_EXPANDER_DEVICE:
2928 case SAS_FANOUT_EXPANDER_DEVICE:
2929 rphy = sas_expander_alloc(port, identify.device_type);
2936 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2937 "%s: exit at line=%d\n", ioc->name,
2938 __func__, __LINE__));
2942 rphy->identify = identify;
2943 error = sas_rphy_add(rphy);
2945 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2946 "%s: exit at line=%d\n", ioc->name,
2947 __func__, __LINE__));
2948 sas_rphy_free(rphy);
2951 mptsas_set_rphy(ioc, phy_info, rphy);
2959 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
2961 struct mptsas_portinfo *port_info, *hba;
2962 int error = -ENOMEM, i;
2964 hba = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
2968 error = mptsas_sas_io_unit_pg0(ioc, hba);
2970 goto out_free_port_info;
2972 mptsas_sas_io_unit_pg1(ioc);
2973 mutex_lock(&ioc->sas_topology_mutex);
2974 port_info = ioc->hba_port_info;
2976 ioc->hba_port_info = port_info = hba;
2977 ioc->hba_port_num_phy = port_info->num_phys;
2978 list_add_tail(&port_info->list, &ioc->sas_topology);
2980 for (i = 0; i < hba->num_phys; i++) {
2981 port_info->phy_info[i].negotiated_link_rate =
2982 hba->phy_info[i].negotiated_link_rate;
2983 port_info->phy_info[i].handle =
2984 hba->phy_info[i].handle;
2985 port_info->phy_info[i].port_id =
2986 hba->phy_info[i].port_id;
2988 kfree(hba->phy_info);
2992 mutex_unlock(&ioc->sas_topology_mutex);
2993 #if defined(CPQ_CIM)
2994 ioc->num_ports = port_info->num_phys;
2996 for (i = 0; i < port_info->num_phys; i++) {
2997 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
2998 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
2999 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
3000 port_info->phy_info[i].identify.handle =
3001 port_info->phy_info[i].handle;
3002 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
3003 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3004 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3005 port_info->phy_info[i].identify.handle);
3006 if (!ioc->hba_port_sas_addr)
3007 ioc->hba_port_sas_addr =
3008 port_info->phy_info[i].identify.sas_address;
3009 port_info->phy_info[i].identify.phy_id =
3010 port_info->phy_info[i].phy_id = i;
3011 if (port_info->phy_info[i].attached.handle)
3012 mptsas_sas_device_pg0(ioc,
3013 &port_info->phy_info[i].attached,
3014 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3015 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3016 port_info->phy_info[i].attached.handle);
3019 mptsas_setup_wide_ports(ioc, port_info);
3021 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
3022 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
3023 &port_info->phy_info[i], ioc->sas_index, 1);
3034 mptsas_expander_refresh(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
3036 struct mptsas_portinfo *parent;
3037 struct device *parent_dev;
3038 struct sas_rphy *rphy;
3040 u64 sas_address; /* expander sas address */
3043 handle = port_info->phy_info[0].handle;
3044 sas_address = port_info->phy_info[0].identify.sas_address;
3045 for (i = 0; i < port_info->num_phys; i++) {
3046 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
3047 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
3048 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + handle);
3050 mptsas_sas_device_pg0(ioc,
3051 &port_info->phy_info[i].identify,
3052 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3053 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3054 port_info->phy_info[i].identify.handle);
3055 port_info->phy_info[i].identify.phy_id =
3056 port_info->phy_info[i].phy_id;
3058 if (port_info->phy_info[i].attached.handle) {
3059 mptsas_sas_device_pg0(ioc,
3060 &port_info->phy_info[i].attached,
3061 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3062 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3063 port_info->phy_info[i].attached.handle);
3064 port_info->phy_info[i].attached.phy_id =
3065 port_info->phy_info[i].phy_id;
3069 mutex_lock(&ioc->sas_topology_mutex);
3070 parent = mptsas_find_portinfo_by_handle(ioc,
3071 port_info->phy_info[0].identify.handle_parent);
3073 mutex_unlock(&ioc->sas_topology_mutex);
3076 for (i = 0, parent_dev = NULL; i < parent->num_phys && !parent_dev;
3078 if (parent->phy_info[i].attached.sas_address == sas_address) {
3079 rphy = mptsas_get_rphy(&parent->phy_info[i]);
3080 parent_dev = &rphy->dev;
3083 mutex_unlock(&ioc->sas_topology_mutex);
3085 mptsas_setup_wide_ports(ioc, port_info);
3086 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
3087 mptsas_probe_one_phy(parent_dev, &port_info->phy_info[i],
3092 mptsas_expander_event_add(MPT_ADAPTER *ioc,
3093 MpiEventDataSasExpanderStatusChange_t *expander_data)
3095 struct mptsas_portinfo *port_info;
3099 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
3102 port_info->num_phys = (expander_data->NumPhys) ?
3103 expander_data->NumPhys : 1;
3104 port_info->phy_info = kcalloc(port_info->num_phys,
3105 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
3106 if (!port_info->phy_info)
3108 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
3109 for (i = 0; i < port_info->num_phys; i++) {
3110 port_info->phy_info[i].portinfo = port_info;
3111 port_info->phy_info[i].handle =
3112 le16_to_cpu(expander_data->DevHandle);
3113 port_info->phy_info[i].identify.sas_address =
3114 le64_to_cpu(sas_address);
3115 port_info->phy_info[i].identify.handle_parent =
3116 le16_to_cpu(expander_data->ParentDevHandle);
3119 mutex_lock(&ioc->sas_topology_mutex);
3120 list_add_tail(&port_info->list, &ioc->sas_topology);
3121 mutex_unlock(&ioc->sas_topology_mutex);
3123 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3124 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3125 (unsigned long long)sas_address);
3127 mptsas_expander_refresh(ioc, port_info);
3131 * mptsas_delete_expander_siblings - remove siblings attached to expander
3132 * @ioc: Pointer to MPT_ADAPTER structure
3133 * @parent: the parent port_info object
3134 * @expander: the expander port_info object
3137 mptsas_delete_expander_siblings(MPT_ADAPTER *ioc, struct mptsas_portinfo
3138 *parent, struct mptsas_portinfo *expander)
3140 struct mptsas_phyinfo *phy_info;
3141 struct mptsas_portinfo *port_info;
3142 struct sas_rphy *rphy;
3145 phy_info = expander->phy_info;
3146 for (i = 0; i < expander->num_phys; i++, phy_info++) {
3147 rphy = mptsas_get_rphy(phy_info);
3150 if (rphy->identify.device_type == SAS_END_DEVICE)
3151 mptsas_del_end_device(ioc, phy_info);
3154 phy_info = expander->phy_info;
3155 for (i = 0; i < expander->num_phys; i++, phy_info++) {
3156 rphy = mptsas_get_rphy(phy_info);
3159 if (rphy->identify.device_type ==
3160 MPI_SAS_DEVICE_INFO_EDGE_EXPANDER ||
3161 rphy->identify.device_type ==
3162 MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
3163 port_info = mptsas_find_portinfo_by_sas_address(ioc,
3164 rphy->identify.sas_address);
3167 if (port_info == parent) /* backlink rphy */
3170 Delete this expander even if the expdevpage is exists
3171 because the parent expander is already deleted
3173 mptsas_expander_delete(ioc, port_info, 1);
3180 * mptsas_expander_delete - remove this expander
3181 * @ioc: Pointer to MPT_ADAPTER structure
3182 * @port_info: expander port_info struct
3183 * @force: Flag to forcefully delete the expander
3187 static void mptsas_expander_delete(MPT_ADAPTER *ioc,
3188 struct mptsas_portinfo *port_info, u8 force)
3191 struct mptsas_portinfo *parent;
3193 u64 expander_sas_address;
3194 struct mptsas_phyinfo *phy_info;
3195 struct mptsas_portinfo buffer;
3196 struct mptsas_portinfo_details *port_details;
3197 struct sas_port *port;
3202 /* see if expander is still there before deleting */
3203 mptsas_sas_expander_pg0(ioc, &buffer,
3204 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
3205 MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
3206 port_info->phy_info[0].identify.handle);
3208 if (buffer.num_phys) {
3209 kfree(buffer.phy_info);
3216 * Obtain the port_info instance to the parent port
3218 port_details = NULL;
3219 expander_sas_address =
3220 port_info->phy_info[0].identify.sas_address;
3221 parent = mptsas_find_portinfo_by_handle(ioc,
3222 port_info->phy_info[0].identify.handle_parent);
3223 mptsas_delete_expander_siblings(ioc, parent, port_info);
3228 * Delete rphys in the parent that point
3231 phy_info = parent->phy_info;
3233 for (i = 0; i < parent->num_phys; i++, phy_info++) {
3236 if (phy_info->attached.sas_address !=
3237 expander_sas_address)
3240 port = mptsas_get_port(phy_info);
3241 port_details = phy_info->port_details;
3243 dev_printk(KERN_DEBUG, &phy_info->phy->dev,
3244 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", ioc->name,
3245 phy_info->phy_id, phy_info->phy);
3246 sas_port_delete_phy(port, phy_info->phy);
3249 dev_printk(KERN_DEBUG, &port->dev,
3250 MYIOC_s_FMT "delete port %d, sas_addr (0x%llx)\n",
3251 ioc->name, port->port_identifier,
3252 (unsigned long long)expander_sas_address);
3253 sas_port_delete(port);
3254 mptsas_port_delete(ioc, port_details);
3258 printk(MYIOC_s_INFO_FMT "delete expander: num_phys %d, "
3259 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3260 (unsigned long long)expander_sas_address);
3265 list_del(&port_info->list);
3266 kfree(port_info->phy_info);
3272 * mptsas_send_expander_event - expanders events
3273 * @ioc: Pointer to MPT_ADAPTER structure
3274 * @expander_data: event data
3277 * This function handles adding, removing, and refreshing
3278 * device handles within the expander objects.
3281 mptsas_send_expander_event(struct fw_event_work *fw_event)
3284 MpiEventDataSasExpanderStatusChange_t *expander_data;
3285 struct mptsas_portinfo *port_info;
3289 ioc = fw_event->ioc;
3290 expander_data = (MpiEventDataSasExpanderStatusChange_t *)
3291 fw_event->event_data;
3292 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
3293 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3295 if (expander_data->ReasonCode == MPI_EVENT_SAS_EXP_RC_ADDED) {
3297 for (i = 0; i < port_info->num_phys; i++) {
3298 port_info->phy_info[i].portinfo = port_info;
3299 port_info->phy_info[i].handle =
3300 le16_to_cpu(expander_data->DevHandle);
3301 port_info->phy_info[i].identify.sas_address =
3302 le64_to_cpu(sas_address);
3303 port_info->phy_info[i].identify.handle_parent =
3304 le16_to_cpu(expander_data->ParentDevHandle);
3306 mptsas_expander_refresh(ioc, port_info);
3307 } else if (!port_info && expander_data->NumPhys)
3308 mptsas_expander_event_add(ioc, expander_data);
3309 } else if (expander_data->ReasonCode ==
3310 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING)
3311 mptsas_expander_delete(ioc, port_info, 0);
3313 mptsas_free_fw_event(ioc, fw_event);
3318 * mptsas_expander_add -
3319 * @ioc: Pointer to MPT_ADAPTER structure
3323 struct mptsas_portinfo *
3324 mptsas_expander_add(MPT_ADAPTER *ioc, u16 handle)
3326 struct mptsas_portinfo buffer, *port_info;
3329 if ((mptsas_sas_expander_pg0(ioc, &buffer,
3330 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
3331 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)))
3334 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_ATOMIC);
3336 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3337 "%s: exit at line=%d\n", ioc->name,
3338 __func__, __LINE__));
3341 port_info->num_phys = buffer.num_phys;
3342 port_info->phy_info = buffer.phy_info;
3343 for (i = 0; i < port_info->num_phys; i++)
3344 port_info->phy_info[i].portinfo = port_info;
3345 mutex_lock(&ioc->sas_topology_mutex);
3346 list_add_tail(&port_info->list, &ioc->sas_topology);
3347 mutex_unlock(&ioc->sas_topology_mutex);
3348 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3349 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3350 (unsigned long long)buffer.phy_info[0].identify.sas_address);
3351 mptsas_expander_refresh(ioc, port_info);
3356 mptsas_send_link_status_event(struct fw_event_work *fw_event)
3359 MpiEventDataSasPhyLinkStatus_t *link_data;
3360 struct mptsas_portinfo *port_info;
3361 struct mptsas_phyinfo *phy_info = NULL;
3366 ioc = fw_event->ioc;
3367 link_data = (MpiEventDataSasPhyLinkStatus_t *)fw_event->event_data;
3369 memcpy(&sas_address, &link_data->SASAddress, sizeof(__le64));
3370 sas_address = le64_to_cpu(sas_address);
3371 link_rate = link_data->LinkRates >> 4;
3372 phy_num = link_data->PhyNum;
3374 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3376 phy_info = &port_info->phy_info[phy_num];
3378 phy_info->negotiated_link_rate = link_rate;
3381 if (link_rate == MPI_SAS_IOUNIT0_RATE_1_5 ||
3382 link_rate == MPI_SAS_IOUNIT0_RATE_3_0) {
3385 if (ioc->old_sas_discovery_protocal) {
3386 port_info = mptsas_expander_add(ioc,
3387 le16_to_cpu(link_data->DevHandle));
3394 if (port_info == ioc->hba_port_info)
3395 mptsas_probe_hba_phys(ioc);
3397 mptsas_expander_refresh(ioc, port_info);
3398 } else if (phy_info && phy_info->phy) {
3399 if (link_rate == MPI_SAS_IOUNIT0_RATE_PHY_DISABLED)
3400 phy_info->phy->negotiated_linkrate =
3402 else if (link_rate ==
3403 MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION)
3404 phy_info->phy->negotiated_linkrate =
3405 SAS_LINK_RATE_FAILED;
3407 phy_info->phy->negotiated_linkrate =
3408 SAS_LINK_RATE_UNKNOWN;
3411 mptsas_free_fw_event(ioc, fw_event);
3415 mptsas_not_responding_devices(MPT_ADAPTER *ioc)
3417 struct mptsas_portinfo buffer, *port_info;
3418 struct mptsas_device_info *sas_info;
3419 struct mptsas_devinfo sas_device;
3421 VirtTarget *vtarget = NULL;
3422 struct mptsas_phyinfo *phy_info;
3424 int retval, retry_count;
3425 unsigned long flags;
3427 mpt_findImVolumes(ioc);
3429 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
3430 if (ioc->ioc_reset_in_progress) {
3431 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3432 "%s: exiting due to a parallel reset \n", ioc->name,
3434 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3437 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3439 /* devices, logical volumes */
3440 mutex_lock(&ioc->sas_device_info_mutex);
3442 list_for_each_entry(sas_info, &ioc->sas_device_info_list, list) {
3443 if (sas_info->is_cached)
3445 if (!sas_info->is_logical_volume) {
3446 sas_device.handle = 0;
3449 retval = mptsas_sas_device_pg0(ioc, &sas_device,
3450 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID
3451 << MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3452 (sas_info->fw.channel << 8) +
3455 if (sas_device.handle)
3457 if (retval == -EBUSY) {
3458 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
3459 if (ioc->ioc_reset_in_progress) {
3461 printk(MYIOC_s_DEBUG_FMT
3462 "%s: exiting due to reset\n",
3463 ioc->name, __func__));
3464 spin_unlock_irqrestore
3465 (&ioc->taskmgmt_lock, flags);
3467 sas_device_info_mutex);
3470 spin_unlock_irqrestore(&ioc->taskmgmt_lock,
3474 if (retval && (retval != -ENODEV)) {
3475 if (retry_count < 10) {
3479 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3480 "%s: Config page retry exceeded retry "
3481 "count deleting device 0x%llx\n",
3482 ioc->name, __func__,
3483 sas_info->sas_address));
3488 vtarget = mptsas_find_vtarget(ioc,
3489 sas_info->fw.channel, sas_info->fw.id);
3492 vtarget->deleted = 1;
3494 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3495 sas_info->sas_address);
3498 mptsas_del_end_device(ioc, phy_info);
3499 goto redo_device_scan;
3502 mptsas_volume_delete(ioc, sas_info->fw.id);
3504 mutex_lock(&ioc->sas_device_info_mutex);
3507 mutex_lock(&ioc->sas_topology_mutex);
3509 list_for_each_entry(port_info, &ioc->sas_topology, list) {
3511 if (port_info->phy_info &&
3512 (!(port_info->phy_info[0].identify.device_info &
3513 MPI_SAS_DEVICE_INFO_SMP_TARGET)))
3517 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3518 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
3519 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle) &&
3522 handle = buffer.phy_info[0].handle;
3523 if (buffer.phy_info[0].identify.sas_address ==
3524 port_info->phy_info[0].identify.sas_address) {
3527 kfree(buffer.phy_info);
3530 if (!found_expander) {
3531 mptsas_expander_delete(ioc, port_info, 0);
3532 goto redo_expander_scan;
3535 mutex_lock(&ioc->sas_topology_mutex);
3539 * mptsas_probe_expanders - adding expanders
3540 * @ioc: Pointer to MPT_ADAPTER structure
3544 mptsas_probe_expanders(MPT_ADAPTER *ioc)
3546 struct mptsas_portinfo buffer, *port_info;
3551 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3552 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
3553 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)) {
3555 handle = buffer.phy_info[0].handle;
3556 port_info = mptsas_find_portinfo_by_sas_address(ioc,
3557 buffer.phy_info[0].identify.sas_address);
3560 /* refreshing handles */
3561 for (i = 0; i < buffer.num_phys; i++) {
3562 port_info->phy_info[i].handle = handle;
3563 port_info->phy_info[i].identify.handle_parent =
3564 buffer.phy_info[0].identify.handle_parent;
3566 mptsas_expander_refresh(ioc, port_info);
3567 kfree(buffer.phy_info);
3571 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
3573 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3574 "%s: exit at line=%d\n", ioc->name,
3575 __func__, __LINE__));
3578 port_info->num_phys = buffer.num_phys;
3579 port_info->phy_info = buffer.phy_info;
3580 for (i = 0; i < port_info->num_phys; i++)
3581 port_info->phy_info[i].portinfo = port_info;
3582 mutex_lock(&ioc->sas_topology_mutex);
3583 list_add_tail(&port_info->list, &ioc->sas_topology);
3584 mutex_unlock(&ioc->sas_topology_mutex);
3585 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3586 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3587 (unsigned long long)buffer.phy_info[0].identify.sas_address);
3588 mptsas_expander_refresh(ioc, port_info);
3593 mptsas_probe_devices(MPT_ADAPTER *ioc)
3596 struct mptsas_devinfo sas_device;
3597 struct mptsas_phyinfo *phy_info;
3600 while (!(mptsas_sas_device_pg0(ioc, &sas_device,
3601 MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
3603 handle = sas_device.handle;
3605 if ((sas_device.device_info &
3606 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
3607 MPI_SAS_DEVICE_INFO_STP_TARGET |
3608 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0)
3611 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
3615 if (mptsas_get_rphy(phy_info))
3618 mptsas_add_end_device(ioc, phy_info);
3623 * mptsas_scan_sas_topology -
3624 * @ioc: Pointer to MPT_ADAPTER structure
3629 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
3631 struct scsi_device *sdev;
3634 mptsas_probe_hba_phys(ioc);
3635 mptsas_probe_expanders(ioc);
3636 mptsas_probe_devices(ioc);
3639 Reporting RAID volumes.
3641 if (!ioc->ir_firmware || !ioc->raid_data.pIocPg2 ||
3642 !ioc->raid_data.pIocPg2->NumActiveVolumes)
3644 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
3645 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
3646 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
3648 scsi_device_put(sdev);
3651 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
3652 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
3653 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID);
3654 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
3655 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
3661 mptsas_handle_queue_full_event(struct fw_event_work *fw_event)
3664 EventDataQueueFull_t *qfull_data;
3665 struct mptsas_device_info *sas_info;
3666 struct scsi_device *sdev;
3670 int fw_id, fw_channel;
3674 ioc = fw_event->ioc;
3675 qfull_data = (EventDataQueueFull_t *)fw_event->event_data;
3676 fw_id = qfull_data->TargetID;
3677 fw_channel = qfull_data->Bus;
3678 current_depth = le16_to_cpu(qfull_data->CurrentDepth);
3680 /* if hidden raid component, look for the volume id */
3681 mutex_lock(&ioc->sas_device_info_mutex);
3682 if (mptscsih_is_phys_disk(ioc, fw_channel, fw_id)) {
3683 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
3685 if (sas_info->is_cached ||
3686 sas_info->is_logical_volume)
3688 if (sas_info->is_hidden_raid_component &&
3689 (sas_info->fw.channel == fw_channel &&
3690 sas_info->fw.id == fw_id)) {
3691 id = sas_info->volume_id;
3692 channel = MPTSAS_RAID_CHANNEL;
3697 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
3699 if (sas_info->is_cached ||
3700 sas_info->is_hidden_raid_component ||
3701 sas_info->is_logical_volume)
3703 if (sas_info->fw.channel == fw_channel &&
3704 sas_info->fw.id == fw_id) {
3705 id = sas_info->os.id;
3706 channel = sas_info->os.channel;
3714 mutex_unlock(&ioc->sas_device_info_mutex);
3717 shost_for_each_device(sdev, ioc->sh) {
3718 if (sdev->id == id && sdev->channel == channel) {
3719 if (current_depth > sdev->queue_depth) {
3720 sdev_printk(KERN_INFO, sdev,
3721 "strange observation, the queue "
3722 "depth is (%d) meanwhile fw queue "
3723 "depth (%d)\n", sdev->queue_depth,
3727 depth = scsi_track_queue_full(sdev,
3730 sdev_printk(KERN_INFO, sdev,
3731 "Queue depth reduced to (%d)\n",
3734 sdev_printk(KERN_INFO, sdev,
3735 "Tagged Command Queueing is being "
3737 else if (depth == 0)
3738 sdev_printk(KERN_INFO, sdev,
3739 "Queue depth not changed yet\n");
3744 mptsas_free_fw_event(ioc, fw_event);
3748 static struct mptsas_phyinfo *
3749 mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
3751 struct mptsas_portinfo *port_info;
3752 struct mptsas_phyinfo *phy_info = NULL;
3755 mutex_lock(&ioc->sas_topology_mutex);
3756 list_for_each_entry(port_info, &ioc->sas_topology, list) {
3757 for (i = 0; i < port_info->num_phys; i++) {
3758 if (!mptsas_is_end_device(
3759 &port_info->phy_info[i].attached))
3761 if (port_info->phy_info[i].attached.sas_address
3764 phy_info = &port_info->phy_info[i];
3768 mutex_unlock(&ioc->sas_topology_mutex);
3773 * mptsas_find_phyinfo_by_phys_disk_num -
3774 * @ioc: Pointer to MPT_ADAPTER structure
3780 static struct mptsas_phyinfo *
3781 mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num,
3784 struct mptsas_phyinfo *phy_info = NULL;
3785 struct mptsas_portinfo *port_info;
3786 RaidPhysDiskPage1_t *phys_disk = NULL;
3788 u64 sas_address = 0;
3792 if (!ioc->raid_data.pIocPg3)
3794 /* dual port support */
3795 num_paths = mpt_raid_phys_disk_get_num_paths(ioc, phys_disk_num);
3798 phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
3799 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
3802 mpt_raid_phys_disk_pg1(ioc, phys_disk_num, phys_disk);
3803 for (i = 0; i < num_paths; i++) {
3804 if ((phys_disk->Path[i].Flags & 1) != 0)
3805 /* entry no longer valid */
3807 if ((id == phys_disk->Path[i].PhysDiskID) &&
3808 (channel == phys_disk->Path[i].PhysDiskBus)) {
3809 memcpy(&sas_address, &phys_disk->Path[i].WWID,
3811 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3823 * Extra code to handle RAID0 case, where the sas_address is not updated
3824 * in phys_disk_page_1 when hotswapped
3826 mutex_lock(&ioc->sas_topology_mutex);
3827 list_for_each_entry(port_info, &ioc->sas_topology, list) {
3828 for (i = 0; i < port_info->num_phys && !phy_info; i++) {
3829 if (!mptsas_is_end_device(
3830 &port_info->phy_info[i].attached))
3832 if (port_info->phy_info[i].attached.phys_disk_num == ~0)
3834 if ((port_info->phy_info[i].attached.phys_disk_num ==
3836 (port_info->phy_info[i].attached.id == id) &&
3837 (port_info->phy_info[i].attached.channel ==
3839 phy_info = &port_info->phy_info[i];
3842 mutex_unlock(&ioc->sas_topology_mutex);
3847 mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
3851 sdev->no_uld_attach = data ? 1 : 0;
3852 rc = scsi_device_reprobe(sdev);
3856 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
3858 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
3859 mptsas_reprobe_lun);
3863 mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
3866 ConfigPageHeader_t hdr;
3867 dma_addr_t dma_handle;
3868 pRaidVolumePage0_t buffer = NULL;
3869 RaidPhysDiskPage0_t phys_disk;
3871 struct mptsas_phyinfo *phy_info;
3872 struct mptsas_devinfo sas_device;
3874 memset(&cfg, 0 , sizeof(CONFIGPARMS));
3875 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
3876 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
3877 cfg.pageAddr = (channel << 8) + id;
3878 cfg.cfghdr.hdr = &hdr;
3879 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3881 if (mpt_config(ioc, &cfg) != 0)
3884 if (!hdr.PageLength)
3887 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
3893 cfg.physAddr = dma_handle;
3894 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
3896 if (mpt_config(ioc, &cfg) != 0)
3899 if (!(buffer->VolumeStatus.Flags &
3900 MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
3903 if (!buffer->NumPhysDisks)
3906 for (i = 0; i < buffer->NumPhysDisks; i++) {
3908 if (mpt_raid_phys_disk_pg0(ioc,
3909 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
3912 if (mptsas_sas_device_pg0(ioc, &sas_device,
3913 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
3914 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3915 (phys_disk.PhysDiskBus << 8) +
3916 phys_disk.PhysDiskID))
3919 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3920 sas_device.sas_address);
3921 mptsas_add_end_device(ioc, phy_info);
3926 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
3930 * Work queue thread to handle SAS hotplug events
3933 mptsas_hotplug_work(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
3934 struct mptsas_hotplug_event *hot_plug_info)
3936 struct mptsas_phyinfo *phy_info;
3937 struct scsi_target * starget;
3938 struct mptsas_devinfo sas_device;
3939 VirtTarget *vtarget;
3942 switch (hot_plug_info->event_type) {
3944 case MPTSAS_ADD_PHYSDISK:
3946 if (!ioc->raid_data.pIocPg2)
3949 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
3950 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID ==
3951 hot_plug_info->id) {
3952 printk(MYIOC_s_WARN_FMT "firmware bug: unable "
3953 "to add hidden disk - target_id matchs "
3954 "volume_id\n", ioc->name);
3955 mptsas_free_fw_event(ioc, fw_event);
3959 mpt_findImVolumes(ioc);
3961 case MPTSAS_ADD_DEVICE:
3962 memset(&sas_device, 0, sizeof(struct mptsas_devinfo));
3963 mptsas_sas_device_pg0(ioc, &sas_device,
3964 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
3965 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3966 (hot_plug_info->channel << 8) +
3969 if (!sas_device.handle)
3972 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
3976 if (mptsas_get_rphy(phy_info))
3979 mptsas_add_end_device(ioc, phy_info);
3982 case MPTSAS_DEL_DEVICE:
3983 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3984 hot_plug_info->sas_address);
3985 mptsas_del_end_device(ioc, phy_info);
3988 case MPTSAS_DEL_PHYSDISK:
3990 mpt_findImVolumes(ioc);
3992 phy_info = mptsas_find_phyinfo_by_phys_disk_num(
3993 ioc, hot_plug_info->phys_disk_num,
3994 hot_plug_info->channel,
3996 mptsas_del_end_device(ioc, phy_info);
3999 case MPTSAS_ADD_PHYSDISK_REPROBE:
4001 if (mptsas_sas_device_pg0(ioc, &sas_device,
4002 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4003 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4004 (hot_plug_info->channel << 8) + hot_plug_info->id)) {
4005 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4006 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4007 __func__, hot_plug_info->id, __LINE__));
4011 phy_info = mptsas_find_phyinfo_by_sas_address(
4012 ioc, sas_device.sas_address);
4015 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4016 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4017 __func__, hot_plug_info->id, __LINE__));
4021 starget = mptsas_get_starget(phy_info);
4023 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4024 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4025 __func__, hot_plug_info->id, __LINE__));
4029 vtarget = starget->hostdata;
4031 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4032 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4033 __func__, hot_plug_info->id, __LINE__));
4037 mpt_findImVolumes(ioc);
4039 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Hidding: "
4040 "fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
4041 ioc->name, hot_plug_info->channel, hot_plug_info->id,
4042 hot_plug_info->phys_disk_num, (unsigned long long)
4043 sas_device.sas_address);
4045 vtarget->id = hot_plug_info->phys_disk_num;
4046 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
4047 phy_info->attached.phys_disk_num = hot_plug_info->phys_disk_num;
4048 mptsas_reprobe_target(starget, 1);
4051 case MPTSAS_DEL_PHYSDISK_REPROBE:
4053 if (mptsas_sas_device_pg0(ioc, &sas_device,
4054 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4055 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4056 (hot_plug_info->channel << 8) + hot_plug_info->id)) {
4057 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4058 "%s: fw_id=%d exit at line=%d\n",
4059 ioc->name, __func__,
4060 hot_plug_info->id, __LINE__));
4064 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4065 sas_device.sas_address);
4067 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4068 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4069 __func__, hot_plug_info->id, __LINE__));
4073 starget = mptsas_get_starget(phy_info);
4075 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4076 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4077 __func__, hot_plug_info->id, __LINE__));
4081 vtarget = starget->hostdata;
4083 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4084 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4085 __func__, hot_plug_info->id, __LINE__));
4089 if (!(vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)) {
4090 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4091 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4092 __func__, hot_plug_info->id, __LINE__));
4096 mpt_findImVolumes(ioc);
4098 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Exposing:"
4099 " fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
4100 ioc->name, hot_plug_info->channel, hot_plug_info->id,
4101 hot_plug_info->phys_disk_num, (unsigned long long)
4102 sas_device.sas_address);
4104 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
4105 vtarget->id = hot_plug_info->id;
4106 phy_info->attached.phys_disk_num = ~0;
4107 mptsas_reprobe_target(starget, 0);
4108 mptsas_add_device_component_by_fw(ioc,
4109 hot_plug_info->channel, hot_plug_info->id);
4112 case MPTSAS_ADD_RAID:
4114 mpt_findImVolumes(ioc);
4115 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
4116 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
4118 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
4119 hot_plug_info->id, 0);
4122 case MPTSAS_DEL_RAID:
4124 mpt_findImVolumes(ioc);
4125 printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
4126 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
4128 scsi_remove_device(hot_plug_info->sdev);
4129 scsi_device_put(hot_plug_info->sdev);
4132 case MPTSAS_ADD_INACTIVE_VOLUME:
4134 mpt_findImVolumes(ioc);
4135 mptsas_adding_inactive_raid_components(ioc,
4136 hot_plug_info->channel, hot_plug_info->id);
4143 mptsas_free_fw_event(ioc, fw_event);
4147 mptsas_send_sas_event(struct fw_event_work *fw_event)
4150 struct mptsas_hotplug_event hot_plug_info;
4151 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
4155 ioc = fw_event->ioc;
4156 sas_event_data = (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)
4157 fw_event->event_data;
4158 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
4161 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
4162 MPI_SAS_DEVICE_INFO_STP_TARGET |
4163 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) {
4164 mptsas_free_fw_event(ioc, fw_event);
4168 if (sas_event_data->ReasonCode ==
4169 MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED) {
4170 mptbase_sas_persist_operation(ioc,
4171 MPI_SAS_OP_CLEAR_NOT_PRESENT);
4172 mptsas_free_fw_event(ioc, fw_event);
4176 switch (sas_event_data->ReasonCode) {
4177 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
4178 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
4179 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4180 hot_plug_info.handle = le16_to_cpu(sas_event_data->DevHandle);
4181 hot_plug_info.channel = sas_event_data->Bus;
4182 hot_plug_info.id = sas_event_data->TargetID;
4183 hot_plug_info.phy_id = sas_event_data->PhyNum;
4184 memcpy(&sas_address, &sas_event_data->SASAddress,
4186 hot_plug_info.sas_address = le64_to_cpu(sas_address);
4187 hot_plug_info.device_info = device_info;
4188 if (sas_event_data->ReasonCode &
4189 MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
4190 hot_plug_info.event_type = MPTSAS_ADD_DEVICE;
4192 hot_plug_info.event_type = MPTSAS_DEL_DEVICE;
4193 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4196 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
4197 mptbase_sas_persist_operation(ioc,
4198 MPI_SAS_OP_CLEAR_NOT_PRESENT);
4199 mptsas_free_fw_event(ioc, fw_event);
4202 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
4204 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
4207 mptsas_free_fw_event(ioc, fw_event);
4213 mptsas_send_raid_event(struct fw_event_work *fw_event)
4216 EVENT_DATA_RAID *raid_event_data;
4217 struct mptsas_hotplug_event hot_plug_info;
4220 struct scsi_device *sdev = NULL;
4221 VirtDevice *vdevice = NULL;
4222 RaidPhysDiskPage0_t phys_disk;
4224 ioc = fw_event->ioc;
4225 raid_event_data = (EVENT_DATA_RAID *)fw_event->event_data;
4226 status = le32_to_cpu(raid_event_data->SettingsStatus);
4227 state = (status >> 8) & 0xff;
4229 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4230 hot_plug_info.id = raid_event_data->VolumeID;
4231 hot_plug_info.channel = raid_event_data->VolumeBus;
4232 hot_plug_info.phys_disk_num = raid_event_data->PhysDiskNum;
4234 if (raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_DELETED ||
4235 raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_CREATED ||
4236 raid_event_data->ReasonCode ==
4237 MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED) {
4238 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
4239 hot_plug_info.id, 0);
4240 hot_plug_info.sdev = sdev;
4242 vdevice = sdev->hostdata;
4245 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
4246 "ReasonCode=%02x\n", ioc->name, __func__,
4247 raid_event_data->ReasonCode));
4249 switch (raid_event_data->ReasonCode) {
4250 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
4251 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK_REPROBE;
4253 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
4254 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK_REPROBE;
4256 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
4258 case MPI_PD_STATE_ONLINE:
4259 case MPI_PD_STATE_NOT_COMPATIBLE:
4260 mpt_raid_phys_disk_pg0(ioc,
4261 raid_event_data->PhysDiskNum, &phys_disk);
4262 hot_plug_info.id = phys_disk.PhysDiskID;
4263 hot_plug_info.channel = phys_disk.PhysDiskBus;
4264 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
4266 case MPI_PD_STATE_FAILED:
4267 case MPI_PD_STATE_MISSING:
4268 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
4269 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
4270 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
4271 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
4277 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
4280 vdevice->vtarget->deleted = 1; /* block IO */
4281 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4283 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
4285 scsi_device_put(sdev);
4288 hot_plug_info.event_type = MPTSAS_ADD_RAID;
4290 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
4291 if (!(status & MPI_RAIDVOL0_STATUS_FLAG_ENABLED)) {
4294 vdevice->vtarget->deleted = 1; /* block IO */
4295 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4299 case MPI_RAIDVOL0_STATUS_STATE_FAILED:
4300 case MPI_RAIDVOL0_STATUS_STATE_MISSING:
4303 vdevice->vtarget->deleted = 1; /* block IO */
4304 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4306 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
4307 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
4309 scsi_device_put(sdev);
4312 hot_plug_info.event_type = MPTSAS_ADD_RAID;
4322 if (hot_plug_info.event_type != MPTSAS_IGNORE_EVENT)
4323 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4325 mptsas_free_fw_event(ioc, fw_event);
4329 * mptsas_send_ir2_event - handle exposing hidden disk when
4330 * an inactive raid volume is added
4332 * @ioc: Pointer to MPT_ADAPTER structure
4337 mptsas_send_ir2_event(struct fw_event_work *fw_event)
4340 struct mptsas_hotplug_event hot_plug_info;
4341 MPI_EVENT_DATA_IR2 *ir2_data;
4343 RaidPhysDiskPage0_t phys_disk;
4345 ioc = fw_event->ioc;
4346 ir2_data = (MPI_EVENT_DATA_IR2 *)fw_event->event_data;
4347 reasonCode = ir2_data->ReasonCode;
4349 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
4350 "ReasonCode=%02x\n", ioc->name, __func__, reasonCode));
4352 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4353 hot_plug_info.id = ir2_data->TargetID;
4354 hot_plug_info.channel = ir2_data->Bus;
4355 switch (reasonCode) {
4356 case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
4357 hot_plug_info.event_type = MPTSAS_ADD_INACTIVE_VOLUME;
4359 case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED:
4360 hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum;
4361 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
4363 case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED:
4364 hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum;
4365 mpt_raid_phys_disk_pg0(ioc,
4366 ir2_data->PhysDiskNum, &phys_disk);
4367 hot_plug_info.id = phys_disk.PhysDiskID;
4368 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
4371 mptsas_free_fw_event(ioc, fw_event);
4374 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4378 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
4380 u32 event = le32_to_cpu(reply->Event);
4381 int sz, event_data_sz;
4382 struct fw_event_work *fw_event;
4383 unsigned long delay;
4385 /* events turned off due to host reset or driver unloading */
4386 if (ioc->fw_events_off)
4389 delay = msecs_to_jiffies(1);
4391 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
4393 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data =
4394 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data;
4396 if (sas_event_data->ReasonCode ==
4397 MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING) {
4398 mptsas_target_reset_queue(ioc, sas_event_data);
4403 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
4405 MpiEventDataSasExpanderStatusChange_t *expander_data =
4406 (MpiEventDataSasExpanderStatusChange_t *)reply->Data;
4408 if (ioc->old_sas_discovery_protocal)
4411 if (expander_data->ReasonCode ==
4412 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING &&
4413 ioc->device_missing_delay)
4414 delay = HZ * ioc->device_missing_delay;
4417 case MPI_EVENT_SAS_DISCOVERY:
4419 u32 discovery_status;
4420 EventDataSasDiscovery_t *discovery_data =
4421 (EventDataSasDiscovery_t *)reply->Data;
4423 discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus);
4424 ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0;
4425 if (ioc->old_sas_discovery_protocal && !discovery_status)
4426 mptsas_queue_rescan(ioc);
4429 case MPI_EVENT_INTEGRATED_RAID:
4430 case MPI_EVENT_PERSISTENT_TABLE_FULL:
4432 case MPI_EVENT_SAS_PHY_LINK_STATUS:
4433 case MPI_EVENT_QUEUE_FULL:
4439 event_data_sz = ((reply->MsgLength * 4) -
4440 offsetof(EventNotificationReply_t, Data));
4441 sz = offsetof(struct fw_event_work, event_data) + event_data_sz;
4442 fw_event = kzalloc(sz, GFP_ATOMIC);
4444 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", ioc->name,
4445 __func__, __LINE__);
4448 memcpy(fw_event->event_data, reply->Data, event_data_sz);
4449 fw_event->event = event;
4450 fw_event->ioc = ioc;
4451 mptsas_add_fw_event(ioc, fw_event, delay);
4455 /* Delete a volume when no longer listed in ioc pg2
4457 static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id)
4459 struct scsi_device *sdev;
4462 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, id, 0);
4465 if (!ioc->raid_data.pIocPg2)
4467 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
4469 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
4470 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id)
4473 printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
4474 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, id);
4475 scsi_remove_device(sdev);
4477 scsi_device_put(sdev);
4481 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
4483 struct Scsi_Host *sh;
4486 unsigned long flags;
4494 r = mpt_attach(pdev,id);
4498 ioc = pci_get_drvdata(pdev);
4499 mptsas_fw_event_off(ioc);
4500 ioc->DoneCtx = mptsasDoneCtx;
4501 ioc->TaskCtx = mptsasTaskCtx;
4502 ioc->InternalCtx = mptsasInternalCtx;
4504 /* Added sanity check on readiness of the MPT adapter.
4506 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
4507 printk(MYIOC_s_WARN_FMT
4508 "Skipping because it's not operational!\n",
4511 goto out_mptsas_probe;
4515 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
4518 goto out_mptsas_probe;
4521 /* Sanity check - ensure at least 1 port is INITIATOR capable
4524 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
4525 if (ioc->pfacts[ii].ProtocolFlags &
4526 MPI_PORTFACTS_PROTOCOL_INITIATOR)
4531 printk(MYIOC_s_WARN_FMT
4532 "Skipping ioc=%p because SCSI Initiator mode "
4533 "is NOT enabled!\n", ioc->name, ioc);
4537 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
4539 printk(MYIOC_s_WARN_FMT
4540 "Unable to register controller with SCSI subsystem\n",
4543 goto out_mptsas_probe;
4546 spin_lock_irqsave(&ioc->FreeQlock, flags);
4548 /* Attach the SCSI Host to the IOC structure
4556 /* set 16 byte cdb's */
4557 sh->max_cmd_len = 16;
4559 sh->max_id = ioc->pfacts[0].PortSCSIID;
4560 sh->max_lun = max_lun;
4562 sh->transportt = mptsas_transport_template;
4566 sh->unique_id = ioc->id;
4568 INIT_LIST_HEAD(&ioc->sas_topology);
4569 mutex_init(&ioc->sas_topology_mutex);
4570 mutex_init(&ioc->sas_discovery_mutex);
4571 mutex_init(&ioc->sas_mgmt.mutex);
4572 init_completion(&ioc->sas_mgmt.done);
4574 /* Verify that we won't exceed the maximum
4575 * number of chain buffers
4576 * We can optimize: ZZ = req_sz/sizeof(SGE)
4578 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
4579 * + (req_sz - 64)/sizeof(SGE)
4580 * A slightly different algorithm is required for
4583 scale = ioc->req_sz/ioc->SGE_size;
4584 if (ioc->sg_addr_size == sizeof(u64)) {
4585 numSGE = (scale - 1) *
4586 (ioc->facts.MaxChainDepth-1) + scale +
4587 (ioc->req_sz - 60) / ioc->SGE_size;
4589 numSGE = 1 + (scale - 1) *
4590 (ioc->facts.MaxChainDepth-1) + scale +
4591 (ioc->req_sz - 64) / ioc->SGE_size;
4594 if (numSGE < sh->sg_tablesize) {
4595 /* Reset this value */
4596 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4597 "Resetting sg_tablesize to %d from %d\n",
4598 ioc->name, numSGE, sh->sg_tablesize));
4599 sh->sg_tablesize = numSGE;
4602 hd = shost_priv(sh);
4605 /* SCSI needs scsi_cmnd lookup table!
4606 * (with size equal to req_depth*PtrSz!)
4608 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
4609 if (!ioc->ScsiLookup) {
4611 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4612 goto out_mptsas_probe;
4614 spin_lock_init(&ioc->scsi_lookup_lock);
4616 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
4617 ioc->name, ioc->ScsiLookup));
4619 /* Clear the TM flags
4621 hd->abortSCpnt = NULL;
4623 /* Clear the pointer used to store
4624 * single-threaded commands, i.e., those
4625 * issued during a bus scan, dv and
4626 * configuration pages.
4630 /* Initialize this SCSI Hosts' timers
4631 * To use, set the timer expires field
4634 init_timer(&hd->timer);
4635 hd->timer.data = (unsigned long) hd;
4636 hd->timer.function = mptscsih_timer_expired;
4638 ioc->sas_data.ptClear = mpt_pt_clear;
4640 hd->last_queue_full = 0;
4641 INIT_LIST_HEAD(&hd->target_reset_list);
4642 INIT_LIST_HEAD(&ioc->sas_device_info_list);
4643 mutex_init(&ioc->sas_device_info_mutex);
4645 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4647 if (ioc->sas_data.ptClear==1) {
4648 mptbase_sas_persist_operation(
4649 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
4652 error = scsi_add_host(sh, &ioc->pcidev->dev);
4654 dprintk(ioc, printk(MYIOC_s_ERR_FMT
4655 "scsi_add_host failed\n", ioc->name));
4656 goto out_mptsas_probe;
4659 /* older firmware doesn't support expander events */
4660 if ((ioc->facts.HeaderVersion >> 8) < 0xE)
4661 ioc->old_sas_discovery_protocal = 1;
4662 mptsas_scan_sas_topology(ioc);
4663 mptsas_fw_event_on(ioc);
4668 mptscsih_remove(pdev);
4673 mptsas_shutdown(struct pci_dev *pdev)
4675 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
4677 mptsas_fw_event_off(ioc);
4678 mptsas_cleanup_fw_event_q(ioc);
4681 static void __devexit mptsas_remove(struct pci_dev *pdev)
4683 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
4684 struct mptsas_portinfo *p, *n;
4687 mptsas_shutdown(pdev);
4689 mptsas_del_device_components(ioc);
4691 ioc->sas_discovery_ignore_events = 1;
4692 sas_remove_host(ioc->sh);
4694 mutex_lock(&ioc->sas_topology_mutex);
4695 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
4697 for (i = 0 ; i < p->num_phys ; i++)
4698 mptsas_port_delete(ioc, p->phy_info[i].port_details);
4703 mutex_unlock(&ioc->sas_topology_mutex);
4704 ioc->hba_port_info = NULL;
4705 mptscsih_remove(pdev);
4708 static struct pci_device_id mptsas_pci_table[] = {
4709 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
4710 PCI_ANY_ID, PCI_ANY_ID },
4711 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
4712 PCI_ANY_ID, PCI_ANY_ID },
4713 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
4714 PCI_ANY_ID, PCI_ANY_ID },
4715 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
4716 PCI_ANY_ID, PCI_ANY_ID },
4717 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
4718 PCI_ANY_ID, PCI_ANY_ID },
4719 {0} /* Terminating entry */
4721 MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
4724 static struct pci_driver mptsas_driver = {
4726 .id_table = mptsas_pci_table,
4727 .probe = mptsas_probe,
4728 .remove = __devexit_p(mptsas_remove),
4729 .shutdown = mptsas_shutdown,
4731 .suspend = mptscsih_suspend,
4732 .resume = mptscsih_resume,
4741 show_mptmod_ver(my_NAME, my_VERSION);
4743 mptsas_transport_template =
4744 sas_attach_transport(&mptsas_transport_functions);
4745 if (!mptsas_transport_template)
4748 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
4749 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER);
4751 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
4752 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
4753 mptsasDeviceResetCtx =
4754 mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER);
4756 mpt_event_register(mptsasDoneCtx, mptsas_event_process);
4757 mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset);
4759 error = pci_register_driver(&mptsas_driver);
4761 sas_release_transport(mptsas_transport_template);
4769 pci_unregister_driver(&mptsas_driver);
4770 sas_release_transport(mptsas_transport_template);
4772 mpt_reset_deregister(mptsasDoneCtx);
4773 mpt_event_deregister(mptsasDoneCtx);
4775 mpt_deregister(mptsasMgmtCtx);
4776 mpt_deregister(mptsasInternalCtx);
4777 mpt_deregister(mptsasTaskCtx);
4778 mpt_deregister(mptsasDoneCtx);
4779 mpt_deregister(mptsasDeviceResetCtx);
4782 module_init(mptsas_init);
4783 module_exit(mptsas_exit);