1/*
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.
5 *
6 * Copyright (c) 1999-2008 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com)
8 */
9/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
10/*
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.
14
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.
19
20 NO WARRANTY
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.
30
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
39
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
43*/
44/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/slab.h>
49#include <linux/init.h>
50#include <linux/errno.h>
51#include <linux/jiffies.h>
52#include <linux/workqueue.h>
53#include <linux/delay.h> /* for mdelay */
54
55#include <scsi/scsi.h>
56#include <scsi/scsi_cmnd.h>
57#include <scsi/scsi_device.h>
58#include <scsi/scsi_host.h>
59#include <scsi/scsi_transport_sas.h>
60#include <scsi/scsi_transport.h>
61#include <scsi/scsi_dbg.h>
62
63#include "mptbase.h"
64#include "mptscsih.h"
65#include "mptsas.h"
66
67
68#define my_NAME "Fusion MPT SAS Host driver"
69#define my_VERSION MPT_LINUX_VERSION_COMMON
70#define MYNAM "mptsas"
71
72/*
73 * Reserved channel for integrated raid
74 */
75#define MPTSAS_RAID_CHANNEL 1
76
77#define SAS_CONFIG_PAGE_TIMEOUT 30
78MODULE_AUTHOR(MODULEAUTHOR);
79MODULE_DESCRIPTION(my_NAME);
80MODULE_LICENSE("GPL");
81MODULE_VERSION(my_VERSION);
82
83static int mpt_pt_clear;
84module_param(mpt_pt_clear, int, 0);
85MODULE_PARM_DESC(mpt_pt_clear,
86 " Clear persistency table: enable=1 "
87 "(default=MPTSCSIH_PT_CLEAR=0)");
88
89/* scsi-mid layer global parmeter is max_report_luns, which is 511 */
90#define MPTSAS_MAX_LUN (16895)
91static int max_lun = MPTSAS_MAX_LUN;
92module_param(max_lun, int, 0);
93MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
94
95static int mpt_loadtime_max_sectors = 8192;
96module_param(mpt_loadtime_max_sectors, int, 0);
97MODULE_PARM_DESC(mpt_loadtime_max_sectors,
98 " Maximum sector define for Host Bus Adaptor.Range 64 to 8192 default=8192");
99
100static u8 mptsasDoneCtx = MPT_MAX_PROTOCOL_DRIVERS;
101static u8 mptsasTaskCtx = MPT_MAX_PROTOCOL_DRIVERS;
102static u8 mptsasInternalCtx = MPT_MAX_PROTOCOL_DRIVERS; /* Used only for internal commands */
103static u8 mptsasMgmtCtx = MPT_MAX_PROTOCOL_DRIVERS;
104static u8 mptsasDeviceResetCtx = MPT_MAX_PROTOCOL_DRIVERS;
105
106static void mptsas_firmware_event_work(struct work_struct *work);
107static void mptsas_send_sas_event(struct fw_event_work *fw_event);
108static void mptsas_send_raid_event(struct fw_event_work *fw_event);
109static void mptsas_send_ir2_event(struct fw_event_work *fw_event);
110static void mptsas_parse_device_info(struct sas_identify *identify,
111 struct mptsas_devinfo *device_info);
112static inline void mptsas_set_rphy(MPT_ADAPTER *ioc,
113 struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy);
114static struct mptsas_phyinfo *mptsas_find_phyinfo_by_sas_address
115 (MPT_ADAPTER *ioc, u64 sas_address);
116static int mptsas_sas_device_pg0(MPT_ADAPTER *ioc,
117 struct mptsas_devinfo *device_info, u32 form, u32 form_specific);
118static int mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc,
119 struct mptsas_enclosure *enclosure, u32 form, u32 form_specific);
120static int mptsas_add_end_device(MPT_ADAPTER *ioc,
121 struct mptsas_phyinfo *phy_info);
122static void mptsas_del_end_device(MPT_ADAPTER *ioc,
123 struct mptsas_phyinfo *phy_info);
124static void mptsas_send_link_status_event(struct fw_event_work *fw_event);
125static struct mptsas_portinfo *mptsas_find_portinfo_by_sas_address
126 (MPT_ADAPTER *ioc, u64 sas_address);
127static void mptsas_expander_delete(MPT_ADAPTER *ioc,
128 struct mptsas_portinfo *port_info, u8 force);
129static void mptsas_send_expander_event(struct fw_event_work *fw_event);
130static void mptsas_not_responding_devices(MPT_ADAPTER *ioc);
131static void mptsas_scan_sas_topology(MPT_ADAPTER *ioc);
132static void mptsas_broadcast_primitive_work(struct fw_event_work *fw_event);
133static void mptsas_handle_queue_full_event(struct fw_event_work *fw_event);
134static void mptsas_volume_delete(MPT_ADAPTER *ioc, u8 id);
135void mptsas_schedule_target_reset(void *ioc);
136
137static void mptsas_print_phy_data(MPT_ADAPTER *ioc,
138 MPI_SAS_IO_UNIT0_PHY_DATA *phy_data)
139{
140 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
141 "---- IO UNIT PAGE 0 ------------\n", ioc->name));
142 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
143 ioc->name, le16_to_cpu(phy_data->AttachedDeviceHandle)));
144 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Controller Handle=0x%X\n",
145 ioc->name, le16_to_cpu(phy_data->ControllerDevHandle)));
146 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port=0x%X\n",
147 ioc->name, phy_data->Port));
148 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Port Flags=0x%X\n",
149 ioc->name, phy_data->PortFlags));
150 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Flags=0x%X\n",
151 ioc->name, phy_data->PhyFlags));
152 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
153 ioc->name, phy_data->NegotiatedLinkRate));
154 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
155 "Controller PHY Device Info=0x%X\n", ioc->name,
156 le32_to_cpu(phy_data->ControllerPhyDeviceInfo)));
157 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DiscoveryStatus=0x%X\n\n",
158 ioc->name, le32_to_cpu(phy_data->DiscoveryStatus)));
159}
160
161static void mptsas_print_phy_pg0(MPT_ADAPTER *ioc, SasPhyPage0_t *pg0)
162{
163 __le64 sas_address;
164
165 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
166
167 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
168 "---- SAS PHY PAGE 0 ------------\n", ioc->name));
169 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
170 "Attached Device Handle=0x%X\n", ioc->name,
171 le16_to_cpu(pg0->AttachedDevHandle)));
172 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
173 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
174 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
175 "Attached PHY Identifier=0x%X\n", ioc->name,
176 pg0->AttachedPhyIdentifier));
177 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Attached Device Info=0x%X\n",
178 ioc->name, le32_to_cpu(pg0->AttachedDeviceInfo)));
179 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
180 ioc->name, pg0->ProgrammedLinkRate));
181 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Change Count=0x%X\n",
182 ioc->name, pg0->ChangeCount));
183 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Info=0x%X\n\n",
184 ioc->name, le32_to_cpu(pg0->PhyInfo)));
185}
186
187static void mptsas_print_phy_pg1(MPT_ADAPTER *ioc, SasPhyPage1_t *pg1)
188{
189 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
190 "---- SAS PHY PAGE 1 ------------\n", ioc->name));
191 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Invalid Dword Count=0x%x\n",
192 ioc->name, pg1->InvalidDwordCount));
193 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
194 "Running Disparity Error Count=0x%x\n", ioc->name,
195 pg1->RunningDisparityErrorCount));
196 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
197 "Loss Dword Synch Count=0x%x\n", ioc->name,
198 pg1->LossDwordSynchCount));
199 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
200 "PHY Reset Problem Count=0x%x\n\n", ioc->name,
201 pg1->PhyResetProblemCount));
202}
203
204static void mptsas_print_device_pg0(MPT_ADAPTER *ioc, SasDevicePage0_t *pg0)
205{
206 __le64 sas_address;
207
208 memcpy(&sas_address, &pg0->SASAddress, sizeof(__le64));
209
210 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
211 "---- SAS DEVICE PAGE 0 ---------\n", ioc->name));
212 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handle=0x%X\n",
213 ioc->name, le16_to_cpu(pg0->DevHandle)));
214 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Handle=0x%X\n",
215 ioc->name, le16_to_cpu(pg0->ParentDevHandle)));
216 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Enclosure Handle=0x%X\n",
217 ioc->name, le16_to_cpu(pg0->EnclosureHandle)));
218 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Slot=0x%X\n",
219 ioc->name, le16_to_cpu(pg0->Slot)));
220 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SAS Address=0x%llX\n",
221 ioc->name, (unsigned long long)le64_to_cpu(sas_address)));
222 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Target ID=0x%X\n",
223 ioc->name, pg0->TargetID));
224 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Bus=0x%X\n",
225 ioc->name, pg0->Bus));
226 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Parent Phy Num=0x%X\n",
227 ioc->name, pg0->PhyNum));
228 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Access Status=0x%X\n",
229 ioc->name, le16_to_cpu(pg0->AccessStatus)));
230 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Device Info=0x%X\n",
231 ioc->name, le32_to_cpu(pg0->DeviceInfo)));
232 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Flags=0x%X\n",
233 ioc->name, le16_to_cpu(pg0->Flags)));
234 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n\n",
235 ioc->name, pg0->PhysicalPort));
236}
237
238static void mptsas_print_expander_pg1(MPT_ADAPTER *ioc, SasExpanderPage1_t *pg1)
239{
240 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
241 "---- SAS EXPANDER PAGE 1 ------------\n", ioc->name));
242 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Physical Port=0x%X\n",
243 ioc->name, pg1->PhysicalPort));
244 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PHY Identifier=0x%X\n",
245 ioc->name, pg1->PhyIdentifier));
246 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Negotiated Link Rate=0x%X\n",
247 ioc->name, pg1->NegotiatedLinkRate));
248 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Programmed Link Rate=0x%X\n",
249 ioc->name, pg1->ProgrammedLinkRate));
250 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hardware Link Rate=0x%X\n",
251 ioc->name, pg1->HwLinkRate));
252 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Owner Device Handle=0x%X\n",
253 ioc->name, le16_to_cpu(pg1->OwnerDevHandle)));
254 dsasprintk(ioc, printk(MYIOC_s_DEBUG_FMT
255 "Attached Device Handle=0x%X\n\n", ioc->name,
256 le16_to_cpu(pg1->AttachedDevHandle)));
257}
258
259/* inhibit sas firmware event handling */
260static void
261mptsas_fw_event_off(MPT_ADAPTER *ioc)
262{
263 unsigned long flags;
264
265 spin_lock_irqsave(&ioc->fw_event_lock, flags);
266 ioc->fw_events_off = 1;
267 ioc->sas_discovery_quiesce_io = 0;
268 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
269
270}
271
272/* enable sas firmware event handling */
273static void
274mptsas_fw_event_on(MPT_ADAPTER *ioc)
275{
276 unsigned long flags;
277
278 spin_lock_irqsave(&ioc->fw_event_lock, flags);
279 ioc->fw_events_off = 0;
280 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
281}
282
283/* queue a sas firmware event */
284static void
285mptsas_add_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
286 unsigned long delay)
287{
288 unsigned long flags;
289
290 spin_lock_irqsave(&ioc->fw_event_lock, flags);
291 list_add_tail(&fw_event->list, &ioc->fw_event_list);
292 INIT_DELAYED_WORK(&fw_event->work, mptsas_firmware_event_work);
293 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: add (fw_event=0x%p)"
294 "on cpuid %d\n", ioc->name, __func__,
295 fw_event, smp_processor_id()));
296 queue_delayed_work_on(smp_processor_id(), ioc->fw_event_q,
297 &fw_event->work, delay);
298 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
299}
300
301/* requeue a sas firmware event */
302static void
303mptsas_requeue_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event,
304 unsigned long delay)
305{
306 unsigned long flags;
307 spin_lock_irqsave(&ioc->fw_event_lock, flags);
308 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: reschedule task "
309 "(fw_event=0x%p)on cpuid %d\n", ioc->name, __func__,
310 fw_event, smp_processor_id()));
311 fw_event->retries++;
312 queue_delayed_work_on(smp_processor_id(), ioc->fw_event_q,
313 &fw_event->work, msecs_to_jiffies(delay));
314 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
315}
316
317/* free memory associated to a sas firmware event */
318static void
319mptsas_free_fw_event(MPT_ADAPTER *ioc, struct fw_event_work *fw_event)
320{
321 unsigned long flags;
322
323 spin_lock_irqsave(&ioc->fw_event_lock, flags);
324 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: kfree (fw_event=0x%p)\n",
325 ioc->name, __func__, fw_event));
326 list_del(&fw_event->list);
327 kfree(fw_event);
328 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
329}
330
331/* walk the firmware event queue, and either stop or wait for
332 * outstanding events to complete */
333static void
334mptsas_cleanup_fw_event_q(MPT_ADAPTER *ioc)
335{
336 struct fw_event_work *fw_event, *next;
337 struct mptsas_target_reset_event *target_reset_list, *n;
338 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
339
340 /* flush the target_reset_list */
341 if (!list_empty(&hd->target_reset_list)) {
342 list_for_each_entry_safe(target_reset_list, n,
343 &hd->target_reset_list, list) {
344 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
345 "%s: removing target reset for id=%d\n",
346 ioc->name, __func__,
347 target_reset_list->sas_event_data.TargetID));
348 list_del(&target_reset_list->list);
349 kfree(target_reset_list);
350 }
351 }
352
353 if (list_empty(&ioc->fw_event_list) ||
354 !ioc->fw_event_q || in_interrupt())
355 return;
356
357 list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
358 if (cancel_delayed_work(&fw_event->work))
359 mptsas_free_fw_event(ioc, fw_event);
360 }
361}
362
363
364static inline MPT_ADAPTER *phy_to_ioc(struct sas_phy *phy)
365{
366 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
367 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
368}
369
370static inline MPT_ADAPTER *rphy_to_ioc(struct sas_rphy *rphy)
371{
372 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
373 return ((MPT_SCSI_HOST *)shost->hostdata)->ioc;
374}
375
376/*
377 * mptsas_find_portinfo_by_handle
378 *
379 * This function should be called with the sas_topology_mutex already held
380 */
381static struct mptsas_portinfo *
382mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle)
383{
384 struct mptsas_portinfo *port_info, *rc=NULL;
385 int i;
386
387 list_for_each_entry(port_info, &ioc->sas_topology, list)
388 for (i = 0; i < port_info->num_phys; i++)
389 if (port_info->phy_info[i].identify.handle == handle) {
390 rc = port_info;
391 goto out;
392 }
393 out:
394 return rc;
395}
396
397/**
398 * mptsas_find_portinfo_by_sas_address -
399 * @ioc: Pointer to MPT_ADAPTER structure
400 * @handle:
401 *
402 * This function should be called with the sas_topology_mutex already held
403 *
404 **/
405static struct mptsas_portinfo *
406mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
407{
408 struct mptsas_portinfo *port_info, *rc = NULL;
409 int i;
410
411 if (sas_address >= ioc->hba_port_sas_addr &&
412 sas_address < (ioc->hba_port_sas_addr +
413 ioc->hba_port_num_phy))
414 return ioc->hba_port_info;
415
416 mutex_lock(&ioc->sas_topology_mutex);
417 list_for_each_entry(port_info, &ioc->sas_topology, list)
418 for (i = 0; i < port_info->num_phys; i++)
419 if (port_info->phy_info[i].identify.sas_address ==
420 sas_address) {
421 rc = port_info;
422 goto out;
423 }
424 out:
425 mutex_unlock(&ioc->sas_topology_mutex);
426 return rc;
427}
428
429/*
430 * Returns true if there is a scsi end device
431 */
432static inline int
433mptsas_is_end_device(struct mptsas_devinfo * attached)
434{
435 if ((attached->sas_address) &&
436 (attached->device_info &
437 MPI_SAS_DEVICE_INFO_END_DEVICE) &&
438 ((attached->device_info &
439 MPI_SAS_DEVICE_INFO_SSP_TARGET) |
440 (attached->device_info &
441 MPI_SAS_DEVICE_INFO_STP_TARGET) |
442 (attached->device_info &
443 MPI_SAS_DEVICE_INFO_SATA_DEVICE)))
444 return 1;
445 else
446 return 0;
447}
448
449/* no mutex */
450static void
451mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
452{
453 struct mptsas_portinfo *port_info;
454 struct mptsas_phyinfo *phy_info;
455 u8 i;
456
457 if (!port_details)
458 return;
459
460 port_info = port_details->port_info;
461 phy_info = port_info->phy_info;
462
463 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: [%p]: num_phys=%02d "
464 "bitmask=0x%016llX\n", ioc->name, __func__, port_details,
465 port_details->num_phys, (unsigned long long)
466 port_details->phy_bitmask));
467
468 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
469 if(phy_info->port_details != port_details)
470 continue;
471 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
472 mptsas_set_rphy(ioc, phy_info, NULL);
473 phy_info->port_details = NULL;
474 }
475 kfree(port_details);
476}
477
478static inline struct sas_rphy *
479mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
480{
481 if (phy_info->port_details)
482 return phy_info->port_details->rphy;
483 else
484 return NULL;
485}
486
487static inline void
488mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
489{
490 if (phy_info->port_details) {
491 phy_info->port_details->rphy = rphy;
492 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
493 ioc->name, rphy));
494 }
495
496 if (rphy) {
497 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
498 &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
499 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
500 ioc->name, rphy, rphy->dev.release));
501 }
502}
503
504static inline struct sas_port *
505mptsas_get_port(struct mptsas_phyinfo *phy_info)
506{
507 if (phy_info->port_details)
508 return phy_info->port_details->port;
509 else
510 return NULL;
511}
512
513static inline void
514mptsas_set_port(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_port *port)
515{
516 if (phy_info->port_details)
517 phy_info->port_details->port = port;
518
519 if (port) {
520 dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
521 &port->dev, MYIOC_s_FMT "add:", ioc->name));
522 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "port=%p release=%p\n",
523 ioc->name, port, port->dev.release));
524 }
525}
526
527static inline struct scsi_target *
528mptsas_get_starget(struct mptsas_phyinfo *phy_info)
529{
530 if (phy_info->port_details)
531 return phy_info->port_details->starget;
532 else
533 return NULL;
534}
535
536static inline void
537mptsas_set_starget(struct mptsas_phyinfo *phy_info, struct scsi_target *
538starget)
539{
540 if (phy_info->port_details)
541 phy_info->port_details->starget = starget;
542}
543
544/**
545 * mptsas_add_device_component -
546 * @ioc: Pointer to MPT_ADAPTER structure
547 * @channel: fw mapped id's
548 * @id:
549 * @sas_address:
550 * @device_info:
551 *
552 **/
553static void
554mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id,
555 u64 sas_address, u32 device_info, u16 slot, u64 enclosure_logical_id)
556{
557 struct mptsas_device_info *sas_info, *next;
558 struct scsi_device *sdev;
559 struct scsi_target *starget;
560 struct sas_rphy *rphy;
561
562 /*
563 * Delete all matching devices out of the list
564 */
565 mutex_lock(&ioc->sas_device_info_mutex);
566 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
567 list) {
568 if (!sas_info->is_logical_volume &&
569 (sas_info->sas_address == sas_address ||
570 (sas_info->fw.channel == channel &&
571 sas_info->fw.id == id))) {
572 list_del(&sas_info->list);
573 kfree(sas_info);
574 }
575 }
576
577 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
578 if (!sas_info)
579 goto out;
580
581 /*
582 * Set Firmware mapping
583 */
584 sas_info->fw.id = id;
585 sas_info->fw.channel = channel;
586
587 sas_info->sas_address = sas_address;
588 sas_info->device_info = device_info;
589 sas_info->slot = slot;
590 sas_info->enclosure_logical_id = enclosure_logical_id;
591 INIT_LIST_HEAD(&sas_info->list);
592 list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
593
594 /*
595 * Set OS mapping
596 */
597 shost_for_each_device(sdev, ioc->sh) {
598 starget = scsi_target(sdev);
599 rphy = dev_to_rphy(starget->dev.parent);
600 if (rphy->identify.sas_address == sas_address) {
601 sas_info->os.id = starget->id;
602 sas_info->os.channel = starget->channel;
603 }
604 }
605
606 out:
607 mutex_unlock(&ioc->sas_device_info_mutex);
608 return;
609}
610
611/**
612 * mptsas_add_device_component_by_fw -
613 * @ioc: Pointer to MPT_ADAPTER structure
614 * @channel: fw mapped id's
615 * @id:
616 *
617 **/
618static void
619mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id)
620{
621 struct mptsas_devinfo sas_device;
622 struct mptsas_enclosure enclosure_info;
623 int rc;
624
625 rc = mptsas_sas_device_pg0(ioc, &sas_device,
626 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
627 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
628 (channel << 8) + id);
629 if (rc)
630 return;
631
632 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
633 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
634 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
635 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
636 sas_device.handle_enclosure);
637
638 mptsas_add_device_component(ioc, sas_device.channel,
639 sas_device.id, sas_device.sas_address, sas_device.device_info,
640 sas_device.slot, enclosure_info.enclosure_logical_id);
641}
642
643/**
644 * mptsas_add_device_component_starget_ir - Handle Integrated RAID, adding each individual device to list
645 * @ioc: Pointer to MPT_ADAPTER structure
646 * @channel: fw mapped id's
647 * @id:
648 *
649 **/
650static void
651mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc,
652 struct scsi_target *starget)
653{
654 CONFIGPARMS cfg;
655 ConfigPageHeader_t hdr;
656 dma_addr_t dma_handle;
657 pRaidVolumePage0_t buffer = NULL;
658 int i;
659 RaidPhysDiskPage0_t phys_disk;
660 struct mptsas_device_info *sas_info, *next;
661
662 memset(&cfg, 0 , sizeof(CONFIGPARMS));
663 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
664 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
665 /* assumption that all volumes on channel = 0 */
666 cfg.pageAddr = starget->id;
667 cfg.cfghdr.hdr = &hdr;
668 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
669 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
670
671 if (mpt_config(ioc, &cfg) != 0)
672 goto out;
673
674 if (!hdr.PageLength)
675 goto out;
676
677 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
678 &dma_handle);
679
680 if (!buffer)
681 goto out;
682
683 cfg.physAddr = dma_handle;
684 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
685
686 if (mpt_config(ioc, &cfg) != 0)
687 goto out;
688
689 if (!buffer->NumPhysDisks)
690 goto out;
691
692 /*
693 * Adding entry for hidden components
694 */
695 for (i = 0; i < buffer->NumPhysDisks; i++) {
696
697 if (mpt_raid_phys_disk_pg0(ioc,
698 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
699 continue;
700
701 mptsas_add_device_component_by_fw(ioc, phys_disk.PhysDiskBus,
702 phys_disk.PhysDiskID);
703
704 mutex_lock(&ioc->sas_device_info_mutex);
705 list_for_each_entry(sas_info, &ioc->sas_device_info_list,
706 list) {
707 if (!sas_info->is_logical_volume &&
708 (sas_info->fw.channel == phys_disk.PhysDiskBus &&
709 sas_info->fw.id == phys_disk.PhysDiskID)) {
710 sas_info->is_hidden_raid_component = 1;
711 sas_info->volume_id = starget->id;
712 }
713 }
714 mutex_unlock(&ioc->sas_device_info_mutex);
715
716 }
717
718 /*
719 * Delete all matching devices out of the list
720 */
721 mutex_lock(&ioc->sas_device_info_mutex);
722 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
723 list) {
724 if (sas_info->is_logical_volume && sas_info->fw.id ==
725 starget->id) {
726 list_del(&sas_info->list);
727 kfree(sas_info);
728 }
729 }
730
731 sas_info = kzalloc(sizeof(struct mptsas_device_info), GFP_KERNEL);
732 if (sas_info) {
733 sas_info->fw.id = starget->id;
734 sas_info->os.id = starget->id;
735 sas_info->os.channel = starget->channel;
736 sas_info->is_logical_volume = 1;
737 INIT_LIST_HEAD(&sas_info->list);
738 list_add_tail(&sas_info->list, &ioc->sas_device_info_list);
739 }
740 mutex_unlock(&ioc->sas_device_info_mutex);
741
742 out:
743 if (buffer)
744 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
745 dma_handle);
746}
747
748/**
749 * mptsas_add_device_component_starget -
750 * @ioc: Pointer to MPT_ADAPTER structure
751 * @starget:
752 *
753 **/
754static void
755mptsas_add_device_component_starget(MPT_ADAPTER *ioc,
756 struct scsi_target *starget)
757{
758 VirtTarget *vtarget;
759 struct sas_rphy *rphy;
760 struct mptsas_phyinfo *phy_info = NULL;
761 struct mptsas_enclosure enclosure_info;
762
763 rphy = dev_to_rphy(starget->dev.parent);
764 vtarget = starget->hostdata;
765 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
766 rphy->identify.sas_address);
767 if (!phy_info)
768 return;
769
770 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
771 mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
772 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
773 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT),
774 phy_info->attached.handle_enclosure);
775
776 mptsas_add_device_component(ioc, phy_info->attached.channel,
777 phy_info->attached.id, phy_info->attached.sas_address,
778 phy_info->attached.device_info,
779 phy_info->attached.slot, enclosure_info.enclosure_logical_id);
780}
781
782/**
783 * mptsas_del_device_component_by_os - Once a device has been removed, we mark the entry in the list as being cached
784 * @ioc: Pointer to MPT_ADAPTER structure
785 * @channel: os mapped id's
786 * @id:
787 *
788 **/
789static void
790mptsas_del_device_component_by_os(MPT_ADAPTER *ioc, u8 channel, u8 id)
791{
792 struct mptsas_device_info *sas_info, *next;
793
794 /*
795 * Set is_cached flag
796 */
797 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
798 list) {
799 if (sas_info->os.channel == channel && sas_info->os.id == id)
800 sas_info->is_cached = 1;
801 }
802}
803
804/**
805 * mptsas_del_device_components - Cleaning the list
806 * @ioc: Pointer to MPT_ADAPTER structure
807 *
808 **/
809static void
810mptsas_del_device_components(MPT_ADAPTER *ioc)
811{
812 struct mptsas_device_info *sas_info, *next;
813
814 mutex_lock(&ioc->sas_device_info_mutex);
815 list_for_each_entry_safe(sas_info, next, &ioc->sas_device_info_list,
816 list) {
817 list_del(&sas_info->list);
818 kfree(sas_info);
819 }
820 mutex_unlock(&ioc->sas_device_info_mutex);
821}
822
823
824/*
825 * mptsas_setup_wide_ports
826 *
827 * Updates for new and existing narrow/wide port configuration
828 * in the sas_topology
829 */
830static void
831mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
832{
833 struct mptsas_portinfo_details * port_details;
834 struct mptsas_phyinfo *phy_info, *phy_info_cmp;
835 u64 sas_address;
836 int i, j;
837
838 mutex_lock(&ioc->sas_topology_mutex);
839
840 phy_info = port_info->phy_info;
841 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
842 if (phy_info->attached.handle)
843 continue;
844 port_details = phy_info->port_details;
845 if (!port_details)
846 continue;
847 if (port_details->num_phys < 2)
848 continue;
849 /*
850 * Removing a phy from a port, letting the last
851 * phy be removed by firmware events.
852 */
853 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
854 "%s: [%p]: deleting phy = %d\n",
855 ioc->name, __func__, port_details, i));
856 port_details->num_phys--;
857 port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
858 memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
859 if (phy_info->phy) {
860 devtprintk(ioc, dev_printk(KERN_DEBUG,
861 &phy_info->phy->dev, MYIOC_s_FMT
862 "delete phy %d, phy-obj (0x%p)\n", ioc->name,
863 phy_info->phy_id, phy_info->phy));
864 sas_port_delete_phy(port_details->port, phy_info->phy);
865 }
866 phy_info->port_details = NULL;
867 }
868
869 /*
870 * Populate and refresh the tree
871 */
872 phy_info = port_info->phy_info;
873 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
874 sas_address = phy_info->attached.sas_address;
875 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "phy_id=%d sas_address=0x%018llX\n",
876 ioc->name, i, (unsigned long long)sas_address));
877 if (!sas_address)
878 continue;
879 port_details = phy_info->port_details;
880 /*
881 * Forming a port
882 */
883 if (!port_details) {
884 port_details = kzalloc(sizeof(struct
885 mptsas_portinfo_details), GFP_KERNEL);
886 if (!port_details)
887 goto out;
888 port_details->num_phys = 1;
889 port_details->port_info = port_info;
890 if (phy_info->phy_id < 64 )
891 port_details->phy_bitmask |=
892 (1 << phy_info->phy_id);
893 phy_info->sas_port_add_phy=1;
894 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
895 "phy_id=%d sas_address=0x%018llX\n",
896 ioc->name, i, (unsigned long long)sas_address));
897 phy_info->port_details = port_details;
898 }
899
900 if (i == port_info->num_phys - 1)
901 continue;
902 phy_info_cmp = &port_info->phy_info[i + 1];
903 for (j = i + 1 ; j < port_info->num_phys ; j++,
904 phy_info_cmp++) {
905 if (!phy_info_cmp->attached.sas_address)
906 continue;
907 if (sas_address != phy_info_cmp->attached.sas_address)
908 continue;
909 if (phy_info_cmp->port_details == port_details )
910 continue;
911 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
912 "\t\tphy_id=%d sas_address=0x%018llX\n",
913 ioc->name, j, (unsigned long long)
914 phy_info_cmp->attached.sas_address));
915 if (phy_info_cmp->port_details) {
916 port_details->rphy =
917 mptsas_get_rphy(phy_info_cmp);
918 port_details->port =
919 mptsas_get_port(phy_info_cmp);
920 port_details->starget =
921 mptsas_get_starget(phy_info_cmp);
922 port_details->num_phys =
923 phy_info_cmp->port_details->num_phys;
924 if (!phy_info_cmp->port_details->num_phys)
925 kfree(phy_info_cmp->port_details);
926 } else
927 phy_info_cmp->sas_port_add_phy=1;
928 /*
929 * Adding a phy to a port
930 */
931 phy_info_cmp->port_details = port_details;
932 if (phy_info_cmp->phy_id < 64 )
933 port_details->phy_bitmask |=
934 (1 << phy_info_cmp->phy_id);
935 port_details->num_phys++;
936 }
937 }
938
939 out:
940
941 for (i = 0; i < port_info->num_phys; i++) {
942 port_details = port_info->phy_info[i].port_details;
943 if (!port_details)
944 continue;
945 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT
946 "%s: [%p]: phy_id=%02d num_phys=%02d "
947 "bitmask=0x%016llX\n", ioc->name, __func__,
948 port_details, i, port_details->num_phys,
949 (unsigned long long)port_details->phy_bitmask));
950 dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tport = %p rphy=%p\n",
951 ioc->name, port_details->port, port_details->rphy));
952 }
953 dsaswideprintk(ioc, printk("\n"));
954 mutex_unlock(&ioc->sas_topology_mutex);
955}
956
957/**
958 * csmisas_find_vtarget
959 *
960 * @ioc
961 * @volume_id
962 * @volume_bus
963 *
964 **/
965static VirtTarget *
966mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
967{
968 struct scsi_device *sdev;
969 VirtDevice *vdevice;
970 VirtTarget *vtarget = NULL;
971
972 shost_for_each_device(sdev, ioc->sh) {
973 vdevice = sdev->hostdata;
974 if ((vdevice == NULL) ||
975 (vdevice->vtarget == NULL))
976 continue;
977 if ((vdevice->vtarget->tflags &
978 MPT_TARGET_FLAGS_RAID_COMPONENT ||
979 vdevice->vtarget->raidVolume))
980 continue;
981 if (vdevice->vtarget->id == id &&
982 vdevice->vtarget->channel == channel)
983 vtarget = vdevice->vtarget;
984 }
985 return vtarget;
986}
987
988static void
989mptsas_queue_device_delete(MPT_ADAPTER *ioc,
990 MpiEventDataSasDeviceStatusChange_t *sas_event_data)
991{
992 struct fw_event_work *fw_event;
993
994 fw_event = kzalloc(sizeof(*fw_event) +
995 sizeof(MpiEventDataSasDeviceStatusChange_t),
996 GFP_ATOMIC);
997 if (!fw_event) {
998 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
999 ioc->name, __func__, __LINE__);
1000 return;
1001 }
1002 memcpy(fw_event->event_data, sas_event_data,
1003 sizeof(MpiEventDataSasDeviceStatusChange_t));
1004 fw_event->event = MPI_EVENT_SAS_DEVICE_STATUS_CHANGE;
1005 fw_event->ioc = ioc;
1006 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
1007}
1008
1009static void
1010mptsas_queue_rescan(MPT_ADAPTER *ioc)
1011{
1012 struct fw_event_work *fw_event;
1013
1014 fw_event = kzalloc(sizeof(*fw_event), GFP_ATOMIC);
1015 if (!fw_event) {
1016 printk(MYIOC_s_WARN_FMT "%s: failed at (line=%d)\n",
1017 ioc->name, __func__, __LINE__);
1018 return;
1019 }
1020 fw_event->event = -1;
1021 fw_event->ioc = ioc;
1022 mptsas_add_fw_event(ioc, fw_event, msecs_to_jiffies(1));
1023}
1024
1025
1026/**
1027 * mptsas_target_reset
1028 *
1029 * Issues TARGET_RESET to end device using handshaking method
1030 *
1031 * @ioc
1032 * @channel
1033 * @id
1034 *
1035 * Returns (1) success
1036 * (0) failure
1037 *
1038 **/
1039static int
1040mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
1041{
1042 MPT_FRAME_HDR *mf;
1043 SCSITaskMgmt_t *pScsiTm;
1044 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0)
1045 return 0;
1046
1047
1048 mf = mpt_get_msg_frame(mptsasDeviceResetCtx, ioc);
1049 if (mf == NULL) {
1050 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
1051 "%s, no msg frames @%d!!\n", ioc->name,
1052 __func__, __LINE__));
1053 goto out_fail;
1054 }
1055
1056 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
1057 ioc->name, mf));
1058
1059 /* Format the Request
1060 */
1061 pScsiTm = (SCSITaskMgmt_t *) mf;
1062 memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
1063 pScsiTm->TargetID = id;
1064 pScsiTm->Bus = channel;
1065 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
1066 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
1067 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
1068
1069 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
1070
1071 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1072 "TaskMgmt type=%d (sas device delete) fw_channel = %d fw_id = %d)\n",
1073 ioc->name, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, channel, id));
1074
1075 mpt_put_msg_frame_hi_pri(mptsasDeviceResetCtx, ioc, mf);
1076
1077 return 1;
1078
1079 out_fail:
1080
1081 mpt_clear_taskmgmt_in_progress_flag(ioc);
1082 return 0;
1083}
1084
1085static void
1086mptsas_block_io_sdev(struct scsi_device *sdev, void *data)
1087{
1088 scsi_device_set_state(sdev, SDEV_BLOCK);
1089}
1090
1091static void
1092mptsas_block_io_starget(struct scsi_target *starget)
1093{
1094 if (starget)
1095 starget_for_each_device(starget, NULL, mptsas_block_io_sdev);
1096}
1097
1098/**
1099 * mptsas_target_reset_queue
1100 *
1101 * Receive request for TARGET_RESET after receiving an firmware
1102 * event NOT_RESPONDING_EVENT, then put command in link list
1103 * and queue if task_queue already in use.
1104 *
1105 * @ioc
1106 * @sas_event_data
1107 *
1108 **/
1109static void
1110mptsas_target_reset_queue(MPT_ADAPTER *ioc,
1111 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
1112{
1113 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1114 VirtTarget *vtarget = NULL;
1115 struct mptsas_target_reset_event *target_reset_list;
1116 u8 id, channel;
1117
1118 id = sas_event_data->TargetID;
1119 channel = sas_event_data->Bus;
1120
1121 vtarget = mptsas_find_vtarget(ioc, channel, id);
1122 if (vtarget) {
1123 mptsas_block_io_starget(vtarget->starget);
1124 vtarget->deleted = 1; /* block IO */
1125 }
1126
1127 target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event),
1128 GFP_ATOMIC);
1129 if (!target_reset_list) {
1130 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT
1131 "%s, failed to allocate mem @%d..!!\n",
1132 ioc->name, __func__, __LINE__));
1133 return;
1134 }
1135
1136 memcpy(&target_reset_list->sas_event_data, sas_event_data,
1137 sizeof(*sas_event_data));
1138 list_add_tail(&target_reset_list->list, &hd->target_reset_list);
1139
1140 target_reset_list->time_count = jiffies;
1141
1142 if (mptsas_target_reset(ioc, channel, id)) {
1143 target_reset_list->target_reset_issued = 1;
1144 }
1145}
1146
1147/**
1148 * mptsas_schedule_target_reset- send pending target reset
1149 * @iocp: per adapter object
1150 *
1151 * This function will delete scheduled target reset from the list and
1152 * try to send next target reset. This will be called from completion
1153 * context of any Task management command.
1154 */
1155
1156void
1157mptsas_schedule_target_reset(void *iocp)
1158{
1159 MPT_ADAPTER *ioc = (MPT_ADAPTER *)(iocp);
1160 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1161 struct list_head *head = &hd->target_reset_list;
1162 struct mptsas_target_reset_event *target_reset_list;
1163 u8 id, channel;
1164 /*
1165 * issue target reset to next device in the queue
1166 */
1167
1168 if (list_empty(head))
1169 return;
1170
1171 target_reset_list = list_entry(head->next,
1172 struct mptsas_target_reset_event, list);
1173
1174 id = target_reset_list->sas_event_data.TargetID;
1175 channel = target_reset_list->sas_event_data.Bus;
1176 target_reset_list->time_count = jiffies;
1177
1178 if (mptsas_target_reset(ioc, channel, id))
1179 target_reset_list->target_reset_issued = 1;
1180 return;
1181}
1182
1183
1184/**
1185 * mptsas_taskmgmt_complete - complete SAS task management function
1186 * @ioc: Pointer to MPT_ADAPTER structure
1187 *
1188 * Completion for TARGET_RESET after NOT_RESPONDING_EVENT, enable work
1189 * queue to finish off removing device from upper layers. then send next
1190 * TARGET_RESET in the queue.
1191 **/
1192static int
1193mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
1194{
1195 MPT_SCSI_HOST *hd = shost_priv(ioc->sh);
1196 struct list_head *head = &hd->target_reset_list;
1197 u8 id, channel;
1198 struct mptsas_target_reset_event *target_reset_list;
1199 SCSITaskMgmtReply_t *pScsiTmReply;
1200
1201 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed: "
1202 "(mf = %p, mr = %p)\n", ioc->name, mf, mr));
1203
1204 pScsiTmReply = (SCSITaskMgmtReply_t *)mr;
1205 if (!pScsiTmReply)
1206 return 0;
1207
1208 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1209 "\tTaskMgmt completed: fw_channel = %d, fw_id = %d,\n"
1210 "\ttask_type = 0x%02X, iocstatus = 0x%04X "
1211 "loginfo = 0x%08X,\n\tresponse_code = 0x%02X, "
1212 "term_cmnds = %d\n", ioc->name,
1213 pScsiTmReply->Bus, pScsiTmReply->TargetID,
1214 pScsiTmReply->TaskType,
1215 le16_to_cpu(pScsiTmReply->IOCStatus),
1216 le32_to_cpu(pScsiTmReply->IOCLogInfo),
1217 pScsiTmReply->ResponseCode,
1218 le32_to_cpu(pScsiTmReply->TerminationCount)));
1219
1220 if (pScsiTmReply->ResponseCode)
1221 mptscsih_taskmgmt_response_code(ioc,
1222 pScsiTmReply->ResponseCode);
1223
1224 if (pScsiTmReply->TaskType ==
1225 MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK || pScsiTmReply->TaskType ==
1226 MPI_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET) {
1227 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
1228 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
1229 memcpy(ioc->taskmgmt_cmds.reply, mr,
1230 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
1231 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
1232 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
1233 complete(&ioc->taskmgmt_cmds.done);
1234 return 1;
1235 }
1236 return 0;
1237 }
1238
1239 mpt_clear_taskmgmt_in_progress_flag(ioc);
1240
1241 if (list_empty(head))
1242 return 1;
1243
1244 target_reset_list = list_entry(head->next,
1245 struct mptsas_target_reset_event, list);
1246
1247 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1248 "TaskMgmt: completed (%d seconds)\n",
1249 ioc->name, jiffies_to_msecs(jiffies -
1250 target_reset_list->time_count)/1000));
1251
1252 id = pScsiTmReply->TargetID;
1253 channel = pScsiTmReply->Bus;
1254 target_reset_list->time_count = jiffies;
1255
1256 /*
1257 * retry target reset
1258 */
1259 if (!target_reset_list->target_reset_issued) {
1260 if (mptsas_target_reset(ioc, channel, id))
1261 target_reset_list->target_reset_issued = 1;
1262 return 1;
1263 }
1264
1265 /*
1266 * enable work queue to remove device from upper layers
1267 */
1268 list_del(&target_reset_list->list);
1269 if (!ioc->fw_events_off)
1270 mptsas_queue_device_delete(ioc,
1271 &target_reset_list->sas_event_data);
1272
1273
1274 ioc->schedule_target_reset(ioc);
1275
1276 return 1;
1277}
1278
1279/**
1280 * mptscsih_ioc_reset
1281 *
1282 * @ioc
1283 * @reset_phase
1284 *
1285 **/
1286static int
1287mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
1288{
1289 MPT_SCSI_HOST *hd;
1290 int rc;
1291
1292 rc = mptscsih_ioc_reset(ioc, reset_phase);
1293 if ((ioc->bus_type != SAS) || (!rc))
1294 return rc;
1295
1296 hd = shost_priv(ioc->sh);
1297 if (!hd->ioc)
1298 goto out;
1299
1300 switch (reset_phase) {
1301 case MPT_IOC_SETUP_RESET:
1302 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1303 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
1304 mptsas_fw_event_off(ioc);
1305 break;
1306 case MPT_IOC_PRE_RESET:
1307 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1308 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
1309 break;
1310 case MPT_IOC_POST_RESET:
1311 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1312 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
1313 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
1314 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_DID_IOCRESET;
1315 complete(&ioc->sas_mgmt.done);
1316 }
1317 mptsas_cleanup_fw_event_q(ioc);
1318 mptsas_queue_rescan(ioc);
1319 break;
1320 default:
1321 break;
1322 }
1323
1324 out:
1325 return rc;
1326}
1327
1328
1329/**
1330 * enum device_state -
1331 * @DEVICE_RETRY: need to retry the TUR
1332 * @DEVICE_ERROR: TUR return error, don't add device
1333 * @DEVICE_READY: device can be added
1334 *
1335 */
1336enum device_state{
1337 DEVICE_RETRY,
1338 DEVICE_ERROR,
1339 DEVICE_READY,
1340};
1341
1342static int
1343mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
1344 u32 form, u32 form_specific)
1345{
1346 ConfigExtendedPageHeader_t hdr;
1347 CONFIGPARMS cfg;
1348 SasEnclosurePage0_t *buffer;
1349 dma_addr_t dma_handle;
1350 int error;
1351 __le64 le_identifier;
1352
1353 memset(&hdr, 0, sizeof(hdr));
1354 hdr.PageVersion = MPI_SASENCLOSURE0_PAGEVERSION;
1355 hdr.PageNumber = 0;
1356 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1357 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_ENCLOSURE;
1358
1359 cfg.cfghdr.ehdr = &hdr;
1360 cfg.physAddr = -1;
1361 cfg.pageAddr = form + form_specific;
1362 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
1363 cfg.dir = 0; /* read */
1364 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
1365
1366 error = mpt_config(ioc, &cfg);
1367 if (error)
1368 goto out;
1369 if (!hdr.ExtPageLength) {
1370 error = -ENXIO;
1371 goto out;
1372 }
1373
1374 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1375 &dma_handle);
1376 if (!buffer) {
1377 error = -ENOMEM;
1378 goto out;
1379 }
1380
1381 cfg.physAddr = dma_handle;
1382 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
1383
1384 error = mpt_config(ioc, &cfg);
1385 if (error)
1386 goto out_free_consistent;
1387
1388 /* save config data */
1389 memcpy(&le_identifier, &buffer->EnclosureLogicalID, sizeof(__le64));
1390 enclosure->enclosure_logical_id = le64_to_cpu(le_identifier);
1391 enclosure->enclosure_handle = le16_to_cpu(buffer->EnclosureHandle);
1392 enclosure->flags = le16_to_cpu(buffer->Flags);
1393 enclosure->num_slot = le16_to_cpu(buffer->NumSlots);
1394 enclosure->start_slot = le16_to_cpu(buffer->StartSlot);
1395 enclosure->start_id = buffer->StartTargetID;
1396 enclosure->start_channel = buffer->StartBus;
1397 enclosure->sep_id = buffer->SEPTargetID;
1398 enclosure->sep_channel = buffer->SEPBus;
1399
1400 out_free_consistent:
1401 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
1402 buffer, dma_handle);
1403 out:
1404 return error;
1405}
1406
1407/**
1408 * mptsas_add_end_device - report a new end device to sas transport layer
1409 * @ioc: Pointer to MPT_ADAPTER structure
1410 * @phy_info: describes attached device
1411 *
1412 * return (0) success (1) failure
1413 *
1414 **/
1415static int
1416mptsas_add_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1417{
1418 struct sas_rphy *rphy;
1419 struct sas_port *port;
1420 struct sas_identify identify;
1421 char *ds = NULL;
1422 u8 fw_id;
1423
1424 if (!phy_info) {
1425 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1426 "%s: exit at line=%d\n", ioc->name,
1427 __func__, __LINE__));
1428 return 1;
1429 }
1430
1431 fw_id = phy_info->attached.id;
1432
1433 if (mptsas_get_rphy(phy_info)) {
1434 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1435 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1436 __func__, fw_id, __LINE__));
1437 return 2;
1438 }
1439
1440 port = mptsas_get_port(phy_info);
1441 if (!port) {
1442 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1443 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1444 __func__, fw_id, __LINE__));
1445 return 3;
1446 }
1447
1448 if (phy_info->attached.device_info &
1449 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1450 ds = "ssp";
1451 if (phy_info->attached.device_info &
1452 MPI_SAS_DEVICE_INFO_STP_TARGET)
1453 ds = "stp";
1454 if (phy_info->attached.device_info &
1455 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1456 ds = "sata";
1457
1458 printk(MYIOC_s_INFO_FMT "attaching %s device: fw_channel %d, fw_id %d,"
1459 " phy %d, sas_addr 0x%llx\n", ioc->name, ds,
1460 phy_info->attached.channel, phy_info->attached.id,
1461 phy_info->attached.phy_id, (unsigned long long)
1462 phy_info->attached.sas_address);
1463
1464 mptsas_parse_device_info(&identify, &phy_info->attached);
1465 rphy = sas_end_device_alloc(port);
1466 if (!rphy) {
1467 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1468 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1469 __func__, fw_id, __LINE__));
1470 return 5; /* non-fatal: an rphy can be added later */
1471 }
1472
1473 rphy->identify = identify;
1474 if (sas_rphy_add(rphy)) {
1475 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1476 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1477 __func__, fw_id, __LINE__));
1478 sas_rphy_free(rphy);
1479 return 6;
1480 }
1481 mptsas_set_rphy(ioc, phy_info, rphy);
1482 return 0;
1483}
1484
1485/**
1486 * mptsas_del_end_device - report a deleted end device to sas transport layer
1487 * @ioc: Pointer to MPT_ADAPTER structure
1488 * @phy_info: describes attached device
1489 *
1490 **/
1491static void
1492mptsas_del_end_device(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info)
1493{
1494 struct sas_rphy *rphy;
1495 struct sas_port *port;
1496 struct mptsas_portinfo *port_info;
1497 struct mptsas_phyinfo *phy_info_parent;
1498 int i;
1499 char *ds = NULL;
1500 u8 fw_id;
1501 u64 sas_address;
1502
1503 if (!phy_info)
1504 return;
1505
1506 fw_id = phy_info->attached.id;
1507 sas_address = phy_info->attached.sas_address;
1508
1509 if (!phy_info->port_details) {
1510 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1511 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1512 __func__, fw_id, __LINE__));
1513 return;
1514 }
1515 rphy = mptsas_get_rphy(phy_info);
1516 if (!rphy) {
1517 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1518 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1519 __func__, fw_id, __LINE__));
1520 return;
1521 }
1522
1523 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_INITIATOR
1524 || phy_info->attached.device_info
1525 & MPI_SAS_DEVICE_INFO_SMP_INITIATOR
1526 || phy_info->attached.device_info
1527 & MPI_SAS_DEVICE_INFO_STP_INITIATOR)
1528 ds = "initiator";
1529 if (phy_info->attached.device_info &
1530 MPI_SAS_DEVICE_INFO_SSP_TARGET)
1531 ds = "ssp";
1532 if (phy_info->attached.device_info &
1533 MPI_SAS_DEVICE_INFO_STP_TARGET)
1534 ds = "stp";
1535 if (phy_info->attached.device_info &
1536 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
1537 ds = "sata";
1538
1539 dev_printk(KERN_DEBUG, &rphy->dev, MYIOC_s_FMT
1540 "removing %s device: fw_channel %d, fw_id %d, phy %d,"
1541 "sas_addr 0x%llx\n", ioc->name, ds, phy_info->attached.channel,
1542 phy_info->attached.id, phy_info->attached.phy_id,
1543 (unsigned long long) sas_address);
1544
1545 port = mptsas_get_port(phy_info);
1546 if (!port) {
1547 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1548 "%s: fw_id=%d exit at line=%d\n", ioc->name,
1549 __func__, fw_id, __LINE__));
1550 return;
1551 }
1552 port_info = phy_info->portinfo;
1553 phy_info_parent = port_info->phy_info;
1554 for (i = 0; i < port_info->num_phys; i++, phy_info_parent++) {
1555 if (!phy_info_parent->phy)
1556 continue;
1557 if (phy_info_parent->attached.sas_address !=
1558 sas_address)
1559 continue;
1560 dev_printk(KERN_DEBUG, &phy_info_parent->phy->dev,
1561 MYIOC_s_FMT "delete phy %d, phy-obj (0x%p)\n",
1562 ioc->name, phy_info_parent->phy_id,
1563 phy_info_parent->phy);
1564 sas_port_delete_phy(port, phy_info_parent->phy);
1565 }
1566
1567 dev_printk(KERN_DEBUG, &port->dev, MYIOC_s_FMT
1568 "delete port %d, sas_addr (0x%llx)\n", ioc->name,
1569 port->port_identifier, (unsigned long long)sas_address);
1570 sas_port_delete(port);
1571 mptsas_set_port(ioc, phy_info, NULL);
1572 mptsas_port_delete(ioc, phy_info->port_details);
1573}
1574
1575static struct mptsas_phyinfo *
1576mptsas_refreshing_device_handles(MPT_ADAPTER *ioc,
1577 struct mptsas_devinfo *sas_device)
1578{
1579 struct mptsas_phyinfo *phy_info;
1580 struct mptsas_portinfo *port_info;
1581 int i;
1582
1583 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
1584 sas_device->sas_address);
1585 if (!phy_info)
1586 goto out;
1587 port_info = phy_info->portinfo;
1588 if (!port_info)
1589 goto out;
1590 mutex_lock(&ioc->sas_topology_mutex);
1591 for (i = 0; i < port_info->num_phys; i++) {
1592 if (port_info->phy_info[i].attached.sas_address !=
1593 sas_device->sas_address)
1594 continue;
1595 port_info->phy_info[i].attached.channel = sas_device->channel;
1596 port_info->phy_info[i].attached.id = sas_device->id;
1597 port_info->phy_info[i].attached.sas_address =
1598 sas_device->sas_address;
1599 port_info->phy_info[i].attached.handle = sas_device->handle;
1600 port_info->phy_info[i].attached.handle_parent =
1601 sas_device->handle_parent;
1602 port_info->phy_info[i].attached.handle_enclosure =
1603 sas_device->handle_enclosure;
1604 }
1605 mutex_unlock(&ioc->sas_topology_mutex);
1606 out:
1607 return phy_info;
1608}
1609
1610/**
1611 * mptsas_firmware_event_work - work thread for processing fw events
1612 * @work: work queue payload containing info describing the event
1613 * Context: user
1614 *
1615 */
1616static void
1617mptsas_firmware_event_work(struct work_struct *work)
1618{
1619 struct fw_event_work *fw_event =
1620 container_of(work, struct fw_event_work, work.work);
1621 MPT_ADAPTER *ioc = fw_event->ioc;
1622
1623 /* special rescan topology handling */
1624 if (fw_event->event == -1) {
1625 if (ioc->in_rescan) {
1626 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1627 "%s: rescan ignored as it is in progress\n",
1628 ioc->name, __func__));
1629 return;
1630 }
1631 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: rescan after "
1632 "reset\n", ioc->name, __func__));
1633 ioc->in_rescan = 1;
1634 mptsas_not_responding_devices(ioc);
1635 mptsas_scan_sas_topology(ioc);
1636 ioc->in_rescan = 0;
1637 mptsas_free_fw_event(ioc, fw_event);
1638 mptsas_fw_event_on(ioc);
1639 return;
1640 }
1641
1642 /* events handling turned off during host reset */
1643 if (ioc->fw_events_off) {
1644 mptsas_free_fw_event(ioc, fw_event);
1645 return;
1646 }
1647
1648 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: fw_event=(0x%p), "
1649 "event = (0x%02x)\n", ioc->name, __func__, fw_event,
1650 (fw_event->event & 0xFF)));
1651
1652 switch (fw_event->event) {
1653 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
1654 mptsas_send_sas_event(fw_event);
1655 break;
1656 case MPI_EVENT_INTEGRATED_RAID:
1657 mptsas_send_raid_event(fw_event);
1658 break;
1659 case MPI_EVENT_IR2:
1660 mptsas_send_ir2_event(fw_event);
1661 break;
1662 case MPI_EVENT_PERSISTENT_TABLE_FULL:
1663 mptbase_sas_persist_operation(ioc,
1664 MPI_SAS_OP_CLEAR_NOT_PRESENT);
1665 mptsas_free_fw_event(ioc, fw_event);
1666 break;
1667 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
1668 mptsas_broadcast_primitive_work(fw_event);
1669 break;
1670 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
1671 mptsas_send_expander_event(fw_event);
1672 break;
1673 case MPI_EVENT_SAS_PHY_LINK_STATUS:
1674 mptsas_send_link_status_event(fw_event);
1675 break;
1676 case MPI_EVENT_QUEUE_FULL:
1677 mptsas_handle_queue_full_event(fw_event);
1678 break;
1679 }
1680}
1681
1682
1683
1684static int
1685mptsas_slave_configure(struct scsi_device *sdev)
1686{
1687 struct Scsi_Host *host = sdev->host;
1688 MPT_SCSI_HOST *hd = shost_priv(host);
1689 MPT_ADAPTER *ioc = hd->ioc;
1690 VirtDevice *vdevice = sdev->hostdata;
1691
1692 if (vdevice->vtarget->deleted) {
1693 sdev_printk(KERN_INFO, sdev, "clearing deleted flag\n");
1694 vdevice->vtarget->deleted = 0;
1695 }
1696
1697 /*
1698 * RAID volumes placed beyond the last expected port.
1699 * Ignore sending sas mode pages in that case..
1700 */
1701 if (sdev->channel == MPTSAS_RAID_CHANNEL) {
1702 mptsas_add_device_component_starget_ir(ioc, scsi_target(sdev));
1703 goto out;
1704 }
1705
1706 sas_read_port_mode_page(sdev);
1707
1708 mptsas_add_device_component_starget(ioc, scsi_target(sdev));
1709
1710 out:
1711 return mptscsih_slave_configure(sdev);
1712}
1713
1714static int
1715mptsas_target_alloc(struct scsi_target *starget)
1716{
1717 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1718 MPT_SCSI_HOST *hd = shost_priv(host);
1719 VirtTarget *vtarget;
1720 u8 id, channel;
1721 struct sas_rphy *rphy;
1722 struct mptsas_portinfo *p;
1723 int i;
1724 MPT_ADAPTER *ioc = hd->ioc;
1725
1726 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
1727 if (!vtarget)
1728 return -ENOMEM;
1729
1730 vtarget->starget = starget;
1731 vtarget->ioc_id = ioc->id;
1732 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
1733 id = starget->id;
1734 channel = 0;
1735
1736 /*
1737 * RAID volumes placed beyond the last expected port.
1738 */
1739 if (starget->channel == MPTSAS_RAID_CHANNEL) {
1740 if (!ioc->raid_data.pIocPg2) {
1741 kfree(vtarget);
1742 return -ENXIO;
1743 }
1744 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1745 if (id == ioc->raid_data.pIocPg2->
1746 RaidVolume[i].VolumeID) {
1747 channel = ioc->raid_data.pIocPg2->
1748 RaidVolume[i].VolumeBus;
1749 }
1750 }
1751 vtarget->raidVolume = 1;
1752 goto out;
1753 }
1754
1755 rphy = dev_to_rphy(starget->dev.parent);
1756 mutex_lock(&ioc->sas_topology_mutex);
1757 list_for_each_entry(p, &ioc->sas_topology, list) {
1758 for (i = 0; i < p->num_phys; i++) {
1759 if (p->phy_info[i].attached.sas_address !=
1760 rphy->identify.sas_address)
1761 continue;
1762 id = p->phy_info[i].attached.id;
1763 channel = p->phy_info[i].attached.channel;
1764 mptsas_set_starget(&p->phy_info[i], starget);
1765
1766 /*
1767 * Exposing hidden raid components
1768 */
1769 if (mptscsih_is_phys_disk(ioc, channel, id)) {
1770 id = mptscsih_raid_id_to_num(ioc,
1771 channel, id);
1772 vtarget->tflags |=
1773 MPT_TARGET_FLAGS_RAID_COMPONENT;
1774 p->phy_info[i].attached.phys_disk_num = id;
1775 }
1776 mutex_unlock(&ioc->sas_topology_mutex);
1777 goto out;
1778 }
1779 }
1780 mutex_unlock(&ioc->sas_topology_mutex);
1781
1782 kfree(vtarget);
1783 return -ENXIO;
1784
1785 out:
1786 vtarget->id = id;
1787 vtarget->channel = channel;
1788 starget->hostdata = vtarget;
1789 return 0;
1790}
1791
1792static void
1793mptsas_target_destroy(struct scsi_target *starget)
1794{
1795 struct Scsi_Host *host = dev_to_shost(&starget->dev);
1796 MPT_SCSI_HOST *hd = shost_priv(host);
1797 struct sas_rphy *rphy;
1798 struct mptsas_portinfo *p;
1799 int i;
1800 MPT_ADAPTER *ioc = hd->ioc;
1801 VirtTarget *vtarget;
1802
1803 if (!starget->hostdata)
1804 return;
1805
1806 vtarget = starget->hostdata;
1807
1808 mptsas_del_device_component_by_os(ioc, starget->channel,
1809 starget->id);
1810
1811
1812 if (starget->channel == MPTSAS_RAID_CHANNEL)
1813 goto out;
1814
1815 rphy = dev_to_rphy(starget->dev.parent);
1816 list_for_each_entry(p, &ioc->sas_topology, list) {
1817 for (i = 0; i < p->num_phys; i++) {
1818 if (p->phy_info[i].attached.sas_address !=
1819 rphy->identify.sas_address)
1820 continue;
1821
1822 starget_printk(KERN_INFO, starget, MYIOC_s_FMT
1823 "delete device: fw_channel %d, fw_id %d, phy %d, "
1824 "sas_addr 0x%llx\n", ioc->name,
1825 p->phy_info[i].attached.channel,
1826 p->phy_info[i].attached.id,
1827 p->phy_info[i].attached.phy_id, (unsigned long long)
1828 p->phy_info[i].attached.sas_address);
1829
1830 mptsas_set_starget(&p->phy_info[i], NULL);
1831 }
1832 }
1833
1834 out:
1835 vtarget->starget = NULL;
1836 kfree(starget->hostdata);
1837 starget->hostdata = NULL;
1838}
1839
1840
1841static int
1842mptsas_slave_alloc(struct scsi_device *sdev)
1843{
1844 struct Scsi_Host *host = sdev->host;
1845 MPT_SCSI_HOST *hd = shost_priv(host);
1846 struct sas_rphy *rphy;
1847 struct mptsas_portinfo *p;
1848 VirtDevice *vdevice;
1849 struct scsi_target *starget;
1850 int i;
1851 MPT_ADAPTER *ioc = hd->ioc;
1852
1853 vdevice = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
1854 if (!vdevice) {
1855 printk(MYIOC_s_ERR_FMT "slave_alloc kzalloc(%zd) FAILED!\n",
1856 ioc->name, sizeof(VirtDevice));
1857 return -ENOMEM;
1858 }
1859 starget = scsi_target(sdev);
1860 vdevice->vtarget = starget->hostdata;
1861
1862 if (sdev->channel == MPTSAS_RAID_CHANNEL)
1863 goto out;
1864
1865 rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
1866 mutex_lock(&ioc->sas_topology_mutex);
1867 list_for_each_entry(p, &ioc->sas_topology, list) {
1868 for (i = 0; i < p->num_phys; i++) {
1869 if (p->phy_info[i].attached.sas_address !=
1870 rphy->identify.sas_address)
1871 continue;
1872 vdevice->lun = sdev->lun;
1873 /*
1874 * Exposing hidden raid components
1875 */
1876 if (mptscsih_is_phys_disk(ioc,
1877 p->phy_info[i].attached.channel,
1878 p->phy_info[i].attached.id))
1879 sdev->no_uld_attach = 1;
1880 mutex_unlock(&ioc->sas_topology_mutex);
1881 goto out;
1882 }
1883 }
1884 mutex_unlock(&ioc->sas_topology_mutex);
1885
1886 kfree(vdevice);
1887 return -ENXIO;
1888
1889 out:
1890 vdevice->vtarget->num_luns++;
1891 sdev->hostdata = vdevice;
1892 return 0;
1893}
1894
1895static int
1896mptsas_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt)
1897{
1898 MPT_SCSI_HOST *hd;
1899 MPT_ADAPTER *ioc;
1900 VirtDevice *vdevice = SCpnt->device->hostdata;
1901
1902 if (!vdevice || !vdevice->vtarget || vdevice->vtarget->deleted) {
1903 SCpnt->result = DID_NO_CONNECT << 16;
1904 SCpnt->scsi_done(SCpnt);
1905 return 0;
1906 }
1907
1908 hd = shost_priv(shost);
1909 ioc = hd->ioc;
1910
1911 if (ioc->sas_discovery_quiesce_io)
1912 return SCSI_MLQUEUE_HOST_BUSY;
1913
1914 if (ioc->debug_level & MPT_DEBUG_SCSI)
1915 scsi_print_command(SCpnt);
1916
1917 return mptscsih_qcmd(SCpnt);
1918}
1919
1920/**
1921 * mptsas_mptsas_eh_timed_out - resets the scsi_cmnd timeout
1922 * if the device under question is currently in the
1923 * device removal delay.
1924 * @sc: scsi command that the midlayer is about to time out
1925 *
1926 **/
1927static enum blk_eh_timer_return mptsas_eh_timed_out(struct scsi_cmnd *sc)
1928{
1929 MPT_SCSI_HOST *hd;
1930 MPT_ADAPTER *ioc;
1931 VirtDevice *vdevice;
1932 enum blk_eh_timer_return rc = BLK_EH_DONE;
1933
1934 hd = shost_priv(sc->device->host);
1935 if (hd == NULL) {
1936 printk(KERN_ERR MYNAM ": %s: Can't locate host! (sc=%p)\n",
1937 __func__, sc);
1938 goto done;
1939 }
1940
1941 ioc = hd->ioc;
1942 if (ioc->bus_type != SAS) {
1943 printk(KERN_ERR MYNAM ": %s: Wrong bus type (sc=%p)\n",
1944 __func__, sc);
1945 goto done;
1946 }
1947
1948 /* In case if IOC is in reset from internal context.
1949 * Do not execute EEH for the same IOC. SML should to reset timer.
1950 */
1951 if (ioc->ioc_reset_in_progress) {
1952 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT ": %s: ioc is in reset,"
1953 "SML need to reset the timer (sc=%p)\n",
1954 ioc->name, __func__, sc));
1955 rc = BLK_EH_RESET_TIMER;
1956 }
1957 vdevice = sc->device->hostdata;
1958 if (vdevice && vdevice->vtarget && (vdevice->vtarget->inDMD
1959 || vdevice->vtarget->deleted)) {
1960 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT ": %s: target removed "
1961 "or in device removal delay (sc=%p)\n",
1962 ioc->name, __func__, sc));
1963 rc = BLK_EH_RESET_TIMER;
1964 goto done;
1965 }
1966
1967done:
1968 return rc;
1969}
1970
1971
1972static struct scsi_host_template mptsas_driver_template = {
1973 .module = THIS_MODULE,
1974 .proc_name = "mptsas",
1975 .show_info = mptscsih_show_info,
1976 .name = "MPT SAS Host",
1977 .info = mptscsih_info,
1978 .queuecommand = mptsas_qcmd,
1979 .target_alloc = mptsas_target_alloc,
1980 .slave_alloc = mptsas_slave_alloc,
1981 .slave_configure = mptsas_slave_configure,
1982 .target_destroy = mptsas_target_destroy,
1983 .slave_destroy = mptscsih_slave_destroy,
1984 .change_queue_depth = mptscsih_change_queue_depth,
1985 .eh_timed_out = mptsas_eh_timed_out,
1986 .eh_abort_handler = mptscsih_abort,
1987 .eh_device_reset_handler = mptscsih_dev_reset,
1988 .eh_host_reset_handler = mptscsih_host_reset,
1989 .bios_param = mptscsih_bios_param,
1990 .can_queue = MPT_SAS_CAN_QUEUE,
1991 .this_id = -1,
1992 .sg_tablesize = MPT_SCSI_SG_DEPTH,
1993 .max_sectors = 8192,
1994 .cmd_per_lun = 7,
1995 .shost_attrs = mptscsih_host_attrs,
1996 .no_write_same = 1,
1997};
1998
1999static int mptsas_get_linkerrors(struct sas_phy *phy)
2000{
2001 MPT_ADAPTER *ioc = phy_to_ioc(phy);
2002 ConfigExtendedPageHeader_t hdr;
2003 CONFIGPARMS cfg;
2004 SasPhyPage1_t *buffer;
2005 dma_addr_t dma_handle;
2006 int error;
2007
2008 /* FIXME: only have link errors on local phys */
2009 if (!scsi_is_sas_phy_local(phy))
2010 return -EINVAL;
2011
2012 hdr.PageVersion = MPI_SASPHY1_PAGEVERSION;
2013 hdr.ExtPageLength = 0;
2014 hdr.PageNumber = 1 /* page number 1*/;
2015 hdr.Reserved1 = 0;
2016 hdr.Reserved2 = 0;
2017 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2018 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
2019
2020 cfg.cfghdr.ehdr = &hdr;
2021 cfg.physAddr = -1;
2022 cfg.pageAddr = phy->identify.phy_identifier;
2023 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2024 cfg.dir = 0; /* read */
2025 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2026
2027 error = mpt_config(ioc, &cfg);
2028 if (error)
2029 return error;
2030 if (!hdr.ExtPageLength)
2031 return -ENXIO;
2032
2033 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2034 &dma_handle);
2035 if (!buffer)
2036 return -ENOMEM;
2037
2038 cfg.physAddr = dma_handle;
2039 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2040
2041 error = mpt_config(ioc, &cfg);
2042 if (error)
2043 goto out_free_consistent;
2044
2045 mptsas_print_phy_pg1(ioc, buffer);
2046
2047 phy->invalid_dword_count = le32_to_cpu(buffer->InvalidDwordCount);
2048 phy->running_disparity_error_count =
2049 le32_to_cpu(buffer->RunningDisparityErrorCount);
2050 phy->loss_of_dword_sync_count =
2051 le32_to_cpu(buffer->LossDwordSynchCount);
2052 phy->phy_reset_problem_count =
2053 le32_to_cpu(buffer->PhyResetProblemCount);
2054
2055 out_free_consistent:
2056 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2057 buffer, dma_handle);
2058 return error;
2059}
2060
2061static int mptsas_mgmt_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
2062 MPT_FRAME_HDR *reply)
2063{
2064 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
2065 if (reply != NULL) {
2066 ioc->sas_mgmt.status |= MPT_MGMT_STATUS_RF_VALID;
2067 memcpy(ioc->sas_mgmt.reply, reply,
2068 min(ioc->reply_sz, 4 * reply->u.reply.MsgLength));
2069 }
2070
2071 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_PENDING) {
2072 ioc->sas_mgmt.status &= ~MPT_MGMT_STATUS_PENDING;
2073 complete(&ioc->sas_mgmt.done);
2074 return 1;
2075 }
2076 return 0;
2077}
2078
2079static int mptsas_phy_reset(struct sas_phy *phy, int hard_reset)
2080{
2081 MPT_ADAPTER *ioc = phy_to_ioc(phy);
2082 SasIoUnitControlRequest_t *req;
2083 SasIoUnitControlReply_t *reply;
2084 MPT_FRAME_HDR *mf;
2085 MPIHeader_t *hdr;
2086 unsigned long timeleft;
2087 int error = -ERESTARTSYS;
2088
2089 /* FIXME: fusion doesn't allow non-local phy reset */
2090 if (!scsi_is_sas_phy_local(phy))
2091 return -EINVAL;
2092
2093 /* not implemented for expanders */
2094 if (phy->identify.target_port_protocols & SAS_PROTOCOL_SMP)
2095 return -ENXIO;
2096
2097 if (mutex_lock_interruptible(&ioc->sas_mgmt.mutex))
2098 goto out;
2099
2100 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2101 if (!mf) {
2102 error = -ENOMEM;
2103 goto out_unlock;
2104 }
2105
2106 hdr = (MPIHeader_t *) mf;
2107 req = (SasIoUnitControlRequest_t *)mf;
2108 memset(req, 0, sizeof(SasIoUnitControlRequest_t));
2109 req->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
2110 req->MsgContext = hdr->MsgContext;
2111 req->Operation = hard_reset ?
2112 MPI_SAS_OP_PHY_HARD_RESET : MPI_SAS_OP_PHY_LINK_RESET;
2113 req->PhyNum = phy->identify.phy_identifier;
2114
2115 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2116 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2117
2118 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done,
2119 10 * HZ);
2120 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2121 error = -ETIME;
2122 mpt_free_msg_frame(ioc, mf);
2123 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2124 goto out_unlock;
2125 if (!timeleft)
2126 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
2127 goto out_unlock;
2128 }
2129
2130 /* a reply frame is expected */
2131 if ((ioc->sas_mgmt.status &
2132 MPT_MGMT_STATUS_RF_VALID) == 0) {
2133 error = -ENXIO;
2134 goto out_unlock;
2135 }
2136
2137 /* process the completed Reply Message Frame */
2138 reply = (SasIoUnitControlReply_t *)ioc->sas_mgmt.reply;
2139 if (reply->IOCStatus != MPI_IOCSTATUS_SUCCESS) {
2140 printk(MYIOC_s_INFO_FMT "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
2141 ioc->name, __func__, reply->IOCStatus, reply->IOCLogInfo);
2142 error = -ENXIO;
2143 goto out_unlock;
2144 }
2145
2146 error = 0;
2147
2148 out_unlock:
2149 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2150 mutex_unlock(&ioc->sas_mgmt.mutex);
2151 out:
2152 return error;
2153}
2154
2155static int
2156mptsas_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier)
2157{
2158 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2159 int i, error;
2160 struct mptsas_portinfo *p;
2161 struct mptsas_enclosure enclosure_info;
2162 u64 enclosure_handle;
2163
2164 mutex_lock(&ioc->sas_topology_mutex);
2165 list_for_each_entry(p, &ioc->sas_topology, list) {
2166 for (i = 0; i < p->num_phys; i++) {
2167 if (p->phy_info[i].attached.sas_address ==
2168 rphy->identify.sas_address) {
2169 enclosure_handle = p->phy_info[i].
2170 attached.handle_enclosure;
2171 goto found_info;
2172 }
2173 }
2174 }
2175 mutex_unlock(&ioc->sas_topology_mutex);
2176 return -ENXIO;
2177
2178 found_info:
2179 mutex_unlock(&ioc->sas_topology_mutex);
2180 memset(&enclosure_info, 0, sizeof(struct mptsas_enclosure));
2181 error = mptsas_sas_enclosure_pg0(ioc, &enclosure_info,
2182 (MPI_SAS_ENCLOS_PGAD_FORM_HANDLE <<
2183 MPI_SAS_ENCLOS_PGAD_FORM_SHIFT), enclosure_handle);
2184 if (!error)
2185 *identifier = enclosure_info.enclosure_logical_id;
2186 return error;
2187}
2188
2189static int
2190mptsas_get_bay_identifier(struct sas_rphy *rphy)
2191{
2192 MPT_ADAPTER *ioc = rphy_to_ioc(rphy);
2193 struct mptsas_portinfo *p;
2194 int i, rc;
2195
2196 mutex_lock(&ioc->sas_topology_mutex);
2197 list_for_each_entry(p, &ioc->sas_topology, list) {
2198 for (i = 0; i < p->num_phys; i++) {
2199 if (p->phy_info[i].attached.sas_address ==
2200 rphy->identify.sas_address) {
2201 rc = p->phy_info[i].attached.slot;
2202 goto out;
2203 }
2204 }
2205 }
2206 rc = -ENXIO;
2207 out:
2208 mutex_unlock(&ioc->sas_topology_mutex);
2209 return rc;
2210}
2211
2212static void mptsas_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
2213 struct sas_rphy *rphy)
2214{
2215 MPT_ADAPTER *ioc = ((MPT_SCSI_HOST *) shost->hostdata)->ioc;
2216 MPT_FRAME_HDR *mf;
2217 SmpPassthroughRequest_t *smpreq;
2218 int flagsLength;
2219 unsigned long timeleft;
2220 char *psge;
2221 u64 sas_address = 0;
2222 unsigned int reslen = 0;
2223 int ret = -EINVAL;
2224
2225 /* do we need to support multiple segments? */
2226 if (job->request_payload.sg_cnt > 1 ||
2227 job->reply_payload.sg_cnt > 1) {
2228 printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u, rsp %u\n",
2229 ioc->name, __func__, job->request_payload.payload_len,
2230 job->reply_payload.payload_len);
2231 goto out;
2232 }
2233
2234 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
2235 if (ret)
2236 goto out;
2237
2238 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2239 if (!mf) {
2240 ret = -ENOMEM;
2241 goto out_unlock;
2242 }
2243
2244 smpreq = (SmpPassthroughRequest_t *)mf;
2245 memset(smpreq, 0, sizeof(*smpreq));
2246
2247 smpreq->RequestDataLength =
2248 cpu_to_le16(job->request_payload.payload_len - 4);
2249 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
2250
2251 if (rphy)
2252 sas_address = rphy->identify.sas_address;
2253 else {
2254 struct mptsas_portinfo *port_info;
2255
2256 mutex_lock(&ioc->sas_topology_mutex);
2257 port_info = ioc->hba_port_info;
2258 if (port_info && port_info->phy_info)
2259 sas_address =
2260 port_info->phy_info[0].phy->identify.sas_address;
2261 mutex_unlock(&ioc->sas_topology_mutex);
2262 }
2263
2264 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
2265
2266 psge = (char *)
2267 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
2268
2269 /* request */
2270 flagsLength = (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2271 MPI_SGE_FLAGS_END_OF_BUFFER |
2272 MPI_SGE_FLAGS_DIRECTION)
2273 << MPI_SGE_FLAGS_SHIFT;
2274
2275 if (!dma_map_sg(&ioc->pcidev->dev, job->request_payload.sg_list,
2276 1, PCI_DMA_BIDIRECTIONAL))
2277 goto put_mf;
2278
2279 flagsLength |= (sg_dma_len(job->request_payload.sg_list) - 4);
2280 ioc->add_sge(psge, flagsLength,
2281 sg_dma_address(job->request_payload.sg_list));
2282 psge += ioc->SGE_size;
2283
2284 /* response */
2285 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2286 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2287 MPI_SGE_FLAGS_IOC_TO_HOST |
2288 MPI_SGE_FLAGS_END_OF_BUFFER;
2289
2290 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2291
2292 if (!dma_map_sg(&ioc->pcidev->dev, job->reply_payload.sg_list,
2293 1, PCI_DMA_BIDIRECTIONAL))
2294 goto unmap_out;
2295 flagsLength |= sg_dma_len(job->reply_payload.sg_list) + 4;
2296 ioc->add_sge(psge, flagsLength,
2297 sg_dma_address(job->reply_payload.sg_list));
2298
2299 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2300 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2301
2302 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
2303 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2304 ret = -ETIME;
2305 mpt_free_msg_frame(ioc, mf);
2306 mf = NULL;
2307 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2308 goto unmap_in;
2309 if (!timeleft)
2310 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
2311 goto unmap_in;
2312 }
2313 mf = NULL;
2314
2315 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
2316 SmpPassthroughReply_t *smprep;
2317
2318 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
2319 memcpy(job->reply, smprep, sizeof(*smprep));
2320 job->reply_len = sizeof(*smprep);
2321 reslen = smprep->ResponseDataLength;
2322 } else {
2323 printk(MYIOC_s_ERR_FMT
2324 "%s: smp passthru reply failed to be returned\n",
2325 ioc->name, __func__);
2326 ret = -ENXIO;
2327 }
2328
2329unmap_in:
2330 dma_unmap_sg(&ioc->pcidev->dev, job->reply_payload.sg_list, 1,
2331 PCI_DMA_BIDIRECTIONAL);
2332unmap_out:
2333 dma_unmap_sg(&ioc->pcidev->dev, job->request_payload.sg_list, 1,
2334 PCI_DMA_BIDIRECTIONAL);
2335put_mf:
2336 if (mf)
2337 mpt_free_msg_frame(ioc, mf);
2338out_unlock:
2339 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2340 mutex_unlock(&ioc->sas_mgmt.mutex);
2341out:
2342 bsg_job_done(job, ret, reslen);
2343}
2344
2345static struct sas_function_template mptsas_transport_functions = {
2346 .get_linkerrors = mptsas_get_linkerrors,
2347 .get_enclosure_identifier = mptsas_get_enclosure_identifier,
2348 .get_bay_identifier = mptsas_get_bay_identifier,
2349 .phy_reset = mptsas_phy_reset,
2350 .smp_handler = mptsas_smp_handler,
2351};
2352
2353static struct scsi_transport_template *mptsas_transport_template;
2354
2355static int
2356mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
2357{
2358 ConfigExtendedPageHeader_t hdr;
2359 CONFIGPARMS cfg;
2360 SasIOUnitPage0_t *buffer;
2361 dma_addr_t dma_handle;
2362 int error, i;
2363
2364 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
2365 hdr.ExtPageLength = 0;
2366 hdr.PageNumber = 0;
2367 hdr.Reserved1 = 0;
2368 hdr.Reserved2 = 0;
2369 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2370 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2371
2372 cfg.cfghdr.ehdr = &hdr;
2373 cfg.physAddr = -1;
2374 cfg.pageAddr = 0;
2375 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2376 cfg.dir = 0; /* read */
2377 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2378
2379 error = mpt_config(ioc, &cfg);
2380 if (error)
2381 goto out;
2382 if (!hdr.ExtPageLength) {
2383 error = -ENXIO;
2384 goto out;
2385 }
2386
2387 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2388 &dma_handle);
2389 if (!buffer) {
2390 error = -ENOMEM;
2391 goto out;
2392 }
2393
2394 cfg.physAddr = dma_handle;
2395 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2396
2397 error = mpt_config(ioc, &cfg);
2398 if (error)
2399 goto out_free_consistent;
2400
2401 port_info->num_phys = buffer->NumPhys;
2402 port_info->phy_info = kcalloc(port_info->num_phys,
2403 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
2404 if (!port_info->phy_info) {
2405 error = -ENOMEM;
2406 goto out_free_consistent;
2407 }
2408
2409 ioc->nvdata_version_persistent =
2410 le16_to_cpu(buffer->NvdataVersionPersistent);
2411 ioc->nvdata_version_default =
2412 le16_to_cpu(buffer->NvdataVersionDefault);
2413
2414 for (i = 0; i < port_info->num_phys; i++) {
2415 mptsas_print_phy_data(ioc, &buffer->PhyData[i]);
2416 port_info->phy_info[i].phy_id = i;
2417 port_info->phy_info[i].port_id =
2418 buffer->PhyData[i].Port;
2419 port_info->phy_info[i].negotiated_link_rate =
2420 buffer->PhyData[i].NegotiatedLinkRate;
2421 port_info->phy_info[i].portinfo = port_info;
2422 port_info->phy_info[i].handle =
2423 le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
2424 }
2425
2426 out_free_consistent:
2427 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2428 buffer, dma_handle);
2429 out:
2430 return error;
2431}
2432
2433static int
2434mptsas_sas_io_unit_pg1(MPT_ADAPTER *ioc)
2435{
2436 ConfigExtendedPageHeader_t hdr;
2437 CONFIGPARMS cfg;
2438 SasIOUnitPage1_t *buffer;
2439 dma_addr_t dma_handle;
2440 int error;
2441 u8 device_missing_delay;
2442
2443 memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
2444 memset(&cfg, 0, sizeof(CONFIGPARMS));
2445
2446 cfg.cfghdr.ehdr = &hdr;
2447 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2448 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2449 cfg.cfghdr.ehdr->PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2450 cfg.cfghdr.ehdr->ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
2451 cfg.cfghdr.ehdr->PageVersion = MPI_SASIOUNITPAGE1_PAGEVERSION;
2452 cfg.cfghdr.ehdr->PageNumber = 1;
2453
2454 error = mpt_config(ioc, &cfg);
2455 if (error)
2456 goto out;
2457 if (!hdr.ExtPageLength) {
2458 error = -ENXIO;
2459 goto out;
2460 }
2461
2462 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2463 &dma_handle);
2464 if (!buffer) {
2465 error = -ENOMEM;
2466 goto out;
2467 }
2468
2469 cfg.physAddr = dma_handle;
2470 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2471
2472 error = mpt_config(ioc, &cfg);
2473 if (error)
2474 goto out_free_consistent;
2475
2476 ioc->io_missing_delay =
2477 le16_to_cpu(buffer->IODeviceMissingDelay);
2478 device_missing_delay = buffer->ReportDeviceMissingDelay;
2479 ioc->device_missing_delay = (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_UNIT_16) ?
2480 (device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16 :
2481 device_missing_delay & MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2482
2483 out_free_consistent:
2484 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2485 buffer, dma_handle);
2486 out:
2487 return error;
2488}
2489
2490static int
2491mptsas_sas_phy_pg0(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2492 u32 form, u32 form_specific)
2493{
2494 ConfigExtendedPageHeader_t hdr;
2495 CONFIGPARMS cfg;
2496 SasPhyPage0_t *buffer;
2497 dma_addr_t dma_handle;
2498 int error;
2499
2500 hdr.PageVersion = MPI_SASPHY0_PAGEVERSION;
2501 hdr.ExtPageLength = 0;
2502 hdr.PageNumber = 0;
2503 hdr.Reserved1 = 0;
2504 hdr.Reserved2 = 0;
2505 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2506 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_PHY;
2507
2508 cfg.cfghdr.ehdr = &hdr;
2509 cfg.dir = 0; /* read */
2510 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2511
2512 /* Get Phy Pg 0 for each Phy. */
2513 cfg.physAddr = -1;
2514 cfg.pageAddr = form + form_specific;
2515 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2516
2517 error = mpt_config(ioc, &cfg);
2518 if (error)
2519 goto out;
2520
2521 if (!hdr.ExtPageLength) {
2522 error = -ENXIO;
2523 goto out;
2524 }
2525
2526 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2527 &dma_handle);
2528 if (!buffer) {
2529 error = -ENOMEM;
2530 goto out;
2531 }
2532
2533 cfg.physAddr = dma_handle;
2534 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2535
2536 error = mpt_config(ioc, &cfg);
2537 if (error)
2538 goto out_free_consistent;
2539
2540 mptsas_print_phy_pg0(ioc, buffer);
2541
2542 phy_info->hw_link_rate = buffer->HwLinkRate;
2543 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2544 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2545 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2546
2547 out_free_consistent:
2548 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2549 buffer, dma_handle);
2550 out:
2551 return error;
2552}
2553
2554static int
2555mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
2556 u32 form, u32 form_specific)
2557{
2558 ConfigExtendedPageHeader_t hdr;
2559 CONFIGPARMS cfg;
2560 SasDevicePage0_t *buffer;
2561 dma_addr_t dma_handle;
2562 __le64 sas_address;
2563 int error=0;
2564
2565 hdr.PageVersion = MPI_SASDEVICE0_PAGEVERSION;
2566 hdr.ExtPageLength = 0;
2567 hdr.PageNumber = 0;
2568 hdr.Reserved1 = 0;
2569 hdr.Reserved2 = 0;
2570 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2571 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE;
2572
2573 cfg.cfghdr.ehdr = &hdr;
2574 cfg.pageAddr = form + form_specific;
2575 cfg.physAddr = -1;
2576 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2577 cfg.dir = 0; /* read */
2578 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2579
2580 memset(device_info, 0, sizeof(struct mptsas_devinfo));
2581 error = mpt_config(ioc, &cfg);
2582 if (error)
2583 goto out;
2584 if (!hdr.ExtPageLength) {
2585 error = -ENXIO;
2586 goto out;
2587 }
2588
2589 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2590 &dma_handle);
2591 if (!buffer) {
2592 error = -ENOMEM;
2593 goto out;
2594 }
2595
2596 cfg.physAddr = dma_handle;
2597 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2598
2599 error = mpt_config(ioc, &cfg);
2600
2601 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
2602 error = -ENODEV;
2603 goto out_free_consistent;
2604 }
2605
2606 if (error)
2607 goto out_free_consistent;
2608
2609 mptsas_print_device_pg0(ioc, buffer);
2610
2611 memset(device_info, 0, sizeof(struct mptsas_devinfo));
2612 device_info->handle = le16_to_cpu(buffer->DevHandle);
2613 device_info->handle_parent = le16_to_cpu(buffer->ParentDevHandle);
2614 device_info->handle_enclosure =
2615 le16_to_cpu(buffer->EnclosureHandle);
2616 device_info->slot = le16_to_cpu(buffer->Slot);
2617 device_info->phy_id = buffer->PhyNum;
2618 device_info->port_id = buffer->PhysicalPort;
2619 device_info->id = buffer->TargetID;
2620 device_info->phys_disk_num = ~0;
2621 device_info->channel = buffer->Bus;
2622 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
2623 device_info->sas_address = le64_to_cpu(sas_address);
2624 device_info->device_info =
2625 le32_to_cpu(buffer->DeviceInfo);
2626 device_info->flags = le16_to_cpu(buffer->Flags);
2627
2628 out_free_consistent:
2629 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2630 buffer, dma_handle);
2631 out:
2632 return error;
2633}
2634
2635static int
2636mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
2637 u32 form, u32 form_specific)
2638{
2639 ConfigExtendedPageHeader_t hdr;
2640 CONFIGPARMS cfg;
2641 SasExpanderPage0_t *buffer;
2642 dma_addr_t dma_handle;
2643 int i, error;
2644 __le64 sas_address;
2645
2646 memset(port_info, 0, sizeof(struct mptsas_portinfo));
2647 hdr.PageVersion = MPI_SASEXPANDER0_PAGEVERSION;
2648 hdr.ExtPageLength = 0;
2649 hdr.PageNumber = 0;
2650 hdr.Reserved1 = 0;
2651 hdr.Reserved2 = 0;
2652 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2653 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2654
2655 cfg.cfghdr.ehdr = &hdr;
2656 cfg.physAddr = -1;
2657 cfg.pageAddr = form + form_specific;
2658 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2659 cfg.dir = 0; /* read */
2660 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2661
2662 memset(port_info, 0, sizeof(struct mptsas_portinfo));
2663 error = mpt_config(ioc, &cfg);
2664 if (error)
2665 goto out;
2666
2667 if (!hdr.ExtPageLength) {
2668 error = -ENXIO;
2669 goto out;
2670 }
2671
2672 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2673 &dma_handle);
2674 if (!buffer) {
2675 error = -ENOMEM;
2676 goto out;
2677 }
2678
2679 cfg.physAddr = dma_handle;
2680 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2681
2682 error = mpt_config(ioc, &cfg);
2683 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
2684 error = -ENODEV;
2685 goto out_free_consistent;
2686 }
2687
2688 if (error)
2689 goto out_free_consistent;
2690
2691 /* save config data */
2692 port_info->num_phys = (buffer->NumPhys) ? buffer->NumPhys : 1;
2693 port_info->phy_info = kcalloc(port_info->num_phys,
2694 sizeof(struct mptsas_phyinfo), GFP_KERNEL);
2695 if (!port_info->phy_info) {
2696 error = -ENOMEM;
2697 goto out_free_consistent;
2698 }
2699
2700 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
2701 for (i = 0; i < port_info->num_phys; i++) {
2702 port_info->phy_info[i].portinfo = port_info;
2703 port_info->phy_info[i].handle =
2704 le16_to_cpu(buffer->DevHandle);
2705 port_info->phy_info[i].identify.sas_address =
2706 le64_to_cpu(sas_address);
2707 port_info->phy_info[i].identify.handle_parent =
2708 le16_to_cpu(buffer->ParentDevHandle);
2709 }
2710
2711 out_free_consistent:
2712 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2713 buffer, dma_handle);
2714 out:
2715 return error;
2716}
2717
2718static int
2719mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2720 u32 form, u32 form_specific)
2721{
2722 ConfigExtendedPageHeader_t hdr;
2723 CONFIGPARMS cfg;
2724 SasExpanderPage1_t *buffer;
2725 dma_addr_t dma_handle;
2726 int error=0;
2727
2728 hdr.PageVersion = MPI_SASEXPANDER1_PAGEVERSION;
2729 hdr.ExtPageLength = 0;
2730 hdr.PageNumber = 1;
2731 hdr.Reserved1 = 0;
2732 hdr.Reserved2 = 0;
2733 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
2734 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER;
2735
2736 cfg.cfghdr.ehdr = &hdr;
2737 cfg.physAddr = -1;
2738 cfg.pageAddr = form + form_specific;
2739 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2740 cfg.dir = 0; /* read */
2741 cfg.timeout = SAS_CONFIG_PAGE_TIMEOUT;
2742
2743 error = mpt_config(ioc, &cfg);
2744 if (error)
2745 goto out;
2746
2747 if (!hdr.ExtPageLength) {
2748 error = -ENXIO;
2749 goto out;
2750 }
2751
2752 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2753 &dma_handle);
2754 if (!buffer) {
2755 error = -ENOMEM;
2756 goto out;
2757 }
2758
2759 cfg.physAddr = dma_handle;
2760 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2761
2762 error = mpt_config(ioc, &cfg);
2763
2764 if (error == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
2765 error = -ENODEV;
2766 goto out_free_consistent;
2767 }
2768
2769 if (error)
2770 goto out_free_consistent;
2771
2772
2773 mptsas_print_expander_pg1(ioc, buffer);
2774
2775 /* save config data */
2776 phy_info->phy_id = buffer->PhyIdentifier;
2777 phy_info->port_id = buffer->PhysicalPort;
2778 phy_info->negotiated_link_rate = buffer->NegotiatedLinkRate;
2779 phy_info->programmed_link_rate = buffer->ProgrammedLinkRate;
2780 phy_info->hw_link_rate = buffer->HwLinkRate;
2781 phy_info->identify.handle = le16_to_cpu(buffer->OwnerDevHandle);
2782 phy_info->attached.handle = le16_to_cpu(buffer->AttachedDevHandle);
2783
2784 out_free_consistent:
2785 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
2786 buffer, dma_handle);
2787 out:
2788 return error;
2789}
2790
2791struct rep_manu_request{
2792 u8 smp_frame_type;
2793 u8 function;
2794 u8 reserved;
2795 u8 request_length;
2796};
2797
2798struct rep_manu_reply{
2799 u8 smp_frame_type; /* 0x41 */
2800 u8 function; /* 0x01 */
2801 u8 function_result;
2802 u8 response_length;
2803 u16 expander_change_count;
2804 u8 reserved0[2];
2805 u8 sas_format:1;
2806 u8 reserved1:7;
2807 u8 reserved2[3];
2808 u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN];
2809 u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN];
2810 u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN];
2811 u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN];
2812 u16 component_id;
2813 u8 component_revision_id;
2814 u8 reserved3;
2815 u8 vendor_specific[8];
2816};
2817
2818/**
2819 * mptsas_exp_repmanufacture_info -
2820 * @ioc: per adapter object
2821 * @sas_address: expander sas address
2822 * @edev: the sas_expander_device object
2823 *
2824 * Fills in the sas_expander_device object when SMP port is created.
2825 *
2826 * Returns 0 for success, non-zero for failure.
2827 */
2828static int
2829mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc,
2830 u64 sas_address, struct sas_expander_device *edev)
2831{
2832 MPT_FRAME_HDR *mf;
2833 SmpPassthroughRequest_t *smpreq;
2834 SmpPassthroughReply_t *smprep;
2835 struct rep_manu_reply *manufacture_reply;
2836 struct rep_manu_request *manufacture_request;
2837 int ret;
2838 int flagsLength;
2839 unsigned long timeleft;
2840 char *psge;
2841 unsigned long flags;
2842 void *data_out = NULL;
2843 dma_addr_t data_out_dma = 0;
2844 u32 sz;
2845
2846 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
2847 if (ioc->ioc_reset_in_progress) {
2848 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2849 printk(MYIOC_s_INFO_FMT "%s: host reset in progress!\n",
2850 __func__, ioc->name);
2851 return -EFAULT;
2852 }
2853 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2854
2855 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
2856 if (ret)
2857 goto out;
2858
2859 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2860 if (!mf) {
2861 ret = -ENOMEM;
2862 goto out_unlock;
2863 }
2864
2865 smpreq = (SmpPassthroughRequest_t *)mf;
2866 memset(smpreq, 0, sizeof(*smpreq));
2867
2868 sz = sizeof(struct rep_manu_request) + sizeof(struct rep_manu_reply);
2869
2870 data_out = pci_alloc_consistent(ioc->pcidev, sz, &data_out_dma);
2871 if (!data_out) {
2872 printk(KERN_ERR "Memory allocation failure at %s:%d/%s()!\n",
2873 __FILE__, __LINE__, __func__);
2874 ret = -ENOMEM;
2875 goto put_mf;
2876 }
2877
2878 manufacture_request = data_out;
2879 manufacture_request->smp_frame_type = 0x40;
2880 manufacture_request->function = 1;
2881 manufacture_request->reserved = 0;
2882 manufacture_request->request_length = 0;
2883
2884 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
2885 smpreq->PhysicalPort = 0xFF;
2886 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
2887 smpreq->RequestDataLength = sizeof(struct rep_manu_request);
2888
2889 psge = (char *)
2890 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
2891
2892 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2893 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2894 MPI_SGE_FLAGS_HOST_TO_IOC |
2895 MPI_SGE_FLAGS_END_OF_BUFFER;
2896 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2897 flagsLength |= sizeof(struct rep_manu_request);
2898
2899 ioc->add_sge(psge, flagsLength, data_out_dma);
2900 psge += ioc->SGE_size;
2901
2902 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2903 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2904 MPI_SGE_FLAGS_IOC_TO_HOST |
2905 MPI_SGE_FLAGS_END_OF_BUFFER;
2906 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2907 flagsLength |= sizeof(struct rep_manu_reply);
2908 ioc->add_sge(psge, flagsLength, data_out_dma +
2909 sizeof(struct rep_manu_request));
2910
2911 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2912 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2913
2914 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
2915 if (!(ioc->