2 * linux/drivers/message/fusion/mptbase.c
3 * This is the Fusion MPT base driver which supports multiple
4 * (SCSI + LAN) specialized protocol drivers.
5 * For use with LSI Logic PCI chip/adapter(s)
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
8 * Copyright (c) 1999-2005 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com)
12 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; version 2 of the License.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
24 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
25 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
26 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
27 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
28 solely responsible for determining the appropriateness of using and
29 distributing the Program and assumes all risks associated with its
30 exercise of rights under this Agreement, including but not limited to
31 the risks and costs of program errors, damage to or loss of data,
32 programs or equipment, and unavailability or interruption of operations.
34 DISCLAIMER OF LIABILITY
35 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
36 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
38 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
39 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
40 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
41 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
43 You should have received a copy of the GNU General Public License
44 along with this program; if not, write to the Free Software
45 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
49 #include <linux/config.h>
50 #include <linux/version.h>
51 #include <linux/kernel.h>
52 #include <linux/module.h>
53 #include <linux/errno.h>
54 #include <linux/init.h>
55 #include <linux/slab.h>
56 #include <linux/types.h>
57 #include <linux/pci.h>
58 #include <linux/kdev_t.h>
59 #include <linux/blkdev.h>
60 #include <linux/delay.h>
61 #include <linux/interrupt.h> /* needed for in_interrupt() proto */
62 #include <linux/dma-mapping.h>
68 #include <asm/irq.h> /* needed for __irq_itoa() proto */
73 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
74 #define my_NAME "Fusion MPT base driver"
75 #define my_VERSION MPT_LINUX_VERSION_COMMON
76 #define MYNAM "mptbase"
78 MODULE_AUTHOR(MODULEAUTHOR);
79 MODULE_DESCRIPTION(my_NAME);
80 MODULE_LICENSE("GPL");
86 static int mfcounter = 0;
87 #define PRINT_MF_COUNT 20000
90 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
94 int mpt_lan_index = -1;
95 int mpt_stm_index = -1;
97 struct proc_dir_entry *mpt_proc_root_dir;
99 #define WHOINIT_UNKNOWN 0xAA
101 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
105 /* Adapter link list */
107 /* Callback lookup table */
108 static MPT_CALLBACK MptCallbacks[MPT_MAX_PROTOCOL_DRIVERS];
109 /* Protocol driver class lookup table */
110 static int MptDriverClass[MPT_MAX_PROTOCOL_DRIVERS];
111 /* Event handler lookup table */
112 static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
113 /* Reset handler lookup table */
114 static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
115 static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
117 static int mpt_base_index = -1;
118 static int last_drv_idx = -1;
120 static DECLARE_WAIT_QUEUE_HEAD(mpt_waitq);
122 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
126 static irqreturn_t mpt_interrupt(int irq, void *bus_id, struct pt_regs *r);
127 static int mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
128 static int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
129 u32 *req, int replyBytes, u16 *u16reply, int maxwait,
131 static int mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag);
132 static void mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev);
133 static void mpt_adapter_disable(MPT_ADAPTER *ioc);
134 static void mpt_adapter_dispose(MPT_ADAPTER *ioc);
136 static void MptDisplayIocCapabilities(MPT_ADAPTER *ioc);
137 static int MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag);
138 //static u32 mpt_GetIocState(MPT_ADAPTER *ioc, int cooked);
139 static int GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason);
140 static int GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
141 static int SendIocInit(MPT_ADAPTER *ioc, int sleepFlag);
142 static int SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
143 static int mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag);
144 static int mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag);
145 static int mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
146 static int KickStart(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
147 static int SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag);
148 static int PrimeIocFifos(MPT_ADAPTER *ioc);
149 static int WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
150 static int WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
151 static int WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
152 static int GetLanConfigPages(MPT_ADAPTER *ioc);
153 static int GetFcPortPage0(MPT_ADAPTER *ioc, int portnum);
154 static int GetIoUnitPage2(MPT_ADAPTER *ioc);
155 static int mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
156 static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
157 static void mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
158 static void mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
159 static void mpt_timer_expired(unsigned long data);
160 static int SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch);
161 static int SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
163 #ifdef CONFIG_PROC_FS
164 static int procmpt_summary_read(char *buf, char **start, off_t offset,
165 int request, int *eof, void *data);
166 static int procmpt_version_read(char *buf, char **start, off_t offset,
167 int request, int *eof, void *data);
168 static int procmpt_iocinfo_read(char *buf, char **start, off_t offset,
169 int request, int *eof, void *data);
171 static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
173 //int mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
174 static int ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers);
175 static void mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
176 static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
177 static void mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info);
179 /* module entry point */
180 static int __init fusion_init (void);
181 static void __exit fusion_exit (void);
183 #define CHIPREG_READ32(addr) readl_relaxed(addr)
184 #define CHIPREG_READ32_dmasync(addr) readl(addr)
185 #define CHIPREG_WRITE32(addr,val) writel(val, addr)
186 #define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
187 #define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
190 pci_disable_io_access(struct pci_dev *pdev)
194 pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
196 pci_write_config_word(pdev, PCI_COMMAND, command_reg);
200 pci_enable_io_access(struct pci_dev *pdev)
204 pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
206 pci_write_config_word(pdev, PCI_COMMAND, command_reg);
209 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
211 * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
212 * @irq: irq number (not used)
213 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
214 * @r: pt_regs pointer (not used)
216 * This routine is registered via the request_irq() kernel API call,
217 * and handles all interrupts generated from a specific MPT adapter
218 * (also referred to as a IO Controller or IOC).
219 * This routine must clear the interrupt from the adapter and does
220 * so by reading the reply FIFO. Multiple replies may be processed
221 * per single call to this routine; up to MPT_MAX_REPLIES_PER_ISR
222 * which is currently set to 32 in mptbase.h.
224 * This routine handles register-level access of the adapter but
225 * dispatches (calls) a protocol-specific callback routine to handle
226 * the protocol-specific details of the MPT request completion.
229 mpt_interrupt(int irq, void *bus_id, struct pt_regs *r)
240 ioc = (MPT_ADAPTER *)bus_id;
243 * Drain the reply FIFO!
245 * NOTES: I've seen up to 10 replies processed in this loop, so far...
246 * Update: I've seen up to 9182 replies processed in this loop! ??
247 * Update: Limit ourselves to processing max of N replies
252 if ((pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo)) == 0xFFFFFFFF)
259 * Check for non-TURBO reply!
261 if (pa & MPI_ADDRESS_REPLY_A_BIT) {
265 /* non-TURBO reply! Hmmm, something may be up...
266 * Newest turbo reply mechanism; get address
267 * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
270 /* Map DMA address of reply header to cpu address.
271 * pa is 32 bits - but the dma address may be 32 or 64 bits
272 * get offset based only only the low addresses
274 reply_dma_low = (pa = (pa << 1));
275 mr = (MPT_FRAME_HDR *)((u8 *)ioc->reply_frames +
276 (reply_dma_low - ioc->reply_frames_low_dma));
278 req_idx = le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx);
279 cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
280 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
282 dmfprintk((MYIOC_s_INFO_FMT "Got non-TURBO reply=%p req_idx=%x\n",
283 ioc->name, mr, req_idx));
284 DBG_DUMP_REPLY_FRAME(mr)
286 /* Check/log IOC log info
288 ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
289 if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
290 u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
291 if (ioc->bus_type == FC)
292 mpt_fc_log_info(ioc, log_info);
293 else if (ioc->bus_type == SCSI)
294 mpt_sp_log_info(ioc, log_info);
296 if (ioc_stat & MPI_IOCSTATUS_MASK) {
297 if (ioc->bus_type == SCSI)
298 mpt_sp_ioc_info(ioc, (u32)ioc_stat, mf);
302 * Process turbo (context) reply...
304 dmfprintk((MYIOC_s_INFO_FMT "Got TURBO reply req_idx=%08x\n", ioc->name, pa));
305 type = (pa >> MPI_CONTEXT_REPLY_TYPE_SHIFT);
306 if (type == MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET) {
307 cb_idx = mpt_stm_index;
309 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
310 } else if (type == MPI_CONTEXT_REPLY_TYPE_LAN) {
311 cb_idx = mpt_lan_index;
312 /* Blind set of mf to NULL here was fatal
313 * after lan_reply says "freeme"
314 * Fix sort of combined with an optimization here;
315 * added explicit check for case where lan_reply
316 * was just returning 1 and doing nothing else.
317 * For this case skip the callback, but set up
318 * proper mf value first here:-)
320 if ((pa & 0x58000000) == 0x58000000) {
321 req_idx = pa & 0x0000FFFF;
322 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
325 * IMPORTANT! Invalidate the callback!
331 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
333 req_idx = pa & 0x0000FFFF;
334 cb_idx = (pa & 0x00FF0000) >> 16;
335 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
338 pa = 0; /* No reply flush! */
342 if (ioc->bus_type == SCSI) {
343 /* Verify mf, mr are reasonable.
345 if ((mf) && ((mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))
346 || (mf < ioc->req_frames)) ) {
347 printk(MYIOC_s_WARN_FMT
348 "mpt_interrupt: Invalid mf (%p) req_idx (%d)!\n", ioc->name, (void *)mf, req_idx);
353 if ((pa) && (mr) && ((mr >= MPT_INDEX_2_RFPTR(ioc, ioc->req_depth))
354 || (mr < ioc->reply_frames)) ) {
355 printk(MYIOC_s_WARN_FMT
356 "mpt_interrupt: Invalid rf (%p)!\n", ioc->name, (void *)mr);
361 if (cb_idx > (MPT_MAX_PROTOCOL_DRIVERS-1)) {
362 printk(MYIOC_s_WARN_FMT
363 "mpt_interrupt: Invalid cb_idx (%d)!\n", ioc->name, cb_idx);
371 /* Check for (valid) IO callback! */
373 /* Do the callback! */
374 freeme = (*(MptCallbacks[cb_idx]))(ioc, mf, mr);
378 /* Flush (non-TURBO) reply with a WRITE! */
379 CHIPREG_WRITE32(&ioc->chip->ReplyFifo, pa);
383 /* Put Request back on FreeQ! */
384 mpt_free_msg_frame(ioc, mf);
388 } /* drain reply FIFO */
393 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
395 * mpt_base_reply - MPT base driver's callback routine; all base driver
396 * "internal" request/reply processing is routed here.
397 * Currently used for EventNotification and EventAck handling.
398 * @ioc: Pointer to MPT_ADAPTER structure
399 * @mf: Pointer to original MPT request frame
400 * @reply: Pointer to MPT reply frame (NULL if TurboReply)
402 * Returns 1 indicating original alloc'd request frame ptr
403 * should be freed, or 0 if it shouldn't.
406 mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
411 dprintk((MYIOC_s_INFO_FMT "mpt_base_reply() called\n", ioc->name));
414 (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
415 printk(MYIOC_s_ERR_FMT "NULL or BAD request frame ptr! (=%p)\n",
416 ioc->name, (void *)mf);
421 dprintk((MYIOC_s_ERR_FMT "Unexpected NULL Event (turbo?) reply!\n",
426 if (!(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) {
427 dmfprintk((KERN_INFO MYNAM ": Original request frame (@%p) header\n", mf));
428 DBG_DUMP_REQUEST_FRAME_HDR(mf)
431 func = reply->u.hdr.Function;
432 dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, Function=%02Xh\n",
435 if (func == MPI_FUNCTION_EVENT_NOTIFICATION) {
436 EventNotificationReply_t *pEvReply = (EventNotificationReply_t *) reply;
440 results = ProcessEventNotification(ioc, pEvReply, &evHandlers);
441 if (results != evHandlers) {
442 /* CHECKME! Any special handling needed here? */
443 devtprintk((MYIOC_s_WARN_FMT "Called %d event handlers, sum results = %d\n",
444 ioc->name, evHandlers, results));
448 * Hmmm... It seems that EventNotificationReply is an exception
449 * to the rule of one reply per request.
451 if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)
454 #ifdef CONFIG_PROC_FS
455 // LogEvent(ioc, pEvReply);
458 } else if (func == MPI_FUNCTION_EVENT_ACK) {
459 dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, EventAck reply received\n",
461 } else if (func == MPI_FUNCTION_CONFIG ||
462 func == MPI_FUNCTION_TOOLBOX) {
466 dcprintk((MYIOC_s_INFO_FMT "config_complete (mf=%p,mr=%p)\n",
467 ioc->name, mf, reply));
469 pCfg = * ((CONFIGPARMS **)((u8 *) mf + ioc->req_sz - sizeof(void *)));
472 /* disable timer and remove from linked list */
473 del_timer(&pCfg->timer);
475 spin_lock_irqsave(&ioc->FreeQlock, flags);
476 list_del(&pCfg->linkage);
477 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
480 * If IOC Status is SUCCESS, save the header
481 * and set the status code to GOOD.
483 pCfg->status = MPT_CONFIG_ERROR;
485 ConfigReply_t *pReply = (ConfigReply_t *)reply;
488 status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
489 dcprintk((KERN_NOTICE " IOCStatus=%04xh, IOCLogInfo=%08xh\n",
490 status, le32_to_cpu(pReply->IOCLogInfo)));
492 pCfg->status = status;
493 if (status == MPI_IOCSTATUS_SUCCESS) {
494 pCfg->hdr->PageVersion = pReply->Header.PageVersion;
495 pCfg->hdr->PageLength = pReply->Header.PageLength;
496 pCfg->hdr->PageNumber = pReply->Header.PageNumber;
497 pCfg->hdr->PageType = pReply->Header.PageType;
502 * Wake up the original calling thread
508 printk(MYIOC_s_ERR_FMT "Unexpected msg function (=%02Xh) reply received!\n",
513 * Conditionally tell caller to free the original
514 * EventNotification/EventAck/unexpected request frame!
519 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
521 * mpt_register - Register protocol-specific main callback handler.
522 * @cbfunc: callback function pointer
523 * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
525 * This routine is called by a protocol-specific driver (SCSI host,
526 * LAN, SCSI target) to register it's reply callback routine. Each
527 * protocol-specific driver must do this before it will be able to
528 * use any IOC resources, such as obtaining request frames.
530 * NOTES: The SCSI protocol driver currently calls this routine thrice
531 * in order to register separate callbacks; one for "normal" SCSI IO;
532 * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
534 * Returns a positive integer valued "handle" in the
535 * range (and S.O.D. order) {N,...,7,6,5,...,1} if successful.
536 * Any non-positive return value (including zero!) should be considered
537 * an error by the caller.
540 mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
547 * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
548 * (slot/handle 0 is reserved!)
550 for (i = MPT_MAX_PROTOCOL_DRIVERS-1; i; i--) {
551 if (MptCallbacks[i] == NULL) {
552 MptCallbacks[i] = cbfunc;
553 MptDriverClass[i] = dclass;
554 MptEvHandlers[i] = NULL;
563 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
565 * mpt_deregister - Deregister a protocol drivers resources.
566 * @cb_idx: previously registered callback handle
568 * Each protocol-specific driver should call this routine when it's
569 * module is unloaded.
572 mpt_deregister(int cb_idx)
574 if ((cb_idx >= 0) && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
575 MptCallbacks[cb_idx] = NULL;
576 MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
577 MptEvHandlers[cb_idx] = NULL;
583 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
585 * mpt_event_register - Register protocol-specific event callback
587 * @cb_idx: previously registered (via mpt_register) callback handle
588 * @ev_cbfunc: callback function
590 * This routine can be called by one or more protocol-specific drivers
591 * if/when they choose to be notified of MPT events.
593 * Returns 0 for success.
596 mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc)
598 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
601 MptEvHandlers[cb_idx] = ev_cbfunc;
605 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
607 * mpt_event_deregister - Deregister protocol-specific event callback
609 * @cb_idx: previously registered callback handle
611 * Each protocol-specific driver should call this routine
612 * when it does not (or can no longer) handle events,
613 * or when it's module is unloaded.
616 mpt_event_deregister(int cb_idx)
618 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
621 MptEvHandlers[cb_idx] = NULL;
624 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
626 * mpt_reset_register - Register protocol-specific IOC reset handler.
627 * @cb_idx: previously registered (via mpt_register) callback handle
628 * @reset_func: reset function
630 * This routine can be called by one or more protocol-specific drivers
631 * if/when they choose to be notified of IOC resets.
633 * Returns 0 for success.
636 mpt_reset_register(int cb_idx, MPT_RESETHANDLER reset_func)
638 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
641 MptResetHandlers[cb_idx] = reset_func;
645 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
647 * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
648 * @cb_idx: previously registered callback handle
650 * Each protocol-specific driver should call this routine
651 * when it does not (or can no longer) handle IOC reset handling,
652 * or when it's module is unloaded.
655 mpt_reset_deregister(int cb_idx)
657 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
660 MptResetHandlers[cb_idx] = NULL;
663 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
665 * mpt_device_driver_register - Register device driver hooks
668 mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx)
672 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS) {
676 MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
678 /* call per pci device probe entry point */
679 list_for_each_entry(ioc, &ioc_list, list) {
680 if(dd_cbfunc->probe) {
681 dd_cbfunc->probe(ioc->pcidev,
682 ioc->pcidev->driver->id_table);
689 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
691 * mpt_device_driver_deregister - DeRegister device driver hooks
694 mpt_device_driver_deregister(int cb_idx)
696 struct mpt_pci_driver *dd_cbfunc;
699 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
702 dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
704 list_for_each_entry(ioc, &ioc_list, list) {
705 if (dd_cbfunc->remove)
706 dd_cbfunc->remove(ioc->pcidev);
709 MptDeviceDriverHandlers[cb_idx] = NULL;
713 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
715 * mpt_get_msg_frame - Obtain a MPT request frame from the pool (of 1024)
716 * allocated per MPT adapter.
717 * @handle: Handle of registered MPT protocol driver
718 * @ioc: Pointer to MPT adapter structure
720 * Returns pointer to a MPT request frame or %NULL if none are available
721 * or IOC is not active.
724 mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
728 u16 req_idx; /* Request index */
730 /* validate handle and ioc identifier */
734 printk(KERN_WARNING "IOC Not Active! mpt_get_msg_frame returning NULL!\n");
737 /* If interrupts are not attached, do not return a request frame */
741 spin_lock_irqsave(&ioc->FreeQlock, flags);
742 if (!list_empty(&ioc->FreeQ)) {
745 mf = list_entry(ioc->FreeQ.next, MPT_FRAME_HDR,
746 u.frame.linkage.list);
747 list_del(&mf->u.frame.linkage.list);
748 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
749 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
751 req_idx = req_offset / ioc->req_sz;
752 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
753 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
754 ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame; /* Default, will be changed if necessary in SG generation */
761 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
765 printk(KERN_WARNING "IOC Active. No free Msg Frames! Count 0x%x Max 0x%x\n", ioc->mfcnt, ioc->req_depth);
767 if (mfcounter == PRINT_MF_COUNT)
768 printk(KERN_INFO "MF Count 0x%x Max 0x%x \n", ioc->mfcnt, ioc->req_depth);
771 dmfprintk((KERN_INFO MYNAM ": %s: mpt_get_msg_frame(%d,%d), got mf=%p\n",
772 ioc->name, handle, ioc->id, mf));
776 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
778 * mpt_put_msg_frame - Send a protocol specific MPT request frame
780 * @handle: Handle of registered MPT protocol driver
781 * @ioc: Pointer to MPT adapter structure
782 * @mf: Pointer to MPT request frame
784 * This routine posts a MPT request frame to the request post FIFO of a
785 * specific MPT adapter.
788 mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
792 u16 req_idx; /* Request index */
794 /* ensure values are reset properly! */
795 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
796 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
798 req_idx = req_offset / ioc->req_sz;
799 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
800 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
802 #ifdef MPT_DEBUG_MSG_FRAME
804 u32 *m = mf->u.frame.hwhdr.__hdr;
807 printk(KERN_INFO MYNAM ": %s: About to Put msg frame @ %p:\n" KERN_INFO " ",
809 n = ioc->req_sz/4 - 1;
812 for (ii=0; ii<=n; ii++) {
813 if (ii && ((ii%8)==0))
814 printk("\n" KERN_INFO " ");
815 printk(" %08x", le32_to_cpu(m[ii]));
821 mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
822 dsgprintk((MYIOC_s_INFO_FMT "mf_dma_addr=%x req_idx=%d RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx, ioc->RequestNB[req_idx]));
823 CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
826 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
828 * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
829 * @handle: Handle of registered MPT protocol driver
830 * @ioc: Pointer to MPT adapter structure
831 * @mf: Pointer to MPT request frame
833 * This routine places a MPT request frame back on the MPT adapter's
837 mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
841 /* Put Request back on FreeQ! */
842 spin_lock_irqsave(&ioc->FreeQlock, flags);
843 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
847 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
850 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
852 * mpt_add_sge - Place a simple SGE at address pAddr.
853 * @pAddr: virtual address for SGE
854 * @flagslength: SGE flags and data transfer length
855 * @dma_addr: Physical address
857 * This routine places a MPT request frame back on the MPT adapter's
861 mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
863 if (sizeof(dma_addr_t) == sizeof(u64)) {
864 SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
865 u32 tmp = dma_addr & 0xFFFFFFFF;
867 pSge->FlagsLength = cpu_to_le32(flagslength);
868 pSge->Address.Low = cpu_to_le32(tmp);
869 tmp = (u32) ((u64)dma_addr >> 32);
870 pSge->Address.High = cpu_to_le32(tmp);
873 SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
874 pSge->FlagsLength = cpu_to_le32(flagslength);
875 pSge->Address = cpu_to_le32(dma_addr);
879 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
881 * mpt_send_handshake_request - Send MPT request via doorbell
883 * @handle: Handle of registered MPT protocol driver
884 * @ioc: Pointer to MPT adapter structure
885 * @reqBytes: Size of the request in bytes
886 * @req: Pointer to MPT request frame
887 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
889 * This routine is used exclusively to send MptScsiTaskMgmt
890 * requests since they are required to be sent via doorbell handshake.
892 * NOTE: It is the callers responsibility to byte-swap fields in the
893 * request which are greater than 1 byte in size.
895 * Returns 0 for success, non-zero for failure.
898 mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
904 /* State is known to be good upon entering
905 * this function so issue the bus reset
910 * Emulate what mpt_put_msg_frame() does /wrt to sanity
911 * setting cb_idx/req_idx. But ONLY if this request
912 * is in proper (pre-alloc'd) request buffer range...
914 ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
915 if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
916 MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
917 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
918 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle;
921 /* Make sure there are no doorbells */
922 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
924 CHIPREG_WRITE32(&ioc->chip->Doorbell,
925 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
926 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
928 /* Wait for IOC doorbell int */
929 if ((ii = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0) {
933 /* Read doorbell and check for active bit */
934 if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
937 dhsprintk((KERN_INFO MYNAM ": %s: mpt_send_handshake_request start, WaitCnt=%d\n",
940 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
942 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
946 /* Send request via doorbell handshake */
947 req_as_bytes = (u8 *) req;
948 for (ii = 0; ii < reqBytes/4; ii++) {
951 word = ((req_as_bytes[(ii*4) + 0] << 0) |
952 (req_as_bytes[(ii*4) + 1] << 8) |
953 (req_as_bytes[(ii*4) + 2] << 16) |
954 (req_as_bytes[(ii*4) + 3] << 24));
955 CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
956 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
962 if (r >= 0 && WaitForDoorbellInt(ioc, 10, sleepFlag) >= 0)
967 /* Make sure there are no doorbells */
968 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
973 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
975 * mpt_verify_adapter - Given a unique IOC identifier, set pointer to
976 * the associated MPT adapter structure.
977 * @iocid: IOC unique identifier (integer)
978 * @iocpp: Pointer to pointer to IOC adapter
980 * Returns iocid and sets iocpp.
983 mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
987 list_for_each_entry(ioc,&ioc_list,list) {
988 if (ioc->id == iocid) {
998 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1000 * mpt_attach - Install a PCI intelligent MPT adapter.
1001 * @pdev: Pointer to pci_dev structure
1003 * This routine performs all the steps necessary to bring the IOC of
1004 * a MPT adapter to a OPERATIONAL state. This includes registering
1005 * memory regions, registering the interrupt, and allocating request
1006 * and reply memory pools.
1008 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1011 * Returns 0 for success, non-zero for failure.
1013 * TODO: Add support for polled controllers
1016 mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1020 unsigned long mem_phys;
1028 static int mpt_ids = 0;
1029 #ifdef CONFIG_PROC_FS
1030 struct proc_dir_entry *dent, *ent;
1033 if (pci_enable_device(pdev))
1036 dinitprintk((KERN_WARNING MYNAM ": mpt_adapter_install\n"));
1038 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
1039 dprintk((KERN_INFO MYNAM
1040 ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n"));
1041 } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
1042 printk(KERN_WARNING MYNAM ": 32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
1046 if (!pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))
1047 dprintk((KERN_INFO MYNAM
1048 ": Using 64 bit consistent mask\n"));
1050 dprintk((KERN_INFO MYNAM
1051 ": Not using 64 bit consistent mask\n"));
1053 ioc = kmalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
1055 printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
1058 memset(ioc, 0, sizeof(MPT_ADAPTER));
1059 ioc->alloc_total = sizeof(MPT_ADAPTER);
1060 ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
1061 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
1064 ioc->diagPending = 0;
1065 spin_lock_init(&ioc->diagLock);
1067 /* Initialize the event logging.
1069 ioc->eventTypes = 0; /* None */
1070 ioc->eventContext = 0;
1071 ioc->eventLogSize = 0;
1078 ioc->cached_fw = NULL;
1080 /* Initilize SCSI Config Data structure
1082 memset(&ioc->spi_data, 0, sizeof(ScsiCfgData));
1084 /* Initialize the running configQ head.
1086 INIT_LIST_HEAD(&ioc->configQ);
1088 /* Find lookup slot. */
1089 INIT_LIST_HEAD(&ioc->list);
1090 ioc->id = mpt_ids++;
1092 mem_phys = msize = 0;
1094 for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) {
1095 if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
1096 /* Get I/O space! */
1097 port = pci_resource_start(pdev, ii);
1098 psize = pci_resource_len(pdev,ii);
1101 mem_phys = pci_resource_start(pdev, ii);
1102 msize = pci_resource_len(pdev,ii);
1106 ioc->mem_size = msize;
1108 if (ii == DEVICE_COUNT_RESOURCE) {
1109 printk(KERN_ERR MYNAM ": ERROR - MPT adapter has no memory regions defined!\n");
1114 dinitprintk((KERN_INFO MYNAM ": MPT adapter @ %lx, msize=%dd bytes\n", mem_phys, msize));
1115 dinitprintk((KERN_INFO MYNAM ": (port i/o @ %lx, psize=%dd bytes)\n", port, psize));
1118 /* Get logical ptr for PciMem0 space */
1119 /*mem = ioremap(mem_phys, msize);*/
1120 mem = ioremap(mem_phys, 0x100);
1122 printk(KERN_ERR MYNAM ": ERROR - Unable to map adapter memory!\n");
1127 dinitprintk((KERN_INFO MYNAM ": mem = %p, mem_phys = %lx\n", mem, mem_phys));
1129 dinitprintk((KERN_INFO MYNAM ": facts @ %p, pfacts[0] @ %p\n",
1130 &ioc->facts, &ioc->pfacts[0]));
1132 ioc->mem_phys = mem_phys;
1133 ioc->chip = (SYSIF_REGS __iomem *)mem;
1135 /* Save Port IO values in case we need to do downloadboot */
1137 u8 *pmem = (u8*)port;
1138 ioc->pio_mem_phys = port;
1139 ioc->pio_chip = (SYSIF_REGS __iomem *)pmem;
1142 if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC909) {
1143 ioc->prod_name = "LSIFC909";
1146 if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929) {
1147 ioc->prod_name = "LSIFC929";
1150 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919) {
1151 ioc->prod_name = "LSIFC919";
1154 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929X) {
1155 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1157 if (revision < XL_929) {
1158 ioc->prod_name = "LSIFC929X";
1159 /* 929X Chip Fix. Set Split transactions level
1160 * for PCIX. Set MOST bits to zero.
1162 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1164 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1166 ioc->prod_name = "LSIFC929XL";
1167 /* 929XL Chip Fix. Set MMRBC to 0x08.
1169 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1171 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1174 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919X) {
1175 ioc->prod_name = "LSIFC919X";
1177 /* 919X Chip Fix. Set Split transactions level
1178 * for PCIX. Set MOST bits to zero.
1180 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1182 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1184 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC939X) {
1185 ioc->prod_name = "LSIFC939X";
1187 ioc->errata_flag_1064 = 1;
1189 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC949X) {
1190 ioc->prod_name = "LSIFC949X";
1192 ioc->errata_flag_1064 = 1;
1194 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_53C1030) {
1195 ioc->prod_name = "LSI53C1030";
1196 ioc->bus_type = SCSI;
1197 /* 1030 Chip Fix. Disable Split transactions
1198 * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
1200 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1201 if (revision < C0_1030) {
1202 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1204 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1207 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_1030_53C1035) {
1208 ioc->prod_name = "LSI53C1035";
1209 ioc->bus_type = SCSI;
1212 if (ioc->errata_flag_1064)
1213 pci_disable_io_access(pdev);
1215 sprintf(ioc->name, "ioc%d", ioc->id);
1217 spin_lock_init(&ioc->FreeQlock);
1220 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1222 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1224 /* Set lookup ptr. */
1225 list_add_tail(&ioc->list, &ioc_list);
1229 r = request_irq(pdev->irq, mpt_interrupt, SA_SHIRQ, ioc->name, ioc);
1233 printk(MYIOC_s_ERR_FMT "Unable to allocate interrupt %d!\n",
1234 ioc->name, pdev->irq);
1236 printk(MYIOC_s_ERR_FMT "Unable to allocate interrupt %s!\n",
1237 ioc->name, __irq_itoa(pdev->irq));
1239 list_del(&ioc->list);
1245 ioc->pci_irq = pdev->irq;
1247 pci_set_master(pdev); /* ?? */
1248 pci_set_drvdata(pdev, ioc);
1251 dprintk((KERN_INFO MYNAM ": %s installed at interrupt %d\n", ioc->name, pdev->irq));
1253 dprintk((KERN_INFO MYNAM ": %s installed at interrupt %s\n", ioc->name, __irq_itoa(pdev->irq)));
1257 /* Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
1259 mpt_detect_bound_ports(ioc, pdev);
1261 if ((r = mpt_do_ioc_recovery(ioc,
1262 MPT_HOSTEVENT_IOC_BRINGUP, CAN_SLEEP)) != 0) {
1263 printk(KERN_WARNING MYNAM
1264 ": WARNING - %s did not initialize properly! (%d)\n",
1267 list_del(&ioc->list);
1268 free_irq(ioc->pci_irq, ioc);
1271 pci_set_drvdata(pdev, NULL);
1275 /* call per device driver probe entry point */
1276 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1277 if(MptDeviceDriverHandlers[ii] &&
1278 MptDeviceDriverHandlers[ii]->probe) {
1279 MptDeviceDriverHandlers[ii]->probe(pdev,id);
1283 #ifdef CONFIG_PROC_FS
1285 * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
1287 dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
1289 ent = create_proc_entry("info", S_IFREG|S_IRUGO, dent);
1291 ent->read_proc = procmpt_iocinfo_read;
1294 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, dent);
1296 ent->read_proc = procmpt_summary_read;
1305 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1307 * mpt_detach - Remove a PCI intelligent MPT adapter.
1308 * @pdev: Pointer to pci_dev structure
1313 mpt_detach(struct pci_dev *pdev)
1315 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1319 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
1320 remove_proc_entry(pname, NULL);
1321 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/info", ioc->name);
1322 remove_proc_entry(pname, NULL);
1323 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
1324 remove_proc_entry(pname, NULL);
1326 /* call per device driver remove entry point */
1327 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1328 if(MptDeviceDriverHandlers[ii] &&
1329 MptDeviceDriverHandlers[ii]->remove) {
1330 MptDeviceDriverHandlers[ii]->remove(pdev);
1334 /* Disable interrupts! */
1335 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1338 synchronize_irq(pdev->irq);
1340 /* Clear any lingering interrupt */
1341 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1343 CHIPREG_READ32(&ioc->chip->IntStatus);
1345 mpt_adapter_dispose(ioc);
1347 pci_set_drvdata(pdev, NULL);
1350 /**************************************************************************
1354 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1356 * mpt_suspend - Fusion MPT base driver suspend routine.
1361 mpt_suspend(struct pci_dev *pdev, pm_message_t state)
1364 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1366 device_state=pci_choose_state(pdev, state);
1368 printk(MYIOC_s_INFO_FMT
1369 "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n",
1370 ioc->name, pdev, pci_name(pdev), device_state);
1372 pci_save_state(pdev);
1374 /* put ioc into READY_STATE */
1375 if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
1376 printk(MYIOC_s_ERR_FMT
1377 "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
1380 /* disable interrupts */
1381 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1384 /* Clear any lingering interrupt */
1385 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1387 pci_disable_device(pdev);
1388 pci_set_power_state(pdev, device_state);
1393 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1395 * mpt_resume - Fusion MPT base driver resume routine.
1400 mpt_resume(struct pci_dev *pdev)
1402 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1403 u32 device_state = pdev->current_state;
1407 printk(MYIOC_s_INFO_FMT
1408 "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n",
1409 ioc->name, pdev, pci_name(pdev), device_state);
1411 pci_set_power_state(pdev, 0);
1412 pci_restore_state(pdev);
1413 pci_enable_device(pdev);
1415 /* enable interrupts */
1416 CHIPREG_WRITE32(&ioc->chip->IntMask, ~(MPI_HIM_RIM));
1419 /* F/W not running */
1420 if(!CHIPREG_READ32(&ioc->chip->Doorbell)) {
1421 /* enable domain validation flags */
1422 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
1423 ioc->spi_data.dvStatus[ii] |= MPT_SCSICFG_NEED_DV;
1427 printk(MYIOC_s_INFO_FMT
1428 "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
1430 (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
1431 CHIPREG_READ32(&ioc->chip->Doorbell));
1433 /* bring ioc to operational state */
1434 if ((recovery_state = mpt_do_ioc_recovery(ioc,
1435 MPT_HOSTEVENT_IOC_RECOVER, CAN_SLEEP)) != 0) {
1436 printk(MYIOC_s_INFO_FMT
1437 "pci-resume: Cannot recover, error:[%x]\n",
1438 ioc->name, recovery_state);
1440 printk(MYIOC_s_INFO_FMT
1441 "pci-resume: success\n", ioc->name);
1448 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1450 * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
1451 * @ioc: Pointer to MPT adapter structure
1452 * @reason: Event word / reason
1453 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
1455 * This routine performs all the steps necessary to bring the IOC
1456 * to a OPERATIONAL state.
1458 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1463 * -1 if failed to get board READY
1464 * -2 if READY but IOCFacts Failed
1465 * -3 if READY but PrimeIOCFifos Failed
1466 * -4 if READY but IOCInit Failed
1469 mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1471 int hard_reset_done = 0;
1472 int alt_ioc_ready = 0;
1478 int reset_alt_ioc_active = 0;
1480 printk(KERN_INFO MYNAM ": Initiating %s %s\n",
1481 ioc->name, reason==MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
1483 /* Disable reply interrupts (also blocks FreeQ) */
1484 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1488 if (ioc->alt_ioc->active)
1489 reset_alt_ioc_active = 1;
1491 /* Disable alt-IOC's reply interrupts (and FreeQ) for a bit ... */
1492 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, 0xFFFFFFFF);
1493 ioc->alt_ioc->active = 0;
1497 if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
1500 if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
1501 if (hard_reset_done == -4) {
1502 printk(KERN_WARNING MYNAM ": %s Owned by PEER..skipping!\n",
1505 if (reset_alt_ioc_active && ioc->alt_ioc) {
1506 /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
1507 dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
1508 ioc->alt_ioc->name));
1509 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM));
1510 ioc->alt_ioc->active = 1;
1514 printk(KERN_WARNING MYNAM ": %s NOT READY WARNING!\n",
1520 /* hard_reset_done = 0 if a soft reset was performed
1521 * and 1 if a hard reset was performed.
1523 if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
1524 if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
1527 printk(KERN_WARNING MYNAM
1528 ": alt-%s: Not ready WARNING!\n",
1529 ioc->alt_ioc->name);
1532 for (ii=0; ii<5; ii++) {
1533 /* Get IOC facts! Allow 5 retries */
1534 if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
1540 dinitprintk((MYIOC_s_INFO_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc));
1542 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1543 MptDisplayIocCapabilities(ioc);
1546 if (alt_ioc_ready) {
1547 if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
1548 dinitprintk((MYIOC_s_INFO_FMT "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc));
1549 /* Retry - alt IOC was initialized once
1551 rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
1554 dinitprintk((MYIOC_s_INFO_FMT "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
1556 reset_alt_ioc_active = 0;
1557 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1558 MptDisplayIocCapabilities(ioc->alt_ioc);
1562 /* Prime reply & request queues!
1563 * (mucho alloc's) Must be done prior to
1564 * init as upper addresses are needed for init.
1565 * If fails, continue with alt-ioc processing
1567 if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
1570 /* May need to check/upload firmware & data here!
1571 * If fails, continue with alt-ioc processing
1573 if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
1576 if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
1577 printk(KERN_WARNING MYNAM ": alt-%s: (%d) FIFO mgmt alloc WARNING!\n",
1578 ioc->alt_ioc->name, rc);
1580 reset_alt_ioc_active = 0;
1583 if (alt_ioc_ready) {
1584 if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
1586 reset_alt_ioc_active = 0;
1587 printk(KERN_WARNING MYNAM
1588 ": alt-%s: (%d) init failure WARNING!\n",
1589 ioc->alt_ioc->name, rc);
1593 if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
1594 if (ioc->upload_fw) {
1595 ddlprintk((MYIOC_s_INFO_FMT
1596 "firmware upload required!\n", ioc->name));
1598 /* Controller is not operational, cannot do upload
1601 rc = mpt_do_upload(ioc, sleepFlag);
1603 printk(KERN_WARNING MYNAM ": firmware upload failure!\n");
1609 /* Enable! (reply interrupt) */
1610 CHIPREG_WRITE32(&ioc->chip->IntMask, ~(MPI_HIM_RIM));
1614 if (reset_alt_ioc_active && ioc->alt_ioc) {
1615 /* (re)Enable alt-IOC! (reply interrupt) */
1616 dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
1617 ioc->alt_ioc->name));
1618 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM));
1619 ioc->alt_ioc->active = 1;
1622 /* Enable MPT base driver management of EventNotification
1623 * and EventAck handling.
1625 if ((ret == 0) && (!ioc->facts.EventState))
1626 (void) SendEventNotification(ioc, 1); /* 1=Enable EventNotification */
1628 if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
1629 (void) SendEventNotification(ioc->alt_ioc, 1); /* 1=Enable EventNotification */
1631 /* Add additional "reason" check before call to GetLanConfigPages
1632 * (combined with GetIoUnitPage2 call). This prevents a somewhat
1633 * recursive scenario; GetLanConfigPages times out, timer expired
1634 * routine calls HardResetHandler, which calls into here again,
1635 * and we try GetLanConfigPages again...
1637 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
1638 if (ioc->bus_type == FC) {
1640 * Pre-fetch FC port WWN and stuff...
1641 * (FCPortPage0_t stuff)
1643 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1644 (void) GetFcPortPage0(ioc, ii);
1647 if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
1648 (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
1650 * Pre-fetch the ports LAN MAC address!
1651 * (LANPage1_t stuff)
1653 (void) GetLanConfigPages(ioc);
1656 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
1657 dprintk((MYIOC_s_INFO_FMT "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1658 ioc->name, a[5], a[4], a[3], a[2], a[1], a[0] ));
1663 /* Get NVRAM and adapter maximums from SPP 0 and 2
1665 mpt_GetScsiPortSettings(ioc, 0);
1667 /* Get version and length of SDP 1
1669 mpt_readScsiDevicePageHeaders(ioc, 0);
1673 if (ioc->facts.MsgVersion >= 0x0102)
1674 mpt_findImVolumes(ioc);
1676 /* Check, and possibly reset, the coalescing value
1678 mpt_read_ioc_pg_1(ioc);
1680 mpt_read_ioc_pg_4(ioc);
1683 GetIoUnitPage2(ioc);
1687 * Call each currently registered protocol IOC reset handler
1688 * with post-reset indication.
1689 * NOTE: If we're doing _IOC_BRINGUP, there can be no
1690 * MptResetHandlers[] registered yet.
1692 if (hard_reset_done) {
1694 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
1695 if ((ret == 0) && MptResetHandlers[ii]) {
1696 dprintk((MYIOC_s_INFO_FMT "Calling IOC post_reset handler #%d\n",
1698 rc += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_POST_RESET);
1702 if (alt_ioc_ready && MptResetHandlers[ii]) {
1703 dprintk((MYIOC_s_INFO_FMT "Calling alt-%s post_reset handler #%d\n",
1704 ioc->name, ioc->alt_ioc->name, ii));
1705 rc += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_POST_RESET);
1709 /* FIXME? Examine results here? */
1715 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1717 * mpt_detect_bound_ports - Search for PCI bus/dev_function
1718 * which matches PCI bus/dev_function (+/-1) for newly discovered 929,
1719 * 929X, 1030 or 1035.
1720 * @ioc: Pointer to MPT adapter structure
1721 * @pdev: Pointer to (struct pci_dev) structure
1723 * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
1724 * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
1727 mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
1729 struct pci_dev *peer=NULL;
1730 unsigned int slot = PCI_SLOT(pdev->devfn);
1731 unsigned int func = PCI_FUNC(pdev->devfn);
1732 MPT_ADAPTER *ioc_srch;
1734 dprintk((MYIOC_s_INFO_FMT "PCI device %s devfn=%x/%x,"
1735 " searching for devfn match on %x or %x\n",
1736 ioc->name, pci_name(pdev), pdev->devfn,
1739 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
1741 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func+1));
1746 list_for_each_entry(ioc_srch, &ioc_list, list) {
1747 struct pci_dev *_pcidev = ioc_srch->pcidev;
1748 if (_pcidev == peer) {
1749 /* Paranoia checks */
1750 if (ioc->alt_ioc != NULL) {
1751 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
1752 ioc->name, ioc->alt_ioc->name);
1754 } else if (ioc_srch->alt_ioc != NULL) {
1755 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
1756 ioc_srch->name, ioc_srch->alt_ioc->name);
1759 dprintk((KERN_INFO MYNAM ": FOUND! binding %s <==> %s\n",
1760 ioc->name, ioc_srch->name));
1761 ioc_srch->alt_ioc = ioc;
1762 ioc->alt_ioc = ioc_srch;
1768 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1770 * mpt_adapter_disable - Disable misbehaving MPT adapter.
1771 * @this: Pointer to MPT adapter structure
1774 mpt_adapter_disable(MPT_ADAPTER *ioc)
1779 if (ioc->cached_fw != NULL) {
1780 ddlprintk((KERN_INFO MYNAM ": mpt_adapter_disable: Pushing FW onto adapter\n"));
1781 if ((ret = mpt_downloadboot(ioc, NO_SLEEP)) < 0) {
1782 printk(KERN_WARNING MYNAM
1783 ": firmware downloadboot failure (%d)!\n", ret);
1787 /* Disable adapter interrupts! */
1788 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1790 /* Clear any lingering interrupt */
1791 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1793 if (ioc->alloc != NULL) {
1795 dexitprintk((KERN_INFO MYNAM ": %s.free @ %p, sz=%d bytes\n",
1796 ioc->name, ioc->alloc, ioc->alloc_sz));
1797 pci_free_consistent(ioc->pcidev, sz,
1798 ioc->alloc, ioc->alloc_dma);
1799 ioc->reply_frames = NULL;
1800 ioc->req_frames = NULL;
1802 ioc->alloc_total -= sz;
1805 if (ioc->sense_buf_pool != NULL) {
1806 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
1807 pci_free_consistent(ioc->pcidev, sz,
1808 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
1809 ioc->sense_buf_pool = NULL;
1810 ioc->alloc_total -= sz;
1813 if (ioc->events != NULL){
1814 sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
1817 ioc->alloc_total -= sz;
1820 if (ioc->cached_fw != NULL) {
1821 sz = ioc->facts.FWImageSize;
1822 pci_free_consistent(ioc->pcidev, sz,
1823 ioc->cached_fw, ioc->cached_fw_dma);
1824 ioc->cached_fw = NULL;
1825 ioc->alloc_total -= sz;
1828 kfree(ioc->spi_data.nvram);
1829 kfree(ioc->spi_data.pIocPg3);
1830 ioc->spi_data.nvram = NULL;
1831 ioc->spi_data.pIocPg3 = NULL;
1833 if (ioc->spi_data.pIocPg4 != NULL) {
1834 sz = ioc->spi_data.IocPg4Sz;
1835 pci_free_consistent(ioc->pcidev, sz,
1836 ioc->spi_data.pIocPg4,
1837 ioc->spi_data.IocPg4_dma);
1838 ioc->spi_data.pIocPg4 = NULL;
1839 ioc->alloc_total -= sz;
1842 if (ioc->ReqToChain != NULL) {
1843 kfree(ioc->ReqToChain);
1844 kfree(ioc->RequestNB);
1845 ioc->ReqToChain = NULL;
1848 kfree(ioc->ChainToChain);
1849 ioc->ChainToChain = NULL;
1852 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1854 * mpt_adapter_dispose - Free all resources associated with a MPT
1856 * @ioc: Pointer to MPT adapter structure
1858 * This routine unregisters h/w resources and frees all alloc'd memory
1859 * associated with a MPT adapter structure.
1862 mpt_adapter_dispose(MPT_ADAPTER *ioc)
1865 int sz_first, sz_last;
1867 sz_first = ioc->alloc_total;
1869 mpt_adapter_disable(ioc);
1871 if (ioc->pci_irq != -1) {
1872 free_irq(ioc->pci_irq, ioc);
1876 if (ioc->memmap != NULL)
1877 iounmap(ioc->memmap);
1879 #if defined(CONFIG_MTRR) && 0
1880 if (ioc->mtrr_reg > 0) {
1881 mtrr_del(ioc->mtrr_reg, 0, 0);
1882 dprintk((KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
1886 /* Zap the adapter lookup ptr! */
1887 list_del(&ioc->list);
1889 sz_last = ioc->alloc_total;
1890 dprintk((KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
1891 ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
1896 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1898 * MptDisplayIocCapabilities - Disply IOC's capacilities.
1899 * @ioc: Pointer to MPT adapter structure
1902 MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
1906 printk(KERN_INFO "%s: ", ioc->name);
1907 if (ioc->prod_name && strlen(ioc->prod_name) > 3)
1908 printk("%s: ", ioc->prod_name+3);
1909 printk("Capabilities={");
1911 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
1912 printk("Initiator");
1916 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
1917 printk("%sTarget", i ? "," : "");
1921 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
1922 printk("%sLAN", i ? "," : "");
1928 * This would probably evoke more questions than it's worth
1930 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
1931 printk("%sLogBusAddr", i ? "," : "");
1939 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1941 * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
1942 * @ioc: Pointer to MPT_ADAPTER structure
1943 * @force: Force hard KickStart of IOC
1944 * @sleepFlag: Specifies whether the process can sleep
1947 * 1 - DIAG reset and READY
1948 * 0 - READY initially OR soft reset and READY
1949 * -1 - Any failure on KickStart
1950 * -2 - Msg Unit Reset Failed
1951 * -3 - IO Unit Reset Failed
1952 * -4 - IOC owned by a PEER
1955 MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
1960 int hard_reset_done = 0;
1965 /* Get current [raw] IOC state */
1966 ioc_state = mpt_GetIocState(ioc, 0);
1967 dhsprintk((KERN_INFO MYNAM "::MakeIocReady, %s [raw] state=%08x\n", ioc->name, ioc_state));
1970 * Check to see if IOC got left/stuck in doorbell handshake
1971 * grip of death. If so, hard reset the IOC.
1973 if (ioc_state & MPI_DOORBELL_ACTIVE) {
1975 printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
1979 /* Is it already READY? */
1980 if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
1984 * Check to see if IOC is in FAULT state.
1986 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
1988 printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
1990 printk(KERN_WARNING " FAULT code = %04xh\n",
1991 ioc_state & MPI_DOORBELL_DATA_MASK);
1995 * Hmmm... Did it get left operational?
1997 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
1998 dinitprintk((MYIOC_s_WARN_FMT "IOC operational unexpected\n",
2002 * If PCI Peer, exit.
2003 * Else, if no fault conditions are present, issue a MessageUnitReset
2004 * Else, fall through to KickStart case
2006 whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
2007 dprintk((KERN_WARNING MYNAM
2008 ": whoinit 0x%x\n statefault %d force %d\n",
2009 whoinit, statefault, force));
2010 if (whoinit == MPI_WHOINIT_PCI_PEER)
2013 if ((statefault == 0 ) && (force == 0)) {
2014 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
2021 hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
2022 if (hard_reset_done < 0)
2026 * Loop here waiting for IOC to come READY.
2029 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
2031 while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
2032 if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
2034 * BIOS or previous driver load left IOC in OP state.
2035 * Reset messaging FIFOs.
2037 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
2038 printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
2041 } else if (ioc_state == MPI_IOC_STATE_RESET) {
2043 * Something is wrong. Try to get IOC back
2046 if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
2047 printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
2054 printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
2055 ioc->name, (int)((ii+5)/HZ));
2059 if (sleepFlag == CAN_SLEEP) {
2060 msleep_interruptible(1);
2062 mdelay (1); /* 1 msec delay */
2067 if (statefault < 3) {
2068 printk(MYIOC_s_INFO_FMT "Recovered from %s\n",
2070 statefault==1 ? "stuck handshake" : "IOC FAULT");
2073 return hard_reset_done;
2076 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2078 * mpt_GetIocState - Get the current state of a MPT adapter.
2079 * @ioc: Pointer to MPT_ADAPTER structure
2080 * @cooked: Request raw or cooked IOC state
2082 * Returns all IOC Doorbell register bits if cooked==0, else just the
2083 * Doorbell bits in MPI_IOC_STATE_MASK.
2086 mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
2091 s = CHIPREG_READ32(&ioc->chip->Doorbell);
2092 // dprintk((MYIOC_s_INFO_FMT "raw state = %08x\n", ioc->name, s));
2093 sc = s & MPI_IOC_STATE_MASK;
2096 ioc->last_state = sc;
2098 return cooked ? sc : s;
2101 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2103 * GetIocFacts - Send IOCFacts request to MPT adapter.
2104 * @ioc: Pointer to MPT_ADAPTER structure
2105 * @sleepFlag: Specifies whether the process can sleep
2106 * @reason: If recovery, only update facts.
2108 * Returns 0 for success, non-zero for failure.
2111 GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2113 IOCFacts_t get_facts;
2114 IOCFactsReply_t *facts;
2122 /* IOC *must* NOT be in RESET state! */
2123 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2124 printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
2130 facts = &ioc->facts;
2132 /* Destination (reply area)... */
2133 reply_sz = sizeof(*facts);
2134 memset(facts, 0, reply_sz);
2136 /* Request area (get_facts on the stack right now!) */
2137 req_sz = sizeof(get_facts);
2138 memset(&get_facts, 0, req_sz);
2140 get_facts.Function = MPI_FUNCTION_IOC_FACTS;
2141 /* Assert: All other get_facts fields are zero! */
2143 dinitprintk((MYIOC_s_INFO_FMT
2144 "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
2145 ioc->name, req_sz, reply_sz));
2147 /* No non-zero fields in the get_facts request are greater than
2148 * 1 byte in size, so we can just fire it off as is.
2150 r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
2151 reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
2156 * Now byte swap (GRRR) the necessary fields before any further
2157 * inspection of reply contents.
2159 * But need to do some sanity checks on MsgLength (byte) field
2160 * to make sure we don't zero IOC's req_sz!
2162 /* Did we get a valid reply? */
2163 if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
2164 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2166 * If not been here, done that, save off first WhoInit value
2168 if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
2169 ioc->FirstWhoInit = facts->WhoInit;
2172 facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
2173 facts->MsgContext = le32_to_cpu(facts->MsgContext);
2174 facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
2175 facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
2176 facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
2177 status = facts->IOCStatus & MPI_IOCSTATUS_MASK;
2178 /* CHECKME! IOCStatus, IOCLogInfo */
2180 facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
2181 facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
2184 * FC f/w version changed between 1.1 and 1.2
2185 * Old: u16{Major(4),Minor(4),SubMinor(8)}
2186 * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
2188 if (facts->MsgVersion < 0x0102) {
2190 * Handle old FC f/w style, convert to new...
2192 u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
2193 facts->FWVersion.Word =
2194 ((oldv<<12) & 0xFF000000) |
2195 ((oldv<<8) & 0x000FFF00);
2197 facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
2199 facts->ProductID = le16_to_cpu(facts->ProductID);
2200 facts->CurrentHostMfaHighAddr =
2201 le32_to_cpu(facts->CurrentHostMfaHighAddr);
2202 facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
2203 facts->CurrentSenseBufferHighAddr =
2204 le32_to_cpu(facts->CurrentSenseBufferHighAddr);
2205 facts->CurReplyFrameSize =
2206 le16_to_cpu(facts->CurReplyFrameSize);
2209 * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
2210 * Older MPI-1.00.xx struct had 13 dwords, and enlarged
2211 * to 14 in MPI-1.01.0x.
2213 if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
2214 facts->MsgVersion > 0x0100) {
2215 facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
2218 sz = facts->FWImageSize;
2223 facts->FWImageSize = sz;
2225 if (!facts->RequestFrameSize) {
2226 /* Something is wrong! */
2227 printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
2232 r = sz = facts->BlockSize;
2233 vv = ((63 / (sz * 4)) + 1) & 0x03;
2234 ioc->NB_for_64_byte_frame = vv;
2240 ioc->NBShiftFactor = shiftFactor;
2241 dinitprintk((MYIOC_s_INFO_FMT "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
2242 ioc->name, vv, shiftFactor, r));
2244 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2246 * Set values for this IOC's request & reply frame sizes,
2247 * and request & reply queue depths...
2249 ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
2250 ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
2251 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
2252 ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
2254 dinitprintk((MYIOC_s_INFO_FMT "reply_sz=%3d, reply_depth=%4d\n",
2255 ioc->name, ioc->reply_sz, ioc->reply_depth));
2256 dinitprintk((MYIOC_s_INFO_FMT "req_sz =%3d, req_depth =%4d\n",
2257 ioc->name, ioc->req_sz, ioc->req_depth));
2259 /* Get port facts! */
2260 if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
2264 printk(MYIOC_s_ERR_FMT
2265 "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
2266 ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
2267 RequestFrameSize)/sizeof(u32)));
2274 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2276 * GetPortFacts - Send PortFacts request to MPT adapter.
2277 * @ioc: Pointer to MPT_ADAPTER structure
2278 * @portnum: Port number
2279 * @sleepFlag: Specifies whether the process can sleep
2281 * Returns 0 for success, non-zero for failure.
2284 GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2286 PortFacts_t get_pfacts;
2287 PortFactsReply_t *pfacts;
2292 /* IOC *must* NOT be in RESET state! */
2293 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2294 printk(KERN_ERR MYNAM ": ERROR - Can't get PortFacts, %s NOT READY! (%08x)\n",
2300 pfacts = &ioc->pfacts[portnum];
2302 /* Destination (reply area)... */
2303 reply_sz = sizeof(*pfacts);
2304 memset(pfacts, 0, reply_sz);
2306 /* Request area (get_pfacts on the stack right now!) */
2307 req_sz = sizeof(get_pfacts);
2308 memset(&get_pfacts, 0, req_sz);
2310 get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
2311 get_pfacts.PortNumber = portnum;
2312 /* Assert: All other get_pfacts fields are zero! */
2314 dinitprintk((MYIOC_s_INFO_FMT "Sending get PortFacts(%d) request\n",
2315 ioc->name, portnum));
2317 /* No non-zero fields in the get_pfacts request are greater than
2318 * 1 byte in size, so we can just fire it off as is.
2320 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
2321 reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
2325 /* Did we get a valid reply? */
2327 /* Now byte swap the necessary fields in the response. */
2328 pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
2329 pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
2330 pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
2331 pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
2332 pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
2333 pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
2334 pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
2335 pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
2336 pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
2341 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2343 * SendIocInit - Send IOCInit request to MPT adapter.
2344 * @ioc: Pointer to MPT_ADAPTER structure
2345 * @sleepFlag: Specifies whether the process can sleep
2347 * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
2349 * Returns 0 for success, non-zero for failure.
2352 SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
2355 MPIDefaultReply_t init_reply;
2361 memset(&ioc_init, 0, sizeof(ioc_init));
2362 memset(&init_reply, 0, sizeof(init_reply));
2364 ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
2365 ioc_init.Function = MPI_FUNCTION_IOC_INIT;
2367 /* If we are in a recovery mode and we uploaded the FW image,
2368 * then this pointer is not NULL. Skip the upload a second time.
2369 * Set this flag if cached_fw set for either IOC.
2371 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
2375 ddlprintk((MYIOC_s_INFO_FMT "upload_fw %d facts.Flags=%x\n",
2376 ioc->name, ioc->upload_fw, ioc->facts.Flags));
2378 if (ioc->bus_type == FC)
2379 ioc_init.MaxDevices = MPT_MAX_FC_DEVICES;
2381 ioc_init.MaxDevices = MPT_MAX_SCSI_DEVICES;
2383 ioc_init.MaxBuses = MPT_MAX_BUS;
2385 ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
2387 if (sizeof(dma_addr_t) == sizeof(u64)) {
2388 /* Save the upper 32-bits of the request
2389 * (reply) and sense buffers.
2391 ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
2392 ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2394 /* Force 32-bit addressing */
2395 ioc_init.HostMfaHighAddr = cpu_to_le32(0);
2396 ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
2399 ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
2400 ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
2402 dhsprintk((MYIOC_s_INFO_FMT "Sending IOCInit (req @ %p)\n",
2403 ioc->name, &ioc_init));
2405 r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
2406 sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
2410 /* No need to byte swap the multibyte fields in the reply
2411 * since we don't even look at it's contents.
2414 dhsprintk((MYIOC_s_INFO_FMT "Sending PortEnable (req @ %p)\n",
2415 ioc->name, &ioc_init));
2417 if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0)
2420 /* YIKES! SUPER IMPORTANT!!!
2421 * Poll IocState until _OPERATIONAL while IOC is doing
2422 * LoopInit and TargetDiscovery!
2425 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
2426 state = mpt_GetIocState(ioc, 1);
2427 while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
2428 if (sleepFlag == CAN_SLEEP) {
2429 msleep_interruptible(1);
2435 printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
2436 ioc->name, (int)((count+5)/HZ));
2440 state = mpt_GetIocState(ioc, 1);
2443 dhsprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
2449 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2451 * SendPortEnable - Send PortEnable request to MPT adapter port.
2452 * @ioc: Pointer to MPT_ADAPTER structure
2453 * @portnum: Port number to enable
2454 * @sleepFlag: Specifies whether the process can sleep
2456 * Send PortEnable to bring IOC to OPERATIONAL state.
2458 * Returns 0 for success, non-zero for failure.
2461 SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2463 PortEnable_t port_enable;
2464 MPIDefaultReply_t reply_buf;
2469 /* Destination... */
2470 reply_sz = sizeof(MPIDefaultReply_t);
2471 memset(&reply_buf, 0, reply_sz);
2473 req_sz = sizeof(PortEnable_t);
2474 memset(&port_enable, 0, req_sz);
2476 port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
2477 port_enable.PortNumber = portnum;
2478 /* port_enable.ChainOffset = 0; */
2479 /* port_enable.MsgFlags = 0; */
2480 /* port_enable.MsgContext = 0; */
2482 dinitprintk((MYIOC_s_INFO_FMT "Sending Port(%d)Enable (req @ %p)\n",
2483 ioc->name, portnum, &port_enable));
2485 /* RAID FW may take a long time to enable
2487 if (ioc->bus_type == FC) {
2488 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
2489 reply_sz, (u16*)&reply_buf, 65 /*seconds*/, sleepFlag);
2491 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
2492 reply_sz, (u16*)&reply_buf, 300 /*seconds*/, sleepFlag);
2498 /* We do not even look at the reply, so we need not
2499 * swap the multi-byte fields.
2506 * ioc: Pointer to MPT_ADAPTER structure
2507 * size - total FW bytes
2510 mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
2513 return; /* use already allocated memory */
2514 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
2515 ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
2516 ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
2518 if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
2519 ioc->alloc_total += size;
2523 * If alt_img is NULL, delete from ioc structure.
2524 * Else, delete a secondary image in same format.
2527 mpt_free_fw_memory(MPT_ADAPTER *ioc)
2531 sz = ioc->facts.FWImageSize;
2532 dinitprintk((KERN_WARNING MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
2533 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2534 pci_free_consistent(ioc->pcidev, sz,
2535 ioc->cached_fw, ioc->cached_fw_dma);
2536 ioc->cached_fw = NULL;
2542 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2544 * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
2545 * @ioc: Pointer to MPT_ADAPTER structure
2546 * @sleepFlag: Specifies whether the process can sleep
2548 * Returns 0 for success, >0 for handshake failure
2549 * <0 for fw upload failure.
2551 * Remark: If bound IOC and a successful FWUpload was performed
2552 * on the bound IOC, the second image is discarded
2553 * and memory is free'd. Both channels must upload to prevent
2554 * IOC from running in degraded mode.
2557 mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
2559 u8 request[ioc->req_sz];
2560 u8 reply[sizeof(FWUploadReply_t)];
2561 FWUpload_t *prequest;
2562 FWUploadReply_t *preply;
2563 FWUploadTCSGE_t *ptcsge;
2566 int ii, sz, reply_sz;
2569 /* If the image size is 0, we are done.
2571 if ((sz = ioc->facts.FWImageSize) == 0)
2574 mpt_alloc_fw_memory(ioc, sz);
2576 dinitprintk((KERN_WARNING MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
2577 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2579 if (ioc->cached_fw == NULL) {
2585 prequest = (FWUpload_t *)&request;
2586 preply = (FWUploadReply_t *)&reply;
2588 /* Destination... */
2589 memset(prequest, 0, ioc->req_sz);
2591 reply_sz = sizeof(reply);
2592 memset(preply, 0, reply_sz);
2594 prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
2595 prequest->Function = MPI_FUNCTION_FW_UPLOAD;
2597 ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
2598 ptcsge->DetailsLength = 12;
2599 ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
2600 ptcsge->ImageSize = cpu_to_le32(sz);
2602 sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
2604 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
2605 mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
2607 sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
2608 dinitprintk((KERN_WARNING MYNAM "Sending FW Upload (req @ %p) sgeoffset=%d \n",
2609 prequest, sgeoffset));
2610 DBG_DUMP_FW_REQUEST_FRAME(prequest)
2612 ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
2613 reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
2615 dinitprintk((KERN_WARNING MYNAM "FW Upload completed rc=%x \n", ii));
2617 cmdStatus = -EFAULT;
2619 /* Handshake transfer was complete and successful.
2620 * Check the Reply Frame.
2622 int status, transfer_sz;
2623 status = le16_to_cpu(preply->IOCStatus);
2624 if (status == MPI_IOCSTATUS_SUCCESS) {
2625 transfer_sz = le32_to_cpu(preply->ActualImageSize);
2626 if (transfer_sz == sz)
2630 dinitprintk((MYIOC_s_INFO_FMT ": do_upload status %d \n",
2631 ioc->name, cmdStatus));
2636 ddlprintk((MYIOC_s_INFO_FMT ": fw upload failed, freeing image \n",
2638 mpt_free_fw_memory(ioc);
2644 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2646 * mpt_downloadboot - DownloadBoot code
2647 * @ioc: Pointer to MPT_ADAPTER structure
2648 * @flag: Specify which part of IOC memory is to be uploaded.
2649 * @sleepFlag: Specifies whether the process can sleep
2651 * FwDownloadBoot requires Programmed IO access.
2653 * Returns 0 for success
2654 * -1 FW Image size is 0
2655 * -2 No valid cached_fw Pointer
2656 * <0 for fw upload failure.
2659 mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag)
2661 MpiFwHeader_t *pFwHeader;
2662 MpiExtImageHeader_t *pExtImage;
2672 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: fw size 0x%x, ioc FW Ptr %p\n",
2673 ioc->name, ioc->facts.FWImageSize, ioc->cached_fw));
2675 if ( ioc->facts.FWImageSize == 0 )
2678 if (ioc->cached_fw == NULL)
2681 /* prevent a second downloadboot and memory free with alt_ioc */
2682 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
2683 ioc->alt_ioc->cached_fw = NULL;
2685 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2686 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2687 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2688 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2689 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2690 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2692 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
2695 if (sleepFlag == CAN_SLEEP) {
2696 msleep_interruptible(1);
2701 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2702 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
2704 for (count = 0; count < 30; count ++) {
2705 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2706 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
2707 ddlprintk((MYIOC_s_INFO_FMT "RESET_ADAPTER cleared, count=%d\n",
2712 if (sleepFlag == CAN_SLEEP) {
2713 msleep_interruptible (1000);
2719 if ( count == 30 ) {
2720 ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! Unable to RESET_ADAPTER diag0val=%x\n",
2721 ioc->name, diag0val));
2725 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2726 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2727 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2728 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2729 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2730 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2732 /* Set the DiagRwEn and Disable ARM bits */
2733 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
2735 pFwHeader = (MpiFwHeader_t *) ioc->cached_fw;
2736 fwSize = (pFwHeader->ImageSize + 3)/4;
2737 ptrFw = (u32 *) pFwHeader;
2739 /* Write the LoadStartAddress to the DiagRw Address Register
2740 * using Programmed IO
2742 if (ioc->errata_flag_1064)
2743 pci_enable_io_access(ioc->pcidev);
2745 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
2746 ddlprintk((MYIOC_s_INFO_FMT "LoadStart addr written 0x%x \n",
2747 ioc->name, pFwHeader->LoadStartAddress));
2749 ddlprintk((MYIOC_s_INFO_FMT "Write FW Image: 0x%x bytes @ %p\n",
2750 ioc->name, fwSize*4, ptrFw));
2752 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
2755 nextImage = pFwHeader->NextImageHeaderOffset;
2757 pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
2759 load_addr = pExtImage->LoadStartAddress;
2761 fwSize = (pExtImage->ImageSize + 3) >> 2;
2762 ptrFw = (u32 *)pExtImage;
2764 ddlprintk((MYIOC_s_INFO_FMT "Write Ext Image: 0x%x bytes @ %p load_addr=%x\n",
2765 ioc->name, fwSize*4, ptrFw, load_addr));
2766 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
2769 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
2771 nextImage = pExtImage->NextImageHeaderOffset;
2774 /* Write the IopResetVectorRegAddr */
2775 ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
2776 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
2778 /* Write the IopResetVectorValue */
2779 ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
2780 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
2782 /* Clear the internal flash bad bit - autoincrementing register,
2783 * so must do two writes.
2785 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
2786 diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
2787 diagRwData |= 0x4000000;
2788 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
2789 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
2791 if (ioc->errata_flag_1064)
2792 pci_disable_io_access(ioc->pcidev);
2794 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2795 ddlprintk((MYIOC_s_INFO_FMT "downloadboot diag0val=%x, turning off PREVENT_IOC_BOOT, DISABLE_ARM\n",
2796 ioc->name, diag0val));
2797 diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM);
2798 ddlprintk((MYIOC_s_INFO_FMT "downloadboot now diag0val=%x\n",
2799 ioc->name, diag0val));
2800 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
2802 /* Write 0xFF to reset the sequencer */
2803 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2805 for (count=0; count<HZ*20; count++) {
2806 if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
2807 ddlprintk((MYIOC_s_INFO_FMT "downloadboot successful! (count=%d) IocState=%x\n",
2808 ioc->name, count, ioc_state));
2809 if ((SendIocInit(ioc, sleepFlag)) != 0) {
2810 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit failed\n",
2814 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit successful\n",
2818 if (sleepFlag == CAN_SLEEP) {
2819 msleep_interruptible (10);
2824 ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! IocState=%x\n",
2825 ioc->name, ioc_state));
2829 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2831 * KickStart - Perform hard reset of MPT adapter.
2832 * @ioc: Pointer to MPT_ADAPTER structure
2833 * @force: Force hard reset
2834 * @sleepFlag: Specifies whether the process can sleep
2836 * This routine places MPT adapter in diagnostic mode via the
2837 * WriteSequence register, and then performs a hard reset of adapter
2838 * via the Diagnostic register.
2840 * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
2841 * or NO_SLEEP (interrupt thread, use mdelay)
2842 * force - 1 if doorbell active, board fault state
2843 * board operational, IOC_RECOVERY or
2844 * IOC_BRINGUP and there is an alt_ioc.
2848 * 1 - hard reset, READY
2849 * 0 - no reset due to History bit, READY
2850 * -1 - no reset due to History bit but not READY
2851 * OR reset but failed to come READY
2852 * -2 - no reset, could not enter DIAG mode
2853 * -3 - reset but bad FW bit
2856 KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
2858 int hard_reset_done = 0;
2862 dinitprintk((KERN_WARNING MYNAM ": KickStarting %s!\n", ioc->name));
2863 if (ioc->bus_type == SCSI) {
2864 /* Always issue a Msg Unit Reset first. This will clear some
2865 * SCSI bus hang conditions.
2867 SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
2869 if (sleepFlag == CAN_SLEEP) {
2870 msleep_interruptible (1000);
2876 hard_reset_done = mpt_diag_reset(ioc, force, sleepFlag);
2877 if (hard_reset_done < 0)
2878 return hard_reset_done;
2880 dinitprintk((MYIOC_s_INFO_FMT "Diagnostic reset successful!\n",
2883 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2; /* 2 seconds */
2884 for (cnt=0; cnt<cntdn; cnt++) {
2885 ioc_state = mpt_GetIocState(ioc, 1);
2886 if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
2887 dinitprintk((MYIOC_s_INFO_FMT "KickStart successful! (cnt=%d)\n",
2889 return hard_reset_done;
2891 if (sleepFlag == CAN_SLEEP) {
2892 msleep_interruptible (10);
2898 printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
2899 ioc->name, ioc_state);
2903 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2905 * mpt_diag_reset - Perform hard reset of the adapter.
2906 * @ioc: Pointer to MPT_ADAPTER structure
2907 * @ignore: Set if to honor and clear to ignore
2908 * the reset history bit
2909 * @sleepflag: CAN_SLEEP if called in a non-interrupt thread,
2910 * else set to NO_SLEEP (use mdelay instead)
2912 * This routine places the adapter in diagnostic mode via the
2913 * WriteSequence register and then performs a hard reset of adapter
2914 * via the Diagnostic register. Adapter should be in ready state
2915 * upon successful completion.
2917 * Returns: 1 hard reset successful
2918 * 0 no reset performed because reset history bit set
2919 * -2 enabling diagnostic mode failed
2920 * -3 diagnostic reset failed
2923 mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
2927 int hard_reset_done = 0;
2933 /* Clear any existing interrupts */
2934 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
2936 /* Use "Diagnostic reset" method! (only thing available!) */
2937 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2941 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
2942 dprintk((MYIOC_s_INFO_FMT "DbG1: diag0=%08x, diag1=%08x\n",
2943 ioc->name, diag0val, diag1val));
2946 /* Do the reset if we are told to ignore the reset history
2947 * or if the reset history is 0
2949 if (ignore || !(diag0val & MPI_DIAG_RESET_HISTORY)) {
2950 while ((diag0val & MPI_DIAG_DRWE) == 0) {
2951 /* Write magic sequence to WriteSequence register
2952 * Loop until in diagnostic mode
2954 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2955 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2956 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2957 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2958 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2959 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2962 if (sleepFlag == CAN_SLEEP) {
2963 msleep_interruptible (100);
2970 printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
2971 ioc->name, diag0val);
2976 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2978 dprintk((MYIOC_s_INFO_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
2979 ioc->name, diag0val));
2984 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
2985 dprintk((MYIOC_s_INFO_FMT "DbG2: diag0=%08x, diag1=%08x\n",
2986 ioc->name, diag0val, diag1val));
2989 * Disable the ARM (Bug fix)
2992 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
2996 * Now hit the reset bit in the Diagnostic register
2997 * (THE BIG HAMMER!) (Clears DRWE bit).
2999 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
3000 hard_reset_done = 1;
3001 dprintk((MYIOC_s_INFO_FMT "Diagnostic reset performed\n",
3005 * Call each currently registered protocol IOC reset handler
3006 * with pre-reset indication.
3007 * NOTE: If we're doing _IOC_BRINGUP, there can be no
3008 * MptResetHandlers[] registered yet.
3014 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
3015 if (MptResetHandlers[ii]) {
3016 dprintk((MYIOC_s_INFO_FMT "Calling IOC pre_reset handler #%d\n",
3018 r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_PRE_RESET);
3020 dprintk((MYIOC_s_INFO_FMT "Calling alt-%s pre_reset handler #%d\n",
3021 ioc->name, ioc->alt_ioc->name, ii));
3022 r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_PRE_RESET);
3026 /* FIXME? Examine results here? */
3029 if (ioc->cached_fw) {
3030 /* If the DownloadBoot operation fails, the
3031 * IOC will be left unusable. This is a fatal error
3032 * case. _diag_reset will return < 0
3034 for (count = 0; count < 30; count ++) {
3035 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3036 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
3041 if (sleepFlag == CAN_SLEEP) {
3047 if ((count = mpt_downloadboot(ioc, sleepFlag)) < 0) {
3048 printk(KERN_WARNING MYNAM
3049 ": firmware downloadboot failure (%d)!\n", count);
3053 /* Wait for FW to reload and for board
3054 * to go to the READY state.
3055 * Maximum wait is 60 seconds.
3056 * If fail, no error will check again
3057 * with calling program.
3059 for (count = 0; count < 60; count ++) {
3060 doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
3061 doorbell &= MPI_IOC_STATE_MASK;
3063 if (doorbell == MPI_IOC_STATE_READY) {
3068 if (sleepFlag == CAN_SLEEP) {
3069 msleep_interruptible (1000);
3077 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3080 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3081 dprintk((MYIOC_s_INFO_FMT "DbG3: diag0=%08x, diag1=%08x\n",
3082 ioc->name, diag0val, diag1val));
3085 /* Clear RESET_HISTORY bit! Place board in the
3086 * diagnostic mode to update the diag register.
3088 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3090 while ((diag0val & MPI_DIAG_DRWE) == 0) {
3091 /* Write magic sequence to WriteSequence register
3092 * Loop until in diagnostic mode
3094 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
3095 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
3096 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
3097 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
3098 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
3099 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
3102 if (sleepFlag == CAN_SLEEP) {
3103 msleep_interruptible (100);
3110 printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
3111 ioc->name, diag0val);
3114 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3116 diag0val &= ~MPI_DIAG_RESET_HISTORY;
3117 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
3118 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3119 if (diag0val & MPI_DIAG_RESET_HISTORY) {
3120 printk(MYIOC_s_WARN_FMT "ResetHistory bit failed to clear!\n",
3124 /* Disable Diagnostic Mode
3126 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFFFFFFFF);
3128 /* Check FW reload status flags.
3130 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3131 if (diag0val & (MPI_DIAG_FLASH_BAD_SIG | MPI_DIAG_RESET_ADAPTER | MPI_DIAG_DISABLE_ARM)) {
3132 printk(MYIOC_s_ERR_FMT "Diagnostic reset FAILED! (%02xh)\n",
3133 ioc->name, diag0val);
3139 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3140 dprintk((MYIOC_s_INFO_FMT "DbG4: diag0=%08x, diag1=%08x\n",
3141 ioc->name, diag0val, diag1val));
3145 * Reset flag that says we've enabled event notification
3147 ioc->facts.EventState = 0;
3150 ioc->alt_ioc->facts.EventState = 0;
3152 return hard_reset_done;
3155 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3157 * SendIocReset - Send IOCReset request to MPT adapter.
3158 * @ioc: Pointer to MPT_ADAPTER structure
3159 * @reset_type: reset type, expected values are
3160 * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
3162 * Send IOCReset request to the MPT adapter.
3164 * Returns 0 for success, non-zero for failure.
3167 SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
3173 drsprintk((KERN_WARNING MYNAM ": %s: Sending IOC reset(0x%02x)!\n",
3174 ioc->name, reset_type));
3175 CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
3176 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3179 /* FW ACK'd request, wait for READY state
3182 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
3184 while ((state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
3188 if (sleepFlag != CAN_SLEEP)
3191 printk(KERN_ERR MYNAM ": %s: ERROR - Wait IOC_READY state timeout(%d)!\n",
3192 ioc->name, (int)((count+5)/HZ));
3196 if (sleepFlag == CAN_SLEEP) {
3197 msleep_interruptible(1);
3199 mdelay (1); /* 1 msec delay */
3204 * Cleanup all event stuff for this IOC; re-issue EventNotification
3205 * request if needed.
3207 if (ioc->facts.Function)
3208 ioc->facts.EventState = 0;
3213 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3215 * initChainBuffers - Allocate memory for and initialize
3216 * chain buffers, chain buffer control arrays and spinlock.
3217 * @hd: Pointer to MPT_SCSI_HOST structure
3218 * @init: If set, initialize the spin lock.
3221 initChainBuffers(MPT_ADAPTER *ioc)
3224 int sz, ii, num_chain;
3225 int scale, num_sge, numSGE;
3227 /* ReqToChain size must equal the req_depth
3230 if (ioc->ReqToChain == NULL) {
3231 sz = ioc->req_depth * sizeof(int);
3232 mem = kmalloc(sz, GFP_ATOMIC);
3236 ioc->ReqToChain = (int *) mem;
3237 dinitprintk((KERN_INFO MYNAM ": %s ReqToChain alloc @ %p, sz=%d bytes\n",
3238 ioc->name, mem, sz));
3239 mem = kmalloc(sz, GFP_ATOMIC);
3243 ioc->RequestNB = (int *) mem;
3244 dinitprintk((KERN_INFO MYNAM ": %s RequestNB alloc @ %p, sz=%d bytes\n",
3245 ioc->name, mem, sz));
3247 for (ii = 0; ii < ioc->req_depth; ii++) {
3248 ioc->ReqToChain[ii] = MPT_HOST_NO_CHAIN;
3251 /* ChainToChain size must equal the total number
3252 * of chain buffers to be allocated.
3255 * Calculate the number of chain buffers needed(plus 1) per I/O
3256 * then multiply the the maximum number of simultaneous cmds
3258 * num_sge = num sge in request frame + last chain buffer
3259 * scale = num sge per chain buffer if no chain element
3261 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
3262 if (sizeof(dma_addr_t) == sizeof(u64))
3263 num_sge = scale + (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
3265 num_sge = 1+ scale + (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
3267 if (sizeof(dma_addr_t) == sizeof(u64)) {
3268 numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
3269 (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
3271 numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
3272 (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
3274 dinitprintk((KERN_INFO MYNAM ": %s num_sge=%d numSGE=%d\n",
3275 ioc->name, num_sge, numSGE));
3277 if ( numSGE > MPT_SCSI_SG_DEPTH )
3278 numSGE = MPT_SCSI_SG_DEPTH;
3281 while (numSGE - num_sge > 0) {
3283 num_sge += (scale - 1);
3287 dinitprintk((KERN_INFO MYNAM ": %s Now numSGE=%d num_sge=%d num_chain=%d\n",
3288 ioc->name, numSGE, num_sge, num_chain));
3290 if (ioc->bus_type == SCSI)
3291 num_chain *= MPT_SCSI_CAN_QUEUE;
3293 num_chain *= MPT_FC_CAN_QUEUE;
3295 ioc->num_chain = num_chain;
3297 sz = num_chain * sizeof(int);
3298 if (ioc->ChainToChain == NULL) {
3299 mem = kmalloc(sz, GFP_ATOMIC);
3303 ioc->ChainToChain = (int *) mem;
3304 dinitprintk((KERN_INFO MYNAM ": %s ChainToChain alloc @ %p, sz=%d bytes\n",
3305 ioc->name, mem, sz));
3307 mem = (u8 *) ioc->ChainToChain;
3309 memset(mem, 0xFF, sz);
3313 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3315 * PrimeIocFifos - Initialize IOC request and reply FIFOs.
3316 * @ioc: Pointer to MPT_ADAPTER structure
3318 * This routine allocates memory for the MPT reply and request frame
3319 * pools (if necessary), and primes the IOC reply FIFO with
3322 * Returns 0 for success, non-zero for failure.
3325 PrimeIocFifos(MPT_ADAPTER *ioc)
3328 unsigned long flags;
3329 dma_addr_t alloc_dma;
3331 int i, reply_sz, sz, total_size, num_chain;
3333 /* Prime reply FIFO... */
3335 if (ioc->reply_frames == NULL) {
3336 if ( (num_chain = initChainBuffers(ioc)) < 0)
3339 total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
3340 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
3341 ioc->name, ioc->reply_sz, ioc->reply_depth));
3342 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d[%x] bytes\n",
3343 ioc->name, reply_sz, reply_sz));
3345 sz = (ioc->req_sz * ioc->req_depth);
3346 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d bytes, RequestDepth=%d\n",
3347 ioc->name, ioc->req_sz, ioc->req_depth));
3348 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d[%x] bytes\n",
3349 ioc->name, sz, sz));
3352 sz = num_chain * ioc->req_sz; /* chain buffer pool size */
3353 dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d bytes, ChainDepth=%d\n",
3354 ioc->name, ioc->req_sz, num_chain));
3355 dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
3356 ioc->name, sz, sz, num_chain));
3359 mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
3361 printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
3366 dinitprintk((KERN_INFO MYNAM ": %s.Total alloc @ %p[%p], sz=%d[%x] bytes\n",
3367 ioc->name, mem, (void *)(ulong)alloc_dma, total_size, total_size));
3369 memset(mem, 0, total_size);
3370 ioc->alloc_total += total_size;
3372 ioc->alloc_dma = alloc_dma;
3373 ioc->alloc_sz = total_size;
3374 ioc->reply_frames = (MPT_FRAME_HDR *) mem;
3375 ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
3377 alloc_dma += reply_sz;
3380 /* Request FIFO - WE manage this! */
3382 ioc->req_frames = (MPT_FRAME_HDR *) mem;
3383 ioc->req_frames_dma = alloc_dma;
3385 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffers @ %p[%p]\n",
3386 ioc->name, mem, (void *)(ulong)alloc_dma));
3388 ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
3390 #if defined(CONFIG_MTRR) && 0
3392 * Enable Write Combining MTRR for IOC's memory region.
3393 * (at least as much as we can; "size and base must be
3394 * multiples of 4 kiB"
3396 ioc->mtrr_reg = mtrr_add(ioc->req_frames_dma,
3398 MTRR_TYPE_WRCOMB, 1);
3399 dprintk((MYIOC_s_INFO_FMT "MTRR region registered (base:size=%08x:%x)\n",
3400 ioc->name, ioc->req_frames_dma, sz));
3403 for (i = 0; i < ioc->req_depth; i++) {
3404 alloc_dma += ioc->req_sz;
3408 ioc->ChainBuffer = mem;
3409 ioc->ChainBufferDMA = alloc_dma;
3411 dinitprintk((KERN_INFO MYNAM " :%s.ChainBuffers @ %p(%p)\n",
3412 ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
3414 /* Initialize the free chain Q.
3417 INIT_LIST_HEAD(&ioc->FreeChainQ);
3419 /* Post the chain buffers to the FreeChainQ.
3421 mem = (u8 *)ioc->ChainBuffer;
3422 for (i=0; i < num_chain; i++) {
3423 mf = (MPT_FRAME_HDR *) mem;
3424 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeChainQ);
3428 /* Initialize Request frames linked list
3430 alloc_dma = ioc->req_frames_dma;
3431 mem = (u8 *) ioc->req_frames;
3433 spin_lock_irqsave(&ioc->FreeQlock, flags);
3434 INIT_LIST_HEAD(&ioc->FreeQ);
3435 for (i = 0; i < ioc->req_depth; i++) {
3436 mf = (MPT_FRAME_HDR *) mem;
3438 /* Queue REQUESTs *internally*! */
3439 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
3443 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
3445 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
3446 ioc->sense_buf_pool =
3447 pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
3448 if (ioc->sense_buf_pool == NULL) {
3449 printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
3454 ioc->sense_buf_low_dma = (u32) (ioc->sense_buf_pool_dma & 0xFFFFFFFF);
3455 ioc->alloc_total += sz;
3456 dinitprintk((KERN_INFO MYNAM ": %s.SenseBuffers @ %p[%p]\n",
3457 ioc->name, ioc->sense_buf_pool, (void *)(ulong)ioc->sense_buf_pool_dma));
3461 /* Post Reply frames to FIFO
3463 alloc_dma = ioc->alloc_dma;
3464 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffers @ %p[%p]\n",
3465 ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
3467 for (i = 0; i < ioc->reply_depth; i++) {
3468 /* Write each address to the IOC! */
3469 CHIPREG_WRITE32(&ioc->chip->ReplyFifo, alloc_dma);
3470 alloc_dma += ioc->reply_sz;
3476 if (ioc->alloc != NULL) {
3478 pci_free_consistent(ioc->pcidev,
3480 ioc->alloc, ioc->alloc_dma);
3481 ioc->reply_frames = NULL;
3482 ioc->req_frames = NULL;
3483 ioc->alloc_total -= sz;
3485 if (ioc->sense_buf_pool != NULL) {
3486 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
3487 pci_free_consistent(ioc->pcidev,
3489 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
3490 ioc->sense_buf_pool = NULL;
3495 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3497 * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
3498 * from IOC via doorbell handshake method.
3499 * @ioc: Pointer to MPT_ADAPTER structure
3500 * @reqBytes: Size of the request in bytes
3501 * @req: Pointer to MPT request frame
3502 * @replyBytes: Expected size of the reply in bytes
3503 * @u16reply: Pointer to area where reply should be written
3504 * @maxwait: Max wait time for a reply (in seconds)
3505 * @sleepFlag: Specifies whether the process can sleep
3507 * NOTES: It is the callers responsibility to byte-swap fields in the
3508 * request which are greater than 1 byte in size. It is also the
3509 * callers responsibility to byte-swap response fields which are
3510 * greater than 1 byte in size.
3512 * Returns 0 for success, non-zero for failure.
3515 mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
3516 int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
3518 MPIDefaultReply_t *mptReply;
3523 * Get ready to cache a handshake reply
3525 ioc->hs_reply_idx = 0;
3526 mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
3527 mptReply->MsgLength = 0;
3530 * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
3531 * then tell IOC that we want to handshake a request of N words.
3532 * (WRITE u32val to Doorbell reg).
3534 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3535 CHIPREG_WRITE32(&ioc->chip->Doorbell,
3536 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
3537 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
3540 * Wait for IOC's doorbell handshake int
3542 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3545 dhsprintk((MYIOC_s_INFO_FMT "HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
3546 ioc->name, reqBytes, t, failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
3548 /* Read doorbell and check for active bit */
3549 if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
3553 * Clear doorbell int (WRITE 0 to IntStatus reg),
3554 * then wait for IOC to ACKnowledge that it's ready for
3555 * our handshake request.
3557 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3558 if (!failcnt && (t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3563 u8 *req_as_bytes = (u8 *) req;
3566 * Stuff request words via doorbell handshake,
3567 * with ACK from IOC for each.
3569 for (ii = 0; !failcnt && ii < reqBytes/4; ii++) {
3570 u32 word = ((req_as_bytes[(ii*4) + 0] << 0) |
3571 (req_as_bytes[(ii*4) + 1] << 8) |
3572 (req_as_bytes[(ii*4) + 2] << 16) |
3573 (req_as_bytes[(ii*4) + 3] << 24));
3575 CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
3576 if ((t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3580 dhsprintk((KERN_INFO MYNAM ": Handshake request frame (@%p) header\n", req));
3581 DBG_DUMP_REQUEST_FRAME_HDR(req)
3583 dhsprintk((MYIOC_s_INFO_FMT "HandShake request post done, WaitCnt=%d%s\n",
3584 ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
3587 * Wait for completion of doorbell handshake reply from the IOC
3589 if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
3592 dhsprintk((MYIOC_s_INFO_FMT "HandShake reply count=%d%s\n",
3593 ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
3596 * Copy out the cached reply...
3598 for (ii=0; ii < min(replyBytes/2,mptReply->MsgLength*2); ii++)
3599 u16reply[ii] = ioc->hs_reply[ii];
3607 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3609 * WaitForDoorbellAck - Wait for IOC to clear the IOP_DOORBELL_STATUS bit
3610 * in it's IntStatus register.
3611 * @ioc: Pointer to MPT_ADAPTER structure
3612 * @howlong: How long to wait (in seconds)
3613 * @sleepFlag: Specifies whether the process can sleep
3615 * This routine waits (up to ~2 seconds max) for IOC doorbell
3616 * handshake ACKnowledge.
3618 * Returns a negative value on failure, else wait loop count.
3621 WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3627 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
3629 if (sleepFlag == CAN_SLEEP) {
3631 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3632 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
3634 msleep_interruptible (1);
3639 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3640 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
3648 dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell ACK (count=%d)\n",
3653 printk(MYIOC_s_ERR_FMT "Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
3654 ioc->name, count, intstat);
3658 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3660 * WaitForDoorbellInt - Wait for IOC to set the HIS_DOORBELL_INTERRUPT bit
3661 * in it's IntStatus register.
3662 * @ioc: Pointer to MPT_ADAPTER structure
3663 * @howlong: How long to wait (in seconds)
3664 * @sleepFlag: Specifies whether the process can sleep
3666 * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt.
3668 * Returns a negative value on failure, else wait loop count.
3671 WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3677 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
3678 if (sleepFlag == CAN_SLEEP) {
3680 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3681 if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
3683 msleep_interruptible(1);
3688 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3689 if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
3697 dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell INT (cnt=%d) howlong=%d\n",
3698 ioc->name, count, howlong));
3702 printk(MYIOC_s_ERR_FMT "Doorbell INT timeout (count=%d), IntStatus=%x!\n",
3703 ioc->name, count, intstat);
3707 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3709 * WaitForDoorbellReply - Wait for and capture a IOC handshake reply.
3710 * @ioc: Pointer to MPT_ADAPTER structure
3711 * @howlong: How long to wait (in seconds)
3712 * @sleepFlag: Specifies whether the process can sleep
3714 * This routine polls the IOC for a handshake reply, 16 bits at a time.
3715 * Reply is cached to IOC private area large enough to hold a maximum
3716 * of 128 bytes of reply data.
3718 * Returns a negative value on failure, else size of reply in WORDS.
3721 WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3726 u16 *hs_reply = ioc->hs_reply;
3727 volatile MPIDefaultReply_t *mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
3730 hs_reply[0] = hs_reply[1] = hs_reply[7] = 0;
3733 * Get first two u16's so we can look at IOC's intended reply MsgLength
3736 if ((t = WaitForDoorbellInt(ioc, howlong, sleepFlag)) < 0) {
3739 hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
3740 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3741 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3744 hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
3745 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3749 dhsprintk((MYIOC_s_INFO_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
3750 ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
3751 failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
3754 * If no error (and IOC said MsgLength is > 0), piece together
3755 * reply 16 bits at a time.
3757 for (u16cnt=2; !failcnt && u16cnt < (2 * mptReply->MsgLength); u16cnt++) {
3758 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3760 hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
3761 /* don't overflow our IOC hs_reply[] buffer! */
3762 if (u16cnt < sizeof(ioc->hs_reply) / sizeof(ioc->hs_reply[0]))
3763 hs_reply[u16cnt] = hword;
3764 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3767 if (!failcnt && (t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3769 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3772 printk(MYIOC_s_ERR_FMT "Handshake reply failure!\n",
3777 else if (u16cnt != (2 * mptReply->MsgLength)) {
3780 else if ((mptReply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
3785 dhsprintk((MYIOC_s_INFO_FMT "Got Handshake reply:\n", ioc->name));
3786 DBG_DUMP_REPLY_FRAME(mptReply)
3788 dhsprintk((MYIOC_s_INFO_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
3789 ioc->name, t, u16cnt/2));
3793 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3795 * GetLanConfigPages - Fetch LANConfig pages.
3796 * @ioc: Pointer to MPT_ADAPTER structure
3798 * Return: 0 for success
3799 * -ENOMEM if no memory available
3800 * -EPERM if not allowed due to ISR context
3801 * -EAGAIN if no msg frames currently available
3802 * -EFAULT for non-successful reply or no reply (timeout)
3805 GetLanConfigPages(MPT_ADAPTER *ioc)
3807 ConfigPageHeader_t hdr;
3809 LANPage0_t *ppage0_alloc;
3810 dma_addr_t page0_dma;
3811 LANPage1_t *ppage1_alloc;
3812 dma_addr_t page1_dma;
3817 /* Get LAN Page 0 header */
3818 hdr.PageVersion = 0;
3821 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
3824 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3829 if ((rc = mpt_config(ioc, &cfg)) != 0)
3832 if (hdr.PageLength > 0) {
3833 data_sz = hdr.PageLength * 4;
3834 ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
3837 memset((u8 *)ppage0_alloc, 0, data_sz);
3838 cfg.physAddr = page0_dma;
3839 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
3841 if ((rc = mpt_config(ioc, &cfg)) == 0) {
3843 copy_sz = min_t(int, sizeof(LANPage0_t), data_sz);
3844 memcpy(&ioc->lan_cnfg_page0, ppage0_alloc, copy_sz);
3848 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
3851 * Normalize endianness of structure data,
3852 * by byte-swapping all > 1 byte fields!
3861 /* Get LAN Page 1 header */
3862 hdr.PageVersion = 0;
3865 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
3868 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3872 if ((rc = mpt_config(ioc, &cfg)) != 0)
3875 if (hdr.PageLength == 0)
3878 data_sz = hdr.PageLength * 4;
3880 ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
3882 memset((u8 *)ppage1_alloc, 0, data_sz);
3883 cfg.physAddr = page1_dma;
3884 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
3886 if ((rc = mpt_config(ioc, &cfg)) == 0) {
3888 copy_sz = min_t(int, sizeof(LANPage1_t), data_sz);
3889 memcpy(&ioc->lan_cnfg_page1, ppage1_alloc, copy_sz);
3892 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
3895 * Normalize endianness of structure data,
3896 * by byte-swapping all > 1 byte fields!
3904 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3906 * GetFcPortPage0 - Fetch FCPort config Page0.
3907 * @ioc: Pointer to MPT_ADAPTER structure
3908 * @portnum: IOC Port number
3910 * Return: 0 for success
3911 * -ENOMEM if no memory available
3912 * -EPERM if not allowed due to ISR context
3913 * -EAGAIN if no msg frames currently available
3914 * -EFAULT for non-successful reply or no reply (timeout)
3917 GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
3919 ConfigPageHeader_t hdr;
3921 FCPortPage0_t *ppage0_alloc;
3922 FCPortPage0_t *pp0dest;
3923 dma_addr_t page0_dma;
3928 /* Get FCPort Page 0 header */
3929 hdr.PageVersion = 0;
3932 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
3935 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3937 cfg.pageAddr = portnum;
3940 if ((rc = mpt_config(ioc, &cfg)) != 0)
3943 if (hdr.PageLength == 0)
3946 data_sz = hdr.PageLength * 4;
3948 ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
3950 memset((u8 *)ppage0_alloc, 0, data_sz);
3951 cfg.physAddr = page0_dma;
3952 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
3954 if ((rc = mpt_config(ioc, &cfg)) == 0) {
3956 pp0dest = &ioc->fc_port_page0[portnum];
3957 copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
3958 memcpy(pp0dest, ppage0_alloc, copy_sz);
3961 * Normalize endianness of structure data,
3962 * by byte-swapping all > 1 byte fields!
3964 pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
3965 pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
3966 pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
3967 pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
3968 pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
3969 pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
3970 pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
3971 pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
3972 pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
3973 pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
3974 pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
3975 pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
3976 pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
3977 pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
3978 pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
3979 pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
3983 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
3989 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3991 * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
3992 * @ioc: Pointer to MPT_ADAPTER structure
3994 * Returns: 0 for success
3995 * -ENOMEM if no memory available
3996 * -EPERM if not allowed due to ISR context
3997 * -EAGAIN if no msg frames currently available
3998 * -EFAULT for non-successful reply or no reply (timeout)
4001 GetIoUnitPage2(MPT_ADAPTER *ioc)
4003 ConfigPageHeader_t hdr;
4005 IOUnitPage2_t *ppage_alloc;
4006 dma_addr_t page_dma;
4010 /* Get the page header */
4011 hdr.PageVersion = 0;
4014 hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
4017 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4022 if ((rc = mpt_config(ioc, &cfg)) != 0)
4025 if (hdr.PageLength == 0)
4028 /* Read the config page */
4029 data_sz = hdr.PageLength * 4;
4031 ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
4033 memset((u8 *)ppage_alloc, 0, data_sz);
4034 cfg.physAddr = page_dma;
4035 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4037 /* If Good, save data */
4038 if ((rc = mpt_config(ioc, &cfg)) == 0)
4039 ioc->biosVersion = le32_to_cpu(ppage_alloc->BiosVersion);
4041 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage_alloc, page_dma);
4047 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4048 /* mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
4049 * @ioc: Pointer to a Adapter Strucutre
4050 * @portnum: IOC port number
4052 * Return: -EFAULT if read of config page header fails
4054 * If read of SCSI Port Page 0 fails,
4055 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
4056 * Adapter settings: async, narrow
4058 * If read of SCSI Port Page 2 fails,
4059 * Adapter settings valid
4060 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
4065 * CHECK - what type of locking mechanisms should be used????
4068 mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
4073 ConfigPageHeader_t header;
4079 if (!ioc->spi_data.nvram) {
4082 sz = MPT_MAX_SCSI_DEVICES * sizeof(int);
4083 mem = kmalloc(sz, GFP_ATOMIC);
4087 ioc->spi_data.nvram = (int *) mem;
4089 dprintk((MYIOC_s_INFO_FMT "SCSI device NVRAM settings @ %p, sz=%d\n",
4090 ioc->name, ioc->spi_data.nvram, sz));
4093 /* Invalidate NVRAM information
4095 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
4096 ioc->spi_data.nvram[ii] = MPT_HOST_NVRAM_INVALID;
4099 /* Read SPP0 header, allocate memory, then read page.
4101 header.PageVersion = 0;
4102 header.PageLength = 0;
4103 header.PageNumber = 0;
4104 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
4107 cfg.pageAddr = portnum;
4108 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4110 cfg.timeout = 0; /* use default */
4111 if (mpt_config(ioc, &cfg) != 0)
4114 if (header.PageLength > 0) {
4115 pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
4117 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4118 cfg.physAddr = buf_dma;
4119 if (mpt_config(ioc, &cfg) != 0) {
4120 ioc->spi_data.maxBusWidth = MPT_NARROW;
4121 ioc->spi_data.maxSyncOffset = 0;
4122 ioc->spi_data.minSyncFactor = MPT_ASYNC;
4123 ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
4126 /* Save the Port Page 0 data
4128 SCSIPortPage0_t *pPP0 = (SCSIPortPage0_t *) pbuf;
4129 pPP0->Capabilities = le32_to_cpu(pPP0->Capabilities);
4130 pPP0->PhysicalInterface = le32_to_cpu(pPP0->PhysicalInterface);
4132 if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
4133 ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
4134 dinitprintk((KERN_INFO MYNAM " :%s noQas due to Capabilities=%x\n",
4135 ioc->name, pPP0->Capabilities));
4137 ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
4138 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK;
4140 ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
4141 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
4142 ioc->spi_data.minSyncFactor = (u8) (data >> 8);
4144 ioc->spi_data.maxSyncOffset = 0;
4145 ioc->spi_data.minSyncFactor = MPT_ASYNC;
4148 ioc->spi_data.busType = pPP0->PhysicalInterface & MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK;
4150 /* Update the minSyncFactor based on bus type.
4152 if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
4153 (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
4155 if (ioc->spi_data.minSyncFactor < MPT_ULTRA)
4156 ioc->spi_data.minSyncFactor = MPT_ULTRA;
4160 pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
4165 /* SCSI Port Page 2 - Read the header then the page.
4167 header.PageVersion = 0;
4168 header.PageLength = 0;
4169 header.PageNumber = 2;
4170 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
4173 cfg.pageAddr = portnum;
4174 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4176 if (mpt_config(ioc, &cfg) != 0)
4179 if (header.PageLength > 0) {
4180 /* Allocate memory and read SCSI Port Page 2
4182 pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
4184 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_NVRAM;
4185 cfg.physAddr = buf_dma;
4186 if (mpt_config(ioc, &cfg) != 0) {
4187 /* Nvram data is left with INVALID mark
4191 SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t *) pbuf;
4192 MpiDeviceInfo_t *pdevice = NULL;
4194 /* Save the Port Page 2 data
4195 * (reformat into a 32bit quantity)
4197 data = le32_to_cpu(pPP2->PortFlags) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
4198 ioc->spi_data.PortFlags = data;
4199 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
4200 pdevice = &pPP2->DeviceSettings[ii];
4201 data = (le16_to_cpu(pdevice->DeviceFlags) << 16) |
4202 (pdevice->SyncFactor << 8) | pdevice->Timeout;
4203 ioc->spi_data.nvram[ii] = data;
4207 pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
4211 /* Update Adapter limits with those from NVRAM
4212 * Comment: Don't need to do this. Target performance
4213 * parameters will never exceed the adapters limits.
4219 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4220 /* mpt_readScsiDevicePageHeaders - save version and length of SDP1
4221 * @ioc: Pointer to a Adapter Strucutre
4222 * @portnum: IOC port number
4224 * Return: -EFAULT if read of config page header fails
4228 mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
4231 ConfigPageHeader_t header;
4233 /* Read the SCSI Device Page 1 header
4235 header.PageVersion = 0;
4236 header.PageLength = 0;
4237 header.PageNumber = 1;
4238 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4241 cfg.pageAddr = portnum;
4242 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4245 if (mpt_config(ioc, &cfg) != 0)
4248 ioc->spi_data.sdp1version = cfg.hdr->PageVersion;
4249 ioc->spi_data.sdp1length = cfg.hdr->PageLength;
4251 header.PageVersion = 0;
4252 header.PageLength = 0;
4253 header.PageNumber = 0;
4254 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4255 if (mpt_config(ioc, &cfg) != 0)
4258 ioc->spi_data.sdp0version = cfg.hdr->PageVersion;
4259 ioc->spi_data.sdp0length = cfg.hdr->PageLength;
4261 dcprintk((MYIOC_s_INFO_FMT "Headers: 0: version %d length %d\n",
4262 ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
4264 dcprintk((MYIOC_s_INFO_FMT "Headers: 1: version %d length %d\n",
4265 ioc->name, ioc->spi_data.sdp1version, ioc->spi_data.sdp1length));
4269 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4271 * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
4272 * @ioc: Pointer to a Adapter Strucutre
4273 * @portnum: IOC port number
4277 * -EFAULT if read of config page header fails or data pointer not NULL
4278 * -ENOMEM if pci_alloc failed
4281 mpt_findImVolumes(MPT_ADAPTER *ioc)
4285 ConfigPageIoc2RaidVol_t *pIocRv;
4286 dma_addr_t ioc2_dma;
4288 ConfigPageHeader_t header;
4295 /* Read IOCP2 header then the page.
4297 header.PageVersion = 0;
4298 header.PageLength = 0;
4299 header.PageNumber = 2;
4300 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4304 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4307 if (mpt_config(ioc, &cfg) != 0)
4310 if (header.PageLength == 0)
4313 iocpage2sz = header.PageLength * 4;
4314 pIoc2 = pci_alloc_consistent(ioc->pcidev, iocpage2sz, &ioc2_dma);
4318 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4319 cfg.physAddr = ioc2_dma;
4320 if (mpt_config(ioc, &cfg) != 0)
4323 if ( (mem = (u8 *)ioc->spi_data.pIocPg2) == NULL ) {
4324 mem = kmalloc(iocpage2sz, GFP_ATOMIC);
4326 ioc->spi_data.pIocPg2 = (IOCPage2_t *) mem;
4331 memcpy(mem, (u8 *)pIoc2, iocpage2sz);
4333 /* Identify RAID Volume Id's */
4334 nVols = pIoc2->NumActiveVolumes;
4340 /* At least 1 RAID Volume
4342 pIocRv = pIoc2->RaidVolume;
4343 ioc->spi_data.isRaid = 0;
4344 for (jj = 0; jj < nVols; jj++, pIocRv++) {
4345 vid = pIocRv->VolumeID;
4346 vbus = pIocRv->VolumeBus;
4347 vioc = pIocRv->VolumeIOC;
4352 ioc->spi_data.isRaid |= (1 << vid);
4354 /* Error! Always bus 0
4360 /* Identify Hidden Physical Disk Id's */
4361 nPhys = pIoc2->NumActivePhysDisks;
4363 /* No physical disks.
4366 mpt_read_ioc_pg_3(ioc);
4370 pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
4376 mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
4381 ConfigPageHeader_t header;
4382 dma_addr_t ioc3_dma;
4385 /* Free the old page
4387 kfree(ioc->spi_data.pIocPg3);
4388 ioc->spi_data.pIocPg3 = NULL;
4390 /* There is at least one physical disk.
4391 * Read and save IOC Page 3
4393 header.PageVersion = 0;
4394 header.PageLength = 0;
4395 header.PageNumber = 3;
4396 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4400 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4403 if (mpt_config(ioc, &cfg) != 0)
4406 if (header.PageLength == 0)
4409 /* Read Header good, alloc memory
4411 iocpage3sz = header.PageLength * 4;
4412 pIoc3 = pci_alloc_consistent(ioc->pcidev, iocpage3sz, &ioc3_dma);
4416 /* Read the Page and save the data
4417 * into malloc'd memory.
4419 cfg.physAddr = ioc3_dma;
4420 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4421 if (mpt_config(ioc, &cfg) == 0) {
4422 mem = kmalloc(iocpage3sz, GFP_ATOMIC);
4424 memcpy(mem, (u8 *)pIoc3, iocpage3sz);
4425 ioc->spi_data.pIocPg3 = (IOCPage3_t *) mem;
4429 pci_free_consistent(ioc->pcidev, iocpage3sz, pIoc3, ioc3_dma);
4435 mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
4439 ConfigPageHeader_t header;
4440 dma_addr_t ioc4_dma;
4443 /* Read and save IOC Page 4
4445 header.PageVersion = 0;
4446 header.PageLength = 0;
4447 header.PageNumber = 4;
4448 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4452 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4455 if (mpt_config(ioc, &cfg) != 0)
4458 if (header.PageLength == 0)
4461 if ( (pIoc4 = ioc->spi_data.pIocPg4) == NULL ) {
4462 iocpage4sz = (header.PageLength + 4) * 4; /* Allow 4 additional SEP's */
4463 pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
4467 ioc4_dma = ioc->spi_data.IocPg4_dma;
4468 iocpage4sz = ioc->spi_data.IocPg4Sz;
4471 /* Read the Page into dma memory.
4473 cfg.physAddr = ioc4_dma;
4474 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4475 if (mpt_config(ioc, &cfg) == 0) {
4476 ioc->spi_data.pIocPg4 = (IOCPage4_t *) pIoc4;
4477 ioc->spi_data.IocPg4_dma = ioc4_dma;
4478 ioc->spi_data.IocPg4Sz = iocpage4sz;
4480 pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
4481 ioc->spi_data.pIocPg4 = NULL;
4486 mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
4490 ConfigPageHeader_t header;
4491 dma_addr_t ioc1_dma;
4495 /* Check the Coalescing Timeout in IOC Page 1
4497 header.PageVersion = 0;
4498 header.PageLength = 0;
4499 header.PageNumber = 1;
4500 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4504 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4507 if (mpt_config(ioc, &cfg) != 0)
4510 if (header.PageLength == 0)
4513 /* Read Header good, alloc memory
4515 iocpage1sz = header.PageLength * 4;
4516 pIoc1 = pci_alloc_consistent(ioc->pcidev, iocpage1sz, &ioc1_dma);
4520 /* Read the Page and check coalescing timeout
4522 cfg.physAddr = ioc1_dma;
4523 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4524 if (mpt_config(ioc, &cfg) == 0) {
4526 tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
4527 if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
4528 tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
4530 dprintk((MYIOC_s_INFO_FMT "Coalescing Enabled Timeout = %d\n",
4533 if (tmp > MPT_COALESCING_TIMEOUT) {
4534 pIoc1->CoalescingTimeout = cpu_to_le32(MPT_COALESCING_TIMEOUT);
4536 /* Write NVRAM and current
4539 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
4540 if (mpt_config(ioc, &cfg) == 0) {
4541 dprintk((MYIOC_s_INFO_FMT "Reset Current Coalescing Timeout to = %d\n",
4542 ioc->name, MPT_COALESCING_TIMEOUT));
4544 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
4545 if (mpt_config(ioc, &cfg) == 0) {
4546 dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout to = %d\n",
4547 ioc->name, MPT_COALESCING_TIMEOUT));
4549 dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout Failed\n",
4554 dprintk((MYIOC_s_WARN_FMT "Reset of Current Coalescing Timeout Failed!\n",
4560 dprintk((MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
4564 pci_free_consistent(ioc->pcidev, iocpage1sz, pIoc1, ioc1_dma);
4569 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4571 * SendEventNotification - Send EventNotification (on or off) request
4573 * @ioc: Pointer to MPT_ADAPTER structure
4574 * @EvSwitch: Event switch flags
4577 SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch)
4579 EventNotification_t *evnp;
4581 evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc);
4583 dprintk((MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n",
4587 memset(evnp, 0, sizeof(*evnp));
4589 dprintk((MYIOC_s_INFO_FMT "Sending EventNotification(%d)\n", ioc->name, EvSwitch));
4591 evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
4592 evnp->ChainOffset = 0;
4594 evnp->Switch = EvSwitch;
4596 mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)evnp);
4601 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4603 * SendEventAck - Send EventAck request to MPT adapter.
4604 * @ioc: Pointer to MPT_ADAPTER structure
4605 * @evnp: Pointer to original EventNotification request
4608 SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
4612 if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
4613 printk(MYIOC_s_WARN_FMT "Unable to allocate event ACK request frame!\n",
4617 memset(pAck, 0, sizeof(*pAck));
4619 dprintk((MYIOC_s_INFO_FMT "Sending EventAck\n", ioc->name));
4621 pAck->Function = MPI_FUNCTION_EVENT_ACK;
4622 pAck->ChainOffset = 0;
4624 pAck->Event = evnp->Event;
4625 pAck->EventContext = evnp->EventContext;
4627 mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)pAck);
4632 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4634 * mpt_config - Generic function to issue config message
4635 * @ioc - Pointer to an adapter structure
4636 * @cfg - Pointer to a configuration structure. Struct contains
4637 * action, page address, direction, physical address
4638 * and pointer to a configuration page header
4639 * Page header is updated.
4641 * Returns 0 for success
4642 * -EPERM if not allowed due to ISR context
4643 * -EAGAIN if no msg frames currently available
4644 * -EFAULT for non-successful reply or no reply (timeout)
4647 mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
4651 unsigned long flags;
4656 /* Prevent calling wait_event() (below), if caller happens
4657 * to be in ISR context, because that is fatal!
4659 in_isr = in_interrupt();
4661 dcprintk((MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
4666 /* Get and Populate a free Frame
4668 if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
4669 dcprintk((MYIOC_s_WARN_FMT "mpt_config: no msg frames!\n",
4673 pReq = (Config_t *)mf;
4674 pReq->Action = pCfg->action;
4676 pReq->ChainOffset = 0;
4677 pReq->Function = MPI_FUNCTION_CONFIG;
4678 pReq->ExtPageLength = 0;
4679 pReq->ExtPageType = 0;
4681 for (ii=0; ii < 8; ii++)
4682 pReq->Reserved2[ii] = 0;
4684 pReq->Header.PageVersion = pCfg->hdr->PageVersion;
4685 pReq->Header.PageLength = pCfg->hdr->PageLength;
4686 pReq->Header.PageNumber = pCfg->hdr->PageNumber;
4687 pReq->Header.PageType = (pCfg->hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
4688 pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
4690 /* Add a SGE to the config request.
4693 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
4695 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
4697 flagsLength |= pCfg->hdr->PageLength * 4;
4699 mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
4701 dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
4702 ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
4704 /* Append pCfg pointer to end of mf
4706 *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
4708 /* Initalize the timer
4710 init_timer(&pCfg->timer);
4711 pCfg->timer.data = (unsigned long) ioc;
4712 pCfg->timer.function = mpt_timer_expired;
4713 pCfg->wait_done = 0;
4715 /* Set the timer; ensure 10 second minimum */
4716 if (pCfg->timeout < 10)
4717 pCfg->timer.expires = jiffies + HZ*10;
4719 pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
4721 /* Add to end of Q, set timer and then issue this command */
4722 spin_lock_irqsave(&ioc->FreeQlock, flags);
4723 list_add_tail(&pCfg->linkage, &ioc->configQ);
4724 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4726 add_timer(&pCfg->timer);
4727 mpt_put_msg_frame(mpt_base_index, ioc, mf);
4728 wait_event(mpt_waitq, pCfg->wait_done);
4730 /* mf has been freed - do not access */
4737 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4739 * mpt_toolbox - Generic function to issue toolbox message
4740 * @ioc - Pointer to an adapter structure
4741 * @cfg - Pointer to a toolbox structure. Struct contains
4742 * action, page address, direction, physical address
4743 * and pointer to a configuration page header
4744 * Page header is updated.
4746 * Returns 0 for success
4747 * -EPERM if not allowed due to ISR context
4748 * -EAGAIN if no msg frames currently available
4749 * -EFAULT for non-successful reply or no reply (timeout)
4752 mpt_toolbox(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
4754 ToolboxIstwiReadWriteRequest_t *pReq;
4756 struct pci_dev *pdev;
4757 unsigned long flags;
4762 /* Prevent calling wait_event() (below), if caller happens
4763 * to be in ISR context, because that is fatal!
4765 in_isr = in_interrupt();
4767 dcprintk((MYIOC_s_WARN_FMT "toobox request not allowed in ISR context!\n",
4772 /* Get and Populate a free Frame
4774 if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
4775 dcprintk((MYIOC_s_WARN_FMT "mpt_toolbox: no msg frames!\n",
4779 pReq = (ToolboxIstwiReadWriteRequest_t *)mf;
4780 pReq->Tool = pCfg->action;
4782 pReq->ChainOffset = 0;
4783 pReq->Function = MPI_FUNCTION_TOOLBOX;
4784 pReq->Reserved1 = 0;
4785 pReq->Reserved2 = 0;
4787 pReq->Flags = pCfg->dir;
4789 pReq->Reserved3 = 0;
4790 pReq->NumAddressBytes = 0x01;
4791 pReq->Reserved4 = 0;
4792 pReq->DataLength = 0x04;
4793 pdev = (struct pci_dev *) ioc->pcidev;
4794 if (pdev->devfn & 1)
4795 pReq->DeviceAddr = 0xB2;
4797 pReq->DeviceAddr = 0xB0;
4801 pReq->Reserved5 = 0;
4803 /* Add a SGE to the config request.
4806 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | 4;
4808 mpt_add_sge((char *)&pReq->SGL, flagsLength, pCfg->physAddr);
4810 dcprintk((MYIOC_s_INFO_FMT "Sending Toolbox request, Tool=%x\n",
4811 ioc->name, pReq->Tool));
4813 /* Append pCfg pointer to end of mf
4815 *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
4817 /* Initalize the timer
4819 init_timer(&pCfg->timer);
4820 pCfg->timer.data = (unsigned long) ioc;
4821 pCfg->timer.function = mpt_timer_expired;
4822 pCfg->wait_done = 0;
4824 /* Set the timer; ensure 10 second minimum */
4825 if (pCfg->timeout < 10)
4826 pCfg->timer.expires = jiffies + HZ*10;
4828 pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
4830 /* Add to end of Q, set timer and then issue this command */
4831 spin_lock_irqsave(&ioc->FreeQlock, flags);
4832 list_add_tail(&pCfg->linkage, &ioc->configQ);
4833 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4835 add_timer(&pCfg->timer);
4836 mpt_put_msg_frame(mpt_base_index, ioc, mf);
4837 wait_event(mpt_waitq, pCfg->wait_done);
4839 /* mf has been freed - do not access */
4846 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4848 * mpt_timer_expired - Call back for timer process.
4849 * Used only internal config functionality.
4850 * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
4853 mpt_timer_expired(unsigned long data)
4855 MPT_ADAPTER *ioc = (MPT_ADAPTER *) data;
4857 dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired! \n", ioc->name));
4859 /* Perform a FW reload */
4860 if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
4861 printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
4863 /* No more processing.
4864 * Hard reset clean-up will wake up
4865 * process and free all resources.
4867 dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired complete!\n", ioc->name));
4872 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4874 * mpt_ioc_reset - Base cleanup for hard reset
4875 * @ioc: Pointer to the adapter structure
4876 * @reset_phase: Indicates pre- or post-reset functionality
4878 * Remark: Free's resources with internally generated commands.
4881 mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
4884 unsigned long flags;
4886 dprintk((KERN_WARNING MYNAM
4887 ": IOC %s_reset routed to MPT base driver!\n",
4888 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
4889 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
4891 if (reset_phase == MPT_IOC_SETUP_RESET) {
4893 } else if (reset_phase == MPT_IOC_PRE_RESET) {
4894 /* If the internal config Q is not empty -
4895 * delete timer. MF resources will be freed when
4896 * the FIFO's are primed.
4898 spin_lock_irqsave(&ioc->FreeQlock, flags);
4899 list_for_each_entry(pCfg, &ioc->configQ, linkage)
4900 del_timer(&pCfg->timer);
4901 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4906 /* Search the configQ for internal commands.
4907 * Flush the Q, and wake up all suspended threads.
4909 spin_lock_irqsave(&ioc->FreeQlock, flags);
4910 list_for_each_entry_safe(pCfg, pNext, &ioc->configQ, linkage) {
4911 list_del(&pCfg->linkage);
4913 pCfg->status = MPT_CONFIG_ERROR;
4914 pCfg->wait_done = 1;
4915 wake_up(&mpt_waitq);
4917 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4920 return 1; /* currently means nothing really */
4924 #ifdef CONFIG_PROC_FS /* { */
4925 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4927 * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
4929 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4931 * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
4933 * Returns 0 for success, non-zero for failure.
4936 procmpt_create(void)
4938 struct proc_dir_entry *ent;
4940 mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
4941 if (mpt_proc_root_dir == NULL)
4944 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, mpt_proc_root_dir);
4946 ent->read_proc = procmpt_summary_read;
4948 ent = create_proc_entry("version", S_IFREG|S_IRUGO, mpt_proc_root_dir);
4950 ent->read_proc = procmpt_version_read;
4955 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4957 * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
4959 * Returns 0 for success, non-zero for failure.
4962 procmpt_destroy(void)
4964 remove_proc_entry("version", mpt_proc_root_dir);
4965 remove_proc_entry("summary", mpt_proc_root_dir);
4966 remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
4969 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4971 * procmpt_summary_read - Handle read request from /proc/mpt/summary
4972 * or from /proc/mpt/iocN/summary.
4973 * @buf: Pointer to area to write information
4974 * @start: Pointer to start pointer
4975 * @offset: Offset to start writing
4977 * @eof: Pointer to EOF integer
4980 * Returns number of characters written to process performing the read.
4983 procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
4993 mpt_print_ioc_summary(ioc, out, &more, 0, 1);
4997 list_for_each_entry(ioc, &ioc_list, list) {
5000 mpt_print_ioc_summary(ioc, out, &more, 0, 1);
5003 if ((out-buf) >= request)
5010 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5013 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5015 * procmpt_version_read - Handle read request from /proc/mpt/version.
5016 * @buf: Pointer to area to write information
5017 * @start: Pointer to start pointer
5018 * @offset: Offset to start writing
5020 * @eof: Pointer to EOF integer
5023 * Returns number of characters written to process performing the read.
5026 procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
5029 int scsi, fc, sas, lan, ctl, targ, dmp;
5033 len = sprintf(buf, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
5034 len += sprintf(buf+len, " Fusion MPT base driver\n");
5036 scsi = fc = sas = lan = ctl = targ = dmp = 0;
5037 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
5039 if (MptCallbacks[ii]) {
5040 switch (MptDriverClass[ii]) {
5042 if (!scsi++) drvname = "SPI host";
5045 if (!fc++) drvname = "FC host";
5048 if (!sas++) drvname = "SAS host";
5051 if (!lan++) drvname = "LAN";
5054 if (!targ++) drvname = "SCSI target";
5057 if (!ctl++) drvname = "ioctl";
5062 len += sprintf(buf+len, " Fusion MPT %s driver\n", drvname);
5066 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5069 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5071 * procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info.
5072 * @buf: Pointer to area to write information
5073 * @start: Pointer to start pointer
5074 * @offset: Offset to start writing
5076 * @eof: Pointer to EOF integer
5079 * Returns number of characters written to process performing the read.
5082 procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
5084 MPT_ADAPTER *ioc = data;
5090 mpt_get_fw_exp_ver(expVer, ioc);
5092 len = sprintf(buf, "%s:", ioc->name);
5093 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
5094 len += sprintf(buf+len, " (f/w download boot flag set)");
5095 // if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
5096 // len += sprintf(buf+len, " CONFIG_CHECKSUM_FAIL!");
5098 len += sprintf(buf+len, "\n ProductID = 0x%04x (%s)\n",
5099 ioc->facts.ProductID,
5101 len += sprintf(buf+len, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
5102 if (ioc->facts.FWImageSize)
5103 len += sprintf(buf+len, " (fw_size=%d)", ioc->facts.FWImageSize);
5104 len += sprintf(buf+len, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
5105 len += sprintf(buf+len, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
5106 len += sprintf(buf+len, " EventState = 0x%02x\n", ioc->facts.EventState);
5108 len += sprintf(buf+len, " CurrentHostMfaHighAddr = 0x%08x\n",
5109 ioc->facts.CurrentHostMfaHighAddr);
5110 len += sprintf(buf+len, " CurrentSenseBufferHighAddr = 0x%08x\n",
5111 ioc->facts.CurrentSenseBufferHighAddr);
5113 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
5114 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
5116 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
5117 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
5119 * Rounding UP to nearest 4-kB boundary here...
5121 sz = (ioc->req_sz * ioc->req_depth) + 128;
5122 sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
5123 len += sprintf(buf+len, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
5124 ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
5125 len += sprintf(buf+len, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
5126 4*ioc->facts.RequestFrameSize,
5127 ioc->facts.GlobalCredits);
5129 len += sprintf(buf+len, " Frames @ 0x%p (Dma @ 0x%p)\n",
5130 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
5131 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
5132 len += sprintf(buf+len, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
5133 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
5134 len += sprintf(buf+len, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
5135 ioc->facts.CurReplyFrameSize,
5136 ioc->facts.ReplyQueueDepth);
5138 len += sprintf(buf+len, " MaxDevices = %d\n",
5139 (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
5140 len += sprintf(buf+len, " MaxBuses = %d\n", ioc->facts.MaxBuses);
5143 for (p=0; p < ioc->facts.NumberOfPorts; p++) {
5144 len += sprintf(buf+len, " PortNumber = %d (of %d)\n",
5146 ioc->facts.NumberOfPorts);
5147 if (ioc->bus_type == FC) {
5148 if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
5149 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
5150 len += sprintf(buf+len, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
5151 a[5], a[4], a[3], a[2], a[1], a[0]);
5153 len += sprintf(buf+len, " WWN = %08X%08X:%08X%08X\n",
5154 ioc->fc_port_page0[p].WWNN.High,
5155 ioc->fc_port_page0[p].WWNN.Low,
5156 ioc->fc_port_page0[p].WWPN.High,
5157 ioc->fc_port_page0[p].WWPN.Low);
5161 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5164 #endif /* CONFIG_PROC_FS } */
5166 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5168 mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
5171 if ((ioc->facts.FWVersion.Word >> 24) == 0x0E) {
5172 sprintf(buf, " (Exp %02d%02d)",
5173 (ioc->facts.FWVersion.Word >> 16) & 0x00FF, /* Month */
5174 (ioc->facts.FWVersion.Word >> 8) & 0x1F); /* Day */
5177 if ((ioc->facts.FWVersion.Word >> 8) & 0x80)
5178 strcat(buf, " [MDBG]");
5182 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5184 * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
5185 * @ioc: Pointer to MPT_ADAPTER structure
5186 * @buffer: Pointer to buffer where IOC summary info should be written
5187 * @size: Pointer to number of bytes we wrote (set by this routine)
5188 * @len: Offset at which to start writing in buffer
5189 * @showlan: Display LAN stuff?
5191 * This routine writes (english readable) ASCII text, which represents
5192 * a summary of IOC information, to a buffer.
5195 mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
5200 mpt_get_fw_exp_ver(expVer, ioc);
5203 * Shorter summary of attached ioc's...
5205 y = sprintf(buffer+len, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
5208 MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
5209 ioc->facts.FWVersion.Word,
5211 ioc->facts.NumberOfPorts,
5214 if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
5215 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
5216 y += sprintf(buffer+len+y, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
5217 a[5], a[4], a[3], a[2], a[1], a[0]);
5221 y += sprintf(buffer+len+y, ", IRQ=%d", ioc->pci_irq);
5223 y += sprintf(buffer+len+y, ", IRQ=%s", __irq_itoa(ioc->pci_irq));
5227 y += sprintf(buffer+len+y, " (disabled)");
5229 y += sprintf(buffer+len+y, "\n");
5234 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5238 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5240 * mpt_HardResetHandler - Generic reset handler, issue SCSI Task
5241 * Management call based on input arg values. If TaskMgmt fails,
5242 * return associated SCSI request.
5243 * @ioc: Pointer to MPT_ADAPTER structure
5244 * @sleepFlag: Indicates if sleep or schedule must be called.
5246 * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
5247 * or a non-interrupt thread. In the former, must not call schedule().
5249 * Remark: A return of -1 is a FATAL error case, as it means a
5250 * FW reload/initialization failed.
5252 * Returns 0 for SUCCESS or -1 if FAILED.
5255 mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
5258 unsigned long flags;
5260 dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name));
5262 printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
5263 printk("MF count 0x%x !\n", ioc->mfcnt);
5266 /* Reset the adapter. Prevent more than 1 call to
5267 * mpt_do_ioc_recovery at any instant in time.
5269 spin_lock_irqsave(&ioc->diagLock, flags);
5270 if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)){
5271 spin_unlock_irqrestore(&ioc->diagLock, flags);
5274 ioc->diagPending = 1;
5276 spin_unlock_irqrestore(&ioc->diagLock, flags);
5278 /* FIXME: If do_ioc_recovery fails, repeat....
5281 /* The SCSI driver needs to adjust timeouts on all current
5282 * commands prior to the diagnostic reset being issued.
5283 * Prevents timeouts occuring during a diagnostic reset...very bad.
5284 * For all other protocol drivers, this is a no-op.
5290 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
5291 if (MptResetHandlers[ii]) {
5292 dtmprintk((MYIOC_s_INFO_FMT "Calling IOC reset_setup handler #%d\n",
5294 r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_SETUP_RESET);
5296 dtmprintk((MYIOC_s_INFO_FMT "Calling alt-%s setup reset handler #%d\n",
5297 ioc->name, ioc->alt_ioc->name, ii));
5298 r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_SETUP_RESET);
5304 if ((rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag)) != 0) {
5305 printk(KERN_WARNING MYNAM ": WARNING - (%d) Cannot recover %s\n",
5310 ioc->alt_ioc->reload_fw = 0;
5312 spin_lock_irqsave(&ioc->diagLock, flags);
5313 ioc->diagPending = 0;
5315 ioc->alt_ioc->diagPending = 0;
5316 spin_unlock_irqrestore(&ioc->diagLock, flags);
5318 dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler rc = %d!\n", ioc->name, rc));
5323 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5325 EventDescriptionStr(u8 event, u32 evData0)
5330 case MPI_EVENT_NONE:
5333 case MPI_EVENT_LOG_DATA:
5336 case MPI_EVENT_STATE_CHANGE:
5337 ds = "State Change";
5339 case MPI_EVENT_UNIT_ATTENTION:
5340 ds = "Unit Attention";
5342 case MPI_EVENT_IOC_BUS_RESET:
5343 ds = "IOC Bus Reset";
5345 case MPI_EVENT_EXT_BUS_RESET:
5346 ds = "External Bus Reset";
5348 case MPI_EVENT_RESCAN:
5349 ds = "Bus Rescan Event";
5350 /* Ok, do we need to do anything here? As far as
5351 I can tell, this is when a new device gets added
5354 case MPI_EVENT_LINK_STATUS_CHANGE:
5355 if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
5356 ds = "Link Status(FAILURE) Change";
5358 ds = "Link Status(ACTIVE) Change";
5360 case MPI_EVENT_LOOP_STATE_CHANGE:
5361 if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
5362 ds = "Loop State(LIP) Change";
5363 else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
5364 ds = "Loop State(LPE) Change"; /* ??? */
5366 ds = "Loop State(LPB) Change"; /* ??? */
5368 case MPI_EVENT_LOGOUT:
5371 case MPI_EVENT_EVENT_CHANGE:
5373 ds = "Events(ON) Change";
5375 ds = "Events(OFF) Change";
5377 case MPI_EVENT_INTEGRATED_RAID:
5378 ds = "Integrated Raid";
5381 * MPT base "custom" events may be added here...
5390 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5392 * ProcessEventNotification - Route a received EventNotificationReply to
5393 * all currently regeistered event handlers.
5394 * @ioc: Pointer to MPT_ADAPTER structure
5395 * @pEventReply: Pointer to EventNotification reply frame
5396 * @evHandlers: Pointer to integer, number of event handlers
5398 * Returns sum of event handlers return values.
5401 ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
5413 * Do platform normalization of values
5415 event = le32_to_cpu(pEventReply->Event) & 0xFF;
5416 // evCtx = le32_to_cpu(pEventReply->EventContext);
5417 evDataLen = le16_to_cpu(pEventReply->EventDataLength);
5419 evData0 = le32_to_cpu(pEventReply->Data[0]);
5422 evStr = EventDescriptionStr(event, evData0);
5423 devtprintk((MYIOC_s_INFO_FMT "MPT event (%s=%02Xh) detected!\n",
5428 #if defined(MPT_DEBUG) || defined(MPT_DEBUG_EVENTS)
5429 printk(KERN_INFO MYNAM ": Event data:\n" KERN_INFO);
5430 for (ii = 0; ii < evDataLen; ii++)
5431 printk(" %08x", le32_to_cpu(pEventReply->Data[ii]));
5436 * Do general / base driver event processing
5439 case MPI_EVENT_NONE: /* 00 */
5440 case MPI_EVENT_LOG_DATA: /* 01 */
5441 case MPI_EVENT_STATE_CHANGE: /* 02 */
5442 case MPI_EVENT_UNIT_ATTENTION: /* 03 */
5443 case MPI_EVENT_IOC_BUS_RESET: /* 04 */
5444 case MPI_EVENT_EXT_BUS_RESET: /* 05 */
5445 case MPI_EVENT_RESCAN: /* 06 */
5446 case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
5447 case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
5448 case MPI_EVENT_LOGOUT: /* 09 */
5449 case MPI_EVENT_INTEGRATED_RAID: /* 0B */
5450 case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE: /* 0C */
5453 case MPI_EVENT_EVENT_CHANGE: /* 0A */
5455 u8 evState = evData0 & 0xFF;
5457 /* CHECKME! What if evState unexpectedly says OFF (0)? */
5459 /* Update EventState field in cached IocFacts */
5460 if (ioc->facts.Function) {
5461 ioc->facts.EventState = evState;
5468 * Should this event be logged? Events are written sequentially.
5469 * When buffer is full, start again at the top.
5471 if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
5474 idx = ioc->eventContext % ioc->eventLogSize;
5476 ioc->events[idx].event = event;
5477 ioc->events[idx].eventContext = ioc->eventContext;
5479 for (ii = 0; ii < 2; ii++) {
5481 ioc->events[idx].data[ii] = le32_to_cpu(pEventReply->Data[ii]);
5483 ioc->events[idx].data[ii] = 0;
5486 ioc->eventContext++;
5491 * Call each currently registered protocol event handler.
5493 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
5494 if (MptEvHandlers[ii]) {
5495 devtprintk((MYIOC_s_INFO_FMT "Routing Event to event handler #%d\n",
5497 r += (*(MptEvHandlers[ii]))(ioc, pEventReply);
5501 /* FIXME? Examine results here? */
5504 * If needed, send (a single) EventAck.
5506 if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
5507 if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
5508 devtprintk((MYIOC_s_WARN_FMT "SendEventAck returned %d\n",
5513 *evHandlers = handlers;
5517 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5519 * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
5520 * @ioc: Pointer to MPT_ADAPTER structure
5521 * @log_info: U32 LogInfo reply word from the IOC
5523 * Refer to lsi/fc_log.h.
5526 mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
5528 static char *subcl_str[8] = {
5529 "FCP Initiator", "FCP Target", "LAN", "MPI Message Layer",
5530 "FC Link", "Context Manager", "Invalid Field Offset", "State Change Info"
5532 u8 subcl = (log_info >> 24) & 0x7;
5534 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): SubCl={%s}\n",
5535 ioc->name, log_info, subcl_str[subcl]);
5538 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5540 * mpt_sp_log_info - Log information returned from SCSI Parallel IOC.
5541 * @ioc: Pointer to MPT_ADAPTER structure
5542 * @mr: Pointer to MPT reply frame
5543 * @log_info: U32 LogInfo word from the IOC
5545 * Refer to lsi/sp_log.h.
5548 mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info)
5550 u32 info = log_info & 0x00FF0000;
5551 char *desc = "unknown";
5555 desc = "bug! MID not found";
5556 if (ioc->reload_fw == 0)
5561 desc = "Parity Error";
5565 desc = "ASYNC Outbound Overrun";
5569 desc = "SYNC Offset Error";
5577 desc = "Msg In Overflow";
5585 desc = "Outbound DMA Overrun";
5589 desc = "Task Management";
5593 desc = "Device Problem";
5597 desc = "Invalid Phase Change";
5601 desc = "Untagged Table Size";
5606 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
5609 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5611 * mpt_sp_ioc_info - IOC information returned from SCSI Parallel IOC.
5612 * @ioc: Pointer to MPT_ADAPTER structure
5613 * @ioc_status: U32 IOCStatus word from IOC
5614 * @mf: Pointer to MPT request frame
5616 * Refer to lsi/mpi.h.
5619 mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
5621 u32 status = ioc_status & MPI_IOCSTATUS_MASK;
5625 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
5626 desc = "Invalid Function";
5629 case MPI_IOCSTATUS_BUSY: /* 0x0002 */
5633 case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
5634 desc = "Invalid SGL";
5637 case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
5638 desc = "Internal Error";
5641 case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
5645 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
5646 desc = "Insufficient Resources";
5649 case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
5650 desc = "Invalid Field";
5653 case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
5654 desc = "Invalid State";
5657 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
5658 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
5659 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
5660 case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
5661 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
5662 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
5663 /* No message for Config IOCStatus values */
5666 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
5667 /* No message for recovered error
5668 desc = "SCSI Recovered Error";
5672 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
5673 desc = "SCSI Invalid Bus";
5676 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
5677 desc = "SCSI Invalid TargetID";
5680 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
5682 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
5683 U8 cdb = pScsiReq->CDB[0];
5684 if (cdb != 0x12) { /* Inquiry is issued for device scanning */
5685 desc = "SCSI Device Not There";
5690 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
5691 desc = "SCSI Data Overrun";
5694 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
5695 /* This error is checked in scsi_io_done(). Skip.
5696 desc = "SCSI Data Underrun";
5700 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
5701 desc = "SCSI I/O Data Error";
5704 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
5705 desc = "SCSI Protocol Error";
5708 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
5709 desc = "SCSI Task Terminated";
5712 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
5713 desc = "SCSI Residual Mismatch";
5716 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
5717 desc = "SCSI Task Management Failed";
5720 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
5721 desc = "SCSI IOC Terminated";
5724 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
5725 desc = "SCSI Ext Terminated";
5733 printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04x): %s\n", ioc->name, status, desc);
5736 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5737 EXPORT_SYMBOL(mpt_attach);
5738 EXPORT_SYMBOL(mpt_detach);
5740 EXPORT_SYMBOL(mpt_resume);
5741 EXPORT_SYMBOL(mpt_suspend);
5743 EXPORT_SYMBOL(ioc_list);
5744 EXPORT_SYMBOL(mpt_proc_root_dir);
5745 EXPORT_SYMBOL(mpt_register);
5746 EXPORT_SYMBOL(mpt_deregister);
5747 EXPORT_SYMBOL(mpt_event_register);
5748 EXPORT_SYMBOL(mpt_event_deregister);
5749 EXPORT_SYMBOL(mpt_reset_register);
5750 EXPORT_SYMBOL(mpt_reset_deregister);
5751 EXPORT_SYMBOL(mpt_device_driver_register);
5752 EXPORT_SYMBOL(mpt_device_driver_deregister);
5753 EXPORT_SYMBOL(mpt_get_msg_frame);
5754 EXPORT_SYMBOL(mpt_put_msg_frame);
5755 EXPORT_SYMBOL(mpt_free_msg_frame);
5756 EXPORT_SYMBOL(mpt_add_sge);
5757 EXPORT_SYMBOL(mpt_send_handshake_request);
5758 EXPORT_SYMBOL(mpt_verify_adapter);
5759 EXPORT_SYMBOL(mpt_GetIocState);
5760 EXPORT_SYMBOL(mpt_print_ioc_summary);
5761 EXPORT_SYMBOL(mpt_lan_index);
5762 EXPORT_SYMBOL(mpt_stm_index);
5763 EXPORT_SYMBOL(mpt_HardResetHandler);
5764 EXPORT_SYMBOL(mpt_config);
5765 EXPORT_SYMBOL(mpt_toolbox);
5766 EXPORT_SYMBOL(mpt_findImVolumes);
5767 EXPORT_SYMBOL(mpt_read_ioc_pg_3);
5768 EXPORT_SYMBOL(mpt_alloc_fw_memory);
5769 EXPORT_SYMBOL(mpt_free_fw_memory);
5772 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5774 * fusion_init - Fusion MPT base driver initialization routine.
5776 * Returns 0 for success, non-zero for failure.
5783 show_mptmod_ver(my_NAME, my_VERSION);
5784 printk(KERN_INFO COPYRIGHT "\n");
5786 for (i = 0; i < MPT_MAX_PROTOCOL_DRIVERS; i++) {
5787 MptCallbacks[i] = NULL;
5788 MptDriverClass[i] = MPTUNKNOWN_DRIVER;
5789 MptEvHandlers[i] = NULL;
5790 MptResetHandlers[i] = NULL;
5793 /* Register ourselves (mptbase) in order to facilitate
5794 * EventNotification handling.
5796 mpt_base_index = mpt_register(mpt_base_reply, MPTBASE_DRIVER);
5798 /* Register for hard reset handling callbacks.
5800 if (mpt_reset_register(mpt_base_index, mpt_ioc_reset) == 0) {
5801 dprintk((KERN_INFO MYNAM ": Register for IOC reset notification\n"));
5806 #ifdef CONFIG_PROC_FS
5807 (void) procmpt_create();
5812 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5814 * fusion_exit - Perform driver unload cleanup.
5816 * This routine frees all resources associated with each MPT adapter
5817 * and removes all %MPT_PROCFS_MPTBASEDIR entries.
5823 dexitprintk((KERN_INFO MYNAM ": fusion_exit() called!\n"));
5825 mpt_reset_deregister(mpt_base_index);
5827 #ifdef CONFIG_PROC_FS
5832 module_init(fusion_init);
5833 module_exit(fusion_exit);