11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/drivers/message/fusion/mptscsih.c 30d0c7974SMoore, Eric Dean * For use with LSI Logic PCI chip/adapter(s) 41da177e4SLinus Torvalds * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 51da177e4SLinus Torvalds * 60d0c7974SMoore, Eric Dean * Copyright (c) 1999-2005 LSI Logic Corporation 71da177e4SLinus Torvalds * (mailto:mpt_linux_developer@lsil.com) 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds */ 101da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 111da177e4SLinus Torvalds /* 121da177e4SLinus Torvalds This program is free software; you can redistribute it and/or modify 131da177e4SLinus Torvalds it under the terms of the GNU General Public License as published by 141da177e4SLinus Torvalds the Free Software Foundation; version 2 of the License. 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds This program is distributed in the hope that it will be useful, 171da177e4SLinus Torvalds but WITHOUT ANY WARRANTY; without even the implied warranty of 181da177e4SLinus Torvalds MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 191da177e4SLinus Torvalds GNU General Public License for more details. 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds NO WARRANTY 221da177e4SLinus Torvalds THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR 231da177e4SLinus Torvalds CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT 241da177e4SLinus Torvalds LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 251da177e4SLinus Torvalds MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is 261da177e4SLinus Torvalds solely responsible for determining the appropriateness of using and 271da177e4SLinus Torvalds distributing the Program and assumes all risks associated with its 281da177e4SLinus Torvalds exercise of rights under this Agreement, including but not limited to 291da177e4SLinus Torvalds the risks and costs of program errors, damage to or loss of data, 301da177e4SLinus Torvalds programs or equipment, and unavailability or interruption of operations. 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds DISCLAIMER OF LIABILITY 331da177e4SLinus Torvalds NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY 341da177e4SLinus Torvalds DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 351da177e4SLinus Torvalds DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND 361da177e4SLinus Torvalds ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 371da177e4SLinus Torvalds TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 381da177e4SLinus Torvalds USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 391da177e4SLinus Torvalds HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds You should have received a copy of the GNU General Public License 421da177e4SLinus Torvalds along with this program; if not, write to the Free Software 431da177e4SLinus Torvalds Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 441da177e4SLinus Torvalds */ 451da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds #include "linux_compat.h" /* linux-2.6 tweaks */ 481da177e4SLinus Torvalds #include <linux/module.h> 491da177e4SLinus Torvalds #include <linux/kernel.h> 501da177e4SLinus Torvalds #include <linux/init.h> 511da177e4SLinus Torvalds #include <linux/errno.h> 521da177e4SLinus Torvalds #include <linux/kdev_t.h> 531da177e4SLinus Torvalds #include <linux/blkdev.h> 541da177e4SLinus Torvalds #include <linux/delay.h> /* for mdelay */ 551da177e4SLinus Torvalds #include <linux/interrupt.h> /* needed for in_interrupt() proto */ 561da177e4SLinus Torvalds #include <linux/reboot.h> /* notifier code */ 571da177e4SLinus Torvalds #include <linux/sched.h> 581da177e4SLinus Torvalds #include <linux/workqueue.h> 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds #include <scsi/scsi.h> 611da177e4SLinus Torvalds #include <scsi/scsi_cmnd.h> 621da177e4SLinus Torvalds #include <scsi/scsi_device.h> 631da177e4SLinus Torvalds #include <scsi/scsi_host.h> 641da177e4SLinus Torvalds #include <scsi/scsi_tcq.h> 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds #include "mptbase.h" 671da177e4SLinus Torvalds #include "mptscsih.h" 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 701da177e4SLinus Torvalds #define my_NAME "Fusion MPT SCSI Host driver" 711da177e4SLinus Torvalds #define my_VERSION MPT_LINUX_VERSION_COMMON 721da177e4SLinus Torvalds #define MYNAM "mptscsih" 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds MODULE_AUTHOR(MODULEAUTHOR); 751da177e4SLinus Torvalds MODULE_DESCRIPTION(my_NAME); 761da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds typedef struct _BIG_SENSE_BUF { 811da177e4SLinus Torvalds u8 data[MPT_SENSE_BUFFER_ALLOC]; 821da177e4SLinus Torvalds } BIG_SENSE_BUF; 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds #define MPT_SCANDV_GOOD (0x00000000) /* must be 0 */ 851da177e4SLinus Torvalds #define MPT_SCANDV_DID_RESET (0x00000001) 861da177e4SLinus Torvalds #define MPT_SCANDV_SENSE (0x00000002) 871da177e4SLinus Torvalds #define MPT_SCANDV_SOME_ERROR (0x00000004) 881da177e4SLinus Torvalds #define MPT_SCANDV_SELECTION_TIMEOUT (0x00000008) 891da177e4SLinus Torvalds #define MPT_SCANDV_ISSUE_SENSE (0x00000010) 901da177e4SLinus Torvalds #define MPT_SCANDV_FALLBACK (0x00000020) 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds #define MPT_SCANDV_MAX_RETRIES (10) 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds #define MPT_ICFLAG_BUF_CAP 0x01 /* ReadBuffer Read Capacity format */ 951da177e4SLinus Torvalds #define MPT_ICFLAG_ECHO 0x02 /* ReadBuffer Echo buffer format */ 961da177e4SLinus Torvalds #define MPT_ICFLAG_PHYS_DISK 0x04 /* Any SCSI IO but do Phys Disk Format */ 971da177e4SLinus Torvalds #define MPT_ICFLAG_TAGGED_CMD 0x08 /* Do tagged IO */ 981da177e4SLinus Torvalds #define MPT_ICFLAG_DID_RESET 0x20 /* Bus Reset occurred with this command */ 991da177e4SLinus Torvalds #define MPT_ICFLAG_RESERVED 0x40 /* Reserved has been issued */ 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds typedef struct _internal_cmd { 1021da177e4SLinus Torvalds char *data; /* data pointer */ 1031da177e4SLinus Torvalds dma_addr_t data_dma; /* data dma address */ 1041da177e4SLinus Torvalds int size; /* transfer size */ 1051da177e4SLinus Torvalds u8 cmd; /* SCSI Op Code */ 1061da177e4SLinus Torvalds u8 bus; /* bus number */ 1071da177e4SLinus Torvalds u8 id; /* SCSI ID (virtual) */ 1081da177e4SLinus Torvalds u8 lun; 1091da177e4SLinus Torvalds u8 flags; /* Bit Field - See above */ 1101da177e4SLinus Torvalds u8 physDiskNum; /* Phys disk number, -1 else */ 1111da177e4SLinus Torvalds u8 rsvd2; 1121da177e4SLinus Torvalds u8 rsvd; 1131da177e4SLinus Torvalds } INTERNAL_CMD; 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds typedef struct _negoparms { 1161da177e4SLinus Torvalds u8 width; 1171da177e4SLinus Torvalds u8 offset; 1181da177e4SLinus Torvalds u8 factor; 1191da177e4SLinus Torvalds u8 flags; 1201da177e4SLinus Torvalds } NEGOPARMS; 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds typedef struct _dv_parameters { 1231da177e4SLinus Torvalds NEGOPARMS max; 1241da177e4SLinus Torvalds NEGOPARMS now; 1251da177e4SLinus Torvalds u8 cmd; 1261da177e4SLinus Torvalds u8 id; 1271da177e4SLinus Torvalds u16 pad1; 1281da177e4SLinus Torvalds } DVPARAMETERS; 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds /* 1311da177e4SLinus Torvalds * Other private/forward protos... 1321da177e4SLinus Torvalds */ 1330d0c7974SMoore, Eric Dean int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r); 1341da177e4SLinus Torvalds static void mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq); 1350d0c7974SMoore, Eric Dean int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r); 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds static int mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt, 1381da177e4SLinus Torvalds SCSIIORequest_t *pReq, int req_idx); 1391da177e4SLinus Torvalds static void mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx); 1400d0c7974SMoore, Eric Dean static void mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply); 1411da177e4SLinus Torvalds static int mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd); 1421da177e4SLinus Torvalds static int mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout ); 1431da177e4SLinus Torvalds static u32 SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc); 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds static int mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout); 1461da177e4SLinus Torvalds static int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout); 1471da177e4SLinus Torvalds 1480d0c7974SMoore, Eric Dean int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset); 1490d0c7974SMoore, Eric Dean int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply); 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds static void mptscsih_initTarget(MPT_SCSI_HOST *hd, int bus_id, int target_id, u8 lun, char *data, int dlen); 1521da177e4SLinus Torvalds static void mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtDevice *target, char byte56); 1531da177e4SLinus Torvalds static void mptscsih_set_dvflags(MPT_SCSI_HOST *hd, SCSIIORequest_t *pReq); 1541da177e4SLinus Torvalds static void mptscsih_setDevicePage1Flags (u8 width, u8 factor, u8 offset, int *requestedPtr, int *configurationPtr, u8 flags); 1551da177e4SLinus Torvalds static void mptscsih_no_negotiate(MPT_SCSI_HOST *hd, int target_id); 1561da177e4SLinus Torvalds static int mptscsih_writeSDP1(MPT_SCSI_HOST *hd, int portnum, int target, int flags); 1571da177e4SLinus Torvalds static int mptscsih_writeIOCPage4(MPT_SCSI_HOST *hd, int target_id, int bus); 1580d0c7974SMoore, Eric Dean int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r); 1591da177e4SLinus Torvalds static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd); 1601da177e4SLinus Torvalds static int mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, int portnum); 1611da177e4SLinus Torvalds 1621da177e4SLinus Torvalds #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION 1631da177e4SLinus Torvalds static int mptscsih_do_raid(MPT_SCSI_HOST *hd, u8 action, INTERNAL_CMD *io); 1641da177e4SLinus Torvalds static void mptscsih_domainValidation(void *hd); 1651da177e4SLinus Torvalds static int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id); 1661da177e4SLinus Torvalds static void mptscsih_qas_check(MPT_SCSI_HOST *hd, int id); 1671da177e4SLinus Torvalds static int mptscsih_doDv(MPT_SCSI_HOST *hd, int channel, int target); 1681da177e4SLinus Torvalds static void mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage); 1691da177e4SLinus Torvalds static void mptscsih_fillbuf(char *buffer, int size, int index, int width); 1701da177e4SLinus Torvalds #endif 1711da177e4SLinus Torvalds 1720d0c7974SMoore, Eric Dean void mptscsih_remove(struct pci_dev *); 1730d0c7974SMoore, Eric Dean void mptscsih_shutdown(struct device *); 1741da177e4SLinus Torvalds #ifdef CONFIG_PM 1750d0c7974SMoore, Eric Dean int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state); 1760d0c7974SMoore, Eric Dean int mptscsih_resume(struct pci_dev *pdev); 1771da177e4SLinus Torvalds #endif 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds #define SNS_LEN(scp) sizeof((scp)->sense_buffer) 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION 1821da177e4SLinus Torvalds /* 1831da177e4SLinus Torvalds * Domain Validation task structure 1841da177e4SLinus Torvalds */ 1851da177e4SLinus Torvalds static DEFINE_SPINLOCK(dvtaskQ_lock); 1861da177e4SLinus Torvalds static int dvtaskQ_active = 0; 1871da177e4SLinus Torvalds static int dvtaskQ_release = 0; 1880d0c7974SMoore, Eric Dean static struct work_struct dvTaskQ_task; 1891da177e4SLinus Torvalds #endif 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1921da177e4SLinus Torvalds /** 1931da177e4SLinus Torvalds * mptscsih_add_sge - Place a simple SGE at address pAddr. 1941da177e4SLinus Torvalds * @pAddr: virtual address for SGE 1951da177e4SLinus Torvalds * @flagslength: SGE flags and data transfer length 1961da177e4SLinus Torvalds * @dma_addr: Physical address 1971da177e4SLinus Torvalds * 1981da177e4SLinus Torvalds * This routine places a MPT request frame back on the MPT adapter's 1991da177e4SLinus Torvalds * FreeQ. 2001da177e4SLinus Torvalds */ 2011da177e4SLinus Torvalds static inline void 2021da177e4SLinus Torvalds mptscsih_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr) 2031da177e4SLinus Torvalds { 2041da177e4SLinus Torvalds if (sizeof(dma_addr_t) == sizeof(u64)) { 2051da177e4SLinus Torvalds SGESimple64_t *pSge = (SGESimple64_t *) pAddr; 2061da177e4SLinus Torvalds u32 tmp = dma_addr & 0xFFFFFFFF; 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds pSge->FlagsLength = cpu_to_le32(flagslength); 2091da177e4SLinus Torvalds pSge->Address.Low = cpu_to_le32(tmp); 2101da177e4SLinus Torvalds tmp = (u32) ((u64)dma_addr >> 32); 2111da177e4SLinus Torvalds pSge->Address.High = cpu_to_le32(tmp); 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds } else { 2141da177e4SLinus Torvalds SGESimple32_t *pSge = (SGESimple32_t *) pAddr; 2151da177e4SLinus Torvalds pSge->FlagsLength = cpu_to_le32(flagslength); 2161da177e4SLinus Torvalds pSge->Address = cpu_to_le32(dma_addr); 2171da177e4SLinus Torvalds } 2181da177e4SLinus Torvalds } /* mptscsih_add_sge() */ 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2211da177e4SLinus Torvalds /** 2221da177e4SLinus Torvalds * mptscsih_add_chain - Place a chain SGE at address pAddr. 2231da177e4SLinus Torvalds * @pAddr: virtual address for SGE 2241da177e4SLinus Torvalds * @next: nextChainOffset value (u32's) 2251da177e4SLinus Torvalds * @length: length of next SGL segment 2261da177e4SLinus Torvalds * @dma_addr: Physical address 2271da177e4SLinus Torvalds * 2281da177e4SLinus Torvalds * This routine places a MPT request frame back on the MPT adapter's 2291da177e4SLinus Torvalds * FreeQ. 2301da177e4SLinus Torvalds */ 2311da177e4SLinus Torvalds static inline void 2321da177e4SLinus Torvalds mptscsih_add_chain(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr) 2331da177e4SLinus Torvalds { 2341da177e4SLinus Torvalds if (sizeof(dma_addr_t) == sizeof(u64)) { 2351da177e4SLinus Torvalds SGEChain64_t *pChain = (SGEChain64_t *) pAddr; 2361da177e4SLinus Torvalds u32 tmp = dma_addr & 0xFFFFFFFF; 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds pChain->Length = cpu_to_le16(length); 2391da177e4SLinus Torvalds pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size(); 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds pChain->NextChainOffset = next; 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds pChain->Address.Low = cpu_to_le32(tmp); 2441da177e4SLinus Torvalds tmp = (u32) ((u64)dma_addr >> 32); 2451da177e4SLinus Torvalds pChain->Address.High = cpu_to_le32(tmp); 2461da177e4SLinus Torvalds } else { 2471da177e4SLinus Torvalds SGEChain32_t *pChain = (SGEChain32_t *) pAddr; 2481da177e4SLinus Torvalds pChain->Length = cpu_to_le16(length); 2491da177e4SLinus Torvalds pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size(); 2501da177e4SLinus Torvalds pChain->NextChainOffset = next; 2511da177e4SLinus Torvalds pChain->Address = cpu_to_le32(dma_addr); 2521da177e4SLinus Torvalds } 2531da177e4SLinus Torvalds } /* mptscsih_add_chain() */ 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2561da177e4SLinus Torvalds /* 2571da177e4SLinus Torvalds * mptscsih_getFreeChainBuffer - Function to get a free chain 2581da177e4SLinus Torvalds * from the MPT_SCSI_HOST FreeChainQ. 2591da177e4SLinus Torvalds * @ioc: Pointer to MPT_ADAPTER structure 2601da177e4SLinus Torvalds * @req_idx: Index of the SCSI IO request frame. (output) 2611da177e4SLinus Torvalds * 2621da177e4SLinus Torvalds * return SUCCESS or FAILED 2631da177e4SLinus Torvalds */ 2641da177e4SLinus Torvalds static inline int 2651da177e4SLinus Torvalds mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex) 2661da177e4SLinus Torvalds { 2671da177e4SLinus Torvalds MPT_FRAME_HDR *chainBuf; 2681da177e4SLinus Torvalds unsigned long flags; 2691da177e4SLinus Torvalds int rc; 2701da177e4SLinus Torvalds int chain_idx; 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds dsgprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer called\n", 2731da177e4SLinus Torvalds ioc->name)); 2741da177e4SLinus Torvalds spin_lock_irqsave(&ioc->FreeQlock, flags); 2751da177e4SLinus Torvalds if (!list_empty(&ioc->FreeChainQ)) { 2761da177e4SLinus Torvalds int offset; 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds chainBuf = list_entry(ioc->FreeChainQ.next, MPT_FRAME_HDR, 2791da177e4SLinus Torvalds u.frame.linkage.list); 2801da177e4SLinus Torvalds list_del(&chainBuf->u.frame.linkage.list); 2811da177e4SLinus Torvalds offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer; 2821da177e4SLinus Torvalds chain_idx = offset / ioc->req_sz; 2831da177e4SLinus Torvalds rc = SUCCESS; 2841da177e4SLinus Torvalds dsgprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer (index %d), got buf=%p\n", 2851da177e4SLinus Torvalds ioc->name, *retIndex, chainBuf)); 2861da177e4SLinus Torvalds } else { 2871da177e4SLinus Torvalds rc = FAILED; 2881da177e4SLinus Torvalds chain_idx = MPT_HOST_NO_CHAIN; 2891da177e4SLinus Torvalds dfailprintk((MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n", 2901da177e4SLinus Torvalds ioc->name)); 2911da177e4SLinus Torvalds } 2921da177e4SLinus Torvalds spin_unlock_irqrestore(&ioc->FreeQlock, flags); 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvalds *retIndex = chain_idx; 2951da177e4SLinus Torvalds return rc; 2961da177e4SLinus Torvalds } /* mptscsih_getFreeChainBuffer() */ 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2991da177e4SLinus Torvalds /* 3001da177e4SLinus Torvalds * mptscsih_AddSGE - Add a SGE (plus chain buffers) to the 3011da177e4SLinus Torvalds * SCSIIORequest_t Message Frame. 3021da177e4SLinus Torvalds * @ioc: Pointer to MPT_ADAPTER structure 3031da177e4SLinus Torvalds * @SCpnt: Pointer to scsi_cmnd structure 3041da177e4SLinus Torvalds * @pReq: Pointer to SCSIIORequest_t structure 3051da177e4SLinus Torvalds * 3061da177e4SLinus Torvalds * Returns ... 3071da177e4SLinus Torvalds */ 3081da177e4SLinus Torvalds static int 3091da177e4SLinus Torvalds mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt, 3101da177e4SLinus Torvalds SCSIIORequest_t *pReq, int req_idx) 3111da177e4SLinus Torvalds { 3121da177e4SLinus Torvalds char *psge; 3131da177e4SLinus Torvalds char *chainSge; 3141da177e4SLinus Torvalds struct scatterlist *sg; 3151da177e4SLinus Torvalds int frm_sz; 3161da177e4SLinus Torvalds int sges_left, sg_done; 3171da177e4SLinus Torvalds int chain_idx = MPT_HOST_NO_CHAIN; 3181da177e4SLinus Torvalds int sgeOffset; 3191da177e4SLinus Torvalds int numSgeSlots, numSgeThisFrame; 3201da177e4SLinus Torvalds u32 sgflags, sgdir, thisxfer = 0; 3211da177e4SLinus Torvalds int chain_dma_off = 0; 3221da177e4SLinus Torvalds int newIndex; 3231da177e4SLinus Torvalds int ii; 3241da177e4SLinus Torvalds dma_addr_t v2; 3251da177e4SLinus Torvalds u32 RequestNB; 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds sgdir = le32_to_cpu(pReq->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK; 3281da177e4SLinus Torvalds if (sgdir == MPI_SCSIIO_CONTROL_WRITE) { 3291da177e4SLinus Torvalds sgdir = MPT_TRANSFER_HOST_TO_IOC; 3301da177e4SLinus Torvalds } else { 3311da177e4SLinus Torvalds sgdir = MPT_TRANSFER_IOC_TO_HOST; 3321da177e4SLinus Torvalds } 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds psge = (char *) &pReq->SGL; 3351da177e4SLinus Torvalds frm_sz = ioc->req_sz; 3361da177e4SLinus Torvalds 3371da177e4SLinus Torvalds /* Map the data portion, if any. 3381da177e4SLinus Torvalds * sges_left = 0 if no data transfer. 3391da177e4SLinus Torvalds */ 3401da177e4SLinus Torvalds if ( (sges_left = SCpnt->use_sg) ) { 3411da177e4SLinus Torvalds sges_left = pci_map_sg(ioc->pcidev, 3421da177e4SLinus Torvalds (struct scatterlist *) SCpnt->request_buffer, 3431da177e4SLinus Torvalds SCpnt->use_sg, 3441da177e4SLinus Torvalds SCpnt->sc_data_direction); 3451da177e4SLinus Torvalds if (sges_left == 0) 3461da177e4SLinus Torvalds return FAILED; 3471da177e4SLinus Torvalds } else if (SCpnt->request_bufflen) { 3481da177e4SLinus Torvalds SCpnt->SCp.dma_handle = pci_map_single(ioc->pcidev, 3491da177e4SLinus Torvalds SCpnt->request_buffer, 3501da177e4SLinus Torvalds SCpnt->request_bufflen, 3511da177e4SLinus Torvalds SCpnt->sc_data_direction); 3521da177e4SLinus Torvalds dsgprintk((MYIOC_s_INFO_FMT "SG: non-SG for %p, len=%d\n", 3531da177e4SLinus Torvalds ioc->name, SCpnt, SCpnt->request_bufflen)); 3541da177e4SLinus Torvalds mptscsih_add_sge((char *) &pReq->SGL, 3551da177e4SLinus Torvalds 0xD1000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|SCpnt->request_bufflen, 3561da177e4SLinus Torvalds SCpnt->SCp.dma_handle); 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds return SUCCESS; 3591da177e4SLinus Torvalds } 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds /* Handle the SG case. 3621da177e4SLinus Torvalds */ 3631da177e4SLinus Torvalds sg = (struct scatterlist *) SCpnt->request_buffer; 3641da177e4SLinus Torvalds sg_done = 0; 3651da177e4SLinus Torvalds sgeOffset = sizeof(SCSIIORequest_t) - sizeof(SGE_IO_UNION); 3661da177e4SLinus Torvalds chainSge = NULL; 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvalds /* Prior to entering this loop - the following must be set 3691da177e4SLinus Torvalds * current MF: sgeOffset (bytes) 3701da177e4SLinus Torvalds * chainSge (Null if original MF is not a chain buffer) 3711da177e4SLinus Torvalds * sg_done (num SGE done for this MF) 3721da177e4SLinus Torvalds */ 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds nextSGEset: 3751da177e4SLinus Torvalds numSgeSlots = ((frm_sz - sgeOffset) / (sizeof(u32) + sizeof(dma_addr_t)) ); 3761da177e4SLinus Torvalds numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots; 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | MPT_SGE_FLAGS_ADDRESSING | sgdir; 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds /* Get first (num - 1) SG elements 3811da177e4SLinus Torvalds * Skip any SG entries with a length of 0 3821da177e4SLinus Torvalds * NOTE: at finish, sg and psge pointed to NEXT data/location positions 3831da177e4SLinus Torvalds */ 3841da177e4SLinus Torvalds for (ii=0; ii < (numSgeThisFrame-1); ii++) { 3851da177e4SLinus Torvalds thisxfer = sg_dma_len(sg); 3861da177e4SLinus Torvalds if (thisxfer == 0) { 3871da177e4SLinus Torvalds sg ++; /* Get next SG element from the OS */ 3881da177e4SLinus Torvalds sg_done++; 3891da177e4SLinus Torvalds continue; 3901da177e4SLinus Torvalds } 3911da177e4SLinus Torvalds 3921da177e4SLinus Torvalds v2 = sg_dma_address(sg); 3931da177e4SLinus Torvalds mptscsih_add_sge(psge, sgflags | thisxfer, v2); 3941da177e4SLinus Torvalds 3951da177e4SLinus Torvalds sg++; /* Get next SG element from the OS */ 3961da177e4SLinus Torvalds psge += (sizeof(u32) + sizeof(dma_addr_t)); 3971da177e4SLinus Torvalds sgeOffset += (sizeof(u32) + sizeof(dma_addr_t)); 3981da177e4SLinus Torvalds sg_done++; 3991da177e4SLinus Torvalds } 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvalds if (numSgeThisFrame == sges_left) { 4021da177e4SLinus Torvalds /* Add last element, end of buffer and end of list flags. 4031da177e4SLinus Torvalds */ 4041da177e4SLinus Torvalds sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT | 4051da177e4SLinus Torvalds MPT_SGE_FLAGS_END_OF_BUFFER | 4061da177e4SLinus Torvalds MPT_SGE_FLAGS_END_OF_LIST; 4071da177e4SLinus Torvalds 4081da177e4SLinus Torvalds /* Add last SGE and set termination flags. 4091da177e4SLinus Torvalds * Note: Last SGE may have a length of 0 - which should be ok. 4101da177e4SLinus Torvalds */ 4111da177e4SLinus Torvalds thisxfer = sg_dma_len(sg); 4121da177e4SLinus Torvalds 4131da177e4SLinus Torvalds v2 = sg_dma_address(sg); 4141da177e4SLinus Torvalds mptscsih_add_sge(psge, sgflags | thisxfer, v2); 4151da177e4SLinus Torvalds /* 4161da177e4SLinus Torvalds sg++; 4171da177e4SLinus Torvalds psge += (sizeof(u32) + sizeof(dma_addr_t)); 4181da177e4SLinus Torvalds */ 4191da177e4SLinus Torvalds sgeOffset += (sizeof(u32) + sizeof(dma_addr_t)); 4201da177e4SLinus Torvalds sg_done++; 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds if (chainSge) { 4231da177e4SLinus Torvalds /* The current buffer is a chain buffer, 4241da177e4SLinus Torvalds * but there is not another one. 4251da177e4SLinus Torvalds * Update the chain element 4261da177e4SLinus Torvalds * Offset and Length fields. 4271da177e4SLinus Torvalds */ 4281da177e4SLinus Torvalds mptscsih_add_chain((char *)chainSge, 0, sgeOffset, ioc->ChainBufferDMA + chain_dma_off); 4291da177e4SLinus Torvalds } else { 4301da177e4SLinus Torvalds /* The current buffer is the original MF 4311da177e4SLinus Torvalds * and there is no Chain buffer. 4321da177e4SLinus Torvalds */ 4331da177e4SLinus Torvalds pReq->ChainOffset = 0; 4341da177e4SLinus Torvalds RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03; 4351da177e4SLinus Torvalds dsgprintk((MYIOC_s_ERR_FMT 4361da177e4SLinus Torvalds "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset)); 4371da177e4SLinus Torvalds ioc->RequestNB[req_idx] = RequestNB; 4381da177e4SLinus Torvalds } 4391da177e4SLinus Torvalds } else { 4401da177e4SLinus Torvalds /* At least one chain buffer is needed. 4411da177e4SLinus Torvalds * Complete the first MF 4421da177e4SLinus Torvalds * - last SGE element, set the LastElement bit 4431da177e4SLinus Torvalds * - set ChainOffset (words) for orig MF 4441da177e4SLinus Torvalds * (OR finish previous MF chain buffer) 4451da177e4SLinus Torvalds * - update MFStructPtr ChainIndex 4461da177e4SLinus Torvalds * - Populate chain element 4471da177e4SLinus Torvalds * Also 4481da177e4SLinus Torvalds * Loop until done. 4491da177e4SLinus Torvalds */ 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds dsgprintk((MYIOC_s_INFO_FMT "SG: Chain Required! sg done %d\n", 4521da177e4SLinus Torvalds ioc->name, sg_done)); 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds /* Set LAST_ELEMENT flag for last non-chain element 4551da177e4SLinus Torvalds * in the buffer. Since psge points at the NEXT 4561da177e4SLinus Torvalds * SGE element, go back one SGE element, update the flags 4571da177e4SLinus Torvalds * and reset the pointer. (Note: sgflags & thisxfer are already 4581da177e4SLinus Torvalds * set properly). 4591da177e4SLinus Torvalds */ 4601da177e4SLinus Torvalds if (sg_done) { 4611da177e4SLinus Torvalds u32 *ptmp = (u32 *) (psge - (sizeof(u32) + sizeof(dma_addr_t))); 4621da177e4SLinus Torvalds sgflags = le32_to_cpu(*ptmp); 4631da177e4SLinus Torvalds sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT; 4641da177e4SLinus Torvalds *ptmp = cpu_to_le32(sgflags); 4651da177e4SLinus Torvalds } 4661da177e4SLinus Torvalds 4671da177e4SLinus Torvalds if (chainSge) { 4681da177e4SLinus Torvalds /* The current buffer is a chain buffer. 4691da177e4SLinus Torvalds * chainSge points to the previous Chain Element. 4701da177e4SLinus Torvalds * Update its chain element Offset and Length (must 4711da177e4SLinus Torvalds * include chain element size) fields. 4721da177e4SLinus Torvalds * Old chain element is now complete. 4731da177e4SLinus Torvalds */ 4741da177e4SLinus Torvalds u8 nextChain = (u8) (sgeOffset >> 2); 4751da177e4SLinus Torvalds sgeOffset += (sizeof(u32) + sizeof(dma_addr_t)); 4761da177e4SLinus Torvalds mptscsih_add_chain((char *)chainSge, nextChain, sgeOffset, ioc->ChainBufferDMA + chain_dma_off); 4771da177e4SLinus Torvalds } else { 4781da177e4SLinus Torvalds /* The original MF buffer requires a chain buffer - 4791da177e4SLinus Torvalds * set the offset. 4801da177e4SLinus Torvalds * Last element in this MF is a chain element. 4811da177e4SLinus Torvalds */ 4821da177e4SLinus Torvalds pReq->ChainOffset = (u8) (sgeOffset >> 2); 4831da177e4SLinus Torvalds RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03; 4841da177e4SLinus Torvalds dsgprintk((MYIOC_s_ERR_FMT "Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset)); 4851da177e4SLinus Torvalds ioc->RequestNB[req_idx] = RequestNB; 4861da177e4SLinus Torvalds } 4871da177e4SLinus Torvalds 4881da177e4SLinus Torvalds sges_left -= sg_done; 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvalds 4911da177e4SLinus Torvalds /* NOTE: psge points to the beginning of the chain element 4921da177e4SLinus Torvalds * in current buffer. Get a chain buffer. 4931da177e4SLinus Torvalds */ 4941da177e4SLinus Torvalds dsgprintk((MYIOC_s_INFO_FMT 4951da177e4SLinus Torvalds "calling getFreeChainBuffer SCSI cmd=%02x (%p)\n", 4961da177e4SLinus Torvalds ioc->name, pReq->CDB[0], SCpnt)); 4971da177e4SLinus Torvalds if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED) 4981da177e4SLinus Torvalds return FAILED; 4991da177e4SLinus Torvalds 5001da177e4SLinus Torvalds /* Update the tracking arrays. 5011da177e4SLinus Torvalds * If chainSge == NULL, update ReqToChain, else ChainToChain 5021da177e4SLinus Torvalds */ 5031da177e4SLinus Torvalds if (chainSge) { 5041da177e4SLinus Torvalds ioc->ChainToChain[chain_idx] = newIndex; 5051da177e4SLinus Torvalds } else { 5061da177e4SLinus Torvalds ioc->ReqToChain[req_idx] = newIndex; 5071da177e4SLinus Torvalds } 5081da177e4SLinus Torvalds chain_idx = newIndex; 5091da177e4SLinus Torvalds chain_dma_off = ioc->req_sz * chain_idx; 5101da177e4SLinus Torvalds 5111da177e4SLinus Torvalds /* Populate the chainSGE for the current buffer. 5121da177e4SLinus Torvalds * - Set chain buffer pointer to psge and fill 5131da177e4SLinus Torvalds * out the Address and Flags fields. 5141da177e4SLinus Torvalds */ 5151da177e4SLinus Torvalds chainSge = (char *) psge; 5161da177e4SLinus Torvalds dsgprintk((KERN_INFO " Current buff @ %p (index 0x%x)", 5171da177e4SLinus Torvalds psge, req_idx)); 5181da177e4SLinus Torvalds 5191da177e4SLinus Torvalds /* Start the SGE for the next buffer 5201da177e4SLinus Torvalds */ 5211da177e4SLinus Torvalds psge = (char *) (ioc->ChainBuffer + chain_dma_off); 5221da177e4SLinus Torvalds sgeOffset = 0; 5231da177e4SLinus Torvalds sg_done = 0; 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds dsgprintk((KERN_INFO " Chain buff @ %p (index 0x%x)\n", 5261da177e4SLinus Torvalds psge, chain_idx)); 5271da177e4SLinus Torvalds 5281da177e4SLinus Torvalds /* Start the SGE for the next buffer 5291da177e4SLinus Torvalds */ 5301da177e4SLinus Torvalds 5311da177e4SLinus Torvalds goto nextSGEset; 5321da177e4SLinus Torvalds } 5331da177e4SLinus Torvalds 5341da177e4SLinus Torvalds return SUCCESS; 5351da177e4SLinus Torvalds } /* mptscsih_AddSGE() */ 5361da177e4SLinus Torvalds 5371da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 5381da177e4SLinus Torvalds /* 5391da177e4SLinus Torvalds * mptscsih_io_done - Main SCSI IO callback routine registered to 5401da177e4SLinus Torvalds * Fusion MPT (base) driver 5411da177e4SLinus Torvalds * @ioc: Pointer to MPT_ADAPTER structure 5421da177e4SLinus Torvalds * @mf: Pointer to original MPT request frame 5431da177e4SLinus Torvalds * @r: Pointer to MPT reply frame (NULL if TurboReply) 5441da177e4SLinus Torvalds * 5451da177e4SLinus Torvalds * This routine is called from mpt.c::mpt_interrupt() at the completion 5461da177e4SLinus Torvalds * of any SCSI IO request. 5471da177e4SLinus Torvalds * This routine is registered with the Fusion MPT (base) driver at driver 5481da177e4SLinus Torvalds * load/init time via the mpt_register() API call. 5491da177e4SLinus Torvalds * 5501da177e4SLinus Torvalds * Returns 1 indicating alloc'd request frame ptr should be freed. 5511da177e4SLinus Torvalds */ 5520d0c7974SMoore, Eric Dean int 5531da177e4SLinus Torvalds mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) 5541da177e4SLinus Torvalds { 5551da177e4SLinus Torvalds struct scsi_cmnd *sc; 5561da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 5571da177e4SLinus Torvalds SCSIIORequest_t *pScsiReq; 5581da177e4SLinus Torvalds SCSIIOReply_t *pScsiReply; 5591da177e4SLinus Torvalds u16 req_idx; 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds hd = (MPT_SCSI_HOST *) ioc->sh->hostdata; 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 5641da177e4SLinus Torvalds sc = hd->ScsiLookup[req_idx]; 5651da177e4SLinus Torvalds if (sc == NULL) { 5661da177e4SLinus Torvalds MPIHeader_t *hdr = (MPIHeader_t *)mf; 5671da177e4SLinus Torvalds 5681da177e4SLinus Torvalds /* Remark: writeSDP1 will use the ScsiDoneCtx 5691da177e4SLinus Torvalds * If a SCSI I/O cmd, device disabled by OS and 5701da177e4SLinus Torvalds * completion done. Cannot touch sc struct. Just free mem. 5711da177e4SLinus Torvalds */ 5721da177e4SLinus Torvalds if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST) 5731da177e4SLinus Torvalds printk(MYIOC_s_ERR_FMT "NULL ScsiCmd ptr!\n", 5741da177e4SLinus Torvalds ioc->name); 5751da177e4SLinus Torvalds 5761da177e4SLinus Torvalds mptscsih_freeChainBuffers(ioc, req_idx); 5771da177e4SLinus Torvalds return 1; 5781da177e4SLinus Torvalds } 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds dmfprintk((MYIOC_s_INFO_FMT 5811da177e4SLinus Torvalds "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n", 5821da177e4SLinus Torvalds ioc->name, mf, mr, sc, req_idx)); 5831da177e4SLinus Torvalds 5841da177e4SLinus Torvalds sc->result = DID_OK << 16; /* Set default reply as OK */ 5851da177e4SLinus Torvalds pScsiReq = (SCSIIORequest_t *) mf; 5861da177e4SLinus Torvalds pScsiReply = (SCSIIOReply_t *) mr; 5871da177e4SLinus Torvalds 5881da177e4SLinus Torvalds if (pScsiReply == NULL) { 5891da177e4SLinus Torvalds /* special context reply handling */ 5901da177e4SLinus Torvalds ; 5911da177e4SLinus Torvalds } else { 5921da177e4SLinus Torvalds u32 xfer_cnt; 5931da177e4SLinus Torvalds u16 status; 5941da177e4SLinus Torvalds u8 scsi_state, scsi_status; 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvalds status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK; 5971da177e4SLinus Torvalds scsi_state = pScsiReply->SCSIState; 5981da177e4SLinus Torvalds scsi_status = pScsiReply->SCSIStatus; 5991da177e4SLinus Torvalds xfer_cnt = le32_to_cpu(pScsiReply->TransferCount); 6001da177e4SLinus Torvalds sc->resid = sc->request_bufflen - xfer_cnt; 6011da177e4SLinus Torvalds 6021da177e4SLinus Torvalds dreplyprintk((KERN_NOTICE "Reply ha=%d id=%d lun=%d:\n" 6031da177e4SLinus Torvalds "IOCStatus=%04xh SCSIState=%02xh SCSIStatus=%02xh\n" 6041da177e4SLinus Torvalds "resid=%d bufflen=%d xfer_cnt=%d\n", 6051da177e4SLinus Torvalds ioc->id, pScsiReq->TargetID, pScsiReq->LUN[1], 6061da177e4SLinus Torvalds status, scsi_state, scsi_status, sc->resid, 6071da177e4SLinus Torvalds sc->request_bufflen, xfer_cnt)); 6081da177e4SLinus Torvalds 6091da177e4SLinus Torvalds if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) 6100d0c7974SMoore, Eric Dean mptscsih_copy_sense_data(sc, hd, mf, pScsiReply); 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds /* 6131da177e4SLinus Torvalds * Look for + dump FCP ResponseInfo[]! 6141da177e4SLinus Torvalds */ 6151da177e4SLinus Torvalds if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID) { 6161da177e4SLinus Torvalds printk(KERN_NOTICE " FCP_ResponseInfo=%08xh\n", 6171da177e4SLinus Torvalds le32_to_cpu(pScsiReply->ResponseInfo)); 6181da177e4SLinus Torvalds } 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds switch(status) { 6211da177e4SLinus Torvalds case MPI_IOCSTATUS_BUSY: /* 0x0002 */ 6221da177e4SLinus Torvalds /* CHECKME! 6231da177e4SLinus Torvalds * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry) 6241da177e4SLinus Torvalds * But not: DID_BUS_BUSY lest one risk 6251da177e4SLinus Torvalds * killing interrupt handler:-( 6261da177e4SLinus Torvalds */ 6271da177e4SLinus Torvalds sc->result = SAM_STAT_BUSY; 6281da177e4SLinus Torvalds break; 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */ 6311da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */ 6321da177e4SLinus Torvalds sc->result = DID_BAD_TARGET << 16; 6331da177e4SLinus Torvalds break; 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */ 6361da177e4SLinus Torvalds /* Spoof to SCSI Selection Timeout! */ 6371da177e4SLinus Torvalds sc->result = DID_NO_CONNECT << 16; 6381da177e4SLinus Torvalds 6391da177e4SLinus Torvalds if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF) 6401da177e4SLinus Torvalds hd->sel_timeout[pScsiReq->TargetID]++; 6411da177e4SLinus Torvalds break; 6421da177e4SLinus Torvalds 6431da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */ 6441da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */ 6451da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */ 6461da177e4SLinus Torvalds /* Linux handles an unsolicited DID_RESET better 6471da177e4SLinus Torvalds * than an unsolicited DID_ABORT. 6481da177e4SLinus Torvalds */ 6491da177e4SLinus Torvalds sc->result = DID_RESET << 16; 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds /* GEM Workaround. */ 6521da177e4SLinus Torvalds if (ioc->bus_type == SCSI) 6531da177e4SLinus Torvalds mptscsih_no_negotiate(hd, sc->device->id); 6541da177e4SLinus Torvalds break; 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */ 6571da177e4SLinus Torvalds if ( xfer_cnt >= sc->underflow ) { 6581da177e4SLinus Torvalds /* Sufficient data transfer occurred */ 6591da177e4SLinus Torvalds sc->result = (DID_OK << 16) | scsi_status; 6601da177e4SLinus Torvalds } else if ( xfer_cnt == 0 ) { 6611da177e4SLinus Torvalds /* A CRC Error causes this condition; retry */ 6621da177e4SLinus Torvalds sc->result = (DRIVER_SENSE << 24) | (DID_OK << 16) | 6631da177e4SLinus Torvalds (CHECK_CONDITION << 1); 6641da177e4SLinus Torvalds sc->sense_buffer[0] = 0x70; 6651da177e4SLinus Torvalds sc->sense_buffer[2] = NO_SENSE; 6661da177e4SLinus Torvalds sc->sense_buffer[12] = 0; 6671da177e4SLinus Torvalds sc->sense_buffer[13] = 0; 6681da177e4SLinus Torvalds } else { 6691da177e4SLinus Torvalds sc->result = DID_SOFT_ERROR << 16; 6701da177e4SLinus Torvalds } 6711da177e4SLinus Torvalds dreplyprintk((KERN_NOTICE "RESIDUAL_MISMATCH: result=%x on id=%d\n", sc->result, sc->target)); 6721da177e4SLinus Torvalds break; 6731da177e4SLinus Torvalds 6741da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */ 6751da177e4SLinus Torvalds /* 6761da177e4SLinus Torvalds * Do upfront check for valid SenseData and give it 6771da177e4SLinus Torvalds * precedence! 6781da177e4SLinus Torvalds */ 6791da177e4SLinus Torvalds sc->result = (DID_OK << 16) | scsi_status; 6801da177e4SLinus Torvalds if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) { 6811da177e4SLinus Torvalds /* Have already saved the status and sense data 6821da177e4SLinus Torvalds */ 6831da177e4SLinus Torvalds ; 6841da177e4SLinus Torvalds } else { 6851da177e4SLinus Torvalds if (xfer_cnt < sc->underflow) { 6861da177e4SLinus Torvalds sc->result = DID_SOFT_ERROR << 16; 6871da177e4SLinus Torvalds } 6881da177e4SLinus Torvalds if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) { 6891da177e4SLinus Torvalds /* What to do? 6901da177e4SLinus Torvalds */ 6911da177e4SLinus Torvalds sc->result = DID_SOFT_ERROR << 16; 6921da177e4SLinus Torvalds } 6931da177e4SLinus Torvalds else if (scsi_state & MPI_SCSI_STATE_TERMINATED) { 6941da177e4SLinus Torvalds /* Not real sure here either... */ 6951da177e4SLinus Torvalds sc->result = DID_RESET << 16; 6961da177e4SLinus Torvalds } 6971da177e4SLinus Torvalds } 6981da177e4SLinus Torvalds 6991da177e4SLinus Torvalds dreplyprintk((KERN_NOTICE " sc->underflow={report ERR if < %02xh bytes xfer'd}\n", 7001da177e4SLinus Torvalds sc->underflow)); 7011da177e4SLinus Torvalds dreplyprintk((KERN_NOTICE " ActBytesXferd=%02xh\n", xfer_cnt)); 7021da177e4SLinus Torvalds /* Report Queue Full 7031da177e4SLinus Torvalds */ 7041da177e4SLinus Torvalds if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL) 7051da177e4SLinus Torvalds mptscsih_report_queue_full(sc, pScsiReply, pScsiReq); 7061da177e4SLinus Torvalds 7071da177e4SLinus Torvalds break; 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */ 7101da177e4SLinus Torvalds case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */ 7111da177e4SLinus Torvalds scsi_status = pScsiReply->SCSIStatus; 7121da177e4SLinus Torvalds sc->result = (DID_OK << 16) | scsi_status; 7131da177e4SLinus Torvalds if (scsi_state == 0) { 7141da177e4SLinus Torvalds ; 7151da177e4SLinus Torvalds } else if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) { 7161da177e4SLinus Torvalds /* 7171da177e4SLinus Torvalds * If running against circa 200003dd 909 MPT f/w, 7181da177e4SLinus Torvalds * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL 7191da177e4SLinus Torvalds * (QUEUE_FULL) returned from device! --> get 0x0000?128 7201da177e4SLinus Torvalds * and with SenseBytes set to 0. 7211da177e4SLinus Torvalds */ 7221da177e4SLinus Torvalds if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL) 7231da177e4SLinus Torvalds mptscsih_report_queue_full(sc, pScsiReply, pScsiReq); 7241da177e4SLinus Torvalds 7251da177e4SLinus Torvalds } 7261da177e4SLinus Torvalds else if (scsi_state & 7271da177e4SLinus Torvalds (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS) 7281da177e4SLinus Torvalds ) { 7291da177e4SLinus Torvalds /* 7301da177e4SLinus Torvalds * What to do? 7311da177e4SLinus Torvalds */ 7321da177e4SLinus Torvalds sc->result = DID_SOFT_ERROR << 16; 7331da177e4SLinus Torvalds } 7341da177e4SLinus Torvalds else if (scsi_state & MPI_SCSI_STATE_TERMINATED) { 7351da177e4SLinus Torvalds /* Not real sure here either... */ 7361da177e4SLinus Torvalds sc->result = DID_RESET << 16; 7371da177e4SLinus Torvalds } 7381da177e4SLinus Torvalds else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) { 7391da177e4SLinus Torvalds /* Device Inq. data indicates that it supports 7401da177e4SLinus Torvalds * QTags, but rejects QTag messages. 7411da177e4SLinus Torvalds * This command completed OK. 7421da177e4SLinus Torvalds * 7431da177e4SLinus Torvalds * Not real sure here either so do nothing... */ 7441da177e4SLinus Torvalds } 7451da177e4SLinus Torvalds 7461da177e4SLinus Torvalds if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL) 7471da177e4SLinus Torvalds mptscsih_report_queue_full(sc, pScsiReply, pScsiReq); 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds /* Add handling of: 7501da177e4SLinus Torvalds * Reservation Conflict, Busy, 7511da177e4SLinus Torvalds * Command Terminated, CHECK 7521da177e4SLinus Torvalds */ 7531da177e4SLinus Torvalds break; 7541da177e4SLinus Torvalds 7551da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */ 7561da177e4SLinus Torvalds sc->result = DID_SOFT_ERROR << 16; 7571da177e4SLinus Torvalds break; 7581da177e4SLinus Torvalds 7591da177e4SLinus Torvalds case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */ 7601da177e4SLinus Torvalds case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */ 7611da177e4SLinus Torvalds case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */ 7621da177e4SLinus Torvalds case MPI_IOCSTATUS_RESERVED: /* 0x0005 */ 7631da177e4SLinus Torvalds case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */ 7641da177e4SLinus Torvalds case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */ 7651da177e4SLinus Torvalds case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */ 7661da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */ 7671da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */ 7681da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */ 7691da177e4SLinus Torvalds default: 7701da177e4SLinus Torvalds /* 7711da177e4SLinus Torvalds * What to do? 7721da177e4SLinus Torvalds */ 7731da177e4SLinus Torvalds sc->result = DID_SOFT_ERROR << 16; 7741da177e4SLinus Torvalds break; 7751da177e4SLinus Torvalds 7761da177e4SLinus Torvalds } /* switch(status) */ 7771da177e4SLinus Torvalds 7781da177e4SLinus Torvalds dreplyprintk((KERN_NOTICE " sc->result is %08xh\n", sc->result)); 7791da177e4SLinus Torvalds } /* end of address reply case */ 7801da177e4SLinus Torvalds 7811da177e4SLinus Torvalds /* Unmap the DMA buffers, if any. */ 7821da177e4SLinus Torvalds if (sc->use_sg) { 7831da177e4SLinus Torvalds pci_unmap_sg(ioc->pcidev, (struct scatterlist *) sc->request_buffer, 7841da177e4SLinus Torvalds sc->use_sg, sc->sc_data_direction); 7851da177e4SLinus Torvalds } else if (sc->request_bufflen) { 7861da177e4SLinus Torvalds pci_unmap_single(ioc->pcidev, sc->SCp.dma_handle, 7871da177e4SLinus Torvalds sc->request_bufflen, sc->sc_data_direction); 7881da177e4SLinus Torvalds } 7891da177e4SLinus Torvalds 7901da177e4SLinus Torvalds hd->ScsiLookup[req_idx] = NULL; 7911da177e4SLinus Torvalds 7921da177e4SLinus Torvalds sc->scsi_done(sc); /* Issue the command callback */ 7931da177e4SLinus Torvalds 7941da177e4SLinus Torvalds /* Free Chain buffers */ 7951da177e4SLinus Torvalds mptscsih_freeChainBuffers(ioc, req_idx); 7961da177e4SLinus Torvalds return 1; 7971da177e4SLinus Torvalds } 7981da177e4SLinus Torvalds 7991da177e4SLinus Torvalds 8001da177e4SLinus Torvalds /* 8011da177e4SLinus Torvalds * mptscsih_flush_running_cmds - For each command found, search 8021da177e4SLinus Torvalds * Scsi_Host instance taskQ and reply to OS. 8031da177e4SLinus Torvalds * Called only if recovering from a FW reload. 8041da177e4SLinus Torvalds * @hd: Pointer to a SCSI HOST structure 8051da177e4SLinus Torvalds * 8061da177e4SLinus Torvalds * Returns: None. 8071da177e4SLinus Torvalds * 8081da177e4SLinus Torvalds * Must be called while new I/Os are being queued. 8091da177e4SLinus Torvalds */ 8101da177e4SLinus Torvalds static void 8111da177e4SLinus Torvalds mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd) 8121da177e4SLinus Torvalds { 8131da177e4SLinus Torvalds MPT_ADAPTER *ioc = hd->ioc; 8141da177e4SLinus Torvalds struct scsi_cmnd *SCpnt; 8151da177e4SLinus Torvalds MPT_FRAME_HDR *mf; 8161da177e4SLinus Torvalds int ii; 8171da177e4SLinus Torvalds int max = ioc->req_depth; 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds dprintk((KERN_INFO MYNAM ": flush_ScsiLookup called\n")); 8201da177e4SLinus Torvalds for (ii= 0; ii < max; ii++) { 8211da177e4SLinus Torvalds if ((SCpnt = hd->ScsiLookup[ii]) != NULL) { 8221da177e4SLinus Torvalds 8231da177e4SLinus Torvalds /* Command found. 8241da177e4SLinus Torvalds */ 8251da177e4SLinus Torvalds 8261da177e4SLinus Torvalds /* Null ScsiLookup index 8271da177e4SLinus Torvalds */ 8281da177e4SLinus Torvalds hd->ScsiLookup[ii] = NULL; 8291da177e4SLinus Torvalds 8301da177e4SLinus Torvalds mf = MPT_INDEX_2_MFPTR(ioc, ii); 8311da177e4SLinus Torvalds dmfprintk(( "flush: ScsiDone (mf=%p,sc=%p)\n", 8321da177e4SLinus Torvalds mf, SCpnt)); 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds /* Set status, free OS resources (SG DMA buffers) 8351da177e4SLinus Torvalds * Do OS callback 8361da177e4SLinus Torvalds * Free driver resources (chain, msg buffers) 8371da177e4SLinus Torvalds */ 8381da177e4SLinus Torvalds if (SCpnt->use_sg) { 8391da177e4SLinus Torvalds pci_unmap_sg(ioc->pcidev, 8401da177e4SLinus Torvalds (struct scatterlist *) SCpnt->request_buffer, 8411da177e4SLinus Torvalds SCpnt->use_sg, 8421da177e4SLinus Torvalds SCpnt->sc_data_direction); 8431da177e4SLinus Torvalds } else if (SCpnt->request_bufflen) { 8441da177e4SLinus Torvalds pci_unmap_single(ioc->pcidev, 8451da177e4SLinus Torvalds SCpnt->SCp.dma_handle, 8461da177e4SLinus Torvalds SCpnt->request_bufflen, 8471da177e4SLinus Torvalds SCpnt->sc_data_direction); 8481da177e4SLinus Torvalds } 8491da177e4SLinus Torvalds SCpnt->result = DID_RESET << 16; 8501da177e4SLinus Torvalds SCpnt->host_scribble = NULL; 8511da177e4SLinus Torvalds 8521da177e4SLinus Torvalds /* Free Chain buffers */ 8531da177e4SLinus Torvalds mptscsih_freeChainBuffers(ioc, ii); 8541da177e4SLinus Torvalds 8551da177e4SLinus Torvalds /* Free Message frames */ 8561da177e4SLinus Torvalds mpt_free_msg_frame(ioc, mf); 8571da177e4SLinus Torvalds 8581da177e4SLinus Torvalds SCpnt->scsi_done(SCpnt); /* Issue the command callback */ 8591da177e4SLinus Torvalds } 8601da177e4SLinus Torvalds } 8611da177e4SLinus Torvalds 8621da177e4SLinus Torvalds return; 8631da177e4SLinus Torvalds } 8641da177e4SLinus Torvalds 8651da177e4SLinus Torvalds /* 8661da177e4SLinus Torvalds * mptscsih_search_running_cmds - Delete any commands associated 8671da177e4SLinus Torvalds * with the specified target and lun. Function called only 8681da177e4SLinus Torvalds * when a lun is disable by mid-layer. 8691da177e4SLinus Torvalds * Do NOT access the referenced scsi_cmnd structure or 8701da177e4SLinus Torvalds * members. Will cause either a paging or NULL ptr error. 8711da177e4SLinus Torvalds * @hd: Pointer to a SCSI HOST structure 8721da177e4SLinus Torvalds * @target: target id 8731da177e4SLinus Torvalds * @lun: lun 8741da177e4SLinus Torvalds * 8751da177e4SLinus Torvalds * Returns: None. 8761da177e4SLinus Torvalds * 8771da177e4SLinus Torvalds * Called from slave_destroy. 8781da177e4SLinus Torvalds */ 8791da177e4SLinus Torvalds static void 8801da177e4SLinus Torvalds mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, uint target, uint lun) 8811da177e4SLinus Torvalds { 8821da177e4SLinus Torvalds SCSIIORequest_t *mf = NULL; 8831da177e4SLinus Torvalds int ii; 8841da177e4SLinus Torvalds int max = hd->ioc->req_depth; 8851da177e4SLinus Torvalds 8861da177e4SLinus Torvalds dsprintk((KERN_INFO MYNAM ": search_running target %d lun %d max %d\n", 8871da177e4SLinus Torvalds target, lun, max)); 8881da177e4SLinus Torvalds 8891da177e4SLinus Torvalds for (ii=0; ii < max; ii++) { 8901da177e4SLinus Torvalds if (hd->ScsiLookup[ii] != NULL) { 8911da177e4SLinus Torvalds 8921da177e4SLinus Torvalds mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(hd->ioc, ii); 8931da177e4SLinus Torvalds 8941da177e4SLinus Torvalds dsprintk(( "search_running: found (sc=%p, mf = %p) target %d, lun %d \n", 8951da177e4SLinus Torvalds hd->ScsiLookup[ii], mf, mf->TargetID, mf->LUN[1])); 8961da177e4SLinus Torvalds 8971da177e4SLinus Torvalds if ((mf->TargetID != ((u8)target)) || (mf->LUN[1] != ((u8) lun))) 8981da177e4SLinus Torvalds continue; 8991da177e4SLinus Torvalds 9001da177e4SLinus Torvalds /* Cleanup 9011da177e4SLinus Torvalds */ 9021da177e4SLinus Torvalds hd->ScsiLookup[ii] = NULL; 9031da177e4SLinus Torvalds mptscsih_freeChainBuffers(hd->ioc, ii); 9041da177e4SLinus Torvalds mpt_free_msg_frame(hd->ioc, (MPT_FRAME_HDR *)mf); 9051da177e4SLinus Torvalds } 9061da177e4SLinus Torvalds } 9071da177e4SLinus Torvalds 9081da177e4SLinus Torvalds return; 9091da177e4SLinus Torvalds } 9101da177e4SLinus Torvalds 9111da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 9121da177e4SLinus Torvalds 9131da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 9141da177e4SLinus Torvalds /* 9151da177e4SLinus Torvalds * mptscsih_report_queue_full - Report QUEUE_FULL status returned 9161da177e4SLinus Torvalds * from a SCSI target device. 9171da177e4SLinus Torvalds * @sc: Pointer to scsi_cmnd structure 9181da177e4SLinus Torvalds * @pScsiReply: Pointer to SCSIIOReply_t 9191da177e4SLinus Torvalds * @pScsiReq: Pointer to original SCSI request 9201da177e4SLinus Torvalds * 9211da177e4SLinus Torvalds * This routine periodically reports QUEUE_FULL status returned from a 9221da177e4SLinus Torvalds * SCSI target device. It reports this to the console via kernel 9231da177e4SLinus Torvalds * printk() API call, not more than once every 10 seconds. 9241da177e4SLinus Torvalds */ 9251da177e4SLinus Torvalds static void 9261da177e4SLinus Torvalds mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq) 9271da177e4SLinus Torvalds { 9281da177e4SLinus Torvalds long time = jiffies; 9291da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 9301da177e4SLinus Torvalds 9310d0c7974SMoore, Eric Dean if (sc->device == NULL) 9320d0c7974SMoore, Eric Dean return; 9330d0c7974SMoore, Eric Dean if (sc->device->host == NULL) 9340d0c7974SMoore, Eric Dean return; 9350d0c7974SMoore, Eric Dean if ((hd = (MPT_SCSI_HOST *)sc->device->host->hostdata) == NULL) 9360d0c7974SMoore, Eric Dean return; 9371da177e4SLinus Torvalds 9380d0c7974SMoore, Eric Dean if (time - hd->last_queue_full > 10 * HZ) { 9390d0c7974SMoore, Eric Dean dprintk((MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n", 9400d0c7974SMoore, Eric Dean hd->ioc->name, 0, sc->device->id, sc->device->lun)); 9410d0c7974SMoore, Eric Dean hd->last_queue_full = time; 9421da177e4SLinus Torvalds } 9431da177e4SLinus Torvalds } 9441da177e4SLinus Torvalds 9451da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 9461da177e4SLinus Torvalds /* 9471da177e4SLinus Torvalds * mptscsih_remove - Removed scsi devices 9481da177e4SLinus Torvalds * @pdev: Pointer to pci_dev structure 9491da177e4SLinus Torvalds * 9501da177e4SLinus Torvalds * 9511da177e4SLinus Torvalds */ 9520d0c7974SMoore, Eric Dean void 9531da177e4SLinus Torvalds mptscsih_remove(struct pci_dev *pdev) 9541da177e4SLinus Torvalds { 9551da177e4SLinus Torvalds MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 9561da177e4SLinus Torvalds struct Scsi_Host *host = ioc->sh; 9571da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 9581da177e4SLinus Torvalds int count; 9591da177e4SLinus Torvalds unsigned long flags; 9600d0c7974SMoore, Eric Dean int sz1; 9611da177e4SLinus Torvalds 9621da177e4SLinus Torvalds if(!host) 9631da177e4SLinus Torvalds return; 9641da177e4SLinus Torvalds 9651da177e4SLinus Torvalds scsi_remove_host(host); 9661da177e4SLinus Torvalds 9670d0c7974SMoore, Eric Dean if((hd = (MPT_SCSI_HOST *)host->hostdata) == NULL) 9680d0c7974SMoore, Eric Dean return; 9690d0c7974SMoore, Eric Dean 9701da177e4SLinus Torvalds #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION 9711da177e4SLinus Torvalds /* Check DV thread active */ 9721da177e4SLinus Torvalds count = 10 * HZ; 9731da177e4SLinus Torvalds spin_lock_irqsave(&dvtaskQ_lock, flags); 9741da177e4SLinus Torvalds if (dvtaskQ_active) { 9751da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, flags); 9761da177e4SLinus Torvalds while(dvtaskQ_active && --count) { 9771da177e4SLinus Torvalds set_current_state(TASK_INTERRUPTIBLE); 9781da177e4SLinus Torvalds schedule_timeout(1); 9791da177e4SLinus Torvalds } 9801da177e4SLinus Torvalds } else { 9811da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, flags); 9821da177e4SLinus Torvalds } 9831da177e4SLinus Torvalds if (!count) 9841da177e4SLinus Torvalds printk(KERN_ERR MYNAM ": ERROR - DV thread still active!\n"); 9851da177e4SLinus Torvalds #if defined(MPT_DEBUG_DV) || defined(MPT_DEBUG_DV_TINY) 9861da177e4SLinus Torvalds else 9871da177e4SLinus Torvalds printk(KERN_ERR MYNAM ": DV thread orig %d, count %d\n", 10 * HZ, count); 9881da177e4SLinus Torvalds #endif 9891da177e4SLinus Torvalds #endif 9901da177e4SLinus Torvalds 9911da177e4SLinus Torvalds mptscsih_shutdown(&pdev->dev); 9921da177e4SLinus Torvalds 9931da177e4SLinus Torvalds sz1=0; 9941da177e4SLinus Torvalds 9951da177e4SLinus Torvalds if (hd->ScsiLookup != NULL) { 9961da177e4SLinus Torvalds sz1 = hd->ioc->req_depth * sizeof(void *); 9971da177e4SLinus Torvalds kfree(hd->ScsiLookup); 9981da177e4SLinus Torvalds hd->ScsiLookup = NULL; 9991da177e4SLinus Torvalds } 10001da177e4SLinus Torvalds 10011da177e4SLinus Torvalds /* 10021da177e4SLinus Torvalds * Free pointer array. 10031da177e4SLinus Torvalds */ 10041da177e4SLinus Torvalds kfree(hd->Targets); 10051da177e4SLinus Torvalds hd->Targets = NULL; 10061da177e4SLinus Torvalds 10071da177e4SLinus Torvalds dprintk((MYIOC_s_INFO_FMT 10081da177e4SLinus Torvalds "Free'd ScsiLookup (%d) memory\n", 10091da177e4SLinus Torvalds hd->ioc->name, sz1)); 10101da177e4SLinus Torvalds 10110d0c7974SMoore, Eric Dean kfree(hd->info_kbuf); 10120d0c7974SMoore, Eric Dean 10131da177e4SLinus Torvalds /* NULL the Scsi_Host pointer 10141da177e4SLinus Torvalds */ 10151da177e4SLinus Torvalds hd->ioc->sh = NULL; 10161da177e4SLinus Torvalds 10171da177e4SLinus Torvalds scsi_host_put(host); 10180d0c7974SMoore, Eric Dean 10190d0c7974SMoore, Eric Dean mpt_detach(pdev); 10201da177e4SLinus Torvalds 10211da177e4SLinus Torvalds } 10221da177e4SLinus Torvalds 10231da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10241da177e4SLinus Torvalds /* 10251da177e4SLinus Torvalds * mptscsih_shutdown - reboot notifier 10261da177e4SLinus Torvalds * 10271da177e4SLinus Torvalds */ 10280d0c7974SMoore, Eric Dean void 10291da177e4SLinus Torvalds mptscsih_shutdown(struct device * dev) 10301da177e4SLinus Torvalds { 10311da177e4SLinus Torvalds MPT_ADAPTER *ioc = pci_get_drvdata(to_pci_dev(dev)); 10321da177e4SLinus Torvalds struct Scsi_Host *host = ioc->sh; 10331da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 10341da177e4SLinus Torvalds 10351da177e4SLinus Torvalds if(!host) 10361da177e4SLinus Torvalds return; 10371da177e4SLinus Torvalds 10381da177e4SLinus Torvalds hd = (MPT_SCSI_HOST *)host->hostdata; 10391da177e4SLinus Torvalds 10401da177e4SLinus Torvalds /* Flush the cache of this adapter 10411da177e4SLinus Torvalds */ 10421da177e4SLinus Torvalds if(hd != NULL) 10431da177e4SLinus Torvalds mptscsih_synchronize_cache(hd, 0); 10441da177e4SLinus Torvalds 10451da177e4SLinus Torvalds } 10461da177e4SLinus Torvalds 10471da177e4SLinus Torvalds #ifdef CONFIG_PM 10481da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10491da177e4SLinus Torvalds /* 10500d0c7974SMoore, Eric Dean * mptscsih_suspend - Fusion MPT scsi driver suspend routine. 10511da177e4SLinus Torvalds * 10521da177e4SLinus Torvalds * 10531da177e4SLinus Torvalds */ 10540d0c7974SMoore, Eric Dean int 10558d189f72SPavel Machek mptscsih_suspend(struct pci_dev *pdev, pm_message_t state) 10561da177e4SLinus Torvalds { 10571da177e4SLinus Torvalds mptscsih_shutdown(&pdev->dev); 10580d0c7974SMoore, Eric Dean return mpt_suspend(pdev,state); 10591da177e4SLinus Torvalds } 10601da177e4SLinus Torvalds 10611da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10621da177e4SLinus Torvalds /* 10631da177e4SLinus Torvalds * mptscsih_resume - Fusion MPT scsi driver resume routine. 10641da177e4SLinus Torvalds * 10651da177e4SLinus Torvalds * 10661da177e4SLinus Torvalds */ 10670d0c7974SMoore, Eric Dean int 10681da177e4SLinus Torvalds mptscsih_resume(struct pci_dev *pdev) 10691da177e4SLinus Torvalds { 10701da177e4SLinus Torvalds MPT_ADAPTER *ioc = pci_get_drvdata(pdev); 10711da177e4SLinus Torvalds struct Scsi_Host *host = ioc->sh; 10721da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 10731da177e4SLinus Torvalds 10740d0c7974SMoore, Eric Dean mpt_resume(pdev); 10750d0c7974SMoore, Eric Dean 10761da177e4SLinus Torvalds if(!host) 10771da177e4SLinus Torvalds return 0; 10781da177e4SLinus Torvalds 10791da177e4SLinus Torvalds hd = (MPT_SCSI_HOST *)host->hostdata; 10801da177e4SLinus Torvalds if(!hd) 10811da177e4SLinus Torvalds return 0; 10821da177e4SLinus Torvalds 10831da177e4SLinus Torvalds #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION 10841da177e4SLinus Torvalds { 10851da177e4SLinus Torvalds unsigned long lflags; 10861da177e4SLinus Torvalds spin_lock_irqsave(&dvtaskQ_lock, lflags); 10871da177e4SLinus Torvalds if (!dvtaskQ_active) { 10881da177e4SLinus Torvalds dvtaskQ_active = 1; 10891da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, lflags); 10900d0c7974SMoore, Eric Dean INIT_WORK(&dvTaskQ_task, 10911da177e4SLinus Torvalds mptscsih_domainValidation, (void *) hd); 10920d0c7974SMoore, Eric Dean schedule_work(&dvTaskQ_task); 10931da177e4SLinus Torvalds } else { 10941da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, lflags); 10951da177e4SLinus Torvalds } 10961da177e4SLinus Torvalds } 10971da177e4SLinus Torvalds #endif 10981da177e4SLinus Torvalds return 0; 10991da177e4SLinus Torvalds } 11001da177e4SLinus Torvalds 11011da177e4SLinus Torvalds #endif 11021da177e4SLinus Torvalds 11031da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 11041da177e4SLinus Torvalds /** 11051da177e4SLinus Torvalds * mptscsih_info - Return information about MPT adapter 11061da177e4SLinus Torvalds * @SChost: Pointer to Scsi_Host structure 11071da177e4SLinus Torvalds * 11081da177e4SLinus Torvalds * (linux scsi_host_template.info routine) 11091da177e4SLinus Torvalds * 11101da177e4SLinus Torvalds * Returns pointer to buffer where information was written. 11111da177e4SLinus Torvalds */ 11120d0c7974SMoore, Eric Dean const char * 11131da177e4SLinus Torvalds mptscsih_info(struct Scsi_Host *SChost) 11141da177e4SLinus Torvalds { 11151da177e4SLinus Torvalds MPT_SCSI_HOST *h; 11161da177e4SLinus Torvalds int size = 0; 11171da177e4SLinus Torvalds 11181da177e4SLinus Torvalds h = (MPT_SCSI_HOST *)SChost->hostdata; 11190d0c7974SMoore, Eric Dean 11201da177e4SLinus Torvalds if (h) { 11210d0c7974SMoore, Eric Dean if (h->info_kbuf == NULL) 11220d0c7974SMoore, Eric Dean if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL) 11230d0c7974SMoore, Eric Dean return h->info_kbuf; 11240d0c7974SMoore, Eric Dean h->info_kbuf[0] = '\0'; 11250d0c7974SMoore, Eric Dean 11260d0c7974SMoore, Eric Dean mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0); 11270d0c7974SMoore, Eric Dean h->info_kbuf[size-1] = '\0'; 11281da177e4SLinus Torvalds } 11291da177e4SLinus Torvalds 11300d0c7974SMoore, Eric Dean return h->info_kbuf; 11311da177e4SLinus Torvalds } 11321da177e4SLinus Torvalds 11331da177e4SLinus Torvalds struct info_str { 11341da177e4SLinus Torvalds char *buffer; 11351da177e4SLinus Torvalds int length; 11361da177e4SLinus Torvalds int offset; 11371da177e4SLinus Torvalds int pos; 11381da177e4SLinus Torvalds }; 11391da177e4SLinus Torvalds 11400d0c7974SMoore, Eric Dean static void 11410d0c7974SMoore, Eric Dean mptscsih_copy_mem_info(struct info_str *info, char *data, int len) 11421da177e4SLinus Torvalds { 11431da177e4SLinus Torvalds if (info->pos + len > info->length) 11441da177e4SLinus Torvalds len = info->length - info->pos; 11451da177e4SLinus Torvalds 11461da177e4SLinus Torvalds if (info->pos + len < info->offset) { 11471da177e4SLinus Torvalds info->pos += len; 11481da177e4SLinus Torvalds return; 11491da177e4SLinus Torvalds } 11501da177e4SLinus Torvalds 11511da177e4SLinus Torvalds if (info->pos < info->offset) { 11521da177e4SLinus Torvalds data += (info->offset - info->pos); 11531da177e4SLinus Torvalds len -= (info->offset - info->pos); 11541da177e4SLinus Torvalds } 11551da177e4SLinus Torvalds 11561da177e4SLinus Torvalds if (len > 0) { 11571da177e4SLinus Torvalds memcpy(info->buffer + info->pos, data, len); 11581da177e4SLinus Torvalds info->pos += len; 11591da177e4SLinus Torvalds } 11601da177e4SLinus Torvalds } 11611da177e4SLinus Torvalds 11620d0c7974SMoore, Eric Dean static int 11630d0c7974SMoore, Eric Dean mptscsih_copy_info(struct info_str *info, char *fmt, ...) 11641da177e4SLinus Torvalds { 11651da177e4SLinus Torvalds va_list args; 11661da177e4SLinus Torvalds char buf[81]; 11671da177e4SLinus Torvalds int len; 11681da177e4SLinus Torvalds 11691da177e4SLinus Torvalds va_start(args, fmt); 11701da177e4SLinus Torvalds len = vsprintf(buf, fmt, args); 11711da177e4SLinus Torvalds va_end(args); 11721da177e4SLinus Torvalds 11730d0c7974SMoore, Eric Dean mptscsih_copy_mem_info(info, buf, len); 11741da177e4SLinus Torvalds return len; 11751da177e4SLinus Torvalds } 11761da177e4SLinus Torvalds 11770d0c7974SMoore, Eric Dean static int 11780d0c7974SMoore, Eric Dean mptscsih_host_info(MPT_ADAPTER *ioc, char *pbuf, off_t offset, int len) 11791da177e4SLinus Torvalds { 11801da177e4SLinus Torvalds struct info_str info; 11811da177e4SLinus Torvalds 11821da177e4SLinus Torvalds info.buffer = pbuf; 11831da177e4SLinus Torvalds info.length = len; 11841da177e4SLinus Torvalds info.offset = offset; 11851da177e4SLinus Torvalds info.pos = 0; 11861da177e4SLinus Torvalds 11870d0c7974SMoore, Eric Dean mptscsih_copy_info(&info, "%s: %s, ", ioc->name, ioc->prod_name); 11880d0c7974SMoore, Eric Dean mptscsih_copy_info(&info, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word); 11890d0c7974SMoore, Eric Dean mptscsih_copy_info(&info, "Ports=%d, ", ioc->facts.NumberOfPorts); 11900d0c7974SMoore, Eric Dean mptscsih_copy_info(&info, "MaxQ=%d\n", ioc->req_depth); 11911da177e4SLinus Torvalds 11921da177e4SLinus Torvalds return ((info.pos > info.offset) ? info.pos - info.offset : 0); 11931da177e4SLinus Torvalds } 11941da177e4SLinus Torvalds 11951da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 11961da177e4SLinus Torvalds /** 11971da177e4SLinus Torvalds * mptscsih_proc_info - Return information about MPT adapter 11981da177e4SLinus Torvalds * 11991da177e4SLinus Torvalds * (linux scsi_host_template.info routine) 12001da177e4SLinus Torvalds * 12011da177e4SLinus Torvalds * buffer: if write, user data; if read, buffer for user 12021da177e4SLinus Torvalds * length: if write, return length; 12031da177e4SLinus Torvalds * offset: if write, 0; if read, the current offset into the buffer from 12041da177e4SLinus Torvalds * the previous read. 12051da177e4SLinus Torvalds * hostno: scsi host number 12061da177e4SLinus Torvalds * func: if write = 1; if read = 0 12071da177e4SLinus Torvalds */ 12080d0c7974SMoore, Eric Dean int 12091da177e4SLinus Torvalds mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, 12101da177e4SLinus Torvalds int length, int func) 12111da177e4SLinus Torvalds { 12121da177e4SLinus Torvalds MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata; 12131da177e4SLinus Torvalds MPT_ADAPTER *ioc = hd->ioc; 12141da177e4SLinus Torvalds int size = 0; 12151da177e4SLinus Torvalds 12161da177e4SLinus Torvalds if (func) { 12171da177e4SLinus Torvalds /* 12181da177e4SLinus Torvalds * write is not supported 12191da177e4SLinus Torvalds */ 12201da177e4SLinus Torvalds } else { 12211da177e4SLinus Torvalds if (start) 12221da177e4SLinus Torvalds *start = buffer; 12231da177e4SLinus Torvalds 12241da177e4SLinus Torvalds size = mptscsih_host_info(ioc, buffer, offset, length); 12251da177e4SLinus Torvalds } 12261da177e4SLinus Torvalds 12271da177e4SLinus Torvalds return size; 12281da177e4SLinus Torvalds } 12291da177e4SLinus Torvalds 12301da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 12311da177e4SLinus Torvalds #define ADD_INDEX_LOG(req_ent) do { } while(0) 12321da177e4SLinus Torvalds 12331da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 12341da177e4SLinus Torvalds /** 12351da177e4SLinus Torvalds * mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine. 12361da177e4SLinus Torvalds * @SCpnt: Pointer to scsi_cmnd structure 12371da177e4SLinus Torvalds * @done: Pointer SCSI mid-layer IO completion function 12381da177e4SLinus Torvalds * 12391da177e4SLinus Torvalds * (linux scsi_host_template.queuecommand routine) 12401da177e4SLinus Torvalds * This is the primary SCSI IO start routine. Create a MPI SCSIIORequest 12411da177e4SLinus Torvalds * from a linux scsi_cmnd request and send it to the IOC. 12421da177e4SLinus Torvalds * 12431da177e4SLinus Torvalds * Returns 0. (rtn value discarded by linux scsi mid-layer) 12441da177e4SLinus Torvalds */ 12450d0c7974SMoore, Eric Dean int 12461da177e4SLinus Torvalds mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 12471da177e4SLinus Torvalds { 12481da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 12491da177e4SLinus Torvalds MPT_FRAME_HDR *mf; 12501da177e4SLinus Torvalds SCSIIORequest_t *pScsiReq; 12511da177e4SLinus Torvalds VirtDevice *pTarget; 12521da177e4SLinus Torvalds int target; 12531da177e4SLinus Torvalds int lun; 12541da177e4SLinus Torvalds u32 datalen; 12551da177e4SLinus Torvalds u32 scsictl; 12561da177e4SLinus Torvalds u32 scsidir; 12571da177e4SLinus Torvalds u32 cmd_len; 12581da177e4SLinus Torvalds int my_idx; 12591da177e4SLinus Torvalds int ii; 12601da177e4SLinus Torvalds 12611da177e4SLinus Torvalds hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata; 12621da177e4SLinus Torvalds target = SCpnt->device->id; 12631da177e4SLinus Torvalds lun = SCpnt->device->lun; 12641da177e4SLinus Torvalds SCpnt->scsi_done = done; 12651da177e4SLinus Torvalds 12661da177e4SLinus Torvalds pTarget = hd->Targets[target]; 12671da177e4SLinus Torvalds 12681da177e4SLinus Torvalds dmfprintk((MYIOC_s_INFO_FMT "qcmd: SCpnt=%p, done()=%p\n", 12691da177e4SLinus Torvalds (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt, done)); 12701da177e4SLinus Torvalds 12711da177e4SLinus Torvalds if (hd->resetPending) { 12721da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT "qcmd: SCpnt=%p timeout + 60HZ\n", 12731da177e4SLinus Torvalds (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt)); 12741da177e4SLinus Torvalds return SCSI_MLQUEUE_HOST_BUSY; 12751da177e4SLinus Torvalds } 12761da177e4SLinus Torvalds 12771da177e4SLinus Torvalds /* 12781da177e4SLinus Torvalds * Put together a MPT SCSI request... 12791da177e4SLinus Torvalds */ 12800d0c7974SMoore, Eric Dean if ((mf = mpt_get_msg_frame(hd->ioc->DoneCtx, hd->ioc)) == NULL) { 12811da177e4SLinus Torvalds dprintk((MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n", 12821da177e4SLinus Torvalds hd->ioc->name)); 12831da177e4SLinus Torvalds return SCSI_MLQUEUE_HOST_BUSY; 12841da177e4SLinus Torvalds } 12851da177e4SLinus Torvalds 12861da177e4SLinus Torvalds pScsiReq = (SCSIIORequest_t *) mf; 12871da177e4SLinus Torvalds 12881da177e4SLinus Torvalds my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 12891da177e4SLinus Torvalds 12901da177e4SLinus Torvalds ADD_INDEX_LOG(my_idx); 12911da177e4SLinus Torvalds 12920d0c7974SMoore, Eric Dean /* TUR's being issued with scsictl=0x02000000 (DATA_IN)! 12931da177e4SLinus Torvalds * Seems we may receive a buffer (datalen>0) even when there 12941da177e4SLinus Torvalds * will be no data transfer! GRRRRR... 12951da177e4SLinus Torvalds */ 12961da177e4SLinus Torvalds if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) { 12971da177e4SLinus Torvalds datalen = SCpnt->request_bufflen; 12981da177e4SLinus Torvalds scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */ 12991da177e4SLinus Torvalds } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) { 13001da177e4SLinus Torvalds datalen = SCpnt->request_bufflen; 13011da177e4SLinus Torvalds scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */ 13021da177e4SLinus Torvalds } else { 13031da177e4SLinus Torvalds datalen = 0; 13041da177e4SLinus Torvalds scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER; 13051da177e4SLinus Torvalds } 13061da177e4SLinus Torvalds 13071da177e4SLinus Torvalds /* Default to untagged. Once a target structure has been allocated, 13081da177e4SLinus Torvalds * use the Inquiry data to determine if device supports tagged. 13091da177e4SLinus Torvalds */ 13101da177e4SLinus Torvalds if ( pTarget 13111da177e4SLinus Torvalds && (pTarget->tflags & MPT_TARGET_FLAGS_Q_YES) 13121da177e4SLinus Torvalds && (SCpnt->device->tagged_supported)) { 13131da177e4SLinus Torvalds scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ; 13141da177e4SLinus Torvalds } else { 13151da177e4SLinus Torvalds scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED; 13161da177e4SLinus Torvalds } 13171da177e4SLinus Torvalds 13181da177e4SLinus Torvalds /* Use the above information to set up the message frame 13191da177e4SLinus Torvalds */ 13201da177e4SLinus Torvalds pScsiReq->TargetID = (u8) target; 13211da177e4SLinus Torvalds pScsiReq->Bus = (u8) SCpnt->device->channel; 13221da177e4SLinus Torvalds pScsiReq->ChainOffset = 0; 13231da177e4SLinus Torvalds pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST; 13241da177e4SLinus Torvalds pScsiReq->CDBLength = SCpnt->cmd_len; 13251da177e4SLinus Torvalds pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE; 13261da177e4SLinus Torvalds pScsiReq->Reserved = 0; 13271da177e4SLinus Torvalds pScsiReq->MsgFlags = mpt_msg_flags(); 13281da177e4SLinus Torvalds pScsiReq->LUN[0] = 0; 13291da177e4SLinus Torvalds pScsiReq->LUN[1] = lun; 13301da177e4SLinus Torvalds pScsiReq->LUN[2] = 0; 13311da177e4SLinus Torvalds pScsiReq->LUN[3] = 0; 13321da177e4SLinus Torvalds pScsiReq->LUN[4] = 0; 13331da177e4SLinus Torvalds pScsiReq->LUN[5] = 0; 13341da177e4SLinus Torvalds pScsiReq->LUN[6] = 0; 13351da177e4SLinus Torvalds pScsiReq->LUN[7] = 0; 13361da177e4SLinus Torvalds pScsiReq->Control = cpu_to_le32(scsictl); 13371da177e4SLinus Torvalds 13381da177e4SLinus Torvalds /* 13391da177e4SLinus Torvalds * Write SCSI CDB into the message 13401da177e4SLinus Torvalds */ 13411da177e4SLinus Torvalds cmd_len = SCpnt->cmd_len; 13421da177e4SLinus Torvalds for (ii=0; ii < cmd_len; ii++) 13431da177e4SLinus Torvalds pScsiReq->CDB[ii] = SCpnt->cmnd[ii]; 13441da177e4SLinus Torvalds 13451da177e4SLinus Torvalds for (ii=cmd_len; ii < 16; ii++) 13461da177e4SLinus Torvalds pScsiReq->CDB[ii] = 0; 13471da177e4SLinus Torvalds 13481da177e4SLinus Torvalds /* DataLength */ 13491da177e4SLinus Torvalds pScsiReq->DataLength = cpu_to_le32(datalen); 13501da177e4SLinus Torvalds 13511da177e4SLinus Torvalds /* SenseBuffer low address */ 13521da177e4SLinus Torvalds pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma 13531da177e4SLinus Torvalds + (my_idx * MPT_SENSE_BUFFER_ALLOC)); 13541da177e4SLinus Torvalds 13551da177e4SLinus Torvalds /* Now add the SG list 13561da177e4SLinus Torvalds * Always have a SGE even if null length. 13571da177e4SLinus Torvalds */ 13581da177e4SLinus Torvalds if (datalen == 0) { 13591da177e4SLinus Torvalds /* Add a NULL SGE */ 13601da177e4SLinus Torvalds mptscsih_add_sge((char *)&pScsiReq->SGL, MPT_SGE_FLAGS_SSIMPLE_READ | 0, 13611da177e4SLinus Torvalds (dma_addr_t) -1); 13621da177e4SLinus Torvalds } else { 13631da177e4SLinus Torvalds /* Add a 32 or 64 bit SGE */ 13641da177e4SLinus Torvalds if (mptscsih_AddSGE(hd->ioc, SCpnt, pScsiReq, my_idx) != SUCCESS) 13651da177e4SLinus Torvalds goto fail; 13661da177e4SLinus Torvalds } 13671da177e4SLinus Torvalds 13681da177e4SLinus Torvalds hd->ScsiLookup[my_idx] = SCpnt; 13691da177e4SLinus Torvalds SCpnt->host_scribble = NULL; 13701da177e4SLinus Torvalds 13711da177e4SLinus Torvalds #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION 13721da177e4SLinus Torvalds if (hd->ioc->bus_type == SCSI) { 13731da177e4SLinus Torvalds int dvStatus = hd->ioc->spi_data.dvStatus[target]; 13741da177e4SLinus Torvalds int issueCmd = 1; 13751da177e4SLinus Torvalds 13761da177e4SLinus Torvalds if (dvStatus || hd->ioc->spi_data.forceDv) { 13771da177e4SLinus Torvalds 13781da177e4SLinus Torvalds if ((dvStatus & MPT_SCSICFG_NEED_DV) || 13791da177e4SLinus Torvalds (hd->ioc->spi_data.forceDv & MPT_SCSICFG_NEED_DV)) { 13801da177e4SLinus Torvalds unsigned long lflags; 13811da177e4SLinus Torvalds /* Schedule DV if necessary */ 13821da177e4SLinus Torvalds spin_lock_irqsave(&dvtaskQ_lock, lflags); 13831da177e4SLinus Torvalds if (!dvtaskQ_active) { 13841da177e4SLinus Torvalds dvtaskQ_active = 1; 13851da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, lflags); 13860d0c7974SMoore, Eric Dean INIT_WORK(&dvTaskQ_task, mptscsih_domainValidation, (void *) hd); 13871da177e4SLinus Torvalds 13880d0c7974SMoore, Eric Dean schedule_work(&dvTaskQ_task); 13891da177e4SLinus Torvalds } else { 13901da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, lflags); 13911da177e4SLinus Torvalds } 13921da177e4SLinus Torvalds hd->ioc->spi_data.forceDv &= ~MPT_SCSICFG_NEED_DV; 13931da177e4SLinus Torvalds } 13941da177e4SLinus Torvalds 13951da177e4SLinus Torvalds /* Trying to do DV to this target, extend timeout. 13961da177e4SLinus Torvalds * Wait to issue until flag is clear 13971da177e4SLinus Torvalds */ 13981da177e4SLinus Torvalds if (dvStatus & MPT_SCSICFG_DV_PENDING) { 13991da177e4SLinus Torvalds mod_timer(&SCpnt->eh_timeout, jiffies + 40 * HZ); 14001da177e4SLinus Torvalds issueCmd = 0; 14011da177e4SLinus Torvalds } 14021da177e4SLinus Torvalds 14031da177e4SLinus Torvalds /* Set the DV flags. 14041da177e4SLinus Torvalds */ 14051da177e4SLinus Torvalds if (dvStatus & MPT_SCSICFG_DV_NOT_DONE) 14061da177e4SLinus Torvalds mptscsih_set_dvflags(hd, pScsiReq); 14071da177e4SLinus Torvalds 14081da177e4SLinus Torvalds if (!issueCmd) 14091da177e4SLinus Torvalds goto fail; 14101da177e4SLinus Torvalds } 14111da177e4SLinus Torvalds } 14121da177e4SLinus Torvalds #endif 14131da177e4SLinus Torvalds 14140d0c7974SMoore, Eric Dean mpt_put_msg_frame(hd->ioc->DoneCtx, hd->ioc, mf); 14151da177e4SLinus Torvalds dmfprintk((MYIOC_s_INFO_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n", 14161da177e4SLinus Torvalds hd->ioc->name, SCpnt, mf, my_idx)); 14171da177e4SLinus Torvalds DBG_DUMP_REQUEST_FRAME(mf) 14181da177e4SLinus Torvalds return 0; 14191da177e4SLinus Torvalds 14201da177e4SLinus Torvalds fail: 14211da177e4SLinus Torvalds mptscsih_freeChainBuffers(hd->ioc, my_idx); 14221da177e4SLinus Torvalds mpt_free_msg_frame(hd->ioc, mf); 14231da177e4SLinus Torvalds return SCSI_MLQUEUE_HOST_BUSY; 14241da177e4SLinus Torvalds } 14251da177e4SLinus Torvalds 14261da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 14271da177e4SLinus Torvalds /* 14281da177e4SLinus Torvalds * mptscsih_freeChainBuffers - Function to free chain buffers associated 14291da177e4SLinus Torvalds * with a SCSI IO request 14301da177e4SLinus Torvalds * @hd: Pointer to the MPT_SCSI_HOST instance 14311da177e4SLinus Torvalds * @req_idx: Index of the SCSI IO request frame. 14321da177e4SLinus Torvalds * 14331da177e4SLinus Torvalds * Called if SG chain buffer allocation fails and mptscsih callbacks. 14341da177e4SLinus Torvalds * No return. 14351da177e4SLinus Torvalds */ 14361da177e4SLinus Torvalds static void 14371da177e4SLinus Torvalds mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx) 14381da177e4SLinus Torvalds { 14391da177e4SLinus Torvalds MPT_FRAME_HDR *chain; 14401da177e4SLinus Torvalds unsigned long flags; 14411da177e4SLinus Torvalds int chain_idx; 14421da177e4SLinus Torvalds int next; 14431da177e4SLinus Torvalds 14441da177e4SLinus Torvalds /* Get the first chain index and reset 14451da177e4SLinus Torvalds * tracker state. 14461da177e4SLinus Torvalds */ 14471da177e4SLinus Torvalds chain_idx = ioc->ReqToChain[req_idx]; 14481da177e4SLinus Torvalds ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN; 14491da177e4SLinus Torvalds 14501da177e4SLinus Torvalds while (chain_idx != MPT_HOST_NO_CHAIN) { 14511da177e4SLinus Torvalds 14521da177e4SLinus Torvalds /* Save the next chain buffer index */ 14531da177e4SLinus Torvalds next = ioc->ChainToChain[chain_idx]; 14541da177e4SLinus Torvalds 14551da177e4SLinus Torvalds /* Free this chain buffer and reset 14561da177e4SLinus Torvalds * tracker 14571da177e4SLinus Torvalds */ 14581da177e4SLinus Torvalds ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN; 14591da177e4SLinus Torvalds 14601da177e4SLinus Torvalds chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer 14611da177e4SLinus Torvalds + (chain_idx * ioc->req_sz)); 14621da177e4SLinus Torvalds 14631da177e4SLinus Torvalds spin_lock_irqsave(&ioc->FreeQlock, flags); 14641da177e4SLinus Torvalds list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ); 14651da177e4SLinus Torvalds spin_unlock_irqrestore(&ioc->FreeQlock, flags); 14661da177e4SLinus Torvalds 14671da177e4SLinus Torvalds dmfprintk((MYIOC_s_INFO_FMT "FreeChainBuffers (index %d)\n", 14681da177e4SLinus Torvalds ioc->name, chain_idx)); 14691da177e4SLinus Torvalds 14701da177e4SLinus Torvalds /* handle next */ 14711da177e4SLinus Torvalds chain_idx = next; 14721da177e4SLinus Torvalds } 14731da177e4SLinus Torvalds return; 14741da177e4SLinus Torvalds } 14751da177e4SLinus Torvalds 14761da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 14771da177e4SLinus Torvalds /* 14781da177e4SLinus Torvalds * Reset Handling 14791da177e4SLinus Torvalds */ 14801da177e4SLinus Torvalds 14811da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 14821da177e4SLinus Torvalds /* 14831da177e4SLinus Torvalds * mptscsih_TMHandler - Generic handler for SCSI Task Management. 14841da177e4SLinus Torvalds * Fall through to mpt_HardResetHandler if: not operational, too many 14851da177e4SLinus Torvalds * failed TM requests or handshake failure. 14861da177e4SLinus Torvalds * 14871da177e4SLinus Torvalds * @ioc: Pointer to MPT_ADAPTER structure 14881da177e4SLinus Torvalds * @type: Task Management type 14891da177e4SLinus Torvalds * @target: Logical Target ID for reset (if appropriate) 14901da177e4SLinus Torvalds * @lun: Logical Unit for reset (if appropriate) 14911da177e4SLinus Torvalds * @ctx2abort: Context for the task to be aborted (if appropriate) 14921da177e4SLinus Torvalds * 14931da177e4SLinus Torvalds * Remark: Currently invoked from a non-interrupt thread (_bh). 14941da177e4SLinus Torvalds * 14951da177e4SLinus Torvalds * Remark: With old EH code, at most 1 SCSI TaskMgmt function per IOC 14961da177e4SLinus Torvalds * will be active. 14971da177e4SLinus Torvalds * 14981da177e4SLinus Torvalds * Returns 0 for SUCCESS or -1 if FAILED. 14991da177e4SLinus Torvalds */ 15001da177e4SLinus Torvalds static int 15011da177e4SLinus Torvalds mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout) 15021da177e4SLinus Torvalds { 15031da177e4SLinus Torvalds MPT_ADAPTER *ioc; 15041da177e4SLinus Torvalds int rc = -1; 15051da177e4SLinus Torvalds int doTask = 1; 15061da177e4SLinus Torvalds u32 ioc_raw_state; 15071da177e4SLinus Torvalds unsigned long flags; 15081da177e4SLinus Torvalds 15091da177e4SLinus Torvalds /* If FW is being reloaded currently, return success to 15101da177e4SLinus Torvalds * the calling function. 15111da177e4SLinus Torvalds */ 15121da177e4SLinus Torvalds if (hd == NULL) 15131da177e4SLinus Torvalds return 0; 15141da177e4SLinus Torvalds 15151da177e4SLinus Torvalds ioc = hd->ioc; 15161da177e4SLinus Torvalds if (ioc == NULL) { 15171da177e4SLinus Torvalds printk(KERN_ERR MYNAM " TMHandler" " NULL ioc!\n"); 15181da177e4SLinus Torvalds return FAILED; 15191da177e4SLinus Torvalds } 15201da177e4SLinus Torvalds dtmprintk((MYIOC_s_INFO_FMT "TMHandler Entered!\n", ioc->name)); 15211da177e4SLinus Torvalds 15221da177e4SLinus Torvalds // SJR - CHECKME - Can we avoid this here? 15231da177e4SLinus Torvalds // (mpt_HardResetHandler has this check...) 15241da177e4SLinus Torvalds spin_lock_irqsave(&ioc->diagLock, flags); 15251da177e4SLinus Torvalds if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)) { 15261da177e4SLinus Torvalds spin_unlock_irqrestore(&ioc->diagLock, flags); 15271da177e4SLinus Torvalds return FAILED; 15281da177e4SLinus Torvalds } 15291da177e4SLinus Torvalds spin_unlock_irqrestore(&ioc->diagLock, flags); 15301da177e4SLinus Torvalds 15311da177e4SLinus Torvalds /* Wait a fixed amount of time for the TM pending flag to be cleared. 15321da177e4SLinus Torvalds * If we time out and not bus reset, then we return a FAILED status to the caller. 15331da177e4SLinus Torvalds * The call to mptscsih_tm_pending_wait() will set the pending flag if we are 15341da177e4SLinus Torvalds * successful. Otherwise, reload the FW. 15351da177e4SLinus Torvalds */ 15361da177e4SLinus Torvalds if (mptscsih_tm_pending_wait(hd) == FAILED) { 15371da177e4SLinus Torvalds if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) { 15381da177e4SLinus Torvalds dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler abort: " 15391da177e4SLinus Torvalds "Timed out waiting for last TM (%d) to complete! \n", 15401da177e4SLinus Torvalds hd->ioc->name, hd->tmPending)); 15411da177e4SLinus Torvalds return FAILED; 15421da177e4SLinus Torvalds } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) { 15431da177e4SLinus Torvalds dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler target reset: " 15441da177e4SLinus Torvalds "Timed out waiting for last TM (%d) to complete! \n", 15451da177e4SLinus Torvalds hd->ioc->name, hd->tmPending)); 15461da177e4SLinus Torvalds return FAILED; 15471da177e4SLinus Torvalds } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) { 15481da177e4SLinus Torvalds dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler bus reset: " 15491da177e4SLinus Torvalds "Timed out waiting for last TM (%d) to complete! \n", 15501da177e4SLinus Torvalds hd->ioc->name, hd->tmPending)); 15511da177e4SLinus Torvalds if (hd->tmPending & (1 << MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)) 15521da177e4SLinus Torvalds return FAILED; 15531da177e4SLinus Torvalds 15541da177e4SLinus Torvalds doTask = 0; 15551da177e4SLinus Torvalds } 15561da177e4SLinus Torvalds } else { 15571da177e4SLinus Torvalds spin_lock_irqsave(&hd->ioc->FreeQlock, flags); 15581da177e4SLinus Torvalds hd->tmPending |= (1 << type); 15591da177e4SLinus Torvalds spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); 15601da177e4SLinus Torvalds } 15611da177e4SLinus Torvalds 15621da177e4SLinus Torvalds /* Is operational? 15631da177e4SLinus Torvalds */ 15641da177e4SLinus Torvalds ioc_raw_state = mpt_GetIocState(hd->ioc, 0); 15651da177e4SLinus Torvalds 15661da177e4SLinus Torvalds #ifdef MPT_DEBUG_RESET 15671da177e4SLinus Torvalds if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) { 15681da177e4SLinus Torvalds printk(MYIOC_s_WARN_FMT 15691da177e4SLinus Torvalds "TM Handler: IOC Not operational(0x%x)!\n", 15701da177e4SLinus Torvalds hd->ioc->name, ioc_raw_state); 15711da177e4SLinus Torvalds } 15721da177e4SLinus Torvalds #endif 15731da177e4SLinus Torvalds 15741da177e4SLinus Torvalds if (doTask && ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) 15751da177e4SLinus Torvalds && !(ioc_raw_state & MPI_DOORBELL_ACTIVE)) { 15761da177e4SLinus Torvalds 15771da177e4SLinus Torvalds /* Isse the Task Mgmt request. 15781da177e4SLinus Torvalds */ 15791da177e4SLinus Torvalds if (hd->hard_resets < -1) 15801da177e4SLinus Torvalds hd->hard_resets++; 15811da177e4SLinus Torvalds rc = mptscsih_IssueTaskMgmt(hd, type, channel, target, lun, ctx2abort, timeout); 15821da177e4SLinus Torvalds if (rc) { 15831da177e4SLinus Torvalds printk(MYIOC_s_INFO_FMT "Issue of TaskMgmt failed!\n", hd->ioc->name); 15841da177e4SLinus Torvalds } else { 15851da177e4SLinus Torvalds dtmprintk((MYIOC_s_INFO_FMT "Issue of TaskMgmt Successful!\n", hd->ioc->name)); 15861da177e4SLinus Torvalds } 15871da177e4SLinus Torvalds } 15881da177e4SLinus Torvalds 15891da177e4SLinus Torvalds /* Only fall through to the HRH if this is a bus reset 15901da177e4SLinus Torvalds */ 15911da177e4SLinus Torvalds if ((type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) && (rc || 15921da177e4SLinus Torvalds ioc->reload_fw || (ioc->alt_ioc && ioc->alt_ioc->reload_fw))) { 15931da177e4SLinus Torvalds dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n", 15941da177e4SLinus Torvalds hd->ioc->name)); 15951da177e4SLinus Torvalds rc = mpt_HardResetHandler(hd->ioc, CAN_SLEEP); 15961da177e4SLinus Torvalds } 15971da177e4SLinus Torvalds 15981da177e4SLinus Torvalds dtmprintk((MYIOC_s_INFO_FMT "TMHandler rc = %d!\n", hd->ioc->name, rc)); 15991da177e4SLinus Torvalds 16001da177e4SLinus Torvalds return rc; 16011da177e4SLinus Torvalds } 16021da177e4SLinus Torvalds 16031da177e4SLinus Torvalds 16041da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 16051da177e4SLinus Torvalds /* 16061da177e4SLinus Torvalds * mptscsih_IssueTaskMgmt - Generic send Task Management function. 16071da177e4SLinus Torvalds * @hd: Pointer to MPT_SCSI_HOST structure 16081da177e4SLinus Torvalds * @type: Task Management type 16091da177e4SLinus Torvalds * @target: Logical Target ID for reset (if appropriate) 16101da177e4SLinus Torvalds * @lun: Logical Unit for reset (if appropriate) 16111da177e4SLinus Torvalds * @ctx2abort: Context for the task to be aborted (if appropriate) 16121da177e4SLinus Torvalds * 16131da177e4SLinus Torvalds * Remark: _HardResetHandler can be invoked from an interrupt thread (timer) 16141da177e4SLinus Torvalds * or a non-interrupt thread. In the former, must not call schedule(). 16151da177e4SLinus Torvalds * 16161da177e4SLinus Torvalds * Not all fields are meaningfull for all task types. 16171da177e4SLinus Torvalds * 16181da177e4SLinus Torvalds * Returns 0 for SUCCESS, -999 for "no msg frames", 16191da177e4SLinus Torvalds * else other non-zero value returned. 16201da177e4SLinus Torvalds */ 16211da177e4SLinus Torvalds static int 16221da177e4SLinus Torvalds mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout) 16231da177e4SLinus Torvalds { 16241da177e4SLinus Torvalds MPT_FRAME_HDR *mf; 16251da177e4SLinus Torvalds SCSITaskMgmt_t *pScsiTm; 16261da177e4SLinus Torvalds int ii; 16271da177e4SLinus Torvalds int retval; 16281da177e4SLinus Torvalds 16291da177e4SLinus Torvalds /* Return Fail to calling function if no message frames available. 16301da177e4SLinus Torvalds */ 16310d0c7974SMoore, Eric Dean if ((mf = mpt_get_msg_frame(hd->ioc->TaskCtx, hd->ioc)) == NULL) { 16321da177e4SLinus Torvalds dfailprintk((MYIOC_s_ERR_FMT "IssueTaskMgmt, no msg frames!!\n", 16331da177e4SLinus Torvalds hd->ioc->name)); 16341da177e4SLinus Torvalds //return FAILED; 16351da177e4SLinus Torvalds return -999; 16361da177e4SLinus Torvalds } 16371da177e4SLinus Torvalds dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt request @ %p\n", 16381da177e4SLinus Torvalds hd->ioc->name, mf)); 16391da177e4SLinus Torvalds 16401da177e4SLinus Torvalds /* Format the Request 16411da177e4SLinus Torvalds */ 16421da177e4SLinus Torvalds pScsiTm = (SCSITaskMgmt_t *) mf; 16431da177e4SLinus Torvalds pScsiTm->TargetID = target; 16441da177e4SLinus Torvalds pScsiTm->Bus = channel; 16451da177e4SLinus Torvalds pScsiTm->ChainOffset = 0; 16461da177e4SLinus Torvalds pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; 16471da177e4SLinus Torvalds 16481da177e4SLinus Torvalds pScsiTm->Reserved = 0; 16491da177e4SLinus Torvalds pScsiTm->TaskType = type; 16501da177e4SLinus Torvalds pScsiTm->Reserved1 = 0; 16511da177e4SLinus Torvalds pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) 16521da177e4SLinus Torvalds ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0; 16531da177e4SLinus Torvalds 16541da177e4SLinus Torvalds for (ii= 0; ii < 8; ii++) { 16551da177e4SLinus Torvalds pScsiTm->LUN[ii] = 0; 16561da177e4SLinus Torvalds } 16571da177e4SLinus Torvalds pScsiTm->LUN[1] = lun; 16581da177e4SLinus Torvalds 16591da177e4SLinus Torvalds for (ii=0; ii < 7; ii++) 16601da177e4SLinus Torvalds pScsiTm->Reserved2[ii] = 0; 16611da177e4SLinus Torvalds 16621da177e4SLinus Torvalds pScsiTm->TaskMsgContext = ctx2abort; 16631da177e4SLinus Torvalds 16641da177e4SLinus Torvalds dtmprintk((MYIOC_s_INFO_FMT 16651da177e4SLinus Torvalds "IssueTaskMgmt: ctx2abort (0x%08x) type=%d\n", 16661da177e4SLinus Torvalds hd->ioc->name, ctx2abort, type)); 16671da177e4SLinus Torvalds 16681da177e4SLinus Torvalds DBG_DUMP_TM_REQUEST_FRAME((u32 *)pScsiTm); 16691da177e4SLinus Torvalds 16700d0c7974SMoore, Eric Dean if ((retval = mpt_send_handshake_request(hd->ioc->TaskCtx, hd->ioc, 16711da177e4SLinus Torvalds sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, 16721da177e4SLinus Torvalds CAN_SLEEP)) != 0) { 16731da177e4SLinus Torvalds dfailprintk((MYIOC_s_ERR_FMT "_send_handshake FAILED!" 16741da177e4SLinus Torvalds " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd, 16751da177e4SLinus Torvalds hd->ioc, mf)); 16761da177e4SLinus Torvalds mpt_free_msg_frame(hd->ioc, mf); 16771da177e4SLinus Torvalds return retval; 16781da177e4SLinus Torvalds } 16791da177e4SLinus Torvalds 16801da177e4SLinus Torvalds if(mptscsih_tm_wait_for_completion(hd, timeout) == FAILED) { 16811da177e4SLinus Torvalds dfailprintk((MYIOC_s_ERR_FMT "_wait_for_completion FAILED!" 16821da177e4SLinus Torvalds " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd, 16831da177e4SLinus Torvalds hd->ioc, mf)); 16841da177e4SLinus Torvalds mpt_free_msg_frame(hd->ioc, mf); 16851da177e4SLinus Torvalds dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n", 16861da177e4SLinus Torvalds hd->ioc->name)); 16871da177e4SLinus Torvalds retval = mpt_HardResetHandler(hd->ioc, CAN_SLEEP); 16881da177e4SLinus Torvalds } 16891da177e4SLinus Torvalds 16901da177e4SLinus Torvalds return retval; 16911da177e4SLinus Torvalds } 16921da177e4SLinus Torvalds 16931da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 16941da177e4SLinus Torvalds /** 16951da177e4SLinus Torvalds * mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant 16961da177e4SLinus Torvalds * @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted 16971da177e4SLinus Torvalds * 16981da177e4SLinus Torvalds * (linux scsi_host_template.eh_abort_handler routine) 16991da177e4SLinus Torvalds * 17001da177e4SLinus Torvalds * Returns SUCCESS or FAILED. 17011da177e4SLinus Torvalds */ 17020d0c7974SMoore, Eric Dean int 17031da177e4SLinus Torvalds mptscsih_abort(struct scsi_cmnd * SCpnt) 17041da177e4SLinus Torvalds { 17051da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 17061da177e4SLinus Torvalds MPT_ADAPTER *ioc; 17071da177e4SLinus Torvalds MPT_FRAME_HDR *mf; 17081da177e4SLinus Torvalds u32 ctx2abort; 17091da177e4SLinus Torvalds int scpnt_idx; 17101da177e4SLinus Torvalds 17111da177e4SLinus Torvalds /* If we can't locate our host adapter structure, return FAILED status. 17121da177e4SLinus Torvalds */ 17131da177e4SLinus Torvalds if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL) { 17141da177e4SLinus Torvalds SCpnt->result = DID_RESET << 16; 17151da177e4SLinus Torvalds SCpnt->scsi_done(SCpnt); 17161da177e4SLinus Torvalds dfailprintk((KERN_WARNING MYNAM ": mptscsih_abort: " 17171da177e4SLinus Torvalds "Can't locate host! (sc=%p)\n", 17181da177e4SLinus Torvalds SCpnt)); 17191da177e4SLinus Torvalds return FAILED; 17201da177e4SLinus Torvalds } 17211da177e4SLinus Torvalds 17221da177e4SLinus Torvalds ioc = hd->ioc; 17231da177e4SLinus Torvalds if (hd->resetPending) 17241da177e4SLinus Torvalds return FAILED; 17251da177e4SLinus Torvalds 17261da177e4SLinus Torvalds printk(KERN_WARNING MYNAM ": %s: >> Attempting task abort! (sc=%p)\n", 17271da177e4SLinus Torvalds hd->ioc->name, SCpnt); 17281da177e4SLinus Torvalds 17291da177e4SLinus Torvalds if (hd->timeouts < -1) 17301da177e4SLinus Torvalds hd->timeouts++; 17311da177e4SLinus Torvalds 17321da177e4SLinus Torvalds /* Find this command 17331da177e4SLinus Torvalds */ 17341da177e4SLinus Torvalds if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(SCpnt)) < 0) { 17351da177e4SLinus Torvalds /* Cmd not found in ScsiLookup. 17361da177e4SLinus Torvalds * Do OS callback. 17371da177e4SLinus Torvalds */ 17381da177e4SLinus Torvalds SCpnt->result = DID_RESET << 16; 17391da177e4SLinus Torvalds dtmprintk((KERN_WARNING MYNAM ": %s: mptscsih_abort: " 17401da177e4SLinus Torvalds "Command not in the active list! (sc=%p)\n", 17411da177e4SLinus Torvalds hd->ioc->name, SCpnt)); 17421da177e4SLinus Torvalds return SUCCESS; 17431da177e4SLinus Torvalds } 17441da177e4SLinus Torvalds 17451da177e4SLinus Torvalds /* Most important! Set TaskMsgContext to SCpnt's MsgContext! 17461da177e4SLinus Torvalds * (the IO to be ABORT'd) 17471da177e4SLinus Torvalds * 17481da177e4SLinus Torvalds * NOTE: Since we do not byteswap MsgContext, we do not 17491da177e4SLinus Torvalds * swap it here either. It is an opaque cookie to 17501da177e4SLinus Torvalds * the controller, so it does not matter. -DaveM 17511da177e4SLinus Torvalds */ 17521da177e4SLinus Torvalds mf = MPT_INDEX_2_MFPTR(hd->ioc, scpnt_idx); 17531da177e4SLinus Torvalds ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext; 17541da177e4SLinus Torvalds 17551da177e4SLinus Torvalds hd->abortSCpnt = SCpnt; 17561da177e4SLinus Torvalds 17571da177e4SLinus Torvalds if (mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK, 17581da177e4SLinus Torvalds SCpnt->device->channel, SCpnt->device->id, SCpnt->device->lun, 17591da177e4SLinus Torvalds ctx2abort, 2 /* 2 second timeout */) 17601da177e4SLinus Torvalds < 0) { 17611da177e4SLinus Torvalds 17621da177e4SLinus Torvalds /* The TM request failed and the subsequent FW-reload failed! 17631da177e4SLinus Torvalds * Fatal error case. 17641da177e4SLinus Torvalds */ 17651da177e4SLinus Torvalds printk(MYIOC_s_WARN_FMT "Error issuing abort task! (sc=%p)\n", 17661da177e4SLinus Torvalds hd->ioc->name, SCpnt); 17671da177e4SLinus Torvalds 17681da177e4SLinus Torvalds /* We must clear our pending flag before clearing our state. 17691da177e4SLinus Torvalds */ 17701da177e4SLinus Torvalds hd->tmPending = 0; 17711da177e4SLinus Torvalds hd->tmState = TM_STATE_NONE; 17721da177e4SLinus Torvalds 17731da177e4SLinus Torvalds /* Unmap the DMA buffers, if any. */ 17741da177e4SLinus Torvalds if (SCpnt->use_sg) { 17751da177e4SLinus Torvalds pci_unmap_sg(ioc->pcidev, (struct scatterlist *) SCpnt->request_buffer, 17761da177e4SLinus Torvalds SCpnt->use_sg, SCpnt->sc_data_direction); 17771da177e4SLinus Torvalds } else if (SCpnt->request_bufflen) { 17781da177e4SLinus Torvalds pci_unmap_single(ioc->pcidev, SCpnt->SCp.dma_handle, 17791da177e4SLinus Torvalds SCpnt->request_bufflen, SCpnt->sc_data_direction); 17801da177e4SLinus Torvalds } 17811da177e4SLinus Torvalds hd->ScsiLookup[scpnt_idx] = NULL; 17821da177e4SLinus Torvalds SCpnt->result = DID_RESET << 16; 17831da177e4SLinus Torvalds SCpnt->scsi_done(SCpnt); /* Issue the command callback */ 17841da177e4SLinus Torvalds mptscsih_freeChainBuffers(ioc, scpnt_idx); 17851da177e4SLinus Torvalds mpt_free_msg_frame(ioc, mf); 17861da177e4SLinus Torvalds return FAILED; 17871da177e4SLinus Torvalds } 17881da177e4SLinus Torvalds return SUCCESS; 17891da177e4SLinus Torvalds } 17901da177e4SLinus Torvalds 17911da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 17921da177e4SLinus Torvalds /** 17931da177e4SLinus Torvalds * mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant 17941da177e4SLinus Torvalds * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to 17951da177e4SLinus Torvalds * 17961da177e4SLinus Torvalds * (linux scsi_host_template.eh_dev_reset_handler routine) 17971da177e4SLinus Torvalds * 17981da177e4SLinus Torvalds * Returns SUCCESS or FAILED. 17991da177e4SLinus Torvalds */ 18000d0c7974SMoore, Eric Dean int 18011da177e4SLinus Torvalds mptscsih_dev_reset(struct scsi_cmnd * SCpnt) 18021da177e4SLinus Torvalds { 18031da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 18041da177e4SLinus Torvalds 18051da177e4SLinus Torvalds /* If we can't locate our host adapter structure, return FAILED status. 18061da177e4SLinus Torvalds */ 18071da177e4SLinus Torvalds if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){ 18081da177e4SLinus Torvalds dtmprintk((KERN_WARNING MYNAM ": mptscsih_dev_reset: " 18091da177e4SLinus Torvalds "Can't locate host! (sc=%p)\n", 18101da177e4SLinus Torvalds SCpnt)); 18111da177e4SLinus Torvalds return FAILED; 18121da177e4SLinus Torvalds } 18131da177e4SLinus Torvalds 18141da177e4SLinus Torvalds if (hd->resetPending) 18151da177e4SLinus Torvalds return FAILED; 18161da177e4SLinus Torvalds 18171da177e4SLinus Torvalds printk(KERN_WARNING MYNAM ": %s: >> Attempting target reset! (sc=%p)\n", 18181da177e4SLinus Torvalds hd->ioc->name, SCpnt); 18191da177e4SLinus Torvalds 18201da177e4SLinus Torvalds if (mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 18211da177e4SLinus Torvalds SCpnt->device->channel, SCpnt->device->id, 18221da177e4SLinus Torvalds 0, 0, 5 /* 5 second timeout */) 18231da177e4SLinus Torvalds < 0){ 18241da177e4SLinus Torvalds /* The TM request failed and the subsequent FW-reload failed! 18251da177e4SLinus Torvalds * Fatal error case. 18261da177e4SLinus Torvalds */ 18271da177e4SLinus Torvalds printk(MYIOC_s_WARN_FMT "Error processing TaskMgmt request (sc=%p)\n", 18281da177e4SLinus Torvalds hd->ioc->name, SCpnt); 18291da177e4SLinus Torvalds hd->tmPending = 0; 18301da177e4SLinus Torvalds hd->tmState = TM_STATE_NONE; 18311da177e4SLinus Torvalds return FAILED; 18321da177e4SLinus Torvalds } 18331da177e4SLinus Torvalds 183494d0e7b8SJeff Garzik return SUCCESS; 18351da177e4SLinus Torvalds } 18361da177e4SLinus Torvalds 18371da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 18381da177e4SLinus Torvalds /** 18391da177e4SLinus Torvalds * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant 18401da177e4SLinus Torvalds * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to 18411da177e4SLinus Torvalds * 18421da177e4SLinus Torvalds * (linux scsi_host_template.eh_bus_reset_handler routine) 18431da177e4SLinus Torvalds * 18441da177e4SLinus Torvalds * Returns SUCCESS or FAILED. 18451da177e4SLinus Torvalds */ 18460d0c7974SMoore, Eric Dean int 18471da177e4SLinus Torvalds mptscsih_bus_reset(struct scsi_cmnd * SCpnt) 18481da177e4SLinus Torvalds { 18491da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 18501da177e4SLinus Torvalds spinlock_t *host_lock = SCpnt->device->host->host_lock; 18511da177e4SLinus Torvalds 18521da177e4SLinus Torvalds /* If we can't locate our host adapter structure, return FAILED status. 18531da177e4SLinus Torvalds */ 18541da177e4SLinus Torvalds if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){ 18551da177e4SLinus Torvalds dtmprintk((KERN_WARNING MYNAM ": mptscsih_bus_reset: " 18561da177e4SLinus Torvalds "Can't locate host! (sc=%p)\n", 18571da177e4SLinus Torvalds SCpnt ) ); 18581da177e4SLinus Torvalds return FAILED; 18591da177e4SLinus Torvalds } 18601da177e4SLinus Torvalds 18611da177e4SLinus Torvalds printk(KERN_WARNING MYNAM ": %s: >> Attempting bus reset! (sc=%p)\n", 18621da177e4SLinus Torvalds hd->ioc->name, SCpnt); 18631da177e4SLinus Torvalds 18641da177e4SLinus Torvalds if (hd->timeouts < -1) 18651da177e4SLinus Torvalds hd->timeouts++; 18661da177e4SLinus Torvalds 18671da177e4SLinus Torvalds /* We are now ready to execute the task management request. */ 18681da177e4SLinus Torvalds spin_unlock_irq(host_lock); 18691da177e4SLinus Torvalds if (mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, 18701da177e4SLinus Torvalds SCpnt->device->channel, 0, 0, 0, 5 /* 5 second timeout */) 18711da177e4SLinus Torvalds < 0){ 18721da177e4SLinus Torvalds 18731da177e4SLinus Torvalds /* The TM request failed and the subsequent FW-reload failed! 18741da177e4SLinus Torvalds * Fatal error case. 18751da177e4SLinus Torvalds */ 18761da177e4SLinus Torvalds printk(MYIOC_s_WARN_FMT 18771da177e4SLinus Torvalds "Error processing TaskMgmt request (sc=%p)\n", 18781da177e4SLinus Torvalds hd->ioc->name, SCpnt); 18791da177e4SLinus Torvalds hd->tmPending = 0; 18801da177e4SLinus Torvalds hd->tmState = TM_STATE_NONE; 18811da177e4SLinus Torvalds spin_lock_irq(host_lock); 18821da177e4SLinus Torvalds return FAILED; 18831da177e4SLinus Torvalds } 18841da177e4SLinus Torvalds spin_lock_irq(host_lock); 18851da177e4SLinus Torvalds return SUCCESS; 18861da177e4SLinus Torvalds } 18871da177e4SLinus Torvalds 18881da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 18891da177e4SLinus Torvalds /** 18901da177e4SLinus Torvalds * mptscsih_host_reset - Perform a SCSI host adapter RESET! 18911da177e4SLinus Torvalds * new_eh variant 18921da177e4SLinus Torvalds * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to 18931da177e4SLinus Torvalds * 18941da177e4SLinus Torvalds * (linux scsi_host_template.eh_host_reset_handler routine) 18951da177e4SLinus Torvalds * 18961da177e4SLinus Torvalds * Returns SUCCESS or FAILED. 18971da177e4SLinus Torvalds */ 18980d0c7974SMoore, Eric Dean int 18991da177e4SLinus Torvalds mptscsih_host_reset(struct scsi_cmnd *SCpnt) 19001da177e4SLinus Torvalds { 19011da177e4SLinus Torvalds MPT_SCSI_HOST * hd; 19021da177e4SLinus Torvalds int status = SUCCESS; 19031da177e4SLinus Torvalds spinlock_t *host_lock = SCpnt->device->host->host_lock; 19041da177e4SLinus Torvalds 19051da177e4SLinus Torvalds /* If we can't locate the host to reset, then we failed. */ 19061da177e4SLinus Torvalds if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){ 19071da177e4SLinus Torvalds dtmprintk( ( KERN_WARNING MYNAM ": mptscsih_host_reset: " 19081da177e4SLinus Torvalds "Can't locate host! (sc=%p)\n", 19091da177e4SLinus Torvalds SCpnt ) ); 19101da177e4SLinus Torvalds return FAILED; 19111da177e4SLinus Torvalds } 19121da177e4SLinus Torvalds 19131da177e4SLinus Torvalds printk(KERN_WARNING MYNAM ": %s: >> Attempting host reset! (sc=%p)\n", 19141da177e4SLinus Torvalds hd->ioc->name, SCpnt); 19151da177e4SLinus Torvalds 19161da177e4SLinus Torvalds /* If our attempts to reset the host failed, then return a failed 19171da177e4SLinus Torvalds * status. The host will be taken off line by the SCSI mid-layer. 19181da177e4SLinus Torvalds */ 19191da177e4SLinus Torvalds spin_unlock_irq(host_lock); 19201da177e4SLinus Torvalds if (mpt_HardResetHandler(hd->ioc, CAN_SLEEP) < 0){ 19211da177e4SLinus Torvalds status = FAILED; 19221da177e4SLinus Torvalds } else { 19231da177e4SLinus Torvalds /* Make sure TM pending is cleared and TM state is set to 19241da177e4SLinus Torvalds * NONE. 19251da177e4SLinus Torvalds */ 19261da177e4SLinus Torvalds hd->tmPending = 0; 19271da177e4SLinus Torvalds hd->tmState = TM_STATE_NONE; 19281da177e4SLinus Torvalds } 19291da177e4SLinus Torvalds spin_lock_irq(host_lock); 19301da177e4SLinus Torvalds 19311da177e4SLinus Torvalds 19321da177e4SLinus Torvalds dtmprintk( ( KERN_WARNING MYNAM ": mptscsih_host_reset: " 19331da177e4SLinus Torvalds "Status = %s\n", 19341da177e4SLinus Torvalds (status == SUCCESS) ? "SUCCESS" : "FAILED" ) ); 19351da177e4SLinus Torvalds 19361da177e4SLinus Torvalds return status; 19371da177e4SLinus Torvalds } 19381da177e4SLinus Torvalds 19391da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 19401da177e4SLinus Torvalds /** 19411da177e4SLinus Torvalds * mptscsih_tm_pending_wait - wait for pending task management request to 19421da177e4SLinus Torvalds * complete. 19431da177e4SLinus Torvalds * @hd: Pointer to MPT host structure. 19441da177e4SLinus Torvalds * 19451da177e4SLinus Torvalds * Returns {SUCCESS,FAILED}. 19461da177e4SLinus Torvalds */ 19471da177e4SLinus Torvalds static int 19481da177e4SLinus Torvalds mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd) 19491da177e4SLinus Torvalds { 19501da177e4SLinus Torvalds unsigned long flags; 19511da177e4SLinus Torvalds int loop_count = 4 * 10; /* Wait 10 seconds */ 19521da177e4SLinus Torvalds int status = FAILED; 19531da177e4SLinus Torvalds 19541da177e4SLinus Torvalds do { 19551da177e4SLinus Torvalds spin_lock_irqsave(&hd->ioc->FreeQlock, flags); 19561da177e4SLinus Torvalds if (hd->tmState == TM_STATE_NONE) { 19571da177e4SLinus Torvalds hd->tmState = TM_STATE_IN_PROGRESS; 19581da177e4SLinus Torvalds hd->tmPending = 1; 19591da177e4SLinus Torvalds status = SUCCESS; 19601da177e4SLinus Torvalds spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); 19611da177e4SLinus Torvalds break; 19621da177e4SLinus Torvalds } 19631da177e4SLinus Torvalds spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); 19641da177e4SLinus Torvalds msleep(250); 19651da177e4SLinus Torvalds } while (--loop_count); 19661da177e4SLinus Torvalds 19671da177e4SLinus Torvalds return status; 19681da177e4SLinus Torvalds } 19691da177e4SLinus Torvalds 19701da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 19711da177e4SLinus Torvalds /** 19721da177e4SLinus Torvalds * mptscsih_tm_wait_for_completion - wait for completion of TM task 19731da177e4SLinus Torvalds * @hd: Pointer to MPT host structure. 19741da177e4SLinus Torvalds * 19751da177e4SLinus Torvalds * Returns {SUCCESS,FAILED}. 19761da177e4SLinus Torvalds */ 19771da177e4SLinus Torvalds static int 19781da177e4SLinus Torvalds mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout ) 19791da177e4SLinus Torvalds { 19801da177e4SLinus Torvalds unsigned long flags; 19811da177e4SLinus Torvalds int loop_count = 4 * timeout; 19821da177e4SLinus Torvalds int status = FAILED; 19831da177e4SLinus Torvalds 19841da177e4SLinus Torvalds do { 19851da177e4SLinus Torvalds spin_lock_irqsave(&hd->ioc->FreeQlock, flags); 19861da177e4SLinus Torvalds if(hd->tmPending == 0) { 19871da177e4SLinus Torvalds status = SUCCESS; 19881da177e4SLinus Torvalds spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); 19891da177e4SLinus Torvalds break; 19901da177e4SLinus Torvalds } 19911da177e4SLinus Torvalds spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); 19921da177e4SLinus Torvalds msleep_interruptible(250); 19931da177e4SLinus Torvalds } while (--loop_count); 19941da177e4SLinus Torvalds 19951da177e4SLinus Torvalds return status; 19961da177e4SLinus Torvalds } 19971da177e4SLinus Torvalds 19981da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 19991da177e4SLinus Torvalds /** 20001da177e4SLinus Torvalds * mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver 20011da177e4SLinus Torvalds * @ioc: Pointer to MPT_ADAPTER structure 20021da177e4SLinus Torvalds * @mf: Pointer to SCSI task mgmt request frame 20031da177e4SLinus Torvalds * @mr: Pointer to SCSI task mgmt reply frame 20041da177e4SLinus Torvalds * 20051da177e4SLinus Torvalds * This routine is called from mptbase.c::mpt_interrupt() at the completion 20061da177e4SLinus Torvalds * of any SCSI task management request. 20071da177e4SLinus Torvalds * This routine is registered with the MPT (base) driver at driver 20081da177e4SLinus Torvalds * load/init time via the mpt_register() API call. 20091da177e4SLinus Torvalds * 20101da177e4SLinus Torvalds * Returns 1 indicating alloc'd request frame ptr should be freed. 20111da177e4SLinus Torvalds */ 20120d0c7974SMoore, Eric Dean int 20131da177e4SLinus Torvalds mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) 20141da177e4SLinus Torvalds { 20151da177e4SLinus Torvalds SCSITaskMgmtReply_t *pScsiTmReply; 20161da177e4SLinus Torvalds SCSITaskMgmt_t *pScsiTmReq; 20171da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 20181da177e4SLinus Torvalds unsigned long flags; 20191da177e4SLinus Torvalds u16 iocstatus; 20201da177e4SLinus Torvalds u8 tmType; 20211da177e4SLinus Torvalds 20221da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt completed (mf=%p,mr=%p)\n", 20231da177e4SLinus Torvalds ioc->name, mf, mr)); 20241da177e4SLinus Torvalds if (ioc->sh) { 20251da177e4SLinus Torvalds /* Depending on the thread, a timer is activated for 20261da177e4SLinus Torvalds * the TM request. Delete this timer on completion of TM. 20271da177e4SLinus Torvalds * Decrement count of outstanding TM requests. 20281da177e4SLinus Torvalds */ 20291da177e4SLinus Torvalds hd = (MPT_SCSI_HOST *)ioc->sh->hostdata; 20301da177e4SLinus Torvalds } else { 20311da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt Complete: NULL Scsi Host Ptr\n", 20321da177e4SLinus Torvalds ioc->name)); 20331da177e4SLinus Torvalds return 1; 20341da177e4SLinus Torvalds } 20351da177e4SLinus Torvalds 20361da177e4SLinus Torvalds if (mr == NULL) { 20371da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT "ERROR! TaskMgmt Reply: NULL Request %p\n", 20381da177e4SLinus Torvalds ioc->name, mf)); 20391da177e4SLinus Torvalds return 1; 20401da177e4SLinus Torvalds } else { 20411da177e4SLinus Torvalds pScsiTmReply = (SCSITaskMgmtReply_t*)mr; 20421da177e4SLinus Torvalds pScsiTmReq = (SCSITaskMgmt_t*)mf; 20431da177e4SLinus Torvalds 20441da177e4SLinus Torvalds /* Figure out if this was ABORT_TASK, TARGET_RESET, or BUS_RESET! */ 20451da177e4SLinus Torvalds tmType = pScsiTmReq->TaskType; 20461da177e4SLinus Torvalds 20471da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT " TaskType = %d, TerminationCount=%d\n", 20481da177e4SLinus Torvalds ioc->name, tmType, le32_to_cpu(pScsiTmReply->TerminationCount))); 20491da177e4SLinus Torvalds DBG_DUMP_TM_REPLY_FRAME((u32 *)pScsiTmReply); 20501da177e4SLinus Torvalds 20511da177e4SLinus Torvalds iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK; 20521da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT " SCSI TaskMgmt (%d) IOCStatus=%04x IOCLogInfo=%08x\n", 20531da177e4SLinus Torvalds ioc->name, tmType, iocstatus, le32_to_cpu(pScsiTmReply->IOCLogInfo))); 20541da177e4SLinus Torvalds /* Error? (anything non-zero?) */ 20551da177e4SLinus Torvalds if (iocstatus) { 20561da177e4SLinus Torvalds 20571da177e4SLinus Torvalds /* clear flags and continue. 20581da177e4SLinus Torvalds */ 20591da177e4SLinus Torvalds if (tmType == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) 20601da177e4SLinus Torvalds hd->abortSCpnt = NULL; 20611da177e4SLinus Torvalds 20621da177e4SLinus Torvalds /* If an internal command is present 20631da177e4SLinus Torvalds * or the TM failed - reload the FW. 20641da177e4SLinus Torvalds * FC FW may respond FAILED to an ABORT 20651da177e4SLinus Torvalds */ 20661da177e4SLinus Torvalds if (tmType == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) { 20671da177e4SLinus Torvalds if ((hd->cmdPtr) || 20681da177e4SLinus Torvalds (iocstatus == MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED)) { 20691da177e4SLinus Torvalds if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0) { 20701da177e4SLinus Torvalds printk((KERN_WARNING 20711da177e4SLinus Torvalds " Firmware Reload FAILED!!\n")); 20721da177e4SLinus Torvalds } 20731da177e4SLinus Torvalds } 20741da177e4SLinus Torvalds } 20751da177e4SLinus Torvalds } else { 20761da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT " TaskMgmt SUCCESS\n", ioc->name)); 20771da177e4SLinus Torvalds 20781da177e4SLinus Torvalds hd->abortSCpnt = NULL; 20791da177e4SLinus Torvalds 20801da177e4SLinus Torvalds } 20811da177e4SLinus Torvalds } 20821da177e4SLinus Torvalds 20831da177e4SLinus Torvalds spin_lock_irqsave(&ioc->FreeQlock, flags); 20841da177e4SLinus Torvalds hd->tmPending = 0; 20851da177e4SLinus Torvalds spin_unlock_irqrestore(&ioc->FreeQlock, flags); 20861da177e4SLinus Torvalds hd->tmState = TM_STATE_NONE; 20871da177e4SLinus Torvalds 20881da177e4SLinus Torvalds return 1; 20891da177e4SLinus Torvalds } 20901da177e4SLinus Torvalds 20911da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 20921da177e4SLinus Torvalds /* 20931da177e4SLinus Torvalds * This is anyones guess quite frankly. 20941da177e4SLinus Torvalds */ 20950d0c7974SMoore, Eric Dean int 20961da177e4SLinus Torvalds mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev, 20971da177e4SLinus Torvalds sector_t capacity, int geom[]) 20981da177e4SLinus Torvalds { 20991da177e4SLinus Torvalds int heads; 21001da177e4SLinus Torvalds int sectors; 21011da177e4SLinus Torvalds sector_t cylinders; 21021da177e4SLinus Torvalds ulong dummy; 21031da177e4SLinus Torvalds 21041da177e4SLinus Torvalds heads = 64; 21051da177e4SLinus Torvalds sectors = 32; 21061da177e4SLinus Torvalds 21071da177e4SLinus Torvalds dummy = heads * sectors; 21081da177e4SLinus Torvalds cylinders = capacity; 21091da177e4SLinus Torvalds sector_div(cylinders,dummy); 21101da177e4SLinus Torvalds 21111da177e4SLinus Torvalds /* 21121da177e4SLinus Torvalds * Handle extended translation size for logical drives 21131da177e4SLinus Torvalds * > 1Gb 21141da177e4SLinus Torvalds */ 21151da177e4SLinus Torvalds if ((ulong)capacity >= 0x200000) { 21161da177e4SLinus Torvalds heads = 255; 21171da177e4SLinus Torvalds sectors = 63; 21181da177e4SLinus Torvalds dummy = heads * sectors; 21191da177e4SLinus Torvalds cylinders = capacity; 21201da177e4SLinus Torvalds sector_div(cylinders,dummy); 21211da177e4SLinus Torvalds } 21221da177e4SLinus Torvalds 21231da177e4SLinus Torvalds /* return result */ 21241da177e4SLinus Torvalds geom[0] = heads; 21251da177e4SLinus Torvalds geom[1] = sectors; 21261da177e4SLinus Torvalds geom[2] = cylinders; 21271da177e4SLinus Torvalds 21281da177e4SLinus Torvalds dprintk((KERN_NOTICE 21291da177e4SLinus Torvalds ": bios_param: Id=%i Lun=%i Channel=%i CHS=%i/%i/%i\n", 21301da177e4SLinus Torvalds sdev->id, sdev->lun,sdev->channel,(int)cylinders,heads,sectors)); 21311da177e4SLinus Torvalds 21321da177e4SLinus Torvalds return 0; 21331da177e4SLinus Torvalds } 21341da177e4SLinus Torvalds 21351da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 21361da177e4SLinus Torvalds /* 21371da177e4SLinus Torvalds * OS entry point to allow host driver to alloc memory 21381da177e4SLinus Torvalds * for each scsi device. Called once per device the bus scan. 21391da177e4SLinus Torvalds * Return non-zero if allocation fails. 21401da177e4SLinus Torvalds * Init memory once per id (not LUN). 21411da177e4SLinus Torvalds */ 21420d0c7974SMoore, Eric Dean int 21431da177e4SLinus Torvalds mptscsih_slave_alloc(struct scsi_device *device) 21441da177e4SLinus Torvalds { 21451da177e4SLinus Torvalds struct Scsi_Host *host = device->host; 21461da177e4SLinus Torvalds MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata; 21471da177e4SLinus Torvalds VirtDevice *vdev; 21481da177e4SLinus Torvalds uint target = device->id; 21491da177e4SLinus Torvalds 21501da177e4SLinus Torvalds if (hd == NULL) 21511da177e4SLinus Torvalds return -ENODEV; 21521da177e4SLinus Torvalds 21531da177e4SLinus Torvalds if ((vdev = hd->Targets[target]) != NULL) 21541da177e4SLinus Torvalds goto out; 21551da177e4SLinus Torvalds 21561da177e4SLinus Torvalds vdev = kmalloc(sizeof(VirtDevice), GFP_KERNEL); 21571da177e4SLinus Torvalds if (!vdev) { 21581da177e4SLinus Torvalds printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n", 21591da177e4SLinus Torvalds hd->ioc->name, sizeof(VirtDevice)); 21601da177e4SLinus Torvalds return -ENOMEM; 21611da177e4SLinus Torvalds } 21621da177e4SLinus Torvalds 21631da177e4SLinus Torvalds memset(vdev, 0, sizeof(VirtDevice)); 21641da177e4SLinus Torvalds vdev->tflags = MPT_TARGET_FLAGS_Q_YES; 21651da177e4SLinus Torvalds vdev->ioc_id = hd->ioc->id; 21661da177e4SLinus Torvalds vdev->target_id = device->id; 21671da177e4SLinus Torvalds vdev->bus_id = device->channel; 21681da177e4SLinus Torvalds vdev->raidVolume = 0; 21691da177e4SLinus Torvalds hd->Targets[device->id] = vdev; 21701da177e4SLinus Torvalds if (hd->ioc->bus_type == SCSI) { 21711da177e4SLinus Torvalds if (hd->ioc->spi_data.isRaid & (1 << device->id)) { 21721da177e4SLinus Torvalds vdev->raidVolume = 1; 21731da177e4SLinus Torvalds ddvtprintk((KERN_INFO 21741da177e4SLinus Torvalds "RAID Volume @ id %d\n", device->id)); 21751da177e4SLinus Torvalds } 21761da177e4SLinus Torvalds } else { 21771da177e4SLinus Torvalds vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY; 21781da177e4SLinus Torvalds } 21791da177e4SLinus Torvalds 21801da177e4SLinus Torvalds out: 21811da177e4SLinus Torvalds vdev->num_luns++; 21821da177e4SLinus Torvalds return 0; 21831da177e4SLinus Torvalds } 21841da177e4SLinus Torvalds 21850d0c7974SMoore, Eric Dean static int 21860d0c7974SMoore, Eric Dean mptscsih_is_raid_volume(MPT_SCSI_HOST *hd, uint id) 21871da177e4SLinus Torvalds { 21881da177e4SLinus Torvalds int i; 21891da177e4SLinus Torvalds 21901da177e4SLinus Torvalds if (!hd->ioc->spi_data.isRaid || !hd->ioc->spi_data.pIocPg3) 21911da177e4SLinus Torvalds return 0; 21921da177e4SLinus Torvalds 21931da177e4SLinus Torvalds for (i = 0; i < hd->ioc->spi_data.pIocPg3->NumPhysDisks; i++) { 21941da177e4SLinus Torvalds if (id == hd->ioc->spi_data.pIocPg3->PhysDisk[i].PhysDiskID) 21951da177e4SLinus Torvalds return 1; 21961da177e4SLinus Torvalds } 21971da177e4SLinus Torvalds 21981da177e4SLinus Torvalds return 0; 21991da177e4SLinus Torvalds } 22001da177e4SLinus Torvalds 22011da177e4SLinus Torvalds /* 22021da177e4SLinus Torvalds * OS entry point to allow for host driver to free allocated memory 22031da177e4SLinus Torvalds * Called if no device present or device being unloaded 22041da177e4SLinus Torvalds */ 22050d0c7974SMoore, Eric Dean void 22061da177e4SLinus Torvalds mptscsih_slave_destroy(struct scsi_device *device) 22071da177e4SLinus Torvalds { 22081da177e4SLinus Torvalds struct Scsi_Host *host = device->host; 22091da177e4SLinus Torvalds MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata; 22101da177e4SLinus Torvalds VirtDevice *vdev; 22111da177e4SLinus Torvalds uint target = device->id; 22121da177e4SLinus Torvalds uint lun = device->lun; 22131da177e4SLinus Torvalds 22141da177e4SLinus Torvalds if (hd == NULL) 22151da177e4SLinus Torvalds return; 22161da177e4SLinus Torvalds 22171da177e4SLinus Torvalds mptscsih_search_running_cmds(hd, target, lun); 22181da177e4SLinus Torvalds 22191da177e4SLinus Torvalds vdev = hd->Targets[target]; 22201da177e4SLinus Torvalds vdev->luns[0] &= ~(1 << lun); 22211da177e4SLinus Torvalds if (--vdev->num_luns) 22221da177e4SLinus Torvalds return; 22231da177e4SLinus Torvalds 22241da177e4SLinus Torvalds kfree(hd->Targets[target]); 22251da177e4SLinus Torvalds hd->Targets[target] = NULL; 22261da177e4SLinus Torvalds 22271da177e4SLinus Torvalds if (hd->ioc->bus_type == SCSI) { 22281da177e4SLinus Torvalds if (mptscsih_is_raid_volume(hd, target)) { 22291da177e4SLinus Torvalds hd->ioc->spi_data.forceDv |= MPT_SCSICFG_RELOAD_IOC_PG3; 22301da177e4SLinus Torvalds } else { 22311da177e4SLinus Torvalds hd->ioc->spi_data.dvStatus[target] = 22321da177e4SLinus Torvalds MPT_SCSICFG_NEGOTIATE; 22331da177e4SLinus Torvalds 22341da177e4SLinus Torvalds if (!hd->negoNvram) { 22351da177e4SLinus Torvalds hd->ioc->spi_data.dvStatus[target] |= 22361da177e4SLinus Torvalds MPT_SCSICFG_DV_NOT_DONE; 22371da177e4SLinus Torvalds } 22381da177e4SLinus Torvalds } 22391da177e4SLinus Torvalds } 22401da177e4SLinus Torvalds } 22411da177e4SLinus Torvalds 22421da177e4SLinus Torvalds static void 22431da177e4SLinus Torvalds mptscsih_set_queue_depth(struct scsi_device *device, MPT_SCSI_HOST *hd, 22441da177e4SLinus Torvalds VirtDevice *pTarget, int qdepth) 22451da177e4SLinus Torvalds { 22461da177e4SLinus Torvalds int max_depth; 22471da177e4SLinus Torvalds int tagged; 22481da177e4SLinus Torvalds 22491da177e4SLinus Torvalds if (hd->ioc->bus_type == SCSI) { 22501da177e4SLinus Torvalds if (pTarget->tflags & MPT_TARGET_FLAGS_VALID_INQUIRY) { 22511da177e4SLinus Torvalds if (!(pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)) 22521da177e4SLinus Torvalds max_depth = 1; 22531da177e4SLinus Torvalds else if (((pTarget->inq_data[0] & 0x1f) == 0x00) && 22541da177e4SLinus Torvalds (pTarget->minSyncFactor <= MPT_ULTRA160 )) 22551da177e4SLinus Torvalds max_depth = MPT_SCSI_CMD_PER_DEV_HIGH; 22561da177e4SLinus Torvalds else 22571da177e4SLinus Torvalds max_depth = MPT_SCSI_CMD_PER_DEV_LOW; 22581da177e4SLinus Torvalds } else { 22591da177e4SLinus Torvalds /* error case - No Inq. Data */ 22601da177e4SLinus Torvalds max_depth = 1; 22611da177e4SLinus Torvalds } 22621da177e4SLinus Torvalds } else 22631da177e4SLinus Torvalds max_depth = MPT_SCSI_CMD_PER_DEV_HIGH; 22641da177e4SLinus Torvalds 22651da177e4SLinus Torvalds if (qdepth > max_depth) 22661da177e4SLinus Torvalds qdepth = max_depth; 22671da177e4SLinus Torvalds if (qdepth == 1) 22681da177e4SLinus Torvalds tagged = 0; 22691da177e4SLinus Torvalds else 22701da177e4SLinus Torvalds tagged = MSG_SIMPLE_TAG; 22711da177e4SLinus Torvalds 22721da177e4SLinus Torvalds scsi_adjust_queue_depth(device, tagged, qdepth); 22731da177e4SLinus Torvalds } 22741da177e4SLinus Torvalds 22751da177e4SLinus Torvalds 22761da177e4SLinus Torvalds /* 22771da177e4SLinus Torvalds * OS entry point to adjust the queue_depths on a per-device basis. 22781da177e4SLinus Torvalds * Called once per device the bus scan. Use it to force the queue_depth 22791da177e4SLinus Torvalds * member to 1 if a device does not support Q tags. 22801da177e4SLinus Torvalds * Return non-zero if fails. 22811da177e4SLinus Torvalds */ 22820d0c7974SMoore, Eric Dean int 22831da177e4SLinus Torvalds mptscsih_slave_configure(struct scsi_device *device) 22841da177e4SLinus Torvalds { 22851da177e4SLinus Torvalds struct Scsi_Host *sh = device->host; 22861da177e4SLinus Torvalds VirtDevice *pTarget; 22871da177e4SLinus Torvalds MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sh->hostdata; 22881da177e4SLinus Torvalds 22891da177e4SLinus Torvalds if ((hd == NULL) || (hd->Targets == NULL)) { 22901da177e4SLinus Torvalds return 0; 22911da177e4SLinus Torvalds } 22921da177e4SLinus Torvalds 22931da177e4SLinus Torvalds dsprintk((MYIOC_s_INFO_FMT 22941da177e4SLinus Torvalds "device @ %p, id=%d, LUN=%d, channel=%d\n", 22951da177e4SLinus Torvalds hd->ioc->name, device, device->id, device->lun, device->channel)); 22961da177e4SLinus Torvalds dsprintk((MYIOC_s_INFO_FMT 22971da177e4SLinus Torvalds "sdtr %d wdtr %d ppr %d inq length=%d\n", 22981da177e4SLinus Torvalds hd->ioc->name, device->sdtr, device->wdtr, 22991da177e4SLinus Torvalds device->ppr, device->inquiry_len)); 23001da177e4SLinus Torvalds 23011da177e4SLinus Torvalds if (device->id > sh->max_id) { 23021da177e4SLinus Torvalds /* error case, should never happen */ 23031da177e4SLinus Torvalds scsi_adjust_queue_depth(device, 0, 1); 23041da177e4SLinus Torvalds goto slave_configure_exit; 23051da177e4SLinus Torvalds } 23061da177e4SLinus Torvalds 23071da177e4SLinus Torvalds pTarget = hd->Targets[device->id]; 23081da177e4SLinus Torvalds 23091da177e4SLinus Torvalds if (pTarget == NULL) { 23101da177e4SLinus Torvalds /* Driver doesn't know about this device. 23111da177e4SLinus Torvalds * Kernel may generate a "Dummy Lun 0" which 23121da177e4SLinus Torvalds * may become a real Lun if a 23131da177e4SLinus Torvalds * "scsi add-single-device" command is executed 23141da177e4SLinus Torvalds * while the driver is active (hot-plug a 23151da177e4SLinus Torvalds * device). LSI Raid controllers need 23161da177e4SLinus Torvalds * queue_depth set to DEV_HIGH for this reason. 23171da177e4SLinus Torvalds */ 23181da177e4SLinus Torvalds scsi_adjust_queue_depth(device, MSG_SIMPLE_TAG, 23191da177e4SLinus Torvalds MPT_SCSI_CMD_PER_DEV_HIGH); 23201da177e4SLinus Torvalds goto slave_configure_exit; 23211da177e4SLinus Torvalds } 23221da177e4SLinus Torvalds 23231da177e4SLinus Torvalds mptscsih_initTarget(hd, device->channel, device->id, device->lun, 23241da177e4SLinus Torvalds device->inquiry, device->inquiry_len ); 23251da177e4SLinus Torvalds mptscsih_set_queue_depth(device, hd, pTarget, MPT_SCSI_CMD_PER_DEV_HIGH); 23261da177e4SLinus Torvalds 23271da177e4SLinus Torvalds dsprintk((MYIOC_s_INFO_FMT 23281da177e4SLinus Torvalds "Queue depth=%d, tflags=%x\n", 23291da177e4SLinus Torvalds hd->ioc->name, device->queue_depth, pTarget->tflags)); 23301da177e4SLinus Torvalds 23311da177e4SLinus Torvalds dsprintk((MYIOC_s_INFO_FMT 23321da177e4SLinus Torvalds "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n", 23331da177e4SLinus Torvalds hd->ioc->name, pTarget->negoFlags, pTarget->maxOffset, pTarget->minSyncFactor)); 23341da177e4SLinus Torvalds 23351da177e4SLinus Torvalds slave_configure_exit: 23361da177e4SLinus Torvalds 23371da177e4SLinus Torvalds dsprintk((MYIOC_s_INFO_FMT 23381da177e4SLinus Torvalds "tagged %d, simple %d, ordered %d\n", 23391da177e4SLinus Torvalds hd->ioc->name,device->tagged_supported, device->simple_tags, 23401da177e4SLinus Torvalds device->ordered_tags)); 23411da177e4SLinus Torvalds 23421da177e4SLinus Torvalds return 0; 23431da177e4SLinus Torvalds } 23441da177e4SLinus Torvalds 23450d0c7974SMoore, Eric Dean ssize_t 23461da177e4SLinus Torvalds mptscsih_store_queue_depth(struct device *dev, const char *buf, size_t count) 23471da177e4SLinus Torvalds { 23481da177e4SLinus Torvalds int depth; 23491da177e4SLinus Torvalds struct scsi_device *sdev = to_scsi_device(dev); 23501da177e4SLinus Torvalds MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) sdev->host->hostdata; 23511da177e4SLinus Torvalds VirtDevice *pTarget; 23521da177e4SLinus Torvalds 23531da177e4SLinus Torvalds depth = simple_strtoul(buf, NULL, 0); 23541da177e4SLinus Torvalds if (depth == 0) 23551da177e4SLinus Torvalds return -EINVAL; 23561da177e4SLinus Torvalds pTarget = hd->Targets[sdev->id]; 23571da177e4SLinus Torvalds if (pTarget == NULL) 23581da177e4SLinus Torvalds return -EINVAL; 23591da177e4SLinus Torvalds mptscsih_set_queue_depth(sdev, (MPT_SCSI_HOST *) sdev->host->hostdata, 23601da177e4SLinus Torvalds pTarget, depth); 23611da177e4SLinus Torvalds return count; 23621da177e4SLinus Torvalds } 23631da177e4SLinus Torvalds 23641da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 23651da177e4SLinus Torvalds /* 23661da177e4SLinus Torvalds * Private routines... 23671da177e4SLinus Torvalds */ 23681da177e4SLinus Torvalds 23691da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 23701da177e4SLinus Torvalds /* Utility function to copy sense data from the scsi_cmnd buffer 23711da177e4SLinus Torvalds * to the FC and SCSI target structures. 23721da177e4SLinus Torvalds * 23731da177e4SLinus Torvalds */ 23741da177e4SLinus Torvalds static void 23750d0c7974SMoore, Eric Dean mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply) 23761da177e4SLinus Torvalds { 23771da177e4SLinus Torvalds VirtDevice *target; 23781da177e4SLinus Torvalds SCSIIORequest_t *pReq; 23791da177e4SLinus Torvalds u32 sense_count = le32_to_cpu(pScsiReply->SenseCount); 23801da177e4SLinus Torvalds int index; 23811da177e4SLinus Torvalds 23821da177e4SLinus Torvalds /* Get target structure 23831da177e4SLinus Torvalds */ 23841da177e4SLinus Torvalds pReq = (SCSIIORequest_t *) mf; 23851da177e4SLinus Torvalds index = (int) pReq->TargetID; 23861da177e4SLinus Torvalds target = hd->Targets[index]; 23871da177e4SLinus Torvalds 23881da177e4SLinus Torvalds if (sense_count) { 23891da177e4SLinus Torvalds u8 *sense_data; 23901da177e4SLinus Torvalds int req_index; 23911da177e4SLinus Torvalds 23921da177e4SLinus Torvalds /* Copy the sense received into the scsi command block. */ 23931da177e4SLinus Torvalds req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 23941da177e4SLinus Torvalds sense_data = ((u8 *)hd->ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC)); 23951da177e4SLinus Torvalds memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc)); 23961da177e4SLinus Torvalds 23971da177e4SLinus Torvalds /* Log SMART data (asc = 0x5D, non-IM case only) if required. 23981da177e4SLinus Torvalds */ 23991da177e4SLinus Torvalds if ((hd->ioc->events) && (hd->ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) { 24001da177e4SLinus Torvalds if ((sense_data[12] == 0x5D) && (target->raidVolume == 0)) { 24011da177e4SLinus Torvalds int idx; 24021da177e4SLinus Torvalds MPT_ADAPTER *ioc = hd->ioc; 24031da177e4SLinus Torvalds 24041da177e4SLinus Torvalds idx = ioc->eventContext % ioc->eventLogSize; 24051da177e4SLinus Torvalds ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE; 24061da177e4SLinus Torvalds ioc->events[idx].eventContext = ioc->eventContext; 24071da177e4SLinus Torvalds 24081da177e4SLinus Torvalds ioc->events[idx].data[0] = (pReq->LUN[1] << 24) || 24091da177e4SLinus Torvalds (MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) || 24101da177e4SLinus Torvalds (pReq->Bus << 8) || pReq->TargetID; 24111da177e4SLinus Torvalds 24121da177e4SLinus Torvalds ioc->events[idx].data[1] = (sense_data[13] << 8) || sense_data[12]; 24131da177e4SLinus Torvalds 24141da177e4SLinus Torvalds ioc->eventContext++; 24151da177e4SLinus Torvalds } 24161da177e4SLinus Torvalds } 24171da177e4SLinus Torvalds } else { 24181da177e4SLinus Torvalds dprintk((MYIOC_s_INFO_FMT "Hmmm... SenseData len=0! (?)\n", 24191da177e4SLinus Torvalds hd->ioc->name)); 24201da177e4SLinus Torvalds } 24211da177e4SLinus Torvalds } 24221da177e4SLinus Torvalds 24231da177e4SLinus Torvalds static u32 24241da177e4SLinus Torvalds SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc) 24251da177e4SLinus Torvalds { 24261da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 24271da177e4SLinus Torvalds int i; 24281da177e4SLinus Torvalds 24291da177e4SLinus Torvalds hd = (MPT_SCSI_HOST *) sc->device->host->hostdata; 24301da177e4SLinus Torvalds 24311da177e4SLinus Torvalds for (i = 0; i < hd->ioc->req_depth; i++) { 24321da177e4SLinus Torvalds if (hd->ScsiLookup[i] == sc) { 24331da177e4SLinus Torvalds return i; 24341da177e4SLinus Torvalds } 24351da177e4SLinus Torvalds } 24361da177e4SLinus Torvalds 24371da177e4SLinus Torvalds return -1; 24381da177e4SLinus Torvalds } 24391da177e4SLinus Torvalds 24401da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 24410d0c7974SMoore, Eric Dean int 24421da177e4SLinus Torvalds mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) 24431da177e4SLinus Torvalds { 24441da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 24451da177e4SLinus Torvalds unsigned long flags; 24461da177e4SLinus Torvalds 24471da177e4SLinus Torvalds dtmprintk((KERN_WARNING MYNAM 24481da177e4SLinus Torvalds ": IOC %s_reset routed to SCSI host driver!\n", 24491da177e4SLinus Torvalds reset_phase==MPT_IOC_SETUP_RESET ? "setup" : ( 24501da177e4SLinus Torvalds reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post"))); 24511da177e4SLinus Torvalds 24521da177e4SLinus Torvalds /* If a FW reload request arrives after base installed but 24531da177e4SLinus Torvalds * before all scsi hosts have been attached, then an alt_ioc 24541da177e4SLinus Torvalds * may have a NULL sh pointer. 24551da177e4SLinus Torvalds */ 24561da177e4SLinus Torvalds if ((ioc->sh == NULL) || (ioc->sh->hostdata == NULL)) 24571da177e4SLinus Torvalds return 0; 24581da177e4SLinus Torvalds else 24591da177e4SLinus Torvalds hd = (MPT_SCSI_HOST *) ioc->sh->hostdata; 24601da177e4SLinus Torvalds 24611da177e4SLinus Torvalds if (reset_phase == MPT_IOC_SETUP_RESET) { 24621da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT "Setup-Diag Reset\n", ioc->name)); 24631da177e4SLinus Torvalds 24641da177e4SLinus Torvalds /* Clean Up: 24651da177e4SLinus Torvalds * 1. Set Hard Reset Pending Flag 24661da177e4SLinus Torvalds * All new commands go to doneQ 24671da177e4SLinus Torvalds */ 24681da177e4SLinus Torvalds hd->resetPending = 1; 24691da177e4SLinus Torvalds 24701da177e4SLinus Torvalds } else if (reset_phase == MPT_IOC_PRE_RESET) { 24711da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT "Pre-Diag Reset\n", ioc->name)); 24721da177e4SLinus Torvalds 24731da177e4SLinus Torvalds /* 2. Flush running commands 24741da177e4SLinus Torvalds * Clean ScsiLookup (and associated memory) 24751da177e4SLinus Torvalds * AND clean mytaskQ 24761da177e4SLinus Torvalds */ 24771da177e4SLinus Torvalds 24781da177e4SLinus Torvalds /* 2b. Reply to OS all known outstanding I/O commands. 24791da177e4SLinus Torvalds */ 24801da177e4SLinus Torvalds mptscsih_flush_running_cmds(hd); 24811da177e4SLinus Torvalds 24821da177e4SLinus Torvalds /* 2c. If there was an internal command that 24831da177e4SLinus Torvalds * has not completed, configuration or io request, 24841da177e4SLinus Torvalds * free these resources. 24851da177e4SLinus Torvalds */ 24861da177e4SLinus Torvalds if (hd->cmdPtr) { 24871da177e4SLinus Torvalds del_timer(&hd->timer); 24881da177e4SLinus Torvalds mpt_free_msg_frame(ioc, hd->cmdPtr); 24891da177e4SLinus Torvalds } 24901da177e4SLinus Torvalds 24911da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT "Pre-Reset complete.\n", ioc->name)); 24921da177e4SLinus Torvalds 24931da177e4SLinus Torvalds } else { 24941da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT "Post-Diag Reset\n", ioc->name)); 24951da177e4SLinus Torvalds 24961da177e4SLinus Torvalds /* Once a FW reload begins, all new OS commands are 24971da177e4SLinus Torvalds * redirected to the doneQ w/ a reset status. 24981da177e4SLinus Torvalds * Init all control structures. 24991da177e4SLinus Torvalds */ 25001da177e4SLinus Torvalds 25011da177e4SLinus Torvalds /* ScsiLookup initialization 25021da177e4SLinus Torvalds */ 25031da177e4SLinus Torvalds { 25041da177e4SLinus Torvalds int ii; 25051da177e4SLinus Torvalds for (ii=0; ii < hd->ioc->req_depth; ii++) 25061da177e4SLinus Torvalds hd->ScsiLookup[ii] = NULL; 25071da177e4SLinus Torvalds } 25081da177e4SLinus Torvalds 25091da177e4SLinus Torvalds /* 2. Chain Buffer initialization 25101da177e4SLinus Torvalds */ 25111da177e4SLinus Torvalds 25121da177e4SLinus Torvalds /* 4. Renegotiate to all devices, if SCSI 25131da177e4SLinus Torvalds */ 25141da177e4SLinus Torvalds if (ioc->bus_type == SCSI) { 25151da177e4SLinus Torvalds dnegoprintk(("writeSDP1: ALL_IDS USE_NVRAM\n")); 25161da177e4SLinus Torvalds mptscsih_writeSDP1(hd, 0, 0, MPT_SCSICFG_ALL_IDS | MPT_SCSICFG_USE_NVRAM); 25171da177e4SLinus Torvalds } 25181da177e4SLinus Torvalds 25191da177e4SLinus Torvalds /* 5. Enable new commands to be posted 25201da177e4SLinus Torvalds */ 25211da177e4SLinus Torvalds spin_lock_irqsave(&ioc->FreeQlock, flags); 25221da177e4SLinus Torvalds hd->tmPending = 0; 25231da177e4SLinus Torvalds spin_unlock_irqrestore(&ioc->FreeQlock, flags); 25241da177e4SLinus Torvalds hd->resetPending = 0; 25251da177e4SLinus Torvalds hd->tmState = TM_STATE_NONE; 25261da177e4SLinus Torvalds 25271da177e4SLinus Torvalds /* 6. If there was an internal command, 25281da177e4SLinus Torvalds * wake this process up. 25291da177e4SLinus Torvalds */ 25301da177e4SLinus Torvalds if (hd->cmdPtr) { 25311da177e4SLinus Torvalds /* 25321da177e4SLinus Torvalds * Wake up the original calling thread 25331da177e4SLinus Torvalds */ 25341da177e4SLinus Torvalds hd->pLocal = &hd->localReply; 25351da177e4SLinus Torvalds hd->pLocal->completion = MPT_SCANDV_DID_RESET; 25360d0c7974SMoore, Eric Dean hd->scandv_wait_done = 1; 25370d0c7974SMoore, Eric Dean wake_up(&hd->scandv_waitq); 25381da177e4SLinus Torvalds hd->cmdPtr = NULL; 25391da177e4SLinus Torvalds } 25401da177e4SLinus Torvalds 25411da177e4SLinus Torvalds /* 7. Set flag to force DV and re-read IOC Page 3 25421da177e4SLinus Torvalds */ 25431da177e4SLinus Torvalds if (ioc->bus_type == SCSI) { 25441da177e4SLinus Torvalds ioc->spi_data.forceDv = MPT_SCSICFG_NEED_DV | MPT_SCSICFG_RELOAD_IOC_PG3; 25451da177e4SLinus Torvalds ddvtprintk(("Set reload IOC Pg3 Flag\n")); 25461da177e4SLinus Torvalds } 25471da177e4SLinus Torvalds 25481da177e4SLinus Torvalds dtmprintk((MYIOC_s_WARN_FMT "Post-Reset complete.\n", ioc->name)); 25491da177e4SLinus Torvalds 25501da177e4SLinus Torvalds } 25511da177e4SLinus Torvalds 25521da177e4SLinus Torvalds return 1; /* currently means nothing really */ 25531da177e4SLinus Torvalds } 25541da177e4SLinus Torvalds 25551da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 25560d0c7974SMoore, Eric Dean int 25571da177e4SLinus Torvalds mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply) 25581da177e4SLinus Torvalds { 25591da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 25601da177e4SLinus Torvalds u8 event = le32_to_cpu(pEvReply->Event) & 0xFF; 25611da177e4SLinus Torvalds 25621da177e4SLinus Torvalds devtprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n", 25631da177e4SLinus Torvalds ioc->name, event)); 25641da177e4SLinus Torvalds 25651da177e4SLinus Torvalds switch (event) { 25661da177e4SLinus Torvalds case MPI_EVENT_UNIT_ATTENTION: /* 03 */ 25671da177e4SLinus Torvalds /* FIXME! */ 25681da177e4SLinus Torvalds break; 25691da177e4SLinus Torvalds case MPI_EVENT_IOC_BUS_RESET: /* 04 */ 25701da177e4SLinus Torvalds case MPI_EVENT_EXT_BUS_RESET: /* 05 */ 25711da177e4SLinus Torvalds hd = NULL; 25721da177e4SLinus Torvalds if (ioc->sh) { 25731da177e4SLinus Torvalds hd = (MPT_SCSI_HOST *) ioc->sh->hostdata; 25741da177e4SLinus Torvalds if (hd && (ioc->bus_type == SCSI) && (hd->soft_resets < -1)) 25751da177e4SLinus Torvalds hd->soft_resets++; 25761da177e4SLinus Torvalds } 25771da177e4SLinus Torvalds break; 25781da177e4SLinus Torvalds case MPI_EVENT_LOGOUT: /* 09 */ 25791da177e4SLinus Torvalds /* FIXME! */ 25801da177e4SLinus Torvalds break; 25811da177e4SLinus Torvalds 25821da177e4SLinus Torvalds /* 25831da177e4SLinus Torvalds * CHECKME! Don't think we need to do 25841da177e4SLinus Torvalds * anything for these, but... 25851da177e4SLinus Torvalds */ 25861da177e4SLinus Torvalds case MPI_EVENT_RESCAN: /* 06 */ 25871da177e4SLinus Torvalds case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */ 25881da177e4SLinus Torvalds case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */ 25891da177e4SLinus Torvalds /* 25901da177e4SLinus Torvalds * CHECKME! Falling thru... 25911da177e4SLinus Torvalds */ 25921da177e4SLinus Torvalds break; 25931da177e4SLinus Torvalds 25941da177e4SLinus Torvalds case MPI_EVENT_INTEGRATED_RAID: /* 0B */ 25951da177e4SLinus Torvalds #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION 25961da177e4SLinus Torvalds /* negoNvram set to 0 if DV enabled and to USE_NVRAM if 25971da177e4SLinus Torvalds * if DV disabled. Need to check for target mode. 25981da177e4SLinus Torvalds */ 25991da177e4SLinus Torvalds hd = NULL; 26001da177e4SLinus Torvalds if (ioc->sh) 26011da177e4SLinus Torvalds hd = (MPT_SCSI_HOST *) ioc->sh->hostdata; 26021da177e4SLinus Torvalds 26031da177e4SLinus Torvalds if (hd && (ioc->bus_type == SCSI) && (hd->negoNvram == 0)) { 26041da177e4SLinus Torvalds ScsiCfgData *pSpi; 26051da177e4SLinus Torvalds Ioc3PhysDisk_t *pPDisk; 26061da177e4SLinus Torvalds int numPDisk; 26071da177e4SLinus Torvalds u8 reason; 26081da177e4SLinus Torvalds u8 physDiskNum; 26091da177e4SLinus Torvalds 26101da177e4SLinus Torvalds reason = (le32_to_cpu(pEvReply->Data[0]) & 0x00FF0000) >> 16; 26111da177e4SLinus Torvalds if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) { 26121da177e4SLinus Torvalds /* New or replaced disk. 26131da177e4SLinus Torvalds * Set DV flag and schedule DV. 26141da177e4SLinus Torvalds */ 26151da177e4SLinus Torvalds pSpi = &ioc->spi_data; 26161da177e4SLinus Torvalds physDiskNum = (le32_to_cpu(pEvReply->Data[0]) & 0xFF000000) >> 24; 26171da177e4SLinus Torvalds ddvtprintk(("DV requested for phys disk id %d\n", physDiskNum)); 26181da177e4SLinus Torvalds if (pSpi->pIocPg3) { 26191da177e4SLinus Torvalds pPDisk = pSpi->pIocPg3->PhysDisk; 26201da177e4SLinus Torvalds numPDisk =pSpi->pIocPg3->NumPhysDisks; 26211da177e4SLinus Torvalds 26221da177e4SLinus Torvalds while (numPDisk) { 26231da177e4SLinus Torvalds if (physDiskNum == pPDisk->PhysDiskNum) { 26241da177e4SLinus Torvalds pSpi->dvStatus[pPDisk->PhysDiskID] = (MPT_SCSICFG_NEED_DV | MPT_SCSICFG_DV_NOT_DONE); 26251da177e4SLinus Torvalds pSpi->forceDv = MPT_SCSICFG_NEED_DV; 26261da177e4SLinus Torvalds ddvtprintk(("NEED_DV set for phys disk id %d\n", pPDisk->PhysDiskID)); 26271da177e4SLinus Torvalds break; 26281da177e4SLinus Torvalds } 26291da177e4SLinus Torvalds pPDisk++; 26301da177e4SLinus Torvalds numPDisk--; 26311da177e4SLinus Torvalds } 26321da177e4SLinus Torvalds 26331da177e4SLinus Torvalds if (numPDisk == 0) { 26341da177e4SLinus Torvalds /* The physical disk that needs DV was not found 26351da177e4SLinus Torvalds * in the stored IOC Page 3. The driver must reload 26361da177e4SLinus Torvalds * this page. DV routine will set the NEED_DV flag for 26371da177e4SLinus Torvalds * all phys disks that have DV_NOT_DONE set. 26381da177e4SLinus Torvalds */ 26391da177e4SLinus Torvalds pSpi->forceDv = MPT_SCSICFG_NEED_DV | MPT_SCSICFG_RELOAD_IOC_PG3; 26401da177e4SLinus Torvalds ddvtprintk(("phys disk %d not found. Setting reload IOC Pg3 Flag\n", physDiskNum)); 26411da177e4SLinus Torvalds } 26421da177e4SLinus Torvalds } 26431da177e4SLinus Torvalds } 26441da177e4SLinus Torvalds } 26451da177e4SLinus Torvalds #endif 26461da177e4SLinus Torvalds 26471da177e4SLinus Torvalds #if defined(MPT_DEBUG_DV) || defined(MPT_DEBUG_DV_TINY) 26481da177e4SLinus Torvalds printk("Raid Event RF: "); 26491da177e4SLinus Torvalds { 26501da177e4SLinus Torvalds u32 *m = (u32 *)pEvReply; 26511da177e4SLinus Torvalds int ii; 26521da177e4SLinus Torvalds int n = (int)pEvReply->MsgLength; 26531da177e4SLinus Torvalds for (ii=6; ii < n; ii++) 26541da177e4SLinus Torvalds printk(" %08x", le32_to_cpu(m[ii])); 26551da177e4SLinus Torvalds printk("\n"); 26561da177e4SLinus Torvalds } 26571da177e4SLinus Torvalds #endif 26581da177e4SLinus Torvalds break; 26591da177e4SLinus Torvalds 26601da177e4SLinus Torvalds case MPI_EVENT_NONE: /* 00 */ 26611da177e4SLinus Torvalds case MPI_EVENT_LOG_DATA: /* 01 */ 26621da177e4SLinus Torvalds case MPI_EVENT_STATE_CHANGE: /* 02 */ 26631da177e4SLinus Torvalds case MPI_EVENT_EVENT_CHANGE: /* 0A */ 26641da177e4SLinus Torvalds default: 26651da177e4SLinus Torvalds dprintk((KERN_INFO " Ignoring event (=%02Xh)\n", event)); 26661da177e4SLinus Torvalds break; 26671da177e4SLinus Torvalds } 26681da177e4SLinus Torvalds 26691da177e4SLinus Torvalds return 1; /* currently means nothing really */ 26701da177e4SLinus Torvalds } 26711da177e4SLinus Torvalds 26721da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 26731da177e4SLinus Torvalds /* 26741da177e4SLinus Torvalds * mptscsih_initTarget - Target, LUN alloc/free functionality. 26751da177e4SLinus Torvalds * @hd: Pointer to MPT_SCSI_HOST structure 26761da177e4SLinus Torvalds * @bus_id: Bus number (?) 26771da177e4SLinus Torvalds * @target_id: SCSI target id 26781da177e4SLinus Torvalds * @lun: SCSI LUN id 26791da177e4SLinus Torvalds * @data: Pointer to data 26801da177e4SLinus Torvalds * @dlen: Number of INQUIRY bytes 26811da177e4SLinus Torvalds * 26821da177e4SLinus Torvalds * NOTE: It's only SAFE to call this routine if data points to 26831da177e4SLinus Torvalds * sane & valid STANDARD INQUIRY data! 26841da177e4SLinus Torvalds * 26851da177e4SLinus Torvalds * Allocate and initialize memory for this target. 26861da177e4SLinus Torvalds * Save inquiry data. 26871da177e4SLinus Torvalds * 26881da177e4SLinus Torvalds */ 26891da177e4SLinus Torvalds static void 26901da177e4SLinus Torvalds mptscsih_initTarget(MPT_SCSI_HOST *hd, int bus_id, int target_id, u8 lun, char *data, int dlen) 26911da177e4SLinus Torvalds { 26921da177e4SLinus Torvalds int indexed_lun, lun_index; 26931da177e4SLinus Torvalds VirtDevice *vdev; 26941da177e4SLinus Torvalds ScsiCfgData *pSpi; 26951da177e4SLinus Torvalds char data_56; 26961da177e4SLinus Torvalds 26971da177e4SLinus Torvalds dinitprintk((MYIOC_s_INFO_FMT "initTarget bus=%d id=%d lun=%d hd=%p\n", 26981da177e4SLinus Torvalds hd->ioc->name, bus_id, target_id, lun, hd)); 26991da177e4SLinus Torvalds 27001da177e4SLinus Torvalds /* 27011da177e4SLinus Torvalds * If the peripheral qualifier filter is enabled then if the target reports a 0x1 27021da177e4SLinus Torvalds * (i.e. The targer is capable of supporting the specified peripheral device type 27031da177e4SLinus Torvalds * on this logical unit; however, the physical device is not currently connected 27041da177e4SLinus Torvalds * to this logical unit) it will be converted to a 0x3 (i.e. The target is not 27051da177e4SLinus Torvalds * capable of supporting a physical device on this logical unit). This is to work 27061da177e4SLinus Torvalds * around a bug in th emid-layer in some distributions in which the mid-layer will 27071da177e4SLinus Torvalds * continue to try to communicate to the LUN and evntually create a dummy LUN. 27081da177e4SLinus Torvalds */ 27090d0c7974SMoore, Eric Dean if (hd->mpt_pq_filter && dlen && (data[0] & 0xE0)) 27101da177e4SLinus Torvalds data[0] |= 0x40; 27111da177e4SLinus Torvalds 27121da177e4SLinus Torvalds /* Is LUN supported? If so, upper 2 bits will be 0 27131da177e4SLinus Torvalds * in first byte of inquiry data. 27141da177e4SLinus Torvalds */ 27151da177e4SLinus Torvalds if (data[0] & 0xe0) 27161da177e4SLinus Torvalds return; 27171da177e4SLinus Torvalds 27181da177e4SLinus Torvalds if ((vdev = hd->Targets[target_id]) == NULL) { 27191da177e4SLinus Torvalds return; 27201da177e4SLinus Torvalds } 27211da177e4SLinus Torvalds 27221da177e4SLinus Torvalds lun_index = (lun >> 5); /* 32 luns per lun_index */ 27231da177e4SLinus Torvalds indexed_lun = (lun % 32); 27241da177e4SLinus Torvalds vdev->luns[lun_index] |= (1 << indexed_lun); 27251da177e4SLinus Torvalds 27261da177e4SLinus Torvalds if (hd->ioc->bus_type == SCSI) { 27271da177e4SLinus Torvalds if ((data[0] == TYPE_PROCESSOR) && (hd->ioc->spi_data.Saf_Te)) { 27281da177e4SLinus Torvalds /* Treat all Processors as SAF-TE if 27291da177e4SLinus Torvalds * command line option is set */ 27301da177e4SLinus Torvalds vdev->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED; 27311da177e4SLinus Torvalds mptscsih_writeIOCPage4(hd, target_id, bus_id); 27321da177e4SLinus Torvalds }else if ((data[0] == TYPE_PROCESSOR) && 27331da177e4SLinus Torvalds !(vdev->tflags & MPT_TARGET_FLAGS_SAF_TE_ISSUED )) { 27341da177e4SLinus Torvalds if ( dlen > 49 ) { 27351da177e4SLinus Torvalds vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY; 27361da177e4SLinus Torvalds if ( data[44] == 'S' && 27371da177e4SLinus Torvalds data[45] == 'A' && 27381da177e4SLinus Torvalds data[46] == 'F' && 27391da177e4SLinus Torvalds data[47] == '-' && 27401da177e4SLinus Torvalds data[48] == 'T' && 27411da177e4SLinus Torvalds data[49] == 'E' ) { 27421da177e4SLinus Torvalds vdev->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED; 27431da177e4SLinus Torvalds mptscsih_writeIOCPage4(hd, target_id, bus_id); 27441da177e4SLinus Torvalds } 27451da177e4SLinus Torvalds } 27461da177e4SLinus Torvalds } 27471da177e4SLinus Torvalds if (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_INQUIRY)) { 27481da177e4SLinus Torvalds if ( dlen > 8 ) { 27491da177e4SLinus Torvalds memcpy (vdev->inq_data, data, 8); 27501da177e4SLinus Torvalds } else { 27511da177e4SLinus Torvalds memcpy (vdev->inq_data, data, dlen); 27521da177e4SLinus Torvalds } 27531da177e4SLinus Torvalds 27541da177e4SLinus Torvalds /* If have not done DV, set the DV flag. 27551da177e4SLinus Torvalds */ 27561da177e4SLinus Torvalds pSpi = &hd->ioc->spi_data; 27571da177e4SLinus Torvalds if ((data[0] == TYPE_TAPE) || (data[0] == TYPE_PROCESSOR)) { 27581da177e4SLinus Torvalds if (pSpi->dvStatus[target_id] & MPT_SCSICFG_DV_NOT_DONE) 27591da177e4SLinus Torvalds pSpi->dvStatus[target_id] |= MPT_SCSICFG_NEED_DV; 27601da177e4SLinus Torvalds } 27611da177e4SLinus Torvalds 27621da177e4SLinus Torvalds vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY; 27631da177e4SLinus Torvalds 27641da177e4SLinus Torvalds 27651da177e4SLinus Torvalds data_56 = 0x0F; /* Default to full capabilities if Inq data length is < 57 */ 27661da177e4SLinus Torvalds if (dlen > 56) { 27671da177e4SLinus Torvalds if ( (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_56))) { 27681da177e4SLinus Torvalds /* Update the target capabilities 27691da177e4SLinus Torvalds */ 27701da177e4SLinus Torvalds data_56 = data[56]; 27711da177e4SLinus Torvalds vdev->tflags |= MPT_TARGET_FLAGS_VALID_56; 27721da177e4SLinus Torvalds } 27731da177e4SLinus Torvalds } 27741da177e4SLinus Torvalds mptscsih_setTargetNegoParms(hd, vdev, data_56); 27751da177e4SLinus Torvalds } else { 27761da177e4SLinus Torvalds /* Initial Inquiry may not request enough data bytes to 27771da177e4SLinus Torvalds * obtain byte 57. DV will; if target doesn't return 27781da177e4SLinus Torvalds * at least 57 bytes, data[56] will be zero. */ 27791da177e4SLinus Torvalds if (dlen > 56) { 27801da177e4SLinus Torvalds if ( (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_56))) { 27811da177e4SLinus Torvalds /* Update the target capabilities 27821da177e4SLinus Torvalds */ 27831da177e4SLinus Torvalds data_56 = data[56]; 27841da177e4SLinus Torvalds vdev->tflags |= MPT_TARGET_FLAGS_VALID_56; 27851da177e4SLinus Torvalds mptscsih_setTargetNegoParms(hd, vdev, data_56); 27861da177e4SLinus Torvalds } 27871da177e4SLinus Torvalds } 27881da177e4SLinus Torvalds } 27891da177e4SLinus Torvalds } 27901da177e4SLinus Torvalds } 27911da177e4SLinus Torvalds 27921da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 27931da177e4SLinus Torvalds /* 27941da177e4SLinus Torvalds * Update the target negotiation parameters based on the 27951da177e4SLinus Torvalds * the Inquiry data, adapter capabilities, and NVRAM settings. 27961da177e4SLinus Torvalds * 27971da177e4SLinus Torvalds */ 27981da177e4SLinus Torvalds static void 27991da177e4SLinus Torvalds mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtDevice *target, char byte56) 28001da177e4SLinus Torvalds { 28011da177e4SLinus Torvalds ScsiCfgData *pspi_data = &hd->ioc->spi_data; 28021da177e4SLinus Torvalds int id = (int) target->target_id; 28031da177e4SLinus Torvalds int nvram; 28041da177e4SLinus Torvalds VirtDevice *vdev; 28051da177e4SLinus Torvalds int ii; 28061da177e4SLinus Torvalds u8 width = MPT_NARROW; 28071da177e4SLinus Torvalds u8 factor = MPT_ASYNC; 28081da177e4SLinus Torvalds u8 offset = 0; 28091da177e4SLinus Torvalds u8 version, nfactor; 28101da177e4SLinus Torvalds u8 noQas = 1; 28111da177e4SLinus Torvalds 28121da177e4SLinus Torvalds target->negoFlags = pspi_data->noQas; 28131da177e4SLinus Torvalds 28141da177e4SLinus Torvalds /* noQas == 0 => device supports QAS. Need byte 56 of Inq to determine 28151da177e4SLinus Torvalds * support. If available, default QAS to off and allow enabling. 28161da177e4SLinus Torvalds * If not available, default QAS to on, turn off for non-disks. 28171da177e4SLinus Torvalds */ 28181da177e4SLinus Torvalds 28191da177e4SLinus Torvalds /* Set flags based on Inquiry data 28201da177e4SLinus Torvalds */ 28211da177e4SLinus Torvalds version = target->inq_data[2] & 0x07; 28221da177e4SLinus Torvalds if (version < 2) { 28231da177e4SLinus Torvalds width = 0; 28241da177e4SLinus Torvalds factor = MPT_ULTRA2; 28251da177e4SLinus Torvalds offset = pspi_data->maxSyncOffset; 28261da177e4SLinus Torvalds target->tflags &= ~MPT_TARGET_FLAGS_Q_YES; 28271da177e4SLinus Torvalds } else { 28281da177e4SLinus Torvalds if (target->inq_data[7] & 0x20) { 28291da177e4SLinus Torvalds width = 1; 28301da177e4SLinus Torvalds } 28311da177e4SLinus Torvalds 28321da177e4SLinus Torvalds if (target->inq_data[7] & 0x10) { 28331da177e4SLinus Torvalds factor = pspi_data->minSyncFactor; 28341da177e4SLinus Torvalds if (target->tflags & MPT_TARGET_FLAGS_VALID_56) { 28351da177e4SLinus Torvalds /* bits 2 & 3 show Clocking support */ 28361da177e4SLinus Torvalds if ((byte56 & 0x0C) == 0) 28371da177e4SLinus Torvalds factor = MPT_ULTRA2; 28381da177e4SLinus Torvalds else { 28391da177e4SLinus Torvalds if ((byte56 & 0x03) == 0) 28401da177e4SLinus Torvalds factor = MPT_ULTRA160; 28411da177e4SLinus Torvalds else { 28421da177e4SLinus Torvalds factor = MPT_ULTRA320; 28431da177e4SLinus Torvalds if (byte56 & 0x02) 28441da177e4SLinus Torvalds { 28451da177e4SLinus Torvalds ddvtprintk((KERN_INFO "Enabling QAS due to byte56=%02x on id=%d!\n", byte56, id)); 28461da177e4SLinus Torvalds noQas = 0; 28471da177e4SLinus Torvalds } 28481da177e4SLinus Torvalds if (target->inq_data[0] == TYPE_TAPE) { 28491da177e4SLinus Torvalds if (byte56 & 0x01) 28501da177e4SLinus Torvalds target->negoFlags |= MPT_TAPE_NEGO_IDP; 28511da177e4SLinus Torvalds } 28521da177e4SLinus Torvalds } 28531da177e4SLinus Torvalds } 28541da177e4SLinus Torvalds } else { 28551da177e4SLinus Torvalds ddvtprintk((KERN_INFO "Enabling QAS on id=%d due to ~TARGET_FLAGS_VALID_56!\n", id)); 28561da177e4SLinus Torvalds noQas = 0; 28571da177e4SLinus Torvalds } 28581da177e4SLinus Torvalds 28591da177e4SLinus Torvalds offset = pspi_data->maxSyncOffset; 28601da177e4SLinus Torvalds 28611da177e4SLinus Torvalds /* If RAID, never disable QAS 28621da177e4SLinus Torvalds * else if non RAID, do not disable 28631da177e4SLinus Torvalds * QAS if bit 1 is set 28641da177e4SLinus Torvalds * bit 1 QAS support, non-raid only 28651da177e4SLinus Torvalds * bit 0 IU support 28661da177e4SLinus Torvalds */ 28671da177e4SLinus Torvalds if (target->raidVolume == 1) { 28681da177e4SLinus Torvalds noQas = 0; 28691da177e4SLinus Torvalds } 28701da177e4SLinus Torvalds } else { 28711da177e4SLinus Torvalds factor = MPT_ASYNC; 28721da177e4SLinus Torvalds offset = 0; 28731da177e4SLinus Torvalds } 28741da177e4SLinus Torvalds } 28751da177e4SLinus Torvalds 28761da177e4SLinus Torvalds if ( (target->inq_data[7] & 0x02) == 0) { 28771da177e4SLinus Torvalds target->tflags &= ~MPT_TARGET_FLAGS_Q_YES; 28781da177e4SLinus Torvalds } 28791da177e4SLinus Torvalds 28801da177e4SLinus Torvalds /* Update tflags based on NVRAM settings. (SCSI only) 28811da177e4SLinus Torvalds */ 28821da177e4SLinus Torvalds if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) { 28831da177e4SLinus Torvalds nvram = pspi_data->nvram[id]; 28841da177e4SLinus Torvalds nfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8; 28851da177e4SLinus Torvalds 28861da177e4SLinus Torvalds if (width) 28871da177e4SLinus Torvalds width = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1; 28881da177e4SLinus Torvalds 28891da177e4SLinus Torvalds if (offset > 0) { 28901da177e4SLinus Torvalds /* Ensure factor is set to the 28911da177e4SLinus Torvalds * maximum of: adapter, nvram, inquiry 28921da177e4SLinus Torvalds */ 28931da177e4SLinus Torvalds if (nfactor) { 28941da177e4SLinus Torvalds if (nfactor < pspi_data->minSyncFactor ) 28951da177e4SLinus Torvalds nfactor = pspi_data->minSyncFactor; 28961da177e4SLinus Torvalds 28971da177e4SLinus Torvalds factor = max(factor, nfactor); 28981da177e4SLinus Torvalds if (factor == MPT_ASYNC) 28991da177e4SLinus Torvalds offset = 0; 29001da177e4SLinus Torvalds } else { 29011da177e4SLinus Torvalds offset = 0; 29021da177e4SLinus Torvalds factor = MPT_ASYNC; 29031da177e4SLinus Torvalds } 29041da177e4SLinus Torvalds } else { 29051da177e4SLinus Torvalds factor = MPT_ASYNC; 29061da177e4SLinus Torvalds } 29071da177e4SLinus Torvalds } 29081da177e4SLinus Torvalds 29091da177e4SLinus Torvalds /* Make sure data is consistent 29101da177e4SLinus Torvalds */ 29111da177e4SLinus Torvalds if ((!width) && (factor < MPT_ULTRA2)) { 29121da177e4SLinus Torvalds factor = MPT_ULTRA2; 29131da177e4SLinus Torvalds } 29141da177e4SLinus Torvalds 29151da177e4SLinus Torvalds /* Save the data to the target structure. 29161da177e4SLinus Torvalds */ 29171da177e4SLinus Torvalds target->minSyncFactor = factor; 29181da177e4SLinus Torvalds target->maxOffset = offset; 29191da177e4SLinus Torvalds target->maxWidth = width; 29201da177e4SLinus Torvalds 29211da177e4SLinus Torvalds target->tflags |= MPT_TARGET_FLAGS_VALID_NEGO; 29221da177e4SLinus Torvalds 29231da177e4SLinus Torvalds /* Disable unused features. 29241da177e4SLinus Torvalds */ 29251da177e4SLinus Torvalds if (!width) 29261da177e4SLinus Torvalds target->negoFlags |= MPT_TARGET_NO_NEGO_WIDE; 29271da177e4SLinus Torvalds 29281da177e4SLinus Torvalds if (!offset) 29291da177e4SLinus Torvalds target->negoFlags |= MPT_TARGET_NO_NEGO_SYNC; 29301da177e4SLinus Torvalds 29311da177e4SLinus Torvalds if ( factor > MPT_ULTRA320 ) 29321da177e4SLinus Torvalds noQas = 0; 29331da177e4SLinus Torvalds 29341da177e4SLinus Torvalds /* GEM, processor WORKAROUND 29351da177e4SLinus Torvalds */ 29361da177e4SLinus Torvalds if ((target->inq_data[0] == TYPE_PROCESSOR) || (target->inq_data[0] > 0x08)) { 29371da177e4SLinus Torvalds target->negoFlags |= (MPT_TARGET_NO_NEGO_WIDE | MPT_TARGET_NO_NEGO_SYNC); 29381da177e4SLinus Torvalds pspi_data->dvStatus[id] |= MPT_SCSICFG_BLK_NEGO; 29391da177e4SLinus Torvalds } else { 29401da177e4SLinus Torvalds if (noQas && (pspi_data->noQas == 0)) { 29411da177e4SLinus Torvalds pspi_data->noQas |= MPT_TARGET_NO_NEGO_QAS; 29421da177e4SLinus Torvalds target->negoFlags |= MPT_TARGET_NO_NEGO_QAS; 29431da177e4SLinus Torvalds 29441da177e4SLinus Torvalds /* Disable QAS in a mixed configuration case 29451da177e4SLinus Torvalds */ 29461da177e4SLinus Torvalds 29471da177e4SLinus Torvalds ddvtprintk((KERN_INFO "Disabling QAS due to noQas=%02x on id=%d!\n", noQas, id)); 29481da177e4SLinus Torvalds for (ii = 0; ii < id; ii++) { 29491da177e4SLinus Torvalds if ( (vdev = hd->Targets[ii]) ) { 29501da177e4SLinus Torvalds vdev->negoFlags |= MPT_TARGET_NO_NEGO_QAS; 29511da177e4SLinus Torvalds mptscsih_writeSDP1(hd, 0, ii, vdev->negoFlags); 29521da177e4SLinus Torvalds } 29531da177e4SLinus Torvalds } 29541da177e4SLinus Torvalds } 29551da177e4SLinus Torvalds } 29561da177e4SLinus Torvalds 29571da177e4SLinus Torvalds /* Write SDP1 on this I/O to this target */ 29581da177e4SLinus Torvalds if (pspi_data->dvStatus[id] & MPT_SCSICFG_NEGOTIATE) { 29591da177e4SLinus Torvalds ddvtprintk((KERN_INFO "MPT_SCSICFG_NEGOTIATE on id=%d!\n", id)); 29601da177e4SLinus Torvalds mptscsih_writeSDP1(hd, 0, id, hd->negoNvram); 29611da177e4SLinus Torvalds pspi_data->dvStatus[id] &= ~MPT_SCSICFG_NEGOTIATE; 29621da177e4SLinus Torvalds } else if (pspi_data->dvStatus[id] & MPT_SCSICFG_BLK_NEGO) { 29631da177e4SLinus Torvalds ddvtprintk((KERN_INFO "MPT_SCSICFG_BLK_NEGO on id=%d!\n", id)); 29641da177e4SLinus Torvalds mptscsih_writeSDP1(hd, 0, id, MPT_SCSICFG_BLK_NEGO); 29651da177e4SLinus Torvalds pspi_data->dvStatus[id] &= ~MPT_SCSICFG_BLK_NEGO; 29661da177e4SLinus Torvalds } 29671da177e4SLinus Torvalds } 29681da177e4SLinus Torvalds 29691da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 29701da177e4SLinus Torvalds /* If DV disabled (negoNvram set to USE_NVARM) or if not LUN 0, return. 29711da177e4SLinus Torvalds * Else set the NEED_DV flag after Read Capacity Issued (disks) 29721da177e4SLinus Torvalds * or Mode Sense (cdroms). 29731da177e4SLinus Torvalds * 29741da177e4SLinus Torvalds * Tapes, initTarget will set this flag on completion of Inquiry command. 29751da177e4SLinus Torvalds * Called only if DV_NOT_DONE flag is set 29761da177e4SLinus Torvalds */ 29770d0c7974SMoore, Eric Dean static void 29780d0c7974SMoore, Eric Dean mptscsih_set_dvflags(MPT_SCSI_HOST *hd, SCSIIORequest_t *pReq) 29791da177e4SLinus Torvalds { 29801da177e4SLinus Torvalds u8 cmd; 29811da177e4SLinus Torvalds ScsiCfgData *pSpi; 29821da177e4SLinus Torvalds 29831da177e4SLinus Torvalds ddvtprintk((" set_dvflags: id=%d lun=%d negoNvram=%x cmd=%x\n", 29841da177e4SLinus Torvalds pReq->TargetID, pReq->LUN[1], hd->negoNvram, pReq->CDB[0])); 29851da177e4SLinus Torvalds 29861da177e4SLinus Torvalds if ((pReq->LUN[1] != 0) || (hd->negoNvram != 0)) 29871da177e4SLinus Torvalds return; 29881da177e4SLinus Torvalds 29891da177e4SLinus Torvalds cmd = pReq->CDB[0]; 29901da177e4SLinus Torvalds 29911da177e4SLinus Torvalds if ((cmd == READ_CAPACITY) || (cmd == MODE_SENSE)) { 29921da177e4SLinus Torvalds pSpi = &hd->ioc->spi_data; 29931da177e4SLinus Torvalds if ((pSpi->isRaid & (1 << pReq->TargetID)) && pSpi->pIocPg3) { 29941da177e4SLinus Torvalds /* Set NEED_DV for all hidden disks 29951da177e4SLinus Torvalds */ 29961da177e4SLinus Torvalds Ioc3PhysDisk_t *pPDisk = pSpi->pIocPg3->PhysDisk; 29971da177e4SLinus Torvalds int numPDisk = pSpi->pIocPg3->NumPhysDisks; 29981da177e4SLinus Torvalds 29991da177e4SLinus Torvalds while (numPDisk) { 30001da177e4SLinus Torvalds pSpi->dvStatus[pPDisk->PhysDiskID] |= MPT_SCSICFG_NEED_DV; 30011da177e4SLinus Torvalds ddvtprintk(("NEED_DV set for phys disk id %d\n", pPDisk->PhysDiskID)); 30021da177e4SLinus Torvalds pPDisk++; 30031da177e4SLinus Torvalds numPDisk--; 30041da177e4SLinus Torvalds } 30051da177e4SLinus Torvalds } 30061da177e4SLinus Torvalds pSpi->dvStatus[pReq->TargetID] |= MPT_SCSICFG_NEED_DV; 30071da177e4SLinus Torvalds ddvtprintk(("NEED_DV set for visible disk id %d\n", pReq->TargetID)); 30081da177e4SLinus Torvalds } 30091da177e4SLinus Torvalds } 30101da177e4SLinus Torvalds 30111da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 30121da177e4SLinus Torvalds /* 30131da177e4SLinus Torvalds * If no Target, bus reset on 1st I/O. Set the flag to 30141da177e4SLinus Torvalds * prevent any future negotiations to this device. 30151da177e4SLinus Torvalds */ 30160d0c7974SMoore, Eric Dean static void 30170d0c7974SMoore, Eric Dean mptscsih_no_negotiate(MPT_SCSI_HOST *hd, int target_id) 30181da177e4SLinus Torvalds { 30191da177e4SLinus Torvalds 30201da177e4SLinus Torvalds if ((hd->Targets) && (hd->Targets[target_id] == NULL)) 30211da177e4SLinus Torvalds hd->ioc->spi_data.dvStatus[target_id] |= MPT_SCSICFG_BLK_NEGO; 30221da177e4SLinus Torvalds 30231da177e4SLinus Torvalds return; 30241da177e4SLinus Torvalds } 30251da177e4SLinus Torvalds 30261da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 30271da177e4SLinus Torvalds /* 30281da177e4SLinus Torvalds * SCSI Config Page functionality ... 30291da177e4SLinus Torvalds */ 30301da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 30311da177e4SLinus Torvalds /* mptscsih_setDevicePage1Flags - add Requested and Configuration fields flags 30321da177e4SLinus Torvalds * based on width, factor and offset parameters. 30331da177e4SLinus Torvalds * @width: bus width 30341da177e4SLinus Torvalds * @factor: sync factor 30351da177e4SLinus Torvalds * @offset: sync offset 30361da177e4SLinus Torvalds * @requestedPtr: pointer to requested values (updated) 30371da177e4SLinus Torvalds * @configurationPtr: pointer to configuration values (updated) 30381da177e4SLinus Torvalds * @flags: flags to block WDTR or SDTR negotiation 30391da177e4SLinus Torvalds * 30401da177e4SLinus Torvalds * Return: None. 30411da177e4SLinus Torvalds * 30421da177e4SLinus Torvalds * Remark: Called by writeSDP1 and _dv_params 30431da177e4SLinus Torvalds */ 30441da177e4SLinus Torvalds static void 30451da177e4SLinus Torvalds mptscsih_setDevicePage1Flags (u8 width, u8 factor, u8 offset, int *requestedPtr, int *configurationPtr, u8 flags) 30461da177e4SLinus Torvalds { 30471da177e4SLinus Torvalds u8 nowide = flags & MPT_TARGET_NO_NEGO_WIDE; 30481da177e4SLinus Torvalds u8 nosync = flags & MPT_TARGET_NO_NEGO_SYNC; 30491da177e4SLinus Torvalds 30501da177e4SLinus Torvalds *configurationPtr = 0; 30511da177e4SLinus Torvalds *requestedPtr = width ? MPI_SCSIDEVPAGE1_RP_WIDE : 0; 30521da177e4SLinus Torvalds *requestedPtr |= (offset << 16) | (factor << 8); 30531da177e4SLinus Torvalds 30541da177e4SLinus Torvalds if (width && offset && !nowide && !nosync) { 30551da177e4SLinus Torvalds if (factor < MPT_ULTRA160) { 30561da177e4SLinus Torvalds *requestedPtr |= (MPI_SCSIDEVPAGE1_RP_IU + MPI_SCSIDEVPAGE1_RP_DT); 30571da177e4SLinus Torvalds if ((flags & MPT_TARGET_NO_NEGO_QAS) == 0) 30581da177e4SLinus Torvalds *requestedPtr |= MPI_SCSIDEVPAGE1_RP_QAS; 30591da177e4SLinus Torvalds if (flags & MPT_TAPE_NEGO_IDP) 30601da177e4SLinus Torvalds *requestedPtr |= 0x08000000; 30611da177e4SLinus Torvalds } else if (factor < MPT_ULTRA2) { 30621da177e4SLinus Torvalds *requestedPtr |= MPI_SCSIDEVPAGE1_RP_DT; 30631da177e4SLinus Torvalds } 30641da177e4SLinus Torvalds } 30651da177e4SLinus Torvalds 30661da177e4SLinus Torvalds if (nowide) 30671da177e4SLinus Torvalds *configurationPtr |= MPI_SCSIDEVPAGE1_CONF_WDTR_DISALLOWED; 30681da177e4SLinus Torvalds 30691da177e4SLinus Torvalds if (nosync) 30701da177e4SLinus Torvalds *configurationPtr |= MPI_SCSIDEVPAGE1_CONF_SDTR_DISALLOWED; 30711da177e4SLinus Torvalds 30721da177e4SLinus Torvalds return; 30731da177e4SLinus Torvalds } 30741da177e4SLinus Torvalds 30751da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 30761da177e4SLinus Torvalds /* mptscsih_writeSDP1 - write SCSI Device Page 1 30771da177e4SLinus Torvalds * @hd: Pointer to a SCSI Host Strucutre 30781da177e4SLinus Torvalds * @portnum: IOC port number 30791da177e4SLinus Torvalds * @target_id: writeSDP1 for single ID 30801da177e4SLinus Torvalds * @flags: MPT_SCSICFG_ALL_IDS, MPT_SCSICFG_USE_NVRAM, MPT_SCSICFG_BLK_NEGO 30811da177e4SLinus Torvalds * 30821da177e4SLinus Torvalds * Return: -EFAULT if read of config page header fails 30831da177e4SLinus Torvalds * or 0 if success. 30841da177e4SLinus Torvalds * 30851da177e4SLinus Torvalds * Remark: If a target has been found, the settings from the 30861da177e4SLinus Torvalds * target structure are used, else the device is set 30871da177e4SLinus Torvalds * to async/narrow. 30881da177e4SLinus Torvalds * 30891da177e4SLinus Torvalds * Remark: Called during init and after a FW reload. 30901da177e4SLinus Torvalds * Remark: We do not wait for a return, write pages sequentially. 30911da177e4SLinus Torvalds */ 30921da177e4SLinus Torvalds static int 30931da177e4SLinus Torvalds mptscsih_writeSDP1(MPT_SCSI_HOST *hd, int portnum, int target_id, int flags) 30941da177e4SLinus Torvalds { 30951da177e4SLinus Torvalds MPT_ADAPTER *ioc = hd->ioc; 30961da177e4SLinus Torvalds Config_t *pReq; 30971da177e4SLinus Torvalds SCSIDevicePage1_t *pData; 30981da177e4SLinus Torvalds VirtDevice *pTarget; 30991da177e4SLinus Torvalds MPT_FRAME_HDR *mf; 31001da177e4SLinus Torvalds dma_addr_t dataDma; 31011da177e4SLinus Torvalds u16 req_idx; 31021da177e4SLinus Torvalds u32 frameOffset; 31031da177e4SLinus Torvalds u32 requested, configuration, flagsLength; 31041da177e4SLinus Torvalds int ii, nvram; 31051da177e4SLinus Torvalds int id = 0, maxid = 0; 31061da177e4SLinus Torvalds u8 width; 31071da177e4SLinus Torvalds u8 factor; 31081da177e4SLinus Torvalds u8 offset; 31091da177e4SLinus Torvalds u8 bus = 0; 31101da177e4SLinus Torvalds u8 negoFlags; 31111da177e4SLinus Torvalds u8 maxwidth, maxoffset, maxfactor; 31121da177e4SLinus Torvalds 31131da177e4SLinus Torvalds if (ioc->spi_data.sdp1length == 0) 31141da177e4SLinus Torvalds return 0; 31151da177e4SLinus Torvalds 31161da177e4SLinus Torvalds if (flags & MPT_SCSICFG_ALL_IDS) { 31171da177e4SLinus Torvalds id = 0; 31181da177e4SLinus Torvalds maxid = ioc->sh->max_id - 1; 31191da177e4SLinus Torvalds } else if (ioc->sh) { 31201da177e4SLinus Torvalds id = target_id; 31211da177e4SLinus Torvalds maxid = min_t(int, id, ioc->sh->max_id - 1); 31221da177e4SLinus Torvalds } 31231da177e4SLinus Torvalds 31241da177e4SLinus Torvalds for (; id <= maxid; id++) { 31251da177e4SLinus Torvalds 31261da177e4SLinus Torvalds if (id == ioc->pfacts[portnum].PortSCSIID) 31271da177e4SLinus Torvalds continue; 31281da177e4SLinus Torvalds 31291da177e4SLinus Torvalds /* Use NVRAM to get adapter and target maximums 31301da177e4SLinus Torvalds * Data over-riden by target structure information, if present 31311da177e4SLinus Torvalds */ 31321da177e4SLinus Torvalds maxwidth = ioc->spi_data.maxBusWidth; 31331da177e4SLinus Torvalds maxoffset = ioc->spi_data.maxSyncOffset; 31341da177e4SLinus Torvalds maxfactor = ioc->spi_data.minSyncFactor; 31351da177e4SLinus Torvalds if (ioc->spi_data.nvram && (ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) { 31361da177e4SLinus Torvalds nvram = ioc->spi_data.nvram[id]; 31371da177e4SLinus Torvalds 31381da177e4SLinus Torvalds if (maxwidth) 31391da177e4SLinus Torvalds maxwidth = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1; 31401da177e4SLinus Torvalds 31411da177e4SLinus Torvalds if (maxoffset > 0) { 31421da177e4SLinus Torvalds maxfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8; 31431da177e4SLinus Torvalds if (maxfactor == 0) { 31441da177e4SLinus Torvalds /* Key for async */ 31451da177e4SLinus Torvalds maxfactor = MPT_ASYNC; 31461da177e4SLinus Torvalds maxoffset = 0; 31471da177e4SLinus Torvalds } else if (maxfactor < ioc->spi_data.minSyncFactor) { 31481da177e4SLinus Torvalds maxfactor = ioc->spi_data.minSyncFactor; 31491da177e4SLinus Torvalds } 31501da177e4SLinus Torvalds } else 31511da177e4SLinus Torvalds maxfactor = MPT_ASYNC; 31521da177e4SLinus Torvalds } 31531da177e4SLinus Torvalds 31541da177e4SLinus Torvalds /* Set the negotiation flags. 31551da177e4SLinus Torvalds */ 31561da177e4SLinus Torvalds negoFlags = ioc->spi_data.noQas; 31571da177e4SLinus Torvalds if (!maxwidth) 31581da177e4SLinus Torvalds negoFlags |= MPT_TARGET_NO_NEGO_WIDE; 31591da177e4SLinus Torvalds 31601da177e4SLinus Torvalds if (!maxoffset) 31611da177e4SLinus Torvalds negoFlags |= MPT_TARGET_NO_NEGO_SYNC; 31621da177e4SLinus Torvalds 31631da177e4SLinus Torvalds if (flags & MPT_SCSICFG_USE_NVRAM) { 31641da177e4SLinus Torvalds width = maxwidth; 31651da177e4SLinus Torvalds factor = maxfactor; 31661da177e4SLinus Torvalds offset = maxoffset; 31671da177e4SLinus Torvalds } else { 31681da177e4SLinus Torvalds width = 0; 31691da177e4SLinus Torvalds factor = MPT_ASYNC; 31701da177e4SLinus Torvalds offset = 0; 31711da177e4SLinus Torvalds //negoFlags = 0; 31721da177e4SLinus Torvalds //negoFlags = MPT_TARGET_NO_NEGO_SYNC; 31731da177e4SLinus Torvalds } 31741da177e4SLinus Torvalds 31751da177e4SLinus Torvalds /* If id is not a raid volume, get the updated 31761da177e4SLinus Torvalds * transmission settings from the target structure. 31771da177e4SLinus Torvalds */ 31781da177e4SLinus Torvalds if (hd->Targets && (pTarget = hd->Targets[id]) && !pTarget->raidVolume) { 31791da177e4SLinus Torvalds width = pTarget->maxWidth; 31801da177e4SLinus Torvalds factor = pTarget->minSyncFactor; 31811da177e4SLinus Torvalds offset = pTarget->maxOffset; 31821da177e4SLinus Torvalds negoFlags = pTarget->negoFlags; 31831da177e4SLinus Torvalds } 31841da177e4SLinus Torvalds 31851da177e4SLinus Torvalds #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION 31861da177e4SLinus Torvalds /* Force to async and narrow if DV has not been executed 31871da177e4SLinus Torvalds * for this ID 31881da177e4SLinus Torvalds */ 31891da177e4SLinus Torvalds if ((hd->ioc->spi_data.dvStatus[id] & MPT_SCSICFG_DV_NOT_DONE) != 0) { 31901da177e4SLinus Torvalds width = 0; 31911da177e4SLinus Torvalds factor = MPT_ASYNC; 31921da177e4SLinus Torvalds offset = 0; 31931da177e4SLinus Torvalds } 31941da177e4SLinus Torvalds #endif 31951da177e4SLinus Torvalds 31961da177e4SLinus Torvalds if (flags & MPT_SCSICFG_BLK_NEGO) 31971da177e4SLinus Torvalds negoFlags = MPT_TARGET_NO_NEGO_WIDE | MPT_TARGET_NO_NEGO_SYNC; 31981da177e4SLinus Torvalds 31991da177e4SLinus Torvalds mptscsih_setDevicePage1Flags(width, factor, offset, 32001da177e4SLinus Torvalds &requested, &configuration, negoFlags); 32011da177e4SLinus Torvalds dnegoprintk(("writeSDP1: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n", 32021da177e4SLinus Torvalds target_id, width, factor, offset, negoFlags, requested, configuration)); 32031da177e4SLinus Torvalds 32041da177e4SLinus Torvalds /* Get a MF for this command. 32051da177e4SLinus Torvalds */ 32060d0c7974SMoore, Eric Dean if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) { 32071da177e4SLinus Torvalds dprintk((MYIOC_s_WARN_FMT "write SDP1: no msg frames!\n", 32081da177e4SLinus Torvalds ioc->name)); 32091da177e4SLinus Torvalds return -EAGAIN; 32101da177e4SLinus Torvalds } 32111da177e4SLinus Torvalds 32121da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT "WriteSDP1 (mf=%p, id=%d, req=0x%x, cfg=0x%x)\n", 32131da177e4SLinus Torvalds hd->ioc->name, mf, id, requested, configuration)); 32141da177e4SLinus Torvalds 32151da177e4SLinus Torvalds 32161da177e4SLinus Torvalds /* Set the request and the data pointers. 32171da177e4SLinus Torvalds * Request takes: 36 bytes (32 bit SGE) 32181da177e4SLinus Torvalds * SCSI Device Page 1 requires 16 bytes 32191da177e4SLinus Torvalds * 40 + 16 <= size of SCSI IO Request = 56 bytes 32201da177e4SLinus Torvalds * and MF size >= 64 bytes. 32211da177e4SLinus Torvalds * Place data at end of MF. 32221da177e4SLinus Torvalds */ 32231da177e4SLinus Torvalds pReq = (Config_t *)mf; 32241da177e4SLinus Torvalds 32251da177e4SLinus Torvalds req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 32261da177e4SLinus Torvalds frameOffset = ioc->req_sz - sizeof(SCSIDevicePage1_t); 32271da177e4SLinus Torvalds 32281da177e4SLinus Torvalds pData = (SCSIDevicePage1_t *)((u8 *) mf + frameOffset); 32291da177e4SLinus Torvalds dataDma = ioc->req_frames_dma + (req_idx * ioc->req_sz) + frameOffset; 32301da177e4SLinus Torvalds 32311da177e4SLinus Torvalds /* Complete the request frame (same for all requests). 32321da177e4SLinus Torvalds */ 32331da177e4SLinus Torvalds pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 32341da177e4SLinus Torvalds pReq->Reserved = 0; 32351da177e4SLinus Torvalds pReq->ChainOffset = 0; 32361da177e4SLinus Torvalds pReq->Function = MPI_FUNCTION_CONFIG; 32371da177e4SLinus Torvalds pReq->ExtPageLength = 0; 32381da177e4SLinus Torvalds pReq->ExtPageType = 0; 32391da177e4SLinus Torvalds pReq->MsgFlags = 0; 32401da177e4SLinus Torvalds for (ii=0; ii < 8; ii++) { 32411da177e4SLinus Torvalds pReq->Reserved2[ii] = 0; 32421da177e4SLinus Torvalds } 32431da177e4SLinus Torvalds pReq->Header.PageVersion = ioc->spi_data.sdp1version; 32441da177e4SLinus Torvalds pReq->Header.PageLength = ioc->spi_data.sdp1length; 32451da177e4SLinus Torvalds pReq->Header.PageNumber = 1; 32461da177e4SLinus Torvalds pReq->Header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; 32471da177e4SLinus Torvalds pReq->PageAddress = cpu_to_le32(id | (bus << 8 )); 32481da177e4SLinus Torvalds 32491da177e4SLinus Torvalds /* Add a SGE to the config request. 32501da177e4SLinus Torvalds */ 32511da177e4SLinus Torvalds flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE | ioc->spi_data.sdp1length * 4; 32521da177e4SLinus Torvalds 32531da177e4SLinus Torvalds mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma); 32541da177e4SLinus Torvalds 32551da177e4SLinus Torvalds /* Set up the common data portion 32561da177e4SLinus Torvalds */ 32571da177e4SLinus Torvalds pData->Header.PageVersion = pReq->Header.PageVersion; 32581da177e4SLinus Torvalds pData->Header.PageLength = pReq->Header.PageLength; 32591da177e4SLinus Torvalds pData->Header.PageNumber = pReq->Header.PageNumber; 32601da177e4SLinus Torvalds pData->Header.PageType = pReq->Header.PageType; 32611da177e4SLinus Torvalds pData->RequestedParameters = cpu_to_le32(requested); 32621da177e4SLinus Torvalds pData->Reserved = 0; 32631da177e4SLinus Torvalds pData->Configuration = cpu_to_le32(configuration); 32641da177e4SLinus Torvalds 32651da177e4SLinus Torvalds dprintk((MYIOC_s_INFO_FMT 32661da177e4SLinus Torvalds "write SDP1: id %d pgaddr 0x%x req 0x%x config 0x%x\n", 32671da177e4SLinus Torvalds ioc->name, id, (id | (bus<<8)), 32681da177e4SLinus Torvalds requested, configuration)); 32691da177e4SLinus Torvalds 32700d0c7974SMoore, Eric Dean mpt_put_msg_frame(ioc->DoneCtx, ioc, mf); 32711da177e4SLinus Torvalds } 32721da177e4SLinus Torvalds 32731da177e4SLinus Torvalds return 0; 32741da177e4SLinus Torvalds } 32751da177e4SLinus Torvalds 32761da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 32771da177e4SLinus Torvalds /* mptscsih_writeIOCPage4 - write IOC Page 4 32781da177e4SLinus Torvalds * @hd: Pointer to a SCSI Host Structure 32791da177e4SLinus Torvalds * @target_id: write IOC Page4 for this ID & Bus 32801da177e4SLinus Torvalds * 32811da177e4SLinus Torvalds * Return: -EAGAIN if unable to obtain a Message Frame 32821da177e4SLinus Torvalds * or 0 if success. 32831da177e4SLinus Torvalds * 32841da177e4SLinus Torvalds * Remark: We do not wait for a return, write pages sequentially. 32851da177e4SLinus Torvalds */ 32861da177e4SLinus Torvalds static int 32871da177e4SLinus Torvalds mptscsih_writeIOCPage4(MPT_SCSI_HOST *hd, int target_id, int bus) 32881da177e4SLinus Torvalds { 32891da177e4SLinus Torvalds MPT_ADAPTER *ioc = hd->ioc; 32901da177e4SLinus Torvalds Config_t *pReq; 32911da177e4SLinus Torvalds IOCPage4_t *IOCPage4Ptr; 32921da177e4SLinus Torvalds MPT_FRAME_HDR *mf; 32931da177e4SLinus Torvalds dma_addr_t dataDma; 32941da177e4SLinus Torvalds u16 req_idx; 32951da177e4SLinus Torvalds u32 frameOffset; 32961da177e4SLinus Torvalds u32 flagsLength; 32971da177e4SLinus Torvalds int ii; 32981da177e4SLinus Torvalds 32991da177e4SLinus Torvalds /* Get a MF for this command. 33001da177e4SLinus Torvalds */ 33010d0c7974SMoore, Eric Dean if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) { 33021da177e4SLinus Torvalds dprintk((MYIOC_s_WARN_FMT "writeIOCPage4 : no msg frames!\n", 33031da177e4SLinus Torvalds ioc->name)); 33041da177e4SLinus Torvalds return -EAGAIN; 33051da177e4SLinus Torvalds } 33061da177e4SLinus Torvalds 33071da177e4SLinus Torvalds /* Set the request and the data pointers. 33081da177e4SLinus Torvalds * Place data at end of MF. 33091da177e4SLinus Torvalds */ 33101da177e4SLinus Torvalds pReq = (Config_t *)mf; 33111da177e4SLinus Torvalds 33121da177e4SLinus Torvalds req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 33131da177e4SLinus Torvalds frameOffset = ioc->req_sz - sizeof(IOCPage4_t); 33141da177e4SLinus Torvalds 33151da177e4SLinus Torvalds /* Complete the request frame (same for all requests). 33161da177e4SLinus Torvalds */ 33171da177e4SLinus Torvalds pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 33181da177e4SLinus Torvalds pReq->Reserved = 0; 33191da177e4SLinus Torvalds pReq->ChainOffset = 0; 33201da177e4SLinus Torvalds pReq->Function = MPI_FUNCTION_CONFIG; 33211da177e4SLinus Torvalds pReq->ExtPageLength = 0; 33221da177e4SLinus Torvalds pReq->ExtPageType = 0; 33231da177e4SLinus Torvalds pReq->MsgFlags = 0; 33241da177e4SLinus Torvalds for (ii=0; ii < 8; ii++) { 33251da177e4SLinus Torvalds pReq->Reserved2[ii] = 0; 33261da177e4SLinus Torvalds } 33271da177e4SLinus Torvalds 33281da177e4SLinus Torvalds IOCPage4Ptr = ioc->spi_data.pIocPg4; 33291da177e4SLinus Torvalds dataDma = ioc->spi_data.IocPg4_dma; 33301da177e4SLinus Torvalds ii = IOCPage4Ptr->ActiveSEP++; 33311da177e4SLinus Torvalds IOCPage4Ptr->SEP[ii].SEPTargetID = target_id; 33321da177e4SLinus Torvalds IOCPage4Ptr->SEP[ii].SEPBus = bus; 33331da177e4SLinus Torvalds pReq->Header = IOCPage4Ptr->Header; 33341da177e4SLinus Torvalds pReq->PageAddress = cpu_to_le32(target_id | (bus << 8 )); 33351da177e4SLinus Torvalds 33361da177e4SLinus Torvalds /* Add a SGE to the config request. 33371da177e4SLinus Torvalds */ 33381da177e4SLinus Torvalds flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE | 33391da177e4SLinus Torvalds (IOCPage4Ptr->Header.PageLength + ii) * 4; 33401da177e4SLinus Torvalds 33411da177e4SLinus Torvalds mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma); 33421da177e4SLinus Torvalds 33431da177e4SLinus Torvalds dinitprintk((MYIOC_s_INFO_FMT 33441da177e4SLinus Torvalds "writeIOCPage4: MaxSEP=%d ActiveSEP=%d id=%d bus=%d\n", 33451da177e4SLinus Torvalds ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, target_id, bus)); 33461da177e4SLinus Torvalds 33470d0c7974SMoore, Eric Dean mpt_put_msg_frame(ioc->DoneCtx, ioc, mf); 33481da177e4SLinus Torvalds 33491da177e4SLinus Torvalds return 0; 33501da177e4SLinus Torvalds } 33511da177e4SLinus Torvalds 33521da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 33531da177e4SLinus Torvalds /* 33541da177e4SLinus Torvalds * Bus Scan and Domain Validation functionality ... 33551da177e4SLinus Torvalds */ 33561da177e4SLinus Torvalds 33571da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 33581da177e4SLinus Torvalds /* 33591da177e4SLinus Torvalds * mptscsih_scandv_complete - Scan and DV callback routine registered 33601da177e4SLinus Torvalds * to Fustion MPT (base) driver. 33611da177e4SLinus Torvalds * 33621da177e4SLinus Torvalds * @ioc: Pointer to MPT_ADAPTER structure 33631da177e4SLinus Torvalds * @mf: Pointer to original MPT request frame 33641da177e4SLinus Torvalds * @mr: Pointer to MPT reply frame (NULL if TurboReply) 33651da177e4SLinus Torvalds * 33661da177e4SLinus Torvalds * This routine is called from mpt.c::mpt_interrupt() at the completion 33671da177e4SLinus Torvalds * of any SCSI IO request. 33681da177e4SLinus Torvalds * This routine is registered with the Fusion MPT (base) driver at driver 33691da177e4SLinus Torvalds * load/init time via the mpt_register() API call. 33701da177e4SLinus Torvalds * 33711da177e4SLinus Torvalds * Returns 1 indicating alloc'd request frame ptr should be freed. 33721da177e4SLinus Torvalds * 33731da177e4SLinus Torvalds * Remark: Sets a completion code and (possibly) saves sense data 33741da177e4SLinus Torvalds * in the IOC member localReply structure. 33751da177e4SLinus Torvalds * Used ONLY for DV and other internal commands. 33761da177e4SLinus Torvalds */ 33770d0c7974SMoore, Eric Dean int 33781da177e4SLinus Torvalds mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) 33791da177e4SLinus Torvalds { 33801da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 33811da177e4SLinus Torvalds SCSIIORequest_t *pReq; 33821da177e4SLinus Torvalds int completionCode; 33831da177e4SLinus Torvalds u16 req_idx; 33841da177e4SLinus Torvalds 33850d0c7974SMoore, Eric Dean hd = (MPT_SCSI_HOST *) ioc->sh->hostdata; 33860d0c7974SMoore, Eric Dean 33871da177e4SLinus Torvalds if ((mf == NULL) || 33881da177e4SLinus Torvalds (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) { 33891da177e4SLinus Torvalds printk(MYIOC_s_ERR_FMT 33901da177e4SLinus Torvalds "ScanDvComplete, %s req frame ptr! (=%p)\n", 33911da177e4SLinus Torvalds ioc->name, mf?"BAD":"NULL", (void *) mf); 33921da177e4SLinus Torvalds goto wakeup; 33931da177e4SLinus Torvalds } 33941da177e4SLinus Torvalds 33951da177e4SLinus Torvalds del_timer(&hd->timer); 33961da177e4SLinus Torvalds req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 33971da177e4SLinus Torvalds hd->ScsiLookup[req_idx] = NULL; 33981da177e4SLinus Torvalds pReq = (SCSIIORequest_t *) mf; 33991da177e4SLinus Torvalds 34001da177e4SLinus Torvalds if (mf != hd->cmdPtr) { 34011da177e4SLinus Torvalds printk(MYIOC_s_WARN_FMT "ScanDvComplete (mf=%p, cmdPtr=%p, idx=%d)\n", 34021da177e4SLinus Torvalds hd->ioc->name, (void *)mf, (void *) hd->cmdPtr, req_idx); 34031da177e4SLinus Torvalds } 34041da177e4SLinus Torvalds hd->cmdPtr = NULL; 34051da177e4SLinus Torvalds 34061da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT "ScanDvComplete (mf=%p,mr=%p,idx=%d)\n", 34071da177e4SLinus Torvalds hd->ioc->name, mf, mr, req_idx)); 34081da177e4SLinus Torvalds 34091da177e4SLinus Torvalds hd->pLocal = &hd->localReply; 34101da177e4SLinus Torvalds hd->pLocal->scsiStatus = 0; 34111da177e4SLinus Torvalds 34121da177e4SLinus Torvalds /* If target struct exists, clear sense valid flag. 34131da177e4SLinus Torvalds */ 34141da177e4SLinus Torvalds if (mr == NULL) { 34151da177e4SLinus Torvalds completionCode = MPT_SCANDV_GOOD; 34161da177e4SLinus Torvalds } else { 34171da177e4SLinus Torvalds SCSIIOReply_t *pReply; 34181da177e4SLinus Torvalds u16 status; 34191da177e4SLinus Torvalds u8 scsi_status; 34201da177e4SLinus Torvalds 34211da177e4SLinus Torvalds pReply = (SCSIIOReply_t *) mr; 34221da177e4SLinus Torvalds 34231da177e4SLinus Torvalds status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK; 34241da177e4SLinus Torvalds scsi_status = pReply->SCSIStatus; 34251da177e4SLinus Torvalds 34261da177e4SLinus Torvalds ddvtprintk((KERN_NOTICE " IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh, IOCLogInfo=%08xh\n", 34271da177e4SLinus Torvalds status, pReply->SCSIState, scsi_status, 34281da177e4SLinus Torvalds le32_to_cpu(pReply->IOCLogInfo))); 34291da177e4SLinus Torvalds 34301da177e4SLinus Torvalds switch(status) { 34311da177e4SLinus Torvalds 34321da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */ 34331da177e4SLinus Torvalds completionCode = MPT_SCANDV_SELECTION_TIMEOUT; 34341da177e4SLinus Torvalds break; 34351da177e4SLinus Torvalds 34361da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */ 34371da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */ 34381da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */ 34391da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */ 34401da177e4SLinus Torvalds completionCode = MPT_SCANDV_DID_RESET; 34411da177e4SLinus Torvalds break; 34421da177e4SLinus Torvalds 34431da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */ 34441da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */ 34451da177e4SLinus Torvalds case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */ 34461da177e4SLinus Torvalds if (pReply->Function == MPI_FUNCTION_CONFIG) { 34471da177e4SLinus Torvalds ConfigReply_t *pr = (ConfigReply_t *)mr; 34481da177e4SLinus Torvalds completionCode = MPT_SCANDV_GOOD; 34491da177e4SLinus Torvalds hd->pLocal->header.PageVersion = pr->Header.PageVersion; 34501da177e4SLinus Torvalds hd->pLocal->header.PageLength = pr->Header.PageLength; 34511da177e4SLinus Torvalds hd->pLocal->header.PageNumber = pr->Header.PageNumber; 34521da177e4SLinus Torvalds hd->pLocal->header.PageType = pr->Header.PageType; 34531da177e4SLinus Torvalds 34541da177e4SLinus Torvalds } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) { 34551da177e4SLinus Torvalds /* If the RAID Volume request is successful, 34561da177e4SLinus Torvalds * return GOOD, else indicate that 34571da177e4SLinus Torvalds * some type of error occurred. 34581da177e4SLinus Torvalds */ 34591da177e4SLinus Torvalds MpiRaidActionReply_t *pr = (MpiRaidActionReply_t *)mr; 34601da177e4SLinus Torvalds if (pr->ActionStatus == MPI_RAID_ACTION_ASTATUS_SUCCESS) 34611da177e4SLinus Torvalds completionCode = MPT_SCANDV_GOOD; 34621da177e4SLinus Torvalds else 34631da177e4SLinus Torvalds completionCode = MPT_SCANDV_SOME_ERROR; 34641da177e4SLinus Torvalds 34651da177e4SLinus Torvalds } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) { 34661da177e4SLinus Torvalds u8 *sense_data; 34671da177e4SLinus Torvalds int sz; 34681da177e4SLinus Torvalds 34691da177e4SLinus Torvalds /* save sense data in global structure 34701da177e4SLinus Torvalds */ 34711da177e4SLinus Torvalds completionCode = MPT_SCANDV_SENSE; 34721da177e4SLinus Torvalds hd->pLocal->scsiStatus = scsi_status; 34731da177e4SLinus Torvalds sense_data = ((u8 *)hd->ioc->sense_buf_pool + 34741da177e4SLinus Torvalds (req_idx * MPT_SENSE_BUFFER_ALLOC)); 34751da177e4SLinus Torvalds 34761da177e4SLinus Torvalds sz = min_t(int, pReq->SenseBufferLength, 34771da177e4SLinus Torvalds SCSI_STD_SENSE_BYTES); 34781da177e4SLinus Torvalds memcpy(hd->pLocal->sense, sense_data, sz); 34791da177e4SLinus Torvalds 34801da177e4SLinus Torvalds ddvprintk((KERN_NOTICE " Check Condition, sense ptr %p\n", 34811da177e4SLinus Torvalds sense_data)); 34821da177e4SLinus Torvalds } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) { 34831da177e4SLinus Torvalds if (pReq->CDB[0] == INQUIRY) 34841da177e4SLinus Torvalds completionCode = MPT_SCANDV_ISSUE_SENSE; 34851da177e4SLinus Torvalds else 34861da177e4SLinus Torvalds completionCode = MPT_SCANDV_DID_RESET; 34871da177e4SLinus Torvalds } 34881da177e4SLinus Torvalds else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS) 34891da177e4SLinus Torvalds completionCode = MPT_SCANDV_DID_RESET; 34901da177e4SLinus Torvalds else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED) 34911da177e4SLinus Torvalds completionCode = MPT_SCANDV_DID_RESET; 34921da177e4SLinus Torvalds else { 34931da177e4SLinus Torvalds completionCode = MPT_SCANDV_GOOD; 34941da177e4SLinus Torvalds hd->pLocal->scsiStatus = scsi_status; 34951da177e4SLinus Torvalds } 34961da177e4SLinus Torvalds break; 34971da177e4SLinus Torvalds 34981da177e4SLinus Torvalds case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */ 34991da177e4SLinus Torvalds if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED) 35001da177e4SLinus Torvalds completionCode = MPT_SCANDV_DID_RESET; 35011da177e4SLinus Torvalds else 35021da177e4SLinus Torvalds completionCode = MPT_SCANDV_SOME_ERROR; 35031da177e4SLinus Torvalds break; 35041da177e4SLinus Torvalds 35051da177e4SLinus Torvalds default: 35061da177e4SLinus Torvalds completionCode = MPT_SCANDV_SOME_ERROR; 35071da177e4SLinus Torvalds break; 35081da177e4SLinus Torvalds 35091da177e4SLinus Torvalds } /* switch(status) */ 35101da177e4SLinus Torvalds 35111da177e4SLinus Torvalds ddvtprintk((KERN_NOTICE " completionCode set to %08xh\n", 35121da177e4SLinus Torvalds completionCode)); 35131da177e4SLinus Torvalds } /* end of address reply case */ 35141da177e4SLinus Torvalds 35151da177e4SLinus Torvalds hd->pLocal->completion = completionCode; 35161da177e4SLinus Torvalds 35171da177e4SLinus Torvalds /* MF and RF are freed in mpt_interrupt 35181da177e4SLinus Torvalds */ 35191da177e4SLinus Torvalds wakeup: 35201da177e4SLinus Torvalds /* Free Chain buffers (will never chain) in scan or dv */ 35211da177e4SLinus Torvalds //mptscsih_freeChainBuffers(ioc, req_idx); 35221da177e4SLinus Torvalds 35231da177e4SLinus Torvalds /* 35241da177e4SLinus Torvalds * Wake up the original calling thread 35251da177e4SLinus Torvalds */ 35260d0c7974SMoore, Eric Dean hd->scandv_wait_done = 1; 35270d0c7974SMoore, Eric Dean wake_up(&hd->scandv_waitq); 35281da177e4SLinus Torvalds 35291da177e4SLinus Torvalds return 1; 35301da177e4SLinus Torvalds } 35311da177e4SLinus Torvalds 35321da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 35331da177e4SLinus Torvalds /* mptscsih_timer_expired - Call back for timer process. 35341da177e4SLinus Torvalds * Used only for dv functionality. 35351da177e4SLinus Torvalds * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long 35361da177e4SLinus Torvalds * 35371da177e4SLinus Torvalds */ 35380d0c7974SMoore, Eric Dean void 35390d0c7974SMoore, Eric Dean mptscsih_timer_expired(unsigned long data) 35401da177e4SLinus Torvalds { 35411da177e4SLinus Torvalds MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) data; 35421da177e4SLinus Torvalds 35431da177e4SLinus Torvalds ddvprintk((MYIOC_s_WARN_FMT "Timer Expired! Cmd %p\n", hd->ioc->name, hd->cmdPtr)); 35441da177e4SLinus Torvalds 35451da177e4SLinus Torvalds if (hd->cmdPtr) { 35461da177e4SLinus Torvalds MPIHeader_t *cmd = (MPIHeader_t *)hd->cmdPtr; 35471da177e4SLinus Torvalds 35481da177e4SLinus Torvalds if (cmd->Function == MPI_FUNCTION_SCSI_IO_REQUEST) { 35491da177e4SLinus Torvalds /* Desire to issue a task management request here. 35501da177e4SLinus Torvalds * TM requests MUST be single threaded. 35511da177e4SLinus Torvalds * If old eh code and no TM current, issue request. 35521da177e4SLinus Torvalds * If new eh code, do nothing. Wait for OS cmd timeout 35531da177e4SLinus Torvalds * for bus reset. 35541da177e4SLinus Torvalds */ 35551da177e4SLinus Torvalds ddvtprintk((MYIOC_s_NOTE_FMT "DV Cmd Timeout: NoOp\n", hd->ioc->name)); 35561da177e4SLinus Torvalds } else { 35571da177e4SLinus Torvalds /* Perform a FW reload */ 35581da177e4SLinus Torvalds if (mpt_HardResetHandler(hd->ioc, NO_SLEEP) < 0) { 35591da177e4SLinus Torvalds printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", hd->ioc->name); 35601da177e4SLinus Torvalds } 35611da177e4SLinus Torvalds } 35621da177e4SLinus Torvalds } else { 35631da177e4SLinus Torvalds /* This should NEVER happen */ 35641da177e4SLinus Torvalds printk(MYIOC_s_WARN_FMT "Null cmdPtr!!!!\n", hd->ioc->name); 35651da177e4SLinus Torvalds } 35661da177e4SLinus Torvalds 35671da177e4SLinus Torvalds /* No more processing. 35681da177e4SLinus Torvalds * TM call will generate an interrupt for SCSI TM Management. 35691da177e4SLinus Torvalds * The FW will reply to all outstanding commands, callback will finish cleanup. 35701da177e4SLinus Torvalds * Hard reset clean-up will free all resources. 35711da177e4SLinus Torvalds */ 35721da177e4SLinus Torvalds ddvprintk((MYIOC_s_WARN_FMT "Timer Expired Complete!\n", hd->ioc->name)); 35731da177e4SLinus Torvalds 35741da177e4SLinus Torvalds return; 35751da177e4SLinus Torvalds } 35761da177e4SLinus Torvalds 35771da177e4SLinus Torvalds #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION 35781da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 35791da177e4SLinus Torvalds /* mptscsih_do_raid - Format and Issue a RAID volume request message. 35801da177e4SLinus Torvalds * @hd: Pointer to scsi host structure 35811da177e4SLinus Torvalds * @action: What do be done. 35821da177e4SLinus Torvalds * @id: Logical target id. 35831da177e4SLinus Torvalds * @bus: Target locations bus. 35841da177e4SLinus Torvalds * 35851da177e4SLinus Torvalds * Returns: < 0 on a fatal error 35861da177e4SLinus Torvalds * 0 on success 35871da177e4SLinus Torvalds * 35881da177e4SLinus Torvalds * Remark: Wait to return until reply processed by the ISR. 35891da177e4SLinus Torvalds */ 35901da177e4SLinus Torvalds static int 35911da177e4SLinus Torvalds mptscsih_do_raid(MPT_SCSI_HOST *hd, u8 action, INTERNAL_CMD *io) 35921da177e4SLinus Torvalds { 35931da177e4SLinus Torvalds MpiRaidActionRequest_t *pReq; 35941da177e4SLinus Torvalds MPT_FRAME_HDR *mf; 35951da177e4SLinus Torvalds int in_isr; 35961da177e4SLinus Torvalds 35971da177e4SLinus Torvalds in_isr = in_interrupt(); 35981da177e4SLinus Torvalds if (in_isr) { 35991da177e4SLinus Torvalds dprintk((MYIOC_s_WARN_FMT "Internal raid request not allowed in ISR context!\n", 36001da177e4SLinus Torvalds hd->ioc->name)); 36011da177e4SLinus Torvalds return -EPERM; 36021da177e4SLinus Torvalds } 36031da177e4SLinus Torvalds 36041da177e4SLinus Torvalds /* Get and Populate a free Frame 36051da177e4SLinus Torvalds */ 36060d0c7974SMoore, Eric Dean if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) { 36071da177e4SLinus Torvalds ddvprintk((MYIOC_s_WARN_FMT "_do_raid: no msg frames!\n", 36081da177e4SLinus Torvalds hd->ioc->name)); 36091da177e4SLinus Torvalds return -EAGAIN; 36101da177e4SLinus Torvalds } 36111da177e4SLinus Torvalds pReq = (MpiRaidActionRequest_t *)mf; 36121da177e4SLinus Torvalds pReq->Action = action; 36131da177e4SLinus Torvalds pReq->Reserved1 = 0; 36141da177e4SLinus Torvalds pReq->ChainOffset = 0; 36151da177e4SLinus Torvalds pReq->Function = MPI_FUNCTION_RAID_ACTION; 36161da177e4SLinus Torvalds pReq->VolumeID = io->id; 36171da177e4SLinus Torvalds pReq->VolumeBus = io->bus; 36181da177e4SLinus Torvalds pReq->PhysDiskNum = io->physDiskNum; 36191da177e4SLinus Torvalds pReq->MsgFlags = 0; 36201da177e4SLinus Torvalds pReq->Reserved2 = 0; 36211da177e4SLinus Torvalds pReq->ActionDataWord = 0; /* Reserved for this action */ 36221da177e4SLinus Torvalds //pReq->ActionDataSGE = 0; 36231da177e4SLinus Torvalds 36241da177e4SLinus Torvalds mpt_add_sge((char *)&pReq->ActionDataSGE, 36251da177e4SLinus Torvalds MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1); 36261da177e4SLinus Torvalds 36271da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT "RAID Volume action %x id %d\n", 36281da177e4SLinus Torvalds hd->ioc->name, action, io->id)); 36291da177e4SLinus Torvalds 36301da177e4SLinus Torvalds hd->pLocal = NULL; 36311da177e4SLinus Torvalds hd->timer.expires = jiffies + HZ*10; /* 10 second timeout */ 36320d0c7974SMoore, Eric Dean hd->scandv_wait_done = 0; 36331da177e4SLinus Torvalds 36341da177e4SLinus Torvalds /* Save cmd pointer, for resource free if timeout or 36351da177e4SLinus Torvalds * FW reload occurs 36361da177e4SLinus Torvalds */ 36371da177e4SLinus Torvalds hd->cmdPtr = mf; 36381da177e4SLinus Torvalds 36391da177e4SLinus Torvalds add_timer(&hd->timer); 36400d0c7974SMoore, Eric Dean mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf); 36410d0c7974SMoore, Eric Dean wait_event(hd->scandv_waitq, hd->scandv_wait_done); 36421da177e4SLinus Torvalds 36431da177e4SLinus Torvalds if ((hd->pLocal == NULL) || (hd->pLocal->completion != MPT_SCANDV_GOOD)) 36441da177e4SLinus Torvalds return -1; 36451da177e4SLinus Torvalds 36461da177e4SLinus Torvalds return 0; 36471da177e4SLinus Torvalds } 36481da177e4SLinus Torvalds #endif /* ~MPTSCSIH_ENABLE_DOMAIN_VALIDATION */ 36491da177e4SLinus Torvalds 36501da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 36511da177e4SLinus Torvalds /** 36521da177e4SLinus Torvalds * mptscsih_do_cmd - Do internal command. 36531da177e4SLinus Torvalds * @hd: MPT_SCSI_HOST pointer 36541da177e4SLinus Torvalds * @io: INTERNAL_CMD pointer. 36551da177e4SLinus Torvalds * 36561da177e4SLinus Torvalds * Issue the specified internally generated command and do command 36571da177e4SLinus Torvalds * specific cleanup. For bus scan / DV only. 36581da177e4SLinus Torvalds * NOTES: If command is Inquiry and status is good, 36591da177e4SLinus Torvalds * initialize a target structure, save the data 36601da177e4SLinus Torvalds * 36611da177e4SLinus Torvalds * Remark: Single threaded access only. 36621da177e4SLinus Torvalds * 36631da177e4SLinus Torvalds * Return: 36641da177e4SLinus Torvalds * < 0 if an illegal command or no resources 36651da177e4SLinus Torvalds * 36661da177e4SLinus Torvalds * 0 if good 36671da177e4SLinus Torvalds * 36681da177e4SLinus Torvalds * > 0 if command complete but some type of completion error. 36691da177e4SLinus Torvalds */ 36701da177e4SLinus Torvalds static int 36711da177e4SLinus Torvalds mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io) 36721da177e4SLinus Torvalds { 36731da177e4SLinus Torvalds MPT_FRAME_HDR *mf; 36741da177e4SLinus Torvalds SCSIIORequest_t *pScsiReq; 36751da177e4SLinus Torvalds SCSIIORequest_t ReqCopy; 36761da177e4SLinus Torvalds int my_idx, ii, dir; 36771da177e4SLinus Torvalds int rc, cmdTimeout; 36781da177e4SLinus Torvalds int in_isr; 36791da177e4SLinus Torvalds char cmdLen; 36801da177e4SLinus Torvalds char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 36811da177e4SLinus Torvalds char cmd = io->cmd; 36821da177e4SLinus Torvalds 36831da177e4SLinus Torvalds in_isr = in_interrupt(); 36841da177e4SLinus Torvalds if (in_isr) { 36851da177e4SLinus Torvalds dprintk((MYIOC_s_WARN_FMT "Internal SCSI IO request not allowed in ISR context!\n", 36861da177e4SLinus Torvalds hd->ioc->name)); 36871da177e4SLinus Torvalds return -EPERM; 36881da177e4SLinus Torvalds } 36891da177e4SLinus Torvalds 36901da177e4SLinus Torvalds 36911da177e4SLinus Torvalds /* Set command specific information 36921da177e4SLinus Torvalds */ 36931da177e4SLinus Torvalds switch (cmd) { 36941da177e4SLinus Torvalds case INQUIRY: 36951da177e4SLinus Torvalds cmdLen = 6; 36961da177e4SLinus Torvalds dir = MPI_SCSIIO_CONTROL_READ; 36971da177e4SLinus Torvalds CDB[0] = cmd; 36981da177e4SLinus Torvalds CDB[4] = io->size; 36991da177e4SLinus Torvalds cmdTimeout = 10; 37001da177e4SLinus Torvalds break; 37011da177e4SLinus Torvalds 37021da177e4SLinus Torvalds case TEST_UNIT_READY: 37031da177e4SLinus Torvalds cmdLen = 6; 37041da177e4SLinus Torvalds dir = MPI_SCSIIO_CONTROL_READ; 37051da177e4SLinus Torvalds cmdTimeout = 10; 37061da177e4SLinus Torvalds break; 37071da177e4SLinus Torvalds 37081da177e4SLinus Torvalds case START_STOP: 37091da177e4SLinus Torvalds cmdLen = 6; 37101da177e4SLinus Torvalds dir = MPI_SCSIIO_CONTROL_READ; 37111da177e4SLinus Torvalds CDB[0] = cmd; 37121da177e4SLinus Torvalds CDB[4] = 1; /*Spin up the disk */ 37131da177e4SLinus Torvalds cmdTimeout = 15; 37141da177e4SLinus Torvalds break; 37151da177e4SLinus Torvalds 37161da177e4SLinus Torvalds case REQUEST_SENSE: 37171da177e4SLinus Torvalds cmdLen = 6; 37181da177e4SLinus Torvalds CDB[0] = cmd; 37191da177e4SLinus Torvalds CDB[4] = io->size; 37201da177e4SLinus Torvalds dir = MPI_SCSIIO_CONTROL_READ; 37211da177e4SLinus Torvalds cmdTimeout = 10; 37221da177e4SLinus Torvalds break; 37231da177e4SLinus Torvalds 37241da177e4SLinus Torvalds case READ_BUFFER: 37251da177e4SLinus Torvalds cmdLen = 10; 37261da177e4SLinus Torvalds dir = MPI_SCSIIO_CONTROL_READ; 37271da177e4SLinus Torvalds CDB[0] = cmd; 37281da177e4SLinus Torvalds if (io->flags & MPT_ICFLAG_ECHO) { 37291da177e4SLinus Torvalds CDB[1] = 0x0A; 37301da177e4SLinus Torvalds } else { 37311da177e4SLinus Torvalds CDB[1] = 0x02; 37321da177e4SLinus Torvalds } 37331da177e4SLinus Torvalds 37341da177e4SLinus Torvalds if (io->flags & MPT_ICFLAG_BUF_CAP) { 37351da177e4SLinus Torvalds CDB[1] |= 0x01; 37361da177e4SLinus Torvalds } 37371da177e4SLinus Torvalds CDB[6] = (io->size >> 16) & 0xFF; 37381da177e4SLinus Torvalds CDB[7] = (io->size >> 8) & 0xFF; 37391da177e4SLinus Torvalds CDB[8] = io->size & 0xFF; 37401da177e4SLinus Torvalds cmdTimeout = 10; 37411da177e4SLinus Torvalds break; 37421da177e4SLinus Torvalds 37431da177e4SLinus Torvalds case WRITE_BUFFER: 37441da177e4SLinus Torvalds cmdLen = 10; 37451da177e4SLinus Torvalds dir = MPI_SCSIIO_CONTROL_WRITE; 37461da177e4SLinus Torvalds CDB[0] = cmd; 37471da177e4SLinus Torvalds if (io->flags & MPT_ICFLAG_ECHO) { 37481da177e4SLinus Torvalds CDB[1] = 0x0A; 37491da177e4SLinus Torvalds } else { 37501da177e4SLinus Torvalds CDB[1] = 0x02; 37511da177e4SLinus Torvalds } 37521da177e4SLinus Torvalds CDB[6] = (io->size >> 16) & 0xFF; 37531da177e4SLinus Torvalds CDB[7] = (io->size >> 8) & 0xFF; 37541da177e4SLinus Torvalds CDB[8] = io->size & 0xFF; 37551da177e4SLinus Torvalds cmdTimeout = 10; 37561da177e4SLinus Torvalds break; 37571da177e4SLinus Torvalds 37581da177e4SLinus Torvalds case RESERVE: 37591da177e4SLinus Torvalds cmdLen = 6; 37601da177e4SLinus Torvalds dir = MPI_SCSIIO_CONTROL_READ; 37611da177e4SLinus Torvalds CDB[0] = cmd; 37621da177e4SLinus Torvalds cmdTimeout = 10; 37631da177e4SLinus Torvalds break; 37641da177e4SLinus Torvalds 37651da177e4SLinus Torvalds case RELEASE: 37661da177e4SLinus Torvalds cmdLen = 6; 37671da177e4SLinus Torvalds dir = MPI_SCSIIO_CONTROL_READ; 37681da177e4SLinus Torvalds CDB[0] = cmd; 37691da177e4SLinus Torvalds cmdTimeout = 10; 37701da177e4SLinus Torvalds break; 37711da177e4SLinus Torvalds 37721da177e4SLinus Torvalds case SYNCHRONIZE_CACHE: 37731da177e4SLinus Torvalds cmdLen = 10; 37741da177e4SLinus Torvalds dir = MPI_SCSIIO_CONTROL_READ; 37751da177e4SLinus Torvalds CDB[0] = cmd; 37761da177e4SLinus Torvalds // CDB[1] = 0x02; /* set immediate bit */ 37771da177e4SLinus Torvalds cmdTimeout = 10; 37781da177e4SLinus Torvalds break; 37791da177e4SLinus Torvalds 37801da177e4SLinus Torvalds default: 37811da177e4SLinus Torvalds /* Error Case */ 37821da177e4SLinus Torvalds return -EFAULT; 37831da177e4SLinus Torvalds } 37841da177e4SLinus Torvalds 37851da177e4SLinus Torvalds /* Get and Populate a free Frame 37861da177e4SLinus Torvalds */ 37870d0c7974SMoore, Eric Dean if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) { 37881da177e4SLinus Torvalds ddvprintk((MYIOC_s_WARN_FMT "No msg frames!\n", 37891da177e4SLinus Torvalds hd->ioc->name)); 37901da177e4SLinus Torvalds return -EBUSY; 37911da177e4SLinus Torvalds } 37921da177e4SLinus Torvalds 37931da177e4SLinus Torvalds pScsiReq = (SCSIIORequest_t *) mf; 37941da177e4SLinus Torvalds 37951da177e4SLinus Torvalds /* Get the request index */ 37961da177e4SLinus Torvalds my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx); 37971da177e4SLinus Torvalds ADD_INDEX_LOG(my_idx); /* for debug */ 37981da177e4SLinus Torvalds 37991da177e4SLinus Torvalds if (io->flags & MPT_ICFLAG_PHYS_DISK) { 38001da177e4SLinus Torvalds pScsiReq->TargetID = io->physDiskNum; 38011da177e4SLinus Torvalds pScsiReq->Bus = 0; 38021da177e4SLinus Torvalds pScsiReq->ChainOffset = 0; 38031da177e4SLinus Torvalds pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; 38041da177e4SLinus Torvalds } else { 38051da177e4SLinus Torvalds pScsiReq->TargetID = io->id; 38061da177e4SLinus Torvalds pScsiReq->Bus = io->bus; 38071da177e4SLinus Torvalds pScsiReq->ChainOffset = 0; 38081da177e4SLinus Torvalds pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST; 38091da177e4SLinus Torvalds } 38101da177e4SLinus Torvalds 38111da177e4SLinus Torvalds pScsiReq->CDBLength = cmdLen; 38121da177e4SLinus Torvalds pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE; 38131da177e4SLinus Torvalds 38141da177e4SLinus Torvalds pScsiReq->Reserved = 0; 38151da177e4SLinus Torvalds 38161da177e4SLinus Torvalds pScsiReq->MsgFlags = mpt_msg_flags(); 38171da177e4SLinus Torvalds /* MsgContext set in mpt_get_msg_fram call */ 38181da177e4SLinus Torvalds 38191da177e4SLinus Torvalds for (ii=0; ii < 8; ii++) 38201da177e4SLinus Torvalds pScsiReq->LUN[ii] = 0; 38211da177e4SLinus Torvalds pScsiReq->LUN[1] = io->lun; 38221da177e4SLinus Torvalds 38231da177e4SLinus Torvalds if (io->flags & MPT_ICFLAG_TAGGED_CMD) 38241da177e4SLinus Torvalds pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ); 38251da177e4SLinus Torvalds else 38261da177e4SLinus Torvalds pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED); 38271da177e4SLinus Torvalds 38281da177e4SLinus Torvalds if (cmd == REQUEST_SENSE) { 38291da177e4SLinus Torvalds pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED); 38301da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT "Untagged! 0x%2x\n", 38311da177e4SLinus Torvalds hd->ioc->name, cmd)); 38321da177e4SLinus Torvalds } 38331da177e4SLinus Torvalds 38341da177e4SLinus Torvalds for (ii=0; ii < 16; ii++) 38351da177e4SLinus Torvalds pScsiReq->CDB[ii] = CDB[ii]; 38361da177e4SLinus Torvalds 38371da177e4SLinus Torvalds pScsiReq->DataLength = cpu_to_le32(io->size); 38381da177e4SLinus Torvalds pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma 38391da177e4SLinus Torvalds + (my_idx * MPT_SENSE_BUFFER_ALLOC)); 38401da177e4SLinus Torvalds 38411da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT "Sending Command 0x%x for (%d:%d:%d)\n", 38421da177e4SLinus Torvalds hd->ioc->name, cmd, io->bus, io->id, io->lun)); 38431da177e4SLinus Torvalds 38441da177e4SLinus Torvalds if (dir == MPI_SCSIIO_CONTROL_READ) { 38451da177e4SLinus Torvalds mpt_add_sge((char *) &pScsiReq->SGL, 38461da177e4SLinus Torvalds MPT_SGE_FLAGS_SSIMPLE_READ | io->size, 38471da177e4SLinus Torvalds io->data_dma); 38481da177e4SLinus Torvalds } else { 38491da177e4SLinus Torvalds mpt_add_sge((char *) &pScsiReq->SGL, 38501da177e4SLinus Torvalds MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size, 38511da177e4SLinus Torvalds io->data_dma); 38521da177e4SLinus Torvalds } 38531da177e4SLinus Torvalds 38541da177e4SLinus Torvalds /* The ISR will free the request frame, but we need 38551da177e4SLinus Torvalds * the information to initialize the target. Duplicate. 38561da177e4SLinus Torvalds */ 38571da177e4SLinus Torvalds memcpy(&ReqCopy, pScsiReq, sizeof(SCSIIORequest_t)); 38581da177e4SLinus Torvalds 38591da177e4SLinus Torvalds /* Issue this command after: 38601da177e4SLinus Torvalds * finish init 38611da177e4SLinus Torvalds * add timer 38621da177e4SLinus Torvalds * Wait until the reply has been received 38631da177e4SLinus Torvalds * ScsiScanDvCtx callback function will 38641da177e4SLinus Torvalds * set hd->pLocal; 38651da177e4SLinus Torvalds * set scandv_wait_done and call wake_up 38661da177e4SLinus Torvalds */ 38671da177e4SLinus Torvalds hd->pLocal = NULL; 38681da177e4SLinus Torvalds hd->timer.expires = jiffies + HZ*cmdTimeout; 38690d0c7974SMoore, Eric Dean hd->scandv_wait_done = 0; 38701da177e4SLinus Torvalds 38711da177e4SLinus Torvalds /* Save cmd pointer, for resource free if timeout or 38721da177e4SLinus Torvalds * FW reload occurs 38731da177e4SLinus Torvalds */ 38741da177e4SLinus Torvalds hd->cmdPtr = mf; 38751da177e4SLinus Torvalds 38761da177e4SLinus Torvalds add_timer(&hd->timer); 38770d0c7974SMoore, Eric Dean mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf); 38780d0c7974SMoore, Eric Dean wait_event(hd->scandv_waitq, hd->scandv_wait_done); 38791da177e4SLinus Torvalds 38801da177e4SLinus Torvalds if (hd->pLocal) { 38811da177e4SLinus Torvalds rc = hd->pLocal->completion; 38821da177e4SLinus Torvalds hd->pLocal->skip = 0; 38831da177e4SLinus Torvalds 38841da177e4SLinus Torvalds /* Always set fatal error codes in some cases. 38851da177e4SLinus Torvalds */ 38861da177e4SLinus Torvalds if (rc == MPT_SCANDV_SELECTION_TIMEOUT) 38871da177e4SLinus Torvalds rc = -ENXIO; 38881da177e4SLinus Torvalds else if (rc == MPT_SCANDV_SOME_ERROR) 38891da177e4SLinus Torvalds rc = -rc; 38901da177e4SLinus Torvalds } else { 38911da177e4SLinus Torvalds rc = -EFAULT; 38921da177e4SLinus Torvalds /* This should never happen. */ 38931da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT "_do_cmd: Null pLocal!!!\n", 38941da177e4SLinus Torvalds hd->ioc->name)); 38951da177e4SLinus Torvalds } 38961da177e4SLinus Torvalds 38971da177e4SLinus Torvalds return rc; 38981da177e4SLinus Torvalds } 38991da177e4SLinus Torvalds 39001da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 39011da177e4SLinus Torvalds /** 39021da177e4SLinus Torvalds * mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks. 39031da177e4SLinus Torvalds * @hd: Pointer to MPT_SCSI_HOST structure 39041da177e4SLinus Torvalds * @portnum: IOC port number 39051da177e4SLinus Torvalds * 39061da177e4SLinus Torvalds * Uses the ISR, but with special processing. 39071da177e4SLinus Torvalds * MUST be single-threaded. 39081da177e4SLinus Torvalds * 39091da177e4SLinus Torvalds * Return: 0 on completion 39101da177e4SLinus Torvalds */ 39111da177e4SLinus Torvalds static int 39121da177e4SLinus Torvalds mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, int portnum) 39131da177e4SLinus Torvalds { 39141da177e4SLinus Torvalds MPT_ADAPTER *ioc= hd->ioc; 39151da177e4SLinus Torvalds VirtDevice *pTarget; 39161da177e4SLinus Torvalds SCSIDevicePage1_t *pcfg1Data = NULL; 39171da177e4SLinus Torvalds INTERNAL_CMD iocmd; 39181da177e4SLinus Torvalds CONFIGPARMS cfg; 39191da177e4SLinus Torvalds dma_addr_t cfg1_dma_addr = -1; 39201da177e4SLinus Torvalds ConfigPageHeader_t header1; 39211da177e4SLinus Torvalds int bus = 0; 39221da177e4SLinus Torvalds int id = 0; 39231da177e4SLinus Torvalds int lun; 39241da177e4SLinus Torvalds int indexed_lun, lun_index; 39251da177e4SLinus Torvalds int hostId = ioc->pfacts[portnum].PortSCSIID; 39261da177e4SLinus Torvalds int max_id; 39271da177e4SLinus Torvalds int requested, configuration, data; 39281da177e4SLinus Torvalds int doConfig = 0; 39291da177e4SLinus Torvalds u8 flags, factor; 39301da177e4SLinus Torvalds 39311da177e4SLinus Torvalds max_id = ioc->sh->max_id - 1; 39321da177e4SLinus Torvalds 39331da177e4SLinus Torvalds /* Following parameters will not change 39341da177e4SLinus Torvalds * in this routine. 39351da177e4SLinus Torvalds */ 39361da177e4SLinus Torvalds iocmd.cmd = SYNCHRONIZE_CACHE; 39371da177e4SLinus Torvalds iocmd.flags = 0; 39381da177e4SLinus Torvalds iocmd.physDiskNum = -1; 39391da177e4SLinus Torvalds iocmd.data = NULL; 39401da177e4SLinus Torvalds iocmd.data_dma = -1; 39411da177e4SLinus Torvalds iocmd.size = 0; 39421da177e4SLinus Torvalds iocmd.rsvd = iocmd.rsvd2 = 0; 39431da177e4SLinus Torvalds 39441da177e4SLinus Torvalds /* No SCSI hosts 39451da177e4SLinus Torvalds */ 39461da177e4SLinus Torvalds if (hd->Targets == NULL) 39471da177e4SLinus Torvalds return 0; 39481da177e4SLinus Torvalds 39491da177e4SLinus Torvalds /* Skip the host 39501da177e4SLinus Torvalds */ 39511da177e4SLinus Torvalds if (id == hostId) 39521da177e4SLinus Torvalds id++; 39531da177e4SLinus Torvalds 39541da177e4SLinus Torvalds /* Write SDP1 for all SCSI devices 39551da177e4SLinus Torvalds * Alloc memory and set up config buffer 39561da177e4SLinus Torvalds */ 39571da177e4SLinus Torvalds if (ioc->bus_type == SCSI) { 39581da177e4SLinus Torvalds if (ioc->spi_data.sdp1length > 0) { 39591da177e4SLinus Torvalds pcfg1Data = (SCSIDevicePage1_t *)pci_alloc_consistent(ioc->pcidev, 39601da177e4SLinus Torvalds ioc->spi_data.sdp1length * 4, &cfg1_dma_addr); 39611da177e4SLinus Torvalds 39621da177e4SLinus Torvalds if (pcfg1Data != NULL) { 39631da177e4SLinus Torvalds doConfig = 1; 39641da177e4SLinus Torvalds header1.PageVersion = ioc->spi_data.sdp1version; 39651da177e4SLinus Torvalds header1.PageLength = ioc->spi_data.sdp1length; 39661da177e4SLinus Torvalds header1.PageNumber = 1; 39671da177e4SLinus Torvalds header1.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; 39681da177e4SLinus Torvalds cfg.hdr = &header1; 39691da177e4SLinus Torvalds cfg.physAddr = cfg1_dma_addr; 39701da177e4SLinus Torvalds cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 39711da177e4SLinus Torvalds cfg.dir = 1; 39721da177e4SLinus Torvalds cfg.timeout = 0; 39731da177e4SLinus Torvalds } 39741da177e4SLinus Torvalds } 39751da177e4SLinus Torvalds } 39761da177e4SLinus Torvalds 39771da177e4SLinus Torvalds /* loop through all devices on this port 39781da177e4SLinus Torvalds */ 39791da177e4SLinus Torvalds while (bus < MPT_MAX_BUS) { 39801da177e4SLinus Torvalds iocmd.bus = bus; 39811da177e4SLinus Torvalds iocmd.id = id; 39821da177e4SLinus Torvalds pTarget = hd->Targets[(int)id]; 39831da177e4SLinus Torvalds 39841da177e4SLinus Torvalds if (doConfig) { 39851da177e4SLinus Torvalds 39861da177e4SLinus Torvalds /* Set the negotiation flags */ 39871da177e4SLinus Torvalds if (pTarget && (pTarget = hd->Targets[id]) && !pTarget->raidVolume) { 39881da177e4SLinus Torvalds flags = pTarget->negoFlags; 39891da177e4SLinus Torvalds } else { 39901da177e4SLinus Torvalds flags = hd->ioc->spi_data.noQas; 39911da177e4SLinus Torvalds if (hd->ioc->spi_data.nvram && (hd->ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) { 39921da177e4SLinus Torvalds data = hd->ioc->spi_data.nvram[id]; 39931da177e4SLinus Torvalds 39941da177e4SLinus Torvalds if (data & MPT_NVRAM_WIDE_DISABLE) 39951da177e4SLinus Torvalds flags |= MPT_TARGET_NO_NEGO_WIDE; 39961da177e4SLinus Torvalds 39971da177e4SLinus Torvalds factor = (data & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT; 39981da177e4SLinus Torvalds if ((factor == 0) || (factor == MPT_ASYNC)) 39991da177e4SLinus Torvalds flags |= MPT_TARGET_NO_NEGO_SYNC; 40001da177e4SLinus Torvalds } 40011da177e4SLinus Torvalds } 40021da177e4SLinus Torvalds 40031da177e4SLinus Torvalds /* Force to async, narrow */ 40041da177e4SLinus Torvalds mptscsih_setDevicePage1Flags(0, MPT_ASYNC, 0, &requested, 40051da177e4SLinus Torvalds &configuration, flags); 40061da177e4SLinus Torvalds dnegoprintk(("syncronize cache: id=%d width=0 factor=MPT_ASYNC " 40071da177e4SLinus Torvalds "offset=0 negoFlags=%x request=%x config=%x\n", 40081da177e4SLinus Torvalds id, flags, requested, configuration)); 40091da177e4SLinus Torvalds pcfg1Data->RequestedParameters = le32_to_cpu(requested); 40101da177e4SLinus Torvalds pcfg1Data->Reserved = 0; 40111da177e4SLinus Torvalds pcfg1Data->Configuration = le32_to_cpu(configuration); 40121da177e4SLinus Torvalds cfg.pageAddr = (bus<<8) | id; 40131da177e4SLinus Torvalds mpt_config(hd->ioc, &cfg); 40141da177e4SLinus Torvalds } 40151da177e4SLinus Torvalds 40161da177e4SLinus Torvalds /* If target Ptr NULL or if this target is NOT a disk, skip. 40171da177e4SLinus Torvalds */ 40181da177e4SLinus Torvalds if ((pTarget) && (pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)){ 40191da177e4SLinus Torvalds for (lun=0; lun <= MPT_LAST_LUN; lun++) { 40201da177e4SLinus Torvalds /* If LUN present, issue the command 40211da177e4SLinus Torvalds */ 40221da177e4SLinus Torvalds lun_index = (lun >> 5); /* 32 luns per lun_index */ 40231da177e4SLinus Torvalds indexed_lun = (lun % 32); 40241da177e4SLinus Torvalds if (pTarget->luns[lun_index] & (1<<indexed_lun)) { 40251da177e4SLinus Torvalds iocmd.lun = lun; 40261da177e4SLinus Torvalds (void) mptscsih_do_cmd(hd, &iocmd); 40271da177e4SLinus Torvalds } 40281da177e4SLinus Torvalds } 40291da177e4SLinus Torvalds } 40301da177e4SLinus Torvalds 40311da177e4SLinus Torvalds /* get next relevant device */ 40321da177e4SLinus Torvalds id++; 40331da177e4SLinus Torvalds 40341da177e4SLinus Torvalds if (id == hostId) 40351da177e4SLinus Torvalds id++; 40361da177e4SLinus Torvalds 40371da177e4SLinus Torvalds if (id > max_id) { 40381da177e4SLinus Torvalds id = 0; 40391da177e4SLinus Torvalds bus++; 40401da177e4SLinus Torvalds } 40411da177e4SLinus Torvalds } 40421da177e4SLinus Torvalds 40431da177e4SLinus Torvalds if (pcfg1Data) { 40441da177e4SLinus Torvalds pci_free_consistent(ioc->pcidev, header1.PageLength * 4, pcfg1Data, cfg1_dma_addr); 40451da177e4SLinus Torvalds } 40461da177e4SLinus Torvalds 40471da177e4SLinus Torvalds return 0; 40481da177e4SLinus Torvalds } 40491da177e4SLinus Torvalds 40501da177e4SLinus Torvalds #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION 40511da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 40521da177e4SLinus Torvalds /** 40531da177e4SLinus Torvalds * mptscsih_domainValidation - Top level handler for domain validation. 40541da177e4SLinus Torvalds * @hd: Pointer to MPT_SCSI_HOST structure. 40551da177e4SLinus Torvalds * 40561da177e4SLinus Torvalds * Uses the ISR, but with special processing. 40571da177e4SLinus Torvalds * Called from schedule, should not be in interrupt mode. 40581da177e4SLinus Torvalds * While thread alive, do dv for all devices needing dv 40591da177e4SLinus Torvalds * 40601da177e4SLinus Torvalds * Return: None. 40611da177e4SLinus Torvalds */ 40621da177e4SLinus Torvalds static void 40631da177e4SLinus Torvalds mptscsih_domainValidation(void *arg) 40641da177e4SLinus Torvalds { 40651da177e4SLinus Torvalds MPT_SCSI_HOST *hd; 40661da177e4SLinus Torvalds MPT_ADAPTER *ioc; 40671da177e4SLinus Torvalds unsigned long flags; 40681da177e4SLinus Torvalds int id, maxid, dvStatus, did; 40691da177e4SLinus Torvalds int ii, isPhysDisk; 40701da177e4SLinus Torvalds 40711da177e4SLinus Torvalds spin_lock_irqsave(&dvtaskQ_lock, flags); 40721da177e4SLinus Torvalds dvtaskQ_active = 1; 40731da177e4SLinus Torvalds if (dvtaskQ_release) { 40741da177e4SLinus Torvalds dvtaskQ_active = 0; 40751da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, flags); 40761da177e4SLinus Torvalds return; 40771da177e4SLinus Torvalds } 40781da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, flags); 40791da177e4SLinus Torvalds 40801da177e4SLinus Torvalds /* For this ioc, loop through all devices and do dv to each device. 40811da177e4SLinus Torvalds * When complete with this ioc, search through the ioc list, and 40821da177e4SLinus Torvalds * for each scsi ioc found, do dv for all devices. Exit when no 40831da177e4SLinus Torvalds * device needs dv. 40841da177e4SLinus Torvalds */ 40851da177e4SLinus Torvalds did = 1; 40861da177e4SLinus Torvalds while (did) { 40871da177e4SLinus Torvalds did = 0; 40881da177e4SLinus Torvalds list_for_each_entry(ioc, &ioc_list, list) { 40891da177e4SLinus Torvalds spin_lock_irqsave(&dvtaskQ_lock, flags); 40901da177e4SLinus Torvalds if (dvtaskQ_release) { 40911da177e4SLinus Torvalds dvtaskQ_active = 0; 40921da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, flags); 40931da177e4SLinus Torvalds return; 40941da177e4SLinus Torvalds } 40951da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, flags); 40961da177e4SLinus Torvalds 40971da177e4SLinus Torvalds msleep(250); 40981da177e4SLinus Torvalds 40991da177e4SLinus Torvalds /* DV only to SCSI adapters */ 41001da177e4SLinus Torvalds if (ioc->bus_type != SCSI) 41011da177e4SLinus Torvalds continue; 41021da177e4SLinus Torvalds 41031da177e4SLinus Torvalds /* Make sure everything looks ok */ 41041da177e4SLinus Torvalds if (ioc->sh == NULL) 41051da177e4SLinus Torvalds continue; 41061da177e4SLinus Torvalds 41071da177e4SLinus Torvalds hd = (MPT_SCSI_HOST *) ioc->sh->hostdata; 41081da177e4SLinus Torvalds if (hd == NULL) 41091da177e4SLinus Torvalds continue; 41101da177e4SLinus Torvalds 41111da177e4SLinus Torvalds if ((ioc->spi_data.forceDv & MPT_SCSICFG_RELOAD_IOC_PG3) != 0) { 41121da177e4SLinus Torvalds mpt_read_ioc_pg_3(ioc); 41131da177e4SLinus Torvalds if (ioc->spi_data.pIocPg3) { 41141da177e4SLinus Torvalds Ioc3PhysDisk_t *pPDisk = ioc->spi_data.pIocPg3->PhysDisk; 41151da177e4SLinus Torvalds int numPDisk = ioc->spi_data.pIocPg3->NumPhysDisks; 41161da177e4SLinus Torvalds 41171da177e4SLinus Torvalds while (numPDisk) { 41181da177e4SLinus Torvalds if (ioc->spi_data.dvStatus[pPDisk->PhysDiskID] & MPT_SCSICFG_DV_NOT_DONE) 41191da177e4SLinus Torvalds ioc->spi_data.dvStatus[pPDisk->PhysDiskID] |= MPT_SCSICFG_NEED_DV; 41201da177e4SLinus Torvalds 41211da177e4SLinus Torvalds pPDisk++; 41221da177e4SLinus Torvalds numPDisk--; 41231da177e4SLinus Torvalds } 41241da177e4SLinus Torvalds } 41251da177e4SLinus Torvalds ioc->spi_data.forceDv &= ~MPT_SCSICFG_RELOAD_IOC_PG3; 41261da177e4SLinus Torvalds } 41271da177e4SLinus Torvalds 41281da177e4SLinus Torvalds maxid = min_t(int, ioc->sh->max_id, MPT_MAX_SCSI_DEVICES); 41291da177e4SLinus Torvalds 41301da177e4SLinus Torvalds for (id = 0; id < maxid; id++) { 41311da177e4SLinus Torvalds spin_lock_irqsave(&dvtaskQ_lock, flags); 41321da177e4SLinus Torvalds if (dvtaskQ_release) { 41331da177e4SLinus Torvalds dvtaskQ_active = 0; 41341da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, flags); 41351da177e4SLinus Torvalds return; 41361da177e4SLinus Torvalds } 41371da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, flags); 41381da177e4SLinus Torvalds dvStatus = hd->ioc->spi_data.dvStatus[id]; 41391da177e4SLinus Torvalds 41401da177e4SLinus Torvalds if (dvStatus & MPT_SCSICFG_NEED_DV) { 41411da177e4SLinus Torvalds did++; 41421da177e4SLinus Torvalds hd->ioc->spi_data.dvStatus[id] |= MPT_SCSICFG_DV_PENDING; 41431da177e4SLinus Torvalds hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_NEED_DV; 41441da177e4SLinus Torvalds 41451da177e4SLinus Torvalds msleep(250); 41461da177e4SLinus Torvalds 41471da177e4SLinus Torvalds /* If hidden phys disk, block IO's to all 41481da177e4SLinus Torvalds * raid volumes 41491da177e4SLinus Torvalds * else, process normally 41501da177e4SLinus Torvalds */ 41511da177e4SLinus Torvalds isPhysDisk = mptscsih_is_phys_disk(ioc, id); 41521da177e4SLinus Torvalds if (isPhysDisk) { 41531da177e4SLinus Torvalds for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) { 41541da177e4SLinus Torvalds if (hd->ioc->spi_data.isRaid & (1 << ii)) { 41551da177e4SLinus Torvalds hd->ioc->spi_data.dvStatus[ii] |= MPT_SCSICFG_DV_PENDING; 41561da177e4SLinus Torvalds } 41571da177e4SLinus Torvalds } 41581da177e4SLinus Torvalds } 41591da177e4SLinus Torvalds 41601da177e4SLinus Torvalds if (mptscsih_doDv(hd, 0, id) == 1) { 41611da177e4SLinus Torvalds /* Untagged device was busy, try again 41621da177e4SLinus Torvalds */ 41631da177e4SLinus Torvalds hd->ioc->spi_data.dvStatus[id] |= MPT_SCSICFG_NEED_DV; 41641da177e4SLinus Torvalds hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_DV_PENDING; 41651da177e4SLinus Torvalds } else { 41661da177e4SLinus Torvalds /* DV is complete. Clear flags. 41671da177e4SLinus Torvalds */ 41681da177e4SLinus Torvalds hd->ioc->spi_data.dvStatus[id] &= ~(MPT_SCSICFG_DV_NOT_DONE | MPT_SCSICFG_DV_PENDING); 41691da177e4SLinus Torvalds } 41701da177e4SLinus Torvalds 41711da177e4SLinus Torvalds if (isPhysDisk) { 41721da177e4SLinus Torvalds for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) { 41731da177e4SLinus Torvalds if (hd->ioc->spi_data.isRaid & (1 << ii)) { 41741da177e4SLinus Torvalds hd->ioc->spi_data.dvStatus[ii] &= ~MPT_SCSICFG_DV_PENDING; 41751da177e4SLinus Torvalds } 41761da177e4SLinus Torvalds } 41771da177e4SLinus Torvalds } 41781da177e4SLinus Torvalds 41791da177e4SLinus Torvalds if (hd->ioc->spi_data.noQas) 41801da177e4SLinus Torvalds mptscsih_qas_check(hd, id); 41811da177e4SLinus Torvalds } 41821da177e4SLinus Torvalds } 41831da177e4SLinus Torvalds } 41841da177e4SLinus Torvalds } 41851da177e4SLinus Torvalds 41861da177e4SLinus Torvalds spin_lock_irqsave(&dvtaskQ_lock, flags); 41871da177e4SLinus Torvalds dvtaskQ_active = 0; 41881da177e4SLinus Torvalds spin_unlock_irqrestore(&dvtaskQ_lock, flags); 41891da177e4SLinus Torvalds 41901da177e4SLinus Torvalds return; 41911da177e4SLinus Torvalds } 41921da177e4SLinus Torvalds 41931da177e4SLinus Torvalds /* Search IOC page 3 to determine if this is hidden physical disk 41941da177e4SLinus Torvalds */ 41950d0c7974SMoore, Eric Dean static int 41960d0c7974SMoore, Eric Dean mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id) 41971da177e4SLinus Torvalds { 41981da177e4SLinus Torvalds if (ioc->spi_data.pIocPg3) { 41991da177e4SLinus Torvalds Ioc3PhysDisk_t *pPDisk = ioc->spi_data.pIocPg3->PhysDisk; 42001da177e4SLinus Torvalds int numPDisk = ioc->spi_data.pIocPg3->NumPhysDisks; 42011da177e4SLinus Torvalds 42021da177e4SLinus Torvalds while (numPDisk) { 42031da177e4SLinus Torvalds if (pPDisk->PhysDiskID == id) { 42041da177e4SLinus Torvalds return 1; 42051da177e4SLinus Torvalds } 42061da177e4SLinus Torvalds pPDisk++; 42071da177e4SLinus Torvalds numPDisk--; 42081da177e4SLinus Torvalds } 42091da177e4SLinus Torvalds } 42101da177e4SLinus Torvalds return 0; 42111da177e4SLinus Torvalds } 42121da177e4SLinus Torvalds 42131da177e4SLinus Torvalds /* Write SDP1 if no QAS has been enabled 42141da177e4SLinus Torvalds */ 42150d0c7974SMoore, Eric Dean static void 42160d0c7974SMoore, Eric Dean mptscsih_qas_check(MPT_SCSI_HOST *hd, int id) 42171da177e4SLinus Torvalds { 42181da177e4SLinus Torvalds VirtDevice *pTarget; 42191da177e4SLinus Torvalds int ii; 42201da177e4SLinus Torvalds 42211da177e4SLinus Torvalds if (hd->Targets == NULL) 42221da177e4SLinus Torvalds return; 42231da177e4SLinus Torvalds 42241da177e4SLinus Torvalds for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) { 42251da177e4SLinus Torvalds if (ii == id) 42261da177e4SLinus Torvalds continue; 42271da177e4SLinus Torvalds 42281da177e4SLinus Torvalds if ((hd->ioc->spi_data.dvStatus[ii] & MPT_SCSICFG_DV_NOT_DONE) != 0) 42291da177e4SLinus Torvalds continue; 42301da177e4SLinus Torvalds 42311da177e4SLinus Torvalds pTarget = hd->Targets[ii]; 42321da177e4SLinus Torvalds 42331da177e4SLinus Torvalds if ((pTarget != NULL) && (!pTarget->raidVolume)) { 42341da177e4SLinus Torvalds if ((pTarget->negoFlags & hd->ioc->spi_data.noQas) == 0) { 42351da177e4SLinus Torvalds pTarget->negoFlags |= hd->ioc->spi_data.noQas; 42361da177e4SLinus Torvalds dnegoprintk(("writeSDP1: id=%d flags=0\n", id)); 42371da177e4SLinus Torvalds mptscsih_writeSDP1(hd, 0, ii, 0); 42381da177e4SLinus Torvalds } 42391da177e4SLinus Torvalds } else { 42401da177e4SLinus Torvalds if (mptscsih_is_phys_disk(hd->ioc, ii) == 1) { 42411da177e4SLinus Torvalds dnegoprintk(("writeSDP1: id=%d SCSICFG_USE_NVRAM\n", id)); 42421da177e4SLinus Torvalds mptscsih_writeSDP1(hd, 0, ii, MPT_SCSICFG_USE_NVRAM); 42431da177e4SLinus Torvalds } 42441da177e4SLinus Torvalds } 42451da177e4SLinus Torvalds } 42461da177e4SLinus Torvalds return; 42471da177e4SLinus Torvalds } 42481da177e4SLinus Torvalds 42491da177e4SLinus Torvalds 42501da177e4SLinus Torvalds 42511da177e4SLinus Torvalds #define MPT_GET_NVRAM_VALS 0x01 42521da177e4SLinus Torvalds #define MPT_UPDATE_MAX 0x02 42531da177e4SLinus Torvalds #define MPT_SET_MAX 0x04 42541da177e4SLinus Torvalds #define MPT_SET_MIN 0x08 42551da177e4SLinus Torvalds #define MPT_FALLBACK 0x10 42561da177e4SLinus Torvalds #define MPT_SAVE 0x20 42571da177e4SLinus Torvalds 42581da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 42591da177e4SLinus Torvalds /** 42601da177e4SLinus Torvalds * mptscsih_doDv - Perform domain validation to a target. 42611da177e4SLinus Torvalds * @hd: Pointer to MPT_SCSI_HOST structure. 42621da177e4SLinus Torvalds * @portnum: IOC port number. 42631da177e4SLinus Torvalds * @target: Physical ID of this target 42641da177e4SLinus Torvalds * 42651da177e4SLinus Torvalds * Uses the ISR, but with special processing. 42661da177e4SLinus Torvalds * MUST be single-threaded. 42671da177e4SLinus Torvalds * Test will exit if target is at async & narrow. 42681da177e4SLinus Torvalds * 42691da177e4SLinus Torvalds * Return: None. 42701da177e4SLinus Torvalds */ 42711da177e4SLinus Torvalds static int 42721da177e4SLinus Torvalds mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id) 42731da177e4SLinus Torvalds { 42741da177e4SLinus Torvalds MPT_ADAPTER *ioc = hd->ioc; 42751da177e4SLinus Torvalds VirtDevice *pTarget; 42761da177e4SLinus Torvalds SCSIDevicePage1_t *pcfg1Data; 42771da177e4SLinus Torvalds SCSIDevicePage0_t *pcfg0Data; 42781da177e4SLinus Torvalds u8 *pbuf1; 42791da177e4SLinus Torvalds u8 *pbuf2; 42801da177e4SLinus Torvalds u8 *pDvBuf; 42811da177e4SLinus Torvalds dma_addr_t dvbuf_dma = -1; 42821da177e4SLinus Torvalds dma_addr_t buf1_dma = -1; 42831da177e4SLinus Torvalds dma_addr_t buf2_dma = -1; 42841da177e4SLinus Torvalds dma_addr_t cfg1_dma_addr = -1; 42851da177e4SLinus Torvalds dma_addr_t cfg0_dma_addr = -1; 42861da177e4SLinus Torvalds ConfigPageHeader_t header1; 42871da177e4SLinus Torvalds ConfigPageHeader_t header0; 42881da177e4SLinus Torvalds DVPARAMETERS dv; 42891da177e4SLinus Torvalds INTERNAL_CMD iocmd; 42901da177e4SLinus Torvalds CONFIGPARMS cfg; 42911da177e4SLinus Torvalds int dv_alloc = 0; 42921da177e4SLinus Torvalds int rc, sz = 0; 42931da177e4SLinus Torvalds int bufsize = 0; 42941da177e4SLinus Torvalds int dataBufSize = 0; 42951da177e4SLinus Torvalds int echoBufSize = 0; 42961da177e4SLinus Torvalds int notDone; 42971da177e4SLinus Torvalds int patt; 42981da177e4SLinus Torvalds int repeat; 42991da177e4SLinus Torvalds int retcode = 0; 43001da177e4SLinus Torvalds int nfactor = MPT_ULTRA320; 43011da177e4SLinus Torvalds char firstPass = 1; 43021da177e4SLinus Torvalds char doFallback = 0; 43031da177e4SLinus Torvalds char readPage0; 43041da177e4SLinus Torvalds char bus, lun; 43051da177e4SLinus Torvalds char inq0 = 0; 43061da177e4SLinus Torvalds 43071da177e4SLinus Torvalds if (ioc->spi_data.sdp1length == 0) 43081da177e4SLinus Torvalds return 0; 43091da177e4SLinus Torvalds 43101da177e4SLinus Torvalds if (ioc->spi_data.sdp0length == 0) 43111da177e4SLinus Torvalds return 0; 43121da177e4SLinus Torvalds 43131da177e4SLinus Torvalds /* If multiple buses are used, require that the initiator 43141da177e4SLinus Torvalds * id be the same on all buses. 43151da177e4SLinus Torvalds */ 43161da177e4SLinus Torvalds if (id == ioc->pfacts[0].PortSCSIID) 43171da177e4SLinus Torvalds return 0; 43181da177e4SLinus Torvalds 43191da177e4SLinus Torvalds lun = 0; 43201da177e4SLinus Torvalds bus = (u8) bus_number; 43211da177e4SLinus Torvalds ddvtprintk((MYIOC_s_NOTE_FMT 43221da177e4SLinus Torvalds "DV started: bus=%d, id=%d dv @ %p\n", 43231da177e4SLinus Torvalds ioc->name, bus, id, &dv)); 43241da177e4SLinus Torvalds 43251da177e4SLinus Torvalds /* Prep DV structure 43261da177e4SLinus Torvalds */ 43271da177e4SLinus Torvalds memset (&dv, 0, sizeof(DVPARAMETERS)); 43281da177e4SLinus Torvalds dv.id = id; 43291da177e4SLinus Torvalds 43301da177e4SLinus Torvalds /* Populate tmax with the current maximum 43311da177e4SLinus Torvalds * transfer parameters for this target. 43321da177e4SLinus Torvalds * Exit if narrow and async. 43331da177e4SLinus Torvalds */ 43341da177e4SLinus Torvalds dv.cmd = MPT_GET_NVRAM_VALS; 43351da177e4SLinus Torvalds mptscsih_dv_parms(hd, &dv, NULL); 43361da177e4SLinus Torvalds 43371da177e4SLinus Torvalds /* Prep SCSI IO structure 43381da177e4SLinus Torvalds */ 43391da177e4SLinus Torvalds iocmd.id = id; 43401da177e4SLinus Torvalds iocmd.bus = bus; 43411da177e4SLinus Torvalds iocmd.lun = lun; 43421da177e4SLinus Torvalds iocmd.flags = 0; 43431da177e4SLinus Torvalds iocmd.physDiskNum = -1; 43441da177e4SLinus Torvalds iocmd.rsvd = iocmd.rsvd2 = 0; 43451da177e4SLinus Torvalds 43461da177e4SLinus Torvalds pTarget = hd->Targets[id]; 43471da177e4SLinus Torvalds 43481da177e4SLinus Torvalds /* Use tagged commands if possible. 43491da177e4SLinus Torvalds */ 43501da177e4SLinus Torvalds if (pTarget) { 43511da177e4SLinus Torvalds if (pTarget->tflags & MPT_TARGET_FLAGS_Q_YES) 43521da177e4SLinus Torvalds iocmd.flags |= MPT_ICFLAG_TAGGED_CMD; 43531da177e4SLinus Torvalds else { 43541da177e4SLinus Torvalds if (hd->ioc->facts.FWVersion.Word < 0x01000600) 43551da177e4SLinus Torvalds return 0; 43561da177e4SLinus Torvalds 43571da177e4SLinus Torvalds if ((hd->ioc->facts.FWVersion.Word >= 0x01010000) && 43581da177e4SLinus Torvalds (hd->ioc->facts.FWVersion.Word < 0x01010B00)) 43591da177e4SLinus Torvalds return 0; 43601da177e4SLinus Torvalds } 43611da177e4SLinus Torvalds } 43621da177e4SLinus Torvalds 43631da177e4SLinus Torvalds /* Prep cfg structure 43641da177e4SLinus Torvalds */ 43651da177e4SLinus Torvalds cfg.pageAddr = (bus<<8) | id; 43661da177e4SLinus Torvalds cfg.hdr = NULL; 43671da177e4SLinus Torvalds 43681da177e4SLinus Torvalds /* Prep SDP0 header 43691da177e4SLinus Torvalds */ 43701da177e4SLinus Torvalds header0.PageVersion = ioc->spi_data.sdp0version; 43711da177e4SLinus Torvalds header0.PageLength = ioc->spi_data.sdp0length; 43721da177e4SLinus Torvalds header0.PageNumber = 0; 43731da177e4SLinus Torvalds header0.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; 43741da177e4SLinus Torvalds 43751da177e4SLinus Torvalds /* Prep SDP1 header 43761da177e4SLinus Torvalds */ 43771da177e4SLinus Torvalds header1.PageVersion = ioc->spi_data.sdp1version; 43781da177e4SLinus Torvalds header1.PageLength = ioc->spi_data.sdp1length; 43791da177e4SLinus Torvalds header1.PageNumber = 1; 43801da177e4SLinus Torvalds header1.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; 43811da177e4SLinus Torvalds 43821da177e4SLinus Torvalds if (header0.PageLength & 1) 43831da177e4SLinus Torvalds dv_alloc = (header0.PageLength * 4) + 4; 43841da177e4SLinus Torvalds 43851da177e4SLinus Torvalds dv_alloc += (2048 + (header1.PageLength * 4)); 43861da177e4SLinus Torvalds 43871da177e4SLinus Torvalds pDvBuf = pci_alloc_consistent(ioc->pcidev, dv_alloc, &dvbuf_dma); 43881da177e4SLinus Torvalds if (pDvBuf == NULL) 43891da177e4SLinus Torvalds return 0; 43901da177e4SLinus Torvalds 43911da177e4SLinus Torvalds sz = 0; 43921da177e4SLinus Torvalds pbuf1 = (u8 *)pDvBuf; 43931da177e4SLinus Torvalds buf1_dma = dvbuf_dma; 43941da177e4SLinus Torvalds sz +=1024; 43951da177e4SLinus Torvalds 43961da177e4SLinus Torvalds pbuf2 = (u8 *) (pDvBuf + sz); 43971da177e4SLinus Torvalds buf2_dma = dvbuf_dma + sz; 43981da177e4SLinus Torvalds sz +=1024; 43991da177e4SLinus Torvalds 44001da177e4SLinus Torvalds pcfg0Data = (SCSIDevicePage0_t *) (pDvBuf + sz); 44011da177e4SLinus Torvalds cfg0_dma_addr = dvbuf_dma + sz; 44021da177e4SLinus Torvalds sz += header0.PageLength * 4; 44031da177e4SLinus Torvalds 44041da177e4SLinus Torvalds /* 8-byte alignment 44051da177e4SLinus Torvalds */ 44061da177e4SLinus Torvalds if (header0.PageLength & 1) 44071da177e4SLinus Torvalds sz += 4; 44081da177e4SLinus Torvalds 44091da177e4SLinus Torvalds pcfg1Data = (SCSIDevicePage1_t *) (pDvBuf + sz); 44101da177e4SLinus Torvalds cfg1_dma_addr = dvbuf_dma + sz; 44111da177e4SLinus Torvalds 44121da177e4SLinus Torvalds /* Skip this ID? Set cfg.hdr to force config page write 44131da177e4SLinus Torvalds */ 44141da177e4SLinus Torvalds { 44151da177e4SLinus Torvalds ScsiCfgData *pspi_data = &hd->ioc->spi_data; 44161da177e4SLinus Torvalds if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) { 44171da177e4SLinus Torvalds /* Set the factor from nvram */ 44181da177e4SLinus Torvalds nfactor = (pspi_data->nvram[id] & MPT_NVRAM_SYNC_MASK) >> 8; 44191da177e4SLinus Torvalds if (nfactor < pspi_data->minSyncFactor ) 44201da177e4SLinus Torvalds nfactor = pspi_data->minSyncFactor; 44211da177e4SLinus Torvalds 44221da177e4SLinus Torvalds if (!(pspi_data->nvram[id] & MPT_NVRAM_ID_SCAN_ENABLE) || 44231da177e4SLinus Torvalds (pspi_data->PortFlags == MPI_SCSIPORTPAGE2_PORT_FLAGS_OFF_DV) ) { 44241da177e4SLinus Torvalds 44251da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT "DV Skipped: bus, id, lun (%d, %d, %d)\n", 44261da177e4SLinus Torvalds ioc->name, bus, id, lun)); 44271da177e4SLinus Torvalds 44281da177e4SLinus Torvalds dv.cmd = MPT_SET_MAX; 44291da177e4SLinus Torvalds mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data); 44301da177e4SLinus Torvalds cfg.hdr = &header1; 44311da177e4SLinus Torvalds 44321da177e4SLinus Torvalds /* Save the final negotiated settings to 44331da177e4SLinus Torvalds * SCSI device page 1. 44341da177e4SLinus Torvalds */ 44351da177e4SLinus Torvalds cfg.physAddr = cfg1_dma_addr; 44361da177e4SLinus Torvalds cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 44371da177e4SLinus Torvalds cfg.dir = 1; 44381da177e4SLinus Torvalds mpt_config(hd->ioc, &cfg); 44391da177e4SLinus Torvalds goto target_done; 44401da177e4SLinus Torvalds } 44411da177e4SLinus Torvalds } 44421da177e4SLinus Torvalds } 44431da177e4SLinus Torvalds 44441da177e4SLinus Torvalds /* Finish iocmd inititialization - hidden or visible disk? */ 44451da177e4SLinus Torvalds if (ioc->spi_data.pIocPg3) { 44461da177e4SLinus Torvalds /* Search IOC page 3 for matching id 44471da177e4SLinus Torvalds */ 44481da177e4SLinus Torvalds Ioc3PhysDisk_t *pPDisk = ioc->spi_data.pIocPg3->PhysDisk; 44491da177e4SLinus Torvalds int numPDisk = ioc->spi_data.pIocPg3->NumPhysDisks; 44501da177e4SLinus Torvalds 44511da177e4SLinus Torvalds while (numPDisk) { 44521da177e4SLinus Torvalds if (pPDisk->PhysDiskID == id) { 44531da177e4SLinus Torvalds /* match */ 44541da177e4SLinus Torvalds iocmd.flags |= MPT_ICFLAG_PHYS_DISK; 44551da177e4SLinus Torvalds iocmd.physDiskNum = pPDisk->PhysDiskNum; 44561da177e4SLinus Torvalds 44571da177e4SLinus Torvalds /* Quiesce the IM 44581da177e4SLinus Torvalds */ 44591da177e4SLinus Torvalds if (mptscsih_do_raid(hd, MPI_RAID_ACTION_QUIESCE_PHYS_IO, &iocmd) < 0) { 44601da177e4SLinus Torvalds ddvprintk((MYIOC_s_ERR_FMT "RAID Queisce FAILED!\n", ioc->name)); 44611da177e4SLinus Torvalds goto target_done; 44621da177e4SLinus Torvalds } 44631da177e4SLinus Torvalds break; 44641da177e4SLinus Torvalds } 44651da177e4SLinus Torvalds pPDisk++; 44661da177e4SLinus Torvalds numPDisk--; 44671da177e4SLinus Torvalds } 44681da177e4SLinus Torvalds } 44691da177e4SLinus Torvalds 44701da177e4SLinus Torvalds /* RAID Volume ID's may double for a physical device. If RAID but 44711da177e4SLinus Torvalds * not a physical ID as well, skip DV. 44721da177e4SLinus Torvalds */ 44731da177e4SLinus Torvalds if ((hd->ioc->spi_data.isRaid & (1 << id)) && !(iocmd.flags & MPT_ICFLAG_PHYS_DISK)) 44741da177e4SLinus Torvalds goto target_done; 44751da177e4SLinus Torvalds 44761da177e4SLinus Torvalds 44771da177e4SLinus Torvalds /* Basic Test. 44781da177e4SLinus Torvalds * Async & Narrow - Inquiry 44791da177e4SLinus Torvalds * Async & Narrow - Inquiry 44801da177e4SLinus Torvalds * Maximum transfer rate - Inquiry 44811da177e4SLinus Torvalds * Compare buffers: 44821da177e4SLinus Torvalds * If compare, test complete. 44831da177e4SLinus Torvalds * If miscompare and first pass, repeat 44841da177e4SLinus Torvalds * If miscompare and not first pass, fall back and repeat 44851da177e4SLinus Torvalds */ 44861da177e4SLinus Torvalds hd->pLocal = NULL; 44871da177e4SLinus Torvalds readPage0 = 0; 44881da177e4SLinus Torvalds sz = SCSI_MAX_INQUIRY_BYTES; 44891da177e4SLinus Torvalds rc = MPT_SCANDV_GOOD; 44901da177e4SLinus Torvalds while (1) { 44911da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT "DV: Start Basic test on id=%d\n", ioc->name, id)); 44921da177e4SLinus Torvalds retcode = 0; 44931da177e4SLinus Torvalds dv.cmd = MPT_SET_MIN; 44941da177e4SLinus Torvalds mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data); 44951da177e4SLinus Torvalds 44961da177e4SLinus Torvalds cfg.hdr = &header1; 44971da177e4SLinus Torvalds cfg.physAddr = cfg1_dma_addr; 44981da177e4SLinus Torvalds cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 44991da177e4SLinus Torvalds cfg.dir = 1; 45001da177e4SLinus Torvalds if (mpt_config(hd->ioc, &cfg) != 0) 45011da177e4SLinus Torvalds goto target_done; 45021da177e4SLinus Torvalds 45031da177e4SLinus Torvalds /* Wide - narrow - wide workaround case 45041da177e4SLinus Torvalds */ 45051da177e4SLinus Torvalds if ((rc == MPT_SCANDV_ISSUE_SENSE) && dv.max.width) { 45061da177e4SLinus Torvalds /* Send an untagged command to reset disk Qs corrupted 45071da177e4SLinus Torvalds * when a parity error occurs on a Request Sense. 45081da177e4SLinus Torvalds */ 45091da177e4SLinus Torvalds if ((hd->ioc->facts.FWVersion.Word >= 0x01000600) || 45101da177e4SLinus Torvalds ((hd->ioc->facts.FWVersion.Word >= 0x01010000) && 45111da177e4SLinus Torvalds (hd->ioc->facts.FWVersion.Word < 0x01010B00)) ) { 45121da177e4SLinus Torvalds 45131da177e4SLinus Torvalds iocmd.cmd = REQUEST_SENSE; 45141da177e4SLinus Torvalds iocmd.data_dma = buf1_dma; 45151da177e4SLinus Torvalds iocmd.data = pbuf1; 45161da177e4SLinus Torvalds iocmd.size = 0x12; 45171da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 45181da177e4SLinus Torvalds goto target_done; 45191da177e4SLinus Torvalds else { 45201da177e4SLinus Torvalds if (hd->pLocal == NULL) 45211da177e4SLinus Torvalds goto target_done; 45221da177e4SLinus Torvalds rc = hd->pLocal->completion; 45231da177e4SLinus Torvalds if ((rc == MPT_SCANDV_GOOD) || (rc == MPT_SCANDV_SENSE)) { 45241da177e4SLinus Torvalds dv.max.width = 0; 45251da177e4SLinus Torvalds doFallback = 0; 45261da177e4SLinus Torvalds } else 45271da177e4SLinus Torvalds goto target_done; 45281da177e4SLinus Torvalds } 45291da177e4SLinus Torvalds } else 45301da177e4SLinus Torvalds goto target_done; 45311da177e4SLinus Torvalds } 45321da177e4SLinus Torvalds 45331da177e4SLinus Torvalds iocmd.cmd = INQUIRY; 45341da177e4SLinus Torvalds iocmd.data_dma = buf1_dma; 45351da177e4SLinus Torvalds iocmd.data = pbuf1; 45361da177e4SLinus Torvalds iocmd.size = sz; 45371da177e4SLinus Torvalds memset(pbuf1, 0x00, sz); 45381da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 45391da177e4SLinus Torvalds goto target_done; 45401da177e4SLinus Torvalds else { 45411da177e4SLinus Torvalds if (hd->pLocal == NULL) 45421da177e4SLinus Torvalds goto target_done; 45431da177e4SLinus Torvalds rc = hd->pLocal->completion; 45441da177e4SLinus Torvalds if (rc == MPT_SCANDV_GOOD) { 45451da177e4SLinus Torvalds if (hd->pLocal->scsiStatus == SAM_STAT_BUSY) { 45461da177e4SLinus Torvalds if ((iocmd.flags & MPT_ICFLAG_TAGGED_CMD) == 0) 45471da177e4SLinus Torvalds retcode = 1; 45481da177e4SLinus Torvalds else 45491da177e4SLinus Torvalds retcode = 0; 45501da177e4SLinus Torvalds 45511da177e4SLinus Torvalds goto target_done; 45521da177e4SLinus Torvalds } 45531da177e4SLinus Torvalds } else if (rc == MPT_SCANDV_SENSE) { 45541da177e4SLinus Torvalds ; 45551da177e4SLinus Torvalds } else { 45561da177e4SLinus Torvalds /* If first command doesn't complete 45571da177e4SLinus Torvalds * with a good status or with a check condition, 45581da177e4SLinus Torvalds * exit. 45591da177e4SLinus Torvalds */ 45601da177e4SLinus Torvalds goto target_done; 45611da177e4SLinus Torvalds } 45621da177e4SLinus Torvalds } 45631da177e4SLinus Torvalds 45641da177e4SLinus Torvalds /* Reset the size for disks 45651da177e4SLinus Torvalds */ 45661da177e4SLinus Torvalds inq0 = (*pbuf1) & 0x1F; 45671da177e4SLinus Torvalds if ((inq0 == 0) && pTarget && !pTarget->raidVolume) { 45681da177e4SLinus Torvalds sz = 0x40; 45691da177e4SLinus Torvalds iocmd.size = sz; 45701da177e4SLinus Torvalds } 45711da177e4SLinus Torvalds 45721da177e4SLinus Torvalds /* Another GEM workaround. Check peripheral device type, 45731da177e4SLinus Torvalds * if PROCESSOR, quit DV. 45741da177e4SLinus Torvalds */ 45751da177e4SLinus Torvalds if (inq0 == TYPE_PROCESSOR) { 45761da177e4SLinus Torvalds mptscsih_initTarget(hd, 45771da177e4SLinus Torvalds bus, 45781da177e4SLinus Torvalds id, 45791da177e4SLinus Torvalds lun, 45801da177e4SLinus Torvalds pbuf1, 45811da177e4SLinus Torvalds sz); 45821da177e4SLinus Torvalds goto target_done; 45831da177e4SLinus Torvalds } 45841da177e4SLinus Torvalds 45851da177e4SLinus Torvalds if (inq0 > 0x08) 45861da177e4SLinus Torvalds goto target_done; 45871da177e4SLinus Torvalds 45881da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 45891da177e4SLinus Torvalds goto target_done; 45901da177e4SLinus Torvalds 45911da177e4SLinus Torvalds if (sz == 0x40) { 45921da177e4SLinus Torvalds if ((pTarget->maxWidth == 1) && (pTarget->maxOffset) && (nfactor < 0x0A) 45931da177e4SLinus Torvalds && (pTarget->minSyncFactor > 0x09)) { 45941da177e4SLinus Torvalds if ((pbuf1[56] & 0x04) == 0) 45951da177e4SLinus Torvalds ; 45961da177e4SLinus Torvalds else if ((pbuf1[56] & 0x01) == 1) { 45971da177e4SLinus Torvalds pTarget->minSyncFactor = 45981da177e4SLinus Torvalds nfactor > MPT_ULTRA320 ? nfactor : MPT_ULTRA320; 45991da177e4SLinus Torvalds } else { 46001da177e4SLinus Torvalds pTarget->minSyncFactor = 46011da177e4SLinus Torvalds nfactor > MPT_ULTRA160 ? nfactor : MPT_ULTRA160; 46021da177e4SLinus Torvalds } 46031da177e4SLinus Torvalds 46041da177e4SLinus Torvalds dv.max.factor = pTarget->minSyncFactor; 46051da177e4SLinus Torvalds 46061da177e4SLinus Torvalds if ((pbuf1[56] & 0x02) == 0) { 46071da177e4SLinus Torvalds pTarget->negoFlags |= MPT_TARGET_NO_NEGO_QAS; 46081da177e4SLinus Torvalds hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS; 46091da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT 46101da177e4SLinus Torvalds "DV: Start Basic noQas on id=%d due to pbuf1[56]=%x\n", 46111da177e4SLinus Torvalds ioc->name, id, pbuf1[56])); 46121da177e4SLinus Torvalds } 46131da177e4SLinus Torvalds } 46141da177e4SLinus Torvalds } 46151da177e4SLinus Torvalds 46161da177e4SLinus Torvalds if (doFallback) 46171da177e4SLinus Torvalds dv.cmd = MPT_FALLBACK; 46181da177e4SLinus Torvalds else 46191da177e4SLinus Torvalds dv.cmd = MPT_SET_MAX; 46201da177e4SLinus Torvalds 46211da177e4SLinus Torvalds mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data); 46221da177e4SLinus Torvalds if (mpt_config(hd->ioc, &cfg) != 0) 46231da177e4SLinus Torvalds goto target_done; 46241da177e4SLinus Torvalds 46251da177e4SLinus Torvalds if ((!dv.now.width) && (!dv.now.offset)) 46261da177e4SLinus Torvalds goto target_done; 46271da177e4SLinus Torvalds 46281da177e4SLinus Torvalds iocmd.cmd = INQUIRY; 46291da177e4SLinus Torvalds iocmd.data_dma = buf2_dma; 46301da177e4SLinus Torvalds iocmd.data = pbuf2; 46311da177e4SLinus Torvalds iocmd.size = sz; 46321da177e4SLinus Torvalds memset(pbuf2, 0x00, sz); 46331da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 46341da177e4SLinus Torvalds goto target_done; 46351da177e4SLinus Torvalds else if (hd->pLocal == NULL) 46361da177e4SLinus Torvalds goto target_done; 46371da177e4SLinus Torvalds else { 46381da177e4SLinus Torvalds /* Save the return code. 46391da177e4SLinus Torvalds * If this is the first pass, 46401da177e4SLinus Torvalds * read SCSI Device Page 0 46411da177e4SLinus Torvalds * and update the target max parameters. 46421da177e4SLinus Torvalds */ 46431da177e4SLinus Torvalds rc = hd->pLocal->completion; 46441da177e4SLinus Torvalds doFallback = 0; 46451da177e4SLinus Torvalds if (rc == MPT_SCANDV_GOOD) { 46461da177e4SLinus Torvalds if (!readPage0) { 46471da177e4SLinus Torvalds u32 sdp0_info; 46481da177e4SLinus Torvalds u32 sdp0_nego; 46491da177e4SLinus Torvalds 46501da177e4SLinus Torvalds cfg.hdr = &header0; 46511da177e4SLinus Torvalds cfg.physAddr = cfg0_dma_addr; 46521da177e4SLinus Torvalds cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 46531da177e4SLinus Torvalds cfg.dir = 0; 46541da177e4SLinus Torvalds 46551da177e4SLinus Torvalds if (mpt_config(hd->ioc, &cfg) != 0) 46561da177e4SLinus Torvalds goto target_done; 46571da177e4SLinus Torvalds 46581da177e4SLinus Torvalds sdp0_info = le32_to_cpu(pcfg0Data->Information) & 0x0E; 46591da177e4SLinus Torvalds sdp0_nego = (le32_to_cpu(pcfg0Data->NegotiatedParameters) & 0xFF00 ) >> 8; 46601da177e4SLinus Torvalds 46611da177e4SLinus Torvalds /* Quantum and Fujitsu workarounds. 46621da177e4SLinus Torvalds * Quantum: PPR U320 -> PPR reply with Ultra2 and wide 46631da177e4SLinus Torvalds * Fujitsu: PPR U320 -> Msg Reject and Ultra2 and wide 46641da177e4SLinus Torvalds * Resetart with a request for U160. 46651da177e4SLinus Torvalds */ 46661da177e4SLinus Torvalds if ((dv.now.factor == MPT_ULTRA320) && (sdp0_nego == MPT_ULTRA2)) { 46671da177e4SLinus Torvalds doFallback = 1; 46681da177e4SLinus Torvalds } else { 46691da177e4SLinus Torvalds dv.cmd = MPT_UPDATE_MAX; 46701da177e4SLinus Torvalds mptscsih_dv_parms(hd, &dv, (void *)pcfg0Data); 46711da177e4SLinus Torvalds /* Update the SCSI device page 1 area 46721da177e4SLinus Torvalds */ 46731da177e4SLinus Torvalds pcfg1Data->RequestedParameters = pcfg0Data->NegotiatedParameters; 46741da177e4SLinus Torvalds readPage0 = 1; 46751da177e4SLinus Torvalds } 46761da177e4SLinus Torvalds } 46771da177e4SLinus Torvalds 46781da177e4SLinus Torvalds /* Quantum workaround. Restart this test will the fallback 46791da177e4SLinus Torvalds * flag set. 46801da177e4SLinus Torvalds */ 46811da177e4SLinus Torvalds if (doFallback == 0) { 46821da177e4SLinus Torvalds if (memcmp(pbuf1, pbuf2, sz) != 0) { 46831da177e4SLinus Torvalds if (!firstPass) 46841da177e4SLinus Torvalds doFallback = 1; 46851da177e4SLinus Torvalds } else { 46861da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT 46871da177e4SLinus Torvalds "DV:Inquiry compared id=%d, calling initTarget\n", ioc->name, id)); 46881da177e4SLinus Torvalds hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_DV_NOT_DONE; 46891da177e4SLinus Torvalds mptscsih_initTarget(hd, 46901da177e4SLinus Torvalds bus, 46911da177e4SLinus Torvalds id, 46921da177e4SLinus Torvalds lun, 46931da177e4SLinus Torvalds pbuf1, 46941da177e4SLinus Torvalds sz); 46951da177e4SLinus Torvalds break; /* test complete */ 46961da177e4SLinus Torvalds } 46971da177e4SLinus Torvalds } 46981da177e4SLinus Torvalds 46991da177e4SLinus Torvalds 47001da177e4SLinus Torvalds } else if (rc == MPT_SCANDV_ISSUE_SENSE) 47011da177e4SLinus Torvalds doFallback = 1; /* set fallback flag */ 47021da177e4SLinus Torvalds else if ((rc == MPT_SCANDV_DID_RESET) || 47031da177e4SLinus Torvalds (rc == MPT_SCANDV_SENSE) || 47041da177e4SLinus Torvalds (rc == MPT_SCANDV_FALLBACK)) 47051da177e4SLinus Torvalds doFallback = 1; /* set fallback flag */ 47061da177e4SLinus Torvalds else 47071da177e4SLinus Torvalds goto target_done; 47081da177e4SLinus Torvalds 47091da177e4SLinus Torvalds firstPass = 0; 47101da177e4SLinus Torvalds } 47111da177e4SLinus Torvalds } 47121da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT "DV: Basic test on id=%d completed OK.\n", ioc->name, id)); 47131da177e4SLinus Torvalds 47140d0c7974SMoore, Eric Dean if (ioc->spi_data.mpt_dv == 0) 47151da177e4SLinus Torvalds goto target_done; 47161da177e4SLinus Torvalds 47171da177e4SLinus Torvalds inq0 = (*pbuf1) & 0x1F; 47181da177e4SLinus Torvalds 47191da177e4SLinus Torvalds /* Continue only for disks 47201da177e4SLinus Torvalds */ 47211da177e4SLinus Torvalds if (inq0 != 0) 47221da177e4SLinus Torvalds goto target_done; 47231da177e4SLinus Torvalds 47241da177e4SLinus Torvalds if ( ioc->spi_data.PortFlags == MPI_SCSIPORTPAGE2_PORT_FLAGS_BASIC_DV_ONLY ) 47251da177e4SLinus Torvalds goto target_done; 47261da177e4SLinus Torvalds 47271da177e4SLinus Torvalds /* Start the Enhanced Test. 47281da177e4SLinus Torvalds * 0) issue TUR to clear out check conditions 47291da177e4SLinus Torvalds * 1) read capacity of echo (regular) buffer 47301da177e4SLinus Torvalds * 2) reserve device 47311da177e4SLinus Torvalds * 3) do write-read-compare data pattern test 47321da177e4SLinus Torvalds * 4) release 47331da177e4SLinus Torvalds * 5) update nego parms to target struct 47341da177e4SLinus Torvalds */ 47351da177e4SLinus Torvalds cfg.hdr = &header1; 47361da177e4SLinus Torvalds cfg.physAddr = cfg1_dma_addr; 47371da177e4SLinus Torvalds cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 47381da177e4SLinus Torvalds cfg.dir = 1; 47391da177e4SLinus Torvalds 47401da177e4SLinus Torvalds iocmd.cmd = TEST_UNIT_READY; 47411da177e4SLinus Torvalds iocmd.data_dma = -1; 47421da177e4SLinus Torvalds iocmd.data = NULL; 47431da177e4SLinus Torvalds iocmd.size = 0; 47441da177e4SLinus Torvalds notDone = 1; 47451da177e4SLinus Torvalds while (notDone) { 47461da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 47471da177e4SLinus Torvalds goto target_done; 47481da177e4SLinus Torvalds 47491da177e4SLinus Torvalds if (hd->pLocal == NULL) 47501da177e4SLinus Torvalds goto target_done; 47511da177e4SLinus Torvalds 47521da177e4SLinus Torvalds rc = hd->pLocal->completion; 47531da177e4SLinus Torvalds if (rc == MPT_SCANDV_GOOD) 47541da177e4SLinus Torvalds notDone = 0; 47551da177e4SLinus Torvalds else if (rc == MPT_SCANDV_SENSE) { 47561da177e4SLinus Torvalds u8 skey = hd->pLocal->sense[2] & 0x0F; 47571da177e4SLinus Torvalds u8 asc = hd->pLocal->sense[12]; 47581da177e4SLinus Torvalds u8 ascq = hd->pLocal->sense[13]; 47591da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT 47601da177e4SLinus Torvalds "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n", 47611da177e4SLinus Torvalds ioc->name, skey, asc, ascq)); 47621da177e4SLinus Torvalds 47631da177e4SLinus Torvalds if (skey == UNIT_ATTENTION) 47641da177e4SLinus Torvalds notDone++; /* repeat */ 47651da177e4SLinus Torvalds else if ((skey == NOT_READY) && 47661da177e4SLinus Torvalds (asc == 0x04)&&(ascq == 0x01)) { 47671da177e4SLinus Torvalds /* wait then repeat */ 47681da177e4SLinus Torvalds mdelay (2000); 47691da177e4SLinus Torvalds notDone++; 47701da177e4SLinus Torvalds } else if ((skey == NOT_READY) && (asc == 0x3A)) { 47711da177e4SLinus Torvalds /* no medium, try read test anyway */ 47721da177e4SLinus Torvalds notDone = 0; 47731da177e4SLinus Torvalds } else { 47741da177e4SLinus Torvalds /* All other errors are fatal. 47751da177e4SLinus Torvalds */ 47761da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT "DV: fatal error.", 47771da177e4SLinus Torvalds ioc->name)); 47781da177e4SLinus Torvalds goto target_done; 47791da177e4SLinus Torvalds } 47801da177e4SLinus Torvalds } else 47811da177e4SLinus Torvalds goto target_done; 47821da177e4SLinus Torvalds } 47831da177e4SLinus Torvalds 47841da177e4SLinus Torvalds iocmd.cmd = READ_BUFFER; 47851da177e4SLinus Torvalds iocmd.data_dma = buf1_dma; 47861da177e4SLinus Torvalds iocmd.data = pbuf1; 47871da177e4SLinus Torvalds iocmd.size = 4; 47881da177e4SLinus Torvalds iocmd.flags |= MPT_ICFLAG_BUF_CAP; 47891da177e4SLinus Torvalds 47901da177e4SLinus Torvalds dataBufSize = 0; 47911da177e4SLinus Torvalds echoBufSize = 0; 47921da177e4SLinus Torvalds for (patt = 0; patt < 2; patt++) { 47931da177e4SLinus Torvalds if (patt == 0) 47941da177e4SLinus Torvalds iocmd.flags |= MPT_ICFLAG_ECHO; 47951da177e4SLinus Torvalds else 47961da177e4SLinus Torvalds iocmd.flags &= ~MPT_ICFLAG_ECHO; 47971da177e4SLinus Torvalds 47981da177e4SLinus Torvalds notDone = 1; 47991da177e4SLinus Torvalds while (notDone) { 48001da177e4SLinus Torvalds bufsize = 0; 48011da177e4SLinus Torvalds 48021da177e4SLinus Torvalds /* If not ready after 8 trials, 48031da177e4SLinus Torvalds * give up on this device. 48041da177e4SLinus Torvalds */ 48051da177e4SLinus Torvalds if (notDone > 8) 48061da177e4SLinus Torvalds goto target_done; 48071da177e4SLinus Torvalds 48081da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 48091da177e4SLinus Torvalds goto target_done; 48101da177e4SLinus Torvalds else if (hd->pLocal == NULL) 48111da177e4SLinus Torvalds goto target_done; 48121da177e4SLinus Torvalds else { 48131da177e4SLinus Torvalds rc = hd->pLocal->completion; 48141da177e4SLinus Torvalds ddvprintk(("ReadBuffer Comp Code %d", rc)); 48151da177e4SLinus Torvalds ddvprintk((" buff: %0x %0x %0x %0x\n", 48161da177e4SLinus Torvalds pbuf1[0], pbuf1[1], pbuf1[2], pbuf1[3])); 48171da177e4SLinus Torvalds 48181da177e4SLinus Torvalds if (rc == MPT_SCANDV_GOOD) { 48191da177e4SLinus Torvalds notDone = 0; 48201da177e4SLinus Torvalds if (iocmd.flags & MPT_ICFLAG_ECHO) { 48211da177e4SLinus Torvalds bufsize = ((pbuf1[2] & 0x1F) <<8) | pbuf1[3]; 48221da177e4SLinus Torvalds } else { 48231da177e4SLinus Torvalds bufsize = pbuf1[1]<<16 | pbuf1[2]<<8 | pbuf1[3]; 48241da177e4SLinus Torvalds } 48251da177e4SLinus Torvalds } else if (rc == MPT_SCANDV_SENSE) { 48261da177e4SLinus Torvalds u8 skey = hd->pLocal->sense[2] & 0x0F; 48271da177e4SLinus Torvalds u8 asc = hd->pLocal->sense[12]; 48281da177e4SLinus Torvalds u8 ascq = hd->pLocal->sense[13]; 48291da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT 48301da177e4SLinus Torvalds "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n", 48311da177e4SLinus Torvalds ioc->name, skey, asc, ascq)); 48321da177e4SLinus Torvalds if (skey == ILLEGAL_REQUEST) { 48331da177e4SLinus Torvalds notDone = 0; 48341da177e4SLinus Torvalds } else if (skey == UNIT_ATTENTION) { 48351da177e4SLinus Torvalds notDone++; /* repeat */ 48361da177e4SLinus Torvalds } else if ((skey == NOT_READY) && 48371da177e4SLinus Torvalds (asc == 0x04)&&(ascq == 0x01)) { 48381da177e4SLinus Torvalds /* wait then repeat */ 48391da177e4SLinus Torvalds mdelay (2000); 48401da177e4SLinus Torvalds notDone++; 48411da177e4SLinus Torvalds } else { 48421da177e4SLinus Torvalds /* All other errors are fatal. 48431da177e4SLinus Torvalds */ 48441da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT "DV: fatal error.", 48451da177e4SLinus Torvalds ioc->name)); 48461da177e4SLinus Torvalds goto target_done; 48471da177e4SLinus Torvalds } 48481da177e4SLinus Torvalds } else { 48491da177e4SLinus Torvalds /* All other errors are fatal 48501da177e4SLinus Torvalds */ 48511da177e4SLinus Torvalds goto target_done; 48521da177e4SLinus Torvalds } 48531da177e4SLinus Torvalds } 48541da177e4SLinus Torvalds } 48551da177e4SLinus Torvalds 48561da177e4SLinus Torvalds if (iocmd.flags & MPT_ICFLAG_ECHO) 48571da177e4SLinus Torvalds echoBufSize = bufsize; 48581da177e4SLinus Torvalds else 48591da177e4SLinus Torvalds dataBufSize = bufsize; 48601da177e4SLinus Torvalds } 48611da177e4SLinus Torvalds sz = 0; 48621da177e4SLinus Torvalds iocmd.flags &= ~MPT_ICFLAG_BUF_CAP; 48631da177e4SLinus Torvalds 48641da177e4SLinus Torvalds /* Use echo buffers if possible, 48651da177e4SLinus Torvalds * Exit if both buffers are 0. 48661da177e4SLinus Torvalds */ 48671da177e4SLinus Torvalds if (echoBufSize > 0) { 48681da177e4SLinus Torvalds iocmd.flags |= MPT_ICFLAG_ECHO; 48691da177e4SLinus Torvalds if (dataBufSize > 0) 48701da177e4SLinus Torvalds bufsize = min(echoBufSize, dataBufSize); 48711da177e4SLinus Torvalds else 48721da177e4SLinus Torvalds bufsize = echoBufSize; 48731da177e4SLinus Torvalds } else if (dataBufSize == 0) 48741da177e4SLinus Torvalds goto target_done; 48751da177e4SLinus Torvalds 48761da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT "%s Buffer Capacity %d\n", ioc->name, 48771da177e4SLinus Torvalds (iocmd.flags & MPT_ICFLAG_ECHO) ? "Echo" : " ", bufsize)); 48781da177e4SLinus Torvalds 48791da177e4SLinus Torvalds /* Data buffers for write-read-compare test max 1K. 48801da177e4SLinus Torvalds */ 48811da177e4SLinus Torvalds sz = min(bufsize, 1024); 48821da177e4SLinus Torvalds 48831da177e4SLinus Torvalds /* --- loop ---- 48841da177e4SLinus Torvalds * On first pass, always issue a reserve. 48851da177e4SLinus Torvalds * On additional loops, only if a reset has occurred. 48861da177e4SLinus Torvalds * iocmd.flags indicates if echo or regular buffer 48871da177e4SLinus Torvalds */ 48881da177e4SLinus Torvalds for (patt = 0; patt < 4; patt++) { 48891da177e4SLinus Torvalds ddvprintk(("Pattern %d\n", patt)); 48901da177e4SLinus Torvalds if ((iocmd.flags & MPT_ICFLAG_RESERVED) && (iocmd.flags & MPT_ICFLAG_DID_RESET)) { 48911da177e4SLinus Torvalds iocmd.cmd = TEST_UNIT_READY; 48921da177e4SLinus Torvalds iocmd.data_dma = -1; 48931da177e4SLinus Torvalds iocmd.data = NULL; 48941da177e4SLinus Torvalds iocmd.size = 0; 48951da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 48961da177e4SLinus Torvalds goto target_done; 48971da177e4SLinus Torvalds 48981da177e4SLinus Torvalds iocmd.cmd = RELEASE; 48991da177e4SLinus Torvalds iocmd.data_dma = -1; 49001da177e4SLinus Torvalds iocmd.data = NULL; 49011da177e4SLinus Torvalds iocmd.size = 0; 49021da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 49031da177e4SLinus Torvalds goto target_done; 49041da177e4SLinus Torvalds else if (hd->pLocal == NULL) 49051da177e4SLinus Torvalds goto target_done; 49061da177e4SLinus Torvalds else { 49071da177e4SLinus Torvalds rc = hd->pLocal->completion; 49081da177e4SLinus Torvalds ddvprintk(("Release rc %d\n", rc)); 49091da177e4SLinus Torvalds if (rc == MPT_SCANDV_GOOD) 49101da177e4SLinus Torvalds iocmd.flags &= ~MPT_ICFLAG_RESERVED; 49111da177e4SLinus Torvalds else 49121da177e4SLinus Torvalds goto target_done; 49131da177e4SLinus Torvalds } 49141da177e4SLinus Torvalds iocmd.flags &= ~MPT_ICFLAG_RESERVED; 49151da177e4SLinus Torvalds } 49161da177e4SLinus Torvalds iocmd.flags &= ~MPT_ICFLAG_DID_RESET; 49171da177e4SLinus Torvalds 49181da177e4SLinus Torvalds repeat = 5; 49191da177e4SLinus Torvalds while (repeat && (!(iocmd.flags & MPT_ICFLAG_RESERVED))) { 49201da177e4SLinus Torvalds iocmd.cmd = RESERVE; 49211da177e4SLinus Torvalds iocmd.data_dma = -1; 49221da177e4SLinus Torvalds iocmd.data = NULL; 49231da177e4SLinus Torvalds iocmd.size = 0; 49241da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 49251da177e4SLinus Torvalds goto target_done; 49261da177e4SLinus Torvalds else if (hd->pLocal == NULL) 49271da177e4SLinus Torvalds goto target_done; 49281da177e4SLinus Torvalds else { 49291da177e4SLinus Torvalds rc = hd->pLocal->completion; 49301da177e4SLinus Torvalds if (rc == MPT_SCANDV_GOOD) { 49311da177e4SLinus Torvalds iocmd.flags |= MPT_ICFLAG_RESERVED; 49321da177e4SLinus Torvalds } else if (rc == MPT_SCANDV_SENSE) { 49331da177e4SLinus Torvalds /* Wait if coming ready 49341da177e4SLinus Torvalds */ 49351da177e4SLinus Torvalds u8 skey = hd->pLocal->sense[2] & 0x0F; 49361da177e4SLinus Torvalds u8 asc = hd->pLocal->sense[12]; 49371da177e4SLinus Torvalds u8 ascq = hd->pLocal->sense[13]; 49381da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT 49391da177e4SLinus Torvalds "DV: Reserve Failed: ", ioc->name)); 49401da177e4SLinus Torvalds ddvprintk(("SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n", 49411da177e4SLinus Torvalds skey, asc, ascq)); 49421da177e4SLinus Torvalds 49431da177e4SLinus Torvalds if ((skey == NOT_READY) && (asc == 0x04)&& 49441da177e4SLinus Torvalds (ascq == 0x01)) { 49451da177e4SLinus Torvalds /* wait then repeat */ 49461da177e4SLinus Torvalds mdelay (2000); 49471da177e4SLinus Torvalds notDone++; 49481da177e4SLinus Torvalds } else { 49491da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT 49501da177e4SLinus Torvalds "DV: Reserved Failed.", ioc->name)); 49511da177e4SLinus Torvalds goto target_done; 49521da177e4SLinus Torvalds } 49531da177e4SLinus Torvalds } else { 49541da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT "DV: Reserved Failed.", 49551da177e4SLinus Torvalds ioc->name)); 49561da177e4SLinus Torvalds goto target_done; 49571da177e4SLinus Torvalds } 49581da177e4SLinus Torvalds } 49591da177e4SLinus Torvalds } 49601da177e4SLinus Torvalds 49611da177e4SLinus Torvalds mptscsih_fillbuf(pbuf1, sz, patt, 1); 49621da177e4SLinus Torvalds iocmd.cmd = WRITE_BUFFER; 49631da177e4SLinus Torvalds iocmd.data_dma = buf1_dma; 49641da177e4SLinus Torvalds iocmd.data = pbuf1; 49651da177e4SLinus Torvalds iocmd.size = sz; 49661da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 49671da177e4SLinus Torvalds goto target_done; 49681da177e4SLinus Torvalds else if (hd->pLocal == NULL) 49691da177e4SLinus Torvalds goto target_done; 49701da177e4SLinus Torvalds else { 49711da177e4SLinus Torvalds rc = hd->pLocal->completion; 49721da177e4SLinus Torvalds if (rc == MPT_SCANDV_GOOD) 49731da177e4SLinus Torvalds ; /* Issue read buffer */ 49741da177e4SLinus Torvalds else if (rc == MPT_SCANDV_DID_RESET) { 49751da177e4SLinus Torvalds /* If using echo buffers, reset to data buffers. 49761da177e4SLinus Torvalds * Else do Fallback and restart 49771da177e4SLinus Torvalds * this test (re-issue reserve 49781da177e4SLinus Torvalds * because of bus reset). 49791da177e4SLinus Torvalds */ 49801da177e4SLinus Torvalds if ((iocmd.flags & MPT_ICFLAG_ECHO) && (dataBufSize >= bufsize)) { 49811da177e4SLinus Torvalds iocmd.flags &= ~MPT_ICFLAG_ECHO; 49821da177e4SLinus Torvalds } else { 49831da177e4SLinus Torvalds dv.cmd = MPT_FALLBACK; 49841da177e4SLinus Torvalds mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data); 49851da177e4SLinus Torvalds 49861da177e4SLinus Torvalds if (mpt_config(hd->ioc, &cfg) != 0) 49871da177e4SLinus Torvalds goto target_done; 49881da177e4SLinus Torvalds 49891da177e4SLinus Torvalds if ((!dv.now.width) && (!dv.now.offset)) 49901da177e4SLinus Torvalds goto target_done; 49911da177e4SLinus Torvalds } 49921da177e4SLinus Torvalds 49931da177e4SLinus Torvalds iocmd.flags |= MPT_ICFLAG_DID_RESET; 49941da177e4SLinus Torvalds patt = -1; 49951da177e4SLinus Torvalds continue; 49961da177e4SLinus Torvalds } else if (rc == MPT_SCANDV_SENSE) { 49971da177e4SLinus Torvalds /* Restart data test if UA, else quit. 49981da177e4SLinus Torvalds */ 49991da177e4SLinus Torvalds u8 skey = hd->pLocal->sense[2] & 0x0F; 50001da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT 50011da177e4SLinus Torvalds "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n", ioc->name, skey, 50021da177e4SLinus Torvalds hd->pLocal->sense[12], hd->pLocal->sense[13])); 50031da177e4SLinus Torvalds if (skey == UNIT_ATTENTION) { 50041da177e4SLinus Torvalds patt = -1; 50051da177e4SLinus Torvalds continue; 50061da177e4SLinus Torvalds } else if (skey == ILLEGAL_REQUEST) { 50071da177e4SLinus Torvalds if (iocmd.flags & MPT_ICFLAG_ECHO) { 50081da177e4SLinus Torvalds if (dataBufSize >= bufsize) { 50091da177e4SLinus Torvalds iocmd.flags &= ~MPT_ICFLAG_ECHO; 50101da177e4SLinus Torvalds patt = -1; 50111da177e4SLinus Torvalds continue; 50121da177e4SLinus Torvalds } 50131da177e4SLinus Torvalds } 50141da177e4SLinus Torvalds goto target_done; 50151da177e4SLinus Torvalds } 50161da177e4SLinus Torvalds else 50171da177e4SLinus Torvalds goto target_done; 50181da177e4SLinus Torvalds } else { 50191da177e4SLinus Torvalds /* fatal error */ 50201da177e4SLinus Torvalds goto target_done; 50211da177e4SLinus Torvalds } 50221da177e4SLinus Torvalds } 50231da177e4SLinus Torvalds 50241da177e4SLinus Torvalds iocmd.cmd = READ_BUFFER; 50251da177e4SLinus Torvalds iocmd.data_dma = buf2_dma; 50261da177e4SLinus Torvalds iocmd.data = pbuf2; 50271da177e4SLinus Torvalds iocmd.size = sz; 50281da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 50291da177e4SLinus Torvalds goto target_done; 50301da177e4SLinus Torvalds else if (hd->pLocal == NULL) 50311da177e4SLinus Torvalds goto target_done; 50321da177e4SLinus Torvalds else { 50331da177e4SLinus Torvalds rc = hd->pLocal->completion; 50341da177e4SLinus Torvalds if (rc == MPT_SCANDV_GOOD) { 50351da177e4SLinus Torvalds /* If buffers compare, 50361da177e4SLinus Torvalds * go to next pattern, 50371da177e4SLinus Torvalds * else, do a fallback and restart 50381da177e4SLinus Torvalds * data transfer test. 50391da177e4SLinus Torvalds */ 50401da177e4SLinus Torvalds if (memcmp (pbuf1, pbuf2, sz) == 0) { 50411da177e4SLinus Torvalds ; /* goto next pattern */ 50421da177e4SLinus Torvalds } else { 50431da177e4SLinus Torvalds /* Miscompare with Echo buffer, go to data buffer, 50441da177e4SLinus Torvalds * if that buffer exists. 50451da177e4SLinus Torvalds * Miscompare with Data buffer, check first 4 bytes, 50461da177e4SLinus Torvalds * some devices return capacity. Exit in this case. 50471da177e4SLinus Torvalds */ 50481da177e4SLinus Torvalds if (iocmd.flags & MPT_ICFLAG_ECHO) { 50491da177e4SLinus Torvalds if (dataBufSize >= bufsize) 50501da177e4SLinus Torvalds iocmd.flags &= ~MPT_ICFLAG_ECHO; 50511da177e4SLinus Torvalds else 50521da177e4SLinus Torvalds goto target_done; 50531da177e4SLinus Torvalds } else { 50541da177e4SLinus Torvalds if (dataBufSize == (pbuf2[1]<<16 | pbuf2[2]<<8 | pbuf2[3])) { 50551da177e4SLinus Torvalds /* Argh. Device returning wrong data. 50561da177e4SLinus Torvalds * Quit DV for this device. 50571da177e4SLinus Torvalds */ 50581da177e4SLinus Torvalds goto target_done; 50591da177e4SLinus Torvalds } 50601da177e4SLinus Torvalds 50611da177e4SLinus Torvalds /* Had an actual miscompare. Slow down.*/ 50621da177e4SLinus Torvalds dv.cmd = MPT_FALLBACK; 50631da177e4SLinus Torvalds mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data); 50641da177e4SLinus Torvalds 50651da177e4SLinus Torvalds if (mpt_config(hd->ioc, &cfg) != 0) 50661da177e4SLinus Torvalds goto target_done; 50671da177e4SLinus Torvalds 50681da177e4SLinus Torvalds if ((!dv.now.width) && (!dv.now.offset)) 50691da177e4SLinus Torvalds goto target_done; 50701da177e4SLinus Torvalds } 50711da177e4SLinus Torvalds 50721da177e4SLinus Torvalds patt = -1; 50731da177e4SLinus Torvalds continue; 50741da177e4SLinus Torvalds } 50751da177e4SLinus Torvalds } else if (rc == MPT_SCANDV_DID_RESET) { 50761da177e4SLinus Torvalds /* Do Fallback and restart 50771da177e4SLinus Torvalds * this test (re-issue reserve 50781da177e4SLinus Torvalds * because of bus reset). 50791da177e4SLinus Torvalds */ 50801da177e4SLinus Torvalds dv.cmd = MPT_FALLBACK; 50811da177e4SLinus Torvalds mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data); 50821da177e4SLinus Torvalds 50831da177e4SLinus Torvalds if (mpt_config(hd->ioc, &cfg) != 0) 50841da177e4SLinus Torvalds goto target_done; 50851da177e4SLinus Torvalds 50861da177e4SLinus Torvalds if ((!dv.now.width) && (!dv.now.offset)) 50871da177e4SLinus Torvalds goto target_done; 50881da177e4SLinus Torvalds 50891da177e4SLinus Torvalds iocmd.flags |= MPT_ICFLAG_DID_RESET; 50901da177e4SLinus Torvalds patt = -1; 50911da177e4SLinus Torvalds continue; 50921da177e4SLinus Torvalds } else if (rc == MPT_SCANDV_SENSE) { 50931da177e4SLinus Torvalds /* Restart data test if UA, else quit. 50941da177e4SLinus Torvalds */ 50951da177e4SLinus Torvalds u8 skey = hd->pLocal->sense[2] & 0x0F; 50961da177e4SLinus Torvalds ddvprintk((MYIOC_s_INFO_FMT 50971da177e4SLinus Torvalds "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n", ioc->name, skey, 50981da177e4SLinus Torvalds hd->pLocal->sense[12], hd->pLocal->sense[13])); 50991da177e4SLinus Torvalds if (skey == UNIT_ATTENTION) { 51001da177e4SLinus Torvalds patt = -1; 51011da177e4SLinus Torvalds continue; 51021da177e4SLinus Torvalds } 51031da177e4SLinus Torvalds else 51041da177e4SLinus Torvalds goto target_done; 51051da177e4SLinus Torvalds } else { 51061da177e4SLinus Torvalds /* fatal error */ 51071da177e4SLinus Torvalds goto target_done; 51081da177e4SLinus Torvalds } 51091da177e4SLinus Torvalds } 51101da177e4SLinus Torvalds 51111da177e4SLinus Torvalds } /* --- end of patt loop ---- */ 51121da177e4SLinus Torvalds 51131da177e4SLinus Torvalds target_done: 51141da177e4SLinus Torvalds if (iocmd.flags & MPT_ICFLAG_RESERVED) { 51151da177e4SLinus Torvalds iocmd.cmd = RELEASE; 51161da177e4SLinus Torvalds iocmd.data_dma = -1; 51171da177e4SLinus Torvalds iocmd.data = NULL; 51181da177e4SLinus Torvalds iocmd.size = 0; 51191da177e4SLinus Torvalds if (mptscsih_do_cmd(hd, &iocmd) < 0) 51201da177e4SLinus Torvalds printk(MYIOC_s_INFO_FMT "DV: Release failed. id %d", 51211da177e4SLinus Torvalds ioc->name, id); 51221da177e4SLinus Torvalds else if (hd->pLocal) { 51231da177e4SLinus Torvalds if (hd->pLocal->completion == MPT_SCANDV_GOOD) 51241da177e4SLinus Torvalds iocmd.flags &= ~MPT_ICFLAG_RESERVED; 51251da177e4SLinus Torvalds } else { 51261da177e4SLinus Torvalds printk(MYIOC_s_INFO_FMT "DV: Release failed. id %d", 51271da177e4SLinus Torvalds ioc->name, id); 51281da177e4SLinus Torvalds } 51291da177e4SLinus Torvalds } 51301da177e4SLinus Torvalds 51311da177e4SLinus Torvalds 51321da177e4SLinus Torvalds /* Set if cfg1_dma_addr contents is valid 51331da177e4SLinus Torvalds */ 51341da177e4SLinus Torvalds if ((cfg.hdr != NULL) && (retcode == 0)){ 51351da177e4SLinus Torvalds /* If disk, not U320, disable QAS 51361da177e4SLinus Torvalds */ 51371da177e4SLinus Torvalds if ((inq0 == 0) && (dv.now.factor > MPT_ULTRA320)) { 51381da177e4SLinus Torvalds hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS; 51391da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT 51401da177e4SLinus Torvalds "noQas set due to id=%d has factor=%x\n", ioc->name, id, dv.now.factor)); 51411da177e4SLinus Torvalds } 51421da177e4SLinus Torvalds 51431da177e4SLinus Torvalds dv.cmd = MPT_SAVE; 51441da177e4SLinus Torvalds mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data); 51451da177e4SLinus Torvalds 51461da177e4SLinus Torvalds /* Double writes to SDP1 can cause problems, 51471da177e4SLinus Torvalds * skip save of the final negotiated settings to 51481da177e4SLinus Torvalds * SCSI device page 1. 51491da177e4SLinus Torvalds * 51501da177e4SLinus Torvalds cfg.hdr = &header1; 51511da177e4SLinus Torvalds cfg.physAddr = cfg1_dma_addr; 51521da177e4SLinus Torvalds cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 51531da177e4SLinus Torvalds cfg.dir = 1; 51541da177e4SLinus Torvalds mpt_config(hd->ioc, &cfg); 51551da177e4SLinus Torvalds */ 51561da177e4SLinus Torvalds } 51571da177e4SLinus Torvalds 51581da177e4SLinus Torvalds /* If this is a RAID Passthrough, enable internal IOs 51591da177e4SLinus Torvalds */ 51601da177e4SLinus Torvalds if (iocmd.flags & MPT_ICFLAG_PHYS_DISK) { 51611da177e4SLinus Torvalds if (mptscsih_do_raid(hd, MPI_RAID_ACTION_ENABLE_PHYS_IO, &iocmd) < 0) 51621da177e4SLinus Torvalds ddvprintk((MYIOC_s_ERR_FMT "RAID Enable FAILED!\n", ioc->name)); 51631da177e4SLinus Torvalds } 51641da177e4SLinus Torvalds 51651da177e4SLinus Torvalds /* Done with the DV scan of the current target 51661da177e4SLinus Torvalds */ 51671da177e4SLinus Torvalds if (pDvBuf) 51681da177e4SLinus Torvalds pci_free_consistent(ioc->pcidev, dv_alloc, pDvBuf, dvbuf_dma); 51691da177e4SLinus Torvalds 51701da177e4SLinus Torvalds ddvtprintk((MYIOC_s_INFO_FMT "DV Done id=%d\n", 51711da177e4SLinus Torvalds ioc->name, id)); 51721da177e4SLinus Torvalds 51731da177e4SLinus Torvalds return retcode; 51741da177e4SLinus Torvalds } 51751da177e4SLinus Torvalds 51761da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 51771da177e4SLinus Torvalds /* mptscsih_dv_parms - perform a variety of operations on the 51781da177e4SLinus Torvalds * parameters used for negotiation. 51791da177e4SLinus Torvalds * @hd: Pointer to a SCSI host. 51801da177e4SLinus Torvalds * @dv: Pointer to a structure that contains the maximum and current 51811da177e4SLinus Torvalds * negotiated parameters. 51821da177e4SLinus Torvalds */ 51831da177e4SLinus Torvalds static void 51841da177e4SLinus Torvalds mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage) 51851da177e4SLinus Torvalds { 51861da177e4SLinus Torvalds VirtDevice *pTarget; 51871da177e4SLinus Torvalds SCSIDevicePage0_t *pPage0; 51881da177e4SLinus Torvalds SCSIDevicePage1_t *pPage1; 51891da177e4SLinus Torvalds int val = 0, data, configuration; 51901da177e4SLinus Torvalds u8 width = 0; 51911da177e4SLinus Torvalds u8 offset = 0; 51921da177e4SLinus Torvalds u8 factor = 0; 51931da177e4SLinus Torvalds u8 negoFlags = 0; 51941da177e4SLinus Torvalds u8 cmd = dv->cmd; 51951da177e4SLinus Torvalds u8 id = dv->id; 51961da177e4SLinus Torvalds 51971da177e4SLinus Torvalds switch (cmd) { 51981da177e4SLinus Torvalds case MPT_GET_NVRAM_VALS: 51991da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT "Getting NVRAM: ", 52001da177e4SLinus Torvalds hd->ioc->name)); 52011da177e4SLinus Torvalds /* Get the NVRAM values and save in tmax 52021da177e4SLinus Torvalds * If not an LVD bus, the adapter minSyncFactor has been 52031da177e4SLinus Torvalds * already throttled back. 52041da177e4SLinus Torvalds */ 52051da177e4SLinus Torvalds if ((hd->Targets)&&((pTarget = hd->Targets[(int)id]) != NULL) && !pTarget->raidVolume) { 52061da177e4SLinus Torvalds width = pTarget->maxWidth; 52071da177e4SLinus Torvalds offset = pTarget->maxOffset; 52081da177e4SLinus Torvalds factor = pTarget->minSyncFactor; 52091da177e4SLinus Torvalds negoFlags = pTarget->negoFlags; 52101da177e4SLinus Torvalds } else { 52111da177e4SLinus Torvalds if (hd->ioc->spi_data.nvram && (hd->ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) { 52121da177e4SLinus Torvalds data = hd->ioc->spi_data.nvram[id]; 52131da177e4SLinus Torvalds width = data & MPT_NVRAM_WIDE_DISABLE ? 0 : 1; 52141da177e4SLinus Torvalds if ((offset = hd->ioc->spi_data.maxSyncOffset) == 0) 52151da177e4SLinus Torvalds factor = MPT_ASYNC; 52161da177e4SLinus Torvalds else { 52171da177e4SLinus Torvalds factor = (data & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT; 52181da177e4SLinus Torvalds if ((factor == 0) || (factor == MPT_ASYNC)){ 52191da177e4SLinus Torvalds factor = MPT_ASYNC; 52201da177e4SLinus Torvalds offset = 0; 52211da177e4SLinus Torvalds } 52221da177e4SLinus Torvalds } 52231da177e4SLinus Torvalds } else { 52241da177e4SLinus Torvalds width = MPT_NARROW; 52251da177e4SLinus Torvalds offset = 0; 52261da177e4SLinus Torvalds factor = MPT_ASYNC; 52271da177e4SLinus Torvalds } 52281da177e4SLinus Torvalds 52291da177e4SLinus Torvalds /* Set the negotiation flags */ 52301da177e4SLinus Torvalds negoFlags = hd->ioc->spi_data.noQas; 52311da177e4SLinus Torvalds if (!width) 52321da177e4SLinus Torvalds negoFlags |= MPT_TARGET_NO_NEGO_WIDE; 52331da177e4SLinus Torvalds 52341da177e4SLinus Torvalds if (!offset) 52351da177e4SLinus Torvalds negoFlags |= MPT_TARGET_NO_NEGO_SYNC; 52361da177e4SLinus Torvalds } 52371da177e4SLinus Torvalds 52381da177e4SLinus Torvalds /* limit by adapter capabilities */ 52391da177e4SLinus Torvalds width = min(width, hd->ioc->spi_data.maxBusWidth); 52401da177e4SLinus Torvalds offset = min(offset, hd->ioc->spi_data.maxSyncOffset); 52411da177e4SLinus Torvalds factor = max(factor, hd->ioc->spi_data.minSyncFactor); 52421da177e4SLinus Torvalds 52431da177e4SLinus Torvalds /* Check Consistency */ 52441da177e4SLinus Torvalds if (offset && (factor < MPT_ULTRA2) && !width) 52451da177e4SLinus Torvalds factor = MPT_ULTRA2; 52461da177e4SLinus Torvalds 52471da177e4SLinus Torvalds dv->max.width = width; 52481da177e4SLinus Torvalds dv->max.offset = offset; 52491da177e4SLinus Torvalds dv->max.factor = factor; 52501da177e4SLinus Torvalds dv->max.flags = negoFlags; 52511da177e4SLinus Torvalds ddvprintk((" id=%d width=%d factor=%x offset=%x flags=%x\n", 52521da177e4SLinus Torvalds id, width, factor, offset, negoFlags)); 52531da177e4SLinus Torvalds break; 52541da177e4SLinus Torvalds 52551da177e4SLinus Torvalds case MPT_UPDATE_MAX: 52561da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT 52571da177e4SLinus Torvalds "Updating with SDP0 Data: ", hd->ioc->name)); 52581da177e4SLinus Torvalds /* Update tmax values with those from Device Page 0.*/ 52591da177e4SLinus Torvalds pPage0 = (SCSIDevicePage0_t *) pPage; 52601da177e4SLinus Torvalds if (pPage0) { 52611da177e4SLinus Torvalds val = cpu_to_le32(pPage0->NegotiatedParameters); 52621da177e4SLinus Torvalds dv->max.width = val & MPI_SCSIDEVPAGE0_NP_WIDE ? 1 : 0; 52631da177e4SLinus Torvalds dv->max.offset = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> 16; 52641da177e4SLinus Torvalds dv->max.factor = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8; 52651da177e4SLinus Torvalds } 52661da177e4SLinus Torvalds 52671da177e4SLinus Torvalds dv->now.width = dv->max.width; 52681da177e4SLinus Torvalds dv->now.offset = dv->max.offset; 52691da177e4SLinus Torvalds dv->now.factor = dv->max.factor; 52701da177e4SLinus Torvalds ddvprintk(("id=%d width=%d factor=%x offset=%x flags=%x\n", 52711da177e4SLinus Torvalds id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags)); 52721da177e4SLinus Torvalds break; 52731da177e4SLinus Torvalds 52741da177e4SLinus Torvalds case MPT_SET_MAX: 52751da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT "Setting Max: ", 52761da177e4SLinus Torvalds hd->ioc->name)); 52771da177e4SLinus Torvalds /* Set current to the max values. Update the config page.*/ 52781da177e4SLinus Torvalds dv->now.width = dv->max.width; 52791da177e4SLinus Torvalds dv->now.offset = dv->max.offset; 52801da177e4SLinus Torvalds dv->now.factor = dv->max.factor; 52811da177e4SLinus Torvalds dv->now.flags = dv->max.flags; 52821da177e4SLinus Torvalds 52831da177e4SLinus Torvalds pPage1 = (SCSIDevicePage1_t *)pPage; 52841da177e4SLinus Torvalds if (pPage1) { 52851da177e4SLinus Torvalds mptscsih_setDevicePage1Flags (dv->now.width, dv->now.factor, 52861da177e4SLinus Torvalds dv->now.offset, &val, &configuration, dv->now.flags); 52871da177e4SLinus Torvalds dnegoprintk(("Setting Max: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n", 52881da177e4SLinus Torvalds id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration)); 52891da177e4SLinus Torvalds pPage1->RequestedParameters = le32_to_cpu(val); 52901da177e4SLinus Torvalds pPage1->Reserved = 0; 52911da177e4SLinus Torvalds pPage1->Configuration = le32_to_cpu(configuration); 52921da177e4SLinus Torvalds } 52931da177e4SLinus Torvalds 52941da177e4SLinus Torvalds ddvprintk(("id=%d width=%d factor=%x offset=%x flags=%x request=%x configuration=%x\n", 52951da177e4SLinus Torvalds id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration)); 52961da177e4SLinus Torvalds break; 52971da177e4SLinus Torvalds 52981da177e4SLinus Torvalds case MPT_SET_MIN: 52991da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT "Setting Min: ", 53001da177e4SLinus Torvalds hd->ioc->name)); 53011da177e4SLinus Torvalds /* Set page to asynchronous and narrow 53021da177e4SLinus Torvalds * Do not update now, breaks fallback routine. */ 53031da177e4SLinus Torvalds width = MPT_NARROW; 53041da177e4SLinus Torvalds offset = 0; 53051da177e4SLinus Torvalds factor = MPT_ASYNC; 53061da177e4SLinus Torvalds negoFlags = dv->max.flags; 53071da177e4SLinus Torvalds 53081da177e4SLinus Torvalds pPage1 = (SCSIDevicePage1_t *)pPage; 53091da177e4SLinus Torvalds if (pPage1) { 53101da177e4SLinus Torvalds mptscsih_setDevicePage1Flags (width, factor, 53111da177e4SLinus Torvalds offset, &val, &configuration, negoFlags); 53121da177e4SLinus Torvalds dnegoprintk(("Setting Min: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n", 53131da177e4SLinus Torvalds id, width, factor, offset, negoFlags, val, configuration)); 53141da177e4SLinus Torvalds pPage1->RequestedParameters = le32_to_cpu(val); 53151da177e4SLinus Torvalds pPage1->Reserved = 0; 53161da177e4SLinus Torvalds pPage1->Configuration = le32_to_cpu(configuration); 53171da177e4SLinus Torvalds } 53181da177e4SLinus Torvalds ddvprintk(("id=%d width=%d factor=%x offset=%x request=%x config=%x negoFlags=%x\n", 53191da177e4SLinus Torvalds id, width, factor, offset, val, configuration, negoFlags)); 53201da177e4SLinus Torvalds break; 53211da177e4SLinus Torvalds 53221da177e4SLinus Torvalds case MPT_FALLBACK: 53231da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT 53241da177e4SLinus Torvalds "Fallback: Start: offset %d, factor %x, width %d \n", 53251da177e4SLinus Torvalds hd->ioc->name, dv->now.offset, 53261da177e4SLinus Torvalds dv->now.factor, dv->now.width)); 53271da177e4SLinus Torvalds width = dv->now.width; 53281da177e4SLinus Torvalds offset = dv->now.offset; 53291da177e4SLinus Torvalds factor = dv->now.factor; 53301da177e4SLinus Torvalds if ((offset) && (dv->max.width)) { 53311da177e4SLinus Torvalds if (factor < MPT_ULTRA160) 53321da177e4SLinus Torvalds factor = MPT_ULTRA160; 53331da177e4SLinus Torvalds else if (factor < MPT_ULTRA2) { 53341da177e4SLinus Torvalds factor = MPT_ULTRA2; 53351da177e4SLinus Torvalds width = MPT_WIDE; 53361da177e4SLinus Torvalds } else if ((factor == MPT_ULTRA2) && width) { 53371da177e4SLinus Torvalds factor = MPT_ULTRA2; 53381da177e4SLinus Torvalds width = MPT_NARROW; 53391da177e4SLinus Torvalds } else if (factor < MPT_ULTRA) { 53401da177e4SLinus Torvalds factor = MPT_ULTRA; 53411da177e4SLinus Torvalds width = MPT_WIDE; 53421da177e4SLinus Torvalds } else if ((factor == MPT_ULTRA) && width) { 53431da177e4SLinus Torvalds width = MPT_NARROW; 53441da177e4SLinus Torvalds } else if (factor < MPT_FAST) { 53451da177e4SLinus Torvalds factor = MPT_FAST; 53461da177e4SLinus Torvalds width = MPT_WIDE; 53471da177e4SLinus Torvalds } else if ((factor == MPT_FAST) && width) { 53481da177e4SLinus Torvalds factor = MPT_FAST; 53491da177e4SLinus Torvalds width = MPT_NARROW; 53501da177e4SLinus Torvalds } else if (factor < MPT_SCSI) { 53511da177e4SLinus Torvalds factor = MPT_SCSI; 53521da177e4SLinus Torvalds width = MPT_WIDE; 53531da177e4SLinus Torvalds } else if ((factor == MPT_SCSI) && width) { 53541da177e4SLinus Torvalds factor = MPT_SCSI; 53551da177e4SLinus Torvalds width = MPT_NARROW; 53561da177e4SLinus Torvalds } else { 53571da177e4SLinus Torvalds factor = MPT_ASYNC; 53581da177e4SLinus Torvalds offset = 0; 53591da177e4SLinus Torvalds } 53601da177e4SLinus Torvalds 53611da177e4SLinus Torvalds } else if (offset) { 53621da177e4SLinus Torvalds width = MPT_NARROW; 53631da177e4SLinus Torvalds if (factor < MPT_ULTRA) 53641da177e4SLinus Torvalds factor = MPT_ULTRA; 53651da177e4SLinus Torvalds else if (factor < MPT_FAST) 53661da177e4SLinus Torvalds factor = MPT_FAST; 53671da177e4SLinus Torvalds else if (factor < MPT_SCSI) 53681da177e4SLinus Torvalds factor = MPT_SCSI; 53691da177e4SLinus Torvalds else { 53701da177e4SLinus Torvalds factor = MPT_ASYNC; 53711da177e4SLinus Torvalds offset = 0; 53721da177e4SLinus Torvalds } 53731da177e4SLinus Torvalds 53741da177e4SLinus Torvalds } else { 53751da177e4SLinus Torvalds width = MPT_NARROW; 53761da177e4SLinus Torvalds factor = MPT_ASYNC; 53771da177e4SLinus Torvalds } 53781da177e4SLinus Torvalds dv->max.flags |= MPT_TARGET_NO_NEGO_QAS; 53791da177e4SLinus Torvalds dv->max.flags &= ~MPT_TAPE_NEGO_IDP; 53801da177e4SLinus Torvalds 53811da177e4SLinus Torvalds dv->now.width = width; 53821da177e4SLinus Torvalds dv->now.offset = offset; 53831da177e4SLinus Torvalds dv->now.factor = factor; 53841da177e4SLinus Torvalds dv->now.flags = dv->max.flags; 53851da177e4SLinus Torvalds 53861da177e4SLinus Torvalds pPage1 = (SCSIDevicePage1_t *)pPage; 53871da177e4SLinus Torvalds if (pPage1) { 53881da177e4SLinus Torvalds mptscsih_setDevicePage1Flags (width, factor, offset, &val, 53891da177e4SLinus Torvalds &configuration, dv->now.flags); 53901da177e4SLinus Torvalds dnegoprintk(("Finish: id=%d width=%d offset=%d factor=%x flags=%x request=%x config=%x\n", 53911da177e4SLinus Torvalds id, width, offset, factor, dv->now.flags, val, configuration)); 53921da177e4SLinus Torvalds 53931da177e4SLinus Torvalds pPage1->RequestedParameters = le32_to_cpu(val); 53941da177e4SLinus Torvalds pPage1->Reserved = 0; 53951da177e4SLinus Torvalds pPage1->Configuration = le32_to_cpu(configuration); 53961da177e4SLinus Torvalds } 53971da177e4SLinus Torvalds 53981da177e4SLinus Torvalds ddvprintk(("Finish: id=%d offset=%d factor=%x width=%d request=%x config=%x\n", 53991da177e4SLinus Torvalds id, dv->now.offset, dv->now.factor, dv->now.width, val, configuration)); 54001da177e4SLinus Torvalds break; 54011da177e4SLinus Torvalds 54021da177e4SLinus Torvalds case MPT_SAVE: 54031da177e4SLinus Torvalds ddvprintk((MYIOC_s_NOTE_FMT 54041da177e4SLinus Torvalds "Saving to Target structure: ", hd->ioc->name)); 54051da177e4SLinus Torvalds ddvprintk(("id=%d width=%x factor=%x offset=%d flags=%x\n", 54061da177e4SLinus Torvalds id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags)); 54071da177e4SLinus Torvalds 54081da177e4SLinus Torvalds /* Save these values to target structures 54091da177e4SLinus Torvalds * or overwrite nvram (phys disks only). 54101da177e4SLinus Torvalds */ 54111da177e4SLinus Torvalds 54121da177e4SLinus Torvalds if ((hd->Targets)&&((pTarget = hd->Targets[(int)id]) != NULL) && !pTarget->raidVolume ) { 54131da177e4SLinus Torvalds pTarget->maxWidth = dv->now.width; 54141da177e4SLinus Torvalds pTarget->maxOffset = dv->now.offset; 54151da177e4SLinus Torvalds pTarget->minSyncFactor = dv->now.factor; 54161da177e4SLinus Torvalds pTarget->negoFlags = dv->now.flags; 54171da177e4SLinus Torvalds } else { 54181da177e4SLinus Torvalds /* Preserv all flags, use 54191da177e4SLinus Torvalds * read-modify-write algorithm 54201da177e4SLinus Torvalds */ 54211da177e4SLinus Torvalds if (hd->ioc->spi_data.nvram) { 54221da177e4SLinus Torvalds data = hd->ioc->spi_data.nvram[id]; 54231da177e4SLinus Torvalds 54241da177e4SLinus Torvalds if (dv->now.width) 54251da177e4SLinus Torvalds data &= ~MPT_NVRAM_WIDE_DISABLE; 54261da177e4SLinus Torvalds else 54271da177e4SLinus Torvalds data |= MPT_NVRAM_WIDE_DISABLE; 54281da177e4SLinus Torvalds 54291da177e4SLinus Torvalds if (!dv->now.offset) 54301da177e4SLinus Torvalds factor = MPT_ASYNC; 54311da177e4SLinus Torvalds 54321da177e4SLinus Torvalds data &= ~MPT_NVRAM_SYNC_MASK; 54331da177e4SLinus Torvalds data |= (dv->now.factor << MPT_NVRAM_SYNC_SHIFT) & MPT_NVRAM_SYNC_MASK; 54341da177e4SLinus Torvalds 54351da177e4SLinus Torvalds hd->ioc->spi_data.nvram[id] = data; 54361da177e4SLinus Torvalds } 54371da177e4SLinus Torvalds } 54381da177e4SLinus Torvalds break; 54391da177e4SLinus Torvalds } 54401da177e4SLinus Torvalds } 54411da177e4SLinus Torvalds 54421da177e4SLinus Torvalds /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 54431da177e4SLinus Torvalds /* mptscsih_fillbuf - fill a buffer with a special data pattern 54441da177e4SLinus Torvalds * cleanup. For bus scan only. 54451da177e4SLinus Torvalds * 54461da177e4SLinus Torvalds * @buffer: Pointer to data buffer to be filled. 54471da177e4SLinus Torvalds * @size: Number of bytes to fill 54481da177e4SLinus Torvalds * @index: Pattern index 54491da177e4SLinus Torvalds * @width: bus width, 0 (8 bits) or 1 (16 bits) 54501da177e4SLinus Torvalds */ 54511da177e4SLinus Torvalds static void 54521da177e4SLinus Torvalds mptscsih_fillbuf(char *buffer, int size, int index, int width) 54531da177e4SLinus Torvalds { 54541da177e4SLinus Torvalds char *ptr = buffer; 54551da177e4SLinus Torvalds int ii; 54561da177e4SLinus Torvalds char byte; 54571da177e4SLinus Torvalds short val; 54581da177e4SLinus Torvalds 54591da177e4SLinus Torvalds switch (index) { 54601da177e4SLinus Torvalds case 0: 54611da177e4SLinus Torvalds 54621da177e4SLinus Torvalds if (width) { 54631da177e4SLinus Torvalds /* Pattern: 0000 FFFF 0000 FFFF 54641da177e4SLinus Torvalds */ 54651da177e4SLinus Torvalds for (ii=0; ii < size; ii++, ptr++) { 54661da177e4SLinus Torvalds if (ii & 0x02) 54671da177e4SLinus Torvalds *ptr = 0xFF; 54681da177e4SLinus Torvalds else 54691da177e4SLinus Torvalds *ptr = 0x00; 54701da177e4SLinus Torvalds } 54711da177e4SLinus Torvalds } else { 54721da177e4SLinus Torvalds /* Pattern: 00 FF 00 FF 54731da177e4SLinus Torvalds */ 54741da177e4SLinus Torvalds for (ii=0; ii < size; ii++, ptr++) { 54751da177e4SLinus Torvalds if (ii & 0x01) 54761da177e4SLinus Torvalds *ptr = 0xFF; 54771da177e4SLinus Torvalds else 54781da177e4SLinus Torvalds *ptr = 0x00; 54791da177e4SLinus Torvalds } 54801da177e4SLinus Torvalds } 54811da177e4SLinus Torvalds break; 54821da177e4SLinus Torvalds 54831da177e4SLinus Torvalds case 1: 54841da177e4SLinus Torvalds if (width) { 54851da177e4SLinus Torvalds /* Pattern: 5555 AAAA 5555 AAAA 5555 54861da177e4SLinus Torvalds */ 54871da177e4SLinus Torvalds for (ii=0; ii < size; ii++, ptr++) { 54881da177e4SLinus Torvalds if (ii & 0x02) 54891da177e4SLinus Torvalds *ptr = 0xAA; 54901da177e4SLinus Torvalds else 54911da177e4SLinus Torvalds *ptr = 0x55; 54921da177e4SLinus Torvalds } 54931da177e4SLinus Torvalds } else { 54941da177e4SLinus Torvalds /* Pattern: 55 AA 55 AA 55 54951da177e4SLinus Torvalds */ 54961da177e4SLinus Torvalds for (ii=0; ii < size; ii++, ptr++) { 54971da177e4SLinus Torvalds if (ii & 0x01) 54981da177e4SLinus Torvalds *ptr = 0xAA; 54991da177e4SLinus Torvalds else 55001da177e4SLinus Torvalds *ptr = 0x55; 55011da177e4SLinus Torvalds } 55021da177e4SLinus Torvalds } 55031da177e4SLinus Torvalds break; 55041da177e4SLinus Torvalds 55051da177e4SLinus Torvalds case 2: 55061da177e4SLinus Torvalds /* Pattern: 00 01 02 03 04 05 55071da177e4SLinus Torvalds * ... FE FF 00 01.. 55081da177e4SLinus Torvalds */ 55091da177e4SLinus Torvalds for (ii=0; ii < size; ii++, ptr++) 55101da177e4SLinus Torvalds *ptr = (char) ii; 55111da177e4SLinus Torvalds break; 55121da177e4SLinus Torvalds 55131da177e4SLinus Torvalds case 3: 55141da177e4SLinus Torvalds if (width) { 55151da177e4SLinus Torvalds /* Wide Pattern: FFFE 0001 FFFD 0002 55161da177e4SLinus Torvalds * ... 4000 DFFF 8000 EFFF 55171da177e4SLinus Torvalds */ 55181da177e4SLinus Torvalds byte = 0; 55191da177e4SLinus Torvalds for (ii=0; ii < size/2; ii++) { 55201da177e4SLinus Torvalds /* Create the base pattern 55211da177e4SLinus Torvalds */ 55221da177e4SLinus Torvalds val = (1 << byte); 55231da177e4SLinus Torvalds /* every 64 (0x40) bytes flip the pattern 55241da177e4SLinus Torvalds * since we fill 2 bytes / iteration, 55251da177e4SLinus Torvalds * test for ii = 0x20 55261da177e4SLinus Torvalds */ 55271da177e4SLinus Torvalds if (ii & 0x20) 55281da177e4SLinus Torvalds val = ~(val); 55291da177e4SLinus Torvalds 55301da177e4SLinus Torvalds if (ii & 0x01) { 55311da177e4SLinus Torvalds *ptr = (char)( (val & 0xFF00) >> 8); 55321da177e4SLinus Torvalds ptr++; 55331da177e4SLinus Torvalds *ptr = (char)(val & 0xFF); 55341da177e4SLinus Torvalds byte++; 55351da177e4SLinus Torvalds byte &= 0x0F; 55361da177e4SLinus Torvalds } else { 55371da177e4SLinus Torvalds val = ~val; 55381da177e4SLinus Torvalds *ptr = (char)( (val & 0xFF00) >> 8); 55391da177e4SLinus Torvalds ptr++; 55401da177e4SLinus Torvalds *ptr = (char)(val & 0xFF); 55411da177e4SLinus Torvalds } 55421da177e4SLinus Torvalds 55431da177e4SLinus Torvalds ptr++; 55441da177e4SLinus Torvalds } 55451da177e4SLinus Torvalds } else { 55461da177e4SLinus Torvalds /* Narrow Pattern: FE 01 FD 02 FB 04 55471da177e4SLinus Torvalds * .. 7F 80 01 FE 02 FD ... 80 7F 55481da177e4SLinus Torvalds */ 55491da177e4SLinus Torvalds byte = 0; 55501da177e4SLinus Torvalds for (ii=0; ii < size; ii++, ptr++) { 55511da177e4SLinus Torvalds /* Base pattern - first 32 bytes 55521da177e4SLinus Torvalds */ 55531da177e4SLinus Torvalds if (ii & 0x01) { 55541da177e4SLinus Torvalds *ptr = (1 << byte); 55551da177e4SLinus Torvalds byte++; 55561da177e4SLinus Torvalds byte &= 0x07; 55571da177e4SLinus Torvalds } else { 55581da177e4SLinus Torvalds *ptr = (char) (~(1 << byte)); 55591da177e4SLinus Torvalds } 55601da177e4SLinus Torvalds 55611da177e4SLinus Torvalds /* Flip the pattern every 32 bytes 55621da177e4SLinus Torvalds */ 55631da177e4SLinus Torvalds if (ii & 0x20) 55641da177e4SLinus Torvalds *ptr = ~(*ptr); 55651da177e4SLinus Torvalds } 55661da177e4SLinus Torvalds } 55671da177e4SLinus Torvalds break; 55681da177e4SLinus Torvalds } 55691da177e4SLinus Torvalds } 55701da177e4SLinus Torvalds #endif /* ~MPTSCSIH_ENABLE_DOMAIN_VALIDATION */ 55711da177e4SLinus Torvalds 55720d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_remove); 55730d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_shutdown); 55740d0c7974SMoore, Eric Dean #ifdef CONFIG_PM 55750d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_suspend); 55760d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_resume); 55770d0c7974SMoore, Eric Dean #endif 55780d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_proc_info); 55790d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_info); 55800d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_qcmd); 55810d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_slave_alloc); 55820d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_slave_destroy); 55830d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_slave_configure); 55840d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_abort); 55850d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_dev_reset); 55860d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_bus_reset); 55870d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_host_reset); 55880d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_bios_param); 55890d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_io_done); 55900d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_taskmgmt_complete); 55910d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_scandv_complete); 55920d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_event_process); 55930d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_ioc_reset); 55940d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_store_queue_depth); 55950d0c7974SMoore, Eric Dean EXPORT_SYMBOL(mptscsih_timer_expired); 55961da177e4SLinus Torvalds 55970d0c7974SMoore, Eric Dean /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 5598