2 * linux/drivers/message/fusion/mptbase.c
3 * This is the Fusion MPT base driver which supports multiple
4 * (SCSI + LAN) specialized protocol drivers.
5 * For use with LSI Logic PCI chip/adapter(s)
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
8 * Copyright (c) 1999-2005 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com)
12 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; version 2 of the License.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
24 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
25 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
26 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
27 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
28 solely responsible for determining the appropriateness of using and
29 distributing the Program and assumes all risks associated with its
30 exercise of rights under this Agreement, including but not limited to
31 the risks and costs of program errors, damage to or loss of data,
32 programs or equipment, and unavailability or interruption of operations.
34 DISCLAIMER OF LIABILITY
35 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
36 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
38 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
39 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
40 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
41 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
43 You should have received a copy of the GNU General Public License
44 along with this program; if not, write to the Free Software
45 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
49 #include <linux/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");
80 static int mpt_msi_enable;
81 module_param(mpt_msi_enable, int, 0);
82 MODULE_PARM_DESC(mpt_msi_enable, " MSI Support Enable (default=0)");
85 static int mfcounter = 0;
86 #define PRINT_MF_COUNT 20000
89 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
93 int mpt_lan_index = -1;
94 int mpt_stm_index = -1;
96 struct proc_dir_entry *mpt_proc_root_dir;
98 #define WHOINIT_UNKNOWN 0xAA
100 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
104 /* Adapter link list */
106 /* Callback lookup table */
107 static MPT_CALLBACK MptCallbacks[MPT_MAX_PROTOCOL_DRIVERS];
108 /* Protocol driver class lookup table */
109 static int MptDriverClass[MPT_MAX_PROTOCOL_DRIVERS];
110 /* Event handler lookup table */
111 static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
112 /* Reset handler lookup table */
113 static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
114 static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
116 static int mpt_base_index = -1;
117 static int last_drv_idx = -1;
119 static DECLARE_WAIT_QUEUE_HEAD(mpt_waitq);
121 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
125 static irqreturn_t mpt_interrupt(int irq, void *bus_id, struct pt_regs *r);
126 static int mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
127 static int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
128 u32 *req, int replyBytes, u16 *u16reply, int maxwait,
130 static int mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag);
131 static void mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev);
132 static void mpt_adapter_disable(MPT_ADAPTER *ioc);
133 static void mpt_adapter_dispose(MPT_ADAPTER *ioc);
135 static void MptDisplayIocCapabilities(MPT_ADAPTER *ioc);
136 static int MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag);
137 static int GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason);
138 static int GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
139 static int SendIocInit(MPT_ADAPTER *ioc, int sleepFlag);
140 static int SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
141 static int mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag);
142 static int mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag);
143 static int mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
144 static int KickStart(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
145 static int SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag);
146 static int PrimeIocFifos(MPT_ADAPTER *ioc);
147 static int WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
148 static int WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
149 static int WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
150 static int GetLanConfigPages(MPT_ADAPTER *ioc);
151 static int GetIoUnitPage2(MPT_ADAPTER *ioc);
152 int mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
153 static int mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
154 static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
155 static void mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
156 static void mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
157 static void mpt_timer_expired(unsigned long data);
158 static int SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch);
159 static int SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
160 static int mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag);
161 static int mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
163 #ifdef CONFIG_PROC_FS
164 static int procmpt_summary_read(char *buf, char **start, off_t offset,
165 int request, int *eof, void *data);
166 static int procmpt_version_read(char *buf, char **start, off_t offset,
167 int request, int *eof, void *data);
168 static int procmpt_iocinfo_read(char *buf, char **start, off_t offset,
169 int request, int *eof, void *data);
171 static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
173 //int mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
174 static int ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers);
175 static void mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
176 static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
177 static void mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info);
178 static void mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info);
179 static int mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
181 /* module entry point */
182 static int __init fusion_init (void);
183 static void __exit fusion_exit (void);
185 #define CHIPREG_READ32(addr) readl_relaxed(addr)
186 #define CHIPREG_READ32_dmasync(addr) readl(addr)
187 #define CHIPREG_WRITE32(addr,val) writel(val, addr)
188 #define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
189 #define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
192 pci_disable_io_access(struct pci_dev *pdev)
196 pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
198 pci_write_config_word(pdev, PCI_COMMAND, command_reg);
202 pci_enable_io_access(struct pci_dev *pdev)
206 pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
208 pci_write_config_word(pdev, PCI_COMMAND, command_reg);
212 * Process turbo (context) reply...
215 mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa)
217 MPT_FRAME_HDR *mf = NULL;
218 MPT_FRAME_HDR *mr = NULL;
222 dmfprintk((MYIOC_s_INFO_FMT "Got TURBO reply req_idx=%08x\n",
225 switch (pa >> MPI_CONTEXT_REPLY_TYPE_SHIFT) {
226 case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT:
227 req_idx = pa & 0x0000FFFF;
228 cb_idx = (pa & 0x00FF0000) >> 16;
229 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
231 case MPI_CONTEXT_REPLY_TYPE_LAN:
232 cb_idx = mpt_lan_index;
234 * Blind set of mf to NULL here was fatal
235 * after lan_reply says "freeme"
236 * Fix sort of combined with an optimization here;
237 * added explicit check for case where lan_reply
238 * was just returning 1 and doing nothing else.
239 * For this case skip the callback, but set up
240 * proper mf value first here:-)
242 if ((pa & 0x58000000) == 0x58000000) {
243 req_idx = pa & 0x0000FFFF;
244 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
245 mpt_free_msg_frame(ioc, mf);
250 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
252 case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET:
253 cb_idx = mpt_stm_index;
254 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
261 /* Check for (valid) IO callback! */
262 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
263 MptCallbacks[cb_idx] == NULL) {
264 printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
265 __FUNCTION__, ioc->name, cb_idx);
269 if (MptCallbacks[cb_idx](ioc, mf, mr))
270 mpt_free_msg_frame(ioc, mf);
276 mpt_reply(MPT_ADAPTER *ioc, u32 pa)
287 /* non-TURBO reply! Hmmm, something may be up...
288 * Newest turbo reply mechanism; get address
289 * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
292 /* Map DMA address of reply header to cpu address.
293 * pa is 32 bits - but the dma address may be 32 or 64 bits
294 * get offset based only only the low addresses
297 reply_dma_low = (pa <<= 1);
298 mr = (MPT_FRAME_HDR *)((u8 *)ioc->reply_frames +
299 (reply_dma_low - ioc->reply_frames_low_dma));
301 req_idx = le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx);
302 cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
303 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
305 dmfprintk((MYIOC_s_INFO_FMT "Got non-TURBO reply=%p req_idx=%x cb_idx=%x Function=%x\n",
306 ioc->name, mr, req_idx, cb_idx, mr->u.hdr.Function));
307 DBG_DUMP_REPLY_FRAME(mr)
309 /* Check/log IOC log info
311 ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
312 if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
313 u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
314 if (ioc->bus_type == FC)
315 mpt_fc_log_info(ioc, log_info);
316 else if (ioc->bus_type == SPI)
317 mpt_spi_log_info(ioc, log_info);
318 else if (ioc->bus_type == SAS)
319 mpt_sas_log_info(ioc, log_info);
321 if (ioc_stat & MPI_IOCSTATUS_MASK) {
322 if (ioc->bus_type == SPI &&
323 cb_idx != mpt_stm_index &&
324 cb_idx != mpt_lan_index)
325 mpt_sp_ioc_info(ioc, (u32)ioc_stat, mf);
329 /* Check for (valid) IO callback! */
330 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
331 MptCallbacks[cb_idx] == NULL) {
332 printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
333 __FUNCTION__, ioc->name, cb_idx);
338 freeme = MptCallbacks[cb_idx](ioc, mf, mr);
341 /* Flush (non-TURBO) reply with a WRITE! */
342 CHIPREG_WRITE32(&ioc->chip->ReplyFifo, pa);
345 mpt_free_msg_frame(ioc, mf);
349 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
351 * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
352 * @irq: irq number (not used)
353 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
354 * @r: pt_regs pointer (not used)
356 * This routine is registered via the request_irq() kernel API call,
357 * and handles all interrupts generated from a specific MPT adapter
358 * (also referred to as a IO Controller or IOC).
359 * This routine must clear the interrupt from the adapter and does
360 * so by reading the reply FIFO. Multiple replies may be processed
361 * per single call to this routine.
363 * This routine handles register-level access of the adapter but
364 * dispatches (calls) a protocol-specific callback routine to handle
365 * the protocol-specific details of the MPT request completion.
368 mpt_interrupt(int irq, void *bus_id, struct pt_regs *r)
370 MPT_ADAPTER *ioc = bus_id;
371 u32 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
373 if (pa == 0xFFFFFFFF)
377 * Drain the reply FIFO!
380 if (pa & MPI_ADDRESS_REPLY_A_BIT)
383 mpt_turbo_reply(ioc, pa);
384 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
385 } while (pa != 0xFFFFFFFF);
390 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
392 * mpt_base_reply - MPT base driver's callback routine; all base driver
393 * "internal" request/reply processing is routed here.
394 * Currently used for EventNotification and EventAck handling.
395 * @ioc: Pointer to MPT_ADAPTER structure
396 * @mf: Pointer to original MPT request frame
397 * @reply: Pointer to MPT reply frame (NULL if TurboReply)
399 * Returns 1 indicating original alloc'd request frame ptr
400 * should be freed, or 0 if it shouldn't.
403 mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
408 dmfprintk((MYIOC_s_INFO_FMT "mpt_base_reply() called\n", ioc->name));
410 #if defined(MPT_DEBUG_MSG_FRAME)
411 if (!(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) {
412 dmfprintk((KERN_INFO MYNAM ": Original request frame (@%p) header\n", mf));
413 DBG_DUMP_REQUEST_FRAME_HDR(mf)
417 func = reply->u.hdr.Function;
418 dmfprintk((MYIOC_s_INFO_FMT "mpt_base_reply, Function=%02Xh\n",
421 if (func == MPI_FUNCTION_EVENT_NOTIFICATION) {
422 EventNotificationReply_t *pEvReply = (EventNotificationReply_t *) reply;
426 results = ProcessEventNotification(ioc, pEvReply, &evHandlers);
427 if (results != evHandlers) {
428 /* CHECKME! Any special handling needed here? */
429 devtverboseprintk((MYIOC_s_WARN_FMT "Called %d event handlers, sum results = %d\n",
430 ioc->name, evHandlers, results));
434 * Hmmm... It seems that EventNotificationReply is an exception
435 * to the rule of one reply per request.
437 if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) {
439 devtverboseprintk((MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p does not return Request frame\n",
440 ioc->name, pEvReply));
442 devtverboseprintk((MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p returns Request frame\n",
443 ioc->name, pEvReply));
446 #ifdef CONFIG_PROC_FS
447 // LogEvent(ioc, pEvReply);
450 } else if (func == MPI_FUNCTION_EVENT_ACK) {
451 dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, EventAck reply received\n",
453 } else if (func == MPI_FUNCTION_CONFIG) {
457 dcprintk((MYIOC_s_INFO_FMT "config_complete (mf=%p,mr=%p)\n",
458 ioc->name, mf, reply));
460 pCfg = * ((CONFIGPARMS **)((u8 *) mf + ioc->req_sz - sizeof(void *)));
463 /* disable timer and remove from linked list */
464 del_timer(&pCfg->timer);
466 spin_lock_irqsave(&ioc->FreeQlock, flags);
467 list_del(&pCfg->linkage);
468 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
471 * If IOC Status is SUCCESS, save the header
472 * and set the status code to GOOD.
474 pCfg->status = MPT_CONFIG_ERROR;
476 ConfigReply_t *pReply = (ConfigReply_t *)reply;
479 status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
480 dcprintk((KERN_NOTICE " IOCStatus=%04xh, IOCLogInfo=%08xh\n",
481 status, le32_to_cpu(pReply->IOCLogInfo)));
483 pCfg->status = status;
484 if (status == MPI_IOCSTATUS_SUCCESS) {
485 if ((pReply->Header.PageType &
486 MPI_CONFIG_PAGETYPE_MASK) ==
487 MPI_CONFIG_PAGETYPE_EXTENDED) {
488 pCfg->cfghdr.ehdr->ExtPageLength =
489 le16_to_cpu(pReply->ExtPageLength);
490 pCfg->cfghdr.ehdr->ExtPageType =
493 pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
495 /* If this is a regular header, save PageLength. */
496 /* LMP Do this better so not using a reserved field! */
497 pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
498 pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
499 pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
504 * Wake up the original calling thread
509 } else if (func == MPI_FUNCTION_SAS_IO_UNIT_CONTROL) {
510 /* we should be always getting a reply frame */
511 memcpy(ioc->persist_reply_frame, reply,
512 min(MPT_DEFAULT_FRAME_SIZE,
513 4*reply->u.reply.MsgLength));
514 del_timer(&ioc->persist_timer);
515 ioc->persist_wait_done = 1;
518 printk(MYIOC_s_ERR_FMT "Unexpected msg function (=%02Xh) reply received!\n",
523 * Conditionally tell caller to free the original
524 * EventNotification/EventAck/unexpected request frame!
529 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
531 * mpt_register - Register protocol-specific main callback handler.
532 * @cbfunc: callback function pointer
533 * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
535 * This routine is called by a protocol-specific driver (SCSI host,
536 * LAN, SCSI target) to register it's reply callback routine. Each
537 * protocol-specific driver must do this before it will be able to
538 * use any IOC resources, such as obtaining request frames.
540 * NOTES: The SCSI protocol driver currently calls this routine thrice
541 * in order to register separate callbacks; one for "normal" SCSI IO;
542 * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
544 * Returns a positive integer valued "handle" in the
545 * range (and S.O.D. order) {N,...,7,6,5,...,1} if successful.
546 * Any non-positive return value (including zero!) should be considered
547 * an error by the caller.
550 mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
557 * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
558 * (slot/handle 0 is reserved!)
560 for (i = MPT_MAX_PROTOCOL_DRIVERS-1; i; i--) {
561 if (MptCallbacks[i] == NULL) {
562 MptCallbacks[i] = cbfunc;
563 MptDriverClass[i] = dclass;
564 MptEvHandlers[i] = NULL;
573 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
575 * mpt_deregister - Deregister a protocol drivers resources.
576 * @cb_idx: previously registered callback handle
578 * Each protocol-specific driver should call this routine when it's
579 * module is unloaded.
582 mpt_deregister(int cb_idx)
584 if ((cb_idx >= 0) && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
585 MptCallbacks[cb_idx] = NULL;
586 MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
587 MptEvHandlers[cb_idx] = NULL;
593 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
595 * mpt_event_register - Register protocol-specific event callback
597 * @cb_idx: previously registered (via mpt_register) callback handle
598 * @ev_cbfunc: callback function
600 * This routine can be called by one or more protocol-specific drivers
601 * if/when they choose to be notified of MPT events.
603 * Returns 0 for success.
606 mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc)
608 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
611 MptEvHandlers[cb_idx] = ev_cbfunc;
615 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
617 * mpt_event_deregister - Deregister protocol-specific event callback
619 * @cb_idx: previously registered callback handle
621 * Each protocol-specific driver should call this routine
622 * when it does not (or can no longer) handle events,
623 * or when it's module is unloaded.
626 mpt_event_deregister(int cb_idx)
628 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
631 MptEvHandlers[cb_idx] = NULL;
634 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
636 * mpt_reset_register - Register protocol-specific IOC reset handler.
637 * @cb_idx: previously registered (via mpt_register) callback handle
638 * @reset_func: reset function
640 * This routine can be called by one or more protocol-specific drivers
641 * if/when they choose to be notified of IOC resets.
643 * Returns 0 for success.
646 mpt_reset_register(int cb_idx, MPT_RESETHANDLER reset_func)
648 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
651 MptResetHandlers[cb_idx] = reset_func;
655 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
657 * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
658 * @cb_idx: previously registered callback handle
660 * Each protocol-specific driver should call this routine
661 * when it does not (or can no longer) handle IOC reset handling,
662 * or when it's module is unloaded.
665 mpt_reset_deregister(int cb_idx)
667 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
670 MptResetHandlers[cb_idx] = NULL;
673 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
675 * mpt_device_driver_register - Register device driver hooks
678 mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx)
682 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS) {
686 MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
688 /* call per pci device probe entry point */
689 list_for_each_entry(ioc, &ioc_list, list) {
690 if(dd_cbfunc->probe) {
691 dd_cbfunc->probe(ioc->pcidev,
692 ioc->pcidev->driver->id_table);
699 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
701 * mpt_device_driver_deregister - DeRegister device driver hooks
704 mpt_device_driver_deregister(int cb_idx)
706 struct mpt_pci_driver *dd_cbfunc;
709 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
712 dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
714 list_for_each_entry(ioc, &ioc_list, list) {
715 if (dd_cbfunc->remove)
716 dd_cbfunc->remove(ioc->pcidev);
719 MptDeviceDriverHandlers[cb_idx] = NULL;
723 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
725 * mpt_get_msg_frame - Obtain a MPT request frame from the pool (of 1024)
726 * allocated per MPT adapter.
727 * @handle: Handle of registered MPT protocol driver
728 * @ioc: Pointer to MPT adapter structure
730 * Returns pointer to a MPT request frame or %NULL if none are available
731 * or IOC is not active.
734 mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
738 u16 req_idx; /* Request index */
740 /* validate handle and ioc identifier */
744 printk(KERN_WARNING "IOC Not Active! mpt_get_msg_frame returning NULL!\n");
747 /* If interrupts are not attached, do not return a request frame */
751 spin_lock_irqsave(&ioc->FreeQlock, flags);
752 if (!list_empty(&ioc->FreeQ)) {
755 mf = list_entry(ioc->FreeQ.next, MPT_FRAME_HDR,
756 u.frame.linkage.list);
757 list_del(&mf->u.frame.linkage.list);
758 mf->u.frame.linkage.arg1 = 0;
759 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
760 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
762 req_idx = req_offset / ioc->req_sz;
763 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
764 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
765 ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame; /* Default, will be changed if necessary in SG generation */
772 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
776 printk(KERN_WARNING "IOC Active. No free Msg Frames! Count 0x%x Max 0x%x\n", ioc->mfcnt, ioc->req_depth);
778 if (mfcounter == PRINT_MF_COUNT)
779 printk(KERN_INFO "MF Count 0x%x Max 0x%x \n", ioc->mfcnt, ioc->req_depth);
782 dmfprintk((KERN_INFO MYNAM ": %s: mpt_get_msg_frame(%d,%d), got mf=%p\n",
783 ioc->name, handle, ioc->id, mf));
787 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
789 * mpt_put_msg_frame - Send a protocol specific MPT request frame
791 * @handle: Handle of registered MPT protocol driver
792 * @ioc: Pointer to MPT adapter structure
793 * @mf: Pointer to MPT request frame
795 * This routine posts a MPT request frame to the request post FIFO of a
796 * specific MPT adapter.
799 mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
803 u16 req_idx; /* Request index */
805 /* ensure values are reset properly! */
806 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
807 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
809 req_idx = req_offset / ioc->req_sz;
810 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
811 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
813 #ifdef MPT_DEBUG_MSG_FRAME
815 u32 *m = mf->u.frame.hwhdr.__hdr;
818 printk(KERN_INFO MYNAM ": %s: About to Put msg frame @ %p:\n" KERN_INFO " ",
820 n = ioc->req_sz/4 - 1;
823 for (ii=0; ii<=n; ii++) {
824 if (ii && ((ii%8)==0))
825 printk("\n" KERN_INFO " ");
826 printk(" %08x", le32_to_cpu(m[ii]));
832 mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
833 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]));
834 CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
837 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
839 * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
840 * @handle: Handle of registered MPT protocol driver
841 * @ioc: Pointer to MPT adapter structure
842 * @mf: Pointer to MPT request frame
844 * This routine places a MPT request frame back on the MPT adapter's
848 mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
852 /* Put Request back on FreeQ! */
853 spin_lock_irqsave(&ioc->FreeQlock, flags);
854 mf->u.frame.linkage.arg1 = 0xdeadbeaf; /* signature to know if this mf is freed */
855 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
859 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
862 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
864 * mpt_add_sge - Place a simple SGE at address pAddr.
865 * @pAddr: virtual address for SGE
866 * @flagslength: SGE flags and data transfer length
867 * @dma_addr: Physical address
869 * This routine places a MPT request frame back on the MPT adapter's
873 mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
875 if (sizeof(dma_addr_t) == sizeof(u64)) {
876 SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
877 u32 tmp = dma_addr & 0xFFFFFFFF;
879 pSge->FlagsLength = cpu_to_le32(flagslength);
880 pSge->Address.Low = cpu_to_le32(tmp);
881 tmp = (u32) ((u64)dma_addr >> 32);
882 pSge->Address.High = cpu_to_le32(tmp);
885 SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
886 pSge->FlagsLength = cpu_to_le32(flagslength);
887 pSge->Address = cpu_to_le32(dma_addr);
891 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
893 * mpt_send_handshake_request - Send MPT request via doorbell
895 * @handle: Handle of registered MPT protocol driver
896 * @ioc: Pointer to MPT adapter structure
897 * @reqBytes: Size of the request in bytes
898 * @req: Pointer to MPT request frame
899 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
901 * This routine is used exclusively to send MptScsiTaskMgmt
902 * requests since they are required to be sent via doorbell handshake.
904 * NOTE: It is the callers responsibility to byte-swap fields in the
905 * request which are greater than 1 byte in size.
907 * Returns 0 for success, non-zero for failure.
910 mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
916 /* State is known to be good upon entering
917 * this function so issue the bus reset
922 * Emulate what mpt_put_msg_frame() does /wrt to sanity
923 * setting cb_idx/req_idx. But ONLY if this request
924 * is in proper (pre-alloc'd) request buffer range...
926 ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
927 if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
928 MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
929 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
930 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle;
933 /* Make sure there are no doorbells */
934 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
936 CHIPREG_WRITE32(&ioc->chip->Doorbell,
937 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
938 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
940 /* Wait for IOC doorbell int */
941 if ((ii = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0) {
945 /* Read doorbell and check for active bit */
946 if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
949 dhsprintk((KERN_INFO MYNAM ": %s: mpt_send_handshake_request start, WaitCnt=%d\n",
952 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
954 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
958 /* Send request via doorbell handshake */
959 req_as_bytes = (u8 *) req;
960 for (ii = 0; ii < reqBytes/4; ii++) {
963 word = ((req_as_bytes[(ii*4) + 0] << 0) |
964 (req_as_bytes[(ii*4) + 1] << 8) |
965 (req_as_bytes[(ii*4) + 2] << 16) |
966 (req_as_bytes[(ii*4) + 3] << 24));
967 CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
968 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
974 if (r >= 0 && WaitForDoorbellInt(ioc, 10, sleepFlag) >= 0)
979 /* Make sure there are no doorbells */
980 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
985 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
987 * mpt_host_page_access_control - provides mechanism for the host
988 * driver to control the IOC's Host Page Buffer access.
989 * @ioc: Pointer to MPT adapter structure
990 * @access_control_value: define bits below
992 * Access Control Value - bits[15:12]
994 * 1h Enable Access { MPI_DB_HPBAC_ENABLE_ACCESS }
995 * 2h Disable Access { MPI_DB_HPBAC_DISABLE_ACCESS }
996 * 3h Free Buffer { MPI_DB_HPBAC_FREE_BUFFER }
998 * Returns 0 for success, non-zero for failure.
1002 mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag)
1006 /* return if in use */
1007 if (CHIPREG_READ32(&ioc->chip->Doorbell)
1008 & MPI_DOORBELL_ACTIVE)
1011 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1013 CHIPREG_WRITE32(&ioc->chip->Doorbell,
1014 ((MPI_FUNCTION_HOST_PAGEBUF_ACCESS_CONTROL
1015 <<MPI_DOORBELL_FUNCTION_SHIFT) |
1016 (access_control_value<<12)));
1018 /* Wait for IOC to clear Doorbell Status bit */
1019 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
1025 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1027 * mpt_host_page_alloc - allocate system memory for the fw
1028 * If we already allocated memory in past, then resend the same pointer.
1029 * ioc@: Pointer to pointer to IOC adapter
1030 * ioc_init@: Pointer to ioc init config page
1032 * Returns 0 for success, non-zero for failure.
1035 mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
1039 u32 host_page_buffer_sz=0;
1041 if(!ioc->HostPageBuffer) {
1043 host_page_buffer_sz =
1044 le32_to_cpu(ioc->facts.HostPageBufferSGE.FlagsLength) & 0xFFFFFF;
1046 if(!host_page_buffer_sz)
1047 return 0; /* fw doesn't need any host buffers */
1049 /* spin till we get enough memory */
1050 while(host_page_buffer_sz > 0) {
1052 if((ioc->HostPageBuffer = pci_alloc_consistent(
1054 host_page_buffer_sz,
1055 &ioc->HostPageBuffer_dma)) != NULL) {
1057 dinitprintk((MYIOC_s_INFO_FMT
1058 "host_page_buffer @ %p, dma @ %x, sz=%d bytes\n",
1060 ioc->HostPageBuffer,
1061 ioc->HostPageBuffer_dma,
1062 host_page_buffer_sz));
1063 ioc->alloc_total += host_page_buffer_sz;
1064 ioc->HostPageBuffer_sz = host_page_buffer_sz;
1068 host_page_buffer_sz -= (4*1024);
1072 if(!ioc->HostPageBuffer) {
1073 printk(MYIOC_s_ERR_FMT
1074 "Failed to alloc memory for host_page_buffer!\n",
1079 psge = (char *)&ioc_init->HostPageBufferSGE;
1080 flags_length = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
1081 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
1082 MPI_SGE_FLAGS_32_BIT_ADDRESSING |
1083 MPI_SGE_FLAGS_HOST_TO_IOC |
1084 MPI_SGE_FLAGS_END_OF_BUFFER;
1085 if (sizeof(dma_addr_t) == sizeof(u64)) {
1086 flags_length |= MPI_SGE_FLAGS_64_BIT_ADDRESSING;
1088 flags_length = flags_length << MPI_SGE_FLAGS_SHIFT;
1089 flags_length |= ioc->HostPageBuffer_sz;
1090 mpt_add_sge(psge, flags_length, ioc->HostPageBuffer_dma);
1091 ioc->facts.HostPageBufferSGE = ioc_init->HostPageBufferSGE;
1096 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1098 * mpt_verify_adapter - Given a unique IOC identifier, set pointer to
1099 * the associated MPT adapter structure.
1100 * @iocid: IOC unique identifier (integer)
1101 * @iocpp: Pointer to pointer to IOC adapter
1103 * Returns iocid and sets iocpp.
1106 mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
1110 list_for_each_entry(ioc,&ioc_list,list) {
1111 if (ioc->id == iocid) {
1121 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1123 * mpt_attach - Install a PCI intelligent MPT adapter.
1124 * @pdev: Pointer to pci_dev structure
1126 * This routine performs all the steps necessary to bring the IOC of
1127 * a MPT adapter to a OPERATIONAL state. This includes registering
1128 * memory regions, registering the interrupt, and allocating request
1129 * and reply memory pools.
1131 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1134 * Returns 0 for success, non-zero for failure.
1136 * TODO: Add support for polled controllers
1139 mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1143 unsigned long mem_phys;
1151 static int mpt_ids = 0;
1152 #ifdef CONFIG_PROC_FS
1153 struct proc_dir_entry *dent, *ent;
1156 if (pci_enable_device(pdev))
1159 dinitprintk((KERN_WARNING MYNAM ": mpt_adapter_install\n"));
1161 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
1162 dprintk((KERN_INFO MYNAM
1163 ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n"));
1164 } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
1165 printk(KERN_WARNING MYNAM ": 32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
1169 if (!pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))
1170 dprintk((KERN_INFO MYNAM
1171 ": Using 64 bit consistent mask\n"));
1173 dprintk((KERN_INFO MYNAM
1174 ": Not using 64 bit consistent mask\n"));
1176 ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
1178 printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
1181 ioc->alloc_total = sizeof(MPT_ADAPTER);
1182 ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
1183 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
1186 ioc->diagPending = 0;
1187 spin_lock_init(&ioc->diagLock);
1188 spin_lock_init(&ioc->initializing_hba_lock);
1190 /* Initialize the event logging.
1192 ioc->eventTypes = 0; /* None */
1193 ioc->eventContext = 0;
1194 ioc->eventLogSize = 0;
1201 ioc->cached_fw = NULL;
1203 /* Initilize SCSI Config Data structure
1205 memset(&ioc->spi_data, 0, sizeof(SpiCfgData));
1207 /* Initialize the running configQ head.
1209 INIT_LIST_HEAD(&ioc->configQ);
1211 /* Initialize the fc rport list head.
1213 INIT_LIST_HEAD(&ioc->fc_rports);
1215 /* Find lookup slot. */
1216 INIT_LIST_HEAD(&ioc->list);
1217 ioc->id = mpt_ids++;
1219 mem_phys = msize = 0;
1221 for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) {
1222 if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
1225 /* Get I/O space! */
1226 port = pci_resource_start(pdev, ii);
1227 psize = pci_resource_len(pdev,ii);
1232 mem_phys = pci_resource_start(pdev, ii);
1233 msize = pci_resource_len(pdev,ii);
1236 ioc->mem_size = msize;
1239 /* Get logical ptr for PciMem0 space */
1240 /*mem = ioremap(mem_phys, msize);*/
1241 mem = ioremap(mem_phys, msize);
1243 printk(KERN_ERR MYNAM ": ERROR - Unable to map adapter memory!\n");
1248 dinitprintk((KERN_INFO MYNAM ": mem = %p, mem_phys = %lx\n", mem, mem_phys));
1250 dinitprintk((KERN_INFO MYNAM ": facts @ %p, pfacts[0] @ %p\n",
1251 &ioc->facts, &ioc->pfacts[0]));
1253 ioc->mem_phys = mem_phys;
1254 ioc->chip = (SYSIF_REGS __iomem *)mem;
1256 /* Save Port IO values in case we need to do downloadboot */
1258 u8 *pmem = (u8*)port;
1259 ioc->pio_mem_phys = port;
1260 ioc->pio_chip = (SYSIF_REGS __iomem *)pmem;
1263 if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC909) {
1264 ioc->prod_name = "LSIFC909";
1267 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929) {
1268 ioc->prod_name = "LSIFC929";
1271 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919) {
1272 ioc->prod_name = "LSIFC919";
1275 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929X) {
1276 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1278 if (revision < XL_929) {
1279 ioc->prod_name = "LSIFC929X";
1280 /* 929X Chip Fix. Set Split transactions level
1281 * for PCIX. Set MOST bits to zero.
1283 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1285 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1287 ioc->prod_name = "LSIFC929XL";
1288 /* 929XL Chip Fix. Set MMRBC to 0x08.
1290 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1292 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1295 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919X) {
1296 ioc->prod_name = "LSIFC919X";
1298 /* 919X Chip Fix. Set Split transactions level
1299 * for PCIX. Set MOST bits to zero.
1301 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1303 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1305 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC939X) {
1306 ioc->prod_name = "LSIFC939X";
1308 ioc->errata_flag_1064 = 1;
1310 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC949X) {
1311 ioc->prod_name = "LSIFC949X";
1313 ioc->errata_flag_1064 = 1;
1315 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC949E) {
1316 ioc->prod_name = "LSIFC949E";
1319 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_53C1030) {
1320 ioc->prod_name = "LSI53C1030";
1321 ioc->bus_type = SPI;
1322 /* 1030 Chip Fix. Disable Split transactions
1323 * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
1325 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1326 if (revision < C0_1030) {
1327 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1329 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1332 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_1030_53C1035) {
1333 ioc->prod_name = "LSI53C1035";
1334 ioc->bus_type = SPI;
1336 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1064) {
1337 ioc->prod_name = "LSISAS1064";
1338 ioc->bus_type = SAS;
1339 ioc->errata_flag_1064 = 1;
1341 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1068) {
1342 ioc->prod_name = "LSISAS1068";
1343 ioc->bus_type = SAS;
1344 ioc->errata_flag_1064 = 1;
1346 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1064E) {
1347 ioc->prod_name = "LSISAS1064E";
1348 ioc->bus_type = SAS;
1350 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1068E) {
1351 ioc->prod_name = "LSISAS1068E";
1352 ioc->bus_type = SAS;
1354 else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
1355 ioc->prod_name = "LSISAS1078";
1356 ioc->bus_type = SAS;
1359 if (ioc->errata_flag_1064)
1360 pci_disable_io_access(pdev);
1362 sprintf(ioc->name, "ioc%d", ioc->id);
1364 spin_lock_init(&ioc->FreeQlock);
1367 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1369 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1371 /* Set lookup ptr. */
1372 list_add_tail(&ioc->list, &ioc_list);
1374 /* Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
1376 mpt_detect_bound_ports(ioc, pdev);
1378 if ((r = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
1380 printk(KERN_WARNING MYNAM
1381 ": WARNING - %s did not initialize properly! (%d)\n",
1383 list_del(&ioc->list);
1385 ioc->alt_ioc->alt_ioc = NULL;
1388 pci_set_drvdata(pdev, NULL);
1392 /* call per device driver probe entry point */
1393 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1394 if(MptDeviceDriverHandlers[ii] &&
1395 MptDeviceDriverHandlers[ii]->probe) {
1396 MptDeviceDriverHandlers[ii]->probe(pdev,id);
1400 #ifdef CONFIG_PROC_FS
1402 * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
1404 dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
1406 ent = create_proc_entry("info", S_IFREG|S_IRUGO, dent);
1408 ent->read_proc = procmpt_iocinfo_read;
1411 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, dent);
1413 ent->read_proc = procmpt_summary_read;
1422 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1424 * mpt_detach - Remove a PCI intelligent MPT adapter.
1425 * @pdev: Pointer to pci_dev structure
1430 mpt_detach(struct pci_dev *pdev)
1432 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1436 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
1437 remove_proc_entry(pname, NULL);
1438 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/info", ioc->name);
1439 remove_proc_entry(pname, NULL);
1440 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
1441 remove_proc_entry(pname, NULL);
1443 /* call per device driver remove entry point */
1444 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1445 if(MptDeviceDriverHandlers[ii] &&
1446 MptDeviceDriverHandlers[ii]->remove) {
1447 MptDeviceDriverHandlers[ii]->remove(pdev);
1451 /* Disable interrupts! */
1452 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1455 synchronize_irq(pdev->irq);
1457 /* Clear any lingering interrupt */
1458 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1460 CHIPREG_READ32(&ioc->chip->IntStatus);
1462 mpt_adapter_dispose(ioc);
1464 pci_set_drvdata(pdev, NULL);
1467 /**************************************************************************
1471 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1473 * mpt_suspend - Fusion MPT base driver suspend routine.
1478 mpt_suspend(struct pci_dev *pdev, pm_message_t state)
1481 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1483 device_state=pci_choose_state(pdev, state);
1485 printk(MYIOC_s_INFO_FMT
1486 "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n",
1487 ioc->name, pdev, pci_name(pdev), device_state);
1489 pci_save_state(pdev);
1491 /* put ioc into READY_STATE */
1492 if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
1493 printk(MYIOC_s_ERR_FMT
1494 "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
1497 /* disable interrupts */
1498 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1501 /* Clear any lingering interrupt */
1502 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1504 pci_disable_device(pdev);
1505 pci_set_power_state(pdev, device_state);
1510 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1512 * mpt_resume - Fusion MPT base driver resume routine.
1517 mpt_resume(struct pci_dev *pdev)
1519 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1520 u32 device_state = pdev->current_state;
1523 printk(MYIOC_s_INFO_FMT
1524 "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n",
1525 ioc->name, pdev, pci_name(pdev), device_state);
1527 pci_set_power_state(pdev, 0);
1528 pci_restore_state(pdev);
1529 pci_enable_device(pdev);
1531 /* enable interrupts */
1532 CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
1535 printk(MYIOC_s_INFO_FMT
1536 "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
1538 (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
1539 CHIPREG_READ32(&ioc->chip->Doorbell));
1541 /* bring ioc to operational state */
1542 if ((recovery_state = mpt_do_ioc_recovery(ioc,
1543 MPT_HOSTEVENT_IOC_RECOVER, CAN_SLEEP)) != 0) {
1544 printk(MYIOC_s_INFO_FMT
1545 "pci-resume: Cannot recover, error:[%x]\n",
1546 ioc->name, recovery_state);
1548 printk(MYIOC_s_INFO_FMT
1549 "pci-resume: success\n", ioc->name);
1557 mpt_signal_reset(int index, MPT_ADAPTER *ioc, int reset_phase)
1559 if ((MptDriverClass[index] == MPTSPI_DRIVER &&
1560 ioc->bus_type != SPI) ||
1561 (MptDriverClass[index] == MPTFC_DRIVER &&
1562 ioc->bus_type != FC) ||
1563 (MptDriverClass[index] == MPTSAS_DRIVER &&
1564 ioc->bus_type != SAS))
1565 /* make sure we only call the relevant reset handler
1568 return (MptResetHandlers[index])(ioc, reset_phase);
1571 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1573 * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
1574 * @ioc: Pointer to MPT adapter structure
1575 * @reason: Event word / reason
1576 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
1578 * This routine performs all the steps necessary to bring the IOC
1579 * to a OPERATIONAL state.
1581 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1586 * -1 if failed to get board READY
1587 * -2 if READY but IOCFacts Failed
1588 * -3 if READY but PrimeIOCFifos Failed
1589 * -4 if READY but IOCInit Failed
1592 mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1594 int hard_reset_done = 0;
1595 int alt_ioc_ready = 0;
1601 int reset_alt_ioc_active = 0;
1602 int irq_allocated = 0;
1604 printk(KERN_INFO MYNAM ": Initiating %s %s\n",
1605 ioc->name, reason==MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
1607 /* Disable reply interrupts (also blocks FreeQ) */
1608 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1612 if (ioc->alt_ioc->active)
1613 reset_alt_ioc_active = 1;
1615 /* Disable alt-IOC's reply interrupts (and FreeQ) for a bit ... */
1616 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, 0xFFFFFFFF);
1617 ioc->alt_ioc->active = 0;
1621 if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
1624 if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
1625 if (hard_reset_done == -4) {
1626 printk(KERN_WARNING MYNAM ": %s Owned by PEER..skipping!\n",
1629 if (reset_alt_ioc_active && ioc->alt_ioc) {
1630 /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
1631 dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
1632 ioc->alt_ioc->name));
1633 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
1634 ioc->alt_ioc->active = 1;
1638 printk(KERN_WARNING MYNAM ": %s NOT READY WARNING!\n",
1644 /* hard_reset_done = 0 if a soft reset was performed
1645 * and 1 if a hard reset was performed.
1647 if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
1648 if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
1651 printk(KERN_WARNING MYNAM
1652 ": alt-%s: Not ready WARNING!\n",
1653 ioc->alt_ioc->name);
1656 for (ii=0; ii<5; ii++) {
1657 /* Get IOC facts! Allow 5 retries */
1658 if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
1664 dinitprintk((MYIOC_s_INFO_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc));
1666 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1667 MptDisplayIocCapabilities(ioc);
1670 if (alt_ioc_ready) {
1671 if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
1672 dinitprintk((MYIOC_s_INFO_FMT "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc));
1673 /* Retry - alt IOC was initialized once
1675 rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
1678 dinitprintk((MYIOC_s_INFO_FMT "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
1680 reset_alt_ioc_active = 0;
1681 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1682 MptDisplayIocCapabilities(ioc->alt_ioc);
1687 * Device is reset now. It must have de-asserted the interrupt line
1688 * (if it was asserted) and it should be safe to register for the
1691 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
1693 if (ioc->pcidev->irq) {
1694 if (mpt_msi_enable && !pci_enable_msi(ioc->pcidev))
1695 printk(MYIOC_s_INFO_FMT "PCI-MSI enabled\n",
1697 rc = request_irq(ioc->pcidev->irq, mpt_interrupt,
1698 IRQF_SHARED, ioc->name, ioc);
1700 printk(MYIOC_s_ERR_FMT "Unable to allocate "
1701 "interrupt %d!\n", ioc->name,
1704 pci_disable_msi(ioc->pcidev);
1708 ioc->pci_irq = ioc->pcidev->irq;
1709 pci_set_master(ioc->pcidev); /* ?? */
1710 pci_set_drvdata(ioc->pcidev, ioc);
1711 dprintk((KERN_INFO MYNAM ": %s installed at interrupt "
1712 "%d\n", ioc->name, ioc->pcidev->irq));
1716 /* Prime reply & request queues!
1717 * (mucho alloc's) Must be done prior to
1718 * init as upper addresses are needed for init.
1719 * If fails, continue with alt-ioc processing
1721 if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
1724 /* May need to check/upload firmware & data here!
1725 * If fails, continue with alt-ioc processing
1727 if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
1730 if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
1731 printk(KERN_WARNING MYNAM ": alt-%s: (%d) FIFO mgmt alloc WARNING!\n",
1732 ioc->alt_ioc->name, rc);
1734 reset_alt_ioc_active = 0;
1737 if (alt_ioc_ready) {
1738 if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
1740 reset_alt_ioc_active = 0;
1741 printk(KERN_WARNING MYNAM
1742 ": alt-%s: (%d) init failure WARNING!\n",
1743 ioc->alt_ioc->name, rc);
1747 if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
1748 if (ioc->upload_fw) {
1749 ddlprintk((MYIOC_s_INFO_FMT
1750 "firmware upload required!\n", ioc->name));
1752 /* Controller is not operational, cannot do upload
1755 rc = mpt_do_upload(ioc, sleepFlag);
1757 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
1759 * Maintain only one pointer to FW memory
1760 * so there will not be two attempt to
1761 * downloadboot onboard dual function
1762 * chips (mpt_adapter_disable,
1765 ioc->cached_fw = NULL;
1766 ddlprintk((MYIOC_s_INFO_FMT ": mpt_upload: alt_%s has cached_fw=%p \n",
1767 ioc->name, ioc->alt_ioc->name, ioc->alt_ioc->cached_fw));
1770 printk(KERN_WARNING MYNAM ": firmware upload failure!\n");
1778 /* Enable! (reply interrupt) */
1779 CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
1783 if (reset_alt_ioc_active && ioc->alt_ioc) {
1784 /* (re)Enable alt-IOC! (reply interrupt) */
1785 dinitprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
1786 ioc->alt_ioc->name));
1787 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
1788 ioc->alt_ioc->active = 1;
1791 /* Enable MPT base driver management of EventNotification
1792 * and EventAck handling.
1794 if ((ret == 0) && (!ioc->facts.EventState))
1795 (void) SendEventNotification(ioc, 1); /* 1=Enable EventNotification */
1797 if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
1798 (void) SendEventNotification(ioc->alt_ioc, 1); /* 1=Enable EventNotification */
1800 /* Add additional "reason" check before call to GetLanConfigPages
1801 * (combined with GetIoUnitPage2 call). This prevents a somewhat
1802 * recursive scenario; GetLanConfigPages times out, timer expired
1803 * routine calls HardResetHandler, which calls into here again,
1804 * and we try GetLanConfigPages again...
1806 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
1807 if (ioc->bus_type == SAS) {
1809 /* clear persistency table */
1810 if(ioc->facts.IOCExceptions &
1811 MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL) {
1812 ret = mptbase_sas_persist_operation(ioc,
1813 MPI_SAS_OP_CLEAR_NOT_PRESENT);
1820 mpt_findImVolumes(ioc);
1822 } else if (ioc->bus_type == FC) {
1823 if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
1824 (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
1826 * Pre-fetch the ports LAN MAC address!
1827 * (LANPage1_t stuff)
1829 (void) GetLanConfigPages(ioc);
1832 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
1833 dprintk((MYIOC_s_INFO_FMT "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
1834 ioc->name, a[5], a[4], a[3], a[2], a[1], a[0] ));
1839 /* Get NVRAM and adapter maximums from SPP 0 and 2
1841 mpt_GetScsiPortSettings(ioc, 0);
1843 /* Get version and length of SDP 1
1845 mpt_readScsiDevicePageHeaders(ioc, 0);
1849 if (ioc->facts.MsgVersion >= MPI_VERSION_01_02)
1850 mpt_findImVolumes(ioc);
1852 /* Check, and possibly reset, the coalescing value
1854 mpt_read_ioc_pg_1(ioc);
1856 mpt_read_ioc_pg_4(ioc);
1859 GetIoUnitPage2(ioc);
1863 * Call each currently registered protocol IOC reset handler
1864 * with post-reset indication.
1865 * NOTE: If we're doing _IOC_BRINGUP, there can be no
1866 * MptResetHandlers[] registered yet.
1868 if (hard_reset_done) {
1870 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
1871 if ((ret == 0) && MptResetHandlers[ii]) {
1872 dprintk((MYIOC_s_INFO_FMT "Calling IOC post_reset handler #%d\n",
1874 rc += mpt_signal_reset(ii, ioc, MPT_IOC_POST_RESET);
1878 if (alt_ioc_ready && MptResetHandlers[ii]) {
1879 drsprintk((MYIOC_s_INFO_FMT "Calling alt-%s post_reset handler #%d\n",
1880 ioc->name, ioc->alt_ioc->name, ii));
1881 rc += mpt_signal_reset(ii, ioc->alt_ioc, MPT_IOC_POST_RESET);
1885 /* FIXME? Examine results here? */
1889 if ((ret != 0) && irq_allocated) {
1890 free_irq(ioc->pci_irq, ioc);
1892 pci_disable_msi(ioc->pcidev);
1897 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1899 * mpt_detect_bound_ports - Search for PCI bus/dev_function
1900 * which matches PCI bus/dev_function (+/-1) for newly discovered 929,
1901 * 929X, 1030 or 1035.
1902 * @ioc: Pointer to MPT adapter structure
1903 * @pdev: Pointer to (struct pci_dev) structure
1905 * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
1906 * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
1909 mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
1911 struct pci_dev *peer=NULL;
1912 unsigned int slot = PCI_SLOT(pdev->devfn);
1913 unsigned int func = PCI_FUNC(pdev->devfn);
1914 MPT_ADAPTER *ioc_srch;
1916 dprintk((MYIOC_s_INFO_FMT "PCI device %s devfn=%x/%x,"
1917 " searching for devfn match on %x or %x\n",
1918 ioc->name, pci_name(pdev), pdev->bus->number,
1919 pdev->devfn, func-1, func+1));
1921 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
1923 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func+1));
1928 list_for_each_entry(ioc_srch, &ioc_list, list) {
1929 struct pci_dev *_pcidev = ioc_srch->pcidev;
1930 if (_pcidev == peer) {
1931 /* Paranoia checks */
1932 if (ioc->alt_ioc != NULL) {
1933 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
1934 ioc->name, ioc->alt_ioc->name);
1936 } else if (ioc_srch->alt_ioc != NULL) {
1937 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
1938 ioc_srch->name, ioc_srch->alt_ioc->name);
1941 dprintk((KERN_INFO MYNAM ": FOUND! binding %s <==> %s\n",
1942 ioc->name, ioc_srch->name));
1943 ioc_srch->alt_ioc = ioc;
1944 ioc->alt_ioc = ioc_srch;
1950 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1952 * mpt_adapter_disable - Disable misbehaving MPT adapter.
1953 * @this: Pointer to MPT adapter structure
1956 mpt_adapter_disable(MPT_ADAPTER *ioc)
1961 if (ioc->cached_fw != NULL) {
1962 ddlprintk((KERN_INFO MYNAM ": mpt_adapter_disable: Pushing FW onto adapter\n"));
1963 if ((ret = mpt_downloadboot(ioc, (MpiFwHeader_t *)ioc->cached_fw, NO_SLEEP)) < 0) {
1964 printk(KERN_WARNING MYNAM
1965 ": firmware downloadboot failure (%d)!\n", ret);
1969 /* Disable adapter interrupts! */
1970 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1972 /* Clear any lingering interrupt */
1973 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1975 if (ioc->alloc != NULL) {
1977 dexitprintk((KERN_INFO MYNAM ": %s.free @ %p, sz=%d bytes\n",
1978 ioc->name, ioc->alloc, ioc->alloc_sz));
1979 pci_free_consistent(ioc->pcidev, sz,
1980 ioc->alloc, ioc->alloc_dma);
1981 ioc->reply_frames = NULL;
1982 ioc->req_frames = NULL;
1984 ioc->alloc_total -= sz;
1987 if (ioc->sense_buf_pool != NULL) {
1988 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
1989 pci_free_consistent(ioc->pcidev, sz,
1990 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
1991 ioc->sense_buf_pool = NULL;
1992 ioc->alloc_total -= sz;
1995 if (ioc->events != NULL){
1996 sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
1999 ioc->alloc_total -= sz;
2002 if (ioc->cached_fw != NULL) {
2003 sz = ioc->facts.FWImageSize;
2004 pci_free_consistent(ioc->pcidev, sz,
2005 ioc->cached_fw, ioc->cached_fw_dma);
2006 ioc->cached_fw = NULL;
2007 ioc->alloc_total -= sz;
2010 kfree(ioc->spi_data.nvram);
2011 kfree(ioc->raid_data.pIocPg3);
2012 ioc->spi_data.nvram = NULL;
2013 ioc->raid_data.pIocPg3 = NULL;
2015 if (ioc->spi_data.pIocPg4 != NULL) {
2016 sz = ioc->spi_data.IocPg4Sz;
2017 pci_free_consistent(ioc->pcidev, sz,
2018 ioc->spi_data.pIocPg4,
2019 ioc->spi_data.IocPg4_dma);
2020 ioc->spi_data.pIocPg4 = NULL;
2021 ioc->alloc_total -= sz;
2024 if (ioc->ReqToChain != NULL) {
2025 kfree(ioc->ReqToChain);
2026 kfree(ioc->RequestNB);
2027 ioc->ReqToChain = NULL;
2030 kfree(ioc->ChainToChain);
2031 ioc->ChainToChain = NULL;
2033 if (ioc->HostPageBuffer != NULL) {
2034 if((ret = mpt_host_page_access_control(ioc,
2035 MPI_DB_HPBAC_FREE_BUFFER, NO_SLEEP)) != 0) {
2036 printk(KERN_ERR MYNAM
2037 ": %s: host page buffers free failed (%d)!\n",
2040 dexitprintk((KERN_INFO MYNAM ": %s HostPageBuffer free @ %p, sz=%d bytes\n",
2041 ioc->name, ioc->HostPageBuffer, ioc->HostPageBuffer_sz));
2042 pci_free_consistent(ioc->pcidev, ioc->HostPageBuffer_sz,
2043 ioc->HostPageBuffer,
2044 ioc->HostPageBuffer_dma);
2045 ioc->HostPageBuffer = NULL;
2046 ioc->HostPageBuffer_sz = 0;
2047 ioc->alloc_total -= ioc->HostPageBuffer_sz;
2051 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2053 * mpt_adapter_dispose - Free all resources associated with a MPT
2055 * @ioc: Pointer to MPT adapter structure
2057 * This routine unregisters h/w resources and frees all alloc'd memory
2058 * associated with a MPT adapter structure.
2061 mpt_adapter_dispose(MPT_ADAPTER *ioc)
2063 int sz_first, sz_last;
2068 sz_first = ioc->alloc_total;
2070 mpt_adapter_disable(ioc);
2072 if (ioc->pci_irq != -1) {
2073 free_irq(ioc->pci_irq, ioc);
2075 pci_disable_msi(ioc->pcidev);
2079 if (ioc->memmap != NULL) {
2080 iounmap(ioc->memmap);
2084 #if defined(CONFIG_MTRR) && 0
2085 if (ioc->mtrr_reg > 0) {
2086 mtrr_del(ioc->mtrr_reg, 0, 0);
2087 dprintk((KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
2091 /* Zap the adapter lookup ptr! */
2092 list_del(&ioc->list);
2094 sz_last = ioc->alloc_total;
2095 dprintk((KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
2096 ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
2099 ioc->alt_ioc->alt_ioc = NULL;
2104 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2106 * MptDisplayIocCapabilities - Disply IOC's capacilities.
2107 * @ioc: Pointer to MPT adapter structure
2110 MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
2114 printk(KERN_INFO "%s: ", ioc->name);
2115 if (ioc->prod_name && strlen(ioc->prod_name) > 3)
2116 printk("%s: ", ioc->prod_name+3);
2117 printk("Capabilities={");
2119 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
2120 printk("Initiator");
2124 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2125 printk("%sTarget", i ? "," : "");
2129 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
2130 printk("%sLAN", i ? "," : "");
2136 * This would probably evoke more questions than it's worth
2138 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2139 printk("%sLogBusAddr", i ? "," : "");
2147 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2149 * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
2150 * @ioc: Pointer to MPT_ADAPTER structure
2151 * @force: Force hard KickStart of IOC
2152 * @sleepFlag: Specifies whether the process can sleep
2155 * 1 - DIAG reset and READY
2156 * 0 - READY initially OR soft reset and READY
2157 * -1 - Any failure on KickStart
2158 * -2 - Msg Unit Reset Failed
2159 * -3 - IO Unit Reset Failed
2160 * -4 - IOC owned by a PEER
2163 MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
2168 int hard_reset_done = 0;
2173 /* Get current [raw] IOC state */
2174 ioc_state = mpt_GetIocState(ioc, 0);
2175 dhsprintk((KERN_INFO MYNAM "::MakeIocReady, %s [raw] state=%08x\n", ioc->name, ioc_state));
2178 * Check to see if IOC got left/stuck in doorbell handshake
2179 * grip of death. If so, hard reset the IOC.
2181 if (ioc_state & MPI_DOORBELL_ACTIVE) {
2183 printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
2187 /* Is it already READY? */
2188 if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
2192 * Check to see if IOC is in FAULT state.
2194 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
2196 printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
2198 printk(KERN_WARNING " FAULT code = %04xh\n",
2199 ioc_state & MPI_DOORBELL_DATA_MASK);
2203 * Hmmm... Did it get left operational?
2205 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
2206 dinitprintk((MYIOC_s_INFO_FMT "IOC operational unexpected\n",
2210 * If PCI Peer, exit.
2211 * Else, if no fault conditions are present, issue a MessageUnitReset
2212 * Else, fall through to KickStart case
2214 whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
2215 dinitprintk((KERN_INFO MYNAM
2216 ": whoinit 0x%x statefault %d force %d\n",
2217 whoinit, statefault, force));
2218 if (whoinit == MPI_WHOINIT_PCI_PEER)
2221 if ((statefault == 0 ) && (force == 0)) {
2222 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
2229 hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
2230 if (hard_reset_done < 0)
2234 * Loop here waiting for IOC to come READY.
2237 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 5; /* 5 seconds */
2239 while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
2240 if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
2242 * BIOS or previous driver load left IOC in OP state.
2243 * Reset messaging FIFOs.
2245 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
2246 printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
2249 } else if (ioc_state == MPI_IOC_STATE_RESET) {
2251 * Something is wrong. Try to get IOC back
2254 if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
2255 printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
2262 printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
2263 ioc->name, (int)((ii+5)/HZ));
2267 if (sleepFlag == CAN_SLEEP) {
2270 mdelay (1); /* 1 msec delay */
2275 if (statefault < 3) {
2276 printk(MYIOC_s_INFO_FMT "Recovered from %s\n",
2278 statefault==1 ? "stuck handshake" : "IOC FAULT");
2281 return hard_reset_done;
2284 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2286 * mpt_GetIocState - Get the current state of a MPT adapter.
2287 * @ioc: Pointer to MPT_ADAPTER structure
2288 * @cooked: Request raw or cooked IOC state
2290 * Returns all IOC Doorbell register bits if cooked==0, else just the
2291 * Doorbell bits in MPI_IOC_STATE_MASK.
2294 mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
2299 s = CHIPREG_READ32(&ioc->chip->Doorbell);
2300 // dprintk((MYIOC_s_INFO_FMT "raw state = %08x\n", ioc->name, s));
2301 sc = s & MPI_IOC_STATE_MASK;
2304 ioc->last_state = sc;
2306 return cooked ? sc : s;
2309 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2311 * GetIocFacts - Send IOCFacts request to MPT adapter.
2312 * @ioc: Pointer to MPT_ADAPTER structure
2313 * @sleepFlag: Specifies whether the process can sleep
2314 * @reason: If recovery, only update facts.
2316 * Returns 0 for success, non-zero for failure.
2319 GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2321 IOCFacts_t get_facts;
2322 IOCFactsReply_t *facts;
2330 /* IOC *must* NOT be in RESET state! */
2331 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2332 printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
2338 facts = &ioc->facts;
2340 /* Destination (reply area)... */
2341 reply_sz = sizeof(*facts);
2342 memset(facts, 0, reply_sz);
2344 /* Request area (get_facts on the stack right now!) */
2345 req_sz = sizeof(get_facts);
2346 memset(&get_facts, 0, req_sz);
2348 get_facts.Function = MPI_FUNCTION_IOC_FACTS;
2349 /* Assert: All other get_facts fields are zero! */
2351 dinitprintk((MYIOC_s_INFO_FMT
2352 "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
2353 ioc->name, req_sz, reply_sz));
2355 /* No non-zero fields in the get_facts request are greater than
2356 * 1 byte in size, so we can just fire it off as is.
2358 r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
2359 reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
2364 * Now byte swap (GRRR) the necessary fields before any further
2365 * inspection of reply contents.
2367 * But need to do some sanity checks on MsgLength (byte) field
2368 * to make sure we don't zero IOC's req_sz!
2370 /* Did we get a valid reply? */
2371 if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
2372 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2374 * If not been here, done that, save off first WhoInit value
2376 if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
2377 ioc->FirstWhoInit = facts->WhoInit;
2380 facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
2381 facts->MsgContext = le32_to_cpu(facts->MsgContext);
2382 facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
2383 facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
2384 facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
2385 status = le16_to_cpu(facts->IOCStatus) & MPI_IOCSTATUS_MASK;
2386 /* CHECKME! IOCStatus, IOCLogInfo */
2388 facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
2389 facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
2392 * FC f/w version changed between 1.1 and 1.2
2393 * Old: u16{Major(4),Minor(4),SubMinor(8)}
2394 * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
2396 if (facts->MsgVersion < 0x0102) {
2398 * Handle old FC f/w style, convert to new...
2400 u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
2401 facts->FWVersion.Word =
2402 ((oldv<<12) & 0xFF000000) |
2403 ((oldv<<8) & 0x000FFF00);
2405 facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
2407 facts->ProductID = le16_to_cpu(facts->ProductID);
2408 facts->CurrentHostMfaHighAddr =
2409 le32_to_cpu(facts->CurrentHostMfaHighAddr);
2410 facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
2411 facts->CurrentSenseBufferHighAddr =
2412 le32_to_cpu(facts->CurrentSenseBufferHighAddr);
2413 facts->CurReplyFrameSize =
2414 le16_to_cpu(facts->CurReplyFrameSize);
2415 facts->IOCCapabilities = le32_to_cpu(facts->IOCCapabilities);
2418 * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
2419 * Older MPI-1.00.xx struct had 13 dwords, and enlarged
2420 * to 14 in MPI-1.01.0x.
2422 if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
2423 facts->MsgVersion > 0x0100) {
2424 facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
2427 sz = facts->FWImageSize;
2432 facts->FWImageSize = sz;
2434 if (!facts->RequestFrameSize) {
2435 /* Something is wrong! */
2436 printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
2441 r = sz = facts->BlockSize;
2442 vv = ((63 / (sz * 4)) + 1) & 0x03;
2443 ioc->NB_for_64_byte_frame = vv;
2449 ioc->NBShiftFactor = shiftFactor;
2450 dinitprintk((MYIOC_s_INFO_FMT "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
2451 ioc->name, vv, shiftFactor, r));
2453 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2455 * Set values for this IOC's request & reply frame sizes,
2456 * and request & reply queue depths...
2458 ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
2459 ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
2460 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
2461 ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
2463 dinitprintk((MYIOC_s_INFO_FMT "reply_sz=%3d, reply_depth=%4d\n",
2464 ioc->name, ioc->reply_sz, ioc->reply_depth));
2465 dinitprintk((MYIOC_s_INFO_FMT "req_sz =%3d, req_depth =%4d\n",
2466 ioc->name, ioc->req_sz, ioc->req_depth));
2468 /* Get port facts! */
2469 if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
2473 printk(MYIOC_s_ERR_FMT
2474 "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
2475 ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
2476 RequestFrameSize)/sizeof(u32)));
2483 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2485 * GetPortFacts - Send PortFacts request to MPT adapter.
2486 * @ioc: Pointer to MPT_ADAPTER structure
2487 * @portnum: Port number
2488 * @sleepFlag: Specifies whether the process can sleep
2490 * Returns 0 for success, non-zero for failure.
2493 GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2495 PortFacts_t get_pfacts;
2496 PortFactsReply_t *pfacts;
2501 /* IOC *must* NOT be in RESET state! */
2502 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2503 printk(KERN_ERR MYNAM ": ERROR - Can't get PortFacts, %s NOT READY! (%08x)\n",
2509 pfacts = &ioc->pfacts[portnum];
2511 /* Destination (reply area)... */
2512 reply_sz = sizeof(*pfacts);
2513 memset(pfacts, 0, reply_sz);
2515 /* Request area (get_pfacts on the stack right now!) */
2516 req_sz = sizeof(get_pfacts);
2517 memset(&get_pfacts, 0, req_sz);
2519 get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
2520 get_pfacts.PortNumber = portnum;
2521 /* Assert: All other get_pfacts fields are zero! */
2523 dinitprintk((MYIOC_s_INFO_FMT "Sending get PortFacts(%d) request\n",
2524 ioc->name, portnum));
2526 /* No non-zero fields in the get_pfacts request are greater than
2527 * 1 byte in size, so we can just fire it off as is.
2529 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
2530 reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
2534 /* Did we get a valid reply? */
2536 /* Now byte swap the necessary fields in the response. */
2537 pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
2538 pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
2539 pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
2540 pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
2541 pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
2542 pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
2543 pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
2544 pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
2545 pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
2550 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2552 * SendIocInit - Send IOCInit request to MPT adapter.
2553 * @ioc: Pointer to MPT_ADAPTER structure
2554 * @sleepFlag: Specifies whether the process can sleep
2556 * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
2558 * Returns 0 for success, non-zero for failure.
2561 SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
2564 MPIDefaultReply_t init_reply;
2570 memset(&ioc_init, 0, sizeof(ioc_init));
2571 memset(&init_reply, 0, sizeof(init_reply));
2573 ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
2574 ioc_init.Function = MPI_FUNCTION_IOC_INIT;
2576 /* If we are in a recovery mode and we uploaded the FW image,
2577 * then this pointer is not NULL. Skip the upload a second time.
2578 * Set this flag if cached_fw set for either IOC.
2580 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
2584 ddlprintk((MYIOC_s_INFO_FMT "upload_fw %d facts.Flags=%x\n",
2585 ioc->name, ioc->upload_fw, ioc->facts.Flags));
2587 if(ioc->bus_type == SAS)
2588 ioc_init.MaxDevices = ioc->facts.MaxDevices;
2589 else if(ioc->bus_type == FC)
2590 ioc_init.MaxDevices = MPT_MAX_FC_DEVICES;
2592 ioc_init.MaxDevices = MPT_MAX_SCSI_DEVICES;
2593 ioc_init.MaxBuses = MPT_MAX_BUS;
2594 dinitprintk((MYIOC_s_INFO_FMT "facts.MsgVersion=%x\n",
2595 ioc->name, ioc->facts.MsgVersion));
2596 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05) {
2597 // set MsgVersion and HeaderVersion host driver was built with
2598 ioc_init.MsgVersion = cpu_to_le16(MPI_VERSION);
2599 ioc_init.HeaderVersion = cpu_to_le16(MPI_HEADER_VERSION);
2601 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_HOST_PAGE_BUFFER_PERSISTENT) {
2602 ioc_init.HostPageBufferSGE = ioc->facts.HostPageBufferSGE;
2603 } else if(mpt_host_page_alloc(ioc, &ioc_init))
2606 ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
2608 if (sizeof(dma_addr_t) == sizeof(u64)) {
2609 /* Save the upper 32-bits of the request
2610 * (reply) and sense buffers.
2612 ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
2613 ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2615 /* Force 32-bit addressing */
2616 ioc_init.HostMfaHighAddr = cpu_to_le32(0);
2617 ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
2620 ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
2621 ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
2622 ioc->facts.MaxDevices = ioc_init.MaxDevices;
2623 ioc->facts.MaxBuses = ioc_init.MaxBuses;
2625 dhsprintk((MYIOC_s_INFO_FMT "Sending IOCInit (req @ %p)\n",
2626 ioc->name, &ioc_init));
2628 r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
2629 sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
2631 printk(MYIOC_s_ERR_FMT "Sending IOCInit failed(%d)!\n",ioc->name, r);
2635 /* No need to byte swap the multibyte fields in the reply
2636 * since we don't even look at it's contents.
2639 dhsprintk((MYIOC_s_INFO_FMT "Sending PortEnable (req @ %p)\n",
2640 ioc->name, &ioc_init));
2642 if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0) {
2643 printk(MYIOC_s_ERR_FMT "Sending PortEnable failed(%d)!\n",ioc->name, r);
2647 /* YIKES! SUPER IMPORTANT!!!
2648 * Poll IocState until _OPERATIONAL while IOC is doing
2649 * LoopInit and TargetDiscovery!
2652 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
2653 state = mpt_GetIocState(ioc, 1);
2654 while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
2655 if (sleepFlag == CAN_SLEEP) {
2662 printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
2663 ioc->name, (int)((count+5)/HZ));
2667 state = mpt_GetIocState(ioc, 1);
2670 dinitprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
2676 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2678 * SendPortEnable - Send PortEnable request to MPT adapter port.
2679 * @ioc: Pointer to MPT_ADAPTER structure
2680 * @portnum: Port number to enable
2681 * @sleepFlag: Specifies whether the process can sleep
2683 * Send PortEnable to bring IOC to OPERATIONAL state.
2685 * Returns 0 for success, non-zero for failure.
2688 SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2690 PortEnable_t port_enable;
2691 MPIDefaultReply_t reply_buf;
2696 /* Destination... */
2697 reply_sz = sizeof(MPIDefaultReply_t);
2698 memset(&reply_buf, 0, reply_sz);
2700 req_sz = sizeof(PortEnable_t);
2701 memset(&port_enable, 0, req_sz);
2703 port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
2704 port_enable.PortNumber = portnum;
2705 /* port_enable.ChainOffset = 0; */
2706 /* port_enable.MsgFlags = 0; */
2707 /* port_enable.MsgContext = 0; */
2709 dinitprintk((MYIOC_s_INFO_FMT "Sending Port(%d)Enable (req @ %p)\n",
2710 ioc->name, portnum, &port_enable));
2712 /* RAID FW may take a long time to enable
2714 if (((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
2715 > MPI_FW_HEADER_PID_PROD_TARGET_SCSI) ||
2716 (ioc->bus_type == SAS)) {
2717 rc = mpt_handshake_req_reply_wait(ioc, req_sz,
2718 (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
2719 300 /*seconds*/, sleepFlag);
2721 rc = mpt_handshake_req_reply_wait(ioc, req_sz,
2722 (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
2723 30 /*seconds*/, sleepFlag);
2729 * ioc: Pointer to MPT_ADAPTER structure
2730 * size - total FW bytes
2733 mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
2736 return; /* use already allocated memory */
2737 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
2738 ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
2739 ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
2741 if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
2742 ioc->alloc_total += size;
2746 * If alt_img is NULL, delete from ioc structure.
2747 * Else, delete a secondary image in same format.
2750 mpt_free_fw_memory(MPT_ADAPTER *ioc)
2754 sz = ioc->facts.FWImageSize;
2755 dinitprintk((KERN_INFO MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
2756 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2757 pci_free_consistent(ioc->pcidev, sz,
2758 ioc->cached_fw, ioc->cached_fw_dma);
2759 ioc->cached_fw = NULL;
2765 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2767 * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
2768 * @ioc: Pointer to MPT_ADAPTER structure
2769 * @sleepFlag: Specifies whether the process can sleep
2771 * Returns 0 for success, >0 for handshake failure
2772 * <0 for fw upload failure.
2774 * Remark: If bound IOC and a successful FWUpload was performed
2775 * on the bound IOC, the second image is discarded
2776 * and memory is free'd. Both channels must upload to prevent
2777 * IOC from running in degraded mode.
2780 mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
2782 u8 request[ioc->req_sz];
2783 u8 reply[sizeof(FWUploadReply_t)];
2784 FWUpload_t *prequest;
2785 FWUploadReply_t *preply;
2786 FWUploadTCSGE_t *ptcsge;
2789 int ii, sz, reply_sz;
2792 /* If the image size is 0, we are done.
2794 if ((sz = ioc->facts.FWImageSize) == 0)
2797 mpt_alloc_fw_memory(ioc, sz);
2799 dinitprintk((KERN_INFO MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
2800 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2802 if (ioc->cached_fw == NULL) {
2808 prequest = (FWUpload_t *)&request;
2809 preply = (FWUploadReply_t *)&reply;
2811 /* Destination... */
2812 memset(prequest, 0, ioc->req_sz);
2814 reply_sz = sizeof(reply);
2815 memset(preply, 0, reply_sz);
2817 prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
2818 prequest->Function = MPI_FUNCTION_FW_UPLOAD;
2820 ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
2821 ptcsge->DetailsLength = 12;
2822 ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
2823 ptcsge->ImageSize = cpu_to_le32(sz);
2825 sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
2827 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
2828 mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
2830 sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
2831 dinitprintk((KERN_INFO MYNAM ": Sending FW Upload (req @ %p) sgeoffset=%d \n",
2832 prequest, sgeoffset));
2833 DBG_DUMP_FW_REQUEST_FRAME(prequest)
2835 ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
2836 reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
2838 dinitprintk((KERN_INFO MYNAM ": FW Upload completed rc=%x \n", ii));
2840 cmdStatus = -EFAULT;
2842 /* Handshake transfer was complete and successful.
2843 * Check the Reply Frame.
2845 int status, transfer_sz;
2846 status = le16_to_cpu(preply->IOCStatus);
2847 if (status == MPI_IOCSTATUS_SUCCESS) {
2848 transfer_sz = le32_to_cpu(preply->ActualImageSize);
2849 if (transfer_sz == sz)
2853 dinitprintk((MYIOC_s_INFO_FMT ": do_upload cmdStatus=%d \n",
2854 ioc->name, cmdStatus));
2859 ddlprintk((MYIOC_s_INFO_FMT ": fw upload failed, freeing image \n",
2861 mpt_free_fw_memory(ioc);
2867 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2869 * mpt_downloadboot - DownloadBoot code
2870 * @ioc: Pointer to MPT_ADAPTER structure
2871 * @flag: Specify which part of IOC memory is to be uploaded.
2872 * @sleepFlag: Specifies whether the process can sleep
2874 * FwDownloadBoot requires Programmed IO access.
2876 * Returns 0 for success
2877 * -1 FW Image size is 0
2878 * -2 No valid cached_fw Pointer
2879 * <0 for fw upload failure.
2882 mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag)
2884 MpiExtImageHeader_t *pExtImage;
2894 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: fw size 0x%x (%d), FW Ptr %p\n",
2895 ioc->name, pFwHeader->ImageSize, pFwHeader->ImageSize, pFwHeader));
2897 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2898 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2899 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2900 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2901 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2902 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2904 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
2907 if (sleepFlag == CAN_SLEEP) {
2913 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2914 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
2916 for (count = 0; count < 30; count ++) {
2917 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
2918 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
2919 ddlprintk((MYIOC_s_INFO_FMT "RESET_ADAPTER cleared, count=%d\n",
2924 if (sleepFlag == CAN_SLEEP) {
2931 if ( count == 30 ) {
2932 ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! "
2933 "Unable to get MPI_DIAG_DRWE mode, diag0val=%x\n",
2934 ioc->name, diag0val));
2938 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
2939 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
2940 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
2941 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
2942 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
2943 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
2945 /* Set the DiagRwEn and Disable ARM bits */
2946 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
2948 fwSize = (pFwHeader->ImageSize + 3)/4;
2949 ptrFw = (u32 *) pFwHeader;
2951 /* Write the LoadStartAddress to the DiagRw Address Register
2952 * using Programmed IO
2954 if (ioc->errata_flag_1064)
2955 pci_enable_io_access(ioc->pcidev);
2957 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
2958 ddlprintk((MYIOC_s_INFO_FMT "LoadStart addr written 0x%x \n",
2959 ioc->name, pFwHeader->LoadStartAddress));
2961 ddlprintk((MYIOC_s_INFO_FMT "Write FW Image: 0x%x bytes @ %p\n",
2962 ioc->name, fwSize*4, ptrFw));
2964 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
2967 nextImage = pFwHeader->NextImageHeaderOffset;
2969 pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
2971 load_addr = pExtImage->LoadStartAddress;
2973 fwSize = (pExtImage->ImageSize + 3) >> 2;
2974 ptrFw = (u32 *)pExtImage;
2976 ddlprintk((MYIOC_s_INFO_FMT "Write Ext Image: 0x%x (%d) bytes @ %p load_addr=%x\n",
2977 ioc->name, fwSize*4, fwSize*4, ptrFw, load_addr));
2978 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
2981 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
2983 nextImage = pExtImage->NextImageHeaderOffset;
2986 /* Write the IopResetVectorRegAddr */
2987 ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
2988 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
2990 /* Write the IopResetVectorValue */
2991 ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
2992 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
2994 /* Clear the internal flash bad bit - autoincrementing register,
2995 * so must do two writes.
2997 if (ioc->bus_type == SPI) {
2999 * 1030 and 1035 H/W errata, workaround to access
3000 * the ClearFlashBadSignatureBit
3002 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
3003 diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
3004 diagRwData |= 0x40000000;
3005 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
3006 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
3008 } else /* if((ioc->bus_type == SAS) || (ioc->bus_type == FC)) */ {
3009 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3010 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val |
3011 MPI_DIAG_CLEAR_FLASH_BAD_SIG);
3014 if (sleepFlag == CAN_SLEEP) {
3021 if (ioc->errata_flag_1064)
3022 pci_disable_io_access(ioc->pcidev);
3024 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3025 ddlprintk((MYIOC_s_INFO_FMT "downloadboot diag0val=%x, "
3026 "turning off PREVENT_IOC_BOOT, DISABLE_ARM, RW_ENABLE\n",
3027 ioc->name, diag0val));
3028 diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM | MPI_DIAG_RW_ENABLE);
3029 ddlprintk((MYIOC_s_INFO_FMT "downloadboot now diag0val=%x\n",
3030 ioc->name, diag0val));
3031 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
3033 /* Write 0xFF to reset the sequencer */
3034 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
3036 if (ioc->bus_type == SAS) {
3037 ioc_state = mpt_GetIocState(ioc, 0);
3038 if ( (GetIocFacts(ioc, sleepFlag,
3039 MPT_HOSTEVENT_IOC_BRINGUP)) != 0 ) {
3040 ddlprintk((MYIOC_s_INFO_FMT "GetIocFacts failed: IocState=%x\n",
3041 ioc->name, ioc_state));
3046 for (count=0; count<HZ*20; count++) {
3047 if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
3048 ddlprintk((MYIOC_s_INFO_FMT "downloadboot successful! (count=%d) IocState=%x\n",
3049 ioc->name, count, ioc_state));
3050 if (ioc->bus_type == SAS) {
3053 if ((SendIocInit(ioc, sleepFlag)) != 0) {
3054 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit failed\n",
3058 ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit successful\n",
3062 if (sleepFlag == CAN_SLEEP) {
3068 ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! IocState=%x\n",
3069 ioc->name, ioc_state));
3073 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3075 * KickStart - Perform hard reset of MPT adapter.
3076 * @ioc: Pointer to MPT_ADAPTER structure
3077 * @force: Force hard reset
3078 * @sleepFlag: Specifies whether the process can sleep
3080 * This routine places MPT adapter in diagnostic mode via the
3081 * WriteSequence register, and then performs a hard reset of adapter
3082 * via the Diagnostic register.
3084 * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
3085 * or NO_SLEEP (interrupt thread, use mdelay)
3086 * force - 1 if doorbell active, board fault state
3087 * board operational, IOC_RECOVERY or
3088 * IOC_BRINGUP and there is an alt_ioc.
3092 * 1 - hard reset, READY
3093 * 0 - no reset due to History bit, READY
3094 * -1 - no reset due to History bit but not READY
3095 * OR reset but failed to come READY
3096 * -2 - no reset, could not enter DIAG mode
3097 * -3 - reset but bad FW bit
3100 KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
3102 int hard_reset_done = 0;
3106 dinitprintk((KERN_WARNING MYNAM ": KickStarting %s!\n", ioc->name));
3107 if (ioc->bus_type == SPI) {
3108 /* Always issue a Msg Unit Reset first. This will clear some
3109 * SCSI bus hang conditions.