Path: blob/master/drivers/message/fusion/mptscsih.c
15109 views
/*1* linux/drivers/message/fusion/mptscsih.c2* For use with LSI PCI chip/adapter(s)3* running LSI Fusion MPT (Message Passing Technology) firmware.4*5* Copyright (c) 1999-2008 LSI Corporation6* (mailto:[email protected])7*8*/9/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/10/*11This program is free software; you can redistribute it and/or modify12it under the terms of the GNU General Public License as published by13the Free Software Foundation; version 2 of the License.1415This program is distributed in the hope that it will be useful,16but WITHOUT ANY WARRANTY; without even the implied warranty of17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the18GNU General Public License for more details.1920NO WARRANTY21THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR22CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT23LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,24MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is25solely responsible for determining the appropriateness of using and26distributing the Program and assumes all risks associated with its27exercise of rights under this Agreement, including but not limited to28the risks and costs of program errors, damage to or loss of data,29programs or equipment, and unavailability or interruption of operations.3031DISCLAIMER OF LIABILITY32NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY33DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL34DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND35ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR36TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE37USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED38HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES3940You should have received a copy of the GNU General Public License41along with this program; if not, write to the Free Software42Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA43*/44/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/4546#include <linux/module.h>47#include <linux/kernel.h>48#include <linux/slab.h>49#include <linux/init.h>50#include <linux/errno.h>51#include <linux/kdev_t.h>52#include <linux/blkdev.h>53#include <linux/delay.h> /* for mdelay */54#include <linux/interrupt.h> /* needed for in_interrupt() proto */55#include <linux/reboot.h> /* notifier code */56#include <linux/workqueue.h>5758#include <scsi/scsi.h>59#include <scsi/scsi_cmnd.h>60#include <scsi/scsi_device.h>61#include <scsi/scsi_host.h>62#include <scsi/scsi_tcq.h>63#include <scsi/scsi_dbg.h>6465#include "mptbase.h"66#include "mptscsih.h"67#include "lsi/mpi_log_sas.h"6869/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/70#define my_NAME "Fusion MPT SCSI Host driver"71#define my_VERSION MPT_LINUX_VERSION_COMMON72#define MYNAM "mptscsih"7374MODULE_AUTHOR(MODULEAUTHOR);75MODULE_DESCRIPTION(my_NAME);76MODULE_LICENSE("GPL");77MODULE_VERSION(my_VERSION);7879/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/80/*81* Other private/forward protos...82*/83struct scsi_cmnd *mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);84static struct scsi_cmnd * mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i);85static void mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd);86static int SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *scmd);87int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);88static void mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq);89int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);9091static int mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,92SCSIIORequest_t *pReq, int req_idx);93static void mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx);94static void mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply);9596int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id,97int lun, int ctx2abort, ulong timeout);9899int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);100int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);101102void103mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code);104static int mptscsih_get_completion_code(MPT_ADAPTER *ioc,105MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);106int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);107static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);108static void mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice);109110static int111mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type,112SCSITaskMgmtReply_t *pScsiTmReply);113void mptscsih_remove(struct pci_dev *);114void mptscsih_shutdown(struct pci_dev *);115#ifdef CONFIG_PM116int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);117int mptscsih_resume(struct pci_dev *pdev);118#endif119120#define SNS_LEN(scp) SCSI_SENSE_BUFFERSIZE121122123/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/124/*125* mptscsih_getFreeChainBuffer - Function to get a free chain126* from the MPT_SCSI_HOST FreeChainQ.127* @ioc: Pointer to MPT_ADAPTER structure128* @req_idx: Index of the SCSI IO request frame. (output)129*130* return SUCCESS or FAILED131*/132static inline int133mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)134{135MPT_FRAME_HDR *chainBuf;136unsigned long flags;137int rc;138int chain_idx;139140dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "getFreeChainBuffer called\n",141ioc->name));142spin_lock_irqsave(&ioc->FreeQlock, flags);143if (!list_empty(&ioc->FreeChainQ)) {144int offset;145146chainBuf = list_entry(ioc->FreeChainQ.next, MPT_FRAME_HDR,147u.frame.linkage.list);148list_del(&chainBuf->u.frame.linkage.list);149offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;150chain_idx = offset / ioc->req_sz;151rc = SUCCESS;152dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT153"getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",154ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));155} else {156rc = FAILED;157chain_idx = MPT_HOST_NO_CHAIN;158dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n",159ioc->name));160}161spin_unlock_irqrestore(&ioc->FreeQlock, flags);162163*retIndex = chain_idx;164return rc;165} /* mptscsih_getFreeChainBuffer() */166167/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/168/*169* mptscsih_AddSGE - Add a SGE (plus chain buffers) to the170* SCSIIORequest_t Message Frame.171* @ioc: Pointer to MPT_ADAPTER structure172* @SCpnt: Pointer to scsi_cmnd structure173* @pReq: Pointer to SCSIIORequest_t structure174*175* Returns ...176*/177static int178mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,179SCSIIORequest_t *pReq, int req_idx)180{181char *psge;182char *chainSge;183struct scatterlist *sg;184int frm_sz;185int sges_left, sg_done;186int chain_idx = MPT_HOST_NO_CHAIN;187int sgeOffset;188int numSgeSlots, numSgeThisFrame;189u32 sgflags, sgdir, thisxfer = 0;190int chain_dma_off = 0;191int newIndex;192int ii;193dma_addr_t v2;194u32 RequestNB;195196sgdir = le32_to_cpu(pReq->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK;197if (sgdir == MPI_SCSIIO_CONTROL_WRITE) {198sgdir = MPT_TRANSFER_HOST_TO_IOC;199} else {200sgdir = MPT_TRANSFER_IOC_TO_HOST;201}202203psge = (char *) &pReq->SGL;204frm_sz = ioc->req_sz;205206/* Map the data portion, if any.207* sges_left = 0 if no data transfer.208*/209sges_left = scsi_dma_map(SCpnt);210if (sges_left < 0)211return FAILED;212213/* Handle the SG case.214*/215sg = scsi_sglist(SCpnt);216sg_done = 0;217sgeOffset = sizeof(SCSIIORequest_t) - sizeof(SGE_IO_UNION);218chainSge = NULL;219220/* Prior to entering this loop - the following must be set221* current MF: sgeOffset (bytes)222* chainSge (Null if original MF is not a chain buffer)223* sg_done (num SGE done for this MF)224*/225226nextSGEset:227numSgeSlots = ((frm_sz - sgeOffset) / ioc->SGE_size);228numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots;229230sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | sgdir;231232/* Get first (num - 1) SG elements233* Skip any SG entries with a length of 0234* NOTE: at finish, sg and psge pointed to NEXT data/location positions235*/236for (ii=0; ii < (numSgeThisFrame-1); ii++) {237thisxfer = sg_dma_len(sg);238if (thisxfer == 0) {239/* Get next SG element from the OS */240sg = sg_next(sg);241sg_done++;242continue;243}244245v2 = sg_dma_address(sg);246ioc->add_sge(psge, sgflags | thisxfer, v2);247248/* Get next SG element from the OS */249sg = sg_next(sg);250psge += ioc->SGE_size;251sgeOffset += ioc->SGE_size;252sg_done++;253}254255if (numSgeThisFrame == sges_left) {256/* Add last element, end of buffer and end of list flags.257*/258sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT |259MPT_SGE_FLAGS_END_OF_BUFFER |260MPT_SGE_FLAGS_END_OF_LIST;261262/* Add last SGE and set termination flags.263* Note: Last SGE may have a length of 0 - which should be ok.264*/265thisxfer = sg_dma_len(sg);266267v2 = sg_dma_address(sg);268ioc->add_sge(psge, sgflags | thisxfer, v2);269sgeOffset += ioc->SGE_size;270sg_done++;271272if (chainSge) {273/* The current buffer is a chain buffer,274* but there is not another one.275* Update the chain element276* Offset and Length fields.277*/278ioc->add_chain((char *)chainSge, 0, sgeOffset,279ioc->ChainBufferDMA + chain_dma_off);280} else {281/* The current buffer is the original MF282* and there is no Chain buffer.283*/284pReq->ChainOffset = 0;285RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;286dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT287"Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));288ioc->RequestNB[req_idx] = RequestNB;289}290} else {291/* At least one chain buffer is needed.292* Complete the first MF293* - last SGE element, set the LastElement bit294* - set ChainOffset (words) for orig MF295* (OR finish previous MF chain buffer)296* - update MFStructPtr ChainIndex297* - Populate chain element298* Also299* Loop until done.300*/301302dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SG: Chain Required! sg done %d\n",303ioc->name, sg_done));304305/* Set LAST_ELEMENT flag for last non-chain element306* in the buffer. Since psge points at the NEXT307* SGE element, go back one SGE element, update the flags308* and reset the pointer. (Note: sgflags & thisxfer are already309* set properly).310*/311if (sg_done) {312u32 *ptmp = (u32 *) (psge - ioc->SGE_size);313sgflags = le32_to_cpu(*ptmp);314sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT;315*ptmp = cpu_to_le32(sgflags);316}317318if (chainSge) {319/* The current buffer is a chain buffer.320* chainSge points to the previous Chain Element.321* Update its chain element Offset and Length (must322* include chain element size) fields.323* Old chain element is now complete.324*/325u8 nextChain = (u8) (sgeOffset >> 2);326sgeOffset += ioc->SGE_size;327ioc->add_chain((char *)chainSge, nextChain, sgeOffset,328ioc->ChainBufferDMA + chain_dma_off);329} else {330/* The original MF buffer requires a chain buffer -331* set the offset.332* Last element in this MF is a chain element.333*/334pReq->ChainOffset = (u8) (sgeOffset >> 2);335RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;336dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));337ioc->RequestNB[req_idx] = RequestNB;338}339340sges_left -= sg_done;341342343/* NOTE: psge points to the beginning of the chain element344* in current buffer. Get a chain buffer.345*/346if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED) {347dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT348"getFreeChainBuffer FAILED SCSI cmd=%02x (%p)\n",349ioc->name, pReq->CDB[0], SCpnt));350return FAILED;351}352353/* Update the tracking arrays.354* If chainSge == NULL, update ReqToChain, else ChainToChain355*/356if (chainSge) {357ioc->ChainToChain[chain_idx] = newIndex;358} else {359ioc->ReqToChain[req_idx] = newIndex;360}361chain_idx = newIndex;362chain_dma_off = ioc->req_sz * chain_idx;363364/* Populate the chainSGE for the current buffer.365* - Set chain buffer pointer to psge and fill366* out the Address and Flags fields.367*/368chainSge = (char *) psge;369dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT " Current buff @ %p (index 0x%x)",370ioc->name, psge, req_idx));371372/* Start the SGE for the next buffer373*/374psge = (char *) (ioc->ChainBuffer + chain_dma_off);375sgeOffset = 0;376sg_done = 0;377378dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT " Chain buff @ %p (index 0x%x)\n",379ioc->name, psge, chain_idx));380381/* Start the SGE for the next buffer382*/383384goto nextSGEset;385}386387return SUCCESS;388} /* mptscsih_AddSGE() */389390static void391mptscsih_issue_sep_command(MPT_ADAPTER *ioc, VirtTarget *vtarget,392U32 SlotStatus)393{394MPT_FRAME_HDR *mf;395SEPRequest_t *SEPMsg;396397if (ioc->bus_type != SAS)398return;399400/* Not supported for hidden raid components401*/402if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)403return;404405if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {406dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: no msg frames!!\n",407ioc->name,__func__));408return;409}410411SEPMsg = (SEPRequest_t *)mf;412SEPMsg->Function = MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;413SEPMsg->Bus = vtarget->channel;414SEPMsg->TargetID = vtarget->id;415SEPMsg->Action = MPI_SEP_REQ_ACTION_WRITE_STATUS;416SEPMsg->SlotStatus = SlotStatus;417devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT418"Sending SEP cmd=%x channel=%d id=%d\n",419ioc->name, SlotStatus, SEPMsg->Bus, SEPMsg->TargetID));420mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);421}422423#ifdef CONFIG_FUSION_LOGGING424/**425* mptscsih_info_scsiio - debug print info on reply frame426* @ioc: Pointer to MPT_ADAPTER structure427* @sc: original scsi cmnd pointer428* @pScsiReply: Pointer to MPT reply frame429*430* MPT_DEBUG_REPLY needs to be enabled to obtain this info431*432* Refer to lsi/mpi.h.433**/434static void435mptscsih_info_scsiio(MPT_ADAPTER *ioc, struct scsi_cmnd *sc, SCSIIOReply_t * pScsiReply)436{437char *desc = NULL;438char *desc1 = NULL;439u16 ioc_status;440u8 skey, asc, ascq;441442ioc_status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;443444switch (ioc_status) {445446case MPI_IOCSTATUS_SUCCESS:447desc = "success";448break;449case MPI_IOCSTATUS_SCSI_INVALID_BUS:450desc = "invalid bus";451break;452case MPI_IOCSTATUS_SCSI_INVALID_TARGETID:453desc = "invalid target_id";454break;455case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE:456desc = "device not there";457break;458case MPI_IOCSTATUS_SCSI_DATA_OVERRUN:459desc = "data overrun";460break;461case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:462desc = "data underrun";463break;464case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR:465desc = "I/O data error";466break;467case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR:468desc = "protocol error";469break;470case MPI_IOCSTATUS_SCSI_TASK_TERMINATED:471desc = "task terminated";472break;473case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:474desc = "residual mismatch";475break;476case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED:477desc = "task management failed";478break;479case MPI_IOCSTATUS_SCSI_IOC_TERMINATED:480desc = "IOC terminated";481break;482case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:483desc = "ext terminated";484break;485default:486desc = "";487break;488}489490switch (pScsiReply->SCSIStatus)491{492493case MPI_SCSI_STATUS_SUCCESS:494desc1 = "success";495break;496case MPI_SCSI_STATUS_CHECK_CONDITION:497desc1 = "check condition";498break;499case MPI_SCSI_STATUS_CONDITION_MET:500desc1 = "condition met";501break;502case MPI_SCSI_STATUS_BUSY:503desc1 = "busy";504break;505case MPI_SCSI_STATUS_INTERMEDIATE:506desc1 = "intermediate";507break;508case MPI_SCSI_STATUS_INTERMEDIATE_CONDMET:509desc1 = "intermediate condmet";510break;511case MPI_SCSI_STATUS_RESERVATION_CONFLICT:512desc1 = "reservation conflict";513break;514case MPI_SCSI_STATUS_COMMAND_TERMINATED:515desc1 = "command terminated";516break;517case MPI_SCSI_STATUS_TASK_SET_FULL:518desc1 = "task set full";519break;520case MPI_SCSI_STATUS_ACA_ACTIVE:521desc1 = "aca active";522break;523case MPI_SCSI_STATUS_FCPEXT_DEVICE_LOGGED_OUT:524desc1 = "fcpext device logged out";525break;526case MPI_SCSI_STATUS_FCPEXT_NO_LINK:527desc1 = "fcpext no link";528break;529case MPI_SCSI_STATUS_FCPEXT_UNASSIGNED:530desc1 = "fcpext unassigned";531break;532default:533desc1 = "";534break;535}536537scsi_print_command(sc);538printk(MYIOC_s_DEBUG_FMT "\tfw_channel = %d, fw_id = %d, lun = %d\n",539ioc->name, pScsiReply->Bus, pScsiReply->TargetID, sc->device->lun);540printk(MYIOC_s_DEBUG_FMT "\trequest_len = %d, underflow = %d, "541"resid = %d\n", ioc->name, scsi_bufflen(sc), sc->underflow,542scsi_get_resid(sc));543printk(MYIOC_s_DEBUG_FMT "\ttag = %d, transfer_count = %d, "544"sc->result = %08X\n", ioc->name, le16_to_cpu(pScsiReply->TaskTag),545le32_to_cpu(pScsiReply->TransferCount), sc->result);546547printk(MYIOC_s_DEBUG_FMT "\tiocstatus = %s (0x%04x), "548"scsi_status = %s (0x%02x), scsi_state = (0x%02x)\n",549ioc->name, desc, ioc_status, desc1, pScsiReply->SCSIStatus,550pScsiReply->SCSIState);551552if (pScsiReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {553skey = sc->sense_buffer[2] & 0x0F;554asc = sc->sense_buffer[12];555ascq = sc->sense_buffer[13];556557printk(MYIOC_s_DEBUG_FMT "\t[sense_key,asc,ascq]: "558"[0x%02x,0x%02x,0x%02x]\n", ioc->name, skey, asc, ascq);559}560561/*562* Look for + dump FCP ResponseInfo[]!563*/564if (pScsiReply->SCSIState & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&565pScsiReply->ResponseInfo)566printk(MYIOC_s_DEBUG_FMT "response_info = %08xh\n",567ioc->name, le32_to_cpu(pScsiReply->ResponseInfo));568}569#endif570571/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/572/*573* mptscsih_io_done - Main SCSI IO callback routine registered to574* Fusion MPT (base) driver575* @ioc: Pointer to MPT_ADAPTER structure576* @mf: Pointer to original MPT request frame577* @r: Pointer to MPT reply frame (NULL if TurboReply)578*579* This routine is called from mpt.c::mpt_interrupt() at the completion580* of any SCSI IO request.581* This routine is registered with the Fusion MPT (base) driver at driver582* load/init time via the mpt_register() API call.583*584* Returns 1 indicating alloc'd request frame ptr should be freed.585*/586int587mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)588{589struct scsi_cmnd *sc;590MPT_SCSI_HOST *hd;591SCSIIORequest_t *pScsiReq;592SCSIIOReply_t *pScsiReply;593u16 req_idx, req_idx_MR;594VirtDevice *vdevice;595VirtTarget *vtarget;596597hd = shost_priv(ioc->sh);598req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);599req_idx_MR = (mr != NULL) ?600le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx) : req_idx;601602/* Special case, where already freed message frame is received from603* Firmware. It happens with Resetting IOC.604* Return immediately. Do not care605*/606if ((req_idx != req_idx_MR) ||607(le32_to_cpu(mf->u.frame.linkage.arg1) == 0xdeadbeaf))608return 0;609610sc = mptscsih_getclear_scsi_lookup(ioc, req_idx);611if (sc == NULL) {612MPIHeader_t *hdr = (MPIHeader_t *)mf;613614/* Remark: writeSDP1 will use the ScsiDoneCtx615* If a SCSI I/O cmd, device disabled by OS and616* completion done. Cannot touch sc struct. Just free mem.617*/618if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST)619printk(MYIOC_s_ERR_FMT "NULL ScsiCmd ptr!\n",620ioc->name);621622mptscsih_freeChainBuffers(ioc, req_idx);623return 1;624}625626if ((unsigned char *)mf != sc->host_scribble) {627mptscsih_freeChainBuffers(ioc, req_idx);628return 1;629}630631if (ioc->bus_type == SAS) {632VirtDevice *vdevice = sc->device->hostdata;633634if (!vdevice || !vdevice->vtarget ||635vdevice->vtarget->deleted) {636sc->result = DID_NO_CONNECT << 16;637goto out;638}639}640641sc->host_scribble = NULL;642sc->result = DID_OK << 16; /* Set default reply as OK */643pScsiReq = (SCSIIORequest_t *) mf;644pScsiReply = (SCSIIOReply_t *) mr;645646if((ioc->facts.MsgVersion >= MPI_VERSION_01_05) && pScsiReply){647dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT648"ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task-tag=%d)\n",649ioc->name, mf, mr, sc, req_idx, pScsiReply->TaskTag));650}else{651dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT652"ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",653ioc->name, mf, mr, sc, req_idx));654}655656if (pScsiReply == NULL) {657/* special context reply handling */658;659} else {660u32 xfer_cnt;661u16 status;662u8 scsi_state, scsi_status;663u32 log_info;664665status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;666667scsi_state = pScsiReply->SCSIState;668scsi_status = pScsiReply->SCSIStatus;669xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);670scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);671log_info = le32_to_cpu(pScsiReply->IOCLogInfo);672673/*674* if we get a data underrun indication, yet no data was675* transferred and the SCSI status indicates that the676* command was never started, change the data underrun677* to success678*/679if (status == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&680(scsi_status == MPI_SCSI_STATUS_BUSY ||681scsi_status == MPI_SCSI_STATUS_RESERVATION_CONFLICT ||682scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)) {683status = MPI_IOCSTATUS_SUCCESS;684}685686if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)687mptscsih_copy_sense_data(sc, hd, mf, pScsiReply);688689/*690* Look for + dump FCP ResponseInfo[]!691*/692if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&693pScsiReply->ResponseInfo) {694printk(MYIOC_s_NOTE_FMT "[%d:%d:%d:%d] "695"FCP_ResponseInfo=%08xh\n", ioc->name,696sc->device->host->host_no, sc->device->channel,697sc->device->id, sc->device->lun,698le32_to_cpu(pScsiReply->ResponseInfo));699}700701switch(status) {702case MPI_IOCSTATUS_BUSY: /* 0x0002 */703case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */704/* CHECKME!705* Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry)706* But not: DID_BUS_BUSY lest one risk707* killing interrupt handler:-(708*/709sc->result = SAM_STAT_BUSY;710break;711712case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */713case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */714sc->result = DID_BAD_TARGET << 16;715break;716717case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */718/* Spoof to SCSI Selection Timeout! */719if (ioc->bus_type != FC)720sc->result = DID_NO_CONNECT << 16;721/* else fibre, just stall until rescan event */722else723sc->result = DID_REQUEUE << 16;724725if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)726hd->sel_timeout[pScsiReq->TargetID]++;727728vdevice = sc->device->hostdata;729if (!vdevice)730break;731vtarget = vdevice->vtarget;732if (vtarget->tflags & MPT_TARGET_FLAGS_LED_ON) {733mptscsih_issue_sep_command(ioc, vtarget,734MPI_SEP_REQ_SLOTSTATUS_UNCONFIGURED);735vtarget->tflags &= ~MPT_TARGET_FLAGS_LED_ON;736}737break;738739case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */740if ( ioc->bus_type == SAS ) {741u16 ioc_status =742le16_to_cpu(pScsiReply->IOCStatus);743if ((ioc_status &744MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)745&&746((log_info & SAS_LOGINFO_MASK) ==747SAS_LOGINFO_NEXUS_LOSS)) {748VirtDevice *vdevice =749sc->device->hostdata;750751/* flag the device as being in752* device removal delay so we can753* notify the midlayer to hold off754* on timeout eh */755if (vdevice && vdevice->756vtarget &&757vdevice->vtarget->758raidVolume)759printk(KERN_INFO760"Skipping Raid Volume"761"for inDMD\n");762else if (vdevice &&763vdevice->vtarget)764vdevice->vtarget->765inDMD = 1;766767sc->result =768(DID_TRANSPORT_DISRUPTED769<< 16);770break;771}772} else if (ioc->bus_type == FC) {773/*774* The FC IOC may kill a request for variety of775* reasons, some of which may be recovered by a776* retry, some which are unlikely to be777* recovered. Return DID_ERROR instead of778* DID_RESET to permit retry of the command,779* just not an infinite number of them780*/781sc->result = DID_ERROR << 16;782break;783}784785/*786* Allow non-SAS & non-NEXUS_LOSS to drop into below code787*/788789case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */790/* Linux handles an unsolicited DID_RESET better791* than an unsolicited DID_ABORT.792*/793sc->result = DID_RESET << 16;794795case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */796if (ioc->bus_type == FC)797sc->result = DID_ERROR << 16;798else799sc->result = DID_RESET << 16;800break;801802case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */803scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);804if((xfer_cnt==0)||(sc->underflow > xfer_cnt))805sc->result=DID_SOFT_ERROR << 16;806else /* Sufficient data transfer occurred */807sc->result = (DID_OK << 16) | scsi_status;808dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT809"RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",810ioc->name, sc->result, sc->device->channel, sc->device->id));811break;812813case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */814/*815* Do upfront check for valid SenseData and give it816* precedence!817*/818sc->result = (DID_OK << 16) | scsi_status;819if (!(scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)) {820821/*822* For an Errata on LSI53C1030823* When the length of request data824* and transfer data are different825* with result of command (READ or VERIFY),826* DID_SOFT_ERROR is set.827*/828if (ioc->bus_type == SPI) {829if (pScsiReq->CDB[0] == READ_6 ||830pScsiReq->CDB[0] == READ_10 ||831pScsiReq->CDB[0] == READ_12 ||832pScsiReq->CDB[0] == READ_16 ||833pScsiReq->CDB[0] == VERIFY ||834pScsiReq->CDB[0] == VERIFY_16) {835if (scsi_bufflen(sc) !=836xfer_cnt) {837sc->result =838DID_SOFT_ERROR << 16;839printk(KERN_WARNING "Errata"840"on LSI53C1030 occurred."841"sc->req_bufflen=0x%02x,"842"xfer_cnt=0x%02x\n",843scsi_bufflen(sc),844xfer_cnt);845}846}847}848849if (xfer_cnt < sc->underflow) {850if (scsi_status == SAM_STAT_BUSY)851sc->result = SAM_STAT_BUSY;852else853sc->result = DID_SOFT_ERROR << 16;854}855if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {856/* What to do?857*/858sc->result = DID_SOFT_ERROR << 16;859}860else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {861/* Not real sure here either... */862sc->result = DID_RESET << 16;863}864}865866867dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT868" sc->underflow={report ERR if < %02xh bytes xfer'd}\n",869ioc->name, sc->underflow));870dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT871" ActBytesXferd=%02xh\n", ioc->name, xfer_cnt));872873/* Report Queue Full874*/875if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)876mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);877878break;879880case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */881scsi_set_resid(sc, 0);882case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */883case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */884sc->result = (DID_OK << 16) | scsi_status;885if (scsi_state == 0) {886;887} else if (scsi_state &888MPI_SCSI_STATE_AUTOSENSE_VALID) {889890/*891* For potential trouble on LSI53C1030.892* (date:2007.xx.)893* It is checked whether the length of894* request data is equal to895* the length of transfer and residual.896* MEDIUM_ERROR is set by incorrect data.897*/898if ((ioc->bus_type == SPI) &&899(sc->sense_buffer[2] & 0x20)) {900u32 difftransfer;901difftransfer =902sc->sense_buffer[3] << 24 |903sc->sense_buffer[4] << 16 |904sc->sense_buffer[5] << 8 |905sc->sense_buffer[6];906if (((sc->sense_buffer[3] & 0x80) ==9070x80) && (scsi_bufflen(sc)908!= xfer_cnt)) {909sc->sense_buffer[2] =910MEDIUM_ERROR;911sc->sense_buffer[12] = 0xff;912sc->sense_buffer[13] = 0xff;913printk(KERN_WARNING"Errata"914"on LSI53C1030 occurred."915"sc->req_bufflen=0x%02x,"916"xfer_cnt=0x%02x\n" ,917scsi_bufflen(sc),918xfer_cnt);919}920if (((sc->sense_buffer[3] & 0x80)921!= 0x80) &&922(scsi_bufflen(sc) !=923xfer_cnt + difftransfer)) {924sc->sense_buffer[2] =925MEDIUM_ERROR;926sc->sense_buffer[12] = 0xff;927sc->sense_buffer[13] = 0xff;928printk(KERN_WARNING929"Errata on LSI53C1030 occurred"930"sc->req_bufflen=0x%02x,"931" xfer_cnt=0x%02x,"932"difftransfer=0x%02x\n",933scsi_bufflen(sc),934xfer_cnt,935difftransfer);936}937}938939/*940* If running against circa 200003dd 909 MPT f/w,941* may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL942* (QUEUE_FULL) returned from device! --> get 0x0000?128943* and with SenseBytes set to 0.944*/945if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL)946mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);947948}949else if (scsi_state &950(MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)951) {952/*953* What to do?954*/955sc->result = DID_SOFT_ERROR << 16;956}957else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {958/* Not real sure here either... */959sc->result = DID_RESET << 16;960}961else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) {962/* Device Inq. data indicates that it supports963* QTags, but rejects QTag messages.964* This command completed OK.965*966* Not real sure here either so do nothing... */967}968969if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL)970mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);971972/* Add handling of:973* Reservation Conflict, Busy,974* Command Terminated, CHECK975*/976break;977978case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */979sc->result = DID_SOFT_ERROR << 16;980break;981982case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */983case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */984case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */985case MPI_IOCSTATUS_RESERVED: /* 0x0005 */986case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */987case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */988case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */989case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */990default:991/*992* What to do?993*/994sc->result = DID_SOFT_ERROR << 16;995break;996997} /* switch(status) */998999#ifdef CONFIG_FUSION_LOGGING1000if (sc->result && (ioc->debug_level & MPT_DEBUG_REPLY))1001mptscsih_info_scsiio(ioc, sc, pScsiReply);1002#endif10031004} /* end of address reply case */1005out:1006/* Unmap the DMA buffers, if any. */1007scsi_dma_unmap(sc);10081009sc->scsi_done(sc); /* Issue the command callback */10101011/* Free Chain buffers */1012mptscsih_freeChainBuffers(ioc, req_idx);1013return 1;1014}10151016/*1017* mptscsih_flush_running_cmds - For each command found, search1018* Scsi_Host instance taskQ and reply to OS.1019* Called only if recovering from a FW reload.1020* @hd: Pointer to a SCSI HOST structure1021*1022* Returns: None.1023*1024* Must be called while new I/Os are being queued.1025*/1026static void1027mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)1028{1029MPT_ADAPTER *ioc = hd->ioc;1030struct scsi_cmnd *sc;1031SCSIIORequest_t *mf = NULL;1032int ii;1033int channel, id;10341035for (ii= 0; ii < ioc->req_depth; ii++) {1036sc = mptscsih_getclear_scsi_lookup(ioc, ii);1037if (!sc)1038continue;1039mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);1040if (!mf)1041continue;1042channel = mf->Bus;1043id = mf->TargetID;1044mptscsih_freeChainBuffers(ioc, ii);1045mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);1046if ((unsigned char *)mf != sc->host_scribble)1047continue;1048scsi_dma_unmap(sc);1049sc->result = DID_RESET << 16;1050sc->host_scribble = NULL;1051dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT1052"completing cmds: fw_channel %d, fw_id %d, sc=%p, mf = %p, "1053"idx=%x\n", ioc->name, channel, id, sc, mf, ii));1054sc->scsi_done(sc);1055}1056}10571058/*1059* mptscsih_search_running_cmds - Delete any commands associated1060* with the specified target and lun. Function called only1061* when a lun is disable by mid-layer.1062* Do NOT access the referenced scsi_cmnd structure or1063* members. Will cause either a paging or NULL ptr error.1064* (BUT, BUT, BUT, the code does reference it! - mdr)1065* @hd: Pointer to a SCSI HOST structure1066* @vdevice: per device private data1067*1068* Returns: None.1069*1070* Called from slave_destroy.1071*/1072static void1073mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)1074{1075SCSIIORequest_t *mf = NULL;1076int ii;1077struct scsi_cmnd *sc;1078struct scsi_lun lun;1079MPT_ADAPTER *ioc = hd->ioc;1080unsigned long flags;10811082spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);1083for (ii = 0; ii < ioc->req_depth; ii++) {1084if ((sc = ioc->ScsiLookup[ii]) != NULL) {10851086mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);1087if (mf == NULL)1088continue;1089/* If the device is a hidden raid component, then its1090* expected that the mf->function will be RAID_SCSI_IO1091*/1092if (vdevice->vtarget->tflags &1093MPT_TARGET_FLAGS_RAID_COMPONENT && mf->Function !=1094MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)1095continue;10961097int_to_scsilun(vdevice->lun, &lun);1098if ((mf->Bus != vdevice->vtarget->channel) ||1099(mf->TargetID != vdevice->vtarget->id) ||1100memcmp(lun.scsi_lun, mf->LUN, 8))1101continue;11021103if ((unsigned char *)mf != sc->host_scribble)1104continue;1105ioc->ScsiLookup[ii] = NULL;1106spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);1107mptscsih_freeChainBuffers(ioc, ii);1108mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);1109scsi_dma_unmap(sc);1110sc->host_scribble = NULL;1111sc->result = DID_NO_CONNECT << 16;1112dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device,1113MYIOC_s_FMT "completing cmds: fw_channel %d, "1114"fw_id %d, sc=%p, mf = %p, idx=%x\n", ioc->name,1115vdevice->vtarget->channel, vdevice->vtarget->id,1116sc, mf, ii));1117sc->scsi_done(sc);1118spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);1119}1120}1121spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);1122return;1123}11241125/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/11261127/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1128/*1129* mptscsih_report_queue_full - Report QUEUE_FULL status returned1130* from a SCSI target device.1131* @sc: Pointer to scsi_cmnd structure1132* @pScsiReply: Pointer to SCSIIOReply_t1133* @pScsiReq: Pointer to original SCSI request1134*1135* This routine periodically reports QUEUE_FULL status returned from a1136* SCSI target device. It reports this to the console via kernel1137* printk() API call, not more than once every 10 seconds.1138*/1139static void1140mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq)1141{1142long time = jiffies;1143MPT_SCSI_HOST *hd;1144MPT_ADAPTER *ioc;11451146if (sc->device == NULL)1147return;1148if (sc->device->host == NULL)1149return;1150if ((hd = shost_priv(sc->device->host)) == NULL)1151return;1152ioc = hd->ioc;1153if (time - hd->last_queue_full > 10 * HZ) {1154dprintk(ioc, printk(MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n",1155ioc->name, 0, sc->device->id, sc->device->lun));1156hd->last_queue_full = time;1157}1158}11591160/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1161/*1162* mptscsih_remove - Removed scsi devices1163* @pdev: Pointer to pci_dev structure1164*1165*1166*/1167void1168mptscsih_remove(struct pci_dev *pdev)1169{1170MPT_ADAPTER *ioc = pci_get_drvdata(pdev);1171struct Scsi_Host *host = ioc->sh;1172MPT_SCSI_HOST *hd;1173int sz1;11741175scsi_remove_host(host);11761177if((hd = shost_priv(host)) == NULL)1178return;11791180mptscsih_shutdown(pdev);11811182sz1=0;11831184if (ioc->ScsiLookup != NULL) {1185sz1 = ioc->req_depth * sizeof(void *);1186kfree(ioc->ScsiLookup);1187ioc->ScsiLookup = NULL;1188}11891190dprintk(ioc, printk(MYIOC_s_DEBUG_FMT1191"Free'd ScsiLookup (%d) memory\n",1192ioc->name, sz1));11931194kfree(hd->info_kbuf);11951196/* NULL the Scsi_Host pointer1197*/1198ioc->sh = NULL;11991200scsi_host_put(host);12011202mpt_detach(pdev);12031204}12051206/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1207/*1208* mptscsih_shutdown - reboot notifier1209*1210*/1211void1212mptscsih_shutdown(struct pci_dev *pdev)1213{1214}12151216#ifdef CONFIG_PM1217/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1218/*1219* mptscsih_suspend - Fusion MPT scsi driver suspend routine.1220*1221*1222*/1223int1224mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)1225{1226MPT_ADAPTER *ioc = pci_get_drvdata(pdev);12271228scsi_block_requests(ioc->sh);1229flush_scheduled_work();1230mptscsih_shutdown(pdev);1231return mpt_suspend(pdev,state);1232}12331234/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1235/*1236* mptscsih_resume - Fusion MPT scsi driver resume routine.1237*1238*1239*/1240int1241mptscsih_resume(struct pci_dev *pdev)1242{1243MPT_ADAPTER *ioc = pci_get_drvdata(pdev);1244int rc;12451246rc = mpt_resume(pdev);1247scsi_unblock_requests(ioc->sh);1248return rc;1249}12501251#endif12521253/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1254/**1255* mptscsih_info - Return information about MPT adapter1256* @SChost: Pointer to Scsi_Host structure1257*1258* (linux scsi_host_template.info routine)1259*1260* Returns pointer to buffer where information was written.1261*/1262const char *1263mptscsih_info(struct Scsi_Host *SChost)1264{1265MPT_SCSI_HOST *h;1266int size = 0;12671268h = shost_priv(SChost);12691270if (h) {1271if (h->info_kbuf == NULL)1272if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)1273return h->info_kbuf;1274h->info_kbuf[0] = '\0';12751276mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);1277h->info_kbuf[size-1] = '\0';1278}12791280return h->info_kbuf;1281}12821283struct info_str {1284char *buffer;1285int length;1286int offset;1287int pos;1288};12891290static void1291mptscsih_copy_mem_info(struct info_str *info, char *data, int len)1292{1293if (info->pos + len > info->length)1294len = info->length - info->pos;12951296if (info->pos + len < info->offset) {1297info->pos += len;1298return;1299}13001301if (info->pos < info->offset) {1302data += (info->offset - info->pos);1303len -= (info->offset - info->pos);1304}13051306if (len > 0) {1307memcpy(info->buffer + info->pos, data, len);1308info->pos += len;1309}1310}13111312static int1313mptscsih_copy_info(struct info_str *info, char *fmt, ...)1314{1315va_list args;1316char buf[81];1317int len;13181319va_start(args, fmt);1320len = vsprintf(buf, fmt, args);1321va_end(args);13221323mptscsih_copy_mem_info(info, buf, len);1324return len;1325}13261327static int1328mptscsih_host_info(MPT_ADAPTER *ioc, char *pbuf, off_t offset, int len)1329{1330struct info_str info;13311332info.buffer = pbuf;1333info.length = len;1334info.offset = offset;1335info.pos = 0;13361337mptscsih_copy_info(&info, "%s: %s, ", ioc->name, ioc->prod_name);1338mptscsih_copy_info(&info, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word);1339mptscsih_copy_info(&info, "Ports=%d, ", ioc->facts.NumberOfPorts);1340mptscsih_copy_info(&info, "MaxQ=%d\n", ioc->req_depth);13411342return ((info.pos > info.offset) ? info.pos - info.offset : 0);1343}13441345/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1346/**1347* mptscsih_proc_info - Return information about MPT adapter1348* @host: scsi host struct1349* @buffer: if write, user data; if read, buffer for user1350* @start: returns the buffer address1351* @offset: if write, 0; if read, the current offset into the buffer from1352* the previous read.1353* @length: if write, return length;1354* @func: write = 1; read = 01355*1356* (linux scsi_host_template.info routine)1357*/1358int1359mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,1360int length, int func)1361{1362MPT_SCSI_HOST *hd = shost_priv(host);1363MPT_ADAPTER *ioc = hd->ioc;1364int size = 0;13651366if (func) {1367/*1368* write is not supported1369*/1370} else {1371if (start)1372*start = buffer;13731374size = mptscsih_host_info(ioc, buffer, offset, length);1375}13761377return size;1378}13791380/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1381#define ADD_INDEX_LOG(req_ent) do { } while(0)13821383/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1384/**1385* mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine.1386* @SCpnt: Pointer to scsi_cmnd structure1387* @done: Pointer SCSI mid-layer IO completion function1388*1389* (linux scsi_host_template.queuecommand routine)1390* This is the primary SCSI IO start routine. Create a MPI SCSIIORequest1391* from a linux scsi_cmnd request and send it to the IOC.1392*1393* Returns 0. (rtn value discarded by linux scsi mid-layer)1394*/1395int1396mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))1397{1398MPT_SCSI_HOST *hd;1399MPT_FRAME_HDR *mf;1400SCSIIORequest_t *pScsiReq;1401VirtDevice *vdevice = SCpnt->device->hostdata;1402u32 datalen;1403u32 scsictl;1404u32 scsidir;1405u32 cmd_len;1406int my_idx;1407int ii;1408MPT_ADAPTER *ioc;14091410hd = shost_priv(SCpnt->device->host);1411ioc = hd->ioc;1412SCpnt->scsi_done = done;14131414dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "qcmd: SCpnt=%p, done()=%p\n",1415ioc->name, SCpnt, done));14161417if (ioc->taskmgmt_quiesce_io)1418return SCSI_MLQUEUE_HOST_BUSY;14191420/*1421* Put together a MPT SCSI request...1422*/1423if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {1424dprintk(ioc, printk(MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",1425ioc->name));1426return SCSI_MLQUEUE_HOST_BUSY;1427}14281429pScsiReq = (SCSIIORequest_t *) mf;14301431my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);14321433ADD_INDEX_LOG(my_idx);14341435/* TUR's being issued with scsictl=0x02000000 (DATA_IN)!1436* Seems we may receive a buffer (datalen>0) even when there1437* will be no data transfer! GRRRRR...1438*/1439if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {1440datalen = scsi_bufflen(SCpnt);1441scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */1442} else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {1443datalen = scsi_bufflen(SCpnt);1444scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */1445} else {1446datalen = 0;1447scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER;1448}14491450/* Default to untagged. Once a target structure has been allocated,1451* use the Inquiry data to determine if device supports tagged.1452*/1453if (vdevice1454&& (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)1455&& (SCpnt->device->tagged_supported)) {1456scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;1457if (SCpnt->request && SCpnt->request->ioprio) {1458if (((SCpnt->request->ioprio & 0x7) == 1) ||1459!(SCpnt->request->ioprio & 0x7))1460scsictl |= MPI_SCSIIO_CONTROL_HEADOFQ;1461}1462} else1463scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;146414651466/* Use the above information to set up the message frame1467*/1468pScsiReq->TargetID = (u8) vdevice->vtarget->id;1469pScsiReq->Bus = vdevice->vtarget->channel;1470pScsiReq->ChainOffset = 0;1471if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)1472pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;1473else1474pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;1475pScsiReq->CDBLength = SCpnt->cmd_len;1476pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;1477pScsiReq->Reserved = 0;1478pScsiReq->MsgFlags = mpt_msg_flags(ioc);1479int_to_scsilun(SCpnt->device->lun, (struct scsi_lun *)pScsiReq->LUN);1480pScsiReq->Control = cpu_to_le32(scsictl);14811482/*1483* Write SCSI CDB into the message1484*/1485cmd_len = SCpnt->cmd_len;1486for (ii=0; ii < cmd_len; ii++)1487pScsiReq->CDB[ii] = SCpnt->cmnd[ii];14881489for (ii=cmd_len; ii < 16; ii++)1490pScsiReq->CDB[ii] = 0;14911492/* DataLength */1493pScsiReq->DataLength = cpu_to_le32(datalen);14941495/* SenseBuffer low address */1496pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma1497+ (my_idx * MPT_SENSE_BUFFER_ALLOC));14981499/* Now add the SG list1500* Always have a SGE even if null length.1501*/1502if (datalen == 0) {1503/* Add a NULL SGE */1504ioc->add_sge((char *)&pScsiReq->SGL,1505MPT_SGE_FLAGS_SSIMPLE_READ | 0,1506(dma_addr_t) -1);1507} else {1508/* Add a 32 or 64 bit SGE */1509if (mptscsih_AddSGE(ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)1510goto fail;1511}15121513SCpnt->host_scribble = (unsigned char *)mf;1514mptscsih_set_scsi_lookup(ioc, my_idx, SCpnt);15151516mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);1517dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",1518ioc->name, SCpnt, mf, my_idx));1519DBG_DUMP_REQUEST_FRAME(ioc, (u32 *)mf);1520return 0;15211522fail:1523mptscsih_freeChainBuffers(ioc, my_idx);1524mpt_free_msg_frame(ioc, mf);1525return SCSI_MLQUEUE_HOST_BUSY;1526}15271528/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1529/*1530* mptscsih_freeChainBuffers - Function to free chain buffers associated1531* with a SCSI IO request1532* @hd: Pointer to the MPT_SCSI_HOST instance1533* @req_idx: Index of the SCSI IO request frame.1534*1535* Called if SG chain buffer allocation fails and mptscsih callbacks.1536* No return.1537*/1538static void1539mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)1540{1541MPT_FRAME_HDR *chain;1542unsigned long flags;1543int chain_idx;1544int next;15451546/* Get the first chain index and reset1547* tracker state.1548*/1549chain_idx = ioc->ReqToChain[req_idx];1550ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN;15511552while (chain_idx != MPT_HOST_NO_CHAIN) {15531554/* Save the next chain buffer index */1555next = ioc->ChainToChain[chain_idx];15561557/* Free this chain buffer and reset1558* tracker1559*/1560ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN;15611562chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer1563+ (chain_idx * ioc->req_sz));15641565spin_lock_irqsave(&ioc->FreeQlock, flags);1566list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);1567spin_unlock_irqrestore(&ioc->FreeQlock, flags);15681569dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FreeChainBuffers (index %d)\n",1570ioc->name, chain_idx));15711572/* handle next */1573chain_idx = next;1574}1575return;1576}15771578/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1579/*1580* Reset Handling1581*/15821583/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1584/**1585* mptscsih_IssueTaskMgmt - Generic send Task Management function.1586* @hd: Pointer to MPT_SCSI_HOST structure1587* @type: Task Management type1588* @channel: channel number for task management1589* @id: Logical Target ID for reset (if appropriate)1590* @lun: Logical Unit for reset (if appropriate)1591* @ctx2abort: Context for the task to be aborted (if appropriate)1592* @timeout: timeout for task management control1593*1594* Remark: _HardResetHandler can be invoked from an interrupt thread (timer)1595* or a non-interrupt thread. In the former, must not call schedule().1596*1597* Not all fields are meaningfull for all task types.1598*1599* Returns 0 for SUCCESS, or FAILED.1600*1601**/1602int1603mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun,1604int ctx2abort, ulong timeout)1605{1606MPT_FRAME_HDR *mf;1607SCSITaskMgmt_t *pScsiTm;1608int ii;1609int retval;1610MPT_ADAPTER *ioc = hd->ioc;1611unsigned long timeleft;1612u8 issue_hard_reset;1613u32 ioc_raw_state;1614unsigned long time_count;16151616issue_hard_reset = 0;1617ioc_raw_state = mpt_GetIocState(ioc, 0);16181619if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {1620printk(MYIOC_s_WARN_FMT1621"TaskMgmt type=%x: IOC Not operational (0x%x)!\n",1622ioc->name, type, ioc_raw_state);1623printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",1624ioc->name, __func__);1625if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)1626printk(MYIOC_s_WARN_FMT "TaskMgmt HardReset "1627"FAILED!!\n", ioc->name);1628return 0;1629}16301631if (ioc_raw_state & MPI_DOORBELL_ACTIVE) {1632printk(MYIOC_s_WARN_FMT1633"TaskMgmt type=%x: ioc_state: "1634"DOORBELL_ACTIVE (0x%x)!\n",1635ioc->name, type, ioc_raw_state);1636return FAILED;1637}16381639mutex_lock(&ioc->taskmgmt_cmds.mutex);1640if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {1641mf = NULL;1642retval = FAILED;1643goto out;1644}16451646/* Return Fail to calling function if no message frames available.1647*/1648if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {1649dfailprintk(ioc, printk(MYIOC_s_ERR_FMT1650"TaskMgmt no msg frames!!\n", ioc->name));1651retval = FAILED;1652mpt_clear_taskmgmt_in_progress_flag(ioc);1653goto out;1654}1655dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",1656ioc->name, mf));16571658/* Format the Request1659*/1660pScsiTm = (SCSITaskMgmt_t *) mf;1661pScsiTm->TargetID = id;1662pScsiTm->Bus = channel;1663pScsiTm->ChainOffset = 0;1664pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;16651666pScsiTm->Reserved = 0;1667pScsiTm->TaskType = type;1668pScsiTm->Reserved1 = 0;1669pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)1670? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;16711672int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);16731674for (ii=0; ii < 7; ii++)1675pScsiTm->Reserved2[ii] = 0;16761677pScsiTm->TaskMsgContext = ctx2abort;16781679dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt: ctx2abort (0x%08x) "1680"task_type = 0x%02X, timeout = %ld\n", ioc->name, ctx2abort,1681type, timeout));16821683DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)pScsiTm);16841685INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)1686time_count = jiffies;1687if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&1688(ioc->facts.MsgVersion >= MPI_VERSION_01_05))1689mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf);1690else {1691retval = mpt_send_handshake_request(ioc->TaskCtx, ioc,1692sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);1693if (retval) {1694dfailprintk(ioc, printk(MYIOC_s_ERR_FMT1695"TaskMgmt handshake FAILED!(mf=%p, rc=%d) \n",1696ioc->name, mf, retval));1697mpt_free_msg_frame(ioc, mf);1698mpt_clear_taskmgmt_in_progress_flag(ioc);1699goto out;1700}1701}17021703timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done,1704timeout*HZ);1705if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {1706retval = FAILED;1707dtmprintk(ioc, printk(MYIOC_s_ERR_FMT1708"TaskMgmt TIMED OUT!(mf=%p)\n", ioc->name, mf));1709mpt_clear_taskmgmt_in_progress_flag(ioc);1710if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)1711goto out;1712issue_hard_reset = 1;1713goto out;1714}17151716retval = mptscsih_taskmgmt_reply(ioc, type,1717(SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply);17181719dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT1720"TaskMgmt completed (%d seconds)\n",1721ioc->name, jiffies_to_msecs(jiffies - time_count)/1000));17221723out:17241725CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)1726if (issue_hard_reset) {1727printk(MYIOC_s_WARN_FMT1728"Issuing Reset from %s!! doorbell=0x%08x\n",1729ioc->name, __func__, mpt_GetIocState(ioc, 0));1730retval = mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);1731mpt_free_msg_frame(ioc, mf);1732}17331734retval = (retval == 0) ? 0 : FAILED;1735mutex_unlock(&ioc->taskmgmt_cmds.mutex);1736return retval;1737}1738EXPORT_SYMBOL(mptscsih_IssueTaskMgmt);17391740static int1741mptscsih_get_tm_timeout(MPT_ADAPTER *ioc)1742{1743switch (ioc->bus_type) {1744case FC:1745return 40;1746case SAS:1747return 30;1748case SPI:1749default:1750return 10;1751}1752}17531754/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1755/**1756* mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant1757* @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted1758*1759* (linux scsi_host_template.eh_abort_handler routine)1760*1761* Returns SUCCESS or FAILED.1762**/1763int1764mptscsih_abort(struct scsi_cmnd * SCpnt)1765{1766MPT_SCSI_HOST *hd;1767MPT_FRAME_HDR *mf;1768u32 ctx2abort;1769int scpnt_idx;1770int retval;1771VirtDevice *vdevice;1772MPT_ADAPTER *ioc;17731774/* If we can't locate our host adapter structure, return FAILED status.1775*/1776if ((hd = shost_priv(SCpnt->device->host)) == NULL) {1777SCpnt->result = DID_RESET << 16;1778SCpnt->scsi_done(SCpnt);1779printk(KERN_ERR MYNAM ": task abort: "1780"can't locate host! (sc=%p)\n", SCpnt);1781return FAILED;1782}17831784ioc = hd->ioc;1785printk(MYIOC_s_INFO_FMT "attempting task abort! (sc=%p)\n",1786ioc->name, SCpnt);1787scsi_print_command(SCpnt);17881789vdevice = SCpnt->device->hostdata;1790if (!vdevice || !vdevice->vtarget) {1791dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT1792"task abort: device has been deleted (sc=%p)\n",1793ioc->name, SCpnt));1794SCpnt->result = DID_NO_CONNECT << 16;1795SCpnt->scsi_done(SCpnt);1796retval = SUCCESS;1797goto out;1798}17991800/* Task aborts are not supported for hidden raid components.1801*/1802if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {1803dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT1804"task abort: hidden raid component (sc=%p)\n",1805ioc->name, SCpnt));1806SCpnt->result = DID_RESET << 16;1807retval = FAILED;1808goto out;1809}18101811/* Task aborts are not supported for volumes.1812*/1813if (vdevice->vtarget->raidVolume) {1814dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT1815"task abort: raid volume (sc=%p)\n",1816ioc->name, SCpnt));1817SCpnt->result = DID_RESET << 16;1818retval = FAILED;1819goto out;1820}18211822/* Find this command1823*/1824if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(ioc, SCpnt)) < 0) {1825/* Cmd not found in ScsiLookup.1826* Do OS callback.1827*/1828SCpnt->result = DID_RESET << 16;1829dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "task abort: "1830"Command not in the active list! (sc=%p)\n", ioc->name,1831SCpnt));1832retval = SUCCESS;1833goto out;1834}18351836if (ioc->timeouts < -1)1837ioc->timeouts++;18381839if (mpt_fwfault_debug)1840mpt_halt_firmware(ioc);18411842/* Most important! Set TaskMsgContext to SCpnt's MsgContext!1843* (the IO to be ABORT'd)1844*1845* NOTE: Since we do not byteswap MsgContext, we do not1846* swap it here either. It is an opaque cookie to1847* the controller, so it does not matter. -DaveM1848*/1849mf = MPT_INDEX_2_MFPTR(ioc, scpnt_idx);1850ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;1851retval = mptscsih_IssueTaskMgmt(hd,1852MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,1853vdevice->vtarget->channel,1854vdevice->vtarget->id, vdevice->lun,1855ctx2abort, mptscsih_get_tm_timeout(ioc));18561857if (SCPNT_TO_LOOKUP_IDX(ioc, SCpnt) == scpnt_idx) {1858dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT1859"task abort: command still in active list! (sc=%p)\n",1860ioc->name, SCpnt));1861retval = FAILED;1862} else {1863dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT1864"task abort: command cleared from active list! (sc=%p)\n",1865ioc->name, SCpnt));1866retval = SUCCESS;1867}18681869out:1870printk(MYIOC_s_INFO_FMT "task abort: %s (rv=%04x) (sc=%p)\n",1871ioc->name, ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), retval,1872SCpnt);18731874return retval;1875}18761877/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1878/**1879* mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant1880* @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to1881*1882* (linux scsi_host_template.eh_dev_reset_handler routine)1883*1884* Returns SUCCESS or FAILED.1885**/1886int1887mptscsih_dev_reset(struct scsi_cmnd * SCpnt)1888{1889MPT_SCSI_HOST *hd;1890int retval;1891VirtDevice *vdevice;1892MPT_ADAPTER *ioc;18931894/* If we can't locate our host adapter structure, return FAILED status.1895*/1896if ((hd = shost_priv(SCpnt->device->host)) == NULL){1897printk(KERN_ERR MYNAM ": target reset: "1898"Can't locate host! (sc=%p)\n", SCpnt);1899return FAILED;1900}19011902ioc = hd->ioc;1903printk(MYIOC_s_INFO_FMT "attempting target reset! (sc=%p)\n",1904ioc->name, SCpnt);1905scsi_print_command(SCpnt);19061907vdevice = SCpnt->device->hostdata;1908if (!vdevice || !vdevice->vtarget) {1909retval = 0;1910goto out;1911}19121913/* Target reset to hidden raid component is not supported1914*/1915if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {1916retval = FAILED;1917goto out;1918}19191920retval = mptscsih_IssueTaskMgmt(hd,1921MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,1922vdevice->vtarget->channel,1923vdevice->vtarget->id, 0, 0,1924mptscsih_get_tm_timeout(ioc));19251926out:1927printk (MYIOC_s_INFO_FMT "target reset: %s (sc=%p)\n",1928ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);19291930if (retval == 0)1931return SUCCESS;1932else1933return FAILED;1934}193519361937/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1938/**1939* mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant1940* @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to1941*1942* (linux scsi_host_template.eh_bus_reset_handler routine)1943*1944* Returns SUCCESS or FAILED.1945**/1946int1947mptscsih_bus_reset(struct scsi_cmnd * SCpnt)1948{1949MPT_SCSI_HOST *hd;1950int retval;1951VirtDevice *vdevice;1952MPT_ADAPTER *ioc;19531954/* If we can't locate our host adapter structure, return FAILED status.1955*/1956if ((hd = shost_priv(SCpnt->device->host)) == NULL){1957printk(KERN_ERR MYNAM ": bus reset: "1958"Can't locate host! (sc=%p)\n", SCpnt);1959return FAILED;1960}19611962ioc = hd->ioc;1963printk(MYIOC_s_INFO_FMT "attempting bus reset! (sc=%p)\n",1964ioc->name, SCpnt);1965scsi_print_command(SCpnt);19661967if (ioc->timeouts < -1)1968ioc->timeouts++;19691970vdevice = SCpnt->device->hostdata;1971if (!vdevice || !vdevice->vtarget)1972return SUCCESS;1973retval = mptscsih_IssueTaskMgmt(hd,1974MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,1975vdevice->vtarget->channel, 0, 0, 0,1976mptscsih_get_tm_timeout(ioc));19771978printk(MYIOC_s_INFO_FMT "bus reset: %s (sc=%p)\n",1979ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);19801981if (retval == 0)1982return SUCCESS;1983else1984return FAILED;1985}19861987/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/1988/**1989* mptscsih_host_reset - Perform a SCSI host adapter RESET (new_eh variant)1990* @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to1991*1992* (linux scsi_host_template.eh_host_reset_handler routine)1993*1994* Returns SUCCESS or FAILED.1995*/1996int1997mptscsih_host_reset(struct scsi_cmnd *SCpnt)1998{1999MPT_SCSI_HOST * hd;2000int status = SUCCESS;2001MPT_ADAPTER *ioc;2002int retval;20032004/* If we can't locate the host to reset, then we failed. */2005if ((hd = shost_priv(SCpnt->device->host)) == NULL){2006printk(KERN_ERR MYNAM ": host reset: "2007"Can't locate host! (sc=%p)\n", SCpnt);2008return FAILED;2009}20102011/* make sure we have no outstanding commands at this stage */2012mptscsih_flush_running_cmds(hd);20132014ioc = hd->ioc;2015printk(MYIOC_s_INFO_FMT "attempting host reset! (sc=%p)\n",2016ioc->name, SCpnt);20172018/* If our attempts to reset the host failed, then return a failed2019* status. The host will be taken off line by the SCSI mid-layer.2020*/2021retval = mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);2022if (retval < 0)2023status = FAILED;2024else2025status = SUCCESS;20262027printk(MYIOC_s_INFO_FMT "host reset: %s (sc=%p)\n",2028ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);20292030return status;2031}20322033static int2034mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type,2035SCSITaskMgmtReply_t *pScsiTmReply)2036{2037u16 iocstatus;2038u32 termination_count;2039int retval;20402041if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {2042retval = FAILED;2043goto out;2044}20452046DBG_DUMP_TM_REPLY_FRAME(ioc, (u32 *)pScsiTmReply);20472048iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;2049termination_count = le32_to_cpu(pScsiTmReply->TerminationCount);20502051dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT2052"TaskMgmt fw_channel = %d, fw_id = %d, task_type = 0x%02X,\n"2053"\tiocstatus = 0x%04X, loginfo = 0x%08X, response_code = 0x%02X,\n"2054"\tterm_cmnds = %d\n", ioc->name, pScsiTmReply->Bus,2055pScsiTmReply->TargetID, type, le16_to_cpu(pScsiTmReply->IOCStatus),2056le32_to_cpu(pScsiTmReply->IOCLogInfo), pScsiTmReply->ResponseCode,2057termination_count));20582059if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 &&2060pScsiTmReply->ResponseCode)2061mptscsih_taskmgmt_response_code(ioc,2062pScsiTmReply->ResponseCode);20632064if (iocstatus == MPI_IOCSTATUS_SUCCESS) {2065retval = 0;2066goto out;2067}20682069retval = FAILED;2070if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {2071if (termination_count == 1)2072retval = 0;2073goto out;2074}20752076if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||2077iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED)2078retval = 0;20792080out:2081return retval;2082}20832084/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/2085void2086mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code)2087{2088char *desc;20892090switch (response_code) {2091case MPI_SCSITASKMGMT_RSP_TM_COMPLETE:2092desc = "The task completed.";2093break;2094case MPI_SCSITASKMGMT_RSP_INVALID_FRAME:2095desc = "The IOC received an invalid frame status.";2096break;2097case MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:2098desc = "The task type is not supported.";2099break;2100case MPI_SCSITASKMGMT_RSP_TM_FAILED:2101desc = "The requested task failed.";2102break;2103case MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED:2104desc = "The task completed successfully.";2105break;2106case MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN:2107desc = "The LUN request is invalid.";2108break;2109case MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:2110desc = "The task is in the IOC queue and has not been sent to target.";2111break;2112default:2113desc = "unknown";2114break;2115}2116printk(MYIOC_s_INFO_FMT "Response Code(0x%08x): F/W: %s\n",2117ioc->name, response_code, desc);2118}2119EXPORT_SYMBOL(mptscsih_taskmgmt_response_code);21202121/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/2122/**2123* mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver2124* @ioc: Pointer to MPT_ADAPTER structure2125* @mf: Pointer to SCSI task mgmt request frame2126* @mr: Pointer to SCSI task mgmt reply frame2127*2128* This routine is called from mptbase.c::mpt_interrupt() at the completion2129* of any SCSI task management request.2130* This routine is registered with the MPT (base) driver at driver2131* load/init time via the mpt_register() API call.2132*2133* Returns 1 indicating alloc'd request frame ptr should be freed.2134**/2135int2136mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf,2137MPT_FRAME_HDR *mr)2138{2139dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT2140"TaskMgmt completed (mf=%p, mr=%p)\n", ioc->name, mf, mr));21412142ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;21432144if (!mr)2145goto out;21462147ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;2148memcpy(ioc->taskmgmt_cmds.reply, mr,2149min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));2150out:2151if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {2152mpt_clear_taskmgmt_in_progress_flag(ioc);2153ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;2154complete(&ioc->taskmgmt_cmds.done);2155if (ioc->bus_type == SAS)2156ioc->schedule_target_reset(ioc);2157return 1;2158}2159return 0;2160}21612162/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/2163/*2164* This is anyones guess quite frankly.2165*/2166int2167mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,2168sector_t capacity, int geom[])2169{2170int heads;2171int sectors;2172sector_t cylinders;2173ulong dummy;21742175heads = 64;2176sectors = 32;21772178dummy = heads * sectors;2179cylinders = capacity;2180sector_div(cylinders,dummy);21812182/*2183* Handle extended translation size for logical drives2184* > 1Gb2185*/2186if ((ulong)capacity >= 0x200000) {2187heads = 255;2188sectors = 63;2189dummy = heads * sectors;2190cylinders = capacity;2191sector_div(cylinders,dummy);2192}21932194/* return result */2195geom[0] = heads;2196geom[1] = sectors;2197geom[2] = cylinders;21982199return 0;2200}22012202/* Search IOC page 3 to determine if this is hidden physical disk2203*2204*/2205int2206mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id)2207{2208struct inactive_raid_component_info *component_info;2209int i, j;2210RaidPhysDiskPage1_t *phys_disk;2211int rc = 0;2212int num_paths;22132214if (!ioc->raid_data.pIocPg3)2215goto out;2216for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {2217if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&2218(channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {2219rc = 1;2220goto out;2221}2222}22232224if (ioc->bus_type != SAS)2225goto out;22262227/*2228* Check if dual path2229*/2230for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {2231num_paths = mpt_raid_phys_disk_get_num_paths(ioc,2232ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);2233if (num_paths < 2)2234continue;2235phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +2236(num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);2237if (!phys_disk)2238continue;2239if ((mpt_raid_phys_disk_pg1(ioc,2240ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,2241phys_disk))) {2242kfree(phys_disk);2243continue;2244}2245for (j = 0; j < num_paths; j++) {2246if ((phys_disk->Path[j].Flags &2247MPI_RAID_PHYSDISK1_FLAG_INVALID))2248continue;2249if ((phys_disk->Path[j].Flags &2250MPI_RAID_PHYSDISK1_FLAG_BROKEN))2251continue;2252if ((id == phys_disk->Path[j].PhysDiskID) &&2253(channel == phys_disk->Path[j].PhysDiskBus)) {2254rc = 1;2255kfree(phys_disk);2256goto out;2257}2258}2259kfree(phys_disk);2260}226122622263/*2264* Check inactive list for matching phys disks2265*/2266if (list_empty(&ioc->raid_data.inactive_list))2267goto out;22682269mutex_lock(&ioc->raid_data.inactive_list_mutex);2270list_for_each_entry(component_info, &ioc->raid_data.inactive_list,2271list) {2272if ((component_info->d.PhysDiskID == id) &&2273(component_info->d.PhysDiskBus == channel))2274rc = 1;2275}2276mutex_unlock(&ioc->raid_data.inactive_list_mutex);22772278out:2279return rc;2280}2281EXPORT_SYMBOL(mptscsih_is_phys_disk);22822283u82284mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)2285{2286struct inactive_raid_component_info *component_info;2287int i, j;2288RaidPhysDiskPage1_t *phys_disk;2289int rc = -ENXIO;2290int num_paths;22912292if (!ioc->raid_data.pIocPg3)2293goto out;2294for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {2295if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&2296(channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {2297rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;2298goto out;2299}2300}23012302if (ioc->bus_type != SAS)2303goto out;23042305/*2306* Check if dual path2307*/2308for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {2309num_paths = mpt_raid_phys_disk_get_num_paths(ioc,2310ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);2311if (num_paths < 2)2312continue;2313phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +2314(num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);2315if (!phys_disk)2316continue;2317if ((mpt_raid_phys_disk_pg1(ioc,2318ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,2319phys_disk))) {2320kfree(phys_disk);2321continue;2322}2323for (j = 0; j < num_paths; j++) {2324if ((phys_disk->Path[j].Flags &2325MPI_RAID_PHYSDISK1_FLAG_INVALID))2326continue;2327if ((phys_disk->Path[j].Flags &2328MPI_RAID_PHYSDISK1_FLAG_BROKEN))2329continue;2330if ((id == phys_disk->Path[j].PhysDiskID) &&2331(channel == phys_disk->Path[j].PhysDiskBus)) {2332rc = phys_disk->PhysDiskNum;2333kfree(phys_disk);2334goto out;2335}2336}2337kfree(phys_disk);2338}23392340/*2341* Check inactive list for matching phys disks2342*/2343if (list_empty(&ioc->raid_data.inactive_list))2344goto out;23452346mutex_lock(&ioc->raid_data.inactive_list_mutex);2347list_for_each_entry(component_info, &ioc->raid_data.inactive_list,2348list) {2349if ((component_info->d.PhysDiskID == id) &&2350(component_info->d.PhysDiskBus == channel))2351rc = component_info->d.PhysDiskNum;2352}2353mutex_unlock(&ioc->raid_data.inactive_list_mutex);23542355out:2356return rc;2357}2358EXPORT_SYMBOL(mptscsih_raid_id_to_num);23592360/*2361* OS entry point to allow for host driver to free allocated memory2362* Called if no device present or device being unloaded2363*/2364void2365mptscsih_slave_destroy(struct scsi_device *sdev)2366{2367struct Scsi_Host *host = sdev->host;2368MPT_SCSI_HOST *hd = shost_priv(host);2369VirtTarget *vtarget;2370VirtDevice *vdevice;2371struct scsi_target *starget;23722373starget = scsi_target(sdev);2374vtarget = starget->hostdata;2375vdevice = sdev->hostdata;2376if (!vdevice)2377return;23782379mptscsih_search_running_cmds(hd, vdevice);2380vtarget->num_luns--;2381mptscsih_synchronize_cache(hd, vdevice);2382kfree(vdevice);2383sdev->hostdata = NULL;2384}23852386/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/2387/*2388* mptscsih_change_queue_depth - This function will set a devices queue depth2389* @sdev: per scsi_device pointer2390* @qdepth: requested queue depth2391* @reason: calling context2392*2393* Adding support for new 'change_queue_depth' api.2394*/2395int2396mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)2397{2398MPT_SCSI_HOST *hd = shost_priv(sdev->host);2399VirtTarget *vtarget;2400struct scsi_target *starget;2401int max_depth;2402int tagged;2403MPT_ADAPTER *ioc = hd->ioc;24042405starget = scsi_target(sdev);2406vtarget = starget->hostdata;24072408if (reason != SCSI_QDEPTH_DEFAULT)2409return -EOPNOTSUPP;24102411if (ioc->bus_type == SPI) {2412if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))2413max_depth = 1;2414else if (sdev->type == TYPE_DISK &&2415vtarget->minSyncFactor <= MPT_ULTRA160)2416max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;2417else2418max_depth = MPT_SCSI_CMD_PER_DEV_LOW;2419} else2420max_depth = ioc->sh->can_queue;24212422if (!sdev->tagged_supported)2423max_depth = 1;24242425if (qdepth > max_depth)2426qdepth = max_depth;2427if (qdepth == 1)2428tagged = 0;2429else2430tagged = MSG_SIMPLE_TAG;24312432scsi_adjust_queue_depth(sdev, tagged, qdepth);2433return sdev->queue_depth;2434}24352436/*2437* OS entry point to adjust the queue_depths on a per-device basis.2438* Called once per device the bus scan. Use it to force the queue_depth2439* member to 1 if a device does not support Q tags.2440* Return non-zero if fails.2441*/2442int2443mptscsih_slave_configure(struct scsi_device *sdev)2444{2445struct Scsi_Host *sh = sdev->host;2446VirtTarget *vtarget;2447VirtDevice *vdevice;2448struct scsi_target *starget;2449MPT_SCSI_HOST *hd = shost_priv(sh);2450MPT_ADAPTER *ioc = hd->ioc;24512452starget = scsi_target(sdev);2453vtarget = starget->hostdata;2454vdevice = sdev->hostdata;24552456dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT2457"device @ %p, channel=%d, id=%d, lun=%d\n",2458ioc->name, sdev, sdev->channel, sdev->id, sdev->lun));2459if (ioc->bus_type == SPI)2460dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT2461"sdtr %d wdtr %d ppr %d inq length=%d\n",2462ioc->name, sdev->sdtr, sdev->wdtr,2463sdev->ppr, sdev->inquiry_len));24642465vdevice->configured_lun = 1;24662467dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT2468"Queue depth=%d, tflags=%x\n",2469ioc->name, sdev->queue_depth, vtarget->tflags));24702471if (ioc->bus_type == SPI)2472dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT2473"negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",2474ioc->name, vtarget->negoFlags, vtarget->maxOffset,2475vtarget->minSyncFactor));24762477mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH,2478SCSI_QDEPTH_DEFAULT);2479dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT2480"tagged %d, simple %d, ordered %d\n",2481ioc->name,sdev->tagged_supported, sdev->simple_tags,2482sdev->ordered_tags));24832484blk_queue_dma_alignment (sdev->request_queue, 512 - 1);24852486return 0;2487}24882489/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/2490/*2491* Private routines...2492*/24932494/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/2495/* Utility function to copy sense data from the scsi_cmnd buffer2496* to the FC and SCSI target structures.2497*2498*/2499static void2500mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply)2501{2502VirtDevice *vdevice;2503SCSIIORequest_t *pReq;2504u32 sense_count = le32_to_cpu(pScsiReply->SenseCount);2505MPT_ADAPTER *ioc = hd->ioc;25062507/* Get target structure2508*/2509pReq = (SCSIIORequest_t *) mf;2510vdevice = sc->device->hostdata;25112512if (sense_count) {2513u8 *sense_data;2514int req_index;25152516/* Copy the sense received into the scsi command block. */2517req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);2518sense_data = ((u8 *)ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));2519memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc));25202521/* Log SMART data (asc = 0x5D, non-IM case only) if required.2522*/2523if ((ioc->events) && (ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {2524if ((sense_data[12] == 0x5D) && (vdevice->vtarget->raidVolume == 0)) {2525int idx;25262527idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;2528ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE;2529ioc->events[idx].eventContext = ioc->eventContext;25302531ioc->events[idx].data[0] = (pReq->LUN[1] << 24) |2532(MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) |2533(sc->device->channel << 8) | sc->device->id;25342535ioc->events[idx].data[1] = (sense_data[13] << 8) | sense_data[12];25362537ioc->eventContext++;2538if (ioc->pcidev->vendor ==2539PCI_VENDOR_ID_IBM) {2540mptscsih_issue_sep_command(ioc,2541vdevice->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);2542vdevice->vtarget->tflags |=2543MPT_TARGET_FLAGS_LED_ON;2544}2545}2546}2547} else {2548dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hmmm... SenseData len=0! (?)\n",2549ioc->name));2550}2551}25522553/**2554* mptscsih_get_scsi_lookup - retrieves scmd entry2555* @ioc: Pointer to MPT_ADAPTER structure2556* @i: index into the array2557*2558* Returns the scsi_cmd pointer2559*/2560struct scsi_cmnd *2561mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i)2562{2563unsigned long flags;2564struct scsi_cmnd *scmd;25652566spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);2567scmd = ioc->ScsiLookup[i];2568spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);25692570return scmd;2571}2572EXPORT_SYMBOL(mptscsih_get_scsi_lookup);25732574/**2575* mptscsih_getclear_scsi_lookup - retrieves and clears scmd entry from ScsiLookup[] array list2576* @ioc: Pointer to MPT_ADAPTER structure2577* @i: index into the array2578*2579* Returns the scsi_cmd pointer2580*2581**/2582static struct scsi_cmnd *2583mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i)2584{2585unsigned long flags;2586struct scsi_cmnd *scmd;25872588spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);2589scmd = ioc->ScsiLookup[i];2590ioc->ScsiLookup[i] = NULL;2591spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);25922593return scmd;2594}25952596/**2597* mptscsih_set_scsi_lookup - write a scmd entry into the ScsiLookup[] array list2598*2599* @ioc: Pointer to MPT_ADAPTER structure2600* @i: index into the array2601* @scmd: scsi_cmnd pointer2602*2603**/2604static void2605mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd)2606{2607unsigned long flags;26082609spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);2610ioc->ScsiLookup[i] = scmd;2611spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);2612}26132614/**2615* SCPNT_TO_LOOKUP_IDX - searches for a given scmd in the ScsiLookup[] array list2616* @ioc: Pointer to MPT_ADAPTER structure2617* @sc: scsi_cmnd pointer2618*/2619static int2620SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *sc)2621{2622unsigned long flags;2623int i, index=-1;26242625spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);2626for (i = 0; i < ioc->req_depth; i++) {2627if (ioc->ScsiLookup[i] == sc) {2628index = i;2629goto out;2630}2631}26322633out:2634spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);2635return index;2636}26372638/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/2639int2640mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)2641{2642MPT_SCSI_HOST *hd;26432644if (ioc->sh == NULL || shost_priv(ioc->sh) == NULL)2645return 0;26462647hd = shost_priv(ioc->sh);2648switch (reset_phase) {2649case MPT_IOC_SETUP_RESET:2650dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT2651"%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));2652break;2653case MPT_IOC_PRE_RESET:2654dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT2655"%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));2656mptscsih_flush_running_cmds(hd);2657break;2658case MPT_IOC_POST_RESET:2659dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT2660"%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));2661if (ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING) {2662ioc->internal_cmds.status |=2663MPT_MGMT_STATUS_DID_IOCRESET;2664complete(&ioc->internal_cmds.done);2665}2666break;2667default:2668break;2669}2670return 1; /* currently means nothing really */2671}26722673/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/2674int2675mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)2676{2677u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;26782679devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT2680"MPT event (=%02Xh) routed to SCSI host driver!\n",2681ioc->name, event));26822683if ((event == MPI_EVENT_IOC_BUS_RESET ||2684event == MPI_EVENT_EXT_BUS_RESET) &&2685(ioc->bus_type == SPI) && (ioc->soft_resets < -1))2686ioc->soft_resets++;26872688return 1; /* currently means nothing really */2689}26902691/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/2692/*2693* Bus Scan and Domain Validation functionality ...2694*/26952696/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/2697/*2698* mptscsih_scandv_complete - Scan and DV callback routine registered2699* to Fustion MPT (base) driver.2700*2701* @ioc: Pointer to MPT_ADAPTER structure2702* @mf: Pointer to original MPT request frame2703* @mr: Pointer to MPT reply frame (NULL if TurboReply)2704*2705* This routine is called from mpt.c::mpt_interrupt() at the completion2706* of any SCSI IO request.2707* This routine is registered with the Fusion MPT (base) driver at driver2708* load/init time via the mpt_register() API call.2709*2710* Returns 1 indicating alloc'd request frame ptr should be freed.2711*2712* Remark: Sets a completion code and (possibly) saves sense data2713* in the IOC member localReply structure.2714* Used ONLY for DV and other internal commands.2715*/2716int2717mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,2718MPT_FRAME_HDR *reply)2719{2720SCSIIORequest_t *pReq;2721SCSIIOReply_t *pReply;2722u8 cmd;2723u16 req_idx;2724u8 *sense_data;2725int sz;27262727ioc->internal_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;2728ioc->internal_cmds.completion_code = MPT_SCANDV_GOOD;2729if (!reply)2730goto out;27312732pReply = (SCSIIOReply_t *) reply;2733pReq = (SCSIIORequest_t *) req;2734ioc->internal_cmds.completion_code =2735mptscsih_get_completion_code(ioc, req, reply);2736ioc->internal_cmds.status |= MPT_MGMT_STATUS_RF_VALID;2737memcpy(ioc->internal_cmds.reply, reply,2738min(MPT_DEFAULT_FRAME_SIZE, 4 * reply->u.reply.MsgLength));2739cmd = reply->u.hdr.Function;2740if (((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||2741(cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) &&2742(pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)) {2743req_idx = le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);2744sense_data = ((u8 *)ioc->sense_buf_pool +2745(req_idx * MPT_SENSE_BUFFER_ALLOC));2746sz = min_t(int, pReq->SenseBufferLength,2747MPT_SENSE_BUFFER_ALLOC);2748memcpy(ioc->internal_cmds.sense, sense_data, sz);2749}2750out:2751if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING))2752return 0;2753ioc->internal_cmds.status &= ~MPT_MGMT_STATUS_PENDING;2754complete(&ioc->internal_cmds.done);2755return 1;2756}275727582759/**2760* mptscsih_get_completion_code - get completion code from MPT request2761* @ioc: Pointer to MPT_ADAPTER structure2762* @req: Pointer to original MPT request frame2763* @reply: Pointer to MPT reply frame (NULL if TurboReply)2764*2765**/2766static int2767mptscsih_get_completion_code(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,2768MPT_FRAME_HDR *reply)2769{2770SCSIIOReply_t *pReply;2771MpiRaidActionReply_t *pr;2772u8 scsi_status;2773u16 status;2774int completion_code;27752776pReply = (SCSIIOReply_t *)reply;2777status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;2778scsi_status = pReply->SCSIStatus;27792780devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT2781"IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh,"2782"IOCLogInfo=%08xh\n", ioc->name, status, pReply->SCSIState,2783scsi_status, le32_to_cpu(pReply->IOCLogInfo)));27842785switch (status) {27862787case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */2788completion_code = MPT_SCANDV_SELECTION_TIMEOUT;2789break;27902791case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */2792case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */2793case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */2794case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */2795completion_code = MPT_SCANDV_DID_RESET;2796break;27972798case MPI_IOCSTATUS_BUSY:2799case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:2800completion_code = MPT_SCANDV_BUSY;2801break;28022803case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */2804case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */2805case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */2806if (pReply->Function == MPI_FUNCTION_CONFIG) {2807completion_code = MPT_SCANDV_GOOD;2808} else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {2809pr = (MpiRaidActionReply_t *)reply;2810if (le16_to_cpu(pr->ActionStatus) ==2811MPI_RAID_ACTION_ASTATUS_SUCCESS)2812completion_code = MPT_SCANDV_GOOD;2813else2814completion_code = MPT_SCANDV_SOME_ERROR;2815} else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)2816completion_code = MPT_SCANDV_SENSE;2817else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {2818if (req->u.scsireq.CDB[0] == INQUIRY)2819completion_code = MPT_SCANDV_ISSUE_SENSE;2820else2821completion_code = MPT_SCANDV_DID_RESET;2822} else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)2823completion_code = MPT_SCANDV_DID_RESET;2824else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)2825completion_code = MPT_SCANDV_DID_RESET;2826else if (scsi_status == MPI_SCSI_STATUS_BUSY)2827completion_code = MPT_SCANDV_BUSY;2828else2829completion_code = MPT_SCANDV_GOOD;2830break;28312832case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */2833if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)2834completion_code = MPT_SCANDV_DID_RESET;2835else2836completion_code = MPT_SCANDV_SOME_ERROR;2837break;2838default:2839completion_code = MPT_SCANDV_SOME_ERROR;2840break;28412842} /* switch(status) */28432844devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT2845" completionCode set to %08xh\n", ioc->name, completion_code));2846return completion_code;2847}28482849/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/2850/**2851* mptscsih_do_cmd - Do internal command.2852* @hd: MPT_SCSI_HOST pointer2853* @io: INTERNAL_CMD pointer.2854*2855* Issue the specified internally generated command and do command2856* specific cleanup. For bus scan / DV only.2857* NOTES: If command is Inquiry and status is good,2858* initialize a target structure, save the data2859*2860* Remark: Single threaded access only.2861*2862* Return:2863* < 0 if an illegal command or no resources2864*2865* 0 if good2866*2867* > 0 if command complete but some type of completion error.2868*/2869static int2870mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)2871{2872MPT_FRAME_HDR *mf;2873SCSIIORequest_t *pScsiReq;2874int my_idx, ii, dir;2875int timeout;2876char cmdLen;2877char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};2878u8 cmd = io->cmd;2879MPT_ADAPTER *ioc = hd->ioc;2880int ret = 0;2881unsigned long timeleft;2882unsigned long flags;28832884/* don't send internal command during diag reset */2885spin_lock_irqsave(&ioc->taskmgmt_lock, flags);2886if (ioc->ioc_reset_in_progress) {2887spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);2888dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT2889"%s: busy with host reset\n", ioc->name, __func__));2890return MPT_SCANDV_BUSY;2891}2892spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);28932894mutex_lock(&ioc->internal_cmds.mutex);28952896/* Set command specific information2897*/2898switch (cmd) {2899case INQUIRY:2900cmdLen = 6;2901dir = MPI_SCSIIO_CONTROL_READ;2902CDB[0] = cmd;2903CDB[4] = io->size;2904timeout = 10;2905break;29062907case TEST_UNIT_READY:2908cmdLen = 6;2909dir = MPI_SCSIIO_CONTROL_READ;2910timeout = 10;2911break;29122913case START_STOP:2914cmdLen = 6;2915dir = MPI_SCSIIO_CONTROL_READ;2916CDB[0] = cmd;2917CDB[4] = 1; /*Spin up the disk */2918timeout = 15;2919break;29202921case REQUEST_SENSE:2922cmdLen = 6;2923CDB[0] = cmd;2924CDB[4] = io->size;2925dir = MPI_SCSIIO_CONTROL_READ;2926timeout = 10;2927break;29282929case READ_BUFFER:2930cmdLen = 10;2931dir = MPI_SCSIIO_CONTROL_READ;2932CDB[0] = cmd;2933if (io->flags & MPT_ICFLAG_ECHO) {2934CDB[1] = 0x0A;2935} else {2936CDB[1] = 0x02;2937}29382939if (io->flags & MPT_ICFLAG_BUF_CAP) {2940CDB[1] |= 0x01;2941}2942CDB[6] = (io->size >> 16) & 0xFF;2943CDB[7] = (io->size >> 8) & 0xFF;2944CDB[8] = io->size & 0xFF;2945timeout = 10;2946break;29472948case WRITE_BUFFER:2949cmdLen = 10;2950dir = MPI_SCSIIO_CONTROL_WRITE;2951CDB[0] = cmd;2952if (io->flags & MPT_ICFLAG_ECHO) {2953CDB[1] = 0x0A;2954} else {2955CDB[1] = 0x02;2956}2957CDB[6] = (io->size >> 16) & 0xFF;2958CDB[7] = (io->size >> 8) & 0xFF;2959CDB[8] = io->size & 0xFF;2960timeout = 10;2961break;29622963case RESERVE:2964cmdLen = 6;2965dir = MPI_SCSIIO_CONTROL_READ;2966CDB[0] = cmd;2967timeout = 10;2968break;29692970case RELEASE:2971cmdLen = 6;2972dir = MPI_SCSIIO_CONTROL_READ;2973CDB[0] = cmd;2974timeout = 10;2975break;29762977case SYNCHRONIZE_CACHE:2978cmdLen = 10;2979dir = MPI_SCSIIO_CONTROL_READ;2980CDB[0] = cmd;2981// CDB[1] = 0x02; /* set immediate bit */2982timeout = 10;2983break;29842985default:2986/* Error Case */2987ret = -EFAULT;2988goto out;2989}29902991/* Get and Populate a free Frame2992* MsgContext set in mpt_get_msg_frame call2993*/2994if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {2995dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: No msg frames!\n",2996ioc->name, __func__));2997ret = MPT_SCANDV_BUSY;2998goto out;2999}30003001pScsiReq = (SCSIIORequest_t *) mf;30023003/* Get the request index */3004my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);3005ADD_INDEX_LOG(my_idx); /* for debug */30063007if (io->flags & MPT_ICFLAG_PHYS_DISK) {3008pScsiReq->TargetID = io->physDiskNum;3009pScsiReq->Bus = 0;3010pScsiReq->ChainOffset = 0;3011pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;3012} else {3013pScsiReq->TargetID = io->id;3014pScsiReq->Bus = io->channel;3015pScsiReq->ChainOffset = 0;3016pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;3017}30183019pScsiReq->CDBLength = cmdLen;3020pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;30213022pScsiReq->Reserved = 0;30233024pScsiReq->MsgFlags = mpt_msg_flags(ioc);3025/* MsgContext set in mpt_get_msg_fram call */30263027int_to_scsilun(io->lun, (struct scsi_lun *)pScsiReq->LUN);30283029if (io->flags & MPT_ICFLAG_TAGGED_CMD)3030pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);3031else3032pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);30333034if (cmd == REQUEST_SENSE) {3035pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);3036devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT3037"%s: Untagged! 0x%02x\n", ioc->name, __func__, cmd));3038}30393040for (ii = 0; ii < 16; ii++)3041pScsiReq->CDB[ii] = CDB[ii];30423043pScsiReq->DataLength = cpu_to_le32(io->size);3044pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma3045+ (my_idx * MPT_SENSE_BUFFER_ALLOC));30463047devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT3048"%s: Sending Command 0x%02x for fw_channel=%d fw_id=%d lun=%d\n",3049ioc->name, __func__, cmd, io->channel, io->id, io->lun));30503051if (dir == MPI_SCSIIO_CONTROL_READ)3052ioc->add_sge((char *) &pScsiReq->SGL,3053MPT_SGE_FLAGS_SSIMPLE_READ | io->size, io->data_dma);3054else3055ioc->add_sge((char *) &pScsiReq->SGL,3056MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size, io->data_dma);30573058INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status)3059mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);3060timeleft = wait_for_completion_timeout(&ioc->internal_cmds.done,3061timeout*HZ);3062if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {3063ret = MPT_SCANDV_DID_RESET;3064dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT3065"%s: TIMED OUT for cmd=0x%02x\n", ioc->name, __func__,3066cmd));3067if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {3068mpt_free_msg_frame(ioc, mf);3069goto out;3070}3071if (!timeleft) {3072printk(MYIOC_s_WARN_FMT3073"Issuing Reset from %s!! doorbell=0x%08xh"3074" cmd=0x%02x\n",3075ioc->name, __func__, mpt_GetIocState(ioc, 0),3076cmd);3077mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);3078mpt_free_msg_frame(ioc, mf);3079}3080goto out;3081}30823083ret = ioc->internal_cmds.completion_code;3084devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: success, rc=0x%02x\n",3085ioc->name, __func__, ret));30863087out:3088CLEAR_MGMT_STATUS(ioc->internal_cmds.status)3089mutex_unlock(&ioc->internal_cmds.mutex);3090return ret;3091}30923093/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/3094/**3095* mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks.3096* @hd: Pointer to a SCSI HOST structure3097* @vdevice: virtual target device3098*3099* Uses the ISR, but with special processing.3100* MUST be single-threaded.3101*3102*/3103static void3104mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)3105{3106INTERNAL_CMD iocmd;31073108/* Ignore hidden raid components, this is handled when the command3109* is sent to the volume3110*/3111if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)3112return;31133114if (vdevice->vtarget->type != TYPE_DISK || vdevice->vtarget->deleted ||3115!vdevice->configured_lun)3116return;31173118/* Following parameters will not change3119* in this routine.3120*/3121iocmd.cmd = SYNCHRONIZE_CACHE;3122iocmd.flags = 0;3123iocmd.physDiskNum = -1;3124iocmd.data = NULL;3125iocmd.data_dma = -1;3126iocmd.size = 0;3127iocmd.rsvd = iocmd.rsvd2 = 0;3128iocmd.channel = vdevice->vtarget->channel;3129iocmd.id = vdevice->vtarget->id;3130iocmd.lun = vdevice->lun;31313132mptscsih_do_cmd(hd, &iocmd);3133}31343135static ssize_t3136mptscsih_version_fw_show(struct device *dev, struct device_attribute *attr,3137char *buf)3138{3139struct Scsi_Host *host = class_to_shost(dev);3140MPT_SCSI_HOST *hd = shost_priv(host);3141MPT_ADAPTER *ioc = hd->ioc;31423143return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",3144(ioc->facts.FWVersion.Word & 0xFF000000) >> 24,3145(ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,3146(ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,3147ioc->facts.FWVersion.Word & 0x000000FF);3148}3149static DEVICE_ATTR(version_fw, S_IRUGO, mptscsih_version_fw_show, NULL);31503151static ssize_t3152mptscsih_version_bios_show(struct device *dev, struct device_attribute *attr,3153char *buf)3154{3155struct Scsi_Host *host = class_to_shost(dev);3156MPT_SCSI_HOST *hd = shost_priv(host);3157MPT_ADAPTER *ioc = hd->ioc;31583159return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",3160(ioc->biosVersion & 0xFF000000) >> 24,3161(ioc->biosVersion & 0x00FF0000) >> 16,3162(ioc->biosVersion & 0x0000FF00) >> 8,3163ioc->biosVersion & 0x000000FF);3164}3165static DEVICE_ATTR(version_bios, S_IRUGO, mptscsih_version_bios_show, NULL);31663167static ssize_t3168mptscsih_version_mpi_show(struct device *dev, struct device_attribute *attr,3169char *buf)3170{3171struct Scsi_Host *host = class_to_shost(dev);3172MPT_SCSI_HOST *hd = shost_priv(host);3173MPT_ADAPTER *ioc = hd->ioc;31743175return snprintf(buf, PAGE_SIZE, "%03x\n", ioc->facts.MsgVersion);3176}3177static DEVICE_ATTR(version_mpi, S_IRUGO, mptscsih_version_mpi_show, NULL);31783179static ssize_t3180mptscsih_version_product_show(struct device *dev,3181struct device_attribute *attr,3182char *buf)3183{3184struct Scsi_Host *host = class_to_shost(dev);3185MPT_SCSI_HOST *hd = shost_priv(host);3186MPT_ADAPTER *ioc = hd->ioc;31873188return snprintf(buf, PAGE_SIZE, "%s\n", ioc->prod_name);3189}3190static DEVICE_ATTR(version_product, S_IRUGO,3191mptscsih_version_product_show, NULL);31923193static ssize_t3194mptscsih_version_nvdata_persistent_show(struct device *dev,3195struct device_attribute *attr,3196char *buf)3197{3198struct Scsi_Host *host = class_to_shost(dev);3199MPT_SCSI_HOST *hd = shost_priv(host);3200MPT_ADAPTER *ioc = hd->ioc;32013202return snprintf(buf, PAGE_SIZE, "%02xh\n",3203ioc->nvdata_version_persistent);3204}3205static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,3206mptscsih_version_nvdata_persistent_show, NULL);32073208static ssize_t3209mptscsih_version_nvdata_default_show(struct device *dev,3210struct device_attribute *attr, char *buf)3211{3212struct Scsi_Host *host = class_to_shost(dev);3213MPT_SCSI_HOST *hd = shost_priv(host);3214MPT_ADAPTER *ioc = hd->ioc;32153216return snprintf(buf, PAGE_SIZE, "%02xh\n",ioc->nvdata_version_default);3217}3218static DEVICE_ATTR(version_nvdata_default, S_IRUGO,3219mptscsih_version_nvdata_default_show, NULL);32203221static ssize_t3222mptscsih_board_name_show(struct device *dev, struct device_attribute *attr,3223char *buf)3224{3225struct Scsi_Host *host = class_to_shost(dev);3226MPT_SCSI_HOST *hd = shost_priv(host);3227MPT_ADAPTER *ioc = hd->ioc;32283229return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_name);3230}3231static DEVICE_ATTR(board_name, S_IRUGO, mptscsih_board_name_show, NULL);32323233static ssize_t3234mptscsih_board_assembly_show(struct device *dev,3235struct device_attribute *attr, char *buf)3236{3237struct Scsi_Host *host = class_to_shost(dev);3238MPT_SCSI_HOST *hd = shost_priv(host);3239MPT_ADAPTER *ioc = hd->ioc;32403241return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_assembly);3242}3243static DEVICE_ATTR(board_assembly, S_IRUGO,3244mptscsih_board_assembly_show, NULL);32453246static ssize_t3247mptscsih_board_tracer_show(struct device *dev, struct device_attribute *attr,3248char *buf)3249{3250struct Scsi_Host *host = class_to_shost(dev);3251MPT_SCSI_HOST *hd = shost_priv(host);3252MPT_ADAPTER *ioc = hd->ioc;32533254return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_tracer);3255}3256static DEVICE_ATTR(board_tracer, S_IRUGO,3257mptscsih_board_tracer_show, NULL);32583259static ssize_t3260mptscsih_io_delay_show(struct device *dev, struct device_attribute *attr,3261char *buf)3262{3263struct Scsi_Host *host = class_to_shost(dev);3264MPT_SCSI_HOST *hd = shost_priv(host);3265MPT_ADAPTER *ioc = hd->ioc;32663267return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);3268}3269static DEVICE_ATTR(io_delay, S_IRUGO,3270mptscsih_io_delay_show, NULL);32713272static ssize_t3273mptscsih_device_delay_show(struct device *dev, struct device_attribute *attr,3274char *buf)3275{3276struct Scsi_Host *host = class_to_shost(dev);3277MPT_SCSI_HOST *hd = shost_priv(host);3278MPT_ADAPTER *ioc = hd->ioc;32793280return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);3281}3282static DEVICE_ATTR(device_delay, S_IRUGO,3283mptscsih_device_delay_show, NULL);32843285static ssize_t3286mptscsih_debug_level_show(struct device *dev, struct device_attribute *attr,3287char *buf)3288{3289struct Scsi_Host *host = class_to_shost(dev);3290MPT_SCSI_HOST *hd = shost_priv(host);3291MPT_ADAPTER *ioc = hd->ioc;32923293return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->debug_level);3294}3295static ssize_t3296mptscsih_debug_level_store(struct device *dev, struct device_attribute *attr,3297const char *buf, size_t count)3298{3299struct Scsi_Host *host = class_to_shost(dev);3300MPT_SCSI_HOST *hd = shost_priv(host);3301MPT_ADAPTER *ioc = hd->ioc;3302int val = 0;33033304if (sscanf(buf, "%x", &val) != 1)3305return -EINVAL;33063307ioc->debug_level = val;3308printk(MYIOC_s_INFO_FMT "debug_level=%08xh\n",3309ioc->name, ioc->debug_level);3310return strlen(buf);3311}3312static DEVICE_ATTR(debug_level, S_IRUGO | S_IWUSR,3313mptscsih_debug_level_show, mptscsih_debug_level_store);33143315struct device_attribute *mptscsih_host_attrs[] = {3316&dev_attr_version_fw,3317&dev_attr_version_bios,3318&dev_attr_version_mpi,3319&dev_attr_version_product,3320&dev_attr_version_nvdata_persistent,3321&dev_attr_version_nvdata_default,3322&dev_attr_board_name,3323&dev_attr_board_assembly,3324&dev_attr_board_tracer,3325&dev_attr_io_delay,3326&dev_attr_device_delay,3327&dev_attr_debug_level,3328NULL,3329};33303331EXPORT_SYMBOL(mptscsih_host_attrs);33323333EXPORT_SYMBOL(mptscsih_remove);3334EXPORT_SYMBOL(mptscsih_shutdown);3335#ifdef CONFIG_PM3336EXPORT_SYMBOL(mptscsih_suspend);3337EXPORT_SYMBOL(mptscsih_resume);3338#endif3339EXPORT_SYMBOL(mptscsih_proc_info);3340EXPORT_SYMBOL(mptscsih_info);3341EXPORT_SYMBOL(mptscsih_qcmd);3342EXPORT_SYMBOL(mptscsih_slave_destroy);3343EXPORT_SYMBOL(mptscsih_slave_configure);3344EXPORT_SYMBOL(mptscsih_abort);3345EXPORT_SYMBOL(mptscsih_dev_reset);3346EXPORT_SYMBOL(mptscsih_bus_reset);3347EXPORT_SYMBOL(mptscsih_host_reset);3348EXPORT_SYMBOL(mptscsih_bios_param);3349EXPORT_SYMBOL(mptscsih_io_done);3350EXPORT_SYMBOL(mptscsih_taskmgmt_complete);3351EXPORT_SYMBOL(mptscsih_scandv_complete);3352EXPORT_SYMBOL(mptscsih_event_process);3353EXPORT_SYMBOL(mptscsih_ioc_reset);3354EXPORT_SYMBOL(mptscsih_change_queue_depth);33553356/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/335733583359