2 * linux/drivers/message/fusion/mptbase.c
3 * High performance SCSI + LAN / Fibre Channel device drivers.
4 * This is the Fusion MPT base driver which supports multiple
5 * (SCSI + LAN) specialized protocol drivers.
6 * For use with PCI chip/adapter(s):
7 * LSIFC9xx/LSI409xx Fibre Channel
8 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
11 * There are lots of people not mentioned below that deserve credit
12 * and thanks but won't get it here - sorry in advance that you
15 * This driver would not exist if not for Alan Cox's development
16 * of the linux i2o driver.
18 * A special thanks to Noah Romer (LSI Logic) for tons of work
19 * and tough debugging on the LAN driver, especially early on;-)
20 * And to Roger Hickerson (LSI Logic) for tirelessly supporting
21 * this driver project.
23 * A special thanks to Pamela Delaney (LSI Logic) for tons of work
24 * and countless enhancements while adding support for the 1030
25 * chip family. Pam has been instrumental in the development of
26 * of the 2.xx.xx series fusion drivers, and her contributions are
27 * far too numerous to hope to list in one place.
29 * All manner of help from Stephen Shirron (LSI Logic):
30 * low-level FC analysis, debug + various fixes in FCxx firmware,
31 * initial port to alpha platform, various driver code optimizations,
32 * being a faithful sounding board on all sorts of issues & ideas,
35 * A huge debt of gratitude is owed to David S. Miller (DaveM)
36 * for fixing much of the stupid and broken stuff in the early
37 * driver while porting to sparc64 platform. THANK YOU!
39 * Special thanks goes to the I2O LAN driver people at the
40 * University of Helsinki, who, unbeknownst to them, provided
41 * the inspiration and initial structure for this driver.
43 * A really huge debt of gratitude is owed to Eddie C. Dost
44 * for gobs of hard work fixing and optimizing LAN code.
47 * Copyright (c) 1999-2004 LSI Logic Corporation
48 * Originally By: Steven J. Ralston
49 * (mailto:sjralston1@netscape.net)
50 * (mailto:mpt_linux_developer@lsil.com)
52 * $Id: mptbase.c,v 1.126 2002/12/16 15:28:45 pdelaney Exp $
54 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
56 This program is free software; you can redistribute it and/or modify
57 it under the terms of the GNU General Public License as published by
58 the Free Software Foundation; version 2 of the License.
60 This program is distributed in the hope that it will be useful,
61 but WITHOUT ANY WARRANTY; without even the implied warranty of
62 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63 GNU General Public License for more details.
66 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
67 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
68 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
69 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
70 solely responsible for determining the appropriateness of using and
71 distributing the Program and assumes all risks associated with its
72 exercise of rights under this Agreement, including but not limited to
73 the risks and costs of program errors, damage to or loss of data,
74 programs or equipment, and unavailability or interruption of operations.
76 DISCLAIMER OF LIABILITY
77 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
78 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
79 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
80 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
81 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
82 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
83 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
85 You should have received a copy of the GNU General Public License
86 along with this program; if not, write to the Free Software
87 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
89 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
91 #include <linux/config.h>
92 #include <linux/version.h>
93 #include <linux/kernel.h>
94 #include <linux/module.h>
95 #include <linux/errno.h>
96 #include <linux/init.h>
97 #include <linux/slab.h>
98 #include <linux/types.h>
99 #include <linux/pci.h>
100 #include <linux/kdev_t.h>
101 #include <linux/blkdev.h>
102 #include <linux/delay.h>
103 #include <linux/interrupt.h> /* needed for in_interrupt() proto */
106 #include <asm/mtrr.h>
109 #include <asm/irq.h> /* needed for __irq_itoa() proto */
114 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
115 #define my_NAME "Fusion MPT base driver"
116 #define my_VERSION MPT_LINUX_VERSION_COMMON
117 #define MYNAM "mptbase"
119 MODULE_AUTHOR(MODULEAUTHOR);
120 MODULE_DESCRIPTION(my_NAME);
121 MODULE_LICENSE("GPL");
124 * cmd line parameters
127 static int mfcounter = 0;
128 #define PRINT_MF_COUNT 20000
131 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
135 int mpt_lan_index = -1;
136 int mpt_stm_index = -1;
138 struct proc_dir_entry *mpt_proc_root_dir;
140 #define WHOINIT_UNKNOWN 0xAA
142 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
146 /* Adapter link list */
148 /* Callback lookup table */
149 static MPT_CALLBACK MptCallbacks[MPT_MAX_PROTOCOL_DRIVERS];
150 /* Protocol driver class lookup table */
151 static int MptDriverClass[MPT_MAX_PROTOCOL_DRIVERS];
152 /* Event handler lookup table */
153 static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
154 /* Reset handler lookup table */
155 static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
156 static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
158 static int mpt_base_index = -1;
159 static int last_drv_idx = -1;
161 static DECLARE_WAIT_QUEUE_HEAD(mpt_waitq);
163 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
167 static irqreturn_t mpt_interrupt(int irq, void *bus_id, struct pt_regs *r);
168 static int mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
169 static int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
170 u32 *req, int replyBytes, u16 *u16reply, int maxwait,
172 static int mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag);
173 static void mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev);
174 static void mpt_adapter_disable(MPT_ADAPTER *ioc);
175 static void mpt_adapter_dispose(MPT_ADAPTER *ioc);
177 static void MptDisplayIocCapabilities(MPT_ADAPTER *ioc);
178 static int MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag);
179 //static u32 mpt_GetIocState(MPT_ADAPTER *ioc, int cooked);
180 static int GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason);
181 static int GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
182 static int SendIocInit(MPT_ADAPTER *ioc, int sleepFlag);
183 static int SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
184 static int mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag);
185 static int mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag);
186 static int mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
187 static int KickStart(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
188 static int SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag);
189 static int PrimeIocFifos(MPT_ADAPTER *ioc);
190 static int WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
191 static int WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
192 static int WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
193 static int GetLanConfigPages(MPT_ADAPTER *ioc);
194 static int GetFcPortPage0(MPT_ADAPTER *ioc, int portnum);
195 static int GetIoUnitPage2(MPT_ADAPTER *ioc);
196 static int mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
197 static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
198 static void mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
199 static void mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
200 static void mpt_timer_expired(unsigned long data);
201 static int SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch);
202 static int SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
204 #ifdef CONFIG_PROC_FS
205 static int procmpt_summary_read(char *buf, char **start, off_t offset,
206 int request, int *eof, void *data);
207 static int procmpt_version_read(char *buf, char **start, off_t offset,
208 int request, int *eof, void *data);
209 static int procmpt_iocinfo_read(char *buf, char **start, off_t offset,
210 int request, int *eof, void *data);
212 static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
214 //int mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
215 static int ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers);
216 static void mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
217 static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
218 static void mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info);
220 /* module entry point */
221 static int __devinit mptbase_probe (struct pci_dev *, const struct pci_device_id *);
222 static void __devexit mptbase_remove(struct pci_dev *);
223 static void mptbase_shutdown(struct device * );
224 static int __init fusion_init (void);
225 static void __exit fusion_exit (void);
227 /****************************************************************************
231 static struct pci_device_id mptbase_pci_table[] = {
232 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC909,
233 PCI_ANY_ID, PCI_ANY_ID },
234 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929,
235 PCI_ANY_ID, PCI_ANY_ID },
236 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919,
237 PCI_ANY_ID, PCI_ANY_ID },
238 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929X,
239 PCI_ANY_ID, PCI_ANY_ID },
240 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919X,
241 PCI_ANY_ID, PCI_ANY_ID },
242 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1030,
243 PCI_ANY_ID, PCI_ANY_ID },
244 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_1030_53C1035,
245 PCI_ANY_ID, PCI_ANY_ID },
246 {0} /* Terminating entry */
248 MODULE_DEVICE_TABLE(pci, mptbase_pci_table);
250 #define CHIPREG_READ32(addr) readl_relaxed(addr)
251 #define CHIPREG_READ32_dmasync(addr) readl(addr)
252 #define CHIPREG_WRITE32(addr,val) writel(val, addr)
253 #define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
254 #define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
256 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
258 * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
259 * @irq: irq number (not used)
260 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
261 * @r: pt_regs pointer (not used)
263 * This routine is registered via the request_irq() kernel API call,
264 * and handles all interrupts generated from a specific MPT adapter
265 * (also referred to as a IO Controller or IOC).
266 * This routine must clear the interrupt from the adapter and does
267 * so by reading the reply FIFO. Multiple replies may be processed
268 * per single call to this routine; up to MPT_MAX_REPLIES_PER_ISR
269 * which is currently set to 32 in mptbase.h.
271 * This routine handles register-level access of the adapter but
272 * dispatches (calls) a protocol-specific callback routine to handle
273 * the protocol-specific details of the MPT request completion.
276 mpt_interrupt(int irq, void *bus_id, struct pt_regs *r)
287 ioc = (MPT_ADAPTER *)bus_id;
290 * Drain the reply FIFO!
292 * NOTES: I've seen up to 10 replies processed in this loop, so far...
293 * Update: I've seen up to 9182 replies processed in this loop! ??
294 * Update: Limit ourselves to processing max of N replies
299 if ((pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo)) == 0xFFFFFFFF)
306 * Check for non-TURBO reply!
308 if (pa & MPI_ADDRESS_REPLY_A_BIT) {
312 /* non-TURBO reply! Hmmm, something may be up...
313 * Newest turbo reply mechanism; get address
314 * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
317 /* Map DMA address of reply header to cpu address.
318 * pa is 32 bits - but the dma address may be 32 or 64 bits
319 * get offset based only only the low addresses
321 reply_dma_low = (pa = (pa << 1));
322 mr = (MPT_FRAME_HDR *)((u8 *)ioc->reply_frames +
323 (reply_dma_low - ioc->reply_frames_low_dma));
325 req_idx = le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx);
326 cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
327 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
329 dmfprintk((MYIOC_s_INFO_FMT "Got non-TURBO reply=%p req_idx=%x\n",
330 ioc->name, mr, req_idx));
331 DBG_DUMP_REPLY_FRAME(mr)
333 /* NEW! 20010301 -sralston
334 * Check/log IOC log info
336 ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
337 if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
338 u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
339 if (ioc->bus_type == FC)
340 mpt_fc_log_info(ioc, log_info);
341 else if (ioc->bus_type == SCSI)
342 mpt_sp_log_info(ioc, log_info);
344 if (ioc_stat & MPI_IOCSTATUS_MASK) {
345 if (ioc->bus_type == SCSI)
346 mpt_sp_ioc_info(ioc, (u32)ioc_stat, mf);
350 * Process turbo (context) reply...
352 dmfprintk((MYIOC_s_INFO_FMT "Got TURBO reply req_idx=%08x\n", ioc->name, pa));
353 type = (pa >> MPI_CONTEXT_REPLY_TYPE_SHIFT);
354 if (type == MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET) {
355 cb_idx = mpt_stm_index;
357 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
358 } else if (type == MPI_CONTEXT_REPLY_TYPE_LAN) {
359 cb_idx = mpt_lan_index;
361 * BUG FIX! 20001218 -sralston
362 * Blind set of mf to NULL here was fatal
363 * after lan_reply says "freeme"
364 * Fix sort of combined with an optimization here;
365 * added explicit check for case where lan_reply
366 * was just returning 1 and doing nothing else.
367 * For this case skip the callback, but set up
368 * proper mf value first here:-)
370 if ((pa & 0x58000000) == 0x58000000) {
371 req_idx = pa & 0x0000FFFF;
372 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
375 * IMPORTANT! Invalidate the callback!
381 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
383 req_idx = pa & 0x0000FFFF;
384 cb_idx = (pa & 0x00FF0000) >> 16;
385 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
388 pa = 0; /* No reply flush! */
392 if (ioc->bus_type == SCSI) {
393 /* Verify mf, mr are reasonable.
395 if ((mf) && ((mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))
396 || (mf < ioc->req_frames)) ) {
397 printk(MYIOC_s_WARN_FMT
398 "mpt_interrupt: Invalid mf (%p) req_idx (%d)!\n", ioc->name, (void *)mf, req_idx);
403 if ((pa) && (mr) && ((mr >= MPT_INDEX_2_RFPTR(ioc, ioc->req_depth))
404 || (mr < ioc->reply_frames)) ) {
405 printk(MYIOC_s_WARN_FMT
406 "mpt_interrupt: Invalid rf (%p)!\n", ioc->name, (void *)mr);
411 if (cb_idx > (MPT_MAX_PROTOCOL_DRIVERS-1)) {
412 printk(MYIOC_s_WARN_FMT
413 "mpt_interrupt: Invalid cb_idx (%d)!\n", ioc->name, cb_idx);
421 /* Check for (valid) IO callback! */
423 /* Do the callback! */
424 freeme = (*(MptCallbacks[cb_idx]))(ioc, mf, mr);
428 /* Flush (non-TURBO) reply with a WRITE! */
429 CHIPREG_WRITE32(&ioc->chip->ReplyFifo, pa);
435 /* Put Request back on FreeQ! */
436 spin_lock_irqsave(&ioc->FreeQlock, flags);
437 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
441 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
445 } /* drain reply FIFO */
450 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
452 * mpt_base_reply - MPT base driver's callback routine; all base driver
453 * "internal" request/reply processing is routed here.
454 * Currently used for EventNotification and EventAck handling.
455 * @ioc: Pointer to MPT_ADAPTER structure
456 * @mf: Pointer to original MPT request frame
457 * @reply: Pointer to MPT reply frame (NULL if TurboReply)
459 * Returns 1 indicating original alloc'd request frame ptr
460 * should be freed, or 0 if it shouldn't.
463 mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
468 dprintk((MYIOC_s_INFO_FMT "mpt_base_reply() called\n", ioc->name));
471 (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
472 printk(MYIOC_s_ERR_FMT "NULL or BAD request frame ptr! (=%p)\n",
473 ioc->name, (void *)mf);
478 dprintk((MYIOC_s_ERR_FMT "Unexpected NULL Event (turbo?) reply!\n",
483 if (!(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) {
484 dmfprintk((KERN_INFO MYNAM ": Original request frame (@%p) header\n", mf));
485 DBG_DUMP_REQUEST_FRAME_HDR(mf)
488 func = reply->u.hdr.Function;
489 dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, Function=%02Xh\n",
492 if (func == MPI_FUNCTION_EVENT_NOTIFICATION) {
493 EventNotificationReply_t *pEvReply = (EventNotificationReply_t *) reply;
497 results = ProcessEventNotification(ioc, pEvReply, &evHandlers);
498 if (results != evHandlers) {
499 /* CHECKME! Any special handling needed here? */
500 devtprintk((MYIOC_s_WARN_FMT "Called %d event handlers, sum results = %d\n",
501 ioc->name, evHandlers, results));
505 * Hmmm... It seems that EventNotificationReply is an exception
506 * to the rule of one reply per request.
508 if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)
511 #ifdef CONFIG_PROC_FS
512 // LogEvent(ioc, pEvReply);
515 } else if (func == MPI_FUNCTION_EVENT_ACK) {
516 dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, EventAck reply received\n",
518 } else if (func == MPI_FUNCTION_CONFIG ||
519 func == MPI_FUNCTION_TOOLBOX) {
523 dcprintk((MYIOC_s_INFO_FMT "config_complete (mf=%p,mr=%p)\n",
524 ioc->name, mf, reply));
526 pCfg = * ((CONFIGPARMS **)((u8 *) mf + ioc->req_sz - sizeof(void *)));
529 /* disable timer and remove from linked list */
530 del_timer(&pCfg->timer);
532 spin_lock_irqsave(&ioc->FreeQlock, flags);
533 list_del(&pCfg->linkage);
534 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
537 * If IOC Status is SUCCESS, save the header
538 * and set the status code to GOOD.
540 pCfg->status = MPT_CONFIG_ERROR;
542 ConfigReply_t *pReply = (ConfigReply_t *)reply;
545 status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
546 dcprintk((KERN_NOTICE " IOCStatus=%04xh, IOCLogInfo=%08xh\n",
547 status, le32_to_cpu(pReply->IOCLogInfo)));
549 pCfg->status = status;
550 if (status == MPI_IOCSTATUS_SUCCESS) {
551 pCfg->hdr->PageVersion = pReply->Header.PageVersion;
552 pCfg->hdr->PageLength = pReply->Header.PageLength;
553 pCfg->hdr->PageNumber = pReply->Header.PageNumber;
554 pCfg->hdr->PageType = pReply->Header.PageType;
559 * Wake up the original calling thread
565 printk(MYIOC_s_ERR_FMT "Unexpected msg function (=%02Xh) reply received!\n",
570 * Conditionally tell caller to free the original
571 * EventNotification/EventAck/unexpected request frame!
576 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
578 * mpt_register - Register protocol-specific main callback handler.
579 * @cbfunc: callback function pointer
580 * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
582 * This routine is called by a protocol-specific driver (SCSI host,
583 * LAN, SCSI target) to register it's reply callback routine. Each
584 * protocol-specific driver must do this before it will be able to
585 * use any IOC resources, such as obtaining request frames.
587 * NOTES: The SCSI protocol driver currently calls this routine thrice
588 * in order to register separate callbacks; one for "normal" SCSI IO;
589 * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
591 * Returns a positive integer valued "handle" in the
592 * range (and S.O.D. order) {N,...,7,6,5,...,1} if successful.
593 * Any non-positive return value (including zero!) should be considered
594 * an error by the caller.
597 mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
604 * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
605 * (slot/handle 0 is reserved!)
607 for (i = MPT_MAX_PROTOCOL_DRIVERS-1; i; i--) {
608 if (MptCallbacks[i] == NULL) {
609 MptCallbacks[i] = cbfunc;
610 MptDriverClass[i] = dclass;
611 MptEvHandlers[i] = NULL;
620 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
622 * mpt_deregister - Deregister a protocol drivers resources.
623 * @cb_idx: previously registered callback handle
625 * Each protocol-specific driver should call this routine when it's
626 * module is unloaded.
629 mpt_deregister(int cb_idx)
631 if ((cb_idx >= 0) && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
632 MptCallbacks[cb_idx] = NULL;
633 MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
634 MptEvHandlers[cb_idx] = NULL;
640 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
642 * mpt_event_register - Register protocol-specific event callback
644 * @cb_idx: previously registered (via mpt_register) callback handle
645 * @ev_cbfunc: callback function
647 * This routine can be called by one or more protocol-specific drivers
648 * if/when they choose to be notified of MPT events.
650 * Returns 0 for success.
653 mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc)
655 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
658 MptEvHandlers[cb_idx] = ev_cbfunc;
662 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
664 * mpt_event_deregister - Deregister protocol-specific event callback
666 * @cb_idx: previously registered callback handle
668 * Each protocol-specific driver should call this routine
669 * when it does not (or can no longer) handle events,
670 * or when it's module is unloaded.
673 mpt_event_deregister(int cb_idx)
675 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
678 MptEvHandlers[cb_idx] = NULL;
681 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
683 * mpt_reset_register - Register protocol-specific IOC reset handler.
684 * @cb_idx: previously registered (via mpt_register) callback handle
685 * @reset_func: reset function
687 * This routine can be called by one or more protocol-specific drivers
688 * if/when they choose to be notified of IOC resets.
690 * Returns 0 for success.
693 mpt_reset_register(int cb_idx, MPT_RESETHANDLER reset_func)
695 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
698 MptResetHandlers[cb_idx] = reset_func;
702 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
704 * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
705 * @cb_idx: previously registered callback handle
707 * Each protocol-specific driver should call this routine
708 * when it does not (or can no longer) handle IOC reset handling,
709 * or when it's module is unloaded.
712 mpt_reset_deregister(int cb_idx)
714 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
717 MptResetHandlers[cb_idx] = NULL;
720 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
722 * mpt_device_driver_register - Register device driver hooks
725 mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx)
730 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS) {
735 MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
737 /* call per pci device probe entry point */
738 list_for_each_entry(ioc, &ioc_list, list) {
739 if(dd_cbfunc->probe) {
740 error = dd_cbfunc->probe(ioc->pcidev,
741 ioc->pcidev->driver->id_table);
750 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
752 * mpt_device_driver_deregister - DeRegister device driver hooks
755 mpt_device_driver_deregister(int cb_idx)
757 struct mpt_pci_driver *dd_cbfunc;
760 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
763 dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
765 list_for_each_entry(ioc, &ioc_list, list) {
766 if (dd_cbfunc->remove)
767 dd_cbfunc->remove(ioc->pcidev);
770 MptDeviceDriverHandlers[cb_idx] = NULL;
774 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
776 * mpt_get_msg_frame - Obtain a MPT request frame from the pool (of 1024)
777 * allocated per MPT adapter.
778 * @handle: Handle of registered MPT protocol driver
779 * @ioc: Pointer to MPT adapter structure
781 * Returns pointer to a MPT request frame or %NULL if none are available
782 * or IOC is not active.
785 mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
789 u16 req_idx; /* Request index */
791 /* validate handle and ioc identifier */
795 printk(KERN_WARNING "IOC Not Active! mpt_get_msg_frame returning NULL!\n");
798 /* If interrupts are not attached, do not return a request frame */
802 spin_lock_irqsave(&ioc->FreeQlock, flags);
803 if (!list_empty(&ioc->FreeQ)) {
806 mf = list_entry(ioc->FreeQ.next, MPT_FRAME_HDR,
807 u.frame.linkage.list);
808 list_del(&mf->u.frame.linkage.list);
809 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
810 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
812 req_idx = cpu_to_le16(req_offset / ioc->req_sz);
813 mf->u.frame.hwhdr.msgctxu.fld.req_idx = req_idx;
814 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
815 ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame; /* Default, will be changed if necessary in SG generation */
822 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
826 printk(KERN_WARNING "IOC Active. No free Msg Frames! Count 0x%x Max 0x%x\n", ioc->mfcnt, ioc->req_depth);
828 if (mfcounter == PRINT_MF_COUNT)
829 printk(KERN_INFO "MF Count 0x%x Max 0x%x \n", ioc->mfcnt, ioc->req_depth);
832 dmfprintk((KERN_INFO MYNAM ": %s: mpt_get_msg_frame(%d,%d), got mf=%p\n",
833 ioc->name, handle, ioc->id, mf));
837 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
839 * mpt_put_msg_frame - Send a protocol specific MPT request frame
841 * @handle: Handle of registered MPT protocol driver
842 * @ioc: Pointer to MPT adapter structure
843 * @mf: Pointer to MPT request frame
845 * This routine posts a MPT request frame to the request post FIFO of a
846 * specific MPT adapter.
849 mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
853 u16 req_idx; /* Request index */
855 /* ensure values are reset properly! */
856 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
857 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
859 req_idx = cpu_to_le16(req_offset / ioc->req_sz);
860 mf->u.frame.hwhdr.msgctxu.fld.req_idx = req_idx;
861 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
863 #ifdef MPT_DEBUG_MSG_FRAME
865 u32 *m = mf->u.frame.hwhdr.__hdr;
868 printk(KERN_INFO MYNAM ": %s: About to Put msg frame @ %p:\n" KERN_INFO " ",
870 n = ioc->req_sz/4 - 1;
873 for (ii=0; ii<=n; ii++) {
874 if (ii && ((ii%8)==0))
875 printk("\n" KERN_INFO " ");
876 printk(" %08x", le32_to_cpu(m[ii]));
882 mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
883 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]));
884 CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
887 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
889 * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
890 * @handle: Handle of registered MPT protocol driver
891 * @ioc: Pointer to MPT adapter structure
892 * @mf: Pointer to MPT request frame
894 * This routine places a MPT request frame back on the MPT adapter's
898 mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
902 /* Put Request back on FreeQ! */
903 spin_lock_irqsave(&ioc->FreeQlock, flags);
904 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
908 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
911 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
913 * mpt_add_sge - Place a simple SGE at address pAddr.
914 * @pAddr: virtual address for SGE
915 * @flagslength: SGE flags and data transfer length
916 * @dma_addr: Physical address
918 * This routine places a MPT request frame back on the MPT adapter's
922 mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
924 if (sizeof(dma_addr_t) == sizeof(u64)) {
925 SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
926 u32 tmp = dma_addr & 0xFFFFFFFF;
928 pSge->FlagsLength = cpu_to_le32(flagslength);
929 pSge->Address.Low = cpu_to_le32(tmp);
930 tmp = (u32) ((u64)dma_addr >> 32);
931 pSge->Address.High = cpu_to_le32(tmp);
934 SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
935 pSge->FlagsLength = cpu_to_le32(flagslength);
936 pSge->Address = cpu_to_le32(dma_addr);
940 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
942 * mpt_send_handshake_request - Send MPT request via doorbell
944 * @handle: Handle of registered MPT protocol driver
945 * @ioc: Pointer to MPT adapter structure
946 * @reqBytes: Size of the request in bytes
947 * @req: Pointer to MPT request frame
948 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
950 * This routine is used exclusively to send MptScsiTaskMgmt
951 * requests since they are required to be sent via doorbell handshake.
953 * NOTE: It is the callers responsibility to byte-swap fields in the
954 * request which are greater than 1 byte in size.
956 * Returns 0 for success, non-zero for failure.
959 mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
965 /* State is known to be good upon entering
966 * this function so issue the bus reset
971 * Emulate what mpt_put_msg_frame() does /wrt to sanity
972 * setting cb_idx/req_idx. But ONLY if this request
973 * is in proper (pre-alloc'd) request buffer range...
975 ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
976 if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
977 MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
978 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
979 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle;
982 /* Make sure there are no doorbells */
983 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
985 CHIPREG_WRITE32(&ioc->chip->Doorbell,
986 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
987 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
989 /* Wait for IOC doorbell int */
990 if ((ii = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0) {
994 /* Read doorbell and check for active bit */
995 if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
998 dhsprintk((KERN_INFO MYNAM ": %s: mpt_send_handshake_request start, WaitCnt=%d\n",
1001 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1003 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
1007 /* Send request via doorbell handshake */
1008 req_as_bytes = (u8 *) req;
1009 for (ii = 0; ii < reqBytes/4; ii++) {
1012 word = ((req_as_bytes[(ii*4) + 0] << 0) |
1013 (req_as_bytes[(ii*4) + 1] << 8) |
1014 (req_as_bytes[(ii*4) + 2] << 16) |
1015 (req_as_bytes[(ii*4) + 3] << 24));
1016 CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
1017 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
1023 if (r >= 0 && WaitForDoorbellInt(ioc, 10, sleepFlag) >= 0)
1028 /* Make sure there are no doorbells */
1029 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1034 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1036 * mpt_verify_adapter - Given a unique IOC identifier, set pointer to
1037 * the associated MPT adapter structure.
1038 * @iocid: IOC unique identifier (integer)
1039 * @iocpp: Pointer to pointer to IOC adapter
1041 * Returns iocid and sets iocpp.
1044 mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
1048 list_for_each_entry(ioc,&ioc_list,list) {
1049 if (ioc->id == iocid) {
1059 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1061 * mptbase_probe - Install a PCI intelligent MPT adapter.
1062 * @pdev: Pointer to pci_dev structure
1064 * This routine performs all the steps necessary to bring the IOC of
1065 * a MPT adapter to a OPERATIONAL state. This includes registering
1066 * memory regions, registering the interrupt, and allocating request
1067 * and reply memory pools.
1069 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1072 * Returns 0 for success, non-zero for failure.
1074 * TODO: Add support for polled controllers
1076 static int __devinit
1077 mptbase_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1081 unsigned long mem_phys;
1087 u64 mask = 0xffffffffffffffffULL;
1090 static int mpt_ids = 0;
1091 #ifdef CONFIG_PROC_FS
1092 struct proc_dir_entry *dent, *ent;
1095 if (pci_enable_device(pdev))
1098 dinitprintk((KERN_WARNING MYNAM ": mpt_adapter_install\n"));
1100 if (!pci_set_dma_mask(pdev, mask)) {
1101 dprintk((KERN_INFO MYNAM
1102 ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n"));
1103 } else if (pci_set_dma_mask(pdev, (u64) 0xffffffff)) {
1104 printk(KERN_WARNING MYNAM ": 32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
1108 if (!pci_set_consistent_dma_mask(pdev, mask))
1109 dprintk((KERN_INFO MYNAM
1110 ": Using 64 bit consistent mask\n"));
1112 dprintk((KERN_INFO MYNAM
1113 ": Not using 64 bit consistent mask\n"));
1115 ioc = kmalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
1117 printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
1120 memset(ioc, 0, sizeof(MPT_ADAPTER));
1121 ioc->alloc_total = sizeof(MPT_ADAPTER);
1122 ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
1123 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
1126 ioc->diagPending = 0;
1127 spin_lock_init(&ioc->diagLock);
1129 /* Initialize the event logging.
1131 ioc->eventTypes = 0; /* None */
1132 ioc->eventContext = 0;
1133 ioc->eventLogSize = 0;
1140 ioc->cached_fw = NULL;
1142 /* Initilize SCSI Config Data structure
1144 memset(&ioc->spi_data, 0, sizeof(ScsiCfgData));
1146 /* Initialize the running configQ head.
1148 INIT_LIST_HEAD(&ioc->configQ);
1150 /* Find lookup slot. */
1151 INIT_LIST_HEAD(&ioc->list);
1152 ioc->id = mpt_ids++;
1154 mem_phys = msize = 0;
1156 for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) {
1157 if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
1158 /* Get I/O space! */
1159 port = pci_resource_start(pdev, ii);
1160 psize = pci_resource_len(pdev,ii);
1163 mem_phys = pci_resource_start(pdev, ii);
1164 msize = pci_resource_len(pdev,ii);
1168 ioc->mem_size = msize;
1170 if (ii == DEVICE_COUNT_RESOURCE) {
1171 printk(KERN_ERR MYNAM ": ERROR - MPT adapter has no memory regions defined!\n");
1176 dinitprintk((KERN_INFO MYNAM ": MPT adapter @ %lx, msize=%dd bytes\n", mem_phys, msize));
1177 dinitprintk((KERN_INFO MYNAM ": (port i/o @ %lx, psize=%dd bytes)\n", port, psize));
1180 /* Get logical ptr for PciMem0 space */
1181 /*mem = ioremap(mem_phys, msize);*/
1182 mem = ioremap(mem_phys, 0x100);
1184 printk(KERN_ERR MYNAM ": ERROR - Unable to map adapter memory!\n");
1189 dinitprintk((KERN_INFO MYNAM ": mem = %p, mem_phys = %lx\n", mem, mem_phys));
1191 dinitprintk((KERN_INFO MYNAM ": facts @ %p, pfacts[0] @ %p\n",
1192 &ioc->facts, &ioc->pfacts[0]));
1194 ioc->mem_phys = mem_phys;
1195 ioc->chip = (SYSIF_REGS __iomem *)mem;
1197 /* Save Port IO values in case we need to do downloadboot */
1199 u8 *pmem = (u8*)port;
1200 ioc->pio_mem_phys = port;
1201 ioc->pio_chip = (SYSIF_REGS __iomem *)pmem;
1204 if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC909) {
1205 ioc->prod_name = "LSIFC909";
1208 if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929) {
1209 ioc->prod_name = "LSIFC929";
1212 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919) {
1213 ioc->prod_name = "LSIFC919";
1216 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929X) {
1217 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1219 if (revision < XL_929) {
1220 ioc->prod_name = "LSIFC929X";
1221 /* 929X Chip Fix. Set Split transactions level
1222 * for PCIX. Set MOST bits to zero.
1224 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1226 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1228 ioc->prod_name = "LSIFC929XL";
1229 /* 929XL Chip Fix. Set MMRBC to 0x08.
1231 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1233 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1236 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919X) {
1237 ioc->prod_name = "LSIFC919X";
1239 /* 919X Chip Fix. Set Split transactions level
1240 * for PCIX. Set MOST bits to zero.
1242 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1244 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1246 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_53C1030) {
1247 ioc->prod_name = "LSI53C1030";
1248 ioc->bus_type = SCSI;
1249 /* 1030 Chip Fix. Disable Split transactions
1250 * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
1252 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1253 if (revision < C0_1030) {
1254 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1256 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1259 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_1030_53C1035) {
1260 ioc->prod_name = "LSI53C1035";
1261 ioc->bus_type = SCSI;
1264 sprintf(ioc->name, "ioc%d", ioc->id);
1266 spin_lock_init(&ioc->FreeQlock);
1269 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1271 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1273 /* Set lookup ptr. */
1274 list_add_tail(&ioc->list, &ioc_list);
1278 r = request_irq(pdev->irq, mpt_interrupt, SA_SHIRQ, ioc->name, ioc);
1282 printk(MYIOC_s_ERR_FMT "Unable to allocate interrupt %d!\n",
1283 ioc->name, pdev->irq);
1285 printk(MYIOC_s_ERR_FMT "Unable to allocate interrupt %s!\n",
1286 ioc->name, __irq_itoa(pdev->irq));
1288 list_del(&ioc->list);
1294 ioc->pci_irq = pdev->irq;
1296 pci_set_master(pdev); /* ?? */
1297 pci_set_drvdata(pdev, ioc);
1300 dprintk((KERN_INFO MYNAM ": %s installed at interrupt %d\n", ioc->name, pdev->irq));
1302 dprintk((KERN_INFO MYNAM ": %s installed at interrupt %s\n", ioc->name, __irq_itoa(pdev->irq)));
1306 /* NEW! 20010220 -sralston
1307 * Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
1309 mpt_detect_bound_ports(ioc, pdev);
1311 if ((r = mpt_do_ioc_recovery(ioc,
1312 MPT_HOSTEVENT_IOC_BRINGUP, CAN_SLEEP)) != 0) {
1313 printk(KERN_WARNING MYNAM
1314 ": WARNING - %s did not initialize properly! (%d)\n",
1317 list_del(&ioc->list);
1318 free_irq(ioc->pci_irq, ioc);
1321 pci_set_drvdata(pdev, NULL);
1325 /* call per device driver probe entry point */
1326 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1327 if(MptDeviceDriverHandlers[ii] &&
1328 MptDeviceDriverHandlers[ii]->probe) {
1329 MptDeviceDriverHandlers[ii]->probe(pdev,id);
1333 #ifdef CONFIG_PROC_FS
1335 * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
1337 dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
1339 ent = create_proc_entry("info", S_IFREG|S_IRUGO, dent);
1341 ent->read_proc = procmpt_iocinfo_read;
1344 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, dent);
1346 ent->read_proc = procmpt_summary_read;
1355 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1357 * mptbase_remove - Remove a PCI intelligent MPT adapter.
1358 * @pdev: Pointer to pci_dev structure
1362 static void __devexit
1363 mptbase_remove(struct pci_dev *pdev)
1365 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1369 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
1370 remove_proc_entry(pname, NULL);
1371 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/info", ioc->name);
1372 remove_proc_entry(pname, NULL);
1373 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
1374 remove_proc_entry(pname, NULL);
1376 /* call per device driver remove entry point */
1377 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1378 if(MptDeviceDriverHandlers[ii] &&
1379 MptDeviceDriverHandlers[ii]->remove) {
1380 MptDeviceDriverHandlers[ii]->remove(pdev);
1384 /* Disable interrupts! */
1385 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1388 synchronize_irq(pdev->irq);
1390 /* Clear any lingering interrupt */
1391 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1393 CHIPREG_READ32(&ioc->chip->IntStatus);
1395 mpt_adapter_dispose(ioc);
1397 pci_set_drvdata(pdev, NULL);
1400 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1402 * mptbase_shutdown -
1406 mptbase_shutdown(struct device * dev)
1410 /* call per device driver shutdown entry point */
1411 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1412 if(MptDeviceDriverHandlers[ii] &&
1413 MptDeviceDriverHandlers[ii]->shutdown) {
1414 MptDeviceDriverHandlers[ii]->shutdown(dev);
1421 /**************************************************************************
1425 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1427 * mptbase_suspend - Fusion MPT base driver suspend routine.
1432 mptbase_suspend(struct pci_dev *pdev, u32 state)
1435 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1441 device_state=1; /* D1 */;
1445 device_state=3; /* D3 */;
1448 return -EAGAIN /*FIXME*/;
1452 printk(MYIOC_s_INFO_FMT
1453 "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n",
1454 ioc->name, pdev, pci_name(pdev), device_state);
1456 /* call per device driver suspend entry point */
1457 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1458 if(MptDeviceDriverHandlers[ii] &&
1459 MptDeviceDriverHandlers[ii]->suspend) {
1460 MptDeviceDriverHandlers[ii]->suspend(pdev, state);
1464 pci_save_state(pdev);
1466 /* put ioc into READY_STATE */
1467 if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
1468 printk(MYIOC_s_ERR_FMT
1469 "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
1472 /* disable interrupts */
1473 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1476 /* Clear any lingering interrupt */
1477 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1479 pci_disable_device(pdev);
1480 pci_set_power_state(pdev, device_state);
1485 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1487 * mptbase_resume - Fusion MPT base driver resume routine.
1492 mptbase_resume(struct pci_dev *pdev)
1494 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1495 u32 device_state = pdev->current_state;
1499 printk(MYIOC_s_INFO_FMT
1500 "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n",
1501 ioc->name, pdev, pci_name(pdev), device_state);
1503 pci_set_power_state(pdev, 0);
1504 pci_restore_state(pdev);
1505 pci_enable_device(pdev);
1507 /* enable interrupts */
1508 CHIPREG_WRITE32(&ioc->chip->IntMask, ~(MPI_HIM_RIM));
1511 /* F/W not running */
1512 if(!CHIPREG_READ32(&ioc->chip->Doorbell)) {
1513 /* enable domain validation flags */
1514 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
1515 ioc->spi_data.dvStatus[ii] |= MPT_SCSICFG_NEED_DV;
1519 printk(MYIOC_s_INFO_FMT
1520 "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
1522 (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
1523 CHIPREG_READ32(&ioc->chip->Doorbell));
1525 /* bring ioc to operational state */
1526 if ((recovery_state = mpt_do_ioc_recovery(ioc,
1527 MPT_HOSTEVENT_IOC_RECOVER, CAN_SLEEP)) != 0) {
1528 printk(MYIOC_s_INFO_FMT
1529 "pci-resume: Cannot recover, error:[%x]\n",
1530 ioc->name, recovery_state);
1532 printk(MYIOC_s_INFO_FMT
1533 "pci-resume: success\n", ioc->name);
1536 /* call per device driver resume entry point */
1537 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1538 if(MptDeviceDriverHandlers[ii] &&
1539 MptDeviceDriverHandlers[ii]->resume) {
1540 MptDeviceDriverHandlers[ii]->resume(pdev);
1548 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1550 * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
1551 * @ioc: Pointer to MPT adapter structure
1552 * @reason: Event word / reason
1553 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
1555 * This routine performs all the steps necessary to bring the IOC
1556 * to a OPERATIONAL state.
1558 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1563 * -1 if failed to get board READY
1564 * -2 if READY but IOCFacts Failed
1565 * -3 if READY but PrimeIOCFifos Failed
1566 * -4 if READY but IOCInit Failed
1569 mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1571 int hard_reset_done = 0;
1572 int alt_ioc_ready = 0;
1578 int reset_alt_ioc_active = 0;
1580 printk(KERN_INFO MYNAM ": Initiating %s %s\n",
1581 ioc->name, reason==MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
1583 /* Disable reply interrupts (also blocks FreeQ) */
1584 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1588 if (ioc->alt_ioc->active)
1589 reset_alt_ioc_active = 1;
1591 /* Disable alt-IOC's reply interrupts (and FreeQ) for a bit ... */
1592 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, 0xFFFFFFFF);
1593 ioc->alt_ioc->active = 0;
1597 if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
1600 if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
1601 if (hard_reset_done == -4) {
1602 printk(KERN_WARNING MYNAM ": %s Owned by PEER..skipping!\n",
1605 if (reset_alt_ioc_active && ioc->alt_ioc) {
1606 /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
1607 dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
1608 ioc->alt_ioc->name));
1609 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM));
1610 ioc->alt_ioc->active = 1;
1614 printk(KERN_WARNING MYNAM ": %s NOT READY WARNING!\n",
1620 /* hard_reset_done = 0 if a soft reset was performed
1621 * and 1 if a hard reset was performed.
1623 if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
1624 if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
1627 printk(KERN_WARNING MYNAM
1628 ": alt-%s: Not ready WARNING!\n",
1629 ioc->alt_ioc->name);
1632 for (ii=0; ii<5; ii++) {
1633 /* Get IOC facts! Allow 5 retries */
1634 if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
1640 dinitprintk((MYIOC_s_INFO_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc));
1642 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1643 MptDisplayIocCapabilities(ioc);
1646 if (alt_ioc_ready) {
1647 if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
1648 dinitprintk((MYIOC_s_INFO_FMT "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc));
1649 /* Retry - alt IOC was initialized once
1651 rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
1654 dinitprintk((MYIOC_s_INFO_FMT "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
1656 reset_alt_ioc_active = 0;
1657 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1658 MptDisplayIocCapabilities(ioc->alt_ioc);
1662 /* Prime reply & request queues!
1663 * (mucho alloc's) Must be done prior to
1664 * init as upper addresses are needed for init.
1665 * If fails, continue with alt-ioc processing
1667 if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
1670 /* May need to check/upload firmware & data here!
1671 * If fails, continue with alt-ioc processing
1673 if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
1676 if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
1677 printk(KERN_WARNING MYNAM ": alt-%s: (%d) FIFO mgmt alloc WARNING!\n",
1678 ioc->alt_ioc->name, rc);
1680 reset_alt_ioc_active = 0;
1683 if (alt_ioc_ready) {
1684 if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
1686 reset_alt_ioc_active = 0;
1687 printk(KERN_WARNING MYNAM
1688 ": alt-%s: (%d) init failure WARNING!\n",
1689 ioc->alt_ioc->name, rc);
1693 if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
1694 if (ioc->upload_fw) {
1695 ddlprintk((MYIOC_s_INFO_FMT
1696 "firmware upload required!\n", ioc->name));
1698 /* Controller is not operational, cannot do upload
1701 rc = mpt_do_upload(ioc, sleepFlag);
1703 printk(KERN_WARNING MYNAM ": firmware upload failure!\n");
1709 /* Enable! (reply interrupt) */
1710 CHIPREG_WRITE32(&ioc->chip->IntMask, ~(MPI_HIM_RIM));
1714 if (reset_alt_ioc_active && ioc->alt_ioc) {
1715 /* (re)Enable alt-IOC! (reply interrupt) */
1716 dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
1717 ioc->alt_ioc->name));
1718 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM));
1719 ioc->alt_ioc->active = 1;
1722 /* NEW! 20010120 -sralston
1723 * Enable MPT base driver management of EventNotification
1724 * and EventAck handling.
1726 if ((ret == 0) && (!ioc->facts.EventState))
1727 (void) SendEventNotification(ioc, 1); /* 1=Enable EventNotification */
1729 if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
1730 (void) SendEventNotification(ioc->alt_ioc, 1); /* 1=Enable EventNotification */
1732 /* (Bugzilla:fibrebugs, #513)
1733 * Bug fix (part 2)! 20010905 -sralston
1734 * Add additional "reason" check before call to GetLanConfigPages
1735 * (combined with GetIoUnitPage2 call). This prevents a somewhat
1736 * recursive scenario; GetLanConfigPages times out, timer expired
1737 * routine calls HardResetHandler, which calls into here again,
1738 * and we try GetLanConfigPages again...
1740 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
1741 if (ioc->bus_type == FC) {
1743 * Pre-fetch FC port WWN and stuff...
1744 * (FCPortPage0_t stuff)
1746 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
1747 (void) GetFcPortPage0(ioc, ii);
1750 if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
1751 (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
1753 * Pre-fetch the ports LAN MAC address!
1754 * (LANPage1_t stuff)
1756 (void) GetLanConfigPages(ioc);
1759 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
1760 dprintk((MYIOC_s_INFO_FMT "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1761 ioc->name, a[5], a[4], a[3], a[2], a[1], a[0] ));
1766 /* Get NVRAM and adapter maximums from SPP 0 and 2
1768 mpt_GetScsiPortSettings(ioc, 0);
1770 /* Get version and length of SDP 1
1772 mpt_readScsiDevicePageHeaders(ioc, 0);
1776 if (ioc->facts.MsgVersion >= 0x0102)
1777 mpt_findImVolumes(ioc);
1779 /* Check, and possibly reset, the coalescing value
1781 mpt_read_ioc_pg_1(ioc);
1783 mpt_read_ioc_pg_4(ioc);
1786 GetIoUnitPage2(ioc);
1790 * Call each currently registered protocol IOC reset handler
1791 * with post-reset indication.
1792 * NOTE: If we're doing _IOC_BRINGUP, there can be no
1793 * MptResetHandlers[] registered yet.
1795 if (hard_reset_done) {
1797 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
1798 if ((ret == 0) && MptResetHandlers[ii]) {
1799 dprintk((MYIOC_s_INFO_FMT "Calling IOC post_reset handler #%d\n",
1801 rc += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_POST_RESET);
1805 if (alt_ioc_ready && MptResetHandlers[ii]) {
1806 dprintk((MYIOC_s_INFO_FMT "Calling alt-%s post_reset handler #%d\n",
1807 ioc->name, ioc->alt_ioc->name, ii));
1808 rc += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_POST_RESET);
1812 /* FIXME? Examine results here? */
1818 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1820 * mpt_detect_bound_ports - Search for PCI bus/dev_function
1821 * which matches PCI bus/dev_function (+/-1) for newly discovered 929,
1822 * 929X, 1030 or 1035.
1823 * @ioc: Pointer to MPT adapter structure
1824 * @pdev: Pointer to (struct pci_dev) structure
1826 * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
1827 * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
1830 mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
1832 unsigned int match_lo, match_hi;
1833 MPT_ADAPTER *ioc_srch;
1835 match_lo = pdev->devfn-1;
1836 match_hi = pdev->devfn+1;
1837 dprintk((MYIOC_s_INFO_FMT "PCI bus/devfn=%x/%x, searching for devfn match on %x or %x\n",
1838 ioc->name, pdev->bus->number, pdev->devfn, match_lo, match_hi));
1840 list_for_each_entry(ioc_srch, &ioc_list, list) {
1841 struct pci_dev *_pcidev = ioc_srch->pcidev;
1843 if ((_pcidev->device == pdev->device) &&
1844 (_pcidev->bus->number == pdev->bus->number) &&
1845 (_pcidev->devfn == match_lo || _pcidev->devfn == match_hi) ) {
1846 /* Paranoia checks */
1847 if (ioc->alt_ioc != NULL) {
1848 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
1849 ioc->name, ioc->alt_ioc->name);
1851 } else if (ioc_srch->alt_ioc != NULL) {
1852 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
1853 ioc_srch->name, ioc_srch->alt_ioc->name);
1856 dprintk((KERN_INFO MYNAM ": FOUND! binding %s <==> %s\n",
1857 ioc->name, ioc_srch->name));
1858 ioc_srch->alt_ioc = ioc;
1859 ioc->alt_ioc = ioc_srch;
1865 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1867 * mpt_adapter_disable - Disable misbehaving MPT adapter.
1868 * @this: Pointer to MPT adapter structure
1871 mpt_adapter_disable(MPT_ADAPTER *ioc)
1876 if (ioc->cached_fw != NULL) {
1877 ddlprintk((KERN_INFO MYNAM ": mpt_adapter_disable: Pushing FW onto adapter\n"));
1878 if ((ret = mpt_downloadboot(ioc, NO_SLEEP)) < 0) {
1879 printk(KERN_WARNING MYNAM
1880 ": firmware downloadboot failure (%d)!\n", ret);
1884 /* Disable adapter interrupts! */
1885 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1887 /* Clear any lingering interrupt */
1888 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1890 if (ioc->alloc != NULL) {
1892 dexitprintk((KERN_INFO MYNAM ": %s.free @ %p, sz=%d bytes\n",
1893 ioc->name, ioc->alloc, ioc->alloc_sz));
1894 pci_free_consistent(ioc->pcidev, sz,
1895 ioc->alloc, ioc->alloc_dma);
1896 ioc->reply_frames = NULL;
1897 ioc->req_frames = NULL;
1899 ioc->alloc_total -= sz;
1902 if (ioc->sense_buf_pool != NULL) {
1903 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
1904 pci_free_consistent(ioc->pcidev, sz,
1905 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
1906 ioc->sense_buf_pool = NULL;
1907 ioc->alloc_total -= sz;
1910 if (ioc->events != NULL){
1911 sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
1914 ioc->alloc_total -= sz;
1917 if (ioc->cached_fw != NULL) {
1918 sz = ioc->facts.FWImageSize;
1919 pci_free_consistent(ioc->pcidev, sz,
1920 ioc->cached_fw, ioc->cached_fw_dma);
1921 ioc->cached_fw = NULL;
1922 ioc->alloc_total -= sz;
1925 if (ioc->spi_data.nvram != NULL) {
1926 kfree(ioc->spi_data.nvram);
1927 ioc->spi_data.nvram = NULL;
1930 if (ioc->spi_data.pIocPg3 != NULL) {
1931 kfree(ioc->spi_data.pIocPg3);
1932 ioc->spi_data.pIocPg3 = NULL;
1935 if (ioc->spi_data.pIocPg4 != NULL) {
1936 sz = ioc->spi_data.IocPg4Sz;
1937 pci_free_consistent(ioc->pcidev, sz,
1938 ioc->spi_data.pIocPg4,
1939 ioc->spi_data.IocPg4_dma);
1940 ioc->spi_data.pIocPg4 = NULL;
1941 ioc->alloc_total -= sz;
1944 if (ioc->ReqToChain != NULL) {
1945 kfree(ioc->ReqToChain);
1946 kfree(ioc->RequestNB);
1947 ioc->ReqToChain = NULL;
1950 if (ioc->ChainToChain != NULL) {
1951 kfree(ioc->ChainToChain);
1952 ioc->ChainToChain = NULL;
1956 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1958 * mpt_adapter_dispose - Free all resources associated with a MPT
1960 * @ioc: Pointer to MPT adapter structure
1962 * This routine unregisters h/w resources and frees all alloc'd memory
1963 * associated with a MPT adapter structure.
1966 mpt_adapter_dispose(MPT_ADAPTER *ioc)
1969 int sz_first, sz_last;
1971 sz_first = ioc->alloc_total;
1973 mpt_adapter_disable(ioc);
1975 if (ioc->pci_irq != -1) {
1976 free_irq(ioc->pci_irq, ioc);
1980 if (ioc->memmap != NULL)
1981 iounmap(ioc->memmap);
1983 #if defined(CONFIG_MTRR) && 0
1984 if (ioc->mtrr_reg > 0) {
1985 mtrr_del(ioc->mtrr_reg, 0, 0);
1986 dprintk((KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
1990 /* Zap the adapter lookup ptr! */
1991 list_del(&ioc->list);
1993 sz_last = ioc->alloc_total;
1994 dprintk((KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
1995 ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
2000 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2002 * MptDisplayIocCapabilities - Disply IOC's capacilities.
2003 * @ioc: Pointer to MPT adapter structure
2006 MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
2010 printk(KERN_INFO "%s: ", ioc->name);
2011 if (ioc->prod_name && strlen(ioc->prod_name) > 3)
2012 printk("%s: ", ioc->prod_name+3);
2013 printk("Capabilities={");
2015 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
2016 printk("Initiator");
2020 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2021 printk("%sTarget", i ? "," : "");
2025 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
2026 printk("%sLAN", i ? "," : "");
2032 * This would probably evoke more questions than it's worth
2034 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2035 printk("%sLogBusAddr", i ? "," : "");
2043 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2045 * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
2046 * @ioc: Pointer to MPT_ADAPTER structure
2047 * @force: Force hard KickStart of IOC
2048 * @sleepFlag: Specifies whether the process can sleep
2051 * 1 - DIAG reset and READY
2052 * 0 - READY initially OR soft reset and READY
2053 * -1 - Any failure on KickStart
2054 * -2 - Msg Unit Reset Failed
2055 * -3 - IO Unit Reset Failed
2056 * -4 - IOC owned by a PEER
2059 MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
2064 int hard_reset_done = 0;
2069 /* Get current [raw] IOC state */
2070 ioc_state = mpt_GetIocState(ioc, 0);
2071 dhsprintk((KERN_INFO MYNAM "::MakeIocReady, %s [raw] state=%08x\n", ioc->name, ioc_state));
2074 * Check to see if IOC got left/stuck in doorbell handshake
2075 * grip of death. If so, hard reset the IOC.
2077 if (ioc_state & MPI_DOORBELL_ACTIVE) {
2079 printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
2083 /* Is it already READY? */
2084 if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
2088 * Check to see if IOC is in FAULT state.
2090 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
2092 printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
2094 printk(KERN_WARNING " FAULT code = %04xh\n",
2095 ioc_state & MPI_DOORBELL_DATA_MASK);
2099 * Hmmm... Did it get left operational?
2101 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
2102 dinitprintk((MYIOC_s_WARN_FMT "IOC operational unexpected\n",
2106 * If PCI Peer, exit.
2107 * Else, if no fault conditions are present, issue a MessageUnitReset
2108 * Else, fall through to KickStart case
2110 whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
2111 dprintk((KERN_WARNING MYNAM
2112 ": whoinit 0x%x\n statefault %d force %d\n",
2113 whoinit, statefault, force));
2114 if (whoinit == MPI_WHOINIT_PCI_PEER)
2117 if ((statefault == 0 ) && (force == 0)) {
2118 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
2125 hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
2126 if (hard_reset_done < 0)
2130 * Loop here waiting for IOC to come READY.
2133 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
2135 while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
2136 if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
2138 * BIOS or previous driver load left IOC in OP state.
2139 * Reset messaging FIFOs.
2141 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
2142 printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
2145 } else if (ioc_state == MPI_IOC_STATE_RESET) {
2147 * Something is wrong. Try to get IOC back
2150 if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
2151 printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
2158 printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
2159 ioc->name, (int)((ii+5)/HZ));
2163 if (sleepFlag == CAN_SLEEP) {
2164 msleep_interruptible(1);
2166 mdelay (1); /* 1 msec delay */
2171 if (statefault < 3) {
2172 printk(MYIOC_s_INFO_FMT "Recovered from %s\n",
2174 statefault==1 ? "stuck handshake" : "IOC FAULT");
2177 return hard_reset_done;
2180 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2182 * mpt_GetIocState - Get the current state of a MPT adapter.
2183 * @ioc: Pointer to MPT_ADAPTER structure
2184 * @cooked: Request raw or cooked IOC state
2186 * Returns all IOC Doorbell register bits if cooked==0, else just the
2187 * Doorbell bits in MPI_IOC_STATE_MASK.
2190 mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
2195 s = CHIPREG_READ32(&ioc->chip->Doorbell);
2196 // dprintk((MYIOC_s_INFO_FMT "raw state = %08x\n", ioc->name, s));
2197 sc = s & MPI_IOC_STATE_MASK;
2200 ioc->last_state = sc;
2202 return cooked ? sc : s;
2205 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2207 * GetIocFacts - Send IOCFacts request to MPT adapter.
2208 * @ioc: Pointer to MPT_ADAPTER structure
2209 * @sleepFlag: Specifies whether the process can sleep
2210 * @reason: If recovery, only update facts.
2212 * Returns 0 for success, non-zero for failure.
2215 GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2217 IOCFacts_t get_facts;
2218 IOCFactsReply_t *facts;
2226 /* IOC *must* NOT be in RESET state! */
2227 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2228 printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
2234 facts = &ioc->facts;
2236 /* Destination (reply area)... */
2237 reply_sz = sizeof(*facts);
2238 memset(facts, 0, reply_sz);
2240 /* Request area (get_facts on the stack right now!) */
2241 req_sz = sizeof(get_facts);
2242 memset(&get_facts, 0, req_sz);
2244 get_facts.Function = MPI_FUNCTION_IOC_FACTS;
2245 /* Assert: All other get_facts fields are zero! */
2247 dinitprintk((MYIOC_s_INFO_FMT
2248 "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
2249 ioc->name, req_sz, reply_sz));
2251 /* No non-zero fields in the get_facts request are greater than
2252 * 1 byte in size, so we can just fire it off as is.
2254 r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
2255 reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
2260 * Now byte swap (GRRR) the necessary fields before any further
2261 * inspection of reply contents.
2263 * But need to do some sanity checks on MsgLength (byte) field
2264 * to make sure we don't zero IOC's req_sz!
2266 /* Did we get a valid reply? */
2267 if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
2268 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2270 * If not been here, done that, save off first WhoInit value
2272 if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
2273 ioc->FirstWhoInit = facts->WhoInit;
2276 facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
2277 facts->MsgContext = le32_to_cpu(facts->MsgContext);
2278 facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
2279 facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
2280 facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
2281 status = facts->IOCStatus & MPI_IOCSTATUS_MASK;
2282 /* CHECKME! IOCStatus, IOCLogInfo */
2284 facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
2285 facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
2288 * FC f/w version changed between 1.1 and 1.2
2289 * Old: u16{Major(4),Minor(4),SubMinor(8)}
2290 * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
2292 if (facts->MsgVersion < 0x0102) {
2294 * Handle old FC f/w style, convert to new...
2296 u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
2297 facts->FWVersion.Word =
2298 ((oldv<<12) & 0xFF000000) |
2299 ((oldv<<8) & 0x000FFF00);
2301 facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
2303 facts->ProductID = le16_to_cpu(facts->ProductID);
2304 facts->CurrentHostMfaHighAddr =
2305 le32_to_cpu(facts->CurrentHostMfaHighAddr);
2306 facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
2307 facts->CurrentSenseBufferHighAddr =
2308 le32_to_cpu(facts->CurrentSenseBufferHighAddr);
2309 facts->CurReplyFrameSize =
2310 le16_to_cpu(facts->CurReplyFrameSize);
2313 * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
2314 * Older MPI-1.00.xx struct had 13 dwords, and enlarged
2315 * to 14 in MPI-1.01.0x.
2317 if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
2318 facts->MsgVersion > 0x0100) {
2319 facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
2322 sz = facts->FWImageSize;
2327 facts->FWImageSize = sz;
2329 if (!facts->RequestFrameSize) {
2330 /* Something is wrong! */
2331 printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
2336 r = sz = le32_to_cpu(facts->BlockSize);
2337 vv = ((63 / (sz * 4)) + 1) & 0x03;
2338 ioc->NB_for_64_byte_frame = vv;
2344 ioc->NBShiftFactor = shiftFactor;
2345 dinitprintk((MYIOC_s_INFO_FMT "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
2346 ioc->name, vv, shiftFactor, r));
2348 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2350 * Set values for this IOC's request & reply frame sizes,
2351 * and request & reply queue depths...
2353 ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
2354 ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
2355 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
2356 ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
2358 dinitprintk((MYIOC_s_INFO_FMT "reply_sz=%3d, reply_depth=%4d\n",
2359 ioc->name, ioc->reply_sz, ioc->reply_depth));
2360 dinitprintk((MYIOC_s_INFO_FMT "req_sz =%3d, req_depth =%4d\n",
2361 ioc->name, ioc->req_sz, ioc->req_depth));
2363 /* Get port facts! */
2364 if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
2368 printk(MYIOC_s_ERR_FMT
2369 "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
2370 ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
2371 RequestFrameSize)/sizeof(u32)));
2378 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2380 * GetPortFacts - Send PortFacts request to MPT adapter.
2381 * @ioc: Pointer to MPT_ADAPTER structure
2382 * @portnum: Port number
2383 * @sleepFlag: Specifies whether the process can sleep
2385 * Returns 0 for success, non-zero for failure.
2388 GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2390 PortFacts_t get_pfacts;
2391 PortFactsReply_t *pfacts;
2396 /* IOC *must* NOT be in RESET state! */
2397 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2398 printk(KERN_ERR MYNAM ": ERROR - Can't get PortFacts, %s NOT READY! (%08x)\n",
2404 pfacts = &ioc->pfacts[portnum];
2406 /* Destination (reply area)... */
2407 reply_sz = sizeof(*pfacts);
2408 memset(pfacts, 0, reply_sz);
2410 /* Request area (get_pfacts on the stack right now!) */
2411 req_sz = sizeof(get_pfacts);
2412 memset(&get_pfacts, 0, req_sz);
2414 get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
2415 get_pfacts.PortNumber = portnum;
2416 /* Assert: All other get_pfacts fields are zero! */
2418 dinitprintk((MYIOC_s_INFO_FMT "Sending get PortFacts(%d) request\n",
2419 ioc->name, portnum));
2421 /* No non-zero fields in the get_pfacts request are greater than
2422 * 1 byte in size, so we can just fire it off as is.
2424 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
2425 reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
2429 /* Did we get a valid reply? */
2431 /* Now byte swap the necessary fields in the response. */
2432 pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
2433 pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
2434 pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
2435 pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
2436 pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
2437 pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
2438 pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
2439 pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
2440 pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
2445 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2447 * SendIocInit - Send IOCInit request to MPT adapter.
2448 * @ioc: Pointer to MPT_ADAPTER structure
2449 * @sleepFlag: Specifies whether the process can sleep
2451 * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
2453 * Returns 0 for success, non-zero for failure.
2456 SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
2459 MPIDefaultReply_t init_reply;
2465 memset(&ioc_init, 0, sizeof(ioc_init));
2466 memset(&init_reply, 0, sizeof(init_reply));
2468 ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
2469 ioc_init.Function = MPI_FUNCTION_IOC_INIT;
2471 /* If we are in a recovery mode and we uploaded the FW image,
2472 * then this pointer is not NULL. Skip the upload a second time.
2473 * Set this flag if cached_fw set for either IOC.
2475 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
2479 ddlprintk((MYIOC_s_INFO_FMT "upload_fw %d facts.Flags=%x\n",
2480 ioc->name, ioc->upload_fw, ioc->facts.Flags));
2482 if (ioc->bus_type == FC)
2483 ioc_init.MaxDevices = MPT_MAX_FC_DEVICES;
2485 ioc_init.MaxDevices = MPT_MAX_SCSI_DEVICES;
2487 ioc_init.MaxBuses = MPT_MAX_BUS;
2489 ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
2491 if (sizeof(dma_addr_t) == sizeof(u64)) {
2492 /* Save the upper 32-bits of the request
2493 * (reply) and sense buffers.
2495 ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
2496 ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2498 /* Force 32-bit addressing */
2499 ioc_init.HostMfaHighAddr = cpu_to_le32(0);
2500 ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
2503 ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
2504 ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
2506 dhsprintk((MYIOC_s_INFO_FMT "Sending IOCInit (req @ %p)\n",
2507 ioc->name, &ioc_init));
2509 r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
2510 sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
2514 /* No need to byte swap the multibyte fields in the reply
2515 * since we don't even look at it's contents.
2518 dhsprintk((MYIOC_s_INFO_FMT "Sending PortEnable (req @ %p)\n",
2519 ioc->name, &ioc_init));
2521 if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0)
2524 /* YIKES! SUPER IMPORTANT!!!
2525 * Poll IocState until _OPERATIONAL while IOC is doing
2526 * LoopInit and TargetDiscovery!
2529 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
2530 state = mpt_GetIocState(ioc, 1);
2531 while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
2532 if (sleepFlag == CAN_SLEEP) {
2533 msleep_interruptible(1);
2539 printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
2540 ioc->name, (int)((count+5)/HZ));
2544 state = mpt_GetIocState(ioc, 1);
2547 dhsprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
2553 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2555 * SendPortEnable - Send PortEnable request to MPT adapter port.
2556 * @ioc: Pointer to MPT_ADAPTER structure
2557 * @portnum: Port number to enable
2558 * @sleepFlag: Specifies whether the process can sleep
2560 * Send PortEnable to bring IOC to OPERATIONAL state.
2562 * Returns 0 for success, non-zero for failure.
2565 SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2567 PortEnable_t port_enable;
2568 MPIDefaultReply_t reply_buf;
2573 /* Destination... */
2574 reply_sz = sizeof(MPIDefaultReply_t);
2575 memset(&reply_buf, 0, reply_sz);
2577 req_sz = sizeof(PortEnable_t);
2578 memset(&port_enable, 0, req_sz);
2580 port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
2581 port_enable.PortNumber = portnum;
2582 /* port_enable.ChainOffset = 0; */
2583 /* port_enable.MsgFlags = 0; */
2584 /* port_enable.MsgContext = 0; */
2586 dinitprintk((MYIOC_s_INFO_FMT "Sending Port(%d)Enable (req @ %p)\n",
2587 ioc->name, portnum, &port_enable));
2589 /* RAID FW may take a long time to enable
2591 if (ioc->bus_type == FC) {
2592 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
2593 reply_sz, (u16*)&reply_buf, 65 /*seconds*/, sleepFlag);
2595 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&port_enable,
2596 reply_sz, (u16*)&reply_buf, 300 /*seconds*/, sleepFlag);
2602 /* We do not even look at the reply, so we need not
2603 * swap the multi-byte fields.
2610 * ioc: Pointer to MPT_ADAPTER structure
2611 * size - total FW bytes
2614 mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
2617 return; /* use already allocated memory */
2618 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
2619 ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
2620 ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
2622 if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
2623 ioc->alloc_total += size;
2627 * If alt_img is NULL, delete from ioc structure.
2628 * Else, delete a secondary image in same format.
2631 mpt_free_fw_memory(MPT_ADAPTER *ioc)
2635 sz = ioc->facts.FWImageSize;
2636 dinitprintk((KERN_WARNING MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
2637 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2638 pci_free_consistent(ioc->pcidev, sz,
2639 ioc->cached_fw, ioc->cached_fw_dma);
2640 ioc->cached_fw = NULL;
2646 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2648 * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
2649 * @ioc: Pointer to MPT_ADAPTER structure
2650 * @sleepFlag: Specifies whether the process can sleep
2652 * Returns 0 for success, >0 for handshake failure
2653 * <0 for fw upload failure.
2655 * Remark: If bound IOC and a successful FWUpload was performed
2656 * on the bound IOC, the second image is discarded
2657 * and memory is free'd. Both channels must upload to prevent
2658 * IOC from running in degraded mode.
2661 mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
2663 u8 request[ioc->req_sz];
2664 u8 reply[sizeof(FWUploadReply_t)];
2665 FWUpload_t *prequest;
2666 FWUploadReply_t *preply;
2667 FWUploadTCSGE_t *ptcsge;
2670 int ii, sz, reply_sz;
2673 /* If the image size is 0, we are done.
2675 if ((sz = ioc->facts.FWImageSize) == 0)
2678 mpt_alloc_fw_memory(ioc, sz);
2680 dinitprintk((KERN_WARNING MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
2681 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2683 if (ioc->cached_fw == NULL) {
2689 prequest = (FWUpload_t *)&request;
2690 preply = (FWUploadReply_t *)&reply;
2692 /* Destination... */
2693 memset(prequest, 0, ioc->req_sz);
2695 reply_sz = sizeof(reply);
2696 memset(preply, 0, reply_sz);
2698 prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
2699 prequest->Function = MPI_FUNCTION_FW_UPLOAD;
2701 ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
2702 ptcsge->DetailsLength = 12;
2703 ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
2704 ptcsge->ImageSize = cpu_to_le32(sz);
2706 sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
2708 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
2709 mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
2711 sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
2712 dinitprintk((KERN_WARNING MYNAM "Sending FW Upload (req @ %p) sgeoffset=%d \n",
2713 prequest, sgeoffset));
2714 DBG_DUMP_FW_REQUEST_FRAME(prequest)
2716 ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
2717 reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
2719 dinitprintk((KERN_WARNING MYNAM "FW Upload completed rc=%x \n", ii));
2721 cmdStatus = -EFAULT;
2723 /* Handshake transfer was complete and successful.
2724 * Check the Reply Frame.
2726 int status, transfer_sz;
2727 status = le16_to_cpu(preply->IOCStatus);
2728 if (status == MPI_IOCSTATUS_SUCCESS) {
2729 transfer_sz = le32_to_cpu(preply->ActualImageSize);
2730 if (transfer_sz == sz)
2734 dinitprintk((MYIOC_s_INFO_FMT ": do_upload status %d \n",
2735 ioc->name, cmdStatus));
2740 ddlprintk((MYIOC_s_INFO_FMT ": fw upload failed, freeing image \n",
2742 mpt_free_fw_memory(ioc);
2748 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2750 * mpt_downloadboot - DownloadBoot code
2751 * @ioc: Pointer to MPT_ADAPTER structure
2752 * @flag: Specify which part of IOC memory is to be uploaded.
2753 * @sleepFlag: Specifies whether the process can sleep
2755 * FwDownloadBoot requires Programmed IO access.
2757 * Returns 0 for success
2758 * -1 FW Image size is 0
2759 * -2 No valid cached_fw Pointer
2760 * <0 for fw upload failure.
2763 mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag)
2765 MpiFwHeader_t *pFwHeader;
2766 MpiExtImageHeader_t *pExtImage;
2776 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: fw size 0x%x, ioc FW Ptr %p\n",
2777 ioc->name, ioc->facts.FWImageSize, ioc->cached_fw));
2779 if ( ioc->facts.FWImageSize == 0 )
2782 if (ioc->cached_fw == NULL)
2785 /* prevent a second downloadboot and memory free with alt_ioc */
2786 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
2787 ioc->alt_ioc->cached_fw = NULL;
2789 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2790 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2791 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2792 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2793 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2794 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2796 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
2799 if (sleepFlag == CAN_SLEEP) {
2800 msleep_interruptible(1);
2805 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2806 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
2808 for (count = 0; count < 30; count ++) {
2809 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2810 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
2811 ddlprintk((MYIOC_s_INFO_FMT "RESET_ADAPTER cleared, count=%d\n",
2816 if (sleepFlag == CAN_SLEEP) {
2817 msleep_interruptible (1000);
2823 if ( count == 30 ) {
2824 ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! Unable to RESET_ADAPTER diag0val=%x\n",
2825 ioc->name, diag0val));
2829 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2830 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2831 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2832 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2833 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2834 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2836 /* Set the DiagRwEn and Disable ARM bits */
2837 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
2839 pFwHeader = (MpiFwHeader_t *) ioc->cached_fw;
2840 fwSize = (pFwHeader->ImageSize + 3)/4;
2841 ptrFw = (u32 *) pFwHeader;
2843 /* Write the LoadStartAddress to the DiagRw Address Register
2844 * using Programmed IO
2846 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
2847 ddlprintk((MYIOC_s_INFO_FMT "LoadStart addr written 0x%x \n",
2848 ioc->name, pFwHeader->LoadStartAddress));
2850 ddlprintk((MYIOC_s_INFO_FMT "Write FW Image: 0x%x bytes @ %p\n",
2851 ioc->name, fwSize*4, ptrFw));
2853 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
2856 nextImage = pFwHeader->NextImageHeaderOffset;
2858 pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
2860 load_addr = pExtImage->LoadStartAddress;
2862 fwSize = (pExtImage->ImageSize + 3) >> 2;
2863 ptrFw = (u32 *)pExtImage;
2865 ddlprintk((MYIOC_s_INFO_FMT "Write Ext Image: 0x%x bytes @ %p load_addr=%x\n",
2866 ioc->name, fwSize*4, ptrFw, load_addr));
2867 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
2870 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
2872 nextImage = pExtImage->NextImageHeaderOffset;
2875 /* Write the IopResetVectorRegAddr */
2876 ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
2877 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
2879 /* Write the IopResetVectorValue */
2880 ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
2881 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
2883 /* Clear the internal flash bad bit - autoincrementing register,
2884 * so must do two writes.
2886 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
2887 diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
2888 diagRwData |= 0x4000000;
2889 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
2890 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
2892 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2893 ddlprintk((MYIOC_s_INFO_FMT "downloadboot diag0val=%x, turning off PREVENT_IOC_BOOT, DISABLE_ARM\n",
2894 ioc->name, diag0val));
2895 diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM);
2896 ddlprintk((MYIOC_s_INFO_FMT "downloadboot now diag0val=%x\n",
2897 ioc->name, diag0val));
2898 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
2900 /* Write 0xFF to reset the sequencer */
2901 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2903 for (count=0; count<HZ*20; count++) {
2904 if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
2905 ddlprintk((MYIOC_s_INFO_FMT "downloadboot successful! (count=%d) IocState=%x\n",
2906 ioc->name, count, ioc_state));
2907 if ((SendIocInit(ioc, sleepFlag)) != 0) {
2908 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit failed\n",
2912 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit successful\n",
2916 if (sleepFlag == CAN_SLEEP) {
2917 msleep_interruptible (10);
2922 ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! IocState=%x\n",
2923 ioc->name, ioc_state));
2927 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2929 * KickStart - Perform hard reset of MPT adapter.
2930 * @ioc: Pointer to MPT_ADAPTER structure
2931 * @force: Force hard reset
2932 * @sleepFlag: Specifies whether the process can sleep
2934 * This routine places MPT adapter in diagnostic mode via the
2935 * WriteSequence register, and then performs a hard reset of adapter
2936 * via the Diagnostic register.
2938 * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
2939 * or NO_SLEEP (interrupt thread, use mdelay)
2940 * force - 1 if doorbell active, board fault state
2941 * board operational, IOC_RECOVERY or
2942 * IOC_BRINGUP and there is an alt_ioc.
2946 * 1 - hard reset, READY
2947 * 0 - no reset due to History bit, READY
2948 * -1 - no reset due to History bit but not READY
2949 * OR reset but failed to come READY
2950 * -2 - no reset, could not enter DIAG mode
2951 * -3 - reset but bad FW bit
2954 KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
2956 int hard_reset_done = 0;
2960 dinitprintk((KERN_WARNING MYNAM ": KickStarting %s!\n", ioc->name));
2961 if (ioc->bus_type == SCSI) {
2962 /* Always issue a Msg Unit Reset first. This will clear some
2963 * SCSI bus hang conditions.
2965 SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
2967 if (sleepFlag == CAN_SLEEP) {
2968 msleep_interruptible (1000);
2974 hard_reset_done = mpt_diag_reset(ioc, force, sleepFlag);
2975 if (hard_reset_done < 0)
2976 return hard_reset_done;
2978 dinitprintk((MYIOC_s_INFO_FMT "Diagnostic reset successful!\n",
2981 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2; /* 2 seconds */
2982 for (cnt=0; cnt<cntdn; cnt++) {
2983 ioc_state = mpt_GetIocState(ioc, 1);
2984 if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
2985 dinitprintk((MYIOC_s_INFO_FMT "KickStart successful! (cnt=%d)\n",
2987 return hard_reset_done;
2989 if (sleepFlag == CAN_SLEEP) {
2990 msleep_interruptible (10);
2996 printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
2997 ioc->name, ioc_state);
3001 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3003 * mpt_diag_reset - Perform hard reset of the adapter.
3004 * @ioc: Pointer to MPT_ADAPTER structure
3005 * @ignore: Set if to honor and clear to ignore
3006 * the reset history bit
3007 * @sleepflag: CAN_SLEEP if called in a non-interrupt thread,
3008 * else set to NO_SLEEP (use mdelay instead)
3010 * This routine places the adapter in diagnostic mode via the
3011 * WriteSequence register and then performs a hard reset of adapter
3012 * via the Diagnostic register. Adapter should be in ready state
3013 * upon successful completion.
3015 * Returns: 1 hard reset successful
3016 * 0 no reset performed because reset history bit set
3017 * -2 enabling diagnostic mode failed
3018 * -3 diagnostic reset failed
3021 mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
3025 int hard_reset_done = 0;
3031 /* Clear any existing interrupts */
3032 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3034 /* Use "Diagnostic reset" method! (only thing available!) */
3035 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3039 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3040 dprintk((MYIOC_s_INFO_FMT "DbG1: diag0=%08x, diag1=%08x\n",
3041 ioc->name, diag0val, diag1val));
3044 /* Do the reset if we are told to ignore the reset history
3045 * or if the reset history is 0
3047 if (ignore || !(diag0val & MPI_DIAG_RESET_HISTORY)) {
3048 while ((diag0val & MPI_DIAG_DRWE) == 0) {
3049 /* Write magic sequence to WriteSequence register
3050 * Loop until in diagnostic mode
3052 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
3053 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
3054 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
3055 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
3056 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
3057 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
3060 if (sleepFlag == CAN_SLEEP) {
3061 msleep_interruptible (100);
3068 printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
3069 ioc->name, diag0val);
3074 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3076 dprintk((MYIOC_s_INFO_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
3077 ioc->name, diag0val));
3082 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3083 dprintk((MYIOC_s_INFO_FMT "DbG2: diag0=%08x, diag1=%08x\n",
3084 ioc->name, diag0val, diag1val));
3087 * Disable the ARM (Bug fix)
3090 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
3094 * Now hit the reset bit in the Diagnostic register
3095 * (THE BIG HAMMER!) (Clears DRWE bit).
3097 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
3098 hard_reset_done = 1;
3099 dprintk((MYIOC_s_INFO_FMT "Diagnostic reset performed\n",
3103 * Call each currently registered protocol IOC reset handler
3104 * with pre-reset indication.
3105 * NOTE: If we're doing _IOC_BRINGUP, there can be no
3106 * MptResetHandlers[] registered yet.
3112 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
3113 if (MptResetHandlers[ii]) {
3114 dprintk((MYIOC_s_INFO_FMT "Calling IOC pre_reset handler #%d\n",
3116 r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_PRE_RESET);
3118 dprintk((MYIOC_s_INFO_FMT "Calling alt-%s pre_reset handler #%d\n",
3119 ioc->name, ioc->alt_ioc->name, ii));
3120 r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_PRE_RESET);
3124 /* FIXME? Examine results here? */
3127 if (ioc->cached_fw) {
3128 /* If the DownloadBoot operation fails, the
3129 * IOC will be left unusable. This is a fatal error
3130 * case. _diag_reset will return < 0
3132 for (count = 0; count < 30; count ++) {
3133 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3134 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
3139 if (sleepFlag == CAN_SLEEP) {
3140 set_current_state(TASK_INTERRUPTIBLE);
3141 schedule_timeout(1000 * HZ / 1000);
3146 if ((count = mpt_downloadboot(ioc, sleepFlag)) < 0) {
3147 printk(KERN_WARNING MYNAM
3148 ": firmware downloadboot failure (%d)!\n", count);
3152 /* Wait for FW to reload and for board
3153 * to go to the READY state.
3154 * Maximum wait is 60 seconds.
3155 * If fail, no error will check again
3156 * with calling program.
3158 for (count = 0; count < 60; count ++) {
3159 doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
3160 doorbell &= MPI_IOC_STATE_MASK;
3162 if (doorbell == MPI_IOC_STATE_READY) {
3167 if (sleepFlag == CAN_SLEEP) {
3168 msleep_interruptible (1000);
3176 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3179 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3180 dprintk((MYIOC_s_INFO_FMT "DbG3: diag0=%08x, diag1=%08x\n",
3181 ioc->name, diag0val, diag1val));
3184 /* Clear RESET_HISTORY bit! Place board in the
3185 * diagnostic mode to update the diag register.
3187 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3189 while ((diag0val & MPI_DIAG_DRWE) == 0) {
3190 /* Write magic sequence to WriteSequence register
3191 * Loop until in diagnostic mode
3193 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
3194 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
3195 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
3196 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
3197 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
3198 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
3201 if (sleepFlag == CAN_SLEEP) {
3202 msleep_interruptible (100);
3209 printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
3210 ioc->name, diag0val);
3213 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3215 diag0val &= ~MPI_DIAG_RESET_HISTORY;
3216 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
3217 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3218 if (diag0val & MPI_DIAG_RESET_HISTORY) {
3219 printk(MYIOC_s_WARN_FMT "ResetHistory bit failed to clear!\n",
3223 /* Disable Diagnostic Mode
3225 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFFFFFFFF);
3227 /* Check FW reload status flags.
3229 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3230 if (diag0val & (MPI_DIAG_FLASH_BAD_SIG | MPI_DIAG_RESET_ADAPTER | MPI_DIAG_DISABLE_ARM)) {
3231 printk(MYIOC_s_ERR_FMT "Diagnostic reset FAILED! (%02xh)\n",
3232 ioc->name, diag0val);
3238 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3239 dprintk((MYIOC_s_INFO_FMT "DbG4: diag0=%08x, diag1=%08x\n",
3240 ioc->name, diag0val, diag1val));
3244 * Reset flag that says we've enabled event notification
3246 ioc->facts.EventState = 0;
3249 ioc->alt_ioc->facts.EventState = 0;
3251 return hard_reset_done;
3254 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3256 * SendIocReset - Send IOCReset request to MPT adapter.
3257 * @ioc: Pointer to MPT_ADAPTER structure
3258 * @reset_type: reset type, expected values are
3259 * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
3261 * Send IOCReset request to the MPT adapter.
3263 * Returns 0 for success, non-zero for failure.
3266 SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
3272 drsprintk((KERN_WARNING MYNAM ": %s: Sending IOC reset(0x%02x)!\n",
3273 ioc->name, reset_type));
3274 CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
3275 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3278 /* FW ACK'd request, wait for READY state
3281 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
3283 while ((state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
3287 if (sleepFlag != CAN_SLEEP)
3290 printk(KERN_ERR MYNAM ": %s: ERROR - Wait IOC_READY state timeout(%d)!\n",
3291 ioc->name, (int)((count+5)/HZ));
3295 if (sleepFlag == CAN_SLEEP) {
3296 msleep_interruptible(1);
3298 mdelay (1); /* 1 msec delay */
3303 * Cleanup all event stuff for this IOC; re-issue EventNotification
3304 * request if needed.
3306 if (ioc->facts.Function)
3307 ioc->facts.EventState = 0;
3312 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3314 * initChainBuffers - Allocate memory for and initialize
3315 * chain buffers, chain buffer control arrays and spinlock.
3316 * @hd: Pointer to MPT_SCSI_HOST structure
3317 * @init: If set, initialize the spin lock.
3320 initChainBuffers(MPT_ADAPTER *ioc)
3323 int sz, ii, num_chain;
3324 int scale, num_sge, numSGE;
3326 /* ReqToChain size must equal the req_depth
3329 if (ioc->ReqToChain == NULL) {
3330 sz = ioc->req_depth * sizeof(int);
3331 mem = kmalloc(sz, GFP_ATOMIC);
3335 ioc->ReqToChain = (int *) mem;
3336 dinitprintk((KERN_INFO MYNAM ": %s ReqToChain alloc @ %p, sz=%d bytes\n",
3337 ioc->name, mem, sz));
3338 mem = kmalloc(sz, GFP_ATOMIC);
3342 ioc->RequestNB = (int *) mem;
3343 dinitprintk((KERN_INFO MYNAM ": %s RequestNB alloc @ %p, sz=%d bytes\n",
3344 ioc->name, mem, sz));
3346 for (ii = 0; ii < ioc->req_depth; ii++) {
3347 ioc->ReqToChain[ii] = MPT_HOST_NO_CHAIN;
3350 /* ChainToChain size must equal the total number
3351 * of chain buffers to be allocated.
3354 * Calculate the number of chain buffers needed(plus 1) per I/O
3355 * then multiply the the maximum number of simultaneous cmds
3357 * num_sge = num sge in request frame + last chain buffer
3358 * scale = num sge per chain buffer if no chain element
3360 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
3361 if (sizeof(dma_addr_t) == sizeof(u64))
3362 num_sge = scale + (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
3364 num_sge = 1+ scale + (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
3366 if (sizeof(dma_addr_t) == sizeof(u64)) {
3367 numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
3368 (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
3370 numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
3371 (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
3373 dinitprintk((KERN_INFO MYNAM ": %s num_sge=%d numSGE=%d\n",
3374 ioc->name, num_sge, numSGE));
3376 if ( numSGE > MPT_SCSI_SG_DEPTH )
3377 numSGE = MPT_SCSI_SG_DEPTH;
3380 while (numSGE - num_sge > 0) {
3382 num_sge += (scale - 1);
3386 dinitprintk((KERN_INFO MYNAM ": %s Now numSGE=%d num_sge=%d num_chain=%d\n",
3387 ioc->name, numSGE, num_sge, num_chain));
3389 if (ioc->bus_type == SCSI)
3390 num_chain *= MPT_SCSI_CAN_QUEUE;
3392 num_chain *= MPT_FC_CAN_QUEUE;
3394 ioc->num_chain = num_chain;
3396 sz = num_chain * sizeof(int);
3397 if (ioc->ChainToChain == NULL) {
3398 mem = kmalloc(sz, GFP_ATOMIC);
3402 ioc->ChainToChain = (int *) mem;
3403 dinitprintk((KERN_INFO MYNAM ": %s ChainToChain alloc @ %p, sz=%d bytes\n",
3404 ioc->name, mem, sz));
3406 mem = (u8 *) ioc->ChainToChain;
3408 memset(mem, 0xFF, sz);
3412 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3414 * PrimeIocFifos - Initialize IOC request and reply FIFOs.
3415 * @ioc: Pointer to MPT_ADAPTER structure
3417 * This routine allocates memory for the MPT reply and request frame
3418 * pools (if necessary), and primes the IOC reply FIFO with
3421 * Returns 0 for success, non-zero for failure.
3424 PrimeIocFifos(MPT_ADAPTER *ioc)
3427 unsigned long flags;
3428 dma_addr_t alloc_dma;
3430 int i, reply_sz, sz, total_size, num_chain;
3432 /* Prime reply FIFO... */
3434 if (ioc->reply_frames == NULL) {
3435 if ( (num_chain = initChainBuffers(ioc)) < 0)
3438 total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
3439 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
3440 ioc->name, ioc->reply_sz, ioc->reply_depth));
3441 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d[%x] bytes\n",
3442 ioc->name, reply_sz, reply_sz));
3444 sz = (ioc->req_sz * ioc->req_depth);
3445 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d bytes, RequestDepth=%d\n",
3446 ioc->name, ioc->req_sz, ioc->req_depth));
3447 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d[%x] bytes\n",
3448 ioc->name, sz, sz));
3451 sz = num_chain * ioc->req_sz; /* chain buffer pool size */
3452 dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d bytes, ChainDepth=%d\n",
3453 ioc->name, ioc->req_sz, num_chain));
3454 dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
3455 ioc->name, sz, sz, num_chain));
3458 mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
3460 printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
3465 dinitprintk((KERN_INFO MYNAM ": %s.Total alloc @ %p[%p], sz=%d[%x] bytes\n",
3466 ioc->name, mem, (void *)(ulong)alloc_dma, total_size, total_size));
3468 memset(mem, 0, total_size);
3469 ioc->alloc_total += total_size;
3471 ioc->alloc_dma = alloc_dma;
3472 ioc->alloc_sz = total_size;
3473 ioc->reply_frames = (MPT_FRAME_HDR *) mem;
3474 ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
3476 alloc_dma += reply_sz;
3479 /* Request FIFO - WE manage this! */
3481 ioc->req_frames = (MPT_FRAME_HDR *) mem;
3482 ioc->req_frames_dma = alloc_dma;
3484 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffers @ %p[%p]\n",
3485 ioc->name, mem, (void *)(ulong)alloc_dma));
3487 ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
3489 #if defined(CONFIG_MTRR) && 0
3491 * Enable Write Combining MTRR for IOC's memory region.
3492 * (at least as much as we can; "size and base must be
3493 * multiples of 4 kiB"
3495 ioc->mtrr_reg = mtrr_add(ioc->req_frames_dma,
3497 MTRR_TYPE_WRCOMB, 1);
3498 dprintk((MYIOC_s_INFO_FMT "MTRR region registered (base:size=%08x:%x)\n",
3499 ioc->name, ioc->req_frames_dma, sz));
3502 for (i = 0; i < ioc->req_depth; i++) {
3503 alloc_dma += ioc->req_sz;
3507 ioc->ChainBuffer = mem;
3508 ioc->ChainBufferDMA = alloc_dma;
3510 dinitprintk((KERN_INFO MYNAM " :%s.ChainBuffers @ %p(%p)\n",
3511 ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
3513 /* Initialize the free chain Q.
3516 INIT_LIST_HEAD(&ioc->FreeChainQ);
3518 /* Post the chain buffers to the FreeChainQ.
3520 mem = (u8 *)ioc->ChainBuffer;
3521 for (i=0; i < num_chain; i++) {
3522 mf = (MPT_FRAME_HDR *) mem;
3523 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeChainQ);
3527 /* Initialize Request frames linked list
3529 alloc_dma = ioc->req_frames_dma;
3530 mem = (u8 *) ioc->req_frames;
3532 spin_lock_irqsave(&ioc->FreeQlock, flags);
3533 INIT_LIST_HEAD(&ioc->FreeQ);
3534 for (i = 0; i < ioc->req_depth; i++) {
3535 mf = (MPT_FRAME_HDR *) mem;
3537 /* Queue REQUESTs *internally*! */
3538 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
3542 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
3544 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
3545 ioc->sense_buf_pool =
3546 pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
3547 if (ioc->sense_buf_pool == NULL) {
3548 printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
3553 ioc->sense_buf_low_dma = (u32) (ioc->sense_buf_pool_dma & 0xFFFFFFFF);
3554 ioc->alloc_total += sz;
3555 dinitprintk((KERN_INFO MYNAM ": %s.SenseBuffers @ %p[%p]\n",
3556 ioc->name, ioc->sense_buf_pool, (void *)(ulong)ioc->sense_buf_pool_dma));
3560 /* Post Reply frames to FIFO
3562 alloc_dma = ioc->alloc_dma;
3563 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffers @ %p[%p]\n",
3564 ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
3566 for (i = 0; i < ioc->reply_depth; i++) {
3567 /* Write each address to the IOC! */
3568 CHIPREG_WRITE32(&ioc->chip->ReplyFifo, alloc_dma);
3569 alloc_dma += ioc->reply_sz;
3575 if (ioc->alloc != NULL) {
3577 pci_free_consistent(ioc->pcidev,
3579 ioc->alloc, ioc->alloc_dma);
3580 ioc->reply_frames = NULL;
3581 ioc->req_frames = NULL;
3582 ioc->alloc_total -= sz;
3584 if (ioc->sense_buf_pool != NULL) {
3585 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
3586 pci_free_consistent(ioc->pcidev,
3588 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
3589 ioc->sense_buf_pool = NULL;
3594 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3596 * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
3597 * from IOC via doorbell handshake method.
3598 * @ioc: Pointer to MPT_ADAPTER structure
3599 * @reqBytes: Size of the request in bytes
3600 * @req: Pointer to MPT request frame
3601 * @replyBytes: Expected size of the reply in bytes
3602 * @u16reply: Pointer to area where reply should be written
3603 * @maxwait: Max wait time for a reply (in seconds)
3604 * @sleepFlag: Specifies whether the process can sleep
3606 * NOTES: It is the callers responsibility to byte-swap fields in the
3607 * request which are greater than 1 byte in size. It is also the
3608 * callers responsibility to byte-swap response fields which are
3609 * greater than 1 byte in size.
3611 * Returns 0 for success, non-zero for failure.
3614 mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
3615 int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
3617 MPIDefaultReply_t *mptReply;
3622 * Get ready to cache a handshake reply
3624 ioc->hs_reply_idx = 0;
3625 mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
3626 mptReply->MsgLength = 0;
3629 * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
3630 * then tell IOC that we want to handshake a request of N words.
3631 * (WRITE u32val to Doorbell reg).
3633 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3634 CHIPREG_WRITE32(&ioc->chip->Doorbell,
3635 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
3636 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
3639 * Wait for IOC's doorbell handshake int
3641 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3644 dhsprintk((MYIOC_s_INFO_FMT "HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
3645 ioc->name, reqBytes, t, failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
3647 /* Read doorbell and check for active bit */
3648 if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
3652 * Clear doorbell int (WRITE 0 to IntStatus reg),
3653 * then wait for IOC to ACKnowledge that it's ready for
3654 * our handshake request.
3656 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3657 if (!failcnt && (t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3662 u8 *req_as_bytes = (u8 *) req;
3665 * Stuff request words via doorbell handshake,
3666 * with ACK from IOC for each.
3668 for (ii = 0; !failcnt && ii < reqBytes/4; ii++) {
3669 u32 word = ((req_as_bytes[(ii*4) + 0] << 0) |
3670 (req_as_bytes[(ii*4) + 1] << 8) |
3671 (req_as_bytes[(ii*4) + 2] << 16) |
3672 (req_as_bytes[(ii*4) + 3] << 24));
3674 CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
3675 if ((t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3679 dhsprintk((KERN_INFO MYNAM ": Handshake request frame (@%p) header\n", req));
3680 DBG_DUMP_REQUEST_FRAME_HDR(req)
3682 dhsprintk((MYIOC_s_INFO_FMT "HandShake request post done, WaitCnt=%d%s\n",
3683 ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
3686 * Wait for completion of doorbell handshake reply from the IOC
3688 if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
3691 dhsprintk((MYIOC_s_INFO_FMT "HandShake reply count=%d%s\n",
3692 ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
3695 * Copy out the cached reply...
3697 for (ii=0; ii < min(replyBytes/2,mptReply->MsgLength*2); ii++)
3698 u16reply[ii] = ioc->hs_reply[ii];
3706 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3708 * WaitForDoorbellAck - Wait for IOC to clear the IOP_DOORBELL_STATUS bit
3709 * in it's IntStatus register.
3710 * @ioc: Pointer to MPT_ADAPTER structure
3711 * @howlong: How long to wait (in seconds)
3712 * @sleepFlag: Specifies whether the process can sleep
3714 * This routine waits (up to ~2 seconds max) for IOC doorbell
3715 * handshake ACKnowledge.
3717 * Returns a negative value on failure, else wait loop count.
3720 WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3726 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
3728 if (sleepFlag == CAN_SLEEP) {
3730 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3731 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
3733 msleep_interruptible (1);
3738 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3739 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
3747 dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell ACK (count=%d)\n",
3752 printk(MYIOC_s_ERR_FMT "Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
3753 ioc->name, count, intstat);
3757 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3759 * WaitForDoorbellInt - Wait for IOC to set the HIS_DOORBELL_INTERRUPT bit
3760 * in it's IntStatus register.
3761 * @ioc: Pointer to MPT_ADAPTER structure
3762 * @howlong: How long to wait (in seconds)
3763 * @sleepFlag: Specifies whether the process can sleep
3765 * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt.
3767 * Returns a negative value on failure, else wait loop count.
3770 WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3776 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * howlong;
3777 if (sleepFlag == CAN_SLEEP) {
3779 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3780 if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
3782 msleep_interruptible(1);
3787 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3788 if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
3796 dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell INT (cnt=%d) howlong=%d\n",
3797 ioc->name, count, howlong));
3801 printk(MYIOC_s_ERR_FMT "Doorbell INT timeout (count=%d), IntStatus=%x!\n",
3802 ioc->name, count, intstat);
3806 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3808 * WaitForDoorbellReply - Wait for and capture a IOC handshake reply.
3809 * @ioc: Pointer to MPT_ADAPTER structure
3810 * @howlong: How long to wait (in seconds)
3811 * @sleepFlag: Specifies whether the process can sleep
3813 * This routine polls the IOC for a handshake reply, 16 bits at a time.
3814 * Reply is cached to IOC private area large enough to hold a maximum
3815 * of 128 bytes of reply data.
3817 * Returns a negative value on failure, else size of reply in WORDS.
3820 WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3825 u16 *hs_reply = ioc->hs_reply;
3826 volatile MPIDefaultReply_t *mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
3829 hs_reply[0] = hs_reply[1] = hs_reply[7] = 0;
3832 * Get first two u16's so we can look at IOC's intended reply MsgLength
3835 if ((t = WaitForDoorbellInt(ioc, howlong, sleepFlag)) < 0) {
3838 hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
3839 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3840 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3843 hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
3844 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3848 dhsprintk((MYIOC_s_INFO_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
3849 ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
3850 failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
3853 * If no error (and IOC said MsgLength is > 0), piece together
3854 * reply 16 bits at a time.
3856 for (u16cnt=2; !failcnt && u16cnt < (2 * mptReply->MsgLength); u16cnt++) {
3857 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3859 hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
3860 /* don't overflow our IOC hs_reply[] buffer! */
3861 if (u16cnt < sizeof(ioc->hs_reply) / sizeof(ioc->hs_reply[0]))
3862 hs_reply[u16cnt] = hword;
3863 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3866 if (!failcnt && (t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3868 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3871 printk(MYIOC_s_ERR_FMT "Handshake reply failure!\n",
3876 else if (u16cnt != (2 * mptReply->MsgLength)) {
3879 else if ((mptReply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
3884 dhsprintk((MYIOC_s_INFO_FMT "Got Handshake reply:\n", ioc->name));
3885 DBG_DUMP_REPLY_FRAME(mptReply)
3887 dhsprintk((MYIOC_s_INFO_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
3888 ioc->name, t, u16cnt/2));
3892 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3894 * GetLanConfigPages - Fetch LANConfig pages.
3895 * @ioc: Pointer to MPT_ADAPTER structure
3897 * Return: 0 for success
3898 * -ENOMEM if no memory available
3899 * -EPERM if not allowed due to ISR context
3900 * -EAGAIN if no msg frames currently available
3901 * -EFAULT for non-successful reply or no reply (timeout)
3904 GetLanConfigPages(MPT_ADAPTER *ioc)
3906 ConfigPageHeader_t hdr;
3908 LANPage0_t *ppage0_alloc;
3909 dma_addr_t page0_dma;
3910 LANPage1_t *ppage1_alloc;
3911 dma_addr_t page1_dma;
3916 /* Get LAN Page 0 header */
3917 hdr.PageVersion = 0;
3920 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
3923 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3928 if ((rc = mpt_config(ioc, &cfg)) != 0)
3931 if (hdr.PageLength > 0) {
3932 data_sz = hdr.PageLength * 4;
3933 ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
3936 memset((u8 *)ppage0_alloc, 0, data_sz);
3937 cfg.physAddr = page0_dma;
3938 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
3940 if ((rc = mpt_config(ioc, &cfg)) == 0) {
3942 copy_sz = min_t(int, sizeof(LANPage0_t), data_sz);
3943 memcpy(&ioc->lan_cnfg_page0, ppage0_alloc, copy_sz);
3947 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
3950 * Normalize endianness of structure data,
3951 * by byte-swapping all > 1 byte fields!
3960 /* Get LAN Page 1 header */
3961 hdr.PageVersion = 0;
3964 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
3967 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3971 if ((rc = mpt_config(ioc, &cfg)) != 0)
3974 if (hdr.PageLength == 0)
3977 data_sz = hdr.PageLength * 4;
3979 ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
3981 memset((u8 *)ppage1_alloc, 0, data_sz);
3982 cfg.physAddr = page1_dma;
3983 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
3985 if ((rc = mpt_config(ioc, &cfg)) == 0) {
3987 copy_sz = min_t(int, sizeof(LANPage1_t), data_sz);
3988 memcpy(&ioc->lan_cnfg_page1, ppage1_alloc, copy_sz);
3991 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
3994 * Normalize endianness of structure data,
3995 * by byte-swapping all > 1 byte fields!
4003 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4005 * GetFcPortPage0 - Fetch FCPort config Page0.
4006 * @ioc: Pointer to MPT_ADAPTER structure
4007 * @portnum: IOC Port number
4009 * Return: 0 for success
4010 * -ENOMEM if no memory available
4011 * -EPERM if not allowed due to ISR context
4012 * -EAGAIN if no msg frames currently available
4013 * -EFAULT for non-successful reply or no reply (timeout)
4016 GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
4018 ConfigPageHeader_t hdr;
4020 FCPortPage0_t *ppage0_alloc;
4021 FCPortPage0_t *pp0dest;
4022 dma_addr_t page0_dma;
4027 /* Get FCPort Page 0 header */
4028 hdr.PageVersion = 0;
4031 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
4034 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4036 cfg.pageAddr = portnum;
4039 if ((rc = mpt_config(ioc, &cfg)) != 0)
4042 if (hdr.PageLength == 0)
4045 data_sz = hdr.PageLength * 4;
4047 ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
4049 memset((u8 *)ppage0_alloc, 0, data_sz);
4050 cfg.physAddr = page0_dma;
4051 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4053 if ((rc = mpt_config(ioc, &cfg)) == 0) {
4055 pp0dest = &ioc->fc_port_page0[portnum];
4056 copy_sz = min_t(int, sizeof(FCPortPage0_t), data_sz);
4057 memcpy(pp0dest, ppage0_alloc, copy_sz);
4060 * Normalize endianness of structure data,
4061 * by byte-swapping all > 1 byte fields!
4063 pp0dest->Flags = le32_to_cpu(pp0dest->Flags);
4064 pp0dest->PortIdentifier = le32_to_cpu(pp0dest->PortIdentifier);
4065 pp0dest->WWNN.Low = le32_to_cpu(pp0dest->WWNN.Low);
4066 pp0dest->WWNN.High = le32_to_cpu(pp0dest->WWNN.High);
4067 pp0dest->WWPN.Low = le32_to_cpu(pp0dest->WWPN.Low);
4068 pp0dest->WWPN.High = le32_to_cpu(pp0dest->WWPN.High);
4069 pp0dest->SupportedServiceClass = le32_to_cpu(pp0dest->SupportedServiceClass);
4070 pp0dest->SupportedSpeeds = le32_to_cpu(pp0dest->SupportedSpeeds);
4071 pp0dest->CurrentSpeed = le32_to_cpu(pp0dest->CurrentSpeed);
4072 pp0dest->MaxFrameSize = le32_to_cpu(pp0dest->MaxFrameSize);
4073 pp0dest->FabricWWNN.Low = le32_to_cpu(pp0dest->FabricWWNN.Low);
4074 pp0dest->FabricWWNN.High = le32_to_cpu(pp0dest->FabricWWNN.High);
4075 pp0dest->FabricWWPN.Low = le32_to_cpu(pp0dest->FabricWWPN.Low);
4076 pp0dest->FabricWWPN.High = le32_to_cpu(pp0dest->FabricWWPN.High);
4077 pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
4078 pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
4082 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
4088 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4090 * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
4091 * @ioc: Pointer to MPT_ADAPTER structure
4093 * Returns: 0 for success
4094 * -ENOMEM if no memory available
4095 * -EPERM if not allowed due to ISR context
4096 * -EAGAIN if no msg frames currently available
4097 * -EFAULT for non-successful reply or no reply (timeout)
4100 GetIoUnitPage2(MPT_ADAPTER *ioc)
4102 ConfigPageHeader_t hdr;
4104 IOUnitPage2_t *ppage_alloc;
4105 dma_addr_t page_dma;
4109 /* Get the page header */
4110 hdr.PageVersion = 0;
4113 hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
4116 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4121 if ((rc = mpt_config(ioc, &cfg)) != 0)
4124 if (hdr.PageLength == 0)
4127 /* Read the config page */
4128 data_sz = hdr.PageLength * 4;
4130 ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
4132 memset((u8 *)ppage_alloc, 0, data_sz);
4133 cfg.physAddr = page_dma;
4134 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4136 /* If Good, save data */
4137 if ((rc = mpt_config(ioc, &cfg)) == 0)
4138 ioc->biosVersion = le32_to_cpu(ppage_alloc->BiosVersion);
4140 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage_alloc, page_dma);
4146 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4147 /* mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
4148 * @ioc: Pointer to a Adapter Strucutre
4149 * @portnum: IOC port number
4151 * Return: -EFAULT if read of config page header fails
4153 * If read of SCSI Port Page 0 fails,
4154 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
4155 * Adapter settings: async, narrow
4157 * If read of SCSI Port Page 2 fails,
4158 * Adapter settings valid
4159 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
4164 * CHECK - what type of locking mechanisms should be used????
4167 mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
4172 ConfigPageHeader_t header;
4178 if (!ioc->spi_data.nvram) {
4181 sz = MPT_MAX_SCSI_DEVICES * sizeof(int);
4182 mem = kmalloc(sz, GFP_ATOMIC);
4186 ioc->spi_data.nvram = (int *) mem;
4188 dprintk((MYIOC_s_INFO_FMT "SCSI device NVRAM settings @ %p, sz=%d\n",
4189 ioc->name, ioc->spi_data.nvram, sz));
4192 /* Invalidate NVRAM information
4194 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
4195 ioc->spi_data.nvram[ii] = MPT_HOST_NVRAM_INVALID;
4198 /* Read SPP0 header, allocate memory, then read page.
4200 header.PageVersion = 0;
4201 header.PageLength = 0;
4202 header.PageNumber = 0;
4203 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
4206 cfg.pageAddr = portnum;
4207 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4209 cfg.timeout = 0; /* use default */
4210 if (mpt_config(ioc, &cfg) != 0)
4213 if (header.PageLength > 0) {
4214 pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
4216 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4217 cfg.physAddr = buf_dma;
4218 if (mpt_config(ioc, &cfg) != 0) {
4219 ioc->spi_data.maxBusWidth = MPT_NARROW;
4220 ioc->spi_data.maxSyncOffset = 0;
4221 ioc->spi_data.minSyncFactor = MPT_ASYNC;
4222 ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
4225 /* Save the Port Page 0 data
4227 SCSIPortPage0_t *pPP0 = (SCSIPortPage0_t *) pbuf;
4228 pPP0->Capabilities = le32_to_cpu(pPP0->Capabilities);
4229 pPP0->PhysicalInterface = le32_to_cpu(pPP0->PhysicalInterface);
4231 if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
4232 ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
4233 dinitprintk((KERN_INFO MYNAM " :%s noQas due to Capabilities=%x\n",
4234 ioc->name, pPP0->Capabilities));
4236 ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
4237 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK;
4239 ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
4240 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
4241 ioc->spi_data.minSyncFactor = (u8) (data >> 8);
4243 ioc->spi_data.maxSyncOffset = 0;
4244 ioc->spi_data.minSyncFactor = MPT_ASYNC;
4247 ioc->spi_data.busType = pPP0->PhysicalInterface & MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK;
4249 /* Update the minSyncFactor based on bus type.
4251 if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
4252 (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
4254 if (ioc->spi_data.minSyncFactor < MPT_ULTRA)
4255 ioc->spi_data.minSyncFactor = MPT_ULTRA;
4259 pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
4264 /* SCSI Port Page 2 - Read the header then the page.
4266 header.PageVersion = 0;
4267 header.PageLength = 0;
4268 header.PageNumber = 2;
4269 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
4272 cfg.pageAddr = portnum;
4273 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4275 if (mpt_config(ioc, &cfg) != 0)
4278 if (header.PageLength > 0) {
4279 /* Allocate memory and read SCSI Port Page 2
4281 pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
4283 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_NVRAM;
4284 cfg.physAddr = buf_dma;
4285 if (mpt_config(ioc, &cfg) != 0) {
4286 /* Nvram data is left with INVALID mark
4290 SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t *) pbuf;
4291 MpiDeviceInfo_t *pdevice = NULL;
4293 /* Save the Port Page 2 data
4294 * (reformat into a 32bit quantity)
4296 data = le32_to_cpu(pPP2->PortFlags) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
4297 ioc->spi_data.PortFlags = data;
4298 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
4299 pdevice = &pPP2->DeviceSettings[ii];
4300 data = (le16_to_cpu(pdevice->DeviceFlags) << 16) |
4301 (pdevice->SyncFactor << 8) | pdevice->Timeout;
4302 ioc->spi_data.nvram[ii] = data;
4306 pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
4310 /* Update Adapter limits with those from NVRAM
4311 * Comment: Don't need to do this. Target performance
4312 * parameters will never exceed the adapters limits.
4318 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4319 /* mpt_readScsiDevicePageHeaders - save version and length of SDP1
4320 * @ioc: Pointer to a Adapter Strucutre
4321 * @portnum: IOC port number
4323 * Return: -EFAULT if read of config page header fails
4327 mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
4330 ConfigPageHeader_t header;
4332 /* Read the SCSI Device Page 1 header
4334 header.PageVersion = 0;
4335 header.PageLength = 0;
4336 header.PageNumber = 1;
4337 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4340 cfg.pageAddr = portnum;
4341 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4344 if (mpt_config(ioc, &cfg) != 0)
4347 ioc->spi_data.sdp1version = cfg.hdr->PageVersion;
4348 ioc->spi_data.sdp1length = cfg.hdr->PageLength;
4350 header.PageVersion = 0;
4351 header.PageLength = 0;
4352 header.PageNumber = 0;
4353 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4354 if (mpt_config(ioc, &cfg) != 0)
4357 ioc->spi_data.sdp0version = cfg.hdr->PageVersion;
4358 ioc->spi_data.sdp0length = cfg.hdr->PageLength;
4360 dcprintk((MYIOC_s_INFO_FMT "Headers: 0: version %d length %d\n",
4361 ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
4363 dcprintk((MYIOC_s_INFO_FMT "Headers: 1: version %d length %d\n",
4364 ioc->name, ioc->spi_data.sdp1version, ioc->spi_data.sdp1length));
4368 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4370 * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
4371 * @ioc: Pointer to a Adapter Strucutre
4372 * @portnum: IOC port number
4376 * -EFAULT if read of config page header fails or data pointer not NULL
4377 * -ENOMEM if pci_alloc failed
4380 mpt_findImVolumes(MPT_ADAPTER *ioc)
4384 ConfigPageIoc2RaidVol_t *pIocRv;
4385 dma_addr_t ioc2_dma;
4387 ConfigPageHeader_t header;
4394 /* Read IOCP2 header then the page.
4396 header.PageVersion = 0;
4397 header.PageLength = 0;
4398 header.PageNumber = 2;
4399 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4403 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4406 if (mpt_config(ioc, &cfg) != 0)
4409 if (header.PageLength == 0)
4412 iocpage2sz = header.PageLength * 4;
4413 pIoc2 = pci_alloc_consistent(ioc->pcidev, iocpage2sz, &ioc2_dma);
4417 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4418 cfg.physAddr = ioc2_dma;
4419 if (mpt_config(ioc, &cfg) != 0)
4422 if ( (mem = (u8 *)ioc->spi_data.pIocPg2) == NULL ) {
4423 mem = kmalloc(iocpage2sz, GFP_ATOMIC);
4425 ioc->spi_data.pIocPg2 = (IOCPage2_t *) mem;
4430 memcpy(mem, (u8 *)pIoc2, iocpage2sz);
4432 /* Identify RAID Volume Id's */
4433 nVols = pIoc2->NumActiveVolumes;
4439 /* At least 1 RAID Volume
4441 pIocRv = pIoc2->RaidVolume;
4442 ioc->spi_data.isRaid = 0;
4443 for (jj = 0; jj < nVols; jj++, pIocRv++) {
4444 vid = pIocRv->VolumeID;
4445 vbus = pIocRv->VolumeBus;
4446 vioc = pIocRv->VolumeIOC;
4451 ioc->spi_data.isRaid |= (1 << vid);
4453 /* Error! Always bus 0
4459 /* Identify Hidden Physical Disk Id's */
4460 nPhys = pIoc2->NumActivePhysDisks;
4462 /* No physical disks.
4465 mpt_read_ioc_pg_3(ioc);
4469 pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
4475 mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
4480 ConfigPageHeader_t header;
4481 dma_addr_t ioc3_dma;
4484 /* Free the old page
4486 if (ioc->spi_data.pIocPg3) {
4487 kfree(ioc->spi_data.pIocPg3);
4488 ioc->spi_data.pIocPg3 = NULL;
4491 /* There is at least one physical disk.
4492 * Read and save IOC Page 3
4494 header.PageVersion = 0;
4495 header.PageLength = 0;
4496 header.PageNumber = 3;
4497 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4501 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4504 if (mpt_config(ioc, &cfg) != 0)
4507 if (header.PageLength == 0)
4510 /* Read Header good, alloc memory
4512 iocpage3sz = header.PageLength * 4;
4513 pIoc3 = pci_alloc_consistent(ioc->pcidev, iocpage3sz, &ioc3_dma);
4517 /* Read the Page and save the data
4518 * into malloc'd memory.
4520 cfg.physAddr = ioc3_dma;
4521 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4522 if (mpt_config(ioc, &cfg) == 0) {
4523 mem = kmalloc(iocpage3sz, GFP_ATOMIC);
4525 memcpy(mem, (u8 *)pIoc3, iocpage3sz);
4526 ioc->spi_data.pIocPg3 = (IOCPage3_t *) mem;
4530 pci_free_consistent(ioc->pcidev, iocpage3sz, pIoc3, ioc3_dma);
4536 mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
4540 ConfigPageHeader_t header;
4541 dma_addr_t ioc4_dma;
4544 /* Read and save IOC Page 4
4546 header.PageVersion = 0;
4547 header.PageLength = 0;
4548 header.PageNumber = 4;
4549 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4553 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4556 if (mpt_config(ioc, &cfg) != 0)
4559 if (header.PageLength == 0)
4562 if ( (pIoc4 = ioc->spi_data.pIocPg4) == NULL ) {
4563 iocpage4sz = (header.PageLength + 4) * 4; /* Allow 4 additional SEP's */
4564 pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
4568 ioc4_dma = ioc->spi_data.IocPg4_dma;
4569 iocpage4sz = ioc->spi_data.IocPg4Sz;
4572 /* Read the Page into dma memory.
4574 cfg.physAddr = ioc4_dma;
4575 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4576 if (mpt_config(ioc, &cfg) == 0) {
4577 ioc->spi_data.pIocPg4 = (IOCPage4_t *) pIoc4;
4578 ioc->spi_data.IocPg4_dma = ioc4_dma;
4579 ioc->spi_data.IocPg4Sz = iocpage4sz;
4581 pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
4582 ioc->spi_data.pIocPg4 = NULL;
4587 mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
4591 ConfigPageHeader_t header;
4592 dma_addr_t ioc1_dma;
4596 /* Check the Coalescing Timeout in IOC Page 1
4598 header.PageVersion = 0;
4599 header.PageLength = 0;
4600 header.PageNumber = 1;
4601 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4605 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4608 if (mpt_config(ioc, &cfg) != 0)
4611 if (header.PageLength == 0)
4614 /* Read Header good, alloc memory
4616 iocpage1sz = header.PageLength * 4;
4617 pIoc1 = pci_alloc_consistent(ioc->pcidev, iocpage1sz, &ioc1_dma);
4621 /* Read the Page and check coalescing timeout
4623 cfg.physAddr = ioc1_dma;
4624 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4625 if (mpt_config(ioc, &cfg) == 0) {
4627 tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
4628 if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
4629 tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
4631 dprintk((MYIOC_s_INFO_FMT "Coalescing Enabled Timeout = %d\n",
4634 if (tmp > MPT_COALESCING_TIMEOUT) {
4635 pIoc1->CoalescingTimeout = cpu_to_le32(MPT_COALESCING_TIMEOUT);
4637 /* Write NVRAM and current
4640 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
4641 if (mpt_config(ioc, &cfg) == 0) {
4642 dprintk((MYIOC_s_INFO_FMT "Reset Current Coalescing Timeout to = %d\n",
4643 ioc->name, MPT_COALESCING_TIMEOUT));
4645 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
4646 if (mpt_config(ioc, &cfg) == 0) {
4647 dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout to = %d\n",
4648 ioc->name, MPT_COALESCING_TIMEOUT));
4650 dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout Failed\n",
4655 dprintk((MYIOC_s_WARN_FMT "Reset of Current Coalescing Timeout Failed!\n",
4661 dprintk((MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
4665 pci_free_consistent(ioc->pcidev, iocpage1sz, pIoc1, ioc1_dma);
4670 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4672 * SendEventNotification - Send EventNotification (on or off) request
4674 * @ioc: Pointer to MPT_ADAPTER structure
4675 * @EvSwitch: Event switch flags
4678 SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch)
4680 EventNotification_t *evnp;
4682 evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc);
4684 dprintk((MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n",
4688 memset(evnp, 0, sizeof(*evnp));
4690 dprintk((MYIOC_s_INFO_FMT "Sending EventNotification(%d)\n", ioc->name, EvSwitch));
4692 evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
4693 evnp->ChainOffset = 0;
4695 evnp->Switch = EvSwitch;
4697 mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)evnp);
4702 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4704 * SendEventAck - Send EventAck request to MPT adapter.
4705 * @ioc: Pointer to MPT_ADAPTER structure
4706 * @evnp: Pointer to original EventNotification request
4709 SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
4713 if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
4714 printk(MYIOC_s_WARN_FMT "Unable to allocate event ACK request frame!\n",
4718 memset(pAck, 0, sizeof(*pAck));
4720 dprintk((MYIOC_s_INFO_FMT "Sending EventAck\n", ioc->name));
4722 pAck->Function = MPI_FUNCTION_EVENT_ACK;
4723 pAck->ChainOffset = 0;
4725 pAck->Event = evnp->Event;
4726 pAck->EventContext = evnp->EventContext;
4728 mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)pAck);
4733 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4735 * mpt_config - Generic function to issue config message
4736 * @ioc - Pointer to an adapter structure
4737 * @cfg - Pointer to a configuration structure. Struct contains
4738 * action, page address, direction, physical address
4739 * and pointer to a configuration page header
4740 * Page header is updated.
4742 * Returns 0 for success
4743 * -EPERM if not allowed due to ISR context
4744 * -EAGAIN if no msg frames currently available
4745 * -EFAULT for non-successful reply or no reply (timeout)
4748 mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
4752 unsigned long flags;
4757 /* (Bugzilla:fibrebugs, #513)
4758 * Bug fix (part 1)! 20010905 -sralston
4759 * Prevent calling wait_event() (below), if caller happens
4760 * to be in ISR context, because that is fatal!
4762 in_isr = in_interrupt();
4764 dcprintk((MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
4769 /* Get and Populate a free Frame
4771 if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
4772 dcprintk((MYIOC_s_WARN_FMT "mpt_config: no msg frames!\n",
4776 pReq = (Config_t *)mf;
4777 pReq->Action = pCfg->action;
4779 pReq->ChainOffset = 0;
4780 pReq->Function = MPI_FUNCTION_CONFIG;
4781 pReq->ExtPageLength = 0;
4782 pReq->ExtPageType = 0;
4784 for (ii=0; ii < 8; ii++)
4785 pReq->Reserved2[ii] = 0;
4787 pReq->Header.PageVersion = pCfg->hdr->PageVersion;
4788 pReq->Header.PageLength = pCfg->hdr->PageLength;
4789 pReq->Header.PageNumber = pCfg->hdr->PageNumber;
4790 pReq->Header.PageType = (pCfg->hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
4791 pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
4793 /* Add a SGE to the config request.
4796 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
4798 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
4800 flagsLength |= pCfg->hdr->PageLength * 4;
4802 mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
4804 dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
4805 ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
4807 /* Append pCfg pointer to end of mf
4809 *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
4811 /* Initalize the timer
4813 init_timer(&pCfg->timer);
4814 pCfg->timer.data = (unsigned long) ioc;
4815 pCfg->timer.function = mpt_timer_expired;
4816 pCfg->wait_done = 0;
4818 /* Set the timer; ensure 10 second minimum */
4819 if (pCfg->timeout < 10)
4820 pCfg->timer.expires = jiffies + HZ*10;
4822 pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
4824 /* Add to end of Q, set timer and then issue this command */
4825 spin_lock_irqsave(&ioc->FreeQlock, flags);
4826 list_add_tail(&pCfg->linkage, &ioc->configQ);
4827 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4829 add_timer(&pCfg->timer);
4830 mpt_put_msg_frame(mpt_base_index, ioc, mf);
4831 wait_event(mpt_waitq, pCfg->wait_done);
4833 /* mf has been freed - do not access */
4840 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4842 * mpt_toolbox - Generic function to issue toolbox message
4843 * @ioc - Pointer to an adapter structure
4844 * @cfg - Pointer to a toolbox structure. Struct contains
4845 * action, page address, direction, physical address
4846 * and pointer to a configuration page header
4847 * Page header is updated.
4849 * Returns 0 for success
4850 * -EPERM if not allowed due to ISR context
4851 * -EAGAIN if no msg frames currently available
4852 * -EFAULT for non-successful reply or no reply (timeout)
4855 mpt_toolbox(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
4857 ToolboxIstwiReadWriteRequest_t *pReq;
4859 struct pci_dev *pdev;
4860 unsigned long flags;
4865 /* (Bugzilla:fibrebugs, #513)
4866 * Bug fix (part 1)! 20010905 -sralston
4867 * Prevent calling wait_event() (below), if caller happens
4868 * to be in ISR context, because that is fatal!
4870 in_isr = in_interrupt();
4872 dcprintk((MYIOC_s_WARN_FMT "toobox request not allowed in ISR context!\n",
4877 /* Get and Populate a free Frame
4879 if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
4880 dcprintk((MYIOC_s_WARN_FMT "mpt_toolbox: no msg frames!\n",
4884 pReq = (ToolboxIstwiReadWriteRequest_t *)mf;
4885 pReq->Tool = pCfg->action;
4887 pReq->ChainOffset = 0;
4888 pReq->Function = MPI_FUNCTION_TOOLBOX;
4889 pReq->Reserved1 = 0;
4890 pReq->Reserved2 = 0;
4892 pReq->Flags = pCfg->dir;
4894 pReq->Reserved3 = 0;
4895 pReq->NumAddressBytes = 0x01;
4896 pReq->Reserved4 = 0;
4897 pReq->DataLength = 0x04;
4898 pdev = (struct pci_dev *) ioc->pcidev;
4899 if (pdev->devfn & 1)
4900 pReq->DeviceAddr = 0xB2;
4902 pReq->DeviceAddr = 0xB0;
4906 pReq->Reserved5 = 0;
4908 /* Add a SGE to the config request.
4911 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | 4;
4913 mpt_add_sge((char *)&pReq->SGL, flagsLength, pCfg->physAddr);
4915 dcprintk((MYIOC_s_INFO_FMT "Sending Toolbox request, Tool=%x\n",
4916 ioc->name, pReq->Tool));
4918 /* Append pCfg pointer to end of mf
4920 *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
4922 /* Initalize the timer
4924 init_timer(&pCfg->timer);
4925 pCfg->timer.data = (unsigned long) ioc;
4926 pCfg->timer.function = mpt_timer_expired;
4927 pCfg->wait_done = 0;
4929 /* Set the timer; ensure 10 second minimum */
4930 if (pCfg->timeout < 10)
4931 pCfg->timer.expires = jiffies + HZ*10;
4933 pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
4935 /* Add to end of Q, set timer and then issue this command */
4936 spin_lock_irqsave(&ioc->FreeQlock, flags);
4937 list_add_tail(&pCfg->linkage, &ioc->configQ);
4938 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4940 add_timer(&pCfg->timer);
4941 mpt_put_msg_frame(mpt_base_index, ioc, mf);
4942 wait_event(mpt_waitq, pCfg->wait_done);
4944 /* mf has been freed - do not access */
4951 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4953 * mpt_timer_expired - Call back for timer process.
4954 * Used only internal config functionality.
4955 * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
4958 mpt_timer_expired(unsigned long data)
4960 MPT_ADAPTER *ioc = (MPT_ADAPTER *) data;
4962 dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired! \n", ioc->name));
4964 /* Perform a FW reload */
4965 if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
4966 printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
4968 /* No more processing.
4969 * Hard reset clean-up will wake up
4970 * process and free all resources.
4972 dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired complete!\n", ioc->name));
4977 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4979 * mpt_ioc_reset - Base cleanup for hard reset
4980 * @ioc: Pointer to the adapter structure
4981 * @reset_phase: Indicates pre- or post-reset functionality
4983 * Remark: Free's resources with internally generated commands.
4986 mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
4989 unsigned long flags;
4991 dprintk((KERN_WARNING MYNAM
4992 ": IOC %s_reset routed to MPT base driver!\n",
4993 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
4994 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
4996 if (reset_phase == MPT_IOC_SETUP_RESET) {
4998 } else if (reset_phase == MPT_IOC_PRE_RESET) {
4999 /* If the internal config Q is not empty -
5000 * delete timer. MF resources will be freed when
5001 * the FIFO's are primed.
5003 spin_lock_irqsave(&ioc->FreeQlock, flags);
5004 list_for_each_entry(pCfg, &ioc->configQ, linkage)
5005 del_timer(&pCfg->timer);
5006 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
5011 /* Search the configQ for internal commands.
5012 * Flush the Q, and wake up all suspended threads.
5014 spin_lock_irqsave(&ioc->FreeQlock, flags);
5015 list_for_each_entry_safe(pCfg, pNext, &ioc->configQ, linkage) {
5016 list_del(&pCfg->linkage);
5018 pCfg->status = MPT_CONFIG_ERROR;
5019 pCfg->wait_done = 1;
5020 wake_up(&mpt_waitq);
5022 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
5025 return 1; /* currently means nothing really */
5029 #ifdef CONFIG_PROC_FS /* { */
5030 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5032 * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
5034 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5036 * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
5038 * Returns 0 for success, non-zero for failure.
5041 procmpt_create(void)
5043 struct proc_dir_entry *ent;
5045 mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
5046 if (mpt_proc_root_dir == NULL)
5049 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, mpt_proc_root_dir);
5051 ent->read_proc = procmpt_summary_read;
5053 ent = create_proc_entry("version", S_IFREG|S_IRUGO, mpt_proc_root_dir);
5055 ent->read_proc = procmpt_version_read;
5060 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5062 * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
5064 * Returns 0 for success, non-zero for failure.
5067 procmpt_destroy(void)
5069 remove_proc_entry("version", mpt_proc_root_dir);
5070 remove_proc_entry("summary", mpt_proc_root_dir);
5071 remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
5074 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5076 * procmpt_summary_read - Handle read request from /proc/mpt/summary
5077 * or from /proc/mpt/iocN/summary.
5078 * @buf: Pointer to area to write information
5079 * @start: Pointer to start pointer
5080 * @offset: Offset to start writing
5082 * @eof: Pointer to EOF integer
5085 * Returns number of characters written to process performing the read.
5088 procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
5098 mpt_print_ioc_summary(ioc, out, &more, 0, 1);
5102 list_for_each_entry(ioc, &ioc_list, list) {
5105 mpt_print_ioc_summary(ioc, out, &more, 0, 1);
5108 if ((out-buf) >= request)
5115 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5118 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5120 * procmpt_version_read - Handle read request from /proc/mpt/version.
5121 * @buf: Pointer to area to write information
5122 * @start: Pointer to start pointer
5123 * @offset: Offset to start writing
5125 * @eof: Pointer to EOF integer
5128 * Returns number of characters written to process performing the read.
5131 procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
5134 int scsi, lan, ctl, targ, dmp;
5138 len = sprintf(buf, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
5139 len += sprintf(buf+len, " Fusion MPT base driver\n");
5141 scsi = lan = ctl = targ = dmp = 0;
5142 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
5144 if (MptCallbacks[ii]) {
5145 switch (MptDriverClass[ii]) {
5146 case MPTSCSIH_DRIVER:
5147 if (!scsi++) drvname = "SCSI host";
5150 if (!lan++) drvname = "LAN";
5153 if (!targ++) drvname = "SCSI target";
5156 if (!ctl++) drvname = "ioctl";
5161 len += sprintf(buf+len, " Fusion MPT %s driver\n", drvname);
5165 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5168 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5170 * procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info.
5171 * @buf: Pointer to area to write information
5172 * @start: Pointer to start pointer
5173 * @offset: Offset to start writing
5175 * @eof: Pointer to EOF integer
5178 * Returns number of characters written to process performing the read.
5181 procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
5183 MPT_ADAPTER *ioc = data;
5189 mpt_get_fw_exp_ver(expVer, ioc);
5191 len = sprintf(buf, "%s:", ioc->name);
5192 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
5193 len += sprintf(buf+len, " (f/w download boot flag set)");
5194 // if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
5195 // len += sprintf(buf+len, " CONFIG_CHECKSUM_FAIL!");
5197 len += sprintf(buf+len, "\n ProductID = 0x%04x (%s)\n",
5198 ioc->facts.ProductID,
5200 len += sprintf(buf+len, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
5201 if (ioc->facts.FWImageSize)
5202 len += sprintf(buf+len, " (fw_size=%d)", ioc->facts.FWImageSize);
5203 len += sprintf(buf+len, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
5204 len += sprintf(buf+len, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
5205 len += sprintf(buf+len, " EventState = 0x%02x\n", ioc->facts.EventState);
5207 len += sprintf(buf+len, " CurrentHostMfaHighAddr = 0x%08x\n",
5208 ioc->facts.CurrentHostMfaHighAddr);
5209 len += sprintf(buf+len, " CurrentSenseBufferHighAddr = 0x%08x\n",
5210 ioc->facts.CurrentSenseBufferHighAddr);
5212 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
5213 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
5215 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
5216 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
5218 * Rounding UP to nearest 4-kB boundary here...
5220 sz = (ioc->req_sz * ioc->req_depth) + 128;
5221 sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
5222 len += sprintf(buf+len, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
5223 ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
5224 len += sprintf(buf+len, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
5225 4*ioc->facts.RequestFrameSize,
5226 ioc->facts.GlobalCredits);
5228 len += sprintf(buf+len, " Frames @ 0x%p (Dma @ 0x%p)\n",
5229 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
5230 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
5231 len += sprintf(buf+len, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
5232 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
5233 len += sprintf(buf+len, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
5234 ioc->facts.CurReplyFrameSize,
5235 ioc->facts.ReplyQueueDepth);
5237 len += sprintf(buf+len, " MaxDevices = %d\n",
5238 (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
5239 len += sprintf(buf+len, " MaxBuses = %d\n", ioc->facts.MaxBuses);
5242 for (p=0; p < ioc->facts.NumberOfPorts; p++) {
5243 len += sprintf(buf+len, " PortNumber = %d (of %d)\n",
5245 ioc->facts.NumberOfPorts);
5246 if (ioc->bus_type == FC) {
5247 if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
5248 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
5249 len += sprintf(buf+len, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
5250 a[5], a[4], a[3], a[2], a[1], a[0]);
5252 len += sprintf(buf+len, " WWN = %08X%08X:%08X%08X\n",
5253 ioc->fc_port_page0[p].WWNN.High,
5254 ioc->fc_port_page0[p].WWNN.Low,
5255 ioc->fc_port_page0[p].WWPN.High,
5256 ioc->fc_port_page0[p].WWPN.Low);
5260 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5263 #endif /* CONFIG_PROC_FS } */
5265 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5267 mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
5270 if ((ioc->facts.FWVersion.Word >> 24) == 0x0E) {
5271 sprintf(buf, " (Exp %02d%02d)",
5272 (ioc->facts.FWVersion.Word >> 16) & 0x00FF, /* Month */
5273 (ioc->facts.FWVersion.Word >> 8) & 0x1F); /* Day */
5276 if ((ioc->facts.FWVersion.Word >> 8) & 0x80)
5277 strcat(buf, " [MDBG]");
5281 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5283 * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
5284 * @ioc: Pointer to MPT_ADAPTER structure
5285 * @buffer: Pointer to buffer where IOC summary info should be written
5286 * @size: Pointer to number of bytes we wrote (set by this routine)
5287 * @len: Offset at which to start writing in buffer
5288 * @showlan: Display LAN stuff?
5290 * This routine writes (english readable) ASCII text, which represents
5291 * a summary of IOC information, to a buffer.
5294 mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
5299 mpt_get_fw_exp_ver(expVer, ioc);
5302 * Shorter summary of attached ioc's...
5304 y = sprintf(buffer+len, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
5307 MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
5308 ioc->facts.FWVersion.Word,
5310 ioc->facts.NumberOfPorts,
5313 if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
5314 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
5315 y += sprintf(buffer+len+y, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
5316 a[5], a[4], a[3], a[2], a[1], a[0]);
5320 y += sprintf(buffer+len+y, ", IRQ=%d", ioc->pci_irq);
5322 y += sprintf(buffer+len+y, ", IRQ=%s", __irq_itoa(ioc->pci_irq));
5326 y += sprintf(buffer+len+y, " (disabled)");
5328 y += sprintf(buffer+len+y, "\n");
5333 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5337 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5339 * mpt_HardResetHandler - Generic reset handler, issue SCSI Task
5340 * Management call based on input arg values. If TaskMgmt fails,
5341 * return associated SCSI request.
5342 * @ioc: Pointer to MPT_ADAPTER structure
5343 * @sleepFlag: Indicates if sleep or schedule must be called.
5345 * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
5346 * or a non-interrupt thread. In the former, must not call schedule().
5348 * Remark: A return of -1 is a FATAL error case, as it means a
5349 * FW reload/initialization failed.
5351 * Returns 0 for SUCCESS or -1 if FAILED.
5354 mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
5357 unsigned long flags;
5359 dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name));
5361 printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
5362 printk("MF count 0x%x !\n", ioc->mfcnt);
5365 /* Reset the adapter. Prevent more than 1 call to
5366 * mpt_do_ioc_recovery at any instant in time.
5368 spin_lock_irqsave(&ioc->diagLock, flags);
5369 if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)){
5370 spin_unlock_irqrestore(&ioc->diagLock, flags);
5373 ioc->diagPending = 1;
5375 spin_unlock_irqrestore(&ioc->diagLock, flags);
5377 /* FIXME: If do_ioc_recovery fails, repeat....
5380 /* The SCSI driver needs to adjust timeouts on all current
5381 * commands prior to the diagnostic reset being issued.
5382 * Prevents timeouts occuring during a diagnostic reset...very bad.
5383 * For all other protocol drivers, this is a no-op.
5389 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
5390 if (MptResetHandlers[ii]) {
5391 dtmprintk((MYIOC_s_INFO_FMT "Calling IOC reset_setup handler #%d\n",
5393 r += (*(MptResetHandlers[ii]))(ioc, MPT_IOC_SETUP_RESET);
5395 dtmprintk((MYIOC_s_INFO_FMT "Calling alt-%s setup reset handler #%d\n",
5396 ioc->name, ioc->alt_ioc->name, ii));
5397 r += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_SETUP_RESET);
5403 if ((rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag)) != 0) {
5404 printk(KERN_WARNING MYNAM ": WARNING - (%d) Cannot recover %s\n",
5409 ioc->alt_ioc->reload_fw = 0;
5411 spin_lock_irqsave(&ioc->diagLock, flags);
5412 ioc->diagPending = 0;
5414 ioc->alt_ioc->diagPending = 0;
5415 spin_unlock_irqrestore(&ioc->diagLock, flags);
5417 dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler rc = %d!\n", ioc->name, rc));
5422 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5424 EventDescriptionStr(u8 event, u32 evData0)
5429 case MPI_EVENT_NONE:
5432 case MPI_EVENT_LOG_DATA:
5435 case MPI_EVENT_STATE_CHANGE:
5436 ds = "State Change";
5438 case MPI_EVENT_UNIT_ATTENTION:
5439 ds = "Unit Attention";
5441 case MPI_EVENT_IOC_BUS_RESET:
5442 ds = "IOC Bus Reset";
5444 case MPI_EVENT_EXT_BUS_RESET:
5445 ds = "External Bus Reset";
5447 case MPI_EVENT_RESCAN:
5448 ds = "Bus Rescan Event";
5449 /* Ok, do we need to do anything here? As far as
5450 I can tell, this is when a new device gets added
5453 case MPI_EVENT_LINK_STATUS_CHANGE:
5454 if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
5455 ds = "Link Status(FAILURE) Change";
5457 ds = "Link Status(ACTIVE) Change";
5459 case MPI_EVENT_LOOP_STATE_CHANGE:
5460 if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
5461 ds = "Loop State(LIP) Change";
5462 else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
5463 ds = "Loop State(LPE) Change"; /* ??? */
5465 ds = "Loop State(LPB) Change"; /* ??? */
5467 case MPI_EVENT_LOGOUT:
5470 case MPI_EVENT_EVENT_CHANGE:
5472 ds = "Events(ON) Change";
5474 ds = "Events(OFF) Change";
5476 case MPI_EVENT_INTEGRATED_RAID:
5477 ds = "Integrated Raid";
5480 * MPT base "custom" events may be added here...
5489 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5491 * ProcessEventNotification - Route a received EventNotificationReply to
5492 * all currently regeistered event handlers.
5493 * @ioc: Pointer to MPT_ADAPTER structure
5494 * @pEventReply: Pointer to EventNotification reply frame
5495 * @evHandlers: Pointer to integer, number of event handlers
5497 * Returns sum of event handlers return values.
5500 ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
5512 * Do platform normalization of values
5514 event = le32_to_cpu(pEventReply->Event) & 0xFF;
5515 // evCtx = le32_to_cpu(pEventReply->EventContext);
5516 evDataLen = le16_to_cpu(pEventReply->EventDataLength);
5518 evData0 = le32_to_cpu(pEventReply->Data[0]);
5521 evStr = EventDescriptionStr(event, evData0);
5522 devtprintk((MYIOC_s_INFO_FMT "MPT event (%s=%02Xh) detected!\n",
5527 #if defined(MPT_DEBUG) || defined(MPT_DEBUG_EVENTS)
5528 printk(KERN_INFO MYNAM ": Event data:\n" KERN_INFO);
5529 for (ii = 0; ii < evDataLen; ii++)
5530 printk(" %08x", le32_to_cpu(pEventReply->Data[ii]));
5535 * Do general / base driver event processing
5538 case MPI_EVENT_NONE: /* 00 */
5539 case MPI_EVENT_LOG_DATA: /* 01 */
5540 case MPI_EVENT_STATE_CHANGE: /* 02 */
5541 case MPI_EVENT_UNIT_ATTENTION: /* 03 */
5542 case MPI_EVENT_IOC_BUS_RESET: /* 04 */
5543 case MPI_EVENT_EXT_BUS_RESET: /* 05 */
5544 case MPI_EVENT_RESCAN: /* 06 */
5545 case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
5546 case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
5547 case MPI_EVENT_LOGOUT: /* 09 */
5548 case MPI_EVENT_INTEGRATED_RAID: /* 0B */
5549 case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE: /* 0C */
5552 case MPI_EVENT_EVENT_CHANGE: /* 0A */
5554 u8 evState = evData0 & 0xFF;
5556 /* CHECKME! What if evState unexpectedly says OFF (0)? */
5558 /* Update EventState field in cached IocFacts */
5559 if (ioc->facts.Function) {
5560 ioc->facts.EventState = evState;
5567 * Should this event be logged? Events are written sequentially.
5568 * When buffer is full, start again at the top.
5570 if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
5573 idx = ioc->eventContext % ioc->eventLogSize;
5575 ioc->events[idx].event = event;
5576 ioc->events[idx].eventContext = ioc->eventContext;
5578 for (ii = 0; ii < 2; ii++) {
5580 ioc->events[idx].data[ii] = le32_to_cpu(pEventReply->Data[ii]);
5582 ioc->events[idx].data[ii] = 0;
5585 ioc->eventContext++;
5590 * Call each currently registered protocol event handler.
5592 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
5593 if (MptEvHandlers[ii]) {
5594 devtprintk((MYIOC_s_INFO_FMT "Routing Event to event handler #%d\n",
5596 r += (*(MptEvHandlers[ii]))(ioc, pEventReply);
5600 /* FIXME? Examine results here? */
5603 * If needed, send (a single) EventAck.
5605 if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
5606 if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
5607 devtprintk((MYIOC_s_WARN_FMT "SendEventAck returned %d\n",
5612 *evHandlers = handlers;
5616 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5618 * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
5619 * @ioc: Pointer to MPT_ADAPTER structure
5620 * @log_info: U32 LogInfo reply word from the IOC
5622 * Refer to lsi/fc_log.h.
5625 mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
5627 static char *subcl_str[8] = {
5628 "FCP Initiator", "FCP Target", "LAN", "MPI Message Layer",
5629 "FC Link", "Context Manager", "Invalid Field Offset", "State Change Info"
5631 u8 subcl = (log_info >> 24) & 0x7;
5633 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): SubCl={%s}\n",
5634 ioc->name, log_info, subcl_str[subcl]);
5637 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5639 * mpt_sp_log_info - Log information returned from SCSI Parallel IOC.
5640 * @ioc: Pointer to MPT_ADAPTER structure
5641 * @mr: Pointer to MPT reply frame
5642 * @log_info: U32 LogInfo word from the IOC
5644 * Refer to lsi/sp_log.h.
5647 mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info)
5649 u32 info = log_info & 0x00FF0000;
5650 char *desc = "unknown";
5654 desc = "bug! MID not found";
5655 if (ioc->reload_fw == 0)
5660 desc = "Parity Error";
5664 desc = "ASYNC Outbound Overrun";
5668 desc = "SYNC Offset Error";
5676 desc = "Msg In Overflow";
5684 desc = "Outbound DMA Overrun";
5688 desc = "Task Management";
5692 desc = "Device Problem";
5696 desc = "Invalid Phase Change";
5700 desc = "Untagged Table Size";
5705 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
5708 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5710 * mpt_sp_ioc_info - IOC information returned from SCSI Parallel IOC.
5711 * @ioc: Pointer to MPT_ADAPTER structure
5712 * @ioc_status: U32 IOCStatus word from IOC
5713 * @mf: Pointer to MPT request frame
5715 * Refer to lsi/mpi.h.
5718 mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
5720 u32 status = ioc_status & MPI_IOCSTATUS_MASK;
5724 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
5725 desc = "Invalid Function";
5728 case MPI_IOCSTATUS_BUSY: /* 0x0002 */
5732 case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
5733 desc = "Invalid SGL";
5736 case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
5737 desc = "Internal Error";
5740 case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
5744 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
5745 desc = "Insufficient Resources";
5748 case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
5749 desc = "Invalid Field";
5752 case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
5753 desc = "Invalid State";
5756 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
5757 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
5758 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
5759 case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
5760 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
5761 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
5762 /* No message for Config IOCStatus values */
5765 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
5766 /* No message for recovered error
5767 desc = "SCSI Recovered Error";
5771 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
5772 desc = "SCSI Invalid Bus";
5775 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
5776 desc = "SCSI Invalid TargetID";
5779 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
5781 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
5782 U8 cdb = pScsiReq->CDB[0];
5783 if (cdb != 0x12) { /* Inquiry is issued for device scanning */
5784 desc = "SCSI Device Not There";
5789 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
5790 desc = "SCSI Data Overrun";
5793 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
5794 /* This error is checked in scsi_io_done(). Skip.
5795 desc = "SCSI Data Underrun";
5799 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
5800 desc = "SCSI I/O Data Error";
5803 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
5804 desc = "SCSI Protocol Error";
5807 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
5808 desc = "SCSI Task Terminated";
5811 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
5812 desc = "SCSI Residual Mismatch";
5815 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
5816 desc = "SCSI Task Management Failed";
5819 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
5820 desc = "SCSI IOC Terminated";
5823 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
5824 desc = "SCSI Ext Terminated";
5832 printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04x): %s\n", ioc->name, status, desc);
5835 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5836 EXPORT_SYMBOL(ioc_list);
5837 EXPORT_SYMBOL(mpt_proc_root_dir);
5838 EXPORT_SYMBOL(mpt_register);
5839 EXPORT_SYMBOL(mpt_deregister);
5840 EXPORT_SYMBOL(mpt_event_register);
5841 EXPORT_SYMBOL(mpt_event_deregister);
5842 EXPORT_SYMBOL(mpt_reset_register);
5843 EXPORT_SYMBOL(mpt_reset_deregister);
5844 EXPORT_SYMBOL(mpt_device_driver_register);
5845 EXPORT_SYMBOL(mpt_device_driver_deregister);
5846 EXPORT_SYMBOL(mpt_get_msg_frame);
5847 EXPORT_SYMBOL(mpt_put_msg_frame);
5848 EXPORT_SYMBOL(mpt_free_msg_frame);
5849 EXPORT_SYMBOL(mpt_add_sge);
5850 EXPORT_SYMBOL(mpt_send_handshake_request);
5851 EXPORT_SYMBOL(mpt_verify_adapter);
5852 EXPORT_SYMBOL(mpt_GetIocState);
5853 EXPORT_SYMBOL(mpt_print_ioc_summary);
5854 EXPORT_SYMBOL(mpt_lan_index);
5855 EXPORT_SYMBOL(mpt_stm_index);
5856 EXPORT_SYMBOL(mpt_HardResetHandler);
5857 EXPORT_SYMBOL(mpt_config);
5858 EXPORT_SYMBOL(mpt_toolbox);
5859 EXPORT_SYMBOL(mpt_findImVolumes);
5860 EXPORT_SYMBOL(mpt_read_ioc_pg_3);
5861 EXPORT_SYMBOL(mpt_alloc_fw_memory);
5862 EXPORT_SYMBOL(mpt_free_fw_memory);
5864 static struct pci_driver mptbase_driver = {
5866 .id_table = mptbase_pci_table,
5867 .probe = mptbase_probe,
5868 .remove = __devexit_p(mptbase_remove),
5870 .shutdown = mptbase_shutdown,
5873 .suspend = mptbase_suspend,
5874 .resume = mptbase_resume,
5878 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5880 * fusion_init - Fusion MPT base driver initialization routine.
5882 * Returns 0 for success, non-zero for failure.
5890 show_mptmod_ver(my_NAME, my_VERSION);
5891 printk(KERN_INFO COPYRIGHT "\n");
5893 for (i = 0; i < MPT_MAX_PROTOCOL_DRIVERS; i++) {
5894 MptCallbacks[i] = NULL;
5895 MptDriverClass[i] = MPTUNKNOWN_DRIVER;
5896 MptEvHandlers[i] = NULL;
5897 MptResetHandlers[i] = NULL;
5900 /* NEW! 20010120 -sralston
5901 * Register ourselves (mptbase) in order to facilitate
5902 * EventNotification handling.
5904 mpt_base_index = mpt_register(mpt_base_reply, MPTBASE_DRIVER);
5906 /* Register for hard reset handling callbacks.
5908 if (mpt_reset_register(mpt_base_index, mpt_ioc_reset) == 0) {
5909 dprintk((KERN_INFO MYNAM ": Register for IOC reset notification\n"));
5914 #ifdef CONFIG_PROC_FS
5915 (void) procmpt_create();
5917 r = pci_module_init(&mptbase_driver);
5924 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5926 * fusion_exit - Perform driver unload cleanup.
5928 * This routine frees all resources associated with each MPT adapter
5929 * and removes all %MPT_PROCFS_MPTBASEDIR entries.
5935 dexitprintk((KERN_INFO MYNAM ": fusion_exit() called!\n"));
5937 pci_unregister_driver(&mptbase_driver);
5938 mpt_reset_deregister(mpt_base_index);
5940 #ifdef CONFIG_PROC_FS
5946 module_init(fusion_init);
5947 module_exit(fusion_exit);