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 PCI chip/adapter(s)
6 * running LSI Fusion MPT (Message Passing Technology) firmware.
8 * Copyright (c) 1999-2008 LSI 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/seq_file.h>
54 #include <linux/slab.h>
55 #include <linux/types.h>
56 #include <linux/pci.h>
57 #include <linux/kdev_t.h>
58 #include <linux/blkdev.h>
59 #include <linux/delay.h>
60 #include <linux/interrupt.h> /* needed for in_interrupt() proto */
61 #include <linux/dma-mapping.h>
66 #include <linux/kthread.h>
67 #include <scsi/scsi_host.h>
70 #include "lsi/mpi_log_fc.h"
72 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
73 #define my_NAME "Fusion MPT base driver"
74 #define my_VERSION MPT_LINUX_VERSION_COMMON
75 #define MYNAM "mptbase"
77 MODULE_AUTHOR(MODULEAUTHOR
);
78 MODULE_DESCRIPTION(my_NAME
);
79 MODULE_LICENSE("GPL");
80 MODULE_VERSION(my_VERSION
);
86 static int mpt_msi_enable_spi
;
87 module_param(mpt_msi_enable_spi
, int, 0);
88 MODULE_PARM_DESC(mpt_msi_enable_spi
,
89 " Enable MSI Support for SPI controllers (default=0)");
91 static int mpt_msi_enable_fc
;
92 module_param(mpt_msi_enable_fc
, int, 0);
93 MODULE_PARM_DESC(mpt_msi_enable_fc
,
94 " Enable MSI Support for FC controllers (default=0)");
96 static int mpt_msi_enable_sas
;
97 module_param(mpt_msi_enable_sas
, int, 0);
98 MODULE_PARM_DESC(mpt_msi_enable_sas
,
99 " Enable MSI Support for SAS controllers (default=0)");
101 static int mpt_channel_mapping
;
102 module_param(mpt_channel_mapping
, int, 0);
103 MODULE_PARM_DESC(mpt_channel_mapping
, " Mapping id's to channels (default=0)");
105 static int mpt_debug_level
;
106 static int mpt_set_debug_level(const char *val
, struct kernel_param
*kp
);
107 module_param_call(mpt_debug_level
, mpt_set_debug_level
, param_get_int
,
108 &mpt_debug_level
, 0600);
109 MODULE_PARM_DESC(mpt_debug_level
,
110 " debug level - refer to mptdebug.h - (default=0)");
112 int mpt_fwfault_debug
;
113 EXPORT_SYMBOL(mpt_fwfault_debug
);
114 module_param(mpt_fwfault_debug
, int, 0600);
115 MODULE_PARM_DESC(mpt_fwfault_debug
,
116 "Enable detection of Firmware fault and halt Firmware on fault - (default=0)");
118 static char MptCallbacksName
[MPT_MAX_PROTOCOL_DRIVERS
][50];
121 static int mfcounter
= 0;
122 #define PRINT_MF_COUNT 20000
125 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
130 #define WHOINIT_UNKNOWN 0xAA
132 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
136 /* Adapter link list */
138 /* Callback lookup table */
139 static MPT_CALLBACK MptCallbacks
[MPT_MAX_PROTOCOL_DRIVERS
];
140 /* Protocol driver class lookup table */
141 static int MptDriverClass
[MPT_MAX_PROTOCOL_DRIVERS
];
142 /* Event handler lookup table */
143 static MPT_EVHANDLER MptEvHandlers
[MPT_MAX_PROTOCOL_DRIVERS
];
144 /* Reset handler lookup table */
145 static MPT_RESETHANDLER MptResetHandlers
[MPT_MAX_PROTOCOL_DRIVERS
];
146 static struct mpt_pci_driver
*MptDeviceDriverHandlers
[MPT_MAX_PROTOCOL_DRIVERS
];
148 #ifdef CONFIG_PROC_FS
149 static struct proc_dir_entry
*mpt_proc_root_dir
;
153 * Driver Callback Index's
155 static u8 mpt_base_index
= MPT_MAX_PROTOCOL_DRIVERS
;
156 static u8 last_drv_idx
;
158 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
162 static irqreturn_t
mpt_interrupt(int irq
, void *bus_id
);
163 static int mptbase_reply(MPT_ADAPTER
*ioc
, MPT_FRAME_HDR
*req
,
164 MPT_FRAME_HDR
*reply
);
165 static int mpt_handshake_req_reply_wait(MPT_ADAPTER
*ioc
, int reqBytes
,
166 u32
*req
, int replyBytes
, u16
*u16reply
, int maxwait
,
168 static int mpt_do_ioc_recovery(MPT_ADAPTER
*ioc
, u32 reason
, int sleepFlag
);
169 static void mpt_detect_bound_ports(MPT_ADAPTER
*ioc
, struct pci_dev
*pdev
);
170 static void mpt_adapter_disable(MPT_ADAPTER
*ioc
);
171 static void mpt_adapter_dispose(MPT_ADAPTER
*ioc
);
173 static void MptDisplayIocCapabilities(MPT_ADAPTER
*ioc
);
174 static int MakeIocReady(MPT_ADAPTER
*ioc
, int force
, int sleepFlag
);
175 static int GetIocFacts(MPT_ADAPTER
*ioc
, int sleepFlag
, int reason
);
176 static int GetPortFacts(MPT_ADAPTER
*ioc
, int portnum
, int sleepFlag
);
177 static int SendIocInit(MPT_ADAPTER
*ioc
, int sleepFlag
);
178 static int SendPortEnable(MPT_ADAPTER
*ioc
, int portnum
, int sleepFlag
);
179 static int mpt_do_upload(MPT_ADAPTER
*ioc
, int sleepFlag
);
180 static int mpt_downloadboot(MPT_ADAPTER
*ioc
, MpiFwHeader_t
*pFwHeader
, int sleepFlag
);
181 static int mpt_diag_reset(MPT_ADAPTER
*ioc
, int ignore
, int sleepFlag
);
182 static int KickStart(MPT_ADAPTER
*ioc
, int ignore
, int sleepFlag
);
183 static int SendIocReset(MPT_ADAPTER
*ioc
, u8 reset_type
, int sleepFlag
);
184 static int PrimeIocFifos(MPT_ADAPTER
*ioc
);
185 static int WaitForDoorbellAck(MPT_ADAPTER
*ioc
, int howlong
, int sleepFlag
);
186 static int WaitForDoorbellInt(MPT_ADAPTER
*ioc
, int howlong
, int sleepFlag
);
187 static int WaitForDoorbellReply(MPT_ADAPTER
*ioc
, int howlong
, int sleepFlag
);
188 static int GetLanConfigPages(MPT_ADAPTER
*ioc
);
189 static int GetIoUnitPage2(MPT_ADAPTER
*ioc
);
190 int mptbase_sas_persist_operation(MPT_ADAPTER
*ioc
, u8 persist_opcode
);
191 static int mpt_GetScsiPortSettings(MPT_ADAPTER
*ioc
, int portnum
);
192 static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER
*ioc
, int portnum
);
193 static void mpt_read_ioc_pg_1(MPT_ADAPTER
*ioc
);
194 static void mpt_read_ioc_pg_4(MPT_ADAPTER
*ioc
);
195 static void mpt_get_manufacturing_pg_0(MPT_ADAPTER
*ioc
);
196 static int SendEventNotification(MPT_ADAPTER
*ioc
, u8 EvSwitch
,
198 static int SendEventAck(MPT_ADAPTER
*ioc
, EventNotificationReply_t
*evnp
);
199 static int mpt_host_page_access_control(MPT_ADAPTER
*ioc
, u8 access_control_value
, int sleepFlag
);
200 static int mpt_host_page_alloc(MPT_ADAPTER
*ioc
, pIOCInit_t ioc_init
);
202 #ifdef CONFIG_PROC_FS
203 static const struct file_operations mpt_summary_proc_fops
;
204 static const struct file_operations mpt_version_proc_fops
;
205 static const struct file_operations mpt_iocinfo_proc_fops
;
207 static void mpt_get_fw_exp_ver(char *buf
, MPT_ADAPTER
*ioc
);
209 static int ProcessEventNotification(MPT_ADAPTER
*ioc
,
210 EventNotificationReply_t
*evReply
, int *evHandlers
);
211 static void mpt_iocstatus_info(MPT_ADAPTER
*ioc
, u32 ioc_status
, MPT_FRAME_HDR
*mf
);
212 static void mpt_fc_log_info(MPT_ADAPTER
*ioc
, u32 log_info
);
213 static void mpt_spi_log_info(MPT_ADAPTER
*ioc
, u32 log_info
);
214 static void mpt_sas_log_info(MPT_ADAPTER
*ioc
, u32 log_info
, u8 cb_idx
);
215 static int mpt_read_ioc_pg_3(MPT_ADAPTER
*ioc
);
216 static void mpt_inactive_raid_list_free(MPT_ADAPTER
*ioc
);
218 /* module entry point */
219 static int __init
fusion_init (void);
220 static void __exit
fusion_exit (void);
222 #define CHIPREG_READ32(addr) readl_relaxed(addr)
223 #define CHIPREG_READ32_dmasync(addr) readl(addr)
224 #define CHIPREG_WRITE32(addr,val) writel(val, addr)
225 #define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
226 #define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
229 pci_disable_io_access(struct pci_dev
*pdev
)
233 pci_read_config_word(pdev
, PCI_COMMAND
, &command_reg
);
235 pci_write_config_word(pdev
, PCI_COMMAND
, command_reg
);
239 pci_enable_io_access(struct pci_dev
*pdev
)
243 pci_read_config_word(pdev
, PCI_COMMAND
, &command_reg
);
245 pci_write_config_word(pdev
, PCI_COMMAND
, command_reg
);
248 static int mpt_set_debug_level(const char *val
, struct kernel_param
*kp
)
250 int ret
= param_set_int(val
, kp
);
256 list_for_each_entry(ioc
, &ioc_list
, list
)
257 ioc
->debug_level
= mpt_debug_level
;
262 * mpt_get_cb_idx - obtain cb_idx for registered driver
263 * @dclass: class driver enum
265 * Returns cb_idx, or zero means it wasn't found
268 mpt_get_cb_idx(MPT_DRIVER_CLASS dclass
)
272 for (cb_idx
= MPT_MAX_PROTOCOL_DRIVERS
-1; cb_idx
; cb_idx
--)
273 if (MptDriverClass
[cb_idx
] == dclass
)
279 * mpt_is_discovery_complete - determine if discovery has completed
280 * @ioc: per adatper instance
282 * Returns 1 when discovery completed, else zero.
285 mpt_is_discovery_complete(MPT_ADAPTER
*ioc
)
287 ConfigExtendedPageHeader_t hdr
;
289 SasIOUnitPage0_t
*buffer
;
290 dma_addr_t dma_handle
;
293 memset(&hdr
, 0, sizeof(ConfigExtendedPageHeader_t
));
294 memset(&cfg
, 0, sizeof(CONFIGPARMS
));
295 hdr
.PageVersion
= MPI_SASIOUNITPAGE0_PAGEVERSION
;
296 hdr
.PageType
= MPI_CONFIG_PAGETYPE_EXTENDED
;
297 hdr
.ExtPageType
= MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT
;
298 cfg
.cfghdr
.ehdr
= &hdr
;
299 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
301 if ((mpt_config(ioc
, &cfg
)))
303 if (!hdr
.ExtPageLength
)
306 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
311 cfg
.physAddr
= dma_handle
;
312 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
314 if ((mpt_config(ioc
, &cfg
)))
315 goto out_free_consistent
;
317 if (!(buffer
->PhyData
[0].PortFlags
&
318 MPI_SAS_IOUNIT0_PORT_FLAGS_DISCOVERY_IN_PROGRESS
))
322 pci_free_consistent(ioc
->pcidev
, hdr
.ExtPageLength
* 4,
330 * mpt_remove_dead_ioc_func - kthread context to remove dead ioc
331 * @arg: input argument, used to derive ioc
333 * Return 0 if controller is removed from pci subsystem.
334 * Return -1 for other case.
336 static int mpt_remove_dead_ioc_func(void *arg
)
338 MPT_ADAPTER
*ioc
= (MPT_ADAPTER
*)arg
;
339 struct pci_dev
*pdev
;
348 pci_remove_bus_device(pdev
);
355 * mpt_fault_reset_work - work performed on workq after ioc fault
356 * @work: input argument, used to derive ioc
360 mpt_fault_reset_work(struct work_struct
*work
)
363 container_of(work
, MPT_ADAPTER
, fault_reset_work
.work
);
368 struct task_struct
*p
;
370 if (ioc
->ioc_reset_in_progress
|| !ioc
->active
)
374 ioc_raw_state
= mpt_GetIocState(ioc
, 0);
375 if ((ioc_raw_state
& MPI_IOC_STATE_MASK
) == MPI_IOC_STATE_MASK
) {
376 printk(MYIOC_s_INFO_FMT
"%s: IOC is non-operational !!!!\n",
377 ioc
->name
, __func__
);
380 * Call mptscsih_flush_pending_cmds callback so that we
381 * flush all pending commands back to OS.
382 * This call is required to aovid deadlock at block layer.
383 * Dead IOC will fail to do diag reset,and this call is safe
384 * since dead ioc will never return any command back from HW.
386 hd
= shost_priv(ioc
->sh
);
387 ioc
->schedule_dead_ioc_flush_running_cmds(hd
);
389 /*Remove the Dead Host */
390 p
= kthread_run(mpt_remove_dead_ioc_func
, ioc
,
391 "mpt_dead_ioc_%d", ioc
->id
);
393 printk(MYIOC_s_ERR_FMT
394 "%s: Running mpt_dead_ioc thread failed !\n",
395 ioc
->name
, __func__
);
397 printk(MYIOC_s_WARN_FMT
398 "%s: Running mpt_dead_ioc thread success !\n",
399 ioc
->name
, __func__
);
401 return; /* don't rearm timer */
404 if ((ioc_raw_state
& MPI_IOC_STATE_MASK
)
405 == MPI_IOC_STATE_FAULT
) {
406 printk(MYIOC_s_WARN_FMT
"IOC is in FAULT state (%04xh)!!!\n",
407 ioc
->name
, ioc_raw_state
& MPI_DOORBELL_DATA_MASK
);
408 printk(MYIOC_s_WARN_FMT
"Issuing HardReset from %s!!\n",
409 ioc
->name
, __func__
);
410 rc
= mpt_HardResetHandler(ioc
, CAN_SLEEP
);
411 printk(MYIOC_s_WARN_FMT
"%s: HardReset: %s\n", ioc
->name
,
412 __func__
, (rc
== 0) ? "success" : "failed");
413 ioc_raw_state
= mpt_GetIocState(ioc
, 0);
414 if ((ioc_raw_state
& MPI_IOC_STATE_MASK
) == MPI_IOC_STATE_FAULT
)
415 printk(MYIOC_s_WARN_FMT
"IOC is in FAULT state after "
416 "reset (%04xh)\n", ioc
->name
, ioc_raw_state
&
417 MPI_DOORBELL_DATA_MASK
);
418 } else if (ioc
->bus_type
== SAS
&& ioc
->sas_discovery_quiesce_io
) {
419 if ((mpt_is_discovery_complete(ioc
))) {
420 devtprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"clearing "
421 "discovery_quiesce_io flag\n", ioc
->name
));
422 ioc
->sas_discovery_quiesce_io
= 0;
428 * Take turns polling alternate controller
433 /* rearm the timer */
434 spin_lock_irqsave(&ioc
->taskmgmt_lock
, flags
);
435 if (ioc
->reset_work_q
)
436 queue_delayed_work(ioc
->reset_work_q
, &ioc
->fault_reset_work
,
437 msecs_to_jiffies(MPT_POLLING_INTERVAL
));
438 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
443 * Process turbo (context) reply...
446 mpt_turbo_reply(MPT_ADAPTER
*ioc
, u32 pa
)
448 MPT_FRAME_HDR
*mf
= NULL
;
449 MPT_FRAME_HDR
*mr
= NULL
;
453 dmfprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Got TURBO reply req_idx=%08x\n",
456 switch (pa
>> MPI_CONTEXT_REPLY_TYPE_SHIFT
) {
457 case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT
:
458 req_idx
= pa
& 0x0000FFFF;
459 cb_idx
= (pa
& 0x00FF0000) >> 16;
460 mf
= MPT_INDEX_2_MFPTR(ioc
, req_idx
);
462 case MPI_CONTEXT_REPLY_TYPE_LAN
:
463 cb_idx
= mpt_get_cb_idx(MPTLAN_DRIVER
);
465 * Blind set of mf to NULL here was fatal
466 * after lan_reply says "freeme"
467 * Fix sort of combined with an optimization here;
468 * added explicit check for case where lan_reply
469 * was just returning 1 and doing nothing else.
470 * For this case skip the callback, but set up
471 * proper mf value first here:-)
473 if ((pa
& 0x58000000) == 0x58000000) {
474 req_idx
= pa
& 0x0000FFFF;
475 mf
= MPT_INDEX_2_MFPTR(ioc
, req_idx
);
476 mpt_free_msg_frame(ioc
, mf
);
481 mr
= (MPT_FRAME_HDR
*) CAST_U32_TO_PTR(pa
);
483 case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET
:
484 cb_idx
= mpt_get_cb_idx(MPTSTM_DRIVER
);
485 mr
= (MPT_FRAME_HDR
*) CAST_U32_TO_PTR(pa
);
492 /* Check for (valid) IO callback! */
493 if (!cb_idx
|| cb_idx
>= MPT_MAX_PROTOCOL_DRIVERS
||
494 MptCallbacks
[cb_idx
] == NULL
) {
495 printk(MYIOC_s_WARN_FMT
"%s: Invalid cb_idx (%d)!\n",
496 __func__
, ioc
->name
, cb_idx
);
500 if (MptCallbacks
[cb_idx
](ioc
, mf
, mr
))
501 mpt_free_msg_frame(ioc
, mf
);
507 mpt_reply(MPT_ADAPTER
*ioc
, u32 pa
)
518 /* non-TURBO reply! Hmmm, something may be up...
519 * Newest turbo reply mechanism; get address
520 * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
523 /* Map DMA address of reply header to cpu address.
524 * pa is 32 bits - but the dma address may be 32 or 64 bits
525 * get offset based only only the low addresses
528 reply_dma_low
= (pa
<<= 1);
529 mr
= (MPT_FRAME_HDR
*)((u8
*)ioc
->reply_frames
+
530 (reply_dma_low
- ioc
->reply_frames_low_dma
));
532 req_idx
= le16_to_cpu(mr
->u
.frame
.hwhdr
.msgctxu
.fld
.req_idx
);
533 cb_idx
= mr
->u
.frame
.hwhdr
.msgctxu
.fld
.cb_idx
;
534 mf
= MPT_INDEX_2_MFPTR(ioc
, req_idx
);
536 dmfprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Got non-TURBO reply=%p req_idx=%x cb_idx=%x Function=%x\n",
537 ioc
->name
, mr
, req_idx
, cb_idx
, mr
->u
.hdr
.Function
));
538 DBG_DUMP_REPLY_FRAME(ioc
, (u32
*)mr
);
540 /* Check/log IOC log info
542 ioc_stat
= le16_to_cpu(mr
->u
.reply
.IOCStatus
);
543 if (ioc_stat
& MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
) {
544 u32 log_info
= le32_to_cpu(mr
->u
.reply
.IOCLogInfo
);
545 if (ioc
->bus_type
== FC
)
546 mpt_fc_log_info(ioc
, log_info
);
547 else if (ioc
->bus_type
== SPI
)
548 mpt_spi_log_info(ioc
, log_info
);
549 else if (ioc
->bus_type
== SAS
)
550 mpt_sas_log_info(ioc
, log_info
, cb_idx
);
553 if (ioc_stat
& MPI_IOCSTATUS_MASK
)
554 mpt_iocstatus_info(ioc
, (u32
)ioc_stat
, mf
);
556 /* Check for (valid) IO callback! */
557 if (!cb_idx
|| cb_idx
>= MPT_MAX_PROTOCOL_DRIVERS
||
558 MptCallbacks
[cb_idx
] == NULL
) {
559 printk(MYIOC_s_WARN_FMT
"%s: Invalid cb_idx (%d)!\n",
560 __func__
, ioc
->name
, cb_idx
);
565 freeme
= MptCallbacks
[cb_idx
](ioc
, mf
, mr
);
568 /* Flush (non-TURBO) reply with a WRITE! */
569 CHIPREG_WRITE32(&ioc
->chip
->ReplyFifo
, pa
);
572 mpt_free_msg_frame(ioc
, mf
);
576 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
578 * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
579 * @irq: irq number (not used)
580 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
582 * This routine is registered via the request_irq() kernel API call,
583 * and handles all interrupts generated from a specific MPT adapter
584 * (also referred to as a IO Controller or IOC).
585 * This routine must clear the interrupt from the adapter and does
586 * so by reading the reply FIFO. Multiple replies may be processed
587 * per single call to this routine.
589 * This routine handles register-level access of the adapter but
590 * dispatches (calls) a protocol-specific callback routine to handle
591 * the protocol-specific details of the MPT request completion.
594 mpt_interrupt(int irq
, void *bus_id
)
596 MPT_ADAPTER
*ioc
= bus_id
;
597 u32 pa
= CHIPREG_READ32_dmasync(&ioc
->chip
->ReplyFifo
);
599 if (pa
== 0xFFFFFFFF)
603 * Drain the reply FIFO!
606 if (pa
& MPI_ADDRESS_REPLY_A_BIT
)
609 mpt_turbo_reply(ioc
, pa
);
610 pa
= CHIPREG_READ32_dmasync(&ioc
->chip
->ReplyFifo
);
611 } while (pa
!= 0xFFFFFFFF);
616 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
618 * mptbase_reply - MPT base driver's callback routine
619 * @ioc: Pointer to MPT_ADAPTER structure
620 * @req: Pointer to original MPT request frame
621 * @reply: Pointer to MPT reply frame (NULL if TurboReply)
623 * MPT base driver's callback routine; all base driver
624 * "internal" request/reply processing is routed here.
625 * Currently used for EventNotification and EventAck handling.
627 * Returns 1 indicating original alloc'd request frame ptr
628 * should be freed, or 0 if it shouldn't.
631 mptbase_reply(MPT_ADAPTER
*ioc
, MPT_FRAME_HDR
*req
, MPT_FRAME_HDR
*reply
)
633 EventNotificationReply_t
*pEventReply
;
638 switch (reply
->u
.hdr
.Function
) {
639 case MPI_FUNCTION_EVENT_NOTIFICATION
:
640 pEventReply
= (EventNotificationReply_t
*)reply
;
642 ProcessEventNotification(ioc
, pEventReply
, &evHandlers
);
643 event
= le32_to_cpu(pEventReply
->Event
) & 0xFF;
644 if (pEventReply
->MsgFlags
& MPI_MSGFLAGS_CONTINUATION_REPLY
)
646 if (event
!= MPI_EVENT_EVENT_CHANGE
)
648 case MPI_FUNCTION_CONFIG
:
649 case MPI_FUNCTION_SAS_IO_UNIT_CONTROL
:
650 ioc
->mptbase_cmds
.status
|= MPT_MGMT_STATUS_COMMAND_GOOD
;
652 ioc
->mptbase_cmds
.status
|= MPT_MGMT_STATUS_RF_VALID
;
653 memcpy(ioc
->mptbase_cmds
.reply
, reply
,
654 min(MPT_DEFAULT_FRAME_SIZE
,
655 4 * reply
->u
.reply
.MsgLength
));
657 if (ioc
->mptbase_cmds
.status
& MPT_MGMT_STATUS_PENDING
) {
658 ioc
->mptbase_cmds
.status
&= ~MPT_MGMT_STATUS_PENDING
;
659 complete(&ioc
->mptbase_cmds
.done
);
662 if (ioc
->mptbase_cmds
.status
& MPT_MGMT_STATUS_FREE_MF
)
665 case MPI_FUNCTION_EVENT_ACK
:
666 devtverboseprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
667 "EventAck reply received\n", ioc
->name
));
670 printk(MYIOC_s_ERR_FMT
671 "Unexpected msg function (=%02Xh) reply received!\n",
672 ioc
->name
, reply
->u
.hdr
.Function
);
677 * Conditionally tell caller to free the original
678 * EventNotification/EventAck/unexpected request frame!
683 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
685 * mpt_register - Register protocol-specific main callback handler.
686 * @cbfunc: callback function pointer
687 * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
688 * @func_name: call function's name
690 * This routine is called by a protocol-specific driver (SCSI host,
691 * LAN, SCSI target) to register its reply callback routine. Each
692 * protocol-specific driver must do this before it will be able to
693 * use any IOC resources, such as obtaining request frames.
695 * NOTES: The SCSI protocol driver currently calls this routine thrice
696 * in order to register separate callbacks; one for "normal" SCSI IO;
697 * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
699 * Returns u8 valued "handle" in the range (and S.O.D. order)
700 * {N,...,7,6,5,...,1} if successful.
701 * A return value of MPT_MAX_PROTOCOL_DRIVERS (including zero!) should be
702 * considered an error by the caller.
705 mpt_register(MPT_CALLBACK cbfunc
, MPT_DRIVER_CLASS dclass
, char *func_name
)
708 last_drv_idx
= MPT_MAX_PROTOCOL_DRIVERS
;
711 * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
712 * (slot/handle 0 is reserved!)
714 for (cb_idx
= MPT_MAX_PROTOCOL_DRIVERS
-1; cb_idx
; cb_idx
--) {
715 if (MptCallbacks
[cb_idx
] == NULL
) {
716 MptCallbacks
[cb_idx
] = cbfunc
;
717 MptDriverClass
[cb_idx
] = dclass
;
718 MptEvHandlers
[cb_idx
] = NULL
;
719 last_drv_idx
= cb_idx
;
720 memcpy(MptCallbacksName
[cb_idx
], func_name
,
721 strlen(func_name
) > 50 ? 50 : strlen(func_name
));
729 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
731 * mpt_deregister - Deregister a protocol drivers resources.
732 * @cb_idx: previously registered callback handle
734 * Each protocol-specific driver should call this routine when its
735 * module is unloaded.
738 mpt_deregister(u8 cb_idx
)
740 if (cb_idx
&& (cb_idx
< MPT_MAX_PROTOCOL_DRIVERS
)) {
741 MptCallbacks
[cb_idx
] = NULL
;
742 MptDriverClass
[cb_idx
] = MPTUNKNOWN_DRIVER
;
743 MptEvHandlers
[cb_idx
] = NULL
;
749 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
751 * mpt_event_register - Register protocol-specific event callback handler.
752 * @cb_idx: previously registered (via mpt_register) callback handle
753 * @ev_cbfunc: callback function
755 * This routine can be called by one or more protocol-specific drivers
756 * if/when they choose to be notified of MPT events.
758 * Returns 0 for success.
761 mpt_event_register(u8 cb_idx
, MPT_EVHANDLER ev_cbfunc
)
763 if (!cb_idx
|| cb_idx
>= MPT_MAX_PROTOCOL_DRIVERS
)
766 MptEvHandlers
[cb_idx
] = ev_cbfunc
;
770 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
772 * mpt_event_deregister - Deregister protocol-specific event callback handler
773 * @cb_idx: previously registered callback handle
775 * Each protocol-specific driver should call this routine
776 * when it does not (or can no longer) handle events,
777 * or when its module is unloaded.
780 mpt_event_deregister(u8 cb_idx
)
782 if (!cb_idx
|| cb_idx
>= MPT_MAX_PROTOCOL_DRIVERS
)
785 MptEvHandlers
[cb_idx
] = NULL
;
788 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
790 * mpt_reset_register - Register protocol-specific IOC reset handler.
791 * @cb_idx: previously registered (via mpt_register) callback handle
792 * @reset_func: reset function
794 * This routine can be called by one or more protocol-specific drivers
795 * if/when they choose to be notified of IOC resets.
797 * Returns 0 for success.
800 mpt_reset_register(u8 cb_idx
, MPT_RESETHANDLER reset_func
)
802 if (!cb_idx
|| cb_idx
>= MPT_MAX_PROTOCOL_DRIVERS
)
805 MptResetHandlers
[cb_idx
] = reset_func
;
809 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
811 * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
812 * @cb_idx: previously registered callback handle
814 * Each protocol-specific driver should call this routine
815 * when it does not (or can no longer) handle IOC reset handling,
816 * or when its module is unloaded.
819 mpt_reset_deregister(u8 cb_idx
)
821 if (!cb_idx
|| cb_idx
>= MPT_MAX_PROTOCOL_DRIVERS
)
824 MptResetHandlers
[cb_idx
] = NULL
;
827 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
829 * mpt_device_driver_register - Register device driver hooks
830 * @dd_cbfunc: driver callbacks struct
831 * @cb_idx: MPT protocol driver index
834 mpt_device_driver_register(struct mpt_pci_driver
* dd_cbfunc
, u8 cb_idx
)
837 const struct pci_device_id
*id
;
839 if (!cb_idx
|| cb_idx
>= MPT_MAX_PROTOCOL_DRIVERS
)
842 MptDeviceDriverHandlers
[cb_idx
] = dd_cbfunc
;
844 /* call per pci device probe entry point */
845 list_for_each_entry(ioc
, &ioc_list
, list
) {
846 id
= ioc
->pcidev
->driver
?
847 ioc
->pcidev
->driver
->id_table
: NULL
;
848 if (dd_cbfunc
->probe
)
849 dd_cbfunc
->probe(ioc
->pcidev
, id
);
855 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
857 * mpt_device_driver_deregister - DeRegister device driver hooks
858 * @cb_idx: MPT protocol driver index
861 mpt_device_driver_deregister(u8 cb_idx
)
863 struct mpt_pci_driver
*dd_cbfunc
;
866 if (!cb_idx
|| cb_idx
>= MPT_MAX_PROTOCOL_DRIVERS
)
869 dd_cbfunc
= MptDeviceDriverHandlers
[cb_idx
];
871 list_for_each_entry(ioc
, &ioc_list
, list
) {
872 if (dd_cbfunc
->remove
)
873 dd_cbfunc
->remove(ioc
->pcidev
);
876 MptDeviceDriverHandlers
[cb_idx
] = NULL
;
880 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
882 * mpt_get_msg_frame - Obtain an MPT request frame from the pool
883 * @cb_idx: Handle of registered MPT protocol driver
884 * @ioc: Pointer to MPT adapter structure
886 * Obtain an MPT request frame from the pool (of 1024) that are
887 * allocated per MPT adapter.
889 * Returns pointer to a MPT request frame or %NULL if none are available
890 * or IOC is not active.
893 mpt_get_msg_frame(u8 cb_idx
, MPT_ADAPTER
*ioc
)
897 u16 req_idx
; /* Request index */
899 /* validate handle and ioc identifier */
903 printk(MYIOC_s_WARN_FMT
"IOC Not Active! mpt_get_msg_frame "
904 "returning NULL!\n", ioc
->name
);
907 /* If interrupts are not attached, do not return a request frame */
911 spin_lock_irqsave(&ioc
->FreeQlock
, flags
);
912 if (!list_empty(&ioc
->FreeQ
)) {
915 mf
= list_entry(ioc
->FreeQ
.next
, MPT_FRAME_HDR
,
916 u
.frame
.linkage
.list
);
917 list_del(&mf
->u
.frame
.linkage
.list
);
918 mf
->u
.frame
.linkage
.arg1
= 0;
919 mf
->u
.frame
.hwhdr
.msgctxu
.fld
.cb_idx
= cb_idx
; /* byte */
920 req_offset
= (u8
*)mf
- (u8
*)ioc
->req_frames
;
922 req_idx
= req_offset
/ ioc
->req_sz
;
923 mf
->u
.frame
.hwhdr
.msgctxu
.fld
.req_idx
= cpu_to_le16(req_idx
);
924 mf
->u
.frame
.hwhdr
.msgctxu
.fld
.rsvd
= 0;
925 /* Default, will be changed if necessary in SG generation */
926 ioc
->RequestNB
[req_idx
] = ioc
->NB_for_64_byte_frame
;
933 spin_unlock_irqrestore(&ioc
->FreeQlock
, flags
);
937 printk(MYIOC_s_WARN_FMT
"IOC Active. No free Msg Frames! "
938 "Count 0x%x Max 0x%x\n", ioc
->name
, ioc
->mfcnt
,
941 if (mfcounter
== PRINT_MF_COUNT
)
942 printk(MYIOC_s_INFO_FMT
"MF Count 0x%x Max 0x%x \n", ioc
->name
,
943 ioc
->mfcnt
, ioc
->req_depth
);
946 dmfprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"mpt_get_msg_frame(%d,%d), got mf=%p\n",
947 ioc
->name
, cb_idx
, ioc
->id
, mf
));
951 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
953 * mpt_put_msg_frame - Send a protocol-specific MPT request frame to an IOC
954 * @cb_idx: Handle of registered MPT protocol driver
955 * @ioc: Pointer to MPT adapter structure
956 * @mf: Pointer to MPT request frame
958 * This routine posts an MPT request frame to the request post FIFO of a
959 * specific MPT adapter.
962 mpt_put_msg_frame(u8 cb_idx
, MPT_ADAPTER
*ioc
, MPT_FRAME_HDR
*mf
)
966 u16 req_idx
; /* Request index */
968 /* ensure values are reset properly! */
969 mf
->u
.frame
.hwhdr
.msgctxu
.fld
.cb_idx
= cb_idx
; /* byte */
970 req_offset
= (u8
*)mf
- (u8
*)ioc
->req_frames
;
972 req_idx
= req_offset
/ ioc
->req_sz
;
973 mf
->u
.frame
.hwhdr
.msgctxu
.fld
.req_idx
= cpu_to_le16(req_idx
);
974 mf
->u
.frame
.hwhdr
.msgctxu
.fld
.rsvd
= 0;
976 DBG_DUMP_PUT_MSG_FRAME(ioc
, (u32
*)mf
);
978 mf_dma_addr
= (ioc
->req_frames_low_dma
+ req_offset
) | ioc
->RequestNB
[req_idx
];
979 dsgprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"mf_dma_addr=%x req_idx=%d "
980 "RequestNB=%x\n", ioc
->name
, mf_dma_addr
, req_idx
,
981 ioc
->RequestNB
[req_idx
]));
982 CHIPREG_WRITE32(&ioc
->chip
->RequestFifo
, mf_dma_addr
);
986 * mpt_put_msg_frame_hi_pri - Send a hi-pri protocol-specific MPT request frame
987 * @cb_idx: Handle of registered MPT protocol driver
988 * @ioc: Pointer to MPT adapter structure
989 * @mf: Pointer to MPT request frame
991 * Send a protocol-specific MPT request frame to an IOC using
992 * hi-priority request queue.
994 * This routine posts an MPT request frame to the request post FIFO of a
995 * specific MPT adapter.
998 mpt_put_msg_frame_hi_pri(u8 cb_idx
, MPT_ADAPTER
*ioc
, MPT_FRAME_HDR
*mf
)
1002 u16 req_idx
; /* Request index */
1004 /* ensure values are reset properly! */
1005 mf
->u
.frame
.hwhdr
.msgctxu
.fld
.cb_idx
= cb_idx
;
1006 req_offset
= (u8
*)mf
- (u8
*)ioc
->req_frames
;
1007 req_idx
= req_offset
/ ioc
->req_sz
;
1008 mf
->u
.frame
.hwhdr
.msgctxu
.fld
.req_idx
= cpu_to_le16(req_idx
);
1009 mf
->u
.frame
.hwhdr
.msgctxu
.fld
.rsvd
= 0;
1011 DBG_DUMP_PUT_MSG_FRAME(ioc
, (u32
*)mf
);
1013 mf_dma_addr
= (ioc
->req_frames_low_dma
+ req_offset
);
1014 dsgprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"mf_dma_addr=%x req_idx=%d\n",
1015 ioc
->name
, mf_dma_addr
, req_idx
));
1016 CHIPREG_WRITE32(&ioc
->chip
->RequestHiPriFifo
, mf_dma_addr
);
1019 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1021 * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
1022 * @ioc: Pointer to MPT adapter structure
1023 * @mf: Pointer to MPT request frame
1025 * This routine places a MPT request frame back on the MPT adapter's
1029 mpt_free_msg_frame(MPT_ADAPTER
*ioc
, MPT_FRAME_HDR
*mf
)
1031 unsigned long flags
;
1033 /* Put Request back on FreeQ! */
1034 spin_lock_irqsave(&ioc
->FreeQlock
, flags
);
1035 if (cpu_to_le32(mf
->u
.frame
.linkage
.arg1
) == 0xdeadbeaf)
1037 /* signature to know if this mf is freed */
1038 mf
->u
.frame
.linkage
.arg1
= cpu_to_le32(0xdeadbeaf);
1039 list_add_tail(&mf
->u
.frame
.linkage
.list
, &ioc
->FreeQ
);
1044 spin_unlock_irqrestore(&ioc
->FreeQlock
, flags
);
1047 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1049 * mpt_add_sge - Place a simple 32 bit SGE at address pAddr.
1050 * @pAddr: virtual address for SGE
1051 * @flagslength: SGE flags and data transfer length
1052 * @dma_addr: Physical address
1054 * This routine places a MPT request frame back on the MPT adapter's
1058 mpt_add_sge(void *pAddr
, u32 flagslength
, dma_addr_t dma_addr
)
1060 SGESimple32_t
*pSge
= (SGESimple32_t
*) pAddr
;
1061 pSge
->FlagsLength
= cpu_to_le32(flagslength
);
1062 pSge
->Address
= cpu_to_le32(dma_addr
);
1066 * mpt_add_sge_64bit - Place a simple 64 bit SGE at address pAddr.
1067 * @pAddr: virtual address for SGE
1068 * @flagslength: SGE flags and data transfer length
1069 * @dma_addr: Physical address
1071 * This routine places a MPT request frame back on the MPT adapter's
1075 mpt_add_sge_64bit(void *pAddr
, u32 flagslength
, dma_addr_t dma_addr
)
1077 SGESimple64_t
*pSge
= (SGESimple64_t
*) pAddr
;
1078 pSge
->Address
.Low
= cpu_to_le32
1079 (lower_32_bits(dma_addr
));
1080 pSge
->Address
.High
= cpu_to_le32
1081 (upper_32_bits(dma_addr
));
1082 pSge
->FlagsLength
= cpu_to_le32
1083 ((flagslength
| MPT_SGE_FLAGS_64_BIT_ADDRESSING
));
1087 * mpt_add_sge_64bit_1078 - Place a simple 64 bit SGE at address pAddr (1078 workaround).
1088 * @pAddr: virtual address for SGE
1089 * @flagslength: SGE flags and data transfer length
1090 * @dma_addr: Physical address
1092 * This routine places a MPT request frame back on the MPT adapter's
1096 mpt_add_sge_64bit_1078(void *pAddr
, u32 flagslength
, dma_addr_t dma_addr
)
1098 SGESimple64_t
*pSge
= (SGESimple64_t
*) pAddr
;
1101 pSge
->Address
.Low
= cpu_to_le32
1102 (lower_32_bits(dma_addr
));
1103 tmp
= (u32
)(upper_32_bits(dma_addr
));
1106 * 1078 errata workaround for the 36GB limitation
1108 if ((((u64
)dma_addr
+ MPI_SGE_LENGTH(flagslength
)) >> 32) == 9) {
1110 MPI_SGE_SET_FLAGS(MPI_SGE_FLAGS_LOCAL_ADDRESS
);
1112 if (mpt_debug_level
& MPT_DEBUG_36GB_MEM
)
1113 printk(KERN_DEBUG
"1078 P0M2 addressing for "
1114 "addr = 0x%llx len = %d\n",
1115 (unsigned long long)dma_addr
,
1116 MPI_SGE_LENGTH(flagslength
));
1119 pSge
->Address
.High
= cpu_to_le32(tmp
);
1120 pSge
->FlagsLength
= cpu_to_le32(
1121 (flagslength
| MPT_SGE_FLAGS_64_BIT_ADDRESSING
));
1124 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1126 * mpt_add_chain - Place a 32 bit chain SGE at address pAddr.
1127 * @pAddr: virtual address for SGE
1128 * @next: nextChainOffset value (u32's)
1129 * @length: length of next SGL segment
1130 * @dma_addr: Physical address
1134 mpt_add_chain(void *pAddr
, u8 next
, u16 length
, dma_addr_t dma_addr
)
1136 SGEChain32_t
*pChain
= (SGEChain32_t
*) pAddr
;
1137 pChain
->Length
= cpu_to_le16(length
);
1138 pChain
->Flags
= MPI_SGE_FLAGS_CHAIN_ELEMENT
;
1139 pChain
->NextChainOffset
= next
;
1140 pChain
->Address
= cpu_to_le32(dma_addr
);
1143 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1145 * mpt_add_chain_64bit - Place a 64 bit chain SGE at address pAddr.
1146 * @pAddr: virtual address for SGE
1147 * @next: nextChainOffset value (u32's)
1148 * @length: length of next SGL segment
1149 * @dma_addr: Physical address
1153 mpt_add_chain_64bit(void *pAddr
, u8 next
, u16 length
, dma_addr_t dma_addr
)
1155 SGEChain64_t
*pChain
= (SGEChain64_t
*) pAddr
;
1156 u32 tmp
= dma_addr
& 0xFFFFFFFF;
1158 pChain
->Length
= cpu_to_le16(length
);
1159 pChain
->Flags
= (MPI_SGE_FLAGS_CHAIN_ELEMENT
|
1160 MPI_SGE_FLAGS_64_BIT_ADDRESSING
);
1162 pChain
->NextChainOffset
= next
;
1164 pChain
->Address
.Low
= cpu_to_le32(tmp
);
1165 tmp
= (u32
)(upper_32_bits(dma_addr
));
1166 pChain
->Address
.High
= cpu_to_le32(tmp
);
1169 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1171 * mpt_send_handshake_request - Send MPT request via doorbell handshake method.
1172 * @cb_idx: Handle of registered MPT protocol driver
1173 * @ioc: Pointer to MPT adapter structure
1174 * @reqBytes: Size of the request in bytes
1175 * @req: Pointer to MPT request frame
1176 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
1178 * This routine is used exclusively to send MptScsiTaskMgmt
1179 * requests since they are required to be sent via doorbell handshake.
1181 * NOTE: It is the callers responsibility to byte-swap fields in the
1182 * request which are greater than 1 byte in size.
1184 * Returns 0 for success, non-zero for failure.
1187 mpt_send_handshake_request(u8 cb_idx
, MPT_ADAPTER
*ioc
, int reqBytes
, u32
*req
, int sleepFlag
)
1193 /* State is known to be good upon entering
1194 * this function so issue the bus reset
1199 * Emulate what mpt_put_msg_frame() does /wrt to sanity
1200 * setting cb_idx/req_idx. But ONLY if this request
1201 * is in proper (pre-alloc'd) request buffer range...
1203 ii
= MFPTR_2_MPT_INDEX(ioc
,(MPT_FRAME_HDR
*)req
);
1204 if (reqBytes
>= 12 && ii
>= 0 && ii
< ioc
->req_depth
) {
1205 MPT_FRAME_HDR
*mf
= (MPT_FRAME_HDR
*)req
;
1206 mf
->u
.frame
.hwhdr
.msgctxu
.fld
.req_idx
= cpu_to_le16(ii
);
1207 mf
->u
.frame
.hwhdr
.msgctxu
.fld
.cb_idx
= cb_idx
;
1210 /* Make sure there are no doorbells */
1211 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
1213 CHIPREG_WRITE32(&ioc
->chip
->Doorbell
,
1214 ((MPI_FUNCTION_HANDSHAKE
<<MPI_DOORBELL_FUNCTION_SHIFT
) |
1215 ((reqBytes
/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT
)));
1217 /* Wait for IOC doorbell int */
1218 if ((ii
= WaitForDoorbellInt(ioc
, 5, sleepFlag
)) < 0) {
1222 /* Read doorbell and check for active bit */
1223 if (!(CHIPREG_READ32(&ioc
->chip
->Doorbell
) & MPI_DOORBELL_ACTIVE
))
1226 dhsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"mpt_send_handshake_request start, WaitCnt=%d\n",
1229 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
1231 if ((r
= WaitForDoorbellAck(ioc
, 5, sleepFlag
)) < 0) {
1235 /* Send request via doorbell handshake */
1236 req_as_bytes
= (u8
*) req
;
1237 for (ii
= 0; ii
< reqBytes
/4; ii
++) {
1240 word
= ((req_as_bytes
[(ii
*4) + 0] << 0) |
1241 (req_as_bytes
[(ii
*4) + 1] << 8) |
1242 (req_as_bytes
[(ii
*4) + 2] << 16) |
1243 (req_as_bytes
[(ii
*4) + 3] << 24));
1244 CHIPREG_WRITE32(&ioc
->chip
->Doorbell
, word
);
1245 if ((r
= WaitForDoorbellAck(ioc
, 5, sleepFlag
)) < 0) {
1251 if (r
>= 0 && WaitForDoorbellInt(ioc
, 10, sleepFlag
) >= 0)
1256 /* Make sure there are no doorbells */
1257 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
1262 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1264 * mpt_host_page_access_control - control the IOC's Host Page Buffer access
1265 * @ioc: Pointer to MPT adapter structure
1266 * @access_control_value: define bits below
1267 * @sleepFlag: Specifies whether the process can sleep
1269 * Provides mechanism for the host driver to control the IOC's
1270 * Host Page Buffer access.
1272 * Access Control Value - bits[15:12]
1274 * 1h Enable Access { MPI_DB_HPBAC_ENABLE_ACCESS }
1275 * 2h Disable Access { MPI_DB_HPBAC_DISABLE_ACCESS }
1276 * 3h Free Buffer { MPI_DB_HPBAC_FREE_BUFFER }
1278 * Returns 0 for success, non-zero for failure.
1282 mpt_host_page_access_control(MPT_ADAPTER
*ioc
, u8 access_control_value
, int sleepFlag
)
1286 /* return if in use */
1287 if (CHIPREG_READ32(&ioc
->chip
->Doorbell
)
1288 & MPI_DOORBELL_ACTIVE
)
1291 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
1293 CHIPREG_WRITE32(&ioc
->chip
->Doorbell
,
1294 ((MPI_FUNCTION_HOST_PAGEBUF_ACCESS_CONTROL
1295 <<MPI_DOORBELL_FUNCTION_SHIFT
) |
1296 (access_control_value
<<12)));
1298 /* Wait for IOC to clear Doorbell Status bit */
1299 if ((r
= WaitForDoorbellAck(ioc
, 5, sleepFlag
)) < 0) {
1305 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1307 * mpt_host_page_alloc - allocate system memory for the fw
1308 * @ioc: Pointer to pointer to IOC adapter
1309 * @ioc_init: Pointer to ioc init config page
1311 * If we already allocated memory in past, then resend the same pointer.
1312 * Returns 0 for success, non-zero for failure.
1315 mpt_host_page_alloc(MPT_ADAPTER
*ioc
, pIOCInit_t ioc_init
)
1319 u32 host_page_buffer_sz
=0;
1321 if(!ioc
->HostPageBuffer
) {
1323 host_page_buffer_sz
=
1324 le32_to_cpu(ioc
->facts
.HostPageBufferSGE
.FlagsLength
) & 0xFFFFFF;
1326 if(!host_page_buffer_sz
)
1327 return 0; /* fw doesn't need any host buffers */
1329 /* spin till we get enough memory */
1330 while(host_page_buffer_sz
> 0) {
1332 if((ioc
->HostPageBuffer
= pci_alloc_consistent(
1334 host_page_buffer_sz
,
1335 &ioc
->HostPageBuffer_dma
)) != NULL
) {
1337 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
1338 "host_page_buffer @ %p, dma @ %x, sz=%d bytes\n",
1339 ioc
->name
, ioc
->HostPageBuffer
,
1340 (u32
)ioc
->HostPageBuffer_dma
,
1341 host_page_buffer_sz
));
1342 ioc
->alloc_total
+= host_page_buffer_sz
;
1343 ioc
->HostPageBuffer_sz
= host_page_buffer_sz
;
1347 host_page_buffer_sz
-= (4*1024);
1351 if(!ioc
->HostPageBuffer
) {
1352 printk(MYIOC_s_ERR_FMT
1353 "Failed to alloc memory for host_page_buffer!\n",
1358 psge
= (char *)&ioc_init
->HostPageBufferSGE
;
1359 flags_length
= MPI_SGE_FLAGS_SIMPLE_ELEMENT
|
1360 MPI_SGE_FLAGS_SYSTEM_ADDRESS
|
1361 MPI_SGE_FLAGS_HOST_TO_IOC
|
1362 MPI_SGE_FLAGS_END_OF_BUFFER
;
1363 flags_length
= flags_length
<< MPI_SGE_FLAGS_SHIFT
;
1364 flags_length
|= ioc
->HostPageBuffer_sz
;
1365 ioc
->add_sge(psge
, flags_length
, ioc
->HostPageBuffer_dma
);
1366 ioc
->facts
.HostPageBufferSGE
= ioc_init
->HostPageBufferSGE
;
1371 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1373 * mpt_verify_adapter - Given IOC identifier, set pointer to its adapter structure.
1374 * @iocid: IOC unique identifier (integer)
1375 * @iocpp: Pointer to pointer to IOC adapter
1377 * Given a unique IOC identifier, set pointer to the associated MPT
1378 * adapter structure.
1380 * Returns iocid and sets iocpp if iocid is found.
1381 * Returns -1 if iocid is not found.
1384 mpt_verify_adapter(int iocid
, MPT_ADAPTER
**iocpp
)
1388 list_for_each_entry(ioc
,&ioc_list
,list
) {
1389 if (ioc
->id
== iocid
) {
1400 * mpt_get_product_name - returns product string
1401 * @vendor: pci vendor id
1402 * @device: pci device id
1403 * @revision: pci revision id
1404 * @prod_name: string returned
1406 * Returns product string displayed when driver loads,
1407 * in /proc/mpt/summary and /sysfs/class/scsi_host/host<X>/version_product
1411 mpt_get_product_name(u16 vendor
, u16 device
, u8 revision
, char *prod_name
)
1413 char *product_str
= NULL
;
1415 if (vendor
== PCI_VENDOR_ID_BROCADE
) {
1418 case MPI_MANUFACTPAGE_DEVICEID_FC949E
:
1422 product_str
= "BRE040 A0";
1425 product_str
= "BRE040 A1";
1428 product_str
= "BRE040";
1438 case MPI_MANUFACTPAGE_DEVICEID_FC909
:
1439 product_str
= "LSIFC909 B1";
1441 case MPI_MANUFACTPAGE_DEVICEID_FC919
:
1442 product_str
= "LSIFC919 B0";
1444 case MPI_MANUFACTPAGE_DEVICEID_FC929
:
1445 product_str
= "LSIFC929 B0";
1447 case MPI_MANUFACTPAGE_DEVICEID_FC919X
:
1448 if (revision
< 0x80)
1449 product_str
= "LSIFC919X A0";
1451 product_str
= "LSIFC919XL A1";
1453 case MPI_MANUFACTPAGE_DEVICEID_FC929X
:
1454 if (revision
< 0x80)
1455 product_str
= "LSIFC929X A0";
1457 product_str
= "LSIFC929XL A1";
1459 case MPI_MANUFACTPAGE_DEVICEID_FC939X
:
1460 product_str
= "LSIFC939X A1";
1462 case MPI_MANUFACTPAGE_DEVICEID_FC949X
:
1463 product_str
= "LSIFC949X A1";
1465 case MPI_MANUFACTPAGE_DEVICEID_FC949E
:
1469 product_str
= "LSIFC949E A0";
1472 product_str
= "LSIFC949E A1";
1475 product_str
= "LSIFC949E";
1479 case MPI_MANUFACTPAGE_DEVID_53C1030
:
1483 product_str
= "LSI53C1030 A0";
1486 product_str
= "LSI53C1030 B0";
1489 product_str
= "LSI53C1030 B1";
1492 product_str
= "LSI53C1030 B2";
1495 product_str
= "LSI53C1030 C0";
1498 product_str
= "LSI53C1030T A0";
1501 product_str
= "LSI53C1030T A2";
1504 product_str
= "LSI53C1030T A3";
1507 product_str
= "LSI53C1020A A1";
1510 product_str
= "LSI53C1030";
1514 case MPI_MANUFACTPAGE_DEVID_1030_53C1035
:
1518 product_str
= "LSI53C1035 A2";
1521 product_str
= "LSI53C1035 B0";
1524 product_str
= "LSI53C1035";
1528 case MPI_MANUFACTPAGE_DEVID_SAS1064
:
1532 product_str
= "LSISAS1064 A1";
1535 product_str
= "LSISAS1064 A2";
1538 product_str
= "LSISAS1064 A3";
1541 product_str
= "LSISAS1064 A4";
1544 product_str
= "LSISAS1064";
1548 case MPI_MANUFACTPAGE_DEVID_SAS1064E
:
1552 product_str
= "LSISAS1064E A0";
1555 product_str
= "LSISAS1064E B0";
1558 product_str
= "LSISAS1064E B1";
1561 product_str
= "LSISAS1064E B2";
1564 product_str
= "LSISAS1064E B3";
1567 product_str
= "LSISAS1064E";
1571 case MPI_MANUFACTPAGE_DEVID_SAS1068
:
1575 product_str
= "LSISAS1068 A0";
1578 product_str
= "LSISAS1068 B0";
1581 product_str
= "LSISAS1068 B1";
1584 product_str
= "LSISAS1068";
1588 case MPI_MANUFACTPAGE_DEVID_SAS1068E
:
1592 product_str
= "LSISAS1068E A0";
1595 product_str
= "LSISAS1068E B0";
1598 product_str
= "LSISAS1068E B1";
1601 product_str
= "LSISAS1068E B2";
1604 product_str
= "LSISAS1068E B3";
1607 product_str
= "LSISAS1068E";
1611 case MPI_MANUFACTPAGE_DEVID_SAS1078
:
1615 product_str
= "LSISAS1078 A0";
1618 product_str
= "LSISAS1078 B0";
1621 product_str
= "LSISAS1078 C0";
1624 product_str
= "LSISAS1078 C1";
1627 product_str
= "LSISAS1078 C2";
1630 product_str
= "LSISAS1078";
1638 sprintf(prod_name
, "%s", product_str
);
1642 * mpt_mapresources - map in memory mapped io
1643 * @ioc: Pointer to pointer to IOC adapter
1647 mpt_mapresources(MPT_ADAPTER
*ioc
)
1651 resource_size_t mem_phys
;
1657 struct pci_dev
*pdev
;
1660 ioc
->bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1661 if (pci_enable_device_mem(pdev
)) {
1662 printk(MYIOC_s_ERR_FMT
"pci_enable_device_mem() "
1663 "failed\n", ioc
->name
);
1666 if (pci_request_selected_regions(pdev
, ioc
->bars
, "mpt")) {
1667 printk(MYIOC_s_ERR_FMT
"pci_request_selected_regions() with "
1668 "MEM failed\n", ioc
->name
);
1672 pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &revision
);
1674 if (sizeof(dma_addr_t
) > 4) {
1675 const uint64_t required_mask
= dma_get_required_mask
1677 if (required_mask
> DMA_BIT_MASK(32)
1678 && !pci_set_dma_mask(pdev
, DMA_BIT_MASK(64))
1679 && !pci_set_consistent_dma_mask(pdev
,
1680 DMA_BIT_MASK(64))) {
1681 ioc
->dma_mask
= DMA_BIT_MASK(64);
1682 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
1683 ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
1685 } else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))
1686 && !pci_set_consistent_dma_mask(pdev
,
1687 DMA_BIT_MASK(32))) {
1688 ioc
->dma_mask
= DMA_BIT_MASK(32);
1689 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
1690 ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
1693 printk(MYIOC_s_WARN_FMT
"no suitable DMA mask for %s\n",
1694 ioc
->name
, pci_name(pdev
));
1695 pci_release_selected_regions(pdev
, ioc
->bars
);
1699 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))
1700 && !pci_set_consistent_dma_mask(pdev
,
1701 DMA_BIT_MASK(32))) {
1702 ioc
->dma_mask
= DMA_BIT_MASK(32);
1703 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
1704 ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
1707 printk(MYIOC_s_WARN_FMT
"no suitable DMA mask for %s\n",
1708 ioc
->name
, pci_name(pdev
));
1709 pci_release_selected_regions(pdev
, ioc
->bars
);
1714 mem_phys
= msize
= 0;
1716 for (ii
= 0; ii
< DEVICE_COUNT_RESOURCE
; ii
++) {
1717 if (pci_resource_flags(pdev
, ii
) & PCI_BASE_ADDRESS_SPACE_IO
) {
1720 /* Get I/O space! */
1721 port
= pci_resource_start(pdev
, ii
);
1722 psize
= pci_resource_len(pdev
, ii
);
1727 mem_phys
= pci_resource_start(pdev
, ii
);
1728 msize
= pci_resource_len(pdev
, ii
);
1731 ioc
->mem_size
= msize
;
1734 /* Get logical ptr for PciMem0 space */
1735 /*mem = ioremap(mem_phys, msize);*/
1736 mem
= ioremap(mem_phys
, msize
);
1738 printk(MYIOC_s_ERR_FMT
": ERROR - Unable to map adapter"
1739 " memory!\n", ioc
->name
);
1740 pci_release_selected_regions(pdev
, ioc
->bars
);
1744 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
"mem = %p, mem_phys = %llx\n",
1745 ioc
->name
, mem
, (unsigned long long)mem_phys
));
1747 ioc
->mem_phys
= mem_phys
;
1748 ioc
->chip
= (SYSIF_REGS __iomem
*)mem
;
1750 /* Save Port IO values in case we need to do downloadboot */
1751 ioc
->pio_mem_phys
= port
;
1752 ioc
->pio_chip
= (SYSIF_REGS __iomem
*)port
;
1757 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1759 * mpt_attach - Install a PCI intelligent MPT adapter.
1760 * @pdev: Pointer to pci_dev structure
1761 * @id: PCI device ID information
1763 * This routine performs all the steps necessary to bring the IOC of
1764 * a MPT adapter to a OPERATIONAL state. This includes registering
1765 * memory regions, registering the interrupt, and allocating request
1766 * and reply memory pools.
1768 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1771 * Returns 0 for success, non-zero for failure.
1773 * TODO: Add support for polled controllers
1776 mpt_attach(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1783 static int mpt_ids
= 0;
1784 #ifdef CONFIG_PROC_FS
1785 struct proc_dir_entry
*dent
;
1788 ioc
= kzalloc(sizeof(MPT_ADAPTER
), GFP_ATOMIC
);
1790 printk(KERN_ERR MYNAM
": ERROR - Insufficient memory to add adapter!\n");
1794 ioc
->id
= mpt_ids
++;
1795 sprintf(ioc
->name
, "ioc%d", ioc
->id
);
1796 dinitprintk(ioc
, printk(KERN_WARNING MYNAM
": mpt_adapter_install\n"));
1799 * set initial debug level
1800 * (refer to mptdebug.h)
1803 ioc
->debug_level
= mpt_debug_level
;
1804 if (mpt_debug_level
)
1805 printk(KERN_INFO
"mpt_debug_level=%xh\n", mpt_debug_level
);
1807 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
": mpt_adapter_install\n", ioc
->name
));
1810 if (mpt_mapresources(ioc
)) {
1816 * Setting up proper handlers for scatter gather handling
1818 if (ioc
->dma_mask
== DMA_BIT_MASK(64)) {
1819 if (pdev
->device
== MPI_MANUFACTPAGE_DEVID_SAS1078
)
1820 ioc
->add_sge
= &mpt_add_sge_64bit_1078
;
1822 ioc
->add_sge
= &mpt_add_sge_64bit
;
1823 ioc
->add_chain
= &mpt_add_chain_64bit
;
1824 ioc
->sg_addr_size
= 8;
1826 ioc
->add_sge
= &mpt_add_sge
;
1827 ioc
->add_chain
= &mpt_add_chain
;
1828 ioc
->sg_addr_size
= 4;
1830 ioc
->SGE_size
= sizeof(u32
) + ioc
->sg_addr_size
;
1832 ioc
->alloc_total
= sizeof(MPT_ADAPTER
);
1833 ioc
->req_sz
= MPT_DEFAULT_FRAME_SIZE
; /* avoid div by zero! */
1834 ioc
->reply_sz
= MPT_REPLY_FRAME_SIZE
;
1837 spin_lock_init(&ioc
->taskmgmt_lock
);
1838 mutex_init(&ioc
->internal_cmds
.mutex
);
1839 init_completion(&ioc
->internal_cmds
.done
);
1840 mutex_init(&ioc
->mptbase_cmds
.mutex
);
1841 init_completion(&ioc
->mptbase_cmds
.done
);
1842 mutex_init(&ioc
->taskmgmt_cmds
.mutex
);
1843 init_completion(&ioc
->taskmgmt_cmds
.done
);
1845 /* Initialize the event logging.
1847 ioc
->eventTypes
= 0; /* None */
1848 ioc
->eventContext
= 0;
1849 ioc
->eventLogSize
= 0;
1857 ioc
->cached_fw
= NULL
;
1859 /* Initialize SCSI Config Data structure
1861 memset(&ioc
->spi_data
, 0, sizeof(SpiCfgData
));
1863 /* Initialize the fc rport list head.
1865 INIT_LIST_HEAD(&ioc
->fc_rports
);
1867 /* Find lookup slot. */
1868 INIT_LIST_HEAD(&ioc
->list
);
1871 /* Initialize workqueue */
1872 INIT_DELAYED_WORK(&ioc
->fault_reset_work
, mpt_fault_reset_work
);
1874 snprintf(ioc
->reset_work_q_name
, MPT_KOBJ_NAME_LEN
,
1875 "mpt_poll_%d", ioc
->id
);
1877 create_singlethread_workqueue(ioc
->reset_work_q_name
);
1878 if (!ioc
->reset_work_q
) {
1879 printk(MYIOC_s_ERR_FMT
"Insufficient memory to add adapter!\n",
1881 pci_release_selected_regions(pdev
, ioc
->bars
);
1886 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
"facts @ %p, pfacts[0] @ %p\n",
1887 ioc
->name
, &ioc
->facts
, &ioc
->pfacts
[0]));
1889 pci_read_config_byte(pdev
, PCI_CLASS_REVISION
, &revision
);
1890 mpt_get_product_name(pdev
->vendor
, pdev
->device
, revision
, ioc
->prod_name
);
1892 switch (pdev
->device
)
1894 case MPI_MANUFACTPAGE_DEVICEID_FC939X
:
1895 case MPI_MANUFACTPAGE_DEVICEID_FC949X
:
1896 ioc
->errata_flag_1064
= 1;
1897 case MPI_MANUFACTPAGE_DEVICEID_FC909
:
1898 case MPI_MANUFACTPAGE_DEVICEID_FC929
:
1899 case MPI_MANUFACTPAGE_DEVICEID_FC919
:
1900 case MPI_MANUFACTPAGE_DEVICEID_FC949E
:
1904 case MPI_MANUFACTPAGE_DEVICEID_FC929X
:
1905 if (revision
< XL_929
) {
1906 /* 929X Chip Fix. Set Split transactions level
1907 * for PCIX. Set MOST bits to zero.
1909 pci_read_config_byte(pdev
, 0x6a, &pcixcmd
);
1911 pci_write_config_byte(pdev
, 0x6a, pcixcmd
);
1913 /* 929XL Chip Fix. Set MMRBC to 0x08.
1915 pci_read_config_byte(pdev
, 0x6a, &pcixcmd
);
1917 pci_write_config_byte(pdev
, 0x6a, pcixcmd
);
1922 case MPI_MANUFACTPAGE_DEVICEID_FC919X
:
1923 /* 919X Chip Fix. Set Split transactions level
1924 * for PCIX. Set MOST bits to zero.
1926 pci_read_config_byte(pdev
, 0x6a, &pcixcmd
);
1928 pci_write_config_byte(pdev
, 0x6a, pcixcmd
);
1932 case MPI_MANUFACTPAGE_DEVID_53C1030
:
1933 /* 1030 Chip Fix. Disable Split transactions
1934 * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
1936 if (revision
< C0_1030
) {
1937 pci_read_config_byte(pdev
, 0x6a, &pcixcmd
);
1939 pci_write_config_byte(pdev
, 0x6a, pcixcmd
);
1942 case MPI_MANUFACTPAGE_DEVID_1030_53C1035
:
1943 ioc
->bus_type
= SPI
;
1946 case MPI_MANUFACTPAGE_DEVID_SAS1064
:
1947 case MPI_MANUFACTPAGE_DEVID_SAS1068
:
1948 ioc
->errata_flag_1064
= 1;
1949 ioc
->bus_type
= SAS
;
1952 case MPI_MANUFACTPAGE_DEVID_SAS1064E
:
1953 case MPI_MANUFACTPAGE_DEVID_SAS1068E
:
1954 case MPI_MANUFACTPAGE_DEVID_SAS1078
:
1955 ioc
->bus_type
= SAS
;
1960 switch (ioc
->bus_type
) {
1963 ioc
->msi_enable
= mpt_msi_enable_sas
;
1967 ioc
->msi_enable
= mpt_msi_enable_spi
;
1971 ioc
->msi_enable
= mpt_msi_enable_fc
;
1975 ioc
->msi_enable
= 0;
1979 ioc
->fw_events_off
= 1;
1981 if (ioc
->errata_flag_1064
)
1982 pci_disable_io_access(pdev
);
1984 spin_lock_init(&ioc
->FreeQlock
);
1987 CHIPREG_WRITE32(&ioc
->chip
->IntMask
, 0xFFFFFFFF);
1989 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
1991 /* Set IOC ptr in the pcidev's driver data. */
1992 pci_set_drvdata(ioc
->pcidev
, ioc
);
1994 /* Set lookup ptr. */
1995 list_add_tail(&ioc
->list
, &ioc_list
);
1997 /* Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
1999 mpt_detect_bound_ports(ioc
, pdev
);
2001 INIT_LIST_HEAD(&ioc
->fw_event_list
);
2002 spin_lock_init(&ioc
->fw_event_lock
);
2003 snprintf(ioc
->fw_event_q_name
, MPT_KOBJ_NAME_LEN
, "mpt/%d", ioc
->id
);
2004 ioc
->fw_event_q
= create_singlethread_workqueue(ioc
->fw_event_q_name
);
2006 if ((r
= mpt_do_ioc_recovery(ioc
, MPT_HOSTEVENT_IOC_BRINGUP
,
2008 printk(MYIOC_s_ERR_FMT
"didn't initialize properly! (%d)\n",
2011 list_del(&ioc
->list
);
2013 ioc
->alt_ioc
->alt_ioc
= NULL
;
2014 iounmap(ioc
->memmap
);
2016 pci_release_selected_regions(pdev
, ioc
->bars
);
2018 destroy_workqueue(ioc
->reset_work_q
);
2019 ioc
->reset_work_q
= NULL
;
2022 pci_set_drvdata(pdev
, NULL
);
2026 /* call per device driver probe entry point */
2027 for(cb_idx
= 0; cb_idx
< MPT_MAX_PROTOCOL_DRIVERS
; cb_idx
++) {
2028 if(MptDeviceDriverHandlers
[cb_idx
] &&
2029 MptDeviceDriverHandlers
[cb_idx
]->probe
) {
2030 MptDeviceDriverHandlers
[cb_idx
]->probe(pdev
,id
);
2034 #ifdef CONFIG_PROC_FS
2036 * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
2038 dent
= proc_mkdir(ioc
->name
, mpt_proc_root_dir
);
2040 proc_create_data("info", S_IRUGO
, dent
, &mpt_iocinfo_proc_fops
, ioc
);
2041 proc_create_data("summary", S_IRUGO
, dent
, &mpt_summary_proc_fops
, ioc
);
2046 queue_delayed_work(ioc
->reset_work_q
, &ioc
->fault_reset_work
,
2047 msecs_to_jiffies(MPT_POLLING_INTERVAL
));
2052 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2054 * mpt_detach - Remove a PCI intelligent MPT adapter.
2055 * @pdev: Pointer to pci_dev structure
2059 mpt_detach(struct pci_dev
*pdev
)
2061 MPT_ADAPTER
*ioc
= pci_get_drvdata(pdev
);
2064 unsigned long flags
;
2065 struct workqueue_struct
*wq
;
2068 * Stop polling ioc for fault condition
2070 spin_lock_irqsave(&ioc
->taskmgmt_lock
, flags
);
2071 wq
= ioc
->reset_work_q
;
2072 ioc
->reset_work_q
= NULL
;
2073 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
2074 cancel_delayed_work(&ioc
->fault_reset_work
);
2075 destroy_workqueue(wq
);
2077 spin_lock_irqsave(&ioc
->fw_event_lock
, flags
);
2078 wq
= ioc
->fw_event_q
;
2079 ioc
->fw_event_q
= NULL
;
2080 spin_unlock_irqrestore(&ioc
->fw_event_lock
, flags
);
2081 destroy_workqueue(wq
);
2083 sprintf(pname
, MPT_PROCFS_MPTBASEDIR
"/%s/summary", ioc
->name
);
2084 remove_proc_entry(pname
, NULL
);
2085 sprintf(pname
, MPT_PROCFS_MPTBASEDIR
"/%s/info", ioc
->name
);
2086 remove_proc_entry(pname
, NULL
);
2087 sprintf(pname
, MPT_PROCFS_MPTBASEDIR
"/%s", ioc
->name
);
2088 remove_proc_entry(pname
, NULL
);
2090 /* call per device driver remove entry point */
2091 for(cb_idx
= 0; cb_idx
< MPT_MAX_PROTOCOL_DRIVERS
; cb_idx
++) {
2092 if(MptDeviceDriverHandlers
[cb_idx
] &&
2093 MptDeviceDriverHandlers
[cb_idx
]->remove
) {
2094 MptDeviceDriverHandlers
[cb_idx
]->remove(pdev
);
2098 /* Disable interrupts! */
2099 CHIPREG_WRITE32(&ioc
->chip
->IntMask
, 0xFFFFFFFF);
2102 synchronize_irq(pdev
->irq
);
2104 /* Clear any lingering interrupt */
2105 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
2107 CHIPREG_READ32(&ioc
->chip
->IntStatus
);
2109 mpt_adapter_dispose(ioc
);
2113 /**************************************************************************
2117 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2119 * mpt_suspend - Fusion MPT base driver suspend routine.
2120 * @pdev: Pointer to pci_dev structure
2121 * @state: new state to enter
2124 mpt_suspend(struct pci_dev
*pdev
, pm_message_t state
)
2127 MPT_ADAPTER
*ioc
= pci_get_drvdata(pdev
);
2129 device_state
= pci_choose_state(pdev
, state
);
2130 printk(MYIOC_s_INFO_FMT
"pci-suspend: pdev=0x%p, slot=%s, Entering "
2131 "operating state [D%d]\n", ioc
->name
, pdev
, pci_name(pdev
),
2134 /* put ioc into READY_STATE */
2135 if(SendIocReset(ioc
, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
, CAN_SLEEP
)) {
2136 printk(MYIOC_s_ERR_FMT
2137 "pci-suspend: IOC msg unit reset failed!\n", ioc
->name
);
2140 /* disable interrupts */
2141 CHIPREG_WRITE32(&ioc
->chip
->IntMask
, 0xFFFFFFFF);
2144 /* Clear any lingering interrupt */
2145 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
2147 free_irq(ioc
->pci_irq
, ioc
);
2148 if (ioc
->msi_enable
)
2149 pci_disable_msi(ioc
->pcidev
);
2151 pci_save_state(pdev
);
2152 pci_disable_device(pdev
);
2153 pci_release_selected_regions(pdev
, ioc
->bars
);
2154 pci_set_power_state(pdev
, device_state
);
2158 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2160 * mpt_resume - Fusion MPT base driver resume routine.
2161 * @pdev: Pointer to pci_dev structure
2164 mpt_resume(struct pci_dev
*pdev
)
2166 MPT_ADAPTER
*ioc
= pci_get_drvdata(pdev
);
2167 u32 device_state
= pdev
->current_state
;
2171 printk(MYIOC_s_INFO_FMT
"pci-resume: pdev=0x%p, slot=%s, Previous "
2172 "operating state [D%d]\n", ioc
->name
, pdev
, pci_name(pdev
),
2175 pci_set_power_state(pdev
, PCI_D0
);
2176 pci_enable_wake(pdev
, PCI_D0
, 0);
2177 pci_restore_state(pdev
);
2179 err
= mpt_mapresources(ioc
);
2183 if (ioc
->dma_mask
== DMA_BIT_MASK(64)) {
2184 if (pdev
->device
== MPI_MANUFACTPAGE_DEVID_SAS1078
)
2185 ioc
->add_sge
= &mpt_add_sge_64bit_1078
;
2187 ioc
->add_sge
= &mpt_add_sge_64bit
;
2188 ioc
->add_chain
= &mpt_add_chain_64bit
;
2189 ioc
->sg_addr_size
= 8;
2192 ioc
->add_sge
= &mpt_add_sge
;
2193 ioc
->add_chain
= &mpt_add_chain
;
2194 ioc
->sg_addr_size
= 4;
2196 ioc
->SGE_size
= sizeof(u32
) + ioc
->sg_addr_size
;
2198 printk(MYIOC_s_INFO_FMT
"pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
2199 ioc
->name
, (mpt_GetIocState(ioc
, 1) >> MPI_IOC_STATE_SHIFT
),
2200 CHIPREG_READ32(&ioc
->chip
->Doorbell
));
2203 * Errata workaround for SAS pci express:
2204 * Upon returning to the D0 state, the contents of the doorbell will be
2205 * stale data, and this will incorrectly signal to the host driver that
2206 * the firmware is ready to process mpt commands. The workaround is
2207 * to issue a diagnostic reset.
2209 if (ioc
->bus_type
== SAS
&& (pdev
->device
==
2210 MPI_MANUFACTPAGE_DEVID_SAS1068E
|| pdev
->device
==
2211 MPI_MANUFACTPAGE_DEVID_SAS1064E
)) {
2212 if (KickStart(ioc
, 1, CAN_SLEEP
) < 0) {
2213 printk(MYIOC_s_WARN_FMT
"pci-resume: Cannot recover\n",
2219 /* bring ioc to operational state */
2220 printk(MYIOC_s_INFO_FMT
"Sending mpt_do_ioc_recovery\n", ioc
->name
);
2221 recovery_state
= mpt_do_ioc_recovery(ioc
, MPT_HOSTEVENT_IOC_BRINGUP
,
2223 if (recovery_state
!= 0)
2224 printk(MYIOC_s_WARN_FMT
"pci-resume: Cannot recover, "
2225 "error:[%x]\n", ioc
->name
, recovery_state
);
2227 printk(MYIOC_s_INFO_FMT
2228 "pci-resume: success\n", ioc
->name
);
2236 mpt_signal_reset(u8 index
, MPT_ADAPTER
*ioc
, int reset_phase
)
2238 if ((MptDriverClass
[index
] == MPTSPI_DRIVER
&&
2239 ioc
->bus_type
!= SPI
) ||
2240 (MptDriverClass
[index
] == MPTFC_DRIVER
&&
2241 ioc
->bus_type
!= FC
) ||
2242 (MptDriverClass
[index
] == MPTSAS_DRIVER
&&
2243 ioc
->bus_type
!= SAS
))
2244 /* make sure we only call the relevant reset handler
2247 return (MptResetHandlers
[index
])(ioc
, reset_phase
);
2250 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2252 * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
2253 * @ioc: Pointer to MPT adapter structure
2254 * @reason: Event word / reason
2255 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
2257 * This routine performs all the steps necessary to bring the IOC
2258 * to a OPERATIONAL state.
2260 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
2265 * -1 if failed to get board READY
2266 * -2 if READY but IOCFacts Failed
2267 * -3 if READY but PrimeIOCFifos Failed
2268 * -4 if READY but IOCInit Failed
2269 * -5 if failed to enable_device and/or request_selected_regions
2270 * -6 if failed to upload firmware
2273 mpt_do_ioc_recovery(MPT_ADAPTER
*ioc
, u32 reason
, int sleepFlag
)
2275 int hard_reset_done
= 0;
2276 int alt_ioc_ready
= 0;
2281 int reset_alt_ioc_active
= 0;
2282 int irq_allocated
= 0;
2285 printk(MYIOC_s_INFO_FMT
"Initiating %s\n", ioc
->name
,
2286 reason
== MPT_HOSTEVENT_IOC_BRINGUP
? "bringup" : "recovery");
2288 /* Disable reply interrupts (also blocks FreeQ) */
2289 CHIPREG_WRITE32(&ioc
->chip
->IntMask
, 0xFFFFFFFF);
2293 if (ioc
->alt_ioc
->active
||
2294 reason
== MPT_HOSTEVENT_IOC_RECOVER
) {
2295 reset_alt_ioc_active
= 1;
2296 /* Disable alt-IOC's reply interrupts
2297 * (and FreeQ) for a bit
2299 CHIPREG_WRITE32(&ioc
->alt_ioc
->chip
->IntMask
,
2301 ioc
->alt_ioc
->active
= 0;
2306 if (reason
== MPT_HOSTEVENT_IOC_BRINGUP
)
2309 if ((hard_reset_done
= MakeIocReady(ioc
, hard
, sleepFlag
)) < 0) {
2310 if (hard_reset_done
== -4) {
2311 printk(MYIOC_s_WARN_FMT
"Owned by PEER..skipping!\n",
2314 if (reset_alt_ioc_active
&& ioc
->alt_ioc
) {
2315 /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
2316 dprintk(ioc
, printk(MYIOC_s_INFO_FMT
2317 "alt_ioc reply irq re-enabled\n", ioc
->alt_ioc
->name
));
2318 CHIPREG_WRITE32(&ioc
->alt_ioc
->chip
->IntMask
, MPI_HIM_DIM
);
2319 ioc
->alt_ioc
->active
= 1;
2323 printk(MYIOC_s_WARN_FMT
2324 "NOT READY WARNING!\n", ioc
->name
);
2330 /* hard_reset_done = 0 if a soft reset was performed
2331 * and 1 if a hard reset was performed.
2333 if (hard_reset_done
&& reset_alt_ioc_active
&& ioc
->alt_ioc
) {
2334 if ((rc
= MakeIocReady(ioc
->alt_ioc
, 0, sleepFlag
)) == 0)
2337 printk(MYIOC_s_WARN_FMT
2338 ": alt-ioc Not ready WARNING!\n",
2339 ioc
->alt_ioc
->name
);
2342 for (ii
=0; ii
<5; ii
++) {
2343 /* Get IOC facts! Allow 5 retries */
2344 if ((rc
= GetIocFacts(ioc
, sleepFlag
, reason
)) == 0)
2350 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
2351 "Retry IocFacts failed rc=%x\n", ioc
->name
, rc
));
2353 } else if (reason
== MPT_HOSTEVENT_IOC_BRINGUP
) {
2354 MptDisplayIocCapabilities(ioc
);
2357 if (alt_ioc_ready
) {
2358 if ((rc
= GetIocFacts(ioc
->alt_ioc
, sleepFlag
, reason
)) != 0) {
2359 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
2360 "Initial Alt IocFacts failed rc=%x\n",
2362 /* Retry - alt IOC was initialized once
2364 rc
= GetIocFacts(ioc
->alt_ioc
, sleepFlag
, reason
);
2367 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
2368 "Retry Alt IocFacts failed rc=%x\n", ioc
->name
, rc
));
2370 reset_alt_ioc_active
= 0;
2371 } else if (reason
== MPT_HOSTEVENT_IOC_BRINGUP
) {
2372 MptDisplayIocCapabilities(ioc
->alt_ioc
);
2376 if ((ret
== 0) && (reason
== MPT_HOSTEVENT_IOC_BRINGUP
) &&
2377 (ioc
->facts
.Flags
& MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT
)) {
2378 pci_release_selected_regions(ioc
->pcidev
, ioc
->bars
);
2379 ioc
->bars
= pci_select_bars(ioc
->pcidev
, IORESOURCE_MEM
|
2381 if (pci_enable_device(ioc
->pcidev
))
2383 if (pci_request_selected_regions(ioc
->pcidev
, ioc
->bars
,
2389 * Device is reset now. It must have de-asserted the interrupt line
2390 * (if it was asserted) and it should be safe to register for the
2393 if ((ret
== 0) && (reason
== MPT_HOSTEVENT_IOC_BRINGUP
)) {
2395 if (ioc
->pcidev
->irq
) {
2396 if (ioc
->msi_enable
&& !pci_enable_msi(ioc
->pcidev
))
2397 printk(MYIOC_s_INFO_FMT
"PCI-MSI enabled\n",
2400 ioc
->msi_enable
= 0;
2401 rc
= request_irq(ioc
->pcidev
->irq
, mpt_interrupt
,
2402 IRQF_SHARED
, ioc
->name
, ioc
);
2404 printk(MYIOC_s_ERR_FMT
"Unable to allocate "
2406 ioc
->name
, ioc
->pcidev
->irq
);
2407 if (ioc
->msi_enable
)
2408 pci_disable_msi(ioc
->pcidev
);
2413 ioc
->pci_irq
= ioc
->pcidev
->irq
;
2414 pci_set_master(ioc
->pcidev
); /* ?? */
2415 pci_set_drvdata(ioc
->pcidev
, ioc
);
2416 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
2417 "installed at interrupt %d\n", ioc
->name
,
2422 /* Prime reply & request queues!
2423 * (mucho alloc's) Must be done prior to
2424 * init as upper addresses are needed for init.
2425 * If fails, continue with alt-ioc processing
2427 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
"PrimeIocFifos\n",
2429 if ((ret
== 0) && ((rc
= PrimeIocFifos(ioc
)) != 0))
2432 /* May need to check/upload firmware & data here!
2433 * If fails, continue with alt-ioc processing
2435 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
"SendIocInit\n",
2437 if ((ret
== 0) && ((rc
= SendIocInit(ioc
, sleepFlag
)) != 0))
2440 if (alt_ioc_ready
&& ((rc
= PrimeIocFifos(ioc
->alt_ioc
)) != 0)) {
2441 printk(MYIOC_s_WARN_FMT
2442 ": alt-ioc (%d) FIFO mgmt alloc WARNING!\n",
2443 ioc
->alt_ioc
->name
, rc
);
2445 reset_alt_ioc_active
= 0;
2448 if (alt_ioc_ready
) {
2449 if ((rc
= SendIocInit(ioc
->alt_ioc
, sleepFlag
)) != 0) {
2451 reset_alt_ioc_active
= 0;
2452 printk(MYIOC_s_WARN_FMT
2453 ": alt-ioc: (%d) init failure WARNING!\n",
2454 ioc
->alt_ioc
->name
, rc
);
2458 if (reason
== MPT_HOSTEVENT_IOC_BRINGUP
){
2459 if (ioc
->upload_fw
) {
2460 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
2461 "firmware upload required!\n", ioc
->name
));
2463 /* Controller is not operational, cannot do upload
2466 rc
= mpt_do_upload(ioc
, sleepFlag
);
2468 if (ioc
->alt_ioc
&& ioc
->alt_ioc
->cached_fw
) {
2470 * Maintain only one pointer to FW memory
2471 * so there will not be two attempt to
2472 * downloadboot onboard dual function
2473 * chips (mpt_adapter_disable,
2476 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
2477 "mpt_upload: alt_%s has cached_fw=%p \n",
2478 ioc
->name
, ioc
->alt_ioc
->name
, ioc
->alt_ioc
->cached_fw
));
2479 ioc
->cached_fw
= NULL
;
2482 printk(MYIOC_s_WARN_FMT
2483 "firmware upload failure!\n", ioc
->name
);
2490 /* Enable MPT base driver management of EventNotification
2491 * and EventAck handling.
2493 if ((ret
== 0) && (!ioc
->facts
.EventState
)) {
2494 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
2495 "SendEventNotification\n",
2497 ret
= SendEventNotification(ioc
, 1, sleepFlag
); /* 1=Enable */
2500 if (ioc
->alt_ioc
&& alt_ioc_ready
&& !ioc
->alt_ioc
->facts
.EventState
)
2501 rc
= SendEventNotification(ioc
->alt_ioc
, 1, sleepFlag
);
2504 /* Enable! (reply interrupt) */
2505 CHIPREG_WRITE32(&ioc
->chip
->IntMask
, MPI_HIM_DIM
);
2508 if (rc
== 0) { /* alt ioc */
2509 if (reset_alt_ioc_active
&& ioc
->alt_ioc
) {
2510 /* (re)Enable alt-IOC! (reply interrupt) */
2511 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"alt-ioc"
2512 "reply irq re-enabled\n",
2513 ioc
->alt_ioc
->name
));
2514 CHIPREG_WRITE32(&ioc
->alt_ioc
->chip
->IntMask
,
2516 ioc
->alt_ioc
->active
= 1;
2521 /* Add additional "reason" check before call to GetLanConfigPages
2522 * (combined with GetIoUnitPage2 call). This prevents a somewhat
2523 * recursive scenario; GetLanConfigPages times out, timer expired
2524 * routine calls HardResetHandler, which calls into here again,
2525 * and we try GetLanConfigPages again...
2527 if ((ret
== 0) && (reason
== MPT_HOSTEVENT_IOC_BRINGUP
)) {
2530 * Initialize link list for inactive raid volumes.
2532 mutex_init(&ioc
->raid_data
.inactive_list_mutex
);
2533 INIT_LIST_HEAD(&ioc
->raid_data
.inactive_list
);
2535 switch (ioc
->bus_type
) {
2538 /* clear persistency table */
2539 if(ioc
->facts
.IOCExceptions
&
2540 MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL
) {
2541 ret
= mptbase_sas_persist_operation(ioc
,
2542 MPI_SAS_OP_CLEAR_NOT_PRESENT
);
2549 mpt_findImVolumes(ioc
);
2551 /* Check, and possibly reset, the coalescing value
2553 mpt_read_ioc_pg_1(ioc
);
2558 if ((ioc
->pfacts
[0].ProtocolFlags
&
2559 MPI_PORTFACTS_PROTOCOL_LAN
) &&
2560 (ioc
->lan_cnfg_page0
.Header
.PageLength
== 0)) {
2562 * Pre-fetch the ports LAN MAC address!
2563 * (LANPage1_t stuff)
2565 (void) GetLanConfigPages(ioc
);
2566 a
= (u8
*)&ioc
->lan_cnfg_page1
.HardwareAddressLow
;
2567 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
2568 "LanAddr = %02X:%02X:%02X"
2569 ":%02X:%02X:%02X\n",
2570 ioc
->name
, a
[5], a
[4],
2571 a
[3], a
[2], a
[1], a
[0]));
2576 /* Get NVRAM and adapter maximums from SPP 0 and 2
2578 mpt_GetScsiPortSettings(ioc
, 0);
2580 /* Get version and length of SDP 1
2582 mpt_readScsiDevicePageHeaders(ioc
, 0);
2586 if (ioc
->facts
.MsgVersion
>= MPI_VERSION_01_02
)
2587 mpt_findImVolumes(ioc
);
2589 /* Check, and possibly reset, the coalescing value
2591 mpt_read_ioc_pg_1(ioc
);
2593 mpt_read_ioc_pg_4(ioc
);
2598 GetIoUnitPage2(ioc
);
2599 mpt_get_manufacturing_pg_0(ioc
);
2603 if ((ret
!= 0) && irq_allocated
) {
2604 free_irq(ioc
->pci_irq
, ioc
);
2605 if (ioc
->msi_enable
)
2606 pci_disable_msi(ioc
->pcidev
);
2611 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2613 * mpt_detect_bound_ports - Search for matching PCI bus/dev_function
2614 * @ioc: Pointer to MPT adapter structure
2615 * @pdev: Pointer to (struct pci_dev) structure
2617 * Search for PCI bus/dev_function which matches
2618 * PCI bus/dev_function (+/-1) for newly discovered 929,
2619 * 929X, 1030 or 1035.
2621 * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
2622 * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
2625 mpt_detect_bound_ports(MPT_ADAPTER
*ioc
, struct pci_dev
*pdev
)
2627 struct pci_dev
*peer
=NULL
;
2628 unsigned int slot
= PCI_SLOT(pdev
->devfn
);
2629 unsigned int func
= PCI_FUNC(pdev
->devfn
);
2630 MPT_ADAPTER
*ioc_srch
;
2632 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"PCI device %s devfn=%x/%x,"
2633 " searching for devfn match on %x or %x\n",
2634 ioc
->name
, pci_name(pdev
), pdev
->bus
->number
,
2635 pdev
->devfn
, func
-1, func
+1));
2637 peer
= pci_get_slot(pdev
->bus
, PCI_DEVFN(slot
,func
-1));
2639 peer
= pci_get_slot(pdev
->bus
, PCI_DEVFN(slot
,func
+1));
2644 list_for_each_entry(ioc_srch
, &ioc_list
, list
) {
2645 struct pci_dev
*_pcidev
= ioc_srch
->pcidev
;
2646 if (_pcidev
== peer
) {
2647 /* Paranoia checks */
2648 if (ioc
->alt_ioc
!= NULL
) {
2649 printk(MYIOC_s_WARN_FMT
2650 "Oops, already bound (%s <==> %s)!\n",
2651 ioc
->name
, ioc
->name
, ioc
->alt_ioc
->name
);
2653 } else if (ioc_srch
->alt_ioc
!= NULL
) {
2654 printk(MYIOC_s_WARN_FMT
2655 "Oops, already bound (%s <==> %s)!\n",
2656 ioc_srch
->name
, ioc_srch
->name
,
2657 ioc_srch
->alt_ioc
->name
);
2660 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
2661 "FOUND! binding %s <==> %s\n",
2662 ioc
->name
, ioc
->name
, ioc_srch
->name
));
2663 ioc_srch
->alt_ioc
= ioc
;
2664 ioc
->alt_ioc
= ioc_srch
;
2670 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2672 * mpt_adapter_disable - Disable misbehaving MPT adapter.
2673 * @ioc: Pointer to MPT adapter structure
2676 mpt_adapter_disable(MPT_ADAPTER
*ioc
)
2681 if (ioc
->cached_fw
!= NULL
) {
2682 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
2683 "%s: Pushing FW onto adapter\n", __func__
, ioc
->name
));
2684 if ((ret
= mpt_downloadboot(ioc
, (MpiFwHeader_t
*)
2685 ioc
->cached_fw
, CAN_SLEEP
)) < 0) {
2686 printk(MYIOC_s_WARN_FMT
2687 ": firmware downloadboot failure (%d)!\n",
2693 * Put the controller into ready state (if its not already)
2695 if (mpt_GetIocState(ioc
, 1) != MPI_IOC_STATE_READY
) {
2696 if (!SendIocReset(ioc
, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
,
2698 if (mpt_GetIocState(ioc
, 1) != MPI_IOC_STATE_READY
)
2699 printk(MYIOC_s_ERR_FMT
"%s: IOC msg unit "
2700 "reset failed to put ioc in ready state!\n",
2701 ioc
->name
, __func__
);
2703 printk(MYIOC_s_ERR_FMT
"%s: IOC msg unit reset "
2704 "failed!\n", ioc
->name
, __func__
);
2708 /* Disable adapter interrupts! */
2709 synchronize_irq(ioc
->pcidev
->irq
);
2710 CHIPREG_WRITE32(&ioc
->chip
->IntMask
, 0xFFFFFFFF);
2713 /* Clear any lingering interrupt */
2714 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
2715 CHIPREG_READ32(&ioc
->chip
->IntStatus
);
2717 if (ioc
->alloc
!= NULL
) {
2719 dexitprintk(ioc
, printk(MYIOC_s_INFO_FMT
"free @ %p, sz=%d bytes\n",
2720 ioc
->name
, ioc
->alloc
, ioc
->alloc_sz
));
2721 pci_free_consistent(ioc
->pcidev
, sz
,
2722 ioc
->alloc
, ioc
->alloc_dma
);
2723 ioc
->reply_frames
= NULL
;
2724 ioc
->req_frames
= NULL
;
2726 ioc
->alloc_total
-= sz
;
2729 if (ioc
->sense_buf_pool
!= NULL
) {
2730 sz
= (ioc
->req_depth
* MPT_SENSE_BUFFER_ALLOC
);
2731 pci_free_consistent(ioc
->pcidev
, sz
,
2732 ioc
->sense_buf_pool
, ioc
->sense_buf_pool_dma
);
2733 ioc
->sense_buf_pool
= NULL
;
2734 ioc
->alloc_total
-= sz
;
2737 if (ioc
->events
!= NULL
){
2738 sz
= MPTCTL_EVENT_LOG_SIZE
* sizeof(MPT_IOCTL_EVENTS
);
2741 ioc
->alloc_total
-= sz
;
2744 mpt_free_fw_memory(ioc
);
2746 kfree(ioc
->spi_data
.nvram
);
2747 mpt_inactive_raid_list_free(ioc
);
2748 kfree(ioc
->raid_data
.pIocPg2
);
2749 kfree(ioc
->raid_data
.pIocPg3
);
2750 ioc
->spi_data
.nvram
= NULL
;
2751 ioc
->raid_data
.pIocPg3
= NULL
;
2753 if (ioc
->spi_data
.pIocPg4
!= NULL
) {
2754 sz
= ioc
->spi_data
.IocPg4Sz
;
2755 pci_free_consistent(ioc
->pcidev
, sz
,
2756 ioc
->spi_data
.pIocPg4
,
2757 ioc
->spi_data
.IocPg4_dma
);
2758 ioc
->spi_data
.pIocPg4
= NULL
;
2759 ioc
->alloc_total
-= sz
;
2762 if (ioc
->ReqToChain
!= NULL
) {
2763 kfree(ioc
->ReqToChain
);
2764 kfree(ioc
->RequestNB
);
2765 ioc
->ReqToChain
= NULL
;
2768 kfree(ioc
->ChainToChain
);
2769 ioc
->ChainToChain
= NULL
;
2771 if (ioc
->HostPageBuffer
!= NULL
) {
2772 if((ret
= mpt_host_page_access_control(ioc
,
2773 MPI_DB_HPBAC_FREE_BUFFER
, NO_SLEEP
)) != 0) {
2774 printk(MYIOC_s_ERR_FMT
2775 ": %s: host page buffers free failed (%d)!\n",
2776 ioc
->name
, __func__
, ret
);
2778 dexitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
2779 "HostPageBuffer free @ %p, sz=%d bytes\n",
2780 ioc
->name
, ioc
->HostPageBuffer
,
2781 ioc
->HostPageBuffer_sz
));
2782 pci_free_consistent(ioc
->pcidev
, ioc
->HostPageBuffer_sz
,
2783 ioc
->HostPageBuffer
, ioc
->HostPageBuffer_dma
);
2784 ioc
->HostPageBuffer
= NULL
;
2785 ioc
->HostPageBuffer_sz
= 0;
2786 ioc
->alloc_total
-= ioc
->HostPageBuffer_sz
;
2789 pci_set_drvdata(ioc
->pcidev
, NULL
);
2791 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2793 * mpt_adapter_dispose - Free all resources associated with an MPT adapter
2794 * @ioc: Pointer to MPT adapter structure
2796 * This routine unregisters h/w resources and frees all alloc'd memory
2797 * associated with a MPT adapter structure.
2800 mpt_adapter_dispose(MPT_ADAPTER
*ioc
)
2802 int sz_first
, sz_last
;
2807 sz_first
= ioc
->alloc_total
;
2809 mpt_adapter_disable(ioc
);
2811 if (ioc
->pci_irq
!= -1) {
2812 free_irq(ioc
->pci_irq
, ioc
);
2813 if (ioc
->msi_enable
)
2814 pci_disable_msi(ioc
->pcidev
);
2818 if (ioc
->memmap
!= NULL
) {
2819 iounmap(ioc
->memmap
);
2823 pci_disable_device(ioc
->pcidev
);
2824 pci_release_selected_regions(ioc
->pcidev
, ioc
->bars
);
2826 #if defined(CONFIG_MTRR) && 0
2827 if (ioc
->mtrr_reg
> 0) {
2828 mtrr_del(ioc
->mtrr_reg
, 0, 0);
2829 dprintk(ioc
, printk(MYIOC_s_INFO_FMT
"MTRR region de-registered\n", ioc
->name
));
2833 /* Zap the adapter lookup ptr! */
2834 list_del(&ioc
->list
);
2836 sz_last
= ioc
->alloc_total
;
2837 dprintk(ioc
, printk(MYIOC_s_INFO_FMT
"free'd %d of %d bytes\n",
2838 ioc
->name
, sz_first
-sz_last
+(int)sizeof(*ioc
), sz_first
));
2841 ioc
->alt_ioc
->alt_ioc
= NULL
;
2846 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2848 * MptDisplayIocCapabilities - Disply IOC's capabilities.
2849 * @ioc: Pointer to MPT adapter structure
2852 MptDisplayIocCapabilities(MPT_ADAPTER
*ioc
)
2856 printk(KERN_INFO
"%s: ", ioc
->name
);
2858 printk("%s: ", ioc
->prod_name
);
2859 printk("Capabilities={");
2861 if (ioc
->pfacts
[0].ProtocolFlags
& MPI_PORTFACTS_PROTOCOL_INITIATOR
) {
2862 printk("Initiator");
2866 if (ioc
->pfacts
[0].ProtocolFlags
& MPI_PORTFACTS_PROTOCOL_TARGET
) {
2867 printk("%sTarget", i
? "," : "");
2871 if (ioc
->pfacts
[0].ProtocolFlags
& MPI_PORTFACTS_PROTOCOL_LAN
) {
2872 printk("%sLAN", i
? "," : "");
2878 * This would probably evoke more questions than it's worth
2880 if (ioc
->pfacts
[0].ProtocolFlags
& MPI_PORTFACTS_PROTOCOL_TARGET
) {
2881 printk("%sLogBusAddr", i
? "," : "");
2889 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2891 * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
2892 * @ioc: Pointer to MPT_ADAPTER structure
2893 * @force: Force hard KickStart of IOC
2894 * @sleepFlag: Specifies whether the process can sleep
2897 * 1 - DIAG reset and READY
2898 * 0 - READY initially OR soft reset and READY
2899 * -1 - Any failure on KickStart
2900 * -2 - Msg Unit Reset Failed
2901 * -3 - IO Unit Reset Failed
2902 * -4 - IOC owned by a PEER
2905 MakeIocReady(MPT_ADAPTER
*ioc
, int force
, int sleepFlag
)
2910 int hard_reset_done
= 0;
2915 /* Get current [raw] IOC state */
2916 ioc_state
= mpt_GetIocState(ioc
, 0);
2917 dhsprintk(ioc
, printk(MYIOC_s_INFO_FMT
"MakeIocReady [raw] state=%08x\n", ioc
->name
, ioc_state
));
2920 * Check to see if IOC got left/stuck in doorbell handshake
2921 * grip of death. If so, hard reset the IOC.
2923 if (ioc_state
& MPI_DOORBELL_ACTIVE
) {
2925 printk(MYIOC_s_WARN_FMT
"Unexpected doorbell active!\n",
2929 /* Is it already READY? */
2931 ((ioc_state
& MPI_IOC_STATE_MASK
) == MPI_IOC_STATE_READY
)) {
2932 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
2933 "IOC is in READY state\n", ioc
->name
));
2938 * Check to see if IOC is in FAULT state.
2940 if ((ioc_state
& MPI_IOC_STATE_MASK
) == MPI_IOC_STATE_FAULT
) {
2942 printk(MYIOC_s_WARN_FMT
"IOC is in FAULT state!!!\n",
2944 printk(MYIOC_s_WARN_FMT
" FAULT code = %04xh\n",
2945 ioc
->name
, ioc_state
& MPI_DOORBELL_DATA_MASK
);
2949 * Hmmm... Did it get left operational?
2951 if ((ioc_state
& MPI_IOC_STATE_MASK
) == MPI_IOC_STATE_OPERATIONAL
) {
2952 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"IOC operational unexpected\n",
2956 * If PCI Peer, exit.
2957 * Else, if no fault conditions are present, issue a MessageUnitReset
2958 * Else, fall through to KickStart case
2960 whoinit
= (ioc_state
& MPI_DOORBELL_WHO_INIT_MASK
) >> MPI_DOORBELL_WHO_INIT_SHIFT
;
2961 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
2962 "whoinit 0x%x statefault %d force %d\n",
2963 ioc
->name
, whoinit
, statefault
, force
));
2964 if (whoinit
== MPI_WHOINIT_PCI_PEER
)
2967 if ((statefault
== 0 ) && (force
== 0)) {
2968 if ((r
= SendIocReset(ioc
, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
, sleepFlag
)) == 0)
2975 hard_reset_done
= KickStart(ioc
, statefault
||force
, sleepFlag
);
2976 if (hard_reset_done
< 0)
2980 * Loop here waiting for IOC to come READY.
2983 cntdn
= ((sleepFlag
== CAN_SLEEP
) ? HZ
: 1000) * 5; /* 5 seconds */
2985 while ((ioc_state
= mpt_GetIocState(ioc
, 1)) != MPI_IOC_STATE_READY
) {
2986 if (ioc_state
== MPI_IOC_STATE_OPERATIONAL
) {
2988 * BIOS or previous driver load left IOC in OP state.
2989 * Reset messaging FIFOs.
2991 if ((r
= SendIocReset(ioc
, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
, sleepFlag
)) != 0) {
2992 printk(MYIOC_s_ERR_FMT
"IOC msg unit reset failed!\n", ioc
->name
);
2995 } else if (ioc_state
== MPI_IOC_STATE_RESET
) {
2997 * Something is wrong. Try to get IOC back
3000 if ((r
= SendIocReset(ioc
, MPI_FUNCTION_IO_UNIT_RESET
, sleepFlag
)) != 0) {
3001 printk(MYIOC_s_ERR_FMT
"IO unit reset failed!\n", ioc
->name
);
3008 printk(MYIOC_s_ERR_FMT
3009 "Wait IOC_READY state (0x%x) timeout(%d)!\n",
3010 ioc
->name
, ioc_state
, (int)((ii
+5)/HZ
));
3014 if (sleepFlag
== CAN_SLEEP
) {
3017 mdelay (1); /* 1 msec delay */
3022 if (statefault
< 3) {
3023 printk(MYIOC_s_INFO_FMT
"Recovered from %s\n", ioc
->name
,
3024 statefault
== 1 ? "stuck handshake" : "IOC FAULT");
3027 return hard_reset_done
;
3030 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3032 * mpt_GetIocState - Get the current state of a MPT adapter.
3033 * @ioc: Pointer to MPT_ADAPTER structure
3034 * @cooked: Request raw or cooked IOC state
3036 * Returns all IOC Doorbell register bits if cooked==0, else just the
3037 * Doorbell bits in MPI_IOC_STATE_MASK.
3040 mpt_GetIocState(MPT_ADAPTER
*ioc
, int cooked
)
3045 s
= CHIPREG_READ32(&ioc
->chip
->Doorbell
);
3046 sc
= s
& MPI_IOC_STATE_MASK
;
3049 ioc
->last_state
= sc
;
3051 return cooked
? sc
: s
;
3054 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3056 * GetIocFacts - Send IOCFacts request to MPT adapter.
3057 * @ioc: Pointer to MPT_ADAPTER structure
3058 * @sleepFlag: Specifies whether the process can sleep
3059 * @reason: If recovery, only update facts.
3061 * Returns 0 for success, non-zero for failure.
3064 GetIocFacts(MPT_ADAPTER
*ioc
, int sleepFlag
, int reason
)
3066 IOCFacts_t get_facts
;
3067 IOCFactsReply_t
*facts
;
3075 /* IOC *must* NOT be in RESET state! */
3076 if (ioc
->last_state
== MPI_IOC_STATE_RESET
) {
3077 printk(KERN_ERR MYNAM
3078 ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
3079 ioc
->name
, ioc
->last_state
);
3083 facts
= &ioc
->facts
;
3085 /* Destination (reply area)... */
3086 reply_sz
= sizeof(*facts
);
3087 memset(facts
, 0, reply_sz
);
3089 /* Request area (get_facts on the stack right now!) */
3090 req_sz
= sizeof(get_facts
);
3091 memset(&get_facts
, 0, req_sz
);
3093 get_facts
.Function
= MPI_FUNCTION_IOC_FACTS
;
3094 /* Assert: All other get_facts fields are zero! */
3096 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
3097 "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
3098 ioc
->name
, req_sz
, reply_sz
));
3100 /* No non-zero fields in the get_facts request are greater than
3101 * 1 byte in size, so we can just fire it off as is.
3103 r
= mpt_handshake_req_reply_wait(ioc
, req_sz
, (u32
*)&get_facts
,
3104 reply_sz
, (u16
*)facts
, 5 /*seconds*/, sleepFlag
);
3109 * Now byte swap (GRRR) the necessary fields before any further
3110 * inspection of reply contents.
3112 * But need to do some sanity checks on MsgLength (byte) field
3113 * to make sure we don't zero IOC's req_sz!
3115 /* Did we get a valid reply? */
3116 if (facts
->MsgLength
> offsetof(IOCFactsReply_t
, RequestFrameSize
)/sizeof(u32
)) {
3117 if (reason
== MPT_HOSTEVENT_IOC_BRINGUP
) {
3119 * If not been here, done that, save off first WhoInit value
3121 if (ioc
->FirstWhoInit
== WHOINIT_UNKNOWN
)
3122 ioc
->FirstWhoInit
= facts
->WhoInit
;
3125 facts
->MsgVersion
= le16_to_cpu(facts
->MsgVersion
);
3126 facts
->MsgContext
= le32_to_cpu(facts
->MsgContext
);
3127 facts
->IOCExceptions
= le16_to_cpu(facts
->IOCExceptions
);
3128 facts
->IOCStatus
= le16_to_cpu(facts
->IOCStatus
);
3129 facts
->IOCLogInfo
= le32_to_cpu(facts
->IOCLogInfo
);
3130 status
= le16_to_cpu(facts
->IOCStatus
) & MPI_IOCSTATUS_MASK
;
3131 /* CHECKME! IOCStatus, IOCLogInfo */
3133 facts
->ReplyQueueDepth
= le16_to_cpu(facts
->ReplyQueueDepth
);
3134 facts
->RequestFrameSize
= le16_to_cpu(facts
->RequestFrameSize
);
3137 * FC f/w version changed between 1.1 and 1.2
3138 * Old: u16{Major(4),Minor(4),SubMinor(8)}
3139 * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
3141 if (facts
->MsgVersion
< MPI_VERSION_01_02
) {
3143 * Handle old FC f/w style, convert to new...
3145 u16 oldv
= le16_to_cpu(facts
->Reserved_0101_FWVersion
);
3146 facts
->FWVersion
.Word
=
3147 ((oldv
<<12) & 0xFF000000) |
3148 ((oldv
<<8) & 0x000FFF00);
3150 facts
->FWVersion
.Word
= le32_to_cpu(facts
->FWVersion
.Word
);
3152 facts
->ProductID
= le16_to_cpu(facts
->ProductID
);
3154 if ((ioc
->facts
.ProductID
& MPI_FW_HEADER_PID_PROD_MASK
)
3155 > MPI_FW_HEADER_PID_PROD_TARGET_SCSI
)
3156 ioc
->ir_firmware
= 1;
3158 facts
->CurrentHostMfaHighAddr
=
3159 le32_to_cpu(facts
->CurrentHostMfaHighAddr
);
3160 facts
->GlobalCredits
= le16_to_cpu(facts
->GlobalCredits
);
3161 facts
->CurrentSenseBufferHighAddr
=
3162 le32_to_cpu(facts
->CurrentSenseBufferHighAddr
);
3163 facts
->CurReplyFrameSize
=
3164 le16_to_cpu(facts
->CurReplyFrameSize
);
3165 facts
->IOCCapabilities
= le32_to_cpu(facts
->IOCCapabilities
);
3168 * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
3169 * Older MPI-1.00.xx struct had 13 dwords, and enlarged
3170 * to 14 in MPI-1.01.0x.
3172 if (facts
->MsgLength
>= (offsetof(IOCFactsReply_t
,FWImageSize
) + 7)/4 &&
3173 facts
->MsgVersion
> MPI_VERSION_01_00
) {
3174 facts
->FWImageSize
= le32_to_cpu(facts
->FWImageSize
);
3177 sz
= facts
->FWImageSize
;
3182 facts
->FWImageSize
= sz
;
3184 if (!facts
->RequestFrameSize
) {
3185 /* Something is wrong! */
3186 printk(MYIOC_s_ERR_FMT
"IOC reported invalid 0 request size!\n",
3191 r
= sz
= facts
->BlockSize
;
3192 vv
= ((63 / (sz
* 4)) + 1) & 0x03;
3193 ioc
->NB_for_64_byte_frame
= vv
;
3199 ioc
->NBShiftFactor
= shiftFactor
;
3200 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
3201 "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
3202 ioc
->name
, vv
, shiftFactor
, r
));
3204 if (reason
== MPT_HOSTEVENT_IOC_BRINGUP
) {
3206 * Set values for this IOC's request & reply frame sizes,
3207 * and request & reply queue depths...
3209 ioc
->req_sz
= min(MPT_DEFAULT_FRAME_SIZE
, facts
->RequestFrameSize
* 4);
3210 ioc
->req_depth
= min_t(int, MPT_MAX_REQ_DEPTH
, facts
->GlobalCredits
);
3211 ioc
->reply_sz
= MPT_REPLY_FRAME_SIZE
;
3212 ioc
->reply_depth
= min_t(int, MPT_DEFAULT_REPLY_DEPTH
, facts
->ReplyQueueDepth
);
3214 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"reply_sz=%3d, reply_depth=%4d\n",
3215 ioc
->name
, ioc
->reply_sz
, ioc
->reply_depth
));
3216 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"req_sz =%3d, req_depth =%4d\n",
3217 ioc
->name
, ioc
->req_sz
, ioc
->req_depth
));
3219 /* Get port facts! */
3220 if ( (r
= GetPortFacts(ioc
, 0, sleepFlag
)) != 0 )
3224 printk(MYIOC_s_ERR_FMT
3225 "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
3226 ioc
->name
, facts
->MsgLength
, (offsetof(IOCFactsReply_t
,
3227 RequestFrameSize
)/sizeof(u32
)));
3234 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3236 * GetPortFacts - Send PortFacts request to MPT adapter.
3237 * @ioc: Pointer to MPT_ADAPTER structure
3238 * @portnum: Port number
3239 * @sleepFlag: Specifies whether the process can sleep
3241 * Returns 0 for success, non-zero for failure.
3244 GetPortFacts(MPT_ADAPTER
*ioc
, int portnum
, int sleepFlag
)
3246 PortFacts_t get_pfacts
;
3247 PortFactsReply_t
*pfacts
;
3253 /* IOC *must* NOT be in RESET state! */
3254 if (ioc
->last_state
== MPI_IOC_STATE_RESET
) {
3255 printk(MYIOC_s_ERR_FMT
"Can't get PortFacts NOT READY! (%08x)\n",
3256 ioc
->name
, ioc
->last_state
);
3260 pfacts
= &ioc
->pfacts
[portnum
];
3262 /* Destination (reply area)... */
3263 reply_sz
= sizeof(*pfacts
);
3264 memset(pfacts
, 0, reply_sz
);
3266 /* Request area (get_pfacts on the stack right now!) */
3267 req_sz
= sizeof(get_pfacts
);
3268 memset(&get_pfacts
, 0, req_sz
);
3270 get_pfacts
.Function
= MPI_FUNCTION_PORT_FACTS
;
3271 get_pfacts
.PortNumber
= portnum
;
3272 /* Assert: All other get_pfacts fields are zero! */
3274 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Sending get PortFacts(%d) request\n",
3275 ioc
->name
, portnum
));
3277 /* No non-zero fields in the get_pfacts request are greater than
3278 * 1 byte in size, so we can just fire it off as is.
3280 ii
= mpt_handshake_req_reply_wait(ioc
, req_sz
, (u32
*)&get_pfacts
,
3281 reply_sz
, (u16
*)pfacts
, 5 /*seconds*/, sleepFlag
);
3285 /* Did we get a valid reply? */
3287 /* Now byte swap the necessary fields in the response. */
3288 pfacts
->MsgContext
= le32_to_cpu(pfacts
->MsgContext
);
3289 pfacts
->IOCStatus
= le16_to_cpu(pfacts
->IOCStatus
);
3290 pfacts
->IOCLogInfo
= le32_to_cpu(pfacts
->IOCLogInfo
);
3291 pfacts
->MaxDevices
= le16_to_cpu(pfacts
->MaxDevices
);
3292 pfacts
->PortSCSIID
= le16_to_cpu(pfacts
->PortSCSIID
);
3293 pfacts
->ProtocolFlags
= le16_to_cpu(pfacts
->ProtocolFlags
);
3294 pfacts
->MaxPostedCmdBuffers
= le16_to_cpu(pfacts
->MaxPostedCmdBuffers
);
3295 pfacts
->MaxPersistentIDs
= le16_to_cpu(pfacts
->MaxPersistentIDs
);
3296 pfacts
->MaxLanBuckets
= le16_to_cpu(pfacts
->MaxLanBuckets
);
3298 max_id
= (ioc
->bus_type
== SAS
) ? pfacts
->PortSCSIID
:
3300 ioc
->devices_per_bus
= (max_id
> 255) ? 256 : max_id
;
3301 ioc
->number_of_buses
= (ioc
->devices_per_bus
< 256) ? 1 : max_id
/256;
3304 * Place all the devices on channels
3308 if (mpt_channel_mapping
) {
3309 ioc
->devices_per_bus
= 1;
3310 ioc
->number_of_buses
= (max_id
> 255) ? 255 : max_id
;
3316 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3318 * SendIocInit - Send IOCInit request to MPT adapter.
3319 * @ioc: Pointer to MPT_ADAPTER structure
3320 * @sleepFlag: Specifies whether the process can sleep
3322 * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
3324 * Returns 0 for success, non-zero for failure.
3327 SendIocInit(MPT_ADAPTER
*ioc
, int sleepFlag
)
3330 MPIDefaultReply_t init_reply
;
3336 memset(&ioc_init
, 0, sizeof(ioc_init
));
3337 memset(&init_reply
, 0, sizeof(init_reply
));
3339 ioc_init
.WhoInit
= MPI_WHOINIT_HOST_DRIVER
;
3340 ioc_init
.Function
= MPI_FUNCTION_IOC_INIT
;
3342 /* If we are in a recovery mode and we uploaded the FW image,
3343 * then this pointer is not NULL. Skip the upload a second time.
3344 * Set this flag if cached_fw set for either IOC.
3346 if (ioc
->facts
.Flags
& MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT
)
3350 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"upload_fw %d facts.Flags=%x\n",
3351 ioc
->name
, ioc
->upload_fw
, ioc
->facts
.Flags
));
3353 ioc_init
.MaxDevices
= (U8
)ioc
->devices_per_bus
;
3354 ioc_init
.MaxBuses
= (U8
)ioc
->number_of_buses
;
3356 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"facts.MsgVersion=%x\n",
3357 ioc
->name
, ioc
->facts
.MsgVersion
));
3358 if (ioc
->facts
.MsgVersion
>= MPI_VERSION_01_05
) {
3359 // set MsgVersion and HeaderVersion host driver was built with
3360 ioc_init
.MsgVersion
= cpu_to_le16(MPI_VERSION
);
3361 ioc_init
.HeaderVersion
= cpu_to_le16(MPI_HEADER_VERSION
);
3363 if (ioc
->facts
.Flags
& MPI_IOCFACTS_FLAGS_HOST_PAGE_BUFFER_PERSISTENT
) {
3364 ioc_init
.HostPageBufferSGE
= ioc
->facts
.HostPageBufferSGE
;
3365 } else if(mpt_host_page_alloc(ioc
, &ioc_init
))
3368 ioc_init
.ReplyFrameSize
= cpu_to_le16(ioc
->reply_sz
); /* in BYTES */
3370 if (ioc
->sg_addr_size
== sizeof(u64
)) {
3371 /* Save the upper 32-bits of the request
3372 * (reply) and sense buffers.
3374 ioc_init
.HostMfaHighAddr
= cpu_to_le32((u32
)((u64
)ioc
->alloc_dma
>> 32));
3375 ioc_init
.SenseBufferHighAddr
= cpu_to_le32((u32
)((u64
)ioc
->sense_buf_pool_dma
>> 32));
3377 /* Force 32-bit addressing */
3378 ioc_init
.HostMfaHighAddr
= cpu_to_le32(0);
3379 ioc_init
.SenseBufferHighAddr
= cpu_to_le32(0);
3382 ioc
->facts
.CurrentHostMfaHighAddr
= ioc_init
.HostMfaHighAddr
;
3383 ioc
->facts
.CurrentSenseBufferHighAddr
= ioc_init
.SenseBufferHighAddr
;
3384 ioc
->facts
.MaxDevices
= ioc_init
.MaxDevices
;
3385 ioc
->facts
.MaxBuses
= ioc_init
.MaxBuses
;
3387 dhsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Sending IOCInit (req @ %p)\n",
3388 ioc
->name
, &ioc_init
));
3390 r
= mpt_handshake_req_reply_wait(ioc
, sizeof(IOCInit_t
), (u32
*)&ioc_init
,
3391 sizeof(MPIDefaultReply_t
), (u16
*)&init_reply
, 10 /*seconds*/, sleepFlag
);
3393 printk(MYIOC_s_ERR_FMT
"Sending IOCInit failed(%d)!\n",ioc
->name
, r
);
3397 /* No need to byte swap the multibyte fields in the reply
3398 * since we don't even look at its contents.
3401 dhsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Sending PortEnable (req @ %p)\n",
3402 ioc
->name
, &ioc_init
));
3404 if ((r
= SendPortEnable(ioc
, 0, sleepFlag
)) != 0) {
3405 printk(MYIOC_s_ERR_FMT
"Sending PortEnable failed(%d)!\n",ioc
->name
, r
);
3409 /* YIKES! SUPER IMPORTANT!!!
3410 * Poll IocState until _OPERATIONAL while IOC is doing
3411 * LoopInit and TargetDiscovery!
3414 cntdn
= ((sleepFlag
== CAN_SLEEP
) ? HZ
: 1000) * 60; /* 60 seconds */
3415 state
= mpt_GetIocState(ioc
, 1);
3416 while (state
!= MPI_IOC_STATE_OPERATIONAL
&& --cntdn
) {
3417 if (sleepFlag
== CAN_SLEEP
) {
3424 printk(MYIOC_s_ERR_FMT
"Wait IOC_OP state timeout(%d)!\n",
3425 ioc
->name
, (int)((count
+5)/HZ
));
3429 state
= mpt_GetIocState(ioc
, 1);
3432 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Wait IOC_OPERATIONAL state (cnt=%d)\n",
3435 ioc
->aen_event_read_flag
=0;
3439 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3441 * SendPortEnable - Send PortEnable request to MPT adapter port.
3442 * @ioc: Pointer to MPT_ADAPTER structure
3443 * @portnum: Port number to enable
3444 * @sleepFlag: Specifies whether the process can sleep
3446 * Send PortEnable to bring IOC to OPERATIONAL state.
3448 * Returns 0 for success, non-zero for failure.
3451 SendPortEnable(MPT_ADAPTER
*ioc
, int portnum
, int sleepFlag
)
3453 PortEnable_t port_enable
;
3454 MPIDefaultReply_t reply_buf
;
3459 /* Destination... */
3460 reply_sz
= sizeof(MPIDefaultReply_t
);
3461 memset(&reply_buf
, 0, reply_sz
);
3463 req_sz
= sizeof(PortEnable_t
);
3464 memset(&port_enable
, 0, req_sz
);
3466 port_enable
.Function
= MPI_FUNCTION_PORT_ENABLE
;
3467 port_enable
.PortNumber
= portnum
;
3468 /* port_enable.ChainOffset = 0; */
3469 /* port_enable.MsgFlags = 0; */
3470 /* port_enable.MsgContext = 0; */
3472 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Sending Port(%d)Enable (req @ %p)\n",
3473 ioc
->name
, portnum
, &port_enable
));
3475 /* RAID FW may take a long time to enable
3477 if (ioc
->ir_firmware
|| ioc
->bus_type
== SAS
) {
3478 rc
= mpt_handshake_req_reply_wait(ioc
, req_sz
,
3479 (u32
*)&port_enable
, reply_sz
, (u16
*)&reply_buf
,
3480 300 /*seconds*/, sleepFlag
);
3482 rc
= mpt_handshake_req_reply_wait(ioc
, req_sz
,
3483 (u32
*)&port_enable
, reply_sz
, (u16
*)&reply_buf
,
3484 30 /*seconds*/, sleepFlag
);
3490 * mpt_alloc_fw_memory - allocate firmware memory
3491 * @ioc: Pointer to MPT_ADAPTER structure
3492 * @size: total FW bytes
3494 * If memory has already been allocated, the same (cached) value
3497 * Return 0 if successful, or non-zero for failure
3500 mpt_alloc_fw_memory(MPT_ADAPTER
*ioc
, int size
)
3504 if (ioc
->cached_fw
) {
3505 rc
= 0; /* use already allocated memory */
3508 else if (ioc
->alt_ioc
&& ioc
->alt_ioc
->cached_fw
) {
3509 ioc
->cached_fw
= ioc
->alt_ioc
->cached_fw
; /* use alt_ioc's memory */
3510 ioc
->cached_fw_dma
= ioc
->alt_ioc
->cached_fw_dma
;
3514 ioc
->cached_fw
= pci_alloc_consistent(ioc
->pcidev
, size
, &ioc
->cached_fw_dma
);
3515 if (!ioc
->cached_fw
) {
3516 printk(MYIOC_s_ERR_FMT
"Unable to allocate memory for the cached firmware image!\n",
3520 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"FW Image @ %p[%p], sz=%d[%x] bytes\n",
3521 ioc
->name
, ioc
->cached_fw
, (void *)(ulong
)ioc
->cached_fw_dma
, size
, size
));
3522 ioc
->alloc_total
+= size
;
3530 * mpt_free_fw_memory - free firmware memory
3531 * @ioc: Pointer to MPT_ADAPTER structure
3533 * If alt_img is NULL, delete from ioc structure.
3534 * Else, delete a secondary image in same format.
3537 mpt_free_fw_memory(MPT_ADAPTER
*ioc
)
3541 if (!ioc
->cached_fw
)
3544 sz
= ioc
->facts
.FWImageSize
;
3545 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
3546 ioc
->name
, ioc
->cached_fw
, (void *)(ulong
)ioc
->cached_fw_dma
, sz
, sz
));
3547 pci_free_consistent(ioc
->pcidev
, sz
, ioc
->cached_fw
, ioc
->cached_fw_dma
);
3548 ioc
->alloc_total
-= sz
;
3549 ioc
->cached_fw
= NULL
;
3552 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3554 * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
3555 * @ioc: Pointer to MPT_ADAPTER structure
3556 * @sleepFlag: Specifies whether the process can sleep
3558 * Returns 0 for success, >0 for handshake failure
3559 * <0 for fw upload failure.
3561 * Remark: If bound IOC and a successful FWUpload was performed
3562 * on the bound IOC, the second image is discarded
3563 * and memory is free'd. Both channels must upload to prevent
3564 * IOC from running in degraded mode.
3567 mpt_do_upload(MPT_ADAPTER
*ioc
, int sleepFlag
)
3569 u8 reply
[sizeof(FWUploadReply_t
)];
3570 FWUpload_t
*prequest
;
3571 FWUploadReply_t
*preply
;
3572 FWUploadTCSGE_t
*ptcsge
;
3574 int ii
, sz
, reply_sz
;
3577 /* If the image size is 0, we are done.
3579 if ((sz
= ioc
->facts
.FWImageSize
) == 0)
3582 if (mpt_alloc_fw_memory(ioc
, ioc
->facts
.FWImageSize
) != 0)
3585 dinitprintk(ioc
, printk(MYIOC_s_INFO_FMT
": FW Image @ %p[%p], sz=%d[%x] bytes\n",
3586 ioc
->name
, ioc
->cached_fw
, (void *)(ulong
)ioc
->cached_fw_dma
, sz
, sz
));
3588 prequest
= (sleepFlag
== NO_SLEEP
) ? kzalloc(ioc
->req_sz
, GFP_ATOMIC
) :
3589 kzalloc(ioc
->req_sz
, GFP_KERNEL
);
3591 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"fw upload failed "
3592 "while allocating memory \n", ioc
->name
));
3593 mpt_free_fw_memory(ioc
);
3597 preply
= (FWUploadReply_t
*)&reply
;
3599 reply_sz
= sizeof(reply
);
3600 memset(preply
, 0, reply_sz
);
3602 prequest
->ImageType
= MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM
;
3603 prequest
->Function
= MPI_FUNCTION_FW_UPLOAD
;
3605 ptcsge
= (FWUploadTCSGE_t
*) &prequest
->SGL
;
3606 ptcsge
->DetailsLength
= 12;
3607 ptcsge
->Flags
= MPI_SGE_FLAGS_TRANSACTION_ELEMENT
;
3608 ptcsge
->ImageSize
= cpu_to_le32(sz
);
3611 flagsLength
= MPT_SGE_FLAGS_SSIMPLE_READ
| sz
;
3612 ioc
->add_sge((char *)ptcsge
, flagsLength
, ioc
->cached_fw_dma
);
3613 request_size
= offsetof(FWUpload_t
, SGL
) + sizeof(FWUploadTCSGE_t
) +
3615 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Sending FW Upload "
3616 " (req @ %p) fw_size=%d mf_request_size=%d\n", ioc
->name
, prequest
,
3617 ioc
->facts
.FWImageSize
, request_size
));
3618 DBG_DUMP_FW_REQUEST_FRAME(ioc
, (u32
*)prequest
);
3620 ii
= mpt_handshake_req_reply_wait(ioc
, request_size
, (u32
*)prequest
,
3621 reply_sz
, (u16
*)preply
, 65 /*seconds*/, sleepFlag
);
3623 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"FW Upload completed "
3624 "rc=%x \n", ioc
->name
, ii
));
3626 cmdStatus
= -EFAULT
;
3628 /* Handshake transfer was complete and successful.
3629 * Check the Reply Frame.
3632 status
= le16_to_cpu(preply
->IOCStatus
) &
3634 if (status
== MPI_IOCSTATUS_SUCCESS
&&
3635 ioc
->facts
.FWImageSize
==
3636 le32_to_cpu(preply
->ActualImageSize
))
3639 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
": do_upload cmdStatus=%d \n",
3640 ioc
->name
, cmdStatus
));
3644 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"fw upload failed, "
3645 "freeing image \n", ioc
->name
));
3646 mpt_free_fw_memory(ioc
);
3653 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3655 * mpt_downloadboot - DownloadBoot code
3656 * @ioc: Pointer to MPT_ADAPTER structure
3657 * @pFwHeader: Pointer to firmware header info
3658 * @sleepFlag: Specifies whether the process can sleep
3660 * FwDownloadBoot requires Programmed IO access.
3662 * Returns 0 for success
3663 * -1 FW Image size is 0
3664 * -2 No valid cached_fw Pointer
3665 * <0 for fw upload failure.
3668 mpt_downloadboot(MPT_ADAPTER
*ioc
, MpiFwHeader_t
*pFwHeader
, int sleepFlag
)
3670 MpiExtImageHeader_t
*pExtImage
;
3680 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"downloadboot: fw size 0x%x (%d), FW Ptr %p\n",
3681 ioc
->name
, pFwHeader
->ImageSize
, pFwHeader
->ImageSize
, pFwHeader
));
3683 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, 0xFF);
3684 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_1ST_KEY_VALUE
);
3685 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_2ND_KEY_VALUE
);
3686 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_3RD_KEY_VALUE
);
3687 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_4TH_KEY_VALUE
);
3688 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_5TH_KEY_VALUE
);
3690 CHIPREG_WRITE32(&ioc
->chip
->Diagnostic
, (MPI_DIAG_PREVENT_IOC_BOOT
| MPI_DIAG_DISABLE_ARM
));
3693 if (sleepFlag
== CAN_SLEEP
) {
3699 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
3700 CHIPREG_WRITE32(&ioc
->chip
->Diagnostic
, diag0val
| MPI_DIAG_RESET_ADAPTER
);
3702 for (count
= 0; count
< 30; count
++) {
3703 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
3704 if (!(diag0val
& MPI_DIAG_RESET_ADAPTER
)) {
3705 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"RESET_ADAPTER cleared, count=%d\n",
3710 if (sleepFlag
== CAN_SLEEP
) {
3717 if ( count
== 30 ) {
3718 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"downloadboot failed! "
3719 "Unable to get MPI_DIAG_DRWE mode, diag0val=%x\n",
3720 ioc
->name
, diag0val
));
3724 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, 0xFF);
3725 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_1ST_KEY_VALUE
);
3726 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_2ND_KEY_VALUE
);
3727 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_3RD_KEY_VALUE
);
3728 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_4TH_KEY_VALUE
);
3729 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_5TH_KEY_VALUE
);
3731 /* Set the DiagRwEn and Disable ARM bits */
3732 CHIPREG_WRITE32(&ioc
->chip
->Diagnostic
, (MPI_DIAG_RW_ENABLE
| MPI_DIAG_DISABLE_ARM
));
3734 fwSize
= (pFwHeader
->ImageSize
+ 3)/4;
3735 ptrFw
= (u32
*) pFwHeader
;
3737 /* Write the LoadStartAddress to the DiagRw Address Register
3738 * using Programmed IO
3740 if (ioc
->errata_flag_1064
)
3741 pci_enable_io_access(ioc
->pcidev
);
3743 CHIPREG_PIO_WRITE32(&ioc
->pio_chip
->DiagRwAddress
, pFwHeader
->LoadStartAddress
);
3744 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"LoadStart addr written 0x%x \n",
3745 ioc
->name
, pFwHeader
->LoadStartAddress
));
3747 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Write FW Image: 0x%x bytes @ %p\n",
3748 ioc
->name
, fwSize
*4, ptrFw
));
3750 CHIPREG_PIO_WRITE32(&ioc
->pio_chip
->DiagRwData
, *ptrFw
++);
3753 nextImage
= pFwHeader
->NextImageHeaderOffset
;
3755 pExtImage
= (MpiExtImageHeader_t
*) ((char *)pFwHeader
+ nextImage
);
3757 load_addr
= pExtImage
->LoadStartAddress
;
3759 fwSize
= (pExtImage
->ImageSize
+ 3) >> 2;
3760 ptrFw
= (u32
*)pExtImage
;
3762 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Write Ext Image: 0x%x (%d) bytes @ %p load_addr=%x\n",
3763 ioc
->name
, fwSize
*4, fwSize
*4, ptrFw
, load_addr
));
3764 CHIPREG_PIO_WRITE32(&ioc
->pio_chip
->DiagRwAddress
, load_addr
);
3767 CHIPREG_PIO_WRITE32(&ioc
->pio_chip
->DiagRwData
, *ptrFw
++);
3769 nextImage
= pExtImage
->NextImageHeaderOffset
;
3772 /* Write the IopResetVectorRegAddr */
3773 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Write IopResetVector Addr=%x! \n", ioc
->name
, pFwHeader
->IopResetRegAddr
));
3774 CHIPREG_PIO_WRITE32(&ioc
->pio_chip
->DiagRwAddress
, pFwHeader
->IopResetRegAddr
);
3776 /* Write the IopResetVectorValue */
3777 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Write IopResetVector Value=%x! \n", ioc
->name
, pFwHeader
->IopResetVectorValue
));
3778 CHIPREG_PIO_WRITE32(&ioc
->pio_chip
->DiagRwData
, pFwHeader
->IopResetVectorValue
);
3780 /* Clear the internal flash bad bit - autoincrementing register,
3781 * so must do two writes.
3783 if (ioc
->bus_type
== SPI
) {
3785 * 1030 and 1035 H/W errata, workaround to access
3786 * the ClearFlashBadSignatureBit
3788 CHIPREG_PIO_WRITE32(&ioc
->pio_chip
->DiagRwAddress
, 0x3F000000);
3789 diagRwData
= CHIPREG_PIO_READ32(&ioc
->pio_chip
->DiagRwData
);
3790 diagRwData
|= 0x40000000;
3791 CHIPREG_PIO_WRITE32(&ioc
->pio_chip
->DiagRwAddress
, 0x3F000000);
3792 CHIPREG_PIO_WRITE32(&ioc
->pio_chip
->DiagRwData
, diagRwData
);
3794 } else /* if((ioc->bus_type == SAS) || (ioc->bus_type == FC)) */ {
3795 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
3796 CHIPREG_WRITE32(&ioc
->chip
->Diagnostic
, diag0val
|
3797 MPI_DIAG_CLEAR_FLASH_BAD_SIG
);
3800 if (sleepFlag
== CAN_SLEEP
) {
3807 if (ioc
->errata_flag_1064
)
3808 pci_disable_io_access(ioc
->pcidev
);
3810 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
3811 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"downloadboot diag0val=%x, "
3812 "turning off PREVENT_IOC_BOOT, DISABLE_ARM, RW_ENABLE\n",
3813 ioc
->name
, diag0val
));
3814 diag0val
&= ~(MPI_DIAG_PREVENT_IOC_BOOT
| MPI_DIAG_DISABLE_ARM
| MPI_DIAG_RW_ENABLE
);
3815 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"downloadboot now diag0val=%x\n",
3816 ioc
->name
, diag0val
));
3817 CHIPREG_WRITE32(&ioc
->chip
->Diagnostic
, diag0val
);
3819 /* Write 0xFF to reset the sequencer */
3820 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, 0xFF);
3822 if (ioc
->bus_type
== SAS
) {
3823 ioc_state
= mpt_GetIocState(ioc
, 0);
3824 if ( (GetIocFacts(ioc
, sleepFlag
,
3825 MPT_HOSTEVENT_IOC_BRINGUP
)) != 0 ) {
3826 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"GetIocFacts failed: IocState=%x\n",
3827 ioc
->name
, ioc_state
));
3832 for (count
=0; count
<HZ
*20; count
++) {
3833 if ((ioc_state
= mpt_GetIocState(ioc
, 0)) & MPI_IOC_STATE_READY
) {
3834 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
3835 "downloadboot successful! (count=%d) IocState=%x\n",
3836 ioc
->name
, count
, ioc_state
));
3837 if (ioc
->bus_type
== SAS
) {
3840 if ((SendIocInit(ioc
, sleepFlag
)) != 0) {
3841 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
3842 "downloadboot: SendIocInit failed\n",
3846 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
3847 "downloadboot: SendIocInit successful\n",
3851 if (sleepFlag
== CAN_SLEEP
) {
3857 ddlprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
3858 "downloadboot failed! IocState=%x\n",ioc
->name
, ioc_state
));
3862 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3864 * KickStart - Perform hard reset of MPT adapter.
3865 * @ioc: Pointer to MPT_ADAPTER structure
3866 * @force: Force hard reset
3867 * @sleepFlag: Specifies whether the process can sleep
3869 * This routine places MPT adapter in diagnostic mode via the
3870 * WriteSequence register, and then performs a hard reset of adapter
3871 * via the Diagnostic register.
3873 * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
3874 * or NO_SLEEP (interrupt thread, use mdelay)
3875 * force - 1 if doorbell active, board fault state
3876 * board operational, IOC_RECOVERY or
3877 * IOC_BRINGUP and there is an alt_ioc.
3881 * 1 - hard reset, READY
3882 * 0 - no reset due to History bit, READY
3883 * -1 - no reset due to History bit but not READY
3884 * OR reset but failed to come READY
3885 * -2 - no reset, could not enter DIAG mode
3886 * -3 - reset but bad FW bit
3889 KickStart(MPT_ADAPTER
*ioc
, int force
, int sleepFlag
)
3891 int hard_reset_done
= 0;
3895 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"KickStarting!\n", ioc
->name
));
3896 if (ioc
->bus_type
== SPI
) {
3897 /* Always issue a Msg Unit Reset first. This will clear some
3898 * SCSI bus hang conditions.
3900 SendIocReset(ioc
, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
, sleepFlag
);
3902 if (sleepFlag
== CAN_SLEEP
) {
3909 hard_reset_done
= mpt_diag_reset(ioc
, force
, sleepFlag
);
3910 if (hard_reset_done
< 0)
3911 return hard_reset_done
;
3913 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Diagnostic reset successful!\n",
3916 cntdn
= ((sleepFlag
== CAN_SLEEP
) ? HZ
: 1000) * 2; /* 2 seconds */
3917 for (cnt
=0; cnt
<cntdn
; cnt
++) {
3918 ioc_state
= mpt_GetIocState(ioc
, 1);
3919 if ((ioc_state
== MPI_IOC_STATE_READY
) || (ioc_state
== MPI_IOC_STATE_OPERATIONAL
)) {
3920 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"KickStart successful! (cnt=%d)\n",
3922 return hard_reset_done
;
3924 if (sleepFlag
== CAN_SLEEP
) {
3931 dinitprintk(ioc
, printk(MYIOC_s_ERR_FMT
"Failed to come READY after reset! IocState=%x\n",
3932 ioc
->name
, mpt_GetIocState(ioc
, 0)));
3936 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
3938 * mpt_diag_reset - Perform hard reset of the adapter.
3939 * @ioc: Pointer to MPT_ADAPTER structure
3940 * @ignore: Set if to honor and clear to ignore
3941 * the reset history bit
3942 * @sleepFlag: CAN_SLEEP if called in a non-interrupt thread,
3943 * else set to NO_SLEEP (use mdelay instead)
3945 * This routine places the adapter in diagnostic mode via the
3946 * WriteSequence register and then performs a hard reset of adapter
3947 * via the Diagnostic register. Adapter should be in ready state
3948 * upon successful completion.
3950 * Returns: 1 hard reset successful
3951 * 0 no reset performed because reset history bit set
3952 * -2 enabling diagnostic mode failed
3953 * -3 diagnostic reset failed
3956 mpt_diag_reset(MPT_ADAPTER
*ioc
, int ignore
, int sleepFlag
)
3960 int hard_reset_done
= 0;
3963 MpiFwHeader_t
*cached_fw
; /* Pointer to FW */
3966 /* Clear any existing interrupts */
3967 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
3969 if (ioc
->pcidev
->device
== MPI_MANUFACTPAGE_DEVID_SAS1078
) {
3974 drsprintk(ioc
, printk(MYIOC_s_WARN_FMT
"%s: Doorbell=%p; 1078 reset "
3975 "address=%p\n", ioc
->name
, __func__
,
3976 &ioc
->chip
->Doorbell
, &ioc
->chip
->Reset_1078
));
3977 CHIPREG_WRITE32(&ioc
->chip
->Reset_1078
, 0x07);
3978 if (sleepFlag
== CAN_SLEEP
)
3984 * Call each currently registered protocol IOC reset handler
3985 * with pre-reset indication.
3986 * NOTE: If we're doing _IOC_BRINGUP, there can be no
3987 * MptResetHandlers[] registered yet.
3989 for (cb_idx
= MPT_MAX_PROTOCOL_DRIVERS
-1; cb_idx
; cb_idx
--) {
3990 if (MptResetHandlers
[cb_idx
])
3991 (*(MptResetHandlers
[cb_idx
]))(ioc
,
3995 for (count
= 0; count
< 60; count
++) {
3996 doorbell
= CHIPREG_READ32(&ioc
->chip
->Doorbell
);
3997 doorbell
&= MPI_IOC_STATE_MASK
;
3999 drsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
4000 "looking for READY STATE: doorbell=%x"
4002 ioc
->name
, doorbell
, count
));
4004 if (doorbell
== MPI_IOC_STATE_READY
) {
4009 if (sleepFlag
== CAN_SLEEP
)
4017 /* Use "Diagnostic reset" method! (only thing available!) */
4018 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
4020 if (ioc
->debug_level
& MPT_DEBUG
) {
4022 diag1val
= CHIPREG_READ32(&ioc
->alt_ioc
->chip
->Diagnostic
);
4023 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"DbG1: diag0=%08x, diag1=%08x\n",
4024 ioc
->name
, diag0val
, diag1val
));
4027 /* Do the reset if we are told to ignore the reset history
4028 * or if the reset history is 0
4030 if (ignore
|| !(diag0val
& MPI_DIAG_RESET_HISTORY
)) {
4031 while ((diag0val
& MPI_DIAG_DRWE
) == 0) {
4032 /* Write magic sequence to WriteSequence register
4033 * Loop until in diagnostic mode
4035 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, 0xFF);
4036 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_1ST_KEY_VALUE
);
4037 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_2ND_KEY_VALUE
);
4038 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_3RD_KEY_VALUE
);
4039 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_4TH_KEY_VALUE
);
4040 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_5TH_KEY_VALUE
);
4043 if (sleepFlag
== CAN_SLEEP
) {
4051 printk(MYIOC_s_ERR_FMT
"Enable Diagnostic mode FAILED! (%02xh)\n",
4052 ioc
->name
, diag0val
);
4057 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
4059 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Wrote magic DiagWriteEn sequence (%x)\n",
4060 ioc
->name
, diag0val
));
4063 if (ioc
->debug_level
& MPT_DEBUG
) {
4065 diag1val
= CHIPREG_READ32(&ioc
->alt_ioc
->chip
->Diagnostic
);
4066 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"DbG2: diag0=%08x, diag1=%08x\n",
4067 ioc
->name
, diag0val
, diag1val
));
4070 * Disable the ARM (Bug fix)
4073 CHIPREG_WRITE32(&ioc
->chip
->Diagnostic
, diag0val
| MPI_DIAG_DISABLE_ARM
);
4077 * Now hit the reset bit in the Diagnostic register
4078 * (THE BIG HAMMER!) (Clears DRWE bit).
4080 CHIPREG_WRITE32(&ioc
->chip
->Diagnostic
, diag0val
| MPI_DIAG_RESET_ADAPTER
);
4081 hard_reset_done
= 1;
4082 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Diagnostic reset performed\n",
4086 * Call each currently registered protocol IOC reset handler
4087 * with pre-reset indication.
4088 * NOTE: If we're doing _IOC_BRINGUP, there can be no
4089 * MptResetHandlers[] registered yet.
4091 for (cb_idx
= MPT_MAX_PROTOCOL_DRIVERS
-1; cb_idx
; cb_idx
--) {
4092 if (MptResetHandlers
[cb_idx
]) {
4093 mpt_signal_reset(cb_idx
,
4094 ioc
, MPT_IOC_PRE_RESET
);
4096 mpt_signal_reset(cb_idx
,
4097 ioc
->alt_ioc
, MPT_IOC_PRE_RESET
);
4103 cached_fw
= (MpiFwHeader_t
*)ioc
->cached_fw
;
4104 else if (ioc
->alt_ioc
&& ioc
->alt_ioc
->cached_fw
)
4105 cached_fw
= (MpiFwHeader_t
*)ioc
->alt_ioc
->cached_fw
;
4109 /* If the DownloadBoot operation fails, the
4110 * IOC will be left unusable. This is a fatal error
4111 * case. _diag_reset will return < 0
4113 for (count
= 0; count
< 30; count
++) {
4114 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
4115 if (!(diag0val
& MPI_DIAG_RESET_ADAPTER
)) {
4119 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"cached_fw: diag0val=%x count=%d\n",
4120 ioc
->name
, diag0val
, count
));
4122 if (sleepFlag
== CAN_SLEEP
) {
4128 if ((count
= mpt_downloadboot(ioc
, cached_fw
, sleepFlag
)) < 0) {
4129 printk(MYIOC_s_WARN_FMT
4130 "firmware downloadboot failure (%d)!\n", ioc
->name
, count
);
4134 /* Wait for FW to reload and for board
4135 * to go to the READY state.
4136 * Maximum wait is 60 seconds.
4137 * If fail, no error will check again
4138 * with calling program.
4140 for (count
= 0; count
< 60; count
++) {
4141 doorbell
= CHIPREG_READ32(&ioc
->chip
->Doorbell
);
4142 doorbell
&= MPI_IOC_STATE_MASK
;
4144 drsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
4145 "looking for READY STATE: doorbell=%x"
4146 " count=%d\n", ioc
->name
, doorbell
, count
));
4148 if (doorbell
== MPI_IOC_STATE_READY
) {
4153 if (sleepFlag
== CAN_SLEEP
) {
4160 if (doorbell
!= MPI_IOC_STATE_READY
)
4161 printk(MYIOC_s_ERR_FMT
"Failed to come READY "
4162 "after reset! IocState=%x", ioc
->name
,
4167 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
4168 if (ioc
->debug_level
& MPT_DEBUG
) {
4170 diag1val
= CHIPREG_READ32(&ioc
->alt_ioc
->chip
->Diagnostic
);
4171 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"DbG3: diag0=%08x, diag1=%08x\n",
4172 ioc
->name
, diag0val
, diag1val
));
4175 /* Clear RESET_HISTORY bit! Place board in the
4176 * diagnostic mode to update the diag register.
4178 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
4180 while ((diag0val
& MPI_DIAG_DRWE
) == 0) {
4181 /* Write magic sequence to WriteSequence register
4182 * Loop until in diagnostic mode
4184 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, 0xFF);
4185 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_1ST_KEY_VALUE
);
4186 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_2ND_KEY_VALUE
);
4187 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_3RD_KEY_VALUE
);
4188 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_4TH_KEY_VALUE
);
4189 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, MPI_WRSEQ_5TH_KEY_VALUE
);
4192 if (sleepFlag
== CAN_SLEEP
) {
4200 printk(MYIOC_s_ERR_FMT
"Enable Diagnostic mode FAILED! (%02xh)\n",
4201 ioc
->name
, diag0val
);
4204 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
4206 diag0val
&= ~MPI_DIAG_RESET_HISTORY
;
4207 CHIPREG_WRITE32(&ioc
->chip
->Diagnostic
, diag0val
);
4208 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
4209 if (diag0val
& MPI_DIAG_RESET_HISTORY
) {
4210 printk(MYIOC_s_WARN_FMT
"ResetHistory bit failed to clear!\n",
4214 /* Disable Diagnostic Mode
4216 CHIPREG_WRITE32(&ioc
->chip
->WriteSequence
, 0xFFFFFFFF);
4218 /* Check FW reload status flags.
4220 diag0val
= CHIPREG_READ32(&ioc
->chip
->Diagnostic
);
4221 if (diag0val
& (MPI_DIAG_FLASH_BAD_SIG
| MPI_DIAG_RESET_ADAPTER
| MPI_DIAG_DISABLE_ARM
)) {
4222 printk(MYIOC_s_ERR_FMT
"Diagnostic reset FAILED! (%02xh)\n",
4223 ioc
->name
, diag0val
);
4227 if (ioc
->debug_level
& MPT_DEBUG
) {
4229 diag1val
= CHIPREG_READ32(&ioc
->alt_ioc
->chip
->Diagnostic
);
4230 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"DbG4: diag0=%08x, diag1=%08x\n",
4231 ioc
->name
, diag0val
, diag1val
));
4235 * Reset flag that says we've enabled event notification
4237 ioc
->facts
.EventState
= 0;
4240 ioc
->alt_ioc
->facts
.EventState
= 0;
4242 return hard_reset_done
;
4245 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4247 * SendIocReset - Send IOCReset request to MPT adapter.
4248 * @ioc: Pointer to MPT_ADAPTER structure
4249 * @reset_type: reset type, expected values are
4250 * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
4251 * @sleepFlag: Specifies whether the process can sleep
4253 * Send IOCReset request to the MPT adapter.
4255 * Returns 0 for success, non-zero for failure.
4258 SendIocReset(MPT_ADAPTER
*ioc
, u8 reset_type
, int sleepFlag
)
4264 drsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Sending IOC reset(0x%02x)!\n",
4265 ioc
->name
, reset_type
));
4266 CHIPREG_WRITE32(&ioc
->chip
->Doorbell
, reset_type
<<MPI_DOORBELL_FUNCTION_SHIFT
);
4267 if ((r
= WaitForDoorbellAck(ioc
, 5, sleepFlag
)) < 0)
4270 /* FW ACK'd request, wait for READY state
4273 cntdn
= ((sleepFlag
== CAN_SLEEP
) ? HZ
: 1000) * 15; /* 15 seconds */
4275 while ((state
= mpt_GetIocState(ioc
, 1)) != MPI_IOC_STATE_READY
) {
4279 if (sleepFlag
!= CAN_SLEEP
)
4282 printk(MYIOC_s_ERR_FMT
4283 "Wait IOC_READY state (0x%x) timeout(%d)!\n",
4284 ioc
->name
, state
, (int)((count
+5)/HZ
));
4288 if (sleepFlag
== CAN_SLEEP
) {
4291 mdelay (1); /* 1 msec delay */
4296 * Cleanup all event stuff for this IOC; re-issue EventNotification
4297 * request if needed.
4299 if (ioc
->facts
.Function
)
4300 ioc
->facts
.EventState
= 0;
4305 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4307 * initChainBuffers - Allocate memory for and initialize chain buffers
4308 * @ioc: Pointer to MPT_ADAPTER structure
4310 * Allocates memory for and initializes chain buffers,
4311 * chain buffer control arrays and spinlock.
4314 initChainBuffers(MPT_ADAPTER
*ioc
)
4317 int sz
, ii
, num_chain
;
4318 int scale
, num_sge
, numSGE
;
4320 /* ReqToChain size must equal the req_depth
4323 if (ioc
->ReqToChain
== NULL
) {
4324 sz
= ioc
->req_depth
* sizeof(int);
4325 mem
= kmalloc(sz
, GFP_ATOMIC
);
4329 ioc
->ReqToChain
= (int *) mem
;
4330 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"ReqToChain alloc @ %p, sz=%d bytes\n",
4331 ioc
->name
, mem
, sz
));
4332 mem
= kmalloc(sz
, GFP_ATOMIC
);
4336 ioc
->RequestNB
= (int *) mem
;
4337 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"RequestNB alloc @ %p, sz=%d bytes\n",
4338 ioc
->name
, mem
, sz
));
4340 for (ii
= 0; ii
< ioc
->req_depth
; ii
++) {
4341 ioc
->ReqToChain
[ii
] = MPT_HOST_NO_CHAIN
;
4344 /* ChainToChain size must equal the total number
4345 * of chain buffers to be allocated.
4348 * Calculate the number of chain buffers needed(plus 1) per I/O
4349 * then multiply the maximum number of simultaneous cmds
4351 * num_sge = num sge in request frame + last chain buffer
4352 * scale = num sge per chain buffer if no chain element
4354 scale
= ioc
->req_sz
/ ioc
->SGE_size
;
4355 if (ioc
->sg_addr_size
== sizeof(u64
))
4356 num_sge
= scale
+ (ioc
->req_sz
- 60) / ioc
->SGE_size
;
4358 num_sge
= 1 + scale
+ (ioc
->req_sz
- 64) / ioc
->SGE_size
;
4360 if (ioc
->sg_addr_size
== sizeof(u64
)) {
4361 numSGE
= (scale
- 1) * (ioc
->facts
.MaxChainDepth
-1) + scale
+
4362 (ioc
->req_sz
- 60) / ioc
->SGE_size
;
4364 numSGE
= 1 + (scale
- 1) * (ioc
->facts
.MaxChainDepth
-1) +
4365 scale
+ (ioc
->req_sz
- 64) / ioc
->SGE_size
;
4367 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"num_sge=%d numSGE=%d\n",
4368 ioc
->name
, num_sge
, numSGE
));
4370 if (ioc
->bus_type
== FC
) {
4371 if (numSGE
> MPT_SCSI_FC_SG_DEPTH
)
4372 numSGE
= MPT_SCSI_FC_SG_DEPTH
;
4374 if (numSGE
> MPT_SCSI_SG_DEPTH
)
4375 numSGE
= MPT_SCSI_SG_DEPTH
;
4379 while (numSGE
- num_sge
> 0) {
4381 num_sge
+= (scale
- 1);
4385 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Now numSGE=%d num_sge=%d num_chain=%d\n",
4386 ioc
->name
, numSGE
, num_sge
, num_chain
));
4388 if (ioc
->bus_type
== SPI
)
4389 num_chain
*= MPT_SCSI_CAN_QUEUE
;
4390 else if (ioc
->bus_type
== SAS
)
4391 num_chain
*= MPT_SAS_CAN_QUEUE
;
4393 num_chain
*= MPT_FC_CAN_QUEUE
;
4395 ioc
->num_chain
= num_chain
;
4397 sz
= num_chain
* sizeof(int);
4398 if (ioc
->ChainToChain
== NULL
) {
4399 mem
= kmalloc(sz
, GFP_ATOMIC
);
4403 ioc
->ChainToChain
= (int *) mem
;
4404 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"ChainToChain alloc @ %p, sz=%d bytes\n",
4405 ioc
->name
, mem
, sz
));
4407 mem
= (u8
*) ioc
->ChainToChain
;
4409 memset(mem
, 0xFF, sz
);
4413 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4415 * PrimeIocFifos - Initialize IOC request and reply FIFOs.
4416 * @ioc: Pointer to MPT_ADAPTER structure
4418 * This routine allocates memory for the MPT reply and request frame
4419 * pools (if necessary), and primes the IOC reply FIFO with
4422 * Returns 0 for success, non-zero for failure.
4425 PrimeIocFifos(MPT_ADAPTER
*ioc
)
4428 unsigned long flags
;
4429 dma_addr_t alloc_dma
;
4431 int i
, reply_sz
, sz
, total_size
, num_chain
;
4436 /* Prime reply FIFO... */
4438 if (ioc
->reply_frames
== NULL
) {
4439 if ( (num_chain
= initChainBuffers(ioc
)) < 0)
4442 * 1078 errata workaround for the 36GB limitation
4444 if (ioc
->pcidev
->device
== MPI_MANUFACTPAGE_DEVID_SAS1078
&&
4445 ioc
->dma_mask
> DMA_BIT_MASK(35)) {
4446 if (!pci_set_dma_mask(ioc
->pcidev
, DMA_BIT_MASK(32))
4447 && !pci_set_consistent_dma_mask(ioc
->pcidev
,
4448 DMA_BIT_MASK(32))) {
4449 dma_mask
= DMA_BIT_MASK(35);
4450 d36memprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
4451 "setting 35 bit addressing for "
4452 "Request/Reply/Chain and Sense Buffers\n",
4455 /*Reseting DMA mask to 64 bit*/
4456 pci_set_dma_mask(ioc
->pcidev
,
4458 pci_set_consistent_dma_mask(ioc
->pcidev
,
4461 printk(MYIOC_s_ERR_FMT
4462 "failed setting 35 bit addressing for "
4463 "Request/Reply/Chain and Sense Buffers\n",
4469 total_size
= reply_sz
= (ioc
->reply_sz
* ioc
->reply_depth
);
4470 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
4471 ioc
->name
, ioc
->reply_sz
, ioc
->reply_depth
));
4472 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"ReplyBuffer sz=%d[%x] bytes\n",
4473 ioc
->name
, reply_sz
, reply_sz
));
4475 sz
= (ioc
->req_sz
* ioc
->req_depth
);
4476 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"RequestBuffer sz=%d bytes, RequestDepth=%d\n",
4477 ioc
->name
, ioc
->req_sz
, ioc
->req_depth
));
4478 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"RequestBuffer sz=%d[%x] bytes\n",
4479 ioc
->name
, sz
, sz
));
4482 sz
= num_chain
* ioc
->req_sz
; /* chain buffer pool size */
4483 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"ChainBuffer sz=%d bytes, ChainDepth=%d\n",
4484 ioc
->name
, ioc
->req_sz
, num_chain
));
4485 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
4486 ioc
->name
, sz
, sz
, num_chain
));
4489 mem
= pci_alloc_consistent(ioc
->pcidev
, total_size
, &alloc_dma
);
4491 printk(MYIOC_s_ERR_FMT
"Unable to allocate Reply, Request, Chain Buffers!\n",
4496 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Total alloc @ %p[%p], sz=%d[%x] bytes\n",
4497 ioc
->name
, mem
, (void *)(ulong
)alloc_dma
, total_size
, total_size
));
4499 memset(mem
, 0, total_size
);
4500 ioc
->alloc_total
+= total_size
;
4502 ioc
->alloc_dma
= alloc_dma
;
4503 ioc
->alloc_sz
= total_size
;
4504 ioc
->reply_frames
= (MPT_FRAME_HDR
*) mem
;
4505 ioc
->reply_frames_low_dma
= (u32
) (alloc_dma
& 0xFFFFFFFF);
4507 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"ReplyBuffers @ %p[%p]\n",
4508 ioc
->name
, ioc
->reply_frames
, (void *)(ulong
)alloc_dma
));
4510 alloc_dma
+= reply_sz
;
4513 /* Request FIFO - WE manage this! */
4515 ioc
->req_frames
= (MPT_FRAME_HDR
*) mem
;
4516 ioc
->req_frames_dma
= alloc_dma
;
4518 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"RequestBuffers @ %p[%p]\n",
4519 ioc
->name
, mem
, (void *)(ulong
)alloc_dma
));
4521 ioc
->req_frames_low_dma
= (u32
) (alloc_dma
& 0xFFFFFFFF);
4523 #if defined(CONFIG_MTRR) && 0
4525 * Enable Write Combining MTRR for IOC's memory region.
4526 * (at least as much as we can; "size and base must be
4527 * multiples of 4 kiB"
4529 ioc
->mtrr_reg
= mtrr_add(ioc
->req_frames_dma
,
4531 MTRR_TYPE_WRCOMB
, 1);
4532 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"MTRR region registered (base:size=%08x:%x)\n",
4533 ioc
->name
, ioc
->req_frames_dma
, sz
));
4536 for (i
= 0; i
< ioc
->req_depth
; i
++) {
4537 alloc_dma
+= ioc
->req_sz
;
4541 ioc
->ChainBuffer
= mem
;
4542 ioc
->ChainBufferDMA
= alloc_dma
;
4544 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"ChainBuffers @ %p(%p)\n",
4545 ioc
->name
, ioc
->ChainBuffer
, (void *)(ulong
)ioc
->ChainBufferDMA
));
4547 /* Initialize the free chain Q.
4550 INIT_LIST_HEAD(&ioc
->FreeChainQ
);
4552 /* Post the chain buffers to the FreeChainQ.
4554 mem
= (u8
*)ioc
->ChainBuffer
;
4555 for (i
=0; i
< num_chain
; i
++) {
4556 mf
= (MPT_FRAME_HDR
*) mem
;
4557 list_add_tail(&mf
->u
.frame
.linkage
.list
, &ioc
->FreeChainQ
);
4561 /* Initialize Request frames linked list
4563 alloc_dma
= ioc
->req_frames_dma
;
4564 mem
= (u8
*) ioc
->req_frames
;
4566 spin_lock_irqsave(&ioc
->FreeQlock
, flags
);
4567 INIT_LIST_HEAD(&ioc
->FreeQ
);
4568 for (i
= 0; i
< ioc
->req_depth
; i
++) {
4569 mf
= (MPT_FRAME_HDR
*) mem
;
4571 /* Queue REQUESTs *internally*! */
4572 list_add_tail(&mf
->u
.frame
.linkage
.list
, &ioc
->FreeQ
);
4576 spin_unlock_irqrestore(&ioc
->FreeQlock
, flags
);
4578 sz
= (ioc
->req_depth
* MPT_SENSE_BUFFER_ALLOC
);
4579 ioc
->sense_buf_pool
=
4580 pci_alloc_consistent(ioc
->pcidev
, sz
, &ioc
->sense_buf_pool_dma
);
4581 if (ioc
->sense_buf_pool
== NULL
) {
4582 printk(MYIOC_s_ERR_FMT
"Unable to allocate Sense Buffers!\n",
4587 ioc
->sense_buf_low_dma
= (u32
) (ioc
->sense_buf_pool_dma
& 0xFFFFFFFF);
4588 ioc
->alloc_total
+= sz
;
4589 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"SenseBuffers @ %p[%p]\n",
4590 ioc
->name
, ioc
->sense_buf_pool
, (void *)(ulong
)ioc
->sense_buf_pool_dma
));
4594 /* Post Reply frames to FIFO
4596 alloc_dma
= ioc
->alloc_dma
;
4597 dinitprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"ReplyBuffers @ %p[%p]\n",
4598 ioc
->name
, ioc
->reply_frames
, (void *)(ulong
)alloc_dma
));
4600 for (i
= 0; i
< ioc
->reply_depth
; i
++) {
4601 /* Write each address to the IOC! */
4602 CHIPREG_WRITE32(&ioc
->chip
->ReplyFifo
, alloc_dma
);
4603 alloc_dma
+= ioc
->reply_sz
;
4606 if (dma_mask
== DMA_BIT_MASK(35) && !pci_set_dma_mask(ioc
->pcidev
,
4607 ioc
->dma_mask
) && !pci_set_consistent_dma_mask(ioc
->pcidev
,
4609 d36memprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
4610 "restoring 64 bit addressing\n", ioc
->name
));
4616 if (ioc
->alloc
!= NULL
) {
4618 pci_free_consistent(ioc
->pcidev
,
4620 ioc
->alloc
, ioc
->alloc_dma
);
4621 ioc
->reply_frames
= NULL
;
4622 ioc
->req_frames
= NULL
;
4623 ioc
->alloc_total
-= sz
;
4625 if (ioc
->sense_buf_pool
!= NULL
) {
4626 sz
= (ioc
->req_depth
* MPT_SENSE_BUFFER_ALLOC
);
4627 pci_free_consistent(ioc
->pcidev
,
4629 ioc
->sense_buf_pool
, ioc
->sense_buf_pool_dma
);
4630 ioc
->sense_buf_pool
= NULL
;
4633 if (dma_mask
== DMA_BIT_MASK(35) && !pci_set_dma_mask(ioc
->pcidev
,
4634 DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(ioc
->pcidev
,
4636 d36memprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
4637 "restoring 64 bit addressing\n", ioc
->name
));
4642 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4644 * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
4645 * from IOC via doorbell handshake method.
4646 * @ioc: Pointer to MPT_ADAPTER structure
4647 * @reqBytes: Size of the request in bytes
4648 * @req: Pointer to MPT request frame
4649 * @replyBytes: Expected size of the reply in bytes
4650 * @u16reply: Pointer to area where reply should be written
4651 * @maxwait: Max wait time for a reply (in seconds)
4652 * @sleepFlag: Specifies whether the process can sleep
4654 * NOTES: It is the callers responsibility to byte-swap fields in the
4655 * request which are greater than 1 byte in size. It is also the
4656 * callers responsibility to byte-swap response fields which are
4657 * greater than 1 byte in size.
4659 * Returns 0 for success, non-zero for failure.
4662 mpt_handshake_req_reply_wait(MPT_ADAPTER
*ioc
, int reqBytes
, u32
*req
,
4663 int replyBytes
, u16
*u16reply
, int maxwait
, int sleepFlag
)
4665 MPIDefaultReply_t
*mptReply
;
4670 * Get ready to cache a handshake reply
4672 ioc
->hs_reply_idx
= 0;
4673 mptReply
= (MPIDefaultReply_t
*) ioc
->hs_reply
;
4674 mptReply
->MsgLength
= 0;
4677 * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
4678 * then tell IOC that we want to handshake a request of N words.
4679 * (WRITE u32val to Doorbell reg).
4681 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
4682 CHIPREG_WRITE32(&ioc
->chip
->Doorbell
,
4683 ((MPI_FUNCTION_HANDSHAKE
<<MPI_DOORBELL_FUNCTION_SHIFT
) |
4684 ((reqBytes
/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT
)));
4687 * Wait for IOC's doorbell handshake int
4689 if ((t
= WaitForDoorbellInt(ioc
, 5, sleepFlag
)) < 0)
4692 dhsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
4693 ioc
->name
, reqBytes
, t
, failcnt
? " - MISSING DOORBELL HANDSHAKE!" : ""));
4695 /* Read doorbell and check for active bit */
4696 if (!(CHIPREG_READ32(&ioc
->chip
->Doorbell
) & MPI_DOORBELL_ACTIVE
))
4700 * Clear doorbell int (WRITE 0 to IntStatus reg),
4701 * then wait for IOC to ACKnowledge that it's ready for
4702 * our handshake request.
4704 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
4705 if (!failcnt
&& (t
= WaitForDoorbellAck(ioc
, 5, sleepFlag
)) < 0)
4710 u8
*req_as_bytes
= (u8
*) req
;
4713 * Stuff request words via doorbell handshake,
4714 * with ACK from IOC for each.
4716 for (ii
= 0; !failcnt
&& ii
< reqBytes
/4; ii
++) {
4717 u32 word
= ((req_as_bytes
[(ii
*4) + 0] << 0) |
4718 (req_as_bytes
[(ii
*4) + 1] << 8) |
4719 (req_as_bytes
[(ii
*4) + 2] << 16) |
4720 (req_as_bytes
[(ii
*4) + 3] << 24));
4722 CHIPREG_WRITE32(&ioc
->chip
->Doorbell
, word
);
4723 if ((t
= WaitForDoorbellAck(ioc
, 5, sleepFlag
)) < 0)
4727 dhsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Handshake request frame (@%p) header\n", ioc
->name
, req
));
4728 DBG_DUMP_REQUEST_FRAME_HDR(ioc
, (u32
*)req
);
4730 dhsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"HandShake request post done, WaitCnt=%d%s\n",
4731 ioc
->name
, t
, failcnt
? " - MISSING DOORBELL ACK!" : ""));
4734 * Wait for completion of doorbell handshake reply from the IOC
4736 if (!failcnt
&& (t
= WaitForDoorbellReply(ioc
, maxwait
, sleepFlag
)) < 0)
4739 dhsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"HandShake reply count=%d%s\n",
4740 ioc
->name
, t
, failcnt
? " - MISSING DOORBELL REPLY!" : ""));
4743 * Copy out the cached reply...
4745 for (ii
=0; ii
< min(replyBytes
/2,mptReply
->MsgLength
*2); ii
++)
4746 u16reply
[ii
] = ioc
->hs_reply
[ii
];
4754 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4756 * WaitForDoorbellAck - Wait for IOC doorbell handshake acknowledge
4757 * @ioc: Pointer to MPT_ADAPTER structure
4758 * @howlong: How long to wait (in seconds)
4759 * @sleepFlag: Specifies whether the process can sleep
4761 * This routine waits (up to ~2 seconds max) for IOC doorbell
4762 * handshake ACKnowledge, indicated by the IOP_DOORBELL_STATUS
4763 * bit in its IntStatus register being clear.
4765 * Returns a negative value on failure, else wait loop count.
4768 WaitForDoorbellAck(MPT_ADAPTER
*ioc
, int howlong
, int sleepFlag
)
4774 cntdn
= 1000 * howlong
;
4776 if (sleepFlag
== CAN_SLEEP
) {
4779 intstat
= CHIPREG_READ32(&ioc
->chip
->IntStatus
);
4780 if (! (intstat
& MPI_HIS_IOP_DOORBELL_STATUS
))
4787 intstat
= CHIPREG_READ32(&ioc
->chip
->IntStatus
);
4788 if (! (intstat
& MPI_HIS_IOP_DOORBELL_STATUS
))
4795 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"WaitForDoorbell ACK (count=%d)\n",
4800 printk(MYIOC_s_ERR_FMT
"Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
4801 ioc
->name
, count
, intstat
);
4805 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4807 * WaitForDoorbellInt - Wait for IOC to set its doorbell interrupt bit
4808 * @ioc: Pointer to MPT_ADAPTER structure
4809 * @howlong: How long to wait (in seconds)
4810 * @sleepFlag: Specifies whether the process can sleep
4812 * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt
4813 * (MPI_HIS_DOORBELL_INTERRUPT) to be set in the IntStatus register.
4815 * Returns a negative value on failure, else wait loop count.
4818 WaitForDoorbellInt(MPT_ADAPTER
*ioc
, int howlong
, int sleepFlag
)
4824 cntdn
= 1000 * howlong
;
4825 if (sleepFlag
== CAN_SLEEP
) {
4827 intstat
= CHIPREG_READ32(&ioc
->chip
->IntStatus
);
4828 if (intstat
& MPI_HIS_DOORBELL_INTERRUPT
)
4835 intstat
= CHIPREG_READ32(&ioc
->chip
->IntStatus
);
4836 if (intstat
& MPI_HIS_DOORBELL_INTERRUPT
)
4844 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"WaitForDoorbell INT (cnt=%d) howlong=%d\n",
4845 ioc
->name
, count
, howlong
));
4849 printk(MYIOC_s_ERR_FMT
"Doorbell INT timeout (count=%d), IntStatus=%x!\n",
4850 ioc
->name
, count
, intstat
);
4854 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4856 * WaitForDoorbellReply - Wait for and capture an IOC handshake reply.
4857 * @ioc: Pointer to MPT_ADAPTER structure
4858 * @howlong: How long to wait (in seconds)
4859 * @sleepFlag: Specifies whether the process can sleep
4861 * This routine polls the IOC for a handshake reply, 16 bits at a time.
4862 * Reply is cached to IOC private area large enough to hold a maximum
4863 * of 128 bytes of reply data.
4865 * Returns a negative value on failure, else size of reply in WORDS.
4868 WaitForDoorbellReply(MPT_ADAPTER
*ioc
, int howlong
, int sleepFlag
)
4873 u16
*hs_reply
= ioc
->hs_reply
;
4874 volatile MPIDefaultReply_t
*mptReply
= (MPIDefaultReply_t
*) ioc
->hs_reply
;
4877 hs_reply
[0] = hs_reply
[1] = hs_reply
[7] = 0;
4880 * Get first two u16's so we can look at IOC's intended reply MsgLength
4883 if ((t
= WaitForDoorbellInt(ioc
, howlong
, sleepFlag
)) < 0) {
4886 hs_reply
[u16cnt
++] = le16_to_cpu(CHIPREG_READ32(&ioc
->chip
->Doorbell
) & 0x0000FFFF);
4887 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
4888 if ((t
= WaitForDoorbellInt(ioc
, 5, sleepFlag
)) < 0)
4891 hs_reply
[u16cnt
++] = le16_to_cpu(CHIPREG_READ32(&ioc
->chip
->Doorbell
) & 0x0000FFFF);
4892 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
4896 dhsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"WaitCnt=%d First handshake reply word=%08x%s\n",
4897 ioc
->name
, t
, le32_to_cpu(*(u32
*)hs_reply
),
4898 failcnt
? " - MISSING DOORBELL HANDSHAKE!" : ""));
4901 * If no error (and IOC said MsgLength is > 0), piece together
4902 * reply 16 bits at a time.
4904 for (u16cnt
=2; !failcnt
&& u16cnt
< (2 * mptReply
->MsgLength
); u16cnt
++) {
4905 if ((t
= WaitForDoorbellInt(ioc
, 5, sleepFlag
)) < 0)
4907 hword
= le16_to_cpu(CHIPREG_READ32(&ioc
->chip
->Doorbell
) & 0x0000FFFF);
4908 /* don't overflow our IOC hs_reply[] buffer! */
4909 if (u16cnt
< ARRAY_SIZE(ioc
->hs_reply
))
4910 hs_reply
[u16cnt
] = hword
;
4911 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
4914 if (!failcnt
&& (t
= WaitForDoorbellInt(ioc
, 5, sleepFlag
)) < 0)
4916 CHIPREG_WRITE32(&ioc
->chip
->IntStatus
, 0);
4919 printk(MYIOC_s_ERR_FMT
"Handshake reply failure!\n",
4924 else if (u16cnt
!= (2 * mptReply
->MsgLength
)) {
4927 else if ((mptReply
->IOCStatus
& MPI_IOCSTATUS_MASK
) != MPI_IOCSTATUS_SUCCESS
) {
4932 dhsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Got Handshake reply:\n", ioc
->name
));
4933 DBG_DUMP_REPLY_FRAME(ioc
, (u32
*)mptReply
);
4935 dhsprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
4936 ioc
->name
, t
, u16cnt
/2));
4940 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4942 * GetLanConfigPages - Fetch LANConfig pages.
4943 * @ioc: Pointer to MPT_ADAPTER structure
4945 * Return: 0 for success
4946 * -ENOMEM if no memory available
4947 * -EPERM if not allowed due to ISR context
4948 * -EAGAIN if no msg frames currently available
4949 * -EFAULT for non-successful reply or no reply (timeout)
4952 GetLanConfigPages(MPT_ADAPTER
*ioc
)
4954 ConfigPageHeader_t hdr
;
4956 LANPage0_t
*ppage0_alloc
;
4957 dma_addr_t page0_dma
;
4958 LANPage1_t
*ppage1_alloc
;
4959 dma_addr_t page1_dma
;
4964 /* Get LAN Page 0 header */
4965 hdr
.PageVersion
= 0;
4968 hdr
.PageType
= MPI_CONFIG_PAGETYPE_LAN
;
4969 cfg
.cfghdr
.hdr
= &hdr
;
4971 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
4976 if ((rc
= mpt_config(ioc
, &cfg
)) != 0)
4979 if (hdr
.PageLength
> 0) {
4980 data_sz
= hdr
.PageLength
* 4;
4981 ppage0_alloc
= (LANPage0_t
*) pci_alloc_consistent(ioc
->pcidev
, data_sz
, &page0_dma
);
4984 memset((u8
*)ppage0_alloc
, 0, data_sz
);
4985 cfg
.physAddr
= page0_dma
;
4986 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
4988 if ((rc
= mpt_config(ioc
, &cfg
)) == 0) {
4990 copy_sz
= min_t(int, sizeof(LANPage0_t
), data_sz
);
4991 memcpy(&ioc
->lan_cnfg_page0
, ppage0_alloc
, copy_sz
);
4995 pci_free_consistent(ioc
->pcidev
, data_sz
, (u8
*) ppage0_alloc
, page0_dma
);
4998 * Normalize endianness of structure data,
4999 * by byte-swapping all > 1 byte fields!
5008 /* Get LAN Page 1 header */
5009 hdr
.PageVersion
= 0;
5012 hdr
.PageType
= MPI_CONFIG_PAGETYPE_LAN
;
5013 cfg
.cfghdr
.hdr
= &hdr
;
5015 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
5019 if ((rc
= mpt_config(ioc
, &cfg
)) != 0)
5022 if (hdr
.PageLength
== 0)
5025 data_sz
= hdr
.PageLength
* 4;
5027 ppage1_alloc
= (LANPage1_t
*) pci_alloc_consistent(ioc
->pcidev
, data_sz
, &page1_dma
);
5029 memset((u8
*)ppage1_alloc
, 0, data_sz
);
5030 cfg
.physAddr
= page1_dma
;
5031 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
5033 if ((rc
= mpt_config(ioc
, &cfg
)) == 0) {
5035 copy_sz
= min_t(int, sizeof(LANPage1_t
), data_sz
);
5036 memcpy(&ioc
->lan_cnfg_page1
, ppage1_alloc
, copy_sz
);
5039 pci_free_consistent(ioc
->pcidev
, data_sz
, (u8
*) ppage1_alloc
, page1_dma
);
5042 * Normalize endianness of structure data,
5043 * by byte-swapping all > 1 byte fields!
5051 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5053 * mptbase_sas_persist_operation - Perform operation on SAS Persistent Table
5054 * @ioc: Pointer to MPT_ADAPTER structure
5055 * @persist_opcode: see below
5057 * MPI_SAS_OP_CLEAR_NOT_PRESENT - Free all persist TargetID mappings for
5058 * devices not currently present.
5059 * MPI_SAS_OP_CLEAR_ALL_PERSISTENT - Clear al persist TargetID mappings
5061 * NOTE: Don't use not this function during interrupt time.
5063 * Returns 0 for success, non-zero error
5066 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5068 mptbase_sas_persist_operation(MPT_ADAPTER
*ioc
, u8 persist_opcode
)
5070 SasIoUnitControlRequest_t
*sasIoUnitCntrReq
;
5071 SasIoUnitControlReply_t
*sasIoUnitCntrReply
;
5072 MPT_FRAME_HDR
*mf
= NULL
;
5073 MPIHeader_t
*mpi_hdr
;
5075 unsigned long timeleft
;
5077 mutex_lock(&ioc
->mptbase_cmds
.mutex
);
5079 /* init the internal cmd struct */
5080 memset(ioc
->mptbase_cmds
.reply
, 0 , MPT_DEFAULT_FRAME_SIZE
);
5081 INITIALIZE_MGMT_STATUS(ioc
->mptbase_cmds
.status
)
5083 /* insure garbage is not sent to fw */
5084 switch(persist_opcode
) {
5086 case MPI_SAS_OP_CLEAR_NOT_PRESENT
:
5087 case MPI_SAS_OP_CLEAR_ALL_PERSISTENT
:
5095 printk(KERN_DEBUG
"%s: persist_opcode=%x\n",
5096 __func__
, persist_opcode
);
5098 /* Get a MF for this command.
5100 if ((mf
= mpt_get_msg_frame(mpt_base_index
, ioc
)) == NULL
) {
5101 printk(KERN_DEBUG
"%s: no msg frames!\n", __func__
);
5106 mpi_hdr
= (MPIHeader_t
*) mf
;
5107 sasIoUnitCntrReq
= (SasIoUnitControlRequest_t
*)mf
;
5108 memset(sasIoUnitCntrReq
,0,sizeof(SasIoUnitControlRequest_t
));
5109 sasIoUnitCntrReq
->Function
= MPI_FUNCTION_SAS_IO_UNIT_CONTROL
;
5110 sasIoUnitCntrReq
->MsgContext
= mpi_hdr
->MsgContext
;
5111 sasIoUnitCntrReq
->Operation
= persist_opcode
;
5113 mpt_put_msg_frame(mpt_base_index
, ioc
, mf
);
5114 timeleft
= wait_for_completion_timeout(&ioc
->mptbase_cmds
.done
, 10*HZ
);
5115 if (!(ioc
->mptbase_cmds
.status
& MPT_MGMT_STATUS_COMMAND_GOOD
)) {
5117 printk(KERN_DEBUG
"%s: failed\n", __func__
);
5118 if (ioc
->mptbase_cmds
.status
& MPT_MGMT_STATUS_DID_IOCRESET
)
5121 printk(MYIOC_s_WARN_FMT
5122 "Issuing Reset from %s!!, doorbell=0x%08x\n",
5123 ioc
->name
, __func__
, mpt_GetIocState(ioc
, 0));
5124 mpt_Soft_Hard_ResetHandler(ioc
, CAN_SLEEP
);
5125 mpt_free_msg_frame(ioc
, mf
);
5130 if (!(ioc
->mptbase_cmds
.status
& MPT_MGMT_STATUS_RF_VALID
)) {
5135 sasIoUnitCntrReply
=
5136 (SasIoUnitControlReply_t
*)ioc
->mptbase_cmds
.reply
;
5137 if (le16_to_cpu(sasIoUnitCntrReply
->IOCStatus
) != MPI_IOCSTATUS_SUCCESS
) {
5138 printk(KERN_DEBUG
"%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
5139 __func__
, sasIoUnitCntrReply
->IOCStatus
,
5140 sasIoUnitCntrReply
->IOCLogInfo
);
5141 printk(KERN_DEBUG
"%s: failed\n", __func__
);
5144 printk(KERN_DEBUG
"%s: success\n", __func__
);
5147 CLEAR_MGMT_STATUS(ioc
->mptbase_cmds
.status
)
5148 mutex_unlock(&ioc
->mptbase_cmds
.mutex
);
5152 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5155 mptbase_raid_process_event_data(MPT_ADAPTER
*ioc
,
5156 MpiEventDataRaid_t
* pRaidEventData
)
5165 volume
= pRaidEventData
->VolumeID
;
5166 reason
= pRaidEventData
->ReasonCode
;
5167 disk
= pRaidEventData
->PhysDiskNum
;
5168 status
= le32_to_cpu(pRaidEventData
->SettingsStatus
);
5169 flags
= (status
>> 0) & 0xff;
5170 state
= (status
>> 8) & 0xff;
5172 if (reason
== MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED
) {
5176 if ((reason
>= MPI_EVENT_RAID_RC_PHYSDISK_CREATED
&&
5177 reason
<= MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED
) ||
5178 (reason
== MPI_EVENT_RAID_RC_SMART_DATA
)) {
5179 printk(MYIOC_s_INFO_FMT
"RAID STATUS CHANGE for PhysDisk %d id=%d\n",
5180 ioc
->name
, disk
, volume
);
5182 printk(MYIOC_s_INFO_FMT
"RAID STATUS CHANGE for VolumeID %d\n",
5187 case MPI_EVENT_RAID_RC_VOLUME_CREATED
:
5188 printk(MYIOC_s_INFO_FMT
" volume has been created\n",
5192 case MPI_EVENT_RAID_RC_VOLUME_DELETED
:
5194 printk(MYIOC_s_INFO_FMT
" volume has been deleted\n",
5198 case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED
:
5199 printk(MYIOC_s_INFO_FMT
" volume settings have been changed\n",
5203 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED
:
5204 printk(MYIOC_s_INFO_FMT
" volume is now %s%s%s%s\n",
5206 state
== MPI_RAIDVOL0_STATUS_STATE_OPTIMAL
5208 : state
== MPI_RAIDVOL0_STATUS_STATE_DEGRADED
5210 : state
== MPI_RAIDVOL0_STATUS_STATE_FAILED
5213 flags
& MPI_RAIDVOL0_STATUS_FLAG_ENABLED
5215 flags
& MPI_RAIDVOL0_STATUS_FLAG_QUIESCED
5216 ? ", quiesced" : "",
5217 flags
& MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
5218 ? ", resync in progress" : "" );
5221 case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED
:
5222 printk(MYIOC_s_INFO_FMT
" volume membership of PhysDisk %d has changed\n",
5226 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED
:
5227 printk(MYIOC_s_INFO_FMT
" PhysDisk has been created\n",
5231 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED
:
5232 printk(MYIOC_s_INFO_FMT
" PhysDisk has been deleted\n",
5236 case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED
:
5237 printk(MYIOC_s_INFO_FMT
" PhysDisk settings have been changed\n",
5241 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED
:
5242 printk(MYIOC_s_INFO_FMT
" PhysDisk is now %s%s%s\n",
5244 state
== MPI_PHYSDISK0_STATUS_ONLINE
5246 : state
== MPI_PHYSDISK0_STATUS_MISSING
5248 : state
== MPI_PHYSDISK0_STATUS_NOT_COMPATIBLE
5250 : state
== MPI_PHYSDISK0_STATUS_FAILED
5252 : state
== MPI_PHYSDISK0_STATUS_INITIALIZING
5254 : state
== MPI_PHYSDISK0_STATUS_OFFLINE_REQUESTED
5255 ? "offline requested"
5256 : state
== MPI_PHYSDISK0_STATUS_FAILED_REQUESTED
5257 ? "failed requested"
5258 : state
== MPI_PHYSDISK0_STATUS_OTHER_OFFLINE
5261 flags
& MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC
5262 ? ", out of sync" : "",
5263 flags
& MPI_PHYSDISK0_STATUS_FLAG_QUIESCED
5264 ? ", quiesced" : "" );
5267 case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED
:
5268 printk(MYIOC_s_INFO_FMT
" Domain Validation needed for PhysDisk %d\n",
5272 case MPI_EVENT_RAID_RC_SMART_DATA
:
5273 printk(MYIOC_s_INFO_FMT
" SMART data received, ASC/ASCQ = %02xh/%02xh\n",
5274 ioc
->name
, pRaidEventData
->ASC
, pRaidEventData
->ASCQ
);
5277 case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED
:
5278 printk(MYIOC_s_INFO_FMT
" replacement of PhysDisk %d has started\n",
5284 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5286 * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
5287 * @ioc: Pointer to MPT_ADAPTER structure
5289 * Returns: 0 for success
5290 * -ENOMEM if no memory available
5291 * -EPERM if not allowed due to ISR context
5292 * -EAGAIN if no msg frames currently available
5293 * -EFAULT for non-successful reply or no reply (timeout)
5296 GetIoUnitPage2(MPT_ADAPTER
*ioc
)
5298 ConfigPageHeader_t hdr
;
5300 IOUnitPage2_t
*ppage_alloc
;
5301 dma_addr_t page_dma
;
5305 /* Get the page header */
5306 hdr
.PageVersion
= 0;
5309 hdr
.PageType
= MPI_CONFIG_PAGETYPE_IO_UNIT
;
5310 cfg
.cfghdr
.hdr
= &hdr
;
5312 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
5317 if ((rc
= mpt_config(ioc
, &cfg
)) != 0)
5320 if (hdr
.PageLength
== 0)
5323 /* Read the config page */
5324 data_sz
= hdr
.PageLength
* 4;
5326 ppage_alloc
= (IOUnitPage2_t
*) pci_alloc_consistent(ioc
->pcidev
, data_sz
, &page_dma
);
5328 memset((u8
*)ppage_alloc
, 0, data_sz
);
5329 cfg
.physAddr
= page_dma
;
5330 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
5332 /* If Good, save data */
5333 if ((rc
= mpt_config(ioc
, &cfg
)) == 0)
5334 ioc
->biosVersion
= le32_to_cpu(ppage_alloc
->BiosVersion
);
5336 pci_free_consistent(ioc
->pcidev
, data_sz
, (u8
*) ppage_alloc
, page_dma
);
5342 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5344 * mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
5345 * @ioc: Pointer to a Adapter Strucutre
5346 * @portnum: IOC port number
5348 * Return: -EFAULT if read of config page header fails
5350 * If read of SCSI Port Page 0 fails,
5351 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
5352 * Adapter settings: async, narrow
5354 * If read of SCSI Port Page 2 fails,
5355 * Adapter settings valid
5356 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
5361 * CHECK - what type of locking mechanisms should be used????
5364 mpt_GetScsiPortSettings(MPT_ADAPTER
*ioc
, int portnum
)
5369 ConfigPageHeader_t header
;
5375 if (!ioc
->spi_data
.nvram
) {
5378 sz
= MPT_MAX_SCSI_DEVICES
* sizeof(int);
5379 mem
= kmalloc(sz
, GFP_ATOMIC
);
5383 ioc
->spi_data
.nvram
= (int *) mem
;
5385 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"SCSI device NVRAM settings @ %p, sz=%d\n",
5386 ioc
->name
, ioc
->spi_data
.nvram
, sz
));
5389 /* Invalidate NVRAM information
5391 for (ii
=0; ii
< MPT_MAX_SCSI_DEVICES
; ii
++) {
5392 ioc
->spi_data
.nvram
[ii
] = MPT_HOST_NVRAM_INVALID
;
5395 /* Read SPP0 header, allocate memory, then read page.
5397 header
.PageVersion
= 0;
5398 header
.PageLength
= 0;
5399 header
.PageNumber
= 0;
5400 header
.PageType
= MPI_CONFIG_PAGETYPE_SCSI_PORT
;
5401 cfg
.cfghdr
.hdr
= &header
;
5403 cfg
.pageAddr
= portnum
;
5404 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
5406 cfg
.timeout
= 0; /* use default */
5407 if (mpt_config(ioc
, &cfg
) != 0)
5410 if (header
.PageLength
> 0) {
5411 pbuf
= pci_alloc_consistent(ioc
->pcidev
, header
.PageLength
* 4, &buf_dma
);
5413 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
5414 cfg
.physAddr
= buf_dma
;
5415 if (mpt_config(ioc
, &cfg
) != 0) {
5416 ioc
->spi_data
.maxBusWidth
= MPT_NARROW
;
5417 ioc
->spi_data
.maxSyncOffset
= 0;
5418 ioc
->spi_data
.minSyncFactor
= MPT_ASYNC
;
5419 ioc
->spi_data
.busType
= MPT_HOST_BUS_UNKNOWN
;
5421 ddvprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
5422 "Unable to read PortPage0 minSyncFactor=%x\n",
5423 ioc
->name
, ioc
->spi_data
.minSyncFactor
));
5425 /* Save the Port Page 0 data
5427 SCSIPortPage0_t
*pPP0
= (SCSIPortPage0_t
*) pbuf
;
5428 pPP0
->Capabilities
= le32_to_cpu(pPP0
->Capabilities
);
5429 pPP0
->PhysicalInterface
= le32_to_cpu(pPP0
->PhysicalInterface
);
5431 if ( (pPP0
->Capabilities
& MPI_SCSIPORTPAGE0_CAP_QAS
) == 0 ) {
5432 ioc
->spi_data
.noQas
|= MPT_TARGET_NO_NEGO_QAS
;
5433 ddvprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
5434 "noQas due to Capabilities=%x\n",
5435 ioc
->name
, pPP0
->Capabilities
));
5437 ioc
->spi_data
.maxBusWidth
= pPP0
->Capabilities
& MPI_SCSIPORTPAGE0_CAP_WIDE
? 1 : 0;
5438 data
= pPP0
->Capabilities
& MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK
;
5440 ioc
->spi_data
.maxSyncOffset
= (u8
) (data
>> 16);
5441 data
= pPP0
->Capabilities
& MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK
;
5442 ioc
->spi_data
.minSyncFactor
= (u8
) (data
>> 8);
5443 ddvprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
5444 "PortPage0 minSyncFactor=%x\n",
5445 ioc
->name
, ioc
->spi_data
.minSyncFactor
));
5447 ioc
->spi_data
.maxSyncOffset
= 0;
5448 ioc
->spi_data
.minSyncFactor
= MPT_ASYNC
;
5451 ioc
->spi_data
.busType
= pPP0
->PhysicalInterface
& MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK
;
5453 /* Update the minSyncFactor based on bus type.
5455 if ((ioc
->spi_data
.busType
== MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD
) ||
5456 (ioc
->spi_data
.busType
== MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE
)) {
5458 if (ioc
->spi_data
.minSyncFactor
< MPT_ULTRA
) {
5459 ioc
->spi_data
.minSyncFactor
= MPT_ULTRA
;
5460 ddvprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
5461 "HVD or SE detected, minSyncFactor=%x\n",
5462 ioc
->name
, ioc
->spi_data
.minSyncFactor
));
5467 pci_free_consistent(ioc
->pcidev
, header
.PageLength
* 4, pbuf
, buf_dma
);
5472 /* SCSI Port Page 2 - Read the header then the page.
5474 header
.PageVersion
= 0;
5475 header
.PageLength
= 0;
5476 header
.PageNumber
= 2;
5477 header
.PageType
= MPI_CONFIG_PAGETYPE_SCSI_PORT
;
5478 cfg
.cfghdr
.hdr
= &header
;
5480 cfg
.pageAddr
= portnum
;
5481 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
5483 if (mpt_config(ioc
, &cfg
) != 0)
5486 if (header
.PageLength
> 0) {
5487 /* Allocate memory and read SCSI Port Page 2
5489 pbuf
= pci_alloc_consistent(ioc
->pcidev
, header
.PageLength
* 4, &buf_dma
);
5491 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_NVRAM
;
5492 cfg
.physAddr
= buf_dma
;
5493 if (mpt_config(ioc
, &cfg
) != 0) {
5494 /* Nvram data is left with INVALID mark
5497 } else if (ioc
->pcidev
->vendor
== PCI_VENDOR_ID_ATTO
) {
5499 /* This is an ATTO adapter, read Page2 accordingly
5501 ATTO_SCSIPortPage2_t
*pPP2
= (ATTO_SCSIPortPage2_t
*) pbuf
;
5502 ATTODeviceInfo_t
*pdevice
= NULL
;
5505 /* Save the Port Page 2 data
5506 * (reformat into a 32bit quantity)
5508 for (ii
=0; ii
< MPT_MAX_SCSI_DEVICES
; ii
++) {
5509 pdevice
= &pPP2
->DeviceSettings
[ii
];
5510 ATTOFlags
= le16_to_cpu(pdevice
->ATTOFlags
);
5513 /* Translate ATTO device flags to LSI format
5515 if (ATTOFlags
& ATTOFLAG_DISC
)
5516 data
|= (MPI_SCSIPORTPAGE2_DEVICE_DISCONNECT_ENABLE
);
5517 if (ATTOFlags
& ATTOFLAG_ID_ENB
)
5518 data
|= (MPI_SCSIPORTPAGE2_DEVICE_ID_SCAN_ENABLE
);
5519 if (ATTOFlags
& ATTOFLAG_LUN_ENB
)
5520 data
|= (MPI_SCSIPORTPAGE2_DEVICE_LUN_SCAN_ENABLE
);
5521 if (ATTOFlags
& ATTOFLAG_TAGGED
)
5522 data
|= (MPI_SCSIPORTPAGE2_DEVICE_TAG_QUEUE_ENABLE
);
5523 if (!(ATTOFlags
& ATTOFLAG_WIDE_ENB
))
5524 data
|= (MPI_SCSIPORTPAGE2_DEVICE_WIDE_DISABLE
);
5526 data
= (data
<< 16) | (pdevice
->Period
<< 8) | 10;
5527 ioc
->spi_data
.nvram
[ii
] = data
;
5530 SCSIPortPage2_t
*pPP2
= (SCSIPortPage2_t
*) pbuf
;
5531 MpiDeviceInfo_t
*pdevice
= NULL
;
5534 * Save "Set to Avoid SCSI Bus Resets" flag
5536 ioc
->spi_data
.bus_reset
=
5537 (le32_to_cpu(pPP2
->PortFlags
) &
5538 MPI_SCSIPORTPAGE2_PORT_FLAGS_AVOID_SCSI_RESET
) ?
5541 /* Save the Port Page 2 data
5542 * (reformat into a 32bit quantity)
5544 data
= le32_to_cpu(pPP2
->PortFlags
) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK
;
5545 ioc
->spi_data
.PortFlags
= data
;
5546 for (ii
=0; ii
< MPT_MAX_SCSI_DEVICES
; ii
++) {
5547 pdevice
= &pPP2
->DeviceSettings
[ii
];
5548 data
= (le16_to_cpu(pdevice
->DeviceFlags
) << 16) |
5549 (pdevice
->SyncFactor
<< 8) | pdevice
->Timeout
;
5550 ioc
->spi_data
.nvram
[ii
] = data
;
5554 pci_free_consistent(ioc
->pcidev
, header
.PageLength
* 4, pbuf
, buf_dma
);
5558 /* Update Adapter limits with those from NVRAM
5559 * Comment: Don't need to do this. Target performance
5560 * parameters will never exceed the adapters limits.
5566 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5568 * mpt_readScsiDevicePageHeaders - save version and length of SDP1
5569 * @ioc: Pointer to a Adapter Strucutre
5570 * @portnum: IOC port number
5572 * Return: -EFAULT if read of config page header fails
5576 mpt_readScsiDevicePageHeaders(MPT_ADAPTER
*ioc
, int portnum
)
5579 ConfigPageHeader_t header
;
5581 /* Read the SCSI Device Page 1 header
5583 header
.PageVersion
= 0;
5584 header
.PageLength
= 0;
5585 header
.PageNumber
= 1;
5586 header
.PageType
= MPI_CONFIG_PAGETYPE_SCSI_DEVICE
;
5587 cfg
.cfghdr
.hdr
= &header
;
5589 cfg
.pageAddr
= portnum
;
5590 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
5593 if (mpt_config(ioc
, &cfg
) != 0)
5596 ioc
->spi_data
.sdp1version
= cfg
.cfghdr
.hdr
->PageVersion
;
5597 ioc
->spi_data
.sdp1length
= cfg
.cfghdr
.hdr
->PageLength
;
5599 header
.PageVersion
= 0;
5600 header
.PageLength
= 0;
5601 header
.PageNumber
= 0;
5602 header
.PageType
= MPI_CONFIG_PAGETYPE_SCSI_DEVICE
;
5603 if (mpt_config(ioc
, &cfg
) != 0)
5606 ioc
->spi_data
.sdp0version
= cfg
.cfghdr
.hdr
->PageVersion
;
5607 ioc
->spi_data
.sdp0length
= cfg
.cfghdr
.hdr
->PageLength
;
5609 dcprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Headers: 0: version %d length %d\n",
5610 ioc
->name
, ioc
->spi_data
.sdp0version
, ioc
->spi_data
.sdp0length
));
5612 dcprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Headers: 1: version %d length %d\n",
5613 ioc
->name
, ioc
->spi_data
.sdp1version
, ioc
->spi_data
.sdp1length
));
5618 * mpt_inactive_raid_list_free - This clears this link list.
5619 * @ioc : pointer to per adapter structure
5622 mpt_inactive_raid_list_free(MPT_ADAPTER
*ioc
)
5624 struct inactive_raid_component_info
*component_info
, *pNext
;
5626 if (list_empty(&ioc
->raid_data
.inactive_list
))
5629 mutex_lock(&ioc
->raid_data
.inactive_list_mutex
);
5630 list_for_each_entry_safe(component_info
, pNext
,
5631 &ioc
->raid_data
.inactive_list
, list
) {
5632 list_del(&component_info
->list
);
5633 kfree(component_info
);
5635 mutex_unlock(&ioc
->raid_data
.inactive_list_mutex
);
5639 * mpt_inactive_raid_volumes - sets up link list of phy_disk_nums for devices belonging in an inactive volume
5641 * @ioc : pointer to per adapter structure
5642 * @channel : volume channel
5643 * @id : volume target id
5646 mpt_inactive_raid_volumes(MPT_ADAPTER
*ioc
, u8 channel
, u8 id
)
5649 ConfigPageHeader_t hdr
;
5650 dma_addr_t dma_handle
;
5651 pRaidVolumePage0_t buffer
= NULL
;
5653 RaidPhysDiskPage0_t phys_disk
;
5654 struct inactive_raid_component_info
*component_info
;
5655 int handle_inactive_volumes
;
5657 memset(&cfg
, 0 , sizeof(CONFIGPARMS
));
5658 memset(&hdr
, 0 , sizeof(ConfigPageHeader_t
));
5659 hdr
.PageType
= MPI_CONFIG_PAGETYPE_RAID_VOLUME
;
5660 cfg
.pageAddr
= (channel
<< 8) + id
;
5661 cfg
.cfghdr
.hdr
= &hdr
;
5662 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
5664 if (mpt_config(ioc
, &cfg
) != 0)
5667 if (!hdr
.PageLength
)
5670 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.PageLength
* 4,
5676 cfg
.physAddr
= dma_handle
;
5677 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
5679 if (mpt_config(ioc
, &cfg
) != 0)
5682 if (!buffer
->NumPhysDisks
)
5685 handle_inactive_volumes
=
5686 (buffer
->VolumeStatus
.Flags
& MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE
||
5687 (buffer
->VolumeStatus
.Flags
& MPI_RAIDVOL0_STATUS_FLAG_ENABLED
) == 0 ||
5688 buffer
->VolumeStatus
.State
== MPI_RAIDVOL0_STATUS_STATE_FAILED
||
5689 buffer
->VolumeStatus
.State
== MPI_RAIDVOL0_STATUS_STATE_MISSING
) ? 1 : 0;
5691 if (!handle_inactive_volumes
)
5694 mutex_lock(&ioc
->raid_data
.inactive_list_mutex
);
5695 for (i
= 0; i
< buffer
->NumPhysDisks
; i
++) {
5696 if(mpt_raid_phys_disk_pg0(ioc
,
5697 buffer
->PhysDisk
[i
].PhysDiskNum
, &phys_disk
) != 0)
5700 if ((component_info
= kmalloc(sizeof (*component_info
),
5701 GFP_KERNEL
)) == NULL
)
5704 component_info
->volumeID
= id
;
5705 component_info
->volumeBus
= channel
;
5706 component_info
->d
.PhysDiskNum
= phys_disk
.PhysDiskNum
;
5707 component_info
->d
.PhysDiskBus
= phys_disk
.PhysDiskBus
;
5708 component_info
->d
.PhysDiskID
= phys_disk
.PhysDiskID
;
5709 component_info
->d
.PhysDiskIOC
= phys_disk
.PhysDiskIOC
;
5711 list_add_tail(&component_info
->list
,
5712 &ioc
->raid_data
.inactive_list
);
5714 mutex_unlock(&ioc
->raid_data
.inactive_list_mutex
);
5718 pci_free_consistent(ioc
->pcidev
, hdr
.PageLength
* 4, buffer
,
5723 * mpt_raid_phys_disk_pg0 - returns phys disk page zero
5724 * @ioc: Pointer to a Adapter Structure
5725 * @phys_disk_num: io unit unique phys disk num generated by the ioc
5726 * @phys_disk: requested payload data returned
5730 * -EFAULT if read of config page header fails or data pointer not NULL
5731 * -ENOMEM if pci_alloc failed
5734 mpt_raid_phys_disk_pg0(MPT_ADAPTER
*ioc
, u8 phys_disk_num
,
5735 RaidPhysDiskPage0_t
*phys_disk
)
5738 ConfigPageHeader_t hdr
;
5739 dma_addr_t dma_handle
;
5740 pRaidPhysDiskPage0_t buffer
= NULL
;
5743 memset(&cfg
, 0 , sizeof(CONFIGPARMS
));
5744 memset(&hdr
, 0 , sizeof(ConfigPageHeader_t
));
5745 memset(phys_disk
, 0, sizeof(RaidPhysDiskPage0_t
));
5747 hdr
.PageVersion
= MPI_RAIDPHYSDISKPAGE0_PAGEVERSION
;
5748 hdr
.PageType
= MPI_CONFIG_PAGETYPE_RAID_PHYSDISK
;
5749 cfg
.cfghdr
.hdr
= &hdr
;
5751 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
5753 if (mpt_config(ioc
, &cfg
) != 0) {
5758 if (!hdr
.PageLength
) {
5763 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.PageLength
* 4,
5771 cfg
.physAddr
= dma_handle
;
5772 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
5773 cfg
.pageAddr
= phys_disk_num
;
5775 if (mpt_config(ioc
, &cfg
) != 0) {
5781 memcpy(phys_disk
, buffer
, sizeof(*buffer
));
5782 phys_disk
->MaxLBA
= le32_to_cpu(buffer
->MaxLBA
);
5787 pci_free_consistent(ioc
->pcidev
, hdr
.PageLength
* 4, buffer
,
5794 * mpt_raid_phys_disk_get_num_paths - returns number paths associated to this phys_num
5795 * @ioc: Pointer to a Adapter Structure
5796 * @phys_disk_num: io unit unique phys disk num generated by the ioc
5799 * returns number paths
5802 mpt_raid_phys_disk_get_num_paths(MPT_ADAPTER
*ioc
, u8 phys_disk_num
)
5805 ConfigPageHeader_t hdr
;
5806 dma_addr_t dma_handle
;
5807 pRaidPhysDiskPage1_t buffer
= NULL
;
5810 memset(&cfg
, 0 , sizeof(CONFIGPARMS
));
5811 memset(&hdr
, 0 , sizeof(ConfigPageHeader_t
));
5813 hdr
.PageVersion
= MPI_RAIDPHYSDISKPAGE1_PAGEVERSION
;
5814 hdr
.PageType
= MPI_CONFIG_PAGETYPE_RAID_PHYSDISK
;
5816 cfg
.cfghdr
.hdr
= &hdr
;
5818 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
5820 if (mpt_config(ioc
, &cfg
) != 0) {
5825 if (!hdr
.PageLength
) {
5830 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.PageLength
* 4,
5838 cfg
.physAddr
= dma_handle
;
5839 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
5840 cfg
.pageAddr
= phys_disk_num
;
5842 if (mpt_config(ioc
, &cfg
) != 0) {
5847 rc
= buffer
->NumPhysDiskPaths
;
5851 pci_free_consistent(ioc
->pcidev
, hdr
.PageLength
* 4, buffer
,
5856 EXPORT_SYMBOL(mpt_raid_phys_disk_get_num_paths
);
5859 * mpt_raid_phys_disk_pg1 - returns phys disk page 1
5860 * @ioc: Pointer to a Adapter Structure
5861 * @phys_disk_num: io unit unique phys disk num generated by the ioc
5862 * @phys_disk: requested payload data returned
5866 * -EFAULT if read of config page header fails or data pointer not NULL
5867 * -ENOMEM if pci_alloc failed
5870 mpt_raid_phys_disk_pg1(MPT_ADAPTER
*ioc
, u8 phys_disk_num
,
5871 RaidPhysDiskPage1_t
*phys_disk
)
5874 ConfigPageHeader_t hdr
;
5875 dma_addr_t dma_handle
;
5876 pRaidPhysDiskPage1_t buffer
= NULL
;
5881 memset(&cfg
, 0 , sizeof(CONFIGPARMS
));
5882 memset(&hdr
, 0 , sizeof(ConfigPageHeader_t
));
5885 hdr
.PageVersion
= MPI_RAIDPHYSDISKPAGE1_PAGEVERSION
;
5886 hdr
.PageType
= MPI_CONFIG_PAGETYPE_RAID_PHYSDISK
;
5888 cfg
.cfghdr
.hdr
= &hdr
;
5890 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
5892 if (mpt_config(ioc
, &cfg
) != 0) {
5897 if (!hdr
.PageLength
) {
5902 buffer
= pci_alloc_consistent(ioc
->pcidev
, hdr
.PageLength
* 4,
5910 cfg
.physAddr
= dma_handle
;
5911 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
5912 cfg
.pageAddr
= phys_disk_num
;
5914 if (mpt_config(ioc
, &cfg
) != 0) {
5919 phys_disk
->NumPhysDiskPaths
= buffer
->NumPhysDiskPaths
;
5920 phys_disk
->PhysDiskNum
= phys_disk_num
;
5921 for (i
= 0; i
< phys_disk
->NumPhysDiskPaths
; i
++) {
5922 phys_disk
->Path
[i
].PhysDiskID
= buffer
->Path
[i
].PhysDiskID
;
5923 phys_disk
->Path
[i
].PhysDiskBus
= buffer
->Path
[i
].PhysDiskBus
;
5924 phys_disk
->Path
[i
].OwnerIdentifier
=
5925 buffer
->Path
[i
].OwnerIdentifier
;
5926 phys_disk
->Path
[i
].Flags
= le16_to_cpu(buffer
->Path
[i
].Flags
);
5927 memcpy(&sas_address
, &buffer
->Path
[i
].WWID
, sizeof(__le64
));
5928 sas_address
= le64_to_cpu(sas_address
);
5929 memcpy(&phys_disk
->Path
[i
].WWID
, &sas_address
, sizeof(__le64
));
5930 memcpy(&sas_address
,
5931 &buffer
->Path
[i
].OwnerWWID
, sizeof(__le64
));
5932 sas_address
= le64_to_cpu(sas_address
);
5933 memcpy(&phys_disk
->Path
[i
].OwnerWWID
,
5934 &sas_address
, sizeof(__le64
));
5940 pci_free_consistent(ioc
->pcidev
, hdr
.PageLength
* 4, buffer
,
5945 EXPORT_SYMBOL(mpt_raid_phys_disk_pg1
);
5949 * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
5950 * @ioc: Pointer to a Adapter Strucutre
5954 * -EFAULT if read of config page header fails or data pointer not NULL
5955 * -ENOMEM if pci_alloc failed
5958 mpt_findImVolumes(MPT_ADAPTER
*ioc
)
5962 dma_addr_t ioc2_dma
;
5964 ConfigPageHeader_t header
;
5969 if (!ioc
->ir_firmware
)
5972 /* Free the old page
5974 kfree(ioc
->raid_data
.pIocPg2
);
5975 ioc
->raid_data
.pIocPg2
= NULL
;
5976 mpt_inactive_raid_list_free(ioc
);
5978 /* Read IOCP2 header then the page.
5980 header
.PageVersion
= 0;
5981 header
.PageLength
= 0;
5982 header
.PageNumber
= 2;
5983 header
.PageType
= MPI_CONFIG_PAGETYPE_IOC
;
5984 cfg
.cfghdr
.hdr
= &header
;
5987 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
5990 if (mpt_config(ioc
, &cfg
) != 0)
5993 if (header
.PageLength
== 0)
5996 iocpage2sz
= header
.PageLength
* 4;
5997 pIoc2
= pci_alloc_consistent(ioc
->pcidev
, iocpage2sz
, &ioc2_dma
);
6001 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
6002 cfg
.physAddr
= ioc2_dma
;
6003 if (mpt_config(ioc
, &cfg
) != 0)
6006 mem
= kmalloc(iocpage2sz
, GFP_KERNEL
);
6012 memcpy(mem
, (u8
*)pIoc2
, iocpage2sz
);
6013 ioc
->raid_data
.pIocPg2
= (IOCPage2_t
*) mem
;
6015 mpt_read_ioc_pg_3(ioc
);
6017 for (i
= 0; i
< pIoc2
->NumActiveVolumes
; i
++)
6018 mpt_inactive_raid_volumes(ioc
,
6019 pIoc2
->RaidVolume
[i
].VolumeBus
,
6020 pIoc2
->RaidVolume
[i
].VolumeID
);
6023 pci_free_consistent(ioc
->pcidev
, iocpage2sz
, pIoc2
, ioc2_dma
);
6029 mpt_read_ioc_pg_3(MPT_ADAPTER
*ioc
)
6034 ConfigPageHeader_t header
;
6035 dma_addr_t ioc3_dma
;
6038 /* Free the old page
6040 kfree(ioc
->raid_data
.pIocPg3
);
6041 ioc
->raid_data
.pIocPg3
= NULL
;
6043 /* There is at least one physical disk.
6044 * Read and save IOC Page 3
6046 header
.PageVersion
= 0;
6047 header
.PageLength
= 0;
6048 header
.PageNumber
= 3;
6049 header
.PageType
= MPI_CONFIG_PAGETYPE_IOC
;
6050 cfg
.cfghdr
.hdr
= &header
;
6053 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
6056 if (mpt_config(ioc
, &cfg
) != 0)
6059 if (header
.PageLength
== 0)
6062 /* Read Header good, alloc memory
6064 iocpage3sz
= header
.PageLength
* 4;
6065 pIoc3
= pci_alloc_consistent(ioc
->pcidev
, iocpage3sz
, &ioc3_dma
);
6069 /* Read the Page and save the data
6070 * into malloc'd memory.
6072 cfg
.physAddr
= ioc3_dma
;
6073 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
6074 if (mpt_config(ioc
, &cfg
) == 0) {
6075 mem
= kmalloc(iocpage3sz
, GFP_KERNEL
);
6077 memcpy(mem
, (u8
*)pIoc3
, iocpage3sz
);
6078 ioc
->raid_data
.pIocPg3
= (IOCPage3_t
*) mem
;
6082 pci_free_consistent(ioc
->pcidev
, iocpage3sz
, pIoc3
, ioc3_dma
);
6088 mpt_read_ioc_pg_4(MPT_ADAPTER
*ioc
)
6092 ConfigPageHeader_t header
;
6093 dma_addr_t ioc4_dma
;
6096 /* Read and save IOC Page 4
6098 header
.PageVersion
= 0;
6099 header
.PageLength
= 0;
6100 header
.PageNumber
= 4;
6101 header
.PageType
= MPI_CONFIG_PAGETYPE_IOC
;
6102 cfg
.cfghdr
.hdr
= &header
;
6105 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
6108 if (mpt_config(ioc
, &cfg
) != 0)
6111 if (header
.PageLength
== 0)
6114 if ( (pIoc4
= ioc
->spi_data
.pIocPg4
) == NULL
) {
6115 iocpage4sz
= (header
.PageLength
+ 4) * 4; /* Allow 4 additional SEP's */
6116 pIoc4
= pci_alloc_consistent(ioc
->pcidev
, iocpage4sz
, &ioc4_dma
);
6119 ioc
->alloc_total
+= iocpage4sz
;
6121 ioc4_dma
= ioc
->spi_data
.IocPg4_dma
;
6122 iocpage4sz
= ioc
->spi_data
.IocPg4Sz
;
6125 /* Read the Page into dma memory.
6127 cfg
.physAddr
= ioc4_dma
;
6128 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
6129 if (mpt_config(ioc
, &cfg
) == 0) {
6130 ioc
->spi_data
.pIocPg4
= (IOCPage4_t
*) pIoc4
;
6131 ioc
->spi_data
.IocPg4_dma
= ioc4_dma
;
6132 ioc
->spi_data
.IocPg4Sz
= iocpage4sz
;
6134 pci_free_consistent(ioc
->pcidev
, iocpage4sz
, pIoc4
, ioc4_dma
);
6135 ioc
->spi_data
.pIocPg4
= NULL
;
6136 ioc
->alloc_total
-= iocpage4sz
;
6141 mpt_read_ioc_pg_1(MPT_ADAPTER
*ioc
)
6145 ConfigPageHeader_t header
;
6146 dma_addr_t ioc1_dma
;
6150 /* Check the Coalescing Timeout in IOC Page 1
6152 header
.PageVersion
= 0;
6153 header
.PageLength
= 0;
6154 header
.PageNumber
= 1;
6155 header
.PageType
= MPI_CONFIG_PAGETYPE_IOC
;
6156 cfg
.cfghdr
.hdr
= &header
;
6159 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
6162 if (mpt_config(ioc
, &cfg
) != 0)
6165 if (header
.PageLength
== 0)
6168 /* Read Header good, alloc memory
6170 iocpage1sz
= header
.PageLength
* 4;
6171 pIoc1
= pci_alloc_consistent(ioc
->pcidev
, iocpage1sz
, &ioc1_dma
);
6175 /* Read the Page and check coalescing timeout
6177 cfg
.physAddr
= ioc1_dma
;
6178 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
6179 if (mpt_config(ioc
, &cfg
) == 0) {
6181 tmp
= le32_to_cpu(pIoc1
->Flags
) & MPI_IOCPAGE1_REPLY_COALESCING
;
6182 if (tmp
== MPI_IOCPAGE1_REPLY_COALESCING
) {
6183 tmp
= le32_to_cpu(pIoc1
->CoalescingTimeout
);
6185 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Coalescing Enabled Timeout = %d\n",
6188 if (tmp
> MPT_COALESCING_TIMEOUT
) {
6189 pIoc1
->CoalescingTimeout
= cpu_to_le32(MPT_COALESCING_TIMEOUT
);
6191 /* Write NVRAM and current
6194 cfg
.action
= MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT
;
6195 if (mpt_config(ioc
, &cfg
) == 0) {
6196 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Reset Current Coalescing Timeout to = %d\n",
6197 ioc
->name
, MPT_COALESCING_TIMEOUT
));
6199 cfg
.action
= MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM
;
6200 if (mpt_config(ioc
, &cfg
) == 0) {
6201 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
6202 "Reset NVRAM Coalescing Timeout to = %d\n",
6203 ioc
->name
, MPT_COALESCING_TIMEOUT
));
6205 dprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
6206 "Reset NVRAM Coalescing Timeout Failed\n",
6211 dprintk(ioc
, printk(MYIOC_s_WARN_FMT
6212 "Reset of Current Coalescing Timeout Failed!\n",
6218 dprintk(ioc
, printk(MYIOC_s_WARN_FMT
"Coalescing Disabled\n", ioc
->name
));
6222 pci_free_consistent(ioc
->pcidev
, iocpage1sz
, pIoc1
, ioc1_dma
);
6228 mpt_get_manufacturing_pg_0(MPT_ADAPTER
*ioc
)
6231 ConfigPageHeader_t hdr
;
6233 ManufacturingPage0_t
*pbuf
= NULL
;
6235 memset(&cfg
, 0 , sizeof(CONFIGPARMS
));
6236 memset(&hdr
, 0 , sizeof(ConfigPageHeader_t
));
6238 hdr
.PageType
= MPI_CONFIG_PAGETYPE_MANUFACTURING
;
6239 cfg
.cfghdr
.hdr
= &hdr
;
6241 cfg
.action
= MPI_CONFIG_ACTION_PAGE_HEADER
;
6244 if (mpt_config(ioc
, &cfg
) != 0)
6247 if (!cfg
.cfghdr
.hdr
->PageLength
)
6250 cfg
.action
= MPI_CONFIG_ACTION_PAGE_READ_CURRENT
;
6251 pbuf
= pci_alloc_consistent(ioc
->pcidev
, hdr
.PageLength
* 4, &buf_dma
);
6255 cfg
.physAddr
= buf_dma
;
6257 if (mpt_config(ioc
, &cfg
) != 0)
6260 memcpy(ioc
->board_name
, pbuf
->BoardName
, sizeof(ioc
->board_name
));
6261 memcpy(ioc
->board_assembly
, pbuf
->BoardAssembly
, sizeof(ioc
->board_assembly
));
6262 memcpy(ioc
->board_tracer
, pbuf
->BoardTracerNumber
, sizeof(ioc
->board_tracer
));
6267 pci_free_consistent(ioc
->pcidev
, hdr
.PageLength
* 4, pbuf
, buf_dma
);
6270 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6272 * SendEventNotification - Send EventNotification (on or off) request to adapter
6273 * @ioc: Pointer to MPT_ADAPTER structure
6274 * @EvSwitch: Event switch flags
6275 * @sleepFlag: Specifies whether the process can sleep
6278 SendEventNotification(MPT_ADAPTER
*ioc
, u8 EvSwitch
, int sleepFlag
)
6280 EventNotification_t evn
;
6281 MPIDefaultReply_t reply_buf
;
6283 memset(&evn
, 0, sizeof(EventNotification_t
));
6284 memset(&reply_buf
, 0, sizeof(MPIDefaultReply_t
));
6286 evn
.Function
= MPI_FUNCTION_EVENT_NOTIFICATION
;
6287 evn
.Switch
= EvSwitch
;
6288 evn
.MsgContext
= cpu_to_le32(mpt_base_index
<< 16);
6290 devtverboseprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
6291 "Sending EventNotification (%d) request %p\n",
6292 ioc
->name
, EvSwitch
, &evn
));
6294 return mpt_handshake_req_reply_wait(ioc
, sizeof(EventNotification_t
),
6295 (u32
*)&evn
, sizeof(MPIDefaultReply_t
), (u16
*)&reply_buf
, 30,
6299 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6301 * SendEventAck - Send EventAck request to MPT adapter.
6302 * @ioc: Pointer to MPT_ADAPTER structure
6303 * @evnp: Pointer to original EventNotification request
6306 SendEventAck(MPT_ADAPTER
*ioc
, EventNotificationReply_t
*evnp
)
6310 if ((pAck
= (EventAck_t
*) mpt_get_msg_frame(mpt_base_index
, ioc
)) == NULL
) {
6311 dfailprintk(ioc
, printk(MYIOC_s_WARN_FMT
"%s, no msg frames!!\n",
6312 ioc
->name
, __func__
));
6316 devtverboseprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"Sending EventAck\n", ioc
->name
));
6318 pAck
->Function
= MPI_FUNCTION_EVENT_ACK
;
6319 pAck
->ChainOffset
= 0;
6320 pAck
->Reserved
[0] = pAck
->Reserved
[1] = 0;
6322 pAck
->Reserved1
[0] = pAck
->Reserved1
[1] = pAck
->Reserved1
[2] = 0;
6323 pAck
->Event
= evnp
->Event
;
6324 pAck
->EventContext
= evnp
->EventContext
;
6326 mpt_put_msg_frame(mpt_base_index
, ioc
, (MPT_FRAME_HDR
*)pAck
);
6331 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6333 * mpt_config - Generic function to issue config message
6334 * @ioc: Pointer to an adapter structure
6335 * @pCfg: Pointer to a configuration structure. Struct contains
6336 * action, page address, direction, physical address
6337 * and pointer to a configuration page header
6338 * Page header is updated.
6340 * Returns 0 for success
6341 * -EPERM if not allowed due to ISR context
6342 * -EAGAIN if no msg frames currently available
6343 * -EFAULT for non-successful reply or no reply (timeout)
6346 mpt_config(MPT_ADAPTER
*ioc
, CONFIGPARMS
*pCfg
)
6349 ConfigReply_t
*pReply
;
6350 ConfigExtendedPageHeader_t
*pExtHdr
= NULL
;
6356 u8 page_type
= 0, extend_page
;
6357 unsigned long timeleft
;
6358 unsigned long flags
;
6360 u8 issue_hard_reset
= 0;
6363 /* Prevent calling wait_event() (below), if caller happens
6364 * to be in ISR context, because that is fatal!
6366 in_isr
= in_interrupt();
6368 dcprintk(ioc
, printk(MYIOC_s_WARN_FMT
"Config request not allowed in ISR context!\n",
6373 /* don't send a config page during diag reset */
6374 spin_lock_irqsave(&ioc
->taskmgmt_lock
, flags
);
6375 if (ioc
->ioc_reset_in_progress
) {
6376 dfailprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
6377 "%s: busy with host reset\n", ioc
->name
, __func__
));
6378 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
6381 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
6383 /* don't send if no chance of success */
6385 mpt_GetIocState(ioc
, 1) != MPI_IOC_STATE_OPERATIONAL
) {
6386 dfailprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
6387 "%s: ioc not operational, %d, %xh\n",
6388 ioc
->name
, __func__
, ioc
->active
,
6389 mpt_GetIocState(ioc
, 0)));
6394 mutex_lock(&ioc
->mptbase_cmds
.mutex
);
6395 /* init the internal cmd struct */
6396 memset(ioc
->mptbase_cmds
.reply
, 0 , MPT_DEFAULT_FRAME_SIZE
);
6397 INITIALIZE_MGMT_STATUS(ioc
->mptbase_cmds
.status
)
6399 /* Get and Populate a free Frame
6401 if ((mf
= mpt_get_msg_frame(mpt_base_index
, ioc
)) == NULL
) {
6402 dcprintk(ioc
, printk(MYIOC_s_WARN_FMT
6403 "mpt_config: no msg frames!\n", ioc
->name
));
6408 pReq
= (Config_t
*)mf
;
6409 pReq
->Action
= pCfg
->action
;
6411 pReq
->ChainOffset
= 0;
6412 pReq
->Function
= MPI_FUNCTION_CONFIG
;
6414 /* Assume page type is not extended and clear "reserved" fields. */
6415 pReq
->ExtPageLength
= 0;
6416 pReq
->ExtPageType
= 0;
6419 for (ii
=0; ii
< 8; ii
++)
6420 pReq
->Reserved2
[ii
] = 0;
6422 pReq
->Header
.PageVersion
= pCfg
->cfghdr
.hdr
->PageVersion
;
6423 pReq
->Header
.PageLength
= pCfg
->cfghdr
.hdr
->PageLength
;
6424 pReq
->Header
.PageNumber
= pCfg
->cfghdr
.hdr
->PageNumber
;
6425 pReq
->Header
.PageType
= (pCfg
->cfghdr
.hdr
->PageType
& MPI_CONFIG_PAGETYPE_MASK
);
6427 if ((pCfg
->cfghdr
.hdr
->PageType
& MPI_CONFIG_PAGETYPE_MASK
) == MPI_CONFIG_PAGETYPE_EXTENDED
) {
6428 pExtHdr
= (ConfigExtendedPageHeader_t
*)pCfg
->cfghdr
.ehdr
;
6429 pReq
->ExtPageLength
= cpu_to_le16(pExtHdr
->ExtPageLength
);
6430 pReq
->ExtPageType
= pExtHdr
->ExtPageType
;
6431 pReq
->Header
.PageType
= MPI_CONFIG_PAGETYPE_EXTENDED
;
6433 /* Page Length must be treated as a reserved field for the
6436 pReq
->Header
.PageLength
= 0;
6439 pReq
->PageAddress
= cpu_to_le32(pCfg
->pageAddr
);
6441 /* Add a SGE to the config request.
6444 flagsLength
= MPT_SGE_FLAGS_SSIMPLE_WRITE
;
6446 flagsLength
= MPT_SGE_FLAGS_SSIMPLE_READ
;
6448 if ((pCfg
->cfghdr
.hdr
->PageType
& MPI_CONFIG_PAGETYPE_MASK
) ==
6449 MPI_CONFIG_PAGETYPE_EXTENDED
) {
6450 flagsLength
|= pExtHdr
->ExtPageLength
* 4;
6451 page_type
= pReq
->ExtPageType
;
6454 flagsLength
|= pCfg
->cfghdr
.hdr
->PageLength
* 4;
6455 page_type
= pReq
->Header
.PageType
;
6459 dcprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
6460 "Sending Config request type 0x%x, page 0x%x and action %d\n",
6461 ioc
->name
, page_type
, pReq
->Header
.PageNumber
, pReq
->Action
));
6463 ioc
->add_sge((char *)&pReq
->PageBufferSGE
, flagsLength
, pCfg
->physAddr
);
6464 timeout
= (pCfg
->timeout
< 15) ? HZ
*15 : HZ
*pCfg
->timeout
;
6465 mpt_put_msg_frame(mpt_base_index
, ioc
, mf
);
6466 timeleft
= wait_for_completion_timeout(&ioc
->mptbase_cmds
.done
,
6468 if (!(ioc
->mptbase_cmds
.status
& MPT_MGMT_STATUS_COMMAND_GOOD
)) {
6470 dfailprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
6471 "Failed Sending Config request type 0x%x, page 0x%x,"
6472 " action %d, status %xh, time left %ld\n\n",
6473 ioc
->name
, page_type
, pReq
->Header
.PageNumber
,
6474 pReq
->Action
, ioc
->mptbase_cmds
.status
, timeleft
));
6475 if (ioc
->mptbase_cmds
.status
& MPT_MGMT_STATUS_DID_IOCRESET
)
6478 spin_lock_irqsave(&ioc
->taskmgmt_lock
, flags
);
6479 if (ioc
->ioc_reset_in_progress
) {
6480 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
,
6482 printk(MYIOC_s_INFO_FMT
"%s: host reset in"
6483 " progress mpt_config timed out.!!\n",
6484 __func__
, ioc
->name
);
6487 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
6488 issue_hard_reset
= 1;
6493 if (!(ioc
->mptbase_cmds
.status
& MPT_MGMT_STATUS_RF_VALID
)) {
6497 pReply
= (ConfigReply_t
*)ioc
->mptbase_cmds
.reply
;
6498 ret
= le16_to_cpu(pReply
->IOCStatus
) & MPI_IOCSTATUS_MASK
;
6499 if (ret
== MPI_IOCSTATUS_SUCCESS
) {
6501 pCfg
->cfghdr
.ehdr
->ExtPageLength
=
6502 le16_to_cpu(pReply
->ExtPageLength
);
6503 pCfg
->cfghdr
.ehdr
->ExtPageType
=
6504 pReply
->ExtPageType
;
6506 pCfg
->cfghdr
.hdr
->PageVersion
= pReply
->Header
.PageVersion
;
6507 pCfg
->cfghdr
.hdr
->PageLength
= pReply
->Header
.PageLength
;
6508 pCfg
->cfghdr
.hdr
->PageNumber
= pReply
->Header
.PageNumber
;
6509 pCfg
->cfghdr
.hdr
->PageType
= pReply
->Header
.PageType
;
6514 printk(MYIOC_s_INFO_FMT
"Retry completed "
6515 "ret=0x%x timeleft=%ld\n",
6516 ioc
->name
, ret
, timeleft
);
6518 dcprintk(ioc
, printk(KERN_DEBUG
"IOCStatus=%04xh, IOCLogInfo=%08xh\n",
6519 ret
, le32_to_cpu(pReply
->IOCLogInfo
)));
6523 CLEAR_MGMT_STATUS(ioc
->mptbase_cmds
.status
)
6524 mutex_unlock(&ioc
->mptbase_cmds
.mutex
);
6525 if (issue_hard_reset
) {
6526 issue_hard_reset
= 0;
6527 printk(MYIOC_s_WARN_FMT
6528 "Issuing Reset from %s!!, doorbell=0x%08x\n",
6529 ioc
->name
, __func__
, mpt_GetIocState(ioc
, 0));
6530 if (retry_count
== 0) {
6531 if (mpt_Soft_Hard_ResetHandler(ioc
, CAN_SLEEP
) != 0)
6534 mpt_HardResetHandler(ioc
, CAN_SLEEP
);
6536 mpt_free_msg_frame(ioc
, mf
);
6537 /* attempt one retry for a timed out command */
6538 if (retry_count
< 2) {
6539 printk(MYIOC_s_INFO_FMT
6540 "Attempting Retry Config request"
6541 " type 0x%x, page 0x%x,"
6542 " action %d\n", ioc
->name
, page_type
,
6543 pCfg
->cfghdr
.hdr
->PageNumber
, pCfg
->action
);
6552 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6554 * mpt_ioc_reset - Base cleanup for hard reset
6555 * @ioc: Pointer to the adapter structure
6556 * @reset_phase: Indicates pre- or post-reset functionality
6558 * Remark: Frees resources with internally generated commands.
6561 mpt_ioc_reset(MPT_ADAPTER
*ioc
, int reset_phase
)
6563 switch (reset_phase
) {
6564 case MPT_IOC_SETUP_RESET
:
6565 ioc
->taskmgmt_quiesce_io
= 1;
6566 dtmprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
6567 "%s: MPT_IOC_SETUP_RESET\n", ioc
->name
, __func__
));
6569 case MPT_IOC_PRE_RESET
:
6570 dtmprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
6571 "%s: MPT_IOC_PRE_RESET\n", ioc
->name
, __func__
));
6573 case MPT_IOC_POST_RESET
:
6574 dtmprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
6575 "%s: MPT_IOC_POST_RESET\n", ioc
->name
, __func__
));
6576 /* wake up mptbase_cmds */
6577 if (ioc
->mptbase_cmds
.status
& MPT_MGMT_STATUS_PENDING
) {
6578 ioc
->mptbase_cmds
.status
|=
6579 MPT_MGMT_STATUS_DID_IOCRESET
;
6580 complete(&ioc
->mptbase_cmds
.done
);
6582 /* wake up taskmgmt_cmds */
6583 if (ioc
->taskmgmt_cmds
.status
& MPT_MGMT_STATUS_PENDING
) {
6584 ioc
->taskmgmt_cmds
.status
|=
6585 MPT_MGMT_STATUS_DID_IOCRESET
;
6586 complete(&ioc
->taskmgmt_cmds
.done
);
6593 return 1; /* currently means nothing really */
6597 #ifdef CONFIG_PROC_FS /* { */
6598 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6600 * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
6602 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6604 * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
6606 * Returns 0 for success, non-zero for failure.
6609 procmpt_create(void)
6611 mpt_proc_root_dir
= proc_mkdir(MPT_PROCFS_MPTBASEDIR
, NULL
);
6612 if (mpt_proc_root_dir
== NULL
)
6615 proc_create("summary", S_IRUGO
, mpt_proc_root_dir
, &mpt_summary_proc_fops
);
6616 proc_create("version", S_IRUGO
, mpt_proc_root_dir
, &mpt_version_proc_fops
);
6620 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6622 * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
6624 * Returns 0 for success, non-zero for failure.
6627 procmpt_destroy(void)
6629 remove_proc_entry("version", mpt_proc_root_dir
);
6630 remove_proc_entry("summary", mpt_proc_root_dir
);
6631 remove_proc_entry(MPT_PROCFS_MPTBASEDIR
, NULL
);
6634 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6636 * Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary.
6638 static void seq_mpt_print_ioc_summary(MPT_ADAPTER
*ioc
, struct seq_file
*m
, int showlan
);
6640 static int mpt_summary_proc_show(struct seq_file
*m
, void *v
)
6642 MPT_ADAPTER
*ioc
= m
->private;
6645 seq_mpt_print_ioc_summary(ioc
, m
, 1);
6647 list_for_each_entry(ioc
, &ioc_list
, list
) {
6648 seq_mpt_print_ioc_summary(ioc
, m
, 1);
6655 static int mpt_summary_proc_open(struct inode
*inode
, struct file
*file
)
6657 return single_open(file
, mpt_summary_proc_show
, PDE(inode
)->data
);
6660 static const struct file_operations mpt_summary_proc_fops
= {
6661 .owner
= THIS_MODULE
,
6662 .open
= mpt_summary_proc_open
,
6664 .llseek
= seq_lseek
,
6665 .release
= single_release
,
6668 static int mpt_version_proc_show(struct seq_file
*m
, void *v
)
6671 int scsi
, fc
, sas
, lan
, ctl
, targ
, dmp
;
6674 seq_printf(m
, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON
);
6675 seq_printf(m
, " Fusion MPT base driver\n");
6677 scsi
= fc
= sas
= lan
= ctl
= targ
= dmp
= 0;
6678 for (cb_idx
= MPT_MAX_PROTOCOL_DRIVERS
-1; cb_idx
; cb_idx
--) {
6680 if (MptCallbacks
[cb_idx
]) {
6681 switch (MptDriverClass
[cb_idx
]) {
6683 if (!scsi
++) drvname
= "SPI host";
6686 if (!fc
++) drvname
= "FC host";
6689 if (!sas
++) drvname
= "SAS host";
6692 if (!lan
++) drvname
= "LAN";
6695 if (!targ
++) drvname
= "SCSI target";
6698 if (!ctl
++) drvname
= "ioctl";
6703 seq_printf(m
, " Fusion MPT %s driver\n", drvname
);
6710 static int mpt_version_proc_open(struct inode
*inode
, struct file
*file
)
6712 return single_open(file
, mpt_version_proc_show
, NULL
);
6715 static const struct file_operations mpt_version_proc_fops
= {
6716 .owner
= THIS_MODULE
,
6717 .open
= mpt_version_proc_open
,
6719 .llseek
= seq_lseek
,
6720 .release
= single_release
,
6723 static int mpt_iocinfo_proc_show(struct seq_file
*m
, void *v
)
6725 MPT_ADAPTER
*ioc
= m
->private;
6730 mpt_get_fw_exp_ver(expVer
, ioc
);
6732 seq_printf(m
, "%s:", ioc
->name
);
6733 if (ioc
->facts
.Flags
& MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT
)
6734 seq_printf(m
, " (f/w download boot flag set)");
6735 // if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
6736 // seq_printf(m, " CONFIG_CHECKSUM_FAIL!");
6738 seq_printf(m
, "\n ProductID = 0x%04x (%s)\n",
6739 ioc
->facts
.ProductID
,
6741 seq_printf(m
, " FWVersion = 0x%08x%s", ioc
->facts
.FWVersion
.Word
, expVer
);
6742 if (ioc
->facts
.FWImageSize
)
6743 seq_printf(m
, " (fw_size=%d)", ioc
->facts
.FWImageSize
);
6744 seq_printf(m
, "\n MsgVersion = 0x%04x\n", ioc
->facts
.MsgVersion
);
6745 seq_printf(m
, " FirstWhoInit = 0x%02x\n", ioc
->FirstWhoInit
);
6746 seq_printf(m
, " EventState = 0x%02x\n", ioc
->facts
.EventState
);
6748 seq_printf(m
, " CurrentHostMfaHighAddr = 0x%08x\n",
6749 ioc
->facts
.CurrentHostMfaHighAddr
);
6750 seq_printf(m
, " CurrentSenseBufferHighAddr = 0x%08x\n",
6751 ioc
->facts
.CurrentSenseBufferHighAddr
);
6753 seq_printf(m
, " MaxChainDepth = 0x%02x frames\n", ioc
->facts
.MaxChainDepth
);
6754 seq_printf(m
, " MinBlockSize = 0x%02x bytes\n", 4*ioc
->facts
.BlockSize
);
6756 seq_printf(m
, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
6757 (void *)ioc
->req_frames
, (void *)(ulong
)ioc
->req_frames_dma
);
6759 * Rounding UP to nearest 4-kB boundary here...
6761 sz
= (ioc
->req_sz
* ioc
->req_depth
) + 128;
6762 sz
= ((sz
+ 0x1000UL
- 1UL) / 0x1000) * 0x1000;
6763 seq_printf(m
, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
6764 ioc
->req_sz
, ioc
->req_depth
, ioc
->req_sz
*ioc
->req_depth
, sz
);
6765 seq_printf(m
, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
6766 4*ioc
->facts
.RequestFrameSize
,
6767 ioc
->facts
.GlobalCredits
);
6769 seq_printf(m
, " Frames @ 0x%p (Dma @ 0x%p)\n",
6770 (void *)ioc
->alloc
, (void *)(ulong
)ioc
->alloc_dma
);
6771 sz
= (ioc
->reply_sz
* ioc
->reply_depth
) + 128;
6772 seq_printf(m
, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
6773 ioc
->reply_sz
, ioc
->reply_depth
, ioc
->reply_sz
*ioc
->reply_depth
, sz
);
6774 seq_printf(m
, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
6775 ioc
->facts
.CurReplyFrameSize
,
6776 ioc
->facts
.ReplyQueueDepth
);
6778 seq_printf(m
, " MaxDevices = %d\n",
6779 (ioc
->facts
.MaxDevices
==0) ? 255 : ioc
->facts
.MaxDevices
);
6780 seq_printf(m
, " MaxBuses = %d\n", ioc
->facts
.MaxBuses
);
6783 for (p
=0; p
< ioc
->facts
.NumberOfPorts
; p
++) {
6784 seq_printf(m
, " PortNumber = %d (of %d)\n",
6786 ioc
->facts
.NumberOfPorts
);
6787 if (ioc
->bus_type
== FC
) {
6788 if (ioc
->pfacts
[p
].ProtocolFlags
& MPI_PORTFACTS_PROTOCOL_LAN
) {
6789 u8
*a
= (u8
*)&ioc
->lan_cnfg_page1
.HardwareAddressLow
;
6790 seq_printf(m
, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
6791 a
[5], a
[4], a
[3], a
[2], a
[1], a
[0]);
6793 seq_printf(m
, " WWN = %08X%08X:%08X%08X\n",
6794 ioc
->fc_port_page0
[p
].WWNN
.High
,
6795 ioc
->fc_port_page0
[p
].WWNN
.Low
,
6796 ioc
->fc_port_page0
[p
].WWPN
.High
,
6797 ioc
->fc_port_page0
[p
].WWPN
.Low
);
6804 static int mpt_iocinfo_proc_open(struct inode
*inode
, struct file
*file
)
6806 return single_open(file
, mpt_iocinfo_proc_show
, PDE(inode
)->data
);
6809 static const struct file_operations mpt_iocinfo_proc_fops
= {
6810 .owner
= THIS_MODULE
,
6811 .open
= mpt_iocinfo_proc_open
,
6813 .llseek
= seq_lseek
,
6814 .release
= single_release
,
6816 #endif /* CONFIG_PROC_FS } */
6818 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6820 mpt_get_fw_exp_ver(char *buf
, MPT_ADAPTER
*ioc
)
6823 if ((ioc
->facts
.FWVersion
.Word
>> 24) == 0x0E) {
6824 sprintf(buf
, " (Exp %02d%02d)",
6825 (ioc
->facts
.FWVersion
.Word
>> 16) & 0x00FF, /* Month */
6826 (ioc
->facts
.FWVersion
.Word
>> 8) & 0x1F); /* Day */
6829 if ((ioc
->facts
.FWVersion
.Word
>> 8) & 0x80)
6830 strcat(buf
, " [MDBG]");
6834 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6836 * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
6837 * @ioc: Pointer to MPT_ADAPTER structure
6838 * @buffer: Pointer to buffer where IOC summary info should be written
6839 * @size: Pointer to number of bytes we wrote (set by this routine)
6840 * @len: Offset at which to start writing in buffer
6841 * @showlan: Display LAN stuff?
6843 * This routine writes (english readable) ASCII text, which represents
6844 * a summary of IOC information, to a buffer.
6847 mpt_print_ioc_summary(MPT_ADAPTER
*ioc
, char *buffer
, int *size
, int len
, int showlan
)
6852 mpt_get_fw_exp_ver(expVer
, ioc
);
6855 * Shorter summary of attached ioc's...
6857 y
= sprintf(buffer
+len
, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
6860 MPT_FW_REV_MAGIC_ID_STRING
, /* "FwRev=" or somesuch */
6861 ioc
->facts
.FWVersion
.Word
,
6863 ioc
->facts
.NumberOfPorts
,
6866 if (showlan
&& (ioc
->pfacts
[0].ProtocolFlags
& MPI_PORTFACTS_PROTOCOL_LAN
)) {
6867 u8
*a
= (u8
*)&ioc
->lan_cnfg_page1
.HardwareAddressLow
;
6868 y
+= sprintf(buffer
+len
+y
, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
6869 a
[5], a
[4], a
[3], a
[2], a
[1], a
[0]);
6872 y
+= sprintf(buffer
+len
+y
, ", IRQ=%d", ioc
->pci_irq
);
6875 y
+= sprintf(buffer
+len
+y
, " (disabled)");
6877 y
+= sprintf(buffer
+len
+y
, "\n");
6882 static void seq_mpt_print_ioc_summary(MPT_ADAPTER
*ioc
, struct seq_file
*m
, int showlan
)
6886 mpt_get_fw_exp_ver(expVer
, ioc
);
6889 * Shorter summary of attached ioc's...
6891 seq_printf(m
, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
6894 MPT_FW_REV_MAGIC_ID_STRING
, /* "FwRev=" or somesuch */
6895 ioc
->facts
.FWVersion
.Word
,
6897 ioc
->facts
.NumberOfPorts
,
6900 if (showlan
&& (ioc
->pfacts
[0].ProtocolFlags
& MPI_PORTFACTS_PROTOCOL_LAN
)) {
6901 u8
*a
= (u8
*)&ioc
->lan_cnfg_page1
.HardwareAddressLow
;
6902 seq_printf(m
, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
6903 a
[5], a
[4], a
[3], a
[2], a
[1], a
[0]);
6906 seq_printf(m
, ", IRQ=%d", ioc
->pci_irq
);
6909 seq_printf(m
, " (disabled)");
6915 * mpt_set_taskmgmt_in_progress_flag - set flags associated with task management
6916 * @ioc: Pointer to MPT_ADAPTER structure
6918 * Returns 0 for SUCCESS or -1 if FAILED.
6920 * If -1 is return, then it was not possible to set the flags
6923 mpt_set_taskmgmt_in_progress_flag(MPT_ADAPTER
*ioc
)
6925 unsigned long flags
;
6928 spin_lock_irqsave(&ioc
->taskmgmt_lock
, flags
);
6929 if (ioc
->ioc_reset_in_progress
|| ioc
->taskmgmt_in_progress
||
6930 (ioc
->alt_ioc
&& ioc
->alt_ioc
->taskmgmt_in_progress
)) {
6935 ioc
->taskmgmt_in_progress
= 1;
6936 ioc
->taskmgmt_quiesce_io
= 1;
6938 ioc
->alt_ioc
->taskmgmt_in_progress
= 1;
6939 ioc
->alt_ioc
->taskmgmt_quiesce_io
= 1;
6942 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
6945 EXPORT_SYMBOL(mpt_set_taskmgmt_in_progress_flag
);
6948 * mpt_clear_taskmgmt_in_progress_flag - clear flags associated with task management
6949 * @ioc: Pointer to MPT_ADAPTER structure
6953 mpt_clear_taskmgmt_in_progress_flag(MPT_ADAPTER
*ioc
)
6955 unsigned long flags
;
6957 spin_lock_irqsave(&ioc
->taskmgmt_lock
, flags
);
6958 ioc
->taskmgmt_in_progress
= 0;
6959 ioc
->taskmgmt_quiesce_io
= 0;
6961 ioc
->alt_ioc
->taskmgmt_in_progress
= 0;
6962 ioc
->alt_ioc
->taskmgmt_quiesce_io
= 0;
6964 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
6966 EXPORT_SYMBOL(mpt_clear_taskmgmt_in_progress_flag
);
6970 * mpt_halt_firmware - Halts the firmware if it is operational and panic
6972 * @ioc: Pointer to MPT_ADAPTER structure
6976 mpt_halt_firmware(MPT_ADAPTER
*ioc
)
6980 ioc_raw_state
= mpt_GetIocState(ioc
, 0);
6982 if ((ioc_raw_state
& MPI_IOC_STATE_MASK
) == MPI_IOC_STATE_FAULT
) {
6983 printk(MYIOC_s_ERR_FMT
"IOC is in FAULT state (%04xh)!!!\n",
6984 ioc
->name
, ioc_raw_state
& MPI_DOORBELL_DATA_MASK
);
6985 panic("%s: IOC Fault (%04xh)!!!\n", ioc
->name
,
6986 ioc_raw_state
& MPI_DOORBELL_DATA_MASK
);
6988 CHIPREG_WRITE32(&ioc
->chip
->Doorbell
, 0xC0FFEE00);
6989 panic("%s: Firmware is halted due to command timeout\n",
6993 EXPORT_SYMBOL(mpt_halt_firmware
);
6996 * mpt_SoftResetHandler - Issues a less expensive reset
6997 * @ioc: Pointer to MPT_ADAPTER structure
6998 * @sleepFlag: Indicates if sleep or schedule must be called.
7000 * Returns 0 for SUCCESS or -1 if FAILED.
7002 * Message Unit Reset - instructs the IOC to reset the Reply Post and
7003 * Free FIFO's. All the Message Frames on Reply Free FIFO are discarded.
7004 * All posted buffers are freed, and event notification is turned off.
7005 * IOC doesn't reply to any outstanding request. This will transfer IOC
7009 mpt_SoftResetHandler(MPT_ADAPTER
*ioc
, int sleepFlag
)
7014 unsigned long flags
;
7016 unsigned long time_count
;
7018 dtmprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"SoftResetHandler Entered!\n",
7021 ioc_state
= mpt_GetIocState(ioc
, 0) & MPI_IOC_STATE_MASK
;
7023 if (mpt_fwfault_debug
)
7024 mpt_halt_firmware(ioc
);
7026 if (ioc_state
== MPI_IOC_STATE_FAULT
||
7027 ioc_state
== MPI_IOC_STATE_RESET
) {
7028 dtmprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
7029 "skipping, either in FAULT or RESET state!\n", ioc
->name
));
7033 if (ioc
->bus_type
== FC
) {
7034 dtmprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
7035 "skipping, because the bus type is FC!\n", ioc
->name
));
7039 spin_lock_irqsave(&ioc
->taskmgmt_lock
, flags
);
7040 if (ioc
->ioc_reset_in_progress
) {
7041 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
7044 ioc
->ioc_reset_in_progress
= 1;
7045 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
7049 for (cb_idx
= MPT_MAX_PROTOCOL_DRIVERS
-1; cb_idx
; cb_idx
--) {
7050 if (MptResetHandlers
[cb_idx
])
7051 mpt_signal_reset(cb_idx
, ioc
, MPT_IOC_SETUP_RESET
);
7054 spin_lock_irqsave(&ioc
->taskmgmt_lock
, flags
);
7055 if (ioc
->taskmgmt_in_progress
) {
7056 ioc
->ioc_reset_in_progress
= 0;
7057 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
7060 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
7061 /* Disable reply interrupts (also blocks FreeQ) */
7062 CHIPREG_WRITE32(&ioc
->chip
->IntMask
, 0xFFFFFFFF);
7064 time_count
= jiffies
;
7066 rc
= SendIocReset(ioc
, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET
, sleepFlag
);
7068 for (cb_idx
= MPT_MAX_PROTOCOL_DRIVERS
-1; cb_idx
; cb_idx
--) {
7069 if (MptResetHandlers
[cb_idx
])
7070 mpt_signal_reset(cb_idx
, ioc
, MPT_IOC_PRE_RESET
);
7076 ioc_state
= mpt_GetIocState(ioc
, 0) & MPI_IOC_STATE_MASK
;
7077 if (ioc_state
!= MPI_IOC_STATE_READY
)
7080 for (ii
= 0; ii
< 5; ii
++) {
7081 /* Get IOC facts! Allow 5 retries */
7082 rc
= GetIocFacts(ioc
, sleepFlag
,
7083 MPT_HOSTEVENT_IOC_RECOVER
);
7086 if (sleepFlag
== CAN_SLEEP
)
7094 rc
= PrimeIocFifos(ioc
);
7098 rc
= SendIocInit(ioc
, sleepFlag
);
7102 rc
= SendEventNotification(ioc
, 1, sleepFlag
);
7106 if (ioc
->hard_resets
< -1)
7110 * At this point, we know soft reset succeeded.
7114 CHIPREG_WRITE32(&ioc
->chip
->IntMask
, MPI_HIM_DIM
);
7117 spin_lock_irqsave(&ioc
->taskmgmt_lock
, flags
);
7118 ioc
->ioc_reset_in_progress
= 0;
7119 ioc
->taskmgmt_quiesce_io
= 0;
7120 ioc
->taskmgmt_in_progress
= 0;
7121 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
7123 if (ioc
->active
) { /* otherwise, hard reset coming */
7124 for (cb_idx
= MPT_MAX_PROTOCOL_DRIVERS
-1; cb_idx
; cb_idx
--) {
7125 if (MptResetHandlers
[cb_idx
])
7126 mpt_signal_reset(cb_idx
, ioc
,
7127 MPT_IOC_POST_RESET
);
7131 dtmprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
7132 "SoftResetHandler: completed (%d seconds): %s\n",
7133 ioc
->name
, jiffies_to_msecs(jiffies
- time_count
)/1000,
7134 ((rc
== 0) ? "SUCCESS" : "FAILED")));
7140 * mpt_Soft_Hard_ResetHandler - Try less expensive reset
7141 * @ioc: Pointer to MPT_ADAPTER structure
7142 * @sleepFlag: Indicates if sleep or schedule must be called.
7144 * Returns 0 for SUCCESS or -1 if FAILED.
7145 * Try for softreset first, only if it fails go for expensive
7149 mpt_Soft_Hard_ResetHandler(MPT_ADAPTER
*ioc
, int sleepFlag
) {
7152 ret
= mpt_SoftResetHandler(ioc
, sleepFlag
);
7155 ret
= mpt_HardResetHandler(ioc
, sleepFlag
);
7158 EXPORT_SYMBOL(mpt_Soft_Hard_ResetHandler
);
7160 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
7164 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
7166 * mpt_HardResetHandler - Generic reset handler
7167 * @ioc: Pointer to MPT_ADAPTER structure
7168 * @sleepFlag: Indicates if sleep or schedule must be called.
7170 * Issues SCSI Task Management call based on input arg values.
7171 * If TaskMgmt fails, returns associated SCSI request.
7173 * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
7174 * or a non-interrupt thread. In the former, must not call schedule().
7176 * Note: A return of -1 is a FATAL error case, as it means a
7177 * FW reload/initialization failed.
7179 * Returns 0 for SUCCESS or -1 if FAILED.
7182 mpt_HardResetHandler(MPT_ADAPTER
*ioc
, int sleepFlag
)
7186 unsigned long flags
;
7187 unsigned long time_count
;
7189 dtmprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"HardResetHandler Entered!\n", ioc
->name
));
7191 printk(MYIOC_s_INFO_FMT
"HardResetHandler Entered!\n", ioc
->name
);
7192 printk("MF count 0x%x !\n", ioc
->mfcnt
);
7194 if (mpt_fwfault_debug
)
7195 mpt_halt_firmware(ioc
);
7197 /* Reset the adapter. Prevent more than 1 call to
7198 * mpt_do_ioc_recovery at any instant in time.
7200 spin_lock_irqsave(&ioc
->taskmgmt_lock
, flags
);
7201 if (ioc
->ioc_reset_in_progress
) {
7202 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
7203 ioc
->wait_on_reset_completion
= 1;
7206 } while (ioc
->ioc_reset_in_progress
== 1);
7207 ioc
->wait_on_reset_completion
= 0;
7208 return ioc
->reset_status
;
7210 if (ioc
->wait_on_reset_completion
) {
7211 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
7213 time_count
= jiffies
;
7216 ioc
->ioc_reset_in_progress
= 1;
7218 ioc
->alt_ioc
->ioc_reset_in_progress
= 1;
7219 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
7222 /* The SCSI driver needs to adjust timeouts on all current
7223 * commands prior to the diagnostic reset being issued.
7224 * Prevents timeouts occurring during a diagnostic reset...very bad.
7225 * For all other protocol drivers, this is a no-op.
7227 for (cb_idx
= MPT_MAX_PROTOCOL_DRIVERS
-1; cb_idx
; cb_idx
--) {
7228 if (MptResetHandlers
[cb_idx
]) {
7229 mpt_signal_reset(cb_idx
, ioc
, MPT_IOC_SETUP_RESET
);
7231 mpt_signal_reset(cb_idx
, ioc
->alt_ioc
,
7232 MPT_IOC_SETUP_RESET
);
7236 time_count
= jiffies
;
7237 rc
= mpt_do_ioc_recovery(ioc
, MPT_HOSTEVENT_IOC_RECOVER
, sleepFlag
);
7239 printk(KERN_WARNING MYNAM
7240 ": WARNING - (%d) Cannot recover %s, doorbell=0x%08x\n",
7241 rc
, ioc
->name
, mpt_GetIocState(ioc
, 0));
7243 if (ioc
->hard_resets
< -1)
7247 spin_lock_irqsave(&ioc
->taskmgmt_lock
, flags
);
7248 ioc
->ioc_reset_in_progress
= 0;
7249 ioc
->taskmgmt_quiesce_io
= 0;
7250 ioc
->taskmgmt_in_progress
= 0;
7251 ioc
->reset_status
= rc
;
7253 ioc
->alt_ioc
->ioc_reset_in_progress
= 0;
7254 ioc
->alt_ioc
->taskmgmt_quiesce_io
= 0;
7255 ioc
->alt_ioc
->taskmgmt_in_progress
= 0;
7257 spin_unlock_irqrestore(&ioc
->taskmgmt_lock
, flags
);
7259 for (cb_idx
= MPT_MAX_PROTOCOL_DRIVERS
-1; cb_idx
; cb_idx
--) {
7260 if (MptResetHandlers
[cb_idx
]) {
7261 mpt_signal_reset(cb_idx
, ioc
, MPT_IOC_POST_RESET
);
7263 mpt_signal_reset(cb_idx
,
7264 ioc
->alt_ioc
, MPT_IOC_POST_RESET
);
7269 printk(MYIOC_s_DEBUG_FMT
7270 "HardResetHandler: completed (%d seconds): %s\n", ioc
->name
,
7271 jiffies_to_msecs(jiffies
- time_count
)/1000, ((rc
== 0) ?
7272 "SUCCESS" : "FAILED")));
7277 #ifdef CONFIG_FUSION_LOGGING
7279 mpt_display_event_info(MPT_ADAPTER
*ioc
, EventNotificationReply_t
*pEventReply
)
7285 char *evStr
= ioc
->evStr
;
7287 event
= le32_to_cpu(pEventReply
->Event
) & 0xFF;
7288 evData0
= le32_to_cpu(pEventReply
->Data
[0]);
7291 case MPI_EVENT_NONE
:
7294 case MPI_EVENT_LOG_DATA
:
7297 case MPI_EVENT_STATE_CHANGE
:
7298 ds
= "State Change";
7300 case MPI_EVENT_UNIT_ATTENTION
:
7301 ds
= "Unit Attention";
7303 case MPI_EVENT_IOC_BUS_RESET
:
7304 ds
= "IOC Bus Reset";
7306 case MPI_EVENT_EXT_BUS_RESET
:
7307 ds
= "External Bus Reset";
7309 case MPI_EVENT_RESCAN
:
7310 ds
= "Bus Rescan Event";
7312 case MPI_EVENT_LINK_STATUS_CHANGE
:
7313 if (evData0
== MPI_EVENT_LINK_STATUS_FAILURE
)
7314 ds
= "Link Status(FAILURE) Change";
7316 ds
= "Link Status(ACTIVE) Change";
7318 case MPI_EVENT_LOOP_STATE_CHANGE
:
7319 if (evData0
== MPI_EVENT_LOOP_STATE_CHANGE_LIP
)
7320 ds
= "Loop State(LIP) Change";
7321 else if (evData0
== MPI_EVENT_LOOP_STATE_CHANGE_LPE
)
7322 ds
= "Loop State(LPE) Change";
7324 ds
= "Loop State(LPB) Change";
7326 case MPI_EVENT_LOGOUT
:
7329 case MPI_EVENT_EVENT_CHANGE
:
7335 case MPI_EVENT_INTEGRATED_RAID
:
7337 u8 ReasonCode
= (u8
)(evData0
>> 16);
7338 switch (ReasonCode
) {
7339 case MPI_EVENT_RAID_RC_VOLUME_CREATED
:
7340 ds
= "Integrated Raid: Volume Created";
7342 case MPI_EVENT_RAID_RC_VOLUME_DELETED
:
7343 ds
= "Integrated Raid: Volume Deleted";
7345 case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED
:
7346 ds
= "Integrated Raid: Volume Settings Changed";
7348 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED
:
7349 ds
= "Integrated Raid: Volume Status Changed";
7351 case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED
:
7352 ds
= "Integrated Raid: Volume Physdisk Changed";
7354 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED
:
7355 ds
= "Integrated Raid: Physdisk Created";
7357 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED
:
7358 ds
= "Integrated Raid: Physdisk Deleted";
7360 case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED
:
7361 ds
= "Integrated Raid: Physdisk Settings Changed";
7363 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED
:
7364 ds
= "Integrated Raid: Physdisk Status Changed";
7366 case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED
:
7367 ds
= "Integrated Raid: Domain Validation Needed";
7369 case MPI_EVENT_RAID_RC_SMART_DATA
:
7370 ds
= "Integrated Raid; Smart Data";
7372 case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED
:
7373 ds
= "Integrated Raid: Replace Action Started";
7376 ds
= "Integrated Raid";
7381 case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE
:
7382 ds
= "SCSI Device Status Change";
7384 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE
:
7386 u8 id
= (u8
)(evData0
);
7387 u8 channel
= (u8
)(evData0
>> 8);
7388 u8 ReasonCode
= (u8
)(evData0
>> 16);
7389 switch (ReasonCode
) {
7390 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED
:
7391 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7392 "SAS Device Status Change: Added: "
7393 "id=%d channel=%d", id
, channel
);
7395 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING
:
7396 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7397 "SAS Device Status Change: Deleted: "
7398 "id=%d channel=%d", id
, channel
);
7400 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA
:
7401 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7402 "SAS Device Status Change: SMART Data: "
7403 "id=%d channel=%d", id
, channel
);
7405 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED
:
7406 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7407 "SAS Device Status Change: No Persistancy: "
7408 "id=%d channel=%d", id
, channel
);
7410 case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED
:
7411 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7412 "SAS Device Status Change: Unsupported Device "
7413 "Discovered : id=%d channel=%d", id
, channel
);
7415 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET
:
7416 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7417 "SAS Device Status Change: Internal Device "
7418 "Reset : id=%d channel=%d", id
, channel
);
7420 case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL
:
7421 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7422 "SAS Device Status Change: Internal Task "
7423 "Abort : id=%d channel=%d", id
, channel
);
7425 case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL
:
7426 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7427 "SAS Device Status Change: Internal Abort "
7428 "Task Set : id=%d channel=%d", id
, channel
);
7430 case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL
:
7431 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7432 "SAS Device Status Change: Internal Clear "
7433 "Task Set : id=%d channel=%d", id
, channel
);
7435 case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL
:
7436 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7437 "SAS Device Status Change: Internal Query "
7438 "Task : id=%d channel=%d", id
, channel
);
7441 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7442 "SAS Device Status Change: Unknown: "
7443 "id=%d channel=%d", id
, channel
);
7448 case MPI_EVENT_ON_BUS_TIMER_EXPIRED
:
7449 ds
= "Bus Timer Expired";
7451 case MPI_EVENT_QUEUE_FULL
:
7453 u16 curr_depth
= (u16
)(evData0
>> 16);
7454 u8 channel
= (u8
)(evData0
>> 8);
7455 u8 id
= (u8
)(evData0
);
7457 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7458 "Queue Full: channel=%d id=%d depth=%d",
7459 channel
, id
, curr_depth
);
7462 case MPI_EVENT_SAS_SES
:
7463 ds
= "SAS SES Event";
7465 case MPI_EVENT_PERSISTENT_TABLE_FULL
:
7466 ds
= "Persistent Table Full";
7468 case MPI_EVENT_SAS_PHY_LINK_STATUS
:
7470 u8 LinkRates
= (u8
)(evData0
>> 8);
7471 u8 PhyNumber
= (u8
)(evData0
);
7472 LinkRates
= (LinkRates
& MPI_EVENT_SAS_PLS_LR_CURRENT_MASK
) >>
7473 MPI_EVENT_SAS_PLS_LR_CURRENT_SHIFT
;
7474 switch (LinkRates
) {
7475 case MPI_EVENT_SAS_PLS_LR_RATE_UNKNOWN
:
7476 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7477 "SAS PHY Link Status: Phy=%d:"
7478 " Rate Unknown",PhyNumber
);
7480 case MPI_EVENT_SAS_PLS_LR_RATE_PHY_DISABLED
:
7481 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7482 "SAS PHY Link Status: Phy=%d:"
7483 " Phy Disabled",PhyNumber
);
7485 case MPI_EVENT_SAS_PLS_LR_RATE_FAILED_SPEED_NEGOTIATION
:
7486 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7487 "SAS PHY Link Status: Phy=%d:"
7488 " Failed Speed Nego",PhyNumber
);
7490 case MPI_EVENT_SAS_PLS_LR_RATE_SATA_OOB_COMPLETE
:
7491 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7492 "SAS PHY Link Status: Phy=%d:"
7493 " Sata OOB Completed",PhyNumber
);
7495 case MPI_EVENT_SAS_PLS_LR_RATE_1_5
:
7496 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7497 "SAS PHY Link Status: Phy=%d:"
7498 " Rate 1.5 Gbps",PhyNumber
);
7500 case MPI_EVENT_SAS_PLS_LR_RATE_3_0
:
7501 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7502 "SAS PHY Link Status: Phy=%d:"
7503 " Rate 3.0 Gbps", PhyNumber
);
7505 case MPI_EVENT_SAS_PLS_LR_RATE_6_0
:
7506 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7507 "SAS PHY Link Status: Phy=%d:"
7508 " Rate 6.0 Gbps", PhyNumber
);
7511 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7512 "SAS PHY Link Status: Phy=%d", PhyNumber
);
7517 case MPI_EVENT_SAS_DISCOVERY_ERROR
:
7518 ds
= "SAS Discovery Error";
7520 case MPI_EVENT_IR_RESYNC_UPDATE
:
7522 u8 resync_complete
= (u8
)(evData0
>> 16);
7523 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7524 "IR Resync Update: Complete = %d:",resync_complete
);
7529 u8 id
= (u8
)(evData0
);
7530 u8 channel
= (u8
)(evData0
>> 8);
7531 u8 phys_num
= (u8
)(evData0
>> 24);
7532 u8 ReasonCode
= (u8
)(evData0
>> 16);
7534 switch (ReasonCode
) {
7535 case MPI_EVENT_IR2_RC_LD_STATE_CHANGED
:
7536 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7537 "IR2: LD State Changed: "
7538 "id=%d channel=%d phys_num=%d",
7539 id
, channel
, phys_num
);
7541 case MPI_EVENT_IR2_RC_PD_STATE_CHANGED
:
7542 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7543 "IR2: PD State Changed "
7544 "id=%d channel=%d phys_num=%d",
7545 id
, channel
, phys_num
);
7547 case MPI_EVENT_IR2_RC_BAD_BLOCK_TABLE_FULL
:
7548 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7549 "IR2: Bad Block Table Full: "
7550 "id=%d channel=%d phys_num=%d",
7551 id
, channel
, phys_num
);
7553 case MPI_EVENT_IR2_RC_PD_INSERTED
:
7554 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7555 "IR2: PD Inserted: "
7556 "id=%d channel=%d phys_num=%d",
7557 id
, channel
, phys_num
);
7559 case MPI_EVENT_IR2_RC_PD_REMOVED
:
7560 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7562 "id=%d channel=%d phys_num=%d",
7563 id
, channel
, phys_num
);
7565 case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED
:
7566 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7567 "IR2: Foreign CFG Detected: "
7568 "id=%d channel=%d phys_num=%d",
7569 id
, channel
, phys_num
);
7571 case MPI_EVENT_IR2_RC_REBUILD_MEDIUM_ERROR
:
7572 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7573 "IR2: Rebuild Medium Error: "
7574 "id=%d channel=%d phys_num=%d",
7575 id
, channel
, phys_num
);
7577 case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED
:
7578 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7579 "IR2: Dual Port Added: "
7580 "id=%d channel=%d phys_num=%d",
7581 id
, channel
, phys_num
);
7583 case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED
:
7584 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7585 "IR2: Dual Port Removed: "
7586 "id=%d channel=%d phys_num=%d",
7587 id
, channel
, phys_num
);
7595 case MPI_EVENT_SAS_DISCOVERY
:
7598 ds
= "SAS Discovery: Start";
7600 ds
= "SAS Discovery: Stop";
7603 case MPI_EVENT_LOG_ENTRY_ADDED
:
7604 ds
= "SAS Log Entry Added";
7607 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE
:
7609 u8 phy_num
= (u8
)(evData0
);
7610 u8 port_num
= (u8
)(evData0
>> 8);
7611 u8 port_width
= (u8
)(evData0
>> 16);
7612 u8 primative
= (u8
)(evData0
>> 24);
7613 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7614 "SAS Broadcase Primative: phy=%d port=%d "
7615 "width=%d primative=0x%02x",
7616 phy_num
, port_num
, port_width
, primative
);
7620 case MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE
:
7622 u8 reason
= (u8
)(evData0
);
7625 case MPI_EVENT_SAS_INIT_RC_ADDED
:
7626 ds
= "SAS Initiator Status Change: Added";
7628 case MPI_EVENT_SAS_INIT_RC_REMOVED
:
7629 ds
= "SAS Initiator Status Change: Deleted";
7632 ds
= "SAS Initiator Status Change";
7638 case MPI_EVENT_SAS_INIT_TABLE_OVERFLOW
:
7640 u8 max_init
= (u8
)(evData0
);
7641 u8 current_init
= (u8
)(evData0
>> 8);
7643 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7644 "SAS Initiator Device Table Overflow: max initiators=%02d "
7645 "current initators=%02d",
7646 max_init
, current_init
);
7649 case MPI_EVENT_SAS_SMP_ERROR
:
7651 u8 status
= (u8
)(evData0
);
7652 u8 port_num
= (u8
)(evData0
>> 8);
7653 u8 result
= (u8
)(evData0
>> 16);
7655 if (status
== MPI_EVENT_SAS_SMP_FUNCTION_RESULT_VALID
)
7656 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7657 "SAS SMP Error: port=%d result=0x%02x",
7659 else if (status
== MPI_EVENT_SAS_SMP_CRC_ERROR
)
7660 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7661 "SAS SMP Error: port=%d : CRC Error",
7663 else if (status
== MPI_EVENT_SAS_SMP_TIMEOUT
)
7664 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7665 "SAS SMP Error: port=%d : Timeout",
7667 else if (status
== MPI_EVENT_SAS_SMP_NO_DESTINATION
)
7668 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7669 "SAS SMP Error: port=%d : No Destination",
7671 else if (status
== MPI_EVENT_SAS_SMP_BAD_DESTINATION
)
7672 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7673 "SAS SMP Error: port=%d : Bad Destination",
7676 snprintf(evStr
, EVENT_DESCR_STR_SZ
,
7677 "SAS SMP Error: port=%d : status=0x%02x",
7682 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE
:
7684 u8 reason
= (u8
)(evData0
);
7687 case MPI_EVENT_SAS_EXP_RC_ADDED
:
7688 ds
= "Expander Status Change: Added";
7690 case MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING
:
7691 ds
= "Expander Status Change: Deleted";
7694 ds
= "Expander Status Change";
7701 * MPT base "custom" events may be added here...
7708 strncpy(evStr
, ds
, EVENT_DESCR_STR_SZ
);
7711 devtprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
7712 "MPT event:(%02Xh) : %s\n",
7713 ioc
->name
, event
, evStr
));
7715 devtverboseprintk(ioc
, printk(KERN_DEBUG MYNAM
7716 ": Event data:\n"));
7717 for (ii
= 0; ii
< le16_to_cpu(pEventReply
->EventDataLength
); ii
++)
7718 devtverboseprintk(ioc
, printk(" %08x",
7719 le32_to_cpu(pEventReply
->Data
[ii
])));
7720 devtverboseprintk(ioc
, printk(KERN_DEBUG
"\n"));
7723 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
7725 * ProcessEventNotification - Route EventNotificationReply to all event handlers
7726 * @ioc: Pointer to MPT_ADAPTER structure
7727 * @pEventReply: Pointer to EventNotification reply frame
7728 * @evHandlers: Pointer to integer, number of event handlers
7730 * Routes a received EventNotificationReply to all currently registered
7732 * Returns sum of event handlers return values.
7735 ProcessEventNotification(MPT_ADAPTER
*ioc
, EventNotificationReply_t
*pEventReply
, int *evHandlers
)
7746 * Do platform normalization of values
7748 event
= le32_to_cpu(pEventReply
->Event
) & 0xFF;
7749 evDataLen
= le16_to_cpu(pEventReply
->EventDataLength
);
7751 evData0
= le32_to_cpu(pEventReply
->Data
[0]);
7754 #ifdef CONFIG_FUSION_LOGGING
7756 mpt_display_event_info(ioc
, pEventReply
);
7760 * Do general / base driver event processing
7763 case MPI_EVENT_EVENT_CHANGE
: /* 0A */
7765 u8 evState
= evData0
& 0xFF;
7767 /* CHECKME! What if evState unexpectedly says OFF (0)? */
7769 /* Update EventState field in cached IocFacts */
7770 if (ioc
->facts
.Function
) {
7771 ioc
->facts
.EventState
= evState
;
7775 case MPI_EVENT_INTEGRATED_RAID
:
7776 mptbase_raid_process_event_data(ioc
,
7777 (MpiEventDataRaid_t
*)pEventReply
->Data
);
7784 * Should this event be logged? Events are written sequentially.
7785 * When buffer is full, start again at the top.
7787 if (ioc
->events
&& (ioc
->eventTypes
& ( 1 << event
))) {
7790 idx
= ioc
->eventContext
% MPTCTL_EVENT_LOG_SIZE
;
7792 ioc
->events
[idx
].event
= event
;
7793 ioc
->events
[idx
].eventContext
= ioc
->eventContext
;
7795 for (ii
= 0; ii
< 2; ii
++) {
7797 ioc
->events
[idx
].data
[ii
] = le32_to_cpu(pEventReply
->Data
[ii
]);
7799 ioc
->events
[idx
].data
[ii
] = 0;
7802 ioc
->eventContext
++;
7807 * Call each currently registered protocol event handler.
7809 for (cb_idx
= MPT_MAX_PROTOCOL_DRIVERS
-1; cb_idx
; cb_idx
--) {
7810 if (MptEvHandlers
[cb_idx
]) {
7811 devtverboseprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
7812 "Routing Event to event handler #%d\n",
7813 ioc
->name
, cb_idx
));
7814 r
+= (*(MptEvHandlers
[cb_idx
]))(ioc
, pEventReply
);
7818 /* FIXME? Examine results here? */
7821 * If needed, send (a single) EventAck.
7823 if (pEventReply
->AckRequired
== MPI_EVENT_NOTIFICATION_ACK_REQUIRED
) {
7824 devtverboseprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
7825 "EventAck required\n",ioc
->name
));
7826 if ((ii
= SendEventAck(ioc
, pEventReply
)) != 0) {
7827 devtverboseprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"SendEventAck returned %d\n",
7832 *evHandlers
= handlers
;
7836 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
7838 * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
7839 * @ioc: Pointer to MPT_ADAPTER structure
7840 * @log_info: U32 LogInfo reply word from the IOC
7842 * Refer to lsi/mpi_log_fc.h.
7845 mpt_fc_log_info(MPT_ADAPTER
*ioc
, u32 log_info
)
7847 char *desc
= "unknown";
7849 switch (log_info
& 0xFF000000) {
7850 case MPI_IOCLOGINFO_FC_INIT_BASE
:
7851 desc
= "FCP Initiator";
7853 case MPI_IOCLOGINFO_FC_TARGET_BASE
:
7854 desc
= "FCP Target";
7856 case MPI_IOCLOGINFO_FC_LAN_BASE
:
7859 case MPI_IOCLOGINFO_FC_MSG_BASE
:
7860 desc
= "MPI Message Layer";
7862 case MPI_IOCLOGINFO_FC_LINK_BASE
:
7865 case MPI_IOCLOGINFO_FC_CTX_BASE
:
7866 desc
= "Context Manager";
7868 case MPI_IOCLOGINFO_FC_INVALID_FIELD_BYTE_OFFSET
:
7869 desc
= "Invalid Field Offset";
7871 case MPI_IOCLOGINFO_FC_STATE_CHANGE
:
7872 desc
= "State Change Info";
7876 printk(MYIOC_s_INFO_FMT
"LogInfo(0x%08x): SubClass={%s}, Value=(0x%06x)\n",
7877 ioc
->name
, log_info
, desc
, (log_info
& 0xFFFFFF));
7880 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
7882 * mpt_spi_log_info - Log information returned from SCSI Parallel IOC.
7883 * @ioc: Pointer to MPT_ADAPTER structure
7884 * @log_info: U32 LogInfo word from the IOC
7886 * Refer to lsi/sp_log.h.
7889 mpt_spi_log_info(MPT_ADAPTER
*ioc
, u32 log_info
)
7891 u32 info
= log_info
& 0x00FF0000;
7892 char *desc
= "unknown";
7896 desc
= "bug! MID not found";
7900 desc
= "Parity Error";
7904 desc
= "ASYNC Outbound Overrun";
7908 desc
= "SYNC Offset Error";
7916 desc
= "Msg In Overflow";
7924 desc
= "Outbound DMA Overrun";
7928 desc
= "Task Management";
7932 desc
= "Device Problem";
7936 desc
= "Invalid Phase Change";
7940 desc
= "Untagged Table Size";
7945 printk(MYIOC_s_INFO_FMT
"LogInfo(0x%08x): F/W: %s\n", ioc
->name
, log_info
, desc
);
7948 /* strings for sas loginfo */
7949 static char *originator_str
[] = {
7954 static char *iop_code_str
[] = {
7956 "Invalid SAS Address", /* 01h */
7958 "Invalid Page", /* 03h */
7959 "Diag Message Error", /* 04h */
7960 "Task Terminated", /* 05h */
7961 "Enclosure Management", /* 06h */
7962 "Target Mode" /* 07h */
7964 static char *pl_code_str
[] = {
7966 "Open Failure", /* 01h */
7967 "Invalid Scatter Gather List", /* 02h */
7968 "Wrong Relative Offset or Frame Length", /* 03h */
7969 "Frame Transfer Error", /* 04h */
7970 "Transmit Frame Connected Low", /* 05h */
7971 "SATA Non-NCQ RW Error Bit Set", /* 06h */
7972 "SATA Read Log Receive Data Error", /* 07h */
7973 "SATA NCQ Fail All Commands After Error", /* 08h */
7974 "SATA Error in Receive Set Device Bit FIS", /* 09h */
7975 "Receive Frame Invalid Message", /* 0Ah */
7976 "Receive Context Message Valid Error", /* 0Bh */
7977 "Receive Frame Current Frame Error", /* 0Ch */
7978 "SATA Link Down", /* 0Dh */
7979 "Discovery SATA Init W IOS", /* 0Eh */
7980 "Config Invalid Page", /* 0Fh */
7981 "Discovery SATA Init Timeout", /* 10h */
7984 "IO Not Yet Executed", /* 13h */
7985 "IO Executed", /* 14h */
7986 "Persistent Reservation Out Not Affiliation "
7988 "Open Transmit DMA Abort", /* 16h */
7989 "IO Device Missing Delay Retry", /* 17h */
7990 "IO Cancelled Due to Receive Error", /* 18h */
7998 "Enclosure Management" /* 20h */
8000 static char *ir_code_str
[] = {
8001 "Raid Action Error", /* 00h */
8011 static char *raid_sub_code_str
[] = {
8013 "Volume Creation Failed: Data Passed too "
8015 "Volume Creation Failed: Duplicate Volumes "
8016 "Attempted", /* 02h */
8017 "Volume Creation Failed: Max Number "
8018 "Supported Volumes Exceeded", /* 03h */
8019 "Volume Creation Failed: DMA Error", /* 04h */
8020 "Volume Creation Failed: Invalid Volume Type", /* 05h */
8021 "Volume Creation Failed: Error Reading "
8022 "MFG Page 4", /* 06h */
8023 "Volume Creation Failed: Creating Internal "
8024 "Structures", /* 07h */
8033 "Activation failed: Already Active Volume", /* 10h */
8034 "Activation failed: Unsupported Volume Type", /* 11h */
8035 "Activation failed: Too Many Active Volumes", /* 12h */
8036 "Activation failed: Volume ID in Use", /* 13h */
8037 "Activation failed: Reported Failure", /* 14h */
8038 "Activation failed: Importing a Volume", /* 15h */
8049 "Phys Disk failed: Too Many Phys Disks", /* 20h */
8050 "Phys Disk failed: Data Passed too Large", /* 21h */
8051 "Phys Disk failed: DMA Error", /* 22h */
8052 "Phys Disk failed: Invalid <channel:id>", /* 23h */
8053 "Phys Disk failed: Creating Phys Disk Config "
8066 "Compatibility Error: IR Disabled", /* 30h */
8067 "Compatibility Error: Inquiry Command Failed", /* 31h */
8068 "Compatibility Error: Device not Direct Access "
8069 "Device ", /* 32h */
8070 "Compatibility Error: Removable Device Found", /* 33h */
8071 "Compatibility Error: Device SCSI Version not "
8072 "2 or Higher", /* 34h */
8073 "Compatibility Error: SATA Device, 48 BIT LBA "
8074 "not Supported", /* 35h */
8075 "Compatibility Error: Device doesn't have "
8076 "512 Byte Block Sizes", /* 36h */
8077 "Compatibility Error: Volume Type Check Failed", /* 37h */
8078 "Compatibility Error: Volume Type is "
8079 "Unsupported by FW", /* 38h */
8080 "Compatibility Error: Disk Drive too Small for "
8081 "use in Volume", /* 39h */
8082 "Compatibility Error: Phys Disk for Create "
8083 "Volume not Found", /* 3Ah */
8084 "Compatibility Error: Too Many or too Few "
8085 "Disks for Volume Type", /* 3Bh */
8086 "Compatibility Error: Disk stripe Sizes "
8087 "Must be 64KB", /* 3Ch */
8088 "Compatibility Error: IME Size Limited to < 2TB", /* 3Dh */
8091 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
8093 * mpt_sas_log_info - Log information returned from SAS IOC.
8094 * @ioc: Pointer to MPT_ADAPTER structure
8095 * @log_info: U32 LogInfo reply word from the IOC
8096 * @cb_idx: callback function's handle
8098 * Refer to lsi/mpi_log_sas.h.
8101 mpt_sas_log_info(MPT_ADAPTER
*ioc
, u32 log_info
, u8 cb_idx
)
8103 union loginfo_type
{
8112 union loginfo_type sas_loginfo
;
8113 char *originator_desc
= NULL
;
8114 char *code_desc
= NULL
;
8115 char *sub_code_desc
= NULL
;
8117 sas_loginfo
.loginfo
= log_info
;
8118 if ((sas_loginfo
.dw
.bus_type
!= 3 /*SAS*/) &&
8119 (sas_loginfo
.dw
.originator
< ARRAY_SIZE(originator_str
)))
8122 originator_desc
= originator_str
[sas_loginfo
.dw
.originator
];
8124 switch (sas_loginfo
.dw
.originator
) {
8127 if (sas_loginfo
.dw
.code
<
8128 ARRAY_SIZE(iop_code_str
))
8129 code_desc
= iop_code_str
[sas_loginfo
.dw
.code
];
8132 if (sas_loginfo
.dw
.code
<
8133 ARRAY_SIZE(pl_code_str
))
8134 code_desc
= pl_code_str
[sas_loginfo
.dw
.code
];
8137 if (sas_loginfo
.dw
.code
>=
8138 ARRAY_SIZE(ir_code_str
))
8140 code_desc
= ir_code_str
[sas_loginfo
.dw
.code
];
8141 if (sas_loginfo
.dw
.subcode
>=
8142 ARRAY_SIZE(raid_sub_code_str
))
8144 if (sas_loginfo
.dw
.code
== 0)
8146 raid_sub_code_str
[sas_loginfo
.dw
.subcode
];
8152 if (sub_code_desc
!= NULL
)
8153 printk(MYIOC_s_INFO_FMT
8154 "LogInfo(0x%08x): Originator={%s}, Code={%s},"
8155 " SubCode={%s} cb_idx %s\n",
8156 ioc
->name
, log_info
, originator_desc
, code_desc
,
8157 sub_code_desc
, MptCallbacksName
[cb_idx
]);
8158 else if (code_desc
!= NULL
)
8159 printk(MYIOC_s_INFO_FMT
8160 "LogInfo(0x%08x): Originator={%s}, Code={%s},"
8161 " SubCode(0x%04x) cb_idx %s\n",
8162 ioc
->name
, log_info
, originator_desc
, code_desc
,
8163 sas_loginfo
.dw
.subcode
, MptCallbacksName
[cb_idx
]);
8165 printk(MYIOC_s_INFO_FMT
8166 "LogInfo(0x%08x): Originator={%s}, Code=(0x%02x),"
8167 " SubCode(0x%04x) cb_idx %s\n",
8168 ioc
->name
, log_info
, originator_desc
,
8169 sas_loginfo
.dw
.code
, sas_loginfo
.dw
.subcode
,
8170 MptCallbacksName
[cb_idx
]);
8173 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
8175 * mpt_iocstatus_info_config - IOCSTATUS information for config pages
8176 * @ioc: Pointer to MPT_ADAPTER structure
8177 * @ioc_status: U32 IOCStatus word from IOC
8178 * @mf: Pointer to MPT request frame
8180 * Refer to lsi/mpi.h.
8183 mpt_iocstatus_info_config(MPT_ADAPTER
*ioc
, u32 ioc_status
, MPT_FRAME_HDR
*mf
)
8185 Config_t
*pReq
= (Config_t
*)mf
;
8186 char extend_desc
[EVENT_DESCR_STR_SZ
];
8191 if (pReq
->Header
.PageType
== MPI_CONFIG_PAGETYPE_EXTENDED
)
8192 page_type
= pReq
->ExtPageType
;
8194 page_type
= pReq
->Header
.PageType
;
8197 * ignore invalid page messages for GET_NEXT_HANDLE
8199 form
= le32_to_cpu(pReq
->PageAddress
);
8200 if (ioc_status
== MPI_IOCSTATUS_CONFIG_INVALID_PAGE
) {
8201 if (page_type
== MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE
||
8202 page_type
== MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER
||
8203 page_type
== MPI_CONFIG_EXTPAGETYPE_ENCLOSURE
) {
8204 if ((form
>> MPI_SAS_DEVICE_PGAD_FORM_SHIFT
) ==
8205 MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE
)
8208 if (page_type
== MPI_CONFIG_PAGETYPE_FC_DEVICE
)
8209 if ((form
& MPI_FC_DEVICE_PGAD_FORM_MASK
) ==
8210 MPI_FC_DEVICE_PGAD_FORM_NEXT_DID
)
8214 snprintf(extend_desc
, EVENT_DESCR_STR_SZ
,
8215 "type=%02Xh, page=%02Xh, action=%02Xh, form=%08Xh",
8216 page_type
, pReq
->Header
.PageNumber
, pReq
->Action
, form
);
8218 switch (ioc_status
) {
8220 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION
: /* 0x0020 */
8221 desc
= "Config Page Invalid Action";
8224 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE
: /* 0x0021 */
8225 desc
= "Config Page Invalid Type";
8228 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE
: /* 0x0022 */
8229 desc
= "Config Page Invalid Page";
8232 case MPI_IOCSTATUS_CONFIG_INVALID_DATA
: /* 0x0023 */
8233 desc
= "Config Page Invalid Data";
8236 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS
: /* 0x0024 */
8237 desc
= "Config Page No Defaults";
8240 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT
: /* 0x0025 */
8241 desc
= "Config Page Can't Commit";
8248 dreplyprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"IOCStatus(0x%04X): %s: %s\n",
8249 ioc
->name
, ioc_status
, desc
, extend_desc
));
8253 * mpt_iocstatus_info - IOCSTATUS information returned from IOC.
8254 * @ioc: Pointer to MPT_ADAPTER structure
8255 * @ioc_status: U32 IOCStatus word from IOC
8256 * @mf: Pointer to MPT request frame
8258 * Refer to lsi/mpi.h.
8261 mpt_iocstatus_info(MPT_ADAPTER
*ioc
, u32 ioc_status
, MPT_FRAME_HDR
*mf
)
8263 u32 status
= ioc_status
& MPI_IOCSTATUS_MASK
;
8268 /****************************************************************************/
8269 /* Common IOCStatus values for all replies */
8270 /****************************************************************************/
8272 case MPI_IOCSTATUS_INVALID_FUNCTION
: /* 0x0001 */
8273 desc
= "Invalid Function";
8276 case MPI_IOCSTATUS_BUSY
: /* 0x0002 */
8280 case MPI_IOCSTATUS_INVALID_SGL
: /* 0x0003 */
8281 desc
= "Invalid SGL";
8284 case MPI_IOCSTATUS_INTERNAL_ERROR
: /* 0x0004 */
8285 desc
= "Internal Error";
8288 case MPI_IOCSTATUS_RESERVED
: /* 0x0005 */
8292 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES
: /* 0x0006 */
8293 desc
= "Insufficient Resources";
8296 case MPI_IOCSTATUS_INVALID_FIELD
: /* 0x0007 */
8297 desc
= "Invalid Field";
8300 case MPI_IOCSTATUS_INVALID_STATE
: /* 0x0008 */
8301 desc
= "Invalid State";
8304 /****************************************************************************/
8305 /* Config IOCStatus values */
8306 /****************************************************************************/
8308 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION
: /* 0x0020 */
8309 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE
: /* 0x0021 */
8310 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE
: /* 0x0022 */
8311 case MPI_IOCSTATUS_CONFIG_INVALID_DATA
: /* 0x0023 */
8312 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS
: /* 0x0024 */
8313 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT
: /* 0x0025 */
8314 mpt_iocstatus_info_config(ioc
, status
, mf
);
8317 /****************************************************************************/
8318 /* SCSIIO Reply (SPI, FCP, SAS) initiator values */
8320 /* Look at mptscsih_iocstatus_info_scsiio in mptscsih.c */
8322 /****************************************************************************/
8324 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR
: /* 0x0040 */
8325 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN
: /* 0x0045 */
8326 case MPI_IOCSTATUS_SCSI_INVALID_BUS
: /* 0x0041 */
8327 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID
: /* 0x0042 */
8328 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE
: /* 0x0043 */
8329 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN
: /* 0x0044 */
8330 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR
: /* 0x0046 */
8331 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR
: /* 0x0047 */
8332 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED
: /* 0x0048 */
8333 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
: /* 0x0049 */
8334 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED
: /* 0x004A */
8335 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED
: /* 0x004B */
8336 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED
: /* 0x004C */
8339 /****************************************************************************/
8340 /* SCSI Target values */
8341 /****************************************************************************/
8343 case MPI_IOCSTATUS_TARGET_PRIORITY_IO
: /* 0x0060 */
8344 desc
= "Target: Priority IO";
8347 case MPI_IOCSTATUS_TARGET_INVALID_PORT
: /* 0x0061 */
8348 desc
= "Target: Invalid Port";
8351 case MPI_IOCSTATUS_TARGET_INVALID_IO_INDEX
: /* 0x0062 */
8352 desc
= "Target Invalid IO Index:";
8355 case MPI_IOCSTATUS_TARGET_ABORTED
: /* 0x0063 */
8356 desc
= "Target: Aborted";
8359 case MPI_IOCSTATUS_TARGET_NO_CONN_RETRYABLE
: /* 0x0064 */
8360 desc
= "Target: No Conn Retryable";
8363 case MPI_IOCSTATUS_TARGET_NO_CONNECTION
: /* 0x0065 */
8364 desc
= "Target: No Connection";
8367 case MPI_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH
: /* 0x006A */
8368 desc
= "Target: Transfer Count Mismatch";
8371 case MPI_IOCSTATUS_TARGET_STS_DATA_NOT_SENT
: /* 0x006B */
8372 desc
= "Target: STS Data not Sent";
8375 case MPI_IOCSTATUS_TARGET_DATA_OFFSET_ERROR
: /* 0x006D */
8376 desc
= "Target: Data Offset Error";
8379 case MPI_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA
: /* 0x006E */
8380 desc
= "Target: Too Much Write Data";
8383 case MPI_IOCSTATUS_TARGET_IU_TOO_SHORT
: /* 0x006F */
8384 desc
= "Target: IU Too Short";
8387 case MPI_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT
: /* 0x0070 */
8388 desc
= "Target: ACK NAK Timeout";
8391 case MPI_IOCSTATUS_TARGET_NAK_RECEIVED
: /* 0x0071 */
8392 desc
= "Target: Nak Received";
8395 /****************************************************************************/
8396 /* Fibre Channel Direct Access values */
8397 /****************************************************************************/
8399 case MPI_IOCSTATUS_FC_ABORTED
: /* 0x0066 */
8400 desc
= "FC: Aborted";
8403 case MPI_IOCSTATUS_FC_RX_ID_INVALID
: /* 0x0067 */
8404 desc
= "FC: RX ID Invalid";
8407 case MPI_IOCSTATUS_FC_DID_INVALID
: /* 0x0068 */
8408 desc
= "FC: DID Invalid";
8411 case MPI_IOCSTATUS_FC_NODE_LOGGED_OUT
: /* 0x0069 */
8412 desc
= "FC: Node Logged Out";
8415 case MPI_IOCSTATUS_FC_EXCHANGE_CANCELED
: /* 0x006C */
8416 desc
= "FC: Exchange Canceled";
8419 /****************************************************************************/
8421 /****************************************************************************/
8423 case MPI_IOCSTATUS_LAN_DEVICE_NOT_FOUND
: /* 0x0080 */
8424 desc
= "LAN: Device not Found";
8427 case MPI_IOCSTATUS_LAN_DEVICE_FAILURE
: /* 0x0081 */
8428 desc
= "LAN: Device Failure";
8431 case MPI_IOCSTATUS_LAN_TRANSMIT_ERROR
: /* 0x0082 */
8432 desc
= "LAN: Transmit Error";
8435 case MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED
: /* 0x0083 */
8436 desc
= "LAN: Transmit Aborted";
8439 case MPI_IOCSTATUS_LAN_RECEIVE_ERROR
: /* 0x0084 */
8440 desc
= "LAN: Receive Error";
8443 case MPI_IOCSTATUS_LAN_RECEIVE_ABORTED
: /* 0x0085 */
8444 desc
= "LAN: Receive Aborted";
8447 case MPI_IOCSTATUS_LAN_PARTIAL_PACKET
: /* 0x0086 */
8448 desc
= "LAN: Partial Packet";
8451 case MPI_IOCSTATUS_LAN_CANCELED
: /* 0x0087 */
8452 desc
= "LAN: Canceled";
8455 /****************************************************************************/
8456 /* Serial Attached SCSI values */
8457 /****************************************************************************/
8459 case MPI_IOCSTATUS_SAS_SMP_REQUEST_FAILED
: /* 0x0090 */
8460 desc
= "SAS: SMP Request Failed";
8463 case MPI_IOCSTATUS_SAS_SMP_DATA_OVERRUN
: /* 0x0090 */
8464 desc
= "SAS: SMP Data Overrun";
8475 dreplyprintk(ioc
, printk(MYIOC_s_DEBUG_FMT
"IOCStatus(0x%04X): %s\n",
8476 ioc
->name
, status
, desc
));
8479 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
8480 EXPORT_SYMBOL(mpt_attach
);
8481 EXPORT_SYMBOL(mpt_detach
);
8483 EXPORT_SYMBOL(mpt_resume
);
8484 EXPORT_SYMBOL(mpt_suspend
);
8486 EXPORT_SYMBOL(ioc_list
);
8487 EXPORT_SYMBOL(mpt_register
);
8488 EXPORT_SYMBOL(mpt_deregister
);
8489 EXPORT_SYMBOL(mpt_event_register
);
8490 EXPORT_SYMBOL(mpt_event_deregister
);
8491 EXPORT_SYMBOL(mpt_reset_register
);
8492 EXPORT_SYMBOL(mpt_reset_deregister
);
8493 EXPORT_SYMBOL(mpt_device_driver_register
);
8494 EXPORT_SYMBOL(mpt_device_driver_deregister
);
8495 EXPORT_SYMBOL(mpt_get_msg_frame
);
8496 EXPORT_SYMBOL(mpt_put_msg_frame
);
8497 EXPORT_SYMBOL(mpt_put_msg_frame_hi_pri
);
8498 EXPORT_SYMBOL(mpt_free_msg_frame
);
8499 EXPORT_SYMBOL(mpt_send_handshake_request
);
8500 EXPORT_SYMBOL(mpt_verify_adapter
);
8501 EXPORT_SYMBOL(mpt_GetIocState
);
8502 EXPORT_SYMBOL(mpt_print_ioc_summary
);
8503 EXPORT_SYMBOL(mpt_HardResetHandler
);
8504 EXPORT_SYMBOL(mpt_config
);
8505 EXPORT_SYMBOL(mpt_findImVolumes
);
8506 EXPORT_SYMBOL(mpt_alloc_fw_memory
);
8507 EXPORT_SYMBOL(mpt_free_fw_memory
);
8508 EXPORT_SYMBOL(mptbase_sas_persist_operation
);
8509 EXPORT_SYMBOL(mpt_raid_phys_disk_pg0
);
8511 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
8513 * fusion_init - Fusion MPT base driver initialization routine.
8515 * Returns 0 for success, non-zero for failure.
8522 show_mptmod_ver(my_NAME
, my_VERSION
);
8523 printk(KERN_INFO COPYRIGHT
"\n");
8525 for (cb_idx
= 0; cb_idx
< MPT_MAX_PROTOCOL_DRIVERS
; cb_idx
++) {
8526 MptCallbacks
[cb_idx
] = NULL
;
8527 MptDriverClass
[cb_idx
] = MPTUNKNOWN_DRIVER
;
8528 MptEvHandlers
[cb_idx
] = NULL
;
8529 MptResetHandlers
[cb_idx
] = NULL
;
8532 /* Register ourselves (mptbase) in order to facilitate
8533 * EventNotification handling.
8535 mpt_base_index
= mpt_register(mptbase_reply
, MPTBASE_DRIVER
,
8538 /* Register for hard reset handling callbacks.
8540 mpt_reset_register(mpt_base_index
, mpt_ioc_reset
);
8542 #ifdef CONFIG_PROC_FS
8543 (void) procmpt_create();
8548 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
8550 * fusion_exit - Perform driver unload cleanup.
8552 * This routine frees all resources associated with each MPT adapter
8553 * and removes all %MPT_PROCFS_MPTBASEDIR entries.
8559 mpt_reset_deregister(mpt_base_index
);
8561 #ifdef CONFIG_PROC_FS
8566 module_init(fusion_init
);
8567 module_exit(fusion_exit
);