2 * linux/drivers/message/fusion/mptbase.c
3 * This is the Fusion MPT base driver which supports multiple
4 * (SCSI + LAN) specialized protocol drivers.
5 * For use with LSI Logic PCI chip/adapter(s)
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsi.com)
12 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; version 2 of the License.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
24 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
25 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
26 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
27 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
28 solely responsible for determining the appropriateness of using and
29 distributing the Program and assumes all risks associated with its
30 exercise of rights under this Agreement, including but not limited to
31 the risks and costs of program errors, damage to or loss of data,
32 programs or equipment, and unavailability or interruption of operations.
34 DISCLAIMER OF LIABILITY
35 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
36 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
38 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
39 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
40 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
41 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
43 You should have received a copy of the GNU General Public License
44 along with this program; if not, write to the Free Software
45 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
49 #include <linux/kernel.h>
50 #include <linux/module.h>
51 #include <linux/errno.h>
52 #include <linux/init.h>
53 #include <linux/slab.h>
54 #include <linux/types.h>
55 #include <linux/pci.h>
56 #include <linux/kdev_t.h>
57 #include <linux/blkdev.h>
58 #include <linux/delay.h>
59 #include <linux/interrupt.h> /* needed for in_interrupt() proto */
60 #include <linux/dma-mapping.h>
68 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
69 #define my_NAME "Fusion MPT base driver"
70 #define my_VERSION MPT_LINUX_VERSION_COMMON
71 #define MYNAM "mptbase"
73 MODULE_AUTHOR(MODULEAUTHOR);
74 MODULE_DESCRIPTION(my_NAME);
75 MODULE_LICENSE("GPL");
76 MODULE_VERSION(my_VERSION);
81 static int mpt_msi_enable;
82 module_param(mpt_msi_enable, int, 0);
83 MODULE_PARM_DESC(mpt_msi_enable, " MSI Support Enable (default=0)");
85 static int mpt_channel_mapping;
86 module_param(mpt_channel_mapping, int, 0);
87 MODULE_PARM_DESC(mpt_channel_mapping, " Mapping id's to channels (default=0)");
90 static int mfcounter = 0;
91 #define PRINT_MF_COUNT 20000
94 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
98 int mpt_lan_index = -1;
99 int mpt_stm_index = -1;
101 struct proc_dir_entry *mpt_proc_root_dir;
103 #define WHOINIT_UNKNOWN 0xAA
105 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
109 /* Adapter link list */
111 /* Callback lookup table */
112 static MPT_CALLBACK MptCallbacks[MPT_MAX_PROTOCOL_DRIVERS];
113 /* Protocol driver class lookup table */
114 static int MptDriverClass[MPT_MAX_PROTOCOL_DRIVERS];
115 /* Event handler lookup table */
116 static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
117 /* Reset handler lookup table */
118 static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
119 static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
121 static int mpt_base_index = -1;
122 static int last_drv_idx = -1;
124 static DECLARE_WAIT_QUEUE_HEAD(mpt_waitq);
126 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
130 static irqreturn_t mpt_interrupt(int irq, void *bus_id);
131 static int mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
132 static int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
133 u32 *req, int replyBytes, u16 *u16reply, int maxwait,
135 static int mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag);
136 static void mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev);
137 static void mpt_adapter_disable(MPT_ADAPTER *ioc);
138 static void mpt_adapter_dispose(MPT_ADAPTER *ioc);
140 static void MptDisplayIocCapabilities(MPT_ADAPTER *ioc);
141 static int MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag);
142 static int GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason);
143 static int GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
144 static int SendIocInit(MPT_ADAPTER *ioc, int sleepFlag);
145 static int SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
146 static int mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag);
147 static int mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag);
148 static int mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
149 static int KickStart(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
150 static int SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag);
151 static int PrimeIocFifos(MPT_ADAPTER *ioc);
152 static int WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
153 static int WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
154 static int WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
155 static int GetLanConfigPages(MPT_ADAPTER *ioc);
156 static int GetIoUnitPage2(MPT_ADAPTER *ioc);
157 int mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
158 static int mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
159 static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
160 static void mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
161 static void mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
162 static void mpt_timer_expired(unsigned long data);
163 static int SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch);
164 static int SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
165 static int mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag);
166 static int mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
168 #ifdef CONFIG_PROC_FS
169 static int procmpt_summary_read(char *buf, char **start, off_t offset,
170 int request, int *eof, void *data);
171 static int procmpt_version_read(char *buf, char **start, off_t offset,
172 int request, int *eof, void *data);
173 static int procmpt_iocinfo_read(char *buf, char **start, off_t offset,
174 int request, int *eof, void *data);
176 static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
178 //int mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
179 static int ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers);
180 #ifdef MPT_DEBUG_REPLY
181 static void mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
183 static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
184 static void mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info);
185 static void mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info);
186 static int mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
187 static void mpt_inactive_raid_list_free(MPT_ADAPTER *ioc);
189 /* module entry point */
190 static int __init fusion_init (void);
191 static void __exit fusion_exit (void);
193 #define CHIPREG_READ32(addr) readl_relaxed(addr)
194 #define CHIPREG_READ32_dmasync(addr) readl(addr)
195 #define CHIPREG_WRITE32(addr,val) writel(val, addr)
196 #define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
197 #define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
200 pci_disable_io_access(struct pci_dev *pdev)
204 pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
206 pci_write_config_word(pdev, PCI_COMMAND, command_reg);
210 pci_enable_io_access(struct pci_dev *pdev)
214 pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
216 pci_write_config_word(pdev, PCI_COMMAND, command_reg);
220 * Process turbo (context) reply...
223 mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa)
225 MPT_FRAME_HDR *mf = NULL;
226 MPT_FRAME_HDR *mr = NULL;
230 dmfprintk((MYIOC_s_INFO_FMT "Got TURBO reply req_idx=%08x\n",
233 switch (pa >> MPI_CONTEXT_REPLY_TYPE_SHIFT) {
234 case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT:
235 req_idx = pa & 0x0000FFFF;
236 cb_idx = (pa & 0x00FF0000) >> 16;
237 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
239 case MPI_CONTEXT_REPLY_TYPE_LAN:
240 cb_idx = mpt_lan_index;
242 * Blind set of mf to NULL here was fatal
243 * after lan_reply says "freeme"
244 * Fix sort of combined with an optimization here;
245 * added explicit check for case where lan_reply
246 * was just returning 1 and doing nothing else.
247 * For this case skip the callback, but set up
248 * proper mf value first here:-)
250 if ((pa & 0x58000000) == 0x58000000) {
251 req_idx = pa & 0x0000FFFF;
252 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
253 mpt_free_msg_frame(ioc, mf);
258 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
260 case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET:
261 cb_idx = mpt_stm_index;
262 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
269 /* Check for (valid) IO callback! */
270 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
271 MptCallbacks[cb_idx] == NULL) {
272 printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
273 __FUNCTION__, ioc->name, cb_idx);
277 if (MptCallbacks[cb_idx](ioc, mf, mr))
278 mpt_free_msg_frame(ioc, mf);
284 mpt_reply(MPT_ADAPTER *ioc, u32 pa)
295 /* non-TURBO reply! Hmmm, something may be up...
296 * Newest turbo reply mechanism; get address
297 * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
300 /* Map DMA address of reply header to cpu address.
301 * pa is 32 bits - but the dma address may be 32 or 64 bits
302 * get offset based only only the low addresses
305 reply_dma_low = (pa <<= 1);
306 mr = (MPT_FRAME_HDR *)((u8 *)ioc->reply_frames +
307 (reply_dma_low - ioc->reply_frames_low_dma));
309 req_idx = le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx);
310 cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
311 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
313 dmfprintk((MYIOC_s_INFO_FMT "Got non-TURBO reply=%p req_idx=%x cb_idx=%x Function=%x\n",
314 ioc->name, mr, req_idx, cb_idx, mr->u.hdr.Function));
315 DBG_DUMP_REPLY_FRAME(mr)
317 /* Check/log IOC log info
319 ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
320 if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
321 u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
322 if (ioc->bus_type == FC)
323 mpt_fc_log_info(ioc, log_info);
324 else if (ioc->bus_type == SPI)
325 mpt_spi_log_info(ioc, log_info);
326 else if (ioc->bus_type == SAS)
327 mpt_sas_log_info(ioc, log_info);
330 #ifdef MPT_DEBUG_REPLY
331 if (ioc_stat & MPI_IOCSTATUS_MASK)
332 mpt_iocstatus_info(ioc, (u32)ioc_stat, mf);
335 /* Check for (valid) IO callback! */
336 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
337 MptCallbacks[cb_idx] == NULL) {
338 printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
339 __FUNCTION__, ioc->name, cb_idx);
344 freeme = MptCallbacks[cb_idx](ioc, mf, mr);
347 /* Flush (non-TURBO) reply with a WRITE! */
348 CHIPREG_WRITE32(&ioc->chip->ReplyFifo, pa);
351 mpt_free_msg_frame(ioc, mf);
355 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
357 * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
358 * @irq: irq number (not used)
359 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
361 * This routine is registered via the request_irq() kernel API call,
362 * and handles all interrupts generated from a specific MPT adapter
363 * (also referred to as a IO Controller or IOC).
364 * This routine must clear the interrupt from the adapter and does
365 * so by reading the reply FIFO. Multiple replies may be processed
366 * per single call to this routine.
368 * This routine handles register-level access of the adapter but
369 * dispatches (calls) a protocol-specific callback routine to handle
370 * the protocol-specific details of the MPT request completion.
373 mpt_interrupt(int irq, void *bus_id)
375 MPT_ADAPTER *ioc = bus_id;
376 u32 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
378 if (pa == 0xFFFFFFFF)
382 * Drain the reply FIFO!
385 if (pa & MPI_ADDRESS_REPLY_A_BIT)
388 mpt_turbo_reply(ioc, pa);
389 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
390 } while (pa != 0xFFFFFFFF);
395 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
397 * mpt_base_reply - MPT base driver's callback routine
398 * @ioc: Pointer to MPT_ADAPTER structure
399 * @mf: Pointer to original MPT request frame
400 * @reply: Pointer to MPT reply frame (NULL if TurboReply)
402 * MPT base driver's callback routine; all base driver
403 * "internal" request/reply processing is routed here.
404 * Currently used for EventNotification and EventAck handling.
406 * Returns 1 indicating original alloc'd request frame ptr
407 * should be freed, or 0 if it shouldn't.
410 mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
415 dmfprintk((MYIOC_s_INFO_FMT "mpt_base_reply() called\n", ioc->name));
417 #if defined(MPT_DEBUG_MSG_FRAME)
418 if (!(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) {
419 dmfprintk((KERN_INFO MYNAM ": Original request frame (@%p) header\n", mf));
420 DBG_DUMP_REQUEST_FRAME_HDR(mf)
424 func = reply->u.hdr.Function;
425 dmfprintk((MYIOC_s_INFO_FMT "mpt_base_reply, Function=%02Xh\n",
428 if (func == MPI_FUNCTION_EVENT_NOTIFICATION) {
429 EventNotificationReply_t *pEvReply = (EventNotificationReply_t *) reply;
433 results = ProcessEventNotification(ioc, pEvReply, &evHandlers);
434 if (results != evHandlers) {
435 /* CHECKME! Any special handling needed here? */
436 devtverboseprintk((MYIOC_s_WARN_FMT "Called %d event handlers, sum results = %d\n",
437 ioc->name, evHandlers, results));
441 * Hmmm... It seems that EventNotificationReply is an exception
442 * to the rule of one reply per request.
444 if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) {
447 devtverboseprintk((MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p returns Request frame\n",
448 ioc->name, pEvReply));
451 #ifdef CONFIG_PROC_FS
452 // LogEvent(ioc, pEvReply);
455 } else if (func == MPI_FUNCTION_EVENT_ACK) {
456 dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, EventAck reply received\n",
458 } else if (func == MPI_FUNCTION_CONFIG) {
462 dcprintk((MYIOC_s_INFO_FMT "config_complete (mf=%p,mr=%p)\n",
463 ioc->name, mf, reply));
465 pCfg = * ((CONFIGPARMS **)((u8 *) mf + ioc->req_sz - sizeof(void *)));
468 /* disable timer and remove from linked list */
469 del_timer(&pCfg->timer);
471 spin_lock_irqsave(&ioc->FreeQlock, flags);
472 list_del(&pCfg->linkage);
473 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
476 * If IOC Status is SUCCESS, save the header
477 * and set the status code to GOOD.
479 pCfg->status = MPT_CONFIG_ERROR;
481 ConfigReply_t *pReply = (ConfigReply_t *)reply;
484 status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
485 dcprintk((KERN_NOTICE " IOCStatus=%04xh, IOCLogInfo=%08xh\n",
486 status, le32_to_cpu(pReply->IOCLogInfo)));
488 pCfg->status = status;
489 if (status == MPI_IOCSTATUS_SUCCESS) {
490 if ((pReply->Header.PageType &
491 MPI_CONFIG_PAGETYPE_MASK) ==
492 MPI_CONFIG_PAGETYPE_EXTENDED) {
493 pCfg->cfghdr.ehdr->ExtPageLength =
494 le16_to_cpu(pReply->ExtPageLength);
495 pCfg->cfghdr.ehdr->ExtPageType =
498 pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
500 /* If this is a regular header, save PageLength. */
501 /* LMP Do this better so not using a reserved field! */
502 pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
503 pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
504 pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
509 * Wake up the original calling thread
514 } else if (func == MPI_FUNCTION_SAS_IO_UNIT_CONTROL) {
515 /* we should be always getting a reply frame */
516 memcpy(ioc->persist_reply_frame, reply,
517 min(MPT_DEFAULT_FRAME_SIZE,
518 4*reply->u.reply.MsgLength));
519 del_timer(&ioc->persist_timer);
520 ioc->persist_wait_done = 1;
523 printk(MYIOC_s_ERR_FMT "Unexpected msg function (=%02Xh) reply received!\n",
528 * Conditionally tell caller to free the original
529 * EventNotification/EventAck/unexpected request frame!
534 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
536 * mpt_register - Register protocol-specific main callback handler.
537 * @cbfunc: callback function pointer
538 * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
540 * This routine is called by a protocol-specific driver (SCSI host,
541 * LAN, SCSI target) to register its reply callback routine. Each
542 * protocol-specific driver must do this before it will be able to
543 * use any IOC resources, such as obtaining request frames.
545 * NOTES: The SCSI protocol driver currently calls this routine thrice
546 * in order to register separate callbacks; one for "normal" SCSI IO;
547 * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
549 * Returns a positive integer valued "handle" in the
550 * range (and S.O.D. order) {N,...,7,6,5,...,1} if successful.
551 * Any non-positive return value (including zero!) should be considered
552 * an error by the caller.
555 mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
562 * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
563 * (slot/handle 0 is reserved!)
565 for (i = MPT_MAX_PROTOCOL_DRIVERS-1; i; i--) {
566 if (MptCallbacks[i] == NULL) {
567 MptCallbacks[i] = cbfunc;
568 MptDriverClass[i] = dclass;
569 MptEvHandlers[i] = NULL;
578 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
580 * mpt_deregister - Deregister a protocol drivers resources.
581 * @cb_idx: previously registered callback handle
583 * Each protocol-specific driver should call this routine when its
584 * module is unloaded.
587 mpt_deregister(int cb_idx)
589 if ((cb_idx >= 0) && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
590 MptCallbacks[cb_idx] = NULL;
591 MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
592 MptEvHandlers[cb_idx] = NULL;
598 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
600 * mpt_event_register - Register protocol-specific event callback
602 * @cb_idx: previously registered (via mpt_register) callback handle
603 * @ev_cbfunc: callback function
605 * This routine can be called by one or more protocol-specific drivers
606 * if/when they choose to be notified of MPT events.
608 * Returns 0 for success.
611 mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc)
613 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
616 MptEvHandlers[cb_idx] = ev_cbfunc;
620 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
622 * mpt_event_deregister - Deregister protocol-specific event callback
624 * @cb_idx: previously registered callback handle
626 * Each protocol-specific driver should call this routine
627 * when it does not (or can no longer) handle events,
628 * or when its module is unloaded.
631 mpt_event_deregister(int cb_idx)
633 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
636 MptEvHandlers[cb_idx] = NULL;
639 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
641 * mpt_reset_register - Register protocol-specific IOC reset handler.
642 * @cb_idx: previously registered (via mpt_register) callback handle
643 * @reset_func: reset function
645 * This routine can be called by one or more protocol-specific drivers
646 * if/when they choose to be notified of IOC resets.
648 * Returns 0 for success.
651 mpt_reset_register(int cb_idx, MPT_RESETHANDLER reset_func)
653 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
656 MptResetHandlers[cb_idx] = reset_func;
660 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
662 * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
663 * @cb_idx: previously registered callback handle
665 * Each protocol-specific driver should call this routine
666 * when it does not (or can no longer) handle IOC reset handling,
667 * or when its module is unloaded.
670 mpt_reset_deregister(int cb_idx)
672 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
675 MptResetHandlers[cb_idx] = NULL;
678 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
680 * mpt_device_driver_register - Register device driver hooks
681 * @dd_cbfunc: driver callbacks struct
682 * @cb_idx: MPT protocol driver index
685 mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx)
688 const struct pci_device_id *id;
690 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
693 MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
695 /* call per pci device probe entry point */
696 list_for_each_entry(ioc, &ioc_list, list) {
697 id = ioc->pcidev->driver ?
698 ioc->pcidev->driver->id_table : NULL;
699 if (dd_cbfunc->probe)
700 dd_cbfunc->probe(ioc->pcidev, id);
706 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
708 * mpt_device_driver_deregister - DeRegister device driver hooks
709 * @cb_idx: MPT protocol driver index
712 mpt_device_driver_deregister(int cb_idx)
714 struct mpt_pci_driver *dd_cbfunc;
717 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
720 dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
722 list_for_each_entry(ioc, &ioc_list, list) {
723 if (dd_cbfunc->remove)
724 dd_cbfunc->remove(ioc->pcidev);
727 MptDeviceDriverHandlers[cb_idx] = NULL;
731 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
733 * mpt_get_msg_frame - Obtain a MPT request frame from the pool (of 1024)
734 * allocated per MPT adapter.
735 * @handle: Handle of registered MPT protocol driver
736 * @ioc: Pointer to MPT adapter structure
738 * Returns pointer to a MPT request frame or %NULL if none are available
739 * or IOC is not active.
742 mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
746 u16 req_idx; /* Request index */
748 /* validate handle and ioc identifier */
752 printk(KERN_WARNING "IOC Not Active! mpt_get_msg_frame returning NULL!\n");
755 /* If interrupts are not attached, do not return a request frame */
759 spin_lock_irqsave(&ioc->FreeQlock, flags);
760 if (!list_empty(&ioc->FreeQ)) {
763 mf = list_entry(ioc->FreeQ.next, MPT_FRAME_HDR,
764 u.frame.linkage.list);
765 list_del(&mf->u.frame.linkage.list);
766 mf->u.frame.linkage.arg1 = 0;
767 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
768 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
770 req_idx = req_offset / ioc->req_sz;
771 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
772 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
773 ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame; /* Default, will be changed if necessary in SG generation */
780 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
784 printk(KERN_WARNING "IOC Active. No free Msg Frames! Count 0x%x Max 0x%x\n", ioc->mfcnt, ioc->req_depth);
786 if (mfcounter == PRINT_MF_COUNT)
787 printk(KERN_INFO "MF Count 0x%x Max 0x%x \n", ioc->mfcnt, ioc->req_depth);
790 dmfprintk((KERN_INFO MYNAM ": %s: mpt_get_msg_frame(%d,%d), got mf=%p\n",
791 ioc->name, handle, ioc->id, mf));
795 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
797 * mpt_put_msg_frame - Send a protocol specific MPT request frame
799 * @handle: Handle of registered MPT protocol driver
800 * @ioc: Pointer to MPT adapter structure
801 * @mf: Pointer to MPT request frame
803 * This routine posts a MPT request frame to the request post FIFO of a
804 * specific MPT adapter.
807 mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
811 u16 req_idx; /* Request index */
813 /* ensure values are reset properly! */
814 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
815 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
817 req_idx = req_offset / ioc->req_sz;
818 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
819 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
821 #ifdef MPT_DEBUG_MSG_FRAME
823 u32 *m = mf->u.frame.hwhdr.__hdr;
826 printk(KERN_INFO MYNAM ": %s: About to Put msg frame @ %p:\n" KERN_INFO " ",
828 n = ioc->req_sz/4 - 1;
831 for (ii=0; ii<=n; ii++) {
832 if (ii && ((ii%8)==0))
833 printk("\n" KERN_INFO " ");
834 printk(" %08x", le32_to_cpu(m[ii]));
840 mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
841 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]));
842 CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
845 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
847 * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
848 * @handle: Handle of registered MPT protocol driver
849 * @ioc: Pointer to MPT adapter structure
850 * @mf: Pointer to MPT request frame
852 * This routine places a MPT request frame back on the MPT adapter's
856 mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
860 /* Put Request back on FreeQ! */
861 spin_lock_irqsave(&ioc->FreeQlock, flags);
862 mf->u.frame.linkage.arg1 = 0xdeadbeaf; /* signature to know if this mf is freed */
863 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
867 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
870 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
872 * mpt_add_sge - Place a simple SGE at address pAddr.
873 * @pAddr: virtual address for SGE
874 * @flagslength: SGE flags and data transfer length
875 * @dma_addr: Physical address
877 * This routine places a MPT request frame back on the MPT adapter's
881 mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
883 if (sizeof(dma_addr_t) == sizeof(u64)) {
884 SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
885 u32 tmp = dma_addr & 0xFFFFFFFF;
887 pSge->FlagsLength = cpu_to_le32(flagslength);
888 pSge->Address.Low = cpu_to_le32(tmp);
889 tmp = (u32) ((u64)dma_addr >> 32);
890 pSge->Address.High = cpu_to_le32(tmp);
893 SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
894 pSge->FlagsLength = cpu_to_le32(flagslength);
895 pSge->Address = cpu_to_le32(dma_addr);
899 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
901 * mpt_send_handshake_request - Send MPT request via doorbell handshake method.
902 * @handle: Handle of registered MPT protocol driver
903 * @ioc: Pointer to MPT adapter structure
904 * @reqBytes: Size of the request in bytes
905 * @req: Pointer to MPT request frame
906 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
908 * This routine is used exclusively to send MptScsiTaskMgmt
909 * requests since they are required to be sent via doorbell handshake.
911 * NOTE: It is the callers responsibility to byte-swap fields in the
912 * request which are greater than 1 byte in size.
914 * Returns 0 for success, non-zero for failure.
917 mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
923 /* State is known to be good upon entering
924 * this function so issue the bus reset
929 * Emulate what mpt_put_msg_frame() does /wrt to sanity
930 * setting cb_idx/req_idx. But ONLY if this request
931 * is in proper (pre-alloc'd) request buffer range...
933 ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
934 if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
935 MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
936 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
937 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle;
940 /* Make sure there are no doorbells */
941 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
943 CHIPREG_WRITE32(&ioc->chip->Doorbell,
944 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
945 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
947 /* Wait for IOC doorbell int */
948 if ((ii = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0) {
952 /* Read doorbell and check for active bit */
953 if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
956 dhsprintk((KERN_INFO MYNAM ": %s: mpt_send_handshake_request start, WaitCnt=%d\n",
959 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
961 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
965 /* Send request via doorbell handshake */
966 req_as_bytes = (u8 *) req;
967 for (ii = 0; ii < reqBytes/4; ii++) {
970 word = ((req_as_bytes[(ii*4) + 0] << 0) |
971 (req_as_bytes[(ii*4) + 1] << 8) |
972 (req_as_bytes[(ii*4) + 2] << 16) |
973 (req_as_bytes[(ii*4) + 3] << 24));
974 CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
975 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
981 if (r >= 0 && WaitForDoorbellInt(ioc, 10, sleepFlag) >= 0)
986 /* Make sure there are no doorbells */
987 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
992 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
994 * mpt_host_page_access_control - control the IOC's Host Page Buffer access
995 * @ioc: Pointer to MPT adapter structure
996 * @access_control_value: define bits below
997 * @sleepFlag: Specifies whether the process can sleep
999 * Provides mechanism for the host driver to control the IOC's
1000 * Host Page Buffer access.
1002 * Access Control Value - bits[15:12]
1004 * 1h Enable Access { MPI_DB_HPBAC_ENABLE_ACCESS }
1005 * 2h Disable Access { MPI_DB_HPBAC_DISABLE_ACCESS }
1006 * 3h Free Buffer { MPI_DB_HPBAC_FREE_BUFFER }
1008 * Returns 0 for success, non-zero for failure.
1012 mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag)
1016 /* return if in use */
1017 if (CHIPREG_READ32(&ioc->chip->Doorbell)
1018 & MPI_DOORBELL_ACTIVE)
1021 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1023 CHIPREG_WRITE32(&ioc->chip->Doorbell,
1024 ((MPI_FUNCTION_HOST_PAGEBUF_ACCESS_CONTROL
1025 <<MPI_DOORBELL_FUNCTION_SHIFT) |
1026 (access_control_value<<12)));
1028 /* Wait for IOC to clear Doorbell Status bit */
1029 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
1035 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1037 * mpt_host_page_alloc - allocate system memory for the fw
1038 * @ioc: Pointer to pointer to IOC adapter
1039 * @ioc_init: Pointer to ioc init config page
1041 * If we already allocated memory in past, then resend the same pointer.
1042 * Returns 0 for success, non-zero for failure.
1045 mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
1049 u32 host_page_buffer_sz=0;
1051 if(!ioc->HostPageBuffer) {
1053 host_page_buffer_sz =
1054 le32_to_cpu(ioc->facts.HostPageBufferSGE.FlagsLength) & 0xFFFFFF;
1056 if(!host_page_buffer_sz)
1057 return 0; /* fw doesn't need any host buffers */
1059 /* spin till we get enough memory */
1060 while(host_page_buffer_sz > 0) {
1062 if((ioc->HostPageBuffer = pci_alloc_consistent(
1064 host_page_buffer_sz,
1065 &ioc->HostPageBuffer_dma)) != NULL) {
1067 dinitprintk((MYIOC_s_INFO_FMT
1068 "host_page_buffer @ %p, dma @ %x, sz=%d bytes\n",
1069 ioc->name, ioc->HostPageBuffer,
1070 (u32)ioc->HostPageBuffer_dma,
1071 host_page_buffer_sz));
1072 ioc->alloc_total += host_page_buffer_sz;
1073 ioc->HostPageBuffer_sz = host_page_buffer_sz;
1077 host_page_buffer_sz -= (4*1024);
1081 if(!ioc->HostPageBuffer) {
1082 printk(MYIOC_s_ERR_FMT
1083 "Failed to alloc memory for host_page_buffer!\n",
1088 psge = (char *)&ioc_init->HostPageBufferSGE;
1089 flags_length = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
1090 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
1091 MPI_SGE_FLAGS_32_BIT_ADDRESSING |
1092 MPI_SGE_FLAGS_HOST_TO_IOC |
1093 MPI_SGE_FLAGS_END_OF_BUFFER;
1094 if (sizeof(dma_addr_t) == sizeof(u64)) {
1095 flags_length |= MPI_SGE_FLAGS_64_BIT_ADDRESSING;
1097 flags_length = flags_length << MPI_SGE_FLAGS_SHIFT;
1098 flags_length |= ioc->HostPageBuffer_sz;
1099 mpt_add_sge(psge, flags_length, ioc->HostPageBuffer_dma);
1100 ioc->facts.HostPageBufferSGE = ioc_init->HostPageBufferSGE;
1105 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1107 * mpt_verify_adapter - Given IOC identifier, set pointer to its adapter structure.
1108 * @iocid: IOC unique identifier (integer)
1109 * @iocpp: Pointer to pointer to IOC adapter
1111 * Given a unique IOC identifier, set pointer to the associated MPT
1112 * adapter structure.
1114 * Returns iocid and sets iocpp if iocid is found.
1115 * Returns -1 if iocid is not found.
1118 mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
1122 list_for_each_entry(ioc,&ioc_list,list) {
1123 if (ioc->id == iocid) {
1133 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1135 * mpt_attach - Install a PCI intelligent MPT adapter.
1136 * @pdev: Pointer to pci_dev structure
1137 * @id: PCI device ID information
1139 * This routine performs all the steps necessary to bring the IOC of
1140 * a MPT adapter to a OPERATIONAL state. This includes registering
1141 * memory regions, registering the interrupt, and allocating request
1142 * and reply memory pools.
1144 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1147 * Returns 0 for success, non-zero for failure.
1149 * TODO: Add support for polled controllers
1152 mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1156 unsigned long mem_phys;
1164 static int mpt_ids = 0;
1165 #ifdef CONFIG_PROC_FS
1166 struct proc_dir_entry *dent, *ent;
1169 if (pci_enable_device(pdev))
1172 dinitprintk((KERN_WARNING MYNAM ": mpt_adapter_install\n"));
1174 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
1175 dprintk((KERN_INFO MYNAM
1176 ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n"));
1177 } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
1178 printk(KERN_WARNING MYNAM ": 32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
1182 if (!pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))
1183 dprintk((KERN_INFO MYNAM
1184 ": Using 64 bit consistent mask\n"));
1186 dprintk((KERN_INFO MYNAM
1187 ": Not using 64 bit consistent mask\n"));
1189 ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
1191 printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
1194 ioc->alloc_total = sizeof(MPT_ADAPTER);
1195 ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
1196 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
1199 ioc->diagPending = 0;
1200 spin_lock_init(&ioc->diagLock);
1201 spin_lock_init(&ioc->initializing_hba_lock);
1203 /* Initialize the event logging.
1205 ioc->eventTypes = 0; /* None */
1206 ioc->eventContext = 0;
1207 ioc->eventLogSize = 0;
1214 ioc->cached_fw = NULL;
1216 /* Initilize SCSI Config Data structure
1218 memset(&ioc->spi_data, 0, sizeof(SpiCfgData));
1220 /* Initialize the running configQ head.
1222 INIT_LIST_HEAD(&ioc->configQ);
1224 /* Initialize the fc rport list head.
1226 INIT_LIST_HEAD(&ioc->fc_rports);
1228 /* Find lookup slot. */
1229 INIT_LIST_HEAD(&ioc->list);
1230 ioc->id = mpt_ids++;
1232 mem_phys = msize = 0;
1234 for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) {
1235 if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
1238 /* Get I/O space! */
1239 port = pci_resource_start(pdev, ii);
1240 psize = pci_resource_len(pdev,ii);
1245 mem_phys = pci_resource_start(pdev, ii);
1246 msize = pci_resource_len(pdev,ii);
1249 ioc->mem_size = msize;
1252 /* Get logical ptr for PciMem0 space */
1253 /*mem = ioremap(mem_phys, msize);*/
1254 mem = ioremap(mem_phys, msize);
1256 printk(KERN_ERR MYNAM ": ERROR - Unable to map adapter memory!\n");
1261 dinitprintk((KERN_INFO MYNAM ": mem = %p, mem_phys = %lx\n", mem, mem_phys));
1263 dinitprintk((KERN_INFO MYNAM ": facts @ %p, pfacts[0] @ %p\n",
1264 &ioc->facts, &ioc->pfacts[0]));
1266 ioc->mem_phys = mem_phys;
1267 ioc->chip = (SYSIF_REGS __iomem *)mem;
1269 /* Save Port IO values in case we need to do downloadboot */
1271 u8 *pmem = (u8*)port;
1272 ioc->pio_mem_phys = port;
1273 ioc->pio_chip = (SYSIF_REGS __iomem *)pmem;
1276 if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC909) {
1277 ioc->prod_name = "LSIFC909";
1280 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929) {
1281 ioc->prod_name = "LSIFC929";
1284 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919) {
1285 ioc->prod_name = "LSIFC919";
1288 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929X) {
1289 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1291 if (revision < XL_929) {
1292 ioc->prod_name = "LSIFC929X";
1293 /* 929X Chip Fix. Set Split transactions level
1294 * for PCIX. Set MOST bits to zero.
1296 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1298 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1300 ioc->prod_name = "LSIFC929XL";
1301 /* 929XL Chip Fix. Set MMRBC to 0x08.
1303 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1305 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1308 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919X) {
1309 ioc->prod_name = "LSIFC919X";
1311 /* 919X Chip Fix. Set Split transactions level
1312 * for PCIX. Set MOST bits to zero.
1314 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1316 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1318 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC939X) {
1319 ioc->prod_name = "LSIFC939X";
1321 ioc->errata_flag_1064 = 1;
1323 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC949X) {
1324 ioc->prod_name = "LSIFC949X";
1326 ioc->errata_flag_1064 = 1;
1328 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC949E) {
1329 ioc->prod_name = "LSIFC949E";
1332 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_53C1030) {
1333 ioc->prod_name = "LSI53C1030";
1334 ioc->bus_type = SPI;
1335 /* 1030 Chip Fix. Disable Split transactions
1336 * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
1338 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1339 if (revision < C0_1030) {
1340 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1342 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1345 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_1030_53C1035) {
1346 ioc->prod_name = "LSI53C1035";
1347 ioc->bus_type = SPI;
1349 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1064) {
1350 ioc->prod_name = "LSISAS1064";
1351 ioc->bus_type = SAS;
1352 ioc->errata_flag_1064 = 1;
1354 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1068) {
1355 ioc->prod_name = "LSISAS1068";
1356 ioc->bus_type = SAS;
1357 ioc->errata_flag_1064 = 1;
1359 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1064E) {
1360 ioc->prod_name = "LSISAS1064E";
1361 ioc->bus_type = SAS;
1363 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1068E) {
1364 ioc->prod_name = "LSISAS1068E";
1365 ioc->bus_type = SAS;
1367 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
1368 ioc->prod_name = "LSISAS1078";
1369 ioc->bus_type = SAS;
1372 if (ioc->errata_flag_1064)
1373 pci_disable_io_access(pdev);
1375 sprintf(ioc->name, "ioc%d", ioc->id);
1377 spin_lock_init(&ioc->FreeQlock);
1380 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1382 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1384 /* Set lookup ptr. */
1385 list_add_tail(&ioc->list, &ioc_list);
1387 /* Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
1389 mpt_detect_bound_ports(ioc, pdev);
1391 if ((r = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
1393 printk(KERN_WARNING MYNAM
1394 ": WARNING - %s did not initialize properly! (%d)\n",
1397 list_del(&ioc->list);
1399 ioc->alt_ioc->alt_ioc = NULL;
1402 pci_set_drvdata(pdev, NULL);
1406 /* call per device driver probe entry point */
1407 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1408 if(MptDeviceDriverHandlers[ii] &&
1409 MptDeviceDriverHandlers[ii]->probe) {
1410 MptDeviceDriverHandlers[ii]->probe(pdev,id);
1414 #ifdef CONFIG_PROC_FS
1416 * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
1418 dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
1420 ent = create_proc_entry("info", S_IFREG|S_IRUGO, dent);
1422 ent->read_proc = procmpt_iocinfo_read;
1425 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, dent);
1427 ent->read_proc = procmpt_summary_read;
1436 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1438 * mpt_detach - Remove a PCI intelligent MPT adapter.
1439 * @pdev: Pointer to pci_dev structure
1443 mpt_detach(struct pci_dev *pdev)
1445 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1449 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
1450 remove_proc_entry(pname, NULL);
1451 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/info", ioc->name);
1452 remove_proc_entry(pname, NULL);
1453 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
1454 remove_proc_entry(pname, NULL);
1456 /* call per device driver remove entry point */
1457 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1458 if(MptDeviceDriverHandlers[ii] &&
1459 MptDeviceDriverHandlers[ii]->remove) {
1460 MptDeviceDriverHandlers[ii]->remove(pdev);
1464 /* Disable interrupts! */
1465 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1468 synchronize_irq(pdev->irq);
1470 /* Clear any lingering interrupt */
1471 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1473 CHIPREG_READ32(&ioc->chip->IntStatus);
1475 mpt_adapter_dispose(ioc);
1477 pci_set_drvdata(pdev, NULL);
1480 /**************************************************************************
1484 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1486 * mpt_suspend - Fusion MPT base driver suspend routine.
1487 * @pdev: Pointer to pci_dev structure
1488 * @state: new state to enter
1491 mpt_suspend(struct pci_dev *pdev, pm_message_t state)
1494 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1496 device_state=pci_choose_state(pdev, state);
1498 printk(MYIOC_s_INFO_FMT
1499 "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n",
1500 ioc->name, pdev, pci_name(pdev), device_state);
1502 pci_save_state(pdev);
1504 /* put ioc into READY_STATE */
1505 if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
1506 printk(MYIOC_s_ERR_FMT
1507 "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
1510 /* disable interrupts */
1511 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1514 /* Clear any lingering interrupt */
1515 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1517 pci_disable_device(pdev);
1518 pci_set_power_state(pdev, device_state);
1523 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1525 * mpt_resume - Fusion MPT base driver resume routine.
1526 * @pdev: Pointer to pci_dev structure
1529 mpt_resume(struct pci_dev *pdev)
1531 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1532 u32 device_state = pdev->current_state;
1536 printk(MYIOC_s_INFO_FMT
1537 "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n",
1538 ioc->name, pdev, pci_name(pdev), device_state);
1540 pci_set_power_state(pdev, 0);
1541 pci_restore_state(pdev);
1542 err = pci_enable_device(pdev);
1546 /* enable interrupts */
1547 CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
1550 printk(MYIOC_s_INFO_FMT
1551 "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
1553 (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
1554 CHIPREG_READ32(&ioc->chip->Doorbell));
1556 /* bring ioc to operational state */
1557 if ((recovery_state = mpt_do_ioc_recovery(ioc,
1558 MPT_HOSTEVENT_IOC_RECOVER, CAN_SLEEP)) != 0) {
1559 printk(MYIOC_s_INFO_FMT
1560 "pci-resume: Cannot recover, error:[%x]\n",
1561 ioc->name, recovery_state);
1563 printk(MYIOC_s_INFO_FMT
1564 "pci-resume: success\n", ioc->name);
1572 mpt_signal_reset(int index, MPT_ADAPTER *ioc, int reset_phase)
1574 if ((MptDriverClass[index] == MPTSPI_DRIVER &&
1575 ioc->bus_type != SPI) ||
1576 (MptDriverClass[index] == MPTFC_DRIVER &&
1577 ioc->bus_type != FC) ||
1578 (MptDriverClass[index] == MPTSAS_DRIVER &&
1579 ioc->bus_type != SAS))
1580 /* make sure we only call the relevant reset handler
1583 return (MptResetHandlers[index])(ioc, reset_phase);
1586 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1588 * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
1589 * @ioc: Pointer to MPT adapter structure
1590 * @reason: Event word / reason
1591 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
1593 * This routine performs all the steps necessary to bring the IOC
1594 * to a OPERATIONAL state.
1596 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1601 * -1 if failed to get board READY
1602 * -2 if READY but IOCFacts Failed
1603 * -3 if READY but PrimeIOCFifos Failed
1604 * -4 if READY but IOCInit Failed
1607 mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1609 int hard_reset_done = 0;
1610 int alt_ioc_ready = 0;
1616 int reset_alt_ioc_active = 0;
1617 int irq_allocated = 0;
1619 printk(KERN_INFO MYNAM ": Initiating %s %s\n",
1620 ioc->name, reason==MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
1622 /* Disable reply interrupts (also blocks FreeQ) */
1623 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1627 if (ioc->alt_ioc->active)
1628 reset_alt_ioc_active = 1;
1630 /* Disable alt-IOC's reply interrupts (and FreeQ) for a bit ... */
1631 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, 0xFFFFFFFF);
1632 ioc->alt_ioc->active = 0;
1636 if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
1639 if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
1640 if (hard_reset_done == -4) {
1641 printk(KERN_WARNING MYNAM ": %s Owned by PEER..skipping!\n",
1644 if (reset_alt_ioc_active && ioc->alt_ioc) {
1645 /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
1646 dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
1647 ioc->alt_ioc->name));
1648 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
1649 ioc->alt_ioc->active = 1;
1653 printk(KERN_WARNING MYNAM ": %s NOT READY WARNING!\n",
1659 /* hard_reset_done = 0 if a soft reset was performed
1660 * and 1 if a hard reset was performed.
1662 if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
1663 if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
1666 printk(KERN_WARNING MYNAM
1667 ": alt-%s: Not ready WARNING!\n",
1668 ioc->alt_ioc->name);
1671 for (ii=0; ii<5; ii++) {
1672 /* Get IOC facts! Allow 5 retries */
1673 if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
1679 dinitprintk((MYIOC_s_INFO_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc));
1681 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1682 MptDisplayIocCapabilities(ioc);
1685 if (alt_ioc_ready) {
1686 if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
1687 dinitprintk((MYIOC_s_INFO_FMT "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc));
1688 /* Retry - alt IOC was initialized once
1690 rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
1693 dinitprintk((MYIOC_s_INFO_FMT "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
1695 reset_alt_ioc_active = 0;
1696 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1697 MptDisplayIocCapabilities(ioc->alt_ioc);
1702 * Device is reset now. It must have de-asserted the interrupt line
1703 * (if it was asserted) and it should be safe to register for the
1706 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
1708 if (ioc->pcidev->irq) {
1709 if (mpt_msi_enable && !pci_enable_msi(ioc->pcidev))
1710 printk(MYIOC_s_INFO_FMT "PCI-MSI enabled\n",
1712 rc = request_irq(ioc->pcidev->irq, mpt_interrupt,
1713 IRQF_SHARED, ioc->name, ioc);
1715 printk(MYIOC_s_ERR_FMT "Unable to allocate "
1716 "interrupt %d!\n", ioc->name,
1719 pci_disable_msi(ioc->pcidev);
1723 ioc->pci_irq = ioc->pcidev->irq;
1724 pci_set_master(ioc->pcidev); /* ?? */
1725 pci_set_drvdata(ioc->pcidev, ioc);
1726 dprintk((KERN_INFO MYNAM ": %s installed at interrupt "
1727 "%d\n", ioc->name, ioc->pcidev->irq));
1731 /* Prime reply & request queues!
1732 * (mucho alloc's) Must be done prior to
1733 * init as upper addresses are needed for init.
1734 * If fails, continue with alt-ioc processing
1736 if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
1739 /* May need to check/upload firmware & data here!
1740 * If fails, continue with alt-ioc processing
1742 if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
1745 if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
1746 printk(KERN_WARNING MYNAM ": alt-%s: (%d) FIFO mgmt alloc WARNING!\n",
1747 ioc->alt_ioc->name, rc);
1749 reset_alt_ioc_active = 0;
1752 if (alt_ioc_ready) {
1753 if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
1755 reset_alt_ioc_active = 0;
1756 printk(KERN_WARNING MYNAM
1757 ": alt-%s: (%d) init failure WARNING!\n",
1758 ioc->alt_ioc->name, rc);
1762 if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
1763 if (ioc->upload_fw) {
1764 ddlprintk((MYIOC_s_INFO_FMT
1765 "firmware upload required!\n", ioc->name));
1767 /* Controller is not operational, cannot do upload
1770 rc = mpt_do_upload(ioc, sleepFlag);
1772 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
1774 * Maintain only one pointer to FW memory
1775 * so there will not be two attempt to
1776 * downloadboot onboard dual function
1777 * chips (mpt_adapter_disable,
1780 ddlprintk((MYIOC_s_INFO_FMT ": mpt_upload: alt_%s has cached_fw=%p \n",
1781 ioc->name, ioc->alt_ioc->name, ioc->alt_ioc->cached_fw));
1782 ioc->alt_ioc->cached_fw = NULL;
1785 printk(KERN_WARNING MYNAM ": firmware upload failure!\n");
1793 /* Enable! (reply interrupt) */
1794 CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
1798 if (reset_alt_ioc_active && ioc->alt_ioc) {
1799 /* (re)Enable alt-IOC! (reply interrupt) */
1800 dinitprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
1801 ioc->alt_ioc->name));
1802 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
1803 ioc->alt_ioc->active = 1;
1806 /* Enable MPT base driver management of EventNotification
1807 * and EventAck handling.
1809 if ((ret == 0) && (!ioc->facts.EventState))
1810 (void) SendEventNotification(ioc, 1); /* 1=Enable EventNotification */
1812 if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
1813 (void) SendEventNotification(ioc->alt_ioc, 1); /* 1=Enable EventNotification */
1815 /* Add additional "reason" check before call to GetLanConfigPages
1816 * (combined with GetIoUnitPage2 call). This prevents a somewhat
1817 * recursive scenario; GetLanConfigPages times out, timer expired
1818 * routine calls HardResetHandler, which calls into here again,
1819 * and we try GetLanConfigPages again...
1821 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
1824 * Initalize link list for inactive raid volumes.
1826 init_MUTEX(&ioc->raid_data.inactive_list_mutex);
1827 INIT_LIST_HEAD(&ioc->raid_data.inactive_list);
1829 if (ioc->bus_type == SAS) {
1831 /* clear persistency table */
1832 if(ioc->facts.IOCExceptions &
1833 MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL) {
1834 ret = mptbase_sas_persist_operation(ioc,
1835 MPI_SAS_OP_CLEAR_NOT_PRESENT);
1842 mpt_findImVolumes(ioc);
1844 } else if (ioc->bus_type == FC) {
1845 if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
1846 (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
1848 * Pre-fetch the ports LAN MAC address!
1849 * (LANPage1_t stuff)
1851 (void) GetLanConfigPages(ioc);
1854 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
1855 dprintk((MYIOC_s_INFO_FMT "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1856 ioc->name, a[5], a[4], a[3], a[2], a[1], a[0] ));
1861 /* Get NVRAM and adapter maximums from SPP 0 and 2
1863 mpt_GetScsiPortSettings(ioc, 0);
1865 /* Get version and length of SDP 1
1867 mpt_readScsiDevicePageHeaders(ioc, 0);
1871 if (ioc->facts.MsgVersion >= MPI_VERSION_01_02)
1872 mpt_findImVolumes(ioc);
1874 /* Check, and possibly reset, the coalescing value
1876 mpt_read_ioc_pg_1(ioc);
1878 mpt_read_ioc_pg_4(ioc);
1881 GetIoUnitPage2(ioc);
1885 * Call each currently registered protocol IOC reset handler
1886 * with post-reset indication.
1887 * NOTE: If we're doing _IOC_BRINGUP, there can be no
1888 * MptResetHandlers[] registered yet.
1890 if (hard_reset_done) {
1892 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
1893 if ((ret == 0) && MptResetHandlers[ii]) {
1894 dprintk((MYIOC_s_INFO_FMT "Calling IOC post_reset handler #%d\n",
1896 rc += mpt_signal_reset(ii, ioc, MPT_IOC_POST_RESET);
1900 if (alt_ioc_ready && MptResetHandlers[ii]) {
1901 drsprintk((MYIOC_s_INFO_FMT "Calling alt-%s post_reset handler #%d\n",
1902 ioc->name, ioc->alt_ioc->name, ii));
1903 rc += mpt_signal_reset(ii, ioc->alt_ioc, MPT_IOC_POST_RESET);
1907 /* FIXME? Examine results here? */
1911 if ((ret != 0) && irq_allocated) {
1912 free_irq(ioc->pci_irq, ioc);
1914 pci_disable_msi(ioc->pcidev);
1919 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1921 * mpt_detect_bound_ports - Search for matching PCI bus/dev_function
1922 * @ioc: Pointer to MPT adapter structure
1923 * @pdev: Pointer to (struct pci_dev) structure
1925 * Search for PCI bus/dev_function which matches
1926 * PCI bus/dev_function (+/-1) for newly discovered 929,
1927 * 929X, 1030 or 1035.
1929 * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
1930 * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
1933 mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
1935 struct pci_dev *peer=NULL;
1936 unsigned int slot = PCI_SLOT(pdev->devfn);
1937 unsigned int func = PCI_FUNC(pdev->devfn);
1938 MPT_ADAPTER *ioc_srch;
1940 dprintk((MYIOC_s_INFO_FMT "PCI device %s devfn=%x/%x,"
1941 " searching for devfn match on %x or %x\n",
1942 ioc->name, pci_name(pdev), pdev->bus->number,
1943 pdev->devfn, func-1, func+1));
1945 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
1947 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func+1));
1952 list_for_each_entry(ioc_srch, &ioc_list, list) {
1953 struct pci_dev *_pcidev = ioc_srch->pcidev;
1954 if (_pcidev == peer) {
1955 /* Paranoia checks */
1956 if (ioc->alt_ioc != NULL) {
1957 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
1958 ioc->name, ioc->alt_ioc->name);
1960 } else if (ioc_srch->alt_ioc != NULL) {
1961 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
1962 ioc_srch->name, ioc_srch->alt_ioc->name);
1965 dprintk((KERN_INFO MYNAM ": FOUND! binding %s <==> %s\n",
1966 ioc->name, ioc_srch->name));
1967 ioc_srch->alt_ioc = ioc;
1968 ioc->alt_ioc = ioc_srch;
1974 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1976 * mpt_adapter_disable - Disable misbehaving MPT adapter.
1977 * @ioc: Pointer to MPT adapter structure
1980 mpt_adapter_disable(MPT_ADAPTER *ioc)
1985 if (ioc->cached_fw != NULL) {
1986 ddlprintk((KERN_INFO MYNAM ": mpt_adapter_disable: Pushing FW onto adapter\n"));
1987 if ((ret = mpt_downloadboot(ioc, (MpiFwHeader_t *)ioc->cached_fw, NO_SLEEP)) < 0) {
1988 printk(KERN_WARNING MYNAM
1989 ": firmware downloadboot failure (%d)!\n", ret);
1993 /* Disable adapter interrupts! */
1994 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1996 /* Clear any lingering interrupt */
1997 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1999 if (ioc->alloc != NULL) {
2001 dexitprintk((KERN_INFO MYNAM ": %s.free @ %p, sz=%d bytes\n",
2002 ioc->name, ioc->alloc, ioc->alloc_sz));
2003 pci_free_consistent(ioc->pcidev, sz,
2004 ioc->alloc, ioc->alloc_dma);
2005 ioc->reply_frames = NULL;
2006 ioc->req_frames = NULL;
2008 ioc->alloc_total -= sz;
2011 if (ioc->sense_buf_pool != NULL) {
2012 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
2013 pci_free_consistent(ioc->pcidev, sz,
2014 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
2015 ioc->sense_buf_pool = NULL;
2016 ioc->alloc_total -= sz;
2019 if (ioc->events != NULL){
2020 sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
2023 ioc->alloc_total -= sz;
2026 if (ioc->cached_fw != NULL) {
2027 sz = ioc->facts.FWImageSize;
2028 pci_free_consistent(ioc->pcidev, sz,
2029 ioc->cached_fw, ioc->cached_fw_dma);
2030 ioc->cached_fw = NULL;
2031 ioc->alloc_total -= sz;
2034 kfree(ioc->spi_data.nvram);
2035 mpt_inactive_raid_list_free(ioc);
2036 kfree(ioc->raid_data.pIocPg2);
2037 kfree(ioc->raid_data.pIocPg3);
2038 ioc->spi_data.nvram = NULL;
2039 ioc->raid_data.pIocPg3 = NULL;
2041 if (ioc->spi_data.pIocPg4 != NULL) {
2042 sz = ioc->spi_data.IocPg4Sz;
2043 pci_free_consistent(ioc->pcidev, sz,
2044 ioc->spi_data.pIocPg4,
2045 ioc->spi_data.IocPg4_dma);
2046 ioc->spi_data.pIocPg4 = NULL;
2047 ioc->alloc_total -= sz;
2050 if (ioc->ReqToChain != NULL) {
2051 kfree(ioc->ReqToChain);
2052 kfree(ioc->RequestNB);
2053 ioc->ReqToChain = NULL;
2056 kfree(ioc->ChainToChain);
2057 ioc->ChainToChain = NULL;
2059 if (ioc->HostPageBuffer != NULL) {
2060 if((ret = mpt_host_page_access_control(ioc,
2061 MPI_DB_HPBAC_FREE_BUFFER, NO_SLEEP)) != 0) {
2062 printk(KERN_ERR MYNAM
2063 ": %s: host page buffers free failed (%d)!\n",
2066 dexitprintk((KERN_INFO MYNAM ": %s HostPageBuffer free @ %p, sz=%d bytes\n",
2067 ioc->name, ioc->HostPageBuffer, ioc->HostPageBuffer_sz));
2068 pci_free_consistent(ioc->pcidev, ioc->HostPageBuffer_sz,
2069 ioc->HostPageBuffer,
2070 ioc->HostPageBuffer_dma);
2071 ioc->HostPageBuffer = NULL;
2072 ioc->HostPageBuffer_sz = 0;
2073 ioc->alloc_total -= ioc->HostPageBuffer_sz;
2077 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2079 * mpt_adapter_dispose - Free all resources associated with an MPT adapter
2080 * @ioc: Pointer to MPT adapter structure
2082 * This routine unregisters h/w resources and frees all alloc'd memory
2083 * associated with a MPT adapter structure.
2086 mpt_adapter_dispose(MPT_ADAPTER *ioc)
2088 int sz_first, sz_last;
2093 sz_first = ioc->alloc_total;
2095 mpt_adapter_disable(ioc);
2097 if (ioc->pci_irq != -1) {
2098 free_irq(ioc->pci_irq, ioc);
2100 pci_disable_msi(ioc->pcidev);
2104 if (ioc->memmap != NULL) {
2105 iounmap(ioc->memmap);
2109 #if defined(CONFIG_MTRR) && 0
2110 if (ioc->mtrr_reg > 0) {
2111 mtrr_del(ioc->mtrr_reg, 0, 0);
2112 dprintk((KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
2116 /* Zap the adapter lookup ptr! */
2117 list_del(&ioc->list);
2119 sz_last = ioc->alloc_total;
2120 dprintk((KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
2121 ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
2124 ioc->alt_ioc->alt_ioc = NULL;
2129 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2131 * MptDisplayIocCapabilities - Disply IOC's capabilities.
2132 * @ioc: Pointer to MPT adapter structure
2135 MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
2139 printk(KERN_INFO "%s: ", ioc->name);
2140 if (ioc->prod_name && strlen(ioc->prod_name) > 3)
2141 printk("%s: ", ioc->prod_name+3);
2142 printk("Capabilities={");
2144 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
2145 printk("Initiator");
2149 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2150 printk("%sTarget", i ? "," : "");
2154 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
2155 printk("%sLAN", i ? "," : "");
2161 * This would probably evoke more questions than it's worth
2163 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2164 printk("%sLogBusAddr", i ? "," : "");
2172 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2174 * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
2175 * @ioc: Pointer to MPT_ADAPTER structure
2176 * @force: Force hard KickStart of IOC
2177 * @sleepFlag: Specifies whether the process can sleep
2180 * 1 - DIAG reset and READY
2181 * 0 - READY initially OR soft reset and READY
2182 * -1 - Any failure on KickStart
2183 * -2 - Msg Unit Reset Failed
2184 * -3 - IO Unit Reset Failed
2185 * -4 - IOC owned by a PEER
2188 MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
2193 int hard_reset_done = 0;
2198 /* Get current [raw] IOC state */
2199 ioc_state = mpt_GetIocState(ioc, 0);
2200 dhsprintk((KERN_INFO MYNAM "::MakeIocReady, %s [raw] state=%08x\n", ioc->name, ioc_state));
2203 * Check to see if IOC got left/stuck in doorbell handshake
2204 * grip of death. If so, hard reset the IOC.
2206 if (ioc_state & MPI_DOORBELL_ACTIVE) {
2208 printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
2212 /* Is it already READY? */
2213 if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
2217 * Check to see if IOC is in FAULT state.
2219 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
2221 printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
2223 printk(KERN_WARNING " FAULT code = %04xh\n",
2224 ioc_state & MPI_DOORBELL_DATA_MASK);
2228 * Hmmm... Did it get left operational?
2230 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
2231 dinitprintk((MYIOC_s_INFO_FMT "IOC operational unexpected\n",
2235 * If PCI Peer, exit.
2236 * Else, if no fault conditions are present, issue a MessageUnitReset
2237 * Else, fall through to KickStart case
2239 whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
2240 dinitprintk((KERN_INFO MYNAM
2241 ": whoinit 0x%x statefault %d force %d\n",
2242 whoinit, statefault, force));
2243 if (whoinit == MPI_WHOINIT_PCI_PEER)
2246 if ((statefault == 0 ) && (force == 0)) {
2247 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
2254 hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
2255 if (hard_reset_done < 0)
2259 * Loop here waiting for IOC to come READY.
2262 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 5; /* 5 seconds */
2264 while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
2265 if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
2267 * BIOS or previous driver load left IOC in OP state.
2268 * Reset messaging FIFOs.
2270 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
2271 printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
2274 } else if (ioc_state == MPI_IOC_STATE_RESET) {
2276 * Something is wrong. Try to get IOC back
2279 if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
2280 printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
2287 printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
2288 ioc->name, (int)((ii+5)/HZ));
2292 if (sleepFlag == CAN_SLEEP) {
2295 mdelay (1); /* 1 msec delay */
2300 if (statefault < 3) {
2301 printk(MYIOC_s_INFO_FMT "Recovered from %s\n",
2303 statefault==1 ? "stuck handshake" : "IOC FAULT");
2306 return hard_reset_done;
2309 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2311 * mpt_GetIocState - Get the current state of a MPT adapter.
2312 * @ioc: Pointer to MPT_ADAPTER structure
2313 * @cooked: Request raw or cooked IOC state
2315 * Returns all IOC Doorbell register bits if cooked==0, else just the
2316 * Doorbell bits in MPI_IOC_STATE_MASK.
2319 mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
2324 s = CHIPREG_READ32(&ioc->chip->Doorbell);
2325 // dprintk((MYIOC_s_INFO_FMT "raw state = %08x\n", ioc->name, s));
2326 sc = s & MPI_IOC_STATE_MASK;
2329 ioc->last_state = sc;
2331 return cooked ? sc : s;
2334 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2336 * GetIocFacts - Send IOCFacts request to MPT adapter.
2337 * @ioc: Pointer to MPT_ADAPTER structure
2338 * @sleepFlag: Specifies whether the process can sleep
2339 * @reason: If recovery, only update facts.
2341 * Returns 0 for success, non-zero for failure.
2344 GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2346 IOCFacts_t get_facts;
2347 IOCFactsReply_t *facts;
2355 /* IOC *must* NOT be in RESET state! */
2356 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2357 printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
2363 facts = &ioc->facts;
2365 /* Destination (reply area)... */
2366 reply_sz = sizeof(*facts);
2367 memset(facts, 0, reply_sz);
2369 /* Request area (get_facts on the stack right now!) */
2370 req_sz = sizeof(get_facts);
2371 memset(&get_facts, 0, req_sz);
2373 get_facts.Function = MPI_FUNCTION_IOC_FACTS;
2374 /* Assert: All other get_facts fields are zero! */
2376 dinitprintk((MYIOC_s_INFO_FMT
2377 "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
2378 ioc->name, req_sz, reply_sz));
2380 /* No non-zero fields in the get_facts request are greater than
2381 * 1 byte in size, so we can just fire it off as is.
2383 r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
2384 reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
2389 * Now byte swap (GRRR) the necessary fields before any further
2390 * inspection of reply contents.
2392 * But need to do some sanity checks on MsgLength (byte) field
2393 * to make sure we don't zero IOC's req_sz!
2395 /* Did we get a valid reply? */
2396 if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
2397 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2399 * If not been here, done that, save off first WhoInit value
2401 if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
2402 ioc->FirstWhoInit = facts->WhoInit;
2405 facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
2406 facts->MsgContext = le32_to_cpu(facts->MsgContext);
2407 facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
2408 facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
2409 facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
2410 status = le16_to_cpu(facts->IOCStatus) & MPI_IOCSTATUS_MASK;
2411 /* CHECKME! IOCStatus, IOCLogInfo */
2413 facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
2414 facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
2417 * FC f/w version changed between 1.1 and 1.2
2418 * Old: u16{Major(4),Minor(4),SubMinor(8)}
2419 * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
2421 if (facts->MsgVersion < 0x0102) {
2423 * Handle old FC f/w style, convert to new...
2425 u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
2426 facts->FWVersion.Word =
2427 ((oldv<<12) & 0xFF000000) |
2428 ((oldv<<8) & 0x000FFF00);
2430 facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
2432 facts->ProductID = le16_to_cpu(facts->ProductID);
2433 if ((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
2434 > MPI_FW_HEADER_PID_PROD_TARGET_SCSI)
2435 ioc->ir_firmware = 1;
2436 facts->CurrentHostMfaHighAddr =
2437 le32_to_cpu(facts->CurrentHostMfaHighAddr);
2438 facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
2439 facts->CurrentSenseBufferHighAddr =
2440 le32_to_cpu(facts->CurrentSenseBufferHighAddr);
2441 facts->CurReplyFrameSize =
2442 le16_to_cpu(facts->CurReplyFrameSize);
2443 facts->IOCCapabilities = le32_to_cpu(facts->IOCCapabilities);
2446 * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
2447 * Older MPI-1.00.xx struct had 13 dwords, and enlarged
2448 * to 14 in MPI-1.01.0x.
2450 if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
2451 facts->MsgVersion > 0x0100) {
2452 facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
2455 sz = facts->FWImageSize;
2460 facts->FWImageSize = sz;
2462 if (!facts->RequestFrameSize) {
2463 /* Something is wrong! */
2464 printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
2469 r = sz = facts->BlockSize;
2470 vv = ((63 / (sz * 4)) + 1) & 0x03;
2471 ioc->NB_for_64_byte_frame = vv;
2477 ioc->NBShiftFactor = shiftFactor;
2478 dinitprintk((MYIOC_s_INFO_FMT "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
2479 ioc->name, vv, shiftFactor, r));
2481 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2483 * Set values for this IOC's request & reply frame sizes,
2484 * and request & reply queue depths...
2486 ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
2487 ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
2488 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
2489 ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
2491 dinitprintk((MYIOC_s_INFO_FMT "reply_sz=%3d, reply_depth=%4d\n",
2492 ioc->name, ioc->reply_sz, ioc->reply_depth));
2493 dinitprintk((MYIOC_s_INFO_FMT "req_sz =%3d, req_depth =%4d\n",
2494 ioc->name, ioc->req_sz, ioc->req_depth));
2496 /* Get port facts! */
2497 if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
2501 printk(MYIOC_s_ERR_FMT
2502 "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
2503 ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
2504 RequestFrameSize)/sizeof(u32)));
2511 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2513 * GetPortFacts - Send PortFacts request to MPT adapter.
2514 * @ioc: Pointer to MPT_ADAPTER structure
2515 * @portnum: Port number
2516 * @sleepFlag: Specifies whether the process can sleep
2518 * Returns 0 for success, non-zero for failure.
2521 GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2523 PortFacts_t get_pfacts;
2524 PortFactsReply_t *pfacts;
2530 /* IOC *must* NOT be in RESET state! */
2531 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2532 printk(KERN_ERR MYNAM ": ERROR - Can't get PortFacts, %s NOT READY! (%08x)\n",
2538 pfacts = &ioc->pfacts[portnum];
2540 /* Destination (reply area)... */
2541 reply_sz = sizeof(*pfacts);
2542 memset(pfacts, 0, reply_sz);
2544 /* Request area (get_pfacts on the stack right now!) */
2545 req_sz = sizeof(get_pfacts);
2546 memset(&get_pfacts, 0, req_sz);
2548 get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
2549 get_pfacts.PortNumber = portnum;
2550 /* Assert: All other get_pfacts fields are zero! */
2552 dinitprintk((MYIOC_s_INFO_FMT "Sending get PortFacts(%d) request\n",
2553 ioc->name, portnum));
2555 /* No non-zero fields in the get_pfacts request are greater than
2556 * 1 byte in size, so we can just fire it off as is.
2558 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
2559 reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
2563 /* Did we get a valid reply? */
2565 /* Now byte swap the necessary fields in the response. */
2566 pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
2567 pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
2568 pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
2569 pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
2570 pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
2571 pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
2572 pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
2573 pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
2574 pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
2576 max_id = (ioc->bus_type == SAS) ? pfacts->PortSCSIID :
2578 ioc->devices_per_bus = (max_id > 255) ? 256 : max_id;
2579 ioc->number_of_buses = (ioc->devices_per_bus < 256) ? 1 : max_id/256;
2582 * Place all the devices on channels
2586 if (mpt_channel_mapping) {
2587 ioc->devices_per_bus = 1;
2588 ioc->number_of_buses = (max_id > 255) ? 255 : max_id;
2594 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2596 * SendIocInit - Send IOCInit request to MPT adapter.
2597 * @ioc: Pointer to MPT_ADAPTER structure
2598 * @sleepFlag: Specifies whether the process can sleep
2600 * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
2602 * Returns 0 for success, non-zero for failure.
2605 SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
2608 MPIDefaultReply_t init_reply;
2614 memset(&ioc_init, 0, sizeof(ioc_init));
2615 memset(&init_reply, 0, sizeof(init_reply));
2617 ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
2618 ioc_init.Function = MPI_FUNCTION_IOC_INIT;
2620 /* If we are in a recovery mode and we uploaded the FW image,
2621 * then this pointer is not NULL. Skip the upload a second time.
2622 * Set this flag if cached_fw set for either IOC.
2624 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
2628 ddlprintk((MYIOC_s_INFO_FMT "upload_fw %d facts.Flags=%x\n",
2629 ioc->name, ioc->upload_fw, ioc->facts.Flags));
2631 ioc_init.MaxDevices = (U8)ioc->devices_per_bus;
2632 ioc_init.MaxBuses = (U8)ioc->number_of_buses;
2633 dinitprintk((MYIOC_s_INFO_FMT "facts.MsgVersion=%x\n",
2634 ioc->name, ioc->facts.MsgVersion));
2635 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05) {
2636 // set MsgVersion and HeaderVersion host driver was built with
2637 ioc_init.MsgVersion = cpu_to_le16(MPI_VERSION);
2638 ioc_init.HeaderVersion = cpu_to_le16(MPI_HEADER_VERSION);
2640 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_HOST_PAGE_BUFFER_PERSISTENT) {
2641 ioc_init.HostPageBufferSGE = ioc->facts.HostPageBufferSGE;
2642 } else if(mpt_host_page_alloc(ioc, &ioc_init))
2645 ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
2647 if (sizeof(dma_addr_t) == sizeof(u64)) {
2648 /* Save the upper 32-bits of the request
2649 * (reply) and sense buffers.
2651 ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
2652 ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2654 /* Force 32-bit addressing */
2655 ioc_init.HostMfaHighAddr = cpu_to_le32(0);
2656 ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
2659 ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
2660 ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
2661 ioc->facts.MaxDevices = ioc_init.MaxDevices;
2662 ioc->facts.MaxBuses = ioc_init.MaxBuses;
2664 dhsprintk((MYIOC_s_INFO_FMT "Sending IOCInit (req @ %p)\n",
2665 ioc->name, &ioc_init));
2667 r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
2668 sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
2670 printk(MYIOC_s_ERR_FMT "Sending IOCInit failed(%d)!\n",ioc->name, r);
2674 /* No need to byte swap the multibyte fields in the reply
2675 * since we don't even look at its contents.
2678 dhsprintk((MYIOC_s_INFO_FMT "Sending PortEnable (req @ %p)\n",
2679 ioc->name, &ioc_init));
2681 if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0) {
2682 printk(MYIOC_s_ERR_FMT "Sending PortEnable failed(%d)!\n",ioc->name, r);
2686 /* YIKES! SUPER IMPORTANT!!!
2687 * Poll IocState until _OPERATIONAL while IOC is doing
2688 * LoopInit and TargetDiscovery!
2691 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
2692 state = mpt_GetIocState(ioc, 1);
2693 while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
2694 if (sleepFlag == CAN_SLEEP) {
2701 printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
2702 ioc->name, (int)((count+5)/HZ));
2706 state = mpt_GetIocState(ioc, 1);
2709 dinitprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
2712 ioc->aen_event_read_flag=0;
2716 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2718 * SendPortEnable - Send PortEnable request to MPT adapter port.
2719 * @ioc: Pointer to MPT_ADAPTER structure
2720 * @portnum: Port number to enable
2721 * @sleepFlag: Specifies whether the process can sleep
2723 * Send PortEnable to bring IOC to OPERATIONAL state.
2725 * Returns 0 for success, non-zero for failure.
2728 SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2730 PortEnable_t port_enable;
2731 MPIDefaultReply_t reply_buf;
2736 /* Destination... */
2737 reply_sz = sizeof(MPIDefaultReply_t);
2738 memset(&reply_buf, 0, reply_sz);
2740 req_sz = sizeof(PortEnable_t);
2741 memset(&port_enable, 0, req_sz);
2743 port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
2744 port_enable.PortNumber = portnum;
2745 /* port_enable.ChainOffset = 0; */
2746 /* port_enable.MsgFlags = 0; */
2747 /* port_enable.MsgContext = 0; */
2749 dinitprintk((MYIOC_s_INFO_FMT "Sending Port(%d)Enable (req @ %p)\n",
2750 ioc->name, portnum, &port_enable));
2752 /* RAID FW may take a long time to enable
2754 if (ioc->ir_firmware || ioc->bus_type == SAS) {
2755 rc = mpt_handshake_req_reply_wait(ioc, req_sz,
2756 (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
2757 300 /*seconds*/, sleepFlag);
2759 rc = mpt_handshake_req_reply_wait(ioc, req_sz,
2760 (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
2761 30 /*seconds*/, sleepFlag);
2767 * mpt_alloc_fw_memory - allocate firmware memory
2768 * @ioc: Pointer to MPT_ADAPTER structure
2769 * @size: total FW bytes
2771 * If memory has already been allocated, the same (cached) value
2775 mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
2778 return; /* use already allocated memory */
2779 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
2780 ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
2781 ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
2782 ioc->alloc_total += size;
2783 ioc->alt_ioc->alloc_total -= size;
2785 if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
2786 ioc->alloc_total += size;
2790 * mpt_free_fw_memory - free firmware memory
2791 * @ioc: Pointer to MPT_ADAPTER structure
2793 * If alt_img is NULL, delete from ioc structure.
2794 * Else, delete a secondary image in same format.
2797 mpt_free_fw_memory(MPT_ADAPTER *ioc)
2801 sz = ioc->facts.FWImageSize;
2802 dinitprintk((KERN_INFO MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
2803 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2804 pci_free_consistent(ioc->pcidev, sz,
2805 ioc->cached_fw, ioc->cached_fw_dma);
2806 ioc->cached_fw = NULL;
2812 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2814 * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
2815 * @ioc: Pointer to MPT_ADAPTER structure
2816 * @sleepFlag: Specifies whether the process can sleep
2818 * Returns 0 for success, >0 for handshake failure
2819 * <0 for fw upload failure.
2821 * Remark: If bound IOC and a successful FWUpload was performed
2822 * on the bound IOC, the second image is discarded
2823 * and memory is free'd. Both channels must upload to prevent
2824 * IOC from running in degraded mode.
2827 mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
2829 u8 request[ioc->req_sz];
2830 u8 reply[sizeof(FWUploadReply_t)];
2831 FWUpload_t *prequest;
2832 FWUploadReply_t *preply;
2833 FWUploadTCSGE_t *ptcsge;
2836 int ii, sz, reply_sz;
2839 /* If the image size is 0, we are done.
2841 if ((sz = ioc->facts.FWImageSize) == 0)
2844 mpt_alloc_fw_memory(ioc, sz);
2846 dinitprintk((KERN_INFO MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
2847 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2849 if (ioc->cached_fw == NULL) {
2855 prequest = (FWUpload_t *)&request;
2856 preply = (FWUploadReply_t *)&reply;
2858 /* Destination... */
2859 memset(prequest, 0, ioc->req_sz);
2861 reply_sz = sizeof(reply);
2862 memset(preply, 0, reply_sz);
2864 prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
2865 prequest->Function = MPI_FUNCTION_FW_UPLOAD;
2867 ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
2868 ptcsge->DetailsLength = 12;
2869 ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
2870 ptcsge->ImageSize = cpu_to_le32(sz);
2872 sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
2874 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
2875 mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
2877 sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
2878 dinitprintk((KERN_INFO MYNAM ": Sending FW Upload (req @ %p) sgeoffset=%d \n",
2879 prequest, sgeoffset));
2880 DBG_DUMP_FW_REQUEST_FRAME(prequest)
2882 ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
2883 reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
2885 dinitprintk((KERN_INFO MYNAM ": FW Upload completed rc=%x \n", ii));
2887 cmdStatus = -EFAULT;
2889 /* Handshake transfer was complete and successful.
2890 * Check the Reply Frame.
2892 int status, transfer_sz;
2893 status = le16_to_cpu(preply->IOCStatus);
2894 if (status == MPI_IOCSTATUS_SUCCESS) {
2895 transfer_sz = le32_to_cpu(preply->ActualImageSize);
2896 if (transfer_sz == sz)
2900 dinitprintk((MYIOC_s_INFO_FMT ": do_upload cmdStatus=%d \n",
2901 ioc->name, cmdStatus));
2906 ddlprintk((MYIOC_s_INFO_FMT ": fw upload failed, freeing image \n",
2908 mpt_free_fw_memory(ioc);
2914 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2916 * mpt_downloadboot - DownloadBoot code
2917 * @ioc: Pointer to MPT_ADAPTER structure
2918 * @pFwHeader: Pointer to firmware header info
2919 * @sleepFlag: Specifies whether the process can sleep
2921 * FwDownloadBoot requires Programmed IO access.
2923 * Returns 0 for success
2924 * -1 FW Image size is 0
2925 * -2 No valid cached_fw Pointer
2926 * <0 for fw upload failure.
2929 mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag)
2931 MpiExtImageHeader_t *pExtImage;
2941 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: fw size 0x%x (%d), FW Ptr %p\n",
2942 ioc->name, pFwHeader->ImageSize, pFwHeader->ImageSize, pFwHeader));
2944 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2945 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2946 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2947 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2948 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2949 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2951 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
2954 if (sleepFlag == CAN_SLEEP) {
2960 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2961 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
2963 for (count = 0; count < 30; count ++) {
2964 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2965 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
2966 ddlprintk((MYIOC_s_INFO_FMT "RESET_ADAPTER cleared, count=%d\n",
2971 if (sleepFlag == CAN_SLEEP) {
2978 if ( count == 30 ) {
2979 ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! "
2980 "Unable to get MPI_DIAG_DRWE mode, diag0val=%x\n",
2981 ioc->name, diag0val));
2985 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2986 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2987 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2988 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2989 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2990 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2992 /* Set the DiagRwEn and Disable ARM bits */
2993 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
2995 fwSize = (pFwHeader->ImageSize + 3)/4;
2996 ptrFw = (u32 *) pFwHeader;
2998 /* Write the LoadStartAddress to the DiagRw Address Register
2999 * using Programmed IO
3001 if (ioc->errata_flag_1064)
3002 pci_enable_io_access(ioc->pcidev);
3004 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
3005 ddlprintk((MYIOC_s_INFO_FMT "LoadStart addr written 0x%x \n",
3006 ioc->name, pFwHeader->LoadStartAddress));
3008 ddlprintk((MYIOC_s_INFO_FMT "Write FW Image: 0x%x bytes @ %p\n",
3009 ioc->name, fwSize*4, ptrFw));
3011 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
3014 nextImage = pFwHeader->NextImageHeaderOffset;
3016 pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
3018 load_addr = pExtImage->LoadStartAddress;
3020 fwSize = (pExtImage->ImageSize + 3) >> 2;
3021 ptrFw = (u32 *)pExtImage;
3023 ddlprintk((MYIOC_s_INFO_FMT "Write Ext Image: 0x%x (%d) bytes @ %p load_addr=%x\n",
3024 ioc->name, fwSize*4, fwSize*4, ptrFw, load_addr));
3025 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
3028 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
3030 nextImage = pExtImage->NextImageHeaderOffset;
3033 /* Write the IopResetVectorRegAddr */
3034 ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
3035 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
3037 /* Write the IopResetVectorValue */
3038 ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
3039 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
3041 /* Clear the internal flash bad bit - autoincrementing register,
3042 * so must do two writes.
3044 if (ioc->bus_type == SPI) {
3046 * 1030 and 1035 H/W errata, workaround to access
3047 * the ClearFlashBadSignatureBit
3049 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
3050 diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
3051 diagRwData |= 0x40000000;
3052 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
3053 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
3055 } else /* if((ioc->bus_type == SAS) || (ioc->bus_type == FC)) */ {
3056 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3057 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val |
3058 MPI_DIAG_CLEAR_FLASH_BAD_SIG);
3061 if (sleepFlag == CAN_SLEEP) {
3068 if (ioc->errata_flag_1064)
3069 pci_disable_io_access(ioc->pcidev);
3071 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3072 ddlprintk((MYIOC_s_INFO_FMT "downloadboot diag0val=%x, "
3073 "turning off PREVENT_IOC_BOOT, DISABLE_ARM, RW_ENABLE\n",
3074 ioc->name, diag0val));
3075 diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM | MPI_DIAG_RW_ENABLE);
3076 ddlprintk((MYIOC_s_INFO_FMT "downloadboot now diag0val=%x\n",
3077 ioc->name, diag0val));
3078 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
3080 /* Write 0xFF to reset the sequencer */
3081 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
3083 if (ioc->bus_type == SAS) {
3084 ioc_state = mpt_GetIocState(ioc, 0);
3085 if ( (GetIocFacts(ioc, sleepFlag,
3086 MPT_HOSTEVENT_IOC_BRINGUP)) != 0 ) {
3087 ddlprintk((MYIOC_s_INFO_FMT "GetIocFacts failed: IocState=%x\n",
3088 ioc->name, ioc_state));
3093 for (count=0; count<HZ*20; count++) {
3094 if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
3095 ddlprintk((MYIOC_s_INFO_FMT "downloadboot successful! (count=%d) IocState=%x\n",
3096 ioc->name, count, ioc_state));
3097 if (ioc->bus_type == SAS) {
3100 if ((SendIocInit(ioc, sleepFlag)) != 0) {
3101 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit failed\n",
3105 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit successful\n",
3109 if (sleepFlag == CAN_SLEEP) {
3115 ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! IocState=%x\n",
3116 ioc->name, ioc_state));
3120 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3122 * KickStart - Perform hard reset of MPT adapter.
3123 * @ioc: Pointer to MPT_ADAPTER structure
3124 * @force: Force hard reset
3125 * @sleepFlag: Specifies whether the process can sleep
3127 * This routine places MPT adapter in diagnostic mode via the
3128 * WriteSequence register, and then performs a hard reset of adapter
3129 * via the Diagnostic register.
3131 * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
3132 * or NO_SLEEP (interrupt thread, use mdelay)
3133 * force - 1 if doorbell active, board fault state
3134 * board operational, IOC_RECOVERY or
3135 * IOC_BRINGUP and there is an alt_ioc.
3139 * 1 - hard reset, READY
3140 * 0 - no reset due to History bit, READY
3141 * -1 - no reset due to History bit but not READY
3142 * OR reset but failed to come READY
3143 * -2 - no reset, could not enter DIAG mode
3144 * -3 - reset but bad FW bit
3147 KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
3149 int hard_reset_done = 0;
3153 dinitprintk((KERN_WARNING MYNAM ": KickStarting %s!\n", ioc->name));
3154 if (ioc->bus_type == SPI) {
3155 /* Always issue a Msg Unit Reset first. This will clear some
3156 * SCSI bus hang conditions.
3158 SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
3160 if (sleepFlag == CAN_SLEEP) {
3167 hard_reset_done = mpt_diag_reset(ioc, force, sleepFlag);
3168 if (hard_reset_done < 0)
3169 return hard_reset_done;
3171 dinitprintk((MYIOC_s_INFO_FMT "Diagnostic reset successful!\n",
3174 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2; /* 2 seconds */
3175 for (cnt=0; cnt<cntdn; cnt++) {
3176 ioc_state = mpt_GetIocState(ioc, 1);
3177 if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
3178 dinitprintk((MYIOC_s_INFO_FMT "KickStart successful! (cnt=%d)\n",
3180 return hard_reset_done;
3182 if (sleepFlag == CAN_SLEEP) {
3189 printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
3190 ioc->name, ioc_state);
3194 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3196 * mpt_diag_reset - Perform hard reset of the adapter.
3197 * @ioc: Pointer to MPT_ADAPTER structure
3198 * @ignore: Set if to honor and clear to ignore
3199 * the reset history bit
3200 * @sleepFlag: CAN_SLEEP if called in a non-interrupt thread,
3201 * else set to NO_SLEEP (use mdelay instead)
3203 * This routine places the adapter in diagnostic mode via the
3204 * WriteSequence register and then performs a hard reset of adapter
3205 * via the Diagnostic register. Adapter should be in ready state
3206 * upon successful completion.
3208 * Returns: 1 hard reset successful
3209 * 0 no reset performed because reset history bit set
3210 * -2 enabling diagnostic mode failed
3211 * -3 diagnostic reset failed
3214 mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
3216 MPT_ADAPTER *iocp=NULL;
3219 int hard_reset_done = 0;
3225 /* Clear any existing interrupts */
3226 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3228 if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
3229 drsprintk((MYIOC_s_WARN_FMT "%s: Doorbell=%p; 1078 reset "
3230 "address=%p\n", ioc->name, __FUNCTION__,
3231 &ioc->chip->Doorbell, &ioc->chip->Reset_1078));
3232 CHIPREG_WRITE32(&ioc->chip->Reset_1078, 0x07);
3233 if (sleepFlag == CAN_SLEEP)
3238 for (count = 0; count < 60; count ++) {
3239 doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
3240 doorbell &= MPI_IOC_STATE_MASK;
3242 drsprintk((MYIOC_s_INFO_FMT
3243 "looking for READY STATE: doorbell=%x"
3245 ioc->name, doorbell, count));
3246 if (doorbell == MPI_IOC_STATE_READY) {
3251 if (sleepFlag == CAN_SLEEP)
3259 /* Use "Diagnostic reset" method! (only thing available!) */
3260 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3264 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3265 dprintk((MYIOC_s_INFO_FMT "DbG1: diag0=%08x, diag1=%08x\n",
3266 ioc->name, diag0val, diag1val));
3269 /* Do the reset if we are told to ignore the reset history
3270 * or if the reset history is 0
3272 if (ignore || !(diag0val & MPI_DIAG_RESET_HISTORY)) {
3273 while ((diag0val & MPI_DIAG_DRWE) == 0) {
3274 /* Write magic sequence to WriteSequence register
3275 * Loop until in diagnostic mode
3277 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
3278 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
3279 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
3280 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
3281 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
3282 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
3285 if (sleepFlag == CAN_SLEEP) {
3293 printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
3294 ioc->name, diag0val);
3299 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3301 dprintk((MYIOC_s_INFO_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
3302 ioc->name, diag0val));
3307 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3308 dprintk((MYIOC_s_INFO_FMT "DbG2: diag0=%08x, diag1=%08x\n",
3309 ioc->name, diag0val, diag1val));
3312 * Disable the ARM (Bug fix)
3315 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
3319 * Now hit the reset bit in the Diagnostic register
3320 * (THE BIG HAMMER!) (Clears DRWE bit).
3322 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
3323 hard_reset_done = 1;
3324 dprintk((MYIOC_s_INFO_FMT "Diagnostic reset performed\n",
3328 * Call each currently registered protocol IOC reset handler
3329 * with pre-reset indication.
3330 * NOTE: If we're doing _IOC_BRINGUP, there can be no
3331 * MptResetHandlers[] registered yet.
3337 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
3338 if (MptResetHandlers[ii]) {
3339 dprintk((MYIOC_s_INFO_FMT "Calling IOC pre_reset handler #%d\n",
3341 r += mpt_signal_reset(ii, ioc, MPT_IOC_PRE_RESET);
3343 dprintk((MYIOC_s_INFO_FMT "Calling alt-%s pre_reset handler #%d\n",
3344 ioc->name, ioc->alt_ioc->name, ii));
3345 r += mpt_signal_reset(ii, ioc->alt_ioc, MPT_IOC_PRE_RESET);
3349 /* FIXME? Examine results here? */
3354 else if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
3355 iocp = ioc->alt_ioc;
3357 /* If the DownloadBoot operation fails, the
3358 * IOC will be left unusable. This is a fatal error
3359 * case. _diag_reset will return < 0
3361 for (count = 0; count < 30; count ++) {
3362 diag0val = CHIPREG_READ32(&iocp->chip->Diagnostic);
3363 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
3367 dprintk((MYIOC_s_INFO_FMT "cached_fw: diag0val=%x count=%d\n",
3368 iocp->name, diag0val, count));
3370 if (sleepFlag == CAN_SLEEP) {
3376 if ((count = mpt_downloadboot(ioc,
3377 (MpiFwHeader_t *)iocp->cached_fw, sleepFlag)) < 0) {
3378 printk(KERN_WARNING MYNAM
3379 ": firmware downloadboot failure (%d)!\n", count);
3383 /* Wait for FW to reload and for board
3384 * to go to the READY state.
3385 * Maximum wait is 60 seconds.
3386 * If fail, no error will check again
3387 * with calling program.
3389 for (count = 0; count < 60; count ++) {
3390 doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
3391 doorbell &= MPI_IOC_STATE_MASK;
3393 if (doorbell == MPI_IOC_STATE_READY) {
3398 if (sleepFlag == CAN_SLEEP) {
3407 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3410 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3411 dprintk((MYIOC_s_INFO_FMT "DbG3: diag0=%08x, diag1=%08x\n",
3412 ioc->name, diag0val, diag1val));
3415 /* Clear RESET_HISTORY bit! Place board in the
3416 * diagnostic mode to update the diag register.
3418 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3420 while ((diag0val & MPI_DIAG_DRWE) == 0) {
3421 /* Write magic sequence to WriteSequence register
3422 * Loop until in diagnostic mode
3424 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
3425 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
3426 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
3427 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
3428 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
3429 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
3432 if (sleepFlag == CAN_SLEEP) {
3440 printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
3441 ioc->name, diag0val);
3444 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3446 diag0val &= ~MPI_DIAG_RESET_HISTORY;
3447 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
3448 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3449 if (diag0val & MPI_DIAG_RESET_HISTORY) {
3450 printk(MYIOC_s_WARN_FMT "ResetHistory bit failed to clear!\n",
3454 /* Disable Diagnostic Mode
3456 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFFFFFFFF);
3458 /* Check FW reload status flags.
3460 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3461 if (diag0val & (MPI_DIAG_FLASH_BAD_SIG | MPI_DIAG_RESET_ADAPTER | MPI_DIAG_DISABLE_ARM)) {
3462 printk(MYIOC_s_ERR_FMT "Diagnostic reset FAILED! (%02xh)\n",
3463 ioc->name, diag0val);
3469 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
3470 dprintk((MYIOC_s_INFO_FMT "DbG4: diag0=%08x, diag1=%08x\n",
3471 ioc->name, diag0val, diag1val));
3475 * Reset flag that says we've enabled event notification
3477 ioc->facts.EventState = 0;
3480 ioc->alt_ioc->facts.EventState = 0;
3482 return hard_reset_done;
3485 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3487 * SendIocReset - Send IOCReset request to MPT adapter.
3488 * @ioc: Pointer to MPT_ADAPTER structure
3489 * @reset_type: reset type, expected values are
3490 * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
3491 * @sleepFlag: Specifies whether the process can sleep
3493 * Send IOCReset request to the MPT adapter.
3495 * Returns 0 for success, non-zero for failure.
3498 SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
3504 drsprintk((KERN_INFO MYNAM ": %s: Sending IOC reset(0x%02x)!\n",
3505 ioc->name, reset_type));
3506 CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
3507 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3510 /* FW ACK'd request, wait for READY state
3513 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
3515 while ((state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
3519 if (sleepFlag != CAN_SLEEP)
3522 printk(KERN_ERR MYNAM ": %s: ERROR - Wait IOC_READY state timeout(%d)!\n",
3523 ioc->name, (int)((count+5)/HZ));
3527 if (sleepFlag == CAN_SLEEP) {
3530 mdelay (1); /* 1 msec delay */
3535 * Cleanup all event stuff for this IOC; re-issue EventNotification
3536 * request if needed.
3538 if (ioc->facts.Function)
3539 ioc->facts.EventState = 0;
3544 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3546 * initChainBuffers - Allocate memory for and initialize chain buffers
3547 * @ioc: Pointer to MPT_ADAPTER structure
3549 * Allocates memory for and initializes chain buffers,
3550 * chain buffer control arrays and spinlock.
3553 initChainBuffers(MPT_ADAPTER *ioc)
3556 int sz, ii, num_chain;
3557 int scale, num_sge, numSGE;
3559 /* ReqToChain size must equal the req_depth
3562 if (ioc->ReqToChain == NULL) {
3563 sz = ioc->req_depth * sizeof(int);
3564 mem = kmalloc(sz, GFP_ATOMIC);
3568 ioc->ReqToChain = (int *) mem;
3569 dinitprintk((KERN_INFO MYNAM ": %s ReqToChain alloc @ %p, sz=%d bytes\n",
3570 ioc->name, mem, sz));
3571 mem = kmalloc(sz, GFP_ATOMIC);
3575 ioc->RequestNB = (int *) mem;
3576 dinitprintk((KERN_INFO MYNAM ": %s RequestNB alloc @ %p, sz=%d bytes\n",
3577 ioc->name, mem, sz));
3579 for (ii = 0; ii < ioc->req_depth; ii++) {
3580 ioc->ReqToChain[ii] = MPT_HOST_NO_CHAIN;
3583 /* ChainToChain size must equal the total number
3584 * of chain buffers to be allocated.
3587 * Calculate the number of chain buffers needed(plus 1) per I/O
3588 * then multiply the the maximum number of simultaneous cmds
3590 * num_sge = num sge in request frame + last chain buffer
3591 * scale = num sge per chain buffer if no chain element
3593 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
3594 if (sizeof(dma_addr_t) == sizeof(u64))
3595 num_sge = scale + (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
3597 num_sge = 1+ scale + (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
3599 if (sizeof(dma_addr_t) == sizeof(u64)) {
3600 numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
3601 (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
3603 numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
3604 (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
3606 dinitprintk((KERN_INFO MYNAM ": %s num_sge=%d numSGE=%d\n",
3607 ioc->name, num_sge, numSGE));
3609 if ( numSGE > MPT_SCSI_SG_DEPTH )
3610 numSGE = MPT_SCSI_SG_DEPTH;
3613 while (numSGE - num_sge > 0) {
3615 num_sge += (scale - 1);
3619 dinitprintk((KERN_INFO MYNAM ": %s Now numSGE=%d num_sge=%d num_chain=%d\n",
3620 ioc->name, numSGE, num_sge, num_chain));
3622 if (ioc->bus_type == SPI)
3623 num_chain *= MPT_SCSI_CAN_QUEUE;
3625 num_chain *= MPT_FC_CAN_QUEUE;
3627 ioc->num_chain = num_chain;
3629 sz = num_chain * sizeof(int);
3630 if (ioc->ChainToChain == NULL) {
3631 mem = kmalloc(sz, GFP_ATOMIC);
3635 ioc->ChainToChain = (int *) mem;
3636 dinitprintk((KERN_INFO MYNAM ": %s ChainToChain alloc @ %p, sz=%d bytes\n",
3637 ioc->name, mem, sz));
3639 mem = (u8 *) ioc->ChainToChain;
3641 memset(mem, 0xFF, sz);
3645 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3647 * PrimeIocFifos - Initialize IOC request and reply FIFOs.
3648 * @ioc: Pointer to MPT_ADAPTER structure
3650 * This routine allocates memory for the MPT reply and request frame
3651 * pools (if necessary), and primes the IOC reply FIFO with
3654 * Returns 0 for success, non-zero for failure.
3657 PrimeIocFifos(MPT_ADAPTER *ioc)
3660 unsigned long flags;
3661 dma_addr_t alloc_dma;
3663 int i, reply_sz, sz, total_size, num_chain;
3665 /* Prime reply FIFO... */
3667 if (ioc->reply_frames == NULL) {
3668 if ( (num_chain = initChainBuffers(ioc)) < 0)
3671 total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
3672 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
3673 ioc->name, ioc->reply_sz, ioc->reply_depth));
3674 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d[%x] bytes\n",
3675 ioc->name, reply_sz, reply_sz));
3677 sz = (ioc->req_sz * ioc->req_depth);
3678 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d bytes, RequestDepth=%d\n",
3679 ioc->name, ioc->req_sz, ioc->req_depth));
3680 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d[%x] bytes\n",
3681 ioc->name, sz, sz));
3684 sz = num_chain * ioc->req_sz; /* chain buffer pool size */
3685 dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d bytes, ChainDepth=%d\n",
3686 ioc->name, ioc->req_sz, num_chain));
3687 dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
3688 ioc->name, sz, sz, num_chain));
3691 mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
3693 printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
3698 dinitprintk((KERN_INFO MYNAM ": %s.Total alloc @ %p[%p], sz=%d[%x] bytes\n",
3699 ioc->name, mem, (void *)(ulong)alloc_dma, total_size, total_size));
3701 memset(mem, 0, total_size);
3702 ioc->alloc_total += total_size;
3704 ioc->alloc_dma = alloc_dma;
3705 ioc->alloc_sz = total_size;
3706 ioc->reply_frames = (MPT_FRAME_HDR *) mem;
3707 ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
3709 dinitprintk((KERN_INFO MYNAM ": %s ReplyBuffers @ %p[%p]\n",
3710 ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
3712 alloc_dma += reply_sz;
3715 /* Request FIFO - WE manage this! */
3717 ioc->req_frames = (MPT_FRAME_HDR *) mem;
3718 ioc->req_frames_dma = alloc_dma;
3720 dinitprintk((KERN_INFO MYNAM ": %s RequestBuffers @ %p[%p]\n",
3721 ioc->name, mem, (void *)(ulong)alloc_dma));
3723 ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
3725 #if defined(CONFIG_MTRR) && 0
3727 * Enable Write Combining MTRR for IOC's memory region.
3728 * (at least as much as we can; "size and base must be
3729 * multiples of 4 kiB"
3731 ioc->mtrr_reg = mtrr_add(ioc->req_frames_dma,
3733 MTRR_TYPE_WRCOMB, 1);
3734 dprintk((MYIOC_s_INFO_FMT "MTRR region registered (base:size=%08x:%x)\n",
3735 ioc->name, ioc->req_frames_dma, sz));
3738 for (i = 0; i < ioc->req_depth; i++) {
3739 alloc_dma += ioc->req_sz;
3743 ioc->ChainBuffer = mem;
3744 ioc->ChainBufferDMA = alloc_dma;
3746 dinitprintk((KERN_INFO MYNAM " :%s ChainBuffers @ %p(%p)\n",
3747 ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
3749 /* Initialize the free chain Q.
3752 INIT_LIST_HEAD(&ioc->FreeChainQ);
3754 /* Post the chain buffers to the FreeChainQ.
3756 mem = (u8 *)ioc->ChainBuffer;
3757 for (i=0; i < num_chain; i++) {
3758 mf = (MPT_FRAME_HDR *) mem;
3759 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeChainQ);
3763 /* Initialize Request frames linked list
3765 alloc_dma = ioc->req_frames_dma;
3766 mem = (u8 *) ioc->req_frames;
3768 spin_lock_irqsave(&ioc->FreeQlock, flags);
3769 INIT_LIST_HEAD(&ioc->FreeQ);
3770 for (i = 0; i < ioc->req_depth; i++) {
3771 mf = (MPT_FRAME_HDR *) mem;
3773 /* Queue REQUESTs *internally*! */
3774 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
3778 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
3780 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
3781 ioc->sense_buf_pool =
3782 pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
3783 if (ioc->sense_buf_pool == NULL) {
3784 printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
3789 ioc->sense_buf_low_dma = (u32) (ioc->sense_buf_pool_dma & 0xFFFFFFFF);
3790 ioc->alloc_total += sz;
3791 dinitprintk((KERN_INFO MYNAM ": %s.SenseBuffers @ %p[%p]\n",
3792 ioc->name, ioc->sense_buf_pool, (void *)(ulong)ioc->sense_buf_pool_dma));
3796 /* Post Reply frames to FIFO
3798 alloc_dma = ioc->alloc_dma;
3799 dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffers @ %p[%p]\n",
3800 ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
3802 for (i = 0; i < ioc->reply_depth; i++) {
3803 /* Write each address to the IOC! */
3804 CHIPREG_WRITE32(&ioc->chip->ReplyFifo, alloc_dma);
3805 alloc_dma += ioc->reply_sz;
3811 if (ioc->alloc != NULL) {
3813 pci_free_consistent(ioc->pcidev,
3815 ioc->alloc, ioc->alloc_dma);
3816 ioc->reply_frames = NULL;
3817 ioc->req_frames = NULL;
3818 ioc->alloc_total -= sz;
3820 if (ioc->sense_buf_pool != NULL) {
3821 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
3822 pci_free_consistent(ioc->pcidev,
3824 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
3825 ioc->sense_buf_pool = NULL;
3830 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3832 * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
3833 * from IOC via doorbell handshake method.
3834 * @ioc: Pointer to MPT_ADAPTER structure
3835 * @reqBytes: Size of the request in bytes
3836 * @req: Pointer to MPT request frame
3837 * @replyBytes: Expected size of the reply in bytes
3838 * @u16reply: Pointer to area where reply should be written
3839 * @maxwait: Max wait time for a reply (in seconds)
3840 * @sleepFlag: Specifies whether the process can sleep
3842 * NOTES: It is the callers responsibility to byte-swap fields in the
3843 * request which are greater than 1 byte in size. It is also the
3844 * callers responsibility to byte-swap response fields which are
3845 * greater than 1 byte in size.
3847 * Returns 0 for success, non-zero for failure.
3850 mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
3851 int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
3853 MPIDefaultReply_t *mptReply;
3858 * Get ready to cache a handshake reply
3860 ioc->hs_reply_idx = 0;
3861 mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
3862 mptReply->MsgLength = 0;
3865 * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
3866 * then tell IOC that we want to handshake a request of N words.
3867 * (WRITE u32val to Doorbell reg).
3869 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3870 CHIPREG_WRITE32(&ioc->chip->Doorbell,
3871 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
3872 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
3875 * Wait for IOC's doorbell handshake int
3877 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
3880 dhsprintk((MYIOC_s_INFO_FMT "HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
3881 ioc->name, reqBytes, t, failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
3883 /* Read doorbell and check for active bit */
3884 if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
3888 * Clear doorbell int (WRITE 0 to IntStatus reg),
3889 * then wait for IOC to ACKnowledge that it's ready for
3890 * our handshake request.
3892 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3893 if (!failcnt && (t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3898 u8 *req_as_bytes = (u8 *) req;
3901 * Stuff request words via doorbell handshake,
3902 * with ACK from IOC for each.
3904 for (ii = 0; !failcnt && ii < reqBytes/4; ii++) {
3905 u32 word = ((req_as_bytes[(ii*4) + 0] << 0) |
3906 (req_as_bytes[(ii*4) + 1] << 8) |
3907 (req_as_bytes[(ii*4) + 2] << 16) |
3908 (req_as_bytes[(ii*4) + 3] << 24));
3910 CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
3911 if ((t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
3915 dhsprintk((KERN_INFO MYNAM ": Handshake request frame (@%p) header\n", req));
3916 DBG_DUMP_REQUEST_FRAME_HDR(req)
3918 dhsprintk((MYIOC_s_INFO_FMT "HandShake request post done, WaitCnt=%d%s\n",
3919 ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
3922 * Wait for completion of doorbell handshake reply from the IOC
3924 if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
3927 dhsprintk((MYIOC_s_INFO_FMT "HandShake reply count=%d%s\n",
3928 ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
3931 * Copy out the cached reply...
3933 for (ii=0; ii < min(replyBytes/2,mptReply->MsgLength*2); ii++)
3934 u16reply[ii] = ioc->hs_reply[ii];
3942 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3944 * WaitForDoorbellAck - Wait for IOC doorbell handshake acknowledge
3945 * @ioc: Pointer to MPT_ADAPTER structure
3946 * @howlong: How long to wait (in seconds)
3947 * @sleepFlag: Specifies whether the process can sleep
3949 * This routine waits (up to ~2 seconds max) for IOC doorbell
3950 * handshake ACKnowledge, indicated by the IOP_DOORBELL_STATUS
3951 * bit in its IntStatus register being clear.
3953 * Returns a negative value on failure, else wait loop count.
3956 WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3962 cntdn = 1000 * howlong;
3964 if (sleepFlag == CAN_SLEEP) {
3967 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3968 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
3975 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3976 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
3983 dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell ACK (count=%d)\n",
3988 printk(MYIOC_s_ERR_FMT "Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
3989 ioc->name, count, intstat);
3993 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3995 * WaitForDoorbellInt - Wait for IOC to set its doorbell interrupt bit
3996 * @ioc: Pointer to MPT_ADAPTER structure
3997 * @howlong: How long to wait (in seconds)
3998 * @sleepFlag: Specifies whether the process can sleep
4000 * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt
4001 * (MPI_HIS_DOORBELL_INTERRUPT) to be set in the IntStatus register.
4003 * Returns a negative value on failure, else wait loop count.
4006 WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
4012 cntdn = 1000 * howlong;
4013 if (sleepFlag == CAN_SLEEP) {
4015 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
4016 if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
4023 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
4024 if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
4032 dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell INT (cnt=%d) howlong=%d\n",
4033 ioc->name, count, howlong));
4037 printk(MYIOC_s_ERR_FMT "Doorbell INT timeout (count=%d), IntStatus=%x!\n",
4038 ioc->name, count, intstat);
4042 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4044 * WaitForDoorbellReply - Wait for and capture an IOC handshake reply.
4045 * @ioc: Pointer to MPT_ADAPTER structure
4046 * @howlong: How long to wait (in seconds)
4047 * @sleepFlag: Specifies whether the process can sleep
4049 * This routine polls the IOC for a handshake reply, 16 bits at a time.
4050 * Reply is cached to IOC private area large enough to hold a maximum
4051 * of 128 bytes of reply data.
4053 * Returns a negative value on failure, else size of reply in WORDS.
4056 WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
4061 u16 *hs_reply = ioc->hs_reply;
4062 volatile MPIDefaultReply_t *mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
4065 hs_reply[0] = hs_reply[1] = hs_reply[7] = 0;
4068 * Get first two u16's so we can look at IOC's intended reply MsgLength
4071 if ((t = WaitForDoorbellInt(ioc, howlong, sleepFlag)) < 0) {
4074 hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
4075 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
4076 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
4079 hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
4080 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
4084 dhsprintk((MYIOC_s_INFO_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
4085 ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
4086 failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
4089 * If no error (and IOC said MsgLength is > 0), piece together
4090 * reply 16 bits at a time.
4092 for (u16cnt=2; !failcnt && u16cnt < (2 * mptReply->MsgLength); u16cnt++) {
4093 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
4095 hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
4096 /* don't overflow our IOC hs_reply[] buffer! */
4097 if (u16cnt < sizeof(ioc->hs_reply) / sizeof(ioc->hs_reply[0]))
4098 hs_reply[u16cnt] = hword;
4099 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
4102 if (!failcnt && (t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
4104 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
4107 printk(MYIOC_s_ERR_FMT "Handshake reply failure!\n",
4112 else if (u16cnt != (2 * mptReply->MsgLength)) {
4115 else if ((mptReply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
4120 dhsprintk((MYIOC_s_INFO_FMT "Got Handshake reply:\n", ioc->name));
4121 DBG_DUMP_REPLY_FRAME(mptReply)
4123 dhsprintk((MYIOC_s_INFO_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
4124 ioc->name, t, u16cnt/2));
4128 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4130 * GetLanConfigPages - Fetch LANConfig pages.
4131 * @ioc: Pointer to MPT_ADAPTER structure
4133 * Return: 0 for success
4134 * -ENOMEM if no memory available
4135 * -EPERM if not allowed due to ISR context
4136 * -EAGAIN if no msg frames currently available
4137 * -EFAULT for non-successful reply or no reply (timeout)
4140 GetLanConfigPages(MPT_ADAPTER *ioc)
4142 ConfigPageHeader_t hdr;
4144 LANPage0_t *ppage0_alloc;
4145 dma_addr_t page0_dma;
4146 LANPage1_t *ppage1_alloc;
4147 dma_addr_t page1_dma;
4152 /* Get LAN Page 0 header */
4153 hdr.PageVersion = 0;
4156 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
4157 cfg.cfghdr.hdr = &hdr;
4159 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4164 if ((rc = mpt_config(ioc, &cfg)) != 0)
4167 if (hdr.PageLength > 0) {
4168 data_sz = hdr.PageLength * 4;
4169 ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
4172 memset((u8 *)ppage0_alloc, 0, data_sz);
4173 cfg.physAddr = page0_dma;
4174 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4176 if ((rc = mpt_config(ioc, &cfg)) == 0) {
4178 copy_sz = min_t(int, sizeof(LANPage0_t), data_sz);
4179 memcpy(&ioc->lan_cnfg_page0, ppage0_alloc, copy_sz);
4183 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
4186 * Normalize endianness of structure data,
4187 * by byte-swapping all > 1 byte fields!
4196 /* Get LAN Page 1 header */
4197 hdr.PageVersion = 0;
4200 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
4201 cfg.cfghdr.hdr = &hdr;
4203 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4207 if ((rc = mpt_config(ioc, &cfg)) != 0)
4210 if (hdr.PageLength == 0)
4213 data_sz = hdr.PageLength * 4;
4215 ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
4217 memset((u8 *)ppage1_alloc, 0, data_sz);
4218 cfg.physAddr = page1_dma;
4219 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4221 if ((rc = mpt_config(ioc, &cfg)) == 0) {
4223 copy_sz = min_t(int, sizeof(LANPage1_t), data_sz);
4224 memcpy(&ioc->lan_cnfg_page1, ppage1_alloc, copy_sz);
4227 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
4230 * Normalize endianness of structure data,
4231 * by byte-swapping all > 1 byte fields!
4239 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4241 * mptbase_sas_persist_operation - Perform operation on SAS Persistent Table
4242 * @ioc: Pointer to MPT_ADAPTER structure
4243 * @persist_opcode: see below
4245 * MPI_SAS_OP_CLEAR_NOT_PRESENT - Free all persist TargetID mappings for
4246 * devices not currently present.
4247 * MPI_SAS_OP_CLEAR_ALL_PERSISTENT - Clear al persist TargetID mappings
4249 * NOTE: Don't use not this function during interrupt time.
4251 * Returns 0 for success, non-zero error
4254 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4256 mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode)
4258 SasIoUnitControlRequest_t *sasIoUnitCntrReq;
4259 SasIoUnitControlReply_t *sasIoUnitCntrReply;
4260 MPT_FRAME_HDR *mf = NULL;
4261 MPIHeader_t *mpi_hdr;
4264 /* insure garbage is not sent to fw */
4265 switch(persist_opcode) {
4267 case MPI_SAS_OP_CLEAR_NOT_PRESENT:
4268 case MPI_SAS_OP_CLEAR_ALL_PERSISTENT:
4276 printk("%s: persist_opcode=%x\n",__FUNCTION__, persist_opcode);
4278 /* Get a MF for this command.
4280 if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
4281 printk("%s: no msg frames!\n",__FUNCTION__);
4285 mpi_hdr = (MPIHeader_t *) mf;
4286 sasIoUnitCntrReq = (SasIoUnitControlRequest_t *)mf;
4287 memset(sasIoUnitCntrReq,0,sizeof(SasIoUnitControlRequest_t));
4288 sasIoUnitCntrReq->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
4289 sasIoUnitCntrReq->MsgContext = mpi_hdr->MsgContext;
4290 sasIoUnitCntrReq->Operation = persist_opcode;
4292 init_timer(&ioc->persist_timer);
4293 ioc->persist_timer.data = (unsigned long) ioc;
4294 ioc->persist_timer.function = mpt_timer_expired;
4295 ioc->persist_timer.expires = jiffies + HZ*10 /* 10 sec */;
4296 ioc->persist_wait_done=0;
4297 add_timer(&ioc->persist_timer);
4298 mpt_put_msg_frame(mpt_base_index, ioc, mf);
4299 wait_event(mpt_waitq, ioc->persist_wait_done);
4301 sasIoUnitCntrReply =
4302 (SasIoUnitControlReply_t *)ioc->persist_reply_frame;
4303 if (le16_to_cpu(sasIoUnitCntrReply->IOCStatus) != MPI_IOCSTATUS_SUCCESS) {
4304 printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
4306 sasIoUnitCntrReply->IOCStatus,
4307 sasIoUnitCntrReply->IOCLogInfo);
4311 printk("%s: success\n",__FUNCTION__);
4315 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4318 mptbase_raid_process_event_data(MPT_ADAPTER *ioc,
4319 MpiEventDataRaid_t * pRaidEventData)
4328 volume = pRaidEventData->VolumeID;
4329 reason = pRaidEventData->ReasonCode;
4330 disk = pRaidEventData->PhysDiskNum;
4331 status = le32_to_cpu(pRaidEventData->SettingsStatus);
4332 flags = (status >> 0) & 0xff;
4333 state = (status >> 8) & 0xff;
4335 if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) {
4339 if ((reason >= MPI_EVENT_RAID_RC_PHYSDISK_CREATED &&
4340 reason <= MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED) ||
4341 (reason == MPI_EVENT_RAID_RC_SMART_DATA)) {
4342 printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for PhysDisk %d id=%d\n",
4343 ioc->name, disk, volume);
4345 printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for VolumeID %d\n",
4350 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
4351 printk(MYIOC_s_INFO_FMT " volume has been created\n",
4355 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
4357 printk(MYIOC_s_INFO_FMT " volume has been deleted\n",
4361 case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED:
4362 printk(MYIOC_s_INFO_FMT " volume settings have been changed\n",
4366 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
4367 printk(MYIOC_s_INFO_FMT " volume is now %s%s%s%s\n",
4369 state == MPI_RAIDVOL0_STATUS_STATE_OPTIMAL
4371 : state == MPI_RAIDVOL0_STATUS_STATE_DEGRADED
4373 : state == MPI_RAIDVOL0_STATUS_STATE_FAILED
4376 flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED
4378 flags & MPI_RAIDVOL0_STATUS_FLAG_QUIESCED
4379 ? ", quiesced" : "",
4380 flags & MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
4381 ? ", resync in progress" : "" );
4384 case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED:
4385 printk(MYIOC_s_INFO_FMT " volume membership of PhysDisk %d has changed\n",
4389 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
4390 printk(MYIOC_s_INFO_FMT " PhysDisk has been created\n",
4394 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
4395 printk(MYIOC_s_INFO_FMT " PhysDisk has been deleted\n",
4399 case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED:
4400 printk(MYIOC_s_INFO_FMT " PhysDisk settings have been changed\n",
4404 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
4405 printk(MYIOC_s_INFO_FMT " PhysDisk is now %s%s%s\n",
4407 state == MPI_PHYSDISK0_STATUS_ONLINE
4409 : state == MPI_PHYSDISK0_STATUS_MISSING
4411 : state == MPI_PHYSDISK0_STATUS_NOT_COMPATIBLE
4413 : state == MPI_PHYSDISK0_STATUS_FAILED
4415 : state == MPI_PHYSDISK0_STATUS_INITIALIZING
4417 : state == MPI_PHYSDISK0_STATUS_OFFLINE_REQUESTED
4418 ? "offline requested"
4419 : state == MPI_PHYSDISK0_STATUS_FAILED_REQUESTED
4420 ? "failed requested"
4421 : state == MPI_PHYSDISK0_STATUS_OTHER_OFFLINE
4424 flags & MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC
4425 ? ", out of sync" : "",
4426 flags & MPI_PHYSDISK0_STATUS_FLAG_QUIESCED
4427 ? ", quiesced" : "" );
4430 case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED:
4431 printk(MYIOC_s_INFO_FMT " Domain Validation needed for PhysDisk %d\n",
4435 case MPI_EVENT_RAID_RC_SMART_DATA:
4436 printk(MYIOC_s_INFO_FMT " SMART data received, ASC/ASCQ = %02xh/%02xh\n",
4437 ioc->name, pRaidEventData->ASC, pRaidEventData->ASCQ);
4440 case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED:
4441 printk(MYIOC_s_INFO_FMT " replacement of PhysDisk %d has started\n",
4447 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4449 * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
4450 * @ioc: Pointer to MPT_ADAPTER structure
4452 * Returns: 0 for success
4453 * -ENOMEM if no memory available
4454 * -EPERM if not allowed due to ISR context
4455 * -EAGAIN if no msg frames currently available
4456 * -EFAULT for non-successful reply or no reply (timeout)
4459 GetIoUnitPage2(MPT_ADAPTER *ioc)
4461 ConfigPageHeader_t hdr;
4463 IOUnitPage2_t *ppage_alloc;
4464 dma_addr_t page_dma;
4468 /* Get the page header */
4469 hdr.PageVersion = 0;
4472 hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
4473 cfg.cfghdr.hdr = &hdr;
4475 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4480 if ((rc = mpt_config(ioc, &cfg)) != 0)
4483 if (hdr.PageLength == 0)
4486 /* Read the config page */
4487 data_sz = hdr.PageLength * 4;
4489 ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
4491 memset((u8 *)ppage_alloc, 0, data_sz);
4492 cfg.physAddr = page_dma;
4493 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4495 /* If Good, save data */
4496 if ((rc = mpt_config(ioc, &cfg)) == 0)
4497 ioc->biosVersion = le32_to_cpu(ppage_alloc->BiosVersion);
4499 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage_alloc, page_dma);
4505 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4507 * mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
4508 * @ioc: Pointer to a Adapter Strucutre
4509 * @portnum: IOC port number
4511 * Return: -EFAULT if read of config page header fails
4513 * If read of SCSI Port Page 0 fails,
4514 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
4515 * Adapter settings: async, narrow
4517 * If read of SCSI Port Page 2 fails,
4518 * Adapter settings valid
4519 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
4524 * CHECK - what type of locking mechanisms should be used????
4527 mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
4532 ConfigPageHeader_t header;
4538 if (!ioc->spi_data.nvram) {
4541 sz = MPT_MAX_SCSI_DEVICES * sizeof(int);
4542 mem = kmalloc(sz, GFP_ATOMIC);
4546 ioc->spi_data.nvram = (int *) mem;
4548 dprintk((MYIOC_s_INFO_FMT "SCSI device NVRAM settings @ %p, sz=%d\n",
4549 ioc->name, ioc->spi_data.nvram, sz));
4552 /* Invalidate NVRAM information
4554 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
4555 ioc->spi_data.nvram[ii] = MPT_HOST_NVRAM_INVALID;
4558 /* Read SPP0 header, allocate memory, then read page.
4560 header.PageVersion = 0;
4561 header.PageLength = 0;
4562 header.PageNumber = 0;
4563 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
4564 cfg.cfghdr.hdr = &header;
4566 cfg.pageAddr = portnum;
4567 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4569 cfg.timeout = 0; /* use default */
4570 if (mpt_config(ioc, &cfg) != 0)
4573 if (header.PageLength > 0) {
4574 pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
4576 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4577 cfg.physAddr = buf_dma;
4578 if (mpt_config(ioc, &cfg) != 0) {
4579 ioc->spi_data.maxBusWidth = MPT_NARROW;
4580 ioc->spi_data.maxSyncOffset = 0;
4581 ioc->spi_data.minSyncFactor = MPT_ASYNC;
4582 ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
4584 ddvprintk((MYIOC_s_INFO_FMT "Unable to read PortPage0 minSyncFactor=%x\n",
4585 ioc->name, ioc->spi_data.minSyncFactor));
4587 /* Save the Port Page 0 data
4589 SCSIPortPage0_t *pPP0 = (SCSIPortPage0_t *) pbuf;
4590 pPP0->Capabilities = le32_to_cpu(pPP0->Capabilities);
4591 pPP0->PhysicalInterface = le32_to_cpu(pPP0->PhysicalInterface);
4593 if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
4594 ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
4595 ddvprintk((KERN_INFO MYNAM " :%s noQas due to Capabilities=%x\n",
4596 ioc->name, pPP0->Capabilities));
4598 ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
4599 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK;
4601 ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
4602 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
4603 ioc->spi_data.minSyncFactor = (u8) (data >> 8);
4604 ddvprintk((MYIOC_s_INFO_FMT "PortPage0 minSyncFactor=%x\n",
4605 ioc->name, ioc->spi_data.minSyncFactor));
4607 ioc->spi_data.maxSyncOffset = 0;
4608 ioc->spi_data.minSyncFactor = MPT_ASYNC;
4611 ioc->spi_data.busType = pPP0->PhysicalInterface & MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK;
4613 /* Update the minSyncFactor based on bus type.
4615 if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
4616 (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
4618 if (ioc->spi_data.minSyncFactor < MPT_ULTRA) {
4619 ioc->spi_data.minSyncFactor = MPT_ULTRA;
4620 ddvprintk((MYIOC_s_INFO_FMT "HVD or SE detected, minSyncFactor=%x\n",
4621 ioc->name, ioc->spi_data.minSyncFactor));
4626 pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
4631 /* SCSI Port Page 2 - Read the header then the page.
4633 header.PageVersion = 0;
4634 header.PageLength = 0;
4635 header.PageNumber = 2;
4636 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
4637 cfg.cfghdr.hdr = &header;
4639 cfg.pageAddr = portnum;
4640 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4642 if (mpt_config(ioc, &cfg) != 0)
4645 if (header.PageLength > 0) {
4646 /* Allocate memory and read SCSI Port Page 2
4648 pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
4650 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_NVRAM;
4651 cfg.physAddr = buf_dma;
4652 if (mpt_config(ioc, &cfg) != 0) {
4653 /* Nvram data is left with INVALID mark
4657 SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t *) pbuf;
4658 MpiDeviceInfo_t *pdevice = NULL;
4661 * Save "Set to Avoid SCSI Bus Resets" flag
4663 ioc->spi_data.bus_reset =
4664 (le32_to_cpu(pPP2->PortFlags) &
4665 MPI_SCSIPORTPAGE2_PORT_FLAGS_AVOID_SCSI_RESET) ?
4668 /* Save the Port Page 2 data
4669 * (reformat into a 32bit quantity)
4671 data = le32_to_cpu(pPP2->PortFlags) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
4672 ioc->spi_data.PortFlags = data;
4673 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
4674 pdevice = &pPP2->DeviceSettings[ii];
4675 data = (le16_to_cpu(pdevice->DeviceFlags) << 16) |
4676 (pdevice->SyncFactor << 8) | pdevice->Timeout;
4677 ioc->spi_data.nvram[ii] = data;
4681 pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
4685 /* Update Adapter limits with those from NVRAM
4686 * Comment: Don't need to do this. Target performance
4687 * parameters will never exceed the adapters limits.
4693 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4695 * mpt_readScsiDevicePageHeaders - save version and length of SDP1
4696 * @ioc: Pointer to a Adapter Strucutre
4697 * @portnum: IOC port number
4699 * Return: -EFAULT if read of config page header fails
4703 mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
4706 ConfigPageHeader_t header;
4708 /* Read the SCSI Device Page 1 header
4710 header.PageVersion = 0;
4711 header.PageLength = 0;
4712 header.PageNumber = 1;
4713 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4714 cfg.cfghdr.hdr = &header;
4716 cfg.pageAddr = portnum;
4717 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4720 if (mpt_config(ioc, &cfg) != 0)
4723 ioc->spi_data.sdp1version = cfg.cfghdr.hdr->PageVersion;
4724 ioc->spi_data.sdp1length = cfg.cfghdr.hdr->PageLength;
4726 header.PageVersion = 0;
4727 header.PageLength = 0;
4728 header.PageNumber = 0;
4729 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4730 if (mpt_config(ioc, &cfg) != 0)
4733 ioc->spi_data.sdp0version = cfg.cfghdr.hdr->PageVersion;
4734 ioc->spi_data.sdp0length = cfg.cfghdr.hdr->PageLength;
4736 dcprintk((MYIOC_s_INFO_FMT "Headers: 0: version %d length %d\n",
4737 ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
4739 dcprintk((MYIOC_s_INFO_FMT "Headers: 1: version %d length %d\n",
4740 ioc->name, ioc->spi_data.sdp1version, ioc->spi_data.sdp1length));
4745 * mpt_inactive_raid_list_free - This clears this link list.
4746 * @ioc : pointer to per adapter structure
4749 mpt_inactive_raid_list_free(MPT_ADAPTER *ioc)
4751 struct inactive_raid_component_info *component_info, *pNext;
4753 if (list_empty(&ioc->raid_data.inactive_list))
4756 down(&ioc->raid_data.inactive_list_mutex);
4757 list_for_each_entry_safe(component_info, pNext,
4758 &ioc->raid_data.inactive_list, list) {
4759 list_del(&component_info->list);
4760 kfree(component_info);
4762 up(&ioc->raid_data.inactive_list_mutex);
4766 * mpt_inactive_raid_volumes - sets up link list of phy_disk_nums for devices belonging in an inactive volume
4768 * @ioc : pointer to per adapter structure
4769 * @channel : volume channel
4770 * @id : volume target id
4773 mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id)
4776 ConfigPageHeader_t hdr;
4777 dma_addr_t dma_handle;
4778 pRaidVolumePage0_t buffer = NULL;
4780 RaidPhysDiskPage0_t phys_disk;
4781 struct inactive_raid_component_info *component_info;
4782 int handle_inactive_volumes;
4784 memset(&cfg, 0 , sizeof(CONFIGPARMS));
4785 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
4786 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
4787 cfg.pageAddr = (channel << 8) + id;
4788 cfg.cfghdr.hdr = &hdr;
4789 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4791 if (mpt_config(ioc, &cfg) != 0)
4794 if (!hdr.PageLength)
4797 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
4803 cfg.physAddr = dma_handle;
4804 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4806 if (mpt_config(ioc, &cfg) != 0)
4809 if (!buffer->NumPhysDisks)
4812 handle_inactive_volumes =
4813 (buffer->VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE ||
4814 (buffer->VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED) == 0 ||
4815 buffer->VolumeStatus.State == MPI_RAIDVOL0_STATUS_STATE_FAILED ||
4816 buffer->VolumeStatus.State == MPI_RAIDVOL0_STATUS_STATE_MISSING) ? 1 : 0;
4818 if (!handle_inactive_volumes)
4821 down(&ioc->raid_data.inactive_list_mutex);
4822 for (i = 0; i < buffer->NumPhysDisks; i++) {
4823 if(mpt_raid_phys_disk_pg0(ioc,
4824 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
4827 if ((component_info = kmalloc(sizeof (*component_info),
4828 GFP_KERNEL)) == NULL)
4831 component_info->volumeID = id;
4832 component_info->volumeBus = channel;
4833 component_info->d.PhysDiskNum = phys_disk.PhysDiskNum;
4834 component_info->d.PhysDiskBus = phys_disk.PhysDiskBus;
4835 component_info->d.PhysDiskID = phys_disk.PhysDiskID;
4836 component_info->d.PhysDiskIOC = phys_disk.PhysDiskIOC;
4838 list_add_tail(&component_info->list,
4839 &ioc->raid_data.inactive_list);
4841 up(&ioc->raid_data.inactive_list_mutex);
4845 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
4850 * mpt_raid_phys_disk_pg0 - returns phys disk page zero
4851 * @ioc: Pointer to a Adapter Structure
4852 * @phys_disk_num: io unit unique phys disk num generated by the ioc
4853 * @phys_disk: requested payload data returned
4857 * -EFAULT if read of config page header fails or data pointer not NULL
4858 * -ENOMEM if pci_alloc failed
4861 mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num, pRaidPhysDiskPage0_t phys_disk)
4864 ConfigPageHeader_t hdr;
4865 dma_addr_t dma_handle;
4866 pRaidPhysDiskPage0_t buffer = NULL;
4869 memset(&cfg, 0 , sizeof(CONFIGPARMS));
4870 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
4872 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
4873 cfg.cfghdr.hdr = &hdr;
4875 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4877 if (mpt_config(ioc, &cfg) != 0) {
4882 if (!hdr.PageLength) {
4887 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
4895 cfg.physAddr = dma_handle;
4896 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4897 cfg.pageAddr = phys_disk_num;
4899 if (mpt_config(ioc, &cfg) != 0) {
4905 memcpy(phys_disk, buffer, sizeof(*buffer));
4906 phys_disk->MaxLBA = le32_to_cpu(buffer->MaxLBA);
4911 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
4918 * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
4919 * @ioc: Pointer to a Adapter Strucutre
4920 * @portnum: IOC port number
4924 * -EFAULT if read of config page header fails or data pointer not NULL
4925 * -ENOMEM if pci_alloc failed
4928 mpt_findImVolumes(MPT_ADAPTER *ioc)
4932 dma_addr_t ioc2_dma;
4934 ConfigPageHeader_t header;
4939 if (!ioc->ir_firmware)
4942 /* Free the old page
4944 kfree(ioc->raid_data.pIocPg2);
4945 ioc->raid_data.pIocPg2 = NULL;
4946 mpt_inactive_raid_list_free(ioc);
4948 /* Read IOCP2 header then the page.
4950 header.PageVersion = 0;
4951 header.PageLength = 0;
4952 header.PageNumber = 2;
4953 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4954 cfg.cfghdr.hdr = &header;
4957 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4960 if (mpt_config(ioc, &cfg) != 0)
4963 if (header.PageLength == 0)
4966 iocpage2sz = header.PageLength * 4;
4967 pIoc2 = pci_alloc_consistent(ioc->pcidev, iocpage2sz, &ioc2_dma);
4971 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4972 cfg.physAddr = ioc2_dma;
4973 if (mpt_config(ioc, &cfg) != 0)
4976 mem = kmalloc(iocpage2sz, GFP_KERNEL);
4980 memcpy(mem, (u8 *)pIoc2, iocpage2sz);
4981 ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
4983 mpt_read_ioc_pg_3(ioc);
4985 for (i = 0; i < pIoc2->NumActiveVolumes ; i++)
4986 mpt_inactive_raid_volumes(ioc,
4987 pIoc2->RaidVolume[i].VolumeBus,
4988 pIoc2->RaidVolume[i].VolumeID);
4991 pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
4997 mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
5002 ConfigPageHeader_t header;
5003 dma_addr_t ioc3_dma;
5006 /* Free the old page
5008 kfree(ioc->raid_data.pIocPg3);
5009 ioc->raid_data.pIocPg3 = NULL;
5011 /* There is at least one physical disk.
5012 * Read and save IOC Page 3
5014 header.PageVersion = 0;
5015 header.PageLength = 0;
5016 header.PageNumber = 3;
5017 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
5018 cfg.cfghdr.hdr = &header;
5021 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5024 if (mpt_config(ioc, &cfg) != 0)
5027 if (header.PageLength == 0)
5030 /* Read Header good, alloc memory
5032 iocpage3sz = header.PageLength * 4;
5033 pIoc3 = pci_alloc_consistent(ioc->pcidev, iocpage3sz, &ioc3_dma);
5037 /* Read the Page and save the data
5038 * into malloc'd memory.
5040 cfg.physAddr = ioc3_dma;
5041 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5042 if (mpt_config(ioc, &cfg) == 0) {
5043 mem = kmalloc(iocpage3sz, GFP_KERNEL);
5045 memcpy(mem, (u8 *)pIoc3, iocpage3sz);
5046 ioc->raid_data.pIocPg3 = (IOCPage3_t *) mem;
5050 pci_free_consistent(ioc->pcidev, iocpage3sz, pIoc3, ioc3_dma);
5056 mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
5060 ConfigPageHeader_t header;
5061 dma_addr_t ioc4_dma;
5064 /* Read and save IOC Page 4
5066 header.PageVersion = 0;
5067 header.PageLength = 0;
5068 header.PageNumber = 4;
5069 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
5070 cfg.cfghdr.hdr = &header;
5073 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5076 if (mpt_config(ioc, &cfg) != 0)
5079 if (header.PageLength == 0)
5082 if ( (pIoc4 = ioc->spi_data.pIocPg4) == NULL ) {
5083 iocpage4sz = (header.PageLength + 4) * 4; /* Allow 4 additional SEP's */
5084 pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
5087 ioc->alloc_total += iocpage4sz;
5089 ioc4_dma = ioc->spi_data.IocPg4_dma;
5090 iocpage4sz = ioc->spi_data.IocPg4Sz;
5093 /* Read the Page into dma memory.
5095 cfg.physAddr = ioc4_dma;
5096 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5097 if (mpt_config(ioc, &cfg) == 0) {
5098 ioc->spi_data.pIocPg4 = (IOCPage4_t *) pIoc4;
5099 ioc->spi_data.IocPg4_dma = ioc4_dma;
5100 ioc->spi_data.IocPg4Sz = iocpage4sz;
5102 pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
5103 ioc->spi_data.pIocPg4 = NULL;
5104 ioc->alloc_total -= iocpage4sz;
5109 mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
5113 ConfigPageHeader_t header;
5114 dma_addr_t ioc1_dma;
5118 /* Check the Coalescing Timeout in IOC Page 1
5120 header.PageVersion = 0;
5121 header.PageLength = 0;
5122 header.PageNumber = 1;
5123 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
5124 cfg.cfghdr.hdr = &header;
5127 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5130 if (mpt_config(ioc, &cfg) != 0)
5133 if (header.PageLength == 0)
5136 /* Read Header good, alloc memory
5138 iocpage1sz = header.PageLength * 4;
5139 pIoc1 = pci_alloc_consistent(ioc->pcidev, iocpage1sz, &ioc1_dma);
5143 /* Read the Page and check coalescing timeout
5145 cfg.physAddr = ioc1_dma;
5146 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5147 if (mpt_config(ioc, &cfg) == 0) {
5149 tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
5150 if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
5151 tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
5153 dprintk((MYIOC_s_INFO_FMT "Coalescing Enabled Timeout = %d\n",
5156 if (tmp > MPT_COALESCING_TIMEOUT) {
5157 pIoc1->CoalescingTimeout = cpu_to_le32(MPT_COALESCING_TIMEOUT);
5159 /* Write NVRAM and current
5162 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
5163 if (mpt_config(ioc, &cfg) == 0) {
5164 dprintk((MYIOC_s_INFO_FMT "Reset Current Coalescing Timeout to = %d\n",
5165 ioc->name, MPT_COALESCING_TIMEOUT));
5167 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
5168 if (mpt_config(ioc, &cfg) == 0) {
5169 dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout to = %d\n",
5170 ioc->name, MPT_COALESCING_TIMEOUT));
5172 dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout Failed\n",
5177 dprintk((MYIOC_s_WARN_FMT "Reset of Current Coalescing Timeout Failed!\n",
5183 dprintk((MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
5187 pci_free_consistent(ioc->pcidev, iocpage1sz, pIoc1, ioc1_dma);
5192 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5194 * SendEventNotification - Send EventNotification (on or off) request to adapter
5195 * @ioc: Pointer to MPT_ADAPTER structure
5196 * @EvSwitch: Event switch flags
5199 SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch)
5201 EventNotification_t *evnp;
5203 evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc);
5205 devtverboseprintk((MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n",
5209 memset(evnp, 0, sizeof(*evnp));
5211 devtverboseprintk((MYIOC_s_INFO_FMT "Sending EventNotification (%d) request %p\n", ioc->name, EvSwitch, evnp));
5213 evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
5214 evnp->ChainOffset = 0;
5216 evnp->Switch = EvSwitch;
5218 mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)evnp);
5223 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5225 * SendEventAck - Send EventAck request to MPT adapter.
5226 * @ioc: Pointer to MPT_ADAPTER structure
5227 * @evnp: Pointer to original EventNotification request
5230 SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
5234 if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
5235 dfailprintk((MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
5236 ioc->name,__FUNCTION__));
5240 devtverboseprintk((MYIOC_s_INFO_FMT "Sending EventAck\n", ioc->name));
5242 pAck->Function = MPI_FUNCTION_EVENT_ACK;
5243 pAck->ChainOffset = 0;
5244 pAck->Reserved[0] = pAck->Reserved[1] = 0;
5246 pAck->Reserved1[0] = pAck->Reserved1[1] = pAck->Reserved1[2] = 0;
5247 pAck->Event = evnp->Event;
5248 pAck->EventContext = evnp->EventContext;
5250 mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)pAck);
5255 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5257 * mpt_config - Generic function to issue config message
5258 * @ioc: Pointer to an adapter structure
5259 * @pCfg: Pointer to a configuration structure. Struct contains
5260 * action, page address, direction, physical address
5261 * and pointer to a configuration page header
5262 * Page header is updated.
5264 * Returns 0 for success
5265 * -EPERM if not allowed due to ISR context
5266 * -EAGAIN if no msg frames currently available
5267 * -EFAULT for non-successful reply or no reply (timeout)
5270 mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
5273 ConfigExtendedPageHeader_t *pExtHdr = NULL;
5275 unsigned long flags;
5280 /* Prevent calling wait_event() (below), if caller happens
5281 * to be in ISR context, because that is fatal!
5283 in_isr = in_interrupt();
5285 dcprintk((MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
5290 /* Get and Populate a free Frame
5292 if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
5293 dcprintk((MYIOC_s_WARN_FMT "mpt_config: no msg frames!\n",
5297 pReq = (Config_t *)mf;
5298 pReq->Action = pCfg->action;
5300 pReq->ChainOffset = 0;
5301 pReq->Function = MPI_FUNCTION_CONFIG;
5303 /* Assume page type is not extended and clear "reserved" fields. */
5304 pReq->ExtPageLength = 0;
5305 pReq->ExtPageType = 0;
5308 for (ii=0; ii < 8; ii++)
5309 pReq->Reserved2[ii] = 0;
5311 pReq->Header.PageVersion = pCfg->cfghdr.hdr->PageVersion;
5312 pReq->Header.PageLength = pCfg->cfghdr.hdr->PageLength;
5313 pReq->Header.PageNumber = pCfg->cfghdr.hdr->PageNumber;
5314 pReq->Header.PageType = (pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
5316 if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) == MPI_CONFIG_PAGETYPE_EXTENDED) {
5317 pExtHdr = (ConfigExtendedPageHeader_t *)pCfg->cfghdr.ehdr;
5318 pReq->ExtPageLength = cpu_to_le16(pExtHdr->ExtPageLength);
5319 pReq->ExtPageType = pExtHdr->ExtPageType;
5320 pReq->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
5322 /* Page Length must be treated as a reserved field for the extended header. */
5323 pReq->Header.PageLength = 0;
5326 pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
5328 /* Add a SGE to the config request.
5331 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
5333 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
5335 if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) == MPI_CONFIG_PAGETYPE_EXTENDED) {
5336 flagsLength |= pExtHdr->ExtPageLength * 4;
5338 dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
5339 ioc->name, pReq->ExtPageType, pReq->Header.PageNumber, pReq->Action));
5342 flagsLength |= pCfg->cfghdr.hdr->PageLength * 4;
5344 dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
5345 ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
5348 mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
5350 /* Append pCfg pointer to end of mf
5352 *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
5354 /* Initalize the timer
5356 init_timer(&pCfg->timer);
5357 pCfg->timer.data = (unsigned long) ioc;
5358 pCfg->timer.function = mpt_timer_expired;
5359 pCfg->wait_done = 0;
5361 /* Set the timer; ensure 10 second minimum */
5362 if (pCfg->timeout < 10)
5363 pCfg->timer.expires = jiffies + HZ*10;
5365 pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
5367 /* Add to end of Q, set timer and then issue this command */
5368 spin_lock_irqsave(&ioc->FreeQlock, flags);
5369 list_add_tail(&pCfg->linkage, &ioc->configQ);
5370 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
5372 add_timer(&pCfg->timer);
5373 mpt_put_msg_frame(mpt_base_index, ioc, mf);
5374 wait_event(mpt_waitq, pCfg->wait_done);
5376 /* mf has been freed - do not access */
5383 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5385 * mpt_timer_expired - Callback for timer process.
5386 * Used only internal config functionality.
5387 * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
5390 mpt_timer_expired(unsigned long data)
5392 MPT_ADAPTER *ioc = (MPT_ADAPTER *) data;
5394 dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired! \n", ioc->name));
5396 /* Perform a FW reload */
5397 if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
5398 printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
5400 /* No more processing.
5401 * Hard reset clean-up will wake up
5402 * process and free all resources.
5404 dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired complete!\n", ioc->name));
5409 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5411 * mpt_ioc_reset - Base cleanup for hard reset
5412 * @ioc: Pointer to the adapter structure
5413 * @reset_phase: Indicates pre- or post-reset functionality
5415 * Remark: Frees resources with internally generated commands.
5418 mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
5421 unsigned long flags;
5423 dprintk((KERN_WARNING MYNAM
5424 ": IOC %s_reset routed to MPT base driver!\n",
5425 reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
5426 reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
5428 if (reset_phase == MPT_IOC_SETUP_RESET) {
5430 } else if (reset_phase == MPT_IOC_PRE_RESET) {
5431 /* If the internal config Q is not empty -
5432 * delete timer. MF resources will be freed when
5433 * the FIFO's are primed.
5435 spin_lock_irqsave(&ioc->FreeQlock, flags);
5436 list_for_each_entry(pCfg, &ioc->configQ, linkage)
5437 del_timer(&pCfg->timer);
5438 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
5443 /* Search the configQ for internal commands.
5444 * Flush the Q, and wake up all suspended threads.
5446 spin_lock_irqsave(&ioc->FreeQlock, flags);
5447 list_for_each_entry_safe(pCfg, pNext, &ioc->configQ, linkage) {
5448 list_del(&pCfg->linkage);
5450 pCfg->status = MPT_CONFIG_ERROR;
5451 pCfg->wait_done = 1;
5452 wake_up(&mpt_waitq);
5454 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
5457 return 1; /* currently means nothing really */
5461 #ifdef CONFIG_PROC_FS /* { */
5462 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5464 * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
5466 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5468 * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
5470 * Returns 0 for success, non-zero for failure.
5473 procmpt_create(void)
5475 struct proc_dir_entry *ent;
5477 mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
5478 if (mpt_proc_root_dir == NULL)
5481 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, mpt_proc_root_dir);
5483 ent->read_proc = procmpt_summary_read;
5485 ent = create_proc_entry("version", S_IFREG|S_IRUGO, mpt_proc_root_dir);
5487 ent->read_proc = procmpt_version_read;
5492 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5494 * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
5496 * Returns 0 for success, non-zero for failure.
5499 procmpt_destroy(void)
5501 remove_proc_entry("version", mpt_proc_root_dir);
5502 remove_proc_entry("summary", mpt_proc_root_dir);
5503 remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
5506 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5508 * procmpt_summary_read - Handle read request of a summary file
5509 * @buf: Pointer to area to write information
5510 * @start: Pointer to start pointer
5511 * @offset: Offset to start writing
5512 * @request: Amount of read data requested
5513 * @eof: Pointer to EOF integer
5516 * Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary.
5517 * Returns number of characters written to process performing the read.
5520 procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
5530 mpt_print_ioc_summary(ioc, out, &more, 0, 1);
5534 list_for_each_entry(ioc, &ioc_list, list) {
5537 mpt_print_ioc_summary(ioc, out, &more, 0, 1);
5540 if ((out-buf) >= request)
5547 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5550 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5552 * procmpt_version_read - Handle read request from /proc/mpt/version.
5553 * @buf: Pointer to area to write information
5554 * @start: Pointer to start pointer
5555 * @offset: Offset to start writing
5556 * @request: Amount of read data requested
5557 * @eof: Pointer to EOF integer
5560 * Returns number of characters written to process performing the read.
5563 procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
5566 int scsi, fc, sas, lan, ctl, targ, dmp;
5570 len = sprintf(buf, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
5571 len += sprintf(buf+len, " Fusion MPT base driver\n");
5573 scsi = fc = sas = lan = ctl = targ = dmp = 0;
5574 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
5576 if (MptCallbacks[ii]) {
5577 switch (MptDriverClass[ii]) {
5579 if (!scsi++) drvname = "SPI host";
5582 if (!fc++) drvname = "FC host";
5585 if (!sas++) drvname = "SAS host";
5588 if (!lan++) drvname = "LAN";
5591 if (!targ++) drvname = "SCSI target";
5594 if (!ctl++) drvname = "ioctl";
5599 len += sprintf(buf+len, " Fusion MPT %s driver\n", drvname);
5603 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5606 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5608 * procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info.
5609 * @buf: Pointer to area to write information
5610 * @start: Pointer to start pointer
5611 * @offset: Offset to start writing
5612 * @request: Amount of read data requested
5613 * @eof: Pointer to EOF integer
5616 * Returns number of characters written to process performing the read.
5619 procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
5621 MPT_ADAPTER *ioc = data;
5627 mpt_get_fw_exp_ver(expVer, ioc);
5629 len = sprintf(buf, "%s:", ioc->name);
5630 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
5631 len += sprintf(buf+len, " (f/w download boot flag set)");
5632 // if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
5633 // len += sprintf(buf+len, " CONFIG_CHECKSUM_FAIL!");
5635 len += sprintf(buf+len, "\n ProductID = 0x%04x (%s)\n",
5636 ioc->facts.ProductID,
5638 len += sprintf(buf+len, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
5639 if (ioc->facts.FWImageSize)
5640 len += sprintf(buf+len, " (fw_size=%d)", ioc->facts.FWImageSize);
5641 len += sprintf(buf+len, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
5642 len += sprintf(buf+len, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
5643 len += sprintf(buf+len, " EventState = 0x%02x\n", ioc->facts.EventState);
5645 len += sprintf(buf+len, " CurrentHostMfaHighAddr = 0x%08x\n",
5646 ioc->facts.CurrentHostMfaHighAddr);
5647 len += sprintf(buf+len, " CurrentSenseBufferHighAddr = 0x%08x\n",
5648 ioc->facts.CurrentSenseBufferHighAddr);
5650 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
5651 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
5653 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
5654 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
5656 * Rounding UP to nearest 4-kB boundary here...
5658 sz = (ioc->req_sz * ioc->req_depth) + 128;
5659 sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
5660 len += sprintf(buf+len, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
5661 ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
5662 len += sprintf(buf+len, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
5663 4*ioc->facts.RequestFrameSize,
5664 ioc->facts.GlobalCredits);
5666 len += sprintf(buf+len, " Frames @ 0x%p (Dma @ 0x%p)\n",
5667 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
5668 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
5669 len += sprintf(buf+len, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
5670 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
5671 len += sprintf(buf+len, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
5672 ioc->facts.CurReplyFrameSize,
5673 ioc->facts.ReplyQueueDepth);
5675 len += sprintf(buf+len, " MaxDevices = %d\n",
5676 (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
5677 len += sprintf(buf+len, " MaxBuses = %d\n", ioc->facts.MaxBuses);
5680 for (p=0; p < ioc->facts.NumberOfPorts; p++) {
5681 len += sprintf(buf+len, " PortNumber = %d (of %d)\n",
5683 ioc->facts.NumberOfPorts);
5684 if (ioc->bus_type == FC) {
5685 if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
5686 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
5687 len += sprintf(buf+len, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
5688 a[5], a[4], a[3], a[2], a[1], a[0]);
5690 len += sprintf(buf+len, " WWN = %08X%08X:%08X%08X\n",
5691 ioc->fc_port_page0[p].WWNN.High,
5692 ioc->fc_port_page0[p].WWNN.Low,
5693 ioc->fc_port_page0[p].WWPN.High,
5694 ioc->fc_port_page0[p].WWPN.Low);
5698 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
5701 #endif /* CONFIG_PROC_FS } */
5703 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5705 mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
5708 if ((ioc->facts.FWVersion.Word >> 24) == 0x0E) {
5709 sprintf(buf, " (Exp %02d%02d)",
5710 (ioc->facts.FWVersion.Word >> 16) & 0x00FF, /* Month */
5711 (ioc->facts.FWVersion.Word >> 8) & 0x1F); /* Day */
5714 if ((ioc->facts.FWVersion.Word >> 8) & 0x80)
5715 strcat(buf, " [MDBG]");
5719 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5721 * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
5722 * @ioc: Pointer to MPT_ADAPTER structure
5723 * @buffer: Pointer to buffer where IOC summary info should be written
5724 * @size: Pointer to number of bytes we wrote (set by this routine)
5725 * @len: Offset at which to start writing in buffer
5726 * @showlan: Display LAN stuff?
5728 * This routine writes (english readable) ASCII text, which represents
5729 * a summary of IOC information, to a buffer.
5732 mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
5737 mpt_get_fw_exp_ver(expVer, ioc);
5740 * Shorter summary of attached ioc's...
5742 y = sprintf(buffer+len, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
5745 MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
5746 ioc->facts.FWVersion.Word,
5748 ioc->facts.NumberOfPorts,
5751 if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
5752 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
5753 y += sprintf(buffer+len+y, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
5754 a[5], a[4], a[3], a[2], a[1], a[0]);
5757 y += sprintf(buffer+len+y, ", IRQ=%d", ioc->pci_irq);
5760 y += sprintf(buffer+len+y, " (disabled)");
5762 y += sprintf(buffer+len+y, "\n");
5767 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5771 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5773 * mpt_HardResetHandler - Generic reset handler
5774 * @ioc: Pointer to MPT_ADAPTER structure
5775 * @sleepFlag: Indicates if sleep or schedule must be called.
5777 * Issues SCSI Task Management call based on input arg values.
5778 * If TaskMgmt fails, returns associated SCSI request.
5780 * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
5781 * or a non-interrupt thread. In the former, must not call schedule().
5783 * Note: A return of -1 is a FATAL error case, as it means a
5784 * FW reload/initialization failed.
5786 * Returns 0 for SUCCESS or -1 if FAILED.
5789 mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
5792 unsigned long flags;
5794 dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name));
5796 printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
5797 printk("MF count 0x%x !\n", ioc->mfcnt);
5800 /* Reset the adapter. Prevent more than 1 call to
5801 * mpt_do_ioc_recovery at any instant in time.
5803 spin_lock_irqsave(&ioc->diagLock, flags);
5804 if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)){
5805 spin_unlock_irqrestore(&ioc->diagLock, flags);
5808 ioc->diagPending = 1;
5810 spin_unlock_irqrestore(&ioc->diagLock, flags);
5812 /* FIXME: If do_ioc_recovery fails, repeat....
5815 /* The SCSI driver needs to adjust timeouts on all current
5816 * commands prior to the diagnostic reset being issued.
5817 * Prevents timeouts occurring during a diagnostic reset...very bad.
5818 * For all other protocol drivers, this is a no-op.
5824 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
5825 if (MptResetHandlers[ii]) {
5826 dtmprintk((MYIOC_s_INFO_FMT "Calling IOC reset_setup handler #%d\n",
5828 r += mpt_signal_reset(ii, ioc, MPT_IOC_SETUP_RESET);
5830 dtmprintk((MYIOC_s_INFO_FMT "Calling alt-%s setup reset handler #%d\n",
5831 ioc->name, ioc->alt_ioc->name, ii));
5832 r += mpt_signal_reset(ii, ioc->alt_ioc, MPT_IOC_SETUP_RESET);
5838 if ((rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag)) != 0) {
5839 printk(KERN_WARNING MYNAM ": WARNING - (%d) Cannot recover %s\n",
5844 ioc->alt_ioc->reload_fw = 0;
5846 spin_lock_irqsave(&ioc->diagLock, flags);
5847 ioc->diagPending = 0;
5849 ioc->alt_ioc->diagPending = 0;
5850 spin_unlock_irqrestore(&ioc->diagLock, flags);
5852 dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler rc = %d!\n", ioc->name, rc));
5857 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5859 EventDescriptionStr(u8 event, u32 evData0, char *evStr)
5864 case MPI_EVENT_NONE:
5867 case MPI_EVENT_LOG_DATA:
5870 case MPI_EVENT_STATE_CHANGE:
5871 ds = "State Change";
5873 case MPI_EVENT_UNIT_ATTENTION:
5874 ds = "Unit Attention";
5876 case MPI_EVENT_IOC_BUS_RESET:
5877 ds = "IOC Bus Reset";
5879 case MPI_EVENT_EXT_BUS_RESET:
5880 ds = "External Bus Reset";
5882 case MPI_EVENT_RESCAN:
5883 ds = "Bus Rescan Event";
5885 case MPI_EVENT_LINK_STATUS_CHANGE:
5886 if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
5887 ds = "Link Status(FAILURE) Change";
5889 ds = "Link Status(ACTIVE) Change";
5891 case MPI_EVENT_LOOP_STATE_CHANGE:
5892 if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
5893 ds = "Loop State(LIP) Change";
5894 else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
5895 ds = "Loop State(LPE) Change"; /* ??? */
5897 ds = "Loop State(LPB) Change"; /* ??? */
5899 case MPI_EVENT_LOGOUT:
5902 case MPI_EVENT_EVENT_CHANGE:
5908 case MPI_EVENT_INTEGRATED_RAID:
5910 u8 ReasonCode = (u8)(evData0 >> 16);
5911 switch (ReasonCode) {
5912 case MPI_EVENT_RAID_RC_VOLUME_CREATED :
5913 ds = "Integrated Raid: Volume Created";
5915 case MPI_EVENT_RAID_RC_VOLUME_DELETED :
5916 ds = "Integrated Raid: Volume Deleted";
5918 case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED :
5919 ds = "Integrated Raid: Volume Settings Changed";
5921 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED :
5922 ds = "Integrated Raid: Volume Status Changed";
5924 case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED :
5925 ds = "Integrated Raid: Volume Physdisk Changed";
5927 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED :
5928 ds = "Integrated Raid: Physdisk Created";
5930 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED :
5931 ds = "Integrated Raid: Physdisk Deleted";
5933 case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED :
5934 ds = "Integrated Raid: Physdisk Settings Changed";
5936 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED :
5937 ds = "Integrated Raid: Physdisk Status Changed";
5939 case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED :
5940 ds = "Integrated Raid: Domain Validation Needed";
5942 case MPI_EVENT_RAID_RC_SMART_DATA :
5943 ds = "Integrated Raid; Smart Data";
5945 case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED :
5946 ds = "Integrated Raid: Replace Action Started";
5949 ds = "Integrated Raid";
5954 case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE:
5955 ds = "SCSI Device Status Change";
5957 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
5959 u8 id = (u8)(evData0);
5960 u8 channel = (u8)(evData0 >> 8);
5961 u8 ReasonCode = (u8)(evData0 >> 16);
5962 switch (ReasonCode) {
5963 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
5964 snprintf(evStr, EVENT_DESCR_STR_SZ,
5965 "SAS Device Status Change: Added: "
5966 "id=%d channel=%d", id, channel);
5968 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
5969 snprintf(evStr, EVENT_DESCR_STR_SZ,
5970 "SAS Device Status Change: Deleted: "
5971 "id=%d channel=%d", id, channel);
5973 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5974 snprintf(evStr, EVENT_DESCR_STR_SZ,
5975 "SAS Device Status Change: SMART Data: "
5976 "id=%d channel=%d", id, channel);
5978 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
5979 snprintf(evStr, EVENT_DESCR_STR_SZ,
5980 "SAS Device Status Change: No Persistancy: "
5981 "id=%d channel=%d", id, channel);
5983 case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5984 snprintf(evStr, EVENT_DESCR_STR_SZ,
5985 "SAS Device Status Change: Unsupported Device "
5986 "Discovered : id=%d channel=%d", id, channel);
5988 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5989 snprintf(evStr, EVENT_DESCR_STR_SZ,
5990 "SAS Device Status Change: Internal Device "
5991 "Reset : id=%d channel=%d", id, channel);
5993 case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5994 snprintf(evStr, EVENT_DESCR_STR_SZ,
5995 "SAS Device Status Change: Internal Task "
5996 "Abort : id=%d channel=%d", id, channel);
5998 case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5999 snprintf(evStr, EVENT_DESCR_STR_SZ,
6000 "SAS Device Status Change: Internal Abort "
6001 "Task Set : id=%d channel=%d", id, channel);
6003 case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
6004 snprintf(evStr, EVENT_DESCR_STR_SZ,
6005 "SAS Device Status Change: Internal Clear "
6006 "Task Set : id=%d channel=%d", id, channel);
6008 case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
6009 snprintf(evStr, EVENT_DESCR_STR_SZ,
6010 "SAS Device Status Change: Internal Query "
6011 "Task : id=%d channel=%d", id, channel);
6014 snprintf(evStr, EVENT_DESCR_STR_SZ,
6015 "SAS Device Status Change: Unknown: "
6016 "id=%d channel=%d", id, channel);
6021 case MPI_EVENT_ON_BUS_TIMER_EXPIRED:
6022 ds = "Bus Timer Expired";
6024 case MPI_EVENT_QUEUE_FULL:
6026 u16 curr_depth = (u16)(evData0 >> 16);
6027 u8 channel = (u8)(evData0 >> 8);
6028 u8 id = (u8)(evData0);
6030 snprintf(evStr, EVENT_DESCR_STR_SZ,
6031 "Queue Full: channel=%d id=%d depth=%d",
6032 channel, id, curr_depth);
6035 case MPI_EVENT_SAS_SES:
6036 ds = "SAS SES Event";
6038 case MPI_EVENT_PERSISTENT_TABLE_FULL:
6039 ds = "Persistent Table Full";
6041 case MPI_EVENT_SAS_PHY_LINK_STATUS:
6043 u8 LinkRates = (u8)(evData0 >> 8);
6044 u8 PhyNumber = (u8)(evData0);
6045 LinkRates = (LinkRates & MPI_EVENT_SAS_PLS_LR_CURRENT_MASK) >>
6046 MPI_EVENT_SAS_PLS_LR_CURRENT_SHIFT;
6047 switch (LinkRates) {
6048 case MPI_EVENT_SAS_PLS_LR_RATE_UNKNOWN:
6049 snprintf(evStr, EVENT_DESCR_STR_SZ,
6050 "SAS PHY Link Status: Phy=%d:"
6051 " Rate Unknown",PhyNumber);
6053 case MPI_EVENT_SAS_PLS_LR_RATE_PHY_DISABLED:
6054 snprintf(evStr, EVENT_DESCR_STR_SZ,
6055 "SAS PHY Link Status: Phy=%d:"
6056 " Phy Disabled",PhyNumber);
6058 case MPI_EVENT_SAS_PLS_LR_RATE_FAILED_SPEED_NEGOTIATION:
6059 snprintf(evStr, EVENT_DESCR_STR_SZ,
6060 "SAS PHY Link Status: Phy=%d:"
6061 " Failed Speed Nego",PhyNumber);
6063 case MPI_EVENT_SAS_PLS_LR_RATE_SATA_OOB_COMPLETE:
6064 snprintf(evStr, EVENT_DESCR_STR_SZ,
6065 "SAS PHY Link Status: Phy=%d:"
6066 " Sata OOB Completed",PhyNumber);
6068 case MPI_EVENT_SAS_PLS_LR_RATE_1_5:
6069 snprintf(evStr, EVENT_DESCR_STR_SZ,
6070 "SAS PHY Link Status: Phy=%d:"
6071 " Rate 1.5 Gbps",PhyNumber);
6073 case MPI_EVENT_SAS_PLS_LR_RATE_3_0:
6074 snprintf(evStr, EVENT_DESCR_STR_SZ,
6075 "SAS PHY Link Status: Phy=%d:"
6076 " Rate 3.0 Gpbs",PhyNumber);
6079 snprintf(evStr, EVENT_DESCR_STR_SZ,
6080 "SAS PHY Link Status: Phy=%d", PhyNumber);
6085 case MPI_EVENT_SAS_DISCOVERY_ERROR:
6086 ds = "SAS Discovery Error";
6088 case MPI_EVENT_IR_RESYNC_UPDATE:
6090 u8 resync_complete = (u8)(evData0 >> 16);
6091 snprintf(evStr, EVENT_DESCR_STR_SZ,
6092 "IR Resync Update: Complete = %d:",resync_complete);
6097 u8 ReasonCode = (u8)(evData0 >> 16);
6098 switch (ReasonCode) {
6099 case MPI_EVENT_IR2_RC_LD_STATE_CHANGED:
6100 ds = "IR2: LD State Changed";
6102 case MPI_EVENT_IR2_RC_PD_STATE_CHANGED:
6103 ds = "IR2: PD State Changed";
6105 case MPI_EVENT_IR2_RC_BAD_BLOCK_TABLE_FULL:
6106 ds = "IR2: Bad Block Table Full";
6108 case MPI_EVENT_IR2_RC_PD_INSERTED:
6109 ds = "IR2: PD Inserted";
6111 case MPI_EVENT_IR2_RC_PD_REMOVED:
6112 ds = "IR2: PD Removed";
6114 case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
6115 ds = "IR2: Foreign CFG Detected";
6117 case MPI_EVENT_IR2_RC_REBUILD_MEDIUM_ERROR:
6118 ds = "IR2: Rebuild Medium Error";
6126 case MPI_EVENT_SAS_DISCOVERY:
6129 ds = "SAS Discovery: Start";
6131 ds = "SAS Discovery: Stop";
6134 case MPI_EVENT_LOG_ENTRY_ADDED:
6135 ds = "SAS Log Entry Added";
6138 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
6140 u8 phy_num = (u8)(evData0);
6141 u8 port_num = (u8)(evData0 >> 8);
6142 u8 port_width = (u8)(evData0 >> 16);
6143 u8 primative = (u8)(evData0 >> 24);
6144 snprintf(evStr, EVENT_DESCR_STR_SZ,
6145 "SAS Broadcase Primative: phy=%d port=%d "
6146 "width=%d primative=0x%02x",
6147 phy_num, port_num, port_width, primative);
6151 case MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
6153 u8 reason = (u8)(evData0);
6154 u8 port_num = (u8)(evData0 >> 8);
6155 u16 handle = le16_to_cpu(evData0 >> 16);
6157 snprintf(evStr, EVENT_DESCR_STR_SZ,
6158 "SAS Initiator Device Status Change: reason=0x%02x "
6159 "port=%d handle=0x%04x",
6160 reason, port_num, handle);
6164 case MPI_EVENT_SAS_INIT_TABLE_OVERFLOW:
6166 u8 max_init = (u8)(evData0);
6167 u8 current_init = (u8)(evData0 >> 8);
6169 snprintf(evStr, EVENT_DESCR_STR_SZ,
6170 "SAS Initiator Device Table Overflow: max initiators=%02d "
6171 "current initators=%02d",
6172 max_init, current_init);
6175 case MPI_EVENT_SAS_SMP_ERROR:
6177 u8 status = (u8)(evData0);
6178 u8 port_num = (u8)(evData0 >> 8);
6179 u8 result = (u8)(evData0 >> 16);
6181 if (status == MPI_EVENT_SAS_SMP_FUNCTION_RESULT_VALID)
6182 snprintf(evStr, EVENT_DESCR_STR_SZ,
6183 "SAS SMP Error: port=%d result=0x%02x",
6185 else if (status == MPI_EVENT_SAS_SMP_CRC_ERROR)
6186 snprintf(evStr, EVENT_DESCR_STR_SZ,
6187 "SAS SMP Error: port=%d : CRC Error",
6189 else if (status == MPI_EVENT_SAS_SMP_TIMEOUT)
6190 snprintf(evStr, EVENT_DESCR_STR_SZ,
6191 "SAS SMP Error: port=%d : Timeout",
6193 else if (status == MPI_EVENT_SAS_SMP_NO_DESTINATION)
6194 snprintf(evStr, EVENT_DESCR_STR_SZ,
6195 "SAS SMP Error: port=%d : No Destination",
6197 else if (status == MPI_EVENT_SAS_SMP_BAD_DESTINATION)
6198 snprintf(evStr, EVENT_DESCR_STR_SZ,
6199 "SAS SMP Error: port=%d : Bad Destination",
6202 snprintf(evStr, EVENT_DESCR_STR_SZ,
6203 "SAS SMP Error: port=%d : status=0x%02x",
6209 * MPT base "custom" events may be added here...
6216 strncpy(evStr, ds, EVENT_DESCR_STR_SZ);
6219 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6221 * ProcessEventNotification - Route EventNotificationReply to all event handlers
6222 * @ioc: Pointer to MPT_ADAPTER structure
6223 * @pEventReply: Pointer to EventNotification reply frame
6224 * @evHandlers: Pointer to integer, number of event handlers
6226 * Routes a received EventNotificationReply to all currently registered
6228 * Returns sum of event handlers return values.
6231 ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
6239 char evStr[EVENT_DESCR_STR_SZ];
6243 * Do platform normalization of values
6245 event = le32_to_cpu(pEventReply->Event) & 0xFF;
6246 // evCtx = le32_to_cpu(pEventReply->EventContext);
6247 evDataLen = le16_to_cpu(pEventReply->EventDataLength);
6249 evData0 = le32_to_cpu(pEventReply->Data[0]);
6252 EventDescriptionStr(event, evData0, evStr);
6253 devtprintk((MYIOC_s_INFO_FMT "MPT event:(%02Xh) : %s\n",
6258 #if defined(MPT_DEBUG) || defined(MPT_DEBUG_VERBOSE_EVENTS)
6259 printk(KERN_INFO MYNAM ": Event data:\n" KERN_INFO);
6260 for (ii = 0; ii < evDataLen; ii++)
6261 printk(" %08x", le32_to_cpu(pEventReply->Data[ii]));
6266 * Do general / base driver event processing
6269 case MPI_EVENT_EVENT_CHANGE: /* 0A */
6271 u8 evState = evData0 & 0xFF;
6273 /* CHECKME! What if evState unexpectedly says OFF (0)? */
6275 /* Update EventState field in cached IocFacts */
6276 if (ioc->facts.Function) {
6277 ioc->facts.EventState = evState;
6281 case MPI_EVENT_INTEGRATED_RAID:
6282 mptbase_raid_process_event_data(ioc,
6283 (MpiEventDataRaid_t *)pEventReply->Data);
6290 * Should this event be logged? Events are written sequentially.
6291 * When buffer is full, start again at the top.
6293 if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
6296 idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
6298 ioc->events[idx].event = event;
6299 ioc->events[idx].eventContext = ioc->eventContext;
6301 for (ii = 0; ii < 2; ii++) {
6303 ioc->events[idx].data[ii] = le32_to_cpu(pEventReply->Data[ii]);
6305 ioc->events[idx].data[ii] = 0;
6308 ioc->eventContext++;
6313 * Call each currently registered protocol event handler.
6315 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
6316 if (MptEvHandlers[ii]) {
6317 devtverboseprintk((MYIOC_s_INFO_FMT "Routing Event to event handler #%d\n",
6319 r += (*(MptEvHandlers[ii]))(ioc, pEventReply);
6323 /* FIXME? Examine results here? */
6326 * If needed, send (a single) EventAck.
6328 if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
6329 devtverboseprintk((MYIOC_s_WARN_FMT
6330 "EventAck required\n",ioc->name));
6331 if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
6332 devtverboseprintk((MYIOC_s_WARN_FMT "SendEventAck returned %d\n",
6337 *evHandlers = handlers;
6341 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6343 * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
6344 * @ioc: Pointer to MPT_ADAPTER structure
6345 * @log_info: U32 LogInfo reply word from the IOC
6347 * Refer to lsi/mpi_log_fc.h.
6350 mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
6352 static char *subcl_str[8] = {
6353 "FCP Initiator", "FCP Target", "LAN", "MPI Message Layer",
6354 "FC Link", "Context Manager", "Invalid Field Offset", "State Change Info"
6356 u8 subcl = (log_info >> 24) & 0x7;
6358 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): SubCl={%s}\n",
6359 ioc->name, log_info, subcl_str[subcl]);
6362 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6364 * mpt_spi_log_info - Log information returned from SCSI Parallel IOC.
6365 * @ioc: Pointer to MPT_ADAPTER structure
6366 * @mr: Pointer to MPT reply frame
6367 * @log_info: U32 LogInfo word from the IOC
6369 * Refer to lsi/sp_log.h.
6372 mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
6374 u32 info = log_info & 0x00FF0000;
6375 char *desc = "unknown";
6379 desc = "bug! MID not found";
6380 if (ioc->reload_fw == 0)
6385 desc = "Parity Error";
6389 desc = "ASYNC Outbound Overrun";
6393 desc = "SYNC Offset Error";
6401 desc = "Msg In Overflow";
6409 desc = "Outbound DMA Overrun";
6413 desc = "Task Management";
6417 desc = "Device Problem";
6421 desc = "Invalid Phase Change";
6425 desc = "Untagged Table Size";
6430 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
6433 /* strings for sas loginfo */
6434 static char *originator_str[] = {
6439 static char *iop_code_str[] = {
6441 "Invalid SAS Address", /* 01h */
6443 "Invalid Page", /* 03h */
6444 "Diag Message Error", /* 04h */
6445 "Task Terminated", /* 05h */
6446 "Enclosure Management", /* 06h */
6447 "Target Mode" /* 07h */
6449 static char *pl_code_str[] = {
6451 "Open Failure", /* 01h */
6452 "Invalid Scatter Gather List", /* 02h */
6453 "Wrong Relative Offset or Frame Length", /* 03h */
6454 "Frame Transfer Error", /* 04h */
6455 "Transmit Frame Connected Low", /* 05h */
6456 "SATA Non-NCQ RW Error Bit Set", /* 06h */
6457 "SATA Read Log Receive Data Error", /* 07h */
6458 "SATA NCQ Fail All Commands After Error", /* 08h */
6459 "SATA Error in Receive Set Device Bit FIS", /* 09h */
6460 "Receive Frame Invalid Message", /* 0Ah */
6461 "Receive Context Message Valid Error", /* 0Bh */
6462 "Receive Frame Current Frame Error", /* 0Ch */
6463 "SATA Link Down", /* 0Dh */
6464 "Discovery SATA Init W IOS", /* 0Eh */
6465 "Config Invalid Page", /* 0Fh */
6466 "Discovery SATA Init Timeout", /* 10h */
6469 "IO Not Yet Executed", /* 13h */
6470 "IO Executed", /* 14h */
6471 "Persistent Reservation Out Not Affiliation "
6473 "Open Transmit DMA Abort", /* 16h */
6474 "IO Device Missing Delay Retry", /* 17h */
6475 "IO Cancelled Due to Recieve Error", /* 18h */
6483 "Enclosure Management" /* 20h */
6485 static char *ir_code_str[] = {
6486 "Raid Action Error", /* 00h */
6496 static char *raid_sub_code_str[] = {
6498 "Volume Creation Failed: Data Passed too "
6500 "Volume Creation Failed: Duplicate Volumes "
6501 "Attempted", /* 02h */
6502 "Volume Creation Failed: Max Number "
6503 "Supported Volumes Exceeded", /* 03h */
6504 "Volume Creation Failed: DMA Error", /* 04h */
6505 "Volume Creation Failed: Invalid Volume Type", /* 05h */
6506 "Volume Creation Failed: Error Reading "
6507 "MFG Page 4", /* 06h */
6508 "Volume Creation Failed: Creating Internal "
6509 "Structures", /* 07h */
6518 "Activation failed: Already Active Volume", /* 10h */
6519 "Activation failed: Unsupported Volume Type", /* 11h */
6520 "Activation failed: Too Many Active Volumes", /* 12h */
6521 "Activation failed: Volume ID in Use", /* 13h */
6522 "Activation failed: Reported Failure", /* 14h */
6523 "Activation failed: Importing a Volume", /* 15h */
6534 "Phys Disk failed: Too Many Phys Disks", /* 20h */
6535 "Phys Disk failed: Data Passed too Large", /* 21h */
6536 "Phys Disk failed: DMA Error", /* 22h */
6537 "Phys Disk failed: Invalid <channel:id>", /* 23h */
6538 "Phys Disk failed: Creating Phys Disk Config "
6551 "Compatibility Error: IR Disabled", /* 30h */
6552 "Compatibility Error: Inquiry Comand Failed", /* 31h */
6553 "Compatibility Error: Device not Direct Access "
6554 "Device ", /* 32h */
6555 "Compatibility Error: Removable Device Found", /* 33h */
6556 "Compatibility Error: Device SCSI Version not "
6557 "2 or Higher", /* 34h */
6558 "Compatibility Error: SATA Device, 48 BIT LBA "
6559 "not Supported", /* 35h */
6560 "Compatibility Error: Device doesn't have "
6561 "512 Byte Block Sizes", /* 36h */
6562 "Compatibility Error: Volume Type Check Failed", /* 37h */
6563 "Compatibility Error: Volume Type is "
6564 "Unsupported by FW", /* 38h */
6565 "Compatibility Error: Disk Drive too Small for "
6566 "use in Volume", /* 39h */
6567 "Compatibility Error: Phys Disk for Create "
6568 "Volume not Found", /* 3Ah */
6569 "Compatibility Error: Too Many or too Few "
6570 "Disks for Volume Type", /* 3Bh */
6571 "Compatibility Error: Disk stripe Sizes "
6572 "Must be 64KB", /* 3Ch */
6573 "Compatibility Error: IME Size Limited to < 2TB", /* 3Dh */
6576 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6578 * mpt_sas_log_info - Log information returned from SAS IOC.
6579 * @ioc: Pointer to MPT_ADAPTER structure
6580 * @log_info: U32 LogInfo reply word from the IOC
6582 * Refer to lsi/mpi_log_sas.h.
6585 mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info)
6587 union loginfo_type {
6596 union loginfo_type sas_loginfo;
6597 char *originator_desc = NULL;
6598 char *code_desc = NULL;
6599 char *sub_code_desc = NULL;
6601 sas_loginfo.loginfo = log_info;
6602 if ((sas_loginfo.dw.bus_type != 3 /*SAS*/) &&
6603 (sas_loginfo.dw.originator < sizeof(originator_str)/sizeof(char*)))
6606 originator_desc = originator_str[sas_loginfo.dw.originator];
6608 switch (sas_loginfo.dw.originator) {
6611 if (sas_loginfo.dw.code <
6612 sizeof(iop_code_str)/sizeof(char*))
6613 code_desc = iop_code_str[sas_loginfo.dw.code];
6616 if (sas_loginfo.dw.code <
6617 sizeof(pl_code_str)/sizeof(char*))
6618 code_desc = pl_code_str[sas_loginfo.dw.code];
6621 if (sas_loginfo.dw.code >=
6622 sizeof(ir_code_str)/sizeof(char*))
6624 code_desc = ir_code_str[sas_loginfo.dw.code];
6625 if (sas_loginfo.dw.subcode >=
6626 sizeof(raid_sub_code_str)/sizeof(char*))
6628 if (sas_loginfo.dw.code == 0)
6630 raid_sub_code_str[sas_loginfo.dw.subcode];
6636 if (sub_code_desc != NULL)
6637 printk(MYIOC_s_INFO_FMT
6638 "LogInfo(0x%08x): Originator={%s}, Code={%s},"
6640 ioc->name, log_info, originator_desc, code_desc,
6642 else if (code_desc != NULL)
6643 printk(MYIOC_s_INFO_FMT
6644 "LogInfo(0x%08x): Originator={%s}, Code={%s},"
6645 " SubCode(0x%04x)\n",
6646 ioc->name, log_info, originator_desc, code_desc,
6647 sas_loginfo.dw.subcode);
6649 printk(MYIOC_s_INFO_FMT
6650 "LogInfo(0x%08x): Originator={%s}, Code=(0x%02x),"
6651 " SubCode(0x%04x)\n",
6652 ioc->name, log_info, originator_desc,
6653 sas_loginfo.dw.code, sas_loginfo.dw.subcode);
6656 #ifdef MPT_DEBUG_REPLY
6657 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6659 * mpt_iocstatus_info_config - IOCSTATUS information for config pages
6660 * @ioc: Pointer to MPT_ADAPTER structure
6661 * @ioc_status: U32 IOCStatus word from IOC
6662 * @mf: Pointer to MPT request frame
6664 * Refer to lsi/mpi.h.
6667 mpt_iocstatus_info_config(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
6669 Config_t *pReq = (Config_t *)mf;
6670 char extend_desc[EVENT_DESCR_STR_SZ];
6675 if (pReq->Header.PageType == MPI_CONFIG_PAGETYPE_EXTENDED)
6676 page_type = pReq->ExtPageType;
6678 page_type = pReq->Header.PageType;
6681 * ignore invalid page messages for GET_NEXT_HANDLE
6683 form = le32_to_cpu(pReq->PageAddress);
6684 if (ioc_status == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
6685 if (page_type == MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE ||
6686 page_type == MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER ||
6687 page_type == MPI_CONFIG_EXTPAGETYPE_ENCLOSURE) {
6688 if ((form >> MPI_SAS_DEVICE_PGAD_FORM_SHIFT) ==
6689 MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE)
6692 if (page_type == MPI_CONFIG_PAGETYPE_FC_DEVICE)
6693 if ((form & MPI_FC_DEVICE_PGAD_FORM_MASK) ==
6694 MPI_FC_DEVICE_PGAD_FORM_NEXT_DID)
6698 snprintf(extend_desc, EVENT_DESCR_STR_SZ,
6699 "type=%02Xh, page=%02Xh, action=%02Xh, form=%08Xh",
6700 page_type, pReq->Header.PageNumber, pReq->Action, form);
6702 switch (ioc_status) {
6704 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
6705 desc = "Config Page Invalid Action";
6708 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
6709 desc = "Config Page Invalid Type";
6712 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
6713 desc = "Config Page Invalid Page";
6716 case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
6717 desc = "Config Page Invalid Data";
6720 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
6721 desc = "Config Page No Defaults";
6724 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
6725 desc = "Config Page Can't Commit";
6732 printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04X): %s: %s\n",
6733 ioc->name, ioc_status, desc, extend_desc);
6737 * mpt_iocstatus_info - IOCSTATUS information returned from IOC.
6738 * @ioc: Pointer to MPT_ADAPTER structure
6739 * @ioc_status: U32 IOCStatus word from IOC
6740 * @mf: Pointer to MPT request frame
6742 * Refer to lsi/mpi.h.
6745 mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
6747 u32 status = ioc_status & MPI_IOCSTATUS_MASK;
6752 /****************************************************************************/
6753 /* Common IOCStatus values for all replies */
6754 /****************************************************************************/
6756 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
6757 desc = "Invalid Function";
6760 case MPI_IOCSTATUS_BUSY: /* 0x0002 */
6764 case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
6765 desc = "Invalid SGL";
6768 case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
6769 desc = "Internal Error";
6772 case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
6776 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
6777 desc = "Insufficient Resources";
6780 case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
6781 desc = "Invalid Field";
6784 case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
6785 desc = "Invalid State";
6788 /****************************************************************************/
6789 /* Config IOCStatus values */
6790 /****************************************************************************/
6792 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
6793 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
6794 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
6795 case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
6796 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
6797 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
6798 mpt_iocstatus_info_config(ioc, status, mf);
6801 /****************************************************************************/
6802 /* SCSIIO Reply (SPI, FCP, SAS) initiator values */
6804 /* Look at mptscsih_iocstatus_info_scsiio in mptscsih.c */
6806 /****************************************************************************/
6808 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
6809 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
6810 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
6811 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
6812 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
6813 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
6814 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
6815 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
6816 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
6817 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
6818 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
6819 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
6820 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
6823 /****************************************************************************/
6824 /* SCSI Target values */
6825 /****************************************************************************/
6827 case MPI_IOCSTATUS_TARGET_PRIORITY_IO: /* 0x0060 */
6828 desc = "Target: Priority IO";
6831 case MPI_IOCSTATUS_TARGET_INVALID_PORT: /* 0x0061 */
6832 desc = "Target: Invalid Port";
6835 case MPI_IOCSTATUS_TARGET_INVALID_IO_INDEX: /* 0x0062 */
6836 desc = "Target Invalid IO Index:";
6839 case MPI_IOCSTATUS_TARGET_ABORTED: /* 0x0063 */
6840 desc = "Target: Aborted";
6843 case MPI_IOCSTATUS_TARGET_NO_CONN_RETRYABLE: /* 0x0064 */
6844 desc = "Target: No Conn Retryable";
6847 case MPI_IOCSTATUS_TARGET_NO_CONNECTION: /* 0x0065 */
6848 desc = "Target: No Connection";
6851 case MPI_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH: /* 0x006A */
6852 desc = "Target: Transfer Count Mismatch";
6855 case MPI_IOCSTATUS_TARGET_STS_DATA_NOT_SENT: /* 0x006B */
6856 desc = "Target: STS Data not Sent";
6859 case MPI_IOCSTATUS_TARGET_DATA_OFFSET_ERROR: /* 0x006D */
6860 desc = "Target: Data Offset Error";
6863 case MPI_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA: /* 0x006E */
6864 desc = "Target: Too Much Write Data";
6867 case MPI_IOCSTATUS_TARGET_IU_TOO_SHORT: /* 0x006F */
6868 desc = "Target: IU Too Short";
6871 case MPI_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT: /* 0x0070 */
6872 desc = "Target: ACK NAK Timeout";
6875 case MPI_IOCSTATUS_TARGET_NAK_RECEIVED: /* 0x0071 */
6876 desc = "Target: Nak Received";
6879 /****************************************************************************/
6880 /* Fibre Channel Direct Access values */
6881 /****************************************************************************/
6883 case MPI_IOCSTATUS_FC_ABORTED: /* 0x0066 */
6884 desc = "FC: Aborted";
6887 case MPI_IOCSTATUS_FC_RX_ID_INVALID: /* 0x0067 */
6888 desc = "FC: RX ID Invalid";
6891 case MPI_IOCSTATUS_FC_DID_INVALID: /* 0x0068 */
6892 desc = "FC: DID Invalid";
6895 case MPI_IOCSTATUS_FC_NODE_LOGGED_OUT: /* 0x0069 */
6896 desc = "FC: Node Logged Out";
6899 case MPI_IOCSTATUS_FC_EXCHANGE_CANCELED: /* 0x006C */
6900 desc = "FC: Exchange Canceled";
6903 /****************************************************************************/
6905 /****************************************************************************/
6907 case MPI_IOCSTATUS_LAN_DEVICE_NOT_FOUND: /* 0x0080 */
6908 desc = "LAN: Device not Found";
6911 case MPI_IOCSTATUS_LAN_DEVICE_FAILURE: /* 0x0081 */
6912 desc = "LAN: Device Failure";
6915 case MPI_IOCSTATUS_LAN_TRANSMIT_ERROR: /* 0x0082 */
6916 desc = "LAN: Transmit Error";
6919 case MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED: /* 0x0083 */
6920 desc = "LAN: Transmit Aborted";
6923 case MPI_IOCSTATUS_LAN_RECEIVE_ERROR: /* 0x0084 */
6924 desc = "LAN: Receive Error";
6927 case MPI_IOCSTATUS_LAN_RECEIVE_ABORTED: /* 0x0085 */
6928 desc = "LAN: Receive Aborted";
6931 case MPI_IOCSTATUS_LAN_PARTIAL_PACKET: /* 0x0086 */
6932 desc = "LAN: Partial Packet";
6935 case MPI_IOCSTATUS_LAN_CANCELED: /* 0x0087 */
6936 desc = "LAN: Canceled";
6939 /****************************************************************************/
6940 /* Serial Attached SCSI values */
6941 /****************************************************************************/
6943 case MPI_IOCSTATUS_SAS_SMP_REQUEST_FAILED: /* 0x0090 */
6944 desc = "SAS: SMP Request Failed";
6947 case MPI_IOCSTATUS_SAS_SMP_DATA_OVERRUN: /* 0x0090 */
6948 desc = "SAS: SMP Data Overrun";
6959 printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04X): %s\n", ioc->name, status, desc);
6963 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6964 EXPORT_SYMBOL(mpt_attach);
6965 EXPORT_SYMBOL(mpt_detach);
6967 EXPORT_SYMBOL(mpt_resume);
6968 EXPORT_SYMBOL(mpt_suspend);
6970 EXPORT_SYMBOL(ioc_list);
6971 EXPORT_SYMBOL(mpt_proc_root_dir);
6972 EXPORT_SYMBOL(mpt_register);
6973 EXPORT_SYMBOL(mpt_deregister);
6974 EXPORT_SYMBOL(mpt_event_register);
6975 EXPORT_SYMBOL(mpt_event_deregister);
6976 EXPORT_SYMBOL(mpt_reset_register);
6977 EXPORT_SYMBOL(mpt_reset_deregister);
6978 EXPORT_SYMBOL(mpt_device_driver_register);
6979 EXPORT_SYMBOL(mpt_device_driver_deregister);
6980 EXPORT_SYMBOL(mpt_get_msg_frame);
6981 EXPORT_SYMBOL(mpt_put_msg_frame);
6982 EXPORT_SYMBOL(mpt_free_msg_frame);
6983 EXPORT_SYMBOL(mpt_add_sge);
6984 EXPORT_SYMBOL(mpt_send_handshake_request);
6985 EXPORT_SYMBOL(mpt_verify_adapter);
6986 EXPORT_SYMBOL(mpt_GetIocState);
6987 EXPORT_SYMBOL(mpt_print_ioc_summary);
6988 EXPORT_SYMBOL(mpt_lan_index);
6989 EXPORT_SYMBOL(mpt_stm_index);
6990 EXPORT_SYMBOL(mpt_HardResetHandler);
6991 EXPORT_SYMBOL(mpt_config);
6992 EXPORT_SYMBOL(mpt_findImVolumes);
6993 EXPORT_SYMBOL(mpt_alloc_fw_memory);
6994 EXPORT_SYMBOL(mpt_free_fw_memory);
6995 EXPORT_SYMBOL(mptbase_sas_persist_operation);
6996 EXPORT_SYMBOL(mpt_raid_phys_disk_pg0);
6998 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
7000 * fusion_init - Fusion MPT base driver initialization routine.
7002 * Returns 0 for success, non-zero for failure.
7009 show_mptmod_ver(my_NAME, my_VERSION);
7010 printk(KERN_INFO COPYRIGHT "\n");
7012 for (i = 0; i < MPT_MAX_PROTOCOL_DRIVERS; i++) {
7013 MptCallbacks[i] = NULL;
7014 MptDriverClass[i] = MPTUNKNOWN_DRIVER;
7015 MptEvHandlers[i] = NULL;
7016 MptResetHandlers[i] = NULL;
7019 /* Register ourselves (mptbase) in order to facilitate
7020 * EventNotification handling.
7022 mpt_base_index = mpt_register(mpt_base_reply, MPTBASE_DRIVER);
7024 /* Register for hard reset handling callbacks.
7026 if (mpt_reset_register(mpt_base_index, mpt_ioc_reset) == 0) {
7027 dprintk((KERN_INFO MYNAM ": Register for IOC reset notification\n"));
7032 #ifdef CONFIG_PROC_FS
7033 (void) procmpt_create();
7038 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
7040 * fusion_exit - Perform driver unload cleanup.
7042 * This routine frees all resources associated with each MPT adapter
7043 * and removes all %MPT_PROCFS_MPTBASEDIR entries.
7049 dexitprintk((KERN_INFO MYNAM ": fusion_exit() called!\n"));
7051 mpt_reset_deregister(mpt_base_index);
7053 #ifdef CONFIG_PROC_FS
7058 module_init(fusion_init);
7059 module_exit(fusion_exit);