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);
1369 device_state=1; /* D1 */;
1373 device_state=3; /* D3 */;
1376 return -EAGAIN /*FIXME*/;
1380 printk(MYIOC_s_INFO_FMT
1381 "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n",
1382 ioc->name, pdev, pci_name(pdev), device_state);
1384 pci_save_state(pdev);
1386 /* put ioc into READY_STATE */
1387 if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
1388 printk(MYIOC_s_ERR_FMT
1389 "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
1392 /* disable interrupts */
1393 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1396 /* Clear any lingering interrupt */
1397 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1399 pci_disable_device(pdev);
1400 pci_set_power_state(pdev, device_state);
1405 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1407 * mpt_resume - Fusion MPT base driver resume routine.
1412 mpt_resume(struct pci_dev *pdev)
1414 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1415 u32 device_state = pdev->current_state;
1419 printk(MYIOC_s_INFO_FMT
1420 "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n",
1421 ioc->name, pdev, pci_name(pdev), device_state);
1423 pci_set_power_state(pdev, 0);
1424 pci_restore_state(pdev);
1425 pci_enable_device(pdev);
1427 /* enable interrupts */
1428 CHIPREG_WRITE32(&ioc->chip->IntMask, ~(MPI_HIM_RIM));
1431 /* F/W not running */
1432 if(!CHIPREG_READ32(&ioc->chip->Doorbell)) {
1433 /* enable domain validation flags */
1434 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
1435 ioc->spi_data.dvStatus[ii] |= MPT_SCSICFG_NEED_DV;
1439 printk(MYIOC_s_INFO_FMT
1440 "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
1442 (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
1443 CHIPREG_READ32(&ioc->chip->Doorbell));
1445 /* bring ioc to operational state */
1446 if ((recovery_state = mpt_do_ioc_recovery(ioc,
1447 MPT_HOSTEVENT_IOC_RECOVER, CAN_SLEEP)) != 0) {
1448 printk(MYIOC_s_INFO_FMT
1449 "pci-resume: Cannot recover, error:[%x]\n",
1450 ioc->name, recovery_state);
1452 printk(MYIOC_s_INFO_FMT
1453 "pci-resume: success\n", ioc->name);
1460 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1462 * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
1463 * @ioc: Pointer to MPT adapter structure
1464 * @reason: Event word / reason
1465 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
1467 * This routine performs all the steps necessary to bring the IOC
1468 * to a OPERATIONAL state.
1470 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1475 * -1 if failed to get board READY
1476 * -2 if READY but IOCFacts Failed
1477 * -3 if READY but PrimeIOCFifos Failed
1478 * -4 if READY but IOCInit Failed
1481 mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1483 int hard_reset_done = 0;
1484 int alt_ioc_ready = 0;
1490 int reset_alt_ioc_active = 0;
1492 printk(KERN_INFO MYNAM ": Initiating %s %s\n",
1493 ioc->name, reason==MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
1495 /* Disable reply interrupts (also blocks FreeQ) */
1496 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1500 if (ioc->alt_ioc->active)
1501 reset_alt_ioc_active = 1;
1503 /* Disable alt-IOC's reply interrupts (and FreeQ) for a bit ... */
1504 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, 0xFFFFFFFF);
1505 ioc->alt_ioc->active = 0;
1509 if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
1512 if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
1513 if (hard_reset_done == -4) {
1514 printk(KERN_WARNING MYNAM ": %s Owned by PEER..skipping!\n",
1517 if (reset_alt_ioc_active && ioc->alt_ioc) {
1518 /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
1519 dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
1520 ioc->alt_ioc->name));
1521 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM));
1522 ioc->alt_ioc->active = 1;
1526 printk(KERN_WARNING MYNAM ": %s NOT READY WARNING!\n",
1532 /* hard_reset_done = 0 if a soft reset was performed
1533 * and 1 if a hard reset was performed.
1535 if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
1536 if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
1539 printk(KERN_WARNING MYNAM
1540 ": alt-%s: Not ready WARNING!\n",
1541 ioc->alt_ioc->name);
1544 for (ii=0; ii<5; ii++) {
1545 /* Get IOC facts! Allow 5 retries */
1546 if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
1552 dinitprintk((MYIOC_s_INFO_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc));
1554 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1555 MptDisplayIocCapabilities(ioc);
1558 if (alt_ioc_ready) {
1559 if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
1560 dinitprintk((MYIOC_s_INFO_FMT "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc));
1561 /* Retry - alt IOC was initialized once
1563 rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
1566 dinitprintk((MYIOC_s_INFO_FMT "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
1568 reset_alt_ioc_active = 0;
1569 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1570 MptDisplayIocCapabilities(ioc->alt_ioc);
1574 /* Prime reply & request queues!
1575 * (mucho alloc's) Must be done prior to
1576 * init as upper addresses are needed for init.
1577 * If fails, continue with alt-ioc processing
1579 if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
1582 /* May need to check/upload firmware & data here!
1583 * If fails, continue with alt-ioc processing
1585 if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
1588 if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
1589 printk(KERN_WARNING MYNAM ": alt-%s: (%d) FIFO mgmt alloc WARNING!\n",
1590 ioc->alt_ioc->name, rc);
1592 reset_alt_ioc_active = 0;
1595 if (alt_ioc_ready) {
1596 if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
1598 reset_alt_ioc_active = 0;
1599 printk(KERN_WARNING MYNAM
1600 ": alt-%s: (%d) init failure WARNING!\n",
1601 ioc->alt_ioc->name, rc);
1605 if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
1606 if (ioc->upload_fw) {
1607 ddlprintk((MYIOC_s_INFO_FMT
1608 "firmware upload required!\n", ioc->name));
1610 /* Controller is not operational, cannot do upload
1613 rc = mpt_do_upload(ioc, sleepFlag);
1615 printk(KERN_WARNING MYNAM ": firmware upload failure!\n");
1621 /* Enable! (reply interrupt) */
1622 CHIPREG_WRITE32(&ioc->chip->IntMask, ~(MPI_HIM_RIM));
1626 if (reset_alt_ioc_active && ioc->alt_ioc) {
1627 /* (re)Enable alt-IOC! (reply interrupt) */
1628 dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
1629 ioc->alt_ioc->name));
1630 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM));
1631 ioc->alt_ioc->active = 1;
1634 /* Enable MPT base driver management of EventNotification
1635 * and EventAck handling.
1637 if ((ret == 0) && (!ioc->facts.EventState))
1638 (void) SendEventNotification(ioc, 1); /* 1=Enable EventNotification */
1640 if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
1641 (void) SendEventNotification(ioc->alt_ioc, 1); /* 1=Enable EventNotification */
1643 /* Add additional "reason" check before call to GetLanConfigPages
1644 * (combined with GetIoUnitPage2 call). This prevents a somewhat
1645 * recursive scenario; GetLanConfigPages times out, timer expired
1646 * routine calls HardResetHandler, which calls into here again,
1647 * and we try GetLanConfigPages again...
1649 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
1650 if (ioc->bus_type == FC) {
1652 * Pre-fetch FC port WWN and stuff...
1653 * (FCPortPage0_t stuff)
1655 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1656 (void) GetFcPortPage0(ioc, ii);
1659 if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
1660 (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
1662 * Pre-fetch the ports LAN MAC address!
1663 * (LANPage1_t stuff)
1665 (void) GetLanConfigPages(ioc);
1668 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
1669 dprintk((MYIOC_s_INFO_FMT "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1670 ioc->name, a[5], a[4], a[3], a[2], a[1], a[0] ));
1675 /* Get NVRAM and adapter maximums from SPP 0 and 2
1677 mpt_GetScsiPortSettings(ioc, 0);
1679 /* Get version and length of SDP 1
1681 mpt_readScsiDevicePageHeaders(ioc, 0);
1685 if (ioc->facts.MsgVersion >= 0x0102)
1686 mpt_findImVolumes(ioc);
1688 /* Check, and possibly reset, the coalescing value
1690 mpt_read_ioc_pg_1(ioc);
1692 mpt_read_ioc_pg_4(ioc);
1695 GetIoUnitPage2(ioc);
1699 * Call each currently registered protocol IOC reset handler
1700 * with post-reset indication.
1701 * NOTE: If we're doing _IOC_BRINGUP, there can be no
1702 * MptResetHandlers[] registered yet.
1704 if (hard_reset_done) {
1706 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
1707 if ((ret == 0) && MptResetHandlers[ii]) {
1708 dprintk((MYIOC_s_INFO_FMT "Calling IOC post_reset handler #%d\n",
1710 rc += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_POST_RESET);
1714 if (alt_ioc_ready && MptResetHandlers[ii]) {
1715 dprintk((MYIOC_s_INFO_FMT "Calling alt-%s post_reset handler #%d\n",
1716 ioc->name, ioc->alt_ioc->name, ii));
1717 rc += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_POST_RESET);
1721 /* FIXME? Examine results here? */
1727 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1729 * mpt_detect_bound_ports - Search for PCI bus/dev_function
1730 * which matches PCI bus/dev_function (+/-1) for newly discovered 929,
1731 * 929X, 1030 or 1035.
1732 * @ioc: Pointer to MPT adapter structure
1733 * @pdev: Pointer to (struct pci_dev) structure
1735 * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
1736 * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
1739 mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
1741 struct pci_dev *peer=NULL;
1742 unsigned int slot = PCI_SLOT(pdev->devfn);
1743 unsigned int func = PCI_FUNC(pdev->devfn);
1744 MPT_ADAPTER *ioc_srch;
1746 dprintk((MYIOC_s_INFO_FMT "PCI device %s devfn=%x/%x,"
1747 " searching for devfn match on %x or %x\n",
1748 ioc->name, pci_name(pdev), pdev->devfn,
1751 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
1753 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func+1));
1758 list_for_each_entry(ioc_srch, &ioc_list, list) {
1759 struct pci_dev *_pcidev = ioc_srch->pcidev;
1760 if (_pcidev == peer) {
1761 /* Paranoia checks */
1762 if (ioc->alt_ioc != NULL) {
1763 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
1764 ioc->name, ioc->alt_ioc->name);
1766 } else if (ioc_srch->alt_ioc != NULL) {
1767 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
1768 ioc_srch->name, ioc_srch->alt_ioc->name);
1771 dprintk((KERN_INFO MYNAM ": FOUND! binding %s <==> %s\n",
1772 ioc->name, ioc_srch->name));
1773 ioc_srch->alt_ioc = ioc;
1774 ioc->alt_ioc = ioc_srch;
1780 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1782 * mpt_adapter_disable - Disable misbehaving MPT adapter.
1783 * @this: Pointer to MPT adapter structure
1786 mpt_adapter_disable(MPT_ADAPTER *ioc)
1791 if (ioc->cached_fw != NULL) {
1792 ddlprintk((KERN_INFO MYNAM ": mpt_adapter_disable: Pushing FW onto adapter\n"));
1793 if ((ret = mpt_downloadboot(ioc, NO_SLEEP)) < 0) {
1794 printk(KERN_WARNING MYNAM
1795 ": firmware downloadboot failure (%d)!\n", ret);
1799 /* Disable adapter interrupts! */
1800 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1802 /* Clear any lingering interrupt */
1803 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1805 if (ioc->alloc != NULL) {
1807 dexitprintk((KERN_INFO MYNAM ": %s.free @ %p, sz=%d bytes\n",
1808 ioc->name, ioc->alloc, ioc->alloc_sz));
1809 pci_free_consistent(ioc->pcidev, sz,
1810 ioc->alloc, ioc->alloc_dma);
1811 ioc->reply_frames = NULL;
1812 ioc->req_frames = NULL;
1814 ioc->alloc_total -= sz;
1817 if (ioc->sense_buf_pool != NULL) {
1818 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
1819 pci_free_consistent(ioc->pcidev, sz,
1820 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
1821 ioc->sense_buf_pool = NULL;
1822 ioc->alloc_total -= sz;
1825 if (ioc->events != NULL){
1826 sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
1829 ioc->alloc_total -= sz;
1832 if (ioc->cached_fw != NULL) {
1833 sz = ioc->facts.FWImageSize;
1834 pci_free_consistent(ioc->pcidev, sz,
1835 ioc->cached_fw, ioc->cached_fw_dma);
1836 ioc->cached_fw = NULL;
1837 ioc->alloc_total -= sz;
1840 kfree(ioc->spi_data.nvram);
1841 kfree(ioc->spi_data.pIocPg3);
1842 ioc->spi_data.nvram = NULL;
1843 ioc->spi_data.pIocPg3 = NULL;
1845 if (ioc->spi_data.pIocPg4 != NULL) {
1846 sz = ioc->spi_data.IocPg4Sz;
1847 pci_free_consistent(ioc->pcidev, sz,
1848 ioc->spi_data.pIocPg4,
1849 ioc->spi_data.IocPg4_dma);
1850 ioc->spi_data.pIocPg4 = NULL;
1851 ioc->alloc_total -= sz;
1854 if (ioc->ReqToChain != NULL) {
1855 kfree(ioc->ReqToChain);
1856 kfree(ioc->RequestNB);
1857 ioc->ReqToChain = NULL;
1860 kfree(ioc->ChainToChain);
1861 ioc->ChainToChain = NULL;
1864 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1866 * mpt_adapter_dispose - Free all resources associated with a MPT
1868 * @ioc: Pointer to MPT adapter structure
1870 * This routine unregisters h/w resources and frees all alloc'd memory
1871 * associated with a MPT adapter structure.
1874 mpt_adapter_dispose(MPT_ADAPTER *ioc)
1877 int sz_first, sz_last;
1879 sz_first = ioc->alloc_total;
1881 mpt_adapter_disable(ioc);
1883 if (ioc->pci_irq != -1) {
1884 free_irq(ioc->pci_irq, ioc);
1888 if (ioc->memmap != NULL)
1889 iounmap(ioc->memmap);
1891 #if defined(CONFIG_MTRR) && 0
1892 if (ioc->mtrr_reg > 0) {
1893 mtrr_del(ioc->mtrr_reg, 0, 0);
1894 dprintk((KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
1898 /* Zap the adapter lookup ptr! */
1899 list_del(&ioc->list);
1901 sz_last = ioc->alloc_total;
1902 dprintk((KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
1903 ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
1908 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1910 * MptDisplayIocCapabilities - Disply IOC's capacilities.
1911 * @ioc: Pointer to MPT adapter structure
1914 MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
1918 printk(KERN_INFO "%s: ", ioc->name);
1919 if (ioc->prod_name && strlen(ioc->prod_name) > 3)
1920 printk("%s: ", ioc->prod_name+3);
1921 printk("Capabilities={");
1923 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
1924 printk("Initiator");
1928 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
1929 printk("%sTarget", i ? "," : "");
1933 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
1934 printk("%sLAN", i ? "," : "");
1940 * This would probably evoke more questions than it's worth
1942 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
1943 printk("%sLogBusAddr", i ? "," : "");
1951 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1953 * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
1954 * @ioc: Pointer to MPT_ADAPTER structure
1955 * @force: Force hard KickStart of IOC
1956 * @sleepFlag: Specifies whether the process can sleep
1959 * 1 - DIAG reset and READY
1960 * 0 - READY initially OR soft reset and READY
1961 * -1 - Any failure on KickStart
1962 * -2 - Msg Unit Reset Failed
1963 * -3 - IO Unit Reset Failed
1964 * -4 - IOC owned by a PEER
1967 MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
1972 int hard_reset_done = 0;
1977 /* Get current [raw] IOC state */
1978 ioc_state = mpt_GetIocState(ioc, 0);
1979 dhsprintk((KERN_INFO MYNAM "::MakeIocReady, %s [raw] state=%08x\n", ioc->name, ioc_state));
1982 * Check to see if IOC got left/stuck in doorbell handshake
1983 * grip of death. If so, hard reset the IOC.
1985 if (ioc_state & MPI_DOORBELL_ACTIVE) {
1987 printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
1991 /* Is it already READY? */
1992 if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
1996 * Check to see if IOC is in FAULT state.
1998 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
2000 printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
2002 printk(KERN_WARNING " FAULT code = %04xh\n",
2003 ioc_state & MPI_DOORBELL_DATA_MASK);
2007 * Hmmm... Did it get left operational?
2009 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
2010 dinitprintk((MYIOC_s_WARN_FMT "IOC operational unexpected\n",
2014 * If PCI Peer, exit.
2015 * Else, if no fault conditions are present, issue a MessageUnitReset
2016 * Else, fall through to KickStart case
2018 whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
2019 dprintk((KERN_WARNING MYNAM
2020 ": whoinit 0x%x\n statefault %d force %d\n",
2021 whoinit, statefault, force));
2022 if (whoinit == MPI_WHOINIT_PCI_PEER)
2025 if ((statefault == 0 ) && (force == 0)) {
2026 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
2033 hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
2034 if (hard_reset_done < 0)
2038 * Loop here waiting for IOC to come READY.
2041 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
2043 while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
2044 if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
2046 * BIOS or previous driver load left IOC in OP state.
2047 * Reset messaging FIFOs.
2049 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
2050 printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
2053 } else if (ioc_state == MPI_IOC_STATE_RESET) {
2055 * Something is wrong. Try to get IOC back
2058 if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
2059 printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
2066 printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
2067 ioc->name, (int)((ii+5)/HZ));
2071 if (sleepFlag == CAN_SLEEP) {
2072 msleep_interruptible(1);
2074 mdelay (1); /* 1 msec delay */
2079 if (statefault < 3) {
2080 printk(MYIOC_s_INFO_FMT "Recovered from %s\n",
2082 statefault==1 ? "stuck handshake" : "IOC FAULT");
2085 return hard_reset_done;
2088 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2090 * mpt_GetIocState - Get the current state of a MPT adapter.
2091 * @ioc: Pointer to MPT_ADAPTER structure
2092 * @cooked: Request raw or cooked IOC state
2094 * Returns all IOC Doorbell register bits if cooked==0, else just the
2095 * Doorbell bits in MPI_IOC_STATE_MASK.
2098 mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
2103 s = CHIPREG_READ32(&ioc->chip->Doorbell);
2104 // dprintk((MYIOC_s_INFO_FMT "raw state = %08x\n", ioc->name, s));
2105 sc = s & MPI_IOC_STATE_MASK;
2108 ioc->last_state = sc;
2110 return cooked ? sc : s;
2113 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2115 * GetIocFacts - Send IOCFacts request to MPT adapter.
2116 * @ioc: Pointer to MPT_ADAPTER structure
2117 * @sleepFlag: Specifies whether the process can sleep
2118 * @reason: If recovery, only update facts.
2120 * Returns 0 for success, non-zero for failure.
2123 GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2125 IOCFacts_t get_facts;
2126 IOCFactsReply_t *facts;
2134 /* IOC *must* NOT be in RESET state! */
2135 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2136 printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
2142 facts = &ioc->facts;
2144 /* Destination (reply area)... */
2145 reply_sz = sizeof(*facts);
2146 memset(facts, 0, reply_sz);
2148 /* Request area (get_facts on the stack right now!) */
2149 req_sz = sizeof(get_facts);
2150 memset(&get_facts, 0, req_sz);
2152 get_facts.Function = MPI_FUNCTION_IOC_FACTS;
2153 /* Assert: All other get_facts fields are zero! */
2155 dinitprintk((MYIOC_s_INFO_FMT
2156 "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
2157 ioc->name, req_sz, reply_sz));
2159 /* No non-zero fields in the get_facts request are greater than
2160 * 1 byte in size, so we can just fire it off as is.
2162 r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
2163 reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
2168 * Now byte swap (GRRR) the necessary fields before any further
2169 * inspection of reply contents.
2171 * But need to do some sanity checks on MsgLength (byte) field
2172 * to make sure we don't zero IOC's req_sz!
2174 /* Did we get a valid reply? */
2175 if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
2176 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2178 * If not been here, done that, save off first WhoInit value
2180 if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
2181 ioc->FirstWhoInit = facts->WhoInit;
2184 facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
2185 facts->MsgContext = le32_to_cpu(facts->MsgContext);
2186 facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
2187 facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
2188 facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
2189 status = facts->IOCStatus & MPI_IOCSTATUS_MASK;
2190 /* CHECKME! IOCStatus, IOCLogInfo */
2192 facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
2193 facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
2196 * FC f/w version changed between 1.1 and 1.2
2197 * Old: u16{Major(4),Minor(4),SubMinor(8)}
2198 * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
2200 if (facts->MsgVersion < 0x0102) {
2202 * Handle old FC f/w style, convert to new...
2204 u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
2205 facts->FWVersion.Word =
2206 ((oldv<<12) & 0xFF000000) |
2207 ((oldv<<8) & 0x000FFF00);
2209 facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
2211 facts->ProductID = le16_to_cpu(facts->ProductID);
2212 facts->CurrentHostMfaHighAddr =
2213 le32_to_cpu(facts->CurrentHostMfaHighAddr);
2214 facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
2215 facts->CurrentSenseBufferHighAddr =
2216 le32_to_cpu(facts->CurrentSenseBufferHighAddr);
2217 facts->CurReplyFrameSize =
2218 le16_to_cpu(facts->CurReplyFrameSize);
2221 * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
2222 * Older MPI-1.00.xx struct had 13 dwords, and enlarged
2223 * to 14 in MPI-1.01.0x.
2225 if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
2226 facts->MsgVersion > 0x0100) {
2227 facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
2230 sz = facts->FWImageSize;
2235 facts->FWImageSize = sz;
2237 if (!facts->RequestFrameSize) {
2238 /* Something is wrong! */
2239 printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
2244 r = sz = facts->BlockSize;
2245 vv = ((63 / (sz * 4)) + 1) & 0x03;
2246 ioc->NB_for_64_byte_frame = vv;
2252 ioc->NBShiftFactor = shiftFactor;
2253 dinitprintk((MYIOC_s_INFO_FMT "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
2254 ioc->name, vv, shiftFactor, r));
2256 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2258 * Set values for this IOC's request & reply frame sizes,
2259 * and request & reply queue depths...
2261 ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
2262 ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
2263 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
2264 ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
2266 dinitprintk((MYIOC_s_INFO_FMT "reply_sz=%3d, reply_depth=%4d\n",
2267 ioc->name, ioc->reply_sz, ioc->reply_depth));
2268 dinitprintk((MYIOC_s_INFO_FMT "req_sz =%3d, req_depth =%4d\n",
2269 ioc->name, ioc->req_sz, ioc->req_depth));
2271 /* Get port facts! */
2272 if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
2276 printk(MYIOC_s_ERR_FMT
2277 "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
2278 ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
2279 RequestFrameSize)/sizeof(u32)));
2286 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2288 * GetPortFacts - Send PortFacts request to MPT adapter.
2289 * @ioc: Pointer to MPT_ADAPTER structure
2290 * @portnum: Port number
2291 * @sleepFlag: Specifies whether the process can sleep
2293 * Returns 0 for success, non-zero for failure.
2296 GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2298 PortFacts_t get_pfacts;
2299 PortFactsReply_t *pfacts;
2304 /* IOC *must* NOT be in RESET state! */
2305 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2306 printk(KERN_ERR MYNAM ": ERROR - Can't get PortFacts, %s NOT READY! (%08x)\n",
2312 pfacts = &ioc->pfacts[portnum];
2314 /* Destination (reply area)... */
2315 reply_sz = sizeof(*pfacts);
2316 memset(pfacts, 0, reply_sz);
2318 /* Request area (get_pfacts on the stack right now!) */
2319 req_sz = sizeof(get_pfacts);
2320 memset(&get_pfacts, 0, req_sz);
2322 get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
2323 get_pfacts.PortNumber = portnum;
2324 /* Assert: All other get_pfacts fields are zero! */
2326 dinitprintk((MYIOC_s_INFO_FMT "Sending get PortFacts(%d) request\n",
2327 ioc->name, portnum));
2329 /* No non-zero fields in the get_pfacts request are greater than
2330 * 1 byte in size, so we can just fire it off as is.
2332 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
2333 reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
2337 /* Did we get a valid reply? */
2339 /* Now byte swap the necessary fields in the response. */
2340 pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
2341 pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
2342 pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
2343 pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
2344 pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
2345 pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
2346 pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
2347 pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
2348 pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
2353 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2355 * SendIocInit - Send IOCInit request to MPT adapter.
2356 * @ioc: Pointer to MPT_ADAPTER structure
2357 * @sleepFlag: Specifies whether the process can sleep
2359 * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
2361 * Returns 0 for success, non-zero for failure.
2364 SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
2367 MPIDefaultReply_t init_reply;
2373 memset(&ioc_init, 0, sizeof(ioc_init));
2374 memset(&init_reply, 0, sizeof(init_reply));
2376 ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
2377 ioc_init.Function = MPI_FUNCTION_IOC_INIT;
2379 /* If we are in a recovery mode and we uploaded the FW image,
2380 * then this pointer is not NULL. Skip the upload a second time.
2381 * Set this flag if cached_fw set for either IOC.
2383 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
2387 ddlprintk((MYIOC_s_INFO_FMT "upload_fw %d facts.Flags=%x\n",
2388 ioc->name, ioc->upload_fw, ioc->facts.Flags));
2390 if (ioc->bus_type == FC)
2391 ioc_init.MaxDevices = MPT_MAX_FC_DEVICES;
2393 ioc_init.MaxDevices = MPT_MAX_SCSI_DEVICES;
2395 ioc_init.MaxBuses = MPT_MAX_BUS;
2397 ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
2399 if (sizeof(dma_addr_t) == sizeof(u64)) {
2400 /* Save the upper 32-bits of the request
2401 * (reply) and sense buffers.
2403 ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
2404 ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2406 /* Force 32-bit addressing */
2407 ioc_init.HostMfaHighAddr = cpu_to_le32(0);
2408 ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
2411 ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
2412 ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
2414 dhsprintk((MYIOC_s_INFO_FMT "Sending IOCInit (req @ %p)\n",
2415 ioc->name, &ioc_init));
2417 r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
2418 sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
2422 /* No need to byte swap the multibyte fields in the reply
2423 * since we don't even look at it's contents.
2426 dhsprintk((MYIOC_s_INFO_FMT "Sending PortEnable (req @ %p)\n",
2427 ioc->name, &ioc_init));
2429 if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0)
2432 /* YIKES! SUPER IMPORTANT!!!
2433 * Poll IocState until _OPERATIONAL while IOC is doing
2434 * LoopInit and TargetDiscovery!
2437 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
2438 state = mpt_GetIocState(ioc, 1);
2439 while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
2440 if (sleepFlag == CAN_SLEEP) {
2441 msleep_interruptible(1);
2447 printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
2448 ioc->name, (int)((count+5)/HZ));
2452 state = mpt_GetIocState(ioc, 1);
2455 dhsprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
2461 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2463 * SendPortEnable - Send PortEnable request to MPT adapter port.
2464 * @ioc: Pointer to MPT_ADAPTER structure
2465 * @portnum: Port number to enable
2466 * @sleepFlag: Specifies whether the process can sleep
2468 * Send PortEnable to bring IOC to OPERATIONAL state.
2470 * Returns 0 for success, non-zero for failure.
2473 SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2475 PortEnable_t port_enable;
2476 MPIDefaultReply_t reply_buf;
2481 /* Destination... */
2482 reply_sz = sizeof(MPIDefaultReply_t);
2483 memset(&reply_buf, 0, reply_sz);
2485 req_sz = sizeof(PortEnable_t);
2486 memset(&port_enable, 0, req_sz);
2488 port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
2489 port_enable.PortNumber = portnum;
2490 /* port_enable.ChainOffset = 0; */
2491 /* port_enable.MsgFlags = 0; */
2492 /* port_enable.MsgContext = 0; */
2494 dinitprintk((MYIOC_s_INFO_FMT "Sending Port(%d)Enable (req @ %p)\n",
2495 ioc->name, portnum, &port_enable));
2497 /* RAID FW may take a long time to enable
2499 if (ioc->bus_type == FC) {
2500 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
2501 reply_sz, (u16*)&reply_buf, 65 /*seconds*/, sleepFlag);
2503 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
2504 reply_sz, (u16*)&reply_buf, 300 /*seconds*/, sleepFlag);
2510 /* We do not even look at the reply, so we need not
2511 * swap the multi-byte fields.
2518 * ioc: Pointer to MPT_ADAPTER structure
2519 * size - total FW bytes
2522 mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
2525 return; /* use already allocated memory */
2526 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
2527 ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
2528 ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
2530 if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
2531 ioc->alloc_total += size;
2535 * If alt_img is NULL, delete from ioc structure.
2536 * Else, delete a secondary image in same format.
2539 mpt_free_fw_memory(MPT_ADAPTER *ioc)
2543 sz = ioc->facts.FWImageSize;
2544 dinitprintk((KERN_WARNING MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
2545 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2546 pci_free_consistent(ioc->pcidev, sz,
2547 ioc->cached_fw, ioc->cached_fw_dma);
2548 ioc->cached_fw = NULL;
2554 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2556 * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
2557 * @ioc: Pointer to MPT_ADAPTER structure
2558 * @sleepFlag: Specifies whether the process can sleep
2560 * Returns 0 for success, >0 for handshake failure
2561 * <0 for fw upload failure.
2563 * Remark: If bound IOC and a successful FWUpload was performed
2564 * on the bound IOC, the second image is discarded
2565 * and memory is free'd. Both channels must upload to prevent
2566 * IOC from running in degraded mode.
2569 mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
2571 u8 request[ioc->req_sz];
2572 u8 reply[sizeof(FWUploadReply_t)];
2573 FWUpload_t *prequest;
2574 FWUploadReply_t *preply;
2575 FWUploadTCSGE_t *ptcsge;
2578 int ii, sz, reply_sz;
2581 /* If the image size is 0, we are done.
2583 if ((sz = ioc->facts.FWImageSize) == 0)
2586 mpt_alloc_fw_memory(ioc, sz);
2588 dinitprintk((KERN_WARNING MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
2589 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2591 if (ioc->cached_fw == NULL) {
2597 prequest = (FWUpload_t *)&request;
2598 preply = (FWUploadReply_t *)&reply;
2600 /* Destination... */
2601 memset(prequest, 0, ioc->req_sz);
2603 reply_sz = sizeof(reply);
2604 memset(preply, 0, reply_sz);
2606 prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
2607 prequest->Function = MPI_FUNCTION_FW_UPLOAD;
2609 ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
2610 ptcsge->DetailsLength = 12;
2611 ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
2612 ptcsge->ImageSize = cpu_to_le32(sz);
2614 sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
2616 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
2617 mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
2619 sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
2620 dinitprintk((KERN_WARNING MYNAM "Sending FW Upload (req @ %p) sgeoffset=%d \n",
2621 prequest, sgeoffset));
2622 DBG_DUMP_FW_REQUEST_FRAME(prequest)
2624 ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
2625 reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
2627 dinitprintk((KERN_WARNING MYNAM "FW Upload completed rc=%x \n", ii));
2629 cmdStatus = -EFAULT;
2631 /* Handshake transfer was complete and successful.
2632 * Check the Reply Frame.
2634 int status, transfer_sz;
2635 status = le16_to_cpu(preply->IOCStatus);
2636 if (status == MPI_IOCSTATUS_SUCCESS) {
2637 transfer_sz = le32_to_cpu(preply->ActualImageSize);
2638 if (transfer_sz == sz)
2642 dinitprintk((MYIOC_s_INFO_FMT ": do_upload status %d \n",
2643 ioc->name, cmdStatus));
2648 ddlprintk((MYIOC_s_INFO_FMT ": fw upload failed, freeing image \n",
2650 mpt_free_fw_memory(ioc);
2656 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2658 * mpt_downloadboot - DownloadBoot code
2659 * @ioc: Pointer to MPT_ADAPTER structure
2660 * @flag: Specify which part of IOC memory is to be uploaded.
2661 * @sleepFlag: Specifies whether the process can sleep
2663 * FwDownloadBoot requires Programmed IO access.
2665 * Returns 0 for success
2666 * -1 FW Image size is 0
2667 * -2 No valid cached_fw Pointer
2668 * <0 for fw upload failure.
2671 mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag)
2673 MpiFwHeader_t *pFwHeader;
2674 MpiExtImageHeader_t *pExtImage;
2684 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: fw size 0x%x, ioc FW Ptr %p\n",
2685 ioc->name, ioc->facts.FWImageSize, ioc->cached_fw));
2687 if ( ioc->facts.FWImageSize == 0 )
2690 if (ioc->cached_fw == NULL)
2693 /* prevent a second downloadboot and memory free with alt_ioc */
2694 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
2695 ioc->alt_ioc->cached_fw = NULL;
2697 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2698 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2699 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2700 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2701 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2702 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2704 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
2707 if (sleepFlag == CAN_SLEEP) {
2708 msleep_interruptible(1);
2713 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2714 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
2716 for (count = 0; count < 30; count ++) {
2717 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2718 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
2719 ddlprintk((MYIOC_s_INFO_FMT "RESET_ADAPTER cleared, count=%d\n",
2724 if (sleepFlag == CAN_SLEEP) {
2725 msleep_interruptible (1000);
2731 if ( count == 30 ) {
2732 ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! Unable to RESET_ADAPTER diag0val=%x\n",
2733 ioc->name, diag0val));
2737 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2738 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2739 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2740 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2741 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2742 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2744 /* Set the DiagRwEn and Disable ARM bits */
2745 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
2747 pFwHeader = (MpiFwHeader_t *) ioc->cached_fw;
2748 fwSize = (pFwHeader->ImageSize + 3)/4;
2749 ptrFw = (u32 *) pFwHeader;
2751 /* Write the LoadStartAddress to the DiagRw Address Register
2752 * using Programmed IO
2754 if (ioc->errata_flag_1064)
2755 pci_enable_io_access(ioc->pcidev);
2757 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
2758 ddlprintk((MYIOC_s_INFO_FMT "LoadStart addr written 0x%x \n",
2759 ioc->name, pFwHeader->LoadStartAddress));
2761 ddlprintk((MYIOC_s_INFO_FMT "Write FW Image: 0x%x bytes @ %p\n",
2762 ioc->name, fwSize*4, ptrFw));
2764 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
2767 nextImage = pFwHeader->NextImageHeaderOffset;
2769 pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
2771 load_addr = pExtImage->LoadStartAddress;
2773 fwSize = (pExtImage->ImageSize + 3) >> 2;
2774 ptrFw = (u32 *)pExtImage;
2776 ddlprintk((MYIOC_s_INFO_FMT "Write Ext Image: 0x%x bytes @ %p load_addr=%x\n",
2777 ioc->name, fwSize*4, ptrFw, load_addr));
2778 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
2781 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
2783 nextImage = pExtImage->NextImageHeaderOffset;
2786 /* Write the IopResetVectorRegAddr */
2787 ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
2788 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
2790 /* Write the IopResetVectorValue */
2791 ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
2792 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
2794 /* Clear the internal flash bad bit - autoincrementing register,
2795 * so must do two writes.
2797 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
2798 diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
2799 diagRwData |= 0x4000000;
2800 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
2801 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
2803 if (ioc->errata_flag_1064)
2804 pci_disable_io_access(ioc->pcidev);
2806 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2807 ddlprintk((MYIOC_s_INFO_FMT "downloadboot diag0val=%x, turning off PREVENT_IOC_BOOT, DISABLE_ARM\n",
2808 ioc->name, diag0val));
2809 diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM);
2810 ddlprintk((MYIOC_s_INFO_FMT "downloadboot now diag0val=%x\n",
2811 ioc->name, diag0val));
2812 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
2814 /* Write 0xFF to reset the sequencer */
2815 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2817 for (count=0; count<HZ*20; count++) {
2818 if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
2819 ddlprintk((MYIOC_s_INFO_FMT "downloadboot successful! (count=%d) IocState=%x\n",
2820 ioc->name, count, ioc_state));
2821 if ((SendIocInit(ioc, sleepFlag)) != 0) {
2822 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit failed\n",
2826 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit successful\n",
2830 if (sleepFlag == CAN_SLEEP) {
2831 msleep_interruptible (10);
2836 ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! IocState=%x\n",
2837 ioc->name, ioc_state));
2841 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2843 * KickStart - Perform hard reset of MPT adapter.
2844 * @ioc: Pointer to MPT_ADAPTER structure
2845 * @force: Force hard reset
2846 * @sleepFlag: Specifies whether the process can sleep
2848 * This routine places MPT adapter in diagnostic mode via the
2849 * WriteSequence register, and then performs a hard reset of adapter
2850 * via the Diagnostic register.
2852 * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
2853 * or NO_SLEEP (interrupt thread, use mdelay)
2854 * force - 1 if doorbell active, board fault state
2855 * board operational, IOC_RECOVERY or
2856 * IOC_BRINGUP and there is an alt_ioc.
2860 * 1 - hard reset, READY
2861 * 0 - no reset due to History bit, READY
2862 * -1 - no reset due to History bit but not READY
2863 * OR reset but failed to come READY
2864 * -2 - no reset, could not enter DIAG mode
2865 * -3 - reset but bad FW bit
2868 KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
2870 int hard_reset_done = 0;
2874 dinitprintk((KERN_WARNING MYNAM ": KickStarting %s!\n", ioc->name));
2875 if (ioc->bus_type == SCSI) {
2876 /* Always issue a Msg Unit Reset first. This will clear some
2877 * SCSI bus hang conditions.
2879 SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
2881 if (sleepFlag == CAN_SLEEP) {
2882 msleep_interruptible (1000);
2888 hard_reset_done = mpt_diag_reset(ioc, force, sleepFlag);
2889 if (hard_reset_done < 0)
2890 return hard_reset_done;
2892 dinitprintk((MYIOC_s_INFO_FMT "Diagnostic reset successful!\n",
2895 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2; /* 2 seconds */
2896 for (cnt=0; cnt<cntdn; cnt++) {
2897 ioc_state = mpt_GetIocState(ioc, 1);
2898 if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
2899 dinitprintk((MYIOC_s_INFO_FMT "KickStart successful! (cnt=%d)\n",
2901 return hard_reset_done;
2903 if (sleepFlag == CAN_SLEEP) {
2904 msleep_interruptible (10);
2910 printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
2911 ioc->name, ioc_state);
2915 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2917 * mpt_diag_reset - Perform hard reset of the adapter.
2918 * @ioc: Pointer to MPT_ADAPTER structure
2919 * @ignore: Set if to honor and clear to ignore
2920 * the reset history bit
2921 * @sleepflag: CAN_SLEEP if called in a non-interrupt thread,
2922 * else set to NO_SLEEP (use mdelay instead)
2924 * This routine places the adapter in diagnostic mode via the
2925 * WriteSequence register and then performs a hard reset of adapter
2926 * via the Diagnostic register. Adapter should be in ready state
2927 * upon successful completion.
2929 * Returns: 1 hard reset successful
2930 * 0 no reset performed because reset history bit set
2931 * -2 enabling diagnostic mode failed
2932 * -3 diagnostic reset failed
2935 mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
2939 int hard_reset_done = 0;
2945 /* Clear any existing interrupts */
2946 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
2948 /* Use "Diagnostic reset" method! (only thing available!) */
2949 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2953 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
2954 dprintk((MYIOC_s_INFO_FMT "DbG1: diag0=%08x, diag1=%08x\n",
2955 ioc->name, diag0val, diag1val));
2958 /* Do the reset if we are told to ignore the reset history
2959 * or if the reset history is 0
2961 if (ignore || !(diag0val & MPI_DIAG_RESET_HISTORY)) {
2962 while ((diag0val & MPI_DIAG_DRWE) == 0) {
2963 /* Write magic sequence to WriteSequence register
2964 * Loop until in diagnostic mode
2966 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2967 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2968 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2969 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2970 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2971 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2974 if (sleepFlag == CAN_SLEEP) {
2975 msleep_interruptible (100);
2982 printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
2983 ioc->name, diag0val);
2988 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2990 dprintk((MYIOC_s_INFO_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
2991 ioc->name, diag0val));
2996 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
2997 dprintk((MYIOC_s_INFO_FMT "DbG2: diag0=%08x, diag1=%08x\n",
2998 ioc->name, diag0val, diag1val));
3001 * Disable the ARM (Bug fix)
3004 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
3008 * Now hit the reset bit in the Diagnostic register
3009 * (THE BIG HAMMER!) (Clears DRWE bit).
3011 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
3012 hard_reset_done = 1;
3013 dprintk((MYIOC_s_INFO_FMT "Diagnostic reset performed\n",
3017 * Call each currently registered protocol IOC reset handler
3018 * with pre-reset indication.
3019 * NOTE: If we're doing _IOC_BRINGUP, there can be no
3020 * MptResetHandlers[] registered yet.
3026 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
3027 if (MptResetHandlers[ii]) {
3028 dprintk((MYIOC_s_INFO_FMT "Calling IOC pre_reset handler #%d\n",
3030 r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_PRE_RESET);
3032 dprintk((MYIOC_s_INFO_FMT "Calling alt-%s pre_reset handler #%d\n",
3033 ioc->name, ioc->alt_ioc->name, ii));
3034 r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_PRE_RESET);
3038 /* FIXME? Examine results here? */
3041 if (ioc->cached_fw) {
3042 /* If the DownloadBoot operation fails, the
3043 * IOC will be left unusable. This is a fatal error
3044 * case. _diag_reset will return < 0
3046 for (count = 0; count < 30; count ++) {
3047 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3048 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
3053 if (sleepFlag == CAN_SLEEP) {
3059 if ((count = mpt_downloadboot(ioc, sleepFlag)) < 0) {
3060 printk(KERN_WARNING MYNAM
3061 ": firmware downloadboot failure (%d)!\n", count);
3065 /* Wait for FW to reload and for board
3066 * to go to the READY state.
3067 * Maximum wait is 60 seconds.
3068 * If fail, no error will check again
3069 * with calling program.
3071 for (count = 0; count < 60; count ++) {
3072 doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
3073 doorbell &= MPI_IOC_STATE_MASK;
3075 if (doorbell == MPI_IOC_STATE_READY) {
3080 if (sleepFlag == CAN_SLEEP) {
3081 msleep_interruptible (1000);
3089 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3092 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3093 dprintk((MYIOC_s_INFO_FMT "DbG3: diag0=%08x, diag1=%08x\n",
3094 ioc->name, diag0val, diag1val));
3097 /* Clear RESET_HISTORY bit! Place board in the
3098 * diagnostic mode to update the diag register.
3100 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3102 while ((diag0val & MPI_DIAG_DRWE) == 0) {
3103 /* Write magic sequence to WriteSequence register
3104 * Loop until in diagnostic mode
3106 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
3107 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
3108 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
3109 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
3110 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
3111 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
3114 if (sleepFlag == CAN_SLEEP) {
3115 msleep_interruptible (100);
3122 printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
3123 ioc->name, diag0val);
3126 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3128 diag0val &= ~MPI_DIAG_RESET_HISTORY;
3129 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
3130 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3131 if (diag0val & MPI_DIAG_RESET_HISTORY) {
3132 printk(MYIOC_s_WARN_FMT "ResetHistory bit failed to clear!\n",
3136 /* Disable Diagnostic Mode
3138 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFFFFFFFF);
3140 /* Check FW reload status flags.
3142 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3143 if (diag0val & (MPI_DIAG_FLASH_BAD_SIG | MPI_DIAG_RESET_ADAPTER | MPI_DIAG_DISABLE_ARM)) {
3144 printk(MYIOC_s_ERR_FMT "Diagnostic reset FAILED! (%02xh)\n",
3145 ioc->name, diag0val);
3151 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3152 dprintk((MYIOC_s_INFO_FMT "DbG4: diag0=%08x, diag1=%08x\n",
3153 ioc->name, diag0val, diag1val));
3157 * Reset flag that says we've enabled event notification
3159 ioc->facts.EventState = 0;
3162 ioc->alt_ioc->facts.EventState = 0;
3164 return hard_reset_done;
3167 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3169 * SendIocReset - Send IOCReset request to MPT adapter.
3170 * @ioc: Pointer to MPT_ADAPTER structure
3171 * @reset_type: reset type, expected values are
3172 * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
3174 * Send IOCReset request to the MPT adapter.
3176 * Returns 0 for success, non-zero for failure.
3179 SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
3185 drsprintk((KERN_WARNING MYNAM ": %s: Sending IOC reset(0x%02x)!\n",
3186 ioc->name, reset_type));
3187 CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
3188 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3191 /* FW ACK'd request, wait for READY state
3194 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
3196 while ((state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
3200 if (sleepFlag != CAN_SLEEP)
3203 printk(KERN_ERR MYNAM ": %s: ERROR - Wait IOC_READY state timeout(%d)!\n",
3204 ioc->name, (int)((count+5)/HZ));
3208 if (sleepFlag == CAN_SLEEP) {
3209 msleep_interruptible(1);
3211 mdelay (1); /* 1 msec delay */
3216 * Cleanup all event stuff for this IOC; re-issue EventNotification
3217 * request if needed.
3219 if (ioc->facts.Function)
3220 ioc->facts.EventState = 0;
3225 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3227 * initChainBuffers - Allocate memory for and initialize
3228 * chain buffers, chain buffer control arrays and spinlock.
3229 * @hd: Pointer to MPT_SCSI_HOST structure
3230 * @init: If set, initialize the spin lock.
3233 initChainBuffers(MPT_ADAPTER *ioc)
3236 int sz, ii, num_chain;
3237 int scale, num_sge, numSGE;
3239 /* ReqToChain size must equal the req_depth
3242 if (ioc->ReqToChain == NULL) {
3243 sz = ioc->req_depth * sizeof(int);
3244 mem = kmalloc(sz, GFP_ATOMIC);
3248 ioc->ReqToChain = (int *) mem;
3249 dinitprintk((KERN_INFO MYNAM ": %s ReqToChain alloc @ %p, sz=%d bytes\n",
3250 ioc->name, mem, sz));
3251 mem = kmalloc(sz, GFP_ATOMIC);
3255 ioc->RequestNB = (int *) mem;
3256 dinitprintk((KERN_INFO MYNAM ": %s RequestNB alloc @ %p, sz=%d bytes\n",
3257 ioc->name, mem, sz));
3259 for (ii = 0; ii < ioc->req_depth; ii++) {
3260 ioc->ReqToChain[ii] = MPT_HOST_NO_CHAIN;
3263 /* ChainToChain size must equal the total number
3264 * of chain buffers to be allocated.
3267 * Calculate the number of chain buffers needed(plus 1) per I/O
3268 * then multiply the the maximum number of simultaneous cmds
3270 * num_sge = num sge in request frame + last chain buffer
3271 * scale = num sge per chain buffer if no chain element
3273 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
3274 if (sizeof(dma_addr_t) == sizeof(u64))
3275 num_sge = scale + (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
3277 num_sge = 1+ scale + (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
3279 if (sizeof(dma_addr_t) == sizeof(u64)) {
3280 numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
3281 (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
3283 numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
3284 (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
3286 dinitprintk((KERN_INFO MYNAM ": %s num_sge=%d numSGE=%d\n",
3287 ioc->name, num_sge, numSGE));
3289 if ( numSGE > MPT_SCSI_SG_DEPTH )
3290 numSGE = MPT_SCSI_SG_DEPTH;
3293 while (numSGE - num_sge > 0) {
3295 num_sge += (scale - 1);
3299 dinitprintk((KERN_INFO MYNAM ": %s Now numSGE=%d num_sge=%d num_chain=%d\n",
3300 ioc->name, numSGE, num_sge, num_chain));
3302 if (ioc->bus_type == SCSI)
3303 num_chain *= MPT_SCSI_CAN_QUEUE;
3305 num_chain *= MPT_FC_CAN_QUEUE;
3307 ioc->num_chain = num_chain;
3309 sz = num_chain * sizeof(int);
3310 if (ioc->ChainToChain == NULL) {
3311 mem = kmalloc(sz, GFP_ATOMIC);
3315 ioc->ChainToChain = (int *) mem;
3316 dinitprintk((KERN_INFO MYNAM ": %s ChainToChain alloc @ %p, sz=%d bytes\n",
3317 ioc->name, mem, sz));
3319 mem = (u8 *) ioc->ChainToChain;
3321 memset(mem, 0xFF, sz);
3325 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3327 * PrimeIocFifos - Initialize IOC request and reply FIFOs.
3328 * @ioc: Pointer to MPT_ADAPTER structure
3330 * This routine allocates memory for the MPT reply and request frame
3331 * pools (if necessary), and primes the IOC reply FIFO with
3334 * Returns 0 for success, non-zero for failure.
3337 PrimeIocFifos(MPT_ADAPTER *ioc)
3340 unsigned long flags;
3341 dma_addr_t alloc_dma;
3343 int i, reply_sz, sz, total_size, num_chain;
3345 /* Prime reply FIFO... */
3347 if (ioc->reply_frames == NULL) {
3348 if ( (num_chain = initChainBuffers(ioc)) < 0)
3351 total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
3352 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
3353 ioc->name, ioc->reply_sz, ioc->reply_depth));
3354 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d[%x] bytes\n",
3355 ioc->name, reply_sz, reply_sz));
3357 sz = (ioc->req_sz * ioc->req_depth);
3358 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d bytes, RequestDepth=%d\n",
3359 ioc->name, ioc->req_sz, ioc->req_depth));
3360 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d[%x] bytes\n",
3361 ioc->name, sz, sz));
3364 sz = num_chain * ioc->req_sz; /* chain buffer pool size */
3365 dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d bytes, ChainDepth=%d\n",
3366 ioc->name, ioc->req_sz, num_chain));
3367 dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
3368 ioc->name, sz, sz, num_chain));
3371 mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
3373 printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
3378 dinitprintk((KERN_INFO MYNAM ": %s.Total alloc @ %p[%p], sz=%d[%x] bytes\n",
3379 ioc->name, mem, (void *)(ulong)alloc_dma, total_size, total_size));
3381 memset(mem, 0, total_size);
3382 ioc->alloc_total += total_size;
3384 ioc->alloc_dma = alloc_dma;
3385 ioc->alloc_sz = total_size;
3386 ioc->reply_frames = (MPT_FRAME_HDR *) mem;
3387 ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
3389 alloc_dma += reply_sz;
3392 /* Request FIFO - WE manage this! */
3394 ioc->req_frames = (MPT_FRAME_HDR *) mem;
3395 ioc->req_frames_dma = alloc_dma;
3397 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffers @ %p[%p]\n",
3398 ioc->name, mem, (void *)(ulong)alloc_dma));
3400 ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
3402 #if defined(CONFIG_MTRR) && 0
3404 * Enable Write Combining MTRR for IOC's memory region.
3405 * (at least as much as we can; "size and base must be
3406 * multiples of 4 kiB"
3408 ioc->mtrr_reg = mtrr_add(ioc->req_frames_dma,
3410 MTRR_TYPE_WRCOMB, 1);
3411 dprintk((MYIOC_s_INFO_FMT "MTRR region registered (base:size=%08x:%x)\n",
3412 ioc->name, ioc->req_frames_dma, sz));
3415 for (i = 0; i < ioc->req_depth; i++) {
3416 alloc_dma += ioc->req_sz;
3420 ioc->ChainBuffer = mem;
3421 ioc->ChainBufferDMA = alloc_dma;
3423 dinitprintk((KERN_INFO MYNAM " :%s.ChainBuffers @ %p(%p)\n",
3424 ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
3426 /* Initialize the free chain Q.
3429 INIT_LIST_HEAD(&ioc->FreeChainQ);
3431 /* Post the chain buffers to the FreeChainQ.
3433 mem = (u8 *)ioc->ChainBuffer;
3434 for (i=0; i < num_chain; i++) {
3435 mf = (MPT_FRAME_HDR *) mem;
3436 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeChainQ);
3440 /* Initialize Request frames linked list
3442 alloc_dma = ioc->req_frames_dma;
3443 mem = (u8 *) ioc->req_frames;
3445 spin_lock_irqsave(&ioc->FreeQlock, flags);
3446 INIT_LIST_HEAD(&ioc->FreeQ);
3447 for (i = 0; i < ioc->req_depth; i++) {
3448 mf = (MPT_FRAME_HDR *) mem;
3450 /* Queue REQUESTs *internally*! */
3451 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
3455 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
3457 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
3458 ioc->sense_buf_pool =
3459 pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
3460 if (ioc->sense_buf_pool == NULL) {
3461 printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
3466 ioc->sense_buf_low_dma = (u32) (ioc->sense_buf_pool_dma & 0xFFFFFFFF);
3467 ioc->alloc_total += sz;
3468 dinitprintk((KERN_INFO MYNAM ": %s.SenseBuffers @ %p[%p]\n",
3469 ioc->name, ioc->sense_buf_pool, (void *)(ulong)ioc->sense_buf_pool_dma));
3473 /* Post Reply frames to FIFO
3475 alloc_dma = ioc->alloc_dma;
3476 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffers @ %p[%p]\n",
3477 ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
3479 for (i = 0; i < ioc->reply_depth; i++) {
3480 /* Write each address to the IOC! */
3481 CHIPREG_WRITE32(&ioc->chip->ReplyFifo, alloc_dma);
3482 alloc_dma += ioc->reply_sz;
3488 if (ioc->alloc != NULL) {
3490 pci_free_consistent(ioc->pcidev,
3492 ioc->alloc, ioc->alloc_dma);
3493 ioc->reply_frames = NULL;
3494 ioc->req_frames = NULL;
3495 ioc->alloc_total -= sz;
3497 if (ioc->sense_buf_pool != NULL) {
3498 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
3499 pci_free_consistent(ioc->pcidev,
3501 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
3502 ioc->sense_buf_pool = NULL;
3507 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3509 * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
3510 * from IOC via doorbell handshake method.
3511 * @ioc: Pointer to MPT_ADAPTER structure
3512 * @reqBytes: Size of the request in bytes
3513 * @req: Pointer to MPT request frame
3514 * @replyBytes: Expected size of the reply in bytes
3515 * @u16reply: Pointer to area where reply should be written
3516 * @maxwait: Max wait time for a reply (in seconds)
3517 * @sleepFlag: Specifies whether the process can sleep
3519 * NOTES: It is the callers responsibility to byte-swap fields in the
3520 * request which are greater than 1 byte in size. It is also the
3521 * callers responsibility to byte-swap response fields which are
3522 * greater than 1 byte in size.
3524 * Returns 0 for success, non-zero for failure.
3527 mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
3528 int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
3530 MPIDefaultReply_t *mptReply;
3535 * Get ready to cache a handshake reply
3537 ioc->hs_reply_idx = 0;
3538 mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
3539 mptReply->MsgLength = 0;
3542 * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
3543 * then tell IOC that we want to handshake a request of N words.
3544 * (WRITE u32val to Doorbell reg).
3546 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3547 CHIPREG_WRITE32(&ioc->chip->Doorbell,
3548 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
3549 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
3552 * Wait for IOC's doorbell handshake int
3554 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3557 dhsprintk((MYIOC_s_INFO_FMT "HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
3558 ioc->name, reqBytes, t, failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
3560 /* Read doorbell and check for active bit */
3561 if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
3565 * Clear doorbell int (WRITE 0 to IntStatus reg),
3566 * then wait for IOC to ACKnowledge that it's ready for
3567 * our handshake request.
3569 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3570 if (!failcnt && (t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3575 u8 *req_as_bytes = (u8 *) req;
3578 * Stuff request words via doorbell handshake,
3579 * with ACK from IOC for each.
3581 for (ii = 0; !failcnt && ii < reqBytes/4; ii++) {
3582 u32 word = ((req_as_bytes[(ii*4) + 0] << 0) |
3583 (req_as_bytes[(ii*4) + 1] << 8) |
3584 (req_as_bytes[(ii*4) + 2] << 16) |
3585 (req_as_bytes[(ii*4) + 3] << 24));
3587 CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
3588 if ((t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3592 dhsprintk((KERN_INFO MYNAM ": Handshake request frame (@%p) header\n", req));
3593 DBG_DUMP_REQUEST_FRAME_HDR(req)
3595 dhsprintk((MYIOC_s_INFO_FMT "HandShake request post done, WaitCnt=%d%s\n",
3596 ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
3599 * Wait for completion of doorbell handshake reply from the IOC
3601 if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
3604 dhsprintk((MYIOC_s_INFO_FMT "HandShake reply count=%d%s\n",
3605 ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
3608 * Copy out the cached reply...
3610 for (ii=0; ii < min(replyBytes/2,mptReply->MsgLength*2); ii++)
3611 u16reply[ii] = ioc->hs_reply[ii];
3619 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3621 * WaitForDoorbellAck - Wait for IOC to clear the IOP_DOORBELL_STATUS bit
3622 * in it's IntStatus register.
3623 * @ioc: Pointer to MPT_ADAPTER structure
3624 * @howlong: How long to wait (in seconds)
3625 * @sleepFlag: Specifies whether the process can sleep
3627 * This routine waits (up to ~2 seconds max) for IOC doorbell
3628 * handshake ACKnowledge.
3630 * Returns a negative value on failure, else wait loop count.
3633 WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3639 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
3641 if (sleepFlag == CAN_SLEEP) {
3643 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3644 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
3646 msleep_interruptible (1);
3651 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3652 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
3660 dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell ACK (count=%d)\n",
3665 printk(MYIOC_s_ERR_FMT "Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
3666 ioc->name, count, intstat);
3670 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3672 * WaitForDoorbellInt - Wait for IOC to set the HIS_DOORBELL_INTERRUPT bit
3673 * in it's IntStatus register.
3674 * @ioc: Pointer to MPT_ADAPTER structure
3675 * @howlong: How long to wait (in seconds)
3676 * @sleepFlag: Specifies whether the process can sleep
3678 * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt.
3680 * Returns a negative value on failure, else wait loop count.
3683 WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3689 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
3690 if (sleepFlag == CAN_SLEEP) {
3692 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3693 if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
3695 msleep_interruptible(1);
3700 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3701 if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
3709 dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell INT (cnt=%d) howlong=%d\n",
3710 ioc->name, count, howlong));
3714 printk(MYIOC_s_ERR_FMT "Doorbell INT timeout (count=%d), IntStatus=%x!\n",
3715 ioc->name, count, intstat);
3719 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3721 * WaitForDoorbellReply - Wait for and capture a IOC handshake reply.
3722 * @ioc: Pointer to MPT_ADAPTER structure
3723 * @howlong: How long to wait (in seconds)
3724 * @sleepFlag: Specifies whether the process can sleep
3726 * This routine polls the IOC for a handshake reply, 16 bits at a time.
3727 * Reply is cached to IOC private area large enough to hold a maximum
3728 * of 128 bytes of reply data.
3730 * Returns a negative value on failure, else size of reply in WORDS.
3733 WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3738 u16 *hs_reply = ioc->hs_reply;
3739 volatile MPIDefaultReply_t *mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
3742 hs_reply[0] = hs_reply[1] = hs_reply[7] = 0;
3745 * Get first two u16's so we can look at IOC's intended reply MsgLength
3748 if ((t = WaitForDoorbellInt(ioc, howlong, sleepFlag)) < 0) {
3751 hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
3752 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3753 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3756 hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
3757 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3761 dhsprintk((MYIOC_s_INFO_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
3762 ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
3763 failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
3766 * If no error (and IOC said MsgLength is > 0), piece together
3767 * reply 16 bits at a time.
3769 for (u16cnt=2; !failcnt && u16cnt < (2 * mptReply->MsgLength); u16cnt++) {
3770 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3772 hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
3773 /* don't overflow our IOC hs_reply[] buffer! */
3774 if (u16cnt < sizeof(ioc->hs_reply) / sizeof(ioc->hs_reply[0]))
3775 hs_reply[u16cnt] = hword;
3776 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3779 if (!failcnt && (t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3781 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3784 printk(MYIOC_s_ERR_FMT "Handshake reply failure!\n",
3789 else if (u16cnt != (2 * mptReply->MsgLength)) {
3792 else if ((mptReply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
3797 dhsprintk((MYIOC_s_INFO_FMT "Got Handshake reply:\n", ioc->name));
3798 DBG_DUMP_REPLY_FRAME(mptReply)
3800 dhsprintk((MYIOC_s_INFO_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
3801 ioc->name, t, u16cnt/2));
3805 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3807 * GetLanConfigPages - Fetch LANConfig pages.
3808 * @ioc: Pointer to MPT_ADAPTER structure
3810 * Return: 0 for success
3811 * -ENOMEM if no memory available
3812 * -EPERM if not allowed due to ISR context
3813 * -EAGAIN if no msg frames currently available
3814 * -EFAULT for non-successful reply or no reply (timeout)
3817 GetLanConfigPages(MPT_ADAPTER *ioc)
3819 ConfigPageHeader_t hdr;
3821 LANPage0_t *ppage0_alloc;
3822 dma_addr_t page0_dma;
3823 LANPage1_t *ppage1_alloc;
3824 dma_addr_t page1_dma;
3829 /* Get LAN Page 0 header */
3830 hdr.PageVersion = 0;
3833 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
3836 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3841 if ((rc = mpt_config(ioc, &cfg)) != 0)
3844 if (hdr.PageLength > 0) {
3845 data_sz = hdr.PageLength * 4;
3846 ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
3849 memset((u8 *)ppage0_alloc, 0, data_sz);
3850 cfg.physAddr = page0_dma;
3851 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
3853 if ((rc = mpt_config(ioc, &cfg)) == 0) {
3855 copy_sz = min_t(int, sizeof(LANPage0_t), data_sz);
3856 memcpy(&ioc->lan_cnfg_page0, ppage0_alloc, copy_sz);
3860 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
3863 * Normalize endianness of structure data,
3864 * by byte-swapping all > 1 byte fields!
3873 /* Get LAN Page 1 header */
3874 hdr.PageVersion = 0;
3877 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
3880 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3884 if ((rc = mpt_config(ioc, &cfg)) != 0)
3887 if (hdr.PageLength == 0)
3890 data_sz = hdr.PageLength * 4;
3892 ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
3894 memset((u8 *)ppage1_alloc, 0, data_sz);
3895 cfg.physAddr = page1_dma;
3896 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
3898 if ((rc = mpt_config(ioc, &cfg)) == 0) {
3900 copy_sz = min_t(int, sizeof(LANPage1_t), data_sz);
3901 memcpy(&ioc->lan_cnfg_page1, ppage1_alloc, copy_sz);
3904 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
3907 * Normalize endianness of structure data,
3908 * by byte-swapping all > 1 byte fields!
3916 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3918 * GetFcPortPage0 - Fetch FCPort config Page0.
3919 * @ioc: Pointer to MPT_ADAPTER structure
3920 * @portnum: IOC Port number
3922 * Return: 0 for success
3923 * -ENOMEM if no memory available
3924 * -EPERM if not allowed due to ISR context
3925 * -EAGAIN if no msg frames currently available
3926 * -EFAULT for non-successful reply or no reply (timeout)
3929 GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
3931 ConfigPageHeader_t hdr;
3933 FCPortPage0_t *ppage0_alloc;
3934 FCPortPage0_t *pp0dest;
3935 dma_addr_t page0_dma;
3940 /* Get FCPort Page 0 header */
3941 hdr.PageVersion = 0;
3944 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
3947 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3949 cfg.pageAddr = portnum;
3952 if ((rc = mpt_config(ioc, &cfg)) != 0)
3955 if (hdr.PageLength == 0)
3958 data_sz = hdr.PageLength * 4;
3960 ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
3962 memset((u8 *)ppage0_alloc, 0, data_sz);
3963 cfg.physAddr = page0_dma;
3964 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
3966 if ((rc = mpt_config(ioc, &cfg)) == 0) {
3968 pp0dest = &ioc->fc_port_page0[portnum];
3969 copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
3970 memcpy(pp0dest, ppage0_alloc, copy_sz);
3973 * Normalize endianness of structure data,
3974 * by byte-swapping all > 1 byte fields!
3976 pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
3977 pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
3978 pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
3979 pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
3980 pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
3981 pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
3982 pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
3983 pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
3984 pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
3985 pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
3986 pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
3987 pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
3988 pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
3989 pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
3990 pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
3991 pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
3995 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
4001 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4003 * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
4004 * @ioc: Pointer to MPT_ADAPTER structure
4006 * Returns: 0 for success
4007 * -ENOMEM if no memory available
4008 * -EPERM if not allowed due to ISR context
4009 * -EAGAIN if no msg frames currently available
4010 * -EFAULT for non-successful reply or no reply (timeout)
4013 GetIoUnitPage2(MPT_ADAPTER *ioc)
4015 ConfigPageHeader_t hdr;
4017 IOUnitPage2_t *ppage_alloc;
4018 dma_addr_t page_dma;
4022 /* Get the page header */
4023 hdr.PageVersion = 0;
4026 hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
4029 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4034 if ((rc = mpt_config(ioc, &cfg)) != 0)
4037 if (hdr.PageLength == 0)
4040 /* Read the config page */
4041 data_sz = hdr.PageLength * 4;
4043 ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
4045 memset((u8 *)ppage_alloc, 0, data_sz);
4046 cfg.physAddr = page_dma;
4047 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4049 /* If Good, save data */
4050 if ((rc = mpt_config(ioc, &cfg)) == 0)
4051 ioc->biosVersion = le32_to_cpu(ppage_alloc->BiosVersion);
4053 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage_alloc, page_dma);
4059 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4060 /* mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
4061 * @ioc: Pointer to a Adapter Strucutre
4062 * @portnum: IOC port number
4064 * Return: -EFAULT if read of config page header fails
4066 * If read of SCSI Port Page 0 fails,
4067 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
4068 * Adapter settings: async, narrow
4070 * If read of SCSI Port Page 2 fails,
4071 * Adapter settings valid
4072 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
4077 * CHECK - what type of locking mechanisms should be used????
4080 mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
4085 ConfigPageHeader_t header;
4091 if (!ioc->spi_data.nvram) {
4094 sz = MPT_MAX_SCSI_DEVICES * sizeof(int);
4095 mem = kmalloc(sz, GFP_ATOMIC);
4099 ioc->spi_data.nvram = (int *) mem;
4101 dprintk((MYIOC_s_INFO_FMT "SCSI device NVRAM settings @ %p, sz=%d\n",
4102 ioc->name, ioc->spi_data.nvram, sz));
4105 /* Invalidate NVRAM information
4107 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
4108 ioc->spi_data.nvram[ii] = MPT_HOST_NVRAM_INVALID;
4111 /* Read SPP0 header, allocate memory, then read page.
4113 header.PageVersion = 0;
4114 header.PageLength = 0;
4115 header.PageNumber = 0;
4116 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
4119 cfg.pageAddr = portnum;
4120 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4122 cfg.timeout = 0; /* use default */
4123 if (mpt_config(ioc, &cfg) != 0)
4126 if (header.PageLength > 0) {
4127 pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
4129 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4130 cfg.physAddr = buf_dma;
4131 if (mpt_config(ioc, &cfg) != 0) {
4132 ioc->spi_data.maxBusWidth = MPT_NARROW;
4133 ioc->spi_data.maxSyncOffset = 0;
4134 ioc->spi_data.minSyncFactor = MPT_ASYNC;
4135 ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
4138 /* Save the Port Page 0 data
4140 SCSIPortPage0_t *pPP0 = (SCSIPortPage0_t *) pbuf;
4141 pPP0->Capabilities = le32_to_cpu(pPP0->Capabilities);
4142 pPP0->PhysicalInterface = le32_to_cpu(pPP0->PhysicalInterface);
4144 if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
4145 ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
4146 dinitprintk((KERN_INFO MYNAM " :%s noQas due to Capabilities=%x\n",
4147 ioc->name, pPP0->Capabilities));
4149 ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
4150 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK;
4152 ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
4153 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
4154 ioc->spi_data.minSyncFactor = (u8) (data >> 8);
4156 ioc->spi_data.maxSyncOffset = 0;
4157 ioc->spi_data.minSyncFactor = MPT_ASYNC;
4160 ioc->spi_data.busType = pPP0->PhysicalInterface & MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK;
4162 /* Update the minSyncFactor based on bus type.
4164 if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
4165 (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
4167 if (ioc->spi_data.minSyncFactor < MPT_ULTRA)
4168 ioc->spi_data.minSyncFactor = MPT_ULTRA;
4172 pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
4177 /* SCSI Port Page 2 - Read the header then the page.
4179 header.PageVersion = 0;
4180 header.PageLength = 0;
4181 header.PageNumber = 2;
4182 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
4185 cfg.pageAddr = portnum;
4186 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4188 if (mpt_config(ioc, &cfg) != 0)
4191 if (header.PageLength > 0) {
4192 /* Allocate memory and read SCSI Port Page 2
4194 pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
4196 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_NVRAM;
4197 cfg.physAddr = buf_dma;
4198 if (mpt_config(ioc, &cfg) != 0) {
4199 /* Nvram data is left with INVALID mark
4203 SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t *) pbuf;
4204 MpiDeviceInfo_t *pdevice = NULL;
4206 /* Save the Port Page 2 data
4207 * (reformat into a 32bit quantity)
4209 data = le32_to_cpu(pPP2->PortFlags) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
4210 ioc->spi_data.PortFlags = data;
4211 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
4212 pdevice = &pPP2->DeviceSettings[ii];
4213 data = (le16_to_cpu(pdevice->DeviceFlags) << 16) |
4214 (pdevice->SyncFactor << 8) | pdevice->Timeout;
4215 ioc->spi_data.nvram[ii] = data;
4219 pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
4223 /* Update Adapter limits with those from NVRAM
4224 * Comment: Don't need to do this. Target performance
4225 * parameters will never exceed the adapters limits.
4231 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4232 /* mpt_readScsiDevicePageHeaders - save version and length of SDP1
4233 * @ioc: Pointer to a Adapter Strucutre
4234 * @portnum: IOC port number
4236 * Return: -EFAULT if read of config page header fails
4240 mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
4243 ConfigPageHeader_t header;
4245 /* Read the SCSI Device Page 1 header
4247 header.PageVersion = 0;
4248 header.PageLength = 0;
4249 header.PageNumber = 1;
4250 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4253 cfg.pageAddr = portnum;
4254 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4257 if (mpt_config(ioc, &cfg) != 0)
4260 ioc->spi_data.sdp1version = cfg.hdr->PageVersion;
4261 ioc->spi_data.sdp1length = cfg.hdr->PageLength;
4263 header.PageVersion = 0;
4264 header.PageLength = 0;
4265 header.PageNumber = 0;
4266 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4267 if (mpt_config(ioc, &cfg) != 0)
4270 ioc->spi_data.sdp0version = cfg.hdr->PageVersion;
4271 ioc->spi_data.sdp0length = cfg.hdr->PageLength;
4273 dcprintk((MYIOC_s_INFO_FMT "Headers: 0: version %d length %d\n",
4274 ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
4276 dcprintk((MYIOC_s_INFO_FMT "Headers: 1: version %d length %d\n",
4277 ioc->name, ioc->spi_data.sdp1version, ioc->spi_data.sdp1length));
4281 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4283 * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
4284 * @ioc: Pointer to a Adapter Strucutre
4285 * @portnum: IOC port number
4289 * -EFAULT if read of config page header fails or data pointer not NULL
4290 * -ENOMEM if pci_alloc failed
4293 mpt_findImVolumes(MPT_ADAPTER *ioc)
4297 ConfigPageIoc2RaidVol_t *pIocRv;
4298 dma_addr_t ioc2_dma;
4300 ConfigPageHeader_t header;
4307 /* Read IOCP2 header then the page.
4309 header.PageVersion = 0;
4310 header.PageLength = 0;
4311 header.PageNumber = 2;
4312 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4316 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4319 if (mpt_config(ioc, &cfg) != 0)
4322 if (header.PageLength == 0)
4325 iocpage2sz = header.PageLength * 4;
4326 pIoc2 = pci_alloc_consistent(ioc->pcidev, iocpage2sz, &ioc2_dma);
4330 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4331 cfg.physAddr = ioc2_dma;
4332 if (mpt_config(ioc, &cfg) != 0)
4335 if ( (mem = (u8 *)ioc->spi_data.pIocPg2) == NULL ) {
4336 mem = kmalloc(iocpage2sz, GFP_ATOMIC);
4338 ioc->spi_data.pIocPg2 = (IOCPage2_t *) mem;
4343 memcpy(mem, (u8 *)pIoc2, iocpage2sz);
4345 /* Identify RAID Volume Id's */
4346 nVols = pIoc2->NumActiveVolumes;
4352 /* At least 1 RAID Volume
4354 pIocRv = pIoc2->RaidVolume;
4355 ioc->spi_data.isRaid = 0;
4356 for (jj = 0; jj < nVols; jj++, pIocRv++) {
4357 vid = pIocRv->VolumeID;
4358 vbus = pIocRv->VolumeBus;
4359 vioc = pIocRv->VolumeIOC;
4364 ioc->spi_data.isRaid |= (1 << vid);
4366 /* Error! Always bus 0
4372 /* Identify Hidden Physical Disk Id's */
4373 nPhys = pIoc2->NumActivePhysDisks;
4375 /* No physical disks.
4378 mpt_read_ioc_pg_3(ioc);
4382 pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
4388 mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
4393 ConfigPageHeader_t header;
4394 dma_addr_t ioc3_dma;
4397 /* Free the old page
4399 kfree(ioc->spi_data.pIocPg3);
4400 ioc->spi_data.pIocPg3 = NULL;
4402 /* There is at least one physical disk.
4403 * Read and save IOC Page 3
4405 header.PageVersion = 0;
4406 header.PageLength = 0;
4407 header.PageNumber = 3;
4408 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4412 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4415 if (mpt_config(ioc, &cfg) != 0)
4418 if (header.PageLength == 0)
4421 /* Read Header good, alloc memory
4423 iocpage3sz = header.PageLength * 4;
4424 pIoc3 = pci_alloc_consistent(ioc->pcidev, iocpage3sz, &ioc3_dma);
4428 /* Read the Page and save the data
4429 * into malloc'd memory.
4431 cfg.physAddr = ioc3_dma;
4432 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4433 if (mpt_config(ioc, &cfg) == 0) {
4434 mem = kmalloc(iocpage3sz, GFP_ATOMIC);
4436 memcpy(mem, (u8 *)pIoc3, iocpage3sz);
4437 ioc->spi_data.pIocPg3 = (IOCPage3_t *) mem;
4441 pci_free_consistent(ioc->pcidev, iocpage3sz, pIoc3, ioc3_dma);
4447 mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
4451 ConfigPageHeader_t header;
4452 dma_addr_t ioc4_dma;
4455 /* Read and save IOC Page 4
4457 header.PageVersion = 0;
4458 header.PageLength = 0;
4459 header.PageNumber = 4;
4460 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4464 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4467 if (mpt_config(ioc, &cfg) != 0)
4470 if (header.PageLength == 0)
4473 if ( (pIoc4 = ioc->spi_data.pIocPg4) == NULL ) {
4474 iocpage4sz = (header.PageLength + 4) * 4; /* Allow 4 additional SEP's */
4475 pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
4479 ioc4_dma = ioc->spi_data.IocPg4_dma;
4480 iocpage4sz = ioc->spi_data.IocPg4Sz;
4483 /* Read the Page into dma memory.
4485 cfg.physAddr = ioc4_dma;
4486 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4487 if (mpt_config(ioc, &cfg) == 0) {
4488 ioc->spi_data.pIocPg4 = (IOCPage4_t *) pIoc4;
4489 ioc->spi_data.IocPg4_dma = ioc4_dma;
4490 ioc->spi_data.IocPg4Sz = iocpage4sz;
4492 pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
4493 ioc->spi_data.pIocPg4 = NULL;
4498 mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
4502 ConfigPageHeader_t header;
4503 dma_addr_t ioc1_dma;
4507 /* Check the Coalescing Timeout in IOC Page 1
4509 header.PageVersion = 0;
4510 header.PageLength = 0;
4511 header.PageNumber = 1;
4512 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4516 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4519 if (mpt_config(ioc, &cfg) != 0)
4522 if (header.PageLength == 0)
4525 /* Read Header good, alloc memory
4527 iocpage1sz = header.PageLength * 4;
4528 pIoc1 = pci_alloc_consistent(ioc->pcidev, iocpage1sz, &ioc1_dma);
4532 /* Read the Page and check coalescing timeout
4534 cfg.physAddr = ioc1_dma;
4535 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4536 if (mpt_config(ioc, &cfg) == 0) {
4538 tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
4539 if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
4540 tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
4542 dprintk((MYIOC_s_INFO_FMT "Coalescing Enabled Timeout = %d\n",
4545 if (tmp > MPT_COALESCING_TIMEOUT) {
4546 pIoc1->CoalescingTimeout = cpu_to_le32(MPT_COALESCING_TIMEOUT);
4548 /* Write NVRAM and current
4551 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
4552 if (mpt_config(ioc, &cfg) == 0) {
4553 dprintk((MYIOC_s_INFO_FMT "Reset Current Coalescing Timeout to = %d\n",
4554 ioc->name, MPT_COALESCING_TIMEOUT));
4556 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
4557 if (mpt_config(ioc, &cfg) == 0) {
4558 dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout to = %d\n",
4559 ioc->name, MPT_COALESCING_TIMEOUT));
4561 dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout Failed\n",
4566 dprintk((MYIOC_s_WARN_FMT "Reset of Current Coalescing Timeout Failed!\n",
4572 dprintk((MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
4576 pci_free_consistent(ioc->pcidev, iocpage1sz, pIoc1, ioc1_dma);
4581 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4583 * SendEventNotification - Send EventNotification (on or off) request
4585 * @ioc: Pointer to MPT_ADAPTER structure
4586 * @EvSwitch: Event switch flags
4589 SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch)
4591 EventNotification_t *evnp;
4593 evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc);
4595 dprintk((MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n",
4599 memset(evnp, 0, sizeof(*evnp));
4601 dprintk((MYIOC_s_INFO_FMT "Sending EventNotification(%d)\n", ioc->name, EvSwitch));
4603 evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
4604 evnp->ChainOffset = 0;
4606 evnp->Switch = EvSwitch;
4608 mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)evnp);
4613 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4615 * SendEventAck - Send EventAck request to MPT adapter.
4616 * @ioc: Pointer to MPT_ADAPTER structure
4617 * @evnp: Pointer to original EventNotification request
4620 SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
4624 if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
4625 printk(MYIOC_s_WARN_FMT "Unable to allocate event ACK request frame!\n",
4629 memset(pAck, 0, sizeof(*pAck));
4631 dprintk((MYIOC_s_INFO_FMT "Sending EventAck\n", ioc->name));
4633 pAck->Function = MPI_FUNCTION_EVENT_ACK;
4634 pAck->ChainOffset = 0;
4636 pAck->Event = evnp->Event;
4637 pAck->EventContext = evnp->EventContext;
4639 mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)pAck);
4644 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4646 * mpt_config - Generic function to issue config message
4647 * @ioc - Pointer to an adapter structure
4648 * @cfg - Pointer to a configuration structure. Struct contains
4649 * action, page address, direction, physical address
4650 * and pointer to a configuration page header
4651 * Page header is updated.
4653 * Returns 0 for success
4654 * -EPERM if not allowed due to ISR context
4655 * -EAGAIN if no msg frames currently available
4656 * -EFAULT for non-successful reply or no reply (timeout)
4659 mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
4663 unsigned long flags;
4668 /* Prevent calling wait_event() (below), if caller happens
4669 * to be in ISR context, because that is fatal!
4671 in_isr = in_interrupt();
4673 dcprintk((MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
4678 /* Get and Populate a free Frame
4680 if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
4681 dcprintk((MYIOC_s_WARN_FMT "mpt_config: no msg frames!\n",
4685 pReq = (Config_t *)mf;
4686 pReq->Action = pCfg->action;
4688 pReq->ChainOffset = 0;
4689 pReq->Function = MPI_FUNCTION_CONFIG;
4690 pReq->ExtPageLength = 0;
4691 pReq->ExtPageType = 0;
4693 for (ii=0; ii < 8; ii++)
4694 pReq->Reserved2[ii] = 0;
4696 pReq->Header.PageVersion = pCfg->hdr->PageVersion;
4697 pReq->Header.PageLength = pCfg->hdr->PageLength;
4698 pReq->Header.PageNumber = pCfg->hdr->PageNumber;
4699 pReq->Header.PageType = (pCfg->hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
4700 pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
4702 /* Add a SGE to the config request.
4705 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
4707 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
4709 flagsLength |= pCfg->hdr->PageLength * 4;
4711 mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
4713 dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
4714 ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
4716 /* Append pCfg pointer to end of mf
4718 *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
4720 /* Initalize the timer
4722 init_timer(&pCfg->timer);
4723 pCfg->timer.data = (unsigned long) ioc;
4724 pCfg->timer.function = mpt_timer_expired;
4725 pCfg->wait_done = 0;
4727 /* Set the timer; ensure 10 second minimum */
4728 if (pCfg->timeout < 10)
4729 pCfg->timer.expires = jiffies + HZ*10;
4731 pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
4733 /* Add to end of Q, set timer and then issue this command */
4734 spin_lock_irqsave(&ioc->FreeQlock, flags);
4735 list_add_tail(&pCfg->linkage, &ioc->configQ);
4736 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4738 add_timer(&pCfg->timer);
4739 mpt_put_msg_frame(mpt_base_index, ioc, mf);
4740 wait_event(mpt_waitq, pCfg->wait_done);
4742 /* mf has been freed - do not access */
4749 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4751 * mpt_toolbox - Generic function to issue toolbox message
4752 * @ioc - Pointer to an adapter structure
4753 * @cfg - Pointer to a toolbox structure. Struct contains
4754 * action, page address, direction, physical address
4755 * and pointer to a configuration page header
4756 * Page header is updated.
4758 * Returns 0 for success
4759 * -EPERM if not allowed due to ISR context
4760 * -EAGAIN if no msg frames currently available
4761 * -EFAULT for non-successful reply or no reply (timeout)
4764 mpt_toolbox(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
4766 ToolboxIstwiReadWriteRequest_t *pReq;
4768 struct pci_dev *pdev;
4769 unsigned long flags;
4774 /* Prevent calling wait_event() (below), if caller happens
4775 * to be in ISR context, because that is fatal!
4777 in_isr = in_interrupt();
4779 dcprintk((MYIOC_s_WARN_FMT "toobox request not allowed in ISR context!\n",
4784 /* Get and Populate a free Frame
4786 if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
4787 dcprintk((MYIOC_s_WARN_FMT "mpt_toolbox: no msg frames!\n",
4791 pReq = (ToolboxIstwiReadWriteRequest_t *)mf;
4792 pReq->Tool = pCfg->action;
4794 pReq->ChainOffset = 0;
4795 pReq->Function = MPI_FUNCTION_TOOLBOX;
4796 pReq->Reserved1 = 0;
4797 pReq->Reserved2 = 0;
4799 pReq->Flags = pCfg->dir;
4801 pReq->Reserved3 = 0;
4802 pReq->NumAddressBytes = 0x01;
4803 pReq->Reserved4 = 0;
4804 pReq->DataLength = 0x04;
4805 pdev = (struct pci_dev *) ioc->pcidev;
4806 if (pdev->devfn & 1)
4807 pReq->DeviceAddr = 0xB2;
4809 pReq->DeviceAddr = 0xB0;
4813 pReq->Reserved5 = 0;
4815 /* Add a SGE to the config request.
4818 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | 4;
4820 mpt_add_sge((char *)&pReq->SGL, flagsLength, pCfg->physAddr);
4822 dcprintk((MYIOC_s_INFO_FMT "Sending Toolbox request, Tool=%x\n",
4823 ioc->name, pReq->Tool));
4825 /* Append pCfg pointer to end of mf
4827 *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
4829 /* Initalize the timer
4831 init_timer(&pCfg->timer);
4832 pCfg->timer.data = (unsigned long) ioc;
4833 pCfg->timer.function = mpt_timer_expired;
4834 pCfg->wait_done = 0;
4836 /* Set the timer; ensure 10 second minimum */
4837 if (pCfg->timeout < 10)
4838 pCfg->timer.expires = jiffies + HZ*10;
4840 pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
4842 /* Add to end of Q, set timer and then issue this command */
4843 spin_lock_irqsave(&ioc->FreeQlock, flags);
4844 list_add_tail(&pCfg->linkage, &ioc->configQ);
4845 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4847 add_timer(&pCfg->timer);
4848 mpt_put_msg_frame(mpt_base_index, ioc, mf);
4849 wait_event(mpt_waitq, pCfg->wait_done);
4851 /* mf has been freed - do not access */
4858 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4860 * mpt_timer_expired - Call back for timer process.
4861 * Used only internal config functionality.
4862 * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
4865 mpt_timer_expired(unsigned long data)
4867 MPT_ADAPTER *ioc = (MPT_ADAPTER *) data;
4869 dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired! \n", ioc->name));
4871 /* Perform a FW reload */
4872 if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
4873 printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
4875 /* No more processing.
4876 * Hard reset clean-up will wake up
4877 * process and free all resources.
4879 dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired complete!\n", ioc->name));
4884 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4886 * mpt_ioc_reset - Base cleanup for hard reset
4887 * @ioc: Pointer to the adapter structure
4888 * @reset_phase: Indicates pre- or post-reset functionality
4890 * Remark: Free's resources with internally generated commands.
4893 mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
4896 unsigned long flags;
4898 dprintk((KERN_WARNING MYNAM
4899 ": IOC %s_reset routed to MPT base driver!\n",
4900 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
4901 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
4903 if (reset_phase == MPT_IOC_SETUP_RESET) {
4905 } else if (reset_phase == MPT_IOC_PRE_RESET) {
4906 /* If the internal config Q is not empty -
4907 * delete timer. MF resources will be freed when
4908 * the FIFO's are primed.
4910 spin_lock_irqsave(&ioc->FreeQlock, flags);
4911 list_for_each_entry(pCfg, &ioc->configQ, linkage)
4912 del_timer(&pCfg->timer);
4913 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4918 /* Search the configQ for internal commands.
4919 * Flush the Q, and wake up all suspended threads.
4921 spin_lock_irqsave(&ioc->FreeQlock, flags);
4922 list_for_each_entry_safe(pCfg, pNext, &ioc->configQ, linkage) {
4923 list_del(&pCfg->linkage);
4925 pCfg->status = MPT_CONFIG_ERROR;
4926 pCfg->wait_done = 1;
4927 wake_up(&mpt_waitq);
4929 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4932 return 1; /* currently means nothing really */
4936 #ifdef CONFIG_PROC_FS /* { */
4937 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4939 * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
4941 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4943 * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
4945 * Returns 0 for success, non-zero for failure.
4948 procmpt_create(void)
4950 struct proc_dir_entry *ent;
4952 mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
4953 if (mpt_proc_root_dir == NULL)
4956 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, mpt_proc_root_dir);
4958 ent->read_proc = procmpt_summary_read;
4960 ent = create_proc_entry("version", S_IFREG|S_IRUGO, mpt_proc_root_dir);
4962 ent->read_proc = procmpt_version_read;
4967 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4969 * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
4971 * Returns 0 for success, non-zero for failure.
4974 procmpt_destroy(void)
4976 remove_proc_entry("version", mpt_proc_root_dir);
4977 remove_proc_entry("summary", mpt_proc_root_dir);
4978 remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
4981 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4983 * procmpt_summary_read - Handle read request from /proc/mpt/summary
4984 * or from /proc/mpt/iocN/summary.
4985 * @buf: Pointer to area to write information
4986 * @start: Pointer to start pointer
4987 * @offset: Offset to start writing
4989 * @eof: Pointer to EOF integer
4992 * Returns number of characters written to process performing the read.
4995 procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
5005 mpt_print_ioc_summary(ioc, out, &more, 0, 1);
5009 list_for_each_entry(ioc, &ioc_list, list) {
5012 mpt_print_ioc_summary(ioc, out, &more, 0, 1);
5015 if ((out-buf) >= request)
5022 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5025 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5027 * procmpt_version_read - Handle read request from /proc/mpt/version.
5028 * @buf: Pointer to area to write information
5029 * @start: Pointer to start pointer
5030 * @offset: Offset to start writing
5032 * @eof: Pointer to EOF integer
5035 * Returns number of characters written to process performing the read.
5038 procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
5041 int scsi, fc, sas, lan, ctl, targ, dmp;
5045 len = sprintf(buf, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
5046 len += sprintf(buf+len, " Fusion MPT base driver\n");
5048 scsi = fc = sas = lan = ctl = targ = dmp = 0;
5049 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
5051 if (MptCallbacks[ii]) {
5052 switch (MptDriverClass[ii]) {
5054 if (!scsi++) drvname = "SPI host";
5057 if (!fc++) drvname = "FC host";
5060 if (!sas++) drvname = "SAS host";
5063 if (!lan++) drvname = "LAN";
5066 if (!targ++) drvname = "SCSI target";
5069 if (!ctl++) drvname = "ioctl";
5074 len += sprintf(buf+len, " Fusion MPT %s driver\n", drvname);
5078 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5081 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5083 * procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info.
5084 * @buf: Pointer to area to write information
5085 * @start: Pointer to start pointer
5086 * @offset: Offset to start writing
5088 * @eof: Pointer to EOF integer
5091 * Returns number of characters written to process performing the read.
5094 procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
5096 MPT_ADAPTER *ioc = data;
5102 mpt_get_fw_exp_ver(expVer, ioc);
5104 len = sprintf(buf, "%s:", ioc->name);
5105 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
5106 len += sprintf(buf+len, " (f/w download boot flag set)");
5107 // if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
5108 // len += sprintf(buf+len, " CONFIG_CHECKSUM_FAIL!");
5110 len += sprintf(buf+len, "\n ProductID = 0x%04x (%s)\n",
5111 ioc->facts.ProductID,
5113 len += sprintf(buf+len, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
5114 if (ioc->facts.FWImageSize)
5115 len += sprintf(buf+len, " (fw_size=%d)", ioc->facts.FWImageSize);
5116 len += sprintf(buf+len, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
5117 len += sprintf(buf+len, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
5118 len += sprintf(buf+len, " EventState = 0x%02x\n", ioc->facts.EventState);
5120 len += sprintf(buf+len, " CurrentHostMfaHighAddr = 0x%08x\n",
5121 ioc->facts.CurrentHostMfaHighAddr);
5122 len += sprintf(buf+len, " CurrentSenseBufferHighAddr = 0x%08x\n",
5123 ioc->facts.CurrentSenseBufferHighAddr);
5125 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
5126 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
5128 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
5129 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
5131 * Rounding UP to nearest 4-kB boundary here...
5133 sz = (ioc->req_sz * ioc->req_depth) + 128;
5134 sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
5135 len += sprintf(buf+len, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
5136 ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
5137 len += sprintf(buf+len, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
5138 4*ioc->facts.RequestFrameSize,
5139 ioc->facts.GlobalCredits);
5141 len += sprintf(buf+len, " Frames @ 0x%p (Dma @ 0x%p)\n",
5142 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
5143 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
5144 len += sprintf(buf+len, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
5145 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
5146 len += sprintf(buf+len, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
5147 ioc->facts.CurReplyFrameSize,
5148 ioc->facts.ReplyQueueDepth);
5150 len += sprintf(buf+len, " MaxDevices = %d\n",
5151 (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
5152 len += sprintf(buf+len, " MaxBuses = %d\n", ioc->facts.MaxBuses);
5155 for (p=0; p < ioc->facts.NumberOfPorts; p++) {
5156 len += sprintf(buf+len, " PortNumber = %d (of %d)\n",
5158 ioc->facts.NumberOfPorts);
5159 if (ioc->bus_type == FC) {
5160 if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
5161 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
5162 len += sprintf(buf+len, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
5163 a[5], a[4], a[3], a[2], a[1], a[0]);
5165 len += sprintf(buf+len, " WWN = %08X%08X:%08X%08X\n",
5166 ioc->fc_port_page0[p].WWNN.High,
5167 ioc->fc_port_page0[p].WWNN.Low,
5168 ioc->fc_port_page0[p].WWPN.High,
5169 ioc->fc_port_page0[p].WWPN.Low);
5173 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5176 #endif /* CONFIG_PROC_FS } */
5178 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5180 mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
5183 if ((ioc->facts.FWVersion.Word >> 24) == 0x0E) {
5184 sprintf(buf, " (Exp %02d%02d)",
5185 (ioc->facts.FWVersion.Word >> 16) & 0x00FF, /* Month */
5186 (ioc->facts.FWVersion.Word >> 8) & 0x1F); /* Day */
5189 if ((ioc->facts.FWVersion.Word >> 8) & 0x80)
5190 strcat(buf, " [MDBG]");
5194 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5196 * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
5197 * @ioc: Pointer to MPT_ADAPTER structure
5198 * @buffer: Pointer to buffer where IOC summary info should be written
5199 * @size: Pointer to number of bytes we wrote (set by this routine)
5200 * @len: Offset at which to start writing in buffer
5201 * @showlan: Display LAN stuff?
5203 * This routine writes (english readable) ASCII text, which represents
5204 * a summary of IOC information, to a buffer.
5207 mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
5212 mpt_get_fw_exp_ver(expVer, ioc);
5215 * Shorter summary of attached ioc's...
5217 y = sprintf(buffer+len, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
5220 MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
5221 ioc->facts.FWVersion.Word,
5223 ioc->facts.NumberOfPorts,
5226 if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
5227 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
5228 y += sprintf(buffer+len+y, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
5229 a[5], a[4], a[3], a[2], a[1], a[0]);
5233 y += sprintf(buffer+len+y, ", IRQ=%d", ioc->pci_irq);
5235 y += sprintf(buffer+len+y, ", IRQ=%s", __irq_itoa(ioc->pci_irq));
5239 y += sprintf(buffer+len+y, " (disabled)");
5241 y += sprintf(buffer+len+y, "\n");
5246 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5250 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5252 * mpt_HardResetHandler - Generic reset handler, issue SCSI Task
5253 * Management call based on input arg values. If TaskMgmt fails,
5254 * return associated SCSI request.
5255 * @ioc: Pointer to MPT_ADAPTER structure
5256 * @sleepFlag: Indicates if sleep or schedule must be called.
5258 * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
5259 * or a non-interrupt thread. In the former, must not call schedule().
5261 * Remark: A return of -1 is a FATAL error case, as it means a
5262 * FW reload/initialization failed.
5264 * Returns 0 for SUCCESS or -1 if FAILED.
5267 mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
5270 unsigned long flags;
5272 dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name));
5274 printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
5275 printk("MF count 0x%x !\n", ioc->mfcnt);
5278 /* Reset the adapter. Prevent more than 1 call to
5279 * mpt_do_ioc_recovery at any instant in time.
5281 spin_lock_irqsave(&ioc->diagLock, flags);
5282 if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)){
5283 spin_unlock_irqrestore(&ioc->diagLock, flags);
5286 ioc->diagPending = 1;
5288 spin_unlock_irqrestore(&ioc->diagLock, flags);
5290 /* FIXME: If do_ioc_recovery fails, repeat....
5293 /* The SCSI driver needs to adjust timeouts on all current
5294 * commands prior to the diagnostic reset being issued.
5295 * Prevents timeouts occuring during a diagnostic reset...very bad.
5296 * For all other protocol drivers, this is a no-op.
5302 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
5303 if (MptResetHandlers[ii]) {
5304 dtmprintk((MYIOC_s_INFO_FMT "Calling IOC reset_setup handler #%d\n",
5306 r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_SETUP_RESET);
5308 dtmprintk((MYIOC_s_INFO_FMT "Calling alt-%s setup reset handler #%d\n",
5309 ioc->name, ioc->alt_ioc->name, ii));
5310 r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_SETUP_RESET);
5316 if ((rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag)) != 0) {
5317 printk(KERN_WARNING MYNAM ": WARNING - (%d) Cannot recover %s\n",
5322 ioc->alt_ioc->reload_fw = 0;
5324 spin_lock_irqsave(&ioc->diagLock, flags);
5325 ioc->diagPending = 0;
5327 ioc->alt_ioc->diagPending = 0;
5328 spin_unlock_irqrestore(&ioc->diagLock, flags);
5330 dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler rc = %d!\n", ioc->name, rc));
5335 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5337 EventDescriptionStr(u8 event, u32 evData0)
5342 case MPI_EVENT_NONE:
5345 case MPI_EVENT_LOG_DATA:
5348 case MPI_EVENT_STATE_CHANGE:
5349 ds = "State Change";
5351 case MPI_EVENT_UNIT_ATTENTION:
5352 ds = "Unit Attention";
5354 case MPI_EVENT_IOC_BUS_RESET:
5355 ds = "IOC Bus Reset";
5357 case MPI_EVENT_EXT_BUS_RESET:
5358 ds = "External Bus Reset";
5360 case MPI_EVENT_RESCAN:
5361 ds = "Bus Rescan Event";
5362 /* Ok, do we need to do anything here? As far as
5363 I can tell, this is when a new device gets added
5366 case MPI_EVENT_LINK_STATUS_CHANGE:
5367 if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
5368 ds = "Link Status(FAILURE) Change";
5370 ds = "Link Status(ACTIVE) Change";
5372 case MPI_EVENT_LOOP_STATE_CHANGE:
5373 if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
5374 ds = "Loop State(LIP) Change";
5375 else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
5376 ds = "Loop State(LPE) Change"; /* ??? */
5378 ds = "Loop State(LPB) Change"; /* ??? */
5380 case MPI_EVENT_LOGOUT:
5383 case MPI_EVENT_EVENT_CHANGE:
5385 ds = "Events(ON) Change";
5387 ds = "Events(OFF) Change";
5389 case MPI_EVENT_INTEGRATED_RAID:
5390 ds = "Integrated Raid";
5393 * MPT base "custom" events may be added here...
5402 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5404 * ProcessEventNotification - Route a received EventNotificationReply to
5405 * all currently regeistered event handlers.
5406 * @ioc: Pointer to MPT_ADAPTER structure
5407 * @pEventReply: Pointer to EventNotification reply frame
5408 * @evHandlers: Pointer to integer, number of event handlers
5410 * Returns sum of event handlers return values.
5413 ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
5425 * Do platform normalization of values
5427 event = le32_to_cpu(pEventReply->Event) & 0xFF;
5428 // evCtx = le32_to_cpu(pEventReply->EventContext);
5429 evDataLen = le16_to_cpu(pEventReply->EventDataLength);
5431 evData0 = le32_to_cpu(pEventReply->Data[0]);
5434 evStr = EventDescriptionStr(event, evData0);
5435 devtprintk((MYIOC_s_INFO_FMT "MPT event (%s=%02Xh) detected!\n",
5440 #if defined(MPT_DEBUG) || defined(MPT_DEBUG_EVENTS)
5441 printk(KERN_INFO MYNAM ": Event data:\n" KERN_INFO);
5442 for (ii = 0; ii < evDataLen; ii++)
5443 printk(" %08x", le32_to_cpu(pEventReply->Data[ii]));
5448 * Do general / base driver event processing
5451 case MPI_EVENT_NONE: /* 00 */
5452 case MPI_EVENT_LOG_DATA: /* 01 */
5453 case MPI_EVENT_STATE_CHANGE: /* 02 */
5454 case MPI_EVENT_UNIT_ATTENTION: /* 03 */
5455 case MPI_EVENT_IOC_BUS_RESET: /* 04 */
5456 case MPI_EVENT_EXT_BUS_RESET: /* 05 */
5457 case MPI_EVENT_RESCAN: /* 06 */
5458 case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
5459 case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
5460 case MPI_EVENT_LOGOUT: /* 09 */
5461 case MPI_EVENT_INTEGRATED_RAID: /* 0B */
5462 case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE: /* 0C */
5465 case MPI_EVENT_EVENT_CHANGE: /* 0A */
5467 u8 evState = evData0 & 0xFF;
5469 /* CHECKME! What if evState unexpectedly says OFF (0)? */
5471 /* Update EventState field in cached IocFacts */
5472 if (ioc->facts.Function) {
5473 ioc->facts.EventState = evState;
5480 * Should this event be logged? Events are written sequentially.
5481 * When buffer is full, start again at the top.
5483 if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
5486 idx = ioc->eventContext % ioc->eventLogSize;
5488 ioc->events[idx].event = event;
5489 ioc->events[idx].eventContext = ioc->eventContext;
5491 for (ii = 0; ii < 2; ii++) {
5493 ioc->events[idx].data[ii] = le32_to_cpu(pEventReply->Data[ii]);
5495 ioc->events[idx].data[ii] = 0;
5498 ioc->eventContext++;
5503 * Call each currently registered protocol event handler.
5505 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
5506 if (MptEvHandlers[ii]) {
5507 devtprintk((MYIOC_s_INFO_FMT "Routing Event to event handler #%d\n",
5509 r += (*(MptEvHandlers[ii]))(ioc, pEventReply);
5513 /* FIXME? Examine results here? */
5516 * If needed, send (a single) EventAck.
5518 if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
5519 if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
5520 devtprintk((MYIOC_s_WARN_FMT "SendEventAck returned %d\n",
5525 *evHandlers = handlers;
5529 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5531 * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
5532 * @ioc: Pointer to MPT_ADAPTER structure
5533 * @log_info: U32 LogInfo reply word from the IOC
5535 * Refer to lsi/fc_log.h.
5538 mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
5540 static char *subcl_str[8] = {
5541 "FCP Initiator", "FCP Target", "LAN", "MPI Message Layer",
5542 "FC Link", "Context Manager", "Invalid Field Offset", "State Change Info"
5544 u8 subcl = (log_info >> 24) & 0x7;
5546 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): SubCl={%s}\n",
5547 ioc->name, log_info, subcl_str[subcl]);
5550 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5552 * mpt_sp_log_info - Log information returned from SCSI Parallel IOC.
5553 * @ioc: Pointer to MPT_ADAPTER structure
5554 * @mr: Pointer to MPT reply frame
5555 * @log_info: U32 LogInfo word from the IOC
5557 * Refer to lsi/sp_log.h.
5560 mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info)
5562 u32 info = log_info & 0x00FF0000;
5563 char *desc = "unknown";
5567 desc = "bug! MID not found";
5568 if (ioc->reload_fw == 0)
5573 desc = "Parity Error";
5577 desc = "ASYNC Outbound Overrun";
5581 desc = "SYNC Offset Error";
5589 desc = "Msg In Overflow";
5597 desc = "Outbound DMA Overrun";
5601 desc = "Task Management";
5605 desc = "Device Problem";
5609 desc = "Invalid Phase Change";
5613 desc = "Untagged Table Size";
5618 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
5621 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5623 * mpt_sp_ioc_info - IOC information returned from SCSI Parallel IOC.
5624 * @ioc: Pointer to MPT_ADAPTER structure
5625 * @ioc_status: U32 IOCStatus word from IOC
5626 * @mf: Pointer to MPT request frame
5628 * Refer to lsi/mpi.h.
5631 mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
5633 u32 status = ioc_status & MPI_IOCSTATUS_MASK;
5637 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
5638 desc = "Invalid Function";
5641 case MPI_IOCSTATUS_BUSY: /* 0x0002 */
5645 case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
5646 desc = "Invalid SGL";
5649 case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
5650 desc = "Internal Error";
5653 case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
5657 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
5658 desc = "Insufficient Resources";
5661 case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
5662 desc = "Invalid Field";
5665 case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
5666 desc = "Invalid State";
5669 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
5670 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
5671 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
5672 case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
5673 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
5674 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
5675 /* No message for Config IOCStatus values */
5678 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
5679 /* No message for recovered error
5680 desc = "SCSI Recovered Error";
5684 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
5685 desc = "SCSI Invalid Bus";
5688 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
5689 desc = "SCSI Invalid TargetID";
5692 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
5694 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
5695 U8 cdb = pScsiReq->CDB[0];
5696 if (cdb != 0x12) { /* Inquiry is issued for device scanning */
5697 desc = "SCSI Device Not There";
5702 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
5703 desc = "SCSI Data Overrun";
5706 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
5707 /* This error is checked in scsi_io_done(). Skip.
5708 desc = "SCSI Data Underrun";
5712 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
5713 desc = "SCSI I/O Data Error";
5716 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
5717 desc = "SCSI Protocol Error";
5720 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
5721 desc = "SCSI Task Terminated";
5724 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
5725 desc = "SCSI Residual Mismatch";
5728 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
5729 desc = "SCSI Task Management Failed";
5732 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
5733 desc = "SCSI IOC Terminated";
5736 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
5737 desc = "SCSI Ext Terminated";
5745 printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04x): %s\n", ioc->name, status, desc);
5748 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5749 EXPORT_SYMBOL(mpt_attach);
5750 EXPORT_SYMBOL(mpt_detach);
5752 EXPORT_SYMBOL(mpt_resume);
5753 EXPORT_SYMBOL(mpt_suspend);
5755 EXPORT_SYMBOL(ioc_list);
5756 EXPORT_SYMBOL(mpt_proc_root_dir);
5757 EXPORT_SYMBOL(mpt_register);
5758 EXPORT_SYMBOL(mpt_deregister);
5759 EXPORT_SYMBOL(mpt_event_register);
5760 EXPORT_SYMBOL(mpt_event_deregister);
5761 EXPORT_SYMBOL(mpt_reset_register);
5762 EXPORT_SYMBOL(mpt_reset_deregister);
5763 EXPORT_SYMBOL(mpt_device_driver_register);
5764 EXPORT_SYMBOL(mpt_device_driver_deregister);
5765 EXPORT_SYMBOL(mpt_get_msg_frame);
5766 EXPORT_SYMBOL(mpt_put_msg_frame);
5767 EXPORT_SYMBOL(mpt_free_msg_frame);
5768 EXPORT_SYMBOL(mpt_add_sge);
5769 EXPORT_SYMBOL(mpt_send_handshake_request);
5770 EXPORT_SYMBOL(mpt_verify_adapter);
5771 EXPORT_SYMBOL(mpt_GetIocState);
5772 EXPORT_SYMBOL(mpt_print_ioc_summary);
5773 EXPORT_SYMBOL(mpt_lan_index);
5774 EXPORT_SYMBOL(mpt_stm_index);
5775 EXPORT_SYMBOL(mpt_HardResetHandler);
5776 EXPORT_SYMBOL(mpt_config);
5777 EXPORT_SYMBOL(mpt_toolbox);
5778 EXPORT_SYMBOL(mpt_findImVolumes);
5779 EXPORT_SYMBOL(mpt_read_ioc_pg_3);
5780 EXPORT_SYMBOL(mpt_alloc_fw_memory);
5781 EXPORT_SYMBOL(mpt_free_fw_memory);
5784 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5786 * fusion_init - Fusion MPT base driver initialization routine.
5788 * Returns 0 for success, non-zero for failure.
5795 show_mptmod_ver(my_NAME, my_VERSION);
5796 printk(KERN_INFO COPYRIGHT "\n");
5798 for (i = 0; i < MPT_MAX_PROTOCOL_DRIVERS; i++) {
5799 MptCallbacks[i] = NULL;
5800 MptDriverClass[i] = MPTUNKNOWN_DRIVER;
5801 MptEvHandlers[i] = NULL;
5802 MptResetHandlers[i] = NULL;
5805 /* Register ourselves (mptbase) in order to facilitate
5806 * EventNotification handling.
5808 mpt_base_index = mpt_register(mpt_base_reply, MPTBASE_DRIVER);
5810 /* Register for hard reset handling callbacks.
5812 if (mpt_reset_register(mpt_base_index, mpt_ioc_reset) == 0) {
5813 dprintk((KERN_INFO MYNAM ": Register for IOC reset notification\n"));
5818 #ifdef CONFIG_PROC_FS
5819 (void) procmpt_create();
5824 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5826 * fusion_exit - Perform driver unload cleanup.
5828 * This routine frees all resources associated with each MPT adapter
5829 * and removes all %MPT_PROCFS_MPTBASEDIR entries.
5835 dexitprintk((KERN_INFO MYNAM ": fusion_exit() called!\n"));
5837 mpt_reset_deregister(mpt_base_index);
5839 #ifdef CONFIG_PROC_FS
5844 module_init(fusion_init);
5845 module_exit(fusion_exit);