blob: 0c252f60c4c1ba2c5ee4e7012b21dc6dddf36129 [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, Sathyaf36789e2007-08-14 16:22:54 +05306 * Copyright (c) 1999-2007 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 */
Eric Mooree8206382007-09-29 10:16:53 -060083static struct scsi_cmnd * mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);
84static struct scsi_cmnd * mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i);
85static void mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd);
86static int SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *scmd);
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 -070095static int mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd);
96static int mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout );
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Eric Moore793955f2007-01-29 09:42:20 -070098static int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400100int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
101int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400103int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
Moore, Eric Deanc7c82982005-11-16 18:54:25 -0700105static void mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400107void mptscsih_remove(struct pci_dev *);
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -0700108void mptscsih_shutdown(struct pci_dev *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#ifdef CONFIG_PM
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400110int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);
111int mptscsih_resume(struct pci_dev *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#endif
113
FUJITA Tomonorib80ca4f2008-01-13 15:46:13 +0900114#define SNS_LEN(scp) SCSI_SENSE_BUFFERSIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
117/**
118 * mptscsih_add_sge - Place a simple SGE at address pAddr.
119 * @pAddr: virtual address for SGE
120 * @flagslength: SGE flags and data transfer length
121 * @dma_addr: Physical address
122 *
123 * This routine places a MPT request frame back on the MPT adapter's
124 * FreeQ.
125 */
126static inline void
127mptscsih_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
128{
129 if (sizeof(dma_addr_t) == sizeof(u64)) {
130 SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
131 u32 tmp = dma_addr & 0xFFFFFFFF;
132
133 pSge->FlagsLength = cpu_to_le32(flagslength);
134 pSge->Address.Low = cpu_to_le32(tmp);
135 tmp = (u32) ((u64)dma_addr >> 32);
136 pSge->Address.High = cpu_to_le32(tmp);
137
138 } else {
139 SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
140 pSge->FlagsLength = cpu_to_le32(flagslength);
141 pSge->Address = cpu_to_le32(dma_addr);
142 }
143} /* mptscsih_add_sge() */
144
145/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
146/**
147 * mptscsih_add_chain - Place a chain SGE at address pAddr.
148 * @pAddr: virtual address for SGE
149 * @next: nextChainOffset value (u32's)
150 * @length: length of next SGL segment
151 * @dma_addr: Physical address
152 *
153 * This routine places a MPT request frame back on the MPT adapter's
154 * FreeQ.
155 */
156static inline void
157mptscsih_add_chain(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
158{
159 if (sizeof(dma_addr_t) == sizeof(u64)) {
160 SGEChain64_t *pChain = (SGEChain64_t *) pAddr;
161 u32 tmp = dma_addr & 0xFFFFFFFF;
162
163 pChain->Length = cpu_to_le16(length);
164 pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
165
166 pChain->NextChainOffset = next;
167
168 pChain->Address.Low = cpu_to_le32(tmp);
169 tmp = (u32) ((u64)dma_addr >> 32);
170 pChain->Address.High = cpu_to_le32(tmp);
171 } else {
172 SGEChain32_t *pChain = (SGEChain32_t *) pAddr;
173 pChain->Length = cpu_to_le16(length);
174 pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
175 pChain->NextChainOffset = next;
176 pChain->Address = cpu_to_le32(dma_addr);
177 }
178} /* mptscsih_add_chain() */
179
180/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
181/*
182 * mptscsih_getFreeChainBuffer - Function to get a free chain
183 * from the MPT_SCSI_HOST FreeChainQ.
184 * @ioc: Pointer to MPT_ADAPTER structure
185 * @req_idx: Index of the SCSI IO request frame. (output)
186 *
187 * return SUCCESS or FAILED
188 */
189static inline int
190mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)
191{
192 MPT_FRAME_HDR *chainBuf;
193 unsigned long flags;
194 int rc;
195 int chain_idx;
196
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530197 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "getFreeChainBuffer called\n",
Eric Moore29dd3602007-09-14 18:46:51 -0600198 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 spin_lock_irqsave(&ioc->FreeQlock, flags);
200 if (!list_empty(&ioc->FreeChainQ)) {
201 int offset;
202
203 chainBuf = list_entry(ioc->FreeChainQ.next, MPT_FRAME_HDR,
204 u.frame.linkage.list);
205 list_del(&chainBuf->u.frame.linkage.list);
206 offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;
207 chain_idx = offset / ioc->req_sz;
208 rc = SUCCESS;
Eric Moore29dd3602007-09-14 18:46:51 -0600209 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT
210 "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
211 ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 } else {
213 rc = FAILED;
214 chain_idx = MPT_HOST_NO_CHAIN;
Eric Moore29dd3602007-09-14 18:46:51 -0600215 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n",
216 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 }
218 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
219
220 *retIndex = chain_idx;
221 return rc;
222} /* mptscsih_getFreeChainBuffer() */
223
224/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
225/*
226 * mptscsih_AddSGE - Add a SGE (plus chain buffers) to the
227 * SCSIIORequest_t Message Frame.
228 * @ioc: Pointer to MPT_ADAPTER structure
229 * @SCpnt: Pointer to scsi_cmnd structure
230 * @pReq: Pointer to SCSIIORequest_t structure
231 *
232 * Returns ...
233 */
234static int
235mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
236 SCSIIORequest_t *pReq, int req_idx)
237{
238 char *psge;
239 char *chainSge;
240 struct scatterlist *sg;
241 int frm_sz;
242 int sges_left, sg_done;
243 int chain_idx = MPT_HOST_NO_CHAIN;
244 int sgeOffset;
245 int numSgeSlots, numSgeThisFrame;
246 u32 sgflags, sgdir, thisxfer = 0;
247 int chain_dma_off = 0;
248 int newIndex;
249 int ii;
250 dma_addr_t v2;
251 u32 RequestNB;
252
253 sgdir = le32_to_cpu(pReq->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK;
254 if (sgdir == MPI_SCSIIO_CONTROL_WRITE) {
255 sgdir = MPT_TRANSFER_HOST_TO_IOC;
256 } else {
257 sgdir = MPT_TRANSFER_IOC_TO_HOST;
258 }
259
260 psge = (char *) &pReq->SGL;
261 frm_sz = ioc->req_sz;
262
263 /* Map the data portion, if any.
264 * sges_left = 0 if no data transfer.
265 */
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900266 sges_left = scsi_dma_map(SCpnt);
267 if (sges_left < 0)
268 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 /* Handle the SG case.
271 */
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900272 sg = scsi_sglist(SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 sg_done = 0;
274 sgeOffset = sizeof(SCSIIORequest_t) - sizeof(SGE_IO_UNION);
275 chainSge = NULL;
276
277 /* Prior to entering this loop - the following must be set
278 * current MF: sgeOffset (bytes)
279 * chainSge (Null if original MF is not a chain buffer)
280 * sg_done (num SGE done for this MF)
281 */
282
283nextSGEset:
284 numSgeSlots = ((frm_sz - sgeOffset) / (sizeof(u32) + sizeof(dma_addr_t)) );
285 numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots;
286
287 sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | MPT_SGE_FLAGS_ADDRESSING | sgdir;
288
289 /* Get first (num - 1) SG elements
290 * Skip any SG entries with a length of 0
291 * NOTE: at finish, sg and psge pointed to NEXT data/location positions
292 */
293 for (ii=0; ii < (numSgeThisFrame-1); ii++) {
294 thisxfer = sg_dma_len(sg);
295 if (thisxfer == 0) {
Jens Axboeed17b032007-07-16 15:30:33 +0200296 sg = sg_next(sg); /* Get next SG element from the OS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 sg_done++;
298 continue;
299 }
300
301 v2 = sg_dma_address(sg);
302 mptscsih_add_sge(psge, sgflags | thisxfer, v2);
303
Jens Axboeed17b032007-07-16 15:30:33 +0200304 sg = sg_next(sg); /* Get next SG element from the OS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 psge += (sizeof(u32) + sizeof(dma_addr_t));
306 sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
307 sg_done++;
308 }
309
310 if (numSgeThisFrame == sges_left) {
311 /* Add last element, end of buffer and end of list flags.
312 */
313 sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT |
314 MPT_SGE_FLAGS_END_OF_BUFFER |
315 MPT_SGE_FLAGS_END_OF_LIST;
316
317 /* Add last SGE and set termination flags.
318 * Note: Last SGE may have a length of 0 - which should be ok.
319 */
320 thisxfer = sg_dma_len(sg);
321
322 v2 = sg_dma_address(sg);
323 mptscsih_add_sge(psge, sgflags | thisxfer, v2);
324 /*
Jens Axboeed17b032007-07-16 15:30:33 +0200325 sg = sg_next(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 psge += (sizeof(u32) + sizeof(dma_addr_t));
327 */
328 sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
329 sg_done++;
330
331 if (chainSge) {
332 /* The current buffer is a chain buffer,
333 * but there is not another one.
334 * Update the chain element
335 * Offset and Length fields.
336 */
337 mptscsih_add_chain((char *)chainSge, 0, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
338 } else {
339 /* The current buffer is the original MF
340 * and there is no Chain buffer.
341 */
342 pReq->ChainOffset = 0;
343 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530344 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
346 ioc->RequestNB[req_idx] = RequestNB;
347 }
348 } else {
349 /* At least one chain buffer is needed.
350 * Complete the first MF
351 * - last SGE element, set the LastElement bit
352 * - set ChainOffset (words) for orig MF
353 * (OR finish previous MF chain buffer)
354 * - update MFStructPtr ChainIndex
355 * - Populate chain element
356 * Also
357 * Loop until done.
358 */
359
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530360 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SG: Chain Required! sg done %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 ioc->name, sg_done));
362
363 /* Set LAST_ELEMENT flag for last non-chain element
364 * in the buffer. Since psge points at the NEXT
365 * SGE element, go back one SGE element, update the flags
366 * and reset the pointer. (Note: sgflags & thisxfer are already
367 * set properly).
368 */
369 if (sg_done) {
370 u32 *ptmp = (u32 *) (psge - (sizeof(u32) + sizeof(dma_addr_t)));
371 sgflags = le32_to_cpu(*ptmp);
372 sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT;
373 *ptmp = cpu_to_le32(sgflags);
374 }
375
376 if (chainSge) {
377 /* The current buffer is a chain buffer.
378 * chainSge points to the previous Chain Element.
379 * Update its chain element Offset and Length (must
380 * include chain element size) fields.
381 * Old chain element is now complete.
382 */
383 u8 nextChain = (u8) (sgeOffset >> 2);
384 sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
385 mptscsih_add_chain((char *)chainSge, nextChain, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
386 } else {
387 /* The original MF buffer requires a chain buffer -
388 * set the offset.
389 * Last element in this MF is a chain element.
390 */
391 pReq->ChainOffset = (u8) (sgeOffset >> 2);
392 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530393 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 -0700394 ioc->RequestNB[req_idx] = RequestNB;
395 }
396
397 sges_left -= sg_done;
398
399
400 /* NOTE: psge points to the beginning of the chain element
401 * in current buffer. Get a chain buffer.
402 */
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200403 if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530404 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200405 "getFreeChainBuffer FAILED SCSI cmd=%02x (%p)\n",
406 ioc->name, pReq->CDB[0], SCpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return FAILED;
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 /* Update the tracking arrays.
411 * If chainSge == NULL, update ReqToChain, else ChainToChain
412 */
413 if (chainSge) {
414 ioc->ChainToChain[chain_idx] = newIndex;
415 } else {
416 ioc->ReqToChain[req_idx] = newIndex;
417 }
418 chain_idx = newIndex;
419 chain_dma_off = ioc->req_sz * chain_idx;
420
421 /* Populate the chainSGE for the current buffer.
422 * - Set chain buffer pointer to psge and fill
423 * out the Address and Flags fields.
424 */
425 chainSge = (char *) psge;
Eric Moore29dd3602007-09-14 18:46:51 -0600426 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT " Current buff @ %p (index 0x%x)",
427 ioc->name, psge, req_idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 /* Start the SGE for the next buffer
430 */
431 psge = (char *) (ioc->ChainBuffer + chain_dma_off);
432 sgeOffset = 0;
433 sg_done = 0;
434
Eric Moore29dd3602007-09-14 18:46:51 -0600435 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT " Chain buff @ %p (index 0x%x)\n",
436 ioc->name, psge, chain_idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 /* Start the SGE for the next buffer
439 */
440
441 goto nextSGEset;
442 }
443
444 return SUCCESS;
445} /* mptscsih_AddSGE() */
446
Eric Moore786899b2006-07-11 17:22:22 -0600447static void
448mptscsih_issue_sep_command(MPT_ADAPTER *ioc, VirtTarget *vtarget,
449 U32 SlotStatus)
450{
451 MPT_FRAME_HDR *mf;
452 SEPRequest_t *SEPMsg;
453
Eric Moorecc78d302007-06-15 17:27:21 -0600454 if (ioc->bus_type != SAS)
455 return;
456
457 /* Not supported for hidden raid components
458 */
459 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
Eric Moore786899b2006-07-11 17:22:22 -0600460 return;
461
462 if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530463 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: no msg frames!!\n",
Eric Moore786899b2006-07-11 17:22:22 -0600464 ioc->name,__FUNCTION__));
465 return;
466 }
467
468 SEPMsg = (SEPRequest_t *)mf;
469 SEPMsg->Function = MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
Eric Moore793955f2007-01-29 09:42:20 -0700470 SEPMsg->Bus = vtarget->channel;
471 SEPMsg->TargetID = vtarget->id;
Eric Moore786899b2006-07-11 17:22:22 -0600472 SEPMsg->Action = MPI_SEP_REQ_ACTION_WRITE_STATUS;
473 SEPMsg->SlotStatus = SlotStatus;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530474 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Eric Moore793955f2007-01-29 09:42:20 -0700475 "Sending SEP cmd=%x channel=%d id=%d\n",
476 ioc->name, SlotStatus, SEPMsg->Bus, SEPMsg->TargetID));
Eric Moore786899b2006-07-11 17:22:22 -0600477 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
478}
479
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530480#ifdef CONFIG_FUSION_LOGGING
Eric Moorec6c727a2007-01-29 09:44:54 -0700481/**
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530482 * mptscsih_info_scsiio - debug print info on reply frame
Eric Moorec6c727a2007-01-29 09:44:54 -0700483 * @ioc: Pointer to MPT_ADAPTER structure
Eric Moorec6c727a2007-01-29 09:44:54 -0700484 * @sc: original scsi cmnd pointer
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530485 * @pScsiReply: Pointer to MPT reply frame
486 *
487 * MPT_DEBUG_REPLY needs to be enabled to obtain this info
Eric Moorec6c727a2007-01-29 09:44:54 -0700488 *
489 * Refer to lsi/mpi.h.
490 **/
491static void
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530492mptscsih_info_scsiio(MPT_ADAPTER *ioc, struct scsi_cmnd *sc, SCSIIOReply_t * pScsiReply)
Eric Moorec6c727a2007-01-29 09:44:54 -0700493{
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530494 char *desc = NULL;
495 char *desc1 = NULL;
496 u16 ioc_status;
497 u8 skey, asc, ascq;
498
499 ioc_status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
Eric Moorec6c727a2007-01-29 09:44:54 -0700500
501 switch (ioc_status) {
502
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530503 case MPI_IOCSTATUS_SUCCESS:
504 desc = "success";
Eric Moorec6c727a2007-01-29 09:44:54 -0700505 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530506 case MPI_IOCSTATUS_SCSI_INVALID_BUS:
507 desc = "invalid bus";
Eric Moorec6c727a2007-01-29 09:44:54 -0700508 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530509 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID:
510 desc = "invalid target_id";
Eric Moorec6c727a2007-01-29 09:44:54 -0700511 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530512 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
513 desc = "device not there";
Eric Moorec6c727a2007-01-29 09:44:54 -0700514 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530515 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN:
516 desc = "data overrun";
Eric Moorec6c727a2007-01-29 09:44:54 -0700517 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530518 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:
519 desc = "data underrun";
Eric Moorec6c727a2007-01-29 09:44:54 -0700520 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530521 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR:
522 desc = "I/O data error";
Eric Moorec6c727a2007-01-29 09:44:54 -0700523 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530524 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR:
525 desc = "protocol error";
Eric Moorec6c727a2007-01-29 09:44:54 -0700526 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530527 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED:
528 desc = "task terminated";
Eric Moorec6c727a2007-01-29 09:44:54 -0700529 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530530 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
531 desc = "residual mismatch";
Eric Moorec6c727a2007-01-29 09:44:54 -0700532 break;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530533 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
534 desc = "task management failed";
535 break;
536 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED:
537 desc = "IOC terminated";
538 break;
539 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:
540 desc = "ext terminated";
541 break;
542 default:
543 desc = "";
Eric Moorec6c727a2007-01-29 09:44:54 -0700544 break;
545 }
546
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530547 switch (pScsiReply->SCSIStatus)
548 {
Eric Moorec6c727a2007-01-29 09:44:54 -0700549
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530550 case MPI_SCSI_STATUS_SUCCESS:
551 desc1 = "success";
552 break;
553 case MPI_SCSI_STATUS_CHECK_CONDITION:
554 desc1 = "check condition";
555 break;
556 case MPI_SCSI_STATUS_CONDITION_MET:
557 desc1 = "condition met";
558 break;
559 case MPI_SCSI_STATUS_BUSY:
560 desc1 = "busy";
561 break;
562 case MPI_SCSI_STATUS_INTERMEDIATE:
563 desc1 = "intermediate";
564 break;
565 case MPI_SCSI_STATUS_INTERMEDIATE_CONDMET:
566 desc1 = "intermediate condmet";
567 break;
568 case MPI_SCSI_STATUS_RESERVATION_CONFLICT:
569 desc1 = "reservation conflict";
570 break;
571 case MPI_SCSI_STATUS_COMMAND_TERMINATED:
572 desc1 = "command terminated";
573 break;
574 case MPI_SCSI_STATUS_TASK_SET_FULL:
575 desc1 = "task set full";
576 break;
577 case MPI_SCSI_STATUS_ACA_ACTIVE:
578 desc1 = "aca active";
579 break;
580 case MPI_SCSI_STATUS_FCPEXT_DEVICE_LOGGED_OUT:
581 desc1 = "fcpext device logged out";
582 break;
583 case MPI_SCSI_STATUS_FCPEXT_NO_LINK:
584 desc1 = "fcpext no link";
585 break;
586 case MPI_SCSI_STATUS_FCPEXT_UNASSIGNED:
587 desc1 = "fcpext unassigned";
588 break;
589 default:
590 desc1 = "";
591 break;
592 }
Eric Moorec6c727a2007-01-29 09:44:54 -0700593
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530594 scsi_print_command(sc);
Eric Moore29dd3602007-09-14 18:46:51 -0600595 printk(MYIOC_s_DEBUG_FMT "\tfw_channel = %d, fw_id = %d\n",
596 ioc->name, pScsiReply->Bus, pScsiReply->TargetID);
597 printk(MYIOC_s_DEBUG_FMT "\trequest_len = %d, underflow = %d, "
598 "resid = %d\n", ioc->name, scsi_bufflen(sc), sc->underflow,
599 scsi_get_resid(sc));
600 printk(MYIOC_s_DEBUG_FMT "\ttag = %d, transfer_count = %d, "
601 "sc->result = %08X\n", ioc->name, le16_to_cpu(pScsiReply->TaskTag),
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530602 le32_to_cpu(pScsiReply->TransferCount), sc->result);
Eric Moore29dd3602007-09-14 18:46:51 -0600603 printk(MYIOC_s_DEBUG_FMT "\tiocstatus = %s (0x%04x), "
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530604 "scsi_status = %s (0x%02x), scsi_state = (0x%02x)\n",
Eric Moore29dd3602007-09-14 18:46:51 -0600605 ioc->name, desc, ioc_status, desc1, pScsiReply->SCSIStatus,
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530606 pScsiReply->SCSIState);
607
608 if (pScsiReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
609 skey = sc->sense_buffer[2] & 0x0F;
610 asc = sc->sense_buffer[12];
611 ascq = sc->sense_buffer[13];
612
Eric Moore29dd3602007-09-14 18:46:51 -0600613 printk(MYIOC_s_DEBUG_FMT "\t[sense_key,asc,ascq]: "
614 "[0x%02x,0x%02x,0x%02x]\n", ioc->name, skey, asc, ascq);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530615 }
616
617 /*
618 * Look for + dump FCP ResponseInfo[]!
619 */
620 if (pScsiReply->SCSIState & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
621 pScsiReply->ResponseInfo)
Eric Moore29dd3602007-09-14 18:46:51 -0600622 printk(MYIOC_s_DEBUG_FMT "response_info = %08xh\n",
623 ioc->name, le32_to_cpu(pScsiReply->ResponseInfo));
Eric Moorec6c727a2007-01-29 09:44:54 -0700624}
625#endif
626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
628/*
629 * mptscsih_io_done - Main SCSI IO callback routine registered to
630 * Fusion MPT (base) driver
631 * @ioc: Pointer to MPT_ADAPTER structure
632 * @mf: Pointer to original MPT request frame
633 * @r: Pointer to MPT reply frame (NULL if TurboReply)
634 *
635 * This routine is called from mpt.c::mpt_interrupt() at the completion
636 * of any SCSI IO request.
637 * This routine is registered with the Fusion MPT (base) driver at driver
638 * load/init time via the mpt_register() API call.
639 *
640 * Returns 1 indicating alloc'd request frame ptr should be freed.
641 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400642int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
644{
645 struct scsi_cmnd *sc;
646 MPT_SCSI_HOST *hd;
647 SCSIIORequest_t *pScsiReq;
648 SCSIIOReply_t *pScsiReply;
Moore, Eric2254c862006-01-17 17:06:29 -0700649 u16 req_idx, req_idx_MR;
Eric Moorea69de502007-09-14 18:48:19 -0600650 VirtDevice *vdevice;
Eric Moore786899b2006-07-11 17:22:22 -0600651 VirtTarget *vtarget;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Eric Mooree7eae9f2007-09-29 10:15:59 -0600653 hd = shost_priv(ioc->sh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
Moore, Eric2254c862006-01-17 17:06:29 -0700655 req_idx_MR = (mr != NULL) ?
656 le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx) : req_idx;
657 if ((req_idx != req_idx_MR) ||
658 (mf->u.frame.linkage.arg1 == 0xdeadbeaf)) {
659 printk(MYIOC_s_ERR_FMT "Received a mf that was already freed\n",
660 ioc->name);
661 printk (MYIOC_s_ERR_FMT
662 "req_idx=%x req_idx_MR=%x mf=%p mr=%p sc=%p\n",
663 ioc->name, req_idx, req_idx_MR, mf, mr,
Eric Mooree8206382007-09-29 10:16:53 -0600664 mptscsih_get_scsi_lookup(ioc, req_idx_MR));
Moore, Eric2254c862006-01-17 17:06:29 -0700665 return 0;
666 }
667
Eric Mooree8206382007-09-29 10:16:53 -0600668 sc = mptscsih_getclear_scsi_lookup(ioc, req_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 if (sc == NULL) {
670 MPIHeader_t *hdr = (MPIHeader_t *)mf;
671
672 /* Remark: writeSDP1 will use the ScsiDoneCtx
673 * If a SCSI I/O cmd, device disabled by OS and
674 * completion done. Cannot touch sc struct. Just free mem.
675 */
676 if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST)
677 printk(MYIOC_s_ERR_FMT "NULL ScsiCmd ptr!\n",
678 ioc->name);
679
680 mptscsih_freeChainBuffers(ioc, req_idx);
681 return 1;
682 }
683
Eric Moore3dc0b032006-07-11 17:32:33 -0600684 if ((unsigned char *)mf != sc->host_scribble) {
685 mptscsih_freeChainBuffers(ioc, req_idx);
686 return 1;
687 }
688
689 sc->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 sc->result = DID_OK << 16; /* Set default reply as OK */
691 pScsiReq = (SCSIIORequest_t *) mf;
692 pScsiReply = (SCSIIOReply_t *) mr;
693
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200694 if((ioc->facts.MsgVersion >= MPI_VERSION_01_05) && pScsiReply){
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530695 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200696 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task-tag=%d)\n",
697 ioc->name, mf, mr, sc, req_idx, pScsiReply->TaskTag));
698 }else{
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530699 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200700 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",
701 ioc->name, mf, mr, sc, req_idx));
702 }
703
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if (pScsiReply == NULL) {
705 /* special context reply handling */
706 ;
707 } else {
708 u32 xfer_cnt;
709 u16 status;
710 u8 scsi_state, scsi_status;
Eric Moorec6c727a2007-01-29 09:44:54 -0700711 u32 log_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713 status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
714 scsi_state = pScsiReply->SCSIState;
715 scsi_status = pScsiReply->SCSIStatus;
716 xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900717 scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
Eric Moorec6c727a2007-01-29 09:44:54 -0700718 log_info = le32_to_cpu(pScsiReply->IOCLogInfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600720 /*
721 * if we get a data underrun indication, yet no data was
722 * transferred and the SCSI status indicates that the
723 * command was never started, change the data underrun
724 * to success
725 */
726 if (status == MPI_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
727 (scsi_status == MPI_SCSI_STATUS_BUSY ||
728 scsi_status == MPI_SCSI_STATUS_RESERVATION_CONFLICT ||
729 scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)) {
730 status = MPI_IOCSTATUS_SUCCESS;
731 }
732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400734 mptscsih_copy_sense_data(sc, hd, mf, pScsiReply);
735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 /*
737 * Look for + dump FCP ResponseInfo[]!
738 */
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600739 if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
740 pScsiReply->ResponseInfo) {
Eric Moore29dd3602007-09-14 18:46:51 -0600741 printk(MYIOC_s_NOTE_FMT "[%d:%d:%d:%d] "
742 "FCP_ResponseInfo=%08xh\n", ioc->name,
Eric Moorec6c727a2007-01-29 09:44:54 -0700743 sc->device->host->host_no, sc->device->channel,
744 sc->device->id, sc->device->lun,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 le32_to_cpu(pScsiReply->ResponseInfo));
746 }
747
748 switch(status) {
749 case MPI_IOCSTATUS_BUSY: /* 0x0002 */
750 /* CHECKME!
751 * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry)
752 * But not: DID_BUS_BUSY lest one risk
753 * killing interrupt handler:-(
754 */
755 sc->result = SAM_STAT_BUSY;
756 break;
757
758 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
759 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
760 sc->result = DID_BAD_TARGET << 16;
761 break;
762
763 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
764 /* Spoof to SCSI Selection Timeout! */
Moore, Eric65207fe2006-04-21 16:14:35 -0600765 if (ioc->bus_type != FC)
766 sc->result = DID_NO_CONNECT << 16;
767 /* else fibre, just stall until rescan event */
768 else
769 sc->result = DID_REQUEUE << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771 if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)
772 hd->sel_timeout[pScsiReq->TargetID]++;
Eric Moore786899b2006-07-11 17:22:22 -0600773
Eric Moorea69de502007-09-14 18:48:19 -0600774 vdevice = sc->device->hostdata;
775 if (!vdevice)
Eric Moore786899b2006-07-11 17:22:22 -0600776 break;
Eric Moorea69de502007-09-14 18:48:19 -0600777 vtarget = vdevice->vtarget;
Eric Moore786899b2006-07-11 17:22:22 -0600778 if (vtarget->tflags & MPT_TARGET_FLAGS_LED_ON) {
779 mptscsih_issue_sep_command(ioc, vtarget,
780 MPI_SEP_REQ_SLOTSTATUS_UNCONFIGURED);
781 vtarget->tflags &= ~MPT_TARGET_FLAGS_LED_ON;
782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 break;
784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
Eric Moorebf451522006-07-11 17:25:35 -0600786 if ( ioc->bus_type == SAS ) {
787 u16 ioc_status = le16_to_cpu(pScsiReply->IOCStatus);
788 if (ioc_status & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
Eric Moorec6c727a2007-01-29 09:44:54 -0700789 if ((log_info & SAS_LOGINFO_MASK)
790 == SAS_LOGINFO_NEXUS_LOSS) {
Eric Moorebf451522006-07-11 17:25:35 -0600791 sc->result = (DID_BUS_BUSY << 16);
792 break;
793 }
794 }
Eric Moore86dd4242007-01-04 20:44:01 -0700795 } else if (ioc->bus_type == FC) {
796 /*
797 * The FC IOC may kill a request for variety of
798 * reasons, some of which may be recovered by a
799 * retry, some which are unlikely to be
800 * recovered. Return DID_ERROR instead of
801 * DID_RESET to permit retry of the command,
802 * just not an infinite number of them
803 */
804 sc->result = DID_ERROR << 16;
805 break;
Eric Moorebf451522006-07-11 17:25:35 -0600806 }
807
808 /*
809 * Allow non-SAS & non-NEXUS_LOSS to drop into below code
810 */
811
812 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
814 /* Linux handles an unsolicited DID_RESET better
815 * than an unsolicited DID_ABORT.
816 */
817 sc->result = DID_RESET << 16;
818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 break;
820
821 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900822 scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600823 if((xfer_cnt==0)||(sc->underflow > xfer_cnt))
824 sc->result=DID_SOFT_ERROR << 16;
825 else /* Sufficient data transfer occurred */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 sc->result = (DID_OK << 16) | scsi_status;
Eric Moore29dd3602007-09-14 18:46:51 -0600827 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Eric Moorec6c727a2007-01-29 09:44:54 -0700828 "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",
Eric Moore29dd3602007-09-14 18:46:51 -0600829 ioc->name, sc->result, sc->device->channel, sc->device->id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 break;
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
833 /*
834 * Do upfront check for valid SenseData and give it
835 * precedence!
836 */
837 sc->result = (DID_OK << 16) | scsi_status;
838 if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
839 /* Have already saved the status and sense data
840 */
841 ;
842 } else {
843 if (xfer_cnt < sc->underflow) {
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600844 if (scsi_status == SAM_STAT_BUSY)
845 sc->result = SAM_STAT_BUSY;
846 else
847 sc->result = DID_SOFT_ERROR << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 }
849 if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {
850 /* What to do?
851 */
852 sc->result = DID_SOFT_ERROR << 16;
853 }
854 else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
855 /* Not real sure here either... */
856 sc->result = DID_RESET << 16;
857 }
858 }
859
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530860
Eric Moore29dd3602007-09-14 18:46:51 -0600861 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
862 " sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
863 ioc->name, sc->underflow));
864 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
865 " ActBytesXferd=%02xh\n", ioc->name, xfer_cnt));
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 /* Report Queue Full
868 */
869 if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)
870 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -0400871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 break;
873
Moore, Eric7e551472006-01-16 18:53:21 -0700874 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900875 scsi_set_resid(sc, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
877 case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
Eric Mooread8c31b2007-03-19 10:31:51 -0600878 sc->result = (DID_OK << 16) | scsi_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 if (scsi_state == 0) {
880 ;
881 } else if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
882 /*
883 * If running against circa 200003dd 909 MPT f/w,
884 * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL
885 * (QUEUE_FULL) returned from device! --> get 0x0000?128
886 * and with SenseBytes set to 0.
887 */
888 if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL)
889 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
890
891 }
892 else if (scsi_state &
893 (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)
894 ) {
895 /*
896 * What to do?
897 */
898 sc->result = DID_SOFT_ERROR << 16;
899 }
900 else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
901 /* Not real sure here either... */
902 sc->result = DID_RESET << 16;
903 }
904 else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) {
905 /* Device Inq. data indicates that it supports
906 * QTags, but rejects QTag messages.
907 * This command completed OK.
908 *
909 * Not real sure here either so do nothing... */
910 }
911
912 if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL)
913 mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
914
915 /* Add handling of:
916 * Reservation Conflict, Busy,
917 * Command Terminated, CHECK
918 */
919 break;
920
921 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
922 sc->result = DID_SOFT_ERROR << 16;
923 break;
924
925 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
926 case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
927 case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
928 case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
929 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
930 case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
931 case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
933 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
934 default:
935 /*
936 * What to do?
937 */
938 sc->result = DID_SOFT_ERROR << 16;
939 break;
940
941 } /* switch(status) */
942
Prakash, Sathya6757d6b2007-07-25 11:14:01 +0530943#ifdef CONFIG_FUSION_LOGGING
944 if (sc->result && (ioc->debug_level & MPT_DEBUG_REPLY))
945 mptscsih_info_scsiio(ioc, sc, pScsiReply);
Eric Moorec6c727a2007-01-29 09:44:54 -0700946#endif
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 } /* end of address reply case */
949
950 /* Unmap the DMA buffers, if any. */
FUJITA Tomonori1928d732007-05-26 00:37:15 +0900951 scsi_dma_unmap(sc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 sc->scsi_done(sc); /* Issue the command callback */
954
955 /* Free Chain buffers */
956 mptscsih_freeChainBuffers(ioc, req_idx);
957 return 1;
958}
959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960/*
961 * mptscsih_flush_running_cmds - For each command found, search
962 * Scsi_Host instance taskQ and reply to OS.
963 * Called only if recovering from a FW reload.
964 * @hd: Pointer to a SCSI HOST structure
965 *
966 * Returns: None.
967 *
968 * Must be called while new I/Os are being queued.
969 */
970static void
971mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
972{
973 MPT_ADAPTER *ioc = hd->ioc;
Eric Mooree8206382007-09-29 10:16:53 -0600974 struct scsi_cmnd *sc;
975 SCSIIORequest_t *mf = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 int ii;
Eric Mooree8206382007-09-29 10:16:53 -0600977 int channel, id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Eric Mooree8206382007-09-29 10:16:53 -0600979 for (ii= 0; ii < ioc->req_depth; ii++) {
980 sc = mptscsih_getclear_scsi_lookup(ioc, ii);
981 if (!sc)
982 continue;
983 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
984 if (!mf)
985 continue;
986 channel = mf->Bus;
987 id = mf->TargetID;
988 mptscsih_freeChainBuffers(ioc, ii);
989 mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
990 if ((unsigned char *)mf != sc->host_scribble)
991 continue;
992 scsi_dma_unmap(sc);
993 sc->result = DID_RESET << 16;
994 sc->host_scribble = NULL;
Eric Moorec51d0be2007-09-29 10:17:21 -0600995 sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT
Eric Mooree8206382007-09-29 10:16:53 -0600996 "completing cmds: fw_channel %d, fw_id %d, sc=%p,"
997 " mf = %p, idx=%x\n", ioc->name, channel, id, sc, mf, ii);
998 sc->scsi_done(sc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000}
1001
1002/*
1003 * mptscsih_search_running_cmds - Delete any commands associated
1004 * with the specified target and lun. Function called only
1005 * when a lun is disable by mid-layer.
1006 * Do NOT access the referenced scsi_cmnd structure or
1007 * members. Will cause either a paging or NULL ptr error.
Michael Reed05e8ec12006-01-13 14:31:54 -06001008 * (BUT, BUT, BUT, the code does reference it! - mdr)
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07001009 * @hd: Pointer to a SCSI HOST structure
1010 * @vdevice: per device private data
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 *
1012 * Returns: None.
1013 *
1014 * Called from slave_destroy.
1015 */
1016static void
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07001017mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
1019 SCSIIORequest_t *mf = NULL;
1020 int ii;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001021 struct scsi_cmnd *sc;
Eric Moore793955f2007-01-29 09:42:20 -07001022 struct scsi_lun lun;
Eric Mooree80b0022007-09-14 18:49:03 -06001023 MPT_ADAPTER *ioc = hd->ioc;
Eric Mooree8206382007-09-29 10:16:53 -06001024 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Eric Mooree8206382007-09-29 10:16:53 -06001026 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1027 for (ii = 0; ii < ioc->req_depth; ii++) {
1028 if ((sc = ioc->ScsiLookup[ii]) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Eric Mooree80b0022007-09-14 18:49:03 -06001030 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
Eric Moore3dc0b032006-07-11 17:32:33 -06001031 if (mf == NULL)
1032 continue;
Eric Moorecc78d302007-06-15 17:27:21 -06001033 /* If the device is a hidden raid component, then its
1034 * expected that the mf->function will be RAID_SCSI_IO
1035 */
1036 if (vdevice->vtarget->tflags &
1037 MPT_TARGET_FLAGS_RAID_COMPONENT && mf->Function !=
1038 MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)
1039 continue;
1040
Eric Moore793955f2007-01-29 09:42:20 -07001041 int_to_scsilun(vdevice->lun, &lun);
1042 if ((mf->Bus != vdevice->vtarget->channel) ||
1043 (mf->TargetID != vdevice->vtarget->id) ||
1044 memcmp(lun.scsi_lun, mf->LUN, 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 continue;
1046
Eric Moore3dc0b032006-07-11 17:32:33 -06001047 if ((unsigned char *)mf != sc->host_scribble)
1048 continue;
Eric Mooree8206382007-09-29 10:16:53 -06001049 ioc->ScsiLookup[ii] = NULL;
1050 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1051 mptscsih_freeChainBuffers(ioc, ii);
1052 mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
FUJITA Tomonori1928d732007-05-26 00:37:15 +09001053 scsi_dma_unmap(sc);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001054 sc->host_scribble = NULL;
1055 sc->result = DID_NO_CONNECT << 16;
Eric Moorec51d0be2007-09-29 10:17:21 -06001056 sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT "completing cmds: fw_channel %d,"
Eric Mooree80b0022007-09-14 18:49:03 -06001057 "fw_id %d, sc=%p, mf = %p, idx=%x\n", ioc->name, vdevice->vtarget->channel,
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301058 vdevice->vtarget->id, sc, mf, ii);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001059 sc->scsi_done(sc);
Eric Mooree8206382007-09-29 10:16:53 -06001060 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 }
1062 }
Eric Mooree8206382007-09-29 10:16:53 -06001063 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 return;
1065}
1066
1067/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
1069/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1070/*
1071 * mptscsih_report_queue_full - Report QUEUE_FULL status returned
1072 * from a SCSI target device.
1073 * @sc: Pointer to scsi_cmnd structure
1074 * @pScsiReply: Pointer to SCSIIOReply_t
1075 * @pScsiReq: Pointer to original SCSI request
1076 *
1077 * This routine periodically reports QUEUE_FULL status returned from a
1078 * SCSI target device. It reports this to the console via kernel
1079 * printk() API call, not more than once every 10 seconds.
1080 */
1081static void
1082mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq)
1083{
1084 long time = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 MPT_SCSI_HOST *hd;
Eric Mooree80b0022007-09-14 18:49:03 -06001086 MPT_ADAPTER *ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001088 if (sc->device == NULL)
1089 return;
1090 if (sc->device->host == NULL)
1091 return;
Eric Mooree7eae9f2007-09-29 10:15:59 -06001092 if ((hd = shost_priv(sc->device->host)) == NULL)
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001093 return;
Eric Mooree80b0022007-09-14 18:49:03 -06001094 ioc = hd->ioc;
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001095 if (time - hd->last_queue_full > 10 * HZ) {
Eric Mooree80b0022007-09-14 18:49:03 -06001096 dprintk(ioc, printk(MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n",
1097 ioc->name, 0, sc->device->id, sc->device->lun));
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001098 hd->last_queue_full = time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100}
1101
1102/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1103/*
1104 * mptscsih_remove - Removed scsi devices
1105 * @pdev: Pointer to pci_dev structure
1106 *
1107 *
1108 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001109void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110mptscsih_remove(struct pci_dev *pdev)
1111{
1112 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1113 struct Scsi_Host *host = ioc->sh;
1114 MPT_SCSI_HOST *hd;
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001115 int sz1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001117 if(!host) {
1118 mpt_detach(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 return;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
1122 scsi_remove_host(host);
1123
Eric Mooree7eae9f2007-09-29 10:15:59 -06001124 if((hd = shost_priv(host)) == NULL)
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001125 return;
1126
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07001127 mptscsih_shutdown(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001129 sz1=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Eric Mooree8206382007-09-29 10:16:53 -06001131 if (ioc->ScsiLookup != NULL) {
Eric Mooree80b0022007-09-14 18:49:03 -06001132 sz1 = ioc->req_depth * sizeof(void *);
Eric Mooree8206382007-09-29 10:16:53 -06001133 kfree(ioc->ScsiLookup);
1134 ioc->ScsiLookup = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 }
1136
Eric Mooree80b0022007-09-14 18:49:03 -06001137 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001138 "Free'd ScsiLookup (%d) memory\n",
Eric Mooree80b0022007-09-14 18:49:03 -06001139 ioc->name, sz1));
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001140
Moore, Eric Dean d485eb82005-05-11 17:37:26 -06001141 kfree(hd->info_kbuf);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001142
1143 /* NULL the Scsi_Host pointer
1144 */
Eric Mooree80b0022007-09-14 18:49:03 -06001145 ioc->sh = NULL;
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001146
1147 scsi_host_put(host);
1148
1149 mpt_detach(pdev);
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001150
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151}
1152
1153/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1154/*
1155 * mptscsih_shutdown - reboot notifier
1156 *
1157 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001158void
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07001159mptscsih_shutdown(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161}
1162
1163#ifdef CONFIG_PM
1164/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1165/*
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001166 * mptscsih_suspend - Fusion MPT scsi driver suspend routine.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 *
1168 *
1169 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001170int
Pavel Machek8d189f72005-04-16 15:25:28 -07001171mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07001173 mptscsih_shutdown(pdev);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001174 return mpt_suspend(pdev,state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175}
1176
1177/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1178/*
1179 * mptscsih_resume - Fusion MPT scsi driver resume routine.
1180 *
1181 *
1182 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001183int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184mptscsih_resume(struct pci_dev *pdev)
1185{
Hormsb364fd52007-03-19 15:06:44 +09001186 return mpt_resume(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
1189#endif
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1192/**
1193 * mptscsih_info - Return information about MPT adapter
1194 * @SChost: Pointer to Scsi_Host structure
1195 *
1196 * (linux scsi_host_template.info routine)
1197 *
1198 * Returns pointer to buffer where information was written.
1199 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001200const char *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201mptscsih_info(struct Scsi_Host *SChost)
1202{
1203 MPT_SCSI_HOST *h;
1204 int size = 0;
1205
Eric Mooree7eae9f2007-09-29 10:15:59 -06001206 h = shost_priv(SChost);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001207
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 if (h) {
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001209 if (h->info_kbuf == NULL)
1210 if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
1211 return h->info_kbuf;
1212 h->info_kbuf[0] = '\0';
1213
1214 mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
1215 h->info_kbuf[size-1] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 }
1217
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001218 return h->info_kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219}
1220
1221struct info_str {
1222 char *buffer;
1223 int length;
1224 int offset;
1225 int pos;
1226};
1227
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001228static void
1229mptscsih_copy_mem_info(struct info_str *info, char *data, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
1231 if (info->pos + len > info->length)
1232 len = info->length - info->pos;
1233
1234 if (info->pos + len < info->offset) {
1235 info->pos += len;
1236 return;
1237 }
1238
1239 if (info->pos < info->offset) {
1240 data += (info->offset - info->pos);
1241 len -= (info->offset - info->pos);
1242 }
1243
1244 if (len > 0) {
1245 memcpy(info->buffer + info->pos, data, len);
1246 info->pos += len;
1247 }
1248}
1249
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001250static int
1251mptscsih_copy_info(struct info_str *info, char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252{
1253 va_list args;
1254 char buf[81];
1255 int len;
1256
1257 va_start(args, fmt);
1258 len = vsprintf(buf, fmt, args);
1259 va_end(args);
1260
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001261 mptscsih_copy_mem_info(info, buf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 return len;
1263}
1264
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001265static int
1266mptscsih_host_info(MPT_ADAPTER *ioc, char *pbuf, off_t offset, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267{
1268 struct info_str info;
1269
1270 info.buffer = pbuf;
1271 info.length = len;
1272 info.offset = offset;
1273 info.pos = 0;
1274
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001275 mptscsih_copy_info(&info, "%s: %s, ", ioc->name, ioc->prod_name);
1276 mptscsih_copy_info(&info, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word);
1277 mptscsih_copy_info(&info, "Ports=%d, ", ioc->facts.NumberOfPorts);
1278 mptscsih_copy_info(&info, "MaxQ=%d\n", ioc->req_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280 return ((info.pos > info.offset) ? info.pos - info.offset : 0);
1281}
1282
1283/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1284/**
1285 * mptscsih_proc_info - Return information about MPT adapter
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001286 * @host: scsi host struct
1287 * @buffer: if write, user data; if read, buffer for user
1288 * @start: returns the buffer address
1289 * @offset: if write, 0; if read, the current offset into the buffer from
1290 * the previous read.
1291 * @length: if write, return length;
1292 * @func: write = 1; read = 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 *
1294 * (linux scsi_host_template.info routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001296int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
1298 int length, int func)
1299{
Eric Mooree7eae9f2007-09-29 10:15:59 -06001300 MPT_SCSI_HOST *hd = shost_priv(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 MPT_ADAPTER *ioc = hd->ioc;
1302 int size = 0;
1303
1304 if (func) {
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001305 /*
1306 * write is not supported
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 */
1308 } else {
1309 if (start)
1310 *start = buffer;
1311
1312 size = mptscsih_host_info(ioc, buffer, offset, length);
1313 }
1314
1315 return size;
1316}
1317
1318/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1319#define ADD_INDEX_LOG(req_ent) do { } while(0)
1320
1321/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1322/**
1323 * mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine.
1324 * @SCpnt: Pointer to scsi_cmnd structure
1325 * @done: Pointer SCSI mid-layer IO completion function
1326 *
1327 * (linux scsi_host_template.queuecommand routine)
1328 * This is the primary SCSI IO start routine. Create a MPI SCSIIORequest
1329 * from a linux scsi_cmnd request and send it to the IOC.
1330 *
1331 * Returns 0. (rtn value discarded by linux scsi mid-layer)
1332 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001333int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1335{
1336 MPT_SCSI_HOST *hd;
1337 MPT_FRAME_HDR *mf;
1338 SCSIIORequest_t *pScsiReq;
Eric Moorea69de502007-09-14 18:48:19 -06001339 VirtDevice *vdevice = SCpnt->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 int lun;
1341 u32 datalen;
1342 u32 scsictl;
1343 u32 scsidir;
1344 u32 cmd_len;
1345 int my_idx;
1346 int ii;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301347 MPT_ADAPTER *ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Eric Mooree7eae9f2007-09-29 10:15:59 -06001349 hd = shost_priv(SCpnt->device->host);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301350 ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 lun = SCpnt->device->lun;
1352 SCpnt->scsi_done = done;
1353
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301354 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "qcmd: SCpnt=%p, done()=%p\n",
1355 ioc->name, SCpnt, done));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
1357 if (hd->resetPending) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301358 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "qcmd: SCpnt=%p timeout + 60HZ\n",
1359 ioc->name, SCpnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 return SCSI_MLQUEUE_HOST_BUSY;
1361 }
1362
1363 /*
1364 * Put together a MPT SCSI request...
1365 */
Eric Mooree80b0022007-09-14 18:49:03 -06001366 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301367 dprintk(ioc, printk(MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
1368 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 return SCSI_MLQUEUE_HOST_BUSY;
1370 }
1371
1372 pScsiReq = (SCSIIORequest_t *) mf;
1373
1374 my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
1375
1376 ADD_INDEX_LOG(my_idx);
1377
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001378 /* TUR's being issued with scsictl=0x02000000 (DATA_IN)!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 * Seems we may receive a buffer (datalen>0) even when there
1380 * will be no data transfer! GRRRRR...
1381 */
1382 if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
FUJITA Tomonori1928d732007-05-26 00:37:15 +09001383 datalen = scsi_bufflen(SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */
1385 } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
FUJITA Tomonori1928d732007-05-26 00:37:15 +09001386 datalen = scsi_bufflen(SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */
1388 } else {
1389 datalen = 0;
1390 scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER;
1391 }
1392
1393 /* Default to untagged. Once a target structure has been allocated,
1394 * use the Inquiry data to determine if device supports tagged.
1395 */
Eric Moorea69de502007-09-14 18:48:19 -06001396 if (vdevice
1397 && (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 && (SCpnt->device->tagged_supported)) {
1399 scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
1400 } else {
1401 scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
1402 }
1403
1404 /* Use the above information to set up the message frame
1405 */
Eric Moorea69de502007-09-14 18:48:19 -06001406 pScsiReq->TargetID = (u8) vdevice->vtarget->id;
1407 pScsiReq->Bus = vdevice->vtarget->channel;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 pScsiReq->ChainOffset = 0;
Eric Moorea69de502007-09-14 18:48:19 -06001409 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
James Bottomleyc92f2222006-03-01 09:02:49 -06001410 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
1411 else
1412 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 pScsiReq->CDBLength = SCpnt->cmd_len;
1414 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1415 pScsiReq->Reserved = 0;
1416 pScsiReq->MsgFlags = mpt_msg_flags();
Eric Moore793955f2007-01-29 09:42:20 -07001417 int_to_scsilun(SCpnt->device->lun, (struct scsi_lun *)pScsiReq->LUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 pScsiReq->Control = cpu_to_le32(scsictl);
1419
1420 /*
1421 * Write SCSI CDB into the message
1422 */
1423 cmd_len = SCpnt->cmd_len;
1424 for (ii=0; ii < cmd_len; ii++)
1425 pScsiReq->CDB[ii] = SCpnt->cmnd[ii];
1426
1427 for (ii=cmd_len; ii < 16; ii++)
1428 pScsiReq->CDB[ii] = 0;
1429
1430 /* DataLength */
1431 pScsiReq->DataLength = cpu_to_le32(datalen);
1432
1433 /* SenseBuffer low address */
Eric Mooree80b0022007-09-14 18:49:03 -06001434 pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 + (my_idx * MPT_SENSE_BUFFER_ALLOC));
1436
1437 /* Now add the SG list
1438 * Always have a SGE even if null length.
1439 */
1440 if (datalen == 0) {
1441 /* Add a NULL SGE */
1442 mptscsih_add_sge((char *)&pScsiReq->SGL, MPT_SGE_FLAGS_SSIMPLE_READ | 0,
1443 (dma_addr_t) -1);
1444 } else {
1445 /* Add a 32 or 64 bit SGE */
Eric Mooree80b0022007-09-14 18:49:03 -06001446 if (mptscsih_AddSGE(ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 goto fail;
1448 }
1449
Eric Moore3dc0b032006-07-11 17:32:33 -06001450 SCpnt->host_scribble = (unsigned char *)mf;
Eric Mooree8206382007-09-29 10:16:53 -06001451 mptscsih_set_scsi_lookup(ioc, my_idx, SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Eric Mooree80b0022007-09-14 18:49:03 -06001453 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301454 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
1455 ioc->name, SCpnt, mf, my_idx));
Eric Moore29dd3602007-09-14 18:46:51 -06001456 DBG_DUMP_REQUEST_FRAME(ioc, (u32 *)mf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 return 0;
1458
1459 fail:
Eric Mooree80b0022007-09-14 18:49:03 -06001460 mptscsih_freeChainBuffers(ioc, my_idx);
1461 mpt_free_msg_frame(ioc, mf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 return SCSI_MLQUEUE_HOST_BUSY;
1463}
1464
1465/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1466/*
1467 * mptscsih_freeChainBuffers - Function to free chain buffers associated
1468 * with a SCSI IO request
1469 * @hd: Pointer to the MPT_SCSI_HOST instance
1470 * @req_idx: Index of the SCSI IO request frame.
1471 *
1472 * Called if SG chain buffer allocation fails and mptscsih callbacks.
1473 * No return.
1474 */
1475static void
1476mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
1477{
1478 MPT_FRAME_HDR *chain;
1479 unsigned long flags;
1480 int chain_idx;
1481 int next;
1482
1483 /* Get the first chain index and reset
1484 * tracker state.
1485 */
1486 chain_idx = ioc->ReqToChain[req_idx];
1487 ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN;
1488
1489 while (chain_idx != MPT_HOST_NO_CHAIN) {
1490
1491 /* Save the next chain buffer index */
1492 next = ioc->ChainToChain[chain_idx];
1493
1494 /* Free this chain buffer and reset
1495 * tracker
1496 */
1497 ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN;
1498
1499 chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer
1500 + (chain_idx * ioc->req_sz));
1501
1502 spin_lock_irqsave(&ioc->FreeQlock, flags);
1503 list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);
1504 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1505
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301506 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FreeChainBuffers (index %d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 ioc->name, chain_idx));
1508
1509 /* handle next */
1510 chain_idx = next;
1511 }
1512 return;
1513}
1514
1515/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1516/*
1517 * Reset Handling
1518 */
1519
1520/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Eric Moorecd2c6192007-01-29 09:47:47 -07001521/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 * mptscsih_TMHandler - Generic handler for SCSI Task Management.
Randy Dunlap1544d672007-02-20 11:17:03 -08001523 * @hd: Pointer to MPT SCSI HOST structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 * @type: Task Management type
Randy Dunlap1544d672007-02-20 11:17:03 -08001525 * @channel: channel number for task management
Eric Moore793955f2007-01-29 09:42:20 -07001526 * @id: Logical Target ID for reset (if appropriate)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 * @lun: Logical Unit for reset (if appropriate)
1528 * @ctx2abort: Context for the task to be aborted (if appropriate)
Randy Dunlap1544d672007-02-20 11:17:03 -08001529 * @timeout: timeout for task management control
1530 *
1531 * Fall through to mpt_HardResetHandler if: not operational, too many
1532 * failed TM requests or handshake failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 *
1534 * Remark: Currently invoked from a non-interrupt thread (_bh).
1535 *
Randy Dunlap7105a382008-02-29 22:03:27 -08001536 * Note: With old EH code, at most 1 SCSI TaskMgmt function per IOC
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 * will be active.
1538 *
Randy Dunlap1544d672007-02-20 11:17:03 -08001539 * Returns 0 for SUCCESS, or %FAILED.
Eric Moorecd2c6192007-01-29 09:47:47 -07001540 **/
James Bottomley663e1aa2006-01-29 12:10:24 -06001541int
Eric Moore793955f2007-01-29 09:42:20 -07001542mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543{
1544 MPT_ADAPTER *ioc;
1545 int rc = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 u32 ioc_raw_state;
1547 unsigned long flags;
1548
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 ioc = hd->ioc;
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301550 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler Entered!\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
1552 // SJR - CHECKME - Can we avoid this here?
1553 // (mpt_HardResetHandler has this check...)
1554 spin_lock_irqsave(&ioc->diagLock, flags);
1555 if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)) {
1556 spin_unlock_irqrestore(&ioc->diagLock, flags);
1557 return FAILED;
1558 }
1559 spin_unlock_irqrestore(&ioc->diagLock, flags);
1560
1561 /* Wait a fixed amount of time for the TM pending flag to be cleared.
Eric Moorecd2c6192007-01-29 09:47:47 -07001562 * If we time out and not bus reset, then we return a FAILED status
1563 * to the caller.
1564 * The call to mptscsih_tm_pending_wait() will set the pending flag
1565 * if we are
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 * successful. Otherwise, reload the FW.
1567 */
1568 if (mptscsih_tm_pending_wait(hd) == FAILED) {
1569 if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
Eric Moore29dd3602007-09-14 18:46:51 -06001570 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler abort: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 "Timed out waiting for last TM (%d) to complete! \n",
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301572 ioc->name, hd->tmPending));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 return FAILED;
1574 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) {
Eric Moore29dd3602007-09-14 18:46:51 -06001575 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler target "
Eric Moorecd2c6192007-01-29 09:47:47 -07001576 "reset: Timed out waiting for last TM (%d) "
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301577 "to complete! \n", ioc->name,
Eric Moorecd2c6192007-01-29 09:47:47 -07001578 hd->tmPending));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 return FAILED;
1580 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
Eric Moore29dd3602007-09-14 18:46:51 -06001581 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler bus reset: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 "Timed out waiting for last TM (%d) to complete! \n",
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301583 ioc->name, hd->tmPending));
Eric Moorecd2c6192007-01-29 09:47:47 -07001584 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 }
1586 } else {
Eric Mooree80b0022007-09-14 18:49:03 -06001587 spin_lock_irqsave(&ioc->FreeQlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 hd->tmPending |= (1 << type);
Eric Mooree80b0022007-09-14 18:49:03 -06001589 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 }
1591
Eric Mooree80b0022007-09-14 18:49:03 -06001592 ioc_raw_state = mpt_GetIocState(ioc, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
1595 printk(MYIOC_s_WARN_FMT
Eric Moorecd2c6192007-01-29 09:47:47 -07001596 "TM Handler for type=%x: IOC Not operational (0x%x)!\n",
1597 ioc->name, type, ioc_raw_state);
Eric Moore29dd3602007-09-14 18:46:51 -06001598 printk(MYIOC_s_WARN_FMT " Issuing HardReset!!\n", ioc->name);
Eric Moorecd2c6192007-01-29 09:47:47 -07001599 if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)
Eric Moore29dd3602007-09-14 18:46:51 -06001600 printk(MYIOC_s_WARN_FMT "TMHandler: HardReset "
1601 "FAILED!!\n", ioc->name);
Eric Moorecd2c6192007-01-29 09:47:47 -07001602 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 }
1604
Eric Moorecd2c6192007-01-29 09:47:47 -07001605 if (ioc_raw_state & MPI_DOORBELL_ACTIVE) {
1606 printk(MYIOC_s_WARN_FMT
1607 "TM Handler for type=%x: ioc_state: "
1608 "DOORBELL_ACTIVE (0x%x)!\n",
1609 ioc->name, type, ioc_raw_state);
1610 return FAILED;
1611 }
1612
1613 /* Isse the Task Mgmt request.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 */
Eric Moorecd2c6192007-01-29 09:47:47 -07001615 if (hd->hard_resets < -1)
1616 hd->hard_resets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
Eric Moorecd2c6192007-01-29 09:47:47 -07001618 rc = mptscsih_IssueTaskMgmt(hd, type, channel, id, lun,
1619 ctx2abort, timeout);
1620 if (rc)
1621 printk(MYIOC_s_INFO_FMT "Issue of TaskMgmt failed!\n",
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301622 ioc->name);
Eric Moorecd2c6192007-01-29 09:47:47 -07001623 else
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301624 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Issue of TaskMgmt Successful!\n",
1625 ioc->name));
Eric Moore3dc0b032006-07-11 17:32:33 -06001626
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301627 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1628 "TMHandler rc = %d!\n", ioc->name, rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629
1630 return rc;
1631}
1632
1633
1634/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Eric Moorecd2c6192007-01-29 09:47:47 -07001635/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 * mptscsih_IssueTaskMgmt - Generic send Task Management function.
1637 * @hd: Pointer to MPT_SCSI_HOST structure
1638 * @type: Task Management type
Randy Dunlap1544d672007-02-20 11:17:03 -08001639 * @channel: channel number for task management
Eric Moore793955f2007-01-29 09:42:20 -07001640 * @id: Logical Target ID for reset (if appropriate)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 * @lun: Logical Unit for reset (if appropriate)
1642 * @ctx2abort: Context for the task to be aborted (if appropriate)
Randy Dunlap1544d672007-02-20 11:17:03 -08001643 * @timeout: timeout for task management control
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 *
1645 * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
1646 * or a non-interrupt thread. In the former, must not call schedule().
1647 *
1648 * Not all fields are meaningfull for all task types.
1649 *
Eric Moorecd2c6192007-01-29 09:47:47 -07001650 * Returns 0 for SUCCESS, or FAILED.
1651 *
1652 **/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653static int
Eric Moore793955f2007-01-29 09:42:20 -07001654mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655{
1656 MPT_FRAME_HDR *mf;
1657 SCSITaskMgmt_t *pScsiTm;
1658 int ii;
1659 int retval;
Eric Mooree80b0022007-09-14 18:49:03 -06001660 MPT_ADAPTER *ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
1662 /* Return Fail to calling function if no message frames available.
1663 */
Eric Mooree80b0022007-09-14 18:49:03 -06001664 if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
1665 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "IssueTaskMgmt, no msg frames!!\n",
1666 ioc->name));
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001667 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 }
Eric Mooree80b0022007-09-14 18:49:03 -06001669 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt request @ %p\n",
1670 ioc->name, mf));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
1672 /* Format the Request
1673 */
1674 pScsiTm = (SCSITaskMgmt_t *) mf;
Eric Moore793955f2007-01-29 09:42:20 -07001675 pScsiTm->TargetID = id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 pScsiTm->Bus = channel;
1677 pScsiTm->ChainOffset = 0;
1678 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
1679
1680 pScsiTm->Reserved = 0;
1681 pScsiTm->TaskType = type;
1682 pScsiTm->Reserved1 = 0;
1683 pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
1684 ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
1685
Eric Moore793955f2007-01-29 09:42:20 -07001686 int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
1688 for (ii=0; ii < 7; ii++)
1689 pScsiTm->Reserved2[ii] = 0;
1690
1691 pScsiTm->TaskMsgContext = ctx2abort;
1692
Eric Mooree80b0022007-09-14 18:49:03 -06001693 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt: ctx2abort (0x%08x) "
1694 "type=%d\n", ioc->name, ctx2abort, type));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05301696 DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)pScsiTm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Eric Mooree80b0022007-09-14 18:49:03 -06001698 if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
1699 (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
1700 mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf);
Prakash, Sathya7a195f42007-08-14 16:08:40 +05301701 else {
Eric Mooree80b0022007-09-14 18:49:03 -06001702 retval = mpt_send_handshake_request(ioc->TaskCtx, ioc,
Prakash, Sathya7a195f42007-08-14 16:08:40 +05301703 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
1704 if (retval) {
Eric Mooree80b0022007-09-14 18:49:03 -06001705 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "send_handshake FAILED!"
1706 " (hd %p, ioc %p, mf %p, rc=%d) \n", ioc->name, hd,
1707 ioc, mf, retval));
Prakash, Sathya7a195f42007-08-14 16:08:40 +05301708 goto fail_out;
1709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 }
1711
1712 if(mptscsih_tm_wait_for_completion(hd, timeout) == FAILED) {
Eric Mooree80b0022007-09-14 18:49:03 -06001713 dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "task management request TIMED OUT!"
1714 " (hd %p, ioc %p, mf %p) \n", ioc->name, hd,
1715 ioc, mf));
1716 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling HardReset! \n",
1717 ioc->name));
1718 retval = mpt_HardResetHandler(ioc, CAN_SLEEP);
1719 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rc=%d \n",
1720 ioc->name, retval));
Eric Moorecd2c6192007-01-29 09:47:47 -07001721 goto fail_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 }
1723
Eric Moorecd2c6192007-01-29 09:47:47 -07001724 /*
1725 * Handle success case, see if theres a non-zero ioc_status.
1726 */
1727 if (hd->tm_iocstatus == MPI_IOCSTATUS_SUCCESS ||
1728 hd->tm_iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
1729 hd->tm_iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED)
1730 retval = 0;
1731 else
1732 retval = FAILED;
1733
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 return retval;
Eric Moorecd2c6192007-01-29 09:47:47 -07001735
1736 fail_out:
1737
1738 /*
Joe Perchesfc1323b2008-02-03 17:21:01 +02001739 * Free task management mf, and corresponding tm flags
Eric Moorecd2c6192007-01-29 09:47:47 -07001740 */
Eric Mooree80b0022007-09-14 18:49:03 -06001741 mpt_free_msg_frame(ioc, mf);
Eric Moorecd2c6192007-01-29 09:47:47 -07001742 hd->tmPending = 0;
1743 hd->tmState = TM_STATE_NONE;
1744 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745}
1746
Christoph Hellwigd66c7a02006-01-17 13:43:14 +00001747static int
1748mptscsih_get_tm_timeout(MPT_ADAPTER *ioc)
1749{
1750 switch (ioc->bus_type) {
1751 case FC:
1752 return 40;
1753 case SAS:
1754 return 10;
1755 case SPI:
1756 default:
1757 return 2;
1758 }
1759}
1760
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1762/**
1763 * mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant
1764 * @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted
1765 *
1766 * (linux scsi_host_template.eh_abort_handler routine)
1767 *
1768 * Returns SUCCESS or FAILED.
Eric Moorecd2c6192007-01-29 09:47:47 -07001769 **/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001770int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771mptscsih_abort(struct scsi_cmnd * SCpnt)
1772{
1773 MPT_SCSI_HOST *hd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 MPT_FRAME_HDR *mf;
1775 u32 ctx2abort;
1776 int scpnt_idx;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001777 int retval;
Eric Moore958d4a32007-06-15 17:24:14 -06001778 VirtDevice *vdevice;
Eric Moore3dc0b032006-07-11 17:32:33 -06001779 ulong sn = SCpnt->serial_number;
Eric Moore958d4a32007-06-15 17:24:14 -06001780 MPT_ADAPTER *ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
1782 /* If we can't locate our host adapter structure, return FAILED status.
1783 */
Eric Mooree7eae9f2007-09-29 10:15:59 -06001784 if ((hd = shost_priv(SCpnt->device->host)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 SCpnt->result = DID_RESET << 16;
1786 SCpnt->scsi_done(SCpnt);
Eric Moore29dd3602007-09-14 18:46:51 -06001787 printk(KERN_ERR MYNAM ": task abort: "
1788 "can't locate host! (sc=%p)\n", SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 return FAILED;
1790 }
1791
Eric Moore958d4a32007-06-15 17:24:14 -06001792 ioc = hd->ioc;
1793 printk(MYIOC_s_INFO_FMT "attempting task abort! (sc=%p)\n",
1794 ioc->name, SCpnt);
1795 scsi_print_command(SCpnt);
1796
1797 vdevice = SCpnt->device->hostdata;
1798 if (!vdevice || !vdevice->vtarget) {
Eric Moore29dd3602007-09-14 18:46:51 -06001799 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1800 "task abort: device has been deleted (sc=%p)\n",
1801 ioc->name, SCpnt));
Eric Moore958d4a32007-06-15 17:24:14 -06001802 SCpnt->result = DID_NO_CONNECT << 16;
1803 SCpnt->scsi_done(SCpnt);
1804 retval = 0;
1805 goto out;
1806 }
1807
Eric Moorecc78d302007-06-15 17:27:21 -06001808 /* Task aborts are not supported for hidden raid components.
1809 */
1810 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
Eric Moore29dd3602007-09-14 18:46:51 -06001811 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1812 "task abort: hidden raid component (sc=%p)\n",
1813 ioc->name, SCpnt));
Eric Moorecc78d302007-06-15 17:27:21 -06001814 SCpnt->result = DID_RESET << 16;
1815 retval = FAILED;
1816 goto out;
1817 }
1818
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 /* Find this command
1820 */
Eric Mooree8206382007-09-29 10:16:53 -06001821 if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(ioc, SCpnt)) < 0) {
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001822 /* Cmd not found in ScsiLookup.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 * Do OS callback.
1824 */
1825 SCpnt->result = DID_RESET << 16;
Eric Moore29dd3602007-09-14 18:46:51 -06001826 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "task abort: "
Eric Moore958d4a32007-06-15 17:24:14 -06001827 "Command not in the active list! (sc=%p)\n", ioc->name,
1828 SCpnt));
1829 retval = 0;
1830 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 }
1832
Eric Moore958d4a32007-06-15 17:24:14 -06001833 if (hd->resetPending) {
1834 retval = FAILED;
1835 goto out;
1836 }
Moore, Eric65207fe2006-04-21 16:14:35 -06001837
1838 if (hd->timeouts < -1)
1839 hd->timeouts++;
1840
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 /* Most important! Set TaskMsgContext to SCpnt's MsgContext!
1842 * (the IO to be ABORT'd)
1843 *
1844 * NOTE: Since we do not byteswap MsgContext, we do not
1845 * swap it here either. It is an opaque cookie to
1846 * the controller, so it does not matter. -DaveM
1847 */
Eric Mooree80b0022007-09-14 18:49:03 -06001848 mf = MPT_INDEX_2_MFPTR(ioc, scpnt_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
1850
1851 hd->abortSCpnt = SCpnt;
1852
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001853 retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
Eric Moore958d4a32007-06-15 17:24:14 -06001854 vdevice->vtarget->channel, vdevice->vtarget->id, vdevice->lun,
1855 ctx2abort, mptscsih_get_tm_timeout(ioc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Eric Mooree8206382007-09-29 10:16:53 -06001857 if (SCPNT_TO_LOOKUP_IDX(ioc, SCpnt) == scpnt_idx &&
Eric Moorecd2c6192007-01-29 09:47:47 -07001858 SCpnt->serial_number == sn)
Eric Moore3dc0b032006-07-11 17:32:33 -06001859 retval = FAILED;
Eric Moore3dc0b032006-07-11 17:32:33 -06001860
Eric Moore958d4a32007-06-15 17:24:14 -06001861 out:
1862 printk(MYIOC_s_INFO_FMT "task abort: %s (sc=%p)\n",
1863 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001865 if (retval == 0)
1866 return SUCCESS;
Eric Moorecd2c6192007-01-29 09:47:47 -07001867 else
1868 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869}
1870
1871/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1872/**
1873 * mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant
1874 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
1875 *
1876 * (linux scsi_host_template.eh_dev_reset_handler routine)
1877 *
1878 * Returns SUCCESS or FAILED.
Eric Moorecd2c6192007-01-29 09:47:47 -07001879 **/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001880int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
1882{
1883 MPT_SCSI_HOST *hd;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001884 int retval;
Eric Moore958d4a32007-06-15 17:24:14 -06001885 VirtDevice *vdevice;
1886 MPT_ADAPTER *ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
1888 /* If we can't locate our host adapter structure, return FAILED status.
1889 */
Eric Mooree7eae9f2007-09-29 10:15:59 -06001890 if ((hd = shost_priv(SCpnt->device->host)) == NULL){
Eric Moore29dd3602007-09-14 18:46:51 -06001891 printk(KERN_ERR MYNAM ": target reset: "
1892 "Can't locate host! (sc=%p)\n", SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 return FAILED;
1894 }
1895
Eric Moore958d4a32007-06-15 17:24:14 -06001896 ioc = hd->ioc;
1897 printk(MYIOC_s_INFO_FMT "attempting target reset! (sc=%p)\n",
1898 ioc->name, SCpnt);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001899 scsi_print_command(SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Eric Moore958d4a32007-06-15 17:24:14 -06001901 if (hd->resetPending) {
1902 retval = FAILED;
1903 goto out;
1904 }
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001905
Eric Moore958d4a32007-06-15 17:24:14 -06001906 vdevice = SCpnt->device->hostdata;
1907 if (!vdevice || !vdevice->vtarget) {
1908 retval = 0;
1909 goto out;
1910 }
1911
Eric Moorecc78d302007-06-15 17:27:21 -06001912 /* Target reset to hidden raid component is not supported
1913 */
1914 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
1915 retval = FAILED;
1916 goto out;
1917 }
1918
Eric Moore958d4a32007-06-15 17:24:14 -06001919 retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
1920 vdevice->vtarget->channel, vdevice->vtarget->id, 0, 0,
1921 mptscsih_get_tm_timeout(ioc));
1922
1923 out:
1924 printk (MYIOC_s_INFO_FMT "target reset: %s (sc=%p)\n",
1925 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001926
1927 if (retval == 0)
1928 return SUCCESS;
Eric Moorecd2c6192007-01-29 09:47:47 -07001929 else
1930 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931}
1932
Eric Moorecd2c6192007-01-29 09:47:47 -07001933
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1935/**
1936 * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant
1937 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
1938 *
1939 * (linux scsi_host_template.eh_bus_reset_handler routine)
1940 *
1941 * Returns SUCCESS or FAILED.
Eric Moorecd2c6192007-01-29 09:47:47 -07001942 **/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001943int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
1945{
1946 MPT_SCSI_HOST *hd;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001947 int retval;
Eric Moorea69de502007-09-14 18:48:19 -06001948 VirtDevice *vdevice;
Eric Moore958d4a32007-06-15 17:24:14 -06001949 MPT_ADAPTER *ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
1951 /* If we can't locate our host adapter structure, return FAILED status.
1952 */
Eric Mooree7eae9f2007-09-29 10:15:59 -06001953 if ((hd = shost_priv(SCpnt->device->host)) == NULL){
Eric Moore29dd3602007-09-14 18:46:51 -06001954 printk(KERN_ERR MYNAM ": bus reset: "
1955 "Can't locate host! (sc=%p)\n", SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 return FAILED;
1957 }
1958
Eric Moore958d4a32007-06-15 17:24:14 -06001959 ioc = hd->ioc;
1960 printk(MYIOC_s_INFO_FMT "attempting bus reset! (sc=%p)\n",
1961 ioc->name, SCpnt);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001962 scsi_print_command(SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
1964 if (hd->timeouts < -1)
1965 hd->timeouts++;
1966
Eric Moorea69de502007-09-14 18:48:19 -06001967 vdevice = SCpnt->device->hostdata;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001968 retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
Eric Moorea69de502007-09-14 18:48:19 -06001969 vdevice->vtarget->channel, 0, 0, 0, mptscsih_get_tm_timeout(ioc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970
Eric Moore958d4a32007-06-15 17:24:14 -06001971 printk(MYIOC_s_INFO_FMT "bus reset: %s (sc=%p)\n",
1972 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001973
1974 if (retval == 0)
1975 return SUCCESS;
Eric Moorecd2c6192007-01-29 09:47:47 -07001976 else
1977 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978}
1979
1980/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1981/**
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001982 * mptscsih_host_reset - Perform a SCSI host adapter RESET (new_eh variant)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
1984 *
1985 * (linux scsi_host_template.eh_host_reset_handler routine)
1986 *
1987 * Returns SUCCESS or FAILED.
1988 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04001989int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990mptscsih_host_reset(struct scsi_cmnd *SCpnt)
1991{
1992 MPT_SCSI_HOST * hd;
Eric Moore958d4a32007-06-15 17:24:14 -06001993 int retval;
1994 MPT_ADAPTER *ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
1996 /* If we can't locate the host to reset, then we failed. */
Eric Mooree7eae9f2007-09-29 10:15:59 -06001997 if ((hd = shost_priv(SCpnt->device->host)) == NULL){
Eric Moore29dd3602007-09-14 18:46:51 -06001998 printk(KERN_ERR MYNAM ": host reset: "
1999 "Can't locate host! (sc=%p)\n", SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 return FAILED;
2001 }
2002
Eric Moore958d4a32007-06-15 17:24:14 -06002003 ioc = hd->ioc;
2004 printk(MYIOC_s_INFO_FMT "attempting host reset! (sc=%p)\n",
2005 ioc->name, SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007 /* If our attempts to reset the host failed, then return a failed
2008 * status. The host will be taken off line by the SCSI mid-layer.
2009 */
Eric Mooree80b0022007-09-14 18:49:03 -06002010 if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0) {
Eric Moore958d4a32007-06-15 17:24:14 -06002011 retval = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 } else {
2013 /* Make sure TM pending is cleared and TM state is set to
2014 * NONE.
2015 */
Eric Moore958d4a32007-06-15 17:24:14 -06002016 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 hd->tmPending = 0;
2018 hd->tmState = TM_STATE_NONE;
2019 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020
Eric Moore958d4a32007-06-15 17:24:14 -06002021 printk(MYIOC_s_INFO_FMT "host reset: %s (sc=%p)\n",
2022 ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
Eric Moore958d4a32007-06-15 17:24:14 -06002024 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025}
2026
2027/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2028/**
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002029 * mptscsih_tm_pending_wait - wait for pending task management request to complete
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 * @hd: Pointer to MPT host structure.
2031 *
2032 * Returns {SUCCESS,FAILED}.
2033 */
2034static int
2035mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd)
2036{
2037 unsigned long flags;
2038 int loop_count = 4 * 10; /* Wait 10 seconds */
2039 int status = FAILED;
Eric Mooree80b0022007-09-14 18:49:03 -06002040 MPT_ADAPTER *ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
2042 do {
Eric Mooree80b0022007-09-14 18:49:03 -06002043 spin_lock_irqsave(&ioc->FreeQlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 if (hd->tmState == TM_STATE_NONE) {
2045 hd->tmState = TM_STATE_IN_PROGRESS;
2046 hd->tmPending = 1;
Eric Mooree80b0022007-09-14 18:49:03 -06002047 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002048 status = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 break;
2050 }
Eric Mooree80b0022007-09-14 18:49:03 -06002051 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 msleep(250);
2053 } while (--loop_count);
2054
2055 return status;
2056}
2057
2058/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2059/**
2060 * mptscsih_tm_wait_for_completion - wait for completion of TM task
2061 * @hd: Pointer to MPT host structure.
Randy Dunlap1544d672007-02-20 11:17:03 -08002062 * @timeout: timeout value
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 *
2064 * Returns {SUCCESS,FAILED}.
2065 */
2066static int
2067mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout )
2068{
2069 unsigned long flags;
2070 int loop_count = 4 * timeout;
2071 int status = FAILED;
Eric Mooree80b0022007-09-14 18:49:03 -06002072 MPT_ADAPTER *ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073
2074 do {
Eric Mooree80b0022007-09-14 18:49:03 -06002075 spin_lock_irqsave(&ioc->FreeQlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 if(hd->tmPending == 0) {
2077 status = SUCCESS;
Eric Mooree80b0022007-09-14 18:49:03 -06002078 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 break;
2080 }
Eric Mooree80b0022007-09-14 18:49:03 -06002081 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
Michael Reedd6be06c2006-05-24 15:07:57 -05002082 msleep(250);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 } while (--loop_count);
2084
2085 return status;
2086}
2087
2088/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Moore, Eric9f63bb72006-01-16 18:53:26 -07002089static void
2090mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code)
2091{
2092 char *desc;
2093
2094 switch (response_code) {
2095 case MPI_SCSITASKMGMT_RSP_TM_COMPLETE:
2096 desc = "The task completed.";
2097 break;
2098 case MPI_SCSITASKMGMT_RSP_INVALID_FRAME:
2099 desc = "The IOC received an invalid frame status.";
2100 break;
2101 case MPI_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
2102 desc = "The task type is not supported.";
2103 break;
2104 case MPI_SCSITASKMGMT_RSP_TM_FAILED:
2105 desc = "The requested task failed.";
2106 break;
2107 case MPI_SCSITASKMGMT_RSP_TM_SUCCEEDED:
2108 desc = "The task completed successfully.";
2109 break;
2110 case MPI_SCSITASKMGMT_RSP_TM_INVALID_LUN:
2111 desc = "The LUN request is invalid.";
2112 break;
2113 case MPI_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
2114 desc = "The task is in the IOC queue and has not been sent to target.";
2115 break;
2116 default:
2117 desc = "unknown";
2118 break;
2119 }
2120 printk(MYIOC_s_INFO_FMT "Response Code(0x%08x): F/W: %s\n",
2121 ioc->name, response_code, desc);
2122}
2123
2124/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125/**
2126 * mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver
2127 * @ioc: Pointer to MPT_ADAPTER structure
2128 * @mf: Pointer to SCSI task mgmt request frame
2129 * @mr: Pointer to SCSI task mgmt reply frame
2130 *
2131 * This routine is called from mptbase.c::mpt_interrupt() at the completion
2132 * of any SCSI task management request.
2133 * This routine is registered with the MPT (base) driver at driver
2134 * load/init time via the mpt_register() API call.
2135 *
2136 * Returns 1 indicating alloc'd request frame ptr should be freed.
Eric Moorecd2c6192007-01-29 09:47:47 -07002137 **/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002138int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
2140{
2141 SCSITaskMgmtReply_t *pScsiTmReply;
2142 SCSITaskMgmt_t *pScsiTmReq;
2143 MPT_SCSI_HOST *hd;
2144 unsigned long flags;
2145 u16 iocstatus;
2146 u8 tmType;
Eric Moorecd2c6192007-01-29 09:47:47 -07002147 u32 termination_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302149 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed (mf=%p,mr=%p)\n",
Eric Moorecd2c6192007-01-29 09:47:47 -07002150 ioc->name, mf, mr));
2151 if (!ioc->sh) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302152 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
Eric Moorecd2c6192007-01-29 09:47:47 -07002153 "TaskMgmt Complete: NULL Scsi Host Ptr\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 return 1;
2155 }
2156
2157 if (mr == NULL) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302158 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
Eric Moorecd2c6192007-01-29 09:47:47 -07002159 "ERROR! TaskMgmt Reply: NULL Request %p\n", ioc->name, mf));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 }
2162
Eric Mooree7eae9f2007-09-29 10:15:59 -06002163 hd = shost_priv(ioc->sh);
Eric Moorecd2c6192007-01-29 09:47:47 -07002164 pScsiTmReply = (SCSITaskMgmtReply_t*)mr;
2165 pScsiTmReq = (SCSITaskMgmt_t*)mf;
2166 tmType = pScsiTmReq->TaskType;
2167 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
2168 termination_count = le32_to_cpu(pScsiTmReply->TerminationCount);
2169
2170 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 &&
2171 pScsiTmReply->ResponseCode)
2172 mptscsih_taskmgmt_response_code(ioc,
2173 pScsiTmReply->ResponseCode);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302174 DBG_DUMP_TM_REPLY_FRAME(ioc, (u32 *)pScsiTmReply);
Eric Moorecd2c6192007-01-29 09:47:47 -07002175
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302176#ifdef CONFIG_FUSION_LOGGING
2177 if ((ioc->debug_level & MPT_DEBUG_REPLY) ||
2178 (ioc->debug_level & MPT_DEBUG_TM ))
2179 printk("%s: ha=%d [%d:%d:0] task_type=0x%02X "
2180 "iocstatus=0x%04X\n\tloginfo=0x%08X response_code=0x%02X "
2181 "term_cmnds=%d\n", __FUNCTION__, ioc->id, pScsiTmReply->Bus,
2182 pScsiTmReply->TargetID, pScsiTmReq->TaskType,
2183 le16_to_cpu(pScsiTmReply->IOCStatus),
2184 le32_to_cpu(pScsiTmReply->IOCLogInfo),pScsiTmReply->ResponseCode,
2185 le32_to_cpu(pScsiTmReply->TerminationCount));
Eric Moorecd2c6192007-01-29 09:47:47 -07002186#endif
2187 if (!iocstatus) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302188 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT " TaskMgmt SUCCESS\n", ioc->name));
Eric Moorecd2c6192007-01-29 09:47:47 -07002189 hd->abortSCpnt = NULL;
2190 goto out;
2191 }
2192
2193 /* Error? (anything non-zero?) */
2194
2195 /* clear flags and continue.
2196 */
2197 switch (tmType) {
2198
2199 case MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2200 if (termination_count == 1)
2201 iocstatus = MPI_IOCSTATUS_SCSI_TASK_TERMINATED;
2202 hd->abortSCpnt = NULL;
2203 break;
2204
2205 case MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS:
2206
2207 /* If an internal command is present
2208 * or the TM failed - reload the FW.
2209 * FC FW may respond FAILED to an ABORT
2210 */
2211 if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED ||
2212 hd->cmdPtr)
2213 if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
Eric Moore29dd3602007-09-14 18:46:51 -06002214 printk(MYIOC_s_WARN_FMT " Firmware Reload FAILED!!\n", ioc->name);
Eric Moorecd2c6192007-01-29 09:47:47 -07002215 break;
2216
2217 case MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2218 default:
2219 break;
2220 }
2221
2222 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 spin_lock_irqsave(&ioc->FreeQlock, flags);
2224 hd->tmPending = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 hd->tmState = TM_STATE_NONE;
Eric Moorecd2c6192007-01-29 09:47:47 -07002226 hd->tm_iocstatus = iocstatus;
2227 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
2229 return 1;
2230}
2231
2232/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2233/*
2234 * This is anyones guess quite frankly.
2235 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002236int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
2238 sector_t capacity, int geom[])
2239{
2240 int heads;
2241 int sectors;
2242 sector_t cylinders;
2243 ulong dummy;
2244
2245 heads = 64;
2246 sectors = 32;
2247
2248 dummy = heads * sectors;
2249 cylinders = capacity;
2250 sector_div(cylinders,dummy);
2251
2252 /*
2253 * Handle extended translation size for logical drives
2254 * > 1Gb
2255 */
2256 if ((ulong)capacity >= 0x200000) {
2257 heads = 255;
2258 sectors = 63;
2259 dummy = heads * sectors;
2260 cylinders = capacity;
2261 sector_div(cylinders,dummy);
2262 }
2263
2264 /* return result */
2265 geom[0] = heads;
2266 geom[1] = sectors;
2267 geom[2] = cylinders;
2268
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 return 0;
2270}
2271
Moore, Ericf44e5462006-03-14 09:14:21 -07002272/* Search IOC page 3 to determine if this is hidden physical disk
2273 *
2274 */
2275int
Eric Moore793955f2007-01-29 09:42:20 -07002276mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id)
Moore, Ericf44e5462006-03-14 09:14:21 -07002277{
Eric Mooreb506ade2007-01-29 09:45:37 -07002278 struct inactive_raid_component_info *component_info;
Moore, Ericf44e5462006-03-14 09:14:21 -07002279 int i;
Eric Moore793955f2007-01-29 09:42:20 -07002280 int rc = 0;
Moore, Ericf44e5462006-03-14 09:14:21 -07002281
Eric Moore793955f2007-01-29 09:42:20 -07002282 if (!ioc->raid_data.pIocPg3)
2283 goto out;
Moore, Ericf44e5462006-03-14 09:14:21 -07002284 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
Eric Moore793955f2007-01-29 09:42:20 -07002285 if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
2286 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
2287 rc = 1;
2288 goto out;
2289 }
2290 }
2291
Eric Mooreb506ade2007-01-29 09:45:37 -07002292 /*
2293 * Check inactive list for matching phys disks
2294 */
2295 if (list_empty(&ioc->raid_data.inactive_list))
2296 goto out;
2297
2298 down(&ioc->raid_data.inactive_list_mutex);
2299 list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
2300 list) {
2301 if ((component_info->d.PhysDiskID == id) &&
2302 (component_info->d.PhysDiskBus == channel))
2303 rc = 1;
2304 }
2305 up(&ioc->raid_data.inactive_list_mutex);
2306
Eric Moore793955f2007-01-29 09:42:20 -07002307 out:
2308 return rc;
Moore, Ericf44e5462006-03-14 09:14:21 -07002309}
2310EXPORT_SYMBOL(mptscsih_is_phys_disk);
2311
Eric Moore793955f2007-01-29 09:42:20 -07002312u8
2313mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
James Bottomleyc92f2222006-03-01 09:02:49 -06002314{
Eric Mooreb506ade2007-01-29 09:45:37 -07002315 struct inactive_raid_component_info *component_info;
James Bottomleyc92f2222006-03-01 09:02:49 -06002316 int i;
Eric Moore793955f2007-01-29 09:42:20 -07002317 int rc = -ENXIO;
James Bottomleyc92f2222006-03-01 09:02:49 -06002318
Eric Moore793955f2007-01-29 09:42:20 -07002319 if (!ioc->raid_data.pIocPg3)
2320 goto out;
2321 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2322 if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
2323 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
2324 rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;
2325 goto out;
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002326 }
2327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
Eric Mooreb506ade2007-01-29 09:45:37 -07002329 /*
2330 * Check inactive list for matching phys disks
2331 */
2332 if (list_empty(&ioc->raid_data.inactive_list))
2333 goto out;
2334
2335 down(&ioc->raid_data.inactive_list_mutex);
2336 list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
2337 list) {
2338 if ((component_info->d.PhysDiskID == id) &&
2339 (component_info->d.PhysDiskBus == channel))
2340 rc = component_info->d.PhysDiskNum;
2341 }
2342 up(&ioc->raid_data.inactive_list_mutex);
2343
Eric Moore793955f2007-01-29 09:42:20 -07002344 out:
2345 return rc;
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002346}
Eric Moore793955f2007-01-29 09:42:20 -07002347EXPORT_SYMBOL(mptscsih_raid_id_to_num);
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002348
2349/*
2350 * OS entry point to allow for host driver to free allocated memory
2351 * Called if no device present or device being unloaded
2352 */
2353void
2354mptscsih_slave_destroy(struct scsi_device *sdev)
2355{
2356 struct Scsi_Host *host = sdev->host;
Eric Mooree7eae9f2007-09-29 10:15:59 -06002357 MPT_SCSI_HOST *hd = shost_priv(host);
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002358 VirtTarget *vtarget;
2359 VirtDevice *vdevice;
2360 struct scsi_target *starget;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002362 starget = scsi_target(sdev);
2363 vtarget = starget->hostdata;
2364 vdevice = sdev->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002366 mptscsih_search_running_cmds(hd, vdevice);
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002367 vtarget->num_luns--;
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002368 mptscsih_synchronize_cache(hd, vdevice);
2369 kfree(vdevice);
2370 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371}
2372
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -06002373/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2374/*
2375 * mptscsih_change_queue_depth - This function will set a devices queue depth
2376 * @sdev: per scsi_device pointer
2377 * @qdepth: requested queue depth
2378 *
2379 * Adding support for new 'change_queue_depth' api.
2380*/
2381int
2382mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383{
Eric Mooree7eae9f2007-09-29 10:15:59 -06002384 MPT_SCSI_HOST *hd = shost_priv(sdev->host);
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002385 VirtTarget *vtarget;
2386 struct scsi_target *starget;
2387 int max_depth;
2388 int tagged;
Eric Mooree80b0022007-09-14 18:49:03 -06002389 MPT_ADAPTER *ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002391 starget = scsi_target(sdev);
2392 vtarget = starget->hostdata;
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -06002393
Eric Mooree80b0022007-09-14 18:49:03 -06002394 if (ioc->bus_type == SPI) {
James Bottomleyc92f2222006-03-01 09:02:49 -06002395 if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 max_depth = 1;
James Bottomleyc92f2222006-03-01 09:02:49 -06002397 else if (sdev->type == TYPE_DISK &&
2398 vtarget->minSyncFactor <= MPT_ULTRA160)
2399 max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
2400 else
2401 max_depth = MPT_SCSI_CMD_PER_DEV_LOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 } else
2403 max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
2404
2405 if (qdepth > max_depth)
2406 qdepth = max_depth;
2407 if (qdepth == 1)
2408 tagged = 0;
2409 else
2410 tagged = MSG_SIMPLE_TAG;
2411
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -06002412 scsi_adjust_queue_depth(sdev, tagged, qdepth);
2413 return sdev->queue_depth;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414}
2415
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416/*
2417 * OS entry point to adjust the queue_depths on a per-device basis.
2418 * Called once per device the bus scan. Use it to force the queue_depth
2419 * member to 1 if a device does not support Q tags.
2420 * Return non-zero if fails.
2421 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002422int
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002423mptscsih_slave_configure(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424{
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002425 struct Scsi_Host *sh = sdev->host;
2426 VirtTarget *vtarget;
2427 VirtDevice *vdevice;
2428 struct scsi_target *starget;
Eric Mooree7eae9f2007-09-29 10:15:59 -06002429 MPT_SCSI_HOST *hd = shost_priv(sh);
Eric Mooree80b0022007-09-14 18:49:03 -06002430 MPT_ADAPTER *ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002432 starget = scsi_target(sdev);
2433 vtarget = starget->hostdata;
2434 vdevice = sdev->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Eric Mooree80b0022007-09-14 18:49:03 -06002436 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Eric Moore793955f2007-01-29 09:42:20 -07002437 "device @ %p, channel=%d, id=%d, lun=%d\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002438 ioc->name, sdev, sdev->channel, sdev->id, sdev->lun));
2439 if (ioc->bus_type == SPI)
2440 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002441 "sdtr %d wdtr %d ppr %d inq length=%d\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002442 ioc->name, sdev->sdtr, sdev->wdtr,
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002443 sdev->ppr, sdev->inquiry_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002445 if (sdev->id > sh->max_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 /* error case, should never happen */
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002447 scsi_adjust_queue_depth(sdev, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 goto slave_configure_exit;
2449 }
2450
Eric Moore793955f2007-01-29 09:42:20 -07002451 vdevice->configured_lun = 1;
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002452 mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453
Eric Mooree80b0022007-09-14 18:49:03 -06002454 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 "Queue depth=%d, tflags=%x\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002456 ioc->name, sdev->queue_depth, vtarget->tflags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457
Eric Mooree80b0022007-09-14 18:49:03 -06002458 if (ioc->bus_type == SPI)
2459 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002460 "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002461 ioc->name, vtarget->negoFlags, vtarget->maxOffset,
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002462 vtarget->minSyncFactor));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
2464slave_configure_exit:
2465
Eric Mooree80b0022007-09-14 18:49:03 -06002466 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 "tagged %d, simple %d, ordered %d\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002468 ioc->name,sdev->tagged_supported, sdev->simple_tags,
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07002469 sdev->ordered_tags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
2471 return 0;
2472}
2473
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2475/*
2476 * Private routines...
2477 */
2478
2479/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2480/* Utility function to copy sense data from the scsi_cmnd buffer
2481 * to the FC and SCSI target structures.
2482 *
2483 */
2484static void
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002485mptscsih_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 -07002486{
Eric Moorea69de502007-09-14 18:48:19 -06002487 VirtDevice *vdevice;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 SCSIIORequest_t *pReq;
2489 u32 sense_count = le32_to_cpu(pScsiReply->SenseCount);
Eric Mooree80b0022007-09-14 18:49:03 -06002490 MPT_ADAPTER *ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491
2492 /* Get target structure
2493 */
2494 pReq = (SCSIIORequest_t *) mf;
Eric Moorea69de502007-09-14 18:48:19 -06002495 vdevice = sc->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496
2497 if (sense_count) {
2498 u8 *sense_data;
2499 int req_index;
2500
2501 /* Copy the sense received into the scsi command block. */
2502 req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
Eric Mooree80b0022007-09-14 18:49:03 -06002503 sense_data = ((u8 *)ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc));
2505
2506 /* Log SMART data (asc = 0x5D, non-IM case only) if required.
2507 */
Eric Mooree80b0022007-09-14 18:49:03 -06002508 if ((ioc->events) && (ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {
Eric Moorea69de502007-09-14 18:48:19 -06002509 if ((sense_data[12] == 0x5D) && (vdevice->vtarget->raidVolume == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
Moore, Eric5b5ef4f2006-02-02 17:19:40 -07002512 idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE;
2514 ioc->events[idx].eventContext = ioc->eventContext;
2515
Dave Jones3d9780b2007-05-21 20:59:47 -04002516 ioc->events[idx].data[0] = (pReq->LUN[1] << 24) |
2517 (MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) |
2518 (sc->device->channel << 8) | sc->device->id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519
Dave Jones3d9780b2007-05-21 20:59:47 -04002520 ioc->events[idx].data[1] = (sense_data[13] << 8) | sense_data[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
2522 ioc->eventContext++;
Eric Mooree80b0022007-09-14 18:49:03 -06002523 if (ioc->pcidev->vendor ==
Eric Moore786899b2006-07-11 17:22:22 -06002524 PCI_VENDOR_ID_IBM) {
Eric Mooree80b0022007-09-14 18:49:03 -06002525 mptscsih_issue_sep_command(ioc,
Eric Moorea69de502007-09-14 18:48:19 -06002526 vdevice->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
2527 vdevice->vtarget->tflags |=
Eric Moore786899b2006-07-11 17:22:22 -06002528 MPT_TARGET_FLAGS_LED_ON;
2529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 }
2531 }
2532 } else {
Eric Mooree80b0022007-09-14 18:49:03 -06002533 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hmmm... SenseData len=0! (?)\n",
2534 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 }
2536}
2537
Eric Mooree8206382007-09-29 10:16:53 -06002538/**
2539 * mptscsih_get_scsi_lookup
Eric Mooree8206382007-09-29 10:16:53 -06002540 * @ioc: Pointer to MPT_ADAPTER structure
2541 * @i: index into the array
2542 *
Randy Dunlap7105a382008-02-29 22:03:27 -08002543 * retrieves scmd entry from ScsiLookup[] array list
Eric Mooree8206382007-09-29 10:16:53 -06002544 *
Randy Dunlap7105a382008-02-29 22:03:27 -08002545 * Returns the scsi_cmd pointer
Eric Mooree8206382007-09-29 10:16:53 -06002546 **/
2547static struct scsi_cmnd *
2548mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549{
Eric Mooree8206382007-09-29 10:16:53 -06002550 unsigned long flags;
2551 struct scsi_cmnd *scmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552
Eric Mooree8206382007-09-29 10:16:53 -06002553 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2554 scmd = ioc->ScsiLookup[i];
2555 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556
Eric Mooree8206382007-09-29 10:16:53 -06002557 return scmd;
2558}
2559
2560/**
2561 * mptscsih_getclear_scsi_lookup
Eric Mooree8206382007-09-29 10:16:53 -06002562 * @ioc: Pointer to MPT_ADAPTER structure
2563 * @i: index into the array
2564 *
Randy Dunlap7105a382008-02-29 22:03:27 -08002565 * retrieves and clears scmd entry from ScsiLookup[] array list
Eric Mooree8206382007-09-29 10:16:53 -06002566 *
Randy Dunlap7105a382008-02-29 22:03:27 -08002567 * Returns the scsi_cmd pointer
Eric Mooree8206382007-09-29 10:16:53 -06002568 **/
2569static struct scsi_cmnd *
2570mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i)
2571{
2572 unsigned long flags;
2573 struct scsi_cmnd *scmd;
2574
2575 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2576 scmd = ioc->ScsiLookup[i];
2577 ioc->ScsiLookup[i] = NULL;
2578 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2579
2580 return scmd;
2581}
2582
2583/**
2584 * mptscsih_set_scsi_lookup
2585 *
2586 * writes a scmd entry into the ScsiLookup[] array list
2587 *
2588 * @ioc: Pointer to MPT_ADAPTER structure
2589 * @i: index into the array
2590 * @scmd: scsi_cmnd pointer
2591 *
2592 **/
2593static void
2594mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd)
2595{
2596 unsigned long flags;
2597
2598 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2599 ioc->ScsiLookup[i] = scmd;
2600 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2601}
2602
2603/**
Randy Dunlap23f9b752007-10-15 17:29:33 -07002604 * SCPNT_TO_LOOKUP_IDX - searches for a given scmd in the ScsiLookup[] array list
Eric Mooree8206382007-09-29 10:16:53 -06002605 * @ioc: Pointer to MPT_ADAPTER structure
Randy Dunlap23f9b752007-10-15 17:29:33 -07002606 * @sc: scsi_cmnd pointer
2607 */
Eric Mooree8206382007-09-29 10:16:53 -06002608static int
2609SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *sc)
2610{
2611 unsigned long flags;
2612 int i, index=-1;
2613
2614 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
2615 for (i = 0; i < ioc->req_depth; i++) {
2616 if (ioc->ScsiLookup[i] == sc) {
2617 index = i;
2618 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 }
2620 }
2621
Eric Mooree8206382007-09-29 10:16:53 -06002622 out:
2623 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
2624 return index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625}
2626
2627/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002628int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
2630{
2631 MPT_SCSI_HOST *hd;
2632 unsigned long flags;
2633
Eric Moore29dd3602007-09-14 18:46:51 -06002634 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2635 ": IOC %s_reset routed to SCSI host driver!\n",
2636 ioc->name, reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
2637 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
2639 /* If a FW reload request arrives after base installed but
2640 * before all scsi hosts have been attached, then an alt_ioc
2641 * may have a NULL sh pointer.
2642 */
Eric Mooree7eae9f2007-09-29 10:15:59 -06002643 if (ioc->sh == NULL || shost_priv(ioc->sh) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 return 0;
2645 else
Eric Mooree7eae9f2007-09-29 10:15:59 -06002646 hd = shost_priv(ioc->sh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
2648 if (reset_phase == MPT_IOC_SETUP_RESET) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302649 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Setup-Diag Reset\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
2651 /* Clean Up:
2652 * 1. Set Hard Reset Pending Flag
2653 * All new commands go to doneQ
2654 */
2655 hd->resetPending = 1;
2656
2657 } else if (reset_phase == MPT_IOC_PRE_RESET) {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302658 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Pre-Diag Reset\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659
2660 /* 2. Flush running commands
2661 * Clean ScsiLookup (and associated memory)
2662 * AND clean mytaskQ
2663 */
2664
2665 /* 2b. Reply to OS all known outstanding I/O commands.
2666 */
2667 mptscsih_flush_running_cmds(hd);
2668
2669 /* 2c. If there was an internal command that
2670 * has not completed, configuration or io request,
2671 * free these resources.
2672 */
2673 if (hd->cmdPtr) {
2674 del_timer(&hd->timer);
2675 mpt_free_msg_frame(ioc, hd->cmdPtr);
2676 }
2677
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302678 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Pre-Reset complete.\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679
2680 } else {
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302681 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Post-Diag Reset\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
2683 /* Once a FW reload begins, all new OS commands are
2684 * redirected to the doneQ w/ a reset status.
2685 * Init all control structures.
2686 */
2687
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 /* 2. Chain Buffer initialization
2689 */
2690
Moore, Eric Deana9b29372005-11-16 18:54:20 -07002691 /* 4. Renegotiate to all devices, if SPI
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693
2694 /* 5. Enable new commands to be posted
2695 */
2696 spin_lock_irqsave(&ioc->FreeQlock, flags);
2697 hd->tmPending = 0;
2698 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
2699 hd->resetPending = 0;
2700 hd->tmState = TM_STATE_NONE;
2701
2702 /* 6. If there was an internal command,
2703 * wake this process up.
2704 */
2705 if (hd->cmdPtr) {
2706 /*
2707 * Wake up the original calling thread
2708 */
2709 hd->pLocal = &hd->localReply;
2710 hd->pLocal->completion = MPT_SCANDV_DID_RESET;
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002711 hd->scandv_wait_done = 1;
2712 wake_up(&hd->scandv_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 hd->cmdPtr = NULL;
2714 }
2715
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302716 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Post-Reset complete.\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717
2718 }
2719
2720 return 1; /* currently means nothing really */
2721}
2722
2723/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002724int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
2726{
2727 MPT_SCSI_HOST *hd;
2728 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
2729
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302730 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 ioc->name, event));
2732
Moore, Eric Dean466544d2005-09-14 18:09:10 -06002733 if (ioc->sh == NULL ||
Eric Mooree7eae9f2007-09-29 10:15:59 -06002734 ((hd = shost_priv(ioc->sh)) == NULL))
Moore, Eric Dean466544d2005-09-14 18:09:10 -06002735 return 1;
2736
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 switch (event) {
2738 case MPI_EVENT_UNIT_ATTENTION: /* 03 */
2739 /* FIXME! */
2740 break;
2741 case MPI_EVENT_IOC_BUS_RESET: /* 04 */
2742 case MPI_EVENT_EXT_BUS_RESET: /* 05 */
Moore, Eric Deana9b29372005-11-16 18:54:20 -07002743 if (hd && (ioc->bus_type == SPI) && (hd->soft_resets < -1))
Moore, Eric Dean466544d2005-09-14 18:09:10 -06002744 hd->soft_resets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 break;
2746 case MPI_EVENT_LOGOUT: /* 09 */
2747 /* FIXME! */
2748 break;
2749
Michael Reed05e8ec12006-01-13 14:31:54 -06002750 case MPI_EVENT_RESCAN: /* 06 */
Michael Reed05e8ec12006-01-13 14:31:54 -06002751 break;
2752
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 /*
2754 * CHECKME! Don't think we need to do
2755 * anything for these, but...
2756 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
2758 case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
2759 /*
2760 * CHECKME! Falling thru...
2761 */
2762 break;
2763
2764 case MPI_EVENT_INTEGRATED_RAID: /* 0B */
Moore, Eric Dean466544d2005-09-14 18:09:10 -06002765 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 case MPI_EVENT_NONE: /* 00 */
2768 case MPI_EVENT_LOG_DATA: /* 01 */
2769 case MPI_EVENT_STATE_CHANGE: /* 02 */
2770 case MPI_EVENT_EVENT_CHANGE: /* 0A */
2771 default:
Eric Moore29dd3602007-09-14 18:46:51 -06002772 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": Ignoring event (=%02Xh)\n",
2773 ioc->name, event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 break;
2775 }
2776
2777 return 1; /* currently means nothing really */
2778}
2779
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2781/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 * Bus Scan and Domain Validation functionality ...
2783 */
2784
2785/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2786/*
2787 * mptscsih_scandv_complete - Scan and DV callback routine registered
2788 * to Fustion MPT (base) driver.
2789 *
2790 * @ioc: Pointer to MPT_ADAPTER structure
2791 * @mf: Pointer to original MPT request frame
2792 * @mr: Pointer to MPT reply frame (NULL if TurboReply)
2793 *
2794 * This routine is called from mpt.c::mpt_interrupt() at the completion
2795 * of any SCSI IO request.
2796 * This routine is registered with the Fusion MPT (base) driver at driver
2797 * load/init time via the mpt_register() API call.
2798 *
2799 * Returns 1 indicating alloc'd request frame ptr should be freed.
2800 *
2801 * Remark: Sets a completion code and (possibly) saves sense data
2802 * in the IOC member localReply structure.
2803 * Used ONLY for DV and other internal commands.
2804 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002805int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
2807{
2808 MPT_SCSI_HOST *hd;
2809 SCSIIORequest_t *pReq;
2810 int completionCode;
2811 u16 req_idx;
2812
Eric Mooree7eae9f2007-09-29 10:15:59 -06002813 hd = shost_priv(ioc->sh);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002814
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 if ((mf == NULL) ||
2816 (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
2817 printk(MYIOC_s_ERR_FMT
2818 "ScanDvComplete, %s req frame ptr! (=%p)\n",
2819 ioc->name, mf?"BAD":"NULL", (void *) mf);
2820 goto wakeup;
2821 }
2822
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 del_timer(&hd->timer);
2824 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
Eric Mooree8206382007-09-29 10:16:53 -06002825 mptscsih_set_scsi_lookup(ioc, req_idx, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 pReq = (SCSIIORequest_t *) mf;
2827
2828 if (mf != hd->cmdPtr) {
2829 printk(MYIOC_s_WARN_FMT "ScanDvComplete (mf=%p, cmdPtr=%p, idx=%d)\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002830 ioc->name, (void *)mf, (void *) hd->cmdPtr, req_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 }
2832 hd->cmdPtr = NULL;
2833
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05302834 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScanDvComplete (mf=%p,mr=%p,idx=%d)\n",
Eric Mooree80b0022007-09-14 18:49:03 -06002835 ioc->name, mf, mr, req_idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836
2837 hd->pLocal = &hd->localReply;
2838 hd->pLocal->scsiStatus = 0;
2839
2840 /* If target struct exists, clear sense valid flag.
2841 */
2842 if (mr == NULL) {
2843 completionCode = MPT_SCANDV_GOOD;
2844 } else {
2845 SCSIIOReply_t *pReply;
2846 u16 status;
2847 u8 scsi_status;
2848
2849 pReply = (SCSIIOReply_t *) mr;
2850
2851 status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
2852 scsi_status = pReply->SCSIStatus;
2853
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
2855 switch(status) {
2856
2857 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
2858 completionCode = MPT_SCANDV_SELECTION_TIMEOUT;
2859 break;
2860
2861 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
2862 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
2863 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
2864 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
2865 completionCode = MPT_SCANDV_DID_RESET;
2866 break;
2867
2868 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
2869 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
2870 case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
2871 if (pReply->Function == MPI_FUNCTION_CONFIG) {
2872 ConfigReply_t *pr = (ConfigReply_t *)mr;
2873 completionCode = MPT_SCANDV_GOOD;
2874 hd->pLocal->header.PageVersion = pr->Header.PageVersion;
2875 hd->pLocal->header.PageLength = pr->Header.PageLength;
2876 hd->pLocal->header.PageNumber = pr->Header.PageNumber;
2877 hd->pLocal->header.PageType = pr->Header.PageType;
2878
2879 } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
2880 /* If the RAID Volume request is successful,
2881 * return GOOD, else indicate that
2882 * some type of error occurred.
2883 */
2884 MpiRaidActionReply_t *pr = (MpiRaidActionReply_t *)mr;
Christoph Hellwig637fa992005-08-18 16:25:44 +02002885 if (le16_to_cpu(pr->ActionStatus) == MPI_RAID_ACTION_ASTATUS_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 completionCode = MPT_SCANDV_GOOD;
2887 else
2888 completionCode = MPT_SCANDV_SOME_ERROR;
James Bottomleyc92f2222006-03-01 09:02:49 -06002889 memcpy(hd->pLocal->sense, pr, sizeof(hd->pLocal->sense));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890
2891 } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
2892 u8 *sense_data;
2893 int sz;
2894
2895 /* save sense data in global structure
2896 */
2897 completionCode = MPT_SCANDV_SENSE;
2898 hd->pLocal->scsiStatus = scsi_status;
Eric Mooree80b0022007-09-14 18:49:03 -06002899 sense_data = ((u8 *)ioc->sense_buf_pool +
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 (req_idx * MPT_SENSE_BUFFER_ALLOC));
2901
2902 sz = min_t(int, pReq->SenseBufferLength,
2903 SCSI_STD_SENSE_BYTES);
2904 memcpy(hd->pLocal->sense, sense_data, sz);
2905
Eric Moore29dd3602007-09-14 18:46:51 -06002906 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT " Check Condition, sense ptr %p\n",
2907 ioc->name, sense_data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
2909 if (pReq->CDB[0] == INQUIRY)
2910 completionCode = MPT_SCANDV_ISSUE_SENSE;
2911 else
2912 completionCode = MPT_SCANDV_DID_RESET;
2913 }
2914 else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
2915 completionCode = MPT_SCANDV_DID_RESET;
2916 else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
2917 completionCode = MPT_SCANDV_DID_RESET;
2918 else {
2919 completionCode = MPT_SCANDV_GOOD;
2920 hd->pLocal->scsiStatus = scsi_status;
2921 }
2922 break;
2923
2924 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
2925 if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
2926 completionCode = MPT_SCANDV_DID_RESET;
2927 else
2928 completionCode = MPT_SCANDV_SOME_ERROR;
2929 break;
2930
2931 default:
2932 completionCode = MPT_SCANDV_SOME_ERROR;
2933 break;
2934
2935 } /* switch(status) */
2936
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 } /* end of address reply case */
2938
2939 hd->pLocal->completion = completionCode;
2940
2941 /* MF and RF are freed in mpt_interrupt
2942 */
2943wakeup:
2944 /* Free Chain buffers (will never chain) in scan or dv */
2945 //mptscsih_freeChainBuffers(ioc, req_idx);
2946
2947 /*
2948 * Wake up the original calling thread
2949 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002950 hd->scandv_wait_done = 1;
2951 wake_up(&hd->scandv_waitq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952
2953 return 1;
2954}
2955
2956/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2957/* mptscsih_timer_expired - Call back for timer process.
2958 * Used only for dv functionality.
2959 * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
2960 *
2961 */
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04002962void
2963mptscsih_timer_expired(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964{
2965 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) data;
Eric Mooree80b0022007-09-14 18:49:03 -06002966 MPT_ADAPTER *ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Eric Mooree80b0022007-09-14 18:49:03 -06002968 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Timer Expired! Cmd %p\n", ioc->name, hd->cmdPtr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969
2970 if (hd->cmdPtr) {
2971 MPIHeader_t *cmd = (MPIHeader_t *)hd->cmdPtr;
2972
2973 if (cmd->Function == MPI_FUNCTION_SCSI_IO_REQUEST) {
2974 /* Desire to issue a task management request here.
2975 * TM requests MUST be single threaded.
2976 * If old eh code and no TM current, issue request.
2977 * If new eh code, do nothing. Wait for OS cmd timeout
2978 * for bus reset.
2979 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 } else {
2981 /* Perform a FW reload */
Eric Mooree80b0022007-09-14 18:49:03 -06002982 if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0) {
2983 printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 }
2985 }
2986 } else {
2987 /* This should NEVER happen */
Eric Mooree80b0022007-09-14 18:49:03 -06002988 printk(MYIOC_s_WARN_FMT "Null cmdPtr!!!!\n", ioc->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 }
2990
2991 /* No more processing.
2992 * TM call will generate an interrupt for SCSI TM Management.
2993 * The FW will reply to all outstanding commands, callback will finish cleanup.
2994 * Hard reset clean-up will free all resources.
2995 */
Eric Mooree80b0022007-09-14 18:49:03 -06002996 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Timer Expired Complete!\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997
2998 return;
2999}
3000
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001
3002/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3003/**
3004 * mptscsih_do_cmd - Do internal command.
3005 * @hd: MPT_SCSI_HOST pointer
3006 * @io: INTERNAL_CMD pointer.
3007 *
3008 * Issue the specified internally generated command and do command
3009 * specific cleanup. For bus scan / DV only.
3010 * NOTES: If command is Inquiry and status is good,
3011 * initialize a target structure, save the data
3012 *
3013 * Remark: Single threaded access only.
3014 *
3015 * Return:
3016 * < 0 if an illegal command or no resources
3017 *
3018 * 0 if good
3019 *
3020 * > 0 if command complete but some type of completion error.
3021 */
3022static int
3023mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
3024{
3025 MPT_FRAME_HDR *mf;
3026 SCSIIORequest_t *pScsiReq;
3027 SCSIIORequest_t ReqCopy;
3028 int my_idx, ii, dir;
3029 int rc, cmdTimeout;
3030 int in_isr;
3031 char cmdLen;
3032 char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
3033 char cmd = io->cmd;
Eric Mooree80b0022007-09-14 18:49:03 -06003034 MPT_ADAPTER *ioc = hd->ioc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035
3036 in_isr = in_interrupt();
3037 if (in_isr) {
Eric Mooree80b0022007-09-14 18:49:03 -06003038 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Internal SCSI IO request not allowed in ISR context!\n",
3039 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 return -EPERM;
3041 }
3042
3043
3044 /* Set command specific information
3045 */
3046 switch (cmd) {
3047 case INQUIRY:
3048 cmdLen = 6;
3049 dir = MPI_SCSIIO_CONTROL_READ;
3050 CDB[0] = cmd;
3051 CDB[4] = io->size;
3052 cmdTimeout = 10;
3053 break;
3054
3055 case TEST_UNIT_READY:
3056 cmdLen = 6;
3057 dir = MPI_SCSIIO_CONTROL_READ;
3058 cmdTimeout = 10;
3059 break;
3060
3061 case START_STOP:
3062 cmdLen = 6;
3063 dir = MPI_SCSIIO_CONTROL_READ;
3064 CDB[0] = cmd;
3065 CDB[4] = 1; /*Spin up the disk */
3066 cmdTimeout = 15;
3067 break;
3068
3069 case REQUEST_SENSE:
3070 cmdLen = 6;
3071 CDB[0] = cmd;
3072 CDB[4] = io->size;
3073 dir = MPI_SCSIIO_CONTROL_READ;
3074 cmdTimeout = 10;
3075 break;
3076
3077 case READ_BUFFER:
3078 cmdLen = 10;
3079 dir = MPI_SCSIIO_CONTROL_READ;
3080 CDB[0] = cmd;
3081 if (io->flags & MPT_ICFLAG_ECHO) {
3082 CDB[1] = 0x0A;
3083 } else {
3084 CDB[1] = 0x02;
3085 }
3086
3087 if (io->flags & MPT_ICFLAG_BUF_CAP) {
3088 CDB[1] |= 0x01;
3089 }
3090 CDB[6] = (io->size >> 16) & 0xFF;
3091 CDB[7] = (io->size >> 8) & 0xFF;
3092 CDB[8] = io->size & 0xFF;
3093 cmdTimeout = 10;
3094 break;
3095
3096 case WRITE_BUFFER:
3097 cmdLen = 10;
3098 dir = MPI_SCSIIO_CONTROL_WRITE;
3099 CDB[0] = cmd;
3100 if (io->flags & MPT_ICFLAG_ECHO) {
3101 CDB[1] = 0x0A;
3102 } else {
3103 CDB[1] = 0x02;
3104 }
3105 CDB[6] = (io->size >> 16) & 0xFF;
3106 CDB[7] = (io->size >> 8) & 0xFF;
3107 CDB[8] = io->size & 0xFF;
3108 cmdTimeout = 10;
3109 break;
3110
3111 case RESERVE:
3112 cmdLen = 6;
3113 dir = MPI_SCSIIO_CONTROL_READ;
3114 CDB[0] = cmd;
3115 cmdTimeout = 10;
3116 break;
3117
3118 case RELEASE:
3119 cmdLen = 6;
3120 dir = MPI_SCSIIO_CONTROL_READ;
3121 CDB[0] = cmd;
3122 cmdTimeout = 10;
3123 break;
3124
3125 case SYNCHRONIZE_CACHE:
3126 cmdLen = 10;
3127 dir = MPI_SCSIIO_CONTROL_READ;
3128 CDB[0] = cmd;
3129// CDB[1] = 0x02; /* set immediate bit */
3130 cmdTimeout = 10;
3131 break;
3132
3133 default:
3134 /* Error Case */
3135 return -EFAULT;
3136 }
3137
3138 /* Get and Populate a free Frame
3139 */
Eric Mooree80b0022007-09-14 18:49:03 -06003140 if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
3141 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "No msg frames!\n",
3142 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 return -EBUSY;
3144 }
3145
3146 pScsiReq = (SCSIIORequest_t *) mf;
3147
3148 /* Get the request index */
3149 my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
3150 ADD_INDEX_LOG(my_idx); /* for debug */
3151
3152 if (io->flags & MPT_ICFLAG_PHYS_DISK) {
3153 pScsiReq->TargetID = io->physDiskNum;
3154 pScsiReq->Bus = 0;
3155 pScsiReq->ChainOffset = 0;
3156 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3157 } else {
3158 pScsiReq->TargetID = io->id;
Eric Moore793955f2007-01-29 09:42:20 -07003159 pScsiReq->Bus = io->channel;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 pScsiReq->ChainOffset = 0;
3161 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
3162 }
3163
3164 pScsiReq->CDBLength = cmdLen;
3165 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
3166
3167 pScsiReq->Reserved = 0;
3168
3169 pScsiReq->MsgFlags = mpt_msg_flags();
3170 /* MsgContext set in mpt_get_msg_fram call */
3171
Eric Moore793955f2007-01-29 09:42:20 -07003172 int_to_scsilun(io->lun, (struct scsi_lun *)pScsiReq->LUN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173
3174 if (io->flags & MPT_ICFLAG_TAGGED_CMD)
3175 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);
3176 else
3177 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
3178
3179 if (cmd == REQUEST_SENSE) {
3180 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
Eric Mooree80b0022007-09-14 18:49:03 -06003181 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Untagged! 0x%2x\n",
3182 ioc->name, cmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 }
3184
3185 for (ii=0; ii < 16; ii++)
3186 pScsiReq->CDB[ii] = CDB[ii];
3187
3188 pScsiReq->DataLength = cpu_to_le32(io->size);
Eric Mooree80b0022007-09-14 18:49:03 -06003189 pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 + (my_idx * MPT_SENSE_BUFFER_ALLOC));
3191
Eric Mooree80b0022007-09-14 18:49:03 -06003192 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Command 0x%x for (%d:%d:%d)\n",
3193 ioc->name, cmd, io->channel, io->id, io->lun));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
3195 if (dir == MPI_SCSIIO_CONTROL_READ) {
3196 mpt_add_sge((char *) &pScsiReq->SGL,
3197 MPT_SGE_FLAGS_SSIMPLE_READ | io->size,
3198 io->data_dma);
3199 } else {
3200 mpt_add_sge((char *) &pScsiReq->SGL,
3201 MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size,
3202 io->data_dma);
3203 }
3204
3205 /* The ISR will free the request frame, but we need
3206 * the information to initialize the target. Duplicate.
3207 */
3208 memcpy(&ReqCopy, pScsiReq, sizeof(SCSIIORequest_t));
3209
3210 /* Issue this command after:
3211 * finish init
3212 * add timer
3213 * Wait until the reply has been received
3214 * ScsiScanDvCtx callback function will
3215 * set hd->pLocal;
3216 * set scandv_wait_done and call wake_up
3217 */
3218 hd->pLocal = NULL;
3219 hd->timer.expires = jiffies + HZ*cmdTimeout;
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04003220 hd->scandv_wait_done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221
3222 /* Save cmd pointer, for resource free if timeout or
3223 * FW reload occurs
3224 */
3225 hd->cmdPtr = mf;
3226
3227 add_timer(&hd->timer);
Eric Mooree80b0022007-09-14 18:49:03 -06003228 mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04003229 wait_event(hd->scandv_waitq, hd->scandv_wait_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230
3231 if (hd->pLocal) {
3232 rc = hd->pLocal->completion;
3233 hd->pLocal->skip = 0;
3234
3235 /* Always set fatal error codes in some cases.
3236 */
3237 if (rc == MPT_SCANDV_SELECTION_TIMEOUT)
3238 rc = -ENXIO;
3239 else if (rc == MPT_SCANDV_SOME_ERROR)
3240 rc = -rc;
3241 } else {
3242 rc = -EFAULT;
3243 /* This should never happen. */
Eric Mooree80b0022007-09-14 18:49:03 -06003244 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "_do_cmd: Null pLocal!!!\n",
3245 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 }
3247
3248 return rc;
3249}
3250
3251/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3252/**
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07003253 * mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks.
3254 * @hd: Pointer to a SCSI HOST structure
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003255 * @vdevice: virtual target device
Moore, Eric Deanc7c82982005-11-16 18:54:25 -07003256 *
3257 * Uses the ISR, but with special processing.
3258 * MUST be single-threaded.
3259 *
3260 */
3261static void
3262mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
3263{
3264 INTERNAL_CMD iocmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265
Eric Moorecc78d302007-06-15 17:27:21 -06003266 /* Ignore hidden raid components, this is handled when the command
3267 * is sent to the volume
3268 */
3269 if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
3270 return;
3271
3272 if (vdevice->vtarget->type != TYPE_DISK || vdevice->vtarget->deleted ||
3273 !vdevice->configured_lun)
3274 return;
3275
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 /* Following parameters will not change
3277 * in this routine.
3278 */
3279 iocmd.cmd = SYNCHRONIZE_CACHE;
3280 iocmd.flags = 0;
3281 iocmd.physDiskNum = -1;
3282 iocmd.data = NULL;
3283 iocmd.data_dma = -1;
3284 iocmd.size = 0;
3285 iocmd.rsvd = iocmd.rsvd2 = 0;
Eric Moore793955f2007-01-29 09:42:20 -07003286 iocmd.channel = vdevice->vtarget->channel;
3287 iocmd.id = vdevice->vtarget->id;
3288 iocmd.lun = vdevice->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289
Eric Moorecc78d302007-06-15 17:27:21 -06003290 mptscsih_do_cmd(hd, &iocmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291}
3292
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303293static ssize_t
3294mptscsih_version_fw_show(struct class_device *cdev, char *buf)
3295{
3296 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003297 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303298 MPT_ADAPTER *ioc = hd->ioc;
3299
3300 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
3301 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
3302 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
3303 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
3304 ioc->facts.FWVersion.Word & 0x000000FF);
3305}
3306static CLASS_DEVICE_ATTR(version_fw, S_IRUGO, mptscsih_version_fw_show, NULL);
3307
3308static ssize_t
3309mptscsih_version_bios_show(struct class_device *cdev, char *buf)
3310{
3311 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003312 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303313 MPT_ADAPTER *ioc = hd->ioc;
3314
3315 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
3316 (ioc->biosVersion & 0xFF000000) >> 24,
3317 (ioc->biosVersion & 0x00FF0000) >> 16,
3318 (ioc->biosVersion & 0x0000FF00) >> 8,
3319 ioc->biosVersion & 0x000000FF);
3320}
3321static CLASS_DEVICE_ATTR(version_bios, S_IRUGO, mptscsih_version_bios_show, NULL);
3322
3323static ssize_t
3324mptscsih_version_mpi_show(struct class_device *cdev, char *buf)
3325{
3326 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003327 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303328 MPT_ADAPTER *ioc = hd->ioc;
3329
3330 return snprintf(buf, PAGE_SIZE, "%03x\n", ioc->facts.MsgVersion);
3331}
3332static CLASS_DEVICE_ATTR(version_mpi, S_IRUGO, mptscsih_version_mpi_show, NULL);
3333
3334static ssize_t
3335mptscsih_version_product_show(struct class_device *cdev, char *buf)
3336{
3337 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003338 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303339 MPT_ADAPTER *ioc = hd->ioc;
3340
3341 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->prod_name);
3342}
3343static CLASS_DEVICE_ATTR(version_product, S_IRUGO,
3344 mptscsih_version_product_show, NULL);
3345
3346static ssize_t
3347mptscsih_version_nvdata_persistent_show(struct class_device *cdev, char *buf)
3348{
3349 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003350 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303351 MPT_ADAPTER *ioc = hd->ioc;
3352
3353 return snprintf(buf, PAGE_SIZE, "%02xh\n",
3354 ioc->nvdata_version_persistent);
3355}
3356static CLASS_DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
3357 mptscsih_version_nvdata_persistent_show, NULL);
3358
3359static ssize_t
3360mptscsih_version_nvdata_default_show(struct class_device *cdev, char *buf)
3361{
3362 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003363 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303364 MPT_ADAPTER *ioc = hd->ioc;
3365
3366 return snprintf(buf, PAGE_SIZE, "%02xh\n",ioc->nvdata_version_default);
3367}
3368static CLASS_DEVICE_ATTR(version_nvdata_default, S_IRUGO,
3369 mptscsih_version_nvdata_default_show, NULL);
3370
3371static ssize_t
3372mptscsih_board_name_show(struct class_device *cdev, char *buf)
3373{
3374 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003375 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303376 MPT_ADAPTER *ioc = hd->ioc;
3377
3378 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_name);
3379}
3380static CLASS_DEVICE_ATTR(board_name, S_IRUGO, mptscsih_board_name_show, NULL);
3381
3382static ssize_t
3383mptscsih_board_assembly_show(struct class_device *cdev, char *buf)
3384{
3385 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003386 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303387 MPT_ADAPTER *ioc = hd->ioc;
3388
3389 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_assembly);
3390}
3391static CLASS_DEVICE_ATTR(board_assembly, S_IRUGO,
3392 mptscsih_board_assembly_show, NULL);
3393
3394static ssize_t
3395mptscsih_board_tracer_show(struct class_device *cdev, char *buf)
3396{
3397 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003398 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303399 MPT_ADAPTER *ioc = hd->ioc;
3400
3401 return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_tracer);
3402}
3403static CLASS_DEVICE_ATTR(board_tracer, S_IRUGO,
3404 mptscsih_board_tracer_show, NULL);
3405
3406static ssize_t
3407mptscsih_io_delay_show(struct class_device *cdev, char *buf)
3408{
3409 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003410 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303411 MPT_ADAPTER *ioc = hd->ioc;
3412
3413 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
3414}
3415static CLASS_DEVICE_ATTR(io_delay, S_IRUGO,
3416 mptscsih_io_delay_show, NULL);
3417
3418static ssize_t
3419mptscsih_device_delay_show(struct class_device *cdev, char *buf)
3420{
3421 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003422 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303423 MPT_ADAPTER *ioc = hd->ioc;
3424
3425 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
3426}
3427static CLASS_DEVICE_ATTR(device_delay, S_IRUGO,
3428 mptscsih_device_delay_show, NULL);
3429
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05303430static ssize_t
3431mptscsih_debug_level_show(struct class_device *cdev, char *buf)
3432{
3433 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003434 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05303435 MPT_ADAPTER *ioc = hd->ioc;
3436
3437 return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->debug_level);
3438}
3439static ssize_t
3440mptscsih_debug_level_store(struct class_device *cdev, const char *buf,
3441 size_t count)
3442{
3443 struct Scsi_Host *host = class_to_shost(cdev);
Eric Mooree7eae9f2007-09-29 10:15:59 -06003444 MPT_SCSI_HOST *hd = shost_priv(host);
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05303445 MPT_ADAPTER *ioc = hd->ioc;
3446 int val = 0;
3447
3448 if (sscanf(buf, "%x", &val) != 1)
3449 return -EINVAL;
3450
3451 ioc->debug_level = val;
3452 printk(MYIOC_s_INFO_FMT "debug_level=%08xh\n",
3453 ioc->name, ioc->debug_level);
3454 return strlen(buf);
3455}
3456static CLASS_DEVICE_ATTR(debug_level, S_IRUGO | S_IWUSR,
3457 mptscsih_debug_level_show, mptscsih_debug_level_store);
3458
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303459struct class_device_attribute *mptscsih_host_attrs[] = {
3460 &class_device_attr_version_fw,
3461 &class_device_attr_version_bios,
3462 &class_device_attr_version_mpi,
3463 &class_device_attr_version_product,
3464 &class_device_attr_version_nvdata_persistent,
3465 &class_device_attr_version_nvdata_default,
3466 &class_device_attr_board_name,
3467 &class_device_attr_board_assembly,
3468 &class_device_attr_board_tracer,
3469 &class_device_attr_io_delay,
3470 &class_device_attr_device_delay,
Prakash, Sathya6757d6b2007-07-25 11:14:01 +05303471 &class_device_attr_debug_level,
Prakash, Sathyaedb90682007-07-17 14:39:14 +05303472 NULL,
3473};
3474EXPORT_SYMBOL(mptscsih_host_attrs);
3475
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04003476EXPORT_SYMBOL(mptscsih_remove);
3477EXPORT_SYMBOL(mptscsih_shutdown);
3478#ifdef CONFIG_PM
3479EXPORT_SYMBOL(mptscsih_suspend);
3480EXPORT_SYMBOL(mptscsih_resume);
3481#endif
3482EXPORT_SYMBOL(mptscsih_proc_info);
3483EXPORT_SYMBOL(mptscsih_info);
3484EXPORT_SYMBOL(mptscsih_qcmd);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04003485EXPORT_SYMBOL(mptscsih_slave_destroy);
3486EXPORT_SYMBOL(mptscsih_slave_configure);
3487EXPORT_SYMBOL(mptscsih_abort);
3488EXPORT_SYMBOL(mptscsih_dev_reset);
3489EXPORT_SYMBOL(mptscsih_bus_reset);
3490EXPORT_SYMBOL(mptscsih_host_reset);
3491EXPORT_SYMBOL(mptscsih_bios_param);
3492EXPORT_SYMBOL(mptscsih_io_done);
3493EXPORT_SYMBOL(mptscsih_taskmgmt_complete);
3494EXPORT_SYMBOL(mptscsih_scandv_complete);
3495EXPORT_SYMBOL(mptscsih_event_process);
3496EXPORT_SYMBOL(mptscsih_ioc_reset);
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -06003497EXPORT_SYMBOL(mptscsih_change_queue_depth);
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04003498EXPORT_SYMBOL(mptscsih_timer_expired);
James Bottomley663e1aa2006-01-29 12:10:24 -06003499EXPORT_SYMBOL(mptscsih_TMHandler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500
Moore, Eric Dean 0d0c7972005-04-22 18:02:09 -04003501/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/