2 * linux/drivers/message/fusion/mptscsih.c
3 * High performance SCSI / Fibre Channel SCSI Host device driver.
4 * For use with PCI chip/adapter(s):
5 * LSIFC9xx/LSI409xx Fibre Channel
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
9 * This driver would not exist if not for Alan Cox's development
10 * of the linux i2o driver.
12 * A special thanks to Pamela Delaney (LSI Logic) for tons of work
13 * and countless enhancements while adding support for the 1030
14 * chip family. Pam has been instrumental in the development of
15 * of the 2.xx.xx series fusion drivers, and her contributions are
16 * far too numerous to hope to list in one place.
18 * A huge debt of gratitude is owed to David S. Miller (DaveM)
19 * for fixing much of the stupid and broken stuff in the early
20 * driver while porting to sparc64 platform. THANK YOU!
24 * Copyright (c) 1999-2004 LSI Logic Corporation
25 * Original author: Steven J. Ralston
26 * (mailto:sjralston1@netscape.net)
27 * (mailto:mpt_linux_developer@lsil.com)
29 * $Id: mptscsih.c,v 1.104 2002/12/03 21:26:34 pdelaney Exp $
31 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
33 This program is free software; you can redistribute it and/or modify
34 it under the terms of the GNU General Public License as published by
35 the Free Software Foundation; version 2 of the License.
37 This program is distributed in the hope that it will be useful,
38 but WITHOUT ANY WARRANTY; without even the implied warranty of
39 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 GNU General Public License for more details.
43 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
44 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
45 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
46 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
47 solely responsible for determining the appropriateness of using and
48 distributing the Program and assumes all risks associated with its
49 exercise of rights under this Agreement, including but not limited to
50 the risks and costs of program errors, damage to or loss of data,
51 programs or equipment, and unavailability or interruption of operations.
53 DISCLAIMER OF LIABILITY
54 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
55 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
57 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
58 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
59 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
60 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
62 You should have received a copy of the GNU General Public License
63 along with this program; if not, write to the Free Software
64 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
66 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
68 #include "linux_compat.h" /* linux-2.6 tweaks */
69 #include <linux/module.h>
70 #include <linux/kernel.h>
71 #include <linux/init.h>
72 #include <linux/errno.h>
73 #include <linux/kdev_t.h>
74 #include <linux/blkdev.h>
75 #include <linux/delay.h> /* for mdelay */
76 #include <linux/interrupt.h> /* needed for in_interrupt() proto */
77 #include <linux/reboot.h> /* notifier code */
78 #include <linux/sched.h>
79 #include <linux/workqueue.h>
81 #include <scsi/scsi.h>
82 #include <scsi/scsi_cmnd.h>
83 #include <scsi/scsi_device.h>
84 #include <scsi/scsi_host.h>
85 #include <scsi/scsi_tcq.h>
90 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
91 #define my_NAME "Fusion MPT SCSI Host driver"
92 #define my_VERSION MPT_LINUX_VERSION_COMMON
93 #define MYNAM "mptscsih"
95 MODULE_AUTHOR(MODULEAUTHOR);
96 MODULE_DESCRIPTION(my_NAME);
97 MODULE_LICENSE("GPL");
100 static int dv = MPTSCSIH_DOMAIN_VALIDATION;
101 module_param(dv, int, 0);
102 MODULE_PARM_DESC(dv, "DV Algorithm: enhanced = 1, basic = 0 (default=MPTSCSIH_DOMAIN_VALIDATION=1)");
104 static int width = MPTSCSIH_MAX_WIDTH;
105 module_param(width, int, 0);
106 MODULE_PARM_DESC(width, "Max Bus Width: wide = 1, narrow = 0 (default=MPTSCSIH_MAX_WIDTH=1)");
108 static ushort factor = MPTSCSIH_MIN_SYNC;
109 module_param(factor, ushort, 0);
110 MODULE_PARM_DESC(factor, "Min Sync Factor: (default=MPTSCSIH_MIN_SYNC=0x08)");
112 static int saf_te = MPTSCSIH_SAF_TE;
113 module_param(saf_te, int, 0);
114 MODULE_PARM_DESC(saf_te, "Force enabling SEP Processor: (default=MPTSCSIH_SAF_TE=0)");
117 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
119 typedef struct _BIG_SENSE_BUF {
120 u8 data[MPT_SENSE_BUFFER_ALLOC];
123 #define MPT_SCANDV_GOOD (0x00000000) /* must be 0 */
124 #define MPT_SCANDV_DID_RESET (0x00000001)
125 #define MPT_SCANDV_SENSE (0x00000002)
126 #define MPT_SCANDV_SOME_ERROR (0x00000004)
127 #define MPT_SCANDV_SELECTION_TIMEOUT (0x00000008)
128 #define MPT_SCANDV_ISSUE_SENSE (0x00000010)
129 #define MPT_SCANDV_FALLBACK (0x00000020)
131 #define MPT_SCANDV_MAX_RETRIES (10)
133 #define MPT_ICFLAG_BUF_CAP 0x01 /* ReadBuffer Read Capacity format */
134 #define MPT_ICFLAG_ECHO 0x02 /* ReadBuffer Echo buffer format */
135 #define MPT_ICFLAG_PHYS_DISK 0x04 /* Any SCSI IO but do Phys Disk Format */
136 #define MPT_ICFLAG_TAGGED_CMD 0x08 /* Do tagged IO */
137 #define MPT_ICFLAG_DID_RESET 0x20 /* Bus Reset occurred with this command */
138 #define MPT_ICFLAG_RESERVED 0x40 /* Reserved has been issued */
140 typedef struct _internal_cmd {
141 char *data; /* data pointer */
142 dma_addr_t data_dma; /* data dma address */
143 int size; /* transfer size */
144 u8 cmd; /* SCSI Op Code */
145 u8 bus; /* bus number */
146 u8 id; /* SCSI ID (virtual) */
148 u8 flags; /* Bit Field - See above */
149 u8 physDiskNum; /* Phys disk number, -1 else */
154 typedef struct _negoparms {
161 typedef struct _dv_parameters {
171 * Other private/forward protos...
173 static int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
174 static void mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq);
175 static int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
177 static int mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
178 SCSIIORequest_t *pReq, int req_idx);
179 static void mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx);
180 static void copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply);
181 static int mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd);
182 static u32 SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc);
184 static int mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout, int sleepFlag);
185 static int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout, int sleepFlag);
187 static int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
188 static int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
190 static void mptscsih_initTarget(MPT_SCSI_HOST *hd, int bus_id, int target_id, u8 lun, char *data, int dlen);
191 static void mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtDevice *target, char byte56);
192 static void mptscsih_set_dvflags(MPT_SCSI_HOST *hd, SCSIIORequest_t *pReq);
193 static void mptscsih_setDevicePage1Flags (u8 width, u8 factor, u8 offset, int *requestedPtr, int *configurationPtr, u8 flags);
194 static void mptscsih_no_negotiate(MPT_SCSI_HOST *hd, int target_id);
195 static int mptscsih_writeSDP1(MPT_SCSI_HOST *hd, int portnum, int target, int flags);
196 static int mptscsih_writeIOCPage4(MPT_SCSI_HOST *hd, int target_id, int bus);
197 static int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
198 static void mptscsih_timer_expired(unsigned long data);
199 static void mptscsih_taskmgmt_timeout(unsigned long data);
200 static void mptscsih_schedule_reset(void *hd);
201 static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
202 static int mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, int portnum);
204 static struct work_struct mptscsih_rstTask;
206 #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
207 static int mptscsih_do_raid(MPT_SCSI_HOST *hd, u8 action, INTERNAL_CMD *io);
208 static void mptscsih_domainValidation(void *hd);
209 static int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id);
210 static void mptscsih_qas_check(MPT_SCSI_HOST *hd, int id);
211 static int mptscsih_doDv(MPT_SCSI_HOST *hd, int channel, int target);
212 static void mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage);
213 static void mptscsih_fillbuf(char *buffer, int size, int index, int width);
215 /* module entry point */
216 static int __init mptscsih_init (void);
217 static void __exit mptscsih_exit (void);
219 static int mptscsih_probe (struct pci_dev *, const struct pci_device_id *);
220 static void mptscsih_remove(struct pci_dev *);
221 static void mptscsih_shutdown(struct device *);
223 static int mptscsih_suspend(struct pci_dev *pdev, u32 state);
224 static int mptscsih_resume(struct pci_dev *pdev);
232 static int mpt_scsi_hosts = 0;
234 static int ScsiDoneCtx = -1;
235 static int ScsiTaskCtx = -1;
236 static int ScsiScanDvCtx = -1; /* Used only for bus scan and dv */
238 #define SNS_LEN(scp) sizeof((scp)->sense_buffer)
240 #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
242 * Domain Validation task structure
244 static DEFINE_SPINLOCK(dvtaskQ_lock);
245 static int dvtaskQ_active = 0;
246 static int dvtaskQ_release = 0;
247 static struct work_struct mptscsih_dvTask;
253 static DECLARE_WAIT_QUEUE_HEAD (scandv_waitq);
254 static int scandv_wait_done = 1;
257 /* Driver command line structure
259 static struct mptscsih_driver_setup driver_setup;
260 static struct scsi_host_template driver_template;
262 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
264 * mptscsih_add_sge - Place a simple SGE at address pAddr.
265 * @pAddr: virtual address for SGE
266 * @flagslength: SGE flags and data transfer length
267 * @dma_addr: Physical address
269 * This routine places a MPT request frame back on the MPT adapter's
273 mptscsih_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
275 if (sizeof(dma_addr_t) == sizeof(u64)) {
276 SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
277 u32 tmp = dma_addr & 0xFFFFFFFF;
279 pSge->FlagsLength = cpu_to_le32(flagslength);
280 pSge->Address.Low = cpu_to_le32(tmp);
281 tmp = (u32) ((u64)dma_addr >> 32);
282 pSge->Address.High = cpu_to_le32(tmp);
285 SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
286 pSge->FlagsLength = cpu_to_le32(flagslength);
287 pSge->Address = cpu_to_le32(dma_addr);
289 } /* mptscsih_add_sge() */
291 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
293 * mptscsih_add_chain - Place a chain SGE at address pAddr.
294 * @pAddr: virtual address for SGE
295 * @next: nextChainOffset value (u32's)
296 * @length: length of next SGL segment
297 * @dma_addr: Physical address
299 * This routine places a MPT request frame back on the MPT adapter's
303 mptscsih_add_chain(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
305 if (sizeof(dma_addr_t) == sizeof(u64)) {
306 SGEChain64_t *pChain = (SGEChain64_t *) pAddr;
307 u32 tmp = dma_addr & 0xFFFFFFFF;
309 pChain->Length = cpu_to_le16(length);
310 pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
312 pChain->NextChainOffset = next;
314 pChain->Address.Low = cpu_to_le32(tmp);
315 tmp = (u32) ((u64)dma_addr >> 32);
316 pChain->Address.High = cpu_to_le32(tmp);
318 SGEChain32_t *pChain = (SGEChain32_t *) pAddr;
319 pChain->Length = cpu_to_le16(length);
320 pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
321 pChain->NextChainOffset = next;
322 pChain->Address = cpu_to_le32(dma_addr);
324 } /* mptscsih_add_chain() */
326 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
328 * mptscsih_getFreeChainBuffer - Function to get a free chain
329 * from the MPT_SCSI_HOST FreeChainQ.
330 * @ioc: Pointer to MPT_ADAPTER structure
331 * @req_idx: Index of the SCSI IO request frame. (output)
333 * return SUCCESS or FAILED
336 mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)
338 MPT_FRAME_HDR *chainBuf;
343 dsgprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer called\n",
345 spin_lock_irqsave(&ioc->FreeQlock, flags);
346 if (!list_empty(&ioc->FreeChainQ)) {
349 chainBuf = list_entry(ioc->FreeChainQ.next, MPT_FRAME_HDR,
350 u.frame.linkage.list);
351 list_del(&chainBuf->u.frame.linkage.list);
352 offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;
353 chain_idx = offset / ioc->req_sz;
355 dsgprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer (index %d), got buf=%p\n",
356 ioc->name, *retIndex, chainBuf));
359 chain_idx = MPT_HOST_NO_CHAIN;
360 dfailprintk((MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n",
363 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
365 *retIndex = chain_idx;
367 } /* mptscsih_getFreeChainBuffer() */
369 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
371 * mptscsih_AddSGE - Add a SGE (plus chain buffers) to the
372 * SCSIIORequest_t Message Frame.
373 * @ioc: Pointer to MPT_ADAPTER structure
374 * @SCpnt: Pointer to scsi_cmnd structure
375 * @pReq: Pointer to SCSIIORequest_t structure
380 mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
381 SCSIIORequest_t *pReq, int req_idx)
385 struct scatterlist *sg;
387 int sges_left, sg_done;
388 int chain_idx = MPT_HOST_NO_CHAIN;
390 int numSgeSlots, numSgeThisFrame;
391 u32 sgflags, sgdir, thisxfer = 0;
392 int chain_dma_off = 0;
398 sgdir = le32_to_cpu(pReq->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK;
399 if (sgdir == MPI_SCSIIO_CONTROL_WRITE) {
400 sgdir = MPT_TRANSFER_HOST_TO_IOC;
402 sgdir = MPT_TRANSFER_IOC_TO_HOST;
405 psge = (char *) &pReq->SGL;
406 frm_sz = ioc->req_sz;
408 /* Map the data portion, if any.
409 * sges_left = 0 if no data transfer.
411 if ( (sges_left = SCpnt->use_sg) ) {
412 sges_left = pci_map_sg(ioc->pcidev,
413 (struct scatterlist *) SCpnt->request_buffer,
415 SCpnt->sc_data_direction);
418 } else if (SCpnt->request_bufflen) {
419 SCpnt->SCp.dma_handle = pci_map_single(ioc->pcidev,
420 SCpnt->request_buffer,
421 SCpnt->request_bufflen,
422 SCpnt->sc_data_direction);
423 dsgprintk((MYIOC_s_INFO_FMT "SG: non-SG for %p, len=%d\n",
424 ioc->name, SCpnt, SCpnt->request_bufflen));
425 mptscsih_add_sge((char *) &pReq->SGL,
426 0xD1000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|SCpnt->request_bufflen,
427 SCpnt->SCp.dma_handle);
432 /* Handle the SG case.
434 sg = (struct scatterlist *) SCpnt->request_buffer;
436 sgeOffset = sizeof(SCSIIORequest_t) - sizeof(SGE_IO_UNION);
439 /* Prior to entering this loop - the following must be set
440 * current MF: sgeOffset (bytes)
441 * chainSge (Null if original MF is not a chain buffer)
442 * sg_done (num SGE done for this MF)
446 numSgeSlots = ((frm_sz - sgeOffset) / (sizeof(u32) + sizeof(dma_addr_t)) );
447 numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots;
449 sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | MPT_SGE_FLAGS_ADDRESSING | sgdir;
451 /* Get first (num - 1) SG elements
452 * Skip any SG entries with a length of 0
453 * NOTE: at finish, sg and psge pointed to NEXT data/location positions
455 for (ii=0; ii < (numSgeThisFrame-1); ii++) {
456 thisxfer = sg_dma_len(sg);
458 sg ++; /* Get next SG element from the OS */
463 v2 = sg_dma_address(sg);
464 mptscsih_add_sge(psge, sgflags | thisxfer, v2);
466 sg++; /* Get next SG element from the OS */
467 psge += (sizeof(u32) + sizeof(dma_addr_t));
468 sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
472 if (numSgeThisFrame == sges_left) {
473 /* Add last element, end of buffer and end of list flags.
475 sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT |
476 MPT_SGE_FLAGS_END_OF_BUFFER |
477 MPT_SGE_FLAGS_END_OF_LIST;
479 /* Add last SGE and set termination flags.
480 * Note: Last SGE may have a length of 0 - which should be ok.
482 thisxfer = sg_dma_len(sg);
484 v2 = sg_dma_address(sg);
485 mptscsih_add_sge(psge, sgflags | thisxfer, v2);
488 psge += (sizeof(u32) + sizeof(dma_addr_t));
490 sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
494 /* The current buffer is a chain buffer,
495 * but there is not another one.
496 * Update the chain element
497 * Offset and Length fields.
499 mptscsih_add_chain((char *)chainSge, 0, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
501 /* The current buffer is the original MF
502 * and there is no Chain buffer.
504 pReq->ChainOffset = 0;
505 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
506 dsgprintk((MYIOC_s_ERR_FMT
507 "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
508 ioc->RequestNB[req_idx] = RequestNB;
511 /* At least one chain buffer is needed.
512 * Complete the first MF
513 * - last SGE element, set the LastElement bit
514 * - set ChainOffset (words) for orig MF
515 * (OR finish previous MF chain buffer)
516 * - update MFStructPtr ChainIndex
517 * - Populate chain element
522 dsgprintk((MYIOC_s_INFO_FMT "SG: Chain Required! sg done %d\n",
523 ioc->name, sg_done));
525 /* Set LAST_ELEMENT flag for last non-chain element
526 * in the buffer. Since psge points at the NEXT
527 * SGE element, go back one SGE element, update the flags
528 * and reset the pointer. (Note: sgflags & thisxfer are already
532 u32 *ptmp = (u32 *) (psge - (sizeof(u32) + sizeof(dma_addr_t)));
533 sgflags = le32_to_cpu(*ptmp);
534 sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT;
535 *ptmp = cpu_to_le32(sgflags);
539 /* The current buffer is a chain buffer.
540 * chainSge points to the previous Chain Element.
541 * Update its chain element Offset and Length (must
542 * include chain element size) fields.
543 * Old chain element is now complete.
545 u8 nextChain = (u8) (sgeOffset >> 2);
546 sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
547 mptscsih_add_chain((char *)chainSge, nextChain, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
549 /* The original MF buffer requires a chain buffer -
551 * Last element in this MF is a chain element.
553 pReq->ChainOffset = (u8) (sgeOffset >> 2);
554 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
555 dsgprintk((MYIOC_s_ERR_FMT "Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
556 ioc->RequestNB[req_idx] = RequestNB;
559 sges_left -= sg_done;
562 /* NOTE: psge points to the beginning of the chain element
563 * in current buffer. Get a chain buffer.
565 dsgprintk((MYIOC_s_INFO_FMT
566 "calling getFreeChainBuffer SCSI cmd=%02x (%p)\n",
567 ioc->name, pReq->CDB[0], SCpnt));
568 if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED)
571 /* Update the tracking arrays.
572 * If chainSge == NULL, update ReqToChain, else ChainToChain
575 ioc->ChainToChain[chain_idx] = newIndex;
577 ioc->ReqToChain[req_idx] = newIndex;
579 chain_idx = newIndex;
580 chain_dma_off = ioc->req_sz * chain_idx;
582 /* Populate the chainSGE for the current buffer.
583 * - Set chain buffer pointer to psge and fill
584 * out the Address and Flags fields.
586 chainSge = (char *) psge;
587 dsgprintk((KERN_INFO " Current buff @ %p (index 0x%x)",
590 /* Start the SGE for the next buffer
592 psge = (char *) (ioc->ChainBuffer + chain_dma_off);
596 dsgprintk((KERN_INFO " Chain buff @ %p (index 0x%x)\n",
599 /* Start the SGE for the next buffer
606 } /* mptscsih_AddSGE() */
608 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
610 * mptscsih_io_done - Main SCSI IO callback routine registered to
611 * Fusion MPT (base) driver
612 * @ioc: Pointer to MPT_ADAPTER structure
613 * @mf: Pointer to original MPT request frame
614 * @r: Pointer to MPT reply frame (NULL if TurboReply)
616 * This routine is called from mpt.c::mpt_interrupt() at the completion
617 * of any SCSI IO request.
618 * This routine is registered with the Fusion MPT (base) driver at driver
619 * load/init time via the mpt_register() API call.
621 * Returns 1 indicating alloc'd request frame ptr should be freed.
624 mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
626 struct scsi_cmnd *sc;
628 SCSIIORequest_t *pScsiReq;
629 SCSIIOReply_t *pScsiReply;
632 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
634 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
635 sc = hd->ScsiLookup[req_idx];
637 MPIHeader_t *hdr = (MPIHeader_t *)mf;
639 /* Remark: writeSDP1 will use the ScsiDoneCtx
640 * If a SCSI I/O cmd, device disabled by OS and
641 * completion done. Cannot touch sc struct. Just free mem.
643 if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST)
644 printk(MYIOC_s_ERR_FMT "NULL ScsiCmd ptr!\n",
647 mptscsih_freeChainBuffers(ioc, req_idx);
651 dmfprintk((MYIOC_s_INFO_FMT
652 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",
653 ioc->name, mf, mr, sc, req_idx));
655 sc->result = DID_OK << 16; /* Set default reply as OK */
656 pScsiReq = (SCSIIORequest_t *) mf;
657 pScsiReply = (SCSIIOReply_t *) mr;
659 if (pScsiReply == NULL) {
660 /* special context reply handling */
665 u8 scsi_state, scsi_status;
667 status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
668 scsi_state = pScsiReply->SCSIState;
669 scsi_status = pScsiReply->SCSIStatus;
670 xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);
671 sc->resid = sc->request_bufflen - xfer_cnt;
673 dreplyprintk((KERN_NOTICE "Reply ha=%d id=%d lun=%d:\n"
674 "IOCStatus=%04xh SCSIState=%02xh SCSIStatus=%02xh\n"
675 "resid=%d bufflen=%d xfer_cnt=%d\n",
676 ioc->id, pScsiReq->TargetID, pScsiReq->LUN[1],
677 status, scsi_state, scsi_status, sc->resid,
678 sc->request_bufflen, xfer_cnt));
680 if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)
681 copy_sense_data(sc, hd, mf, pScsiReply);
684 * Look for + dump FCP ResponseInfo[]!
686 if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID) {
687 printk(KERN_NOTICE " FCP_ResponseInfo=%08xh\n",
688 le32_to_cpu(pScsiReply->ResponseInfo));
692 case MPI_IOCSTATUS_BUSY: /* 0x0002 */
694 * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry)
695 * But not: DID_BUS_BUSY lest one risk
696 * killing interrupt handler:-(
698 sc->result = SAM_STAT_BUSY;
701 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
702 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
703 sc->result = DID_BAD_TARGET << 16;
706 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
707 /* Spoof to SCSI Selection Timeout! */
708 sc->result = DID_NO_CONNECT << 16;
710 if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)
711 hd->sel_timeout[pScsiReq->TargetID]++;
714 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
715 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
716 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
717 /* Linux handles an unsolicited DID_RESET better
718 * than an unsolicited DID_ABORT.
720 sc->result = DID_RESET << 16;
722 /* GEM Workaround. */
723 if (ioc->bus_type == SCSI)
724 mptscsih_no_negotiate(hd, sc->device->id);
727 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
728 if ( xfer_cnt >= sc->underflow ) {
729 /* Sufficient data transfer occurred */
730 sc->result = (DID_OK << 16) | scsi_status;
731 } else if ( xfer_cnt == 0 ) {
732 /* A CRC Error causes this condition; retry */
733 sc->result = (DRIVER_SENSE << 24) | (DID_OK << 16) |
734 (CHECK_CONDITION << 1);
735 sc->sense_buffer[0] = 0x70;
736 sc->sense_buffer[2] = NO_SENSE;
737 sc->sense_buffer[12] = 0;
738 sc->sense_buffer[13] = 0;
740 sc->result = DID_SOFT_ERROR << 16;
742 dreplyprintk((KERN_NOTICE "RESIDUAL_MISMATCH: result=%x on id=%d\n", sc->result, sc->target));
745 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
747 * Do upfront check for valid SenseData and give it
750 sc->result = (DID_OK << 16) | scsi_status;
751 if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
752 /* Have already saved the status and sense data
756 if (xfer_cnt < sc->underflow) {
757 sc->result = DID_SOFT_ERROR << 16;
759 if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {
762 sc->result = DID_SOFT_ERROR << 16;
764 else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
765 /* Not real sure here either... */
766 sc->result = DID_RESET << 16;
770 dreplyprintk((KERN_NOTICE " sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
772 dreplyprintk((KERN_NOTICE " ActBytesXferd=%02xh\n", xfer_cnt));
775 if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)
776 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
780 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
781 case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
782 scsi_status = pScsiReply->SCSIStatus;
783 sc->result = (DID_OK << 16) | scsi_status;
784 if (scsi_state == 0) {
786 } else if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
788 * If running against circa 200003dd 909 MPT f/w,
789 * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL
790 * (QUEUE_FULL) returned from device! --> get 0x0000?128
791 * and with SenseBytes set to 0.
793 if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL)
794 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
797 else if (scsi_state &
798 (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)
803 sc->result = DID_SOFT_ERROR << 16;
805 else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
806 /* Not real sure here either... */
807 sc->result = DID_RESET << 16;
809 else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) {
810 /* Device Inq. data indicates that it supports
811 * QTags, but rejects QTag messages.
812 * This command completed OK.
814 * Not real sure here either so do nothing... */
817 if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL)
818 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
821 * Reservation Conflict, Busy,
822 * Command Terminated, CHECK
826 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
827 sc->result = DID_SOFT_ERROR << 16;
830 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
831 case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
832 case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
833 case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
834 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
835 case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
836 case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
837 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
838 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
839 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
844 sc->result = DID_SOFT_ERROR << 16;
847 } /* switch(status) */
849 dreplyprintk((KERN_NOTICE " sc->result is %08xh\n", sc->result));
850 } /* end of address reply case */
852 /* Unmap the DMA buffers, if any. */
854 pci_unmap_sg(ioc->pcidev, (struct scatterlist *) sc->request_buffer,
855 sc->use_sg, sc->sc_data_direction);
856 } else if (sc->request_bufflen) {
857 pci_unmap_single(ioc->pcidev, sc->SCp.dma_handle,
858 sc->request_bufflen, sc->sc_data_direction);
861 hd->ScsiLookup[req_idx] = NULL;
863 sc->scsi_done(sc); /* Issue the command callback */
865 /* Free Chain buffers */
866 mptscsih_freeChainBuffers(ioc, req_idx);
872 * mptscsih_flush_running_cmds - For each command found, search
873 * Scsi_Host instance taskQ and reply to OS.
874 * Called only if recovering from a FW reload.
875 * @hd: Pointer to a SCSI HOST structure
879 * Must be called while new I/Os are being queued.
882 mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
884 MPT_ADAPTER *ioc = hd->ioc;
885 struct scsi_cmnd *SCpnt;
888 int max = ioc->req_depth;
890 dprintk((KERN_INFO MYNAM ": flush_ScsiLookup called\n"));
891 for (ii= 0; ii < max; ii++) {
892 if ((SCpnt = hd->ScsiLookup[ii]) != NULL) {
897 /* Null ScsiLookup index
899 hd->ScsiLookup[ii] = NULL;
901 mf = MPT_INDEX_2_MFPTR(ioc, ii);
902 dmfprintk(( "flush: ScsiDone (mf=%p,sc=%p)\n",
905 /* Set status, free OS resources (SG DMA buffers)
907 * Free driver resources (chain, msg buffers)
909 if (scsi_device_online(SCpnt->device)) {
911 pci_unmap_sg(ioc->pcidev,
912 (struct scatterlist *) SCpnt->request_buffer,
914 SCpnt->sc_data_direction);
915 } else if (SCpnt->request_bufflen) {
916 pci_unmap_single(ioc->pcidev,
917 SCpnt->SCp.dma_handle,
918 SCpnt->request_bufflen,
919 SCpnt->sc_data_direction);
922 SCpnt->result = DID_RESET << 16;
923 SCpnt->host_scribble = NULL;
925 /* Free Chain buffers */
926 mptscsih_freeChainBuffers(ioc, ii);
928 /* Free Message frames */
929 mpt_free_msg_frame(ioc, mf);
931 SCpnt->scsi_done(SCpnt); /* Issue the command callback */
939 * mptscsih_search_running_cmds - Delete any commands associated
940 * with the specified target and lun. Function called only
941 * when a lun is disable by mid-layer.
942 * Do NOT access the referenced scsi_cmnd structure or
943 * members. Will cause either a paging or NULL ptr error.
944 * @hd: Pointer to a SCSI HOST structure
950 * Called from slave_destroy.
953 mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, uint target, uint lun)
955 SCSIIORequest_t *mf = NULL;
957 int max = hd->ioc->req_depth;
959 dsprintk((KERN_INFO MYNAM ": search_running target %d lun %d max %d\n",
962 for (ii=0; ii < max; ii++) {
963 if (hd->ScsiLookup[ii] != NULL) {
965 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(hd->ioc, ii);
967 dsprintk(( "search_running: found (sc=%p, mf = %p) target %d, lun %d \n",
968 hd->ScsiLookup[ii], mf, mf->TargetID, mf->LUN[1]));
970 if ((mf->TargetID != ((u8)target)) || (mf->LUN[1] != ((u8) lun)))
975 hd->ScsiLookup[ii] = NULL;
976 mptscsih_freeChainBuffers(hd->ioc, ii);
977 mpt_free_msg_frame(hd->ioc, (MPT_FRAME_HDR *)mf);
984 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
986 * Hack! It might be nice to report if a device is returning QUEUE_FULL
987 * but maybe not each and every time...
989 static long last_queue_full = 0;
991 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
993 * mptscsih_report_queue_full - Report QUEUE_FULL status returned
994 * from a SCSI target device.
995 * @sc: Pointer to scsi_cmnd structure
996 * @pScsiReply: Pointer to SCSIIOReply_t
997 * @pScsiReq: Pointer to original SCSI request
999 * This routine periodically reports QUEUE_FULL status returned from a
1000 * SCSI target device. It reports this to the console via kernel
1001 * printk() API call, not more than once every 10 seconds.
1004 mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq)
1006 long time = jiffies;
1008 if (time - last_queue_full > 10 * HZ) {
1009 char *ioc_str = "ioc?";
1011 if (sc->device && sc->device->host != NULL && sc->device->host->hostdata != NULL)
1012 ioc_str = ((MPT_SCSI_HOST *)sc->device->host->hostdata)->ioc->name;
1013 dprintk((MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n",
1014 ioc_str, 0, sc->device->id, sc->device->lun));
1015 last_queue_full = time;
1019 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1020 static char *info_kbuf = NULL;
1022 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1023 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1025 * mptscsih_probe - Installs scsi devices per bus.
1026 * @pdev: Pointer to pci_dev structure
1028 * Returns 0 for success, non-zero for failure.
1033 mptscsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1035 struct Scsi_Host *sh;
1037 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1038 unsigned long flags;
1047 /* 20010202 -sralston
1048 * Added sanity check on readiness of the MPT adapter.
1050 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
1051 printk(MYIOC_s_WARN_FMT
1052 "Skipping because it's not operational!\n",
1058 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
1063 /* Sanity check - ensure at least 1 port is INITIATOR capable
1066 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1067 if (ioc->pfacts[ii].ProtocolFlags &
1068 MPI_PORTFACTS_PROTOCOL_INITIATOR)
1073 printk(MYIOC_s_WARN_FMT
1074 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
1079 sh = scsi_host_alloc(&driver_template, sizeof(MPT_SCSI_HOST));
1082 printk(MYIOC_s_WARN_FMT
1083 "Unable to register controller with SCSI subsystem\n",
1088 spin_lock_irqsave(&ioc->FreeQlock, flags);
1090 /* Attach the SCSI Host to the IOC structure
1098 /* set 16 byte cdb's */
1099 sh->max_cmd_len = 16;
1101 /* Yikes! This is important!
1102 * Otherwise, by default, linux
1103 * only scans target IDs 0-7!
1104 * pfactsN->MaxDevices unreliable
1105 * (not supported in early
1106 * versions of the FW).
1107 * max_id = 1 + actual max id,
1108 * max_lun = 1 + actual last lun,
1111 if (ioc->bus_type == SCSI) {
1112 sh->max_id = MPT_MAX_SCSI_DEVICES;
1114 /* For FC, increase the queue depth
1115 * from MPT_SCSI_CAN_QUEUE (31)
1116 * to MPT_FC_CAN_QUEUE (63).
1118 sh->can_queue = MPT_FC_CAN_QUEUE;
1120 MPT_MAX_FC_DEVICES<256 ? MPT_MAX_FC_DEVICES : 255;
1123 sh->max_lun = MPT_LAST_LUN + 1;
1124 sh->max_channel = 0;
1125 sh->this_id = ioc->pfacts[0].PortSCSIID;
1129 sh->unique_id = ioc->id;
1131 /* Verify that we won't exceed the maximum
1132 * number of chain buffers
1133 * We can optimize: ZZ = req_sz/sizeof(SGE)
1135 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
1136 * + (req_sz - 64)/sizeof(SGE)
1137 * A slightly different algorithm is required for
1140 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
1141 if (sizeof(dma_addr_t) == sizeof(u64)) {
1142 numSGE = (scale - 1) *
1143 (ioc->facts.MaxChainDepth-1) + scale +
1144 (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
1147 numSGE = 1 + (scale - 1) *
1148 (ioc->facts.MaxChainDepth-1) + scale +
1149 (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
1153 if (numSGE < sh->sg_tablesize) {
1154 /* Reset this value */
1155 dprintk((MYIOC_s_INFO_FMT
1156 "Resetting sg_tablesize to %d from %d\n",
1157 ioc->name, numSGE, sh->sg_tablesize));
1158 sh->sg_tablesize = numSGE;
1161 /* Set the pci device pointer in Scsi_Host structure.
1163 scsi_set_device(sh, &ioc->pcidev->dev);
1165 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1167 hd = (MPT_SCSI_HOST *) sh->hostdata;
1170 /* SCSI needs scsi_cmnd lookup table!
1171 * (with size equal to req_depth*PtrSz!)
1173 sz = ioc->req_depth * sizeof(void *);
1174 mem = kmalloc(sz, GFP_ATOMIC);
1177 goto mptscsih_probe_failed;
1181 hd->ScsiLookup = (struct scsi_cmnd **) mem;
1183 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p, sz=%d\n",
1184 ioc->name, hd->ScsiLookup, sz));
1186 /* Allocate memory for the device structures.
1187 * A non-Null pointer at an offset
1188 * indicates a device exists.
1189 * max_id = 1 + maximum id (hosts.h)
1191 sz = sh->max_id * sizeof(void *);
1192 mem = kmalloc(sz, GFP_ATOMIC);
1195 goto mptscsih_probe_failed;
1199 hd->Targets = (VirtDevice **) mem;
1202 " Targets @ %p, sz=%d\n", hd->Targets, sz));
1204 /* Clear the TM flags
1207 hd->tmState = TM_STATE_NONE;
1208 hd->resetPending = 0;
1209 hd->abortSCpnt = NULL;
1212 /* Clear the pointer used to store
1213 * single-threaded commands, i.e., those
1214 * issued during a bus scan, dv and
1215 * configuration pages.
1219 /* Initialize this SCSI Hosts' timers
1220 * To use, set the timer expires field
1223 init_timer(&hd->timer);
1224 hd->timer.data = (unsigned long) hd;
1225 hd->timer.function = mptscsih_timer_expired;
1227 init_timer(&hd->TMtimer);
1228 hd->TMtimer.data = (unsigned long) hd;
1229 hd->TMtimer.function = mptscsih_taskmgmt_timeout;
1230 hd->qtag_tick = jiffies;
1232 /* Moved Earlier Pam D */
1235 if (ioc->bus_type == SCSI) {
1236 /* Update with the driver setup
1239 if (ioc->spi_data.maxBusWidth >
1240 driver_setup.max_width) {
1241 ioc->spi_data.maxBusWidth =
1242 driver_setup.max_width;
1245 if (ioc->spi_data.minSyncFactor <
1246 driver_setup.min_sync_factor) {
1247 ioc->spi_data.minSyncFactor =
1248 driver_setup.min_sync_factor;
1251 if (ioc->spi_data.minSyncFactor == MPT_ASYNC) {
1252 ioc->spi_data.maxSyncOffset = 0;
1255 ioc->spi_data.Saf_Te = driver_setup.saf_te;
1258 #ifndef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
1259 hd->negoNvram = MPT_SCSICFG_USE_NVRAM;
1261 ioc->spi_data.forceDv = 0;
1262 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
1263 ioc->spi_data.dvStatus[ii] =
1264 MPT_SCSICFG_NEGOTIATE;
1267 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++)
1268 ioc->spi_data.dvStatus[ii] |=
1269 MPT_SCSICFG_DV_NOT_DONE;
1271 ddvprintk((MYIOC_s_INFO_FMT
1272 "dv %x width %x factor %x saf_te %x\n",
1273 ioc->name, driver_setup.dv,
1274 driver_setup.max_width,
1275 driver_setup.min_sync_factor,
1276 driver_setup.saf_te));
1281 error = scsi_add_host (sh, &ioc->pcidev->dev);
1283 dprintk((KERN_ERR MYNAM
1284 "scsi_add_host failed\n"));
1285 goto mptscsih_probe_failed;
1291 mptscsih_probe_failed:
1293 mptscsih_remove(pdev);
1298 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1300 * mptscsih_remove - Removed scsi devices
1301 * @pdev: Pointer to pci_dev structure
1306 mptscsih_remove(struct pci_dev *pdev)
1308 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1309 struct Scsi_Host *host = ioc->sh;
1312 unsigned long flags;
1317 scsi_remove_host(host);
1319 #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
1320 /* Check DV thread active */
1322 spin_lock_irqsave(&dvtaskQ_lock, flags);
1323 if (dvtaskQ_active) {
1324 spin_unlock_irqrestore(&dvtaskQ_lock, flags);
1325 while(dvtaskQ_active && --count) {
1326 set_current_state(TASK_INTERRUPTIBLE);
1327 schedule_timeout(1);
1330 spin_unlock_irqrestore(&dvtaskQ_lock, flags);
1333 printk(KERN_ERR MYNAM ": ERROR - DV thread still active!\n");
1334 #if defined(MPT_DEBUG_DV) || defined(MPT_DEBUG_DV_TINY)
1336 printk(KERN_ERR MYNAM ": DV thread orig %d, count %d\n", 10 * HZ, count);
1340 hd = (MPT_SCSI_HOST *)host->hostdata;
1344 mptscsih_shutdown(&pdev->dev);
1348 if (hd->ScsiLookup != NULL) {
1349 sz1 = hd->ioc->req_depth * sizeof(void *);
1350 kfree(hd->ScsiLookup);
1351 hd->ScsiLookup = NULL;
1354 if (hd->Targets != NULL) {
1356 * Free pointer array.
1362 dprintk((MYIOC_s_INFO_FMT
1363 "Free'd ScsiLookup (%d) memory\n",
1364 hd->ioc->name, sz1));
1366 /* NULL the Scsi_Host pointer
1371 scsi_host_put(host);
1376 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1378 * mptscsih_shutdown - reboot notifier
1382 mptscsih_shutdown(struct device * dev)
1384 MPT_ADAPTER *ioc = pci_get_drvdata(to_pci_dev(dev));
1385 struct Scsi_Host *host = ioc->sh;
1391 hd = (MPT_SCSI_HOST *)host->hostdata;
1393 /* Flush the cache of this adapter
1396 mptscsih_synchronize_cache(hd, 0);
1401 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1403 * mptscsih_suspend - Fusion MPT scsie driver suspend routine.
1408 mptscsih_suspend(struct pci_dev *pdev, u32 state)
1410 mptscsih_shutdown(&pdev->dev);
1414 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1416 * mptscsih_resume - Fusion MPT scsi driver resume routine.
1421 mptscsih_resume(struct pci_dev *pdev)
1423 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1424 struct Scsi_Host *host = ioc->sh;
1430 hd = (MPT_SCSI_HOST *)host->hostdata;
1434 #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
1436 unsigned long lflags;
1437 spin_lock_irqsave(&dvtaskQ_lock, lflags);
1438 if (!dvtaskQ_active) {
1440 spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
1441 INIT_WORK(&mptscsih_dvTask,
1442 mptscsih_domainValidation, (void *) hd);
1443 schedule_work(&mptscsih_dvTask);
1445 spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
1454 static struct mpt_pci_driver mptscsih_driver = {
1455 .probe = mptscsih_probe,
1456 .remove = mptscsih_remove,
1457 .shutdown = mptscsih_shutdown,
1459 .suspend = mptscsih_suspend,
1460 .resume = mptscsih_resume,
1464 /* SCSI host fops start here... */
1465 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1467 * mptscsih_init - Register MPT adapter(s) as SCSI host(s) with
1468 * linux scsi mid-layer.
1470 * Returns 0 for success, non-zero for failure.
1476 show_mptmod_ver(my_NAME, my_VERSION);
1478 ScsiDoneCtx = mpt_register(mptscsih_io_done, MPTSCSIH_DRIVER);
1479 ScsiTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSCSIH_DRIVER);
1480 ScsiScanDvCtx = mpt_register(mptscsih_scandv_complete, MPTSCSIH_DRIVER);
1482 if (mpt_event_register(ScsiDoneCtx, mptscsih_event_process) == 0) {
1483 devtprintk((KERN_INFO MYNAM
1484 ": Registered for IOC event notifications\n"));
1487 if (mpt_reset_register(ScsiDoneCtx, mptscsih_ioc_reset) == 0) {
1488 dprintk((KERN_INFO MYNAM
1489 ": Registered for IOC reset notifications\n"));
1493 dinitprintk((KERN_INFO MYNAM
1494 ": Command Line Args: dv=%d max_width=%d "
1495 "factor=0x%x saf_te=%d\n",
1496 dv, width, factor, saf_te));
1498 driver_setup.dv = (dv) ? 1 : 0;
1499 driver_setup.max_width = (width) ? 1 : 0;
1500 driver_setup.min_sync_factor = factor;
1501 driver_setup.saf_te = (saf_te) ? 1 : 0;;
1504 if(mpt_device_driver_register(&mptscsih_driver,
1505 MPTSCSIH_DRIVER) != 0 ) {
1506 dprintk((KERN_INFO MYNAM
1507 ": failed to register dd callbacks\n"));
1514 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1515 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1517 * mptscsih_exit - Unregisters MPT adapter(s)
1523 mpt_device_driver_deregister(MPTSCSIH_DRIVER);
1525 mpt_reset_deregister(ScsiDoneCtx);
1526 dprintk((KERN_INFO MYNAM
1527 ": Deregistered for IOC reset notifications\n"));
1529 mpt_event_deregister(ScsiDoneCtx);
1530 dprintk((KERN_INFO MYNAM
1531 ": Deregistered for IOC event notifications\n"));
1533 mpt_deregister(ScsiScanDvCtx);
1534 mpt_deregister(ScsiTaskCtx);
1535 mpt_deregister(ScsiDoneCtx);
1537 if (info_kbuf != NULL)
1542 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1544 * mptscsih_info - Return information about MPT adapter
1545 * @SChost: Pointer to Scsi_Host structure
1547 * (linux scsi_host_template.info routine)
1549 * Returns pointer to buffer where information was written.
1552 mptscsih_info(struct Scsi_Host *SChost)
1557 if (info_kbuf == NULL)
1558 if ((info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
1561 h = (MPT_SCSI_HOST *)SChost->hostdata;
1562 info_kbuf[0] = '\0';
1564 mpt_print_ioc_summary(h->ioc, info_kbuf, &size, 0, 0);
1565 info_kbuf[size-1] = '\0';
1578 static void copy_mem_info(struct info_str *info, char *data, int len)
1580 if (info->pos + len > info->length)
1581 len = info->length - info->pos;
1583 if (info->pos + len < info->offset) {
1588 if (info->pos < info->offset) {
1589 data += (info->offset - info->pos);
1590 len -= (info->offset - info->pos);
1594 memcpy(info->buffer + info->pos, data, len);
1599 static int copy_info(struct info_str *info, char *fmt, ...)
1605 va_start(args, fmt);
1606 len = vsprintf(buf, fmt, args);
1609 copy_mem_info(info, buf, len);
1613 static int mptscsih_host_info(MPT_ADAPTER *ioc, char *pbuf, off_t offset, int len)
1615 struct info_str info;
1619 info.offset = offset;
1622 copy_info(&info, "%s: %s, ", ioc->name, ioc->prod_name);
1623 copy_info(&info, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word);
1624 copy_info(&info, "Ports=%d, ", ioc->facts.NumberOfPorts);
1625 copy_info(&info, "MaxQ=%d\n", ioc->req_depth);
1627 return ((info.pos > info.offset) ? info.pos - info.offset : 0);
1630 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1632 * mptscsih_proc_info - Return information about MPT adapter
1634 * (linux scsi_host_template.info routine)
1636 * buffer: if write, user data; if read, buffer for user
1637 * length: if write, return length;
1638 * offset: if write, 0; if read, the current offset into the buffer from
1639 * the previous read.
1640 * hostno: scsi host number
1641 * func: if write = 1; if read = 0
1644 mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
1645 int length, int func)
1647 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
1648 MPT_ADAPTER *ioc = hd->ioc;
1653 * write is not supported
1659 size = mptscsih_host_info(ioc, buffer, offset, length);
1665 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1666 #define ADD_INDEX_LOG(req_ent) do { } while(0)
1668 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1670 * mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine.
1671 * @SCpnt: Pointer to scsi_cmnd structure
1672 * @done: Pointer SCSI mid-layer IO completion function
1674 * (linux scsi_host_template.queuecommand routine)
1675 * This is the primary SCSI IO start routine. Create a MPI SCSIIORequest
1676 * from a linux scsi_cmnd request and send it to the IOC.
1678 * Returns 0. (rtn value discarded by linux scsi mid-layer)
1681 mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1685 SCSIIORequest_t *pScsiReq;
1686 VirtDevice *pTarget;
1696 hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata;
1697 target = SCpnt->device->id;
1698 lun = SCpnt->device->lun;
1699 SCpnt->scsi_done = done;
1701 pTarget = hd->Targets[target];
1703 dmfprintk((MYIOC_s_INFO_FMT "qcmd: SCpnt=%p, done()=%p\n",
1704 (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt, done));
1706 if (hd->resetPending) {
1707 dtmprintk((MYIOC_s_WARN_FMT "qcmd: SCpnt=%p timeout + 60HZ\n",
1708 (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt));
1709 return SCSI_MLQUEUE_HOST_BUSY;
1713 * Put together a MPT SCSI request...
1715 if ((mf = mpt_get_msg_frame(ScsiDoneCtx, hd->ioc)) == NULL) {
1716 dprintk((MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
1718 return SCSI_MLQUEUE_HOST_BUSY;
1721 pScsiReq = (SCSIIORequest_t *) mf;
1723 my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1725 ADD_INDEX_LOG(my_idx);
1727 /* BUG FIX! 19991030 -sralston
1728 * TUR's being issued with scsictl=0x02000000 (DATA_IN)!
1729 * Seems we may receive a buffer (datalen>0) even when there
1730 * will be no data transfer! GRRRRR...
1732 if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
1733 datalen = SCpnt->request_bufflen;
1734 scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */
1735 } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
1736 datalen = SCpnt->request_bufflen;
1737 scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */
1740 scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER;
1743 /* Default to untagged. Once a target structure has been allocated,
1744 * use the Inquiry data to determine if device supports tagged.
1747 && (pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)
1748 && (SCpnt->device->tagged_supported)) {
1749 scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
1751 scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
1754 /* Use the above information to set up the message frame
1756 pScsiReq->TargetID = (u8) target;
1757 pScsiReq->Bus = (u8) SCpnt->device->channel;
1758 pScsiReq->ChainOffset = 0;
1759 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
1760 pScsiReq->CDBLength = SCpnt->cmd_len;
1761 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1762 pScsiReq->Reserved = 0;
1763 pScsiReq->MsgFlags = mpt_msg_flags();
1764 pScsiReq->LUN[0] = 0;
1765 pScsiReq->LUN[1] = lun;
1766 pScsiReq->LUN[2] = 0;
1767 pScsiReq->LUN[3] = 0;
1768 pScsiReq->LUN[4] = 0;
1769 pScsiReq->LUN[5] = 0;
1770 pScsiReq->LUN[6] = 0;
1771 pScsiReq->LUN[7] = 0;
1772 pScsiReq->Control = cpu_to_le32(scsictl);
1775 * Write SCSI CDB into the message
1777 cmd_len = SCpnt->cmd_len;
1778 for (ii=0; ii < cmd_len; ii++)
1779 pScsiReq->CDB[ii] = SCpnt->cmnd[ii];
1781 for (ii=cmd_len; ii < 16; ii++)
1782 pScsiReq->CDB[ii] = 0;
1785 pScsiReq->DataLength = cpu_to_le32(datalen);
1787 /* SenseBuffer low address */
1788 pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma
1789 + (my_idx * MPT_SENSE_BUFFER_ALLOC));
1791 /* Now add the SG list
1792 * Always have a SGE even if null length.
1795 /* Add a NULL SGE */
1796 mptscsih_add_sge((char *)&pScsiReq->SGL, MPT_SGE_FLAGS_SSIMPLE_READ | 0,
1799 /* Add a 32 or 64 bit SGE */
1800 if (mptscsih_AddSGE(hd->ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
1804 hd->ScsiLookup[my_idx] = SCpnt;
1805 SCpnt->host_scribble = NULL;
1807 #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
1808 if (hd->ioc->bus_type == SCSI) {
1809 int dvStatus = hd->ioc->spi_data.dvStatus[target];
1812 if (dvStatus || hd->ioc->spi_data.forceDv) {
1814 if ((dvStatus & MPT_SCSICFG_NEED_DV) ||
1815 (hd->ioc->spi_data.forceDv & MPT_SCSICFG_NEED_DV)) {
1816 unsigned long lflags;
1817 /* Schedule DV if necessary */
1818 spin_lock_irqsave(&dvtaskQ_lock, lflags);
1819 if (!dvtaskQ_active) {
1821 spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
1822 INIT_WORK(&mptscsih_dvTask, mptscsih_domainValidation, (void *) hd);
1824 schedule_work(&mptscsih_dvTask);
1826 spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
1828 hd->ioc->spi_data.forceDv &= ~MPT_SCSICFG_NEED_DV;
1831 /* Trying to do DV to this target, extend timeout.
1832 * Wait to issue until flag is clear
1834 if (dvStatus & MPT_SCSICFG_DV_PENDING) {
1835 mod_timer(&SCpnt->eh_timeout, jiffies + 40 * HZ);
1839 /* Set the DV flags.
1841 if (dvStatus & MPT_SCSICFG_DV_NOT_DONE)
1842 mptscsih_set_dvflags(hd, pScsiReq);
1850 mpt_put_msg_frame(ScsiDoneCtx, hd->ioc, mf);
1851 dmfprintk((MYIOC_s_INFO_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
1852 hd->ioc->name, SCpnt, mf, my_idx));
1853 DBG_DUMP_REQUEST_FRAME(mf)
1857 mptscsih_freeChainBuffers(hd->ioc, my_idx);
1858 mpt_free_msg_frame(hd->ioc, mf);
1859 return SCSI_MLQUEUE_HOST_BUSY;
1862 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1864 * mptscsih_freeChainBuffers - Function to free chain buffers associated
1865 * with a SCSI IO request
1866 * @hd: Pointer to the MPT_SCSI_HOST instance
1867 * @req_idx: Index of the SCSI IO request frame.
1869 * Called if SG chain buffer allocation fails and mptscsih callbacks.
1873 mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
1875 MPT_FRAME_HDR *chain;
1876 unsigned long flags;
1880 /* Get the first chain index and reset
1883 chain_idx = ioc->ReqToChain[req_idx];
1884 ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN;
1886 while (chain_idx != MPT_HOST_NO_CHAIN) {
1888 /* Save the next chain buffer index */
1889 next = ioc->ChainToChain[chain_idx];
1891 /* Free this chain buffer and reset
1894 ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN;
1896 chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer
1897 + (chain_idx * ioc->req_sz));
1899 spin_lock_irqsave(&ioc->FreeQlock, flags);
1900 list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);
1901 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1903 dmfprintk((MYIOC_s_INFO_FMT "FreeChainBuffers (index %d)\n",
1904 ioc->name, chain_idx));
1912 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1917 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1919 * mptscsih_TMHandler - Generic handler for SCSI Task Management.
1920 * Fall through to mpt_HardResetHandler if: not operational, too many
1921 * failed TM requests or handshake failure.
1923 * @ioc: Pointer to MPT_ADAPTER structure
1924 * @type: Task Management type
1925 * @target: Logical Target ID for reset (if appropriate)
1926 * @lun: Logical Unit for reset (if appropriate)
1927 * @ctx2abort: Context for the task to be aborted (if appropriate)
1928 * @sleepFlag: If set, use udelay instead of schedule in handshake code.
1930 * Remark: Currently invoked from a non-interrupt thread (_bh).
1932 * Remark: With old EH code, at most 1 SCSI TaskMgmt function per IOC
1935 * Returns 0 for SUCCESS or -1 if FAILED.
1938 mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout, int sleepFlag)
1944 unsigned long flags;
1946 /* If FW is being reloaded currently, return success to
1947 * the calling function.
1954 printk(KERN_ERR MYNAM " TMHandler" " NULL ioc!\n");
1957 dtmprintk((MYIOC_s_INFO_FMT "TMHandler Entered!\n", ioc->name));
1959 // SJR - CHECKME - Can we avoid this here?
1960 // (mpt_HardResetHandler has this check...)
1961 spin_lock_irqsave(&ioc->diagLock, flags);
1962 if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)) {
1963 spin_unlock_irqrestore(&ioc->diagLock, flags);
1966 spin_unlock_irqrestore(&ioc->diagLock, flags);
1968 /* Wait a fixed amount of time for the TM pending flag to be cleared.
1969 * If we time out and not bus reset, then we return a FAILED status to the caller.
1970 * The call to mptscsih_tm_pending_wait() will set the pending flag if we are
1971 * successful. Otherwise, reload the FW.
1973 if (mptscsih_tm_pending_wait(hd) == FAILED) {
1974 if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
1975 dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler abort: "
1976 "Timed out waiting for last TM (%d) to complete! \n",
1977 hd->ioc->name, hd->tmPending));
1979 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) {
1980 dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler target reset: "
1981 "Timed out waiting for last TM (%d) to complete! \n",
1982 hd->ioc->name, hd->tmPending));
1984 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
1985 dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler bus reset: "
1986 "Timed out waiting for last TM (%d) to complete! \n",
1987 hd->ioc->name, hd->tmPending));
1988 if (hd->tmPending & (1 << MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS))
1994 spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
1995 hd->tmPending |= (1 << type);
1996 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
2001 ioc_raw_state = mpt_GetIocState(hd->ioc, 0);
2003 #ifdef MPT_DEBUG_RESET
2004 if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
2005 printk(MYIOC_s_WARN_FMT
2006 "TM Handler: IOC Not operational(0x%x)!\n",
2007 hd->ioc->name, ioc_raw_state);
2011 if (doTask && ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL)
2012 && !(ioc_raw_state & MPI_DOORBELL_ACTIVE)) {
2014 /* Isse the Task Mgmt request.
2016 if (hd->hard_resets < -1)
2018 rc = mptscsih_IssueTaskMgmt(hd, type, channel, target, lun, ctx2abort, timeout, sleepFlag);
2020 printk(MYIOC_s_INFO_FMT "Issue of TaskMgmt failed!\n", hd->ioc->name);
2022 dtmprintk((MYIOC_s_INFO_FMT "Issue of TaskMgmt Successful!\n", hd->ioc->name));
2026 /* Only fall through to the HRH if this is a bus reset
2028 if ((type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) && (rc ||
2029 ioc->reload_fw || (ioc->alt_ioc && ioc->alt_ioc->reload_fw))) {
2030 dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n",
2032 rc = mpt_HardResetHandler(hd->ioc, sleepFlag);
2035 dtmprintk((MYIOC_s_INFO_FMT "TMHandler rc = %d!\n", hd->ioc->name, rc));
2041 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2043 * mptscsih_IssueTaskMgmt - Generic send Task Management function.
2044 * @hd: Pointer to MPT_SCSI_HOST structure
2045 * @type: Task Management type
2046 * @target: Logical Target ID for reset (if appropriate)
2047 * @lun: Logical Unit for reset (if appropriate)
2048 * @ctx2abort: Context for the task to be aborted (if appropriate)
2049 * @sleepFlag: If set, use udelay instead of schedule in handshake code.
2051 * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
2052 * or a non-interrupt thread. In the former, must not call schedule().
2054 * Not all fields are meaningfull for all task types.
2056 * Returns 0 for SUCCESS, -999 for "no msg frames",
2057 * else other non-zero value returned.
2060 mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout, int sleepFlag)
2063 SCSITaskMgmt_t *pScsiTm;
2067 /* Return Fail to calling function if no message frames available.
2069 if ((mf = mpt_get_msg_frame(ScsiTaskCtx, hd->ioc)) == NULL) {
2070 dfailprintk((MYIOC_s_ERR_FMT "IssueTaskMgmt, no msg frames!!\n",
2075 dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt request @ %p\n",
2076 hd->ioc->name, mf));
2078 /* Format the Request
2080 pScsiTm = (SCSITaskMgmt_t *) mf;
2081 pScsiTm->TargetID = target;
2082 pScsiTm->Bus = channel;
2083 pScsiTm->ChainOffset = 0;
2084 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
2086 pScsiTm->Reserved = 0;
2087 pScsiTm->TaskType = type;
2088 pScsiTm->Reserved1 = 0;
2089 pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
2090 ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
2092 for (ii= 0; ii < 8; ii++) {
2093 pScsiTm->LUN[ii] = 0;
2095 pScsiTm->LUN[1] = lun;
2097 for (ii=0; ii < 7; ii++)
2098 pScsiTm->Reserved2[ii] = 0;
2100 pScsiTm->TaskMsgContext = ctx2abort;
2102 /* MPI v0.10 requires SCSITaskMgmt requests be sent via Doorbell/handshake
2103 mpt_put_msg_frame(hd->ioc->id, mf);
2104 * Save the MF pointer in case the request times out.
2107 hd->TMtimer.expires = jiffies + timeout;
2108 add_timer(&hd->TMtimer);
2110 dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt: ctx2abort (0x%08x) type=%d\n",
2111 hd->ioc->name, ctx2abort, type));
2113 DBG_DUMP_TM_REQUEST_FRAME((u32 *)pScsiTm);
2115 if ((retval = mpt_send_handshake_request(ScsiTaskCtx, hd->ioc,
2116 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, sleepFlag))
2118 dfailprintk((MYIOC_s_ERR_FMT "_send_handshake FAILED!"
2119 " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd, hd->ioc, mf));
2121 del_timer(&hd->TMtimer);
2122 mpt_free_msg_frame(hd->ioc, mf);
2128 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2130 * mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant
2131 * @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted
2133 * (linux scsi_host_template.eh_abort_handler routine)
2135 * Returns SUCCESS or FAILED.
2138 mptscsih_abort(struct scsi_cmnd * SCpnt)
2145 spinlock_t *host_lock = SCpnt->device->host->host_lock;
2147 /* If we can't locate our host adapter structure, return FAILED status.
2149 if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL) {
2150 SCpnt->result = DID_RESET << 16;
2151 SCpnt->scsi_done(SCpnt);
2152 dfailprintk((KERN_WARNING MYNAM ": mptscsih_abort: "
2153 "Can't locate host! (sc=%p)\n",
2159 if (hd->resetPending)
2162 printk(KERN_WARNING MYNAM ": %s: >> Attempting task abort! (sc=%p)\n",
2163 hd->ioc->name, SCpnt);
2165 if (hd->timeouts < -1)
2168 /* Find this command
2170 if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(SCpnt)) < 0) {
2171 /* Cmd not found in ScsiLookup.
2174 SCpnt->result = DID_RESET << 16;
2175 dtmprintk((KERN_WARNING MYNAM ": %s: mptscsih_abort: "
2176 "Command not in the active list! (sc=%p)\n",
2177 hd->ioc->name, SCpnt));
2181 /* Most important! Set TaskMsgContext to SCpnt's MsgContext!
2182 * (the IO to be ABORT'd)
2184 * NOTE: Since we do not byteswap MsgContext, we do not
2185 * swap it here either. It is an opaque cookie to
2186 * the controller, so it does not matter. -DaveM
2188 mf = MPT_INDEX_2_MFPTR(hd->ioc, scpnt_idx);
2189 ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
2191 hd->abortSCpnt = SCpnt;
2193 spin_unlock_irq(host_lock);
2194 if (mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
2195 SCpnt->device->channel, SCpnt->device->id, SCpnt->device->lun,
2196 ctx2abort, (HZ*2) /* 2 second timeout */,CAN_SLEEP)
2199 /* The TM request failed and the subsequent FW-reload failed!
2202 printk(MYIOC_s_WARN_FMT "Error issuing abort task! (sc=%p)\n",
2203 hd->ioc->name, SCpnt);
2205 /* We must clear our pending flag before clearing our state.
2208 hd->tmState = TM_STATE_NONE;
2210 spin_lock_irq(host_lock);
2212 /* Unmap the DMA buffers, if any. */
2213 if (SCpnt->use_sg) {
2214 pci_unmap_sg(ioc->pcidev, (struct scatterlist *) SCpnt->request_buffer,
2215 SCpnt->use_sg, SCpnt->sc_data_direction);
2216 } else if (SCpnt->request_bufflen) {
2217 pci_unmap_single(ioc->pcidev, SCpnt->SCp.dma_handle,
2218 SCpnt->request_bufflen, SCpnt->sc_data_direction);
2220 hd->ScsiLookup[scpnt_idx] = NULL;
2221 SCpnt->result = DID_RESET << 16;
2222 SCpnt->scsi_done(SCpnt); /* Issue the command callback */
2223 mptscsih_freeChainBuffers(ioc, scpnt_idx);
2224 mpt_free_msg_frame(ioc, mf);
2227 spin_lock_irq(host_lock);
2232 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2234 * mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant
2235 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
2237 * (linux scsi_host_template.eh_dev_reset_handler routine)
2239 * Returns SUCCESS or FAILED.
2242 mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
2245 spinlock_t *host_lock = SCpnt->device->host->host_lock;
2247 /* If we can't locate our host adapter structure, return FAILED status.
2249 if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
2250 dtmprintk((KERN_WARNING MYNAM ": mptscsih_dev_reset: "
2251 "Can't locate host! (sc=%p)\n",
2256 if (hd->resetPending)
2259 printk(KERN_WARNING MYNAM ": %s: >> Attempting target reset! (sc=%p)\n",
2260 hd->ioc->name, SCpnt);
2262 /* Supported for FC only.
2264 if (hd->ioc->bus_type == SCSI)
2267 spin_unlock_irq(host_lock);
2268 if (mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
2269 SCpnt->device->channel, SCpnt->device->id,
2270 0, 0, (HZ*5) /* 5 second timeout */, CAN_SLEEP)
2272 /* The TM request failed and the subsequent FW-reload failed!
2275 printk(MYIOC_s_WARN_FMT "Error processing TaskMgmt request (sc=%p)\n",
2276 hd->ioc->name, SCpnt);
2278 hd->tmState = TM_STATE_NONE;
2279 spin_lock_irq(host_lock);
2282 spin_lock_irq(host_lock);
2287 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2289 * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant
2290 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
2292 * (linux scsi_host_template.eh_bus_reset_handler routine)
2294 * Returns SUCCESS or FAILED.
2297 mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
2300 spinlock_t *host_lock = SCpnt->device->host->host_lock;
2302 /* If we can't locate our host adapter structure, return FAILED status.
2304 if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
2305 dtmprintk((KERN_WARNING MYNAM ": mptscsih_bus_reset: "
2306 "Can't locate host! (sc=%p)\n",
2311 printk(KERN_WARNING MYNAM ": %s: >> Attempting bus reset! (sc=%p)\n",
2312 hd->ioc->name, SCpnt);
2314 if (hd->timeouts < -1)
2317 /* We are now ready to execute the task management request. */
2318 spin_unlock_irq(host_lock);
2319 if (mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
2320 SCpnt->device->channel, 0, 0, 0, (HZ*5) /* 5 second timeout */, CAN_SLEEP)
2323 /* The TM request failed and the subsequent FW-reload failed!
2326 printk(MYIOC_s_WARN_FMT
2327 "Error processing TaskMgmt request (sc=%p)\n",
2328 hd->ioc->name, SCpnt);
2330 hd->tmState = TM_STATE_NONE;
2331 spin_lock_irq(host_lock);
2334 spin_lock_irq(host_lock);
2338 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2340 * mptscsih_host_reset - Perform a SCSI host adapter RESET!
2342 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
2344 * (linux scsi_host_template.eh_host_reset_handler routine)
2346 * Returns SUCCESS or FAILED.
2349 mptscsih_host_reset(struct scsi_cmnd *SCpnt)
2352 int status = SUCCESS;
2353 spinlock_t *host_lock = SCpnt->device->host->host_lock;
2355 /* If we can't locate the host to reset, then we failed. */
2356 if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
2357 dtmprintk( ( KERN_WARNING MYNAM ": mptscsih_host_reset: "
2358 "Can't locate host! (sc=%p)\n",
2363 printk(KERN_WARNING MYNAM ": %s: >> Attempting host reset! (sc=%p)\n",
2364 hd->ioc->name, SCpnt);
2366 /* If our attempts to reset the host failed, then return a failed
2367 * status. The host will be taken off line by the SCSI mid-layer.
2369 spin_unlock_irq(host_lock);
2370 if (mpt_HardResetHandler(hd->ioc, CAN_SLEEP) < 0){
2373 /* Make sure TM pending is cleared and TM state is set to
2377 hd->tmState = TM_STATE_NONE;
2379 spin_lock_irq(host_lock);
2382 dtmprintk( ( KERN_WARNING MYNAM ": mptscsih_host_reset: "
2384 (status == SUCCESS) ? "SUCCESS" : "FAILED" ) );
2389 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2391 * mptscsih_tm_pending_wait - wait for pending task management request to
2393 * @hd: Pointer to MPT host structure.
2395 * Returns {SUCCESS,FAILED}.
2398 mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd)
2400 unsigned long flags;
2401 int loop_count = 10 * 4; /* Wait 10 seconds */
2402 int status = FAILED;
2405 spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
2406 if (hd->tmState == TM_STATE_NONE) {
2407 hd->tmState = TM_STATE_IN_PROGRESS;
2409 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
2413 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
2415 } while (--loop_count);
2420 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2422 * mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver
2423 * @ioc: Pointer to MPT_ADAPTER structure
2424 * @mf: Pointer to SCSI task mgmt request frame
2425 * @mr: Pointer to SCSI task mgmt reply frame
2427 * This routine is called from mptbase.c::mpt_interrupt() at the completion
2428 * of any SCSI task management request.
2429 * This routine is registered with the MPT (base) driver at driver
2430 * load/init time via the mpt_register() API call.
2432 * Returns 1 indicating alloc'd request frame ptr should be freed.
2435 mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
2437 SCSITaskMgmtReply_t *pScsiTmReply;
2438 SCSITaskMgmt_t *pScsiTmReq;
2440 unsigned long flags;
2444 dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt completed (mf=%p,mr=%p)\n",
2445 ioc->name, mf, mr));
2447 /* Depending on the thread, a timer is activated for
2448 * the TM request. Delete this timer on completion of TM.
2449 * Decrement count of outstanding TM requests.
2451 hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
2453 del_timer(&hd->TMtimer);
2456 dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt Complete: NULL Scsi Host Ptr\n",
2462 dtmprintk((MYIOC_s_WARN_FMT "ERROR! TaskMgmt Reply: NULL Request %p\n",
2466 pScsiTmReply = (SCSITaskMgmtReply_t*)mr;
2467 pScsiTmReq = (SCSITaskMgmt_t*)mf;
2469 /* Figure out if this was ABORT_TASK, TARGET_RESET, or BUS_RESET! */
2470 tmType = pScsiTmReq->TaskType;
2472 dtmprintk((MYIOC_s_WARN_FMT " TaskType = %d, TerminationCount=%d\n",
2473 ioc->name, tmType, le32_to_cpu(pScsiTmReply->TerminationCount)));
2474 DBG_DUMP_TM_REPLY_FRAME((u32 *)pScsiTmReply);
2476 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
2477 dtmprintk((MYIOC_s_WARN_FMT " SCSI TaskMgmt (%d) IOCStatus=%04x IOCLogInfo=%08x\n",
2478 ioc->name, tmType, iocstatus, le32_to_cpu(pScsiTmReply->IOCLogInfo)));
2479 /* Error? (anything non-zero?) */
2482 /* clear flags and continue.
2484 if (tmType == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
2485 hd->abortSCpnt = NULL;
2487 /* If an internal command is present
2488 * or the TM failed - reload the FW.
2489 * FC FW may respond FAILED to an ABORT
2491 if (tmType == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
2493 (iocstatus == MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED)) {
2494 if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0) {
2495 printk((KERN_WARNING
2496 " Firmware Reload FAILED!!\n"));
2501 dtmprintk((MYIOC_s_WARN_FMT " TaskMgmt SUCCESS\n", ioc->name));
2503 hd->abortSCpnt = NULL;
2509 spin_lock_irqsave(&ioc->FreeQlock, flags);
2511 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
2512 hd->tmState = TM_STATE_NONE;
2517 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2519 * This is anyones guess quite frankly.
2522 mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
2523 sector_t capacity, int geom[])
2533 dummy = heads * sectors;
2534 cylinders = capacity;
2535 sector_div(cylinders,dummy);
2538 * Handle extended translation size for logical drives
2541 if ((ulong)capacity >= 0x200000) {
2544 dummy = heads * sectors;
2545 cylinders = capacity;
2546 sector_div(cylinders,dummy);
2552 geom[2] = cylinders;
2554 dprintk((KERN_NOTICE
2555 ": bios_param: Id=%i Lun=%i Channel=%i CHS=%i/%i/%i\n",
2556 sdev->id, sdev->lun,sdev->channel,(int)cylinders,heads,sectors));
2561 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2563 * OS entry point to allow host driver to alloc memory
2564 * for each scsi device. Called once per device the bus scan.
2565 * Return non-zero if allocation fails.
2566 * Init memory once per id (not LUN).
2569 mptscsih_slave_alloc(struct scsi_device *device)
2571 struct Scsi_Host *host = device->host;
2572 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
2574 uint target = device->id;
2579 if ((vdev = hd->Targets[target]) != NULL)
2582 vdev = kmalloc(sizeof(VirtDevice), GFP_KERNEL);
2584 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
2585 hd->ioc->name, sizeof(VirtDevice));
2589 memset(vdev, 0, sizeof(VirtDevice));
2590 vdev->tflags = MPT_TARGET_FLAGS_Q_YES;
2591 vdev->ioc_id = hd->ioc->id;
2592 vdev->target_id = device->id;
2593 vdev->bus_id = device->channel;
2594 vdev->raidVolume = 0;
2595 hd->Targets[device->id] = vdev;
2596 if (hd->ioc->bus_type == SCSI) {
2597 if (hd->ioc->spi_data.isRaid & (1 << device->id)) {
2598 vdev->raidVolume = 1;
2599 ddvtprintk((KERN_INFO
2600 "RAID Volume @ id %d\n", device->id));
2603 vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY;
2611 static int mptscsih_is_raid_volume(MPT_SCSI_HOST *hd, uint id)
2615 if (!hd->ioc->spi_data.isRaid || !hd->ioc->spi_data.pIocPg3)
2618 for (i = 0; i < hd->ioc->spi_data.pIocPg3->NumPhysDisks; i++) {
2619 if (id == hd->ioc->spi_data.pIocPg3->PhysDisk[i].PhysDiskID)
2627 * OS entry point to allow for host driver to free allocated memory
2628 * Called if no device present or device being unloaded
2631 mptscsih_slave_destroy(struct scsi_device *device)
2633 struct Scsi_Host *host = device->host;
2634 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
2636 uint target = device->id;
2637 uint lun = device->lun;
2642 mptscsih_search_running_cmds(hd, target, lun);
2644 vdev = hd->Targets[target];
2645 vdev->luns[0] &= ~(1 << lun);
2646 if (--vdev->num_luns)
2649 kfree(hd->Targets[target]);
2650 hd->Targets[target] = NULL;
2652 if (hd->ioc->bus_type == SCSI) {
2653 if (mptscsih_is_raid_volume(hd, target)) {
2654 hd->ioc->spi_data.forceDv |= MPT_SCSICFG_RELOAD_IOC_PG3;
2656 hd->ioc->spi_data.dvStatus[target] =
2657 MPT_SCSICFG_NEGOTIATE;
2659 if (!hd->negoNvram) {
2660 hd->ioc->spi_data.dvStatus[target] |=
2661 MPT_SCSICFG_DV_NOT_DONE;
2668 mptscsih_set_queue_depth(struct scsi_device *device, MPT_SCSI_HOST *hd,
2669 VirtDevice *pTarget, int qdepth)
2674 if (hd->ioc->bus_type == SCSI) {
2675 if (pTarget->tflags & MPT_TARGET_FLAGS_VALID_INQUIRY) {
2676 if (!(pTarget->tflags & MPT_TARGET_FLAGS_Q_YES))
2678 else if (((pTarget->inq_data[0] & 0x1f) == 0x00) &&
2679 (pTarget->minSyncFactor <= MPT_ULTRA160 ))
2680 max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
2682 max_depth = MPT_SCSI_CMD_PER_DEV_LOW;
2684 /* error case - No Inq. Data */
2688 max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
2690 if (qdepth > max_depth)
2695 tagged = MSG_SIMPLE_TAG;
2697 scsi_adjust_queue_depth(device, tagged, qdepth);
2702 * OS entry point to adjust the queue_depths on a per-device basis.
2703 * Called once per device the bus scan. Use it to force the queue_depth
2704 * member to 1 if a device does not support Q tags.
2705 * Return non-zero if fails.
2708 mptscsih_slave_configure(struct scsi_device *device)
2710 struct Scsi_Host *sh = device->host;
2711 VirtDevice *pTarget;
2712 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sh->hostdata;
2714 if ((hd == NULL) || (hd->Targets == NULL)) {
2718 dsprintk((MYIOC_s_INFO_FMT
2719 "device @ %p, id=%d, LUN=%d, channel=%d\n",
2720 hd->ioc->name, device, device->id, device->lun, device->channel));
2721 dsprintk((MYIOC_s_INFO_FMT
2722 "sdtr %d wdtr %d ppr %d inq length=%d\n",
2723 hd->ioc->name, device->sdtr, device->wdtr,
2724 device->ppr, device->inquiry_len));
2726 if (device->id > sh->max_id) {
2727 /* error case, should never happen */
2728 scsi_adjust_queue_depth(device, 0, 1);
2729 goto slave_configure_exit;
2732 pTarget = hd->Targets[device->id];
2734 if (pTarget == NULL) {
2735 /* Driver doesn't know about this device.
2736 * Kernel may generate a "Dummy Lun 0" which
2737 * may become a real Lun if a
2738 * "scsi add-single-device" command is executed
2739 * while the driver is active (hot-plug a
2740 * device). LSI Raid controllers need
2741 * queue_depth set to DEV_HIGH for this reason.
2743 scsi_adjust_queue_depth(device, MSG_SIMPLE_TAG,
2744 MPT_SCSI_CMD_PER_DEV_HIGH);
2745 goto slave_configure_exit;
2748 mptscsih_initTarget(hd, device->channel, device->id, device->lun,
2749 device->inquiry, device->inquiry_len );
2750 mptscsih_set_queue_depth(device, hd, pTarget, MPT_SCSI_CMD_PER_DEV_HIGH);
2752 dsprintk((MYIOC_s_INFO_FMT
2753 "Queue depth=%d, tflags=%x\n",
2754 hd->ioc->name, device->queue_depth, pTarget->tflags));
2756 dsprintk((MYIOC_s_INFO_FMT
2757 "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
2758 hd->ioc->name, pTarget->negoFlags, pTarget->maxOffset, pTarget->minSyncFactor));
2760 slave_configure_exit:
2762 dsprintk((MYIOC_s_INFO_FMT
2763 "tagged %d, simple %d, ordered %d\n",
2764 hd->ioc->name,device->tagged_supported, device->simple_tags,
2765 device->ordered_tags));
2771 mptscsih_store_queue_depth(struct device *dev, const char *buf, size_t count)
2774 struct scsi_device *sdev = to_scsi_device(dev);
2775 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) sdev->host->hostdata;
2776 VirtDevice *pTarget;
2778 depth = simple_strtoul(buf, NULL, 0);
2781 pTarget = hd->Targets[sdev->id];
2782 if (pTarget == NULL)
2784 mptscsih_set_queue_depth(sdev, (MPT_SCSI_HOST *) sdev->host->hostdata,
2789 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2791 * Private routines...
2794 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2795 /* Utility function to copy sense data from the scsi_cmnd buffer
2796 * to the FC and SCSI target structures.
2800 copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply)
2803 SCSIIORequest_t *pReq;
2804 u32 sense_count = le32_to_cpu(pScsiReply->SenseCount);
2807 /* Get target structure
2809 pReq = (SCSIIORequest_t *) mf;
2810 index = (int) pReq->TargetID;
2811 target = hd->Targets[index];
2817 /* Copy the sense received into the scsi command block. */
2818 req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
2819 sense_data = ((u8 *)hd->ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
2820 memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc));
2822 /* Log SMART data (asc = 0x5D, non-IM case only) if required.
2824 if ((hd->ioc->events) && (hd->ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {
2825 if ((sense_data[12] == 0x5D) && (target->raidVolume == 0)) {
2827 MPT_ADAPTER *ioc = hd->ioc;
2829 idx = ioc->eventContext % ioc->eventLogSize;
2830 ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE;
2831 ioc->events[idx].eventContext = ioc->eventContext;
2833 ioc->events[idx].data[0] = (pReq->LUN[1] << 24) ||
2834 (MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) ||
2835 (pReq->Bus << 8) || pReq->TargetID;
2837 ioc->events[idx].data[1] = (sense_data[13] << 8) || sense_data[12];
2839 ioc->eventContext++;
2843 dprintk((MYIOC_s_INFO_FMT "Hmmm... SenseData len=0! (?)\n",
2849 SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc)
2854 hd = (MPT_SCSI_HOST *) sc->device->host->hostdata;
2856 for (i = 0; i < hd->ioc->req_depth; i++) {
2857 if (hd->ScsiLookup[i] == sc) {
2865 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2867 mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
2870 unsigned long flags;
2872 dtmprintk((KERN_WARNING MYNAM
2873 ": IOC %s_reset routed to SCSI host driver!\n",
2874 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
2875 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
2877 /* If a FW reload request arrives after base installed but
2878 * before all scsi hosts have been attached, then an alt_ioc
2879 * may have a NULL sh pointer.
2881 if ((ioc->sh == NULL) || (ioc->sh->hostdata == NULL))
2884 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
2886 if (reset_phase == MPT_IOC_SETUP_RESET) {
2887 dtmprintk((MYIOC_s_WARN_FMT "Setup-Diag Reset\n", ioc->name));
2890 * 1. Set Hard Reset Pending Flag
2891 * All new commands go to doneQ
2893 hd->resetPending = 1;
2895 } else if (reset_phase == MPT_IOC_PRE_RESET) {
2896 dtmprintk((MYIOC_s_WARN_FMT "Pre-Diag Reset\n", ioc->name));
2898 /* 2. Flush running commands
2899 * Clean ScsiLookup (and associated memory)
2903 /* 2b. Reply to OS all known outstanding I/O commands.
2905 mptscsih_flush_running_cmds(hd);
2907 /* 2c. If there was an internal command that
2908 * has not completed, configuration or io request,
2909 * free these resources.
2912 del_timer(&hd->timer);
2913 mpt_free_msg_frame(ioc, hd->cmdPtr);
2916 /* 2d. If a task management has not completed,
2917 * free resources associated with this request.
2920 del_timer(&hd->TMtimer);
2921 mpt_free_msg_frame(ioc, hd->tmPtr);
2924 dtmprintk((MYIOC_s_WARN_FMT "Pre-Reset complete.\n", ioc->name));
2927 dtmprintk((MYIOC_s_WARN_FMT "Post-Diag Reset\n", ioc->name));
2929 /* Once a FW reload begins, all new OS commands are
2930 * redirected to the doneQ w/ a reset status.
2931 * Init all control structures.
2934 /* ScsiLookup initialization
2938 for (ii=0; ii < hd->ioc->req_depth; ii++)
2939 hd->ScsiLookup[ii] = NULL;
2942 /* 2. Chain Buffer initialization
2951 /* 4. Renegotiate to all devices, if SCSI
2953 if (ioc->bus_type == SCSI) {
2954 dnegoprintk(("writeSDP1: ALL_IDS USE_NVRAM\n"));
2955 mptscsih_writeSDP1(hd, 0, 0, MPT_SCSICFG_ALL_IDS | MPT_SCSICFG_USE_NVRAM);
2958 /* 5. Enable new commands to be posted
2960 spin_lock_irqsave(&ioc->FreeQlock, flags);
2962 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
2963 hd->resetPending = 0;
2964 hd->tmState = TM_STATE_NONE;
2966 /* 6. If there was an internal command,
2967 * wake this process up.
2971 * Wake up the original calling thread
2973 hd->pLocal = &hd->localReply;
2974 hd->pLocal->completion = MPT_SCANDV_DID_RESET;
2975 scandv_wait_done = 1;
2976 wake_up(&scandv_waitq);
2980 /* 7. Set flag to force DV and re-read IOC Page 3
2982 if (ioc->bus_type == SCSI) {
2983 ioc->spi_data.forceDv = MPT_SCSICFG_NEED_DV | MPT_SCSICFG_RELOAD_IOC_PG3;
2984 ddvtprintk(("Set reload IOC Pg3 Flag\n"));
2987 dtmprintk((MYIOC_s_WARN_FMT "Post-Reset complete.\n", ioc->name));
2991 return 1; /* currently means nothing really */
2994 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2996 mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
2999 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
3001 devtprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
3005 case MPI_EVENT_UNIT_ATTENTION: /* 03 */
3008 case MPI_EVENT_IOC_BUS_RESET: /* 04 */
3009 case MPI_EVENT_EXT_BUS_RESET: /* 05 */
3012 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
3013 if (hd && (ioc->bus_type == SCSI) && (hd->soft_resets < -1))
3017 case MPI_EVENT_LOGOUT: /* 09 */
3022 * CHECKME! Don't think we need to do
3023 * anything for these, but...
3025 case MPI_EVENT_RESCAN: /* 06 */
3026 case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
3027 case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
3029 * CHECKME! Falling thru...
3033 case MPI_EVENT_INTEGRATED_RAID: /* 0B */
3034 #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
3035 /* negoNvram set to 0 if DV enabled and to USE_NVRAM if
3036 * if DV disabled. Need to check for target mode.
3040 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
3042 if (hd && (ioc->bus_type == SCSI) && (hd->negoNvram == 0)) {
3044 Ioc3PhysDisk_t *pPDisk;
3049 reason = (le32_to_cpu(pEvReply->Data[0]) & 0x00FF0000) >> 16;
3050 if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) {
3051 /* New or replaced disk.
3052 * Set DV flag and schedule DV.
3054 pSpi = &ioc->spi_data;
3055 physDiskNum = (le32_to_cpu(pEvReply->Data[0]) & 0xFF000000) >> 24;
3056 ddvtprintk(("DV requested for phys disk id %d\n", physDiskNum));
3057 if (pSpi->pIocPg3) {
3058 pPDisk = pSpi->pIocPg3->PhysDisk;
3059 numPDisk =pSpi->pIocPg3->NumPhysDisks;
3062 if (physDiskNum == pPDisk->PhysDiskNum) {
3063 pSpi->dvStatus[pPDisk->PhysDiskID] = (MPT_SCSICFG_NEED_DV | MPT_SCSICFG_DV_NOT_DONE);
3064 pSpi->forceDv = MPT_SCSICFG_NEED_DV;
3065 ddvtprintk(("NEED_DV set for phys disk id %d\n", pPDisk->PhysDiskID));
3072 if (numPDisk == 0) {
3073 /* The physical disk that needs DV was not found
3074 * in the stored IOC Page 3. The driver must reload
3075 * this page. DV routine will set the NEED_DV flag for
3076 * all phys disks that have DV_NOT_DONE set.
3078 pSpi->forceDv = MPT_SCSICFG_NEED_DV | MPT_SCSICFG_RELOAD_IOC_PG3;
3079 ddvtprintk(("phys disk %d not found. Setting reload IOC Pg3 Flag\n", physDiskNum));
3086 #if defined(MPT_DEBUG_DV) || defined(MPT_DEBUG_DV_TINY)
3087 printk("Raid Event RF: ");
3089 u32 *m = (u32 *)pEvReply;
3091 int n = (int)pEvReply->MsgLength;
3092 for (ii=6; ii < n; ii++)
3093 printk(" %08x", le32_to_cpu(m[ii]));
3099 case MPI_EVENT_NONE: /* 00 */
3100 case MPI_EVENT_LOG_DATA: /* 01 */
3101 case MPI_EVENT_STATE_CHANGE: /* 02 */
3102 case MPI_EVENT_EVENT_CHANGE: /* 0A */
3104 dprintk((KERN_INFO " Ignoring event (=%02Xh)\n", event));
3108 return 1; /* currently means nothing really */
3111 static struct device_attribute mptscsih_queue_depth_attr = {
3113 .name = "queue_depth",
3116 .store = mptscsih_store_queue_depth,
3119 static struct device_attribute *mptscsih_dev_attrs[] = {
3120 &mptscsih_queue_depth_attr,
3124 static struct scsi_host_template driver_template = {
3125 .proc_name = "mptscsih",
3126 .proc_info = mptscsih_proc_info,
3127 .name = "MPT SCSI Host",
3128 .info = mptscsih_info,
3129 .queuecommand = mptscsih_qcmd,
3130 .slave_alloc = mptscsih_slave_alloc,
3131 .slave_configure = mptscsih_slave_configure,
3132 .slave_destroy = mptscsih_slave_destroy,
3133 .eh_abort_handler = mptscsih_abort,
3134 .eh_device_reset_handler = mptscsih_dev_reset,
3135 .eh_bus_reset_handler = mptscsih_bus_reset,
3136 .eh_host_reset_handler = mptscsih_host_reset,
3137 .bios_param = mptscsih_bios_param,
3138 .can_queue = MPT_SCSI_CAN_QUEUE,
3140 .sg_tablesize = MPT_SCSI_SG_DEPTH,
3141 .max_sectors = 8192,
3143 .use_clustering = ENABLE_CLUSTERING,
3144 .sdev_attrs = mptscsih_dev_attrs,
3147 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3149 * mptscsih_initTarget - Target, LUN alloc/free functionality.
3150 * @hd: Pointer to MPT_SCSI_HOST structure
3151 * @bus_id: Bus number (?)
3152 * @target_id: SCSI target id
3154 * @data: Pointer to data
3155 * @dlen: Number of INQUIRY bytes
3157 * NOTE: It's only SAFE to call this routine if data points to
3158 * sane & valid STANDARD INQUIRY data!
3160 * Allocate and initialize memory for this target.
3161 * Save inquiry data.
3165 mptscsih_initTarget(MPT_SCSI_HOST *hd, int bus_id, int target_id, u8 lun, char *data, int dlen)
3167 int indexed_lun, lun_index;
3172 dinitprintk((MYIOC_s_INFO_FMT "initTarget bus=%d id=%d lun=%d hd=%p\n",
3173 hd->ioc->name, bus_id, target_id, lun, hd));
3175 /* Is LUN supported? If so, upper 2 bits will be 0
3176 * in first byte of inquiry data.
3181 if ((vdev = hd->Targets[target_id]) == NULL) {
3185 lun_index = (lun >> 5); /* 32 luns per lun_index */
3186 indexed_lun = (lun % 32);
3187 vdev->luns[lun_index] |= (1 << indexed_lun);
3189 if (hd->ioc->bus_type == SCSI) {
3190 if ((data[0] == TYPE_PROCESSOR) && (hd->ioc->spi_data.Saf_Te)) {
3191 /* Treat all Processors as SAF-TE if
3192 * command line option is set */
3193 vdev->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
3194 mptscsih_writeIOCPage4(hd, target_id, bus_id);
3195 }else if ((data[0] == TYPE_PROCESSOR) &&
3196 !(vdev->tflags & MPT_TARGET_FLAGS_SAF_TE_ISSUED )) {
3198 vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY;
3199 if ( data[44] == 'S' &&
3205 vdev->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
3206 mptscsih_writeIOCPage4(hd, target_id, bus_id);
3210 if (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_INQUIRY)) {
3212 memcpy (vdev->inq_data, data, 8);
3214 memcpy (vdev->inq_data, data, dlen);
3217 /* If have not done DV, set the DV flag.
3219 pSpi = &hd->ioc->spi_data;
3220 if ((data[0] == TYPE_TAPE) || (data[0] == TYPE_PROCESSOR)) {
3221 if (pSpi->dvStatus[target_id] & MPT_SCSICFG_DV_NOT_DONE)
3222 pSpi->dvStatus[target_id] |= MPT_SCSICFG_NEED_DV;
3225 vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY;
3228 data_56 = 0x0F; /* Default to full capabilities if Inq data length is < 57 */
3230 if ( (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_56))) {
3231 /* Update the target capabilities
3234 vdev->tflags |= MPT_TARGET_FLAGS_VALID_56;
3237 mptscsih_setTargetNegoParms(hd, vdev, data_56);
3239 /* Initial Inquiry may not request enough data bytes to
3240 * obtain byte 57. DV will; if target doesn't return
3241 * at least 57 bytes, data[56] will be zero. */
3243 if ( (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_56))) {
3244 /* Update the target capabilities
3247 vdev->tflags |= MPT_TARGET_FLAGS_VALID_56;
3248 mptscsih_setTargetNegoParms(hd, vdev, data_56);
3255 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3257 * Update the target negotiation parameters based on the
3258 * the Inquiry data, adapter capabilities, and NVRAM settings.
3262 mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtDevice *target, char byte56)
3264 ScsiCfgData *pspi_data = &hd->ioc->spi_data;
3265 int id = (int) target->target_id;
3269 u8 width = MPT_NARROW;
3270 u8 factor = MPT_ASYNC;
3272 u8 version, nfactor;
3275 target->negoFlags = pspi_data->noQas;
3277 /* noQas == 0 => device supports QAS. Need byte 56 of Inq to determine
3278 * support. If available, default QAS to off and allow enabling.
3279 * If not available, default QAS to on, turn off for non-disks.
3282 /* Set flags based on Inquiry data
3284 version = target->inq_data[2] & 0x07;
3287 factor = MPT_ULTRA2;
3288 offset = pspi_data->maxSyncOffset;
3289 target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
3291 if (target->inq_data[7] & 0x20) {
3295 if (target->inq_data[7] & 0x10) {
3296 factor = pspi_data->minSyncFactor;
3297 if (target->tflags & MPT_TARGET_FLAGS_VALID_56) {
3298 /* bits 2 & 3 show Clocking support */
3299 if ((byte56 & 0x0C) == 0)
3300 factor = MPT_ULTRA2;
3302 if ((byte56 & 0x03) == 0)
3303 factor = MPT_ULTRA160;
3305 factor = MPT_ULTRA320;
3308 ddvtprintk((KERN_INFO "Enabling QAS due to byte56=%02x on id=%d!\n", byte56, id));
3311 if (target->inq_data[0] == TYPE_TAPE) {
3313 target->negoFlags |= MPT_TAPE_NEGO_IDP;
3318 ddvtprintk((KERN_INFO "Enabling QAS on id=%d due to ~TARGET_FLAGS_VALID_56!\n", id));
3322 offset = pspi_data->maxSyncOffset;
3324 /* If RAID, never disable QAS
3325 * else if non RAID, do not disable
3326 * QAS if bit 1 is set
3327 * bit 1 QAS support, non-raid only
3330 if (target->raidVolume == 1) {
3339 if ( (target->inq_data[7] & 0x02) == 0) {
3340 target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
3343 /* Update tflags based on NVRAM settings. (SCSI only)
3345 if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) {
3346 nvram = pspi_data->nvram[id];
3347 nfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8;
3350 width = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
3353 /* Ensure factor is set to the
3354 * maximum of: adapter, nvram, inquiry
3357 if (nfactor < pspi_data->minSyncFactor )
3358 nfactor = pspi_data->minSyncFactor;
3360 factor = max(factor, nfactor);
3361 if (factor == MPT_ASYNC)
3372 /* Make sure data is consistent
3374 if ((!width) && (factor < MPT_ULTRA2)) {
3375 factor = MPT_ULTRA2;
3378 /* Save the data to the target structure.
3380 target->minSyncFactor = factor;
3381 target->maxOffset = offset;
3382 target->maxWidth = width;
3384 target->tflags |= MPT_TARGET_FLAGS_VALID_NEGO;
3386 /* Disable unused features.
3389 target->negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
3392 target->negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
3394 if ( factor > MPT_ULTRA320 )
3397 /* GEM, processor WORKAROUND
3399 if ((target->inq_data[0] == TYPE_PROCESSOR) || (target->inq_data[0] > 0x08)) {
3400 target->negoFlags |= (MPT_TARGET_NO_NEGO_WIDE | MPT_TARGET_NO_NEGO_SYNC);
3401 pspi_data->dvStatus[id] |= MPT_SCSICFG_BLK_NEGO;
3403 if (noQas && (pspi_data->noQas == 0)) {
3404 pspi_data->noQas |= MPT_TARGET_NO_NEGO_QAS;
3405 target->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
3407 /* Disable QAS in a mixed configuration case
3410 ddvtprintk((KERN_INFO "Disabling QAS due to noQas=%02x on id=%d!\n", noQas, id));
3411 for (ii = 0; ii < id; ii++) {
3412 if ( (vdev = hd->Targets[ii]) ) {
3413 vdev->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
3414 mptscsih_writeSDP1(hd, 0, ii, vdev->negoFlags);
3420 /* Write SDP1 on this I/O to this target */
3421 if (pspi_data->dvStatus[id] & MPT_SCSICFG_NEGOTIATE) {
3422 ddvtprintk((KERN_INFO "MPT_SCSICFG_NEGOTIATE on id=%d!\n", id));
3423 mptscsih_writeSDP1(hd, 0, id, hd->negoNvram);
3424 pspi_data->dvStatus[id] &= ~MPT_SCSICFG_NEGOTIATE;
3425 } else if (pspi_data->dvStatus[id] & MPT_SCSICFG_BLK_NEGO) {
3426 ddvtprintk((KERN_INFO "MPT_SCSICFG_BLK_NEGO on id=%d!\n", id));
3427 mptscsih_writeSDP1(hd, 0, id, MPT_SCSICFG_BLK_NEGO);
3428 pspi_data->dvStatus[id] &= ~MPT_SCSICFG_BLK_NEGO;
3432 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3433 /* If DV disabled (negoNvram set to USE_NVARM) or if not LUN 0, return.
3434 * Else set the NEED_DV flag after Read Capacity Issued (disks)
3435 * or Mode Sense (cdroms).
3437 * Tapes, initTarget will set this flag on completion of Inquiry command.
3438 * Called only if DV_NOT_DONE flag is set
3440 static void mptscsih_set_dvflags(MPT_SCSI_HOST *hd, SCSIIORequest_t *pReq)
3445 ddvtprintk((" set_dvflags: id=%d lun=%d negoNvram=%x cmd=%x\n",
3446 pReq->TargetID, pReq->LUN[1], hd->negoNvram, pReq->CDB[0]));
3448 if ((pReq->LUN[1] != 0) || (hd->negoNvram != 0))
3453 if ((cmd == READ_CAPACITY) || (cmd == MODE_SENSE)) {
3454 pSpi = &hd->ioc->spi_data;
3455 if ((pSpi->isRaid & (1 << pReq->TargetID)) && pSpi->pIocPg3) {
3456 /* Set NEED_DV for all hidden disks
3458 Ioc3PhysDisk_t *pPDisk = pSpi->pIocPg3->PhysDisk;
3459 int numPDisk = pSpi->pIocPg3->NumPhysDisks;
3462 pSpi->dvStatus[pPDisk->PhysDiskID] |= MPT_SCSICFG_NEED_DV;
3463 ddvtprintk(("NEED_DV set for phys disk id %d\n", pPDisk->PhysDiskID));
3468 pSpi->dvStatus[pReq->TargetID] |= MPT_SCSICFG_NEED_DV;
3469 ddvtprintk(("NEED_DV set for visible disk id %d\n", pReq->TargetID));
3473 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3475 * If no Target, bus reset on 1st I/O. Set the flag to
3476 * prevent any future negotiations to this device.
3478 static void mptscsih_no_negotiate(MPT_SCSI_HOST *hd, int target_id)
3481 if ((hd->Targets) && (hd->Targets[target_id] == NULL))
3482 hd->ioc->spi_data.dvStatus[target_id] |= MPT_SCSICFG_BLK_NEGO;
3487 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3489 * SCSI Config Page functionality ...
3491 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3492 /* mptscsih_setDevicePage1Flags - add Requested and Configuration fields flags
3493 * based on width, factor and offset parameters.
3495 * @factor: sync factor
3496 * @offset: sync offset
3497 * @requestedPtr: pointer to requested values (updated)
3498 * @configurationPtr: pointer to configuration values (updated)
3499 * @flags: flags to block WDTR or SDTR negotiation
3503 * Remark: Called by writeSDP1 and _dv_params
3506 mptscsih_setDevicePage1Flags (u8 width, u8 factor, u8 offset, int *requestedPtr, int *configurationPtr, u8 flags)
3508 u8 nowide = flags & MPT_TARGET_NO_NEGO_WIDE;
3509 u8 nosync = flags & MPT_TARGET_NO_NEGO_SYNC;
3511 *configurationPtr = 0;
3512 *requestedPtr = width ? MPI_SCSIDEVPAGE1_RP_WIDE : 0;
3513 *requestedPtr |= (offset << 16) | (factor << 8);
3515 if (width && offset && !nowide && !nosync) {
3516 if (factor < MPT_ULTRA160) {
3517 *requestedPtr |= (MPI_SCSIDEVPAGE1_RP_IU + MPI_SCSIDEVPAGE1_RP_DT);
3518 if ((flags & MPT_TARGET_NO_NEGO_QAS) == 0)
3519 *requestedPtr |= MPI_SCSIDEVPAGE1_RP_QAS;
3520 if (flags & MPT_TAPE_NEGO_IDP)
3521 *requestedPtr |= 0x08000000;
3522 } else if (factor < MPT_ULTRA2) {
3523 *requestedPtr |= MPI_SCSIDEVPAGE1_RP_DT;
3528 *configurationPtr |= MPI_SCSIDEVPAGE1_CONF_WDTR_DISALLOWED;
3531 *configurationPtr |= MPI_SCSIDEVPAGE1_CONF_SDTR_DISALLOWED;
3536 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3537 /* mptscsih_writeSDP1 - write SCSI Device Page 1
3538 * @hd: Pointer to a SCSI Host Strucutre
3539 * @portnum: IOC port number
3540 * @target_id: writeSDP1 for single ID
3541 * @flags: MPT_SCSICFG_ALL_IDS, MPT_SCSICFG_USE_NVRAM, MPT_SCSICFG_BLK_NEGO
3543 * Return: -EFAULT if read of config page header fails
3546 * Remark: If a target has been found, the settings from the
3547 * target structure are used, else the device is set
3550 * Remark: Called during init and after a FW reload.
3551 * Remark: We do not wait for a return, write pages sequentially.
3554 mptscsih_writeSDP1(MPT_SCSI_HOST *hd, int portnum, int target_id, int flags)
3556 MPT_ADAPTER *ioc = hd->ioc;
3558 SCSIDevicePage1_t *pData;
3559 VirtDevice *pTarget;
3564 u32 requested, configuration, flagsLength;
3566 int id = 0, maxid = 0;
3572 u8 maxwidth, maxoffset, maxfactor;
3574 if (ioc->spi_data.sdp1length == 0)
3577 if (flags & MPT_SCSICFG_ALL_IDS) {
3579 maxid = ioc->sh->max_id - 1;
3580 } else if (ioc->sh) {
3582 maxid = min_t(int, id, ioc->sh->max_id - 1);
3585 for (; id <= maxid; id++) {
3587 if (id == ioc->pfacts[portnum].PortSCSIID)
3590 /* Use NVRAM to get adapter and target maximums
3591 * Data over-riden by target structure information, if present
3593 maxwidth = ioc->spi_data.maxBusWidth;
3594 maxoffset = ioc->spi_data.maxSyncOffset;
3595 maxfactor = ioc->spi_data.minSyncFactor;
3596 if (ioc->spi_data.nvram && (ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) {
3597 nvram = ioc->spi_data.nvram[id];
3600 maxwidth = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
3602 if (maxoffset > 0) {
3603 maxfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8;
3604 if (maxfactor == 0) {
3606 maxfactor = MPT_ASYNC;
3608 } else if (maxfactor < ioc->spi_data.minSyncFactor) {
3609 maxfactor = ioc->spi_data.minSyncFactor;
3612 maxfactor = MPT_ASYNC;
3615 /* Set the negotiation flags.
3617 negoFlags = ioc->spi_data.noQas;
3619 negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
3622 negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
3624 if (flags & MPT_SCSICFG_USE_NVRAM) {
3633 //negoFlags = MPT_TARGET_NO_NEGO_SYNC;
3636 /* If id is not a raid volume, get the updated
3637 * transmission settings from the target structure.
3639 if (hd->Targets && (pTarget = hd->Targets[id]) && !pTarget->raidVolume) {
3640 width = pTarget->maxWidth;
3641 factor = pTarget->minSyncFactor;
3642 offset = pTarget->maxOffset;
3643 negoFlags = pTarget->negoFlags;
3646 #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
3647 /* Force to async and narrow if DV has not been executed
3650 if ((hd->ioc->spi_data.dvStatus[id] & MPT_SCSICFG_DV_NOT_DONE) != 0) {
3657 if (flags & MPT_SCSICFG_BLK_NEGO)
3658 negoFlags = MPT_TARGET_NO_NEGO_WIDE | MPT_TARGET_NO_NEGO_SYNC;
3660 mptscsih_setDevicePage1Flags(width, factor, offset,
3661 &requested, &configuration, negoFlags);
3662 dnegoprintk(("writeSDP1: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n",
3663 target_id, width, factor, offset, negoFlags, requested, configuration));
3665 /* Get a MF for this command.
3667 if ((mf = mpt_get_msg_frame(ScsiDoneCtx, ioc)) == NULL) {
3668 dprintk((MYIOC_s_WARN_FMT "write SDP1: no msg frames!\n",
3673 ddvprintk((MYIOC_s_INFO_FMT "WriteSDP1 (mf=%p, id=%d, req=0x%x, cfg=0x%x)\n",
3674 hd->ioc->name, mf, id, requested, configuration));
3677 /* Set the request and the data pointers.
3678 * Request takes: 36 bytes (32 bit SGE)
3679 * SCSI Device Page 1 requires 16 bytes
3680 * 40 + 16 <= size of SCSI IO Request = 56 bytes
3681 * and MF size >= 64 bytes.
3682 * Place data at end of MF.
3684 pReq = (Config_t *)mf;
3686 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
3687 frameOffset = ioc->req_sz - sizeof(SCSIDevicePage1_t);
3689 pData = (SCSIDevicePage1_t *)((u8 *) mf + frameOffset);
3690 dataDma = ioc->req_frames_dma + (req_idx * ioc->req_sz) + frameOffset;
3692 /* Complete the request frame (same for all requests).
3694 pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
3696 pReq->ChainOffset = 0;
3697 pReq->Function = MPI_FUNCTION_CONFIG;
3698 pReq->ExtPageLength = 0;
3699 pReq->ExtPageType = 0;
3701 for (ii=0; ii < 8; ii++) {
3702 pReq->Reserved2[ii] = 0;
3704 pReq->Header.PageVersion = ioc->spi_data.sdp1version;
3705 pReq->Header.PageLength = ioc->spi_data.sdp1length;
3706 pReq->Header.PageNumber = 1;
3707 pReq->Header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
3708 pReq->PageAddress = cpu_to_le32(id | (bus << 8 ));
3710 /* Add a SGE to the config request.
3712 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE | ioc->spi_data.sdp1length * 4;
3714 mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
3716 /* Set up the common data portion
3718 pData->Header.PageVersion = pReq->Header.PageVersion;
3719 pData->Header.PageLength = pReq->Header.PageLength;
3720 pData->Header.PageNumber = pReq->Header.PageNumber;
3721 pData->Header.PageType = pReq->Header.PageType;
3722 pData->RequestedParameters = cpu_to_le32(requested);
3723 pData->Reserved = 0;
3724 pData->Configuration = cpu_to_le32(configuration);
3726 dprintk((MYIOC_s_INFO_FMT
3727 "write SDP1: id %d pgaddr 0x%x req 0x%x config 0x%x\n",
3728 ioc->name, id, (id | (bus<<8)),
3729 requested, configuration));
3731 mpt_put_msg_frame(ScsiDoneCtx, ioc, mf);
3737 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3738 /* mptscsih_writeIOCPage4 - write IOC Page 4
3739 * @hd: Pointer to a SCSI Host Structure
3740 * @target_id: write IOC Page4 for this ID & Bus
3742 * Return: -EAGAIN if unable to obtain a Message Frame
3745 * Remark: We do not wait for a return, write pages sequentially.
3748 mptscsih_writeIOCPage4(MPT_SCSI_HOST *hd, int target_id, int bus)
3750 MPT_ADAPTER *ioc = hd->ioc;
3752 IOCPage4_t *IOCPage4Ptr;
3760 /* Get a MF for this command.
3762 if ((mf = mpt_get_msg_frame(ScsiDoneCtx, ioc)) == NULL) {
3763 dprintk((MYIOC_s_WARN_FMT "writeIOCPage4 : no msg frames!\n",
3768 /* Set the request and the data pointers.
3769 * Place data at end of MF.
3771 pReq = (Config_t *)mf;
3773 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
3774 frameOffset = ioc->req_sz - sizeof(IOCPage4_t);
3776 /* Complete the request frame (same for all requests).
3778 pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
3780 pReq->ChainOffset = 0;
3781 pReq->Function = MPI_FUNCTION_CONFIG;
3782 pReq->ExtPageLength = 0;
3783 pReq->ExtPageType = 0;
3785 for (ii=0; ii < 8; ii++) {
3786 pReq->Reserved2[ii] = 0;
3789 IOCPage4Ptr = ioc->spi_data.pIocPg4;
3790 dataDma = ioc->spi_data.IocPg4_dma;
3791 ii = IOCPage4Ptr->ActiveSEP++;
3792 IOCPage4Ptr->SEP[ii].SEPTargetID = target_id;
3793 IOCPage4Ptr->SEP[ii].SEPBus = bus;
3794 pReq->Header = IOCPage4Ptr->Header;
3795 pReq->PageAddress = cpu_to_le32(target_id | (bus << 8 ));
3797 /* Add a SGE to the config request.
3799 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE |
3800 (IOCPage4Ptr->Header.PageLength + ii) * 4;
3802 mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
3804 dinitprintk((MYIOC_s_INFO_FMT
3805 "writeIOCPage4: MaxSEP=%d ActiveSEP=%d id=%d bus=%d\n",
3806 ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, target_id, bus));
3808 mpt_put_msg_frame(ScsiDoneCtx, ioc, mf);
3813 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3814 /* mptscsih_taskmgmt_timeout - Call back for timeout on a
3815 * task management request.
3816 * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
3819 static void mptscsih_taskmgmt_timeout(unsigned long data)
3821 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) data;
3823 dtmprintk((KERN_WARNING MYNAM ": %s: mptscsih_taskmgmt_timeout: "
3824 "TM request timed out!\n", hd->ioc->name));
3826 /* Delete the timer that triggered this callback.
3827 * Remark: del_timer checks to make sure timer is active
3830 del_timer(&hd->TMtimer);
3832 /* Call the reset handler. Already had a TM request
3833 * timeout - so issue a diagnostic reset
3835 INIT_WORK(&mptscsih_rstTask, mptscsih_schedule_reset, (void *)hd);
3836 schedule_work(&mptscsih_rstTask);
3840 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3841 /* mptscsih_schedule_reset - Call back for timeout on a
3842 * task management request.
3843 * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
3847 mptscsih_schedule_reset(void *arg)
3850 hd = (MPT_SCSI_HOST *) arg;
3852 if (mpt_HardResetHandler(hd->ioc, CAN_SLEEP) < 0) {
3853 printk((KERN_WARNING " Firmware Reload FAILED!!\n"));
3855 /* Because we have reset the IOC, no TM requests can be
3856 * pending. So let's make sure the tmPending flag is reset.
3858 dtmprintk((KERN_WARNING MYNAM
3859 ": %s: mptscsih_taskmgmt_timeout\n",
3867 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3869 * Bus Scan and Domain Validation functionality ...
3872 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3874 * mptscsih_scandv_complete - Scan and DV callback routine registered
3875 * to Fustion MPT (base) driver.
3877 * @ioc: Pointer to MPT_ADAPTER structure
3878 * @mf: Pointer to original MPT request frame
3879 * @mr: Pointer to MPT reply frame (NULL if TurboReply)
3881 * This routine is called from mpt.c::mpt_interrupt() at the completion
3882 * of any SCSI IO request.
3883 * This routine is registered with the Fusion MPT (base) driver at driver
3884 * load/init time via the mpt_register() API call.
3886 * Returns 1 indicating alloc'd request frame ptr should be freed.
3888 * Remark: Sets a completion code and (possibly) saves sense data
3889 * in the IOC member localReply structure.
3890 * Used ONLY for DV and other internal commands.
3893 mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
3896 SCSIIORequest_t *pReq;
3901 (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
3902 printk(MYIOC_s_ERR_FMT
3903 "ScanDvComplete, %s req frame ptr! (=%p)\n",
3904 ioc->name, mf?"BAD":"NULL", (void *) mf);
3908 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
3909 del_timer(&hd->timer);
3910 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
3911 hd->ScsiLookup[req_idx] = NULL;
3912 pReq = (SCSIIORequest_t *) mf;
3914 if (mf != hd->cmdPtr) {
3915 printk(MYIOC_s_WARN_FMT "ScanDvComplete (mf=%p, cmdPtr=%p, idx=%d)\n",
3916 hd->ioc->name, (void *)mf, (void *) hd->cmdPtr, req_idx);
3920 ddvprintk((MYIOC_s_INFO_FMT "ScanDvComplete (mf=%p,mr=%p,idx=%d)\n",
3921 hd->ioc->name, mf, mr, req_idx));
3923 hd->pLocal = &hd->localReply;
3924 hd->pLocal->scsiStatus = 0;
3926 /* If target struct exists, clear sense valid flag.
3929 completionCode = MPT_SCANDV_GOOD;
3931 SCSIIOReply_t *pReply;
3935 pReply = (SCSIIOReply_t *) mr;
3937 status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
3938 scsi_status = pReply->SCSIStatus;
3940 ddvtprintk((KERN_NOTICE " IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh, IOCLogInfo=%08xh\n",
3941 status, pReply->SCSIState, scsi_status,
3942 le32_to_cpu(pReply->IOCLogInfo)));
3946 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
3947 completionCode = MPT_SCANDV_SELECTION_TIMEOUT;
3950 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
3951 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
3952 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
3953 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
3954 completionCode = MPT_SCANDV_DID_RESET;
3957 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
3958 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
3959 case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
3960 if (pReply->Function == MPI_FUNCTION_CONFIG) {
3961 ConfigReply_t *pr = (ConfigReply_t *)mr;
3962 completionCode = MPT_SCANDV_GOOD;
3963 hd->pLocal->header.PageVersion = pr->Header.PageVersion;
3964 hd->pLocal->header.PageLength = pr->Header.PageLength;
3965 hd->pLocal->header.PageNumber = pr->Header.PageNumber;
3966 hd->pLocal->header.PageType = pr->Header.PageType;
3968 } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
3969 /* If the RAID Volume request is successful,
3970 * return GOOD, else indicate that
3971 * some type of error occurred.
3973 MpiRaidActionReply_t *pr = (MpiRaidActionReply_t *)mr;
3974 if (pr->ActionStatus == MPI_RAID_ACTION_ASTATUS_SUCCESS)
3975 completionCode = MPT_SCANDV_GOOD;
3977 completionCode = MPT_SCANDV_SOME_ERROR;
3979 } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
3983 /* save sense data in global structure
3985 completionCode = MPT_SCANDV_SENSE;
3986 hd->pLocal->scsiStatus = scsi_status;
3987 sense_data = ((u8 *)hd->ioc->sense_buf_pool +
3988 (req_idx * MPT_SENSE_BUFFER_ALLOC));
3990 sz = min_t(int, pReq->SenseBufferLength,
3991 SCSI_STD_SENSE_BYTES);
3992 memcpy(hd->pLocal->sense, sense_data, sz);
3994 ddvprintk((KERN_NOTICE " Check Condition, sense ptr %p\n",
3996 } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
3997 if (pReq->CDB[0] == INQUIRY)
3998 completionCode = MPT_SCANDV_ISSUE_SENSE;
4000 completionCode = MPT_SCANDV_DID_RESET;
4002 else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
4003 completionCode = MPT_SCANDV_DID_RESET;
4004 else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
4005 completionCode = MPT_SCANDV_DID_RESET;
4007 completionCode = MPT_SCANDV_GOOD;
4008 hd->pLocal->scsiStatus = scsi_status;
4012 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
4013 if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
4014 completionCode = MPT_SCANDV_DID_RESET;
4016 completionCode = MPT_SCANDV_SOME_ERROR;
4020 completionCode = MPT_SCANDV_SOME_ERROR;
4023 } /* switch(status) */
4025 ddvtprintk((KERN_NOTICE " completionCode set to %08xh\n",
4027 } /* end of address reply case */
4029 hd->pLocal->completion = completionCode;
4031 /* MF and RF are freed in mpt_interrupt
4034 /* Free Chain buffers (will never chain) in scan or dv */
4035 //mptscsih_freeChainBuffers(ioc, req_idx);
4038 * Wake up the original calling thread
4040 scandv_wait_done = 1;
4041 wake_up(&scandv_waitq);
4046 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4047 /* mptscsih_timer_expired - Call back for timer process.
4048 * Used only for dv functionality.
4049 * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
4052 static void mptscsih_timer_expired(unsigned long data)
4054 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) data;
4056 ddvprintk((MYIOC_s_WARN_FMT "Timer Expired! Cmd %p\n", hd->ioc->name, hd->cmdPtr));
4059 MPIHeader_t *cmd = (MPIHeader_t *)hd->cmdPtr;
4061 if (cmd->Function == MPI_FUNCTION_SCSI_IO_REQUEST) {
4062 /* Desire to issue a task management request here.
4063 * TM requests MUST be single threaded.
4064 * If old eh code and no TM current, issue request.
4065 * If new eh code, do nothing. Wait for OS cmd timeout
4068 ddvtprintk((MYIOC_s_NOTE_FMT "DV Cmd Timeout: NoOp\n", hd->ioc->name));
4070 /* Perform a FW reload */
4071 if (mpt_HardResetHandler(hd->ioc, NO_SLEEP) < 0) {
4072 printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", hd->ioc->name);
4076 /* This should NEVER happen */
4077 printk(MYIOC_s_WARN_FMT "Null cmdPtr!!!!\n", hd->ioc->name);
4080 /* No more processing.
4081 * TM call will generate an interrupt for SCSI TM Management.
4082 * The FW will reply to all outstanding commands, callback will finish cleanup.
4083 * Hard reset clean-up will free all resources.
4085 ddvprintk((MYIOC_s_WARN_FMT "Timer Expired Complete!\n", hd->ioc->name));
4090 #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
4091 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4092 /* mptscsih_do_raid - Format and Issue a RAID volume request message.
4093 * @hd: Pointer to scsi host structure
4094 * @action: What do be done.
4095 * @id: Logical target id.
4096 * @bus: Target locations bus.
4098 * Returns: < 0 on a fatal error
4101 * Remark: Wait to return until reply processed by the ISR.
4104 mptscsih_do_raid(MPT_SCSI_HOST *hd, u8 action, INTERNAL_CMD *io)
4106 MpiRaidActionRequest_t *pReq;
4110 in_isr = in_interrupt();
4112 dprintk((MYIOC_s_WARN_FMT "Internal raid request not allowed in ISR context!\n",
4117 /* Get and Populate a free Frame
4119 if ((mf = mpt_get_msg_frame(ScsiScanDvCtx, hd->ioc)) == NULL) {
4120 ddvprintk((MYIOC_s_WARN_FMT "_do_raid: no msg frames!\n",
4124 pReq = (MpiRaidActionRequest_t *)mf;
4125 pReq->Action = action;
4126 pReq->Reserved1 = 0;
4127 pReq->ChainOffset = 0;
4128 pReq->Function = MPI_FUNCTION_RAID_ACTION;
4129 pReq->VolumeID = io->id;
4130 pReq->VolumeBus = io->bus;
4131 pReq->PhysDiskNum = io->physDiskNum;
4133 pReq->Reserved2 = 0;
4134 pReq->ActionDataWord = 0; /* Reserved for this action */
4135 //pReq->ActionDataSGE = 0;
4137 mpt_add_sge((char *)&pReq->ActionDataSGE,
4138 MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
4140 ddvprintk((MYIOC_s_INFO_FMT "RAID Volume action %x id %d\n",
4141 hd->ioc->name, action, io->id));
4144 hd->timer.expires = jiffies + HZ*10; /* 10 second timeout */
4145 scandv_wait_done = 0;
4147 /* Save cmd pointer, for resource free if timeout or
4152 add_timer(&hd->timer);
4153 mpt_put_msg_frame(ScsiScanDvCtx, hd->ioc, mf);
4154 wait_event(scandv_waitq, scandv_wait_done);
4156 if ((hd->pLocal == NULL) || (hd->pLocal->completion != MPT_SCANDV_GOOD))
4161 #endif /* ~MPTSCSIH_ENABLE_DOMAIN_VALIDATION */
4163 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4165 * mptscsih_do_cmd - Do internal command.
4166 * @hd: MPT_SCSI_HOST pointer
4167 * @io: INTERNAL_CMD pointer.
4169 * Issue the specified internally generated command and do command
4170 * specific cleanup. For bus scan / DV only.
4171 * NOTES: If command is Inquiry and status is good,
4172 * initialize a target structure, save the data
4174 * Remark: Single threaded access only.
4177 * < 0 if an illegal command or no resources
4181 * > 0 if command complete but some type of completion error.
4184 mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
4187 SCSIIORequest_t *pScsiReq;
4188 SCSIIORequest_t ReqCopy;
4189 int my_idx, ii, dir;
4193 char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
4196 in_isr = in_interrupt();
4198 dprintk((MYIOC_s_WARN_FMT "Internal SCSI IO request not allowed in ISR context!\n",
4204 /* Set command specific information
4209 dir = MPI_SCSIIO_CONTROL_READ;
4215 case TEST_UNIT_READY:
4217 dir = MPI_SCSIIO_CONTROL_READ;
4223 dir = MPI_SCSIIO_CONTROL_READ;
4225 CDB[4] = 1; /*Spin up the disk */
4233 dir = MPI_SCSIIO_CONTROL_READ;
4239 dir = MPI_SCSIIO_CONTROL_READ;
4241 if (io->flags & MPT_ICFLAG_ECHO) {
4247 if (io->flags & MPT_ICFLAG_BUF_CAP) {
4250 CDB[6] = (io->size >> 16) & 0xFF;
4251 CDB[7] = (io->size >> 8) & 0xFF;
4252 CDB[8] = io->size & 0xFF;
4258 dir = MPI_SCSIIO_CONTROL_WRITE;
4260 if (io->flags & MPT_ICFLAG_ECHO) {
4265 CDB[6] = (io->size >> 16) & 0xFF;
4266 CDB[7] = (io->size >> 8) & 0xFF;
4267 CDB[8] = io->size & 0xFF;
4273 dir = MPI_SCSIIO_CONTROL_READ;
4280 dir = MPI_SCSIIO_CONTROL_READ;
4285 case SYNCHRONIZE_CACHE:
4287 dir = MPI_SCSIIO_CONTROL_READ;
4289 // CDB[1] = 0x02; /* set immediate bit */
4298 /* Get and Populate a free Frame
4300 if ((mf = mpt_get_msg_frame(ScsiScanDvCtx, hd->ioc)) == NULL) {
4301 ddvprintk((MYIOC_s_WARN_FMT "No msg frames!\n",
4306 pScsiReq = (SCSIIORequest_t *) mf;
4308 /* Get the request index */
4309 my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
4310 ADD_INDEX_LOG(my_idx); /* for debug */
4312 if (io->flags & MPT_ICFLAG_PHYS_DISK) {
4313 pScsiReq->TargetID = io->physDiskNum;
4315 pScsiReq->ChainOffset = 0;
4316 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
4318 pScsiReq->TargetID = io->id;
4319 pScsiReq->Bus = io->bus;
4320 pScsiReq->ChainOffset = 0;
4321 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
4324 pScsiReq->CDBLength = cmdLen;
4325 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
4327 pScsiReq->Reserved = 0;
4329 pScsiReq->MsgFlags = mpt_msg_flags();
4330 /* MsgContext set in mpt_get_msg_fram call */
4332 for (ii=0; ii < 8; ii++)
4333 pScsiReq->LUN[ii] = 0;
4334 pScsiReq->LUN[1] = io->lun;
4336 if (io->flags & MPT_ICFLAG_TAGGED_CMD)
4337 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);
4339 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
4341 if (cmd == REQUEST_SENSE) {
4342 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
4343 ddvprintk((MYIOC_s_INFO_FMT "Untagged! 0x%2x\n",
4344 hd->ioc->name, cmd));
4347 for (ii=0; ii < 16; ii++)
4348 pScsiReq->CDB[ii] = CDB[ii];
4350 pScsiReq->DataLength = cpu_to_le32(io->size);
4351 pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma
4352 + (my_idx * MPT_SENSE_BUFFER_ALLOC));
4354 ddvprintk((MYIOC_s_INFO_FMT "Sending Command 0x%x for (%d:%d:%d)\n",
4355 hd->ioc->name, cmd, io->bus, io->id, io->lun));
4357 if (dir == MPI_SCSIIO_CONTROL_READ) {
4358 mpt_add_sge((char *) &pScsiReq->SGL,
4359 MPT_SGE_FLAGS_SSIMPLE_READ | io->size,
4362 mpt_add_sge((char *) &pScsiReq->SGL,
4363 MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size,
4367 /* The ISR will free the request frame, but we need
4368 * the information to initialize the target. Duplicate.
4370 memcpy(&ReqCopy, pScsiReq, sizeof(SCSIIORequest_t));
4372 /* Issue this command after:
4375 * Wait until the reply has been received
4376 * ScsiScanDvCtx callback function will
4378 * set scandv_wait_done and call wake_up
4381 hd->timer.expires = jiffies + HZ*cmdTimeout;
4382 scandv_wait_done = 0;
4384 /* Save cmd pointer, for resource free if timeout or
4389 add_timer(&hd->timer);
4390 mpt_put_msg_frame(ScsiScanDvCtx, hd->ioc, mf);
4391 wait_event(scandv_waitq, scandv_wait_done);
4394 rc = hd->pLocal->completion;
4395 hd->pLocal->skip = 0;
4397 /* Always set fatal error codes in some cases.
4399 if (rc == MPT_SCANDV_SELECTION_TIMEOUT)
4401 else if (rc == MPT_SCANDV_SOME_ERROR)
4405 /* This should never happen. */
4406 ddvprintk((MYIOC_s_INFO_FMT "_do_cmd: Null pLocal!!!\n",
4413 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4415 * mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks.
4416 * @hd: Pointer to MPT_SCSI_HOST structure
4417 * @portnum: IOC port number
4419 * Uses the ISR, but with special processing.
4420 * MUST be single-threaded.
4422 * Return: 0 on completion
4425 mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, int portnum)
4427 MPT_ADAPTER *ioc= hd->ioc;
4428 VirtDevice *pTarget;
4429 SCSIDevicePage1_t *pcfg1Data = NULL;
4432 dma_addr_t cfg1_dma_addr = -1;
4433 ConfigPageHeader_t header1;
4437 int indexed_lun, lun_index;
4438 int hostId = ioc->pfacts[portnum].PortSCSIID;
4440 int requested, configuration, data;
4444 max_id = ioc->sh->max_id - 1;
4446 /* Following parameters will not change
4449 iocmd.cmd = SYNCHRONIZE_CACHE;
4451 iocmd.physDiskNum = -1;
4453 iocmd.data_dma = -1;
4455 iocmd.rsvd = iocmd.rsvd2 = 0;
4459 if (hd->Targets == NULL)
4467 /* Write SDP1 for all SCSI devices
4468 * Alloc memory and set up config buffer
4470 if (ioc->bus_type == SCSI) {
4471 if (ioc->spi_data.sdp1length > 0) {
4472 pcfg1Data = (SCSIDevicePage1_t *)pci_alloc_consistent(ioc->pcidev,
4473 ioc->spi_data.sdp1length * 4, &cfg1_dma_addr);
4475 if (pcfg1Data != NULL) {
4477 header1.PageVersion = ioc->spi_data.sdp1version;
4478 header1.PageLength = ioc->spi_data.sdp1length;
4479 header1.PageNumber = 1;
4480 header1.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4482 cfg.physAddr = cfg1_dma_addr;
4483 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
4490 /* loop through all devices on this port
4492 while (bus < MPT_MAX_BUS) {
4495 pTarget = hd->Targets[(int)id];
4499 /* Set the negotiation flags */
4500 if (pTarget && (pTarget = hd->Targets[id]) && !pTarget->raidVolume) {
4501 flags = pTarget->negoFlags;
4503 flags = hd->ioc->spi_data.noQas;
4504 if (hd->ioc->spi_data.nvram && (hd->ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) {
4505 data = hd->ioc->spi_data.nvram[id];
4507 if (data & MPT_NVRAM_WIDE_DISABLE)
4508 flags |= MPT_TARGET_NO_NEGO_WIDE;
4510 factor = (data & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;
4511 if ((factor == 0) || (factor == MPT_ASYNC))
4512 flags |= MPT_TARGET_NO_NEGO_SYNC;
4516 /* Force to async, narrow */
4517 mptscsih_setDevicePage1Flags(0, MPT_ASYNC, 0, &requested,
4518 &configuration, flags);
4519 dnegoprintk(("syncronize cache: id=%d width=0 factor=MPT_ASYNC "
4520 "offset=0 negoFlags=%x request=%x config=%x\n",
4521 id, flags, requested, configuration));
4522 pcfg1Data->RequestedParameters = le32_to_cpu(requested);
4523 pcfg1Data->Reserved = 0;
4524 pcfg1Data->Configuration = le32_to_cpu(configuration);
4525 cfg.pageAddr = (bus<<8) | id;
4526 mpt_config(hd->ioc, &cfg);
4529 /* If target Ptr NULL or if this target is NOT a disk, skip.
4531 if ((pTarget) && (pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)){
4532 for (lun=0; lun <= MPT_LAST_LUN; lun++) {
4533 /* If LUN present, issue the command
4535 lun_index = (lun >> 5); /* 32 luns per lun_index */
4536 indexed_lun = (lun % 32);
4537 if (pTarget->luns[lun_index] & (1<<indexed_lun)) {
4539 (void) mptscsih_do_cmd(hd, &iocmd);
4544 /* get next relevant device */
4557 pci_free_consistent(ioc->pcidev, header1.PageLength * 4, pcfg1Data, cfg1_dma_addr);
4563 #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
4564 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4566 * mptscsih_domainValidation - Top level handler for domain validation.
4567 * @hd: Pointer to MPT_SCSI_HOST structure.
4569 * Uses the ISR, but with special processing.
4570 * Called from schedule, should not be in interrupt mode.
4571 * While thread alive, do dv for all devices needing dv
4576 mptscsih_domainValidation(void *arg)
4580 unsigned long flags;
4581 int id, maxid, dvStatus, did;
4584 spin_lock_irqsave(&dvtaskQ_lock, flags);
4586 if (dvtaskQ_release) {
4588 spin_unlock_irqrestore(&dvtaskQ_lock, flags);
4591 spin_unlock_irqrestore(&dvtaskQ_lock, flags);
4593 /* For this ioc, loop through all devices and do dv to each device.
4594 * When complete with this ioc, search through the ioc list, and
4595 * for each scsi ioc found, do dv for all devices. Exit when no
4601 list_for_each_entry(ioc, &ioc_list, list) {
4602 spin_lock_irqsave(&dvtaskQ_lock, flags);
4603 if (dvtaskQ_release) {
4605 spin_unlock_irqrestore(&dvtaskQ_lock, flags);
4608 spin_unlock_irqrestore(&dvtaskQ_lock, flags);
4612 /* DV only to SCSI adapters */
4613 if (ioc->bus_type != SCSI)
4616 /* Make sure everything looks ok */
4617 if (ioc->sh == NULL)
4620 hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
4624 if ((ioc->spi_data.forceDv & MPT_SCSICFG_RELOAD_IOC_PG3) != 0) {
4625 mpt_read_ioc_pg_3(ioc);
4626 if (ioc->spi_data.pIocPg3) {
4627 Ioc3PhysDisk_t *pPDisk = ioc->spi_data.pIocPg3->PhysDisk;
4628 int numPDisk = ioc->spi_data.pIocPg3->NumPhysDisks;
4631 if (ioc->spi_data.dvStatus[pPDisk->PhysDiskID] & MPT_SCSICFG_DV_NOT_DONE)
4632 ioc->spi_data.dvStatus[pPDisk->PhysDiskID] |= MPT_SCSICFG_NEED_DV;
4638 ioc->spi_data.forceDv &= ~MPT_SCSICFG_RELOAD_IOC_PG3;
4641 maxid = min_t(int, ioc->sh->max_id, MPT_MAX_SCSI_DEVICES);
4643 for (id = 0; id < maxid; id++) {
4644 spin_lock_irqsave(&dvtaskQ_lock, flags);
4645 if (dvtaskQ_release) {
4647 spin_unlock_irqrestore(&dvtaskQ_lock, flags);
4650 spin_unlock_irqrestore(&dvtaskQ_lock, flags);
4651 dvStatus = hd->ioc->spi_data.dvStatus[id];
4653 if (dvStatus & MPT_SCSICFG_NEED_DV) {
4655 hd->ioc->spi_data.dvStatus[id] |= MPT_SCSICFG_DV_PENDING;
4656 hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_NEED_DV;
4660 /* If hidden phys disk, block IO's to all
4662 * else, process normally
4664 isPhysDisk = mptscsih_is_phys_disk(ioc, id);
4666 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
4667 if (hd->ioc->spi_data.isRaid & (1 << ii)) {
4668 hd->ioc->spi_data.dvStatus[ii] |= MPT_SCSICFG_DV_PENDING;
4673 if (mptscsih_doDv(hd, 0, id) == 1) {
4674 /* Untagged device was busy, try again
4676 hd->ioc->spi_data.dvStatus[id] |= MPT_SCSICFG_NEED_DV;
4677 hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_DV_PENDING;
4679 /* DV is complete. Clear flags.
4681 hd->ioc->spi_data.dvStatus[id] &= ~(MPT_SCSICFG_DV_NOT_DONE | MPT_SCSICFG_DV_PENDING);
4685 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
4686 if (hd->ioc->spi_data.isRaid & (1 << ii)) {
4687 hd->ioc->spi_data.dvStatus[ii] &= ~MPT_SCSICFG_DV_PENDING;
4692 if (hd->ioc->spi_data.noQas)
4693 mptscsih_qas_check(hd, id);
4699 spin_lock_irqsave(&dvtaskQ_lock, flags);
4701 spin_unlock_irqrestore(&dvtaskQ_lock, flags);
4706 /* Search IOC page 3 to determine if this is hidden physical disk
4708 static int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id)
4710 if (ioc->spi_data.pIocPg3) {
4711 Ioc3PhysDisk_t *pPDisk = ioc->spi_data.pIocPg3->PhysDisk;
4712 int numPDisk = ioc->spi_data.pIocPg3->NumPhysDisks;
4715 if (pPDisk->PhysDiskID == id) {
4725 /* Write SDP1 if no QAS has been enabled
4727 static void mptscsih_qas_check(MPT_SCSI_HOST *hd, int id)
4729 VirtDevice *pTarget;
4732 if (hd->Targets == NULL)
4735 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
4739 if ((hd->ioc->spi_data.dvStatus[ii] & MPT_SCSICFG_DV_NOT_DONE) != 0)
4742 pTarget = hd->Targets[ii];
4744 if ((pTarget != NULL) && (!pTarget->raidVolume)) {
4745 if ((pTarget->negoFlags & hd->ioc->spi_data.noQas) == 0) {
4746 pTarget->negoFlags |= hd->ioc->spi_data.noQas;
4747 dnegoprintk(("writeSDP1: id=%d flags=0\n", id));
4748 mptscsih_writeSDP1(hd, 0, ii, 0);
4751 if (mptscsih_is_phys_disk(hd->ioc, ii) == 1) {
4752 dnegoprintk(("writeSDP1: id=%d SCSICFG_USE_NVRAM\n", id));
4753 mptscsih_writeSDP1(hd, 0, ii, MPT_SCSICFG_USE_NVRAM);
4762 #define MPT_GET_NVRAM_VALS 0x01
4763 #define MPT_UPDATE_MAX 0x02
4764 #define MPT_SET_MAX 0x04
4765 #define MPT_SET_MIN 0x08
4766 #define MPT_FALLBACK 0x10
4767 #define MPT_SAVE 0x20
4769 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4771 * mptscsih_doDv - Perform domain validation to a target.
4772 * @hd: Pointer to MPT_SCSI_HOST structure.
4773 * @portnum: IOC port number.
4774 * @target: Physical ID of this target
4776 * Uses the ISR, but with special processing.
4777 * MUST be single-threaded.
4778 * Test will exit if target is at async & narrow.
4783 mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
4785 MPT_ADAPTER *ioc = hd->ioc;
4786 VirtDevice *pTarget;
4787 SCSIDevicePage1_t *pcfg1Data;
4788 SCSIDevicePage0_t *pcfg0Data;
4792 dma_addr_t dvbuf_dma = -1;
4793 dma_addr_t buf1_dma = -1;
4794 dma_addr_t buf2_dma = -1;
4795 dma_addr_t cfg1_dma_addr = -1;
4796 dma_addr_t cfg0_dma_addr = -1;
4797 ConfigPageHeader_t header1;
4798 ConfigPageHeader_t header0;
4805 int dataBufSize = 0;
4806 int echoBufSize = 0;
4811 int nfactor = MPT_ULTRA320;
4813 char doFallback = 0;
4818 if (ioc->spi_data.sdp1length == 0)
4821 if (ioc->spi_data.sdp0length == 0)
4824 /* If multiple buses are used, require that the initiator
4825 * id be the same on all buses.
4827 if (id == ioc->pfacts[0].PortSCSIID)
4831 bus = (u8) bus_number;
4832 ddvtprintk((MYIOC_s_NOTE_FMT
4833 "DV started: bus=%d, id=%d dv @ %p\n",
4834 ioc->name, bus, id, &dv));
4836 /* Prep DV structure
4838 memset (&dv, 0, sizeof(DVPARAMETERS));
4841 /* Populate tmax with the current maximum
4842 * transfer parameters for this target.
4843 * Exit if narrow and async.
4845 dv.cmd = MPT_GET_NVRAM_VALS;
4846 mptscsih_dv_parms(hd, &dv, NULL);
4848 /* Prep SCSI IO structure
4854 iocmd.physDiskNum = -1;
4855 iocmd.rsvd = iocmd.rsvd2 = 0;
4857 pTarget = hd->Targets[id];
4859 /* Use tagged commands if possible.
4862 if (pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)
4863 iocmd.flags |= MPT_ICFLAG_TAGGED_CMD;
4865 if (hd->ioc->facts.FWVersion.Word < 0x01000600)
4868 if ((hd->ioc->facts.FWVersion.Word >= 0x01010000) &&
4869 (hd->ioc->facts.FWVersion.Word < 0x01010B00))
4874 /* Prep cfg structure
4876 cfg.pageAddr = (bus<<8) | id;
4881 header0.PageVersion = ioc->spi_data.sdp0version;
4882 header0.PageLength = ioc->spi_data.sdp0length;
4883 header0.PageNumber = 0;
4884 header0.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4888 header1.PageVersion = ioc->spi_data.sdp1version;
4889 header1.PageLength = ioc->spi_data.sdp1length;
4890 header1.PageNumber = 1;
4891 header1.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4893 if (header0.PageLength & 1)
4894 dv_alloc = (header0.PageLength * 4) + 4;
4896 dv_alloc += (2048 + (header1.PageLength * 4));
4898 pDvBuf = pci_alloc_consistent(ioc->pcidev, dv_alloc, &dvbuf_dma);
4903 pbuf1 = (u8 *)pDvBuf;
4904 buf1_dma = dvbuf_dma;
4907 pbuf2 = (u8 *) (pDvBuf + sz);
4908 buf2_dma = dvbuf_dma + sz;
4911 pcfg0Data = (SCSIDevicePage0_t *) (pDvBuf + sz);
4912 cfg0_dma_addr = dvbuf_dma + sz;
4913 sz += header0.PageLength * 4;
4917 if (header0.PageLength & 1)
4920 pcfg1Data = (SCSIDevicePage1_t *) (pDvBuf + sz);
4921 cfg1_dma_addr = dvbuf_dma + sz;
4923 /* Skip this ID? Set cfg.hdr to force config page write
4926 ScsiCfgData *pspi_data = &hd->ioc->spi_data;
4927 if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) {
4928 /* Set the factor from nvram */
4929 nfactor = (pspi_data->nvram[id] & MPT_NVRAM_SYNC_MASK) >> 8;
4930 if (nfactor < pspi_data->minSyncFactor )
4931 nfactor = pspi_data->minSyncFactor;
4933 if (!(pspi_data->nvram[id] & MPT_NVRAM_ID_SCAN_ENABLE) ||
4934 (pspi_data->PortFlags == MPI_SCSIPORTPAGE2_PORT_FLAGS_OFF_DV) ) {
4936 ddvprintk((MYIOC_s_NOTE_FMT "DV Skipped: bus, id, lun (%d, %d, %d)\n",
4937 ioc->name, bus, id, lun));
4939 dv.cmd = MPT_SET_MAX;
4940 mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
4943 /* Save the final negotiated settings to
4944 * SCSI device page 1.
4946 cfg.physAddr = cfg1_dma_addr;
4947 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
4949 mpt_config(hd->ioc, &cfg);
4955 /* Finish iocmd inititialization - hidden or visible disk? */
4956 if (ioc->spi_data.pIocPg3) {
4957 /* Search IOC page 3 for matching id
4959 Ioc3PhysDisk_t *pPDisk = ioc->spi_data.pIocPg3->PhysDisk;
4960 int numPDisk = ioc->spi_data.pIocPg3->NumPhysDisks;
4963 if (pPDisk->PhysDiskID == id) {
4965 iocmd.flags |= MPT_ICFLAG_PHYS_DISK;
4966 iocmd.physDiskNum = pPDisk->PhysDiskNum;
4970 if (mptscsih_do_raid(hd, MPI_RAID_ACTION_QUIESCE_PHYS_IO, &iocmd) < 0) {
4971 ddvprintk((MYIOC_s_ERR_FMT "RAID Queisce FAILED!\n", ioc->name));
4981 /* RAID Volume ID's may double for a physical device. If RAID but
4982 * not a physical ID as well, skip DV.
4984 if ((hd->ioc->spi_data.isRaid & (1 << id)) && !(iocmd.flags & MPT_ICFLAG_PHYS_DISK))
4989 * Async & Narrow - Inquiry
4990 * Async & Narrow - Inquiry
4991 * Maximum transfer rate - Inquiry
4993 * If compare, test complete.
4994 * If miscompare and first pass, repeat
4995 * If miscompare and not first pass, fall back and repeat
4999 sz = SCSI_MAX_INQUIRY_BYTES;
5000 rc = MPT_SCANDV_GOOD;
5002 ddvprintk((MYIOC_s_NOTE_FMT "DV: Start Basic test on id=%d\n", ioc->name, id));
5004 dv.cmd = MPT_SET_MIN;
5005 mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
5008 cfg.physAddr = cfg1_dma_addr;
5009 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
5011 if (mpt_config(hd->ioc, &cfg) != 0)
5014 /* Wide - narrow - wide workaround case
5016 if ((rc == MPT_SCANDV_ISSUE_SENSE) && dv.max.width) {
5017 /* Send an untagged command to reset disk Qs corrupted
5018 * when a parity error occurs on a Request Sense.
5020 if ((hd->ioc->facts.FWVersion.Word >= 0x01000600) ||
5021 ((hd->ioc->facts.FWVersion.Word >= 0x01010000) &&
5022 (hd->ioc->facts.FWVersion.Word < 0x01010B00)) ) {
5024 iocmd.cmd = REQUEST_SENSE;
5025 iocmd.data_dma = buf1_dma;
5028 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5031 if (hd->pLocal == NULL)
5033 rc = hd->pLocal->completion;
5034 if ((rc == MPT_SCANDV_GOOD) || (rc == MPT_SCANDV_SENSE)) {
5044 iocmd.cmd = INQUIRY;
5045 iocmd.data_dma = buf1_dma;
5048 memset(pbuf1, 0x00, sz);
5049 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5052 if (hd->pLocal == NULL)
5054 rc = hd->pLocal->completion;
5055 if (rc == MPT_SCANDV_GOOD) {
5056 if (hd->pLocal->scsiStatus == SAM_STAT_BUSY) {
5057 if ((iocmd.flags & MPT_ICFLAG_TAGGED_CMD) == 0)
5064 } else if (rc == MPT_SCANDV_SENSE) {
5067 /* If first command doesn't complete
5068 * with a good status or with a check condition,
5075 /* Reset the size for disks
5077 inq0 = (*pbuf1) & 0x1F;
5078 if ((inq0 == 0) && pTarget && !pTarget->raidVolume) {
5083 /* Another GEM workaround. Check peripheral device type,
5084 * if PROCESSOR, quit DV.
5086 if (inq0 == TYPE_PROCESSOR) {
5087 mptscsih_initTarget(hd,
5099 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5103 if ((pTarget->maxWidth == 1) && (pTarget->maxOffset) && (nfactor < 0x0A)
5104 && (pTarget->minSyncFactor > 0x09)) {
5105 if ((pbuf1[56] & 0x04) == 0)
5107 else if ((pbuf1[56] & 0x01) == 1) {
5108 pTarget->minSyncFactor =
5109 nfactor > MPT_ULTRA320 ? nfactor : MPT_ULTRA320;
5111 pTarget->minSyncFactor =
5112 nfactor > MPT_ULTRA160 ? nfactor : MPT_ULTRA160;
5115 dv.max.factor = pTarget->minSyncFactor;
5117 if ((pbuf1[56] & 0x02) == 0) {
5118 pTarget->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
5119 hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS;
5120 ddvprintk((MYIOC_s_NOTE_FMT
5121 "DV: Start Basic noQas on id=%d due to pbuf1[56]=%x\n",
5122 ioc->name, id, pbuf1[56]));
5128 dv.cmd = MPT_FALLBACK;
5130 dv.cmd = MPT_SET_MAX;
5132 mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
5133 if (mpt_config(hd->ioc, &cfg) != 0)
5136 if ((!dv.now.width) && (!dv.now.offset))
5139 iocmd.cmd = INQUIRY;
5140 iocmd.data_dma = buf2_dma;
5143 memset(pbuf2, 0x00, sz);
5144 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5146 else if (hd->pLocal == NULL)
5149 /* Save the return code.
5150 * If this is the first pass,
5151 * read SCSI Device Page 0
5152 * and update the target max parameters.
5154 rc = hd->pLocal->completion;
5156 if (rc == MPT_SCANDV_GOOD) {
5162 cfg.physAddr = cfg0_dma_addr;
5163 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5166 if (mpt_config(hd->ioc, &cfg) != 0)
5169 sdp0_info = le32_to_cpu(pcfg0Data->Information) & 0x0E;
5170 sdp0_nego = (le32_to_cpu(pcfg0Data->NegotiatedParameters) & 0xFF00 ) >> 8;
5172 /* Quantum and Fujitsu workarounds.
5173 * Quantum: PPR U320 -> PPR reply with Ultra2 and wide
5174 * Fujitsu: PPR U320 -> Msg Reject and Ultra2 and wide
5175 * Resetart with a request for U160.
5177 if ((dv.now.factor == MPT_ULTRA320) && (sdp0_nego == MPT_ULTRA2)) {
5180 dv.cmd = MPT_UPDATE_MAX;
5181 mptscsih_dv_parms(hd, &dv, (void *)pcfg0Data);
5182 /* Update the SCSI device page 1 area
5184 pcfg1Data->RequestedParameters = pcfg0Data->NegotiatedParameters;
5189 /* Quantum workaround. Restart this test will the fallback
5192 if (doFallback == 0) {
5193 if (memcmp(pbuf1, pbuf2, sz) != 0) {
5197 ddvprintk((MYIOC_s_NOTE_FMT
5198 "DV:Inquiry compared id=%d, calling initTarget\n", ioc->name, id));
5199 hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_DV_NOT_DONE;
5200 mptscsih_initTarget(hd,
5206 break; /* test complete */
5211 } else if (rc == MPT_SCANDV_ISSUE_SENSE)
5212 doFallback = 1; /* set fallback flag */
5213 else if ((rc == MPT_SCANDV_DID_RESET) ||
5214 (rc == MPT_SCANDV_SENSE) ||
5215 (rc == MPT_SCANDV_FALLBACK))
5216 doFallback = 1; /* set fallback flag */
5223 ddvprintk((MYIOC_s_NOTE_FMT "DV: Basic test on id=%d completed OK.\n", ioc->name, id));
5225 if (driver_setup.dv == 0)
5228 inq0 = (*pbuf1) & 0x1F;
5230 /* Continue only for disks
5235 if ( ioc->spi_data.PortFlags == MPI_SCSIPORTPAGE2_PORT_FLAGS_BASIC_DV_ONLY )
5238 /* Start the Enhanced Test.
5239 * 0) issue TUR to clear out check conditions
5240 * 1) read capacity of echo (regular) buffer
5242 * 3) do write-read-compare data pattern test
5244 * 5) update nego parms to target struct
5247 cfg.physAddr = cfg1_dma_addr;
5248 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
5251 iocmd.cmd = TEST_UNIT_READY;
5252 iocmd.data_dma = -1;
5257 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5260 if (hd->pLocal == NULL)
5263 rc = hd->pLocal->completion;
5264 if (rc == MPT_SCANDV_GOOD)
5266 else if (rc == MPT_SCANDV_SENSE) {
5267 u8 skey = hd->pLocal->sense[2] & 0x0F;
5268 u8 asc = hd->pLocal->sense[12];
5269 u8 ascq = hd->pLocal->sense[13];
5270 ddvprintk((MYIOC_s_INFO_FMT
5271 "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n",
5272 ioc->name, skey, asc, ascq));
5274 if (skey == UNIT_ATTENTION)
5275 notDone++; /* repeat */
5276 else if ((skey == NOT_READY) &&
5277 (asc == 0x04)&&(ascq == 0x01)) {
5278 /* wait then repeat */
5281 } else if ((skey == NOT_READY) && (asc == 0x3A)) {
5282 /* no medium, try read test anyway */
5285 /* All other errors are fatal.
5287 ddvprintk((MYIOC_s_INFO_FMT "DV: fatal error.",
5295 iocmd.cmd = READ_BUFFER;
5296 iocmd.data_dma = buf1_dma;
5299 iocmd.flags |= MPT_ICFLAG_BUF_CAP;
5303 for (patt = 0; patt < 2; patt++) {
5305 iocmd.flags |= MPT_ICFLAG_ECHO;
5307 iocmd.flags &= ~MPT_ICFLAG_ECHO;
5313 /* If not ready after 8 trials,
5314 * give up on this device.
5319 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5321 else if (hd->pLocal == NULL)
5324 rc = hd->pLocal->completion;
5325 ddvprintk(("ReadBuffer Comp Code %d", rc));
5326 ddvprintk((" buff: %0x %0x %0x %0x\n",
5327 pbuf1[0], pbuf1[1], pbuf1[2], pbuf1[3]));
5329 if (rc == MPT_SCANDV_GOOD) {
5331 if (iocmd.flags & MPT_ICFLAG_ECHO) {
5332 bufsize = ((pbuf1[2] & 0x1F) <<8) | pbuf1[3];
5334 bufsize = pbuf1[1]<<16 | pbuf1[2]<<8 | pbuf1[3];
5336 } else if (rc == MPT_SCANDV_SENSE) {
5337 u8 skey = hd->pLocal->sense[2] & 0x0F;
5338 u8 asc = hd->pLocal->sense[12];
5339 u8 ascq = hd->pLocal->sense[13];
5340 ddvprintk((MYIOC_s_INFO_FMT
5341 "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n",
5342 ioc->name, skey, asc, ascq));
5343 if (skey == ILLEGAL_REQUEST) {
5345 } else if (skey == UNIT_ATTENTION) {
5346 notDone++; /* repeat */
5347 } else if ((skey == NOT_READY) &&
5348 (asc == 0x04)&&(ascq == 0x01)) {
5349 /* wait then repeat */
5353 /* All other errors are fatal.
5355 ddvprintk((MYIOC_s_INFO_FMT "DV: fatal error.",
5360 /* All other errors are fatal
5367 if (iocmd.flags & MPT_ICFLAG_ECHO)
5368 echoBufSize = bufsize;
5370 dataBufSize = bufsize;
5373 iocmd.flags &= ~MPT_ICFLAG_BUF_CAP;
5375 /* Use echo buffers if possible,
5376 * Exit if both buffers are 0.
5378 if (echoBufSize > 0) {
5379 iocmd.flags |= MPT_ICFLAG_ECHO;
5380 if (dataBufSize > 0)
5381 bufsize = min(echoBufSize, dataBufSize);
5383 bufsize = echoBufSize;
5384 } else if (dataBufSize == 0)
5387 ddvprintk((MYIOC_s_INFO_FMT "%s Buffer Capacity %d\n", ioc->name,
5388 (iocmd.flags & MPT_ICFLAG_ECHO) ? "Echo" : " ", bufsize));
5390 /* Data buffers for write-read-compare test max 1K.
5392 sz = min(bufsize, 1024);
5395 * On first pass, always issue a reserve.
5396 * On additional loops, only if a reset has occurred.
5397 * iocmd.flags indicates if echo or regular buffer
5399 for (patt = 0; patt < 4; patt++) {
5400 ddvprintk(("Pattern %d\n", patt));
5401 if ((iocmd.flags & MPT_ICFLAG_RESERVED) && (iocmd.flags & MPT_ICFLAG_DID_RESET)) {
5402 iocmd.cmd = TEST_UNIT_READY;
5403 iocmd.data_dma = -1;
5406 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5409 iocmd.cmd = RELEASE;
5410 iocmd.data_dma = -1;
5413 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5415 else if (hd->pLocal == NULL)
5418 rc = hd->pLocal->completion;
5419 ddvprintk(("Release rc %d\n", rc));
5420 if (rc == MPT_SCANDV_GOOD)
5421 iocmd.flags &= ~MPT_ICFLAG_RESERVED;
5425 iocmd.flags &= ~MPT_ICFLAG_RESERVED;
5427 iocmd.flags &= ~MPT_ICFLAG_DID_RESET;
5430 while (repeat && (!(iocmd.flags & MPT_ICFLAG_RESERVED))) {
5431 iocmd.cmd = RESERVE;
5432 iocmd.data_dma = -1;
5435 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5437 else if (hd->pLocal == NULL)
5440 rc = hd->pLocal->completion;
5441 if (rc == MPT_SCANDV_GOOD) {
5442 iocmd.flags |= MPT_ICFLAG_RESERVED;
5443 } else if (rc == MPT_SCANDV_SENSE) {
5444 /* Wait if coming ready
5446 u8 skey = hd->pLocal->sense[2] & 0x0F;
5447 u8 asc = hd->pLocal->sense[12];
5448 u8 ascq = hd->pLocal->sense[13];
5449 ddvprintk((MYIOC_s_INFO_FMT
5450 "DV: Reserve Failed: ", ioc->name));
5451 ddvprintk(("SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n",
5454 if ((skey == NOT_READY) && (asc == 0x04)&&
5456 /* wait then repeat */
5460 ddvprintk((MYIOC_s_INFO_FMT
5461 "DV: Reserved Failed.", ioc->name));
5465 ddvprintk((MYIOC_s_INFO_FMT "DV: Reserved Failed.",
5472 mptscsih_fillbuf(pbuf1, sz, patt, 1);
5473 iocmd.cmd = WRITE_BUFFER;
5474 iocmd.data_dma = buf1_dma;
5477 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5479 else if (hd->pLocal == NULL)
5482 rc = hd->pLocal->completion;
5483 if (rc == MPT_SCANDV_GOOD)
5484 ; /* Issue read buffer */
5485 else if (rc == MPT_SCANDV_DID_RESET) {
5486 /* If using echo buffers, reset to data buffers.
5487 * Else do Fallback and restart
5488 * this test (re-issue reserve
5489 * because of bus reset).
5491 if ((iocmd.flags & MPT_ICFLAG_ECHO) && (dataBufSize >= bufsize)) {
5492 iocmd.flags &= ~MPT_ICFLAG_ECHO;
5494 dv.cmd = MPT_FALLBACK;
5495 mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
5497 if (mpt_config(hd->ioc, &cfg) != 0)
5500 if ((!dv.now.width) && (!dv.now.offset))
5504 iocmd.flags |= MPT_ICFLAG_DID_RESET;
5507 } else if (rc == MPT_SCANDV_SENSE) {
5508 /* Restart data test if UA, else quit.
5510 u8 skey = hd->pLocal->sense[2] & 0x0F;
5511 ddvprintk((MYIOC_s_INFO_FMT
5512 "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n", ioc->name, skey,
5513 hd->pLocal->sense[12], hd->pLocal->sense[13]));
5514 if (skey == UNIT_ATTENTION) {
5517 } else if (skey == ILLEGAL_REQUEST) {
5518 if (iocmd.flags & MPT_ICFLAG_ECHO) {
5519 if (dataBufSize >= bufsize) {
5520 iocmd.flags &= ~MPT_ICFLAG_ECHO;
5535 iocmd.cmd = READ_BUFFER;
5536 iocmd.data_dma = buf2_dma;
5539 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5541 else if (hd->pLocal == NULL)
5544 rc = hd->pLocal->completion;
5545 if (rc == MPT_SCANDV_GOOD) {
5546 /* If buffers compare,
5547 * go to next pattern,
5548 * else, do a fallback and restart
5549 * data transfer test.
5551 if (memcmp (pbuf1, pbuf2, sz) == 0) {
5552 ; /* goto next pattern */
5554 /* Miscompare with Echo buffer, go to data buffer,
5555 * if that buffer exists.
5556 * Miscompare with Data buffer, check first 4 bytes,
5557 * some devices return capacity. Exit in this case.
5559 if (iocmd.flags & MPT_ICFLAG_ECHO) {
5560 if (dataBufSize >= bufsize)
5561 iocmd.flags &= ~MPT_ICFLAG_ECHO;
5565 if (dataBufSize == (pbuf2[1]<<16 | pbuf2[2]<<8 | pbuf2[3])) {
5566 /* Argh. Device returning wrong data.
5567 * Quit DV for this device.
5572 /* Had an actual miscompare. Slow down.*/
5573 dv.cmd = MPT_FALLBACK;
5574 mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
5576 if (mpt_config(hd->ioc, &cfg) != 0)
5579 if ((!dv.now.width) && (!dv.now.offset))
5586 } else if (rc == MPT_SCANDV_DID_RESET) {
5587 /* Do Fallback and restart
5588 * this test (re-issue reserve
5589 * because of bus reset).
5591 dv.cmd = MPT_FALLBACK;
5592 mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
5594 if (mpt_config(hd->ioc, &cfg) != 0)
5597 if ((!dv.now.width) && (!dv.now.offset))
5600 iocmd.flags |= MPT_ICFLAG_DID_RESET;
5603 } else if (rc == MPT_SCANDV_SENSE) {
5604 /* Restart data test if UA, else quit.
5606 u8 skey = hd->pLocal->sense[2] & 0x0F;
5607 ddvprintk((MYIOC_s_INFO_FMT
5608 "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n", ioc->name, skey,
5609 hd->pLocal->sense[12], hd->pLocal->sense[13]));
5610 if (skey == UNIT_ATTENTION) {
5622 } /* --- end of patt loop ---- */
5625 if (iocmd.flags & MPT_ICFLAG_RESERVED) {
5626 iocmd.cmd = RELEASE;
5627 iocmd.data_dma = -1;
5630 if (mptscsih_do_cmd(hd, &iocmd) < 0)
5631 printk(MYIOC_s_INFO_FMT "DV: Release failed. id %d",
5633 else if (hd->pLocal) {
5634 if (hd->pLocal->completion == MPT_SCANDV_GOOD)
5635 iocmd.flags &= ~MPT_ICFLAG_RESERVED;
5637 printk(MYIOC_s_INFO_FMT "DV: Release failed. id %d",
5643 /* Set if cfg1_dma_addr contents is valid
5645 if ((cfg.hdr != NULL) && (retcode == 0)){
5646 /* If disk, not U320, disable QAS
5648 if ((inq0 == 0) && (dv.now.factor > MPT_ULTRA320)) {
5649 hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS;
5650 ddvprintk((MYIOC_s_NOTE_FMT
5651 "noQas set due to id=%d has factor=%x\n", ioc->name, id, dv.now.factor));
5655 mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
5657 /* Double writes to SDP1 can cause problems,
5658 * skip save of the final negotiated settings to
5659 * SCSI device page 1.
5662 cfg.physAddr = cfg1_dma_addr;
5663 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
5665 mpt_config(hd->ioc, &cfg);
5669 /* If this is a RAID Passthrough, enable internal IOs
5671 if (iocmd.flags & MPT_ICFLAG_PHYS_DISK) {
5672 if (mptscsih_do_raid(hd, MPI_RAID_ACTION_ENABLE_PHYS_IO, &iocmd) < 0)
5673 ddvprintk((MYIOC_s_ERR_FMT "RAID Enable FAILED!\n", ioc->name));
5676 /* Done with the DV scan of the current target
5679 pci_free_consistent(ioc->pcidev, dv_alloc, pDvBuf, dvbuf_dma);
5681 ddvtprintk((MYIOC_s_INFO_FMT "DV Done id=%d\n",
5687 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5688 /* mptscsih_dv_parms - perform a variety of operations on the
5689 * parameters used for negotiation.
5690 * @hd: Pointer to a SCSI host.
5691 * @dv: Pointer to a structure that contains the maximum and current
5692 * negotiated parameters.
5695 mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage)
5697 VirtDevice *pTarget;
5698 SCSIDevicePage0_t *pPage0;
5699 SCSIDevicePage1_t *pPage1;
5700 int val = 0, data, configuration;
5709 case MPT_GET_NVRAM_VALS:
5710 ddvprintk((MYIOC_s_NOTE_FMT "Getting NVRAM: ",
5712 /* Get the NVRAM values and save in tmax
5713 * If not an LVD bus, the adapter minSyncFactor has been
5714 * already throttled back.
5716 if ((hd->Targets)&&((pTarget = hd->Targets[(int)id]) != NULL) && !pTarget->raidVolume) {
5717 width = pTarget->maxWidth;
5718 offset = pTarget->maxOffset;
5719 factor = pTarget->minSyncFactor;
5720 negoFlags = pTarget->negoFlags;
5722 if (hd->ioc->spi_data.nvram && (hd->ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) {
5723 data = hd->ioc->spi_data.nvram[id];
5724 width = data & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
5725 if ((offset = hd->ioc->spi_data.maxSyncOffset) == 0)
5728 factor = (data & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;
5729 if ((factor == 0) || (factor == MPT_ASYNC)){
5740 /* Set the negotiation flags */
5741 negoFlags = hd->ioc->spi_data.noQas;
5743 negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
5746 negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
5749 /* limit by adapter capabilities */
5750 width = min(width, hd->ioc->spi_data.maxBusWidth);
5751 offset = min(offset, hd->ioc->spi_data.maxSyncOffset);
5752 factor = max(factor, hd->ioc->spi_data.minSyncFactor);
5754 /* Check Consistency */
5755 if (offset && (factor < MPT_ULTRA2) && !width)
5756 factor = MPT_ULTRA2;
5758 dv->max.width = width;
5759 dv->max.offset = offset;
5760 dv->max.factor = factor;
5761 dv->max.flags = negoFlags;
5762 ddvprintk((" id=%d width=%d factor=%x offset=%x flags=%x\n",
5763 id, width, factor, offset, negoFlags));
5766 case MPT_UPDATE_MAX:
5767 ddvprintk((MYIOC_s_NOTE_FMT
5768 "Updating with SDP0 Data: ", hd->ioc->name));
5769 /* Update tmax values with those from Device Page 0.*/
5770 pPage0 = (SCSIDevicePage0_t *) pPage;
5772 val = cpu_to_le32(pPage0->NegotiatedParameters);
5773 dv->max.width = val & MPI_SCSIDEVPAGE0_NP_WIDE ? 1 : 0;
5774 dv->max.offset = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> 16;
5775 dv->max.factor = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
5778 dv->now.width = dv->max.width;
5779 dv->now.offset = dv->max.offset;
5780 dv->now.factor = dv->max.factor;
5781 ddvprintk(("id=%d width=%d factor=%x offset=%x flags=%x\n",
5782 id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags));
5786 ddvprintk((MYIOC_s_NOTE_FMT "Setting Max: ",
5788 /* Set current to the max values. Update the config page.*/
5789 dv->now.width = dv->max.width;
5790 dv->now.offset = dv->max.offset;
5791 dv->now.factor = dv->max.factor;
5792 dv->now.flags = dv->max.flags;
5794 pPage1 = (SCSIDevicePage1_t *)pPage;
5796 mptscsih_setDevicePage1Flags (dv->now.width, dv->now.factor,
5797 dv->now.offset, &val, &configuration, dv->now.flags);
5798 dnegoprintk(("Setting Max: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n",
5799 id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration));
5800 pPage1->RequestedParameters = le32_to_cpu(val);
5801 pPage1->Reserved = 0;
5802 pPage1->Configuration = le32_to_cpu(configuration);
5805 ddvprintk(("id=%d width=%d factor=%x offset=%x flags=%x request=%x configuration=%x\n",
5806 id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration));
5810 ddvprintk((MYIOC_s_NOTE_FMT "Setting Min: ",
5812 /* Set page to asynchronous and narrow
5813 * Do not update now, breaks fallback routine. */
5817 negoFlags = dv->max.flags;
5819 pPage1 = (SCSIDevicePage1_t *)pPage;
5821 mptscsih_setDevicePage1Flags (width, factor,
5822 offset, &val, &configuration, negoFlags);
5823 dnegoprintk(("Setting Min: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n",
5824 id, width, factor, offset, negoFlags, val, configuration));
5825 pPage1->RequestedParameters = le32_to_cpu(val);
5826 pPage1->Reserved = 0;
5827 pPage1->Configuration = le32_to_cpu(configuration);
5829 ddvprintk(("id=%d width=%d factor=%x offset=%x request=%x config=%x negoFlags=%x\n",
5830 id, width, factor, offset, val, configuration, negoFlags));
5834 ddvprintk((MYIOC_s_NOTE_FMT
5835 "Fallback: Start: offset %d, factor %x, width %d \n",
5836 hd->ioc->name, dv->now.offset,
5837 dv->now.factor, dv->now.width));
5838 width = dv->now.width;
5839 offset = dv->now.offset;
5840 factor = dv->now.factor;
5841 if ((offset) && (dv->max.width)) {
5842 if (factor < MPT_ULTRA160)
5843 factor = MPT_ULTRA160;
5844 else if (factor < MPT_ULTRA2) {
5845 factor = MPT_ULTRA2;
5847 } else if ((factor == MPT_ULTRA2) && width) {
5848 factor = MPT_ULTRA2;
5850 } else if (factor < MPT_ULTRA) {
5853 } else if ((factor == MPT_ULTRA) && width) {
5855 } else if (factor < MPT_FAST) {
5858 } else if ((factor == MPT_FAST) && width) {
5861 } else if (factor < MPT_SCSI) {
5864 } else if ((factor == MPT_SCSI) && width) {
5872 } else if (offset) {
5874 if (factor < MPT_ULTRA)
5876 else if (factor < MPT_FAST)
5878 else if (factor < MPT_SCSI)
5889 dv->max.flags |= MPT_TARGET_NO_NEGO_QAS;
5890 dv->max.flags &= ~MPT_TAPE_NEGO_IDP;
5892 dv->now.width = width;
5893 dv->now.offset = offset;
5894 dv->now.factor = factor;
5895 dv->now.flags = dv->max.flags;
5897 pPage1 = (SCSIDevicePage1_t *)pPage;
5899 mptscsih_setDevicePage1Flags (width, factor, offset, &val,
5900 &configuration, dv->now.flags);
5901 dnegoprintk(("Finish: id=%d width=%d offset=%d factor=%x flags=%x request=%x config=%x\n",
5902 id, width, offset, factor, dv->now.flags, val, configuration));
5904 pPage1->RequestedParameters = le32_to_cpu(val);
5905 pPage1->Reserved = 0;
5906 pPage1->Configuration = le32_to_cpu(configuration);
5909 ddvprintk(("Finish: id=%d offset=%d factor=%x width=%d request=%x config=%x\n",
5910 id, dv->now.offset, dv->now.factor, dv->now.width, val, configuration));
5914 ddvprintk((MYIOC_s_NOTE_FMT
5915 "Saving to Target structure: ", hd->ioc->name));
5916 ddvprintk(("id=%d width=%x factor=%x offset=%d flags=%x\n",
5917 id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags));
5919 /* Save these values to target structures
5920 * or overwrite nvram (phys disks only).
5923 if ((hd->Targets)&&((pTarget = hd->Targets[(int)id]) != NULL) && !pTarget->raidVolume ) {
5924 pTarget->maxWidth = dv->now.width;
5925 pTarget->maxOffset = dv->now.offset;
5926 pTarget->minSyncFactor = dv->now.factor;
5927 pTarget->negoFlags = dv->now.flags;
5929 /* Preserv all flags, use
5930 * read-modify-write algorithm
5932 if (hd->ioc->spi_data.nvram) {
5933 data = hd->ioc->spi_data.nvram[id];
5936 data &= ~MPT_NVRAM_WIDE_DISABLE;
5938 data |= MPT_NVRAM_WIDE_DISABLE;
5940 if (!dv->now.offset)
5943 data &= ~MPT_NVRAM_SYNC_MASK;
5944 data |= (dv->now.factor << MPT_NVRAM_SYNC_SHIFT) & MPT_NVRAM_SYNC_MASK;
5946 hd->ioc->spi_data.nvram[id] = data;
5953 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5954 /* mptscsih_fillbuf - fill a buffer with a special data pattern
5955 * cleanup. For bus scan only.
5957 * @buffer: Pointer to data buffer to be filled.
5958 * @size: Number of bytes to fill
5959 * @index: Pattern index
5960 * @width: bus width, 0 (8 bits) or 1 (16 bits)
5963 mptscsih_fillbuf(char *buffer, int size, int index, int width)
5974 /* Pattern: 0000 FFFF 0000 FFFF
5976 for (ii=0; ii < size; ii++, ptr++) {
5983 /* Pattern: 00 FF 00 FF
5985 for (ii=0; ii < size; ii++, ptr++) {
5996 /* Pattern: 5555 AAAA 5555 AAAA 5555
5998 for (ii=0; ii < size; ii++, ptr++) {
6005 /* Pattern: 55 AA 55 AA 55
6007 for (ii=0; ii < size; ii++, ptr++) {
6017 /* Pattern: 00 01 02 03 04 05
6020 for (ii=0; ii < size; ii++, ptr++)
6026 /* Wide Pattern: FFFE 0001 FFFD 0002
6027 * ... 4000 DFFF 8000 EFFF
6030 for (ii=0; ii < size/2; ii++) {
6031 /* Create the base pattern
6034 /* every 64 (0x40) bytes flip the pattern
6035 * since we fill 2 bytes / iteration,
6036 * test for ii = 0x20
6042 *ptr = (char)( (val & 0xFF00) >> 8);
6044 *ptr = (char)(val & 0xFF);
6049 *ptr = (char)( (val & 0xFF00) >> 8);
6051 *ptr = (char)(val & 0xFF);
6057 /* Narrow Pattern: FE 01 FD 02 FB 04
6058 * .. 7F 80 01 FE 02 FD ... 80 7F
6061 for (ii=0; ii < size; ii++, ptr++) {
6062 /* Base pattern - first 32 bytes
6069 *ptr = (char) (~(1 << byte));
6072 /* Flip the pattern every 32 bytes
6081 #endif /* ~MPTSCSIH_ENABLE_DOMAIN_VALIDATION */
6083 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6085 module_init(mptscsih_init);
6086 module_exit(mptscsih_exit);