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:DL-MPTFusionLinux@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>
67 #include "lsi/mpi_log_fc.h"
69 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
70 #define my_NAME "Fusion MPT base driver"
71 #define my_VERSION MPT_LINUX_VERSION_COMMON
72 #define MYNAM "mptbase"
74 MODULE_AUTHOR(MODULEAUTHOR);
75 MODULE_DESCRIPTION(my_NAME);
76 MODULE_LICENSE("GPL");
77 MODULE_VERSION(my_VERSION);
82 static int mpt_msi_enable;
83 module_param(mpt_msi_enable, int, 0);
84 MODULE_PARM_DESC(mpt_msi_enable, " MSI Support Enable (default=0)");
86 static int mpt_channel_mapping;
87 module_param(mpt_channel_mapping, int, 0);
88 MODULE_PARM_DESC(mpt_channel_mapping, " Mapping id's to channels (default=0)");
90 static int mpt_debug_level;
91 module_param(mpt_debug_level, int, 0);
92 MODULE_PARM_DESC(mpt_debug_level, " debug level - refer to mptdebug.h - (default=0)");
95 static int mfcounter = 0;
96 #define PRINT_MF_COUNT 20000
99 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
103 int mpt_lan_index = -1;
104 int mpt_stm_index = -1;
106 struct proc_dir_entry *mpt_proc_root_dir;
108 #define WHOINIT_UNKNOWN 0xAA
110 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
114 /* Adapter link list */
116 /* Callback lookup table */
117 static MPT_CALLBACK MptCallbacks[MPT_MAX_PROTOCOL_DRIVERS];
118 /* Protocol driver class lookup table */
119 static int MptDriverClass[MPT_MAX_PROTOCOL_DRIVERS];
120 /* Event handler lookup table */
121 static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
122 /* Reset handler lookup table */
123 static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
124 static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
126 static int mpt_base_index = -1;
127 static int last_drv_idx = -1;
129 static DECLARE_WAIT_QUEUE_HEAD(mpt_waitq);
131 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
135 static irqreturn_t mpt_interrupt(int irq, void *bus_id);
136 static int mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
137 static int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
138 u32 *req, int replyBytes, u16 *u16reply, int maxwait,
140 static int mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag);
141 static void mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev);
142 static void mpt_adapter_disable(MPT_ADAPTER *ioc);
143 static void mpt_adapter_dispose(MPT_ADAPTER *ioc);
145 static void MptDisplayIocCapabilities(MPT_ADAPTER *ioc);
146 static int MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag);
147 static int GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason);
148 static int GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
149 static int SendIocInit(MPT_ADAPTER *ioc, int sleepFlag);
150 static int SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
151 static int mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag);
152 static int mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag);
153 static int mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
154 static int KickStart(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
155 static int SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag);
156 static int PrimeIocFifos(MPT_ADAPTER *ioc);
157 static int WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
158 static int WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
159 static int WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
160 static int GetLanConfigPages(MPT_ADAPTER *ioc);
161 static int GetIoUnitPage2(MPT_ADAPTER *ioc);
162 int mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
163 static int mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
164 static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
165 static void mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
166 static void mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
167 static void mpt_timer_expired(unsigned long data);
168 static void mpt_get_manufacturing_pg_0(MPT_ADAPTER *ioc);
169 static int SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch);
170 static int SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
171 static int mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag);
172 static int mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
174 #ifdef CONFIG_PROC_FS
175 static int procmpt_summary_read(char *buf, char **start, off_t offset,
176 int request, int *eof, void *data);
177 static int procmpt_version_read(char *buf, char **start, off_t offset,
178 int request, int *eof, void *data);
179 static int procmpt_iocinfo_read(char *buf, char **start, off_t offset,
180 int request, int *eof, void *data);
182 static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
184 //int mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
185 static int ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers);
186 static void mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
187 static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
188 static void mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info);
189 static void mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info);
190 static int mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
191 static void mpt_inactive_raid_list_free(MPT_ADAPTER *ioc);
193 /* module entry point */
194 static int __init fusion_init (void);
195 static void __exit fusion_exit (void);
197 #define CHIPREG_READ32(addr) readl_relaxed(addr)
198 #define CHIPREG_READ32_dmasync(addr) readl(addr)
199 #define CHIPREG_WRITE32(addr,val) writel(val, addr)
200 #define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
201 #define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
204 pci_disable_io_access(struct pci_dev *pdev)
208 pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
210 pci_write_config_word(pdev, PCI_COMMAND, command_reg);
214 pci_enable_io_access(struct pci_dev *pdev)
218 pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
220 pci_write_config_word(pdev, PCI_COMMAND, command_reg);
224 * Process turbo (context) reply...
227 mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa)
229 MPT_FRAME_HDR *mf = NULL;
230 MPT_FRAME_HDR *mr = NULL;
234 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got TURBO reply req_idx=%08x\n",
237 switch (pa >> MPI_CONTEXT_REPLY_TYPE_SHIFT) {
238 case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT:
239 req_idx = pa & 0x0000FFFF;
240 cb_idx = (pa & 0x00FF0000) >> 16;
241 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
243 case MPI_CONTEXT_REPLY_TYPE_LAN:
244 cb_idx = mpt_lan_index;
246 * Blind set of mf to NULL here was fatal
247 * after lan_reply says "freeme"
248 * Fix sort of combined with an optimization here;
249 * added explicit check for case where lan_reply
250 * was just returning 1 and doing nothing else.
251 * For this case skip the callback, but set up
252 * proper mf value first here:-)
254 if ((pa & 0x58000000) == 0x58000000) {
255 req_idx = pa & 0x0000FFFF;
256 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
257 mpt_free_msg_frame(ioc, mf);
262 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
264 case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET:
265 cb_idx = mpt_stm_index;
266 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
273 /* Check for (valid) IO callback! */
274 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
275 MptCallbacks[cb_idx] == NULL) {
276 printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
277 __FUNCTION__, ioc->name, cb_idx);
281 if (MptCallbacks[cb_idx](ioc, mf, mr))
282 mpt_free_msg_frame(ioc, mf);
288 mpt_reply(MPT_ADAPTER *ioc, u32 pa)
299 /* non-TURBO reply! Hmmm, something may be up...
300 * Newest turbo reply mechanism; get address
301 * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
304 /* Map DMA address of reply header to cpu address.
305 * pa is 32 bits - but the dma address may be 32 or 64 bits
306 * get offset based only only the low addresses
309 reply_dma_low = (pa <<= 1);
310 mr = (MPT_FRAME_HDR *)((u8 *)ioc->reply_frames +
311 (reply_dma_low - ioc->reply_frames_low_dma));
313 req_idx = le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx);
314 cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
315 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
317 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got non-TURBO reply=%p req_idx=%x cb_idx=%x Function=%x\n",
318 ioc->name, mr, req_idx, cb_idx, mr->u.hdr.Function));
319 DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mr)
321 /* Check/log IOC log info
323 ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
324 if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
325 u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
326 if (ioc->bus_type == FC)
327 mpt_fc_log_info(ioc, log_info);
328 else if (ioc->bus_type == SPI)
329 mpt_spi_log_info(ioc, log_info);
330 else if (ioc->bus_type == SAS)
331 mpt_sas_log_info(ioc, log_info);
334 if (ioc_stat & MPI_IOCSTATUS_MASK)
335 mpt_iocstatus_info(ioc, (u32)ioc_stat, mf);
337 /* Check for (valid) IO callback! */
338 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
339 MptCallbacks[cb_idx] == NULL) {
340 printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
341 __FUNCTION__, ioc->name, cb_idx);
346 freeme = MptCallbacks[cb_idx](ioc, mf, mr);
349 /* Flush (non-TURBO) reply with a WRITE! */
350 CHIPREG_WRITE32(&ioc->chip->ReplyFifo, pa);
353 mpt_free_msg_frame(ioc, mf);
357 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
359 * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
360 * @irq: irq number (not used)
361 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
363 * This routine is registered via the request_irq() kernel API call,
364 * and handles all interrupts generated from a specific MPT adapter
365 * (also referred to as a IO Controller or IOC).
366 * This routine must clear the interrupt from the adapter and does
367 * so by reading the reply FIFO. Multiple replies may be processed
368 * per single call to this routine.
370 * This routine handles register-level access of the adapter but
371 * dispatches (calls) a protocol-specific callback routine to handle
372 * the protocol-specific details of the MPT request completion.
375 mpt_interrupt(int irq, void *bus_id)
377 MPT_ADAPTER *ioc = bus_id;
378 u32 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
380 if (pa == 0xFFFFFFFF)
384 * Drain the reply FIFO!
387 if (pa & MPI_ADDRESS_REPLY_A_BIT)
390 mpt_turbo_reply(ioc, pa);
391 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
392 } while (pa != 0xFFFFFFFF);
397 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
399 * mpt_base_reply - MPT base driver's callback routine
400 * @ioc: Pointer to MPT_ADAPTER structure
401 * @mf: Pointer to original MPT request frame
402 * @reply: Pointer to MPT reply frame (NULL if TurboReply)
404 * MPT base driver's callback routine; all base driver
405 * "internal" request/reply processing is routed here.
406 * Currently used for EventNotification and EventAck handling.
408 * Returns 1 indicating original alloc'd request frame ptr
409 * should be freed, or 0 if it shouldn't.
412 mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
417 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_base_reply() called\n", ioc->name));
418 #ifdef CONFIG_FUSION_LOGGING
419 if ((ioc->debug_level & MPT_DEBUG_MSG_FRAME) &&
420 !(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) {
421 dmfprintk(ioc, printk(KERN_INFO MYNAM ": Original request frame (@%p) header\n", mf));
422 DBG_DUMP_REQUEST_FRAME_HDR(ioc, (u32 *)mf)
426 func = reply->u.hdr.Function;
427 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_base_reply, Function=%02Xh\n",
430 if (func == MPI_FUNCTION_EVENT_NOTIFICATION) {
431 EventNotificationReply_t *pEvReply = (EventNotificationReply_t *) reply;
435 results = ProcessEventNotification(ioc, pEvReply, &evHandlers);
436 if (results != evHandlers) {
437 /* CHECKME! Any special handling needed here? */
438 devtverboseprintk(ioc, printk(MYIOC_s_WARN_FMT "Called %d event handlers, sum results = %d\n",
439 ioc->name, evHandlers, results));
443 * Hmmm... It seems that EventNotificationReply is an exception
444 * to the rule of one reply per request.
446 if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) {
449 devtverboseprintk(ioc, printk(MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p returns Request frame\n",
450 ioc->name, pEvReply));
453 #ifdef CONFIG_PROC_FS
454 // LogEvent(ioc, pEvReply);
457 } else if (func == MPI_FUNCTION_EVENT_ACK) {
458 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_base_reply, EventAck reply received\n",
460 } else if (func == MPI_FUNCTION_CONFIG) {
464 dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "config_complete (mf=%p,mr=%p)\n",
465 ioc->name, mf, reply));
467 pCfg = * ((CONFIGPARMS **)((u8 *) mf + ioc->req_sz - sizeof(void *)));
470 /* disable timer and remove from linked list */
471 del_timer(&pCfg->timer);
473 spin_lock_irqsave(&ioc->FreeQlock, flags);
474 list_del(&pCfg->linkage);
475 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
478 * If IOC Status is SUCCESS, save the header
479 * and set the status code to GOOD.
481 pCfg->status = MPT_CONFIG_ERROR;
483 ConfigReply_t *pReply = (ConfigReply_t *)reply;
486 status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
487 dcprintk(ioc, printk(KERN_NOTICE " IOCStatus=%04xh, IOCLogInfo=%08xh\n",
488 status, le32_to_cpu(pReply->IOCLogInfo)));
490 pCfg->status = status;
491 if (status == MPI_IOCSTATUS_SUCCESS) {
492 if ((pReply->Header.PageType &
493 MPI_CONFIG_PAGETYPE_MASK) ==
494 MPI_CONFIG_PAGETYPE_EXTENDED) {
495 pCfg->cfghdr.ehdr->ExtPageLength =
496 le16_to_cpu(pReply->ExtPageLength);
497 pCfg->cfghdr.ehdr->ExtPageType =
500 pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
502 /* If this is a regular header, save PageLength. */
503 /* LMP Do this better so not using a reserved field! */
504 pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
505 pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
506 pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
511 * Wake up the original calling thread
516 } else if (func == MPI_FUNCTION_SAS_IO_UNIT_CONTROL) {
517 /* we should be always getting a reply frame */
518 memcpy(ioc->persist_reply_frame, reply,
519 min(MPT_DEFAULT_FRAME_SIZE,
520 4*reply->u.reply.MsgLength));
521 del_timer(&ioc->persist_timer);
522 ioc->persist_wait_done = 1;
525 printk(MYIOC_s_ERR_FMT "Unexpected msg function (=%02Xh) reply received!\n",
530 * Conditionally tell caller to free the original
531 * EventNotification/EventAck/unexpected request frame!
536 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
538 * mpt_register - Register protocol-specific main callback handler.
539 * @cbfunc: callback function pointer
540 * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
542 * This routine is called by a protocol-specific driver (SCSI host,
543 * LAN, SCSI target) to register its reply callback routine. Each
544 * protocol-specific driver must do this before it will be able to
545 * use any IOC resources, such as obtaining request frames.
547 * NOTES: The SCSI protocol driver currently calls this routine thrice
548 * in order to register separate callbacks; one for "normal" SCSI IO;
549 * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
551 * Returns a positive integer valued "handle" in the
552 * range (and S.O.D. order) {N,...,7,6,5,...,1} if successful.
553 * Any non-positive return value (including zero!) should be considered
554 * an error by the caller.
557 mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
564 * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
565 * (slot/handle 0 is reserved!)
567 for (i = MPT_MAX_PROTOCOL_DRIVERS-1; i; i--) {
568 if (MptCallbacks[i] == NULL) {
569 MptCallbacks[i] = cbfunc;
570 MptDriverClass[i] = dclass;
571 MptEvHandlers[i] = NULL;
580 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
582 * mpt_deregister - Deregister a protocol drivers resources.
583 * @cb_idx: previously registered callback handle
585 * Each protocol-specific driver should call this routine when its
586 * module is unloaded.
589 mpt_deregister(int cb_idx)
591 if ((cb_idx >= 0) && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
592 MptCallbacks[cb_idx] = NULL;
593 MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
594 MptEvHandlers[cb_idx] = NULL;
600 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
602 * mpt_event_register - Register protocol-specific event callback
604 * @cb_idx: previously registered (via mpt_register) callback handle
605 * @ev_cbfunc: callback function
607 * This routine can be called by one or more protocol-specific drivers
608 * if/when they choose to be notified of MPT events.
610 * Returns 0 for success.
613 mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc)
615 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
618 MptEvHandlers[cb_idx] = ev_cbfunc;
622 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
624 * mpt_event_deregister - Deregister protocol-specific event callback
626 * @cb_idx: previously registered callback handle
628 * Each protocol-specific driver should call this routine
629 * when it does not (or can no longer) handle events,
630 * or when its module is unloaded.
633 mpt_event_deregister(int cb_idx)
635 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
638 MptEvHandlers[cb_idx] = NULL;
641 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
643 * mpt_reset_register - Register protocol-specific IOC reset handler.
644 * @cb_idx: previously registered (via mpt_register) callback handle
645 * @reset_func: reset function
647 * This routine can be called by one or more protocol-specific drivers
648 * if/when they choose to be notified of IOC resets.
650 * Returns 0 for success.
653 mpt_reset_register(int cb_idx, MPT_RESETHANDLER reset_func)
655 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
658 MptResetHandlers[cb_idx] = reset_func;
662 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
664 * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
665 * @cb_idx: previously registered callback handle
667 * Each protocol-specific driver should call this routine
668 * when it does not (or can no longer) handle IOC reset handling,
669 * or when its module is unloaded.
672 mpt_reset_deregister(int cb_idx)
674 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
677 MptResetHandlers[cb_idx] = NULL;
680 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
682 * mpt_device_driver_register - Register device driver hooks
683 * @dd_cbfunc: driver callbacks struct
684 * @cb_idx: MPT protocol driver index
687 mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx)
690 const struct pci_device_id *id;
692 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
695 MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
697 /* call per pci device probe entry point */
698 list_for_each_entry(ioc, &ioc_list, list) {
699 id = ioc->pcidev->driver ?
700 ioc->pcidev->driver->id_table : NULL;
701 if (dd_cbfunc->probe)
702 dd_cbfunc->probe(ioc->pcidev, id);
708 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
710 * mpt_device_driver_deregister - DeRegister device driver hooks
711 * @cb_idx: MPT protocol driver index
714 mpt_device_driver_deregister(int cb_idx)
716 struct mpt_pci_driver *dd_cbfunc;
719 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
722 dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
724 list_for_each_entry(ioc, &ioc_list, list) {
725 if (dd_cbfunc->remove)
726 dd_cbfunc->remove(ioc->pcidev);
729 MptDeviceDriverHandlers[cb_idx] = NULL;
733 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
735 * mpt_get_msg_frame - Obtain a MPT request frame from the pool (of 1024)
736 * allocated per MPT adapter.
737 * @handle: Handle of registered MPT protocol driver
738 * @ioc: Pointer to MPT adapter structure
740 * Returns pointer to a MPT request frame or %NULL if none are available
741 * or IOC is not active.
744 mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
748 u16 req_idx; /* Request index */
750 /* validate handle and ioc identifier */
754 printk(KERN_WARNING "IOC Not Active! mpt_get_msg_frame returning NULL!\n");
757 /* If interrupts are not attached, do not return a request frame */
761 spin_lock_irqsave(&ioc->FreeQlock, flags);
762 if (!list_empty(&ioc->FreeQ)) {
765 mf = list_entry(ioc->FreeQ.next, MPT_FRAME_HDR,
766 u.frame.linkage.list);
767 list_del(&mf->u.frame.linkage.list);
768 mf->u.frame.linkage.arg1 = 0;
769 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
770 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
772 req_idx = req_offset / ioc->req_sz;
773 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
774 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
775 ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame; /* Default, will be changed if necessary in SG generation */
782 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
786 printk(KERN_WARNING "IOC Active. No free Msg Frames! Count 0x%x Max 0x%x\n", ioc->mfcnt, ioc->req_depth);
788 if (mfcounter == PRINT_MF_COUNT)
789 printk(KERN_INFO "MF Count 0x%x Max 0x%x \n", ioc->mfcnt, ioc->req_depth);
792 dmfprintk(ioc, printk(KERN_INFO MYNAM ": %s: mpt_get_msg_frame(%d,%d), got mf=%p\n",
793 ioc->name, handle, ioc->id, mf));
797 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
799 * mpt_put_msg_frame - Send a protocol specific MPT request frame
801 * @handle: Handle of registered MPT protocol driver
802 * @ioc: Pointer to MPT adapter structure
803 * @mf: Pointer to MPT request frame
805 * This routine posts a MPT request frame to the request post FIFO of a
806 * specific MPT adapter.
809 mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
813 u16 req_idx; /* Request index */
815 /* ensure values are reset properly! */
816 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
817 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
819 req_idx = req_offset / ioc->req_sz;
820 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
821 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
823 DBG_DUMP_PUT_MSG_FRAME(ioc, (u32 *)mf);
825 mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
826 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mf_dma_addr=%x req_idx=%d RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx, ioc->RequestNB[req_idx]));
827 CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
830 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
832 * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
833 * @handle: Handle of registered MPT protocol driver
834 * @ioc: Pointer to MPT adapter structure
835 * @mf: Pointer to MPT request frame
837 * This routine places a MPT request frame back on the MPT adapter's
841 mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
845 /* Put Request back on FreeQ! */
846 spin_lock_irqsave(&ioc->FreeQlock, flags);
847 mf->u.frame.linkage.arg1 = 0xdeadbeaf; /* signature to know if this mf is freed */
848 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
852 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
855 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
857 * mpt_add_sge - Place a simple SGE at address pAddr.
858 * @pAddr: virtual address for SGE
859 * @flagslength: SGE flags and data transfer length
860 * @dma_addr: Physical address
862 * This routine places a MPT request frame back on the MPT adapter's
866 mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
868 if (sizeof(dma_addr_t) == sizeof(u64)) {
869 SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
870 u32 tmp = dma_addr & 0xFFFFFFFF;
872 pSge->FlagsLength = cpu_to_le32(flagslength);
873 pSge->Address.Low = cpu_to_le32(tmp);
874 tmp = (u32) ((u64)dma_addr >> 32);
875 pSge->Address.High = cpu_to_le32(tmp);
878 SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
879 pSge->FlagsLength = cpu_to_le32(flagslength);
880 pSge->Address = cpu_to_le32(dma_addr);
884 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
886 * mpt_send_handshake_request - Send MPT request via doorbell handshake method.
887 * @handle: Handle of registered MPT protocol driver
888 * @ioc: Pointer to MPT adapter structure
889 * @reqBytes: Size of the request in bytes
890 * @req: Pointer to MPT request frame
891 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
893 * This routine is used exclusively to send MptScsiTaskMgmt
894 * requests since they are required to be sent via doorbell handshake.
896 * NOTE: It is the callers responsibility to byte-swap fields in the
897 * request which are greater than 1 byte in size.
899 * Returns 0 for success, non-zero for failure.
902 mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
908 /* State is known to be good upon entering
909 * this function so issue the bus reset
914 * Emulate what mpt_put_msg_frame() does /wrt to sanity
915 * setting cb_idx/req_idx. But ONLY if this request
916 * is in proper (pre-alloc'd) request buffer range...
918 ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
919 if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
920 MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
921 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
922 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle;
925 /* Make sure there are no doorbells */
926 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
928 CHIPREG_WRITE32(&ioc->chip->Doorbell,
929 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
930 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
932 /* Wait for IOC doorbell int */
933 if ((ii = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0) {
937 /* Read doorbell and check for active bit */
938 if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
941 dhsprintk(ioc, printk(KERN_INFO MYNAM ": %s: mpt_send_handshake_request start, WaitCnt=%d\n",
944 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
946 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
950 /* Send request via doorbell handshake */
951 req_as_bytes = (u8 *) req;
952 for (ii = 0; ii < reqBytes/4; ii++) {
955 word = ((req_as_bytes[(ii*4) + 0] << 0) |
956 (req_as_bytes[(ii*4) + 1] << 8) |
957 (req_as_bytes[(ii*4) + 2] << 16) |
958 (req_as_bytes[(ii*4) + 3] << 24));
959 CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
960 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
966 if (r >= 0 && WaitForDoorbellInt(ioc, 10, sleepFlag) >= 0)
971 /* Make sure there are no doorbells */
972 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
977 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
979 * mpt_host_page_access_control - control the IOC's Host Page Buffer access
980 * @ioc: Pointer to MPT adapter structure
981 * @access_control_value: define bits below
982 * @sleepFlag: Specifies whether the process can sleep
984 * Provides mechanism for the host driver to control the IOC's
985 * Host Page Buffer access.
987 * Access Control Value - bits[15:12]
989 * 1h Enable Access { MPI_DB_HPBAC_ENABLE_ACCESS }
990 * 2h Disable Access { MPI_DB_HPBAC_DISABLE_ACCESS }
991 * 3h Free Buffer { MPI_DB_HPBAC_FREE_BUFFER }
993 * Returns 0 for success, non-zero for failure.
997 mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag)
1001 /* return if in use */
1002 if (CHIPREG_READ32(&ioc->chip->Doorbell)
1003 & MPI_DOORBELL_ACTIVE)
1006 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1008 CHIPREG_WRITE32(&ioc->chip->Doorbell,
1009 ((MPI_FUNCTION_HOST_PAGEBUF_ACCESS_CONTROL
1010 <<MPI_DOORBELL_FUNCTION_SHIFT) |
1011 (access_control_value<<12)));
1013 /* Wait for IOC to clear Doorbell Status bit */
1014 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
1020 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1022 * mpt_host_page_alloc - allocate system memory for the fw
1023 * @ioc: Pointer to pointer to IOC adapter
1024 * @ioc_init: Pointer to ioc init config page
1026 * If we already allocated memory in past, then resend the same pointer.
1027 * Returns 0 for success, non-zero for failure.
1030 mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
1034 u32 host_page_buffer_sz=0;
1036 if(!ioc->HostPageBuffer) {
1038 host_page_buffer_sz =
1039 le32_to_cpu(ioc->facts.HostPageBufferSGE.FlagsLength) & 0xFFFFFF;
1041 if(!host_page_buffer_sz)
1042 return 0; /* fw doesn't need any host buffers */
1044 /* spin till we get enough memory */
1045 while(host_page_buffer_sz > 0) {
1047 if((ioc->HostPageBuffer = pci_alloc_consistent(
1049 host_page_buffer_sz,
1050 &ioc->HostPageBuffer_dma)) != NULL) {
1052 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1053 "host_page_buffer @ %p, dma @ %x, sz=%d bytes\n",
1054 ioc->name, ioc->HostPageBuffer,
1055 (u32)ioc->HostPageBuffer_dma,
1056 host_page_buffer_sz));
1057 ioc->alloc_total += host_page_buffer_sz;
1058 ioc->HostPageBuffer_sz = host_page_buffer_sz;
1062 host_page_buffer_sz -= (4*1024);
1066 if(!ioc->HostPageBuffer) {
1067 printk(MYIOC_s_ERR_FMT
1068 "Failed to alloc memory for host_page_buffer!\n",
1073 psge = (char *)&ioc_init->HostPageBufferSGE;
1074 flags_length = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
1075 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
1076 MPI_SGE_FLAGS_32_BIT_ADDRESSING |
1077 MPI_SGE_FLAGS_HOST_TO_IOC |
1078 MPI_SGE_FLAGS_END_OF_BUFFER;
1079 if (sizeof(dma_addr_t) == sizeof(u64)) {
1080 flags_length |= MPI_SGE_FLAGS_64_BIT_ADDRESSING;
1082 flags_length = flags_length << MPI_SGE_FLAGS_SHIFT;
1083 flags_length |= ioc->HostPageBuffer_sz;
1084 mpt_add_sge(psge, flags_length, ioc->HostPageBuffer_dma);
1085 ioc->facts.HostPageBufferSGE = ioc_init->HostPageBufferSGE;
1090 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1092 * mpt_verify_adapter - Given IOC identifier, set pointer to its adapter structure.
1093 * @iocid: IOC unique identifier (integer)
1094 * @iocpp: Pointer to pointer to IOC adapter
1096 * Given a unique IOC identifier, set pointer to the associated MPT
1097 * adapter structure.
1099 * Returns iocid and sets iocpp if iocid is found.
1100 * Returns -1 if iocid is not found.
1103 mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
1107 list_for_each_entry(ioc,&ioc_list,list) {
1108 if (ioc->id == iocid) {
1119 * mpt_get_product_name - returns product string
1120 * @vendor: pci vendor id
1121 * @device: pci device id
1122 * @revision: pci revision id
1123 * @prod_name: string returned
1125 * Returns product string displayed when driver loads,
1126 * in /proc/mpt/summary and /sysfs/class/scsi_host/host<X>/version_product
1130 mpt_get_product_name(u16 vendor, u16 device, u8 revision, char *prod_name)
1132 char *product_str = NULL;
1134 if (vendor == PCI_VENDOR_ID_BROCADE) {
1137 case MPI_MANUFACTPAGE_DEVICEID_FC949E:
1141 product_str = "BRE040 A0";
1144 product_str = "BRE040 A1";
1147 product_str = "BRE040";
1157 case MPI_MANUFACTPAGE_DEVICEID_FC909:
1158 product_str = "LSIFC909 B1";
1160 case MPI_MANUFACTPAGE_DEVICEID_FC919:
1161 product_str = "LSIFC919 B0";
1163 case MPI_MANUFACTPAGE_DEVICEID_FC929:
1164 product_str = "LSIFC929 B0";
1166 case MPI_MANUFACTPAGE_DEVICEID_FC919X:
1167 if (revision < 0x80)
1168 product_str = "LSIFC919X A0";
1170 product_str = "LSIFC919XL A1";
1172 case MPI_MANUFACTPAGE_DEVICEID_FC929X:
1173 if (revision < 0x80)
1174 product_str = "LSIFC929X A0";
1176 product_str = "LSIFC929XL A1";
1178 case MPI_MANUFACTPAGE_DEVICEID_FC939X:
1179 product_str = "LSIFC939X A1";
1181 case MPI_MANUFACTPAGE_DEVICEID_FC949X:
1182 product_str = "LSIFC949X A1";
1184 case MPI_MANUFACTPAGE_DEVICEID_FC949E:
1188 product_str = "LSIFC949E A0";
1191 product_str = "LSIFC949E A1";
1194 product_str = "LSIFC949E";
1198 case MPI_MANUFACTPAGE_DEVID_53C1030:
1202 product_str = "LSI53C1030 A0";
1205 product_str = "LSI53C1030 B0";
1208 product_str = "LSI53C1030 B1";
1211 product_str = "LSI53C1030 B2";
1214 product_str = "LSI53C1030 C0";
1217 product_str = "LSI53C1030T A0";
1220 product_str = "LSI53C1030T A2";
1223 product_str = "LSI53C1030T A3";
1226 product_str = "LSI53C1020A A1";
1229 product_str = "LSI53C1030";
1233 case MPI_MANUFACTPAGE_DEVID_1030_53C1035:
1237 product_str = "LSI53C1035 A2";
1240 product_str = "LSI53C1035 B0";
1243 product_str = "LSI53C1035";
1247 case MPI_MANUFACTPAGE_DEVID_SAS1064:
1251 product_str = "LSISAS1064 A1";
1254 product_str = "LSISAS1064 A2";
1257 product_str = "LSISAS1064 A3";
1260 product_str = "LSISAS1064 A4";
1263 product_str = "LSISAS1064";
1267 case MPI_MANUFACTPAGE_DEVID_SAS1064E:
1271 product_str = "LSISAS1064E A0";
1274 product_str = "LSISAS1064E B0";
1277 product_str = "LSISAS1064E B1";
1280 product_str = "LSISAS1064E B2";
1283 product_str = "LSISAS1064E B3";
1286 product_str = "LSISAS1064E";
1290 case MPI_MANUFACTPAGE_DEVID_SAS1068:
1294 product_str = "LSISAS1068 A0";
1297 product_str = "LSISAS1068 B0";
1300 product_str = "LSISAS1068 B1";
1303 product_str = "LSISAS1068";
1307 case MPI_MANUFACTPAGE_DEVID_SAS1068E:
1311 product_str = "LSISAS1068E A0";
1314 product_str = "LSISAS1068E B0";
1317 product_str = "LSISAS1068E B1";
1320 product_str = "LSISAS1068E B2";
1323 product_str = "LSISAS1068E B3";
1326 product_str = "LSISAS1068E";
1330 case MPI_MANUFACTPAGE_DEVID_SAS1078:
1334 product_str = "LSISAS1078 A0";
1337 product_str = "LSISAS1078 B0";
1340 product_str = "LSISAS1078 C0";
1343 product_str = "LSISAS1078 C1";
1346 product_str = "LSISAS1078 C2";
1349 product_str = "LSISAS1078";
1357 sprintf(prod_name, "%s", product_str);
1360 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1362 * mpt_attach - Install a PCI intelligent MPT adapter.
1363 * @pdev: Pointer to pci_dev structure
1364 * @id: PCI device ID information
1366 * This routine performs all the steps necessary to bring the IOC of
1367 * a MPT adapter to a OPERATIONAL state. This includes registering
1368 * memory regions, registering the interrupt, and allocating request
1369 * and reply memory pools.
1371 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1374 * Returns 0 for success, non-zero for failure.
1376 * TODO: Add support for polled controllers
1379 mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1383 unsigned long mem_phys;
1391 static int mpt_ids = 0;
1392 #ifdef CONFIG_PROC_FS
1393 struct proc_dir_entry *dent, *ent;
1396 ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
1398 printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
1402 ioc->debug_level = mpt_debug_level;
1403 if (mpt_debug_level)
1404 printk(KERN_INFO MYNAM ": mpt_debug_level=%xh\n", mpt_debug_level);
1406 if (pci_enable_device(pdev))
1409 dinitprintk(ioc, printk(KERN_WARNING MYNAM ": mpt_adapter_install\n"));
1411 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
1412 dprintk(ioc, printk(KERN_INFO MYNAM
1413 ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n"));
1414 } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
1415 printk(KERN_WARNING MYNAM ": 32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
1419 if (!pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
1420 dprintk(ioc, printk(KERN_INFO MYNAM
1421 ": Using 64 bit consistent mask\n"));
1423 dprintk(ioc, printk(KERN_INFO MYNAM
1424 ": Not using 64 bit consistent mask\n"));
1427 ioc->alloc_total = sizeof(MPT_ADAPTER);
1428 ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
1429 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
1432 ioc->diagPending = 0;
1433 spin_lock_init(&ioc->diagLock);
1434 spin_lock_init(&ioc->initializing_hba_lock);
1436 /* Initialize the event logging.
1438 ioc->eventTypes = 0; /* None */
1439 ioc->eventContext = 0;
1440 ioc->eventLogSize = 0;
1447 ioc->cached_fw = NULL;
1449 /* Initilize SCSI Config Data structure
1451 memset(&ioc->spi_data, 0, sizeof(SpiCfgData));
1453 /* Initialize the running configQ head.
1455 INIT_LIST_HEAD(&ioc->configQ);
1457 /* Initialize the fc rport list head.
1459 INIT_LIST_HEAD(&ioc->fc_rports);
1461 /* Find lookup slot. */
1462 INIT_LIST_HEAD(&ioc->list);
1463 ioc->id = mpt_ids++;
1465 mem_phys = msize = 0;
1467 for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) {
1468 if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
1471 /* Get I/O space! */
1472 port = pci_resource_start(pdev, ii);
1473 psize = pci_resource_len(pdev,ii);
1478 mem_phys = pci_resource_start(pdev, ii);
1479 msize = pci_resource_len(pdev,ii);
1482 ioc->mem_size = msize;
1485 /* Get logical ptr for PciMem0 space */
1486 /*mem = ioremap(mem_phys, msize);*/
1487 mem = ioremap(mem_phys, msize);
1489 printk(KERN_ERR MYNAM ": ERROR - Unable to map adapter memory!\n");
1494 dinitprintk(ioc, printk(KERN_INFO MYNAM ": mem = %p, mem_phys = %lx\n", mem, mem_phys));
1496 dinitprintk(ioc, printk(KERN_INFO MYNAM ": facts @ %p, pfacts[0] @ %p\n",
1497 &ioc->facts, &ioc->pfacts[0]));
1499 ioc->mem_phys = mem_phys;
1500 ioc->chip = (SYSIF_REGS __iomem *)mem;
1502 /* Save Port IO values in case we need to do downloadboot */
1504 u8 *pmem = (u8*)port;
1505 ioc->pio_mem_phys = port;
1506 ioc->pio_chip = (SYSIF_REGS __iomem *)pmem;
1509 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1510 mpt_get_product_name(pdev->vendor, pdev->device, revision, ioc->prod_name);
1512 switch (pdev->device)
1514 case MPI_MANUFACTPAGE_DEVICEID_FC939X:
1515 case MPI_MANUFACTPAGE_DEVICEID_FC949X:
1516 ioc->errata_flag_1064 = 1;
1517 case MPI_MANUFACTPAGE_DEVICEID_FC909:
1518 case MPI_MANUFACTPAGE_DEVICEID_FC929:
1519 case MPI_MANUFACTPAGE_DEVICEID_FC919:
1520 case MPI_MANUFACTPAGE_DEVICEID_FC949E:
1524 case MPI_MANUFACTPAGE_DEVICEID_FC929X:
1525 if (revision < XL_929) {
1526 /* 929X Chip Fix. Set Split transactions level
1527 * for PCIX. Set MOST bits to zero.
1529 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1531 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1533 /* 929XL Chip Fix. Set MMRBC to 0x08.
1535 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1537 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1542 case MPI_MANUFACTPAGE_DEVICEID_FC919X:
1543 /* 919X Chip Fix. Set Split transactions level
1544 * for PCIX. Set MOST bits to zero.
1546 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1548 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1552 case MPI_MANUFACTPAGE_DEVID_53C1030:
1553 /* 1030 Chip Fix. Disable Split transactions
1554 * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
1556 if (revision < C0_1030) {
1557 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1559 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1562 case MPI_MANUFACTPAGE_DEVID_1030_53C1035:
1563 ioc->bus_type = SPI;
1566 case MPI_MANUFACTPAGE_DEVID_SAS1064:
1567 case MPI_MANUFACTPAGE_DEVID_SAS1068:
1568 ioc->errata_flag_1064 = 1;
1570 case MPI_MANUFACTPAGE_DEVID_SAS1064E:
1571 case MPI_MANUFACTPAGE_DEVID_SAS1068E:
1572 case MPI_MANUFACTPAGE_DEVID_SAS1078:
1573 ioc->bus_type = SAS;
1576 if (ioc->errata_flag_1064)
1577 pci_disable_io_access(pdev);
1579 sprintf(ioc->name, "ioc%d", ioc->id);
1581 spin_lock_init(&ioc->FreeQlock);
1584 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1586 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1588 /* Set lookup ptr. */
1589 list_add_tail(&ioc->list, &ioc_list);
1591 /* Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
1593 mpt_detect_bound_ports(ioc, pdev);
1595 if ((r = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
1597 printk(KERN_WARNING MYNAM
1598 ": WARNING - %s did not initialize properly! (%d)\n",
1601 list_del(&ioc->list);
1603 ioc->alt_ioc->alt_ioc = NULL;
1606 pci_set_drvdata(pdev, NULL);
1610 /* call per device driver probe entry point */
1611 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1612 if(MptDeviceDriverHandlers[ii] &&
1613 MptDeviceDriverHandlers[ii]->probe) {
1614 MptDeviceDriverHandlers[ii]->probe(pdev,id);
1618 #ifdef CONFIG_PROC_FS
1620 * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
1622 dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
1624 ent = create_proc_entry("info", S_IFREG|S_IRUGO, dent);
1626 ent->read_proc = procmpt_iocinfo_read;
1629 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, dent);
1631 ent->read_proc = procmpt_summary_read;
1640 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1642 * mpt_detach - Remove a PCI intelligent MPT adapter.
1643 * @pdev: Pointer to pci_dev structure
1647 mpt_detach(struct pci_dev *pdev)
1649 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1653 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
1654 remove_proc_entry(pname, NULL);
1655 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/info", ioc->name);
1656 remove_proc_entry(pname, NULL);
1657 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
1658 remove_proc_entry(pname, NULL);
1660 /* call per device driver remove entry point */
1661 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1662 if(MptDeviceDriverHandlers[ii] &&
1663 MptDeviceDriverHandlers[ii]->remove) {
1664 MptDeviceDriverHandlers[ii]->remove(pdev);
1668 /* Disable interrupts! */
1669 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1672 synchronize_irq(pdev->irq);
1674 /* Clear any lingering interrupt */
1675 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1677 CHIPREG_READ32(&ioc->chip->IntStatus);
1679 mpt_adapter_dispose(ioc);
1681 pci_set_drvdata(pdev, NULL);
1684 /**************************************************************************
1688 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1690 * mpt_suspend - Fusion MPT base driver suspend routine.
1691 * @pdev: Pointer to pci_dev structure
1692 * @state: new state to enter
1695 mpt_suspend(struct pci_dev *pdev, pm_message_t state)
1698 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1700 device_state=pci_choose_state(pdev, state);
1702 printk(MYIOC_s_INFO_FMT
1703 "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n",
1704 ioc->name, pdev, pci_name(pdev), device_state);
1706 pci_save_state(pdev);
1708 /* put ioc into READY_STATE */
1709 if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
1710 printk(MYIOC_s_ERR_FMT
1711 "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
1714 /* disable interrupts */
1715 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1718 /* Clear any lingering interrupt */
1719 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1721 pci_disable_device(pdev);
1722 pci_set_power_state(pdev, device_state);
1727 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1729 * mpt_resume - Fusion MPT base driver resume routine.
1730 * @pdev: Pointer to pci_dev structure
1733 mpt_resume(struct pci_dev *pdev)
1735 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
1736 u32 device_state = pdev->current_state;
1740 printk(MYIOC_s_INFO_FMT
1741 "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n",
1742 ioc->name, pdev, pci_name(pdev), device_state);
1744 pci_set_power_state(pdev, 0);
1745 pci_restore_state(pdev);
1746 err = pci_enable_device(pdev);
1750 /* enable interrupts */
1751 CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
1754 printk(MYIOC_s_INFO_FMT
1755 "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
1757 (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
1758 CHIPREG_READ32(&ioc->chip->Doorbell));
1760 /* bring ioc to operational state */
1761 if ((recovery_state = mpt_do_ioc_recovery(ioc,
1762 MPT_HOSTEVENT_IOC_RECOVER, CAN_SLEEP)) != 0) {
1763 printk(MYIOC_s_INFO_FMT
1764 "pci-resume: Cannot recover, error:[%x]\n",
1765 ioc->name, recovery_state);
1767 printk(MYIOC_s_INFO_FMT
1768 "pci-resume: success\n", ioc->name);
1776 mpt_signal_reset(int index, MPT_ADAPTER *ioc, int reset_phase)
1778 if ((MptDriverClass[index] == MPTSPI_DRIVER &&
1779 ioc->bus_type != SPI) ||
1780 (MptDriverClass[index] == MPTFC_DRIVER &&
1781 ioc->bus_type != FC) ||
1782 (MptDriverClass[index] == MPTSAS_DRIVER &&
1783 ioc->bus_type != SAS))
1784 /* make sure we only call the relevant reset handler
1787 return (MptResetHandlers[index])(ioc, reset_phase);
1790 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1792 * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
1793 * @ioc: Pointer to MPT adapter structure
1794 * @reason: Event word / reason
1795 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
1797 * This routine performs all the steps necessary to bring the IOC
1798 * to a OPERATIONAL state.
1800 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1805 * -1 if failed to get board READY
1806 * -2 if READY but IOCFacts Failed
1807 * -3 if READY but PrimeIOCFifos Failed
1808 * -4 if READY but IOCInit Failed
1811 mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1813 int hard_reset_done = 0;
1814 int alt_ioc_ready = 0;
1820 int reset_alt_ioc_active = 0;
1821 int irq_allocated = 0;
1824 printk(KERN_INFO MYNAM ": Initiating %s %s\n",
1825 ioc->name, reason==MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
1827 /* Disable reply interrupts (also blocks FreeQ) */
1828 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1832 if (ioc->alt_ioc->active)
1833 reset_alt_ioc_active = 1;
1835 /* Disable alt-IOC's reply interrupts (and FreeQ) for a bit ... */
1836 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, 0xFFFFFFFF);
1837 ioc->alt_ioc->active = 0;
1841 if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
1844 if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
1845 if (hard_reset_done == -4) {
1846 printk(KERN_WARNING MYNAM ": %s Owned by PEER..skipping!\n",
1849 if (reset_alt_ioc_active && ioc->alt_ioc) {
1850 /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
1851 dprintk(ioc, printk(KERN_INFO MYNAM
1852 ": alt-%s reply irq re-enabled\n",
1853 ioc->alt_ioc->name));
1854 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
1855 ioc->alt_ioc->active = 1;
1859 printk(KERN_WARNING MYNAM ": %s NOT READY WARNING!\n",
1865 /* hard_reset_done = 0 if a soft reset was performed
1866 * and 1 if a hard reset was performed.
1868 if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
1869 if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
1872 printk(KERN_WARNING MYNAM
1873 ": alt-%s: Not ready WARNING!\n",
1874 ioc->alt_ioc->name);
1877 for (ii=0; ii<5; ii++) {
1878 /* Get IOC facts! Allow 5 retries */
1879 if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
1885 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc));
1887 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1888 MptDisplayIocCapabilities(ioc);
1891 if (alt_ioc_ready) {
1892 if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
1893 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1894 "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc));
1895 /* Retry - alt IOC was initialized once
1897 rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
1900 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1901 "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
1903 reset_alt_ioc_active = 0;
1904 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1905 MptDisplayIocCapabilities(ioc->alt_ioc);
1910 * Device is reset now. It must have de-asserted the interrupt line
1911 * (if it was asserted) and it should be safe to register for the
1914 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
1916 if (ioc->pcidev->irq) {
1917 if (mpt_msi_enable && !pci_enable_msi(ioc->pcidev))
1918 printk(MYIOC_s_INFO_FMT "PCI-MSI enabled\n",
1920 rc = request_irq(ioc->pcidev->irq, mpt_interrupt,
1921 IRQF_SHARED, ioc->name, ioc);
1923 printk(MYIOC_s_ERR_FMT "Unable to allocate "
1924 "interrupt %d!\n", ioc->name,
1927 pci_disable_msi(ioc->pcidev);
1931 ioc->pci_irq = ioc->pcidev->irq;
1932 pci_set_master(ioc->pcidev); /* ?? */
1933 pci_set_drvdata(ioc->pcidev, ioc);
1934 dprintk(ioc, printk(KERN_INFO MYNAM ": %s installed at interrupt "
1935 "%d\n", ioc->name, ioc->pcidev->irq));
1939 /* Prime reply & request queues!
1940 * (mucho alloc's) Must be done prior to
1941 * init as upper addresses are needed for init.
1942 * If fails, continue with alt-ioc processing
1944 if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
1947 /* May need to check/upload firmware & data here!
1948 * If fails, continue with alt-ioc processing
1950 if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
1953 if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
1954 printk(KERN_WARNING MYNAM ": alt-%s: (%d) FIFO mgmt alloc WARNING!\n",
1955 ioc->alt_ioc->name, rc);
1957 reset_alt_ioc_active = 0;
1960 if (alt_ioc_ready) {
1961 if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
1963 reset_alt_ioc_active = 0;
1964 printk(KERN_WARNING MYNAM
1965 ": alt-%s: (%d) init failure WARNING!\n",
1966 ioc->alt_ioc->name, rc);
1970 if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
1971 if (ioc->upload_fw) {
1972 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1973 "firmware upload required!\n", ioc->name));
1975 /* Controller is not operational, cannot do upload
1978 rc = mpt_do_upload(ioc, sleepFlag);
1980 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
1982 * Maintain only one pointer to FW memory
1983 * so there will not be two attempt to
1984 * downloadboot onboard dual function
1985 * chips (mpt_adapter_disable,
1988 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
1989 ": mpt_upload: alt_%s has cached_fw=%p \n",
1990 ioc->name, ioc->alt_ioc->name, ioc->alt_ioc->cached_fw));
1991 ioc->alt_ioc->cached_fw = NULL;
1994 printk(KERN_WARNING MYNAM ": firmware upload failure!\n");
2002 /* Enable! (reply interrupt) */
2003 CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
2007 if (reset_alt_ioc_active && ioc->alt_ioc) {
2008 /* (re)Enable alt-IOC! (reply interrupt) */
2009 dinitprintk(ioc, printk(KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
2010 ioc->alt_ioc->name));
2011 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
2012 ioc->alt_ioc->active = 1;
2015 /* Enable MPT base driver management of EventNotification
2016 * and EventAck handling.
2018 if ((ret == 0) && (!ioc->facts.EventState))
2019 (void) SendEventNotification(ioc, 1); /* 1=Enable EventNotification */
2021 if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
2022 (void) SendEventNotification(ioc->alt_ioc, 1); /* 1=Enable EventNotification */
2024 /* Add additional "reason" check before call to GetLanConfigPages
2025 * (combined with GetIoUnitPage2 call). This prevents a somewhat
2026 * recursive scenario; GetLanConfigPages times out, timer expired
2027 * routine calls HardResetHandler, which calls into here again,
2028 * and we try GetLanConfigPages again...
2030 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
2033 * Initalize link list for inactive raid volumes.
2035 init_MUTEX(&ioc->raid_data.inactive_list_mutex);
2036 INIT_LIST_HEAD(&ioc->raid_data.inactive_list);
2038 if (ioc->bus_type == SAS) {
2040 /* clear persistency table */
2041 if(ioc->facts.IOCExceptions &
2042 MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL) {
2043 ret = mptbase_sas_persist_operation(ioc,
2044 MPI_SAS_OP_CLEAR_NOT_PRESENT);
2051 mpt_findImVolumes(ioc);
2053 } else if (ioc->bus_type == FC) {
2054 if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
2055 (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
2057 * Pre-fetch the ports LAN MAC address!
2058 * (LANPage1_t stuff)
2060 (void) GetLanConfigPages(ioc);
2061 a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
2062 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2063 "LanAddr = %02X:%02X:%02X:"
2065 ioc->name, a[5], a[4],
2066 a[3], a[2], a[1], a[0] ));
2070 /* Get NVRAM and adapter maximums from SPP 0 and 2
2072 mpt_GetScsiPortSettings(ioc, 0);
2074 /* Get version and length of SDP 1
2076 mpt_readScsiDevicePageHeaders(ioc, 0);
2080 if (ioc->facts.MsgVersion >= MPI_VERSION_01_02)
2081 mpt_findImVolumes(ioc);
2083 /* Check, and possibly reset, the coalescing value
2085 mpt_read_ioc_pg_1(ioc);
2087 mpt_read_ioc_pg_4(ioc);
2090 GetIoUnitPage2(ioc);
2091 mpt_get_manufacturing_pg_0(ioc);
2095 * Call each currently registered protocol IOC reset handler
2096 * with post-reset indication.
2097 * NOTE: If we're doing _IOC_BRINGUP, there can be no
2098 * MptResetHandlers[] registered yet.
2100 if (hard_reset_done) {
2102 for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
2103 if ((ret == 0) && MptResetHandlers[ii]) {
2104 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2105 "Calling IOC post_reset handler #%d\n",
2107 rc += mpt_signal_reset(ii, ioc, MPT_IOC_POST_RESET);
2111 if (alt_ioc_ready && MptResetHandlers[ii]) {
2112 drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2113 "Calling alt-%s post_reset handler #%d\n",
2114 ioc->name, ioc->alt_ioc->name, ii));
2115 rc += mpt_signal_reset(ii, ioc->alt_ioc, MPT_IOC_POST_RESET);
2119 /* FIXME? Examine results here? */
2123 if ((ret != 0) && irq_allocated) {
2124 free_irq(ioc->pci_irq, ioc);
2126 pci_disable_msi(ioc->pcidev);
2131 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2133 * mpt_detect_bound_ports - Search for matching PCI bus/dev_function
2134 * @ioc: Pointer to MPT adapter structure
2135 * @pdev: Pointer to (struct pci_dev) structure
2137 * Search for PCI bus/dev_function which matches
2138 * PCI bus/dev_function (+/-1) for newly discovered 929,
2139 * 929X, 1030 or 1035.
2141 * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
2142 * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
2145 mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
2147 struct pci_dev *peer=NULL;
2148 unsigned int slot = PCI_SLOT(pdev->devfn);
2149 unsigned int func = PCI_FUNC(pdev->devfn);
2150 MPT_ADAPTER *ioc_srch;
2152 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PCI device %s devfn=%x/%x,"
2153 " searching for devfn match on %x or %x\n",
2154 ioc->name, pci_name(pdev), pdev->bus->number,
2155 pdev->devfn, func-1, func+1));
2157 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
2159 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func+1));
2164 list_for_each_entry(ioc_srch, &ioc_list, list) {
2165 struct pci_dev *_pcidev = ioc_srch->pcidev;
2166 if (_pcidev == peer) {
2167 /* Paranoia checks */
2168 if (ioc->alt_ioc != NULL) {
2169 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
2170 ioc->name, ioc->alt_ioc->name);
2172 } else if (ioc_srch->alt_ioc != NULL) {
2173 printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
2174 ioc_srch->name, ioc_srch->alt_ioc->name);
2177 dprintk(ioc, printk(KERN_INFO MYNAM ": FOUND! binding %s <==> %s\n",
2178 ioc->name, ioc_srch->name));
2179 ioc_srch->alt_ioc = ioc;
2180 ioc->alt_ioc = ioc_srch;
2186 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2188 * mpt_adapter_disable - Disable misbehaving MPT adapter.
2189 * @ioc: Pointer to MPT adapter structure
2192 mpt_adapter_disable(MPT_ADAPTER *ioc)
2197 if (ioc->cached_fw != NULL) {
2198 ddlprintk(ioc, printk(KERN_INFO MYNAM ": mpt_adapter_disable: Pushing FW onto adapter\n"));
2199 if ((ret = mpt_downloadboot(ioc, (MpiFwHeader_t *)ioc->cached_fw, NO_SLEEP)) < 0) {
2200 printk(KERN_WARNING MYNAM
2201 ": firmware downloadboot failure (%d)!\n", ret);
2205 /* Disable adapter interrupts! */
2206 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
2208 /* Clear any lingering interrupt */
2209 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
2211 if (ioc->alloc != NULL) {
2213 dexitprintk(ioc, printk(KERN_INFO MYNAM ": %s.free @ %p, sz=%d bytes\n",
2214 ioc->name, ioc->alloc, ioc->alloc_sz));
2215 pci_free_consistent(ioc->pcidev, sz,
2216 ioc->alloc, ioc->alloc_dma);
2217 ioc->reply_frames = NULL;
2218 ioc->req_frames = NULL;
2220 ioc->alloc_total -= sz;
2223 if (ioc->sense_buf_pool != NULL) {
2224 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
2225 pci_free_consistent(ioc->pcidev, sz,
2226 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
2227 ioc->sense_buf_pool = NULL;
2228 ioc->alloc_total -= sz;
2231 if (ioc->events != NULL){
2232 sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
2235 ioc->alloc_total -= sz;
2238 if (ioc->cached_fw != NULL) {
2239 sz = ioc->facts.FWImageSize;
2240 pci_free_consistent(ioc->pcidev, sz,
2241 ioc->cached_fw, ioc->cached_fw_dma);
2242 ioc->cached_fw = NULL;
2243 ioc->alloc_total -= sz;
2246 kfree(ioc->spi_data.nvram);
2247 mpt_inactive_raid_list_free(ioc);
2248 kfree(ioc->raid_data.pIocPg2);
2249 kfree(ioc->raid_data.pIocPg3);
2250 ioc->spi_data.nvram = NULL;
2251 ioc->raid_data.pIocPg3 = NULL;
2253 if (ioc->spi_data.pIocPg4 != NULL) {
2254 sz = ioc->spi_data.IocPg4Sz;
2255 pci_free_consistent(ioc->pcidev, sz,
2256 ioc->spi_data.pIocPg4,
2257 ioc->spi_data.IocPg4_dma);
2258 ioc->spi_data.pIocPg4 = NULL;
2259 ioc->alloc_total -= sz;
2262 if (ioc->ReqToChain != NULL) {
2263 kfree(ioc->ReqToChain);
2264 kfree(ioc->RequestNB);
2265 ioc->ReqToChain = NULL;
2268 kfree(ioc->ChainToChain);
2269 ioc->ChainToChain = NULL;
2271 if (ioc->HostPageBuffer != NULL) {
2272 if((ret = mpt_host_page_access_control(ioc,
2273 MPI_DB_HPBAC_FREE_BUFFER, NO_SLEEP)) != 0) {
2274 printk(KERN_ERR MYNAM
2275 ": %s: host page buffers free failed (%d)!\n",
2278 dexitprintk(ioc, printk(KERN_INFO MYNAM ": %s HostPageBuffer free @ %p, sz=%d bytes\n",
2279 ioc->name, ioc->HostPageBuffer, ioc->HostPageBuffer_sz));
2280 pci_free_consistent(ioc->pcidev, ioc->HostPageBuffer_sz,
2281 ioc->HostPageBuffer,
2282 ioc->HostPageBuffer_dma);
2283 ioc->HostPageBuffer = NULL;
2284 ioc->HostPageBuffer_sz = 0;
2285 ioc->alloc_total -= ioc->HostPageBuffer_sz;
2289 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2291 * mpt_adapter_dispose - Free all resources associated with an MPT adapter
2292 * @ioc: Pointer to MPT adapter structure
2294 * This routine unregisters h/w resources and frees all alloc'd memory
2295 * associated with a MPT adapter structure.
2298 mpt_adapter_dispose(MPT_ADAPTER *ioc)
2300 int sz_first, sz_last;
2305 sz_first = ioc->alloc_total;
2307 mpt_adapter_disable(ioc);
2309 if (ioc->pci_irq != -1) {
2310 free_irq(ioc->pci_irq, ioc);
2312 pci_disable_msi(ioc->pcidev);
2316 if (ioc->memmap != NULL) {
2317 iounmap(ioc->memmap);
2321 #if defined(CONFIG_MTRR) && 0
2322 if (ioc->mtrr_reg > 0) {
2323 mtrr_del(ioc->mtrr_reg, 0, 0);
2324 dprintk(ioc, printk(KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
2328 /* Zap the adapter lookup ptr! */
2329 list_del(&ioc->list);
2331 sz_last = ioc->alloc_total;
2332 dprintk(ioc, printk(KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
2333 ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
2336 ioc->alt_ioc->alt_ioc = NULL;
2341 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2343 * MptDisplayIocCapabilities - Disply IOC's capabilities.
2344 * @ioc: Pointer to MPT adapter structure
2347 MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
2351 printk(KERN_INFO "%s: ", ioc->name);
2353 printk("%s: ", ioc->prod_name);
2354 printk("Capabilities={");
2356 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
2357 printk("Initiator");
2361 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2362 printk("%sTarget", i ? "," : "");
2366 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
2367 printk("%sLAN", i ? "," : "");
2373 * This would probably evoke more questions than it's worth
2375 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2376 printk("%sLogBusAddr", i ? "," : "");
2384 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2386 * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
2387 * @ioc: Pointer to MPT_ADAPTER structure
2388 * @force: Force hard KickStart of IOC
2389 * @sleepFlag: Specifies whether the process can sleep
2392 * 1 - DIAG reset and READY
2393 * 0 - READY initially OR soft reset and READY
2394 * -1 - Any failure on KickStart
2395 * -2 - Msg Unit Reset Failed
2396 * -3 - IO Unit Reset Failed
2397 * -4 - IOC owned by a PEER
2400 MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
2405 int hard_reset_done = 0;
2410 /* Get current [raw] IOC state */
2411 ioc_state = mpt_GetIocState(ioc, 0);
2412 dhsprintk(ioc, printk(KERN_INFO MYNAM "::MakeIocReady, %s [raw] state=%08x\n", ioc->name, ioc_state));
2415 * Check to see if IOC got left/stuck in doorbell handshake
2416 * grip of death. If so, hard reset the IOC.
2418 if (ioc_state & MPI_DOORBELL_ACTIVE) {
2420 printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
2424 /* Is it already READY? */
2425 if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
2429 * Check to see if IOC is in FAULT state.
2431 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
2433 printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
2435 printk(KERN_WARNING " FAULT code = %04xh\n",
2436 ioc_state & MPI_DOORBELL_DATA_MASK);
2440 * Hmmm... Did it get left operational?
2442 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
2443 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOC operational unexpected\n",
2447 * If PCI Peer, exit.
2448 * Else, if no fault conditions are present, issue a MessageUnitReset
2449 * Else, fall through to KickStart case
2451 whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
2452 dinitprintk(ioc, printk(KERN_INFO MYNAM
2453 ": whoinit 0x%x statefault %d force %d\n",
2454 whoinit, statefault, force));
2455 if (whoinit == MPI_WHOINIT_PCI_PEER)
2458 if ((statefault == 0 ) && (force == 0)) {
2459 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
2466 hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
2467 if (hard_reset_done < 0)
2471 * Loop here waiting for IOC to come READY.
2474 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 5; /* 5 seconds */
2476 while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
2477 if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
2479 * BIOS or previous driver load left IOC in OP state.
2480 * Reset messaging FIFOs.
2482 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
2483 printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
2486 } else if (ioc_state == MPI_IOC_STATE_RESET) {
2488 * Something is wrong. Try to get IOC back
2491 if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
2492 printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
2499 printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
2500 ioc->name, (int)((ii+5)/HZ));
2504 if (sleepFlag == CAN_SLEEP) {
2507 mdelay (1); /* 1 msec delay */
2512 if (statefault < 3) {
2513 printk(MYIOC_s_INFO_FMT "Recovered from %s\n",
2515 statefault==1 ? "stuck handshake" : "IOC FAULT");
2518 return hard_reset_done;
2521 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2523 * mpt_GetIocState - Get the current state of a MPT adapter.
2524 * @ioc: Pointer to MPT_ADAPTER structure
2525 * @cooked: Request raw or cooked IOC state
2527 * Returns all IOC Doorbell register bits if cooked==0, else just the
2528 * Doorbell bits in MPI_IOC_STATE_MASK.
2531 mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
2536 s = CHIPREG_READ32(&ioc->chip->Doorbell);
2537 // dprintk((MYIOC_s_INFO_FMT "raw state = %08x\n", ioc->name, s));
2538 sc = s & MPI_IOC_STATE_MASK;
2541 ioc->last_state = sc;
2543 return cooked ? sc : s;
2546 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2548 * GetIocFacts - Send IOCFacts request to MPT adapter.
2549 * @ioc: Pointer to MPT_ADAPTER structure
2550 * @sleepFlag: Specifies whether the process can sleep
2551 * @reason: If recovery, only update facts.
2553 * Returns 0 for success, non-zero for failure.
2556 GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2558 IOCFacts_t get_facts;
2559 IOCFactsReply_t *facts;
2567 /* IOC *must* NOT be in RESET state! */
2568 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2569 printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
2575 facts = &ioc->facts;
2577 /* Destination (reply area)... */
2578 reply_sz = sizeof(*facts);
2579 memset(facts, 0, reply_sz);
2581 /* Request area (get_facts on the stack right now!) */
2582 req_sz = sizeof(get_facts);
2583 memset(&get_facts, 0, req_sz);
2585 get_facts.Function = MPI_FUNCTION_IOC_FACTS;
2586 /* Assert: All other get_facts fields are zero! */
2588 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2589 "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
2590 ioc->name, req_sz, reply_sz));
2592 /* No non-zero fields in the get_facts request are greater than
2593 * 1 byte in size, so we can just fire it off as is.
2595 r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
2596 reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
2601 * Now byte swap (GRRR) the necessary fields before any further
2602 * inspection of reply contents.
2604 * But need to do some sanity checks on MsgLength (byte) field
2605 * to make sure we don't zero IOC's req_sz!
2607 /* Did we get a valid reply? */
2608 if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
2609 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2611 * If not been here, done that, save off first WhoInit value
2613 if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
2614 ioc->FirstWhoInit = facts->WhoInit;
2617 facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
2618 facts->MsgContext = le32_to_cpu(facts->MsgContext);
2619 facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
2620 facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
2621 facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
2622 status = le16_to_cpu(facts->IOCStatus) & MPI_IOCSTATUS_MASK;
2623 /* CHECKME! IOCStatus, IOCLogInfo */
2625 facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
2626 facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
2629 * FC f/w version changed between 1.1 and 1.2
2630 * Old: u16{Major(4),Minor(4),SubMinor(8)}
2631 * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
2633 if (facts->MsgVersion < 0x0102) {
2635 * Handle old FC f/w style, convert to new...
2637 u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
2638 facts->FWVersion.Word =
2639 ((oldv<<12) & 0xFF000000) |
2640 ((oldv<<8) & 0x000FFF00);
2642 facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
2644 facts->ProductID = le16_to_cpu(facts->ProductID);
2645 if ((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
2646 > MPI_FW_HEADER_PID_PROD_TARGET_SCSI)
2647 ioc->ir_firmware = 1;
2648 facts->CurrentHostMfaHighAddr =
2649 le32_to_cpu(facts->CurrentHostMfaHighAddr);
2650 facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
2651 facts->CurrentSenseBufferHighAddr =
2652 le32_to_cpu(facts->CurrentSenseBufferHighAddr);
2653 facts->CurReplyFrameSize =
2654 le16_to_cpu(facts->CurReplyFrameSize);
2655 facts->IOCCapabilities = le32_to_cpu(facts->IOCCapabilities);
2658 * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
2659 * Older MPI-1.00.xx struct had 13 dwords, and enlarged
2660 * to 14 in MPI-1.01.0x.
2662 if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
2663 facts->MsgVersion > 0x0100) {
2664 facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
2667 sz = facts->FWImageSize;
2672 facts->FWImageSize = sz;
2674 if (!facts->RequestFrameSize) {
2675 /* Something is wrong! */
2676 printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
2681 r = sz = facts->BlockSize;
2682 vv = ((63 / (sz * 4)) + 1) & 0x03;
2683 ioc->NB_for_64_byte_frame = vv;
2689 ioc->NBShiftFactor = shiftFactor;
2690 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2691 "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
2692 ioc->name, vv, shiftFactor, r));
2694 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2696 * Set values for this IOC's request & reply frame sizes,
2697 * and request & reply queue depths...
2699 ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
2700 ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
2701 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
2702 ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
2704 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "reply_sz=%3d, reply_depth=%4d\n",
2705 ioc->name, ioc->reply_sz, ioc->reply_depth));
2706 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "req_sz =%3d, req_depth =%4d\n",
2707 ioc->name, ioc->req_sz, ioc->req_depth));
2709 /* Get port facts! */
2710 if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
2714 printk(MYIOC_s_ERR_FMT
2715 "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
2716 ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
2717 RequestFrameSize)/sizeof(u32)));
2724 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2726 * GetPortFacts - Send PortFacts request to MPT adapter.
2727 * @ioc: Pointer to MPT_ADAPTER structure
2728 * @portnum: Port number
2729 * @sleepFlag: Specifies whether the process can sleep
2731 * Returns 0 for success, non-zero for failure.
2734 GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2736 PortFacts_t get_pfacts;
2737 PortFactsReply_t *pfacts;
2743 /* IOC *must* NOT be in RESET state! */
2744 if (ioc->last_state == MPI_IOC_STATE_RESET) {
2745 printk(KERN_ERR MYNAM ": ERROR - Can't get PortFacts, %s NOT READY! (%08x)\n",
2751 pfacts = &ioc->pfacts[portnum];
2753 /* Destination (reply area)... */
2754 reply_sz = sizeof(*pfacts);
2755 memset(pfacts, 0, reply_sz);
2757 /* Request area (get_pfacts on the stack right now!) */
2758 req_sz = sizeof(get_pfacts);
2759 memset(&get_pfacts, 0, req_sz);
2761 get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
2762 get_pfacts.PortNumber = portnum;
2763 /* Assert: All other get_pfacts fields are zero! */
2765 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending get PortFacts(%d) request\n",
2766 ioc->name, portnum));
2768 /* No non-zero fields in the get_pfacts request are greater than
2769 * 1 byte in size, so we can just fire it off as is.
2771 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
2772 reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
2776 /* Did we get a valid reply? */
2778 /* Now byte swap the necessary fields in the response. */
2779 pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
2780 pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
2781 pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
2782 pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
2783 pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
2784 pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
2785 pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
2786 pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
2787 pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
2789 max_id = (ioc->bus_type == SAS) ? pfacts->PortSCSIID :
2791 ioc->devices_per_bus = (max_id > 255) ? 256 : max_id;
2792 ioc->number_of_buses = (ioc->devices_per_bus < 256) ? 1 : max_id/256;
2795 * Place all the devices on channels
2799 if (mpt_channel_mapping) {
2800 ioc->devices_per_bus = 1;
2801 ioc->number_of_buses = (max_id > 255) ? 255 : max_id;
2807 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2809 * SendIocInit - Send IOCInit request to MPT adapter.
2810 * @ioc: Pointer to MPT_ADAPTER structure
2811 * @sleepFlag: Specifies whether the process can sleep
2813 * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
2815 * Returns 0 for success, non-zero for failure.
2818 SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
2821 MPIDefaultReply_t init_reply;
2827 memset(&ioc_init, 0, sizeof(ioc_init));
2828 memset(&init_reply, 0, sizeof(init_reply));
2830 ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
2831 ioc_init.Function = MPI_FUNCTION_IOC_INIT;
2833 /* If we are in a recovery mode and we uploaded the FW image,
2834 * then this pointer is not NULL. Skip the upload a second time.
2835 * Set this flag if cached_fw set for either IOC.
2837 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
2841 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "upload_fw %d facts.Flags=%x\n",
2842 ioc->name, ioc->upload_fw, ioc->facts.Flags));
2844 ioc_init.MaxDevices = (U8)ioc->devices_per_bus;
2845 ioc_init.MaxBuses = (U8)ioc->number_of_buses;
2846 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "facts.MsgVersion=%x\n",
2847 ioc->name, ioc->facts.MsgVersion));
2848 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05) {
2849 // set MsgVersion and HeaderVersion host driver was built with
2850 ioc_init.MsgVersion = cpu_to_le16(MPI_VERSION);
2851 ioc_init.HeaderVersion = cpu_to_le16(MPI_HEADER_VERSION);
2853 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_HOST_PAGE_BUFFER_PERSISTENT) {
2854 ioc_init.HostPageBufferSGE = ioc->facts.HostPageBufferSGE;
2855 } else if(mpt_host_page_alloc(ioc, &ioc_init))
2858 ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
2860 if (sizeof(dma_addr_t) == sizeof(u64)) {
2861 /* Save the upper 32-bits of the request
2862 * (reply) and sense buffers.
2864 ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
2865 ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
2867 /* Force 32-bit addressing */
2868 ioc_init.HostMfaHighAddr = cpu_to_le32(0);
2869 ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
2872 ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
2873 ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
2874 ioc->facts.MaxDevices = ioc_init.MaxDevices;
2875 ioc->facts.MaxBuses = ioc_init.MaxBuses;
2877 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending IOCInit (req @ %p)\n",
2878 ioc->name, &ioc_init));
2880 r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
2881 sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
2883 printk(MYIOC_s_ERR_FMT "Sending IOCInit failed(%d)!\n",ioc->name, r);
2887 /* No need to byte swap the multibyte fields in the reply
2888 * since we don't even look at its contents.
2891 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending PortEnable (req @ %p)\n",
2892 ioc->name, &ioc_init));
2894 if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0) {
2895 printk(MYIOC_s_ERR_FMT "Sending PortEnable failed(%d)!\n",ioc->name, r);
2899 /* YIKES! SUPER IMPORTANT!!!
2900 * Poll IocState until _OPERATIONAL while IOC is doing
2901 * LoopInit and TargetDiscovery!
2904 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
2905 state = mpt_GetIocState(ioc, 1);
2906 while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
2907 if (sleepFlag == CAN_SLEEP) {
2914 printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
2915 ioc->name, (int)((count+5)/HZ));
2919 state = mpt_GetIocState(ioc, 1);
2922 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
2925 ioc->aen_event_read_flag=0;
2929 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2931 * SendPortEnable - Send PortEnable request to MPT adapter port.
2932 * @ioc: Pointer to MPT_ADAPTER structure
2933 * @portnum: Port number to enable
2934 * @sleepFlag: Specifies whether the process can sleep
2936 * Send PortEnable to bring IOC to OPERATIONAL state.
2938 * Returns 0 for success, non-zero for failure.
2941 SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2943 PortEnable_t port_enable;
2944 MPIDefaultReply_t reply_buf;
2949 /* Destination... */
2950 reply_sz = sizeof(MPIDefaultReply_t);
2951 memset(&reply_buf, 0, reply_sz);
2953 req_sz = sizeof(PortEnable_t);
2954 memset(&port_enable, 0, req_sz);
2956 port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
2957 port_enable.PortNumber = portnum;
2958 /* port_enable.ChainOffset = 0; */
2959 /* port_enable.MsgFlags = 0; */
2960 /* port_enable.MsgContext = 0; */
2962 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Port(%d)Enable (req @ %p)\n",
2963 ioc->name, portnum, &port_enable));
2965 /* RAID FW may take a long time to enable
2967 if (ioc->ir_firmware || ioc->bus_type == SAS) {
2968 rc = mpt_handshake_req_reply_wait(ioc, req_sz,
2969 (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
2970 300 /*seconds*/, sleepFlag);
2972 rc = mpt_handshake_req_reply_wait(ioc, req_sz,
2973 (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
2974 30 /*seconds*/, sleepFlag);
2980 * mpt_alloc_fw_memory - allocate firmware memory
2981 * @ioc: Pointer to MPT_ADAPTER structure
2982 * @size: total FW bytes
2984 * If memory has already been allocated, the same (cached) value
2988 mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
2991 return; /* use already allocated memory */
2992 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
2993 ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
2994 ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
2995 ioc->alloc_total += size;
2996 ioc->alt_ioc->alloc_total -= size;
2998 if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
2999 ioc->alloc_total += size;
3003 * mpt_free_fw_memory - free firmware memory
3004 * @ioc: Pointer to MPT_ADAPTER structure
3006 * If alt_img is NULL, delete from ioc structure.
3007 * Else, delete a secondary image in same format.
3010 mpt_free_fw_memory(MPT_ADAPTER *ioc)
3014 sz = ioc->facts.FWImageSize;
3015 dinitprintk(ioc, printk(KERN_INFO MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
3016 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
3017 pci_free_consistent(ioc->pcidev, sz,
3018 ioc->cached_fw, ioc->cached_fw_dma);
3019 ioc->cached_fw = NULL;
3025 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3027 * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
3028 * @ioc: Pointer to MPT_ADAPTER structure
3029 * @sleepFlag: Specifies whether the process can sleep
3031 * Returns 0 for success, >0 for handshake failure
3032 * <0 for fw upload failure.
3034 * Remark: If bound IOC and a successful FWUpload was performed
3035 * on the bound IOC, the second image is discarded
3036 * and memory is free'd. Both channels must upload to prevent
3037 * IOC from running in degraded mode.
3040 mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
3042 u8 request[ioc->req_sz];
3043 u8 reply[sizeof(FWUploadReply_t)];
3044 FWUpload_t *prequest;
3045 FWUploadReply_t *preply;
3046 FWUploadTCSGE_t *ptcsge;
3049 int ii, sz, reply_sz;
3052 /* If the image size is 0, we are done.
3054 if ((sz = ioc->facts.FWImageSize) == 0)
3057 mpt_alloc_fw_memory(ioc, sz);
3059 dinitprintk(ioc, printk(KERN_INFO MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
3060 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
3062 if (ioc->cached_fw == NULL) {
3068 prequest = (FWUpload_t *)&request;
3069 preply = (FWUploadReply_t *)&reply;
3071 /* Destination... */
3072 memset(prequest, 0, ioc->req_sz);
3074 reply_sz = sizeof(reply);
3075 memset(preply, 0, reply_sz);
3077 prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
3078 prequest->Function = MPI_FUNCTION_FW_UPLOAD;
3080 ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
3081 ptcsge->DetailsLength = 12;
3082 ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
3083 ptcsge->ImageSize = cpu_to_le32(sz);
3085 sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
3087 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
3088 mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
3090 sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
3091 dinitprintk(ioc, printk(KERN_INFO MYNAM ": Sending FW Upload (req @ %p) sgeoffset=%d \n",
3092 prequest, sgeoffset));
3093 DBG_DUMP_FW_REQUEST_FRAME(ioc, (u32 *)prequest)
3095 ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
3096 reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
3098 dinitprintk(ioc, printk(KERN_INFO MYNAM ": FW Upload completed rc=%x \n", ii));
3100 cmdStatus = -EFAULT;
3102 /* Handshake transfer was complete and successful.
3103 * Check the Reply Frame.
3105 int status, transfer_sz;
3106 status = le16_to_cpu(preply->IOCStatus);
3107 if (status == MPI_IOCSTATUS_SUCCESS) {
3108 transfer_sz = le32_to_cpu(preply->ActualImageSize);
3109 if (transfer_sz == sz)
3113 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": do_upload cmdStatus=%d \n",