blob: 0e402eb957165c11eed6d4a96f3150e2fab3db45 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/message/fusion/mptscsih.c
Prakash, Sathyaf36789e2007-08-14 16:22:54 +05303 * For use with LSI PCI chip/adapter(s)
4 * running LSI Fusion MPT (Message Passing Technology) firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Prakash, Sathyacddc0ab2008-05-21 00:56:41 +05306 * Copyright (c) 1999-2008 LSI Corporation
Eric Moore16d20102007-06-13 16:31:07 -06007 * (mailto:DL-MPTFusionLinux@lsi.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
11/*
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; version 2 of the License.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 NO WARRANTY
22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
26 solely responsible for determining the appropriateness of using and
27 distributing the Program and assumes all risks associated with its
28 exercise of rights under this Agreement, including but not limited to
29 the risks and costs of program errors, damage to or loss of data,
30 programs or equipment, and unavailability or interruption of operations.
31
32 DISCLAIMER OF LIABILITY
33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
37 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
38 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
39 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40
41 You should have received a copy of the GNU General Public License
42 along with this program; if not, write to the Free Software
43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44*/
45/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/module.h>
48#include <linux/kernel.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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include <linux/workqueue.h>
57
58#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>
Moore, Eric Deane0fc15b2005-09-15 13:17:14 -060063#include <scsi/scsi_dbg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65#include "mptbase.h"
66#include "mptscsih.h"
Eric Moorebf451522006-07-11 17:25:35 -060067#include "lsi/mpi_log_sas.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
70#define my_NAME "Fusion MPT SCSI Host driver"
71#define my_VERSION MPT_LINUX_VERSION_COMMON
72#define MYNAM "mptscsih"
73
74MODULE_AUTHOR(MODULEAUTHOR);
75MODULE_DESCRIPTION(my_NAME);
76MODULE_LICENSE("GPL");
Eric Moore9f4203b2007-01-04 20:47:47 -070077MODULE_VERSION(my_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070080/*
81 * Other private/forward protos...
82 */
Kashyap, Desaidb7051b2009-05-29 16:56:59 +053083struct scsi_cmnd *mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);
Eric Mooree8206382007-09-29 10:16:53 -060084static 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);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -040087int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static void mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -040089int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91static int mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
92 SCSIIORequest_t *pReq, int req_idx);
93static void mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -040094static void mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +053096int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id,
97 int lun, int ctx2abort, ulong timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -040099int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
100int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Kashyap, Desaie7deff32009-05-29 16:46:07 +0530102void
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +0530103mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code);
Kashyap, Desai37c60f32009-05-29 16:44:06 +0530104static int mptscsih_get_completion_code(MPT_ADAPTER *ioc,
105 MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400106int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
Moore, Eric Deanc7c82982005-11-16 18:54:25 -0700108static void mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +0530110static int
111mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type,
112 SCSITaskMgmtReply_t *pScsiTmReply);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400113void mptscsih_remove(struct pci_dev *);
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -0700114void mptscsih_shutdown(struct pci_dev *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#ifdef CONFIG_PM
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400116int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);
117int mptscsih_resume(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#endif
119
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +0900120#define SNS_LEN(scp) SCSI_SENSE_BUFFERSIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
124/*
125 * mptscsih_getFreeChainBuffer - Function to get a free chain
126 * from the MPT_SCSI_HOST FreeChainQ.
127 * @ioc: Pointer to MPT_ADAPTER structure
128 * @req_idx: Index of the SCSI IO request frame. (output)
129 *
130 * return SUCCESS or FAILED
131 */
132static inline int
133mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)
134{
135 MPT_FRAME_HDR *chainBuf;
136 unsigned long flags;
137 int rc;
138 int chain_idx;
139
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530140 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "getFreeChainBuffer called\n",
Eric Moore29dd3602007-09-14 18:46:51 -0600141 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 spin_lock_irqsave(&ioc->FreeQlock, flags);
143 if (!list_empty(&ioc->FreeChainQ)) {
144 int offset;
145
146 chainBuf = list_entry(ioc->FreeChainQ.next, MPT_FRAME_HDR,
147 u.frame.linkage.list);
148 list_del(&chainBuf->u.frame.linkage.list);
149 offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;
150 chain_idx = offset / ioc->req_sz;
151 rc = SUCCESS;
Eric Moore29dd3602007-09-14 18:46:51 -0600152 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT
153 "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
154 ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 } else {
156 rc = FAILED;
157 chain_idx = MPT_HOST_NO_CHAIN;
Eric Moore29dd3602007-09-14 18:46:51 -0600158 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n",
159 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 }
161 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
162
163 *retIndex = chain_idx;
164 return rc;
165} /* mptscsih_getFreeChainBuffer() */
166
167/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
168/*
169 * mptscsih_AddSGE - Add a SGE (plus chain buffers) to the
170 * SCSIIORequest_t Message Frame.
171 * @ioc: Pointer to MPT_ADAPTER structure
172 * @SCpnt: Pointer to scsi_cmnd structure
173 * @pReq: Pointer to SCSIIORequest_t structure
174 *
175 * Returns ...
176 */
177static int
178mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
179 SCSIIORequest_t *pReq, int req_idx)
180{
181 char *psge;
182 char *chainSge;
183 struct scatterlist *sg;
184 int frm_sz;
185 int sges_left, sg_done;
186 int chain_idx = MPT_HOST_NO_CHAIN;
187 int sgeOffset;
188 int numSgeSlots, numSgeThisFrame;
189 u32 sgflags, sgdir, thisxfer = 0;
190 int chain_dma_off = 0;
191 int newIndex;
192 int ii;
193 dma_addr_t v2;
194 u32 RequestNB;
195
196 sgdir = le32_to_cpu(pReq->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK;
197 if (sgdir == MPI_SCSIIO_CONTROL_WRITE) {
198 sgdir = MPT_TRANSFER_HOST_TO_IOC;
199 } else {
200 sgdir = MPT_TRANSFER_IOC_TO_HOST;
201 }
202
203 psge = (char *) &pReq->SGL;
204 frm_sz = ioc->req_sz;
205
206 /* Map the data portion, if any.
207 * sges_left = 0 if no data transfer.
208 */
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900209 sges_left = scsi_dma_map(SCpnt);
210 if (sges_left < 0)
211 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 /* Handle the SG case.
214 */
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900215 sg = scsi_sglist(SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 sg_done = 0;
217 sgeOffset = sizeof(SCSIIORequest_t) - sizeof(SGE_IO_UNION);
218 chainSge = NULL;
219
220 /* Prior to entering this loop - the following must be set
221 * 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 */
225
226nextSGEset:
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +0530227 numSgeSlots = ((frm_sz - sgeOffset) / ioc->SGE_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots;
229
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +0530230 sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | sgdir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 /* Get first (num - 1) SG elements
233 * Skip any SG entries with a length of 0
234 * NOTE: at finish, sg and psge pointed to NEXT data/location positions
235 */
236 for (ii=0; ii < (numSgeThisFrame-1); ii++) {
237 thisxfer = sg_dma_len(sg);
238 if (thisxfer == 0) {
Kashyap, Desai2f187862009-05-29 16:52:37 +0530239 /* Get next SG element from the OS */
240 sg = sg_next(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 sg_done++;
242 continue;
243 }
244
245 v2 = sg_dma_address(sg);
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +0530246 ioc->add_sge(psge, sgflags | thisxfer, v2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Kashyap, Desai2f187862009-05-29 16:52:37 +0530248 /* Get next SG element from the OS */
249 sg = sg_next(sg);
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +0530250 psge += ioc->SGE_size;
251 sgeOffset += ioc->SGE_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 sg_done++;
253 }
254
255 if (numSgeThisFrame == sges_left) {
256 /* Add last element, end of buffer and end of list flags.
257 */
258 sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT |
259 MPT_SGE_FLAGS_END_OF_BUFFER |
260 MPT_SGE_FLAGS_END_OF_LIST;
261
262 /* Add last SGE and set termination flags.
263 * Note: Last SGE may have a length of 0 - which should be ok.
264 */
265 thisxfer = sg_dma_len(sg);
266
267 v2 = sg_dma_address(sg);
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +0530268 ioc->add_sge(psge, sgflags | thisxfer, v2);
269 sgeOffset += ioc->SGE_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 sg_done++;
271
272 if (chainSge) {
273 /* The current buffer is a chain buffer,
274 * but there is not another one.
275 * Update the chain element
276 * Offset and Length fields.
277 */
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +0530278 ioc->add_chain((char *)chainSge, 0, sgeOffset,
279 ioc->ChainBufferDMA + chain_dma_off);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 } else {
281 /* The current buffer is the original MF
282 * and there is no Chain buffer.
283 */
284 pReq->ChainOffset = 0;
285 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530286 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
288 ioc->RequestNB[req_idx] = RequestNB;
289 }
290 } else {
291 /* At least one chain buffer is needed.
292 * Complete the first MF
293 * - last SGE element, set the LastElement bit
294 * - set ChainOffset (words) for orig MF
295 * (OR finish previous MF chain buffer)
296 * - update MFStructPtr ChainIndex
297 * - Populate chain element
298 * Also
299 * Loop until done.
300 */
301
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530302 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SG: Chain Required! sg done %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 ioc->name, sg_done));
304
305 /* Set LAST_ELEMENT flag for last non-chain element
306 * in the buffer. Since psge points at the NEXT
307 * SGE element, go back one SGE element, update the flags
308 * and reset the pointer. (Note: sgflags & thisxfer are already
309 * set properly).
310 */
311 if (sg_done) {
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +0530312 u32 *ptmp = (u32 *) (psge - ioc->SGE_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 sgflags = le32_to_cpu(*ptmp);
314 sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT;
315 *ptmp = cpu_to_le32(sgflags);
316 }
317
318 if (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 (must
322 * include chain element size) fields.
323 * Old chain element is now complete.
324 */
325 u8 nextChain = (u8) (sgeOffset >> 2);
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +0530326 sgeOffset += ioc->SGE_size;
327 ioc->add_chain((char *)chainSge, nextChain, sgeOffset,
328 ioc->ChainBufferDMA + chain_dma_off);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 } 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 */
334 pReq->ChainOffset = (u8) (sgeOffset >> 2);
335 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530336 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 ioc->RequestNB[req_idx] = RequestNB;
338 }
339
340 sges_left -= sg_done;
341
342
343 /* NOTE: psge points to the beginning of the chain element
344 * in current buffer. Get a chain buffer.
345 */
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200346 if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530347 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200348 "getFreeChainBuffer FAILED SCSI cmd=%02x (%p)\n",
349 ioc->name, pReq->CDB[0], SCpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 return FAILED;
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 /* Update the tracking arrays.
354 * If chainSge == NULL, update ReqToChain, else ChainToChain
355 */
356 if (chainSge) {
357 ioc->ChainToChain[chain_idx] = newIndex;
358 } else {
359 ioc->ReqToChain[req_idx] = newIndex;
360 }
361 chain_idx = newIndex;
362 chain_dma_off = ioc->req_sz * chain_idx;
363
364 /* Populate the chainSGE for the current buffer.
365 * - Set chain buffer pointer to psge and fill
366 * out the Address and Flags fields.
367 */
368 chainSge = (char *) psge;
Eric Moore29dd3602007-09-14 18:46:51 -0600369 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT " Current buff @ %p (index 0x%x)",
370 ioc->name, psge, req_idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 /* Start the SGE for the next buffer
373 */
374 psge = (char *) (ioc->ChainBuffer + chain_dma_off);
375 sgeOffset = 0;
376 sg_done = 0;
377
Eric Moore29dd3602007-09-14 18:46:51 -0600378 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT " Chain buff @ %p (index 0x%x)\n",
379 ioc->name, psge, chain_idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
381 /* Start the SGE for the next buffer
382 */
383
384 goto nextSGEset;
385 }
386
387 return SUCCESS;
388} /* mptscsih_AddSGE() */
389
Eric Moore786899b2006-07-11 17:22:22 -0600390static void
391mptscsih_issue_sep_command(MPT_ADAPTER *ioc, VirtTarget *vtarget,
392 U32 SlotStatus)
393{
394 MPT_FRAME_HDR *mf;
395 SEPRequest_t *SEPMsg;
396
Eric Moorecc78d302007-06-15 17:27:21 -0600397 if (ioc->bus_type != SAS)
398 return;
399
400 /* Not supported for hidden raid components
401 */
402 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
Eric Moore786899b2006-07-11 17:22:22 -0600403 return;
404
405 if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530406 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: no msg frames!!\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700407 ioc->name,__func__));
Eric Moore786899b2006-07-11 17:22:22 -0600408 return;
409 }
410
411 SEPMsg = (SEPRequest_t *)mf;
412 SEPMsg->Function = MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
Eric Moore793955f2007-01-29 09:42:20 -0700413 SEPMsg->Bus = vtarget->channel;
414 SEPMsg->TargetID = vtarget->id;
Eric Moore786899b2006-07-11 17:22:22 -0600415 SEPMsg->Action = MPI_SEP_REQ_ACTION_WRITE_STATUS;
416 SEPMsg->SlotStatus = SlotStatus;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530417 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Eric Moore793955f2007-01-29 09:42:20 -0700418 "Sending SEP cmd=%x channel=%d id=%d\n",
419 ioc->name, SlotStatus, SEPMsg->Bus, SEPMsg->TargetID));
Eric Moore786899b2006-07-11 17:22:22 -0600420 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
421}
422
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530423#ifdef CONFIG_FUSION_LOGGING
Eric Moorec6c727a2007-01-29 09:44:54 -0700424/**
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530425 * mptscsih_info_scsiio - debug print info on reply frame
Eric Moorec6c727a2007-01-29 09:44:54 -0700426 * @ioc: Pointer to MPT_ADAPTER structure
Eric Moorec6c727a2007-01-29 09:44:54 -0700427 * @sc: original scsi cmnd pointer
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530428 * @pScsiReply: Pointer to MPT reply frame
429 *
430 * MPT_DEBUG_REPLY needs to be enabled to obtain this info
Eric Moorec6c727a2007-01-29 09:44:54 -0700431 *
432 * Refer to lsi/mpi.h.
433 **/
434static void
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530435mptscsih_info_scsiio(MPT_ADAPTER *ioc, struct scsi_cmnd *sc, SCSIIOReply_t * pScsiReply)
Eric Moorec6c727a2007-01-29 09:44:54 -0700436{
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530437 char *desc = NULL;
438 char *desc1 = NULL;
439 u16 ioc_status;
440 u8 skey, asc, ascq;
441
442 ioc_status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
Eric Moorec6c727a2007-01-29 09:44:54 -0700443
444 switch (ioc_status) {
445
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530446 case MPI_IOCSTATUS_SUCCESS:
447 desc = "success";
Eric Moorec6c727a2007-01-29 09:44:54 -0700448 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530449 case MPI_IOCSTATUS_SCSI_INVALID_BUS:
450 desc = "invalid bus";
Eric Moorec6c727a2007-01-29 09:44:54 -0700451 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530452 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID:
453 desc = "invalid target_id";
Eric Moorec6c727a2007-01-29 09:44:54 -0700454 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530455 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
456 desc = "device not there";
Eric Moorec6c727a2007-01-29 09:44:54 -0700457 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530458 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN:
459 desc = "data overrun";
Eric Moorec6c727a2007-01-29 09:44:54 -0700460 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530461 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:
462 desc = "data underrun";
Eric Moorec6c727a2007-01-29 09:44:54 -0700463 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530464 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR:
465 desc = "I/O data error";
Eric Moorec6c727a2007-01-29 09:44:54 -0700466 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530467 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR:
468 desc = "protocol error";
Eric Moorec6c727a2007-01-29 09:44:54 -0700469 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530470 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED:
471 desc = "task terminated";
Eric Moorec6c727a2007-01-29 09:44:54 -0700472 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530473 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
474 desc = "residual mismatch";
Eric Moorec6c727a2007-01-29 09:44:54 -0700475 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530476 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
477 desc = "task management failed";
478 break;
479 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED:
480 desc = "IOC terminated";
481 break;
482 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:
483 desc = "ext terminated";
484 break;
485 default:
486 desc = "";
Eric Moorec6c727a2007-01-29 09:44:54 -0700487 break;
488 }
489
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530490 switch (pScsiReply->SCSIStatus)
491 {
Eric Moorec6c727a2007-01-29 09:44:54 -0700492
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530493 case MPI_SCSI_STATUS_SUCCESS:
494 desc1 = "success";
495 break;
496 case MPI_SCSI_STATUS_CHECK_CONDITION:
497 desc1 = "check condition";
498 break;
499 case MPI_SCSI_STATUS_CONDITION_MET:
500 desc1 = "condition met";
501 break;
502 case MPI_SCSI_STATUS_BUSY:
503 desc1 = "busy";
504 break;
505 case MPI_SCSI_STATUS_INTERMEDIATE:
506 desc1 = "intermediate";
507 break;
508 case MPI_SCSI_STATUS_INTERMEDIATE_CONDMET:
509 desc1 = "intermediate condmet";
510 break;
511 case MPI_SCSI_STATUS_RESERVATION_CONFLICT:
512 desc1 = "reservation conflict";
513 break;
514 case MPI_SCSI_STATUS_COMMAND_TERMINATED:
515 desc1 = "command terminated";
516 break;
517 case MPI_SCSI_STATUS_TASK_SET_FULL:
518 desc1 = "task set full";
519 break;
520 case MPI_SCSI_STATUS_ACA_ACTIVE:
521 desc1 = "aca active";
522 break;
523 case MPI_SCSI_STATUS_FCPEXT_DEVICE_LOGGED_OUT:
524 desc1 = "fcpext device logged out";
525 break;
526 case MPI_SCSI_STATUS_FCPEXT_NO_LINK:
527 desc1 = "fcpext no link";
528 break;
529 case MPI_SCSI_STATUS_FCPEXT_UNASSIGNED:
530 desc1 = "fcpext unassigned";
531 break;
532 default:
533 desc1 = "";
534 break;
535 }
Eric Moorec6c727a2007-01-29 09:44:54 -0700536
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530537 scsi_print_command(sc);
Kashyap, Desai2f187862009-05-29 16:52:37 +0530538 printk(MYIOC_s_DEBUG_FMT "\tfw_channel = %d, fw_id = %d, lun = %d\n",
539 ioc->name, pScsiReply->Bus, pScsiReply->TargetID, sc->device->lun);
Eric Moore29dd3602007-09-14 18:46:51 -0600540 printk(MYIOC_s_DEBUG_FMT "\trequest_len = %d, underflow = %d, "
541 "resid = %d\n", ioc->name, scsi_bufflen(sc), sc->underflow,
542 scsi_get_resid(sc));
543 printk(MYIOC_s_DEBUG_FMT "\ttag = %d, transfer_count = %d, "
544 "sc->result = %08X\n", ioc->name, le16_to_cpu(pScsiReply->TaskTag),
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530545 le32_to_cpu(pScsiReply->TransferCount), sc->result);
Kashyap, Desai2f187862009-05-29 16:52:37 +0530546
Eric Moore29dd3602007-09-14 18:46:51 -0600547 printk(MYIOC_s_DEBUG_FMT "\tiocstatus = %s (0x%04x), "
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530548 "scsi_status = %s (0x%02x), scsi_state = (0x%02x)\n",
Eric Moore29dd3602007-09-14 18:46:51 -0600549 ioc->name, desc, ioc_status, desc1, pScsiReply->SCSIStatus,
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530550 pScsiReply->SCSIState);
551
552 if (pScsiReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
553 skey = sc->sense_buffer[2] & 0x0F;
554 asc = sc->sense_buffer[12];
555 ascq = sc->sense_buffer[13];
556
Eric Moore29dd3602007-09-14 18:46:51 -0600557 printk(MYIOC_s_DEBUG_FMT "\t[sense_key,asc,ascq]: "
558 "[0x%02x,0x%02x,0x%02x]\n", ioc->name, skey, asc, ascq);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530559 }
560
561 /*
562 * Look for + dump FCP ResponseInfo[]!
563 */
564 if (pScsiReply->SCSIState & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
565 pScsiReply->ResponseInfo)
Eric Moore29dd3602007-09-14 18:46:51 -0600566 printk(MYIOC_s_DEBUG_FMT "response_info = %08xh\n",
567 ioc->name, le32_to_cpu(pScsiReply->ResponseInfo));
Eric Moorec6c727a2007-01-29 09:44:54 -0700568}
569#endif
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
572/*
573 * mptscsih_io_done - Main SCSI IO callback routine registered to
574 * Fusion MPT (base) driver
575 * @ioc: Pointer to MPT_ADAPTER structure
576 * @mf: Pointer to original MPT request frame
577 * @r: Pointer to MPT reply frame (NULL if TurboReply)
578 *
579 * This routine is called from mpt.c::mpt_interrupt() at the completion
580 * of any SCSI IO request.
581 * This routine is registered with the Fusion MPT (base) driver at driver
582 * load/init time via the mpt_register() API call.
583 *
584 * Returns 1 indicating alloc'd request frame ptr should be freed.
585 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400586int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
588{
589 struct scsi_cmnd *sc;
590 MPT_SCSI_HOST *hd;
591 SCSIIORequest_t *pScsiReq;
592 SCSIIOReply_t *pScsiReply;
Moore, Eric2254c862006-01-17 17:06:29 -0700593 u16 req_idx, req_idx_MR;
Eric Moorea69de502007-09-14 18:48:19 -0600594 VirtDevice *vdevice;
Eric Moore786899b2006-07-11 17:22:22 -0600595 VirtTarget *vtarget;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Eric Mooree7eae9f2007-09-29 10:15:59 -0600597 hd = shost_priv(ioc->sh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
Moore, Eric2254c862006-01-17 17:06:29 -0700599 req_idx_MR = (mr != NULL) ?
600 le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx) : req_idx;
Kashyap, Desai2f187862009-05-29 16:52:37 +0530601
602 /* Special case, where already freed message frame is received from
603 * Firmware. It happens with Resetting IOC.
604 * Return immediately. Do not care
605 */
Moore, Eric2254c862006-01-17 17:06:29 -0700606 if ((req_idx != req_idx_MR) ||
Kashyap, Desai2f187862009-05-29 16:52:37 +0530607 (le32_to_cpu(mf->u.frame.linkage.arg1) == 0xdeadbeaf))
Moore, Eric2254c862006-01-17 17:06:29 -0700608 return 0;
Moore, Eric2254c862006-01-17 17:06:29 -0700609
Eric Mooree8206382007-09-29 10:16:53 -0600610 sc = mptscsih_getclear_scsi_lookup(ioc, req_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 if (sc == NULL) {
612 MPIHeader_t *hdr = (MPIHeader_t *)mf;
613
614 /* Remark: writeSDP1 will use the ScsiDoneCtx
615 * If a SCSI I/O cmd, device disabled by OS and
616 * completion done. Cannot touch sc struct. Just free mem.
617 */
618 if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST)
619 printk(MYIOC_s_ERR_FMT "NULL ScsiCmd ptr!\n",
620 ioc->name);
621
622 mptscsih_freeChainBuffers(ioc, req_idx);
623 return 1;
624 }
625
Eric Moore3dc0b032006-07-11 17:32:33 -0600626 if ((unsigned char *)mf != sc->host_scribble) {
627 mptscsih_freeChainBuffers(ioc, req_idx);
628 return 1;
629 }
630
631 sc->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 sc->result = DID_OK << 16; /* Set default reply as OK */
633 pScsiReq = (SCSIIORequest_t *) mf;
634 pScsiReply = (SCSIIOReply_t *) mr;
635
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200636 if((ioc->facts.MsgVersion >= MPI_VERSION_01_05) && pScsiReply){
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530637 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200638 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task-tag=%d)\n",
639 ioc->name, mf, mr, sc, req_idx, pScsiReply->TaskTag));
640 }else{
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530641 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200642 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",
643 ioc->name, mf, mr, sc, req_idx));
644 }
645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (pScsiReply == NULL) {
647 /* special context reply handling */
648 ;
649 } else {
650 u32 xfer_cnt;
651 u16 status;
652 u8 scsi_state, scsi_status;
Eric Moorec6c727a2007-01-29 09:44:54 -0700653 u32 log_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655 status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
656 scsi_state = pScsiReply->SCSIState;
657 scsi_status = pScsiReply->SCSIStatus;
658 xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900659 scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
Eric Moorec6c727a2007-01-29 09:44:54 -0700660 log_info = le32_to_cpu(pScsiReply->IOCLogInfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600662 /*
663 * if we get a data underrun indication, yet no data was
664 * transferred and the SCSI status indicates that the
665 * command was never started, change the data underrun
666 * to success
667 */
668 if (status == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
669 (scsi_status == MPI_SCSI_STATUS_BUSY ||
670 scsi_status == MPI_SCSI_STATUS_RESERVATION_CONFLICT ||
671 scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)) {
672 status = MPI_IOCSTATUS_SUCCESS;
673 }
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400676 mptscsih_copy_sense_data(sc, hd, mf, pScsiReply);
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 /*
679 * Look for + dump FCP ResponseInfo[]!
680 */
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600681 if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
682 pScsiReply->ResponseInfo) {
Eric Moore29dd3602007-09-14 18:46:51 -0600683 printk(MYIOC_s_NOTE_FMT "[%d:%d:%d:%d] "
684 "FCP_ResponseInfo=%08xh\n", ioc->name,
Eric Moorec6c727a2007-01-29 09:44:54 -0700685 sc->device->host->host_no, sc->device->channel,
686 sc->device->id, sc->device->lun,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 le32_to_cpu(pScsiReply->ResponseInfo));
688 }
689
690 switch(status) {
691 case MPI_IOCSTATUS_BUSY: /* 0x0002 */
Kashyap, Desaid23321b2009-08-05 12:51:25 +0530692 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 /* CHECKME!
694 * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry)
695 * But not: DID_BUS_BUSY lest one risk
696 * killing interrupt handler:-(
697 */
698 sc->result = SAM_STAT_BUSY;
699 break;
700
701 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
702 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
703 sc->result = DID_BAD_TARGET << 16;
704 break;
705
706 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
707 /* Spoof to SCSI Selection Timeout! */
Moore, Eric65207fe2006-04-21 16:14:35 -0600708 if (ioc->bus_type != FC)
709 sc->result = DID_NO_CONNECT << 16;
710 /* else fibre, just stall until rescan event */
711 else
712 sc->result = DID_REQUEUE << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
714 if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)
715 hd->sel_timeout[pScsiReq->TargetID]++;
Eric Moore786899b2006-07-11 17:22:22 -0600716
Eric Moorea69de502007-09-14 18:48:19 -0600717 vdevice = sc->device->hostdata;
718 if (!vdevice)
Eric Moore786899b2006-07-11 17:22:22 -0600719 break;
Eric Moorea69de502007-09-14 18:48:19 -0600720 vtarget = vdevice->vtarget;
Eric Moore786899b2006-07-11 17:22:22 -0600721 if (vtarget->tflags & MPT_TARGET_FLAGS_LED_ON) {
722 mptscsih_issue_sep_command(ioc, vtarget,
723 MPI_SEP_REQ_SLOTSTATUS_UNCONFIGURED);
724 vtarget->tflags &= ~MPT_TARGET_FLAGS_LED_ON;
725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 break;
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
Eric Moorebf451522006-07-11 17:25:35 -0600729 if ( ioc->bus_type == SAS ) {
730 u16 ioc_status = le16_to_cpu(pScsiReply->IOCStatus);
731 if (ioc_status & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
Eric Moorec6c727a2007-01-29 09:44:54 -0700732 if ((log_info & SAS_LOGINFO_MASK)
733 == SAS_LOGINFO_NEXUS_LOSS) {
Eric Moorebf451522006-07-11 17:25:35 -0600734 sc->result = (DID_BUS_BUSY << 16);
735 break;
736 }
737 }
Eric Moore86dd4242007-01-04 20:44:01 -0700738 } else if (ioc->bus_type == FC) {
739 /*
740 * The FC IOC may kill a request for variety of
741 * reasons, some of which may be recovered by a
742 * retry, some which are unlikely to be
743 * recovered. Return DID_ERROR instead of
744 * DID_RESET to permit retry of the command,
745 * just not an infinite number of them
746 */
747 sc->result = DID_ERROR << 16;
748 break;
Eric Moorebf451522006-07-11 17:25:35 -0600749 }
750
751 /*
752 * Allow non-SAS & non-NEXUS_LOSS to drop into below code
753 */
754
755 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 /* Linux handles an unsolicited DID_RESET better
757 * than an unsolicited DID_ABORT.
758 */
759 sc->result = DID_RESET << 16;
760
Kashyap, Desai2f187862009-05-29 16:52:37 +0530761 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
762 if (ioc->bus_type == FC)
763 sc->result = DID_ERROR << 16;
764 else
765 sc->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 break;
767
768 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900769 scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600770 if((xfer_cnt==0)||(sc->underflow > xfer_cnt))
771 sc->result=DID_SOFT_ERROR << 16;
772 else /* Sufficient data transfer occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 sc->result = (DID_OK << 16) | scsi_status;
Eric Moore29dd3602007-09-14 18:46:51 -0600774 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Eric Moorec6c727a2007-01-29 09:44:54 -0700775 "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",
Eric Moore29dd3602007-09-14 18:46:51 -0600776 ioc->name, sc->result, sc->device->channel, sc->device->id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 break;
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
780 /*
781 * Do upfront check for valid SenseData and give it
782 * precedence!
783 */
784 sc->result = (DID_OK << 16) | scsi_status;
785 if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
786 /* Have already saved the status and sense data
787 */
788 ;
789 } else {
790 if (xfer_cnt < sc->underflow) {
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600791 if (scsi_status == SAM_STAT_BUSY)
792 sc->result = SAM_STAT_BUSY;
793 else
794 sc->result = DID_SOFT_ERROR << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 }
796 if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {
797 /* What to do?
798 */
799 sc->result = DID_SOFT_ERROR << 16;
800 }
801 else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
802 /* Not real sure here either... */
803 sc->result = DID_RESET << 16;
804 }
805 }
806
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530807
Eric Moore29dd3602007-09-14 18:46:51 -0600808 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
809 " sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
810 ioc->name, sc->underflow));
811 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
812 " ActBytesXferd=%02xh\n", ioc->name, xfer_cnt));
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530813
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 /* Report Queue Full
815 */
816 if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)
817 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 break;
820
Moore, Eric7e551472006-01-16 18:53:21 -0700821 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900822 scsi_set_resid(sc, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
824 case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
Eric Mooread8c31b2007-03-19 10:31:51 -0600825 sc->result = (DID_OK << 16) | scsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 if (scsi_state == 0) {
827 ;
828 } else if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
829 /*
830 * If running against circa 200003dd 909 MPT f/w,
831 * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL
832 * (QUEUE_FULL) returned from device! --> get 0x0000?128
833 * and with SenseBytes set to 0.
834 */
835 if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL)
836 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
837
838 }
839 else if (scsi_state &
840 (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)
841 ) {
842 /*
843 * What to do?
844 */
845 sc->result = DID_SOFT_ERROR << 16;
846 }
847 else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
848 /* Not real sure here either... */
849 sc->result = DID_RESET << 16;
850 }
851 else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) {
852 /* Device Inq. data indicates that it supports
853 * QTags, but rejects QTag messages.
854 * This command completed OK.
855 *
856 * Not real sure here either so do nothing... */
857 }
858
859 if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL)
860 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
861
862 /* Add handling of:
863 * Reservation Conflict, Busy,
864 * Command Terminated, CHECK
865 */
866 break;
867
868 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
869 sc->result = DID_SOFT_ERROR << 16;
870 break;
871
872 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
873 case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
874 case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
875 case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
877 case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
879 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
880 default:
881 /*
882 * What to do?
883 */
884 sc->result = DID_SOFT_ERROR << 16;
885 break;
886
887 } /* switch(status) */
888
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530889#ifdef CONFIG_FUSION_LOGGING
890 if (sc->result && (ioc->debug_level & MPT_DEBUG_REPLY))
891 mptscsih_info_scsiio(ioc, sc, pScsiReply);
Eric Moorec6c727a2007-01-29 09:44:54 -0700892#endif
893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 } /* end of address reply case */
895
896 /* Unmap the DMA buffers, if any. */
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900897 scsi_dma_unmap(sc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 sc->scsi_done(sc); /* Issue the command callback */
900
901 /* Free Chain buffers */
902 mptscsih_freeChainBuffers(ioc, req_idx);
903 return 1;
904}
905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906/*
907 * mptscsih_flush_running_cmds - For each command found, search
908 * Scsi_Host instance taskQ and reply to OS.
909 * Called only if recovering from a FW reload.
910 * @hd: Pointer to a SCSI HOST structure
911 *
912 * Returns: None.
913 *
914 * Must be called while new I/Os are being queued.
915 */
916static void
917mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
918{
919 MPT_ADAPTER *ioc = hd->ioc;
Eric Mooree8206382007-09-29 10:16:53 -0600920 struct scsi_cmnd *sc;
921 SCSIIORequest_t *mf = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 int ii;
Eric Mooree8206382007-09-29 10:16:53 -0600923 int channel, id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Eric Mooree8206382007-09-29 10:16:53 -0600925 for (ii= 0; ii < ioc->req_depth; ii++) {
926 sc = mptscsih_getclear_scsi_lookup(ioc, ii);
927 if (!sc)
928 continue;
929 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
930 if (!mf)
931 continue;
932 channel = mf->Bus;
933 id = mf->TargetID;
934 mptscsih_freeChainBuffers(ioc, ii);
935 mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
936 if ((unsigned char *)mf != sc->host_scribble)
937 continue;
938 scsi_dma_unmap(sc);
939 sc->result = DID_RESET << 16;
940 sc->host_scribble = NULL;
Kashyap, Desai2f187862009-05-29 16:52:37 +0530941 dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT
942 "completing cmds: fw_channel %d, fw_id %d, sc=%p, mf = %p, "
943 "idx=%x\n", ioc->name, channel, id, sc, mf, ii));
Eric Mooree8206382007-09-29 10:16:53 -0600944 sc->scsi_done(sc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946}
947
948/*
949 * mptscsih_search_running_cmds - Delete any commands associated
950 * with the specified target and lun. Function called only
951 * when a lun is disable by mid-layer.
952 * Do NOT access the referenced scsi_cmnd structure or
953 * members. Will cause either a paging or NULL ptr error.
Michael Reed05e8ec12006-01-13 14:31:54 -0600954 * (BUT, BUT, BUT, the code does reference it! - mdr)
Moore, Eric Deanc7c82982005-11-16 18:54:25 -0700955 * @hd: Pointer to a SCSI HOST structure
956 * @vdevice: per device private data
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 *
958 * Returns: None.
959 *
960 * Called from slave_destroy.
961 */
962static void
Moore, Eric Deanc7c82982005-11-16 18:54:25 -0700963mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
965 SCSIIORequest_t *mf = NULL;
966 int ii;
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600967 struct scsi_cmnd *sc;
Eric Moore793955f2007-01-29 09:42:20 -0700968 struct scsi_lun lun;
Eric Mooree80b0022007-09-14 18:49:03 -0600969 MPT_ADAPTER *ioc = hd->ioc;
Eric Mooree8206382007-09-29 10:16:53 -0600970 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
Eric Mooree8206382007-09-29 10:16:53 -0600972 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
973 for (ii = 0; ii < ioc->req_depth; ii++) {
974 if ((sc = ioc->ScsiLookup[ii]) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Eric Mooree80b0022007-09-14 18:49:03 -0600976 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
Eric Moore3dc0b032006-07-11 17:32:33 -0600977 if (mf == NULL)
978 continue;
Eric Moorecc78d302007-06-15 17:27:21 -0600979 /* If the device is a hidden raid component, then its
980 * expected that the mf->function will be RAID_SCSI_IO
981 */
982 if (vdevice->vtarget->tflags &
983 MPT_TARGET_FLAGS_RAID_COMPONENT && mf->Function !=
984 MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)
985 continue;
986
Eric Moore793955f2007-01-29 09:42:20 -0700987 int_to_scsilun(vdevice->lun, &lun);
988 if ((mf->Bus != vdevice->vtarget->channel) ||
989 (mf->TargetID != vdevice->vtarget->id) ||
990 memcmp(lun.scsi_lun, mf->LUN, 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 continue;
992
Eric Moore3dc0b032006-07-11 17:32:33 -0600993 if ((unsigned char *)mf != sc->host_scribble)
994 continue;
Eric Mooree8206382007-09-29 10:16:53 -0600995 ioc->ScsiLookup[ii] = NULL;
996 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
997 mptscsih_freeChainBuffers(ioc, ii);
998 mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900999 scsi_dma_unmap(sc);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001000 sc->host_scribble = NULL;
1001 sc->result = DID_NO_CONNECT << 16;
Kashyap, Desai2f187862009-05-29 16:52:37 +05301002 dtmprintk(ioc, sdev_printk(KERN_INFO, sc->device,
1003 MYIOC_s_FMT "completing cmds: fw_channel %d, "
1004 "fw_id %d, sc=%p, mf = %p, idx=%x\n", ioc->name,
1005 vdevice->vtarget->channel, vdevice->vtarget->id,
1006 sc, mf, ii));
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001007 sc->scsi_done(sc);
Eric Mooree8206382007-09-29 10:16:53 -06001008 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 }
1010 }
Eric Mooree8206382007-09-29 10:16:53 -06001011 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 return;
1013}
1014
1015/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1018/*
1019 * mptscsih_report_queue_full - Report QUEUE_FULL status returned
1020 * from a SCSI target device.
1021 * @sc: Pointer to scsi_cmnd structure
1022 * @pScsiReply: Pointer to SCSIIOReply_t
1023 * @pScsiReq: Pointer to original SCSI request
1024 *
1025 * This routine periodically reports QUEUE_FULL status returned from a
1026 * SCSI target device. It reports this to the console via kernel
1027 * printk() API call, not more than once every 10 seconds.
1028 */
1029static void
1030mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq)
1031{
1032 long time = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 MPT_SCSI_HOST *hd;
Eric Mooree80b0022007-09-14 18:49:03 -06001034 MPT_ADAPTER *ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001036 if (sc->device == NULL)
1037 return;
1038 if (sc->device->host == NULL)
1039 return;
Eric Mooree7eae9f2007-09-29 10:15:59 -06001040 if ((hd = shost_priv(sc->device->host)) == NULL)
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001041 return;
Eric Mooree80b0022007-09-14 18:49:03 -06001042 ioc = hd->ioc;
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001043 if (time - hd->last_queue_full > 10 * HZ) {
Eric Mooree80b0022007-09-14 18:49:03 -06001044 dprintk(ioc, printk(MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n",
1045 ioc->name, 0, sc->device->id, sc->device->lun));
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001046 hd->last_queue_full = time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048}
1049
1050/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1051/*
1052 * mptscsih_remove - Removed scsi devices
1053 * @pdev: Pointer to pci_dev structure
1054 *
1055 *
1056 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001057void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058mptscsih_remove(struct pci_dev *pdev)
1059{
1060 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1061 struct Scsi_Host *host = ioc->sh;
1062 MPT_SCSI_HOST *hd;
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001063 int sz1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001065 if(!host) {
1066 mpt_detach(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 return;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001068 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
1070 scsi_remove_host(host);
1071
Eric Mooree7eae9f2007-09-29 10:15:59 -06001072 if((hd = shost_priv(host)) == NULL)
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001073 return;
1074
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07001075 mptscsih_shutdown(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001077 sz1=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Eric Mooree8206382007-09-29 10:16:53 -06001079 if (ioc->ScsiLookup != NULL) {
Eric Mooree80b0022007-09-14 18:49:03 -06001080 sz1 = ioc->req_depth * sizeof(void *);
Eric Mooree8206382007-09-29 10:16:53 -06001081 kfree(ioc->ScsiLookup);
1082 ioc->ScsiLookup = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 }
1084
Eric Mooree80b0022007-09-14 18:49:03 -06001085 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001086 "Free'd ScsiLookup (%d) memory\n",
Eric Mooree80b0022007-09-14 18:49:03 -06001087 ioc->name, sz1));
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001088
Moore, Eric Dean d485eb82005-05-11 17:37:26 -06001089 kfree(hd->info_kbuf);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001090
1091 /* NULL the Scsi_Host pointer
1092 */
Eric Mooree80b0022007-09-14 18:49:03 -06001093 ioc->sh = NULL;
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001094
1095 scsi_host_put(host);
1096
1097 mpt_detach(pdev);
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099}
1100
1101/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1102/*
1103 * mptscsih_shutdown - reboot notifier
1104 *
1105 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001106void
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07001107mptscsih_shutdown(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109}
1110
1111#ifdef CONFIG_PM
1112/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1113/*
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001114 * mptscsih_suspend - Fusion MPT scsi driver suspend routine.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 *
1116 *
1117 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001118int
Pavel Machek8d189f72005-04-16 15:25:28 -07001119mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301121 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1122
1123 scsi_block_requests(ioc->sh);
1124 flush_scheduled_work();
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07001125 mptscsih_shutdown(pdev);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001126 return mpt_suspend(pdev,state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
1129/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1130/*
1131 * mptscsih_resume - Fusion MPT scsi driver resume routine.
1132 *
1133 *
1134 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001135int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136mptscsih_resume(struct pci_dev *pdev)
1137{
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301138 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1139 int rc;
1140
1141 rc = mpt_resume(pdev);
1142 scsi_unblock_requests(ioc->sh);
1143 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
1146#endif
1147
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1149/**
1150 * mptscsih_info - Return information about MPT adapter
1151 * @SChost: Pointer to Scsi_Host structure
1152 *
1153 * (linux scsi_host_template.info routine)
1154 *
1155 * Returns pointer to buffer where information was written.
1156 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001157const char *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158mptscsih_info(struct Scsi_Host *SChost)
1159{
1160 MPT_SCSI_HOST *h;
1161 int size = 0;
1162
Eric Mooree7eae9f2007-09-29 10:15:59 -06001163 h = shost_priv(SChost);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 if (h) {
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001166 if (h->info_kbuf == NULL)
1167 if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
1168 return h->info_kbuf;
1169 h->info_kbuf[0] = '\0';
1170
1171 mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
1172 h->info_kbuf[size-1] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 }
1174
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001175 return h->info_kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
1178struct info_str {
1179 char *buffer;
1180 int length;
1181 int offset;
1182 int pos;
1183};
1184
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001185static void
1186mptscsih_copy_mem_info(struct info_str *info, char *data, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187{
1188 if (info->pos + len > info->length)
1189 len = info->length - info->pos;
1190
1191 if (info->pos + len < info->offset) {
1192 info->pos += len;
1193 return;
1194 }
1195
1196 if (info->pos < info->offset) {
1197 data += (info->offset - info->pos);
1198 len -= (info->offset - info->pos);
1199 }
1200
1201 if (len > 0) {
1202 memcpy(info->buffer + info->pos, data, len);
1203 info->pos += len;
1204 }
1205}
1206
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001207static int
1208mptscsih_copy_info(struct info_str *info, char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209{
1210 va_list args;
1211 char buf[81];
1212 int len;
1213
1214 va_start(args, fmt);
1215 len = vsprintf(buf, fmt, args);
1216 va_end(args);
1217
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001218 mptscsih_copy_mem_info(info, buf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 return len;
1220}
1221
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001222static int
1223mptscsih_host_info(MPT_ADAPTER *ioc, char *pbuf, off_t offset, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
1225 struct info_str info;
1226
1227 info.buffer = pbuf;
1228 info.length = len;
1229 info.offset = offset;
1230 info.pos = 0;
1231
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001232 mptscsih_copy_info(&info, "%s: %s, ", ioc->name, ioc->prod_name);
1233 mptscsih_copy_info(&info, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word);
1234 mptscsih_copy_info(&info, "Ports=%d, ", ioc->facts.NumberOfPorts);
1235 mptscsih_copy_info(&info, "MaxQ=%d\n", ioc->req_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
1237 return ((info.pos > info.offset) ? info.pos - info.offset : 0);
1238}
1239
1240/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1241/**
1242 * mptscsih_proc_info - Return information about MPT adapter
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001243 * @host: scsi host struct
1244 * @buffer: if write, user data; if read, buffer for user
1245 * @start: returns the buffer address
1246 * @offset: if write, 0; if read, the current offset into the buffer from
1247 * the previous read.
1248 * @length: if write, return length;
1249 * @func: write = 1; read = 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 *
1251 * (linux scsi_host_template.info routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001253int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
1255 int length, int func)
1256{
Eric Mooree7eae9f2007-09-29 10:15:59 -06001257 MPT_SCSI_HOST *hd = shost_priv(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 MPT_ADAPTER *ioc = hd->ioc;
1259 int size = 0;
1260
1261 if (func) {
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001262 /*
1263 * write is not supported
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 */
1265 } else {
1266 if (start)
1267 *start = buffer;
1268
1269 size = mptscsih_host_info(ioc, buffer, offset, length);
1270 }
1271
1272 return size;
1273}
1274
1275/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1276#define ADD_INDEX_LOG(req_ent) do { } while(0)
1277
1278/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1279/**
1280 * mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine.
1281 * @SCpnt: Pointer to scsi_cmnd structure
1282 * @done: Pointer SCSI mid-layer IO completion function
1283 *
1284 * (linux scsi_host_template.queuecommand routine)
1285 * This is the primary SCSI IO start routine. Create a MPI SCSIIORequest
1286 * from a linux scsi_cmnd request and send it to the IOC.
1287 *
1288 * Returns 0. (rtn value discarded by linux scsi mid-layer)
1289 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001290int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1292{
1293 MPT_SCSI_HOST *hd;
1294 MPT_FRAME_HDR *mf;
1295 SCSIIORequest_t *pScsiReq;
Eric Moorea69de502007-09-14 18:48:19 -06001296 VirtDevice *vdevice = SCpnt->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 u32 datalen;
1298 u32 scsictl;
1299 u32 scsidir;
1300 u32 cmd_len;
1301 int my_idx;
1302 int ii;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301303 MPT_ADAPTER *ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Eric Mooree7eae9f2007-09-29 10:15:59 -06001305 hd = shost_priv(SCpnt->device->host);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301306 ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 SCpnt->scsi_done = done;
1308
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301309 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "qcmd: SCpnt=%p, done()=%p\n",
1310 ioc->name, SCpnt, done));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Kashyap, Desaie7deff32009-05-29 16:46:07 +05301312 if (ioc->taskmgmt_quiesce_io) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301313 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "qcmd: SCpnt=%p timeout + 60HZ\n",
1314 ioc->name, SCpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 return SCSI_MLQUEUE_HOST_BUSY;
1316 }
1317
1318 /*
1319 * Put together a MPT SCSI request...
1320 */
Eric Mooree80b0022007-09-14 18:49:03 -06001321 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301322 dprintk(ioc, printk(MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
1323 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 return SCSI_MLQUEUE_HOST_BUSY;
1325 }
1326
1327 pScsiReq = (SCSIIORequest_t *) mf;
1328
1329 my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1330
1331 ADD_INDEX_LOG(my_idx);
1332
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001333 /* TUR's being issued with scsictl=0x02000000 (DATA_IN)!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 * Seems we may receive a buffer (datalen>0) even when there
1335 * will be no data transfer! GRRRRR...
1336 */
1337 if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
FUJITA Tomonori1928d732007-05-26 00:37:15 +09001338 datalen = scsi_bufflen(SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */
1340 } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
FUJITA Tomonori1928d732007-05-26 00:37:15 +09001341 datalen = scsi_bufflen(SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */
1343 } else {
1344 datalen = 0;
1345 scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER;
1346 }
1347
1348 /* Default to untagged. Once a target structure has been allocated,
1349 * use the Inquiry data to determine if device supports tagged.
1350 */
Eric Moorea69de502007-09-14 18:48:19 -06001351 if (vdevice
1352 && (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 && (SCpnt->device->tagged_supported)) {
1354 scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
1355 } else {
1356 scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
1357 }
1358
1359 /* Use the above information to set up the message frame
1360 */
Eric Moorea69de502007-09-14 18:48:19 -06001361 pScsiReq->TargetID = (u8) vdevice->vtarget->id;
1362 pScsiReq->Bus = vdevice->vtarget->channel;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 pScsiReq->ChainOffset = 0;
Eric Moorea69de502007-09-14 18:48:19 -06001364 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
James Bottomleyc92f2222006-03-01 09:02:49 -06001365 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
1366 else
1367 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 pScsiReq->CDBLength = SCpnt->cmd_len;
1369 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1370 pScsiReq->Reserved = 0;
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301371 pScsiReq->MsgFlags = mpt_msg_flags(ioc);
Eric Moore793955f2007-01-29 09:42:20 -07001372 int_to_scsilun(SCpnt->device->lun, (struct scsi_lun *)pScsiReq->LUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 pScsiReq->Control = cpu_to_le32(scsictl);
1374
1375 /*
1376 * Write SCSI CDB into the message
1377 */
1378 cmd_len = SCpnt->cmd_len;
1379 for (ii=0; ii < cmd_len; ii++)
1380 pScsiReq->CDB[ii] = SCpnt->cmnd[ii];
1381
1382 for (ii=cmd_len; ii < 16; ii++)
1383 pScsiReq->CDB[ii] = 0;
1384
1385 /* DataLength */
1386 pScsiReq->DataLength = cpu_to_le32(datalen);
1387
1388 /* SenseBuffer low address */
Eric Mooree80b0022007-09-14 18:49:03 -06001389 pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 + (my_idx * MPT_SENSE_BUFFER_ALLOC));
1391
1392 /* Now add the SG list
1393 * Always have a SGE even if null length.
1394 */
1395 if (datalen == 0) {
1396 /* Add a NULL SGE */
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301397 ioc->add_sge((char *)&pScsiReq->SGL,
1398 MPT_SGE_FLAGS_SSIMPLE_READ | 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 (dma_addr_t) -1);
1400 } else {
1401 /* Add a 32 or 64 bit SGE */
Eric Mooree80b0022007-09-14 18:49:03 -06001402 if (mptscsih_AddSGE(ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 goto fail;
1404 }
1405
Eric Moore3dc0b032006-07-11 17:32:33 -06001406 SCpnt->host_scribble = (unsigned char *)mf;
Eric Mooree8206382007-09-29 10:16:53 -06001407 mptscsih_set_scsi_lookup(ioc, my_idx, SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Eric Mooree80b0022007-09-14 18:49:03 -06001409 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301410 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
1411 ioc->name, SCpnt, mf, my_idx));
Eric Moore29dd3602007-09-14 18:46:51 -06001412 DBG_DUMP_REQUEST_FRAME(ioc, (u32 *)mf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 return 0;
1414
1415 fail:
Eric Mooree80b0022007-09-14 18:49:03 -06001416 mptscsih_freeChainBuffers(ioc, my_idx);
1417 mpt_free_msg_frame(ioc, mf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 return SCSI_MLQUEUE_HOST_BUSY;
1419}
1420
1421/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1422/*
1423 * mptscsih_freeChainBuffers - Function to free chain buffers associated
1424 * with a SCSI IO request
1425 * @hd: Pointer to the MPT_SCSI_HOST instance
1426 * @req_idx: Index of the SCSI IO request frame.
1427 *
1428 * Called if SG chain buffer allocation fails and mptscsih callbacks.
1429 * No return.
1430 */
1431static void
1432mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
1433{
1434 MPT_FRAME_HDR *chain;
1435 unsigned long flags;
1436 int chain_idx;
1437 int next;
1438
1439 /* Get the first chain index and reset
1440 * tracker state.
1441 */
1442 chain_idx = ioc->ReqToChain[req_idx];
1443 ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN;
1444
1445 while (chain_idx != MPT_HOST_NO_CHAIN) {
1446
1447 /* Save the next chain buffer index */
1448 next = ioc->ChainToChain[chain_idx];
1449
1450 /* Free this chain buffer and reset
1451 * tracker
1452 */
1453 ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN;
1454
1455 chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer
1456 + (chain_idx * ioc->req_sz));
1457
1458 spin_lock_irqsave(&ioc->FreeQlock, flags);
1459 list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);
1460 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1461
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301462 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FreeChainBuffers (index %d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 ioc->name, chain_idx));
1464
1465 /* handle next */
1466 chain_idx = next;
1467 }
1468 return;
1469}
1470
1471/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1472/*
1473 * Reset Handling
1474 */
1475
1476/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Eric Moorecd2c6192007-01-29 09:47:47 -07001477/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 * mptscsih_IssueTaskMgmt - Generic send Task Management function.
1479 * @hd: Pointer to MPT_SCSI_HOST structure
1480 * @type: Task Management type
Randy Dunlap1544d672007-02-20 11:17:03 -08001481 * @channel: channel number for task management
Eric Moore793955f2007-01-29 09:42:20 -07001482 * @id: Logical Target ID for reset (if appropriate)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 * @lun: Logical Unit for reset (if appropriate)
1484 * @ctx2abort: Context for the task to be aborted (if appropriate)
Randy Dunlap1544d672007-02-20 11:17:03 -08001485 * @timeout: timeout for task management control
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 *
1487 * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
1488 * or a non-interrupt thread. In the former, must not call schedule().
1489 *
1490 * Not all fields are meaningfull for all task types.
1491 *
Eric Moorecd2c6192007-01-29 09:47:47 -07001492 * Returns 0 for SUCCESS, or FAILED.
1493 *
1494 **/
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301495int
1496mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun,
1497 int ctx2abort, ulong timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
1499 MPT_FRAME_HDR *mf;
1500 SCSITaskMgmt_t *pScsiTm;
1501 int ii;
1502 int retval;
Eric Mooree80b0022007-09-14 18:49:03 -06001503 MPT_ADAPTER *ioc = hd->ioc;
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301504 unsigned long timeleft;
1505 u8 issue_hard_reset;
1506 u32 ioc_raw_state;
1507 unsigned long time_count;
1508
1509 issue_hard_reset = 0;
1510 ioc_raw_state = mpt_GetIocState(ioc, 0);
1511
1512 if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
1513 printk(MYIOC_s_WARN_FMT
1514 "TaskMgmt type=%x: IOC Not operational (0x%x)!\n",
1515 ioc->name, type, ioc_raw_state);
1516 printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
1517 ioc->name, __func__);
1518 if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)
1519 printk(MYIOC_s_WARN_FMT "TaskMgmt HardReset "
1520 "FAILED!!\n", ioc->name);
1521 return 0;
1522 }
1523
1524 if (ioc_raw_state & MPI_DOORBELL_ACTIVE) {
1525 printk(MYIOC_s_WARN_FMT
1526 "TaskMgmt type=%x: ioc_state: "
1527 "DOORBELL_ACTIVE (0x%x)!\n",
1528 ioc->name, type, ioc_raw_state);
1529 return FAILED;
1530 }
1531
1532 mutex_lock(&ioc->taskmgmt_cmds.mutex);
1533 if (mpt_set_taskmgmt_in_progress_flag(ioc) != 0) {
1534 mf = NULL;
1535 retval = FAILED;
1536 goto out;
1537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
1539 /* Return Fail to calling function if no message frames available.
1540 */
Eric Mooree80b0022007-09-14 18:49:03 -06001541 if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301542 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1543 "TaskMgmt no msg frames!!\n", ioc->name));
1544 retval = FAILED;
1545 mpt_clear_taskmgmt_in_progress_flag(ioc);
1546 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 }
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301548 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt request (mf=%p)\n",
Eric Mooree80b0022007-09-14 18:49:03 -06001549 ioc->name, mf));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
1551 /* Format the Request
1552 */
1553 pScsiTm = (SCSITaskMgmt_t *) mf;
Eric Moore793955f2007-01-29 09:42:20 -07001554 pScsiTm->TargetID = id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 pScsiTm->Bus = channel;
1556 pScsiTm->ChainOffset = 0;
1557 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
1558
1559 pScsiTm->Reserved = 0;
1560 pScsiTm->TaskType = type;
1561 pScsiTm->Reserved1 = 0;
1562 pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
1563 ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
1564
Eric Moore793955f2007-01-29 09:42:20 -07001565 int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
1567 for (ii=0; ii < 7; ii++)
1568 pScsiTm->Reserved2[ii] = 0;
1569
1570 pScsiTm->TaskMsgContext = ctx2abort;
1571
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301572 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt: ctx2abort (0x%08x) "
1573 "task_type = 0x%02X, timeout = %ld\n", ioc->name, ctx2abort,
1574 type, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301576 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)pScsiTm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301578 INITIALIZE_MGMT_STATUS(ioc->taskmgmt_cmds.status)
1579 time_count = jiffies;
Eric Mooree80b0022007-09-14 18:49:03 -06001580 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
1581 (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
1582 mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf);
Prakash, Sathya7a195f42007-08-14 16:08:40 +05301583 else {
Eric Mooree80b0022007-09-14 18:49:03 -06001584 retval = mpt_send_handshake_request(ioc->TaskCtx, ioc,
Prakash, Sathya7a195f42007-08-14 16:08:40 +05301585 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
1586 if (retval) {
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301587 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
1588 "TaskMgmt handshake FAILED!(mf=%p, rc=%d) \n",
1589 ioc->name, mf, retval));
1590 mpt_free_msg_frame(ioc, mf);
1591 mpt_clear_taskmgmt_in_progress_flag(ioc);
1592 goto out;
Prakash, Sathya7a195f42007-08-14 16:08:40 +05301593 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 }
1595
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301596 timeleft = wait_for_completion_timeout(&ioc->taskmgmt_cmds.done,
1597 timeout*HZ);
1598 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
1599 retval = FAILED;
1600 dtmprintk(ioc, printk(MYIOC_s_ERR_FMT
1601 "TaskMgmt TIMED OUT!(mf=%p)\n", ioc->name, mf));
1602 mpt_clear_taskmgmt_in_progress_flag(ioc);
1603 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
1604 goto out;
1605 issue_hard_reset = 1;
1606 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 }
1608
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301609 retval = mptscsih_taskmgmt_reply(ioc, type,
1610 (SCSITaskMgmtReply_t *) ioc->taskmgmt_cmds.reply);
Eric Moorecd2c6192007-01-29 09:47:47 -07001611
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301612 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1613 "TaskMgmt completed (%d seconds)\n",
1614 ioc->name, jiffies_to_msecs(jiffies - time_count)/1000));
1615
1616 out:
1617
1618 CLEAR_MGMT_STATUS(ioc->taskmgmt_cmds.status)
1619 if (issue_hard_reset) {
1620 printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
1621 ioc->name, __func__);
1622 retval = mpt_HardResetHandler(ioc, CAN_SLEEP);
1623 mpt_free_msg_frame(ioc, mf);
1624 }
1625
1626 retval = (retval == 0) ? 0 : FAILED;
1627 mutex_unlock(&ioc->taskmgmt_cmds.mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 return retval;
1629}
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301630EXPORT_SYMBOL(mptscsih_IssueTaskMgmt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
Christoph Hellwigd66c7a02006-01-17 13:43:14 +00001632static int
1633mptscsih_get_tm_timeout(MPT_ADAPTER *ioc)
1634{
1635 switch (ioc->bus_type) {
1636 case FC:
1637 return 40;
1638 case SAS:
Christoph Hellwigd66c7a02006-01-17 13:43:14 +00001639 case SPI:
1640 default:
Bernd Schubert22ab0192008-09-23 15:28:58 +02001641 return 10;
Christoph Hellwigd66c7a02006-01-17 13:43:14 +00001642 }
1643}
1644
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1646/**
1647 * mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant
1648 * @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted
1649 *
1650 * (linux scsi_host_template.eh_abort_handler routine)
1651 *
1652 * Returns SUCCESS or FAILED.
Eric Moorecd2c6192007-01-29 09:47:47 -07001653 **/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001654int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655mptscsih_abort(struct scsi_cmnd * SCpnt)
1656{
1657 MPT_SCSI_HOST *hd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 MPT_FRAME_HDR *mf;
1659 u32 ctx2abort;
1660 int scpnt_idx;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001661 int retval;
Eric Moore958d4a32007-06-15 17:24:14 -06001662 VirtDevice *vdevice;
Eric Moore3dc0b032006-07-11 17:32:33 -06001663 ulong sn = SCpnt->serial_number;
Eric Moore958d4a32007-06-15 17:24:14 -06001664 MPT_ADAPTER *ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
1666 /* If we can't locate our host adapter structure, return FAILED status.
1667 */
Eric Mooree7eae9f2007-09-29 10:15:59 -06001668 if ((hd = shost_priv(SCpnt->device->host)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 SCpnt->result = DID_RESET << 16;
1670 SCpnt->scsi_done(SCpnt);
Eric Moore29dd3602007-09-14 18:46:51 -06001671 printk(KERN_ERR MYNAM ": task abort: "
1672 "can't locate host! (sc=%p)\n", SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 return FAILED;
1674 }
1675
Eric Moore958d4a32007-06-15 17:24:14 -06001676 ioc = hd->ioc;
1677 printk(MYIOC_s_INFO_FMT "attempting task abort! (sc=%p)\n",
1678 ioc->name, SCpnt);
1679 scsi_print_command(SCpnt);
1680
1681 vdevice = SCpnt->device->hostdata;
1682 if (!vdevice || !vdevice->vtarget) {
Eric Moore29dd3602007-09-14 18:46:51 -06001683 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1684 "task abort: device has been deleted (sc=%p)\n",
1685 ioc->name, SCpnt));
Eric Moore958d4a32007-06-15 17:24:14 -06001686 SCpnt->result = DID_NO_CONNECT << 16;
1687 SCpnt->scsi_done(SCpnt);
1688 retval = 0;
1689 goto out;
1690 }
1691
Eric Moorecc78d302007-06-15 17:27:21 -06001692 /* Task aborts are not supported for hidden raid components.
1693 */
1694 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
Eric Moore29dd3602007-09-14 18:46:51 -06001695 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1696 "task abort: hidden raid component (sc=%p)\n",
1697 ioc->name, SCpnt));
Eric Moorecc78d302007-06-15 17:27:21 -06001698 SCpnt->result = DID_RESET << 16;
1699 retval = FAILED;
1700 goto out;
1701 }
1702
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 /* Find this command
1704 */
Eric Mooree8206382007-09-29 10:16:53 -06001705 if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(ioc, SCpnt)) < 0) {
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001706 /* Cmd not found in ScsiLookup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 * Do OS callback.
1708 */
1709 SCpnt->result = DID_RESET << 16;
Eric Moore29dd3602007-09-14 18:46:51 -06001710 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "task abort: "
Eric Moore958d4a32007-06-15 17:24:14 -06001711 "Command not in the active list! (sc=%p)\n", ioc->name,
1712 SCpnt));
1713 retval = 0;
1714 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 }
1716
Kashyap, Desai2f187862009-05-29 16:52:37 +05301717 if (ioc->timeouts < -1)
1718 ioc->timeouts++;
Moore, Eric65207fe2006-04-21 16:14:35 -06001719
Kashyap, Desai2f4c7822009-01-06 15:03:37 +05301720 if (mpt_fwfault_debug)
1721 mpt_halt_firmware(ioc);
1722
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 /* Most important! Set TaskMsgContext to SCpnt's MsgContext!
1724 * (the IO to be ABORT'd)
1725 *
1726 * NOTE: Since we do not byteswap MsgContext, we do not
1727 * swap it here either. It is an opaque cookie to
1728 * the controller, so it does not matter. -DaveM
1729 */
Eric Mooree80b0022007-09-14 18:49:03 -06001730 mf = MPT_INDEX_2_MFPTR(ioc, scpnt_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301732 retval = mptscsih_IssueTaskMgmt(hd,
1733 MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
1734 vdevice->vtarget->channel,
1735 vdevice->vtarget->id, vdevice->lun,
1736 ctx2abort, mptscsih_get_tm_timeout(ioc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
Eric Mooree8206382007-09-29 10:16:53 -06001738 if (SCPNT_TO_LOOKUP_IDX(ioc, SCpnt) == scpnt_idx &&
Kashyap, Desai2f187862009-05-29 16:52:37 +05301739 SCpnt->serial_number == sn) {
1740 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1741 "task abort: command still in active list! (sc=%p)\n",
1742 ioc->name, SCpnt));
Eric Moore3dc0b032006-07-11 17:32:33 -06001743 retval = FAILED;
Kashyap, Desai2f187862009-05-29 16:52:37 +05301744 } else {
1745 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1746 "task abort: command cleared from active list! (sc=%p)\n",
1747 ioc->name, SCpnt));
1748 retval = SUCCESS;
1749 }
Eric Moore3dc0b032006-07-11 17:32:33 -06001750
Eric Moore958d4a32007-06-15 17:24:14 -06001751 out:
1752 printk(MYIOC_s_INFO_FMT "task abort: %s (sc=%p)\n",
Kashyap, Desai2f187862009-05-29 16:52:37 +05301753 ioc->name, ((retval == SUCCESS) ? "SUCCESS" : "FAILED"), SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Kashyap, Desai2f187862009-05-29 16:52:37 +05301755 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756}
1757
1758/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1759/**
1760 * mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant
1761 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
1762 *
1763 * (linux scsi_host_template.eh_dev_reset_handler routine)
1764 *
1765 * Returns SUCCESS or FAILED.
Eric Moorecd2c6192007-01-29 09:47:47 -07001766 **/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001767int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
1769{
1770 MPT_SCSI_HOST *hd;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001771 int retval;
Eric Moore958d4a32007-06-15 17:24:14 -06001772 VirtDevice *vdevice;
1773 MPT_ADAPTER *ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
1775 /* If we can't locate our host adapter structure, return FAILED status.
1776 */
Eric Mooree7eae9f2007-09-29 10:15:59 -06001777 if ((hd = shost_priv(SCpnt->device->host)) == NULL){
Eric Moore29dd3602007-09-14 18:46:51 -06001778 printk(KERN_ERR MYNAM ": target reset: "
1779 "Can't locate host! (sc=%p)\n", SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 return FAILED;
1781 }
1782
Eric Moore958d4a32007-06-15 17:24:14 -06001783 ioc = hd->ioc;
1784 printk(MYIOC_s_INFO_FMT "attempting target reset! (sc=%p)\n",
1785 ioc->name, SCpnt);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001786 scsi_print_command(SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
Eric Moore958d4a32007-06-15 17:24:14 -06001788 vdevice = SCpnt->device->hostdata;
1789 if (!vdevice || !vdevice->vtarget) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05301790 retval = SUCCESS;
Eric Moore958d4a32007-06-15 17:24:14 -06001791 goto out;
1792 }
1793
Eric Moorecc78d302007-06-15 17:27:21 -06001794 /* Target reset to hidden raid component is not supported
1795 */
1796 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1797 retval = FAILED;
1798 goto out;
1799 }
1800
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301801 retval = mptscsih_IssueTaskMgmt(hd,
1802 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
1803 vdevice->vtarget->channel,
1804 vdevice->vtarget->id, 0, 0,
1805 mptscsih_get_tm_timeout(ioc));
Eric Moore958d4a32007-06-15 17:24:14 -06001806
1807 out:
1808 printk (MYIOC_s_INFO_FMT "target reset: %s (sc=%p)\n",
1809 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001810
1811 if (retval == 0)
1812 return SUCCESS;
Eric Moorecd2c6192007-01-29 09:47:47 -07001813 else
1814 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815}
1816
Eric Moorecd2c6192007-01-29 09:47:47 -07001817
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1819/**
1820 * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant
1821 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
1822 *
1823 * (linux scsi_host_template.eh_bus_reset_handler routine)
1824 *
1825 * Returns SUCCESS or FAILED.
Eric Moorecd2c6192007-01-29 09:47:47 -07001826 **/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001827int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
1829{
1830 MPT_SCSI_HOST *hd;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001831 int retval;
Eric Moorea69de502007-09-14 18:48:19 -06001832 VirtDevice *vdevice;
Eric Moore958d4a32007-06-15 17:24:14 -06001833 MPT_ADAPTER *ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
1835 /* If we can't locate our host adapter structure, return FAILED status.
1836 */
Eric Mooree7eae9f2007-09-29 10:15:59 -06001837 if ((hd = shost_priv(SCpnt->device->host)) == NULL){
Eric Moore29dd3602007-09-14 18:46:51 -06001838 printk(KERN_ERR MYNAM ": bus reset: "
1839 "Can't locate host! (sc=%p)\n", SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 return FAILED;
1841 }
1842
Eric Moore958d4a32007-06-15 17:24:14 -06001843 ioc = hd->ioc;
1844 printk(MYIOC_s_INFO_FMT "attempting bus reset! (sc=%p)\n",
1845 ioc->name, SCpnt);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001846 scsi_print_command(SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
Kashyap, Desai2f187862009-05-29 16:52:37 +05301848 if (ioc->timeouts < -1)
1849 ioc->timeouts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
Eric Moorea69de502007-09-14 18:48:19 -06001851 vdevice = SCpnt->device->hostdata;
Kashyap, Desai2f187862009-05-29 16:52:37 +05301852 if (!vdevice || !vdevice->vtarget)
1853 return SUCCESS;
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301854 retval = mptscsih_IssueTaskMgmt(hd,
1855 MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
1856 vdevice->vtarget->channel, 0, 0, 0,
1857 mptscsih_get_tm_timeout(ioc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
Eric Moore958d4a32007-06-15 17:24:14 -06001859 printk(MYIOC_s_INFO_FMT "bus reset: %s (sc=%p)\n",
1860 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001861
1862 if (retval == 0)
1863 return SUCCESS;
Eric Moorecd2c6192007-01-29 09:47:47 -07001864 else
1865 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866}
1867
1868/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1869/**
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001870 * mptscsih_host_reset - Perform a SCSI host adapter RESET (new_eh variant)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
1872 *
1873 * (linux scsi_host_template.eh_host_reset_handler routine)
1874 *
1875 * Returns SUCCESS or FAILED.
1876 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001877int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878mptscsih_host_reset(struct scsi_cmnd *SCpnt)
1879{
1880 MPT_SCSI_HOST * hd;
Kashyap, Desai2f187862009-05-29 16:52:37 +05301881 int status = SUCCESS;
Eric Moore958d4a32007-06-15 17:24:14 -06001882 MPT_ADAPTER *ioc;
Kashyap, Desai2f187862009-05-29 16:52:37 +05301883 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
1885 /* If we can't locate the host to reset, then we failed. */
Eric Mooree7eae9f2007-09-29 10:15:59 -06001886 if ((hd = shost_priv(SCpnt->device->host)) == NULL){
Eric Moore29dd3602007-09-14 18:46:51 -06001887 printk(KERN_ERR MYNAM ": host reset: "
1888 "Can't locate host! (sc=%p)\n", SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 return FAILED;
1890 }
1891
James Bottomleya6da74c2008-12-15 14:13:27 -06001892 /* make sure we have no outstanding commands at this stage */
1893 mptscsih_flush_running_cmds(hd);
1894
Eric Moore958d4a32007-06-15 17:24:14 -06001895 ioc = hd->ioc;
1896 printk(MYIOC_s_INFO_FMT "attempting host reset! (sc=%p)\n",
1897 ioc->name, SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
1899 /* If our attempts to reset the host failed, then return a failed
1900 * status. The host will be taken off line by the SCSI mid-layer.
1901 */
Kashyap, Desai2f187862009-05-29 16:52:37 +05301902 retval = mpt_HardResetHandler(ioc, CAN_SLEEP);
1903 if (retval < 0)
1904 status = FAILED;
1905 else
1906 status = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
Eric Moore958d4a32007-06-15 17:24:14 -06001908 printk(MYIOC_s_INFO_FMT "host reset: %s (sc=%p)\n",
1909 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910
Kashyap, Desai2f187862009-05-29 16:52:37 +05301911 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912}
1913
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914static int
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301915mptscsih_taskmgmt_reply(MPT_ADAPTER *ioc, u8 type,
1916 SCSITaskMgmtReply_t *pScsiTmReply)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917{
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301918 u16 iocstatus;
1919 u32 termination_count;
1920 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301922 if (!(ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
1923 retval = FAILED;
1924 goto out;
1925 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301927 DBG_DUMP_TM_REPLY_FRAME(ioc, (u32 *)pScsiTmReply);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301929 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
1930 termination_count = le32_to_cpu(pScsiTmReply->TerminationCount);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301932 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1933 "TaskMgmt fw_channel = %d, fw_id = %d, task_type = 0x%02X,\n"
1934 "\tiocstatus = 0x%04X, loginfo = 0x%08X, response_code = 0x%02X,\n"
1935 "\tterm_cmnds = %d\n", ioc->name, pScsiTmReply->Bus,
1936 pScsiTmReply->TargetID, type, le16_to_cpu(pScsiTmReply->IOCStatus),
1937 le32_to_cpu(pScsiTmReply->IOCLogInfo), pScsiTmReply->ResponseCode,
1938 termination_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301940 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 &&
1941 pScsiTmReply->ResponseCode)
1942 mptscsih_taskmgmt_response_code(ioc,
1943 pScsiTmReply->ResponseCode);
1944
1945 if (iocstatus == MPI_IOCSTATUS_SUCCESS) {
1946 retval = 0;
1947 goto out;
1948 }
1949
1950 retval = FAILED;
1951 if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
1952 if (termination_count == 1)
1953 retval = 0;
1954 goto out;
1955 }
1956
1957 if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
1958 iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED)
1959 retval = 0;
1960
1961 out:
1962 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963}
1964
1965/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Kashyap, Desaie7deff32009-05-29 16:46:07 +05301966void
Moore, Eric9f63bb72006-01-16 18:53:26 -07001967mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code)
1968{
1969 char *desc;
1970
1971 switch (response_code) {
1972 case MPI_SCSITASKMGMT_RSP_TM_COMPLETE:
1973 desc = "The task completed.";
1974 break;
1975 case MPI_SCSITASKMGMT_RSP_INVALID_FRAME:
1976 desc = "The IOC received an invalid frame status.";
1977 break;
1978 case MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
1979 desc = "The task type is not supported.";
1980 break;
1981 case MPI_SCSITASKMGMT_RSP_TM_FAILED:
1982 desc = "The requested task failed.";
1983 break;
1984 case MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED:
1985 desc = "The task completed successfully.";
1986 break;
1987 case MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN:
1988 desc = "The LUN request is invalid.";
1989 break;
1990 case MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
1991 desc = "The task is in the IOC queue and has not been sent to target.";
1992 break;
1993 default:
1994 desc = "unknown";
1995 break;
1996 }
1997 printk(MYIOC_s_INFO_FMT "Response Code(0x%08x): F/W: %s\n",
1998 ioc->name, response_code, desc);
1999}
Kashyap, Desaie7deff32009-05-29 16:46:07 +05302000EXPORT_SYMBOL(mptscsih_taskmgmt_response_code);
Moore, Eric9f63bb72006-01-16 18:53:26 -07002001
2002/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003/**
2004 * mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver
2005 * @ioc: Pointer to MPT_ADAPTER structure
2006 * @mf: Pointer to SCSI task mgmt request frame
2007 * @mr: Pointer to SCSI task mgmt reply frame
2008 *
2009 * This routine is called from mptbase.c::mpt_interrupt() at the completion
2010 * of any SCSI task management request.
2011 * This routine is registered with the MPT (base) driver at driver
2012 * load/init time via the mpt_register() API call.
2013 *
2014 * Returns 1 indicating alloc'd request frame ptr should be freed.
Eric Moorecd2c6192007-01-29 09:47:47 -07002015 **/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002016int
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05302017mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf,
2018 MPT_FRAME_HDR *mr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019{
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05302020 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2021 "TaskMgmt completed (mf=%p, mr=%p)\n", ioc->name, mf, mr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05302023 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05302025 if (!mr)
Eric Moorecd2c6192007-01-29 09:47:47 -07002026 goto out;
Eric Moorecd2c6192007-01-29 09:47:47 -07002027
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05302028 ioc->taskmgmt_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
2029 memcpy(ioc->taskmgmt_cmds.reply, mr,
2030 min(MPT_DEFAULT_FRAME_SIZE, 4 * mr->u.reply.MsgLength));
Eric Moorecd2c6192007-01-29 09:47:47 -07002031 out:
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05302032 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
2033 mpt_clear_taskmgmt_in_progress_flag(ioc);
2034 ioc->taskmgmt_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
2035 complete(&ioc->taskmgmt_cmds.done);
2036 return 1;
2037 }
2038 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039}
2040
2041/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2042/*
2043 * This is anyones guess quite frankly.
2044 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002045int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
2047 sector_t capacity, int geom[])
2048{
2049 int heads;
2050 int sectors;
2051 sector_t cylinders;
2052 ulong dummy;
2053
2054 heads = 64;
2055 sectors = 32;
2056
2057 dummy = heads * sectors;
2058 cylinders = capacity;
2059 sector_div(cylinders,dummy);
2060
2061 /*
2062 * Handle extended translation size for logical drives
2063 * > 1Gb
2064 */
2065 if ((ulong)capacity >= 0x200000) {
2066 heads = 255;
2067 sectors = 63;
2068 dummy = heads * sectors;
2069 cylinders = capacity;
2070 sector_div(cylinders,dummy);
2071 }
2072
2073 /* return result */
2074 geom[0] = heads;
2075 geom[1] = sectors;
2076 geom[2] = cylinders;
2077
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 return 0;
2079}
2080
Moore, Ericf44e5462006-03-14 09:14:21 -07002081/* Search IOC page 3 to determine if this is hidden physical disk
2082 *
2083 */
2084int
Eric Moore793955f2007-01-29 09:42:20 -07002085mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id)
Moore, Ericf44e5462006-03-14 09:14:21 -07002086{
Eric Mooreb506ade2007-01-29 09:45:37 -07002087 struct inactive_raid_component_info *component_info;
Kashyap, Desaia7938b02009-05-29 16:53:56 +05302088 int i, j;
2089 RaidPhysDiskPage1_t *phys_disk;
Eric Moore793955f2007-01-29 09:42:20 -07002090 int rc = 0;
Kashyap, Desaia7938b02009-05-29 16:53:56 +05302091 int num_paths;
Moore, Ericf44e5462006-03-14 09:14:21 -07002092
Eric Moore793955f2007-01-29 09:42:20 -07002093 if (!ioc->raid_data.pIocPg3)
2094 goto out;
Moore, Ericf44e5462006-03-14 09:14:21 -07002095 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
Eric Moore793955f2007-01-29 09:42:20 -07002096 if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
2097 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
2098 rc = 1;
2099 goto out;
2100 }
2101 }
2102
Kashyap, Desaia7938b02009-05-29 16:53:56 +05302103 if (ioc->bus_type != SAS)
2104 goto out;
2105
2106 /*
2107 * Check if dual path
2108 */
2109 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2110 num_paths = mpt_raid_phys_disk_get_num_paths(ioc,
2111 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
2112 if (num_paths < 2)
2113 continue;
2114 phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
2115 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
2116 if (!phys_disk)
2117 continue;
2118 if ((mpt_raid_phys_disk_pg1(ioc,
2119 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
2120 phys_disk))) {
2121 kfree(phys_disk);
2122 continue;
2123 }
2124 for (j = 0; j < num_paths; j++) {
2125 if ((phys_disk->Path[j].Flags &
2126 MPI_RAID_PHYSDISK1_FLAG_INVALID))
2127 continue;
2128 if ((phys_disk->Path[j].Flags &
2129 MPI_RAID_PHYSDISK1_FLAG_BROKEN))
2130 continue;
2131 if ((id == phys_disk->Path[j].PhysDiskID) &&
2132 (channel == phys_disk->Path[j].PhysDiskBus)) {
2133 rc = 1;
2134 kfree(phys_disk);
2135 goto out;
2136 }
2137 }
2138 kfree(phys_disk);
2139 }
2140
2141
Eric Mooreb506ade2007-01-29 09:45:37 -07002142 /*
2143 * Check inactive list for matching phys disks
2144 */
2145 if (list_empty(&ioc->raid_data.inactive_list))
2146 goto out;
2147
Matthias Kaehlckeed5f6062008-03-09 12:16:27 +01002148 mutex_lock(&ioc->raid_data.inactive_list_mutex);
Eric Mooreb506ade2007-01-29 09:45:37 -07002149 list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
2150 list) {
2151 if ((component_info->d.PhysDiskID == id) &&
2152 (component_info->d.PhysDiskBus == channel))
2153 rc = 1;
2154 }
Matthias Kaehlckeed5f6062008-03-09 12:16:27 +01002155 mutex_unlock(&ioc->raid_data.inactive_list_mutex);
Eric Mooreb506ade2007-01-29 09:45:37 -07002156
Eric Moore793955f2007-01-29 09:42:20 -07002157 out:
2158 return rc;
Moore, Ericf44e5462006-03-14 09:14:21 -07002159}
2160EXPORT_SYMBOL(mptscsih_is_phys_disk);
2161
Eric Moore793955f2007-01-29 09:42:20 -07002162u8
2163mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
James Bottomleyc92f2222006-03-01 09:02:49 -06002164{
Eric Mooreb506ade2007-01-29 09:45:37 -07002165 struct inactive_raid_component_info *component_info;
Kashyap, Desaia7938b02009-05-29 16:53:56 +05302166 int i, j;
2167 RaidPhysDiskPage1_t *phys_disk;
Eric Moore793955f2007-01-29 09:42:20 -07002168 int rc = -ENXIO;
Kashyap, Desaia7938b02009-05-29 16:53:56 +05302169 int num_paths;
James Bottomleyc92f2222006-03-01 09:02:49 -06002170
Eric Moore793955f2007-01-29 09:42:20 -07002171 if (!ioc->raid_data.pIocPg3)
2172 goto out;
2173 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2174 if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
2175 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
2176 rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;
2177 goto out;
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002178 }
2179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180
Kashyap, Desaia7938b02009-05-29 16:53:56 +05302181 if (ioc->bus_type != SAS)
2182 goto out;
2183
2184 /*
2185 * Check if dual path
2186 */
2187 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2188 num_paths = mpt_raid_phys_disk_get_num_paths(ioc,
2189 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum);
2190 if (num_paths < 2)
2191 continue;
2192 phys_disk = kzalloc(offsetof(RaidPhysDiskPage1_t, Path) +
2193 (num_paths * sizeof(RAID_PHYS_DISK1_PATH)), GFP_KERNEL);
2194 if (!phys_disk)
2195 continue;
2196 if ((mpt_raid_phys_disk_pg1(ioc,
2197 ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum,
2198 phys_disk))) {
2199 kfree(phys_disk);
2200 continue;
2201 }
2202 for (j = 0; j < num_paths; j++) {
2203 if ((phys_disk->Path[j].Flags &
2204 MPI_RAID_PHYSDISK1_FLAG_INVALID))
2205 continue;
2206 if ((phys_disk->Path[j].Flags &
2207 MPI_RAID_PHYSDISK1_FLAG_BROKEN))
2208 continue;
2209 if ((id == phys_disk->Path[j].PhysDiskID) &&
2210 (channel == phys_disk->Path[j].PhysDiskBus)) {
2211 rc = phys_disk->PhysDiskNum;
2212 kfree(phys_disk);
2213 goto out;
2214 }
2215 }
2216 kfree(phys_disk);
2217 }
2218
Eric Mooreb506ade2007-01-29 09:45:37 -07002219 /*
2220 * Check inactive list for matching phys disks
2221 */
2222 if (list_empty(&ioc->raid_data.inactive_list))
2223 goto out;
2224
Matthias Kaehlckeed5f6062008-03-09 12:16:27 +01002225 mutex_lock(&ioc->raid_data.inactive_list_mutex);
Eric Mooreb506ade2007-01-29 09:45:37 -07002226 list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
2227 list) {
2228 if ((component_info->d.PhysDiskID == id) &&
2229 (component_info->d.PhysDiskBus == channel))
2230 rc = component_info->d.PhysDiskNum;
2231 }
Matthias Kaehlckeed5f6062008-03-09 12:16:27 +01002232 mutex_unlock(&ioc->raid_data.inactive_list_mutex);
Eric Mooreb506ade2007-01-29 09:45:37 -07002233
Eric Moore793955f2007-01-29 09:42:20 -07002234 out:
2235 return rc;
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002236}
Eric Moore793955f2007-01-29 09:42:20 -07002237EXPORT_SYMBOL(mptscsih_raid_id_to_num);
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002238
2239/*
2240 * OS entry point to allow for host driver to free allocated memory
2241 * Called if no device present or device being unloaded
2242 */
2243void
2244mptscsih_slave_destroy(struct scsi_device *sdev)
2245{
2246 struct Scsi_Host *host = sdev->host;
Eric Mooree7eae9f2007-09-29 10:15:59 -06002247 MPT_SCSI_HOST *hd = shost_priv(host);
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002248 VirtTarget *vtarget;
2249 VirtDevice *vdevice;
2250 struct scsi_target *starget;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002252 starget = scsi_target(sdev);
2253 vtarget = starget->hostdata;
2254 vdevice = sdev->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002256 mptscsih_search_running_cmds(hd, vdevice);
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002257 vtarget->num_luns--;
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002258 mptscsih_synchronize_cache(hd, vdevice);
2259 kfree(vdevice);
2260 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261}
2262
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -06002263/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2264/*
2265 * mptscsih_change_queue_depth - This function will set a devices queue depth
2266 * @sdev: per scsi_device pointer
2267 * @qdepth: requested queue depth
2268 *
2269 * Adding support for new 'change_queue_depth' api.
2270*/
2271int
2272mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273{
Eric Mooree7eae9f2007-09-29 10:15:59 -06002274 MPT_SCSI_HOST *hd = shost_priv(sdev->host);
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002275 VirtTarget *vtarget;
2276 struct scsi_target *starget;
2277 int max_depth;
2278 int tagged;
Eric Mooree80b0022007-09-14 18:49:03 -06002279 MPT_ADAPTER *ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002281 starget = scsi_target(sdev);
2282 vtarget = starget->hostdata;
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -06002283
Eric Mooree80b0022007-09-14 18:49:03 -06002284 if (ioc->bus_type == SPI) {
James Bottomleyc92f2222006-03-01 09:02:49 -06002285 if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 max_depth = 1;
James Bottomleyc92f2222006-03-01 09:02:49 -06002287 else if (sdev->type == TYPE_DISK &&
2288 vtarget->minSyncFactor <= MPT_ULTRA160)
2289 max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
2290 else
2291 max_depth = MPT_SCSI_CMD_PER_DEV_LOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 } else
Kashyap, Desai79a3ec12009-08-05 12:52:58 +05302293 max_depth = ioc->sh->can_queue;
2294
2295 if (!sdev->tagged_supported)
2296 max_depth = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297
2298 if (qdepth > max_depth)
2299 qdepth = max_depth;
2300 if (qdepth == 1)
2301 tagged = 0;
2302 else
2303 tagged = MSG_SIMPLE_TAG;
2304
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -06002305 scsi_adjust_queue_depth(sdev, tagged, qdepth);
2306 return sdev->queue_depth;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307}
2308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309/*
2310 * OS entry point to adjust the queue_depths on a per-device basis.
2311 * Called once per device the bus scan. Use it to force the queue_depth
2312 * member to 1 if a device does not support Q tags.
2313 * Return non-zero if fails.
2314 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002315int
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002316mptscsih_slave_configure(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317{
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002318 struct Scsi_Host *sh = sdev->host;
2319 VirtTarget *vtarget;
2320 VirtDevice *vdevice;
2321 struct scsi_target *starget;
Eric Mooree7eae9f2007-09-29 10:15:59 -06002322 MPT_SCSI_HOST *hd = shost_priv(sh);
Eric Mooree80b0022007-09-14 18:49:03 -06002323 MPT_ADAPTER *ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002325 starget = scsi_target(sdev);
2326 vtarget = starget->hostdata;
2327 vdevice = sdev->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
Eric Mooree80b0022007-09-14 18:49:03 -06002329 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Eric Moore793955f2007-01-29 09:42:20 -07002330 "device @ %p, channel=%d, id=%d, lun=%d\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002331 ioc->name, sdev, sdev->channel, sdev->id, sdev->lun));
2332 if (ioc->bus_type == SPI)
2333 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002334 "sdtr %d wdtr %d ppr %d inq length=%d\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002335 ioc->name, sdev->sdtr, sdev->wdtr,
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002336 sdev->ppr, sdev->inquiry_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Eric Moore793955f2007-01-29 09:42:20 -07002338 vdevice->configured_lun = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Eric Mooree80b0022007-09-14 18:49:03 -06002340 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 "Queue depth=%d, tflags=%x\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002342 ioc->name, sdev->queue_depth, vtarget->tflags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
Eric Mooree80b0022007-09-14 18:49:03 -06002344 if (ioc->bus_type == SPI)
2345 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002346 "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002347 ioc->name, vtarget->negoFlags, vtarget->maxOffset,
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002348 vtarget->minSyncFactor));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
Kashyap, Desai2f187862009-05-29 16:52:37 +05302350 mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH);
Eric Mooree80b0022007-09-14 18:49:03 -06002351 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 "tagged %d, simple %d, ordered %d\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002353 ioc->name,sdev->tagged_supported, sdev->simple_tags,
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002354 sdev->ordered_tags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
2356 return 0;
2357}
2358
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2360/*
2361 * Private routines...
2362 */
2363
2364/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2365/* Utility function to copy sense data from the scsi_cmnd buffer
2366 * to the FC and SCSI target structures.
2367 *
2368 */
2369static void
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002370mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371{
Eric Moorea69de502007-09-14 18:48:19 -06002372 VirtDevice *vdevice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 SCSIIORequest_t *pReq;
2374 u32 sense_count = le32_to_cpu(pScsiReply->SenseCount);
Eric Mooree80b0022007-09-14 18:49:03 -06002375 MPT_ADAPTER *ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
2377 /* Get target structure
2378 */
2379 pReq = (SCSIIORequest_t *) mf;
Eric Moorea69de502007-09-14 18:48:19 -06002380 vdevice = sc->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
2382 if (sense_count) {
2383 u8 *sense_data;
2384 int req_index;
2385
2386 /* Copy the sense received into the scsi command block. */
2387 req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
Eric Mooree80b0022007-09-14 18:49:03 -06002388 sense_data = ((u8 *)ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc));
2390
2391 /* Log SMART data (asc = 0x5D, non-IM case only) if required.
2392 */
Eric Mooree80b0022007-09-14 18:49:03 -06002393 if ((ioc->events) && (ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {
Eric Moorea69de502007-09-14 18:48:19 -06002394 if ((sense_data[12] == 0x5D) && (vdevice->vtarget->raidVolume == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396
Moore, Eric5b5ef4f2006-02-02 17:19:40 -07002397 idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE;
2399 ioc->events[idx].eventContext = ioc->eventContext;
2400
Dave Jones3d9780b2007-05-21 20:59:47 -04002401 ioc->events[idx].data[0] = (pReq->LUN[1] << 24) |
2402 (MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) |
2403 (sc->device->channel << 8) | sc->device->id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
Dave Jones3d9780b2007-05-21 20:59:47 -04002405 ioc->events[idx].data[1] = (sense_data[13] << 8) | sense_data[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
2407 ioc->eventContext++;
Eric Mooree80b0022007-09-14 18:49:03 -06002408 if (ioc->pcidev->vendor ==
Eric Moore786899b2006-07-11 17:22:22 -06002409 PCI_VENDOR_ID_IBM) {
Eric Mooree80b0022007-09-14 18:49:03 -06002410 mptscsih_issue_sep_command(ioc,
Eric Moorea69de502007-09-14 18:48:19 -06002411 vdevice->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
2412 vdevice->vtarget->tflags |=
Eric Moore786899b2006-07-11 17:22:22 -06002413 MPT_TARGET_FLAGS_LED_ON;
2414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 }
2416 }
2417 } else {
Eric Mooree80b0022007-09-14 18:49:03 -06002418 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hmmm... SenseData len=0! (?)\n",
2419 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 }
2421}
2422
Kashyap, Desaidb7051b2009-05-29 16:56:59 +05302423/**
2424 * mptscsih_get_scsi_lookup - retrieves scmd entry
2425 * @ioc: Pointer to MPT_ADAPTER structure
2426 * @i: index into the array
2427 *
2428 * Returns the scsi_cmd pointer
2429 */
2430struct scsi_cmnd *
2431mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i)
2432{
2433 unsigned long flags;
2434 struct scsi_cmnd *scmd;
2435
2436 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2437 scmd = ioc->ScsiLookup[i];
2438 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2439
2440 return scmd;
2441}
2442EXPORT_SYMBOL(mptscsih_get_scsi_lookup);
Eric Mooree8206382007-09-29 10:16:53 -06002443
2444/**
James Bottomleyfc847ab2009-06-09 23:01:01 +00002445 * mptscsih_getclear_scsi_lookup - retrieves and clears scmd entry from ScsiLookup[] array list
Kashyap, Desai2f187862009-05-29 16:52:37 +05302446 * @ioc: Pointer to MPT_ADAPTER structure
2447 * @i: index into the array
2448 *
Randy Dunlap7105a382008-02-29 22:03:27 -08002449 * Returns the scsi_cmd pointer
Kashyap, Desai2f187862009-05-29 16:52:37 +05302450 *
Eric Mooree8206382007-09-29 10:16:53 -06002451 **/
2452static struct scsi_cmnd *
2453mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i)
2454{
2455 unsigned long flags;
2456 struct scsi_cmnd *scmd;
2457
2458 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2459 scmd = ioc->ScsiLookup[i];
2460 ioc->ScsiLookup[i] = NULL;
2461 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2462
2463 return scmd;
2464}
2465
2466/**
2467 * mptscsih_set_scsi_lookup
2468 *
2469 * writes a scmd entry into the ScsiLookup[] array list
2470 *
2471 * @ioc: Pointer to MPT_ADAPTER structure
2472 * @i: index into the array
2473 * @scmd: scsi_cmnd pointer
2474 *
2475 **/
2476static void
2477mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd)
2478{
2479 unsigned long flags;
2480
2481 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2482 ioc->ScsiLookup[i] = scmd;
2483 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2484}
2485
2486/**
Randy Dunlap23f9b752007-10-15 17:29:33 -07002487 * SCPNT_TO_LOOKUP_IDX - searches for a given scmd in the ScsiLookup[] array list
Eric Mooree8206382007-09-29 10:16:53 -06002488 * @ioc: Pointer to MPT_ADAPTER structure
Randy Dunlap23f9b752007-10-15 17:29:33 -07002489 * @sc: scsi_cmnd pointer
2490 */
Eric Mooree8206382007-09-29 10:16:53 -06002491static int
2492SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *sc)
2493{
2494 unsigned long flags;
2495 int i, index=-1;
2496
2497 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2498 for (i = 0; i < ioc->req_depth; i++) {
2499 if (ioc->ScsiLookup[i] == sc) {
2500 index = i;
2501 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 }
2503 }
2504
Eric Mooree8206382007-09-29 10:16:53 -06002505 out:
2506 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2507 return index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508}
2509
2510/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002511int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
2513{
2514 MPT_SCSI_HOST *hd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515
Eric Mooree7eae9f2007-09-29 10:15:59 -06002516 if (ioc->sh == NULL || shost_priv(ioc->sh) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302519 hd = shost_priv(ioc->sh);
2520 switch (reset_phase) {
2521 case MPT_IOC_SETUP_RESET:
2522 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2523 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302524 break;
2525 case MPT_IOC_PRE_RESET:
2526 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2527 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302528 mptscsih_flush_running_cmds(hd);
2529 break;
2530 case MPT_IOC_POST_RESET:
2531 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2532 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
2533 if (ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING) {
2534 ioc->internal_cmds.status |=
2535 MPT_MGMT_STATUS_DID_IOCRESET;
2536 complete(&ioc->internal_cmds.done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 }
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302538 break;
2539 default:
2540 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 return 1; /* currently means nothing really */
2543}
2544
2545/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002546int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
2548{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
2550
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302551 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2552 "MPT event (=%02Xh) routed to SCSI host driver!\n",
2553 ioc->name, event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
Kashyap, Desai2f187862009-05-29 16:52:37 +05302555 if ((event == MPI_EVENT_IOC_BUS_RESET ||
2556 event == MPI_EVENT_EXT_BUS_RESET) &&
2557 (ioc->bus_type == SPI) && (ioc->soft_resets < -1))
2558 ioc->soft_resets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
2560 return 1; /* currently means nothing really */
2561}
2562
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2564/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 * Bus Scan and Domain Validation functionality ...
2566 */
2567
2568/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2569/*
2570 * mptscsih_scandv_complete - Scan and DV callback routine registered
2571 * to Fustion MPT (base) driver.
2572 *
2573 * @ioc: Pointer to MPT_ADAPTER structure
2574 * @mf: Pointer to original MPT request frame
2575 * @mr: Pointer to MPT reply frame (NULL if TurboReply)
2576 *
2577 * This routine is called from mpt.c::mpt_interrupt() at the completion
2578 * of any SCSI IO request.
2579 * This routine is registered with the Fusion MPT (base) driver at driver
2580 * load/init time via the mpt_register() API call.
2581 *
2582 * Returns 1 indicating alloc'd request frame ptr should be freed.
2583 *
2584 * Remark: Sets a completion code and (possibly) saves sense data
2585 * in the IOC member localReply structure.
2586 * Used ONLY for DV and other internal commands.
2587 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002588int
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302589mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
2590 MPT_FRAME_HDR *reply)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 SCSIIORequest_t *pReq;
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302593 SCSIIOReply_t *pReply;
2594 u8 cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 u16 req_idx;
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302596 u8 *sense_data;
2597 int sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302599 ioc->internal_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
2600 ioc->internal_cmds.completion_code = MPT_SCANDV_GOOD;
2601 if (!reply)
2602 goto out;
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002603
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302604 pReply = (SCSIIOReply_t *) reply;
2605 pReq = (SCSIIORequest_t *) req;
2606 ioc->internal_cmds.completion_code =
2607 mptscsih_get_completion_code(ioc, req, reply);
2608 ioc->internal_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
2609 memcpy(ioc->internal_cmds.reply, reply,
2610 min(MPT_DEFAULT_FRAME_SIZE, 4 * reply->u.reply.MsgLength));
2611 cmd = reply->u.hdr.Function;
2612 if (((cmd == MPI_FUNCTION_SCSI_IO_REQUEST) ||
2613 (cmd == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) &&
2614 (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)) {
2615 req_idx = le16_to_cpu(req->u.frame.hwhdr.msgctxu.fld.req_idx);
2616 sense_data = ((u8 *)ioc->sense_buf_pool +
2617 (req_idx * MPT_SENSE_BUFFER_ALLOC));
2618 sz = min_t(int, pReq->SenseBufferLength,
2619 MPT_SENSE_BUFFER_ALLOC);
2620 memcpy(ioc->internal_cmds.sense, sense_data, sz);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 }
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302622 out:
2623 if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_PENDING))
2624 return 0;
2625 ioc->internal_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
2626 complete(&ioc->internal_cmds.done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 return 1;
2628}
2629
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302631/**
2632 * mptscsih_get_completion_code -
2633 * @ioc: Pointer to MPT_ADAPTER structure
Randy Dunlap9cf46a32009-06-13 19:37:18 -07002634 * @req: Pointer to original MPT request frame
2635 * @reply: Pointer to MPT reply frame (NULL if TurboReply)
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302636 *
2637 **/
2638static int
2639mptscsih_get_completion_code(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
2640 MPT_FRAME_HDR *reply)
2641{
2642 SCSIIOReply_t *pReply;
2643 MpiRaidActionReply_t *pr;
2644 u8 scsi_status;
2645 u16 status;
2646 int completion_code;
2647
2648 pReply = (SCSIIOReply_t *)reply;
2649 status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
2650 scsi_status = pReply->SCSIStatus;
2651
2652 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2653 "IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh,"
2654 "IOCLogInfo=%08xh\n", ioc->name, status, pReply->SCSIState,
2655 scsi_status, le32_to_cpu(pReply->IOCLogInfo)));
2656
2657 switch (status) {
2658
2659 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
2660 completion_code = MPT_SCANDV_SELECTION_TIMEOUT;
2661 break;
2662
2663 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
2664 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
2665 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
2666 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
2667 completion_code = MPT_SCANDV_DID_RESET;
2668 break;
2669
2670 case MPI_IOCSTATUS_BUSY:
2671 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:
2672 completion_code = MPT_SCANDV_BUSY;
2673 break;
2674
2675 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
2676 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
2677 case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
2678 if (pReply->Function == MPI_FUNCTION_CONFIG) {
2679 completion_code = MPT_SCANDV_GOOD;
2680 } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
2681 pr = (MpiRaidActionReply_t *)reply;
2682 if (le16_to_cpu(pr->ActionStatus) ==
2683 MPI_RAID_ACTION_ASTATUS_SUCCESS)
2684 completion_code = MPT_SCANDV_GOOD;
2685 else
2686 completion_code = MPT_SCANDV_SOME_ERROR;
2687 } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID)
2688 completion_code = MPT_SCANDV_SENSE;
2689 else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
2690 if (req->u.scsireq.CDB[0] == INQUIRY)
2691 completion_code = MPT_SCANDV_ISSUE_SENSE;
2692 else
2693 completion_code = MPT_SCANDV_DID_RESET;
2694 } else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
2695 completion_code = MPT_SCANDV_DID_RESET;
2696 else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
2697 completion_code = MPT_SCANDV_DID_RESET;
2698 else if (scsi_status == MPI_SCSI_STATUS_BUSY)
2699 completion_code = MPT_SCANDV_BUSY;
2700 else
2701 completion_code = MPT_SCANDV_GOOD;
2702 break;
2703
2704 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
2705 if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
2706 completion_code = MPT_SCANDV_DID_RESET;
2707 else
2708 completion_code = MPT_SCANDV_SOME_ERROR;
2709 break;
2710 default:
2711 completion_code = MPT_SCANDV_SOME_ERROR;
2712 break;
2713
2714 } /* switch(status) */
2715
2716 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2717 " completionCode set to %08xh\n", ioc->name, completion_code));
2718 return completion_code;
2719}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
2721/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2722/**
2723 * mptscsih_do_cmd - Do internal command.
2724 * @hd: MPT_SCSI_HOST pointer
2725 * @io: INTERNAL_CMD pointer.
2726 *
2727 * Issue the specified internally generated command and do command
2728 * specific cleanup. For bus scan / DV only.
2729 * NOTES: If command is Inquiry and status is good,
2730 * initialize a target structure, save the data
2731 *
2732 * Remark: Single threaded access only.
2733 *
2734 * Return:
2735 * < 0 if an illegal command or no resources
2736 *
2737 * 0 if good
2738 *
2739 * > 0 if command complete but some type of completion error.
2740 */
2741static int
2742mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
2743{
2744 MPT_FRAME_HDR *mf;
2745 SCSIIORequest_t *pScsiReq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 int my_idx, ii, dir;
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302747 int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 char cmdLen;
2749 char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302750 u8 cmd = io->cmd;
2751 MPT_ADAPTER *ioc = hd->ioc;
2752 int ret = 0;
2753 unsigned long timeleft;
2754 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05302756 /* don't send internal command during diag reset */
2757 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
2758 if (ioc->ioc_reset_in_progress) {
2759 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2760 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2761 "%s: busy with host reset\n", ioc->name, __func__));
2762 return MPT_SCANDV_BUSY;
2763 }
2764 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2765
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302766 mutex_lock(&ioc->internal_cmds.mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
2768 /* Set command specific information
2769 */
2770 switch (cmd) {
2771 case INQUIRY:
2772 cmdLen = 6;
2773 dir = MPI_SCSIIO_CONTROL_READ;
2774 CDB[0] = cmd;
2775 CDB[4] = io->size;
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302776 timeout = 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 break;
2778
2779 case TEST_UNIT_READY:
2780 cmdLen = 6;
2781 dir = MPI_SCSIIO_CONTROL_READ;
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302782 timeout = 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 break;
2784
2785 case START_STOP:
2786 cmdLen = 6;
2787 dir = MPI_SCSIIO_CONTROL_READ;
2788 CDB[0] = cmd;
2789 CDB[4] = 1; /*Spin up the disk */
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302790 timeout = 15;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 break;
2792
2793 case REQUEST_SENSE:
2794 cmdLen = 6;
2795 CDB[0] = cmd;
2796 CDB[4] = io->size;
2797 dir = MPI_SCSIIO_CONTROL_READ;
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302798 timeout = 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 break;
2800
2801 case READ_BUFFER:
2802 cmdLen = 10;
2803 dir = MPI_SCSIIO_CONTROL_READ;
2804 CDB[0] = cmd;
2805 if (io->flags & MPT_ICFLAG_ECHO) {
2806 CDB[1] = 0x0A;
2807 } else {
2808 CDB[1] = 0x02;
2809 }
2810
2811 if (io->flags & MPT_ICFLAG_BUF_CAP) {
2812 CDB[1] |= 0x01;
2813 }
2814 CDB[6] = (io->size >> 16) & 0xFF;
2815 CDB[7] = (io->size >> 8) & 0xFF;
2816 CDB[8] = io->size & 0xFF;
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302817 timeout = 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 break;
2819
2820 case WRITE_BUFFER:
2821 cmdLen = 10;
2822 dir = MPI_SCSIIO_CONTROL_WRITE;
2823 CDB[0] = cmd;
2824 if (io->flags & MPT_ICFLAG_ECHO) {
2825 CDB[1] = 0x0A;
2826 } else {
2827 CDB[1] = 0x02;
2828 }
2829 CDB[6] = (io->size >> 16) & 0xFF;
2830 CDB[7] = (io->size >> 8) & 0xFF;
2831 CDB[8] = io->size & 0xFF;
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302832 timeout = 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 break;
2834
2835 case RESERVE:
2836 cmdLen = 6;
2837 dir = MPI_SCSIIO_CONTROL_READ;
2838 CDB[0] = cmd;
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302839 timeout = 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 break;
2841
2842 case RELEASE:
2843 cmdLen = 6;
2844 dir = MPI_SCSIIO_CONTROL_READ;
2845 CDB[0] = cmd;
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302846 timeout = 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 break;
2848
2849 case SYNCHRONIZE_CACHE:
2850 cmdLen = 10;
2851 dir = MPI_SCSIIO_CONTROL_READ;
2852 CDB[0] = cmd;
2853// CDB[1] = 0x02; /* set immediate bit */
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302854 timeout = 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 break;
2856
2857 default:
2858 /* Error Case */
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302859 ret = -EFAULT;
2860 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 }
2862
2863 /* Get and Populate a free Frame
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302864 * MsgContext set in mpt_get_msg_frame call
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 */
Eric Mooree80b0022007-09-14 18:49:03 -06002866 if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302867 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: No msg frames!\n",
2868 ioc->name, __func__));
2869 ret = MPT_SCANDV_BUSY;
2870 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 }
2872
2873 pScsiReq = (SCSIIORequest_t *) mf;
2874
2875 /* Get the request index */
2876 my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
2877 ADD_INDEX_LOG(my_idx); /* for debug */
2878
2879 if (io->flags & MPT_ICFLAG_PHYS_DISK) {
2880 pScsiReq->TargetID = io->physDiskNum;
2881 pScsiReq->Bus = 0;
2882 pScsiReq->ChainOffset = 0;
2883 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
2884 } else {
2885 pScsiReq->TargetID = io->id;
Eric Moore793955f2007-01-29 09:42:20 -07002886 pScsiReq->Bus = io->channel;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 pScsiReq->ChainOffset = 0;
2888 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
2889 }
2890
2891 pScsiReq->CDBLength = cmdLen;
2892 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
2893
2894 pScsiReq->Reserved = 0;
2895
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05302896 pScsiReq->MsgFlags = mpt_msg_flags(ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 /* MsgContext set in mpt_get_msg_fram call */
2898
Eric Moore793955f2007-01-29 09:42:20 -07002899 int_to_scsilun(io->lun, (struct scsi_lun *)pScsiReq->LUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900
2901 if (io->flags & MPT_ICFLAG_TAGGED_CMD)
2902 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);
2903 else
2904 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
2905
2906 if (cmd == REQUEST_SENSE) {
2907 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302908 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2909 "%s: Untagged! 0x%02x\n", ioc->name, __func__, cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 }
2911
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302912 for (ii = 0; ii < 16; ii++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 pScsiReq->CDB[ii] = CDB[ii];
2914
2915 pScsiReq->DataLength = cpu_to_le32(io->size);
Eric Mooree80b0022007-09-14 18:49:03 -06002916 pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 + (my_idx * MPT_SENSE_BUFFER_ALLOC));
2918
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302919 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2920 "%s: Sending Command 0x%02x for fw_channel=%d fw_id=%d lun=%d\n",
2921 ioc->name, __func__, cmd, io->channel, io->id, io->lun));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302923 if (dir == MPI_SCSIIO_CONTROL_READ)
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05302924 ioc->add_sge((char *) &pScsiReq->SGL,
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302925 MPT_SGE_FLAGS_SSIMPLE_READ | io->size, io->data_dma);
2926 else
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05302927 ioc->add_sge((char *) &pScsiReq->SGL,
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302928 MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size, io->data_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302930 INITIALIZE_MGMT_STATUS(ioc->internal_cmds.status)
Eric Mooree80b0022007-09-14 18:49:03 -06002931 mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302932 timeleft = wait_for_completion_timeout(&ioc->internal_cmds.done,
2933 timeout*HZ);
2934 if (!(ioc->internal_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2935 ret = MPT_SCANDV_DID_RESET;
2936 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2937 "%s: TIMED OUT for cmd=0x%02x\n", ioc->name, __func__,
2938 cmd));
2939 if (ioc->internal_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET) {
2940 mpt_free_msg_frame(ioc, mf);
2941 goto out;
2942 }
2943 if (!timeleft) {
2944 printk(MYIOC_s_WARN_FMT "Issuing Reset from %s!!\n",
2945 ioc->name, __func__);
2946 mpt_HardResetHandler(ioc, CAN_SLEEP);
2947 mpt_free_msg_frame(ioc, mf);
2948 }
2949 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 }
2951
Kashyap, Desai37c60f32009-05-29 16:44:06 +05302952 ret = ioc->internal_cmds.completion_code;
2953 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "%s: success, rc=0x%02x\n",
2954 ioc->name, __func__, ret));
2955
2956 out:
2957 CLEAR_MGMT_STATUS(ioc->internal_cmds.status)
2958 mutex_unlock(&ioc->internal_cmds.mutex);
2959 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960}
2961
2962/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2963/**
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002964 * mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks.
2965 * @hd: Pointer to a SCSI HOST structure
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002966 * @vdevice: virtual target device
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002967 *
2968 * Uses the ISR, but with special processing.
2969 * MUST be single-threaded.
2970 *
2971 */
2972static void
2973mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
2974{
2975 INTERNAL_CMD iocmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
Eric Moorecc78d302007-06-15 17:27:21 -06002977 /* Ignore hidden raid components, this is handled when the command
2978 * is sent to the volume
2979 */
2980 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
2981 return;
2982
2983 if (vdevice->vtarget->type != TYPE_DISK || vdevice->vtarget->deleted ||
2984 !vdevice->configured_lun)
2985 return;
2986
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 /* Following parameters will not change
2988 * in this routine.
2989 */
2990 iocmd.cmd = SYNCHRONIZE_CACHE;
2991 iocmd.flags = 0;
2992 iocmd.physDiskNum = -1;
2993 iocmd.data = NULL;
2994 iocmd.data_dma = -1;
2995 iocmd.size = 0;
2996 iocmd.rsvd = iocmd.rsvd2 = 0;
Eric Moore793955f2007-01-29 09:42:20 -07002997 iocmd.channel = vdevice->vtarget->channel;
2998 iocmd.id = vdevice->vtarget->id;
2999 iocmd.lun = vdevice->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000
Eric Moorecc78d302007-06-15 17:27:21 -06003001 mptscsih_do_cmd(hd, &iocmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002}
3003
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303004static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003005mptscsih_version_fw_show(struct device *dev, struct device_attribute *attr,
3006 char *buf)
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303007{
Tony Jonesee959b02008-02-22 00:13:36 +01003008 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003009 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303010 MPT_ADAPTER *ioc = hd->ioc;
3011
3012 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
3013 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
3014 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
3015 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
3016 ioc->facts.FWVersion.Word & 0x000000FF);
3017}
Tony Jonesee959b02008-02-22 00:13:36 +01003018static DEVICE_ATTR(version_fw, S_IRUGO, mptscsih_version_fw_show, NULL);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303019
3020static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003021mptscsih_version_bios_show(struct device *dev, struct device_attribute *attr,
3022 char *buf)
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303023{
Tony Jonesee959b02008-02-22 00:13:36 +01003024 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003025 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303026 MPT_ADAPTER *ioc = hd->ioc;
3027
3028 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
3029 (ioc->biosVersion & 0xFF000000) >> 24,
3030 (ioc->biosVersion & 0x00FF0000) >> 16,
3031 (ioc->biosVersion & 0x0000FF00) >> 8,
3032 ioc->biosVersion & 0x000000FF);
3033}
Tony Jonesee959b02008-02-22 00:13:36 +01003034static DEVICE_ATTR(version_bios, S_IRUGO, mptscsih_version_bios_show, NULL);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303035
3036static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003037mptscsih_version_mpi_show(struct device *dev, struct device_attribute *attr,
3038 char *buf)
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303039{
Tony Jonesee959b02008-02-22 00:13:36 +01003040 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003041 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303042 MPT_ADAPTER *ioc = hd->ioc;
3043
3044 return snprintf(buf, PAGE_SIZE, "%03x\n", ioc->facts.MsgVersion);
3045}
Tony Jonesee959b02008-02-22 00:13:36 +01003046static DEVICE_ATTR(version_mpi, S_IRUGO, mptscsih_version_mpi_show, NULL);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303047
3048static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003049mptscsih_version_product_show(struct device *dev,
3050 struct device_attribute *attr,
3051char *buf)
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303052{
Tony Jonesee959b02008-02-22 00:13:36 +01003053 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003054 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303055 MPT_ADAPTER *ioc = hd->ioc;
3056
3057 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->prod_name);
3058}
Tony Jonesee959b02008-02-22 00:13:36 +01003059static DEVICE_ATTR(version_product, S_IRUGO,
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303060 mptscsih_version_product_show, NULL);
3061
3062static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003063mptscsih_version_nvdata_persistent_show(struct device *dev,
3064 struct device_attribute *attr,
3065 char *buf)
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303066{
Tony Jonesee959b02008-02-22 00:13:36 +01003067 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003068 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303069 MPT_ADAPTER *ioc = hd->ioc;
3070
3071 return snprintf(buf, PAGE_SIZE, "%02xh\n",
3072 ioc->nvdata_version_persistent);
3073}
Tony Jonesee959b02008-02-22 00:13:36 +01003074static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303075 mptscsih_version_nvdata_persistent_show, NULL);
3076
3077static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003078mptscsih_version_nvdata_default_show(struct device *dev,
3079 struct device_attribute *attr, char *buf)
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303080{
Tony Jonesee959b02008-02-22 00:13:36 +01003081 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003082 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303083 MPT_ADAPTER *ioc = hd->ioc;
3084
3085 return snprintf(buf, PAGE_SIZE, "%02xh\n",ioc->nvdata_version_default);
3086}
Tony Jonesee959b02008-02-22 00:13:36 +01003087static DEVICE_ATTR(version_nvdata_default, S_IRUGO,
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303088 mptscsih_version_nvdata_default_show, NULL);
3089
3090static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003091mptscsih_board_name_show(struct device *dev, struct device_attribute *attr,
3092 char *buf)
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303093{
Tony Jonesee959b02008-02-22 00:13:36 +01003094 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003095 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303096 MPT_ADAPTER *ioc = hd->ioc;
3097
3098 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_name);
3099}
Tony Jonesee959b02008-02-22 00:13:36 +01003100static DEVICE_ATTR(board_name, S_IRUGO, mptscsih_board_name_show, NULL);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303101
3102static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003103mptscsih_board_assembly_show(struct device *dev,
3104 struct device_attribute *attr, char *buf)
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303105{
Tony Jonesee959b02008-02-22 00:13:36 +01003106 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003107 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303108 MPT_ADAPTER *ioc = hd->ioc;
3109
3110 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_assembly);
3111}
Tony Jonesee959b02008-02-22 00:13:36 +01003112static DEVICE_ATTR(board_assembly, S_IRUGO,
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303113 mptscsih_board_assembly_show, NULL);
3114
3115static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003116mptscsih_board_tracer_show(struct device *dev, struct device_attribute *attr,
3117 char *buf)
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303118{
Tony Jonesee959b02008-02-22 00:13:36 +01003119 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003120 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303121 MPT_ADAPTER *ioc = hd->ioc;
3122
3123 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_tracer);
3124}
Tony Jonesee959b02008-02-22 00:13:36 +01003125static DEVICE_ATTR(board_tracer, S_IRUGO,
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303126 mptscsih_board_tracer_show, NULL);
3127
3128static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003129mptscsih_io_delay_show(struct device *dev, struct device_attribute *attr,
3130 char *buf)
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303131{
Tony Jonesee959b02008-02-22 00:13:36 +01003132 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003133 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303134 MPT_ADAPTER *ioc = hd->ioc;
3135
3136 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
3137}
Tony Jonesee959b02008-02-22 00:13:36 +01003138static DEVICE_ATTR(io_delay, S_IRUGO,
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303139 mptscsih_io_delay_show, NULL);
3140
3141static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003142mptscsih_device_delay_show(struct device *dev, struct device_attribute *attr,
3143 char *buf)
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303144{
Tony Jonesee959b02008-02-22 00:13:36 +01003145 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003146 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303147 MPT_ADAPTER *ioc = hd->ioc;
3148
3149 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
3150}
Tony Jonesee959b02008-02-22 00:13:36 +01003151static DEVICE_ATTR(device_delay, S_IRUGO,
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303152 mptscsih_device_delay_show, NULL);
3153
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05303154static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003155mptscsih_debug_level_show(struct device *dev, struct device_attribute *attr,
3156 char *buf)
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05303157{
Tony Jonesee959b02008-02-22 00:13:36 +01003158 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003159 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05303160 MPT_ADAPTER *ioc = hd->ioc;
3161
3162 return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->debug_level);
3163}
3164static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003165mptscsih_debug_level_store(struct device *dev, struct device_attribute *attr,
3166 const char *buf, size_t count)
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05303167{
Tony Jonesee959b02008-02-22 00:13:36 +01003168 struct Scsi_Host *host = class_to_shost(dev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003169 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05303170 MPT_ADAPTER *ioc = hd->ioc;
3171 int val = 0;
3172
3173 if (sscanf(buf, "%x", &val) != 1)
3174 return -EINVAL;
3175
3176 ioc->debug_level = val;
3177 printk(MYIOC_s_INFO_FMT "debug_level=%08xh\n",
3178 ioc->name, ioc->debug_level);
3179 return strlen(buf);
3180}
Tony Jonesee959b02008-02-22 00:13:36 +01003181static DEVICE_ATTR(debug_level, S_IRUGO | S_IWUSR,
3182 mptscsih_debug_level_show, mptscsih_debug_level_store);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05303183
Tony Jonesee959b02008-02-22 00:13:36 +01003184struct device_attribute *mptscsih_host_attrs[] = {
3185 &dev_attr_version_fw,
3186 &dev_attr_version_bios,
3187 &dev_attr_version_mpi,
3188 &dev_attr_version_product,
3189 &dev_attr_version_nvdata_persistent,
3190 &dev_attr_version_nvdata_default,
3191 &dev_attr_board_name,
3192 &dev_attr_board_assembly,
3193 &dev_attr_board_tracer,
3194 &dev_attr_io_delay,
3195 &dev_attr_device_delay,
3196 &dev_attr_debug_level,
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303197 NULL,
3198};
Kashyap, Desai37c60f32009-05-29 16:44:06 +05303199
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303200EXPORT_SYMBOL(mptscsih_host_attrs);
3201
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04003202EXPORT_SYMBOL(mptscsih_remove);
3203EXPORT_SYMBOL(mptscsih_shutdown);
3204#ifdef CONFIG_PM
3205EXPORT_SYMBOL(mptscsih_suspend);
3206EXPORT_SYMBOL(mptscsih_resume);
3207#endif
3208EXPORT_SYMBOL(mptscsih_proc_info);
3209EXPORT_SYMBOL(mptscsih_info);
3210EXPORT_SYMBOL(mptscsih_qcmd);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04003211EXPORT_SYMBOL(mptscsih_slave_destroy);
3212EXPORT_SYMBOL(mptscsih_slave_configure);
3213EXPORT_SYMBOL(mptscsih_abort);
3214EXPORT_SYMBOL(mptscsih_dev_reset);
3215EXPORT_SYMBOL(mptscsih_bus_reset);
3216EXPORT_SYMBOL(mptscsih_host_reset);
3217EXPORT_SYMBOL(mptscsih_bios_param);
3218EXPORT_SYMBOL(mptscsih_io_done);
3219EXPORT_SYMBOL(mptscsih_taskmgmt_complete);
3220EXPORT_SYMBOL(mptscsih_scandv_complete);
3221EXPORT_SYMBOL(mptscsih_event_process);
3222EXPORT_SYMBOL(mptscsih_ioc_reset);
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -06003223EXPORT_SYMBOL(mptscsih_change_queue_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04003225/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/