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 #define SAS_CONFIG_PAGE_TIMEOUT 30
76 MODULE_AUTHOR(MODULEAUTHOR);
77 MODULE_DESCRIPTION(my_NAME);
78 MODULE_LICENSE("GPL");
79 MODULE_VERSION(my_VERSION);
81 static int mpt_pt_clear;
82 module_param(mpt_pt_clear, int, 0);
83 MODULE_PARM_DESC(mpt_pt_clear,
84 " Clear persistency table: enable=1 "
85 "(default=MPTSCSIH_PT_CLEAR=0)");
87 /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
88 #define MPTSAS_MAX_LUN (16895)
89 static int max_lun = MPTSAS_MAX_LUN;
90 module_param(max_lun, int, 0);
91 MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
93 static u8 mptsasDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
94 static u8 mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
95 static u8 mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
96 static u8 mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS;
97 static u8 mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS;
99 static void mptsas_firmware_event_work(struct work_struct *work);
100 static void mptsas_send_sas_event(struct fw_event_work *fw_event);
101 static void mptsas_send_raid_event(struct fw_event_work *fw_event);
102 static void mptsas_send_ir2_event(struct fw_event_work *fw_event);
103 static void mptsas_parse_device_info(struct sas_identify *identify,
104 struct mptsas_devinfo *device_info);
105 static inline void mptsas_set_rphy(MPT_ADAPTER *ioc,
106 struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy);
107 static struct mptsas_phyinfo *mptsas_find_phyinfo_by_sas_address
108 (MPT_ADAPTER *ioc, u64 sas_address);
109 static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc,
110 struct mptsas_devinfo *device_info, u32 form, u32 form_specific);
111 static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc,
112 struct mptsas_enclosure *enclosure, u32 form, u32 form_specific);
113 static int mptsas_add_end_device(MPT_ADAPTER *ioc,
114 struct mptsas_phyinfo *phy_info);
115 static void mptsas_del_end_device(MPT_ADAPTER *ioc,
116 struct mptsas_phyinfo *phy_info);
117 static void mptsas_send_link_status_event(struct fw_event_work *fw_event);
118 static struct mptsas_portinfo *mptsas_find_portinfo_by_sas_address
119 (MPT_ADAPTER *ioc, u64 sas_address);
120 static void mptsas_expander_delete(MPT_ADAPTER *ioc,
121 struct mptsas_portinfo *port_info, u8 force);
122 static void mptsas_send_expander_event(struct fw_event_work *fw_event);
123 static void mptsas_not_responding_devices(MPT_ADAPTER *ioc);
124 static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc);
125 static void mptsas_broadcast_primative_work(struct fw_event_work *fw_event);
126 static void mptsas_handle_queue_full_event(struct fw_event_work *fw_event);
127 static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id);
129 static void mptsas_print_phy_data(MPT_ADAPTER *ioc,
130 MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
132 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
133 "---- IO UNIT PAGE 0 ------------\n", ioc->name));
134 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
135 ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle)));
136 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n",
137 ioc->name, le16_to_cpu(phy_data->ControllerDevHandle)));
138 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n",
139 ioc->name, phy_data->Port));
140 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n",
141 ioc->name, phy_data->PortFlags));
142 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n",
143 ioc->name, phy_data->PhyFlags));
144 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
145 ioc->name, phy_data->NegotiatedLinkRate));
146 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
147 "Controller PHY Device Info=0x%X\n", ioc->name,
148 le32_to_cpu(phy_data->ControllerPhyDeviceInfo)));
149 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n",
150 ioc->name, le32_to_cpu(phy_data->DiscoveryStatus)));
153 static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0)
157 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
159 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
160 "---- SAS PHY PAGE 0 ------------\n", ioc->name));
161 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
162 "Attached Device Handle=0x%X\n", ioc->name,
163 le16_to_cpu(pg0->AttachedDevHandle)));
164 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
165 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
166 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
167 "Attached PHY Identifier=0x%X\n", ioc->name,
168 pg0->AttachedPhyIdentifier));
169 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n",
170 ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo)));
171 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
172 ioc->name, pg0->ProgrammedLinkRate));
173 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n",
174 ioc->name, pg0->ChangeCount));
175 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n",
176 ioc->name, le32_to_cpu(pg0->PhyInfo)));
179 static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1)
181 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
182 "---- SAS PHY PAGE 1 ------------\n", ioc->name));
183 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n",
184 ioc->name, pg1->InvalidDwordCount));
185 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
186 "Running Disparity Error Count=0x%x\n", ioc->name,
187 pg1->RunningDisparityErrorCount));
188 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
189 "Loss Dword Synch Count=0x%x\n", ioc->name,
190 pg1->LossDwordSynchCount));
191 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
192 "PHY Reset Problem Count=0x%x\n\n", ioc->name,
193 pg1->PhyResetProblemCount));
196 static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0)
200 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
202 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
203 "---- SAS DEVICE PAGE 0 ---------\n", ioc->name));
204 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
205 ioc->name, le16_to_cpu(pg0->DevHandle)));
206 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n",
207 ioc->name, le16_to_cpu(pg0->ParentDevHandle)));
208 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n",
209 ioc->name, le16_to_cpu(pg0->EnclosureHandle)));
210 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n",
211 ioc->name, le16_to_cpu(pg0->Slot)));
212 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
213 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
214 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n",
215 ioc->name, pg0->TargetID));
216 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n",
217 ioc->name, pg0->Bus));
218 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n",
219 ioc->name, pg0->PhyNum));
220 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n",
221 ioc->name, le16_to_cpu(pg0->AccessStatus)));
222 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n",
223 ioc->name, le32_to_cpu(pg0->DeviceInfo)));
224 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n",
225 ioc->name, le16_to_cpu(pg0->Flags)));
226 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n",
227 ioc->name, pg0->PhysicalPort));
230 static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1)
232 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
233 "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name));
234 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n",
235 ioc->name, pg1->PhysicalPort));
236 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n",
237 ioc->name, pg1->PhyIdentifier));
238 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
239 ioc->name, pg1->NegotiatedLinkRate));
240 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
241 ioc->name, pg1->ProgrammedLinkRate));
242 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n",
243 ioc->name, pg1->HwLinkRate));
244 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n",
245 ioc->name, le16_to_cpu(pg1->OwnerDevHandle)));
246 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
247 "Attached Device Handle=0x%X\n\n", ioc->name,
248 le16_to_cpu(pg1->AttachedDevHandle)));
251 /* inhibit sas firmware event handling */
253 mptsas_fw_event_off(MPT_ADAPTER *ioc)
257 spin_lock_irqsave(&ioc->fw_event_lock, flags);
258 ioc->fw_events_off = 1;
259 ioc->sas_discovery_quiesce_io = 0;
260 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
264 /* enable sas firmware event handling */
266 mptsas_fw_event_on(MPT_ADAPTER *ioc)
270 spin_lock_irqsave(&ioc->fw_event_lock, flags);
271 ioc->fw_events_off = 0;
272 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
275 /* queue a sas firmware event */
277 mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
282 spin_lock_irqsave(&ioc->fw_event_lock, flags);
283 list_add_tail(&fw_event->list, &ioc->fw_event_list);
284 INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work);
285 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)\n",
286 ioc->name, __func__, fw_event));
287 queue_delayed_work(ioc->fw_event_q, &fw_event->work,
289 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
292 /* requeue a sas firmware event */
294 mptsas_requeue_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
298 spin_lock_irqsave(&ioc->fw_event_lock, flags);
299 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: reschedule task "
300 "(fw_event=0x%p)\n", ioc->name, __func__, fw_event));
302 queue_delayed_work(ioc->fw_event_q, &fw_event->work,
303 msecs_to_jiffies(delay));
304 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
307 /* free memory assoicated to a sas firmware event */
309 mptsas_free_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event)
313 spin_lock_irqsave(&ioc->fw_event_lock, flags);
314 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: kfree (fw_event=0x%p)\n",
315 ioc->name, __func__, fw_event));
316 list_del(&fw_event->list);
318 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
321 /* walk the firmware event queue, and either stop or wait for
322 * outstanding events to complete */
324 mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc)
326 struct fw_event_work *fw_event, *next;
327 struct mptsas_target_reset_event *target_reset_list, *n;
329 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
331 /* flush the target_reset_list */
332 if (!list_empty(&hd->target_reset_list)) {
333 list_for_each_entry_safe(target_reset_list, n,
334 &hd->target_reset_list, list) {
335 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
336 "%s: removing target reset for id=%d\n",
338 target_reset_list->sas_event_data.TargetID));
339 list_del(&target_reset_list->list);
340 kfree(target_reset_list);
344 if (list_empty(&ioc->fw_event_list) ||
345 !ioc->fw_event_q || in_interrupt())
349 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
350 if (cancel_delayed_work(&fw_event->work))
351 mptsas_free_fw_event(ioc, fw_event);
356 flush_workqueue(ioc->fw_event_q);
360 static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
362 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
363 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
366 static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
368 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
369 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
373 * mptsas_find_portinfo_by_handle
375 * This function should be called with the sas_topology_mutex already held
377 static struct mptsas_portinfo *
378 mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
380 struct mptsas_portinfo *port_info, *rc=NULL;
383 list_for_each_entry(port_info, &ioc->sas_topology, list)
384 for (i = 0; i < port_info->num_phys; i++)
385 if (port_info->phy_info[i].identify.handle == handle) {
394 * mptsas_find_portinfo_by_sas_address -
395 * @ioc: Pointer to MPT_ADAPTER structure
398 * This function should be called with the sas_topology_mutex already held
401 static struct mptsas_portinfo *
402 mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
404 struct mptsas_portinfo *port_info, *rc = NULL;
407 if (sas_address >= ioc->hba_port_sas_addr &&
408 sas_address < (ioc->hba_port_sas_addr +
409 ioc->hba_port_num_phy))
410 return ioc->hba_port_info;
412 mutex_lock(&ioc->sas_topology_mutex);
413 list_for_each_entry(port_info, &ioc->sas_topology, list)
414 for (i = 0; i < port_info->num_phys; i++)
415 if (port_info->phy_info[i].identify.sas_address ==
421 mutex_unlock(&ioc->sas_topology_mutex);
426 * Returns true if there is a scsi end device
429 mptsas_is_end_device(struct mptsas_devinfo * attached)
431 if ((attached->sas_address) &&
432 (attached->device_info &
433 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
434 ((attached->device_info &
435 MPI_SAS_DEVICE_INFO_SSP_TARGET) |
436 (attached->device_info &
437 MPI_SAS_DEVICE_INFO_STP_TARGET) |
438 (attached->device_info &
439 MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
447 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
449 struct mptsas_portinfo *port_info;
450 struct mptsas_phyinfo *phy_info;
456 port_info = port_details->port_info;
457 phy_info = port_info->phy_info;
459 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d "
460 "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
461 port_details->num_phys, (unsigned long long)
462 port_details->phy_bitmask));
464 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
465 if(phy_info->port_details != port_details)
467 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
468 mptsas_set_rphy(ioc, phy_info, NULL);
469 phy_info->port_details = NULL;
474 static inline struct sas_rphy *
475 mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
477 if (phy_info->port_details)
478 return phy_info->port_details->rphy;
484 mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
486 if (phy_info->port_details) {
487 phy_info->port_details->rphy = rphy;
488 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
493 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
494 &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
495 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
496 ioc->name, rphy, rphy->dev.release));
500 static inline struct sas_port *
501 mptsas_get_port(struct mptsas_phyinfo *phy_info)
503 if (phy_info->port_details)
504 return phy_info->port_details->port;
510 mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port)
512 if (phy_info->port_details)
513 phy_info->port_details->port = port;
516 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
517 &port->dev, MYIOC_s_FMT "add:", ioc->name));
518 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n",
519 ioc->name, port, port->dev.release));
523 static inline struct scsi_target *
524 mptsas_get_starget(struct mptsas_phyinfo *phy_info)
526 if (phy_info->port_details)
527 return phy_info->port_details->starget;
533 mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
536 if (phy_info->port_details)
537 phy_info->port_details->starget = starget;
541 * mptsas_add_device_component -
542 * @ioc: Pointer to MPT_ADAPTER structure
543 * @channel: fw mapped id's
550 mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id,
551 u64 sas_address, u32 device_info, u16 slot, u64 enclosure_logical_id)
553 struct mptsas_device_info *sas_info, *next;
554 struct scsi_device *sdev;
555 struct scsi_target *starget;
556 struct sas_rphy *rphy;
559 * Delete all matching devices out of the list
561 mutex_lock(&ioc->sas_device_info_mutex);
562 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
564 if (!sas_info->is_logical_volume &&
565 (sas_info->sas_address == sas_address ||
566 (sas_info->fw.channel == channel &&
567 sas_info->fw.id == id))) {
568 list_del(&sas_info->list);
573 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
578 * Set Firmware mapping
580 sas_info->fw.id = id;
581 sas_info->fw.channel = channel;
583 sas_info->sas_address = sas_address;
584 sas_info->device_info = device_info;
585 sas_info->slot = slot;
586 sas_info->enclosure_logical_id = enclosure_logical_id;
587 INIT_LIST_HEAD(&sas_info->list);
588 list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
593 shost_for_each_device(sdev, ioc->sh) {
594 starget = scsi_target(sdev);
595 rphy = dev_to_rphy(starget->dev.parent);
596 if (rphy->identify.sas_address == sas_address) {
597 sas_info->os.id = starget->id;
598 sas_info->os.channel = starget->channel;
603 mutex_unlock(&ioc->sas_device_info_mutex);
608 * mptsas_add_device_component_by_fw -
609 * @ioc: Pointer to MPT_ADAPTER structure
610 * @channel: fw mapped id's
615 mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id)
617 struct mptsas_devinfo sas_device;
618 struct mptsas_enclosure enclosure_info;
621 rc = mptsas_sas_device_pg0(ioc, &sas_device,
622 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
623 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
624 (channel << 8) + id);
628 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
629 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
630 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
631 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
632 sas_device.handle_enclosure);
634 mptsas_add_device_component(ioc, sas_device.channel,
635 sas_device.id, sas_device.sas_address, sas_device.device_info,
636 sas_device.slot, enclosure_info.enclosure_logical_id);
640 * mptsas_add_device_component_starget_ir - Handle Integrated RAID, adding each individual device to list
641 * @ioc: Pointer to MPT_ADAPTER structure
642 * @channel: fw mapped id's
647 mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc,
648 struct scsi_target *starget)
651 ConfigPageHeader_t hdr;
652 dma_addr_t dma_handle;
653 pRaidVolumePage0_t buffer = NULL;
655 RaidPhysDiskPage0_t phys_disk;
656 struct mptsas_device_info *sas_info, *next;
658 memset(&cfg, 0 , sizeof(CONFIGPARMS));
659 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
660 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
661 /* assumption that all volumes on channel = 0 */
662 cfg.pageAddr = starget->id;
663 cfg.cfghdr.hdr = &hdr;
664 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
665 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
667 if (mpt_config(ioc, &cfg) != 0)
673 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
679 cfg.physAddr = dma_handle;
680 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
682 if (mpt_config(ioc, &cfg) != 0)
685 if (!buffer->NumPhysDisks)
689 * Adding entry for hidden components
691 for (i = 0; i < buffer->NumPhysDisks; i++) {
693 if (mpt_raid_phys_disk_pg0(ioc,
694 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
697 mptsas_add_device_component_by_fw(ioc, phys_disk.PhysDiskBus,
698 phys_disk.PhysDiskID);
700 mutex_lock(&ioc->sas_device_info_mutex);
701 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
703 if (!sas_info->is_logical_volume &&
704 (sas_info->fw.channel == phys_disk.PhysDiskBus &&
705 sas_info->fw.id == phys_disk.PhysDiskID)) {
706 sas_info->is_hidden_raid_component = 1;
707 sas_info->volume_id = starget->id;
710 mutex_unlock(&ioc->sas_device_info_mutex);
715 * Delete all matching devices out of the list
717 mutex_lock(&ioc->sas_device_info_mutex);
718 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
720 if (sas_info->is_logical_volume && sas_info->fw.id ==
722 list_del(&sas_info->list);
727 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
729 sas_info->fw.id = starget->id;
730 sas_info->os.id = starget->id;
731 sas_info->os.channel = starget->channel;
732 sas_info->is_logical_volume = 1;
733 INIT_LIST_HEAD(&sas_info->list);
734 list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
736 mutex_unlock(&ioc->sas_device_info_mutex);
740 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
745 * mptsas_add_device_component_starget -
746 * @ioc: Pointer to MPT_ADAPTER structure
751 mptsas_add_device_component_starget(MPT_ADAPTER *ioc,
752 struct scsi_target *starget)
755 struct sas_rphy *rphy;
756 struct mptsas_phyinfo *phy_info = NULL;
757 struct mptsas_enclosure enclosure_info;
759 rphy = dev_to_rphy(starget->dev.parent);
760 vtarget = starget->hostdata;
761 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
762 rphy->identify.sas_address);
766 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
767 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
768 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
769 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
770 phy_info->attached.handle_enclosure);
772 mptsas_add_device_component(ioc, phy_info->attached.channel,
773 phy_info->attached.id, phy_info->attached.sas_address,
774 phy_info->attached.device_info,
775 phy_info->attached.slot, enclosure_info.enclosure_logical_id);
779 * mptsas_del_device_component_by_os - Once a device has been removed, we mark the entry in the list as being cached
780 * @ioc: Pointer to MPT_ADAPTER structure
781 * @channel: os mapped id's
786 mptsas_del_device_component_by_os(MPT_ADAPTER *ioc, u8 channel, u8 id)
788 struct mptsas_device_info *sas_info, *next;
793 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
795 if (sas_info->os.channel == channel && sas_info->os.id == id)
796 sas_info->is_cached = 1;
801 * mptsas_del_device_components - Cleaning the list
802 * @ioc: Pointer to MPT_ADAPTER structure
806 mptsas_del_device_components(MPT_ADAPTER *ioc)
808 struct mptsas_device_info *sas_info, *next;
810 mutex_lock(&ioc->sas_device_info_mutex);
811 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
813 list_del(&sas_info->list);
816 mutex_unlock(&ioc->sas_device_info_mutex);
821 * mptsas_setup_wide_ports
823 * Updates for new and existing narrow/wide port configuration
824 * in the sas_topology
827 mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
829 struct mptsas_portinfo_details * port_details;
830 struct mptsas_phyinfo *phy_info, *phy_info_cmp;
834 mutex_lock(&ioc->sas_topology_mutex);
836 phy_info = port_info->phy_info;
837 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
838 if (phy_info->attached.handle)
840 port_details = phy_info->port_details;
843 if (port_details->num_phys < 2)
846 * Removing a phy from a port, letting the last
847 * phy be removed by firmware events.
849 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
850 "%s: [%p]: deleting phy = %d\n",
851 ioc->name, __func__, port_details, i));
852 port_details->num_phys--;
853 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
854 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
856 devtprintk(ioc, dev_printk(KERN_DEBUG,
857 &phy_info->phy->dev, MYIOC_s_FMT
858 "delete phy %d, phy-obj (0x%p)\n", ioc->name,
859 phy_info->phy_id, phy_info->phy));
860 sas_port_delete_phy(port_details->port, phy_info->phy);
862 phy_info->port_details = NULL;
866 * Populate and refresh the tree
868 phy_info = port_info->phy_info;
869 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
870 sas_address = phy_info->attached.sas_address;
871 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
872 ioc->name, i, (unsigned long long)sas_address));
875 port_details = phy_info->port_details;
880 port_details = kzalloc(sizeof(struct
881 mptsas_portinfo_details), GFP_KERNEL);
884 port_details->num_phys = 1;
885 port_details->port_info = port_info;
886 if (phy_info->phy_id < 64 )
887 port_details->phy_bitmask |=
888 (1 << phy_info->phy_id);
889 phy_info->sas_port_add_phy=1;
890 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
891 "phy_id=%d sas_address=0x%018llX\n",
892 ioc->name, i, (unsigned long long)sas_address));
893 phy_info->port_details = port_details;
896 if (i == port_info->num_phys - 1)
898 phy_info_cmp = &port_info->phy_info[i + 1];
899 for (j = i + 1 ; j < port_info->num_phys ; j++,
901 if (!phy_info_cmp->attached.sas_address)
903 if (sas_address != phy_info_cmp->attached.sas_address)
905 if (phy_info_cmp->port_details == port_details )
907 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
908 "\t\tphy_id=%d sas_address=0x%018llX\n",
909 ioc->name, j, (unsigned long long)
910 phy_info_cmp->attached.sas_address));
911 if (phy_info_cmp->port_details) {
913 mptsas_get_rphy(phy_info_cmp);
915 mptsas_get_port(phy_info_cmp);
916 port_details->starget =
917 mptsas_get_starget(phy_info_cmp);
918 port_details->num_phys =
919 phy_info_cmp->port_details->num_phys;
920 if (!phy_info_cmp->port_details->num_phys)
921 kfree(phy_info_cmp->port_details);
923 phy_info_cmp->sas_port_add_phy=1;
925 * Adding a phy to a port
927 phy_info_cmp->port_details = port_details;
928 if (phy_info_cmp->phy_id < 64 )
929 port_details->phy_bitmask |=
930 (1 << phy_info_cmp->phy_id);
931 port_details->num_phys++;
937 for (i = 0; i < port_info->num_phys; i++) {
938 port_details = port_info->phy_info[i].port_details;
941 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
942 "%s: [%p]: phy_id=%02d num_phys=%02d "
943 "bitmask=0x%016llX\n", ioc->name, __func__,
944 port_details, i, port_details->num_phys,
945 (unsigned long long)port_details->phy_bitmask));
946 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
947 ioc->name, port_details->port, port_details->rphy));
949 dsaswideprintk(ioc, printk("\n"));
950 mutex_unlock(&ioc->sas_topology_mutex);
954 * csmisas_find_vtarget
962 mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
964 struct scsi_device *sdev;
966 VirtTarget *vtarget = NULL;
968 shost_for_each_device(sdev, ioc->sh) {
969 vdevice = sdev->hostdata;
970 if ((vdevice == NULL) ||
971 (vdevice->vtarget == NULL))
973 if ((vdevice->vtarget->tflags &
974 MPT_TARGET_FLAGS_RAID_COMPONENT ||
975 vdevice->vtarget->raidVolume))
977 if (vdevice->vtarget->id == id &&
978 vdevice->vtarget->channel == channel)
979 vtarget = vdevice->vtarget;
985 mptsas_queue_device_delete(MPT_ADAPTER *ioc,
986 MpiEventDataSasDeviceStatusChange_t *sas_event_data)
988 struct fw_event_work *fw_event;
991 sz = offsetof(struct fw_event_work, event_data) +
992 sizeof(MpiEventDataSasDeviceStatusChange_t);
993 fw_event = kzalloc(sz, GFP_ATOMIC);
995 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
996 ioc->name, __func__, __LINE__);
999 memcpy(fw_event->event_data, sas_event_data,
1000 sizeof(MpiEventDataSasDeviceStatusChange_t));
1001 fw_event->event = MPI_EVENT_SAS_DEVICE_STATUS_CHANGE;
1002 fw_event->ioc = ioc;
1003 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
1007 mptsas_queue_rescan(MPT_ADAPTER *ioc)
1009 struct fw_event_work *fw_event;
1012 sz = offsetof(struct fw_event_work, event_data);
1013 fw_event = kzalloc(sz, GFP_ATOMIC);
1015 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
1016 ioc->name, __func__, __LINE__);
1019 fw_event->event = -1;
1020 fw_event->ioc = ioc;
1021 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
1026 * mptsas_target_reset
1028 * Issues TARGET_RESET to end device using handshaking method
1034 * Returns (1) success
1039 mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
1042 SCSITaskMgmt_t *pScsiTm;
1043 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0)
1047 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
1049 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
1050 "%s, no msg frames @%d!!\n", ioc->name,
1051 __func__, __LINE__));
1055 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
1058 /* Format the Request
1060 pScsiTm = (SCSITaskMgmt_t *) mf;
1061 memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
1062 pScsiTm->TargetID = id;
1063 pScsiTm->Bus = channel;
1064 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
1065 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
1066 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
1068 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
1070 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1071 "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
1072 ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id));
1074 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
1080 mpt_clear_taskmgmt_in_progress_flag(ioc);
1085 * mptsas_target_reset_queue
1087 * Receive request for TARGET_RESET after recieving an firmware
1088 * event NOT_RESPONDING_EVENT, then put command in link list
1089 * and queue if task_queue already in use.
1096 mptsas_target_reset_queue(MPT_ADAPTER *ioc,
1097 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1099 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1100 VirtTarget *vtarget = NULL;
1101 struct mptsas_target_reset_event *target_reset_list;
1104 id = sas_event_data->TargetID;
1105 channel = sas_event_data->Bus;
1107 if (!(vtarget = mptsas_find_vtarget(ioc, channel, id)))
1110 vtarget->deleted = 1; /* block IO */
1112 target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event),
1114 if (!target_reset_list) {
1115 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
1116 "%s, failed to allocate mem @%d..!!\n",
1117 ioc->name, __func__, __LINE__));
1121 memcpy(&target_reset_list->sas_event_data, sas_event_data,
1122 sizeof(*sas_event_data));
1123 list_add_tail(&target_reset_list->list, &hd->target_reset_list);
1125 target_reset_list->time_count = jiffies;
1127 if (mptsas_target_reset(ioc, channel, id)) {
1128 target_reset_list->target_reset_issued = 1;
1133 * mptsas_taskmgmt_complete - complete SAS task management function
1134 * @ioc: Pointer to MPT_ADAPTER structure
1136 * Completion for TARGET_RESET after NOT_RESPONDING_EVENT, enable work
1137 * queue to finish off removing device from upper layers. then send next
1138 * TARGET_RESET in the queue.
1141 mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
1143 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1144 struct list_head *head = &hd->target_reset_list;
1146 struct mptsas_target_reset_event *target_reset_list;
1147 SCSITaskMgmtReply_t *pScsiTmReply;
1149 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: "
1150 "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
1152 pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
1154 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1155 "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
1156 "\ttask_type = 0x%02X, iocstatus = 0x%04X "
1157 "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
1158 "term_cmnds = %d\n", ioc->name,
1159 pScsiTmReply->Bus, pScsiTmReply->TargetID,
1160 pScsiTmReply->TaskType,
1161 le16_to_cpu(pScsiTmReply->IOCStatus),
1162 le32_to_cpu(pScsiTmReply->IOCLogInfo),
1163 pScsiTmReply->ResponseCode,
1164 le32_to_cpu(pScsiTmReply->TerminationCount)));
1166 if (pScsiTmReply->ResponseCode)
1167 mptscsih_taskmgmt_response_code(ioc,
1168 pScsiTmReply->ResponseCode);
1171 if (pScsiTmReply && (pScsiTmReply->TaskType ==
1172 MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
1173 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET)) {
1174 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1175 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
1176 memcpy(ioc->taskmgmt_cmds.reply, mr,
1177 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
1178 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
1179 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
1180 complete(&ioc->taskmgmt_cmds.done);
1186 mpt_clear_taskmgmt_in_progress_flag(ioc);
1188 if (list_empty(head))
1191 target_reset_list = list_entry(head->next,
1192 struct mptsas_target_reset_event, list);
1194 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1195 "TaskMgmt: completed (%d seconds)\n",
1196 ioc->name, jiffies_to_msecs(jiffies -
1197 target_reset_list->time_count)/1000));
1199 id = pScsiTmReply->TargetID;
1200 channel = pScsiTmReply->Bus;
1201 target_reset_list->time_count = jiffies;
1204 * retry target reset
1206 if (!target_reset_list->target_reset_issued) {
1207 if (mptsas_target_reset(ioc, channel, id))
1208 target_reset_list->target_reset_issued = 1;
1213 * enable work queue to remove device from upper layers
1215 list_del(&target_reset_list->list);
1216 if ((mptsas_find_vtarget(ioc, channel, id)) && !ioc->fw_events_off)
1217 mptsas_queue_device_delete(ioc,
1218 &target_reset_list->sas_event_data);
1222 * issue target reset to next device in the queue
1225 head = &hd->target_reset_list;
1226 if (list_empty(head))
1229 target_reset_list = list_entry(head->next, struct mptsas_target_reset_event,
1232 id = target_reset_list->sas_event_data.TargetID;
1233 channel = target_reset_list->sas_event_data.Bus;
1234 target_reset_list->time_count = jiffies;
1236 if (mptsas_target_reset(ioc, channel, id))
1237 target_reset_list->target_reset_issued = 1;
1243 * mptscsih_ioc_reset
1250 mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1255 rc = mptscsih_ioc_reset(ioc, reset_phase);
1256 if ((ioc->bus_type != SAS) || (!rc))
1259 hd = shost_priv(ioc->sh);
1263 switch (reset_phase) {
1264 case MPT_IOC_SETUP_RESET:
1265 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1266 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
1267 mptsas_fw_event_off(ioc);
1269 case MPT_IOC_PRE_RESET:
1270 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1271 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
1273 case MPT_IOC_POST_RESET:
1274 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1275 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
1276 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
1277 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET;
1278 complete(&ioc->sas_mgmt.done);
1280 mptsas_cleanup_fw_event_q(ioc);
1281 mptsas_queue_rescan(ioc);
1282 mptsas_fw_event_on(ioc);
1294 * enum device_state -
1295 * @DEVICE_RETRY: need to retry the TUR
1296 * @DEVICE_ERROR: TUR return error, don't add device
1297 * @DEVICE_READY: device can be added
1307 mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
1308 u32 form, u32 form_specific)
1310 ConfigExtendedPageHeader_t hdr;
1312 SasEnclosurePage0_t *buffer;
1313 dma_addr_t dma_handle;
1315 __le64 le_identifier;
1317 memset(&hdr, 0, sizeof(hdr));
1318 hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
1320 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1321 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
1323 cfg.cfghdr.ehdr = &hdr;
1325 cfg.pageAddr = form + form_specific;
1326 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1327 cfg.dir = 0; /* read */
1328 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
1330 error = mpt_config(ioc, &cfg);
1333 if (!hdr.ExtPageLength) {
1338 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1345 cfg.physAddr = dma_handle;
1346 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1348 error = mpt_config(ioc, &cfg);
1350 goto out_free_consistent;
1352 /* save config data */
1353 memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
1354 enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
1355 enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
1356 enclosure->flags = le16_to_cpu(buffer->Flags);
1357 enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
1358 enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
1359 enclosure->start_id = buffer->StartTargetID;
1360 enclosure->start_channel = buffer->StartBus;
1361 enclosure->sep_id = buffer->SEPTargetID;
1362 enclosure->sep_channel = buffer->SEPBus;
1364 out_free_consistent:
1365 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1366 buffer, dma_handle);
1372 * mptsas_add_end_device - report a new end device to sas transport layer
1373 * @ioc: Pointer to MPT_ADAPTER structure
1374 * @phy_info: decribes attached device
1376 * return (0) success (1) failure
1380 mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1382 struct sas_rphy *rphy;
1383 struct sas_port *port;
1384 struct sas_identify identify;
1389 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1390 "%s: exit at line=%d\n", ioc->name,
1391 __func__, __LINE__));
1395 fw_id = phy_info->attached.id;
1397 if (mptsas_get_rphy(phy_info)) {
1398 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1399 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1400 __func__, fw_id, __LINE__));
1404 port = mptsas_get_port(phy_info);
1406 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1407 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1408 __func__, fw_id, __LINE__));
1412 if (phy_info->attached.device_info &
1413 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1415 if (phy_info->attached.device_info &
1416 MPI_SAS_DEVICE_INFO_STP_TARGET)
1418 if (phy_info->attached.device_info &
1419 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1422 printk(MYIOC_s_INFO_FMT "attaching %s device: fw_channel %d, fw_id %d,"
1423 " phy %d, sas_addr 0x%llx\n", ioc->name, ds,
1424 phy_info->attached.channel, phy_info->attached.id,
1425 phy_info->attached.phy_id, (unsigned long long)
1426 phy_info->attached.sas_address);
1428 mptsas_parse_device_info(&identify, &phy_info->attached);
1429 rphy = sas_end_device_alloc(port);
1431 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1432 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1433 __func__, fw_id, __LINE__));
1434 return 5; /* non-fatal: an rphy can be added later */
1437 rphy->identify = identify;
1438 if (sas_rphy_add(rphy)) {
1439 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1440 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1441 __func__, fw_id, __LINE__));
1442 sas_rphy_free(rphy);
1445 mptsas_set_rphy(ioc, phy_info, rphy);
1450 * mptsas_del_end_device - report a deleted end device to sas transport layer
1451 * @ioc: Pointer to MPT_ADAPTER structure
1452 * @phy_info: decribes attached device
1456 mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1458 struct sas_rphy *rphy;
1459 struct sas_port *port;
1460 struct mptsas_portinfo *port_info;
1461 struct mptsas_phyinfo *phy_info_parent;
1470 fw_id = phy_info->attached.id;
1471 sas_address = phy_info->attached.sas_address;
1473 if (!phy_info->port_details) {
1474 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1475 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1476 __func__, fw_id, __LINE__));
1479 rphy = mptsas_get_rphy(phy_info);
1481 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1482 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1483 __func__, fw_id, __LINE__));
1487 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_INITIATOR
1488 || phy_info->attached.device_info
1489 & MPI_SAS_DEVICE_INFO_SMP_INITIATOR
1490 || phy_info->attached.device_info
1491 & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1493 if (phy_info->attached.device_info &
1494 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1496 if (phy_info->attached.device_info &
1497 MPI_SAS_DEVICE_INFO_STP_TARGET)
1499 if (phy_info->attached.device_info &
1500 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1503 dev_printk(KERN_DEBUG, &rphy->dev, MYIOC_s_FMT
1504 "removing %s device: fw_channel %d, fw_id %d, phy %d,"
1505 "sas_addr 0x%llx\n", ioc->name, ds, phy_info->attached.channel,
1506 phy_info->attached.id, phy_info->attached.phy_id,
1507 (unsigned long long) sas_address);
1509 port = mptsas_get_port(phy_info);
1511 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1512 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1513 __func__, fw_id, __LINE__));
1516 port_info = phy_info->portinfo;
1517 phy_info_parent = port_info->phy_info;
1518 for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) {
1519 if (!phy_info_parent->phy)
1521 if (phy_info_parent->attached.sas_address !=
1524 dev_printk(KERN_DEBUG, &phy_info_parent->phy->dev,
1525 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n",
1526 ioc->name, phy_info_parent->phy_id,
1527 phy_info_parent->phy);
1528 sas_port_delete_phy(port, phy_info_parent->phy);
1531 dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
1532 "delete port %d, sas_addr (0x%llx)\n", ioc->name,
1533 port->port_identifier, (unsigned long long)sas_address);
1534 sas_port_delete(port);
1535 mptsas_set_port(ioc, phy_info, NULL);
1536 mptsas_port_delete(ioc, phy_info->port_details);
1539 struct mptsas_phyinfo *
1540 mptsas_refreshing_device_handles(MPT_ADAPTER *ioc,
1541 struct mptsas_devinfo *sas_device)
1543 struct mptsas_phyinfo *phy_info;
1544 struct mptsas_portinfo *port_info;
1547 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
1548 sas_device->sas_address);
1551 port_info = phy_info->portinfo;
1554 mutex_lock(&ioc->sas_topology_mutex);
1555 for (i = 0; i < port_info->num_phys; i++) {
1556 if (port_info->phy_info[i].attached.sas_address !=
1557 sas_device->sas_address)
1559 port_info->phy_info[i].attached.channel = sas_device->channel;
1560 port_info->phy_info[i].attached.id = sas_device->id;
1561 port_info->phy_info[i].attached.sas_address =
1562 sas_device->sas_address;
1563 port_info->phy_info[i].attached.handle = sas_device->handle;
1564 port_info->phy_info[i].attached.handle_parent =
1565 sas_device->handle_parent;
1566 port_info->phy_info[i].attached.handle_enclosure =
1567 sas_device->handle_enclosure;
1569 mutex_unlock(&ioc->sas_topology_mutex);
1575 * mptsas_firmware_event_work - work thread for processing fw events
1576 * @work: work queue payload containing info describing the event
1581 mptsas_firmware_event_work(struct work_struct *work)
1583 struct fw_event_work *fw_event =
1584 container_of(work, struct fw_event_work, work.work);
1585 MPT_ADAPTER *ioc = fw_event->ioc;
1587 /* special rescan topology handling */
1588 if (fw_event->event == -1) {
1589 if (ioc->in_rescan) {
1590 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1591 "%s: rescan ignored as it is in progress\n",
1592 ioc->name, __func__));
1595 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rescan after "
1596 "reset\n", ioc->name, __func__));
1598 mptsas_not_responding_devices(ioc);
1599 mptsas_scan_sas_topology(ioc);
1601 mptsas_free_fw_event(ioc, fw_event);
1605 /* events handling turned off during host reset */
1606 if (ioc->fw_events_off) {
1607 mptsas_free_fw_event(ioc, fw_event);
1611 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_event=(0x%p), "
1612 "event = (0x%02x)\n", ioc->name, __func__, fw_event,
1613 (fw_event->event & 0xFF)));
1615 switch (fw_event->event) {
1616 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
1617 mptsas_send_sas_event(fw_event);
1619 case MPI_EVENT_INTEGRATED_RAID:
1620 mptsas_send_raid_event(fw_event);
1623 mptsas_send_ir2_event(fw_event);
1625 case MPI_EVENT_PERSISTENT_TABLE_FULL:
1626 mptbase_sas_persist_operation(ioc,
1627 MPI_SAS_OP_CLEAR_NOT_PRESENT);
1628 mptsas_free_fw_event(ioc, fw_event);
1630 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
1631 mptsas_broadcast_primative_work(fw_event);
1633 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
1634 mptsas_send_expander_event(fw_event);
1636 case MPI_EVENT_SAS_PHY_LINK_STATUS:
1637 mptsas_send_link_status_event(fw_event);
1639 case MPI_EVENT_QUEUE_FULL:
1640 mptsas_handle_queue_full_event(fw_event);
1648 mptsas_slave_configure(struct scsi_device *sdev)
1650 struct Scsi_Host *host = sdev->host;
1651 MPT_SCSI_HOST *hd = shost_priv(host);
1652 MPT_ADAPTER *ioc = hd->ioc;
1653 VirtDevice *vdevice = sdev->hostdata;
1655 if (vdevice->vtarget->deleted) {
1656 sdev_printk(KERN_INFO, sdev, "clearing deleted flag\n");
1657 vdevice->vtarget->deleted = 0;
1661 * RAID volumes placed beyond the last expected port.
1662 * Ignore sending sas mode pages in that case..
1664 if (sdev->channel == MPTSAS_RAID_CHANNEL) {
1665 mptsas_add_device_component_starget_ir(ioc, scsi_target(sdev));
1669 sas_read_port_mode_page(sdev);
1671 mptsas_add_device_component_starget(ioc, scsi_target(sdev));
1674 return mptscsih_slave_configure(sdev);
1678 mptsas_target_alloc(struct scsi_target *starget)
1680 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1681 MPT_SCSI_HOST *hd = shost_priv(host);
1682 VirtTarget *vtarget;
1684 struct sas_rphy *rphy;
1685 struct mptsas_portinfo *p;
1687 MPT_ADAPTER *ioc = hd->ioc;
1689 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
1693 vtarget->starget = starget;
1694 vtarget->ioc_id = ioc->id;
1695 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
1700 * RAID volumes placed beyond the last expected port.
1702 if (starget->channel == MPTSAS_RAID_CHANNEL) {
1703 if (!ioc->raid_data.pIocPg2) {
1707 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1708 if (id == ioc->raid_data.pIocPg2->
1709 RaidVolume[i].VolumeID) {
1710 channel = ioc->raid_data.pIocPg2->
1711 RaidVolume[i].VolumeBus;
1714 vtarget->raidVolume = 1;
1718 rphy = dev_to_rphy(starget->dev.parent);
1719 mutex_lock(&ioc->sas_topology_mutex);
1720 list_for_each_entry(p, &ioc->sas_topology, list) {
1721 for (i = 0; i < p->num_phys; i++) {
1722 if (p->phy_info[i].attached.sas_address !=
1723 rphy->identify.sas_address)
1725 id = p->phy_info[i].attached.id;
1726 channel = p->phy_info[i].attached.channel;
1727 mptsas_set_starget(&p->phy_info[i], starget);
1730 * Exposing hidden raid components
1732 if (mptscsih_is_phys_disk(ioc, channel, id)) {
1733 id = mptscsih_raid_id_to_num(ioc,
1736 MPT_TARGET_FLAGS_RAID_COMPONENT;
1737 p->phy_info[i].attached.phys_disk_num = id;
1739 mutex_unlock(&ioc->sas_topology_mutex);
1743 mutex_unlock(&ioc->sas_topology_mutex);
1750 vtarget->channel = channel;
1751 starget->hostdata = vtarget;
1756 mptsas_target_destroy(struct scsi_target *starget)
1758 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1759 MPT_SCSI_HOST *hd = shost_priv(host);
1760 struct sas_rphy *rphy;
1761 struct mptsas_portinfo *p;
1763 MPT_ADAPTER *ioc = hd->ioc;
1764 VirtTarget *vtarget;
1766 if (!starget->hostdata)
1769 vtarget = starget->hostdata;
1771 mptsas_del_device_component_by_os(ioc, starget->channel,
1775 if (starget->channel == MPTSAS_RAID_CHANNEL)
1778 rphy = dev_to_rphy(starget->dev.parent);
1779 list_for_each_entry(p, &ioc->sas_topology, list) {
1780 for (i = 0; i < p->num_phys; i++) {
1781 if (p->phy_info[i].attached.sas_address !=
1782 rphy->identify.sas_address)
1785 starget_printk(KERN_INFO, starget, MYIOC_s_FMT
1786 "delete device: fw_channel %d, fw_id %d, phy %d, "
1787 "sas_addr 0x%llx\n", ioc->name,
1788 p->phy_info[i].attached.channel,
1789 p->phy_info[i].attached.id,
1790 p->phy_info[i].attached.phy_id, (unsigned long long)
1791 p->phy_info[i].attached.sas_address);
1793 mptsas_set_starget(&p->phy_info[i], NULL);
1798 vtarget->starget = NULL;
1799 kfree(starget->hostdata);
1800 starget->hostdata = NULL;
1805 mptsas_slave_alloc(struct scsi_device *sdev)
1807 struct Scsi_Host *host = sdev->host;
1808 MPT_SCSI_HOST *hd = shost_priv(host);
1809 struct sas_rphy *rphy;
1810 struct mptsas_portinfo *p;
1811 VirtDevice *vdevice;
1812 struct scsi_target *starget;
1814 MPT_ADAPTER *ioc = hd->ioc;
1816 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
1818 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
1819 ioc->name, sizeof(VirtDevice));
1822 starget = scsi_target(sdev);
1823 vdevice->vtarget = starget->hostdata;
1825 if (sdev->channel == MPTSAS_RAID_CHANNEL)
1828 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
1829 mutex_lock(&ioc->sas_topology_mutex);
1830 list_for_each_entry(p, &ioc->sas_topology, list) {
1831 for (i = 0; i < p->num_phys; i++) {
1832 if (p->phy_info[i].attached.sas_address !=
1833 rphy->identify.sas_address)
1835 vdevice->lun = sdev->lun;
1837 * Exposing hidden raid components
1839 if (mptscsih_is_phys_disk(ioc,
1840 p->phy_info[i].attached.channel,
1841 p->phy_info[i].attached.id))
1842 sdev->no_uld_attach = 1;
1843 mutex_unlock(&ioc->sas_topology_mutex);
1847 mutex_unlock(&ioc->sas_topology_mutex);
1853 vdevice->vtarget->num_luns++;
1854 sdev->hostdata = vdevice;
1859 mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1863 VirtDevice *vdevice = SCpnt->device->hostdata;
1865 if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
1866 SCpnt->result = DID_NO_CONNECT << 16;
1871 hd = shost_priv(SCpnt->device->host);
1874 if (ioc->sas_discovery_quiesce_io)
1875 return SCSI_MLQUEUE_HOST_BUSY;
1877 // scsi_print_command(SCpnt);
1879 return mptscsih_qcmd(SCpnt,done);
1883 static struct scsi_host_template mptsas_driver_template = {
1884 .module = THIS_MODULE,
1885 .proc_name = "mptsas",
1886 .proc_info = mptscsih_proc_info,
1887 .name = "MPT SPI Host",
1888 .info = mptscsih_info,
1889 .queuecommand = mptsas_qcmd,
1890 .target_alloc = mptsas_target_alloc,
1891 .slave_alloc = mptsas_slave_alloc,
1892 .slave_configure = mptsas_slave_configure,
1893 .target_destroy = mptsas_target_destroy,
1894 .slave_destroy = mptscsih_slave_destroy,
1895 .change_queue_depth = mptscsih_change_queue_depth,
1896 .eh_abort_handler = mptscsih_abort,
1897 .eh_device_reset_handler = mptscsih_dev_reset,
1898 .eh_bus_reset_handler = mptscsih_bus_reset,
1899 .eh_host_reset_handler = mptscsih_host_reset,
1900 .bios_param = mptscsih_bios_param,
1901 .can_queue = MPT_SAS_CAN_QUEUE,
1903 .sg_tablesize = MPT_SCSI_SG_DEPTH,
1904 .max_sectors = 8192,
1906 .use_clustering = ENABLE_CLUSTERING,
1907 .shost_attrs = mptscsih_host_attrs,
1910 static int mptsas_get_linkerrors(struct sas_phy *phy)
1912 MPT_ADAPTER *ioc = phy_to_ioc(phy);
1913 ConfigExtendedPageHeader_t hdr;
1915 SasPhyPage1_t *buffer;
1916 dma_addr_t dma_handle;
1919 /* FIXME: only have link errors on local phys */
1920 if (!scsi_is_sas_phy_local(phy))
1923 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
1924 hdr.ExtPageLength = 0;
1925 hdr.PageNumber = 1 /* page number 1*/;
1928 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1929 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
1931 cfg.cfghdr.ehdr = &hdr;
1933 cfg.pageAddr = phy->identify.phy_identifier;
1934 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1935 cfg.dir = 0; /* read */
1936 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
1938 error = mpt_config(ioc, &cfg);
1941 if (!hdr.ExtPageLength)
1944 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1949 cfg.physAddr = dma_handle;
1950 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1952 error = mpt_config(ioc, &cfg);
1954 goto out_free_consistent;
1956 mptsas_print_phy_pg1(ioc, buffer);
1958 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
1959 phy->running_disparity_error_count =
1960 le32_to_cpu(buffer->RunningDisparityErrorCount);
1961 phy->loss_of_dword_sync_count =
1962 le32_to_cpu(buffer->LossDwordSynchCount);
1963 phy->phy_reset_problem_count =
1964 le32_to_cpu(buffer->PhyResetProblemCount);
1966 out_free_consistent:
1967 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1968 buffer, dma_handle);
1972 static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
1973 MPT_FRAME_HDR *reply)
1975 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1976 if (reply != NULL) {
1977 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID;
1978 memcpy(ioc->sas_mgmt.reply, reply,
1979 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
1982 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
1983 ioc->sas_mgmt.status &= ~MPT_MGMT_STATUS_PENDING;
1984 complete(&ioc->sas_mgmt.done);
1990 static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
1992 MPT_ADAPTER *ioc = phy_to_ioc(phy);
1993 SasIoUnitControlRequest_t *req;
1994 SasIoUnitControlReply_t *reply;
1997 unsigned long timeleft;
1998 int error = -ERESTARTSYS;
2000 /* FIXME: fusion doesn't allow non-local phy reset */
2001 if (!scsi_is_sas_phy_local(phy))
2004 /* not implemented for expanders */
2005 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
2008 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
2011 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2017 hdr = (MPIHeader_t *) mf;
2018 req = (SasIoUnitControlRequest_t *)mf;
2019 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
2020 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
2021 req->MsgContext = hdr->MsgContext;
2022 req->Operation = hard_reset ?
2023 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
2024 req->PhyNum = phy->identify.phy_identifier;
2026 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2027 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2029 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
2032 /* On timeout reset the board */
2033 mpt_free_msg_frame(ioc, mf);
2034 mpt_HardResetHandler(ioc, CAN_SLEEP);
2039 /* a reply frame is expected */
2040 if ((ioc->sas_mgmt.status &
2041 MPT_MGMT_STATUS_RF_VALID) == 0) {
2046 /* process the completed Reply Message Frame */
2047 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
2048 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
2049 printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
2050 ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo);
2058 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2059 mutex_unlock(&ioc->sas_mgmt.mutex);
2065 mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
2067 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2069 struct mptsas_portinfo *p;
2070 struct mptsas_enclosure enclosure_info;
2071 u64 enclosure_handle;
2073 mutex_lock(&ioc->sas_topology_mutex);
2074 list_for_each_entry(p, &ioc->sas_topology, list) {
2075 for (i = 0; i < p->num_phys; i++) {
2076 if (p->phy_info[i].attached.sas_address ==
2077 rphy->identify.sas_address) {
2078 enclosure_handle = p->phy_info[i].
2079 attached.handle_enclosure;
2084 mutex_unlock(&ioc->sas_topology_mutex);
2088 mutex_unlock(&ioc->sas_topology_mutex);
2089 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
2090 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
2091 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
2092 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
2094 *identifier = enclosure_info.enclosure_logical_id;
2099 mptsas_get_bay_identifier(struct sas_rphy *rphy)
2101 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2102 struct mptsas_portinfo *p;
2105 mutex_lock(&ioc->sas_topology_mutex);
2106 list_for_each_entry(p, &ioc->sas_topology, list) {
2107 for (i = 0; i < p->num_phys; i++) {
2108 if (p->phy_info[i].attached.sas_address ==
2109 rphy->identify.sas_address) {
2110 rc = p->phy_info[i].attached.slot;
2117 mutex_unlock(&ioc->sas_topology_mutex);
2121 static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
2122 struct request *req)
2124 MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
2126 SmpPassthroughRequest_t *smpreq;
2127 struct request *rsp = req->next_rq;
2130 unsigned long timeleft;
2132 dma_addr_t dma_addr_in = 0;
2133 dma_addr_t dma_addr_out = 0;
2134 u64 sas_address = 0;
2137 printk(MYIOC_s_ERR_FMT "%s: the smp response space is missing\n",
2138 ioc->name, __func__);
2142 /* do we need to support multiple segments? */
2143 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
2144 printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n",
2145 ioc->name, __func__, req->bio->bi_vcnt, blk_rq_bytes(req),
2146 rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
2150 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
2154 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2160 smpreq = (SmpPassthroughRequest_t *)mf;
2161 memset(smpreq, 0, sizeof(*smpreq));
2163 smpreq->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4);
2164 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
2167 sas_address = rphy->identify.sas_address;
2169 struct mptsas_portinfo *port_info;
2171 mutex_lock(&ioc->sas_topology_mutex);
2172 port_info = ioc->hba_port_info;
2173 if (port_info && port_info->phy_info)
2175 port_info->phy_info[0].phy->identify.sas_address;
2176 mutex_unlock(&ioc->sas_topology_mutex);
2179 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
2182 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
2185 flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2186 MPI_SGE_FLAGS_END_OF_BUFFER |
2187 MPI_SGE_FLAGS_DIRECTION)
2188 << MPI_SGE_FLAGS_SHIFT;
2189 flagsLength |= (blk_rq_bytes(req) - 4);
2191 dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
2192 blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
2195 ioc->add_sge(psge, flagsLength, dma_addr_out);
2196 psge += ioc->SGE_size;
2199 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2200 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2201 MPI_SGE_FLAGS_IOC_TO_HOST |
2202 MPI_SGE_FLAGS_END_OF_BUFFER;
2204 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2205 flagsLength |= blk_rq_bytes(rsp) + 4;
2206 dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio),
2207 blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
2210 ioc->add_sge(psge, flagsLength, dma_addr_in);
2212 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2213 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2215 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
2217 printk(MYIOC_s_ERR_FMT "%s: smp timeout!\n", ioc->name, __func__);
2218 /* On timeout reset the board */
2219 mpt_HardResetHandler(ioc, CAN_SLEEP);
2225 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
2226 SmpPassthroughReply_t *smprep;
2228 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
2229 memcpy(req->sense, smprep, sizeof(*smprep));
2230 req->sense_len = sizeof(*smprep);
2232 rsp->resid_len -= smprep->ResponseDataLength;
2234 printk(MYIOC_s_ERR_FMT
2235 "%s: smp passthru reply failed to be returned\n",
2236 ioc->name, __func__);
2241 pci_unmap_single(ioc->pcidev, dma_addr_out, blk_rq_bytes(req),
2242 PCI_DMA_BIDIRECTIONAL);
2244 pci_unmap_single(ioc->pcidev, dma_addr_in, blk_rq_bytes(rsp),
2245 PCI_DMA_BIDIRECTIONAL);
2248 mpt_free_msg_frame(ioc, mf);
2250 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2251 mutex_unlock(&ioc->sas_mgmt.mutex);
2256 static struct sas_function_template mptsas_transport_functions = {
2257 .get_linkerrors = mptsas_get_linkerrors,
2258 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
2259 .get_bay_identifier = mptsas_get_bay_identifier,
2260 .phy_reset = mptsas_phy_reset,
2261 .smp_handler = mptsas_smp_handler,
2264 static struct scsi_transport_template *mptsas_transport_template;
2267 mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
2269 ConfigExtendedPageHeader_t hdr;
2271 SasIOUnitPage0_t *buffer;
2272 dma_addr_t dma_handle;
2275 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
2276 hdr.ExtPageLength = 0;
2280 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2281 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2283 cfg.cfghdr.ehdr = &hdr;
2286 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2287 cfg.dir = 0; /* read */
2288 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2290 error = mpt_config(ioc, &cfg);
2293 if (!hdr.ExtPageLength) {
2298 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2305 cfg.physAddr = dma_handle;
2306 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2308 error = mpt_config(ioc, &cfg);
2310 goto out_free_consistent;
2312 port_info->num_phys = buffer->NumPhys;
2313 port_info->phy_info = kcalloc(port_info->num_phys,
2314 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
2315 if (!port_info->phy_info) {
2317 goto out_free_consistent;
2320 ioc->nvdata_version_persistent =
2321 le16_to_cpu(buffer->NvdataVersionPersistent);
2322 ioc->nvdata_version_default =
2323 le16_to_cpu(buffer->NvdataVersionDefault);
2325 for (i = 0; i < port_info->num_phys; i++) {
2326 mptsas_print_phy_data(ioc, &buffer->PhyData[i]);
2327 port_info->phy_info[i].phy_id = i;
2328 port_info->phy_info[i].port_id =
2329 buffer->PhyData[i].Port;
2330 port_info->phy_info[i].negotiated_link_rate =
2331 buffer->PhyData[i].NegotiatedLinkRate;
2332 port_info->phy_info[i].portinfo = port_info;
2333 port_info->phy_info[i].handle =
2334 le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
2337 out_free_consistent:
2338 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2339 buffer, dma_handle);
2345 mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
2347 ConfigExtendedPageHeader_t hdr;
2349 SasIOUnitPage1_t *buffer;
2350 dma_addr_t dma_handle;
2352 u16 device_missing_delay;
2354 memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
2355 memset(&cfg, 0, sizeof(CONFIGPARMS));
2357 cfg.cfghdr.ehdr = &hdr;
2358 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2359 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2360 cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2361 cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2362 cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION;
2363 cfg.cfghdr.ehdr->PageNumber = 1;
2365 error = mpt_config(ioc, &cfg);
2368 if (!hdr.ExtPageLength) {
2373 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2380 cfg.physAddr = dma_handle;
2381 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2383 error = mpt_config(ioc, &cfg);
2385 goto out_free_consistent;
2387 ioc->io_missing_delay =
2388 le16_to_cpu(buffer->IODeviceMissingDelay);
2389 device_missing_delay = le16_to_cpu(buffer->ReportDeviceMissingDelay);
2390 ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ?
2391 (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 :
2392 device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2394 out_free_consistent:
2395 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2396 buffer, dma_handle);
2402 mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2403 u32 form, u32 form_specific)
2405 ConfigExtendedPageHeader_t hdr;
2407 SasPhyPage0_t *buffer;
2408 dma_addr_t dma_handle;
2411 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
2412 hdr.ExtPageLength = 0;
2416 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2417 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
2419 cfg.cfghdr.ehdr = &hdr;
2420 cfg.dir = 0; /* read */
2421 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2423 /* Get Phy Pg 0 for each Phy. */
2425 cfg.pageAddr = form + form_specific;
2426 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2428 error = mpt_config(ioc, &cfg);
2432 if (!hdr.ExtPageLength) {
2437 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2444 cfg.physAddr = dma_handle;
2445 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2447 error = mpt_config(ioc, &cfg);
2449 goto out_free_consistent;
2451 mptsas_print_phy_pg0(ioc, buffer);
2453 phy_info->hw_link_rate = buffer->HwLinkRate;
2454 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2455 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2456 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2458 out_free_consistent:
2459 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2460 buffer, dma_handle);
2466 mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
2467 u32 form, u32 form_specific)
2469 ConfigExtendedPageHeader_t hdr;
2471 SasDevicePage0_t *buffer;
2472 dma_addr_t dma_handle;
2476 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
2477 hdr.ExtPageLength = 0;
2481 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2482 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
2484 cfg.cfghdr.ehdr = &hdr;
2485 cfg.pageAddr = form + form_specific;
2487 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2488 cfg.dir = 0; /* read */
2489 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2491 memset(device_info, 0, sizeof(struct mptsas_devinfo));
2492 error = mpt_config(ioc, &cfg);
2495 if (!hdr.ExtPageLength) {
2500 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2507 cfg.physAddr = dma_handle;
2508 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2510 error = mpt_config(ioc, &cfg);
2512 goto out_free_consistent;
2514 mptsas_print_device_pg0(ioc, buffer);
2516 memset(device_info, 0, sizeof(struct mptsas_devinfo));
2517 device_info->handle = le16_to_cpu(buffer->DevHandle);
2518 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
2519 device_info->handle_enclosure =
2520 le16_to_cpu(buffer->EnclosureHandle);
2521 device_info->slot = le16_to_cpu(buffer->Slot);
2522 device_info->phy_id = buffer->PhyNum;
2523 device_info->port_id = buffer->PhysicalPort;
2524 device_info->id = buffer->TargetID;
2525 device_info->phys_disk_num = ~0;
2526 device_info->channel = buffer->Bus;
2527 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
2528 device_info->sas_address = le64_to_cpu(sas_address);
2529 device_info->device_info =
2530 le32_to_cpu(buffer->DeviceInfo);
2532 out_free_consistent:
2533 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2534 buffer, dma_handle);
2540 mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
2541 u32 form, u32 form_specific)
2543 ConfigExtendedPageHeader_t hdr;
2545 SasExpanderPage0_t *buffer;
2546 dma_addr_t dma_handle;
2550 memset(port_info, 0, sizeof(struct mptsas_portinfo));
2551 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
2552 hdr.ExtPageLength = 0;
2556 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2557 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2559 cfg.cfghdr.ehdr = &hdr;
2561 cfg.pageAddr = form + form_specific;
2562 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2563 cfg.dir = 0; /* read */
2564 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2566 memset(port_info, 0, sizeof(struct mptsas_portinfo));
2567 error = mpt_config(ioc, &cfg);
2571 if (!hdr.ExtPageLength) {
2576 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2583 cfg.physAddr = dma_handle;
2584 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2586 error = mpt_config(ioc, &cfg);
2588 goto out_free_consistent;
2590 if (!buffer->NumPhys) {
2592 goto out_free_consistent;
2595 /* save config data */
2596 port_info->num_phys = (buffer->NumPhys) ? buffer->NumPhys : 1;
2597 port_info->phy_info = kcalloc(port_info->num_phys,
2598 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
2599 if (!port_info->phy_info) {
2601 goto out_free_consistent;
2604 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
2605 for (i = 0; i < port_info->num_phys; i++) {
2606 port_info->phy_info[i].portinfo = port_info;
2607 port_info->phy_info[i].handle =
2608 le16_to_cpu(buffer->DevHandle);
2609 port_info->phy_info[i].identify.sas_address =
2610 le64_to_cpu(sas_address);
2611 port_info->phy_info[i].identify.handle_parent =
2612 le16_to_cpu(buffer->ParentDevHandle);
2615 out_free_consistent:
2616 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2617 buffer, dma_handle);
2623 mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2624 u32 form, u32 form_specific)
2626 ConfigExtendedPageHeader_t hdr;
2628 SasExpanderPage1_t *buffer;
2629 dma_addr_t dma_handle;
2632 hdr.PageVersion = MPI_SASEXPANDER1_PAGEVERSION;
2633 hdr.ExtPageLength = 0;
2637 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2638 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2640 cfg.cfghdr.ehdr = &hdr;
2642 cfg.pageAddr = form + form_specific;
2643 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2644 cfg.dir = 0; /* read */
2645 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2647 error = mpt_config(ioc, &cfg);
2651 if (!hdr.ExtPageLength) {
2656 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2663 cfg.physAddr = dma_handle;
2664 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2666 error = mpt_config(ioc, &cfg);
2668 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
2674 goto out_free_consistent;
2677 mptsas_print_expander_pg1(ioc, buffer);
2679 /* save config data */
2680 phy_info->phy_id = buffer->PhyIdentifier;
2681 phy_info->port_id = buffer->PhysicalPort;
2682 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
2683 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2684 phy_info->hw_link_rate = buffer->HwLinkRate;
2685 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2686 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2688 out_free_consistent:
2689 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2690 buffer, dma_handle);
2696 mptsas_parse_device_info(struct sas_identify *identify,
2697 struct mptsas_devinfo *device_info)
2701 identify->sas_address = device_info->sas_address;
2702 identify->phy_identifier = device_info->phy_id;
2705 * Fill in Phy Initiator Port Protocol.
2706 * Bits 6:3, more than one bit can be set, fall through cases.
2708 protocols = device_info->device_info & 0x78;
2709 identify->initiator_port_protocols = 0;
2710 if (protocols & MPI_SAS_DEVICE_INFO_SSP_INITIATOR)
2711 identify->initiator_port_protocols |= SAS_PROTOCOL_SSP;
2712 if (protocols & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
2713 identify->initiator_port_protocols |= SAS_PROTOCOL_STP;
2714 if (protocols & MPI_SAS_DEVICE_INFO_SMP_INITIATOR)
2715 identify->initiator_port_protocols |= SAS_PROTOCOL_SMP;
2716 if (protocols & MPI_SAS_DEVICE_INFO_SATA_HOST)
2717 identify->initiator_port_protocols |= SAS_PROTOCOL_SATA;
2720 * Fill in Phy Target Port Protocol.
2721 * Bits 10:7, more than one bit can be set, fall through cases.
2723 protocols = device_info->device_info & 0x780;
2724 identify->target_port_protocols = 0;
2725 if (protocols & MPI_SAS_DEVICE_INFO_SSP_TARGET)
2726 identify->target_port_protocols |= SAS_PROTOCOL_SSP;
2727 if (protocols & MPI_SAS_DEVICE_INFO_STP_TARGET)
2728 identify->target_port_protocols |= SAS_PROTOCOL_STP;
2729 if (protocols & MPI_SAS_DEVICE_INFO_SMP_TARGET)
2730 identify->target_port_protocols |= SAS_PROTOCOL_SMP;
2731 if (protocols & MPI_SAS_DEVICE_INFO_SATA_DEVICE)
2732 identify->target_port_protocols |= SAS_PROTOCOL_SATA;
2735 * Fill in Attached device type.
2737 switch (device_info->device_info &
2738 MPI_SAS_DEVICE_INFO_MASK_DEVICE_TYPE) {
2739 case MPI_SAS_DEVICE_INFO_NO_DEVICE:
2740 identify->device_type = SAS_PHY_UNUSED;
2742 case MPI_SAS_DEVICE_INFO_END_DEVICE:
2743 identify->device_type = SAS_END_DEVICE;
2745 case MPI_SAS_DEVICE_INFO_EDGE_EXPANDER:
2746 identify->device_type = SAS_EDGE_EXPANDER_DEVICE;
2748 case MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER:
2749 identify->device_type = SAS_FANOUT_EXPANDER_DEVICE;
2754 static int mptsas_probe_one_phy(struct device *dev,
2755 struct mptsas_phyinfo *phy_info, int index, int local)
2758 struct sas_phy *phy;
2759 struct sas_port *port;
2767 if (!phy_info->phy) {
2768 phy = sas_phy_alloc(dev, index);
2774 phy = phy_info->phy;
2776 mptsas_parse_device_info(&phy->identify, &phy_info->identify);
2779 * Set Negotiated link rate.
2781 switch (phy_info->negotiated_link_rate) {
2782 case MPI_SAS_IOUNIT0_RATE_PHY_DISABLED:
2783 phy->negotiated_linkrate = SAS_PHY_DISABLED;
2785 case MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION:
2786 phy->negotiated_linkrate = SAS_LINK_RATE_FAILED;
2788 case MPI_SAS_IOUNIT0_RATE_1_5:
2789 phy->negotiated_linkrate = SAS_LINK_RATE_1_5_GBPS;
2791 case MPI_SAS_IOUNIT0_RATE_3_0:
2792 phy->negotiated_linkrate = SAS_LINK_RATE_3_0_GBPS;
2794 case MPI_SAS_IOUNIT0_RATE_SATA_OOB_COMPLETE:
2795 case MPI_SAS_IOUNIT0_RATE_UNKNOWN:
2797 phy->negotiated_linkrate = SAS_LINK_RATE_UNKNOWN;
2802 * Set Max hardware link rate.
2804 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
2805 case MPI_SAS_PHY0_HWRATE_MAX_RATE_1_5:
2806 phy->maximum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
2808 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
2809 phy->maximum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
2816 * Set Max programmed link rate.
2818 switch (phy_info->programmed_link_rate &
2819 MPI_SAS_PHY0_PRATE_MAX_RATE_MASK) {
2820 case MPI_SAS_PHY0_PRATE_MAX_RATE_1_5:
2821 phy->maximum_linkrate = SAS_LINK_RATE_1_5_GBPS;
2823 case MPI_SAS_PHY0_PRATE_MAX_RATE_3_0:
2824 phy->maximum_linkrate = SAS_LINK_RATE_3_0_GBPS;
2831 * Set Min hardware link rate.
2833 switch (phy_info->hw_link_rate & MPI_SAS_PHY0_HWRATE_MIN_RATE_MASK) {
2834 case MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5:
2835 phy->minimum_linkrate_hw = SAS_LINK_RATE_1_5_GBPS;
2837 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
2838 phy->minimum_linkrate_hw = SAS_LINK_RATE_3_0_GBPS;
2845 * Set Min programmed link rate.
2847 switch (phy_info->programmed_link_rate &
2848 MPI_SAS_PHY0_PRATE_MIN_RATE_MASK) {
2849 case MPI_SAS_PHY0_PRATE_MIN_RATE_1_5:
2850 phy->minimum_linkrate = SAS_LINK_RATE_1_5_GBPS;
2852 case MPI_SAS_PHY0_PRATE_MIN_RATE_3_0:
2853 phy->minimum_linkrate = SAS_LINK_RATE_3_0_GBPS;
2859 if (!phy_info->phy) {
2861 error = sas_phy_add(phy);
2866 phy_info->phy = phy;
2869 if (!phy_info->attached.handle ||
2870 !phy_info->port_details)
2873 port = mptsas_get_port(phy_info);
2874 ioc = phy_to_ioc(phy_info->phy);
2876 if (phy_info->sas_port_add_phy) {
2879 port = sas_port_alloc_num(dev);
2884 error = sas_port_add(port);
2886 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2887 "%s: exit at line=%d\n", ioc->name,
2888 __func__, __LINE__));
2891 mptsas_set_port(ioc, phy_info, port);
2892 devtprintk(ioc, dev_printk(KERN_DEBUG, &port->dev,
2893 MYIOC_s_FMT "add port %d, sas_addr (0x%llx)\n",
2894 ioc->name, port->port_identifier,
2895 (unsigned long long)phy_info->
2896 attached.sas_address));
2898 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2899 "sas_port_add_phy: phy_id=%d\n",
2900 ioc->name, phy_info->phy_id));
2901 sas_port_add_phy(port, phy_info->phy);
2902 phy_info->sas_port_add_phy = 0;
2903 devtprintk(ioc, dev_printk(KERN_DEBUG, &phy_info->phy->dev,
2904 MYIOC_s_FMT "add phy %d, phy-obj (0x%p)\n", ioc->name,
2905 phy_info->phy_id, phy_info->phy));
2907 if (!mptsas_get_rphy(phy_info) && port && !port->rphy) {
2909 struct sas_rphy *rphy;
2910 struct device *parent;
2911 struct sas_identify identify;
2913 parent = dev->parent->parent;
2915 * Let the hotplug_work thread handle processing
2916 * the adding/removing of devices that occur
2917 * after start of day.
2919 if (mptsas_is_end_device(&phy_info->attached) &&
2920 phy_info->attached.handle_parent) {
2924 mptsas_parse_device_info(&identify, &phy_info->attached);
2925 if (scsi_is_host_device(parent)) {
2926 struct mptsas_portinfo *port_info;
2929 port_info = ioc->hba_port_info;
2931 for (i = 0; i < port_info->num_phys; i++)
2932 if (port_info->phy_info[i].identify.sas_address ==
2933 identify.sas_address) {
2934 sas_port_mark_backlink(port);
2938 } else if (scsi_is_sas_rphy(parent)) {
2939 struct sas_rphy *parent_rphy = dev_to_rphy(parent);
2940 if (identify.sas_address ==
2941 parent_rphy->identify.sas_address) {
2942 sas_port_mark_backlink(port);
2947 switch (identify.device_type) {
2948 case SAS_END_DEVICE:
2949 rphy = sas_end_device_alloc(port);
2951 case SAS_EDGE_EXPANDER_DEVICE:
2952 case SAS_FANOUT_EXPANDER_DEVICE:
2953 rphy = sas_expander_alloc(port, identify.device_type);
2960 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2961 "%s: exit at line=%d\n", ioc->name,
2962 __func__, __LINE__));
2966 rphy->identify = identify;
2967 error = sas_rphy_add(rphy);
2969 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
2970 "%s: exit at line=%d\n", ioc->name,
2971 __func__, __LINE__));
2972 sas_rphy_free(rphy);
2975 mptsas_set_rphy(ioc, phy_info, rphy);
2983 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
2985 struct mptsas_portinfo *port_info, *hba;
2986 int error = -ENOMEM, i;
2988 hba = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
2992 error = mptsas_sas_io_unit_pg0(ioc, hba);
2994 goto out_free_port_info;
2996 mptsas_sas_io_unit_pg1(ioc);
2997 mutex_lock(&ioc->sas_topology_mutex);
2998 port_info = ioc->hba_port_info;
3000 ioc->hba_port_info = port_info = hba;
3001 ioc->hba_port_num_phy = port_info->num_phys;
3002 list_add_tail(&port_info->list, &ioc->sas_topology);
3004 for (i = 0; i < hba->num_phys; i++) {
3005 port_info->phy_info[i].negotiated_link_rate =
3006 hba->phy_info[i].negotiated_link_rate;
3007 port_info->phy_info[i].handle =
3008 hba->phy_info[i].handle;
3009 port_info->phy_info[i].port_id =
3010 hba->phy_info[i].port_id;
3012 kfree(hba->phy_info);
3016 mutex_unlock(&ioc->sas_topology_mutex);
3017 #if defined(CPQ_CIM)
3018 ioc->num_ports = port_info->num_phys;
3020 for (i = 0; i < port_info->num_phys; i++) {
3021 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
3022 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
3023 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
3024 port_info->phy_info[i].identify.handle =
3025 port_info->phy_info[i].handle;
3026 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
3027 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3028 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3029 port_info->phy_info[i].identify.handle);
3030 if (!ioc->hba_port_sas_addr)
3031 ioc->hba_port_sas_addr =
3032 port_info->phy_info[i].identify.sas_address;
3033 port_info->phy_info[i].identify.phy_id =
3034 port_info->phy_info[i].phy_id = i;
3035 if (port_info->phy_info[i].attached.handle)
3036 mptsas_sas_device_pg0(ioc,
3037 &port_info->phy_info[i].attached,
3038 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3039 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3040 port_info->phy_info[i].attached.handle);
3043 mptsas_setup_wide_ports(ioc, port_info);
3045 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
3046 mptsas_probe_one_phy(&ioc->sh->shost_gendev,
3047 &port_info->phy_info[i], ioc->sas_index, 1);
3058 mptsas_expander_refresh(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
3060 struct mptsas_portinfo *parent;
3061 struct device *parent_dev;
3062 struct sas_rphy *rphy;
3064 u64 sas_address; /* expander sas address */
3067 handle = port_info->phy_info[0].handle;
3068 sas_address = port_info->phy_info[0].identify.sas_address;
3069 for (i = 0; i < port_info->num_phys; i++) {
3070 mptsas_sas_expander_pg1(ioc, &port_info->phy_info[i],
3071 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE_PHY_NUM <<
3072 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), (i << 16) + handle);
3074 mptsas_sas_device_pg0(ioc,
3075 &port_info->phy_info[i].identify,
3076 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3077 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3078 port_info->phy_info[i].identify.handle);
3079 port_info->phy_info[i].identify.phy_id =
3080 port_info->phy_info[i].phy_id;
3082 if (port_info->phy_info[i].attached.handle) {
3083 mptsas_sas_device_pg0(ioc,
3084 &port_info->phy_info[i].attached,
3085 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
3086 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3087 port_info->phy_info[i].attached.handle);
3088 port_info->phy_info[i].attached.phy_id =
3089 port_info->phy_info[i].phy_id;
3093 mutex_lock(&ioc->sas_topology_mutex);
3094 parent = mptsas_find_portinfo_by_handle(ioc,
3095 port_info->phy_info[0].identify.handle_parent);
3097 mutex_unlock(&ioc->sas_topology_mutex);
3100 for (i = 0, parent_dev = NULL; i < parent->num_phys && !parent_dev;
3102 if (parent->phy_info[i].attached.sas_address == sas_address) {
3103 rphy = mptsas_get_rphy(&parent->phy_info[i]);
3104 parent_dev = &rphy->dev;
3107 mutex_unlock(&ioc->sas_topology_mutex);
3109 mptsas_setup_wide_ports(ioc, port_info);
3110 for (i = 0; i < port_info->num_phys; i++, ioc->sas_index++)
3111 mptsas_probe_one_phy(parent_dev, &port_info->phy_info[i],
3116 mptsas_expander_event_add(MPT_ADAPTER *ioc,
3117 MpiEventDataSasExpanderStatusChange_t *expander_data)
3119 struct mptsas_portinfo *port_info;
3123 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
3126 port_info->num_phys = (expander_data->NumPhys) ?
3127 expander_data->NumPhys : 1;
3128 port_info->phy_info = kcalloc(port_info->num_phys,
3129 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
3130 if (!port_info->phy_info)
3132 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
3133 for (i = 0; i < port_info->num_phys; i++) {
3134 port_info->phy_info[i].portinfo = port_info;
3135 port_info->phy_info[i].handle =
3136 le16_to_cpu(expander_data->DevHandle);
3137 port_info->phy_info[i].identify.sas_address =
3138 le64_to_cpu(sas_address);
3139 port_info->phy_info[i].identify.handle_parent =
3140 le16_to_cpu(expander_data->ParentDevHandle);
3143 mutex_lock(&ioc->sas_topology_mutex);
3144 list_add_tail(&port_info->list, &ioc->sas_topology);
3145 mutex_unlock(&ioc->sas_topology_mutex);
3147 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3148 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3149 (unsigned long long)sas_address);
3151 mptsas_expander_refresh(ioc, port_info);
3155 * mptsas_delete_expander_siblings - remove siblings attached to expander
3156 * @ioc: Pointer to MPT_ADAPTER structure
3157 * @parent: the parent port_info object
3158 * @expander: the expander port_info object
3161 mptsas_delete_expander_siblings(MPT_ADAPTER *ioc, struct mptsas_portinfo
3162 *parent, struct mptsas_portinfo *expander)
3164 struct mptsas_phyinfo *phy_info;
3165 struct mptsas_portinfo *port_info;
3166 struct sas_rphy *rphy;
3169 phy_info = expander->phy_info;
3170 for (i = 0; i < expander->num_phys; i++, phy_info++) {
3171 rphy = mptsas_get_rphy(phy_info);
3174 if (rphy->identify.device_type == SAS_END_DEVICE)
3175 mptsas_del_end_device(ioc, phy_info);
3178 phy_info = expander->phy_info;
3179 for (i = 0; i < expander->num_phys; i++, phy_info++) {
3180 rphy = mptsas_get_rphy(phy_info);
3183 if (rphy->identify.device_type ==
3184 MPI_SAS_DEVICE_INFO_EDGE_EXPANDER ||
3185 rphy->identify.device_type ==
3186 MPI_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
3187 port_info = mptsas_find_portinfo_by_sas_address(ioc,
3188 rphy->identify.sas_address);
3191 if (port_info == parent) /* backlink rphy */
3194 Delete this expander even if the expdevpage is exists
3195 because the parent expander is already deleted
3197 mptsas_expander_delete(ioc, port_info, 1);
3204 * mptsas_expander_delete - remove this expander
3205 * @ioc: Pointer to MPT_ADAPTER structure
3206 * @port_info: expander port_info struct
3207 * @force: Flag to forcefully delete the expander
3211 static void mptsas_expander_delete(MPT_ADAPTER *ioc,
3212 struct mptsas_portinfo *port_info, u8 force)
3215 struct mptsas_portinfo *parent;
3217 u64 expander_sas_address;
3218 struct mptsas_phyinfo *phy_info;
3219 struct mptsas_portinfo buffer;
3220 struct mptsas_portinfo_details *port_details;
3221 struct sas_port *port;
3226 /* see if expander is still there before deleting */
3227 mptsas_sas_expander_pg0(ioc, &buffer,
3228 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
3229 MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
3230 port_info->phy_info[0].identify.handle);
3232 if (buffer.num_phys) {
3233 kfree(buffer.phy_info);
3240 * Obtain the port_info instance to the parent port
3242 port_details = NULL;
3243 expander_sas_address =
3244 port_info->phy_info[0].identify.sas_address;
3245 parent = mptsas_find_portinfo_by_handle(ioc,
3246 port_info->phy_info[0].identify.handle_parent);
3247 mptsas_delete_expander_siblings(ioc, parent, port_info);
3252 * Delete rphys in the parent that point
3255 phy_info = parent->phy_info;
3257 for (i = 0; i < parent->num_phys; i++, phy_info++) {
3260 if (phy_info->attached.sas_address !=
3261 expander_sas_address)
3264 port = mptsas_get_port(phy_info);
3265 port_details = phy_info->port_details;
3267 dev_printk(KERN_DEBUG, &phy_info->phy->dev,
3268 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n", ioc->name,
3269 phy_info->phy_id, phy_info->phy);
3270 sas_port_delete_phy(port, phy_info->phy);
3273 dev_printk(KERN_DEBUG, &port->dev,
3274 MYIOC_s_FMT "delete port %d, sas_addr (0x%llx)\n",
3275 ioc->name, port->port_identifier,
3276 (unsigned long long)expander_sas_address);
3277 sas_port_delete(port);
3278 mptsas_port_delete(ioc, port_details);
3282 printk(MYIOC_s_INFO_FMT "delete expander: num_phys %d, "
3283 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3284 (unsigned long long)expander_sas_address);
3289 list_del(&port_info->list);
3290 kfree(port_info->phy_info);
3296 * mptsas_send_expander_event - expanders events
3297 * @ioc: Pointer to MPT_ADAPTER structure
3298 * @expander_data: event data
3301 * This function handles adding, removing, and refreshing
3302 * device handles within the expander objects.
3305 mptsas_send_expander_event(struct fw_event_work *fw_event)
3308 MpiEventDataSasExpanderStatusChange_t *expander_data;
3309 struct mptsas_portinfo *port_info;
3313 ioc = fw_event->ioc;
3314 expander_data = (MpiEventDataSasExpanderStatusChange_t *)
3315 fw_event->event_data;
3316 memcpy(&sas_address, &expander_data->SASAddress, sizeof(__le64));
3317 sas_address = le64_to_cpu(sas_address);
3318 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3320 if (expander_data->ReasonCode == MPI_EVENT_SAS_EXP_RC_ADDED) {
3322 for (i = 0; i < port_info->num_phys; i++) {
3323 port_info->phy_info[i].portinfo = port_info;
3324 port_info->phy_info[i].handle =
3325 le16_to_cpu(expander_data->DevHandle);
3326 port_info->phy_info[i].identify.sas_address =
3327 le64_to_cpu(sas_address);
3328 port_info->phy_info[i].identify.handle_parent =
3329 le16_to_cpu(expander_data->ParentDevHandle);
3331 mptsas_expander_refresh(ioc, port_info);
3332 } else if (!port_info && expander_data->NumPhys)
3333 mptsas_expander_event_add(ioc, expander_data);
3334 } else if (expander_data->ReasonCode ==
3335 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING)
3336 mptsas_expander_delete(ioc, port_info, 0);
3338 mptsas_free_fw_event(ioc, fw_event);
3343 * mptsas_expander_add -
3344 * @ioc: Pointer to MPT_ADAPTER structure
3348 struct mptsas_portinfo *
3349 mptsas_expander_add(MPT_ADAPTER *ioc, u16 handle)
3351 struct mptsas_portinfo buffer, *port_info;
3354 if ((mptsas_sas_expander_pg0(ioc, &buffer,
3355 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
3356 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)))
3359 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_ATOMIC);
3361 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3362 "%s: exit at line=%d\n", ioc->name,
3363 __func__, __LINE__));
3366 port_info->num_phys = buffer.num_phys;
3367 port_info->phy_info = buffer.phy_info;
3368 for (i = 0; i < port_info->num_phys; i++)
3369 port_info->phy_info[i].portinfo = port_info;
3370 mutex_lock(&ioc->sas_topology_mutex);
3371 list_add_tail(&port_info->list, &ioc->sas_topology);
3372 mutex_unlock(&ioc->sas_topology_mutex);
3373 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3374 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3375 (unsigned long long)buffer.phy_info[0].identify.sas_address);
3376 mptsas_expander_refresh(ioc, port_info);
3381 mptsas_send_link_status_event(struct fw_event_work *fw_event)
3384 MpiEventDataSasPhyLinkStatus_t *link_data;
3385 struct mptsas_portinfo *port_info;
3386 struct mptsas_phyinfo *phy_info = NULL;
3391 ioc = fw_event->ioc;
3392 link_data = (MpiEventDataSasPhyLinkStatus_t *)fw_event->event_data;
3394 memcpy(&sas_address, &link_data->SASAddress, sizeof(__le64));
3395 sas_address = le64_to_cpu(sas_address);
3396 link_rate = link_data->LinkRates >> 4;
3397 phy_num = link_data->PhyNum;
3399 port_info = mptsas_find_portinfo_by_sas_address(ioc, sas_address);
3401 phy_info = &port_info->phy_info[phy_num];
3403 phy_info->negotiated_link_rate = link_rate;
3406 if (link_rate == MPI_SAS_IOUNIT0_RATE_1_5 ||
3407 link_rate == MPI_SAS_IOUNIT0_RATE_3_0) {
3410 if (ioc->old_sas_discovery_protocal) {
3411 port_info = mptsas_expander_add(ioc,
3412 le16_to_cpu(link_data->DevHandle));
3419 if (port_info == ioc->hba_port_info)
3420 mptsas_probe_hba_phys(ioc);
3422 mptsas_expander_refresh(ioc, port_info);
3423 } else if (phy_info && phy_info->phy) {
3424 if (link_rate == MPI_SAS_IOUNIT0_RATE_PHY_DISABLED)
3425 phy_info->phy->negotiated_linkrate =
3427 else if (link_rate ==
3428 MPI_SAS_IOUNIT0_RATE_FAILED_SPEED_NEGOTIATION)
3429 phy_info->phy->negotiated_linkrate =
3430 SAS_LINK_RATE_FAILED;
3432 phy_info->phy->negotiated_linkrate =
3433 SAS_LINK_RATE_UNKNOWN;
3436 mptsas_free_fw_event(ioc, fw_event);
3440 mptsas_not_responding_devices(MPT_ADAPTER *ioc)
3442 struct mptsas_portinfo buffer, *port_info;
3443 struct mptsas_device_info *sas_info;
3444 struct mptsas_devinfo sas_device;
3446 VirtTarget *vtarget = NULL;
3447 struct mptsas_phyinfo *phy_info;
3449 int retval, retry_count;
3450 unsigned long flags;
3452 mpt_findImVolumes(ioc);
3454 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
3455 if (ioc->ioc_reset_in_progress) {
3456 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3457 "%s: exiting due to a parallel reset \n", ioc->name,
3459 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3462 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
3464 /* devices, logical volumes */
3465 mutex_lock(&ioc->sas_device_info_mutex);
3467 list_for_each_entry(sas_info, &ioc->sas_device_info_list, list) {
3468 if (sas_info->is_cached)
3470 if (!sas_info->is_logical_volume) {
3471 sas_device.handle = 0;
3474 retval = mptsas_sas_device_pg0(ioc, &sas_device,
3475 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID
3476 << MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3477 (sas_info->fw.channel << 8) +
3480 if (sas_device.handle)
3482 if (retval == -EBUSY) {
3483 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
3484 if (ioc->ioc_reset_in_progress) {
3486 printk(MYIOC_s_DEBUG_FMT
3487 "%s: exiting due to reset\n",
3488 ioc->name, __func__));
3489 spin_unlock_irqrestore
3490 (&ioc->taskmgmt_lock, flags);
3492 sas_device_info_mutex);
3495 spin_unlock_irqrestore(&ioc->taskmgmt_lock,
3499 if (retval && (retval != -ENODEV)) {
3500 if (retry_count < 10) {
3504 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3505 "%s: Config page retry exceeded retry "
3506 "count deleting device 0x%llx\n",
3507 ioc->name, __func__,
3508 sas_info->sas_address));
3513 vtarget = mptsas_find_vtarget(ioc,
3514 sas_info->fw.channel, sas_info->fw.id);
3517 vtarget->deleted = 1;
3519 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3520 sas_info->sas_address);
3523 mptsas_del_end_device(ioc, phy_info);
3524 goto redo_device_scan;
3527 mptsas_volume_delete(ioc, sas_info->fw.id);
3529 mutex_unlock(&ioc->sas_device_info_mutex);
3532 mutex_lock(&ioc->sas_topology_mutex);
3534 list_for_each_entry(port_info, &ioc->sas_topology, list) {
3536 if (port_info->phy_info &&
3537 (!(port_info->phy_info[0].identify.device_info &
3538 MPI_SAS_DEVICE_INFO_SMP_TARGET)))
3542 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3543 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
3544 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle) &&
3547 handle = buffer.phy_info[0].handle;
3548 if (buffer.phy_info[0].identify.sas_address ==
3549 port_info->phy_info[0].identify.sas_address) {
3552 kfree(buffer.phy_info);
3555 if (!found_expander) {
3556 mptsas_expander_delete(ioc, port_info, 0);
3557 goto redo_expander_scan;
3560 mutex_unlock(&ioc->sas_topology_mutex);
3564 * mptsas_probe_expanders - adding expanders
3565 * @ioc: Pointer to MPT_ADAPTER structure
3569 mptsas_probe_expanders(MPT_ADAPTER *ioc)
3571 struct mptsas_portinfo buffer, *port_info;
3576 while (!mptsas_sas_expander_pg0(ioc, &buffer,
3577 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
3578 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), handle)) {
3580 handle = buffer.phy_info[0].handle;
3581 port_info = mptsas_find_portinfo_by_sas_address(ioc,
3582 buffer.phy_info[0].identify.sas_address);
3585 /* refreshing handles */
3586 for (i = 0; i < buffer.num_phys; i++) {
3587 port_info->phy_info[i].handle = handle;
3588 port_info->phy_info[i].identify.handle_parent =
3589 buffer.phy_info[0].identify.handle_parent;
3591 mptsas_expander_refresh(ioc, port_info);
3592 kfree(buffer.phy_info);
3596 port_info = kzalloc(sizeof(struct mptsas_portinfo), GFP_KERNEL);
3598 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
3599 "%s: exit at line=%d\n", ioc->name,
3600 __func__, __LINE__));
3603 port_info->num_phys = buffer.num_phys;
3604 port_info->phy_info = buffer.phy_info;
3605 for (i = 0; i < port_info->num_phys; i++)
3606 port_info->phy_info[i].portinfo = port_info;
3607 mutex_lock(&ioc->sas_topology_mutex);
3608 list_add_tail(&port_info->list, &ioc->sas_topology);
3609 mutex_unlock(&ioc->sas_topology_mutex);
3610 printk(MYIOC_s_INFO_FMT "add expander: num_phys %d, "
3611 "sas_addr (0x%llx)\n", ioc->name, port_info->num_phys,
3612 (unsigned long long)buffer.phy_info[0].identify.sas_address);
3613 mptsas_expander_refresh(ioc, port_info);
3618 mptsas_probe_devices(MPT_ADAPTER *ioc)
3621 struct mptsas_devinfo sas_device;
3622 struct mptsas_phyinfo *phy_info;
3625 while (!(mptsas_sas_device_pg0(ioc, &sas_device,
3626 MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
3628 handle = sas_device.handle;
3630 if ((sas_device.device_info &
3631 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
3632 MPI_SAS_DEVICE_INFO_STP_TARGET |
3633 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0)
3636 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
3640 if (mptsas_get_rphy(phy_info))
3643 mptsas_add_end_device(ioc, phy_info);
3648 * mptsas_scan_sas_topology -
3649 * @ioc: Pointer to MPT_ADAPTER structure
3654 mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
3656 struct scsi_device *sdev;
3659 mptsas_probe_hba_phys(ioc);
3660 mptsas_probe_expanders(ioc);
3661 mptsas_probe_devices(ioc);
3664 Reporting RAID volumes.
3666 if (!ioc->ir_firmware || !ioc->raid_data.pIocPg2 ||
3667 !ioc->raid_data.pIocPg2->NumActiveVolumes)
3669 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
3670 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
3671 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
3673 scsi_device_put(sdev);
3676 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
3677 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
3678 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID);
3679 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
3680 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
3686 mptsas_handle_queue_full_event(struct fw_event_work *fw_event)
3689 EventDataQueueFull_t *qfull_data;
3690 struct mptsas_device_info *sas_info;
3691 struct scsi_device *sdev;
3695 int fw_id, fw_channel;
3699 ioc = fw_event->ioc;
3700 qfull_data = (EventDataQueueFull_t *)fw_event->event_data;
3701 fw_id = qfull_data->TargetID;
3702 fw_channel = qfull_data->Bus;
3703 current_depth = le16_to_cpu(qfull_data->CurrentDepth);
3705 /* if hidden raid component, look for the volume id */
3706 mutex_lock(&ioc->sas_device_info_mutex);
3707 if (mptscsih_is_phys_disk(ioc, fw_channel, fw_id)) {
3708 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
3710 if (sas_info->is_cached ||
3711 sas_info->is_logical_volume)
3713 if (sas_info->is_hidden_raid_component &&
3714 (sas_info->fw.channel == fw_channel &&
3715 sas_info->fw.id == fw_id)) {
3716 id = sas_info->volume_id;
3717 channel = MPTSAS_RAID_CHANNEL;
3722 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
3724 if (sas_info->is_cached ||
3725 sas_info->is_hidden_raid_component ||
3726 sas_info->is_logical_volume)
3728 if (sas_info->fw.channel == fw_channel &&
3729 sas_info->fw.id == fw_id) {
3730 id = sas_info->os.id;
3731 channel = sas_info->os.channel;
3739 mutex_unlock(&ioc->sas_device_info_mutex);
3742 shost_for_each_device(sdev, ioc->sh) {
3743 if (sdev->id == id && sdev->channel == channel) {
3744 if (current_depth > sdev->queue_depth) {
3745 sdev_printk(KERN_INFO, sdev,
3746 "strange observation, the queue "
3747 "depth is (%d) meanwhile fw queue "
3748 "depth (%d)\n", sdev->queue_depth,
3752 depth = scsi_track_queue_full(sdev,
3755 sdev_printk(KERN_INFO, sdev,
3756 "Queue depth reduced to (%d)\n",
3759 sdev_printk(KERN_INFO, sdev,
3760 "Tagged Command Queueing is being "
3762 else if (depth == 0)
3763 sdev_printk(KERN_INFO, sdev,
3764 "Queue depth not changed yet\n");
3769 mptsas_free_fw_event(ioc, fw_event);
3773 static struct mptsas_phyinfo *
3774 mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
3776 struct mptsas_portinfo *port_info;
3777 struct mptsas_phyinfo *phy_info = NULL;
3780 mutex_lock(&ioc->sas_topology_mutex);
3781 list_for_each_entry(port_info, &ioc->sas_topology, list) {
3782 for (i = 0; i < port_info->num_phys; i++) {
3783 if (!mptsas_is_end_device(
3784 &port_info->phy_info[i].attached))
3786 if (port_info->phy_info[i].attached.sas_address
3789 phy_info = &port_info->phy_info[i];
3793 mutex_unlock(&ioc->sas_topology_mutex);
3798 * mptsas_find_phyinfo_by_phys_disk_num -
3799 * @ioc: Pointer to MPT_ADAPTER structure
3805 static struct mptsas_phyinfo *
3806 mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 phys_disk_num,
3809 struct mptsas_phyinfo *phy_info = NULL;
3810 struct mptsas_portinfo *port_info;
3811 RaidPhysDiskPage1_t *phys_disk = NULL;
3813 u64 sas_address = 0;
3817 if (!ioc->raid_data.pIocPg3)
3819 /* dual port support */
3820 num_paths = mpt_raid_phys_disk_get_num_paths(ioc, phys_disk_num);
3823 phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
3824 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
3827 mpt_raid_phys_disk_pg1(ioc, phys_disk_num, phys_disk);
3828 for (i = 0; i < num_paths; i++) {
3829 if ((phys_disk->Path[i].Flags & 1) != 0)
3830 /* entry no longer valid */
3832 if ((id == phys_disk->Path[i].PhysDiskID) &&
3833 (channel == phys_disk->Path[i].PhysDiskBus)) {
3834 memcpy(&sas_address, &phys_disk->Path[i].WWID,
3836 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3848 * Extra code to handle RAID0 case, where the sas_address is not updated
3849 * in phys_disk_page_1 when hotswapped
3851 mutex_lock(&ioc->sas_topology_mutex);
3852 list_for_each_entry(port_info, &ioc->sas_topology, list) {
3853 for (i = 0; i < port_info->num_phys && !phy_info; i++) {
3854 if (!mptsas_is_end_device(
3855 &port_info->phy_info[i].attached))
3857 if (port_info->phy_info[i].attached.phys_disk_num == ~0)
3859 if ((port_info->phy_info[i].attached.phys_disk_num ==
3861 (port_info->phy_info[i].attached.id == id) &&
3862 (port_info->phy_info[i].attached.channel ==
3864 phy_info = &port_info->phy_info[i];
3867 mutex_unlock(&ioc->sas_topology_mutex);
3872 mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
3876 sdev->no_uld_attach = data ? 1 : 0;
3877 rc = scsi_device_reprobe(sdev);
3881 mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
3883 starget_for_each_device(starget, uld_attach ? (void *)1 : NULL,
3884 mptsas_reprobe_lun);
3888 mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
3891 ConfigPageHeader_t hdr;
3892 dma_addr_t dma_handle;
3893 pRaidVolumePage0_t buffer = NULL;
3894 RaidPhysDiskPage0_t phys_disk;
3896 struct mptsas_phyinfo *phy_info;
3897 struct mptsas_devinfo sas_device;
3899 memset(&cfg, 0 , sizeof(CONFIGPARMS));
3900 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
3901 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
3902 cfg.pageAddr = (channel << 8) + id;
3903 cfg.cfghdr.hdr = &hdr;
3904 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3906 if (mpt_config(ioc, &cfg) != 0)
3909 if (!hdr.PageLength)
3912 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
3918 cfg.physAddr = dma_handle;
3919 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
3921 if (mpt_config(ioc, &cfg) != 0)
3924 if (!(buffer->VolumeStatus.Flags &
3925 MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
3928 if (!buffer->NumPhysDisks)
3931 for (i = 0; i < buffer->NumPhysDisks; i++) {
3933 if (mpt_raid_phys_disk_pg0(ioc,
3934 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
3937 if (mptsas_sas_device_pg0(ioc, &sas_device,
3938 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
3939 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3940 (phys_disk.PhysDiskBus << 8) +
3941 phys_disk.PhysDiskID))
3944 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
3945 sas_device.sas_address);
3946 mptsas_add_end_device(ioc, phy_info);
3951 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
3955 * Work queue thread to handle SAS hotplug events
3958 mptsas_hotplug_work(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
3959 struct mptsas_hotplug_event *hot_plug_info)
3961 struct mptsas_phyinfo *phy_info;
3962 struct scsi_target * starget;
3963 struct mptsas_devinfo sas_device;
3964 VirtTarget *vtarget;
3967 switch (hot_plug_info->event_type) {
3969 case MPTSAS_ADD_PHYSDISK:
3971 if (!ioc->raid_data.pIocPg2)
3974 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
3975 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID ==
3976 hot_plug_info->id) {
3977 printk(MYIOC_s_WARN_FMT "firmware bug: unable "
3978 "to add hidden disk - target_id matchs "
3979 "volume_id\n", ioc->name);
3980 mptsas_free_fw_event(ioc, fw_event);
3984 mpt_findImVolumes(ioc);
3986 case MPTSAS_ADD_DEVICE:
3987 memset(&sas_device, 0, sizeof(struct mptsas_devinfo));
3988 mptsas_sas_device_pg0(ioc, &sas_device,
3989 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
3990 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
3991 (hot_plug_info->channel << 8) +
3994 if (!sas_device.handle)
3997 phy_info = mptsas_refreshing_device_handles(ioc, &sas_device);
4001 if (mptsas_get_rphy(phy_info))
4004 mptsas_add_end_device(ioc, phy_info);
4007 case MPTSAS_DEL_DEVICE:
4008 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4009 hot_plug_info->sas_address);
4010 mptsas_del_end_device(ioc, phy_info);
4013 case MPTSAS_DEL_PHYSDISK:
4015 mpt_findImVolumes(ioc);
4017 phy_info = mptsas_find_phyinfo_by_phys_disk_num(
4018 ioc, hot_plug_info->phys_disk_num,
4019 hot_plug_info->channel,
4021 mptsas_del_end_device(ioc, phy_info);
4024 case MPTSAS_ADD_PHYSDISK_REPROBE:
4026 if (mptsas_sas_device_pg0(ioc, &sas_device,
4027 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4028 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4029 (hot_plug_info->channel << 8) + hot_plug_info->id)) {
4030 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4031 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4032 __func__, hot_plug_info->id, __LINE__));
4036 phy_info = mptsas_find_phyinfo_by_sas_address(
4037 ioc, sas_device.sas_address);
4040 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4041 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4042 __func__, hot_plug_info->id, __LINE__));
4046 starget = mptsas_get_starget(phy_info);
4048 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4049 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4050 __func__, hot_plug_info->id, __LINE__));
4054 vtarget = starget->hostdata;
4056 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4057 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4058 __func__, hot_plug_info->id, __LINE__));
4062 mpt_findImVolumes(ioc);
4064 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Hidding: "
4065 "fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
4066 ioc->name, hot_plug_info->channel, hot_plug_info->id,
4067 hot_plug_info->phys_disk_num, (unsigned long long)
4068 sas_device.sas_address);
4070 vtarget->id = hot_plug_info->phys_disk_num;
4071 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
4072 phy_info->attached.phys_disk_num = hot_plug_info->phys_disk_num;
4073 mptsas_reprobe_target(starget, 1);
4076 case MPTSAS_DEL_PHYSDISK_REPROBE:
4078 if (mptsas_sas_device_pg0(ioc, &sas_device,
4079 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
4080 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
4081 (hot_plug_info->channel << 8) + hot_plug_info->id)) {
4082 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4083 "%s: fw_id=%d exit at line=%d\n",
4084 ioc->name, __func__,
4085 hot_plug_info->id, __LINE__));
4089 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
4090 sas_device.sas_address);
4092 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4093 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4094 __func__, hot_plug_info->id, __LINE__));
4098 starget = mptsas_get_starget(phy_info);
4100 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4101 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4102 __func__, hot_plug_info->id, __LINE__));
4106 vtarget = starget->hostdata;
4108 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4109 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4110 __func__, hot_plug_info->id, __LINE__));
4114 if (!(vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)) {
4115 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
4116 "%s: fw_id=%d exit at line=%d\n", ioc->name,
4117 __func__, hot_plug_info->id, __LINE__));
4121 mpt_findImVolumes(ioc);
4123 starget_printk(KERN_INFO, starget, MYIOC_s_FMT "RAID Exposing:"
4124 " fw_channel=%d, fw_id=%d, physdsk %d, sas_addr 0x%llx\n",
4125 ioc->name, hot_plug_info->channel, hot_plug_info->id,
4126 hot_plug_info->phys_disk_num, (unsigned long long)
4127 sas_device.sas_address);
4129 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
4130 vtarget->id = hot_plug_info->id;
4131 phy_info->attached.phys_disk_num = ~0;
4132 mptsas_reprobe_target(starget, 0);
4133 mptsas_add_device_component_by_fw(ioc,
4134 hot_plug_info->channel, hot_plug_info->id);
4137 case MPTSAS_ADD_RAID:
4139 mpt_findImVolumes(ioc);
4140 printk(MYIOC_s_INFO_FMT "attaching raid volume, channel %d, "
4141 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
4143 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
4144 hot_plug_info->id, 0);
4147 case MPTSAS_DEL_RAID:
4149 mpt_findImVolumes(ioc);
4150 printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
4151 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL,
4153 scsi_remove_device(hot_plug_info->sdev);
4154 scsi_device_put(hot_plug_info->sdev);
4157 case MPTSAS_ADD_INACTIVE_VOLUME:
4159 mpt_findImVolumes(ioc);
4160 mptsas_adding_inactive_raid_components(ioc,
4161 hot_plug_info->channel, hot_plug_info->id);
4168 mptsas_free_fw_event(ioc, fw_event);
4172 mptsas_send_sas_event(struct fw_event_work *fw_event)
4175 struct mptsas_hotplug_event hot_plug_info;
4176 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
4180 ioc = fw_event->ioc;
4181 sas_event_data = (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)
4182 fw_event->event_data;
4183 device_info = le32_to_cpu(sas_event_data->DeviceInfo);
4186 (MPI_SAS_DEVICE_INFO_SSP_TARGET |
4187 MPI_SAS_DEVICE_INFO_STP_TARGET |
4188 MPI_SAS_DEVICE_INFO_SATA_DEVICE)) == 0) {
4189 mptsas_free_fw_event(ioc, fw_event);
4193 if (sas_event_data->ReasonCode ==
4194 MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED) {
4195 mptbase_sas_persist_operation(ioc,
4196 MPI_SAS_OP_CLEAR_NOT_PRESENT);
4197 mptsas_free_fw_event(ioc, fw_event);
4201 switch (sas_event_data->ReasonCode) {
4202 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
4203 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
4204 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4205 hot_plug_info.handle = le16_to_cpu(sas_event_data->DevHandle);
4206 hot_plug_info.channel = sas_event_data->Bus;
4207 hot_plug_info.id = sas_event_data->TargetID;
4208 hot_plug_info.phy_id = sas_event_data->PhyNum;
4209 memcpy(&sas_address, &sas_event_data->SASAddress,
4211 hot_plug_info.sas_address = le64_to_cpu(sas_address);
4212 hot_plug_info.device_info = device_info;
4213 if (sas_event_data->ReasonCode &
4214 MPI_EVENT_SAS_DEV_STAT_RC_ADDED)
4215 hot_plug_info.event_type = MPTSAS_ADD_DEVICE;
4217 hot_plug_info.event_type = MPTSAS_DEL_DEVICE;
4218 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4221 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
4222 mptbase_sas_persist_operation(ioc,
4223 MPI_SAS_OP_CLEAR_NOT_PRESENT);
4224 mptsas_free_fw_event(ioc, fw_event);
4227 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
4229 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
4232 mptsas_free_fw_event(ioc, fw_event);
4238 mptsas_send_raid_event(struct fw_event_work *fw_event)
4241 EVENT_DATA_RAID *raid_event_data;
4242 struct mptsas_hotplug_event hot_plug_info;
4245 struct scsi_device *sdev = NULL;
4246 VirtDevice *vdevice = NULL;
4247 RaidPhysDiskPage0_t phys_disk;
4249 ioc = fw_event->ioc;
4250 raid_event_data = (EVENT_DATA_RAID *)fw_event->event_data;
4251 status = le32_to_cpu(raid_event_data->SettingsStatus);
4252 state = (status >> 8) & 0xff;
4254 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4255 hot_plug_info.id = raid_event_data->VolumeID;
4256 hot_plug_info.channel = raid_event_data->VolumeBus;
4257 hot_plug_info.phys_disk_num = raid_event_data->PhysDiskNum;
4259 if (raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_DELETED ||
4260 raid_event_data->ReasonCode == MPI_EVENT_RAID_RC_VOLUME_CREATED ||
4261 raid_event_data->ReasonCode ==
4262 MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED) {
4263 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
4264 hot_plug_info.id, 0);
4265 hot_plug_info.sdev = sdev;
4267 vdevice = sdev->hostdata;
4270 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
4271 "ReasonCode=%02x\n", ioc->name, __func__,
4272 raid_event_data->ReasonCode));
4274 switch (raid_event_data->ReasonCode) {
4275 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
4276 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK_REPROBE;
4278 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
4279 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK_REPROBE;
4281 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
4283 case MPI_PD_STATE_ONLINE:
4284 case MPI_PD_STATE_NOT_COMPATIBLE:
4285 mpt_raid_phys_disk_pg0(ioc,
4286 raid_event_data->PhysDiskNum, &phys_disk);
4287 hot_plug_info.id = phys_disk.PhysDiskID;
4288 hot_plug_info.channel = phys_disk.PhysDiskBus;
4289 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
4291 case MPI_PD_STATE_FAILED:
4292 case MPI_PD_STATE_MISSING:
4293 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
4294 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
4295 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
4296 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
4302 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
4305 vdevice->vtarget->deleted = 1; /* block IO */
4306 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4308 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
4310 scsi_device_put(sdev);
4313 hot_plug_info.event_type = MPTSAS_ADD_RAID;
4315 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
4316 if (!(status & MPI_RAIDVOL0_STATUS_FLAG_ENABLED)) {
4319 vdevice->vtarget->deleted = 1; /* block IO */
4320 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4324 case MPI_RAIDVOL0_STATUS_STATE_FAILED:
4325 case MPI_RAIDVOL0_STATUS_STATE_MISSING:
4328 vdevice->vtarget->deleted = 1; /* block IO */
4329 hot_plug_info.event_type = MPTSAS_DEL_RAID;
4331 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
4332 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
4334 scsi_device_put(sdev);
4337 hot_plug_info.event_type = MPTSAS_ADD_RAID;
4347 if (hot_plug_info.event_type != MPTSAS_IGNORE_EVENT)
4348 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4350 mptsas_free_fw_event(ioc, fw_event);
4354 * mptsas_issue_tm - send mptsas internal tm request
4355 * @ioc: Pointer to MPT_ADAPTER structure
4356 * @type: Task Management type
4357 * @channel: channel number for task management
4358 * @id: Logical Target ID for reset (if appropriate)
4359 * @lun: Logical unit for reset (if appropriate)
4360 * @task_context: Context for the task to be aborted
4361 * @timeout: timeout for task management control
4363 * return 0 on success and -1 on failure:
4367 mptsas_issue_tm(MPT_ADAPTER *ioc, u8 type, u8 channel, u8 id, u64 lun,
4368 int task_context, ulong timeout, u8 *issue_reset)
4371 SCSITaskMgmt_t *pScsiTm;
4373 unsigned long timeleft;
4376 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
4378 retval = -1; /* return failure */
4379 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "TaskMgmt request: no "
4380 "msg frames!!\n", ioc->name));
4384 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request: mr = %p, "
4385 "task_type = 0x%02X,\n\t timeout = %ld, fw_channel = %d, "
4386 "fw_id = %d, lun = %lld,\n\t task_context = 0x%x\n", ioc->name, mf,
4387 type, timeout, channel, id, (unsigned long long)lun,
4390 pScsiTm = (SCSITaskMgmt_t *) mf;
4391 memset(pScsiTm, 0, sizeof(SCSITaskMgmt_t));
4392 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
4393 pScsiTm->TaskType = type;
4394 pScsiTm->MsgFlags = 0;
4395 pScsiTm->TargetID = id;
4396 pScsiTm->Bus = channel;
4397 pScsiTm->ChainOffset = 0;
4398 pScsiTm->Reserved = 0;
4399 pScsiTm->Reserved1 = 0;
4400 pScsiTm->TaskMsgContext = task_context;
4401 int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
4403 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
4404 CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
4406 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
4408 /* Now wait for the command to complete */
4409 timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done,
4411 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
4412 retval = -1; /* return failure */
4413 dtmprintk(ioc, printk(MYIOC_s_ERR_FMT
4414 "TaskMgmt request: TIMED OUT!(mr=%p)\n", ioc->name, mf));
4415 mpt_free_msg_frame(ioc, mf);
4416 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
4422 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
4423 retval = -1; /* return failure */
4424 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4425 "TaskMgmt request: failed with no reply\n", ioc->name));
4430 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
4435 * mptsas_broadcast_primative_work - Handle broadcast primitives
4436 * @work: work queue payload containing info describing the event
4438 * this will be handled in workqueue context.
4441 mptsas_broadcast_primative_work(struct fw_event_work *fw_event)
4443 MPT_ADAPTER *ioc = fw_event->ioc;
4445 VirtDevice *vdevice;
4447 struct scsi_cmnd *sc;
4448 SCSITaskMgmtReply_t *pScsiTmReply;
4453 u32 termination_count;
4456 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4457 "%s - enter\n", ioc->name, __func__));
4459 mutex_lock(&ioc->taskmgmt_cmds.mutex);
4460 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
4461 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
4462 mptsas_requeue_fw_event(ioc, fw_event, 1000);
4467 termination_count = 0;
4469 mpt_findImVolumes(ioc);
4470 pScsiTmReply = (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply;
4472 for (ii = 0; ii < ioc->req_depth; ii++) {
4473 if (ioc->fw_events_off)
4475 sc = mptscsih_get_scsi_lookup(ioc, ii);
4478 mf = MPT_INDEX_2_MFPTR(ioc, ii);
4481 task_context = mf->u.frame.hwhdr.msgctxu.MsgContext;
4482 vdevice = sc->device->hostdata;
4483 if (!vdevice || !vdevice->vtarget)
4485 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
4486 continue; /* skip hidden raid components */
4487 if (vdevice->vtarget->raidVolume)
4488 continue; /* skip hidden raid components */
4489 channel = vdevice->vtarget->channel;
4490 id = vdevice->vtarget->id;
4492 if (mptsas_issue_tm(ioc, MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK,
4493 channel, id, (u64)lun, task_context, 30, &issue_reset))
4496 termination_count +=
4497 le32_to_cpu(pScsiTmReply->TerminationCount);
4498 if ((pScsiTmReply->IOCStatus == MPI_IOCSTATUS_SUCCESS) &&
4499 (pScsiTmReply->ResponseCode ==
4500 MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
4501 pScsiTmReply->ResponseCode ==
4502 MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC))
4504 if (mptsas_issue_tm(ioc,
4505 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET,
4506 channel, id, (u64)lun, 0, 30, &issue_reset))
4508 termination_count +=
4509 le32_to_cpu(pScsiTmReply->TerminationCount);
4513 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4514 "%s - exit, query_count = %d termination_count = %d\n",
4515 ioc->name, __func__, query_count, termination_count));
4517 ioc->broadcast_aen_busy = 0;
4518 mpt_clear_taskmgmt_in_progress_flag(ioc);
4519 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
4522 printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
4523 ioc->name, __func__);
4524 mpt_HardResetHandler(ioc, CAN_SLEEP);
4526 mptsas_free_fw_event(ioc, fw_event);
4530 * mptsas_send_ir2_event - handle exposing hidden disk when
4531 * an inactive raid volume is added
4533 * @ioc: Pointer to MPT_ADAPTER structure
4538 mptsas_send_ir2_event(struct fw_event_work *fw_event)
4541 struct mptsas_hotplug_event hot_plug_info;
4542 MPI_EVENT_DATA_IR2 *ir2_data;
4544 RaidPhysDiskPage0_t phys_disk;
4546 ioc = fw_event->ioc;
4547 ir2_data = (MPI_EVENT_DATA_IR2 *)fw_event->event_data;
4548 reasonCode = ir2_data->ReasonCode;
4550 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Entering %s: "
4551 "ReasonCode=%02x\n", ioc->name, __func__, reasonCode));
4553 memset(&hot_plug_info, 0, sizeof(struct mptsas_hotplug_event));
4554 hot_plug_info.id = ir2_data->TargetID;
4555 hot_plug_info.channel = ir2_data->Bus;
4556 switch (reasonCode) {
4557 case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
4558 hot_plug_info.event_type = MPTSAS_ADD_INACTIVE_VOLUME;
4560 case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED:
4561 hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum;
4562 hot_plug_info.event_type = MPTSAS_DEL_PHYSDISK;
4564 case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED:
4565 hot_plug_info.phys_disk_num = ir2_data->PhysDiskNum;
4566 mpt_raid_phys_disk_pg0(ioc,
4567 ir2_data->PhysDiskNum, &phys_disk);
4568 hot_plug_info.id = phys_disk.PhysDiskID;
4569 hot_plug_info.event_type = MPTSAS_ADD_PHYSDISK;
4572 mptsas_free_fw_event(ioc, fw_event);
4575 mptsas_hotplug_work(ioc, fw_event, &hot_plug_info);
4579 mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
4581 u32 event = le32_to_cpu(reply->Event);
4582 int sz, event_data_sz;
4583 struct fw_event_work *fw_event;
4584 unsigned long delay;
4586 /* events turned off due to host reset or driver unloading */
4587 if (ioc->fw_events_off)
4590 delay = msecs_to_jiffies(1);
4592 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
4594 EVENT_DATA_SAS_BROADCAST_PRIMITIVE *broadcast_event_data =
4595 (EVENT_DATA_SAS_BROADCAST_PRIMITIVE *)reply->Data;
4596 if (broadcast_event_data->Primitive !=
4597 MPI_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
4599 if (ioc->broadcast_aen_busy)
4601 ioc->broadcast_aen_busy = 1;
4604 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
4606 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data =
4607 (EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *)reply->Data;
4609 if (sas_event_data->ReasonCode ==
4610 MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING) {
4611 mptsas_target_reset_queue(ioc, sas_event_data);
4616 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
4618 MpiEventDataSasExpanderStatusChange_t *expander_data =
4619 (MpiEventDataSasExpanderStatusChange_t *)reply->Data;
4621 if (ioc->old_sas_discovery_protocal)
4624 if (expander_data->ReasonCode ==
4625 MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING &&
4626 ioc->device_missing_delay)
4627 delay = HZ * ioc->device_missing_delay;
4630 case MPI_EVENT_SAS_DISCOVERY:
4632 u32 discovery_status;
4633 EventDataSasDiscovery_t *discovery_data =
4634 (EventDataSasDiscovery_t *)reply->Data;
4636 discovery_status = le32_to_cpu(discovery_data->DiscoveryStatus);
4637 ioc->sas_discovery_quiesce_io = discovery_status ? 1 : 0;
4638 if (ioc->old_sas_discovery_protocal && !discovery_status)
4639 mptsas_queue_rescan(ioc);
4642 case MPI_EVENT_INTEGRATED_RAID:
4643 case MPI_EVENT_PERSISTENT_TABLE_FULL:
4645 case MPI_EVENT_SAS_PHY_LINK_STATUS:
4646 case MPI_EVENT_QUEUE_FULL:
4652 event_data_sz = ((reply->MsgLength * 4) -
4653 offsetof(EventNotificationReply_t, Data));
4654 sz = offsetof(struct fw_event_work, event_data) + event_data_sz;
4655 fw_event = kzalloc(sz, GFP_ATOMIC);
4657 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n", ioc->name,
4658 __func__, __LINE__);
4661 memcpy(fw_event->event_data, reply->Data, event_data_sz);
4662 fw_event->event = event;
4663 fw_event->ioc = ioc;
4664 mptsas_add_fw_event(ioc, fw_event, delay);
4668 /* Delete a volume when no longer listed in ioc pg2
4670 static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id)
4672 struct scsi_device *sdev;
4675 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, id, 0);
4678 if (!ioc->raid_data.pIocPg2)
4680 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
4682 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
4683 if (ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id)
4686 printk(MYIOC_s_INFO_FMT "removing raid volume, channel %d, "
4687 "id %d\n", ioc->name, MPTSAS_RAID_CHANNEL, id);
4688 scsi_remove_device(sdev);
4690 scsi_device_put(sdev);
4694 mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
4696 struct Scsi_Host *sh;
4699 unsigned long flags;
4707 r = mpt_attach(pdev,id);
4711 ioc = pci_get_drvdata(pdev);
4712 mptsas_fw_event_off(ioc);
4713 ioc->DoneCtx = mptsasDoneCtx;
4714 ioc->TaskCtx = mptsasTaskCtx;
4715 ioc->InternalCtx = mptsasInternalCtx;
4717 /* Added sanity check on readiness of the MPT adapter.
4719 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
4720 printk(MYIOC_s_WARN_FMT
4721 "Skipping because it's not operational!\n",
4724 goto out_mptsas_probe;
4728 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
4731 goto out_mptsas_probe;
4734 /* Sanity check - ensure at least 1 port is INITIATOR capable
4737 for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {
4738 if (ioc->pfacts[ii].ProtocolFlags &
4739 MPI_PORTFACTS_PROTOCOL_INITIATOR)
4744 printk(MYIOC_s_WARN_FMT
4745 "Skipping ioc=%p because SCSI Initiator mode "
4746 "is NOT enabled!\n", ioc->name, ioc);
4750 sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));
4752 printk(MYIOC_s_WARN_FMT
4753 "Unable to register controller with SCSI subsystem\n",
4756 goto out_mptsas_probe;
4759 spin_lock_irqsave(&ioc->FreeQlock, flags);
4761 /* Attach the SCSI Host to the IOC structure
4769 /* set 16 byte cdb's */
4770 sh->max_cmd_len = 16;
4771 sh->can_queue = min_t(int, ioc->req_depth - 10, sh->can_queue);
4773 sh->max_lun = max_lun;
4774 sh->transportt = mptsas_transport_template;
4778 sh->unique_id = ioc->id;
4780 INIT_LIST_HEAD(&ioc->sas_topology);
4781 mutex_init(&ioc->sas_topology_mutex);
4782 mutex_init(&ioc->sas_discovery_mutex);
4783 mutex_init(&ioc->sas_mgmt.mutex);
4784 init_completion(&ioc->sas_mgmt.done);
4786 /* Verify that we won't exceed the maximum
4787 * number of chain buffers
4788 * We can optimize: ZZ = req_sz/sizeof(SGE)
4790 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
4791 * + (req_sz - 64)/sizeof(SGE)
4792 * A slightly different algorithm is required for
4795 scale = ioc->req_sz/ioc->SGE_size;
4796 if (ioc->sg_addr_size == sizeof(u64)) {
4797 numSGE = (scale - 1) *
4798 (ioc->facts.MaxChainDepth-1) + scale +
4799 (ioc->req_sz - 60) / ioc->SGE_size;
4801 numSGE = 1 + (scale - 1) *
4802 (ioc->facts.MaxChainDepth-1) + scale +
4803 (ioc->req_sz - 64) / ioc->SGE_size;
4806 if (numSGE < sh->sg_tablesize) {
4807 /* Reset this value */
4808 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4809 "Resetting sg_tablesize to %d from %d\n",
4810 ioc->name, numSGE, sh->sg_tablesize));
4811 sh->sg_tablesize = numSGE;
4814 hd = shost_priv(sh);
4817 /* SCSI needs scsi_cmnd lookup table!
4818 * (with size equal to req_depth*PtrSz!)
4820 ioc->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
4821 if (!ioc->ScsiLookup) {
4823 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4824 goto out_mptsas_probe;
4826 spin_lock_init(&ioc->scsi_lookup_lock);
4828 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScsiLookup @ %p\n",
4829 ioc->name, ioc->ScsiLookup));
4831 ioc->sas_data.ptClear = mpt_pt_clear;
4833 hd->last_queue_full = 0;
4834 INIT_LIST_HEAD(&hd->target_reset_list);
4835 INIT_LIST_HEAD(&ioc->sas_device_info_list);
4836 mutex_init(&ioc->sas_device_info_mutex);
4838 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4840 if (ioc->sas_data.ptClear==1) {
4841 mptbase_sas_persist_operation(
4842 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
4845 error = scsi_add_host(sh, &ioc->pcidev->dev);
4847 dprintk(ioc, printk(MYIOC_s_ERR_FMT
4848 "scsi_add_host failed\n", ioc->name));
4849 goto out_mptsas_probe;
4852 /* older firmware doesn't support expander events */
4853 if ((ioc->facts.HeaderVersion >> 8) < 0xE)
4854 ioc->old_sas_discovery_protocal = 1;
4855 mptsas_scan_sas_topology(ioc);
4856 mptsas_fw_event_on(ioc);
4861 mptscsih_remove(pdev);
4866 mptsas_shutdown(struct pci_dev *pdev)
4868 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
4870 mptsas_fw_event_off(ioc);
4871 mptsas_cleanup_fw_event_q(ioc);
4874 static void __devexit mptsas_remove(struct pci_dev *pdev)
4876 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
4877 struct mptsas_portinfo *p, *n;
4880 mptsas_shutdown(pdev);
4882 mptsas_del_device_components(ioc);
4884 ioc->sas_discovery_ignore_events = 1;
4885 sas_remove_host(ioc->sh);
4887 mutex_lock(&ioc->sas_topology_mutex);
4888 list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
4890 for (i = 0 ; i < p->num_phys ; i++)
4891 mptsas_port_delete(ioc, p->phy_info[i].port_details);
4896 mutex_unlock(&ioc->sas_topology_mutex);
4897 ioc->hba_port_info = NULL;
4898 mptscsih_remove(pdev);
4901 static struct pci_device_id mptsas_pci_table[] = {
4902 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064,
4903 PCI_ANY_ID, PCI_ANY_ID },
4904 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068,
4905 PCI_ANY_ID, PCI_ANY_ID },
4906 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1064E,
4907 PCI_ANY_ID, PCI_ANY_ID },
4908 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1068E,
4909 PCI_ANY_ID, PCI_ANY_ID },
4910 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_SAS1078,
4911 PCI_ANY_ID, PCI_ANY_ID },
4912 {0} /* Terminating entry */
4914 MODULE_DEVICE_TABLE(pci, mptsas_pci_table);
4917 static struct pci_driver mptsas_driver = {
4919 .id_table = mptsas_pci_table,
4920 .probe = mptsas_probe,
4921 .remove = __devexit_p(mptsas_remove),
4922 .shutdown = mptsas_shutdown,
4924 .suspend = mptscsih_suspend,
4925 .resume = mptscsih_resume,
4934 show_mptmod_ver(my_NAME, my_VERSION);
4936 mptsas_transport_template =
4937 sas_attach_transport(&mptsas_transport_functions);
4938 if (!mptsas_transport_template)
4941 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
4942 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER);
4944 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
4945 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
4946 mptsasDeviceResetCtx =
4947 mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER);
4949 mpt_event_register(mptsasDoneCtx, mptsas_event_process);
4950 mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset);
4952 error = pci_register_driver(&mptsas_driver);
4954 sas_release_transport(mptsas_transport_template);
4962 pci_unregister_driver(&mptsas_driver);
4963 sas_release_transport(mptsas_transport_template);
4965 mpt_reset_deregister(mptsasDoneCtx);
4966 mpt_event_deregister(mptsasDoneCtx);
4968 mpt_deregister(mptsasMgmtCtx);
4969 mpt_deregister(mptsasInternalCtx);
4970 mpt_deregister(mptsasTaskCtx);
4971 mpt_deregister(mptsasDoneCtx);
4972 mpt_deregister(mptsasDeviceResetCtx);
4975 module_init(mptsas_init);
4976 module_exit(mptsas_exit);