blob: 187f83629f7ef8df1fcf4f5d7c6c7d83cff49fb5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/message/fusion/mptbase.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * This is the Fusion MPT base driver which supports multiple
4 * (SCSI + LAN) specialized protocol drivers.
Prakash, Sathyaf36789e2007-08-14 16:22:54 +05305 * For use with LSI PCI chip/adapter(s)
6 * running LSI Fusion MPT (Message Passing Technology) firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Prakash, Sathyacddc0ab2008-05-21 00:56:41 +05308 * Copyright (c) 1999-2008 LSI Corporation
Eric Moore16d20102007-06-13 16:31:07 -06009 * (mailto:DL-MPTFusionLinux@lsi.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
12/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
13/*
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.
17
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.
22
23 NO WARRANTY
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.
33
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
42
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
46*/
47/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/kernel.h>
50#include <linux/module.h>
51#include <linux/errno.h>
52#include <linux/init.h>
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -070053#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#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 */
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -040061#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#include <asm/io.h>
63#ifdef CONFIG_MTRR
64#include <asm/mtrr.h>
65#endif
kashyap.desai@lsi.come62cca12011-08-04 16:42:15 +053066#include <linux/kthread.h>
67#include <scsi/scsi_host.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#include "mptbase.h"
Eric Moore7c431e52007-06-13 16:34:36 -060070#include "lsi/mpi_log_fc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
73#define my_NAME "Fusion MPT base driver"
74#define my_VERSION MPT_LINUX_VERSION_COMMON
75#define MYNAM "mptbase"
76
77MODULE_AUTHOR(MODULEAUTHOR);
78MODULE_DESCRIPTION(my_NAME);
79MODULE_LICENSE("GPL");
Eric Moore9f4203b2007-01-04 20:47:47 -070080MODULE_VERSION(my_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/*
83 * cmd line parameters
84 */
Kashyap, Desaie3829682009-01-08 14:27:16 +053085
86static int mpt_msi_enable_spi;
87module_param(mpt_msi_enable_spi, int, 0);
Joe Perches85ee7a12011-04-23 20:38:19 -070088MODULE_PARM_DESC(mpt_msi_enable_spi,
89 " Enable MSI Support for SPI controllers (default=0)");
Kashyap, Desaie3829682009-01-08 14:27:16 +053090
91static int mpt_msi_enable_fc;
92module_param(mpt_msi_enable_fc, int, 0);
Joe Perches85ee7a12011-04-23 20:38:19 -070093MODULE_PARM_DESC(mpt_msi_enable_fc,
94 " Enable MSI Support for FC controllers (default=0)");
Kashyap, Desaie3829682009-01-08 14:27:16 +053095
96static int mpt_msi_enable_sas;
Yinghai Lu5ce78682009-02-18 11:25:32 -080097module_param(mpt_msi_enable_sas, int, 0);
Joe Perches85ee7a12011-04-23 20:38:19 -070098MODULE_PARM_DESC(mpt_msi_enable_sas,
99 " Enable MSI Support for SAS controllers (default=0)");
Christoph Hellwig4ddce142006-01-17 13:44:29 +0000100
Eric Moore793955f2007-01-29 09:42:20 -0700101static int mpt_channel_mapping;
102module_param(mpt_channel_mapping, int, 0);
103MODULE_PARM_DESC(mpt_channel_mapping, " Mapping id's to channels (default=0)");
104
Prakash, Sathya436ace72007-07-24 15:42:08 +0530105static int mpt_debug_level;
James Bottomleydb47c2d2007-07-28 13:40:21 -0400106static int mpt_set_debug_level(const char *val, struct kernel_param *kp);
107module_param_call(mpt_debug_level, mpt_set_debug_level, param_get_int,
108 &mpt_debug_level, 0600);
Joe Perches85ee7a12011-04-23 20:38:19 -0700109MODULE_PARM_DESC(mpt_debug_level,
110 " debug level - refer to mptdebug.h - (default=0)");
Kashyap, Desaie3829682009-01-08 14:27:16 +0530111
Kashyap, Desai2f4c7822009-01-06 15:03:37 +0530112int mpt_fwfault_debug;
113EXPORT_SYMBOL(mpt_fwfault_debug);
Rusty Russell57ba4712010-08-11 23:04:39 -0600114module_param(mpt_fwfault_debug, int, 0600);
Joe Perches85ee7a12011-04-23 20:38:19 -0700115MODULE_PARM_DESC(mpt_fwfault_debug,
116 "Enable detection of Firmware fault and halt Firmware on fault - (default=0)");
Kashyap, Desai2f4c7822009-01-06 15:03:37 +0530117
Ferenc Wagner8af3d8d2011-08-25 14:44:57 +0200118static char MptCallbacksName[MPT_MAX_PROTOCOL_DRIVERS]
119 [MPT_MAX_CALLBACKNAME_LEN+1];
Prakash, Sathya436ace72007-07-24 15:42:08 +0530120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#ifdef MFCNT
122static int mfcounter = 0;
123#define PRINT_MF_COUNT 20000
124#endif
125
126/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
127/*
128 * Public data...
129 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#define WHOINIT_UNKNOWN 0xAA
132
133/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
134/*
135 * Private data...
136 */
137 /* Adapter link list */
138LIST_HEAD(ioc_list);
139 /* Callback lookup table */
140static MPT_CALLBACK MptCallbacks[MPT_MAX_PROTOCOL_DRIVERS];
141 /* Protocol driver class lookup table */
142static int MptDriverClass[MPT_MAX_PROTOCOL_DRIVERS];
143 /* Event handler lookup table */
144static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
145 /* Reset handler lookup table */
146static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
147static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
148
Erik Ekmane47c11c2009-12-14 21:21:56 +0100149#ifdef CONFIG_PROC_FS
150static struct proc_dir_entry *mpt_proc_root_dir;
151#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530153/*
154 * Driver Callback Index's
155 */
156static u8 mpt_base_index = MPT_MAX_PROTOCOL_DRIVERS;
157static u8 last_drv_idx;
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
160/*
161 * Forward protos...
162 */
David Howells7d12e782006-10-05 14:55:46 +0100163static irqreturn_t mpt_interrupt(int irq, void *bus_id);
Kashyap, Desaif0f09d32009-05-29 16:40:57 +0530164static int mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
165 MPT_FRAME_HDR *reply);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166static int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
167 u32 *req, int replyBytes, u16 *u16reply, int maxwait,
168 int sleepFlag);
169static int mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag);
170static void mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev);
171static void mpt_adapter_disable(MPT_ADAPTER *ioc);
172static void mpt_adapter_dispose(MPT_ADAPTER *ioc);
173
174static void MptDisplayIocCapabilities(MPT_ADAPTER *ioc);
175static int MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176static int GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason);
177static int GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
178static int SendIocInit(MPT_ADAPTER *ioc, int sleepFlag);
179static int SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
180static int mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +0200181static int mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182static int mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
183static int KickStart(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
184static int SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag);
185static int PrimeIocFifos(MPT_ADAPTER *ioc);
186static int WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
187static int WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
188static int WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
189static int GetLanConfigPages(MPT_ADAPTER *ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190static int GetIoUnitPage2(MPT_ADAPTER *ioc);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +0200191int mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192static int mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
193static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
194static void mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
195static void mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
Prakash, Sathyaedb90682007-07-17 14:39:14 +0530196static void mpt_get_manufacturing_pg_0(MPT_ADAPTER *ioc);
Kashyap, Desaifd761752009-05-29 16:39:06 +0530197static int SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch,
198 int sleepFlag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199static int SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +0200200static int mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag);
201static int mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203#ifdef CONFIG_PROC_FS
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -0700204static const struct file_operations mpt_summary_proc_fops;
205static const struct file_operations mpt_version_proc_fops;
206static const struct file_operations mpt_iocinfo_proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#endif
208static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
209
Kashyap, Desaifd761752009-05-29 16:39:06 +0530210static int ProcessEventNotification(MPT_ADAPTER *ioc,
211 EventNotificationReply_t *evReply, int *evHandlers);
Eric Moorec6c727a2007-01-29 09:44:54 -0700212static void mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
Moore, Eric335a9412006-01-17 17:06:23 -0700214static void mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info);
Kashyap, Desai213aaca2010-07-26 18:57:36 +0530215static void mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info , u8 cb_idx);
Moore, Ericc972c702006-03-14 09:14:06 -0700216static int mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
Eric Mooreb506ade2007-01-29 09:45:37 -0700217static void mpt_inactive_raid_list_free(MPT_ADAPTER *ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219/* module entry point */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220static int __init fusion_init (void);
221static void __exit fusion_exit (void);
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#define CHIPREG_READ32(addr) readl_relaxed(addr)
224#define CHIPREG_READ32_dmasync(addr) readl(addr)
225#define CHIPREG_WRITE32(addr,val) writel(val, addr)
226#define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
227#define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
228
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -0600229static void
230pci_disable_io_access(struct pci_dev *pdev)
231{
232 u16 command_reg;
233
234 pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
235 command_reg &= ~1;
236 pci_write_config_word(pdev, PCI_COMMAND, command_reg);
237}
238
239static void
240pci_enable_io_access(struct pci_dev *pdev)
241{
242 u16 command_reg;
243
244 pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
245 command_reg |= 1;
246 pci_write_config_word(pdev, PCI_COMMAND, command_reg);
247}
248
James Bottomleydb47c2d2007-07-28 13:40:21 -0400249static int mpt_set_debug_level(const char *val, struct kernel_param *kp)
250{
251 int ret = param_set_int(val, kp);
252 MPT_ADAPTER *ioc;
253
254 if (ret)
255 return ret;
256
257 list_for_each_entry(ioc, &ioc_list, list)
258 ioc->debug_level = mpt_debug_level;
259 return 0;
260}
261
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530262/**
263 * mpt_get_cb_idx - obtain cb_idx for registered driver
264 * @dclass: class driver enum
265 *
266 * Returns cb_idx, or zero means it wasn't found
267 **/
268static u8
269mpt_get_cb_idx(MPT_DRIVER_CLASS dclass)
270{
271 u8 cb_idx;
272
273 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--)
274 if (MptDriverClass[cb_idx] == dclass)
275 return cb_idx;
276 return 0;
277}
278
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530279/**
Kashyap, Desai7b5a65b2009-05-29 16:38:14 +0530280 * mpt_is_discovery_complete - determine if discovery has completed
281 * @ioc: per adatper instance
282 *
283 * Returns 1 when discovery completed, else zero.
284 */
285static int
286mpt_is_discovery_complete(MPT_ADAPTER *ioc)
287{
288 ConfigExtendedPageHeader_t hdr;
289 CONFIGPARMS cfg;
290 SasIOUnitPage0_t *buffer;
291 dma_addr_t dma_handle;
292 int rc = 0;
293
294 memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
295 memset(&cfg, 0, sizeof(CONFIGPARMS));
296 hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
297 hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
298 hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
299 cfg.cfghdr.ehdr = &hdr;
300 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
301
302 if ((mpt_config(ioc, &cfg)))
303 goto out;
304 if (!hdr.ExtPageLength)
305 goto out;
306
307 buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
308 &dma_handle);
309 if (!buffer)
310 goto out;
311
312 cfg.physAddr = dma_handle;
313 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
314
315 if ((mpt_config(ioc, &cfg)))
316 goto out_free_consistent;
317
318 if (!(buffer->PhyData[0].PortFlags &
319 MPI_SAS_IOUNIT0_PORT_FLAGS_DISCOVERY_IN_PROGRESS))
320 rc = 1;
321
322 out_free_consistent:
323 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
324 buffer, dma_handle);
325 out:
326 return rc;
327}
328
kashyap.desai@lsi.come62cca12011-08-04 16:42:15 +0530329
330/**
331 * mpt_remove_dead_ioc_func - kthread context to remove dead ioc
332 * @arg: input argument, used to derive ioc
333 *
334 * Return 0 if controller is removed from pci subsystem.
335 * Return -1 for other case.
336 */
337static int mpt_remove_dead_ioc_func(void *arg)
338{
339 MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
340 struct pci_dev *pdev;
341
342 if ((ioc == NULL))
343 return -1;
344
345 pdev = ioc->pcidev;
346 if ((pdev == NULL))
347 return -1;
348
Rafael J. Wysocki64cdb412014-01-10 15:27:56 +0100349 pci_stop_and_remove_bus_device_locked(pdev);
kashyap.desai@lsi.come62cca12011-08-04 16:42:15 +0530350 return 0;
351}
352
353
354
Kashyap, Desai7b5a65b2009-05-29 16:38:14 +0530355/**
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530356 * mpt_fault_reset_work - work performed on workq after ioc fault
357 * @work: input argument, used to derive ioc
358 *
359**/
360static void
361mpt_fault_reset_work(struct work_struct *work)
362{
363 MPT_ADAPTER *ioc =
364 container_of(work, MPT_ADAPTER, fault_reset_work.work);
365 u32 ioc_raw_state;
366 int rc;
367 unsigned long flags;
kashyap.desai@lsi.come62cca12011-08-04 16:42:15 +0530368 MPT_SCSI_HOST *hd;
369 struct task_struct *p;
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530370
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +0530371 if (ioc->ioc_reset_in_progress || !ioc->active)
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530372 goto out;
373
kashyap.desai@lsi.come62cca12011-08-04 16:42:15 +0530374
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530375 ioc_raw_state = mpt_GetIocState(ioc, 0);
kashyap.desai@lsi.come62cca12011-08-04 16:42:15 +0530376 if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_MASK) {
377 printk(MYIOC_s_INFO_FMT "%s: IOC is non-operational !!!!\n",
378 ioc->name, __func__);
379
380 /*
381 * Call mptscsih_flush_pending_cmds callback so that we
382 * flush all pending commands back to OS.
383 * This call is required to aovid deadlock at block layer.
384 * Dead IOC will fail to do diag reset,and this call is safe
385 * since dead ioc will never return any command back from HW.
386 */
387 hd = shost_priv(ioc->sh);
388 ioc->schedule_dead_ioc_flush_running_cmds(hd);
389
390 /*Remove the Dead Host */
391 p = kthread_run(mpt_remove_dead_ioc_func, ioc,
392 "mpt_dead_ioc_%d", ioc->id);
393 if (IS_ERR(p)) {
394 printk(MYIOC_s_ERR_FMT
395 "%s: Running mpt_dead_ioc thread failed !\n",
396 ioc->name, __func__);
397 } else {
398 printk(MYIOC_s_WARN_FMT
399 "%s: Running mpt_dead_ioc thread success !\n",
400 ioc->name, __func__);
401 }
402 return; /* don't rearm timer */
403 }
404
405 if ((ioc_raw_state & MPI_IOC_STATE_MASK)
406 == MPI_IOC_STATE_FAULT) {
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530407 printk(MYIOC_s_WARN_FMT "IOC is in FAULT state (%04xh)!!!\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700408 ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530409 printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700410 ioc->name, __func__);
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530411 rc = mpt_HardResetHandler(ioc, CAN_SLEEP);
412 printk(MYIOC_s_WARN_FMT "%s: HardReset: %s\n", ioc->name,
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700413 __func__, (rc == 0) ? "success" : "failed");
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530414 ioc_raw_state = mpt_GetIocState(ioc, 0);
415 if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT)
416 printk(MYIOC_s_WARN_FMT "IOC is in FAULT state after "
417 "reset (%04xh)\n", ioc->name, ioc_raw_state &
418 MPI_DOORBELL_DATA_MASK);
Kashyap, Desai7b5a65b2009-05-29 16:38:14 +0530419 } else if (ioc->bus_type == SAS && ioc->sas_discovery_quiesce_io) {
420 if ((mpt_is_discovery_complete(ioc))) {
421 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "clearing "
422 "discovery_quiesce_io flag\n", ioc->name));
423 ioc->sas_discovery_quiesce_io = 0;
424 }
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530425 }
426
427 out:
428 /*
429 * Take turns polling alternate controller
430 */
431 if (ioc->alt_ioc)
432 ioc = ioc->alt_ioc;
433
434 /* rearm the timer */
Kashyap, Desai2f187862009-05-29 16:52:37 +0530435 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530436 if (ioc->reset_work_q)
437 queue_delayed_work(ioc->reset_work_q, &ioc->fault_reset_work,
438 msecs_to_jiffies(MPT_POLLING_INTERVAL));
Kashyap, Desai2f187862009-05-29 16:52:37 +0530439 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
Prakash, Sathyad54d48b2008-05-21 01:02:18 +0530440}
441
442
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600443/*
444 * Process turbo (context) reply...
445 */
446static void
447mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa)
448{
449 MPT_FRAME_HDR *mf = NULL;
450 MPT_FRAME_HDR *mr = NULL;
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530451 u16 req_idx = 0;
452 u8 cb_idx;
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600453
Prakash, Sathya436ace72007-07-24 15:42:08 +0530454 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got TURBO reply req_idx=%08x\n",
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600455 ioc->name, pa));
456
457 switch (pa >> MPI_CONTEXT_REPLY_TYPE_SHIFT) {
458 case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT:
459 req_idx = pa & 0x0000FFFF;
460 cb_idx = (pa & 0x00FF0000) >> 16;
461 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
462 break;
463 case MPI_CONTEXT_REPLY_TYPE_LAN:
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530464 cb_idx = mpt_get_cb_idx(MPTLAN_DRIVER);
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600465 /*
466 * Blind set of mf to NULL here was fatal
467 * after lan_reply says "freeme"
468 * Fix sort of combined with an optimization here;
469 * added explicit check for case where lan_reply
470 * was just returning 1 and doing nothing else.
471 * For this case skip the callback, but set up
472 * proper mf value first here:-)
473 */
474 if ((pa & 0x58000000) == 0x58000000) {
475 req_idx = pa & 0x0000FFFF;
476 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
477 mpt_free_msg_frame(ioc, mf);
478 mb();
479 return;
480 break;
481 }
482 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
483 break;
484 case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET:
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530485 cb_idx = mpt_get_cb_idx(MPTSTM_DRIVER);
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600486 mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
487 break;
488 default:
489 cb_idx = 0;
490 BUG();
491 }
492
493 /* Check for (valid) IO callback! */
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530494 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
Eric Moore8d6d83e2007-09-14 18:47:40 -0600495 MptCallbacks[cb_idx] == NULL) {
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600496 printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700497 __func__, ioc->name, cb_idx);
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600498 goto out;
499 }
500
501 if (MptCallbacks[cb_idx](ioc, mf, mr))
502 mpt_free_msg_frame(ioc, mf);
503 out:
504 mb();
505}
506
507static void
508mpt_reply(MPT_ADAPTER *ioc, u32 pa)
509{
510 MPT_FRAME_HDR *mf;
511 MPT_FRAME_HDR *mr;
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530512 u16 req_idx;
513 u8 cb_idx;
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600514 int freeme;
515
516 u32 reply_dma_low;
517 u16 ioc_stat;
518
519 /* non-TURBO reply! Hmmm, something may be up...
520 * Newest turbo reply mechanism; get address
521 * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
522 */
523
524 /* Map DMA address of reply header to cpu address.
525 * pa is 32 bits - but the dma address may be 32 or 64 bits
526 * get offset based only only the low addresses
527 */
528
529 reply_dma_low = (pa <<= 1);
530 mr = (MPT_FRAME_HDR *)((u8 *)ioc->reply_frames +
531 (reply_dma_low - ioc->reply_frames_low_dma));
532
533 req_idx = le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx);
534 cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
535 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
536
Prakash, Sathya436ace72007-07-24 15:42:08 +0530537 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got non-TURBO reply=%p req_idx=%x cb_idx=%x Function=%x\n",
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600538 ioc->name, mr, req_idx, cb_idx, mr->u.hdr.Function));
Eric Moore29dd3602007-09-14 18:46:51 -0600539 DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mr);
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600540
541 /* Check/log IOC log info
542 */
543 ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
544 if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
545 u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
546 if (ioc->bus_type == FC)
547 mpt_fc_log_info(ioc, log_info);
Moore, Eric Deana9b29372005-11-16 18:54:20 -0700548 else if (ioc->bus_type == SPI)
Moore, Eric335a9412006-01-17 17:06:23 -0700549 mpt_spi_log_info(ioc, log_info);
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600550 else if (ioc->bus_type == SAS)
Kashyap, Desai213aaca2010-07-26 18:57:36 +0530551 mpt_sas_log_info(ioc, log_info, cb_idx);
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600552 }
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600553
Eric Moorec6c727a2007-01-29 09:44:54 -0700554 if (ioc_stat & MPI_IOCSTATUS_MASK)
555 mpt_iocstatus_info(ioc, (u32)ioc_stat, mf);
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600556
557 /* Check for (valid) IO callback! */
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530558 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
Eric Moore8d6d83e2007-09-14 18:47:40 -0600559 MptCallbacks[cb_idx] == NULL) {
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600560 printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -0700561 __func__, ioc->name, cb_idx);
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600562 freeme = 0;
563 goto out;
564 }
565
566 freeme = MptCallbacks[cb_idx](ioc, mf, mr);
567
568 out:
569 /* Flush (non-TURBO) reply with a WRITE! */
570 CHIPREG_WRITE32(&ioc->chip->ReplyFifo, pa);
571
572 if (freeme)
573 mpt_free_msg_frame(ioc, mf);
574 mb();
575}
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -0800578/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
580 * @irq: irq number (not used)
581 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 *
583 * This routine is registered via the request_irq() kernel API call,
584 * and handles all interrupts generated from a specific MPT adapter
585 * (also referred to as a IO Controller or IOC).
586 * This routine must clear the interrupt from the adapter and does
587 * so by reading the reply FIFO. Multiple replies may be processed
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200588 * per single call to this routine.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 *
590 * This routine handles register-level access of the adapter but
591 * dispatches (calls) a protocol-specific callback routine to handle
592 * the protocol-specific details of the MPT request completion.
593 */
594static irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100595mpt_interrupt(int irq, void *bus_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600597 MPT_ADAPTER *ioc = bus_id;
Eric Moore3e00a5b2006-06-29 17:38:43 -0600598 u32 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
599
600 if (pa == 0xFFFFFFFF)
601 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 /*
604 * Drain the reply FIFO!
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 */
Eric Moore3e00a5b2006-06-29 17:38:43 -0600606 do {
607 if (pa & MPI_ADDRESS_REPLY_A_BIT)
Moore, Eric Dean466544d2005-09-14 18:09:10 -0600608 mpt_reply(ioc, pa);
609 else
610 mpt_turbo_reply(ioc, pa);
Eric Moore3e00a5b2006-06-29 17:38:43 -0600611 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
612 } while (pa != 0xFFFFFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614 return IRQ_HANDLED;
615}
616
617/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -0800618/**
Kashyap, Desaif0f09d32009-05-29 16:40:57 +0530619 * mptbase_reply - MPT base driver's callback routine
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 * @ioc: Pointer to MPT_ADAPTER structure
Kashyap, Desaif0f09d32009-05-29 16:40:57 +0530621 * @req: Pointer to original MPT request frame
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 * @reply: Pointer to MPT reply frame (NULL if TurboReply)
623 *
Randy Dunlapd9489fb2006-12-06 20:38:43 -0800624 * MPT base driver's callback routine; all base driver
625 * "internal" request/reply processing is routed here.
626 * Currently used for EventNotification and EventAck handling.
627 *
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200628 * Returns 1 indicating original alloc'd request frame ptr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 * should be freed, or 0 if it shouldn't.
630 */
631static int
Kashyap, Desaif0f09d32009-05-29 16:40:57 +0530632mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
Kashyap, Desaif0f09d32009-05-29 16:40:57 +0530634 EventNotificationReply_t *pEventReply;
635 u8 event;
636 int evHandlers;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 int freereq = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Kashyap, Desaif0f09d32009-05-29 16:40:57 +0530639 switch (reply->u.hdr.Function) {
640 case MPI_FUNCTION_EVENT_NOTIFICATION:
641 pEventReply = (EventNotificationReply_t *)reply;
642 evHandlers = 0;
643 ProcessEventNotification(ioc, pEventReply, &evHandlers);
644 event = le32_to_cpu(pEventReply->Event) & 0xFF;
645 if (pEventReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 freereq = 0;
Kashyap, Desaif0f09d32009-05-29 16:40:57 +0530647 if (event != MPI_EVENT_EVENT_CHANGE)
648 break;
649 case MPI_FUNCTION_CONFIG:
650 case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
651 ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
Joe Lawrence9f213162014-06-25 17:06:54 -0400652 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));
Kashyap, Desaif0f09d32009-05-29 16:40:57 +0530656 if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
657 ioc->mptbase_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
658 complete(&ioc->mptbase_cmds.done);
659 } else
660 freereq = 0;
661 if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_FREE_MF)
662 freereq = 1;
663 break;
664 case MPI_FUNCTION_EVENT_ACK:
665 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
666 "EventAck reply received\n", ioc->name));
667 break;
668 default:
669 printk(MYIOC_s_ERR_FMT
670 "Unexpected msg function (=%02Xh) reply received!\n",
671 ioc->name, reply->u.hdr.Function);
672 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 }
674
675 /*
676 * Conditionally tell caller to free the original
677 * EventNotification/EventAck/unexpected request frame!
678 */
679 return freereq;
680}
681
682/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
683/**
684 * mpt_register - Register protocol-specific main callback handler.
685 * @cbfunc: callback function pointer
686 * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
Randy Dunlapfc58fb12010-08-14 13:05:57 -0700687 * @func_name: call function's name
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 *
689 * This routine is called by a protocol-specific driver (SCSI host,
Randy Dunlapd9489fb2006-12-06 20:38:43 -0800690 * LAN, SCSI target) to register its reply callback routine. Each
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 * protocol-specific driver must do this before it will be able to
692 * use any IOC resources, such as obtaining request frames.
693 *
694 * NOTES: The SCSI protocol driver currently calls this routine thrice
695 * in order to register separate callbacks; one for "normal" SCSI IO;
696 * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
697 *
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530698 * Returns u8 valued "handle" in the range (and S.O.D. order)
699 * {N,...,7,6,5,...,1} if successful.
700 * A return value of MPT_MAX_PROTOCOL_DRIVERS (including zero!) should be
701 * considered an error by the caller.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 */
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530703u8
Kashyap, Desai213aaca2010-07-26 18:57:36 +0530704mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass, char *func_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530706 u8 cb_idx;
707 last_drv_idx = MPT_MAX_PROTOCOL_DRIVERS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
709 /*
710 * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
711 * (slot/handle 0 is reserved!)
712 */
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530713 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
714 if (MptCallbacks[cb_idx] == NULL) {
715 MptCallbacks[cb_idx] = cbfunc;
716 MptDriverClass[cb_idx] = dclass;
717 MptEvHandlers[cb_idx] = NULL;
718 last_drv_idx = cb_idx;
Ferenc Wagner8af3d8d2011-08-25 14:44:57 +0200719 strlcpy(MptCallbacksName[cb_idx], func_name,
720 MPT_MAX_CALLBACKNAME_LEN+1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 break;
722 }
723 }
724
725 return last_drv_idx;
726}
727
728/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
729/**
730 * mpt_deregister - Deregister a protocol drivers resources.
731 * @cb_idx: previously registered callback handle
732 *
Randy Dunlapd9489fb2006-12-06 20:38:43 -0800733 * Each protocol-specific driver should call this routine when its
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 * module is unloaded.
735 */
736void
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530737mpt_deregister(u8 cb_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738{
Eric Moore8d6d83e2007-09-14 18:47:40 -0600739 if (cb_idx && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 MptCallbacks[cb_idx] = NULL;
741 MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
742 MptEvHandlers[cb_idx] = NULL;
743
744 last_drv_idx++;
745 }
746}
747
748/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
749/**
Randy Dunlap7105a382008-02-29 22:03:27 -0800750 * mpt_event_register - Register protocol-specific event callback handler.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 * @cb_idx: previously registered (via mpt_register) callback handle
752 * @ev_cbfunc: callback function
753 *
754 * This routine can be called by one or more protocol-specific drivers
755 * if/when they choose to be notified of MPT events.
756 *
757 * Returns 0 for success.
758 */
759int
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530760mpt_event_register(u8 cb_idx, MPT_EVHANDLER ev_cbfunc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761{
Eric Moore8d6d83e2007-09-14 18:47:40 -0600762 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 return -1;
764
765 MptEvHandlers[cb_idx] = ev_cbfunc;
766 return 0;
767}
768
769/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
770/**
Randy Dunlap7105a382008-02-29 22:03:27 -0800771 * mpt_event_deregister - Deregister protocol-specific event callback handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 * @cb_idx: previously registered callback handle
773 *
774 * Each protocol-specific driver should call this routine
775 * when it does not (or can no longer) handle events,
Randy Dunlapd9489fb2006-12-06 20:38:43 -0800776 * or when its module is unloaded.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 */
778void
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530779mpt_event_deregister(u8 cb_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
Eric Moore8d6d83e2007-09-14 18:47:40 -0600781 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 return;
783
784 MptEvHandlers[cb_idx] = NULL;
785}
786
787/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
788/**
789 * mpt_reset_register - Register protocol-specific IOC reset handler.
790 * @cb_idx: previously registered (via mpt_register) callback handle
791 * @reset_func: reset function
792 *
793 * This routine can be called by one or more protocol-specific drivers
794 * if/when they choose to be notified of IOC resets.
795 *
796 * Returns 0 for success.
797 */
798int
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530799mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800{
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530801 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 return -1;
803
804 MptResetHandlers[cb_idx] = reset_func;
805 return 0;
806}
807
808/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
809/**
810 * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
811 * @cb_idx: previously registered callback handle
812 *
813 * Each protocol-specific driver should call this routine
814 * when it does not (or can no longer) handle IOC reset handling,
Randy Dunlapd9489fb2006-12-06 20:38:43 -0800815 * or when its module is unloaded.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 */
817void
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530818mpt_reset_deregister(u8 cb_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819{
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530820 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 return;
822
823 MptResetHandlers[cb_idx] = NULL;
824}
825
826/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
827/**
828 * mpt_device_driver_register - Register device driver hooks
Randy Dunlapd9489fb2006-12-06 20:38:43 -0800829 * @dd_cbfunc: driver callbacks struct
830 * @cb_idx: MPT protocol driver index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 */
832int
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530833mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
835 MPT_ADAPTER *ioc;
Eric Moored58b2722006-07-11 17:23:23 -0600836 const struct pci_device_id *id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
Eric Moore8d6d83e2007-09-14 18:47:40 -0600838 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -0400839 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
842
843 /* call per pci device probe entry point */
844 list_for_each_entry(ioc, &ioc_list, list) {
Eric Moored58b2722006-07-11 17:23:23 -0600845 id = ioc->pcidev->driver ?
846 ioc->pcidev->driver->id_table : NULL;
847 if (dd_cbfunc->probe)
848 dd_cbfunc->probe(ioc->pcidev, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
850
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -0400851 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852}
853
854/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
855/**
856 * mpt_device_driver_deregister - DeRegister device driver hooks
Randy Dunlapd9489fb2006-12-06 20:38:43 -0800857 * @cb_idx: MPT protocol driver index
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 */
859void
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530860mpt_device_driver_deregister(u8 cb_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
862 struct mpt_pci_driver *dd_cbfunc;
863 MPT_ADAPTER *ioc;
864
Eric Moore8d6d83e2007-09-14 18:47:40 -0600865 if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 return;
867
868 dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
869
870 list_for_each_entry(ioc, &ioc_list, list) {
871 if (dd_cbfunc->remove)
872 dd_cbfunc->remove(ioc->pcidev);
873 }
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 MptDeviceDriverHandlers[cb_idx] = NULL;
876}
877
878
879/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
880/**
Randy Dunlap7105a382008-02-29 22:03:27 -0800881 * mpt_get_msg_frame - Obtain an MPT request frame from the pool
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530882 * @cb_idx: Handle of registered MPT protocol driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 * @ioc: Pointer to MPT adapter structure
884 *
Randy Dunlap7105a382008-02-29 22:03:27 -0800885 * Obtain an MPT request frame from the pool (of 1024) that are
886 * allocated per MPT adapter.
887 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 * Returns pointer to a MPT request frame or %NULL if none are available
889 * or IOC is not active.
890 */
891MPT_FRAME_HDR*
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530892mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893{
894 MPT_FRAME_HDR *mf;
895 unsigned long flags;
896 u16 req_idx; /* Request index */
897
898 /* validate handle and ioc identifier */
899
900#ifdef MFCNT
901 if (!ioc->active)
Eric Moore29dd3602007-09-14 18:46:51 -0600902 printk(MYIOC_s_WARN_FMT "IOC Not Active! mpt_get_msg_frame "
903 "returning NULL!\n", ioc->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904#endif
905
906 /* If interrupts are not attached, do not return a request frame */
907 if (!ioc->active)
908 return NULL;
909
910 spin_lock_irqsave(&ioc->FreeQlock, flags);
911 if (!list_empty(&ioc->FreeQ)) {
912 int req_offset;
913
914 mf = list_entry(ioc->FreeQ.next, MPT_FRAME_HDR,
915 u.frame.linkage.list);
916 list_del(&mf->u.frame.linkage.list);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +0200917 mf->u.frame.linkage.arg1 = 0;
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530918 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx; /* byte */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
920 /* u16! */
Moore, Eric Dean d335cc32005-04-30 17:09:38 -0500921 req_idx = req_offset / ioc->req_sz;
922 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
Eric Moore29dd3602007-09-14 18:46:51 -0600924 /* Default, will be changed if necessary in SG generation */
925 ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926#ifdef MFCNT
927 ioc->mfcnt++;
928#endif
929 }
930 else
931 mf = NULL;
932 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
933
934#ifdef MFCNT
935 if (mf == NULL)
Eric Moore29dd3602007-09-14 18:46:51 -0600936 printk(MYIOC_s_WARN_FMT "IOC Active. No free Msg Frames! "
937 "Count 0x%x Max 0x%x\n", ioc->name, ioc->mfcnt,
938 ioc->req_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 mfcounter++;
940 if (mfcounter == PRINT_MF_COUNT)
Eric Moore29dd3602007-09-14 18:46:51 -0600941 printk(MYIOC_s_INFO_FMT "MF Count 0x%x Max 0x%x \n", ioc->name,
942 ioc->mfcnt, ioc->req_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943#endif
944
Eric Moore29dd3602007-09-14 18:46:51 -0600945 dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_get_msg_frame(%d,%d), got mf=%p\n",
946 ioc->name, cb_idx, ioc->id, mf));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 return mf;
948}
949
950/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
951/**
Randy Dunlap7105a382008-02-29 22:03:27 -0800952 * mpt_put_msg_frame - Send a protocol-specific MPT request frame to an IOC
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530953 * @cb_idx: Handle of registered MPT protocol driver
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 * @ioc: Pointer to MPT adapter structure
955 * @mf: Pointer to MPT request frame
956 *
Randy Dunlap7105a382008-02-29 22:03:27 -0800957 * This routine posts an MPT request frame to the request post FIFO of a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 * specific MPT adapter.
959 */
960void
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530961mpt_put_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962{
963 u32 mf_dma_addr;
964 int req_offset;
965 u16 req_idx; /* Request index */
966
967 /* ensure values are reset properly! */
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530968 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx; /* byte */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
970 /* u16! */
Moore, Eric Dean d335cc32005-04-30 17:09:38 -0500971 req_idx = req_offset / ioc->req_sz;
972 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
974
Prakash, Sathya436ace72007-07-24 15:42:08 +0530975 DBG_DUMP_PUT_MSG_FRAME(ioc, (u32 *)mf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
Christoph Hellwigc6678e02005-08-18 16:24:53 +0200977 mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
Eric Moore29dd3602007-09-14 18:46:51 -0600978 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mf_dma_addr=%x req_idx=%d "
979 "RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx,
980 ioc->RequestNB[req_idx]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
982}
983
Prakash, Sathya7a195f42007-08-14 16:08:40 +0530984/**
Randy Dunlap7105a382008-02-29 22:03:27 -0800985 * mpt_put_msg_frame_hi_pri - Send a hi-pri protocol-specific MPT request frame
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530986 * @cb_idx: Handle of registered MPT protocol driver
Prakash, Sathya7a195f42007-08-14 16:08:40 +0530987 * @ioc: Pointer to MPT adapter structure
988 * @mf: Pointer to MPT request frame
989 *
Randy Dunlap7105a382008-02-29 22:03:27 -0800990 * Send a protocol-specific MPT request frame to an IOC using
991 * hi-priority request queue.
992 *
993 * This routine posts an MPT request frame to the request post FIFO of a
Prakash, Sathya7a195f42007-08-14 16:08:40 +0530994 * specific MPT adapter.
995 **/
996void
Prakash, Sathyaf606f572007-08-14 16:12:53 +0530997mpt_put_msg_frame_hi_pri(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
Prakash, Sathya7a195f42007-08-14 16:08:40 +0530998{
999 u32 mf_dma_addr;
1000 int req_offset;
1001 u16 req_idx; /* Request index */
1002
1003 /* ensure values are reset properly! */
Prakash, Sathyaf606f572007-08-14 16:12:53 +05301004 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;
Prakash, Sathya7a195f42007-08-14 16:08:40 +05301005 req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
1006 req_idx = req_offset / ioc->req_sz;
1007 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
1008 mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
1009
1010 DBG_DUMP_PUT_MSG_FRAME(ioc, (u32 *)mf);
1011
1012 mf_dma_addr = (ioc->req_frames_low_dma + req_offset);
1013 dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mf_dma_addr=%x req_idx=%d\n",
1014 ioc->name, mf_dma_addr, req_idx));
1015 CHIPREG_WRITE32(&ioc->chip->RequestHiPriFifo, mf_dma_addr);
1016}
1017
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1019/**
1020 * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 * @ioc: Pointer to MPT adapter structure
1022 * @mf: Pointer to MPT request frame
1023 *
1024 * This routine places a MPT request frame back on the MPT adapter's
1025 * FreeQ.
1026 */
1027void
1028mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
1029{
1030 unsigned long flags;
1031
1032 /* Put Request back on FreeQ! */
1033 spin_lock_irqsave(&ioc->FreeQlock, flags);
Kashyap, Desai2f187862009-05-29 16:52:37 +05301034 if (cpu_to_le32(mf->u.frame.linkage.arg1) == 0xdeadbeaf)
1035 goto out;
1036 /* signature to know if this mf is freed */
1037 mf->u.frame.linkage.arg1 = cpu_to_le32(0xdeadbeaf);
Matthew Wilcoxecc3bc92014-03-27 16:40:35 -04001038 list_add(&mf->u.frame.linkage.list, &ioc->FreeQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039#ifdef MFCNT
1040 ioc->mfcnt--;
1041#endif
Kashyap, Desai2f187862009-05-29 16:52:37 +05301042 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
1044}
1045
1046/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1047/**
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301048 * mpt_add_sge - Place a simple 32 bit SGE at address pAddr.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 * @pAddr: virtual address for SGE
1050 * @flagslength: SGE flags and data transfer length
1051 * @dma_addr: Physical address
1052 *
1053 * This routine places a MPT request frame back on the MPT adapter's
1054 * FreeQ.
1055 */
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301056static void
1057mpt_add_sge(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058{
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301059 SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
1060 pSge->FlagsLength = cpu_to_le32(flagslength);
1061 pSge->Address = cpu_to_le32(dma_addr);
1062}
1063
1064/**
1065 * mpt_add_sge_64bit - Place a simple 64 bit SGE at address pAddr.
1066 * @pAddr: virtual address for SGE
1067 * @flagslength: SGE flags and data transfer length
1068 * @dma_addr: Physical address
1069 *
1070 * This routine places a MPT request frame back on the MPT adapter's
1071 * FreeQ.
1072 **/
1073static void
1074mpt_add_sge_64bit(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
1075{
1076 SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
1077 pSge->Address.Low = cpu_to_le32
Kashyap, Desaic55b89f2009-09-02 11:44:57 +05301078 (lower_32_bits(dma_addr));
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301079 pSge->Address.High = cpu_to_le32
Kashyap, Desaic55b89f2009-09-02 11:44:57 +05301080 (upper_32_bits(dma_addr));
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301081 pSge->FlagsLength = cpu_to_le32
1082 ((flagslength | MPT_SGE_FLAGS_64_BIT_ADDRESSING));
1083}
1084
1085/**
Randy Dunlap9cf46a32009-06-13 19:37:18 -07001086 * mpt_add_sge_64bit_1078 - Place a simple 64 bit SGE at address pAddr (1078 workaround).
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301087 * @pAddr: virtual address for SGE
1088 * @flagslength: SGE flags and data transfer length
1089 * @dma_addr: Physical address
1090 *
1091 * This routine places a MPT request frame back on the MPT adapter's
1092 * FreeQ.
1093 **/
1094static void
1095mpt_add_sge_64bit_1078(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
1096{
1097 SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
1098 u32 tmp;
1099
1100 pSge->Address.Low = cpu_to_le32
Kashyap, Desaic55b89f2009-09-02 11:44:57 +05301101 (lower_32_bits(dma_addr));
1102 tmp = (u32)(upper_32_bits(dma_addr));
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301103
1104 /*
1105 * 1078 errata workaround for the 36GB limitation
1106 */
1107 if ((((u64)dma_addr + MPI_SGE_LENGTH(flagslength)) >> 32) == 9) {
1108 flagslength |=
1109 MPI_SGE_SET_FLAGS(MPI_SGE_FLAGS_LOCAL_ADDRESS);
1110 tmp |= (1<<31);
1111 if (mpt_debug_level & MPT_DEBUG_36GB_MEM)
1112 printk(KERN_DEBUG "1078 P0M2 addressing for "
1113 "addr = 0x%llx len = %d\n",
1114 (unsigned long long)dma_addr,
1115 MPI_SGE_LENGTH(flagslength));
1116 }
1117
1118 pSge->Address.High = cpu_to_le32(tmp);
1119 pSge->FlagsLength = cpu_to_le32(
1120 (flagslength | MPT_SGE_FLAGS_64_BIT_ADDRESSING));
1121}
1122
1123/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1124/**
1125 * mpt_add_chain - Place a 32 bit chain SGE at address pAddr.
1126 * @pAddr: virtual address for SGE
1127 * @next: nextChainOffset value (u32's)
1128 * @length: length of next SGL segment
1129 * @dma_addr: Physical address
1130 *
1131 */
1132static void
1133mpt_add_chain(void *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
1134{
1135 SGEChain32_t *pChain = (SGEChain32_t *) pAddr;
1136 pChain->Length = cpu_to_le16(length);
1137 pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT;
1138 pChain->NextChainOffset = next;
1139 pChain->Address = cpu_to_le32(dma_addr);
1140}
1141
1142/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1143/**
1144 * mpt_add_chain_64bit - Place a 64 bit chain SGE at address pAddr.
1145 * @pAddr: virtual address for SGE
1146 * @next: nextChainOffset value (u32's)
1147 * @length: length of next SGL segment
1148 * @dma_addr: Physical address
1149 *
1150 */
1151static void
1152mpt_add_chain_64bit(void *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
1153{
1154 SGEChain64_t *pChain = (SGEChain64_t *) pAddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 u32 tmp = dma_addr & 0xFFFFFFFF;
1156
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301157 pChain->Length = cpu_to_le16(length);
1158 pChain->Flags = (MPI_SGE_FLAGS_CHAIN_ELEMENT |
1159 MPI_SGE_FLAGS_64_BIT_ADDRESSING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301161 pChain->NextChainOffset = next;
1162
1163 pChain->Address.Low = cpu_to_le32(tmp);
Kashyap, Desaic55b89f2009-09-02 11:44:57 +05301164 tmp = (u32)(upper_32_bits(dma_addr));
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301165 pChain->Address.High = cpu_to_le32(tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166}
1167
1168/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1169/**
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001170 * mpt_send_handshake_request - Send MPT request via doorbell handshake method.
Prakash, Sathyaf606f572007-08-14 16:12:53 +05301171 * @cb_idx: Handle of registered MPT protocol driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 * @ioc: Pointer to MPT adapter structure
1173 * @reqBytes: Size of the request in bytes
1174 * @req: Pointer to MPT request frame
1175 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
1176 *
1177 * This routine is used exclusively to send MptScsiTaskMgmt
1178 * requests since they are required to be sent via doorbell handshake.
1179 *
1180 * NOTE: It is the callers responsibility to byte-swap fields in the
1181 * request which are greater than 1 byte in size.
1182 *
1183 * Returns 0 for success, non-zero for failure.
1184 */
1185int
Prakash, Sathyaf606f572007-08-14 16:12:53 +05301186mpt_send_handshake_request(u8 cb_idx, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187{
Eric Moorecd2c6192007-01-29 09:47:47 -07001188 int r = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 u8 *req_as_bytes;
1190 int ii;
1191
1192 /* State is known to be good upon entering
1193 * this function so issue the bus reset
1194 * request.
1195 */
1196
1197 /*
1198 * Emulate what mpt_put_msg_frame() does /wrt to sanity
1199 * setting cb_idx/req_idx. But ONLY if this request
1200 * is in proper (pre-alloc'd) request buffer range...
1201 */
1202 ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
1203 if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
1204 MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
1205 mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
Prakash, Sathyaf606f572007-08-14 16:12:53 +05301206 mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 }
1208
1209 /* Make sure there are no doorbells */
1210 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001211
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 CHIPREG_WRITE32(&ioc->chip->Doorbell,
1213 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
1214 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
1215
1216 /* Wait for IOC doorbell int */
1217 if ((ii = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0) {
1218 return ii;
1219 }
1220
1221 /* Read doorbell and check for active bit */
1222 if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
1223 return -5;
1224
Eric Moore29dd3602007-09-14 18:46:51 -06001225 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_send_handshake_request start, WaitCnt=%d\n",
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001226 ioc->name, ii));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
1228 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1229
1230 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
1231 return -2;
1232 }
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001233
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 /* Send request via doorbell handshake */
1235 req_as_bytes = (u8 *) req;
1236 for (ii = 0; ii < reqBytes/4; ii++) {
1237 u32 word;
1238
1239 word = ((req_as_bytes[(ii*4) + 0] << 0) |
1240 (req_as_bytes[(ii*4) + 1] << 8) |
1241 (req_as_bytes[(ii*4) + 2] << 16) |
1242 (req_as_bytes[(ii*4) + 3] << 24));
1243 CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
1244 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
1245 r = -3;
1246 break;
1247 }
1248 }
1249
1250 if (r >= 0 && WaitForDoorbellInt(ioc, 10, sleepFlag) >= 0)
1251 r = 0;
1252 else
1253 r = -4;
1254
1255 /* Make sure there are no doorbells */
1256 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02001257
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 return r;
1259}
1260
1261/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1262/**
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001263 * mpt_host_page_access_control - control the IOC's Host Page Buffer access
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02001264 * @ioc: Pointer to MPT adapter structure
1265 * @access_control_value: define bits below
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001266 * @sleepFlag: Specifies whether the process can sleep
1267 *
1268 * Provides mechanism for the host driver to control the IOC's
1269 * Host Page Buffer access.
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02001270 *
1271 * Access Control Value - bits[15:12]
1272 * 0h Reserved
1273 * 1h Enable Access { MPI_DB_HPBAC_ENABLE_ACCESS }
1274 * 2h Disable Access { MPI_DB_HPBAC_DISABLE_ACCESS }
1275 * 3h Free Buffer { MPI_DB_HPBAC_FREE_BUFFER }
1276 *
1277 * Returns 0 for success, non-zero for failure.
1278 */
1279
1280static int
1281mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag)
1282{
1283 int r = 0;
1284
1285 /* return if in use */
1286 if (CHIPREG_READ32(&ioc->chip->Doorbell)
1287 & MPI_DOORBELL_ACTIVE)
1288 return -1;
1289
1290 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1291
1292 CHIPREG_WRITE32(&ioc->chip->Doorbell,
1293 ((MPI_FUNCTION_HOST_PAGEBUF_ACCESS_CONTROL
1294 <<MPI_DOORBELL_FUNCTION_SHIFT) |
1295 (access_control_value<<12)));
1296
1297 /* Wait for IOC to clear Doorbell Status bit */
1298 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
1299 return -2;
1300 }else
1301 return 0;
1302}
1303
1304/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1305/**
1306 * mpt_host_page_alloc - allocate system memory for the fw
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001307 * @ioc: Pointer to pointer to IOC adapter
1308 * @ioc_init: Pointer to ioc init config page
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02001309 *
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001310 * If we already allocated memory in past, then resend the same pointer.
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02001311 * Returns 0 for success, non-zero for failure.
1312 */
1313static int
1314mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
1315{
1316 char *psge;
1317 int flags_length;
1318 u32 host_page_buffer_sz=0;
1319
1320 if(!ioc->HostPageBuffer) {
1321
1322 host_page_buffer_sz =
1323 le32_to_cpu(ioc->facts.HostPageBufferSGE.FlagsLength) & 0xFFFFFF;
1324
1325 if(!host_page_buffer_sz)
1326 return 0; /* fw doesn't need any host buffers */
1327
1328 /* spin till we get enough memory */
1329 while(host_page_buffer_sz > 0) {
1330
1331 if((ioc->HostPageBuffer = pci_alloc_consistent(
1332 ioc->pcidev,
1333 host_page_buffer_sz,
1334 &ioc->HostPageBuffer_dma)) != NULL) {
1335
Prakash, Sathya436ace72007-07-24 15:42:08 +05301336 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02001337 "host_page_buffer @ %p, dma @ %x, sz=%d bytes\n",
Eric Mooreba856d32006-07-11 17:34:01 -06001338 ioc->name, ioc->HostPageBuffer,
1339 (u32)ioc->HostPageBuffer_dma,
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001340 host_page_buffer_sz));
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02001341 ioc->alloc_total += host_page_buffer_sz;
1342 ioc->HostPageBuffer_sz = host_page_buffer_sz;
1343 break;
1344 }
1345
1346 host_page_buffer_sz -= (4*1024);
1347 }
1348 }
1349
1350 if(!ioc->HostPageBuffer) {
1351 printk(MYIOC_s_ERR_FMT
1352 "Failed to alloc memory for host_page_buffer!\n",
1353 ioc->name);
1354 return -999;
1355 }
1356
1357 psge = (char *)&ioc_init->HostPageBufferSGE;
1358 flags_length = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
1359 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02001360 MPI_SGE_FLAGS_HOST_TO_IOC |
1361 MPI_SGE_FLAGS_END_OF_BUFFER;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02001362 flags_length = flags_length << MPI_SGE_FLAGS_SHIFT;
1363 flags_length |= ioc->HostPageBuffer_sz;
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301364 ioc->add_sge(psge, flags_length, ioc->HostPageBuffer_dma);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02001365 ioc->facts.HostPageBufferSGE = ioc_init->HostPageBufferSGE;
1366
1367return 0;
1368}
1369
1370/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1371/**
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001372 * mpt_verify_adapter - Given IOC identifier, set pointer to its adapter structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 * @iocid: IOC unique identifier (integer)
1374 * @iocpp: Pointer to pointer to IOC adapter
1375 *
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001376 * Given a unique IOC identifier, set pointer to the associated MPT
1377 * adapter structure.
1378 *
1379 * Returns iocid and sets iocpp if iocid is found.
1380 * Returns -1 if iocid is not found.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 */
1382int
1383mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
1384{
1385 MPT_ADAPTER *ioc;
1386
1387 list_for_each_entry(ioc,&ioc_list,list) {
1388 if (ioc->id == iocid) {
1389 *iocpp =ioc;
1390 return iocid;
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001391 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 }
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001393
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 *iocpp = NULL;
1395 return -1;
1396}
1397
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05301398/**
1399 * mpt_get_product_name - returns product string
1400 * @vendor: pci vendor id
1401 * @device: pci device id
1402 * @revision: pci revision id
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05301403 *
1404 * Returns product string displayed when driver loads,
1405 * in /proc/mpt/summary and /sysfs/class/scsi_host/host<X>/version_product
1406 *
1407 **/
Joe Lawrencec9834c72014-06-25 17:06:28 -04001408static const char*
1409mpt_get_product_name(u16 vendor, u16 device, u8 revision)
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05301410{
1411 char *product_str = NULL;
1412
1413 if (vendor == PCI_VENDOR_ID_BROCADE) {
1414 switch (device)
1415 {
1416 case MPI_MANUFACTPAGE_DEVICEID_FC949E:
1417 switch (revision)
1418 {
1419 case 0x00:
1420 product_str = "BRE040 A0";
1421 break;
1422 case 0x01:
1423 product_str = "BRE040 A1";
1424 break;
1425 default:
1426 product_str = "BRE040";
1427 break;
1428 }
1429 break;
1430 }
1431 goto out;
1432 }
1433
1434 switch (device)
1435 {
1436 case MPI_MANUFACTPAGE_DEVICEID_FC909:
1437 product_str = "LSIFC909 B1";
1438 break;
1439 case MPI_MANUFACTPAGE_DEVICEID_FC919:
1440 product_str = "LSIFC919 B0";
1441 break;
1442 case MPI_MANUFACTPAGE_DEVICEID_FC929:
1443 product_str = "LSIFC929 B0";
1444 break;
1445 case MPI_MANUFACTPAGE_DEVICEID_FC919X:
1446 if (revision < 0x80)
1447 product_str = "LSIFC919X A0";
1448 else
1449 product_str = "LSIFC919XL A1";
1450 break;
1451 case MPI_MANUFACTPAGE_DEVICEID_FC929X:
1452 if (revision < 0x80)
1453 product_str = "LSIFC929X A0";
1454 else
1455 product_str = "LSIFC929XL A1";
1456 break;
1457 case MPI_MANUFACTPAGE_DEVICEID_FC939X:
1458 product_str = "LSIFC939X A1";
1459 break;
1460 case MPI_MANUFACTPAGE_DEVICEID_FC949X:
1461 product_str = "LSIFC949X A1";
1462 break;
1463 case MPI_MANUFACTPAGE_DEVICEID_FC949E:
1464 switch (revision)
1465 {
1466 case 0x00:
1467 product_str = "LSIFC949E A0";
1468 break;
1469 case 0x01:
1470 product_str = "LSIFC949E A1";
1471 break;
1472 default:
1473 product_str = "LSIFC949E";
1474 break;
1475 }
1476 break;
1477 case MPI_MANUFACTPAGE_DEVID_53C1030:
1478 switch (revision)
1479 {
1480 case 0x00:
1481 product_str = "LSI53C1030 A0";
1482 break;
1483 case 0x01:
1484 product_str = "LSI53C1030 B0";
1485 break;
1486 case 0x03:
1487 product_str = "LSI53C1030 B1";
1488 break;
1489 case 0x07:
1490 product_str = "LSI53C1030 B2";
1491 break;
1492 case 0x08:
1493 product_str = "LSI53C1030 C0";
1494 break;
1495 case 0x80:
1496 product_str = "LSI53C1030T A0";
1497 break;
1498 case 0x83:
1499 product_str = "LSI53C1030T A2";
1500 break;
1501 case 0x87:
1502 product_str = "LSI53C1030T A3";
1503 break;
1504 case 0xc1:
1505 product_str = "LSI53C1020A A1";
1506 break;
1507 default:
1508 product_str = "LSI53C1030";
1509 break;
1510 }
1511 break;
1512 case MPI_MANUFACTPAGE_DEVID_1030_53C1035:
1513 switch (revision)
1514 {
1515 case 0x03:
1516 product_str = "LSI53C1035 A2";
1517 break;
1518 case 0x04:
1519 product_str = "LSI53C1035 B0";
1520 break;
1521 default:
1522 product_str = "LSI53C1035";
1523 break;
1524 }
1525 break;
1526 case MPI_MANUFACTPAGE_DEVID_SAS1064:
1527 switch (revision)
1528 {
1529 case 0x00:
1530 product_str = "LSISAS1064 A1";
1531 break;
1532 case 0x01:
1533 product_str = "LSISAS1064 A2";
1534 break;
1535 case 0x02:
1536 product_str = "LSISAS1064 A3";
1537 break;
1538 case 0x03:
1539 product_str = "LSISAS1064 A4";
1540 break;
1541 default:
1542 product_str = "LSISAS1064";
1543 break;
1544 }
1545 break;
1546 case MPI_MANUFACTPAGE_DEVID_SAS1064E:
1547 switch (revision)
1548 {
1549 case 0x00:
1550 product_str = "LSISAS1064E A0";
1551 break;
1552 case 0x01:
1553 product_str = "LSISAS1064E B0";
1554 break;
1555 case 0x02:
1556 product_str = "LSISAS1064E B1";
1557 break;
1558 case 0x04:
1559 product_str = "LSISAS1064E B2";
1560 break;
1561 case 0x08:
1562 product_str = "LSISAS1064E B3";
1563 break;
1564 default:
1565 product_str = "LSISAS1064E";
1566 break;
1567 }
1568 break;
1569 case MPI_MANUFACTPAGE_DEVID_SAS1068:
1570 switch (revision)
1571 {
1572 case 0x00:
1573 product_str = "LSISAS1068 A0";
1574 break;
1575 case 0x01:
1576 product_str = "LSISAS1068 B0";
1577 break;
1578 case 0x02:
1579 product_str = "LSISAS1068 B1";
1580 break;
1581 default:
1582 product_str = "LSISAS1068";
1583 break;
1584 }
1585 break;
1586 case MPI_MANUFACTPAGE_DEVID_SAS1068E:
1587 switch (revision)
1588 {
1589 case 0x00:
1590 product_str = "LSISAS1068E A0";
1591 break;
1592 case 0x01:
1593 product_str = "LSISAS1068E B0";
1594 break;
1595 case 0x02:
1596 product_str = "LSISAS1068E B1";
1597 break;
1598 case 0x04:
1599 product_str = "LSISAS1068E B2";
1600 break;
1601 case 0x08:
1602 product_str = "LSISAS1068E B3";
1603 break;
1604 default:
1605 product_str = "LSISAS1068E";
1606 break;
1607 }
1608 break;
1609 case MPI_MANUFACTPAGE_DEVID_SAS1078:
1610 switch (revision)
1611 {
1612 case 0x00:
1613 product_str = "LSISAS1078 A0";
1614 break;
1615 case 0x01:
1616 product_str = "LSISAS1078 B0";
1617 break;
1618 case 0x02:
1619 product_str = "LSISAS1078 C0";
1620 break;
1621 case 0x03:
1622 product_str = "LSISAS1078 C1";
1623 break;
1624 case 0x04:
1625 product_str = "LSISAS1078 C2";
1626 break;
1627 default:
1628 product_str = "LSISAS1078";
1629 break;
1630 }
1631 break;
1632 }
1633
1634 out:
Joe Lawrencec9834c72014-06-25 17:06:28 -04001635 return product_str;
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05301636}
1637
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301638/**
1639 * mpt_mapresources - map in memory mapped io
1640 * @ioc: Pointer to pointer to IOC adapter
1641 *
1642 **/
1643static int
1644mpt_mapresources(MPT_ADAPTER *ioc)
1645{
1646 u8 __iomem *mem;
1647 int ii;
Pravin Bathijae46b63b2009-12-02 17:51:46 -08001648 resource_size_t mem_phys;
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301649 unsigned long port;
1650 u32 msize;
1651 u32 psize;
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301652 int r = -ENODEV;
1653 struct pci_dev *pdev;
1654
1655 pdev = ioc->pcidev;
1656 ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
1657 if (pci_enable_device_mem(pdev)) {
1658 printk(MYIOC_s_ERR_FMT "pci_enable_device_mem() "
1659 "failed\n", ioc->name);
1660 return r;
1661 }
1662 if (pci_request_selected_regions(pdev, ioc->bars, "mpt")) {
1663 printk(MYIOC_s_ERR_FMT "pci_request_selected_regions() with "
1664 "MEM failed\n", ioc->name);
Hanjun Guo20953a62012-08-11 10:58:36 +08001665 goto out_pci_disable_device;
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301666 }
1667
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301668 if (sizeof(dma_addr_t) > 4) {
1669 const uint64_t required_mask = dma_get_required_mask
1670 (&pdev->dev);
1671 if (required_mask > DMA_BIT_MASK(32)
1672 && !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
1673 && !pci_set_consistent_dma_mask(pdev,
1674 DMA_BIT_MASK(64))) {
1675 ioc->dma_mask = DMA_BIT_MASK(64);
1676 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
1677 ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
1678 ioc->name));
1679 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
1680 && !pci_set_consistent_dma_mask(pdev,
1681 DMA_BIT_MASK(32))) {
1682 ioc->dma_mask = DMA_BIT_MASK(32);
1683 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
1684 ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
1685 ioc->name));
1686 } else {
1687 printk(MYIOC_s_WARN_FMT "no suitable DMA mask for %s\n",
1688 ioc->name, pci_name(pdev));
Hanjun Guo20953a62012-08-11 10:58:36 +08001689 goto out_pci_release_region;
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301690 }
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301691 } else {
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301692 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
1693 && !pci_set_consistent_dma_mask(pdev,
1694 DMA_BIT_MASK(32))) {
1695 ioc->dma_mask = DMA_BIT_MASK(32);
1696 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
1697 ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
1698 ioc->name));
1699 } else {
1700 printk(MYIOC_s_WARN_FMT "no suitable DMA mask for %s\n",
1701 ioc->name, pci_name(pdev));
Hanjun Guo20953a62012-08-11 10:58:36 +08001702 goto out_pci_release_region;
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301703 }
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301704 }
1705
1706 mem_phys = msize = 0;
1707 port = psize = 0;
1708 for (ii = 0; ii < DEVICE_COUNT_RESOURCE; ii++) {
1709 if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
1710 if (psize)
1711 continue;
1712 /* Get I/O space! */
1713 port = pci_resource_start(pdev, ii);
1714 psize = pci_resource_len(pdev, ii);
1715 } else {
1716 if (msize)
1717 continue;
1718 /* Get memmap */
1719 mem_phys = pci_resource_start(pdev, ii);
1720 msize = pci_resource_len(pdev, ii);
1721 }
1722 }
1723 ioc->mem_size = msize;
1724
1725 mem = NULL;
1726 /* Get logical ptr for PciMem0 space */
1727 /*mem = ioremap(mem_phys, msize);*/
1728 mem = ioremap(mem_phys, msize);
1729 if (mem == NULL) {
1730 printk(MYIOC_s_ERR_FMT ": ERROR - Unable to map adapter"
1731 " memory!\n", ioc->name);
Hanjun Guo20953a62012-08-11 10:58:36 +08001732 r = -EINVAL;
1733 goto out_pci_release_region;
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301734 }
1735 ioc->memmap = mem;
Pravin Bathijae46b63b2009-12-02 17:51:46 -08001736 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "mem = %p, mem_phys = %llx\n",
1737 ioc->name, mem, (unsigned long long)mem_phys));
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301738
1739 ioc->mem_phys = mem_phys;
1740 ioc->chip = (SYSIF_REGS __iomem *)mem;
1741
1742 /* Save Port IO values in case we need to do downloadboot */
1743 ioc->pio_mem_phys = port;
1744 ioc->pio_chip = (SYSIF_REGS __iomem *)port;
1745
1746 return 0;
Hanjun Guo20953a62012-08-11 10:58:36 +08001747
1748out_pci_release_region:
1749 pci_release_selected_regions(pdev, ioc->bars);
1750out_pci_disable_device:
1751 pci_disable_device(pdev);
1752 return r;
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301753}
1754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001756/**
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04001757 * mpt_attach - Install a PCI intelligent MPT adapter.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 * @pdev: Pointer to pci_dev structure
Randy Dunlapd9489fb2006-12-06 20:38:43 -08001759 * @id: PCI device ID information
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 *
1761 * This routine performs all the steps necessary to bring the IOC of
1762 * a MPT adapter to a OPERATIONAL state. This includes registering
1763 * memory regions, registering the interrupt, and allocating request
1764 * and reply memory pools.
1765 *
1766 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
1767 * MPT adapter.
1768 *
1769 * Returns 0 for success, non-zero for failure.
1770 *
1771 * TODO: Add support for polled controllers
1772 */
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04001773int
1774mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775{
1776 MPT_ADAPTER *ioc;
Prakash, Sathyaf606f572007-08-14 16:12:53 +05301777 u8 cb_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 int r = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 u8 pcixcmd;
1780 static int mpt_ids = 0;
1781#ifdef CONFIG_PROC_FS
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07001782 struct proc_dir_entry *dent;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783#endif
1784
Jesper Juhl56876192007-08-10 14:50:51 -07001785 ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
1786 if (ioc == NULL) {
1787 printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
1788 return -ENOMEM;
1789 }
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301790
Eric Moore29dd3602007-09-14 18:46:51 -06001791 ioc->id = mpt_ids++;
1792 sprintf(ioc->name, "ioc%d", ioc->id);
Kashyap, Desai2f187862009-05-29 16:52:37 +05301793 dinitprintk(ioc, printk(KERN_WARNING MYNAM ": mpt_adapter_install\n"));
Jesper Juhl56876192007-08-10 14:50:51 -07001794
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301795 /*
1796 * set initial debug level
1797 * (refer to mptdebug.h)
1798 *
1799 */
1800 ioc->debug_level = mpt_debug_level;
1801 if (mpt_debug_level)
1802 printk(KERN_INFO "mpt_debug_level=%xh\n", mpt_debug_level);
Prakash, Sathyae78d5b82008-02-08 22:05:35 +05301803
Eric Moore29dd3602007-09-14 18:46:51 -06001804 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": mpt_adapter_install\n", ioc->name));
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001805
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05301806 ioc->pcidev = pdev;
1807 if (mpt_mapresources(ioc)) {
Jesper Juhl56876192007-08-10 14:50:51 -07001808 kfree(ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 return r;
1810 }
1811
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05301812 /*
1813 * Setting up proper handlers for scatter gather handling
1814 */
1815 if (ioc->dma_mask == DMA_BIT_MASK(64)) {
1816 if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078)
1817 ioc->add_sge = &mpt_add_sge_64bit_1078;
1818 else
1819 ioc->add_sge = &mpt_add_sge_64bit;
1820 ioc->add_chain = &mpt_add_chain_64bit;
1821 ioc->sg_addr_size = 8;
1822 } else {
1823 ioc->add_sge = &mpt_add_sge;
1824 ioc->add_chain = &mpt_add_chain;
1825 ioc->sg_addr_size = 4;
1826 }
1827 ioc->SGE_size = sizeof(u32) + ioc->sg_addr_size;
1828
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 ioc->alloc_total = sizeof(MPT_ADAPTER);
1830 ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
1831 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001832
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301834 spin_lock_init(&ioc->taskmgmt_lock);
Kashyap, Desai37c60f32009-05-29 16:44:06 +05301835 mutex_init(&ioc->internal_cmds.mutex);
1836 init_completion(&ioc->internal_cmds.done);
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05301837 mutex_init(&ioc->mptbase_cmds.mutex);
1838 init_completion(&ioc->mptbase_cmds.done);
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05301839 mutex_init(&ioc->taskmgmt_cmds.mutex);
1840 init_completion(&ioc->taskmgmt_cmds.done);
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05301841
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 /* Initialize the event logging.
1843 */
1844 ioc->eventTypes = 0; /* None */
1845 ioc->eventContext = 0;
1846 ioc->eventLogSize = 0;
1847 ioc->events = NULL;
1848
1849#ifdef MFCNT
1850 ioc->mfcnt = 0;
1851#endif
1852
Kashyap, Desai2f187862009-05-29 16:52:37 +05301853 ioc->sh = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 ioc->cached_fw = NULL;
1855
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02001856 /* Initialize SCSI Config Data structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 */
Moore, Eric Dean466544d2005-09-14 18:09:10 -06001858 memset(&ioc->spi_data, 0, sizeof(SpiCfgData));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
Michael Reed05e8ec12006-01-13 14:31:54 -06001860 /* Initialize the fc rport list head.
1861 */
1862 INIT_LIST_HEAD(&ioc->fc_rports);
1863
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 /* Find lookup slot. */
1865 INIT_LIST_HEAD(&ioc->list);
Christoph Hellwigc6678e02005-08-18 16:24:53 +02001866
Prakash, Sathyad54d48b2008-05-21 01:02:18 +05301867
1868 /* Initialize workqueue */
1869 INIT_DELAYED_WORK(&ioc->fault_reset_work, mpt_fault_reset_work);
Prakash, Sathyad54d48b2008-05-21 01:02:18 +05301870
Kashyap, Desai2f187862009-05-29 16:52:37 +05301871 snprintf(ioc->reset_work_q_name, MPT_KOBJ_NAME_LEN,
Kay Sieversaab0de22008-05-02 06:02:41 +02001872 "mpt_poll_%d", ioc->id);
Prakash, Sathyad54d48b2008-05-21 01:02:18 +05301873 ioc->reset_work_q =
1874 create_singlethread_workqueue(ioc->reset_work_q_name);
1875 if (!ioc->reset_work_q) {
1876 printk(MYIOC_s_ERR_FMT "Insufficient memory to add adapter!\n",
1877 ioc->name);
1878 pci_release_selected_regions(pdev, ioc->bars);
1879 kfree(ioc);
1880 return -ENOMEM;
1881 }
1882
Eric Moore29dd3602007-09-14 18:46:51 -06001883 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "facts @ %p, pfacts[0] @ %p\n",
1884 ioc->name, &ioc->facts, &ioc->pfacts[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Joe Lawrencec9834c72014-06-25 17:06:28 -04001886 ioc->prod_name = mpt_get_product_name(pdev->vendor, pdev->device,
1887 pdev->revision);
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05301888
1889 switch (pdev->device)
1890 {
1891 case MPI_MANUFACTPAGE_DEVICEID_FC939X:
1892 case MPI_MANUFACTPAGE_DEVICEID_FC949X:
1893 ioc->errata_flag_1064 = 1;
1894 case MPI_MANUFACTPAGE_DEVICEID_FC909:
1895 case MPI_MANUFACTPAGE_DEVICEID_FC929:
1896 case MPI_MANUFACTPAGE_DEVICEID_FC919:
1897 case MPI_MANUFACTPAGE_DEVICEID_FC949E:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 ioc->bus_type = FC;
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05301899 break;
1900
1901 case MPI_MANUFACTPAGE_DEVICEID_FC929X:
Sergei Shtylyov9ceb5c12012-05-31 16:26:06 -07001902 if (pdev->revision < XL_929) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 /* 929X Chip Fix. Set Split transactions level
1904 * for PCIX. Set MOST bits to zero.
1905 */
1906 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1907 pcixcmd &= 0x8F;
1908 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1909 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 /* 929XL Chip Fix. Set MMRBC to 0x08.
1911 */
1912 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1913 pcixcmd |= 0x08;
1914 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1915 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 ioc->bus_type = FC;
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05301917 break;
1918
1919 case MPI_MANUFACTPAGE_DEVICEID_FC919X:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 /* 919X Chip Fix. Set Split transactions level
1921 * for PCIX. Set MOST bits to zero.
1922 */
1923 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1924 pcixcmd &= 0x8F;
1925 pci_write_config_byte(pdev, 0x6a, pcixcmd);
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -06001926 ioc->bus_type = FC;
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05301927 break;
1928
1929 case MPI_MANUFACTPAGE_DEVID_53C1030:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 /* 1030 Chip Fix. Disable Split transactions
1931 * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
1932 */
Sergei Shtylyov9ceb5c12012-05-31 16:26:06 -07001933 if (pdev->revision < C0_1030) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1935 pcixcmd &= 0x8F;
1936 pci_write_config_byte(pdev, 0x6a, pcixcmd);
1937 }
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05301938
1939 case MPI_MANUFACTPAGE_DEVID_1030_53C1035:
Moore, Eric Deana9b29372005-11-16 18:54:20 -07001940 ioc->bus_type = SPI;
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05301941 break;
1942
1943 case MPI_MANUFACTPAGE_DEVID_SAS1064:
1944 case MPI_MANUFACTPAGE_DEVID_SAS1068:
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02001945 ioc->errata_flag_1064 = 1;
Kashyap, Desai2f187862009-05-29 16:52:37 +05301946 ioc->bus_type = SAS;
1947 break;
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05301948
1949 case MPI_MANUFACTPAGE_DEVID_SAS1064E:
1950 case MPI_MANUFACTPAGE_DEVID_SAS1068E:
1951 case MPI_MANUFACTPAGE_DEVID_SAS1078:
Eric Moore87cf8982006-06-27 16:09:26 -06001952 ioc->bus_type = SAS;
Kashyap, Desai2f187862009-05-29 16:52:37 +05301953 break;
Eric Moore87cf8982006-06-27 16:09:26 -06001954 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
Prakash, Sathya23a274c2008-03-07 15:53:21 +05301956
Kashyap, Desaie3829682009-01-08 14:27:16 +05301957 switch (ioc->bus_type) {
1958
1959 case SAS:
1960 ioc->msi_enable = mpt_msi_enable_sas;
1961 break;
1962
1963 case SPI:
1964 ioc->msi_enable = mpt_msi_enable_spi;
1965 break;
1966
1967 case FC:
1968 ioc->msi_enable = mpt_msi_enable_fc;
1969 break;
1970
1971 default:
1972 ioc->msi_enable = 0;
1973 break;
1974 }
Kashyap, Desai8ce13de2010-06-17 14:35:46 +05301975
1976 ioc->fw_events_off = 1;
1977
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -06001978 if (ioc->errata_flag_1064)
1979 pci_disable_io_access(pdev);
1980
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 spin_lock_init(&ioc->FreeQlock);
1982
1983 /* Disable all! */
1984 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1985 ioc->active = 0;
1986 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
1987
Prakash, Sathya07df8af2008-02-08 16:35:40 +05301988 /* Set IOC ptr in the pcidev's driver data. */
1989 pci_set_drvdata(ioc->pcidev, ioc);
1990
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 /* Set lookup ptr. */
1992 list_add_tail(&ioc->list, &ioc_list);
1993
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04001994 /* Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 */
1996 mpt_detect_bound_ports(ioc, pdev);
1997
Kashyap, Desai3eb0822c2009-05-29 16:47:26 +05301998 INIT_LIST_HEAD(&ioc->fw_event_list);
1999 spin_lock_init(&ioc->fw_event_lock);
Kashyap, Desai2f187862009-05-29 16:52:37 +05302000 snprintf(ioc->fw_event_q_name, MPT_KOBJ_NAME_LEN, "mpt/%d", ioc->id);
Kashyap, Desai3eb0822c2009-05-29 16:47:26 +05302001 ioc->fw_event_q = create_singlethread_workqueue(ioc->fw_event_q_name);
2002
James Bottomleyc92f2222006-03-01 09:02:49 -06002003 if ((r = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
2004 CAN_SLEEP)) != 0){
Eric Moore29dd3602007-09-14 18:46:51 -06002005 printk(MYIOC_s_ERR_FMT "didn't initialize properly! (%d)\n",
2006 ioc->name, r);
Eric Mooreba856d32006-07-11 17:34:01 -06002007
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 list_del(&ioc->list);
Moore, Eric335a9412006-01-17 17:06:23 -07002009 if (ioc->alt_ioc)
2010 ioc->alt_ioc->alt_ioc = NULL;
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302011 iounmap(ioc->memmap);
2012 if (r != -5)
2013 pci_release_selected_regions(pdev, ioc->bars);
Prakash, Sathyad54d48b2008-05-21 01:02:18 +05302014
2015 destroy_workqueue(ioc->reset_work_q);
2016 ioc->reset_work_q = NULL;
2017
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 kfree(ioc);
2019 pci_set_drvdata(pdev, NULL);
2020 return r;
2021 }
2022
2023 /* call per device driver probe entry point */
Eric Moore8d6d83e2007-09-14 18:47:40 -06002024 for(cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
Prakash, Sathyaf606f572007-08-14 16:12:53 +05302025 if(MptDeviceDriverHandlers[cb_idx] &&
2026 MptDeviceDriverHandlers[cb_idx]->probe) {
2027 MptDeviceDriverHandlers[cb_idx]->probe(pdev,id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 }
2029 }
2030
2031#ifdef CONFIG_PROC_FS
2032 /*
2033 * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
2034 */
2035 dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
2036 if (dent) {
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07002037 proc_create_data("info", S_IRUGO, dent, &mpt_iocinfo_proc_fops, ioc);
2038 proc_create_data("summary", S_IRUGO, dent, &mpt_summary_proc_fops, ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 }
2040#endif
2041
Prakash, Sathyad54d48b2008-05-21 01:02:18 +05302042 if (!ioc->alt_ioc)
2043 queue_delayed_work(ioc->reset_work_q, &ioc->fault_reset_work,
2044 msecs_to_jiffies(MPT_POLLING_INTERVAL));
2045
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 return 0;
2047}
2048
2049/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002050/**
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002051 * mpt_detach - Remove a PCI intelligent MPT adapter.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 * @pdev: Pointer to pci_dev structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 */
2054
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002055void
2056mpt_detach(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057{
2058 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2059 char pname[32];
Prakash, Sathyaf606f572007-08-14 16:12:53 +05302060 u8 cb_idx;
Prakash, Sathyad54d48b2008-05-21 01:02:18 +05302061 unsigned long flags;
2062 struct workqueue_struct *wq;
2063
2064 /*
2065 * Stop polling ioc for fault condition
2066 */
Kashyap, Desai2f187862009-05-29 16:52:37 +05302067 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
Prakash, Sathyad54d48b2008-05-21 01:02:18 +05302068 wq = ioc->reset_work_q;
2069 ioc->reset_work_q = NULL;
Kashyap, Desai2f187862009-05-29 16:52:37 +05302070 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
Prakash, Sathyad54d48b2008-05-21 01:02:18 +05302071 cancel_delayed_work(&ioc->fault_reset_work);
2072 destroy_workqueue(wq);
2073
Kashyap, Desai3eb0822c2009-05-29 16:47:26 +05302074 spin_lock_irqsave(&ioc->fw_event_lock, flags);
2075 wq = ioc->fw_event_q;
2076 ioc->fw_event_q = NULL;
2077 spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
2078 destroy_workqueue(wq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
2080 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
2081 remove_proc_entry(pname, NULL);
2082 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/info", ioc->name);
2083 remove_proc_entry(pname, NULL);
2084 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
2085 remove_proc_entry(pname, NULL);
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002086
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 /* call per device driver remove entry point */
Eric Moore8d6d83e2007-09-14 18:47:40 -06002088 for(cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
Prakash, Sathyaf606f572007-08-14 16:12:53 +05302089 if(MptDeviceDriverHandlers[cb_idx] &&
2090 MptDeviceDriverHandlers[cb_idx]->remove) {
2091 MptDeviceDriverHandlers[cb_idx]->remove(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 }
2093 }
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002094
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 /* Disable interrupts! */
2096 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
2097
2098 ioc->active = 0;
2099 synchronize_irq(pdev->irq);
2100
2101 /* Clear any lingering interrupt */
2102 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
2103
2104 CHIPREG_READ32(&ioc->chip->IntStatus);
2105
2106 mpt_adapter_dispose(ioc);
2107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108}
2109
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110/**************************************************************************
2111 * Power Management
2112 */
2113#ifdef CONFIG_PM
2114/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002115/**
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002116 * mpt_suspend - Fusion MPT base driver suspend routine.
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002117 * @pdev: Pointer to pci_dev structure
2118 * @state: new state to enter
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 */
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002120int
2121mpt_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
2123 u32 device_state;
2124 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302126 device_state = pci_choose_state(pdev, state);
2127 printk(MYIOC_s_INFO_FMT "pci-suspend: pdev=0x%p, slot=%s, Entering "
2128 "operating state [D%d]\n", ioc->name, pdev, pci_name(pdev),
2129 device_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
2131 /* put ioc into READY_STATE */
2132 if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
2133 printk(MYIOC_s_ERR_FMT
2134 "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
2135 }
2136
2137 /* disable interrupts */
2138 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
2139 ioc->active = 0;
2140
2141 /* Clear any lingering interrupt */
2142 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
2143
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302144 free_irq(ioc->pci_irq, ioc);
James Bottomleyb8e3d3a2008-03-30 11:38:07 -05002145 if (ioc->msi_enable)
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302146 pci_disable_msi(ioc->pcidev);
2147 ioc->pci_irq = -1;
2148 pci_save_state(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 pci_disable_device(pdev);
Prakash, Sathyae78d5b82008-02-08 22:05:35 +05302150 pci_release_selected_regions(pdev, ioc->bars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 pci_set_power_state(pdev, device_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 return 0;
2153}
2154
2155/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002156/**
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002157 * mpt_resume - Fusion MPT base driver resume routine.
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002158 * @pdev: Pointer to pci_dev structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 */
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002160int
2161mpt_resume(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162{
2163 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
2164 u32 device_state = pdev->current_state;
2165 int recovery_state;
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302166 int err;
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002167
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302168 printk(MYIOC_s_INFO_FMT "pci-resume: pdev=0x%p, slot=%s, Previous "
2169 "operating state [D%d]\n", ioc->name, pdev, pci_name(pdev),
2170 device_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302172 pci_set_power_state(pdev, PCI_D0);
2173 pci_enable_wake(pdev, PCI_D0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 pci_restore_state(pdev);
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302175 ioc->pcidev = pdev;
2176 err = mpt_mapresources(ioc);
2177 if (err)
2178 return err;
2179
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05302180 if (ioc->dma_mask == DMA_BIT_MASK(64)) {
2181 if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078)
2182 ioc->add_sge = &mpt_add_sge_64bit_1078;
2183 else
2184 ioc->add_sge = &mpt_add_sge_64bit;
2185 ioc->add_chain = &mpt_add_chain_64bit;
2186 ioc->sg_addr_size = 8;
2187 } else {
2188
2189 ioc->add_sge = &mpt_add_sge;
2190 ioc->add_chain = &mpt_add_chain;
2191 ioc->sg_addr_size = 4;
2192 }
2193 ioc->SGE_size = sizeof(u32) + ioc->sg_addr_size;
2194
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302195 printk(MYIOC_s_INFO_FMT "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
2196 ioc->name, (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
2197 CHIPREG_READ32(&ioc->chip->Doorbell));
2198
2199 /*
2200 * Errata workaround for SAS pci express:
2201 * Upon returning to the D0 state, the contents of the doorbell will be
2202 * stale data, and this will incorrectly signal to the host driver that
2203 * the firmware is ready to process mpt commands. The workaround is
2204 * to issue a diagnostic reset.
2205 */
2206 if (ioc->bus_type == SAS && (pdev->device ==
2207 MPI_MANUFACTPAGE_DEVID_SAS1068E || pdev->device ==
2208 MPI_MANUFACTPAGE_DEVID_SAS1064E)) {
2209 if (KickStart(ioc, 1, CAN_SLEEP) < 0) {
2210 printk(MYIOC_s_WARN_FMT "pci-resume: Cannot recover\n",
2211 ioc->name);
2212 goto out;
2213 }
Prakash, Sathyae78d5b82008-02-08 22:05:35 +05302214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
2216 /* bring ioc to operational state */
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302217 printk(MYIOC_s_INFO_FMT "Sending mpt_do_ioc_recovery\n", ioc->name);
2218 recovery_state = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
2219 CAN_SLEEP);
2220 if (recovery_state != 0)
2221 printk(MYIOC_s_WARN_FMT "pci-resume: Cannot recover, "
2222 "error:[%x]\n", ioc->name, recovery_state);
2223 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 printk(MYIOC_s_INFO_FMT
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302225 "pci-resume: success\n", ioc->name);
2226 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 return 0;
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302228
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230#endif
2231
James Bottomley4ff42a62006-05-17 18:06:52 -05002232static int
Prakash, Sathyaf606f572007-08-14 16:12:53 +05302233mpt_signal_reset(u8 index, MPT_ADAPTER *ioc, int reset_phase)
James Bottomley4ff42a62006-05-17 18:06:52 -05002234{
2235 if ((MptDriverClass[index] == MPTSPI_DRIVER &&
2236 ioc->bus_type != SPI) ||
2237 (MptDriverClass[index] == MPTFC_DRIVER &&
2238 ioc->bus_type != FC) ||
2239 (MptDriverClass[index] == MPTSAS_DRIVER &&
2240 ioc->bus_type != SAS))
2241 /* make sure we only call the relevant reset handler
2242 * for the bus */
2243 return 0;
2244 return (MptResetHandlers[index])(ioc, reset_phase);
2245}
2246
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002248/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
2250 * @ioc: Pointer to MPT adapter structure
2251 * @reason: Event word / reason
2252 * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
2253 *
2254 * This routine performs all the steps necessary to bring the IOC
2255 * to a OPERATIONAL state.
2256 *
2257 * This routine also pre-fetches the LAN MAC address of a Fibre Channel
2258 * MPT adapter.
2259 *
2260 * Returns:
2261 * 0 for success
2262 * -1 if failed to get board READY
2263 * -2 if READY but IOCFacts Failed
2264 * -3 if READY but PrimeIOCFifos Failed
2265 * -4 if READY but IOCInit Failed
Prakash, Sathyae78d5b82008-02-08 22:05:35 +05302266 * -5 if failed to enable_device and/or request_selected_regions
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302267 * -6 if failed to upload firmware
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 */
2269static int
2270mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
2271{
2272 int hard_reset_done = 0;
2273 int alt_ioc_ready = 0;
2274 int hard;
2275 int rc=0;
2276 int ii;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 int ret = 0;
2278 int reset_alt_ioc_active = 0;
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002279 int irq_allocated = 0;
Prakash, Sathya436ace72007-07-24 15:42:08 +05302280 u8 *a;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
Eric Moore29dd3602007-09-14 18:46:51 -06002282 printk(MYIOC_s_INFO_FMT "Initiating %s\n", ioc->name,
2283 reason == MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
2285 /* Disable reply interrupts (also blocks FreeQ) */
2286 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
2287 ioc->active = 0;
2288
2289 if (ioc->alt_ioc) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05302290 if (ioc->alt_ioc->active ||
2291 reason == MPT_HOSTEVENT_IOC_RECOVER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 reset_alt_ioc_active = 1;
Kashyap, Desai2f187862009-05-29 16:52:37 +05302293 /* Disable alt-IOC's reply interrupts
2294 * (and FreeQ) for a bit
2295 **/
2296 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask,
2297 0xFFFFFFFF);
2298 ioc->alt_ioc->active = 0;
2299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 }
2301
2302 hard = 1;
2303 if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
2304 hard = 0;
2305
2306 if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
2307 if (hard_reset_done == -4) {
Eric Moore29dd3602007-09-14 18:46:51 -06002308 printk(MYIOC_s_WARN_FMT "Owned by PEER..skipping!\n",
2309 ioc->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
2311 if (reset_alt_ioc_active && ioc->alt_ioc) {
2312 /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
Eric Moore29dd3602007-09-14 18:46:51 -06002313 dprintk(ioc, printk(MYIOC_s_INFO_FMT
2314 "alt_ioc reply irq re-enabled\n", ioc->alt_ioc->name));
Moore, Eric569b11d2006-01-13 16:25:29 -07002315 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 ioc->alt_ioc->active = 1;
2317 }
2318
2319 } else {
Kashyap, Desai2f187862009-05-29 16:52:37 +05302320 printk(MYIOC_s_WARN_FMT
2321 "NOT READY WARNING!\n", ioc->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 }
Kashyap, Desai2f187862009-05-29 16:52:37 +05302323 ret = -1;
2324 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 }
2326
2327 /* hard_reset_done = 0 if a soft reset was performed
2328 * and 1 if a hard reset was performed.
2329 */
2330 if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
2331 if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
2332 alt_ioc_ready = 1;
2333 else
Kashyap, Desai2f187862009-05-29 16:52:37 +05302334 printk(MYIOC_s_WARN_FMT
2335 ": alt-ioc Not ready WARNING!\n",
2336 ioc->alt_ioc->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 }
2338
2339 for (ii=0; ii<5; ii++) {
2340 /* Get IOC facts! Allow 5 retries */
2341 if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
2342 break;
2343 }
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002344
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
2346 if (ii == 5) {
Eric Moore29dd3602007-09-14 18:46:51 -06002347 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2348 "Retry IocFacts failed rc=%x\n", ioc->name, rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 ret = -2;
2350 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2351 MptDisplayIocCapabilities(ioc);
2352 }
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002353
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 if (alt_ioc_ready) {
2355 if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05302356 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Kashyap, Desai2f187862009-05-29 16:52:37 +05302357 "Initial Alt IocFacts failed rc=%x\n",
2358 ioc->name, rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 /* Retry - alt IOC was initialized once
2360 */
2361 rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
2362 }
2363 if (rc) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05302364 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Eric Moore29dd3602007-09-14 18:46:51 -06002365 "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 alt_ioc_ready = 0;
2367 reset_alt_ioc_active = 0;
2368 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2369 MptDisplayIocCapabilities(ioc->alt_ioc);
2370 }
2371 }
2372
Prakash, Sathyae78d5b82008-02-08 22:05:35 +05302373 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP) &&
2374 (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)) {
2375 pci_release_selected_regions(ioc->pcidev, ioc->bars);
2376 ioc->bars = pci_select_bars(ioc->pcidev, IORESOURCE_MEM |
2377 IORESOURCE_IO);
2378 if (pci_enable_device(ioc->pcidev))
2379 return -5;
2380 if (pci_request_selected_regions(ioc->pcidev, ioc->bars,
2381 "mpt"))
2382 return -5;
2383 }
2384
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002385 /*
2386 * Device is reset now. It must have de-asserted the interrupt line
2387 * (if it was asserted) and it should be safe to register for the
2388 * interrupt now.
2389 */
2390 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
2391 ioc->pci_irq = -1;
2392 if (ioc->pcidev->irq) {
Prakash, Sathya23a274c2008-03-07 15:53:21 +05302393 if (ioc->msi_enable && !pci_enable_msi(ioc->pcidev))
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002394 printk(MYIOC_s_INFO_FMT "PCI-MSI enabled\n",
Eric Moore29dd3602007-09-14 18:46:51 -06002395 ioc->name);
Prakash, Sathya23a274c2008-03-07 15:53:21 +05302396 else
2397 ioc->msi_enable = 0;
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002398 rc = request_irq(ioc->pcidev->irq, mpt_interrupt,
Eric Moore29dd3602007-09-14 18:46:51 -06002399 IRQF_SHARED, ioc->name, ioc);
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002400 if (rc < 0) {
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002401 printk(MYIOC_s_ERR_FMT "Unable to allocate "
Kashyap, Desai2f187862009-05-29 16:52:37 +05302402 "interrupt %d!\n",
2403 ioc->name, ioc->pcidev->irq);
Prakash, Sathya23a274c2008-03-07 15:53:21 +05302404 if (ioc->msi_enable)
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002405 pci_disable_msi(ioc->pcidev);
Kashyap, Desai2f187862009-05-29 16:52:37 +05302406 ret = -EBUSY;
2407 goto out;
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002408 }
2409 irq_allocated = 1;
2410 ioc->pci_irq = ioc->pcidev->irq;
2411 pci_set_master(ioc->pcidev); /* ?? */
Kashyap, Desai2f187862009-05-29 16:52:37 +05302412 pci_set_drvdata(ioc->pcidev, ioc);
2413 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
2414 "installed at interrupt %d\n", ioc->name,
2415 ioc->pcidev->irq));
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002416 }
2417 }
2418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 /* Prime reply & request queues!
2420 * (mucho alloc's) Must be done prior to
2421 * init as upper addresses are needed for init.
2422 * If fails, continue with alt-ioc processing
2423 */
Kashyap, Desai2f187862009-05-29 16:52:37 +05302424 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "PrimeIocFifos\n",
2425 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
2427 ret = -3;
2428
2429 /* May need to check/upload firmware & data here!
2430 * If fails, continue with alt-ioc processing
2431 */
Kashyap, Desai2f187862009-05-29 16:52:37 +05302432 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "SendIocInit\n",
2433 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
2435 ret = -4;
2436// NEW!
2437 if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05302438 printk(MYIOC_s_WARN_FMT
2439 ": alt-ioc (%d) FIFO mgmt alloc WARNING!\n",
Eric Moore29dd3602007-09-14 18:46:51 -06002440 ioc->alt_ioc->name, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 alt_ioc_ready = 0;
2442 reset_alt_ioc_active = 0;
2443 }
2444
2445 if (alt_ioc_ready) {
2446 if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
2447 alt_ioc_ready = 0;
2448 reset_alt_ioc_active = 0;
Kashyap, Desai2f187862009-05-29 16:52:37 +05302449 printk(MYIOC_s_WARN_FMT
2450 ": alt-ioc: (%d) init failure WARNING!\n",
2451 ioc->alt_ioc->name, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 }
2453 }
2454
2455 if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
2456 if (ioc->upload_fw) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05302457 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Eric Moore29dd3602007-09-14 18:46:51 -06002458 "firmware upload required!\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
2460 /* Controller is not operational, cannot do upload
2461 */
2462 if (ret == 0) {
2463 rc = mpt_do_upload(ioc, sleepFlag);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06002464 if (rc == 0) {
2465 if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
2466 /*
2467 * Maintain only one pointer to FW memory
2468 * so there will not be two attempt to
2469 * downloadboot onboard dual function
2470 * chips (mpt_adapter_disable,
2471 * mpt_diag_reset)
2472 */
Prakash, Sathya436ace72007-07-24 15:42:08 +05302473 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Eric Moore29dd3602007-09-14 18:46:51 -06002474 "mpt_upload: alt_%s has cached_fw=%p \n",
2475 ioc->name, ioc->alt_ioc->name, ioc->alt_ioc->cached_fw));
Prakash, Sathya984621b2008-01-11 14:42:17 +05302476 ioc->cached_fw = NULL;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06002477 }
2478 } else {
Eric Moore29dd3602007-09-14 18:46:51 -06002479 printk(MYIOC_s_WARN_FMT
2480 "firmware upload failure!\n", ioc->name);
Prakash, Sathya4d4109d2008-03-07 16:19:50 +05302481 ret = -6;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06002482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 }
2484 }
2485 }
2486
Kashyap, Desaifd761752009-05-29 16:39:06 +05302487 /* Enable MPT base driver management of EventNotification
2488 * and EventAck handling.
2489 */
2490 if ((ret == 0) && (!ioc->facts.EventState)) {
2491 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
2492 "SendEventNotification\n",
2493 ioc->name));
2494 ret = SendEventNotification(ioc, 1, sleepFlag); /* 1=Enable */
2495 }
2496
2497 if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
2498 rc = SendEventNotification(ioc->alt_ioc, 1, sleepFlag);
2499
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 if (ret == 0) {
2501 /* Enable! (reply interrupt) */
Moore, Eric569b11d2006-01-13 16:25:29 -07002502 CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 ioc->active = 1;
2504 }
Kashyap, Desaifd761752009-05-29 16:39:06 +05302505 if (rc == 0) { /* alt ioc */
2506 if (reset_alt_ioc_active && ioc->alt_ioc) {
2507 /* (re)Enable alt-IOC! (reply interrupt) */
2508 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "alt-ioc"
2509 "reply irq re-enabled\n",
2510 ioc->alt_ioc->name));
2511 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask,
2512 MPI_HIM_DIM);
2513 ioc->alt_ioc->active = 1;
2514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 }
2516
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002518 /* Add additional "reason" check before call to GetLanConfigPages
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 * (combined with GetIoUnitPage2 call). This prevents a somewhat
2520 * recursive scenario; GetLanConfigPages times out, timer expired
2521 * routine calls HardResetHandler, which calls into here again,
2522 * and we try GetLanConfigPages again...
2523 */
2524 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
Eric Mooreb506ade2007-01-29 09:45:37 -07002525
2526 /*
Uwe Kleine-König421f91d2010-06-11 12:17:00 +02002527 * Initialize link list for inactive raid volumes.
Eric Mooreb506ade2007-01-29 09:45:37 -07002528 */
Matthias Kaehlckeed5f6062008-03-09 12:16:27 +01002529 mutex_init(&ioc->raid_data.inactive_list_mutex);
Eric Mooreb506ade2007-01-29 09:45:37 -07002530 INIT_LIST_HEAD(&ioc->raid_data.inactive_list);
2531
Kashyap, Desai2f187862009-05-29 16:52:37 +05302532 switch (ioc->bus_type) {
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02002533
Kashyap, Desai2f187862009-05-29 16:52:37 +05302534 case SAS:
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02002535 /* clear persistency table */
2536 if(ioc->facts.IOCExceptions &
2537 MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL) {
2538 ret = mptbase_sas_persist_operation(ioc,
2539 MPI_SAS_OP_CLEAR_NOT_PRESENT);
2540 if(ret != 0)
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002541 goto out;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02002542 }
2543
2544 /* Find IM volumes
2545 */
2546 mpt_findImVolumes(ioc);
2547
Kashyap, Desai2f187862009-05-29 16:52:37 +05302548 /* Check, and possibly reset, the coalescing value
2549 */
2550 mpt_read_ioc_pg_1(ioc);
2551
2552 break;
2553
2554 case FC:
2555 if ((ioc->pfacts[0].ProtocolFlags &
2556 MPI_PORTFACTS_PROTOCOL_LAN) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
2558 /*
2559 * Pre-fetch the ports LAN MAC address!
2560 * (LANPage1_t stuff)
2561 */
2562 (void) GetLanConfigPages(ioc);
Prakash, Sathya436ace72007-07-24 15:42:08 +05302563 a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
2564 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Kashyap, Desai2f187862009-05-29 16:52:37 +05302565 "LanAddr = %02X:%02X:%02X"
2566 ":%02X:%02X:%02X\n",
2567 ioc->name, a[5], a[4],
2568 a[3], a[2], a[1], a[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 }
Kashyap, Desai2f187862009-05-29 16:52:37 +05302570 break;
2571
2572 case SPI:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 /* Get NVRAM and adapter maximums from SPP 0 and 2
2574 */
2575 mpt_GetScsiPortSettings(ioc, 0);
2576
2577 /* Get version and length of SDP 1
2578 */
2579 mpt_readScsiDevicePageHeaders(ioc, 0);
2580
2581 /* Find IM volumes
2582 */
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002583 if (ioc->facts.MsgVersion >= MPI_VERSION_01_02)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 mpt_findImVolumes(ioc);
2585
2586 /* Check, and possibly reset, the coalescing value
2587 */
2588 mpt_read_ioc_pg_1(ioc);
2589
2590 mpt_read_ioc_pg_4(ioc);
Kashyap, Desai2f187862009-05-29 16:52:37 +05302591
2592 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 }
2594
2595 GetIoUnitPage2(ioc);
Prakash, Sathyaedb90682007-07-17 14:39:14 +05302596 mpt_get_manufacturing_pg_0(ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 }
2598
Eric Moore0ccdb002006-07-11 17:33:13 -06002599 out:
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002600 if ((ret != 0) && irq_allocated) {
2601 free_irq(ioc->pci_irq, ioc);
Prakash, Sathya23a274c2008-03-07 15:53:21 +05302602 if (ioc->msi_enable)
Vivek Goyal9bf0a282006-04-27 02:33:13 -07002603 pci_disable_msi(ioc->pcidev);
2604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 return ret;
2606}
2607
2608/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002609/**
2610 * mpt_detect_bound_ports - Search for matching PCI bus/dev_function
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 * @ioc: Pointer to MPT adapter structure
2612 * @pdev: Pointer to (struct pci_dev) structure
2613 *
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002614 * Search for PCI bus/dev_function which matches
2615 * PCI bus/dev_function (+/-1) for newly discovered 929,
2616 * 929X, 1030 or 1035.
2617 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
2619 * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
2620 */
2621static void
2622mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
2623{
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002624 struct pci_dev *peer=NULL;
2625 unsigned int slot = PCI_SLOT(pdev->devfn);
2626 unsigned int func = PCI_FUNC(pdev->devfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 MPT_ADAPTER *ioc_srch;
2628
Prakash, Sathya436ace72007-07-24 15:42:08 +05302629 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PCI device %s devfn=%x/%x,"
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002630 " searching for devfn match on %x or %x\n",
Eric Moore29dd3602007-09-14 18:46:51 -06002631 ioc->name, pci_name(pdev), pdev->bus->number,
2632 pdev->devfn, func-1, func+1));
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002633
2634 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
2635 if (!peer) {
2636 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func+1));
2637 if (!peer)
2638 return;
2639 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640
2641 list_for_each_entry(ioc_srch, &ioc_list, list) {
2642 struct pci_dev *_pcidev = ioc_srch->pcidev;
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002643 if (_pcidev == peer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 /* Paranoia checks */
2645 if (ioc->alt_ioc != NULL) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05302646 printk(MYIOC_s_WARN_FMT
2647 "Oops, already bound (%s <==> %s)!\n",
2648 ioc->name, ioc->name, ioc->alt_ioc->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 break;
2650 } else if (ioc_srch->alt_ioc != NULL) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05302651 printk(MYIOC_s_WARN_FMT
2652 "Oops, already bound (%s <==> %s)!\n",
2653 ioc_srch->name, ioc_srch->name,
2654 ioc_srch->alt_ioc->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 break;
2656 }
Kashyap, Desai2f187862009-05-29 16:52:37 +05302657 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2658 "FOUND! binding %s <==> %s\n",
2659 ioc->name, ioc->name, ioc_srch->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 ioc_srch->alt_ioc = ioc;
2661 ioc->alt_ioc = ioc_srch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 }
2663 }
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04002664 pci_dev_put(peer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665}
2666
2667/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002668/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 * mpt_adapter_disable - Disable misbehaving MPT adapter.
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002670 * @ioc: Pointer to MPT adapter structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 */
2672static void
2673mpt_adapter_disable(MPT_ADAPTER *ioc)
2674{
2675 int sz;
2676 int ret;
2677
2678 if (ioc->cached_fw != NULL) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05302679 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2680 "%s: Pushing FW onto adapter\n", __func__, ioc->name));
Prakash, Sathya984621b2008-01-11 14:42:17 +05302681 if ((ret = mpt_downloadboot(ioc, (MpiFwHeader_t *)
2682 ioc->cached_fw, CAN_SLEEP)) < 0) {
2683 printk(MYIOC_s_WARN_FMT
2684 ": firmware downloadboot failure (%d)!\n",
Eric Moore29dd3602007-09-14 18:46:51 -06002685 ioc->name, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 }
2687 }
2688
Kashyap, Desai71278192009-05-29 16:53:14 +05302689 /*
2690 * Put the controller into ready state (if its not already)
2691 */
2692 if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY) {
2693 if (!SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET,
2694 CAN_SLEEP)) {
2695 if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY)
2696 printk(MYIOC_s_ERR_FMT "%s: IOC msg unit "
2697 "reset failed to put ioc in ready state!\n",
2698 ioc->name, __func__);
2699 } else
2700 printk(MYIOC_s_ERR_FMT "%s: IOC msg unit reset "
2701 "failed!\n", ioc->name, __func__);
2702 }
2703
2704
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 /* Disable adapter interrupts! */
Kashyap, Desai2f187862009-05-29 16:52:37 +05302706 synchronize_irq(ioc->pcidev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
2708 ioc->active = 0;
Kashyap, Desai2f187862009-05-29 16:52:37 +05302709
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 /* Clear any lingering interrupt */
2711 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
Kashyap, Desai2f187862009-05-29 16:52:37 +05302712 CHIPREG_READ32(&ioc->chip->IntStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713
2714 if (ioc->alloc != NULL) {
2715 sz = ioc->alloc_sz;
Eric Moore29dd3602007-09-14 18:46:51 -06002716 dexitprintk(ioc, printk(MYIOC_s_INFO_FMT "free @ %p, sz=%d bytes\n",
2717 ioc->name, ioc->alloc, ioc->alloc_sz));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 pci_free_consistent(ioc->pcidev, sz,
2719 ioc->alloc, ioc->alloc_dma);
2720 ioc->reply_frames = NULL;
2721 ioc->req_frames = NULL;
2722 ioc->alloc = NULL;
2723 ioc->alloc_total -= sz;
2724 }
2725
2726 if (ioc->sense_buf_pool != NULL) {
2727 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
2728 pci_free_consistent(ioc->pcidev, sz,
2729 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
2730 ioc->sense_buf_pool = NULL;
2731 ioc->alloc_total -= sz;
2732 }
2733
2734 if (ioc->events != NULL){
2735 sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
2736 kfree(ioc->events);
2737 ioc->events = NULL;
2738 ioc->alloc_total -= sz;
2739 }
2740
Prakash, Sathya984621b2008-01-11 14:42:17 +05302741 mpt_free_fw_memory(ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742
Moore, Eric Dean d485eb82005-05-11 17:37:26 -06002743 kfree(ioc->spi_data.nvram);
Eric Mooreb506ade2007-01-29 09:45:37 -07002744 mpt_inactive_raid_list_free(ioc);
2745 kfree(ioc->raid_data.pIocPg2);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06002746 kfree(ioc->raid_data.pIocPg3);
Moore, Eric Dean d485eb82005-05-11 17:37:26 -06002747 ioc->spi_data.nvram = NULL;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06002748 ioc->raid_data.pIocPg3 = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749
2750 if (ioc->spi_data.pIocPg4 != NULL) {
2751 sz = ioc->spi_data.IocPg4Sz;
Prakash, Sathya436ace72007-07-24 15:42:08 +05302752 pci_free_consistent(ioc->pcidev, sz,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 ioc->spi_data.pIocPg4,
2754 ioc->spi_data.IocPg4_dma);
2755 ioc->spi_data.pIocPg4 = NULL;
2756 ioc->alloc_total -= sz;
2757 }
2758
2759 if (ioc->ReqToChain != NULL) {
2760 kfree(ioc->ReqToChain);
2761 kfree(ioc->RequestNB);
2762 ioc->ReqToChain = NULL;
2763 }
2764
Moore, Eric Dean d485eb82005-05-11 17:37:26 -06002765 kfree(ioc->ChainToChain);
2766 ioc->ChainToChain = NULL;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02002767
2768 if (ioc->HostPageBuffer != NULL) {
2769 if((ret = mpt_host_page_access_control(ioc,
2770 MPI_DB_HPBAC_FREE_BUFFER, NO_SLEEP)) != 0) {
Eric Moore29dd3602007-09-14 18:46:51 -06002771 printk(MYIOC_s_ERR_FMT
Kashyap, Desai2f187862009-05-29 16:52:37 +05302772 ": %s: host page buffers free failed (%d)!\n",
2773 ioc->name, __func__, ret);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02002774 }
Kashyap, Desai2f187862009-05-29 16:52:37 +05302775 dexitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2776 "HostPageBuffer free @ %p, sz=%d bytes\n",
2777 ioc->name, ioc->HostPageBuffer,
2778 ioc->HostPageBuffer_sz));
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02002779 pci_free_consistent(ioc->pcidev, ioc->HostPageBuffer_sz,
Eric Moore29dd3602007-09-14 18:46:51 -06002780 ioc->HostPageBuffer, ioc->HostPageBuffer_dma);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02002781 ioc->HostPageBuffer = NULL;
2782 ioc->HostPageBuffer_sz = 0;
2783 ioc->alloc_total -= ioc->HostPageBuffer_sz;
2784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785
Kashyap, Desai2f187862009-05-29 16:52:37 +05302786 pci_set_drvdata(ioc->pcidev, NULL);
2787}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002789/**
2790 * mpt_adapter_dispose - Free all resources associated with an MPT adapter
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 * @ioc: Pointer to MPT adapter structure
2792 *
2793 * This routine unregisters h/w resources and frees all alloc'd memory
2794 * associated with a MPT adapter structure.
2795 */
2796static void
2797mpt_adapter_dispose(MPT_ADAPTER *ioc)
2798{
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002799 int sz_first, sz_last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002801 if (ioc == NULL)
2802 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002804 sz_first = ioc->alloc_total;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002806 mpt_adapter_disable(ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002808 if (ioc->pci_irq != -1) {
2809 free_irq(ioc->pci_irq, ioc);
Prakash, Sathya23a274c2008-03-07 15:53:21 +05302810 if (ioc->msi_enable)
Christoph Hellwig4ddce142006-01-17 13:44:29 +00002811 pci_disable_msi(ioc->pcidev);
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002812 ioc->pci_irq = -1;
2813 }
2814
2815 if (ioc->memmap != NULL) {
2816 iounmap(ioc->memmap);
2817 ioc->memmap = NULL;
2818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
Prakash, Sathyae78d5b82008-02-08 22:05:35 +05302820 pci_disable_device(ioc->pcidev);
2821 pci_release_selected_regions(ioc->pcidev, ioc->bars);
2822
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823#if defined(CONFIG_MTRR) && 0
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002824 if (ioc->mtrr_reg > 0) {
2825 mtrr_del(ioc->mtrr_reg, 0, 0);
Eric Moore29dd3602007-09-14 18:46:51 -06002826 dprintk(ioc, printk(MYIOC_s_INFO_FMT "MTRR region de-registered\n", ioc->name));
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828#endif
2829
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002830 /* Zap the adapter lookup ptr! */
2831 list_del(&ioc->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002833 sz_last = ioc->alloc_total;
Eric Moore29dd3602007-09-14 18:46:51 -06002834 dprintk(ioc, printk(MYIOC_s_INFO_FMT "free'd %d of %d bytes\n",
2835 ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
Moore, Eric335a9412006-01-17 17:06:23 -07002836
2837 if (ioc->alt_ioc)
2838 ioc->alt_ioc->alt_ioc = NULL;
2839
Christoph Hellwigc6678e02005-08-18 16:24:53 +02002840 kfree(ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841}
2842
2843/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002844/**
2845 * MptDisplayIocCapabilities - Disply IOC's capabilities.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 * @ioc: Pointer to MPT adapter structure
2847 */
2848static void
2849MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
2850{
2851 int i = 0;
2852
2853 printk(KERN_INFO "%s: ", ioc->name);
Prakash, Sathyaef1d8df2007-07-17 14:18:41 +05302854 if (ioc->prod_name)
2855 printk("%s: ", ioc->prod_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 printk("Capabilities={");
2857
2858 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
2859 printk("Initiator");
2860 i++;
2861 }
2862
2863 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2864 printk("%sTarget", i ? "," : "");
2865 i++;
2866 }
2867
2868 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
2869 printk("%sLAN", i ? "," : "");
2870 i++;
2871 }
2872
2873#if 0
2874 /*
2875 * This would probably evoke more questions than it's worth
2876 */
2877 if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2878 printk("%sLogBusAddr", i ? "," : "");
2879 i++;
2880 }
2881#endif
2882
2883 printk("}\n");
2884}
2885
2886/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08002887/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
2889 * @ioc: Pointer to MPT_ADAPTER structure
2890 * @force: Force hard KickStart of IOC
2891 * @sleepFlag: Specifies whether the process can sleep
2892 *
2893 * Returns:
2894 * 1 - DIAG reset and READY
2895 * 0 - READY initially OR soft reset and READY
2896 * -1 - Any failure on KickStart
2897 * -2 - Msg Unit Reset Failed
2898 * -3 - IO Unit Reset Failed
2899 * -4 - IOC owned by a PEER
2900 */
2901static int
2902MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
2903{
2904 u32 ioc_state;
2905 int statefault = 0;
2906 int cntdn;
2907 int hard_reset_done = 0;
2908 int r;
2909 int ii;
2910 int whoinit;
2911
2912 /* Get current [raw] IOC state */
2913 ioc_state = mpt_GetIocState(ioc, 0);
Eric Moore29dd3602007-09-14 18:46:51 -06002914 dhsprintk(ioc, printk(MYIOC_s_INFO_FMT "MakeIocReady [raw] state=%08x\n", ioc->name, ioc_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
2916 /*
2917 * Check to see if IOC got left/stuck in doorbell handshake
2918 * grip of death. If so, hard reset the IOC.
2919 */
2920 if (ioc_state & MPI_DOORBELL_ACTIVE) {
2921 statefault = 1;
2922 printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
2923 ioc->name);
2924 }
2925
2926 /* Is it already READY? */
Kashyap, Desai2f187862009-05-29 16:52:37 +05302927 if (!statefault &&
2928 ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)) {
2929 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
2930 "IOC is in READY state\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 return 0;
Kashyap, Desai2f187862009-05-29 16:52:37 +05302932 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933
2934 /*
2935 * Check to see if IOC is in FAULT state.
2936 */
2937 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
2938 statefault = 2;
2939 printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
Eric Moore29dd3602007-09-14 18:46:51 -06002940 ioc->name);
2941 printk(MYIOC_s_WARN_FMT " FAULT code = %04xh\n",
2942 ioc->name, ioc_state & MPI_DOORBELL_DATA_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 }
2944
2945 /*
2946 * Hmmm... Did it get left operational?
2947 */
2948 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05302949 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOC operational unexpected\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 ioc->name));
2951
2952 /* Check WhoInit.
2953 * If PCI Peer, exit.
2954 * Else, if no fault conditions are present, issue a MessageUnitReset
2955 * Else, fall through to KickStart case
2956 */
2957 whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
Eric Moore29dd3602007-09-14 18:46:51 -06002958 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
2959 "whoinit 0x%x statefault %d force %d\n",
2960 ioc->name, whoinit, statefault, force));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 if (whoinit == MPI_WHOINIT_PCI_PEER)
2962 return -4;
2963 else {
2964 if ((statefault == 0 ) && (force == 0)) {
2965 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
2966 return 0;
2967 }
2968 statefault = 3;
2969 }
2970 }
2971
2972 hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
2973 if (hard_reset_done < 0)
2974 return -1;
2975
2976 /*
2977 * Loop here waiting for IOC to come READY.
2978 */
2979 ii = 0;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02002980 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 5; /* 5 seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981
2982 while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
2983 if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
2984 /*
2985 * BIOS or previous driver load left IOC in OP state.
2986 * Reset messaging FIFOs.
2987 */
2988 if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
2989 printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
2990 return -2;
2991 }
2992 } else if (ioc_state == MPI_IOC_STATE_RESET) {
2993 /*
2994 * Something is wrong. Try to get IOC back
2995 * to a known state.
2996 */
2997 if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
2998 printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
2999 return -3;
3000 }
3001 }
3002
3003 ii++; cntdn--;
3004 if (!cntdn) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05303005 printk(MYIOC_s_ERR_FMT
3006 "Wait IOC_READY state (0x%x) timeout(%d)!\n",
3007 ioc->name, ioc_state, (int)((ii+5)/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 return -ETIME;
3009 }
3010
3011 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05003012 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 } else {
3014 mdelay (1); /* 1 msec delay */
3015 }
3016
3017 }
3018
3019 if (statefault < 3) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05303020 printk(MYIOC_s_INFO_FMT "Recovered from %s\n", ioc->name,
3021 statefault == 1 ? "stuck handshake" : "IOC FAULT");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 }
3023
3024 return hard_reset_done;
3025}
3026
3027/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003028/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 * mpt_GetIocState - Get the current state of a MPT adapter.
3030 * @ioc: Pointer to MPT_ADAPTER structure
3031 * @cooked: Request raw or cooked IOC state
3032 *
3033 * Returns all IOC Doorbell register bits if cooked==0, else just the
3034 * Doorbell bits in MPI_IOC_STATE_MASK.
3035 */
3036u32
3037mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
3038{
3039 u32 s, sc;
3040
3041 /* Get! */
3042 s = CHIPREG_READ32(&ioc->chip->Doorbell);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 sc = s & MPI_IOC_STATE_MASK;
3044
3045 /* Save! */
3046 ioc->last_state = sc;
3047
3048 return cooked ? sc : s;
3049}
3050
3051/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003052/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 * GetIocFacts - Send IOCFacts request to MPT adapter.
3054 * @ioc: Pointer to MPT_ADAPTER structure
3055 * @sleepFlag: Specifies whether the process can sleep
3056 * @reason: If recovery, only update facts.
3057 *
3058 * Returns 0 for success, non-zero for failure.
3059 */
3060static int
3061GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
3062{
3063 IOCFacts_t get_facts;
3064 IOCFactsReply_t *facts;
3065 int r;
3066 int req_sz;
3067 int reply_sz;
3068 int sz;
3069 u32 status, vv;
3070 u8 shiftFactor=1;
3071
3072 /* IOC *must* NOT be in RESET state! */
3073 if (ioc->last_state == MPI_IOC_STATE_RESET) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05303074 printk(KERN_ERR MYNAM
3075 ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
3076 ioc->name, ioc->last_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 return -44;
3078 }
3079
3080 facts = &ioc->facts;
3081
3082 /* Destination (reply area)... */
3083 reply_sz = sizeof(*facts);
3084 memset(facts, 0, reply_sz);
3085
3086 /* Request area (get_facts on the stack right now!) */
3087 req_sz = sizeof(get_facts);
3088 memset(&get_facts, 0, req_sz);
3089
3090 get_facts.Function = MPI_FUNCTION_IOC_FACTS;
3091 /* Assert: All other get_facts fields are zero! */
3092
Prakash, Sathya436ace72007-07-24 15:42:08 +05303093 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Christoph Hellwigc6678e02005-08-18 16:24:53 +02003094 "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 ioc->name, req_sz, reply_sz));
3096
3097 /* No non-zero fields in the get_facts request are greater than
3098 * 1 byte in size, so we can just fire it off as is.
3099 */
3100 r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
3101 reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
3102 if (r != 0)
3103 return r;
3104
3105 /*
3106 * Now byte swap (GRRR) the necessary fields before any further
3107 * inspection of reply contents.
3108 *
3109 * But need to do some sanity checks on MsgLength (byte) field
3110 * to make sure we don't zero IOC's req_sz!
3111 */
3112 /* Did we get a valid reply? */
3113 if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
3114 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
3115 /*
3116 * If not been here, done that, save off first WhoInit value
3117 */
3118 if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
3119 ioc->FirstWhoInit = facts->WhoInit;
3120 }
3121
3122 facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
3123 facts->MsgContext = le32_to_cpu(facts->MsgContext);
3124 facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
3125 facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
3126 facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
Christoph Hellwig637fa992005-08-18 16:25:44 +02003127 status = le16_to_cpu(facts->IOCStatus) & MPI_IOCSTATUS_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 /* CHECKME! IOCStatus, IOCLogInfo */
3129
3130 facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
3131 facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
3132
3133 /*
3134 * FC f/w version changed between 1.1 and 1.2
3135 * Old: u16{Major(4),Minor(4),SubMinor(8)}
3136 * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
3137 */
Kashyap, Desai2f187862009-05-29 16:52:37 +05303138 if (facts->MsgVersion < MPI_VERSION_01_02) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 /*
3140 * Handle old FC f/w style, convert to new...
3141 */
3142 u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
3143 facts->FWVersion.Word =
3144 ((oldv<<12) & 0xFF000000) |
3145 ((oldv<<8) & 0x000FFF00);
3146 } else
3147 facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
3148
3149 facts->ProductID = le16_to_cpu(facts->ProductID);
Kashyap, Desai2f187862009-05-29 16:52:37 +05303150
Eric Mooreb506ade2007-01-29 09:45:37 -07003151 if ((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
3152 > MPI_FW_HEADER_PID_PROD_TARGET_SCSI)
3153 ioc->ir_firmware = 1;
Kashyap, Desai2f187862009-05-29 16:52:37 +05303154
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 facts->CurrentHostMfaHighAddr =
3156 le32_to_cpu(facts->CurrentHostMfaHighAddr);
3157 facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
3158 facts->CurrentSenseBufferHighAddr =
3159 le32_to_cpu(facts->CurrentSenseBufferHighAddr);
3160 facts->CurReplyFrameSize =
3161 le16_to_cpu(facts->CurReplyFrameSize);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003162 facts->IOCCapabilities = le32_to_cpu(facts->IOCCapabilities);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163
3164 /*
3165 * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
3166 * Older MPI-1.00.xx struct had 13 dwords, and enlarged
3167 * to 14 in MPI-1.01.0x.
3168 */
3169 if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
Kashyap, Desai2f187862009-05-29 16:52:37 +05303170 facts->MsgVersion > MPI_VERSION_01_00) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
3172 }
3173
Rasmus Villemoesf6e495a2014-07-01 14:56:20 +02003174 facts->FWImageSize = ALIGN(facts->FWImageSize, 4);
Christoph Hellwigc6678e02005-08-18 16:24:53 +02003175
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 if (!facts->RequestFrameSize) {
3177 /* Something is wrong! */
3178 printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
3179 ioc->name);
3180 return -55;
3181 }
3182
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04003183 r = sz = facts->BlockSize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 vv = ((63 / (sz * 4)) + 1) & 0x03;
3185 ioc->NB_for_64_byte_frame = vv;
3186 while ( sz )
3187 {
3188 shiftFactor++;
3189 sz = sz >> 1;
3190 }
3191 ioc->NBShiftFactor = shiftFactor;
Prakash, Sathya436ace72007-07-24 15:42:08 +05303192 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Eric Moore29dd3602007-09-14 18:46:51 -06003193 "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
3194 ioc->name, vv, shiftFactor, r));
Christoph Hellwigc6678e02005-08-18 16:24:53 +02003195
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
3197 /*
3198 * Set values for this IOC's request & reply frame sizes,
3199 * and request & reply queue depths...
3200 */
3201 ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
3202 ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
3203 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
3204 ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
3205
Prakash, Sathya436ace72007-07-24 15:42:08 +05303206 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "reply_sz=%3d, reply_depth=%4d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 ioc->name, ioc->reply_sz, ioc->reply_depth));
Prakash, Sathya436ace72007-07-24 15:42:08 +05303208 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "req_sz =%3d, req_depth =%4d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 ioc->name, ioc->req_sz, ioc->req_depth));
3210
3211 /* Get port facts! */
3212 if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
3213 return r;
3214 }
3215 } else {
Christoph Hellwigc6678e02005-08-18 16:24:53 +02003216 printk(MYIOC_s_ERR_FMT
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
3218 ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
3219 RequestFrameSize)/sizeof(u32)));
3220 return -66;
3221 }
3222
3223 return 0;
3224}
3225
3226/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003227/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 * GetPortFacts - Send PortFacts request to MPT adapter.
3229 * @ioc: Pointer to MPT_ADAPTER structure
3230 * @portnum: Port number
3231 * @sleepFlag: Specifies whether the process can sleep
3232 *
3233 * Returns 0 for success, non-zero for failure.
3234 */
3235static int
3236GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
3237{
3238 PortFacts_t get_pfacts;
3239 PortFactsReply_t *pfacts;
3240 int ii;
3241 int req_sz;
3242 int reply_sz;
Eric Moore793955f2007-01-29 09:42:20 -07003243 int max_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244
3245 /* IOC *must* NOT be in RESET state! */
3246 if (ioc->last_state == MPI_IOC_STATE_RESET) {
Eric Moore29dd3602007-09-14 18:46:51 -06003247 printk(MYIOC_s_ERR_FMT "Can't get PortFacts NOT READY! (%08x)\n",
3248 ioc->name, ioc->last_state );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 return -4;
3250 }
3251
3252 pfacts = &ioc->pfacts[portnum];
3253
3254 /* Destination (reply area)... */
3255 reply_sz = sizeof(*pfacts);
3256 memset(pfacts, 0, reply_sz);
3257
3258 /* Request area (get_pfacts on the stack right now!) */
3259 req_sz = sizeof(get_pfacts);
3260 memset(&get_pfacts, 0, req_sz);
3261
3262 get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
3263 get_pfacts.PortNumber = portnum;
3264 /* Assert: All other get_pfacts fields are zero! */
3265
Prakash, Sathya436ace72007-07-24 15:42:08 +05303266 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending get PortFacts(%d) request\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 ioc->name, portnum));
3268
3269 /* No non-zero fields in the get_pfacts request are greater than
3270 * 1 byte in size, so we can just fire it off as is.
3271 */
3272 ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
3273 reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
3274 if (ii != 0)
3275 return ii;
3276
3277 /* Did we get a valid reply? */
3278
3279 /* Now byte swap the necessary fields in the response. */
3280 pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
3281 pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
3282 pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
3283 pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
3284 pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
3285 pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
3286 pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
3287 pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
3288 pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
3289
Eric Moore793955f2007-01-29 09:42:20 -07003290 max_id = (ioc->bus_type == SAS) ? pfacts->PortSCSIID :
3291 pfacts->MaxDevices;
3292 ioc->devices_per_bus = (max_id > 255) ? 256 : max_id;
3293 ioc->number_of_buses = (ioc->devices_per_bus < 256) ? 1 : max_id/256;
3294
3295 /*
3296 * Place all the devices on channels
3297 *
3298 * (for debuging)
3299 */
3300 if (mpt_channel_mapping) {
3301 ioc->devices_per_bus = 1;
3302 ioc->number_of_buses = (max_id > 255) ? 255 : max_id;
3303 }
3304
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 return 0;
3306}
3307
3308/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003309/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 * SendIocInit - Send IOCInit request to MPT adapter.
3311 * @ioc: Pointer to MPT_ADAPTER structure
3312 * @sleepFlag: Specifies whether the process can sleep
3313 *
3314 * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
3315 *
3316 * Returns 0 for success, non-zero for failure.
3317 */
3318static int
3319SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
3320{
3321 IOCInit_t ioc_init;
3322 MPIDefaultReply_t init_reply;
3323 u32 state;
3324 int r;
3325 int count;
3326 int cntdn;
3327
3328 memset(&ioc_init, 0, sizeof(ioc_init));
3329 memset(&init_reply, 0, sizeof(init_reply));
3330
3331 ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
3332 ioc_init.Function = MPI_FUNCTION_IOC_INIT;
3333
3334 /* If we are in a recovery mode and we uploaded the FW image,
3335 * then this pointer is not NULL. Skip the upload a second time.
3336 * Set this flag if cached_fw set for either IOC.
3337 */
3338 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
3339 ioc->upload_fw = 1;
3340 else
3341 ioc->upload_fw = 0;
Prakash, Sathya436ace72007-07-24 15:42:08 +05303342 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "upload_fw %d facts.Flags=%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 ioc->name, ioc->upload_fw, ioc->facts.Flags));
3344
Eric Moore793955f2007-01-29 09:42:20 -07003345 ioc_init.MaxDevices = (U8)ioc->devices_per_bus;
3346 ioc_init.MaxBuses = (U8)ioc->number_of_buses;
Kashyap, Desai2f187862009-05-29 16:52:37 +05303347
Prakash, Sathya436ace72007-07-24 15:42:08 +05303348 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "facts.MsgVersion=%x\n",
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003349 ioc->name, ioc->facts.MsgVersion));
3350 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05) {
3351 // set MsgVersion and HeaderVersion host driver was built with
3352 ioc_init.MsgVersion = cpu_to_le16(MPI_VERSION);
3353 ioc_init.HeaderVersion = cpu_to_le16(MPI_HEADER_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003355 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_HOST_PAGE_BUFFER_PERSISTENT) {
3356 ioc_init.HostPageBufferSGE = ioc->facts.HostPageBufferSGE;
3357 } else if(mpt_host_page_alloc(ioc, &ioc_init))
3358 return -99;
3359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
3361
Kashyap, Desai2f187862009-05-29 16:52:37 +05303362 if (ioc->sg_addr_size == sizeof(u64)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 /* Save the upper 32-bits of the request
3364 * (reply) and sense buffers.
3365 */
3366 ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
3367 ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
3368 } else {
3369 /* Force 32-bit addressing */
3370 ioc_init.HostMfaHighAddr = cpu_to_le32(0);
3371 ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
3372 }
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003373
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
3375 ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003376 ioc->facts.MaxDevices = ioc_init.MaxDevices;
3377 ioc->facts.MaxBuses = ioc_init.MaxBuses;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
Prakash, Sathya436ace72007-07-24 15:42:08 +05303379 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending IOCInit (req @ %p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 ioc->name, &ioc_init));
3381
3382 r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
3383 sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003384 if (r != 0) {
3385 printk(MYIOC_s_ERR_FMT "Sending IOCInit failed(%d)!\n",ioc->name, r);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 return r;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388
3389 /* No need to byte swap the multibyte fields in the reply
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003390 * since we don't even look at its contents.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 */
3392
Prakash, Sathya436ace72007-07-24 15:42:08 +05303393 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending PortEnable (req @ %p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 ioc->name, &ioc_init));
Christoph Hellwigc6678e02005-08-18 16:24:53 +02003395
3396 if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0) {
3397 printk(MYIOC_s_ERR_FMT "Sending PortEnable failed(%d)!\n",ioc->name, r);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 return r;
Christoph Hellwigc6678e02005-08-18 16:24:53 +02003399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400
3401 /* YIKES! SUPER IMPORTANT!!!
3402 * Poll IocState until _OPERATIONAL while IOC is doing
3403 * LoopInit and TargetDiscovery!
3404 */
3405 count = 0;
3406 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
3407 state = mpt_GetIocState(ioc, 1);
3408 while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
3409 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05003410 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 } else {
3412 mdelay(1);
3413 }
3414
3415 if (!cntdn) {
3416 printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
3417 ioc->name, (int)((count+5)/HZ));
3418 return -9;
3419 }
3420
3421 state = mpt_GetIocState(ioc, 1);
3422 count++;
3423 }
Eric Moore29dd3602007-09-14 18:46:51 -06003424 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Wait IOC_OPERATIONAL state (cnt=%d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 ioc->name, count));
3426
Eric Mooreba856d32006-07-11 17:34:01 -06003427 ioc->aen_event_read_flag=0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 return r;
3429}
3430
3431/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003432/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 * SendPortEnable - Send PortEnable request to MPT adapter port.
3434 * @ioc: Pointer to MPT_ADAPTER structure
3435 * @portnum: Port number to enable
3436 * @sleepFlag: Specifies whether the process can sleep
3437 *
3438 * Send PortEnable to bring IOC to OPERATIONAL state.
3439 *
3440 * Returns 0 for success, non-zero for failure.
3441 */
3442static int
3443SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
3444{
3445 PortEnable_t port_enable;
3446 MPIDefaultReply_t reply_buf;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003447 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 int req_sz;
3449 int reply_sz;
3450
3451 /* Destination... */
3452 reply_sz = sizeof(MPIDefaultReply_t);
3453 memset(&reply_buf, 0, reply_sz);
3454
3455 req_sz = sizeof(PortEnable_t);
3456 memset(&port_enable, 0, req_sz);
3457
3458 port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
3459 port_enable.PortNumber = portnum;
3460/* port_enable.ChainOffset = 0; */
3461/* port_enable.MsgFlags = 0; */
3462/* port_enable.MsgContext = 0; */
3463
Prakash, Sathya436ace72007-07-24 15:42:08 +05303464 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Port(%d)Enable (req @ %p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 ioc->name, portnum, &port_enable));
3466
3467 /* RAID FW may take a long time to enable
3468 */
Eric Mooreb506ade2007-01-29 09:45:37 -07003469 if (ioc->ir_firmware || ioc->bus_type == SAS) {
Moore, Eric432b4c82006-01-16 18:53:11 -07003470 rc = mpt_handshake_req_reply_wait(ioc, req_sz,
3471 (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
3472 300 /*seconds*/, sleepFlag);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003473 } else {
Moore, Eric432b4c82006-01-16 18:53:11 -07003474 rc = mpt_handshake_req_reply_wait(ioc, req_sz,
3475 (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
3476 30 /*seconds*/, sleepFlag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 }
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003478 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479}
3480
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003481/**
3482 * mpt_alloc_fw_memory - allocate firmware memory
3483 * @ioc: Pointer to MPT_ADAPTER structure
3484 * @size: total FW bytes
3485 *
3486 * If memory has already been allocated, the same (cached) value
3487 * is returned.
Prakash, Sathya984621b2008-01-11 14:42:17 +05303488 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003489 * Return 0 if successful, or non-zero for failure
Prakash, Sathya984621b2008-01-11 14:42:17 +05303490 **/
3491int
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
3493{
Prakash, Sathya984621b2008-01-11 14:42:17 +05303494 int rc;
3495
3496 if (ioc->cached_fw) {
3497 rc = 0; /* use already allocated memory */
3498 goto out;
3499 }
3500 else if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
3502 ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
Prakash, Sathya984621b2008-01-11 14:42:17 +05303503 rc = 0;
3504 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 }
Prakash, Sathya984621b2008-01-11 14:42:17 +05303506 ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma);
3507 if (!ioc->cached_fw) {
3508 printk(MYIOC_s_ERR_FMT "Unable to allocate memory for the cached firmware image!\n",
3509 ioc->name);
3510 rc = -1;
3511 } else {
3512 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FW Image @ %p[%p], sz=%d[%x] bytes\n",
3513 ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, size, size));
3514 ioc->alloc_total += size;
3515 rc = 0;
3516 }
3517 out:
3518 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519}
Prakash, Sathya984621b2008-01-11 14:42:17 +05303520
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003521/**
3522 * mpt_free_fw_memory - free firmware memory
3523 * @ioc: Pointer to MPT_ADAPTER structure
3524 *
3525 * If alt_img is NULL, delete from ioc structure.
3526 * Else, delete a secondary image in same format.
Prakash, Sathya984621b2008-01-11 14:42:17 +05303527 **/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528void
3529mpt_free_fw_memory(MPT_ADAPTER *ioc)
3530{
3531 int sz;
3532
Prakash, Sathya984621b2008-01-11 14:42:17 +05303533 if (!ioc->cached_fw)
3534 return;
3535
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 sz = ioc->facts.FWImageSize;
Prakash, Sathya984621b2008-01-11 14:42:17 +05303537 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
3538 ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
Eric Moore29dd3602007-09-14 18:46:51 -06003539 pci_free_consistent(ioc->pcidev, sz, ioc->cached_fw, ioc->cached_fw_dma);
Prakash, Sathya984621b2008-01-11 14:42:17 +05303540 ioc->alloc_total -= sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 ioc->cached_fw = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542}
3543
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003545/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
3547 * @ioc: Pointer to MPT_ADAPTER structure
3548 * @sleepFlag: Specifies whether the process can sleep
3549 *
3550 * Returns 0 for success, >0 for handshake failure
3551 * <0 for fw upload failure.
3552 *
3553 * Remark: If bound IOC and a successful FWUpload was performed
3554 * on the bound IOC, the second image is discarded
3555 * and memory is free'd. Both channels must upload to prevent
3556 * IOC from running in degraded mode.
3557 */
3558static int
3559mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
3560{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561 u8 reply[sizeof(FWUploadReply_t)];
3562 FWUpload_t *prequest;
3563 FWUploadReply_t *preply;
3564 FWUploadTCSGE_t *ptcsge;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 u32 flagsLength;
3566 int ii, sz, reply_sz;
3567 int cmdStatus;
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05303568 int request_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 /* If the image size is 0, we are done.
3570 */
3571 if ((sz = ioc->facts.FWImageSize) == 0)
3572 return 0;
3573
Prakash, Sathya984621b2008-01-11 14:42:17 +05303574 if (mpt_alloc_fw_memory(ioc, ioc->facts.FWImageSize) != 0)
3575 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576
Eric Moore29dd3602007-09-14 18:46:51 -06003577 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
3578 ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
Christoph Hellwigc6678e02005-08-18 16:24:53 +02003579
Eric Moorebc6e0892007-09-29 10:16:28 -06003580 prequest = (sleepFlag == NO_SLEEP) ? kzalloc(ioc->req_sz, GFP_ATOMIC) :
3581 kzalloc(ioc->req_sz, GFP_KERNEL);
3582 if (!prequest) {
3583 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "fw upload failed "
3584 "while allocating memory \n", ioc->name));
3585 mpt_free_fw_memory(ioc);
3586 return -ENOMEM;
3587 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588
Eric Moorebc6e0892007-09-29 10:16:28 -06003589 preply = (FWUploadReply_t *)&reply;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590
3591 reply_sz = sizeof(reply);
3592 memset(preply, 0, reply_sz);
3593
3594 prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
3595 prequest->Function = MPI_FUNCTION_FW_UPLOAD;
3596
3597 ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
3598 ptcsge->DetailsLength = 12;
3599 ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
3600 ptcsge->ImageSize = cpu_to_le32(sz);
Eric Moorebc6e0892007-09-29 10:16:28 -06003601 ptcsge++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05303604 ioc->add_sge((char *)ptcsge, flagsLength, ioc->cached_fw_dma);
3605 request_size = offsetof(FWUpload_t, SGL) + sizeof(FWUploadTCSGE_t) +
3606 ioc->SGE_size;
3607 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending FW Upload "
3608 " (req @ %p) fw_size=%d mf_request_size=%d\n", ioc->name, prequest,
3609 ioc->facts.FWImageSize, request_size));
Eric Moore29dd3602007-09-14 18:46:51 -06003610 DBG_DUMP_FW_REQUEST_FRAME(ioc, (u32 *)prequest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05303612 ii = mpt_handshake_req_reply_wait(ioc, request_size, (u32 *)prequest,
3613 reply_sz, (u16 *)preply, 65 /*seconds*/, sleepFlag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614
Kashyap, Desai2f187862009-05-29 16:52:37 +05303615 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FW Upload completed "
3616 "rc=%x \n", ioc->name, ii));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617
3618 cmdStatus = -EFAULT;
3619 if (ii == 0) {
3620 /* Handshake transfer was complete and successful.
3621 * Check the Reply Frame.
3622 */
Kashyap, Desai2f187862009-05-29 16:52:37 +05303623 int status;
3624 status = le16_to_cpu(preply->IOCStatus) &
3625 MPI_IOCSTATUS_MASK;
3626 if (status == MPI_IOCSTATUS_SUCCESS &&
3627 ioc->facts.FWImageSize ==
3628 le32_to_cpu(preply->ActualImageSize))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 cmdStatus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 }
Prakash, Sathya436ace72007-07-24 15:42:08 +05303631 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": do_upload cmdStatus=%d \n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 ioc->name, cmdStatus));
3633
Christoph Hellwigc6678e02005-08-18 16:24:53 +02003634
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 if (cmdStatus) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05303636 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "fw upload failed, "
3637 "freeing image \n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 mpt_free_fw_memory(ioc);
3639 }
Eric Moorebc6e0892007-09-29 10:16:28 -06003640 kfree(prequest);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641
3642 return cmdStatus;
3643}
3644
3645/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003646/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 * mpt_downloadboot - DownloadBoot code
3648 * @ioc: Pointer to MPT_ADAPTER structure
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003649 * @pFwHeader: Pointer to firmware header info
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 * @sleepFlag: Specifies whether the process can sleep
3651 *
3652 * FwDownloadBoot requires Programmed IO access.
3653 *
3654 * Returns 0 for success
3655 * -1 FW Image size is 0
3656 * -2 No valid cached_fw Pointer
3657 * <0 for fw upload failure.
3658 */
3659static int
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003660mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 MpiExtImageHeader_t *pExtImage;
3663 u32 fwSize;
3664 u32 diag0val;
3665 int count;
3666 u32 *ptrFw;
3667 u32 diagRwData;
3668 u32 nextImage;
3669 u32 load_addr;
3670 u32 ioc_state=0;
3671
Prakash, Sathya436ace72007-07-24 15:42:08 +05303672 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot: fw size 0x%x (%d), FW Ptr %p\n",
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003673 ioc->name, pFwHeader->ImageSize, pFwHeader->ImageSize, pFwHeader));
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -06003674
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
3676 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
3677 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
3678 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
3679 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
3680 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
3681
3682 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
3683
3684 /* wait 1 msec */
3685 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05003686 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 } else {
3688 mdelay (1);
3689 }
3690
3691 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3692 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
3693
3694 for (count = 0; count < 30; count ++) {
3695 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3696 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05303697 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RESET_ADAPTER cleared, count=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 ioc->name, count));
3699 break;
3700 }
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003701 /* wait .1 sec */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05003703 msleep (100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 } else {
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003705 mdelay (100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 }
3707 }
3708
3709 if ( count == 30 ) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05303710 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot failed! "
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003711 "Unable to get MPI_DIAG_DRWE mode, diag0val=%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 ioc->name, diag0val));
3713 return -3;
3714 }
3715
3716 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
3717 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
3718 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
3719 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
3720 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
3721 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
3722
3723 /* Set the DiagRwEn and Disable ARM bits */
3724 CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
3725
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 fwSize = (pFwHeader->ImageSize + 3)/4;
3727 ptrFw = (u32 *) pFwHeader;
3728
3729 /* Write the LoadStartAddress to the DiagRw Address Register
3730 * using Programmed IO
3731 */
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -06003732 if (ioc->errata_flag_1064)
3733 pci_enable_io_access(ioc->pcidev);
3734
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
Prakash, Sathya436ace72007-07-24 15:42:08 +05303736 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "LoadStart addr written 0x%x \n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 ioc->name, pFwHeader->LoadStartAddress));
3738
Prakash, Sathya436ace72007-07-24 15:42:08 +05303739 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write FW Image: 0x%x bytes @ %p\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 ioc->name, fwSize*4, ptrFw));
3741 while (fwSize--) {
3742 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
3743 }
3744
3745 nextImage = pFwHeader->NextImageHeaderOffset;
3746 while (nextImage) {
3747 pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
3748
3749 load_addr = pExtImage->LoadStartAddress;
3750
3751 fwSize = (pExtImage->ImageSize + 3) >> 2;
3752 ptrFw = (u32 *)pExtImage;
3753
Prakash, Sathya436ace72007-07-24 15:42:08 +05303754 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write Ext Image: 0x%x (%d) bytes @ %p load_addr=%x\n",
Christoph Hellwigc6678e02005-08-18 16:24:53 +02003755 ioc->name, fwSize*4, fwSize*4, ptrFw, load_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
3757
3758 while (fwSize--) {
3759 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
3760 }
3761 nextImage = pExtImage->NextImageHeaderOffset;
3762 }
3763
3764 /* Write the IopResetVectorRegAddr */
Prakash, Sathya436ace72007-07-24 15:42:08 +05303765 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
3767
3768 /* Write the IopResetVectorValue */
Prakash, Sathya436ace72007-07-24 15:42:08 +05303769 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
3771
3772 /* Clear the internal flash bad bit - autoincrementing register,
3773 * so must do two writes.
3774 */
Moore, Eric Deana9b29372005-11-16 18:54:20 -07003775 if (ioc->bus_type == SPI) {
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003776 /*
3777 * 1030 and 1035 H/W errata, workaround to access
3778 * the ClearFlashBadSignatureBit
3779 */
3780 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
3781 diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
3782 diagRwData |= 0x40000000;
3783 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
3784 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
3785
3786 } else /* if((ioc->bus_type == SAS) || (ioc->bus_type == FC)) */ {
3787 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3788 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val |
3789 MPI_DIAG_CLEAR_FLASH_BAD_SIG);
3790
3791 /* wait 1 msec */
3792 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05003793 msleep (1);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003794 } else {
3795 mdelay (1);
3796 }
3797 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -06003799 if (ioc->errata_flag_1064)
3800 pci_disable_io_access(ioc->pcidev);
3801
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
Prakash, Sathya436ace72007-07-24 15:42:08 +05303803 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot diag0val=%x, "
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003804 "turning off PREVENT_IOC_BOOT, DISABLE_ARM, RW_ENABLE\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 ioc->name, diag0val));
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003806 diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM | MPI_DIAG_RW_ENABLE);
Prakash, Sathya436ace72007-07-24 15:42:08 +05303807 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot now diag0val=%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 ioc->name, diag0val));
3809 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
3810
3811 /* Write 0xFF to reset the sequencer */
3812 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
3813
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003814 if (ioc->bus_type == SAS) {
3815 ioc_state = mpt_GetIocState(ioc, 0);
3816 if ( (GetIocFacts(ioc, sleepFlag,
3817 MPT_HOSTEVENT_IOC_BRINGUP)) != 0 ) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05303818 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "GetIocFacts failed: IocState=%x\n",
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003819 ioc->name, ioc_state));
3820 return -EFAULT;
3821 }
3822 }
3823
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 for (count=0; count<HZ*20; count++) {
3825 if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05303826 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3827 "downloadboot successful! (count=%d) IocState=%x\n",
3828 ioc->name, count, ioc_state));
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02003829 if (ioc->bus_type == SAS) {
3830 return 0;
3831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 if ((SendIocInit(ioc, sleepFlag)) != 0) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05303833 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3834 "downloadboot: SendIocInit failed\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 ioc->name));
3836 return -EFAULT;
3837 }
Prakash, Sathya436ace72007-07-24 15:42:08 +05303838 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3839 "downloadboot: SendIocInit successful\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 ioc->name));
3841 return 0;
3842 }
3843 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05003844 msleep (10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 } else {
3846 mdelay (10);
3847 }
3848 }
Prakash, Sathya436ace72007-07-24 15:42:08 +05303849 ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
3850 "downloadboot failed! IocState=%x\n",ioc->name, ioc_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 return -EFAULT;
3852}
3853
3854/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003855/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 * KickStart - Perform hard reset of MPT adapter.
3857 * @ioc: Pointer to MPT_ADAPTER structure
3858 * @force: Force hard reset
3859 * @sleepFlag: Specifies whether the process can sleep
3860 *
3861 * This routine places MPT adapter in diagnostic mode via the
3862 * WriteSequence register, and then performs a hard reset of adapter
3863 * via the Diagnostic register.
3864 *
3865 * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
3866 * or NO_SLEEP (interrupt thread, use mdelay)
3867 * force - 1 if doorbell active, board fault state
3868 * board operational, IOC_RECOVERY or
3869 * IOC_BRINGUP and there is an alt_ioc.
3870 * 0 else
3871 *
3872 * Returns:
Christoph Hellwigc6678e02005-08-18 16:24:53 +02003873 * 1 - hard reset, READY
3874 * 0 - no reset due to History bit, READY
3875 * -1 - no reset due to History bit but not READY
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 * OR reset but failed to come READY
3877 * -2 - no reset, could not enter DIAG mode
3878 * -3 - reset but bad FW bit
3879 */
3880static int
3881KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
3882{
3883 int hard_reset_done = 0;
3884 u32 ioc_state=0;
3885 int cnt,cntdn;
3886
Eric Moore29dd3602007-09-14 18:46:51 -06003887 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "KickStarting!\n", ioc->name));
Moore, Eric Deana9b29372005-11-16 18:54:20 -07003888 if (ioc->bus_type == SPI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 /* Always issue a Msg Unit Reset first. This will clear some
3890 * SCSI bus hang conditions.
3891 */
3892 SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
3893
3894 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05003895 msleep (1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 } else {
3897 mdelay (1000);
3898 }
3899 }
3900
3901 hard_reset_done = mpt_diag_reset(ioc, force, sleepFlag);
3902 if (hard_reset_done < 0)
3903 return hard_reset_done;
3904
Prakash, Sathya436ace72007-07-24 15:42:08 +05303905 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Diagnostic reset successful!\n",
Eric Moore29dd3602007-09-14 18:46:51 -06003906 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907
3908 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2; /* 2 seconds */
3909 for (cnt=0; cnt<cntdn; cnt++) {
3910 ioc_state = mpt_GetIocState(ioc, 1);
3911 if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05303912 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "KickStart successful! (cnt=%d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 ioc->name, cnt));
3914 return hard_reset_done;
3915 }
3916 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05003917 msleep (10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 } else {
3919 mdelay (10);
3920 }
3921 }
3922
Eric Moore29dd3602007-09-14 18:46:51 -06003923 dinitprintk(ioc, printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
3924 ioc->name, mpt_GetIocState(ioc, 0)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 return -1;
3926}
3927
3928/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003929/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 * mpt_diag_reset - Perform hard reset of the adapter.
3931 * @ioc: Pointer to MPT_ADAPTER structure
3932 * @ignore: Set if to honor and clear to ignore
3933 * the reset history bit
Randy Dunlapd9489fb2006-12-06 20:38:43 -08003934 * @sleepFlag: CAN_SLEEP if called in a non-interrupt thread,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 * else set to NO_SLEEP (use mdelay instead)
3936 *
3937 * This routine places the adapter in diagnostic mode via the
3938 * WriteSequence register and then performs a hard reset of adapter
3939 * via the Diagnostic register. Adapter should be in ready state
3940 * upon successful completion.
3941 *
3942 * Returns: 1 hard reset successful
3943 * 0 no reset performed because reset history bit set
3944 * -2 enabling diagnostic mode failed
3945 * -3 diagnostic reset failed
3946 */
3947static int
3948mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
3949{
3950 u32 diag0val;
3951 u32 doorbell;
3952 int hard_reset_done = 0;
3953 int count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 u32 diag1val = 0;
Prakash, Sathya984621b2008-01-11 14:42:17 +05303955 MpiFwHeader_t *cached_fw; /* Pointer to FW */
Kashyap, Desaid1306912009-08-05 12:53:51 +05303956 u8 cb_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957
Eric Moorecd2c6192007-01-29 09:47:47 -07003958 /* Clear any existing interrupts */
3959 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3960
Eric Moore87cf8982006-06-27 16:09:26 -06003961 if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05303962
3963 if (!ignore)
3964 return 0;
3965
Prakash, Sathya436ace72007-07-24 15:42:08 +05303966 drsprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: Doorbell=%p; 1078 reset "
Harvey Harrisoncadbd4a2008-07-03 23:47:27 -07003967 "address=%p\n", ioc->name, __func__,
Eric Moore87cf8982006-06-27 16:09:26 -06003968 &ioc->chip->Doorbell, &ioc->chip->Reset_1078));
3969 CHIPREG_WRITE32(&ioc->chip->Reset_1078, 0x07);
3970 if (sleepFlag == CAN_SLEEP)
3971 msleep(1);
3972 else
3973 mdelay(1);
3974
Kashyap, Desaid1306912009-08-05 12:53:51 +05303975 /*
3976 * Call each currently registered protocol IOC reset handler
3977 * with pre-reset indication.
3978 * NOTE: If we're doing _IOC_BRINGUP, there can be no
3979 * MptResetHandlers[] registered yet.
3980 */
3981 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
3982 if (MptResetHandlers[cb_idx])
3983 (*(MptResetHandlers[cb_idx]))(ioc,
3984 MPT_IOC_PRE_RESET);
3985 }
3986
Eric Moore87cf8982006-06-27 16:09:26 -06003987 for (count = 0; count < 60; count ++) {
3988 doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
3989 doorbell &= MPI_IOC_STATE_MASK;
3990
Prakash, Sathya436ace72007-07-24 15:42:08 +05303991 drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Eric Moore87cf8982006-06-27 16:09:26 -06003992 "looking for READY STATE: doorbell=%x"
3993 " count=%d\n",
3994 ioc->name, doorbell, count));
Kashyap, Desai2f187862009-05-29 16:52:37 +05303995
Eric Moore87cf8982006-06-27 16:09:26 -06003996 if (doorbell == MPI_IOC_STATE_READY) {
Eric Moorecd2c6192007-01-29 09:47:47 -07003997 return 1;
Eric Moore87cf8982006-06-27 16:09:26 -06003998 }
3999
4000 /* wait 1 sec */
4001 if (sleepFlag == CAN_SLEEP)
4002 msleep(1000);
4003 else
4004 mdelay(1000);
4005 }
4006 return -1;
4007 }
4008
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 /* Use "Diagnostic reset" method! (only thing available!) */
4010 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
4011
Prakash, Sathya436ace72007-07-24 15:42:08 +05304012 if (ioc->debug_level & MPT_DEBUG) {
4013 if (ioc->alt_ioc)
4014 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
4015 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG1: diag0=%08x, diag1=%08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 ioc->name, diag0val, diag1val));
Prakash, Sathya436ace72007-07-24 15:42:08 +05304017 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018
4019 /* Do the reset if we are told to ignore the reset history
4020 * or if the reset history is 0
4021 */
4022 if (ignore || !(diag0val & MPI_DIAG_RESET_HISTORY)) {
4023 while ((diag0val & MPI_DIAG_DRWE) == 0) {
4024 /* Write magic sequence to WriteSequence register
4025 * Loop until in diagnostic mode
4026 */
4027 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
4028 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
4029 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
4030 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
4031 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
4032 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
4033
4034 /* wait 100 msec */
4035 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05004036 msleep (100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 } else {
4038 mdelay (100);
4039 }
4040
4041 count++;
4042 if (count > 20) {
4043 printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
4044 ioc->name, diag0val);
4045 return -2;
4046
4047 }
4048
4049 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
4050
Prakash, Sathya436ace72007-07-24 15:42:08 +05304051 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 ioc->name, diag0val));
4053 }
4054
Prakash, Sathya436ace72007-07-24 15:42:08 +05304055 if (ioc->debug_level & MPT_DEBUG) {
4056 if (ioc->alt_ioc)
4057 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
4058 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG2: diag0=%08x, diag1=%08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059 ioc->name, diag0val, diag1val));
Prakash, Sathya436ace72007-07-24 15:42:08 +05304060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 /*
4062 * Disable the ARM (Bug fix)
4063 *
4064 */
4065 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
Christoph Hellwigc6678e02005-08-18 16:24:53 +02004066 mdelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067
4068 /*
4069 * Now hit the reset bit in the Diagnostic register
4070 * (THE BIG HAMMER!) (Clears DRWE bit).
4071 */
4072 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
4073 hard_reset_done = 1;
Prakash, Sathya436ace72007-07-24 15:42:08 +05304074 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Diagnostic reset performed\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 ioc->name));
4076
4077 /*
4078 * Call each currently registered protocol IOC reset handler
4079 * with pre-reset indication.
4080 * NOTE: If we're doing _IOC_BRINGUP, there can be no
4081 * MptResetHandlers[] registered yet.
4082 */
Kashyap, Desaid1306912009-08-05 12:53:51 +05304083 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
4084 if (MptResetHandlers[cb_idx]) {
4085 mpt_signal_reset(cb_idx,
4086 ioc, MPT_IOC_PRE_RESET);
4087 if (ioc->alt_ioc) {
4088 mpt_signal_reset(cb_idx,
4089 ioc->alt_ioc, MPT_IOC_PRE_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 }
4091 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 }
4093
Eric Moore0ccdb002006-07-11 17:33:13 -06004094 if (ioc->cached_fw)
Prakash, Sathya984621b2008-01-11 14:42:17 +05304095 cached_fw = (MpiFwHeader_t *)ioc->cached_fw;
Eric Moore0ccdb002006-07-11 17:33:13 -06004096 else if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
Prakash, Sathya984621b2008-01-11 14:42:17 +05304097 cached_fw = (MpiFwHeader_t *)ioc->alt_ioc->cached_fw;
4098 else
4099 cached_fw = NULL;
4100 if (cached_fw) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 /* If the DownloadBoot operation fails, the
4102 * IOC will be left unusable. This is a fatal error
4103 * case. _diag_reset will return < 0
4104 */
4105 for (count = 0; count < 30; count ++) {
Prakash, Sathya984621b2008-01-11 14:42:17 +05304106 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
4108 break;
4109 }
4110
Prakash, Sathya436ace72007-07-24 15:42:08 +05304111 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "cached_fw: diag0val=%x count=%d\n",
Prakash, Sathya984621b2008-01-11 14:42:17 +05304112 ioc->name, diag0val, count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 /* wait 1 sec */
4114 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05004115 msleep (1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 } else {
4117 mdelay (1000);
4118 }
4119 }
Prakash, Sathya984621b2008-01-11 14:42:17 +05304120 if ((count = mpt_downloadboot(ioc, cached_fw, sleepFlag)) < 0) {
Eric Moore29dd3602007-09-14 18:46:51 -06004121 printk(MYIOC_s_WARN_FMT
4122 "firmware downloadboot failure (%d)!\n", ioc->name, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 }
4124
4125 } else {
4126 /* Wait for FW to reload and for board
4127 * to go to the READY state.
4128 * Maximum wait is 60 seconds.
4129 * If fail, no error will check again
4130 * with calling program.
4131 */
4132 for (count = 0; count < 60; count ++) {
4133 doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
4134 doorbell &= MPI_IOC_STATE_MASK;
4135
Kashyap, Desai2f187862009-05-29 16:52:37 +05304136 drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4137 "looking for READY STATE: doorbell=%x"
4138 " count=%d\n", ioc->name, doorbell, count));
4139
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 if (doorbell == MPI_IOC_STATE_READY) {
4141 break;
4142 }
4143
4144 /* wait 1 sec */
4145 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05004146 msleep (1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 } else {
4148 mdelay (1000);
4149 }
4150 }
Kashyap, Desai2f187862009-05-29 16:52:37 +05304151
4152 if (doorbell != MPI_IOC_STATE_READY)
4153 printk(MYIOC_s_ERR_FMT "Failed to come READY "
4154 "after reset! IocState=%x", ioc->name,
4155 doorbell);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 }
4157 }
4158
4159 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
Prakash, Sathya436ace72007-07-24 15:42:08 +05304160 if (ioc->debug_level & MPT_DEBUG) {
4161 if (ioc->alt_ioc)
4162 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
4163 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG3: diag0=%08x, diag1=%08x\n",
4164 ioc->name, diag0val, diag1val));
4165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166
4167 /* Clear RESET_HISTORY bit! Place board in the
4168 * diagnostic mode to update the diag register.
4169 */
4170 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
4171 count = 0;
4172 while ((diag0val & MPI_DIAG_DRWE) == 0) {
4173 /* Write magic sequence to WriteSequence register
4174 * Loop until in diagnostic mode
4175 */
4176 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
4177 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
4178 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
4179 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
4180 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
4181 CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
4182
4183 /* wait 100 msec */
4184 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05004185 msleep (100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 } else {
4187 mdelay (100);
4188 }
4189
4190 count++;
4191 if (count > 20) {
4192 printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
4193 ioc->name, diag0val);
4194 break;
4195 }
4196 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
4197 }
4198 diag0val &= ~MPI_DIAG_RESET_HISTORY;
4199 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
4200 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
4201 if (diag0val & MPI_DIAG_RESET_HISTORY) {
4202 printk(MYIOC_s_WARN_FMT "ResetHistory bit failed to clear!\n",
4203 ioc->name);
4204 }
4205
4206 /* Disable Diagnostic Mode
4207 */
4208 CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFFFFFFFF);
4209
4210 /* Check FW reload status flags.
4211 */
4212 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
4213 if (diag0val & (MPI_DIAG_FLASH_BAD_SIG | MPI_DIAG_RESET_ADAPTER | MPI_DIAG_DISABLE_ARM)) {
4214 printk(MYIOC_s_ERR_FMT "Diagnostic reset FAILED! (%02xh)\n",
4215 ioc->name, diag0val);
4216 return -3;
4217 }
4218
Prakash, Sathya436ace72007-07-24 15:42:08 +05304219 if (ioc->debug_level & MPT_DEBUG) {
4220 if (ioc->alt_ioc)
4221 diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
4222 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG4: diag0=%08x, diag1=%08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 ioc->name, diag0val, diag1val));
Prakash, Sathya436ace72007-07-24 15:42:08 +05304224 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225
4226 /*
4227 * Reset flag that says we've enabled event notification
4228 */
4229 ioc->facts.EventState = 0;
4230
4231 if (ioc->alt_ioc)
4232 ioc->alt_ioc->facts.EventState = 0;
4233
4234 return hard_reset_done;
4235}
4236
4237/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08004238/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239 * SendIocReset - Send IOCReset request to MPT adapter.
4240 * @ioc: Pointer to MPT_ADAPTER structure
4241 * @reset_type: reset type, expected values are
4242 * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
Randy Dunlapd9489fb2006-12-06 20:38:43 -08004243 * @sleepFlag: Specifies whether the process can sleep
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244 *
4245 * Send IOCReset request to the MPT adapter.
4246 *
4247 * Returns 0 for success, non-zero for failure.
4248 */
4249static int
4250SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
4251{
4252 int r;
4253 u32 state;
4254 int cntdn, count;
4255
Prakash, Sathya436ace72007-07-24 15:42:08 +05304256 drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending IOC reset(0x%02x)!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 ioc->name, reset_type));
4258 CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
4259 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
4260 return r;
4261
4262 /* FW ACK'd request, wait for READY state
4263 */
4264 count = 0;
4265 cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
4266
4267 while ((state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
4268 cntdn--;
4269 count++;
4270 if (!cntdn) {
4271 if (sleepFlag != CAN_SLEEP)
4272 count *= 10;
4273
Kashyap, Desai2f187862009-05-29 16:52:37 +05304274 printk(MYIOC_s_ERR_FMT
4275 "Wait IOC_READY state (0x%x) timeout(%d)!\n",
4276 ioc->name, state, (int)((count+5)/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277 return -ETIME;
4278 }
4279
4280 if (sleepFlag == CAN_SLEEP) {
Michael Reedd6be06c2006-05-24 15:07:57 -05004281 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 } else {
4283 mdelay (1); /* 1 msec delay */
4284 }
4285 }
4286
4287 /* TODO!
4288 * Cleanup all event stuff for this IOC; re-issue EventNotification
4289 * request if needed.
4290 */
4291 if (ioc->facts.Function)
4292 ioc->facts.EventState = 0;
4293
4294 return 0;
4295}
4296
4297/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08004298/**
4299 * initChainBuffers - Allocate memory for and initialize chain buffers
4300 * @ioc: Pointer to MPT_ADAPTER structure
4301 *
4302 * Allocates memory for and initializes chain buffers,
4303 * chain buffer control arrays and spinlock.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304 */
4305static int
4306initChainBuffers(MPT_ADAPTER *ioc)
4307{
4308 u8 *mem;
4309 int sz, ii, num_chain;
4310 int scale, num_sge, numSGE;
4311
4312 /* ReqToChain size must equal the req_depth
4313 * index = req_idx
4314 */
4315 if (ioc->ReqToChain == NULL) {
4316 sz = ioc->req_depth * sizeof(int);
4317 mem = kmalloc(sz, GFP_ATOMIC);
4318 if (mem == NULL)
4319 return -1;
4320
4321 ioc->ReqToChain = (int *) mem;
Prakash, Sathya436ace72007-07-24 15:42:08 +05304322 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReqToChain alloc @ %p, sz=%d bytes\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 ioc->name, mem, sz));
4324 mem = kmalloc(sz, GFP_ATOMIC);
4325 if (mem == NULL)
4326 return -1;
4327
4328 ioc->RequestNB = (int *) mem;
Prakash, Sathya436ace72007-07-24 15:42:08 +05304329 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestNB alloc @ %p, sz=%d bytes\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 ioc->name, mem, sz));
4331 }
4332 for (ii = 0; ii < ioc->req_depth; ii++) {
4333 ioc->ReqToChain[ii] = MPT_HOST_NO_CHAIN;
4334 }
4335
4336 /* ChainToChain size must equal the total number
4337 * of chain buffers to be allocated.
4338 * index = chain_idx
4339 *
4340 * Calculate the number of chain buffers needed(plus 1) per I/O
Michael Opdenacker59c51592007-05-09 08:57:56 +02004341 * then multiply the maximum number of simultaneous cmds
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 *
4343 * num_sge = num sge in request frame + last chain buffer
4344 * scale = num sge per chain buffer if no chain element
4345 */
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304346 scale = ioc->req_sz / ioc->SGE_size;
4347 if (ioc->sg_addr_size == sizeof(u64))
4348 num_sge = scale + (ioc->req_sz - 60) / ioc->SGE_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 else
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304350 num_sge = 1 + scale + (ioc->req_sz - 64) / ioc->SGE_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304352 if (ioc->sg_addr_size == sizeof(u64)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304354 (ioc->req_sz - 60) / ioc->SGE_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 } else {
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304356 numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) +
4357 scale + (ioc->req_sz - 64) / ioc->SGE_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 }
Prakash, Sathya436ace72007-07-24 15:42:08 +05304359 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "num_sge=%d numSGE=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 ioc->name, num_sge, numSGE));
4361
Kashyap, Desai2f187862009-05-29 16:52:37 +05304362 if (ioc->bus_type == FC) {
4363 if (numSGE > MPT_SCSI_FC_SG_DEPTH)
4364 numSGE = MPT_SCSI_FC_SG_DEPTH;
4365 } else {
4366 if (numSGE > MPT_SCSI_SG_DEPTH)
4367 numSGE = MPT_SCSI_SG_DEPTH;
4368 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369
4370 num_chain = 1;
4371 while (numSGE - num_sge > 0) {
4372 num_chain++;
4373 num_sge += (scale - 1);
4374 }
4375 num_chain++;
4376
Prakash, Sathya436ace72007-07-24 15:42:08 +05304377 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Now numSGE=%d num_sge=%d num_chain=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378 ioc->name, numSGE, num_sge, num_chain));
4379
Moore, Eric Deana9b29372005-11-16 18:54:20 -07004380 if (ioc->bus_type == SPI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381 num_chain *= MPT_SCSI_CAN_QUEUE;
Anatolij Gustschinf1053a72009-12-12 14:52:21 +01004382 else if (ioc->bus_type == SAS)
4383 num_chain *= MPT_SAS_CAN_QUEUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384 else
4385 num_chain *= MPT_FC_CAN_QUEUE;
4386
4387 ioc->num_chain = num_chain;
4388
4389 sz = num_chain * sizeof(int);
4390 if (ioc->ChainToChain == NULL) {
4391 mem = kmalloc(sz, GFP_ATOMIC);
4392 if (mem == NULL)
4393 return -1;
4394
4395 ioc->ChainToChain = (int *) mem;
Prakash, Sathya436ace72007-07-24 15:42:08 +05304396 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainToChain alloc @ %p, sz=%d bytes\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 ioc->name, mem, sz));
4398 } else {
4399 mem = (u8 *) ioc->ChainToChain;
4400 }
4401 memset(mem, 0xFF, sz);
4402 return num_chain;
4403}
4404
4405/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08004406/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 * PrimeIocFifos - Initialize IOC request and reply FIFOs.
4408 * @ioc: Pointer to MPT_ADAPTER structure
4409 *
4410 * This routine allocates memory for the MPT reply and request frame
4411 * pools (if necessary), and primes the IOC reply FIFO with
4412 * reply frames.
4413 *
4414 * Returns 0 for success, non-zero for failure.
4415 */
4416static int
4417PrimeIocFifos(MPT_ADAPTER *ioc)
4418{
4419 MPT_FRAME_HDR *mf;
4420 unsigned long flags;
4421 dma_addr_t alloc_dma;
4422 u8 *mem;
4423 int i, reply_sz, sz, total_size, num_chain;
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304424 u64 dma_mask;
4425
4426 dma_mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427
4428 /* Prime reply FIFO... */
4429
4430 if (ioc->reply_frames == NULL) {
4431 if ( (num_chain = initChainBuffers(ioc)) < 0)
4432 return -1;
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304433 /*
4434 * 1078 errata workaround for the 36GB limitation
4435 */
4436 if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078 &&
Andrew Morton8e20ce92009-06-18 16:49:17 -07004437 ioc->dma_mask > DMA_BIT_MASK(35)) {
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304438 if (!pci_set_dma_mask(ioc->pcidev, DMA_BIT_MASK(32))
4439 && !pci_set_consistent_dma_mask(ioc->pcidev,
4440 DMA_BIT_MASK(32))) {
Andrew Morton8e20ce92009-06-18 16:49:17 -07004441 dma_mask = DMA_BIT_MASK(35);
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304442 d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4443 "setting 35 bit addressing for "
4444 "Request/Reply/Chain and Sense Buffers\n",
4445 ioc->name));
4446 } else {
4447 /*Reseting DMA mask to 64 bit*/
4448 pci_set_dma_mask(ioc->pcidev,
4449 DMA_BIT_MASK(64));
4450 pci_set_consistent_dma_mask(ioc->pcidev,
4451 DMA_BIT_MASK(64));
4452
4453 printk(MYIOC_s_ERR_FMT
4454 "failed setting 35 bit addressing for "
4455 "Request/Reply/Chain and Sense Buffers\n",
4456 ioc->name);
4457 return -1;
4458 }
4459 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460
4461 total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
Prakash, Sathya436ace72007-07-24 15:42:08 +05304462 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 ioc->name, ioc->reply_sz, ioc->reply_depth));
Prakash, Sathya436ace72007-07-24 15:42:08 +05304464 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffer sz=%d[%x] bytes\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 ioc->name, reply_sz, reply_sz));
4466
4467 sz = (ioc->req_sz * ioc->req_depth);
Prakash, Sathya436ace72007-07-24 15:42:08 +05304468 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestBuffer sz=%d bytes, RequestDepth=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 ioc->name, ioc->req_sz, ioc->req_depth));
Prakash, Sathya436ace72007-07-24 15:42:08 +05304470 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestBuffer sz=%d[%x] bytes\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004471 ioc->name, sz, sz));
4472 total_size += sz;
4473
4474 sz = num_chain * ioc->req_sz; /* chain buffer pool size */
Prakash, Sathya436ace72007-07-24 15:42:08 +05304475 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainBuffer sz=%d bytes, ChainDepth=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476 ioc->name, ioc->req_sz, num_chain));
Prakash, Sathya436ace72007-07-24 15:42:08 +05304477 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 ioc->name, sz, sz, num_chain));
4479
4480 total_size += sz;
4481 mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
4482 if (mem == NULL) {
4483 printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
4484 ioc->name);
4485 goto out_fail;
4486 }
4487
Prakash, Sathya436ace72007-07-24 15:42:08 +05304488 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Total alloc @ %p[%p], sz=%d[%x] bytes\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 ioc->name, mem, (void *)(ulong)alloc_dma, total_size, total_size));
4490
4491 memset(mem, 0, total_size);
4492 ioc->alloc_total += total_size;
4493 ioc->alloc = mem;
4494 ioc->alloc_dma = alloc_dma;
4495 ioc->alloc_sz = total_size;
4496 ioc->reply_frames = (MPT_FRAME_HDR *) mem;
4497 ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
4498
Prakash, Sathya436ace72007-07-24 15:42:08 +05304499 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffers @ %p[%p]\n",
Christoph Hellwigc6678e02005-08-18 16:24:53 +02004500 ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
4501
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 alloc_dma += reply_sz;
4503 mem += reply_sz;
4504
4505 /* Request FIFO - WE manage this! */
4506
4507 ioc->req_frames = (MPT_FRAME_HDR *) mem;
4508 ioc->req_frames_dma = alloc_dma;
4509
Prakash, Sathya436ace72007-07-24 15:42:08 +05304510 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestBuffers @ %p[%p]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 ioc->name, mem, (void *)(ulong)alloc_dma));
4512
4513 ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
4514
4515#if defined(CONFIG_MTRR) && 0
4516 /*
4517 * Enable Write Combining MTRR for IOC's memory region.
4518 * (at least as much as we can; "size and base must be
4519 * multiples of 4 kiB"
4520 */
4521 ioc->mtrr_reg = mtrr_add(ioc->req_frames_dma,
4522 sz,
4523 MTRR_TYPE_WRCOMB, 1);
Prakash, Sathya436ace72007-07-24 15:42:08 +05304524 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MTRR region registered (base:size=%08x:%x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 ioc->name, ioc->req_frames_dma, sz));
4526#endif
4527
4528 for (i = 0; i < ioc->req_depth; i++) {
4529 alloc_dma += ioc->req_sz;
4530 mem += ioc->req_sz;
4531 }
4532
4533 ioc->ChainBuffer = mem;
4534 ioc->ChainBufferDMA = alloc_dma;
4535
Prakash, Sathya436ace72007-07-24 15:42:08 +05304536 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainBuffers @ %p(%p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537 ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
4538
4539 /* Initialize the free chain Q.
4540 */
4541
4542 INIT_LIST_HEAD(&ioc->FreeChainQ);
4543
4544 /* Post the chain buffers to the FreeChainQ.
4545 */
4546 mem = (u8 *)ioc->ChainBuffer;
4547 for (i=0; i < num_chain; i++) {
4548 mf = (MPT_FRAME_HDR *) mem;
4549 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeChainQ);
4550 mem += ioc->req_sz;
4551 }
4552
4553 /* Initialize Request frames linked list
4554 */
4555 alloc_dma = ioc->req_frames_dma;
4556 mem = (u8 *) ioc->req_frames;
4557
4558 spin_lock_irqsave(&ioc->FreeQlock, flags);
4559 INIT_LIST_HEAD(&ioc->FreeQ);
4560 for (i = 0; i < ioc->req_depth; i++) {
4561 mf = (MPT_FRAME_HDR *) mem;
4562
4563 /* Queue REQUESTs *internally*! */
4564 list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
4565
4566 mem += ioc->req_sz;
4567 }
4568 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
4569
4570 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
4571 ioc->sense_buf_pool =
4572 pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
4573 if (ioc->sense_buf_pool == NULL) {
4574 printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
4575 ioc->name);
4576 goto out_fail;
4577 }
4578
4579 ioc->sense_buf_low_dma = (u32) (ioc->sense_buf_pool_dma & 0xFFFFFFFF);
4580 ioc->alloc_total += sz;
Prakash, Sathya436ace72007-07-24 15:42:08 +05304581 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SenseBuffers @ %p[%p]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 ioc->name, ioc->sense_buf_pool, (void *)(ulong)ioc->sense_buf_pool_dma));
4583
4584 }
4585
4586 /* Post Reply frames to FIFO
4587 */
4588 alloc_dma = ioc->alloc_dma;
Prakash, Sathya436ace72007-07-24 15:42:08 +05304589 dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffers @ %p[%p]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
4591
4592 for (i = 0; i < ioc->reply_depth; i++) {
4593 /* Write each address to the IOC! */
4594 CHIPREG_WRITE32(&ioc->chip->ReplyFifo, alloc_dma);
4595 alloc_dma += ioc->reply_sz;
4596 }
4597
Andrew Morton8e20ce92009-06-18 16:49:17 -07004598 if (dma_mask == DMA_BIT_MASK(35) && !pci_set_dma_mask(ioc->pcidev,
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304599 ioc->dma_mask) && !pci_set_consistent_dma_mask(ioc->pcidev,
4600 ioc->dma_mask))
4601 d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4602 "restoring 64 bit addressing\n", ioc->name));
4603
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604 return 0;
4605
4606out_fail:
Kashyap, Desai2f187862009-05-29 16:52:37 +05304607
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 if (ioc->alloc != NULL) {
4609 sz = ioc->alloc_sz;
4610 pci_free_consistent(ioc->pcidev,
4611 sz,
4612 ioc->alloc, ioc->alloc_dma);
4613 ioc->reply_frames = NULL;
4614 ioc->req_frames = NULL;
4615 ioc->alloc_total -= sz;
4616 }
4617 if (ioc->sense_buf_pool != NULL) {
4618 sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
4619 pci_free_consistent(ioc->pcidev,
4620 sz,
4621 ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
4622 ioc->sense_buf_pool = NULL;
4623 }
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304624
Andrew Morton8e20ce92009-06-18 16:49:17 -07004625 if (dma_mask == DMA_BIT_MASK(35) && !pci_set_dma_mask(ioc->pcidev,
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05304626 DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(ioc->pcidev,
4627 DMA_BIT_MASK(64)))
4628 d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
4629 "restoring 64 bit addressing\n", ioc->name));
4630
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 return -1;
4632}
4633
4634/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
4635/**
4636 * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
4637 * from IOC via doorbell handshake method.
4638 * @ioc: Pointer to MPT_ADAPTER structure
4639 * @reqBytes: Size of the request in bytes
4640 * @req: Pointer to MPT request frame
4641 * @replyBytes: Expected size of the reply in bytes
4642 * @u16reply: Pointer to area where reply should be written
4643 * @maxwait: Max wait time for a reply (in seconds)
4644 * @sleepFlag: Specifies whether the process can sleep
4645 *
4646 * NOTES: It is the callers responsibility to byte-swap fields in the
4647 * request which are greater than 1 byte in size. It is also the
4648 * callers responsibility to byte-swap response fields which are
4649 * greater than 1 byte in size.
4650 *
4651 * Returns 0 for success, non-zero for failure.
4652 */
4653static int
4654mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
Christoph Hellwigc6678e02005-08-18 16:24:53 +02004655 int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656{
4657 MPIDefaultReply_t *mptReply;
4658 int failcnt = 0;
4659 int t;
4660
4661 /*
4662 * Get ready to cache a handshake reply
4663 */
4664 ioc->hs_reply_idx = 0;
4665 mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
4666 mptReply->MsgLength = 0;
4667
4668 /*
4669 * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
4670 * then tell IOC that we want to handshake a request of N words.
4671 * (WRITE u32val to Doorbell reg).
4672 */
4673 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
4674 CHIPREG_WRITE32(&ioc->chip->Doorbell,
4675 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
4676 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
4677
4678 /*
4679 * Wait for IOC's doorbell handshake int
4680 */
4681 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
4682 failcnt++;
4683
Prakash, Sathya436ace72007-07-24 15:42:08 +05304684 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685 ioc->name, reqBytes, t, failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
4686
4687 /* Read doorbell and check for active bit */
4688 if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
4689 return -1;
4690
4691 /*
4692 * Clear doorbell int (WRITE 0 to IntStatus reg),
4693 * then wait for IOC to ACKnowledge that it's ready for
4694 * our handshake request.
4695 */
4696 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
4697 if (!failcnt && (t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
4698 failcnt++;
4699
4700 if (!failcnt) {
4701 int ii;
4702 u8 *req_as_bytes = (u8 *) req;
4703
4704 /*
4705 * Stuff request words via doorbell handshake,
4706 * with ACK from IOC for each.
4707 */
4708 for (ii = 0; !failcnt && ii < reqBytes/4; ii++) {
4709 u32 word = ((req_as_bytes[(ii*4) + 0] << 0) |
4710 (req_as_bytes[(ii*4) + 1] << 8) |
4711 (req_as_bytes[(ii*4) + 2] << 16) |
4712 (req_as_bytes[(ii*4) + 3] << 24));
4713
4714 CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
4715 if ((t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
4716 failcnt++;
4717 }
4718
Prakash, Sathya436ace72007-07-24 15:42:08 +05304719 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handshake request frame (@%p) header\n", ioc->name, req));
Eric Moore29dd3602007-09-14 18:46:51 -06004720 DBG_DUMP_REQUEST_FRAME_HDR(ioc, (u32 *)req);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721
Prakash, Sathya436ace72007-07-24 15:42:08 +05304722 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HandShake request post done, WaitCnt=%d%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
4724
4725 /*
4726 * Wait for completion of doorbell handshake reply from the IOC
4727 */
4728 if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
4729 failcnt++;
Christoph Hellwigc6678e02005-08-18 16:24:53 +02004730
Prakash, Sathya436ace72007-07-24 15:42:08 +05304731 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HandShake reply count=%d%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732 ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
4733
4734 /*
4735 * Copy out the cached reply...
4736 */
4737 for (ii=0; ii < min(replyBytes/2,mptReply->MsgLength*2); ii++)
4738 u16reply[ii] = ioc->hs_reply[ii];
4739 } else {
4740 return -99;
4741 }
4742
4743 return -failcnt;
4744}
4745
4746/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08004747/**
4748 * WaitForDoorbellAck - Wait for IOC doorbell handshake acknowledge
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 * @ioc: Pointer to MPT_ADAPTER structure
4750 * @howlong: How long to wait (in seconds)
4751 * @sleepFlag: Specifies whether the process can sleep
4752 *
4753 * This routine waits (up to ~2 seconds max) for IOC doorbell
Randy Dunlapd9489fb2006-12-06 20:38:43 -08004754 * handshake ACKnowledge, indicated by the IOP_DOORBELL_STATUS
4755 * bit in its IntStatus register being clear.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756 *
4757 * Returns a negative value on failure, else wait loop count.
4758 */
4759static int
4760WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
4761{
4762 int cntdn;
4763 int count = 0;
4764 u32 intstat=0;
4765
Moore, Eric Dean466544d2005-09-14 18:09:10 -06004766 cntdn = 1000 * howlong;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767
4768 if (sleepFlag == CAN_SLEEP) {
4769 while (--cntdn) {
Eric Moore0ccdb002006-07-11 17:33:13 -06004770 msleep (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
4772 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
4773 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 count++;
4775 }
4776 } else {
4777 while (--cntdn) {
Eric Moorecd2c6192007-01-29 09:47:47 -07004778 udelay (1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
4780 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
4781 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782 count++;
4783 }
4784 }
4785
4786 if (cntdn) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05304787 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitForDoorbell ACK (count=%d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 ioc->name, count));
4789 return count;
4790 }
4791
4792 printk(MYIOC_s_ERR_FMT "Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
4793 ioc->name, count, intstat);
4794 return -1;
4795}
4796
4797/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08004798/**
4799 * WaitForDoorbellInt - Wait for IOC to set its doorbell interrupt bit
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 * @ioc: Pointer to MPT_ADAPTER structure
4801 * @howlong: How long to wait (in seconds)
4802 * @sleepFlag: Specifies whether the process can sleep
4803 *
Randy Dunlapd9489fb2006-12-06 20:38:43 -08004804 * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt
4805 * (MPI_HIS_DOORBELL_INTERRUPT) to be set in the IntStatus register.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806 *
4807 * Returns a negative value on failure, else wait loop count.
4808 */
4809static int
4810WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
4811{
4812 int cntdn;
4813 int count = 0;
4814 u32 intstat=0;
4815
Moore, Eric Dean466544d2005-09-14 18:09:10 -06004816 cntdn = 1000 * howlong;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817 if (sleepFlag == CAN_SLEEP) {
4818 while (--cntdn) {
4819 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
4820 if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
4821 break;
Michael Reedd6be06c2006-05-24 15:07:57 -05004822 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004823 count++;
4824 }
4825 } else {
4826 while (--cntdn) {
4827 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
4828 if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
4829 break;
Eric Moorecd2c6192007-01-29 09:47:47 -07004830 udelay (1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831 count++;
4832 }
4833 }
4834
4835 if (cntdn) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05304836 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitForDoorbell INT (cnt=%d) howlong=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837 ioc->name, count, howlong));
4838 return count;
4839 }
4840
4841 printk(MYIOC_s_ERR_FMT "Doorbell INT timeout (count=%d), IntStatus=%x!\n",
4842 ioc->name, count, intstat);
4843 return -1;
4844}
4845
4846/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08004847/**
4848 * WaitForDoorbellReply - Wait for and capture an IOC handshake reply.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849 * @ioc: Pointer to MPT_ADAPTER structure
4850 * @howlong: How long to wait (in seconds)
4851 * @sleepFlag: Specifies whether the process can sleep
4852 *
4853 * This routine polls the IOC for a handshake reply, 16 bits at a time.
4854 * Reply is cached to IOC private area large enough to hold a maximum
4855 * of 128 bytes of reply data.
4856 *
4857 * Returns a negative value on failure, else size of reply in WORDS.
4858 */
4859static int
4860WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
4861{
4862 int u16cnt = 0;
4863 int failcnt = 0;
4864 int t;
4865 u16 *hs_reply = ioc->hs_reply;
4866 volatile MPIDefaultReply_t *mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
4867 u16 hword;
4868
4869 hs_reply[0] = hs_reply[1] = hs_reply[7] = 0;
4870
4871 /*
4872 * Get first two u16's so we can look at IOC's intended reply MsgLength
4873 */
4874 u16cnt=0;
4875 if ((t = WaitForDoorbellInt(ioc, howlong, sleepFlag)) < 0) {
4876 failcnt++;
4877 } else {
4878 hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
4879 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
4880 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
4881 failcnt++;
4882 else {
4883 hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
4884 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
4885 }
4886 }
4887
Prakash, Sathya436ace72007-07-24 15:42:08 +05304888 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
Christoph Hellwigc6678e02005-08-18 16:24:53 +02004889 ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
4891
4892 /*
4893 * If no error (and IOC said MsgLength is > 0), piece together
4894 * reply 16 bits at a time.
4895 */
4896 for (u16cnt=2; !failcnt && u16cnt < (2 * mptReply->MsgLength); u16cnt++) {
4897 if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
4898 failcnt++;
4899 hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
4900 /* don't overflow our IOC hs_reply[] buffer! */
Julia Lawalldd7c34e2008-11-09 17:55:27 +01004901 if (u16cnt < ARRAY_SIZE(ioc->hs_reply))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902 hs_reply[u16cnt] = hword;
4903 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
4904 }
4905
4906 if (!failcnt && (t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
4907 failcnt++;
4908 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
4909
4910 if (failcnt) {
4911 printk(MYIOC_s_ERR_FMT "Handshake reply failure!\n",
4912 ioc->name);
4913 return -failcnt;
4914 }
4915#if 0
4916 else if (u16cnt != (2 * mptReply->MsgLength)) {
4917 return -101;
4918 }
4919 else if ((mptReply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
4920 return -102;
4921 }
4922#endif
4923
Prakash, Sathya436ace72007-07-24 15:42:08 +05304924 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got Handshake reply:\n", ioc->name));
Eric Moore29dd3602007-09-14 18:46:51 -06004925 DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mptReply);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926
Prakash, Sathya436ace72007-07-24 15:42:08 +05304927 dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928 ioc->name, t, u16cnt/2));
4929 return u16cnt/2;
4930}
4931
4932/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08004933/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004934 * GetLanConfigPages - Fetch LANConfig pages.
4935 * @ioc: Pointer to MPT_ADAPTER structure
4936 *
4937 * Return: 0 for success
4938 * -ENOMEM if no memory available
4939 * -EPERM if not allowed due to ISR context
4940 * -EAGAIN if no msg frames currently available
4941 * -EFAULT for non-successful reply or no reply (timeout)
4942 */
4943static int
4944GetLanConfigPages(MPT_ADAPTER *ioc)
4945{
4946 ConfigPageHeader_t hdr;
4947 CONFIGPARMS cfg;
4948 LANPage0_t *ppage0_alloc;
4949 dma_addr_t page0_dma;
4950 LANPage1_t *ppage1_alloc;
4951 dma_addr_t page1_dma;
4952 int rc = 0;
4953 int data_sz;
4954 int copy_sz;
4955
4956 /* Get LAN Page 0 header */
4957 hdr.PageVersion = 0;
4958 hdr.PageLength = 0;
4959 hdr.PageNumber = 0;
4960 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02004961 cfg.cfghdr.hdr = &hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962 cfg.physAddr = -1;
4963 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4964 cfg.dir = 0;
4965 cfg.pageAddr = 0;
4966 cfg.timeout = 0;
4967
4968 if ((rc = mpt_config(ioc, &cfg)) != 0)
4969 return rc;
4970
4971 if (hdr.PageLength > 0) {
4972 data_sz = hdr.PageLength * 4;
4973 ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
4974 rc = -ENOMEM;
4975 if (ppage0_alloc) {
4976 memset((u8 *)ppage0_alloc, 0, data_sz);
4977 cfg.physAddr = page0_dma;
4978 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4979
4980 if ((rc = mpt_config(ioc, &cfg)) == 0) {
4981 /* save the data */
4982 copy_sz = min_t(int, sizeof(LANPage0_t), data_sz);
4983 memcpy(&ioc->lan_cnfg_page0, ppage0_alloc, copy_sz);
4984
4985 }
4986
4987 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
4988
4989 /* FIXME!
4990 * Normalize endianness of structure data,
4991 * by byte-swapping all > 1 byte fields!
4992 */
4993
4994 }
4995
4996 if (rc)
4997 return rc;
4998 }
4999
5000 /* Get LAN Page 1 header */
5001 hdr.PageVersion = 0;
5002 hdr.PageLength = 0;
5003 hdr.PageNumber = 1;
5004 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02005005 cfg.cfghdr.hdr = &hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006 cfg.physAddr = -1;
5007 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5008 cfg.dir = 0;
5009 cfg.pageAddr = 0;
5010
5011 if ((rc = mpt_config(ioc, &cfg)) != 0)
5012 return rc;
5013
5014 if (hdr.PageLength == 0)
5015 return 0;
5016
5017 data_sz = hdr.PageLength * 4;
5018 rc = -ENOMEM;
5019 ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
5020 if (ppage1_alloc) {
5021 memset((u8 *)ppage1_alloc, 0, data_sz);
5022 cfg.physAddr = page1_dma;
5023 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5024
5025 if ((rc = mpt_config(ioc, &cfg)) == 0) {
5026 /* save the data */
5027 copy_sz = min_t(int, sizeof(LANPage1_t), data_sz);
5028 memcpy(&ioc->lan_cnfg_page1, ppage1_alloc, copy_sz);
5029 }
5030
5031 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
5032
5033 /* FIXME!
5034 * Normalize endianness of structure data,
5035 * by byte-swapping all > 1 byte fields!
5036 */
5037
5038 }
5039
5040 return rc;
5041}
5042
5043/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08005044/**
5045 * mptbase_sas_persist_operation - Perform operation on SAS Persistent Table
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02005046 * @ioc: Pointer to MPT_ADAPTER structure
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02005047 * @persist_opcode: see below
5048 *
5049 * MPI_SAS_OP_CLEAR_NOT_PRESENT - Free all persist TargetID mappings for
5050 * devices not currently present.
5051 * MPI_SAS_OP_CLEAR_ALL_PERSISTENT - Clear al persist TargetID mappings
5052 *
5053 * NOTE: Don't use not this function during interrupt time.
5054 *
Randy Dunlapd9489fb2006-12-06 20:38:43 -08005055 * Returns 0 for success, non-zero error
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02005056 */
5057
5058/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5059int
5060mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode)
5061{
5062 SasIoUnitControlRequest_t *sasIoUnitCntrReq;
5063 SasIoUnitControlReply_t *sasIoUnitCntrReply;
5064 MPT_FRAME_HDR *mf = NULL;
5065 MPIHeader_t *mpi_hdr;
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05305066 int ret = 0;
5067 unsigned long timeleft;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02005068
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05305069 mutex_lock(&ioc->mptbase_cmds.mutex);
5070
5071 /* init the internal cmd struct */
5072 memset(ioc->mptbase_cmds.reply, 0 , MPT_DEFAULT_FRAME_SIZE);
5073 INITIALIZE_MGMT_STATUS(ioc->mptbase_cmds.status)
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02005074
5075 /* insure garbage is not sent to fw */
5076 switch(persist_opcode) {
5077
5078 case MPI_SAS_OP_CLEAR_NOT_PRESENT:
5079 case MPI_SAS_OP_CLEAR_ALL_PERSISTENT:
5080 break;
5081
5082 default:
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05305083 ret = -1;
5084 goto out;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02005085 }
5086
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05305087 printk(KERN_DEBUG "%s: persist_opcode=%x\n",
5088 __func__, persist_opcode);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02005089
5090 /* Get a MF for this command.
5091 */
5092 if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05305093 printk(KERN_DEBUG "%s: no msg frames!\n", __func__);
5094 ret = -1;
5095 goto out;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02005096 }
5097
5098 mpi_hdr = (MPIHeader_t *) mf;
5099 sasIoUnitCntrReq = (SasIoUnitControlRequest_t *)mf;
5100 memset(sasIoUnitCntrReq,0,sizeof(SasIoUnitControlRequest_t));
5101 sasIoUnitCntrReq->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
5102 sasIoUnitCntrReq->MsgContext = mpi_hdr->MsgContext;
5103 sasIoUnitCntrReq->Operation = persist_opcode;
5104
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02005105 mpt_put_msg_frame(mpt_base_index, ioc, mf);
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05305106 timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done, 10*HZ);
5107 if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
5108 ret = -ETIME;
5109 printk(KERN_DEBUG "%s: failed\n", __func__);
5110 if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
5111 goto out;
5112 if (!timeleft) {
Kei Tokunaga97009a22010-06-22 19:01:51 +09005113 printk(MYIOC_s_WARN_FMT
5114 "Issuing Reset from %s!!, doorbell=0x%08x\n",
5115 ioc->name, __func__, mpt_GetIocState(ioc, 0));
Kashyap, Desaid0f698c2010-03-18 19:12:17 +05305116 mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05305117 mpt_free_msg_frame(ioc, mf);
5118 }
5119 goto out;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02005120 }
5121
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05305122 if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
5123 ret = -1;
5124 goto out;
5125 }
5126
5127 sasIoUnitCntrReply =
5128 (SasIoUnitControlReply_t *)ioc->mptbase_cmds.reply;
5129 if (le16_to_cpu(sasIoUnitCntrReply->IOCStatus) != MPI_IOCSTATUS_SUCCESS) {
5130 printk(KERN_DEBUG "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
5131 __func__, sasIoUnitCntrReply->IOCStatus,
5132 sasIoUnitCntrReply->IOCLogInfo);
5133 printk(KERN_DEBUG "%s: failed\n", __func__);
5134 ret = -1;
5135 } else
5136 printk(KERN_DEBUG "%s: success\n", __func__);
5137 out:
5138
5139 CLEAR_MGMT_STATUS(ioc->mptbase_cmds.status)
5140 mutex_unlock(&ioc->mptbase_cmds.mutex);
5141 return ret;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02005142}
5143
5144/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Moore, Ericece50912006-01-16 18:53:19 -07005145
5146static void
5147mptbase_raid_process_event_data(MPT_ADAPTER *ioc,
5148 MpiEventDataRaid_t * pRaidEventData)
5149{
5150 int volume;
5151 int reason;
5152 int disk;
5153 int status;
5154 int flags;
5155 int state;
5156
5157 volume = pRaidEventData->VolumeID;
5158 reason = pRaidEventData->ReasonCode;
5159 disk = pRaidEventData->PhysDiskNum;
5160 status = le32_to_cpu(pRaidEventData->SettingsStatus);
5161 flags = (status >> 0) & 0xff;
5162 state = (status >> 8) & 0xff;
5163
5164 if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) {
5165 return;
5166 }
5167
5168 if ((reason >= MPI_EVENT_RAID_RC_PHYSDISK_CREATED &&
5169 reason <= MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED) ||
5170 (reason == MPI_EVENT_RAID_RC_SMART_DATA)) {
Eric Mooreb506ade2007-01-29 09:45:37 -07005171 printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for PhysDisk %d id=%d\n",
5172 ioc->name, disk, volume);
Moore, Ericece50912006-01-16 18:53:19 -07005173 } else {
5174 printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for VolumeID %d\n",
5175 ioc->name, volume);
5176 }
5177
5178 switch(reason) {
5179 case MPI_EVENT_RAID_RC_VOLUME_CREATED:
5180 printk(MYIOC_s_INFO_FMT " volume has been created\n",
5181 ioc->name);
5182 break;
5183
5184 case MPI_EVENT_RAID_RC_VOLUME_DELETED:
5185
5186 printk(MYIOC_s_INFO_FMT " volume has been deleted\n",
5187 ioc->name);
5188 break;
5189
5190 case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED:
5191 printk(MYIOC_s_INFO_FMT " volume settings have been changed\n",
5192 ioc->name);
5193 break;
5194
5195 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
5196 printk(MYIOC_s_INFO_FMT " volume is now %s%s%s%s\n",
5197 ioc->name,
5198 state == MPI_RAIDVOL0_STATUS_STATE_OPTIMAL
5199 ? "optimal"
5200 : state == MPI_RAIDVOL0_STATUS_STATE_DEGRADED
5201 ? "degraded"
5202 : state == MPI_RAIDVOL0_STATUS_STATE_FAILED
5203 ? "failed"
5204 : "state unknown",
5205 flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED
5206 ? ", enabled" : "",
5207 flags & MPI_RAIDVOL0_STATUS_FLAG_QUIESCED
5208 ? ", quiesced" : "",
5209 flags & MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
5210 ? ", resync in progress" : "" );
5211 break;
5212
5213 case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED:
5214 printk(MYIOC_s_INFO_FMT " volume membership of PhysDisk %d has changed\n",
5215 ioc->name, disk);
5216 break;
5217
5218 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
5219 printk(MYIOC_s_INFO_FMT " PhysDisk has been created\n",
5220 ioc->name);
5221 break;
5222
5223 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
5224 printk(MYIOC_s_INFO_FMT " PhysDisk has been deleted\n",
5225 ioc->name);
5226 break;
5227
5228 case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED:
5229 printk(MYIOC_s_INFO_FMT " PhysDisk settings have been changed\n",
5230 ioc->name);
5231 break;
5232
5233 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
5234 printk(MYIOC_s_INFO_FMT " PhysDisk is now %s%s%s\n",
5235 ioc->name,
5236 state == MPI_PHYSDISK0_STATUS_ONLINE
5237 ? "online"
5238 : state == MPI_PHYSDISK0_STATUS_MISSING
5239 ? "missing"
5240 : state == MPI_PHYSDISK0_STATUS_NOT_COMPATIBLE
5241 ? "not compatible"
5242 : state == MPI_PHYSDISK0_STATUS_FAILED
5243 ? "failed"
5244 : state == MPI_PHYSDISK0_STATUS_INITIALIZING
5245 ? "initializing"
5246 : state == MPI_PHYSDISK0_STATUS_OFFLINE_REQUESTED
5247 ? "offline requested"
5248 : state == MPI_PHYSDISK0_STATUS_FAILED_REQUESTED
5249 ? "failed requested"
5250 : state == MPI_PHYSDISK0_STATUS_OTHER_OFFLINE
5251 ? "offline"
5252 : "state unknown",
5253 flags & MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC
5254 ? ", out of sync" : "",
5255 flags & MPI_PHYSDISK0_STATUS_FLAG_QUIESCED
5256 ? ", quiesced" : "" );
5257 break;
5258
5259 case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED:
5260 printk(MYIOC_s_INFO_FMT " Domain Validation needed for PhysDisk %d\n",
5261 ioc->name, disk);
5262 break;
5263
5264 case MPI_EVENT_RAID_RC_SMART_DATA:
5265 printk(MYIOC_s_INFO_FMT " SMART data received, ASC/ASCQ = %02xh/%02xh\n",
5266 ioc->name, pRaidEventData->ASC, pRaidEventData->ASCQ);
5267 break;
5268
5269 case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED:
5270 printk(MYIOC_s_INFO_FMT " replacement of PhysDisk %d has started\n",
5271 ioc->name, disk);
5272 break;
5273 }
5274}
5275
5276/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08005277/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005278 * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
5279 * @ioc: Pointer to MPT_ADAPTER structure
5280 *
5281 * Returns: 0 for success
5282 * -ENOMEM if no memory available
5283 * -EPERM if not allowed due to ISR context
5284 * -EAGAIN if no msg frames currently available
5285 * -EFAULT for non-successful reply or no reply (timeout)
5286 */
5287static int
5288GetIoUnitPage2(MPT_ADAPTER *ioc)
5289{
5290 ConfigPageHeader_t hdr;
5291 CONFIGPARMS cfg;
5292 IOUnitPage2_t *ppage_alloc;
5293 dma_addr_t page_dma;
5294 int data_sz;
5295 int rc;
5296
5297 /* Get the page header */
5298 hdr.PageVersion = 0;
5299 hdr.PageLength = 0;
5300 hdr.PageNumber = 2;
5301 hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02005302 cfg.cfghdr.hdr = &hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303 cfg.physAddr = -1;
5304 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5305 cfg.dir = 0;
5306 cfg.pageAddr = 0;
5307 cfg.timeout = 0;
5308
5309 if ((rc = mpt_config(ioc, &cfg)) != 0)
5310 return rc;
5311
5312 if (hdr.PageLength == 0)
5313 return 0;
5314
5315 /* Read the config page */
5316 data_sz = hdr.PageLength * 4;
5317 rc = -ENOMEM;
5318 ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
5319 if (ppage_alloc) {
5320 memset((u8 *)ppage_alloc, 0, data_sz);
5321 cfg.physAddr = page_dma;
5322 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5323
5324 /* If Good, save data */
5325 if ((rc = mpt_config(ioc, &cfg)) == 0)
5326 ioc->biosVersion = le32_to_cpu(ppage_alloc->BiosVersion);
5327
5328 pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage_alloc, page_dma);
5329 }
5330
5331 return rc;
5332}
5333
5334/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08005335/**
5336 * mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337 * @ioc: Pointer to a Adapter Strucutre
5338 * @portnum: IOC port number
5339 *
5340 * Return: -EFAULT if read of config page header fails
5341 * or if no nvram
5342 * If read of SCSI Port Page 0 fails,
5343 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
5344 * Adapter settings: async, narrow
5345 * Return 1
5346 * If read of SCSI Port Page 2 fails,
5347 * Adapter settings valid
5348 * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
5349 * Return 1
5350 * Else
5351 * Both valid
5352 * Return 0
5353 * CHECK - what type of locking mechanisms should be used????
5354 */
5355static int
5356mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
5357{
5358 u8 *pbuf;
5359 dma_addr_t buf_dma;
5360 CONFIGPARMS cfg;
5361 ConfigPageHeader_t header;
5362 int ii;
5363 int data, rc = 0;
5364
5365 /* Allocate memory
5366 */
5367 if (!ioc->spi_data.nvram) {
5368 int sz;
5369 u8 *mem;
5370 sz = MPT_MAX_SCSI_DEVICES * sizeof(int);
5371 mem = kmalloc(sz, GFP_ATOMIC);
5372 if (mem == NULL)
5373 return -EFAULT;
5374
5375 ioc->spi_data.nvram = (int *) mem;
5376
Prakash, Sathya436ace72007-07-24 15:42:08 +05305377 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SCSI device NVRAM settings @ %p, sz=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378 ioc->name, ioc->spi_data.nvram, sz));
5379 }
5380
5381 /* Invalidate NVRAM information
5382 */
5383 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
5384 ioc->spi_data.nvram[ii] = MPT_HOST_NVRAM_INVALID;
5385 }
5386
5387 /* Read SPP0 header, allocate memory, then read page.
5388 */
5389 header.PageVersion = 0;
5390 header.PageLength = 0;
5391 header.PageNumber = 0;
5392 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02005393 cfg.cfghdr.hdr = &header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394 cfg.physAddr = -1;
5395 cfg.pageAddr = portnum;
5396 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5397 cfg.dir = 0;
5398 cfg.timeout = 0; /* use default */
5399 if (mpt_config(ioc, &cfg) != 0)
5400 return -EFAULT;
5401
5402 if (header.PageLength > 0) {
5403 pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
5404 if (pbuf) {
5405 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5406 cfg.physAddr = buf_dma;
5407 if (mpt_config(ioc, &cfg) != 0) {
5408 ioc->spi_data.maxBusWidth = MPT_NARROW;
5409 ioc->spi_data.maxSyncOffset = 0;
5410 ioc->spi_data.minSyncFactor = MPT_ASYNC;
5411 ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
5412 rc = 1;
Prakash, Sathya436ace72007-07-24 15:42:08 +05305413 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5414 "Unable to read PortPage0 minSyncFactor=%x\n",
Christoph Hellwigc6678e02005-08-18 16:24:53 +02005415 ioc->name, ioc->spi_data.minSyncFactor));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005416 } else {
5417 /* Save the Port Page 0 data
5418 */
5419 SCSIPortPage0_t *pPP0 = (SCSIPortPage0_t *) pbuf;
5420 pPP0->Capabilities = le32_to_cpu(pPP0->Capabilities);
5421 pPP0->PhysicalInterface = le32_to_cpu(pPP0->PhysicalInterface);
5422
5423 if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
5424 ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
Eric Moore29dd3602007-09-14 18:46:51 -06005425 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5426 "noQas due to Capabilities=%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07005427 ioc->name, pPP0->Capabilities));
5428 }
5429 ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
5430 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK;
5431 if (data) {
5432 ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
5433 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
5434 ioc->spi_data.minSyncFactor = (u8) (data >> 8);
Prakash, Sathya436ace72007-07-24 15:42:08 +05305435 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5436 "PortPage0 minSyncFactor=%x\n",
Christoph Hellwigc6678e02005-08-18 16:24:53 +02005437 ioc->name, ioc->spi_data.minSyncFactor));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438 } else {
5439 ioc->spi_data.maxSyncOffset = 0;
5440 ioc->spi_data.minSyncFactor = MPT_ASYNC;
5441 }
5442
5443 ioc->spi_data.busType = pPP0->PhysicalInterface & MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK;
5444
5445 /* Update the minSyncFactor based on bus type.
5446 */
5447 if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
5448 (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
5449
Christoph Hellwigc6678e02005-08-18 16:24:53 +02005450 if (ioc->spi_data.minSyncFactor < MPT_ULTRA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005451 ioc->spi_data.minSyncFactor = MPT_ULTRA;
Prakash, Sathya436ace72007-07-24 15:42:08 +05305452 ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
5453 "HVD or SE detected, minSyncFactor=%x\n",
Christoph Hellwigc6678e02005-08-18 16:24:53 +02005454 ioc->name, ioc->spi_data.minSyncFactor));
5455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005456 }
5457 }
5458 if (pbuf) {
5459 pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
5460 }
5461 }
5462 }
5463
5464 /* SCSI Port Page 2 - Read the header then the page.
5465 */
5466 header.PageVersion = 0;
5467 header.PageLength = 0;
5468 header.PageNumber = 2;
5469 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02005470 cfg.cfghdr.hdr = &header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471 cfg.physAddr = -1;
5472 cfg.pageAddr = portnum;
5473 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5474 cfg.dir = 0;
5475 if (mpt_config(ioc, &cfg) != 0)
5476 return -EFAULT;
5477
5478 if (header.PageLength > 0) {
5479 /* Allocate memory and read SCSI Port Page 2
5480 */
5481 pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
5482 if (pbuf) {
5483 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_NVRAM;
5484 cfg.physAddr = buf_dma;
5485 if (mpt_config(ioc, &cfg) != 0) {
5486 /* Nvram data is left with INVALID mark
5487 */
5488 rc = 1;
Eric Moore232f08f2007-08-14 17:28:27 -06005489 } else if (ioc->pcidev->vendor == PCI_VENDOR_ID_ATTO) {
5490
5491 /* This is an ATTO adapter, read Page2 accordingly
5492 */
5493 ATTO_SCSIPortPage2_t *pPP2 = (ATTO_SCSIPortPage2_t *) pbuf;
5494 ATTODeviceInfo_t *pdevice = NULL;
5495 u16 ATTOFlags;
5496
5497 /* Save the Port Page 2 data
5498 * (reformat into a 32bit quantity)
5499 */
5500 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
5501 pdevice = &pPP2->DeviceSettings[ii];
5502 ATTOFlags = le16_to_cpu(pdevice->ATTOFlags);
5503 data = 0;
5504
5505 /* Translate ATTO device flags to LSI format
5506 */
5507 if (ATTOFlags & ATTOFLAG_DISC)
5508 data |= (MPI_SCSIPORTPAGE2_DEVICE_DISCONNECT_ENABLE);
5509 if (ATTOFlags & ATTOFLAG_ID_ENB)
5510 data |= (MPI_SCSIPORTPAGE2_DEVICE_ID_SCAN_ENABLE);
5511 if (ATTOFlags & ATTOFLAG_LUN_ENB)
5512 data |= (MPI_SCSIPORTPAGE2_DEVICE_LUN_SCAN_ENABLE);
5513 if (ATTOFlags & ATTOFLAG_TAGGED)
5514 data |= (MPI_SCSIPORTPAGE2_DEVICE_TAG_QUEUE_ENABLE);
5515 if (!(ATTOFlags & ATTOFLAG_WIDE_ENB))
5516 data |= (MPI_SCSIPORTPAGE2_DEVICE_WIDE_DISABLE);
5517
5518 data = (data << 16) | (pdevice->Period << 8) | 10;
5519 ioc->spi_data.nvram[ii] = data;
5520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005521 } else {
5522 SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t *) pbuf;
5523 MpiDeviceInfo_t *pdevice = NULL;
5524
Moore, Ericd8e925d2006-01-16 18:53:06 -07005525 /*
5526 * Save "Set to Avoid SCSI Bus Resets" flag
5527 */
5528 ioc->spi_data.bus_reset =
5529 (le32_to_cpu(pPP2->PortFlags) &
5530 MPI_SCSIPORTPAGE2_PORT_FLAGS_AVOID_SCSI_RESET) ?
5531 0 : 1 ;
5532
Linus Torvalds1da177e2005-04-16 15:20:36 -07005533 /* Save the Port Page 2 data
5534 * (reformat into a 32bit quantity)
5535 */
5536 data = le32_to_cpu(pPP2->PortFlags) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
5537 ioc->spi_data.PortFlags = data;
5538 for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
5539 pdevice = &pPP2->DeviceSettings[ii];
5540 data = (le16_to_cpu(pdevice->DeviceFlags) << 16) |
5541 (pdevice->SyncFactor << 8) | pdevice->Timeout;
5542 ioc->spi_data.nvram[ii] = data;
5543 }
5544 }
5545
5546 pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
5547 }
5548 }
5549
5550 /* Update Adapter limits with those from NVRAM
5551 * Comment: Don't need to do this. Target performance
5552 * parameters will never exceed the adapters limits.
5553 */
5554
5555 return rc;
5556}
5557
5558/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08005559/**
5560 * mpt_readScsiDevicePageHeaders - save version and length of SDP1
Linus Torvalds1da177e2005-04-16 15:20:36 -07005561 * @ioc: Pointer to a Adapter Strucutre
5562 * @portnum: IOC port number
5563 *
5564 * Return: -EFAULT if read of config page header fails
5565 * or 0 if success.
5566 */
5567static int
5568mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
5569{
5570 CONFIGPARMS cfg;
5571 ConfigPageHeader_t header;
5572
5573 /* Read the SCSI Device Page 1 header
5574 */
5575 header.PageVersion = 0;
5576 header.PageLength = 0;
5577 header.PageNumber = 1;
5578 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02005579 cfg.cfghdr.hdr = &header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005580 cfg.physAddr = -1;
5581 cfg.pageAddr = portnum;
5582 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5583 cfg.dir = 0;
5584 cfg.timeout = 0;
5585 if (mpt_config(ioc, &cfg) != 0)
5586 return -EFAULT;
5587
Christoph Hellwig69218ee2005-08-18 16:26:15 +02005588 ioc->spi_data.sdp1version = cfg.cfghdr.hdr->PageVersion;
5589 ioc->spi_data.sdp1length = cfg.cfghdr.hdr->PageLength;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005590
5591 header.PageVersion = 0;
5592 header.PageLength = 0;
5593 header.PageNumber = 0;
5594 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
5595 if (mpt_config(ioc, &cfg) != 0)
5596 return -EFAULT;
5597
Christoph Hellwig69218ee2005-08-18 16:26:15 +02005598 ioc->spi_data.sdp0version = cfg.cfghdr.hdr->PageVersion;
5599 ioc->spi_data.sdp0length = cfg.cfghdr.hdr->PageLength;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005600
Prakash, Sathya436ace72007-07-24 15:42:08 +05305601 dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Headers: 0: version %d length %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07005602 ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
5603
Prakash, Sathya436ace72007-07-24 15:42:08 +05305604 dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Headers: 1: version %d length %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605 ioc->name, ioc->spi_data.sdp1version, ioc->spi_data.sdp1length));
5606 return 0;
5607}
5608
Eric Mooreb506ade2007-01-29 09:45:37 -07005609/**
Randy Dunlap1544d672007-02-20 11:17:03 -08005610 * mpt_inactive_raid_list_free - This clears this link list.
5611 * @ioc : pointer to per adapter structure
Eric Mooreb506ade2007-01-29 09:45:37 -07005612 **/
5613static void
5614mpt_inactive_raid_list_free(MPT_ADAPTER *ioc)
5615{
5616 struct inactive_raid_component_info *component_info, *pNext;
5617
5618 if (list_empty(&ioc->raid_data.inactive_list))
5619 return;
5620
Matthias Kaehlckeed5f6062008-03-09 12:16:27 +01005621 mutex_lock(&ioc->raid_data.inactive_list_mutex);
Eric Mooreb506ade2007-01-29 09:45:37 -07005622 list_for_each_entry_safe(component_info, pNext,
5623 &ioc->raid_data.inactive_list, list) {
5624 list_del(&component_info->list);
5625 kfree(component_info);
5626 }
Matthias Kaehlckeed5f6062008-03-09 12:16:27 +01005627 mutex_unlock(&ioc->raid_data.inactive_list_mutex);
Eric Mooreb506ade2007-01-29 09:45:37 -07005628}
5629
5630/**
Randy Dunlap1544d672007-02-20 11:17:03 -08005631 * mpt_inactive_raid_volumes - sets up link list of phy_disk_nums for devices belonging in an inactive volume
Eric Mooreb506ade2007-01-29 09:45:37 -07005632 *
Randy Dunlap1544d672007-02-20 11:17:03 -08005633 * @ioc : pointer to per adapter structure
5634 * @channel : volume channel
5635 * @id : volume target id
Eric Mooreb506ade2007-01-29 09:45:37 -07005636 **/
5637static void
5638mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id)
5639{
5640 CONFIGPARMS cfg;
5641 ConfigPageHeader_t hdr;
5642 dma_addr_t dma_handle;
5643 pRaidVolumePage0_t buffer = NULL;
5644 int i;
5645 RaidPhysDiskPage0_t phys_disk;
5646 struct inactive_raid_component_info *component_info;
5647 int handle_inactive_volumes;
5648
5649 memset(&cfg, 0 , sizeof(CONFIGPARMS));
5650 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
5651 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
5652 cfg.pageAddr = (channel << 8) + id;
5653 cfg.cfghdr.hdr = &hdr;
5654 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5655
5656 if (mpt_config(ioc, &cfg) != 0)
5657 goto out;
5658
5659 if (!hdr.PageLength)
5660 goto out;
5661
5662 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
5663 &dma_handle);
5664
5665 if (!buffer)
5666 goto out;
5667
5668 cfg.physAddr = dma_handle;
5669 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5670
5671 if (mpt_config(ioc, &cfg) != 0)
5672 goto out;
5673
5674 if (!buffer->NumPhysDisks)
5675 goto out;
5676
5677 handle_inactive_volumes =
5678 (buffer->VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE ||
5679 (buffer->VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED) == 0 ||
5680 buffer->VolumeStatus.State == MPI_RAIDVOL0_STATUS_STATE_FAILED ||
5681 buffer->VolumeStatus.State == MPI_RAIDVOL0_STATUS_STATE_MISSING) ? 1 : 0;
5682
5683 if (!handle_inactive_volumes)
5684 goto out;
5685
Matthias Kaehlckeed5f6062008-03-09 12:16:27 +01005686 mutex_lock(&ioc->raid_data.inactive_list_mutex);
Eric Mooreb506ade2007-01-29 09:45:37 -07005687 for (i = 0; i < buffer->NumPhysDisks; i++) {
5688 if(mpt_raid_phys_disk_pg0(ioc,
5689 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
5690 continue;
5691
5692 if ((component_info = kmalloc(sizeof (*component_info),
5693 GFP_KERNEL)) == NULL)
5694 continue;
5695
5696 component_info->volumeID = id;
5697 component_info->volumeBus = channel;
5698 component_info->d.PhysDiskNum = phys_disk.PhysDiskNum;
5699 component_info->d.PhysDiskBus = phys_disk.PhysDiskBus;
5700 component_info->d.PhysDiskID = phys_disk.PhysDiskID;
5701 component_info->d.PhysDiskIOC = phys_disk.PhysDiskIOC;
5702
5703 list_add_tail(&component_info->list,
5704 &ioc->raid_data.inactive_list);
5705 }
Matthias Kaehlckeed5f6062008-03-09 12:16:27 +01005706 mutex_unlock(&ioc->raid_data.inactive_list_mutex);
Eric Mooreb506ade2007-01-29 09:45:37 -07005707
5708 out:
5709 if (buffer)
5710 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
5711 dma_handle);
5712}
5713
5714/**
5715 * mpt_raid_phys_disk_pg0 - returns phys disk page zero
5716 * @ioc: Pointer to a Adapter Structure
5717 * @phys_disk_num: io unit unique phys disk num generated by the ioc
5718 * @phys_disk: requested payload data returned
5719 *
5720 * Return:
5721 * 0 on success
5722 * -EFAULT if read of config page header fails or data pointer not NULL
5723 * -ENOMEM if pci_alloc failed
5724 **/
5725int
Kashyap, Desai2f187862009-05-29 16:52:37 +05305726mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num,
5727 RaidPhysDiskPage0_t *phys_disk)
Eric Mooreb506ade2007-01-29 09:45:37 -07005728{
Kashyap, Desai2f187862009-05-29 16:52:37 +05305729 CONFIGPARMS cfg;
5730 ConfigPageHeader_t hdr;
Eric Mooreb506ade2007-01-29 09:45:37 -07005731 dma_addr_t dma_handle;
5732 pRaidPhysDiskPage0_t buffer = NULL;
5733 int rc;
5734
5735 memset(&cfg, 0 , sizeof(CONFIGPARMS));
5736 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
Kashyap, Desai2f187862009-05-29 16:52:37 +05305737 memset(phys_disk, 0, sizeof(RaidPhysDiskPage0_t));
Eric Mooreb506ade2007-01-29 09:45:37 -07005738
Kashyap, Desai2f187862009-05-29 16:52:37 +05305739 hdr.PageVersion = MPI_RAIDPHYSDISKPAGE0_PAGEVERSION;
Eric Mooreb506ade2007-01-29 09:45:37 -07005740 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
5741 cfg.cfghdr.hdr = &hdr;
5742 cfg.physAddr = -1;
5743 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5744
5745 if (mpt_config(ioc, &cfg) != 0) {
5746 rc = -EFAULT;
5747 goto out;
5748 }
5749
5750 if (!hdr.PageLength) {
5751 rc = -EFAULT;
5752 goto out;
5753 }
5754
5755 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
5756 &dma_handle);
5757
5758 if (!buffer) {
5759 rc = -ENOMEM;
5760 goto out;
5761 }
5762
5763 cfg.physAddr = dma_handle;
5764 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5765 cfg.pageAddr = phys_disk_num;
5766
5767 if (mpt_config(ioc, &cfg) != 0) {
5768 rc = -EFAULT;
5769 goto out;
5770 }
5771
5772 rc = 0;
5773 memcpy(phys_disk, buffer, sizeof(*buffer));
5774 phys_disk->MaxLBA = le32_to_cpu(buffer->MaxLBA);
5775
5776 out:
5777
5778 if (buffer)
5779 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
5780 dma_handle);
5781
5782 return rc;
5783}
5784
Linus Torvalds1da177e2005-04-16 15:20:36 -07005785/**
Kashyap, Desaia7938b02009-05-29 16:53:56 +05305786 * mpt_raid_phys_disk_get_num_paths - returns number paths associated to this phys_num
5787 * @ioc: Pointer to a Adapter Structure
5788 * @phys_disk_num: io unit unique phys disk num generated by the ioc
5789 *
5790 * Return:
5791 * returns number paths
5792 **/
5793int
5794mpt_raid_phys_disk_get_num_paths(MPT_ADAPTER *ioc, u8 phys_disk_num)
5795{
5796 CONFIGPARMS cfg;
5797 ConfigPageHeader_t hdr;
5798 dma_addr_t dma_handle;
5799 pRaidPhysDiskPage1_t buffer = NULL;
5800 int rc;
5801
5802 memset(&cfg, 0 , sizeof(CONFIGPARMS));
5803 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
5804
5805 hdr.PageVersion = MPI_RAIDPHYSDISKPAGE1_PAGEVERSION;
5806 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
5807 hdr.PageNumber = 1;
5808 cfg.cfghdr.hdr = &hdr;
5809 cfg.physAddr = -1;
5810 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5811
5812 if (mpt_config(ioc, &cfg) != 0) {
5813 rc = 0;
5814 goto out;
5815 }
5816
5817 if (!hdr.PageLength) {
5818 rc = 0;
5819 goto out;
5820 }
5821
5822 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
5823 &dma_handle);
5824
5825 if (!buffer) {
5826 rc = 0;
5827 goto out;
5828 }
5829
5830 cfg.physAddr = dma_handle;
5831 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5832 cfg.pageAddr = phys_disk_num;
5833
5834 if (mpt_config(ioc, &cfg) != 0) {
5835 rc = 0;
5836 goto out;
5837 }
5838
5839 rc = buffer->NumPhysDiskPaths;
5840 out:
5841
5842 if (buffer)
5843 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
5844 dma_handle);
5845
5846 return rc;
5847}
5848EXPORT_SYMBOL(mpt_raid_phys_disk_get_num_paths);
5849
5850/**
5851 * mpt_raid_phys_disk_pg1 - returns phys disk page 1
5852 * @ioc: Pointer to a Adapter Structure
5853 * @phys_disk_num: io unit unique phys disk num generated by the ioc
5854 * @phys_disk: requested payload data returned
5855 *
5856 * Return:
5857 * 0 on success
5858 * -EFAULT if read of config page header fails or data pointer not NULL
5859 * -ENOMEM if pci_alloc failed
5860 **/
5861int
5862mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc, u8 phys_disk_num,
5863 RaidPhysDiskPage1_t *phys_disk)
5864{
5865 CONFIGPARMS cfg;
5866 ConfigPageHeader_t hdr;
5867 dma_addr_t dma_handle;
5868 pRaidPhysDiskPage1_t buffer = NULL;
5869 int rc;
5870 int i;
5871 __le64 sas_address;
5872
5873 memset(&cfg, 0 , sizeof(CONFIGPARMS));
5874 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
5875 rc = 0;
5876
5877 hdr.PageVersion = MPI_RAIDPHYSDISKPAGE1_PAGEVERSION;
5878 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
5879 hdr.PageNumber = 1;
5880 cfg.cfghdr.hdr = &hdr;
5881 cfg.physAddr = -1;
5882 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5883
5884 if (mpt_config(ioc, &cfg) != 0) {
5885 rc = -EFAULT;
5886 goto out;
5887 }
5888
5889 if (!hdr.PageLength) {
5890 rc = -EFAULT;
5891 goto out;
5892 }
5893
5894 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
5895 &dma_handle);
5896
5897 if (!buffer) {
5898 rc = -ENOMEM;
5899 goto out;
5900 }
5901
5902 cfg.physAddr = dma_handle;
5903 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5904 cfg.pageAddr = phys_disk_num;
5905
5906 if (mpt_config(ioc, &cfg) != 0) {
5907 rc = -EFAULT;
5908 goto out;
5909 }
5910
5911 phys_disk->NumPhysDiskPaths = buffer->NumPhysDiskPaths;
5912 phys_disk->PhysDiskNum = phys_disk_num;
5913 for (i = 0; i < phys_disk->NumPhysDiskPaths; i++) {
5914 phys_disk->Path[i].PhysDiskID = buffer->Path[i].PhysDiskID;
5915 phys_disk->Path[i].PhysDiskBus = buffer->Path[i].PhysDiskBus;
5916 phys_disk->Path[i].OwnerIdentifier =
5917 buffer->Path[i].OwnerIdentifier;
5918 phys_disk->Path[i].Flags = le16_to_cpu(buffer->Path[i].Flags);
5919 memcpy(&sas_address, &buffer->Path[i].WWID, sizeof(__le64));
5920 sas_address = le64_to_cpu(sas_address);
5921 memcpy(&phys_disk->Path[i].WWID, &sas_address, sizeof(__le64));
5922 memcpy(&sas_address,
5923 &buffer->Path[i].OwnerWWID, sizeof(__le64));
5924 sas_address = le64_to_cpu(sas_address);
5925 memcpy(&phys_disk->Path[i].OwnerWWID,
5926 &sas_address, sizeof(__le64));
5927 }
5928
5929 out:
5930
5931 if (buffer)
5932 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
5933 dma_handle);
5934
5935 return rc;
5936}
5937EXPORT_SYMBOL(mpt_raid_phys_disk_pg1);
5938
5939
5940/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005941 * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
5942 * @ioc: Pointer to a Adapter Strucutre
Linus Torvalds1da177e2005-04-16 15:20:36 -07005943 *
5944 * Return:
5945 * 0 on success
5946 * -EFAULT if read of config page header fails or data pointer not NULL
5947 * -ENOMEM if pci_alloc failed
Eric Mooreb506ade2007-01-29 09:45:37 -07005948 **/
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949int
5950mpt_findImVolumes(MPT_ADAPTER *ioc)
5951{
5952 IOCPage2_t *pIoc2;
5953 u8 *mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954 dma_addr_t ioc2_dma;
5955 CONFIGPARMS cfg;
5956 ConfigPageHeader_t header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005957 int rc = 0;
5958 int iocpage2sz;
Eric Mooreb506ade2007-01-29 09:45:37 -07005959 int i;
5960
5961 if (!ioc->ir_firmware)
5962 return 0;
5963
5964 /* Free the old page
5965 */
5966 kfree(ioc->raid_data.pIocPg2);
5967 ioc->raid_data.pIocPg2 = NULL;
5968 mpt_inactive_raid_list_free(ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969
5970 /* Read IOCP2 header then the page.
5971 */
5972 header.PageVersion = 0;
5973 header.PageLength = 0;
5974 header.PageNumber = 2;
5975 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02005976 cfg.cfghdr.hdr = &header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005977 cfg.physAddr = -1;
5978 cfg.pageAddr = 0;
5979 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
5980 cfg.dir = 0;
5981 cfg.timeout = 0;
5982 if (mpt_config(ioc, &cfg) != 0)
5983 return -EFAULT;
5984
5985 if (header.PageLength == 0)
5986 return -EFAULT;
5987
5988 iocpage2sz = header.PageLength * 4;
5989 pIoc2 = pci_alloc_consistent(ioc->pcidev, iocpage2sz, &ioc2_dma);
5990 if (!pIoc2)
5991 return -ENOMEM;
5992
5993 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
5994 cfg.physAddr = ioc2_dma;
5995 if (mpt_config(ioc, &cfg) != 0)
Eric Mooreb506ade2007-01-29 09:45:37 -07005996 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997
Eric Mooreb506ade2007-01-29 09:45:37 -07005998 mem = kmalloc(iocpage2sz, GFP_KERNEL);
Julia Lawall1c1acab2010-08-11 12:11:24 +02005999 if (!mem) {
6000 rc = -ENOMEM;
Eric Mooreb506ade2007-01-29 09:45:37 -07006001 goto out;
Julia Lawall1c1acab2010-08-11 12:11:24 +02006002 }
Eric Mooreb506ade2007-01-29 09:45:37 -07006003
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004 memcpy(mem, (u8 *)pIoc2, iocpage2sz);
Eric Mooreb506ade2007-01-29 09:45:37 -07006005 ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006006
Eric Mooreb506ade2007-01-29 09:45:37 -07006007 mpt_read_ioc_pg_3(ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008
Eric Mooreb506ade2007-01-29 09:45:37 -07006009 for (i = 0; i < pIoc2->NumActiveVolumes ; i++)
6010 mpt_inactive_raid_volumes(ioc,
6011 pIoc2->RaidVolume[i].VolumeBus,
6012 pIoc2->RaidVolume[i].VolumeID);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013
Eric Mooreb506ade2007-01-29 09:45:37 -07006014 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015 pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
6016
6017 return rc;
6018}
6019
Moore, Ericc972c702006-03-14 09:14:06 -07006020static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
6022{
6023 IOCPage3_t *pIoc3;
6024 u8 *mem;
6025 CONFIGPARMS cfg;
6026 ConfigPageHeader_t header;
6027 dma_addr_t ioc3_dma;
6028 int iocpage3sz = 0;
6029
6030 /* Free the old page
6031 */
Moore, Eric Dean466544d2005-09-14 18:09:10 -06006032 kfree(ioc->raid_data.pIocPg3);
6033 ioc->raid_data.pIocPg3 = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034
6035 /* There is at least one physical disk.
6036 * Read and save IOC Page 3
6037 */
6038 header.PageVersion = 0;
6039 header.PageLength = 0;
6040 header.PageNumber = 3;
6041 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006042 cfg.cfghdr.hdr = &header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043 cfg.physAddr = -1;
6044 cfg.pageAddr = 0;
6045 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
6046 cfg.dir = 0;
6047 cfg.timeout = 0;
6048 if (mpt_config(ioc, &cfg) != 0)
6049 return 0;
6050
6051 if (header.PageLength == 0)
6052 return 0;
6053
6054 /* Read Header good, alloc memory
6055 */
6056 iocpage3sz = header.PageLength * 4;
6057 pIoc3 = pci_alloc_consistent(ioc->pcidev, iocpage3sz, &ioc3_dma);
6058 if (!pIoc3)
6059 return 0;
6060
6061 /* Read the Page and save the data
6062 * into malloc'd memory.
6063 */
6064 cfg.physAddr = ioc3_dma;
6065 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
6066 if (mpt_config(ioc, &cfg) == 0) {
Eric Mooreb506ade2007-01-29 09:45:37 -07006067 mem = kmalloc(iocpage3sz, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006068 if (mem) {
6069 memcpy(mem, (u8 *)pIoc3, iocpage3sz);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06006070 ioc->raid_data.pIocPg3 = (IOCPage3_t *) mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071 }
6072 }
6073
6074 pci_free_consistent(ioc->pcidev, iocpage3sz, pIoc3, ioc3_dma);
6075
6076 return 0;
6077}
6078
6079static void
6080mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
6081{
6082 IOCPage4_t *pIoc4;
6083 CONFIGPARMS cfg;
6084 ConfigPageHeader_t header;
6085 dma_addr_t ioc4_dma;
6086 int iocpage4sz;
6087
6088 /* Read and save IOC Page 4
6089 */
6090 header.PageVersion = 0;
6091 header.PageLength = 0;
6092 header.PageNumber = 4;
6093 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006094 cfg.cfghdr.hdr = &header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095 cfg.physAddr = -1;
6096 cfg.pageAddr = 0;
6097 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
6098 cfg.dir = 0;
6099 cfg.timeout = 0;
6100 if (mpt_config(ioc, &cfg) != 0)
6101 return;
6102
6103 if (header.PageLength == 0)
6104 return;
6105
6106 if ( (pIoc4 = ioc->spi_data.pIocPg4) == NULL ) {
6107 iocpage4sz = (header.PageLength + 4) * 4; /* Allow 4 additional SEP's */
6108 pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
6109 if (!pIoc4)
6110 return;
Eric Moore0ccdb002006-07-11 17:33:13 -06006111 ioc->alloc_total += iocpage4sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006112 } else {
6113 ioc4_dma = ioc->spi_data.IocPg4_dma;
6114 iocpage4sz = ioc->spi_data.IocPg4Sz;
6115 }
6116
6117 /* Read the Page into dma memory.
6118 */
6119 cfg.physAddr = ioc4_dma;
6120 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
6121 if (mpt_config(ioc, &cfg) == 0) {
6122 ioc->spi_data.pIocPg4 = (IOCPage4_t *) pIoc4;
6123 ioc->spi_data.IocPg4_dma = ioc4_dma;
6124 ioc->spi_data.IocPg4Sz = iocpage4sz;
6125 } else {
6126 pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
6127 ioc->spi_data.pIocPg4 = NULL;
Eric Moore0ccdb002006-07-11 17:33:13 -06006128 ioc->alloc_total -= iocpage4sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129 }
6130}
6131
6132static void
6133mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
6134{
6135 IOCPage1_t *pIoc1;
6136 CONFIGPARMS cfg;
6137 ConfigPageHeader_t header;
6138 dma_addr_t ioc1_dma;
6139 int iocpage1sz = 0;
6140 u32 tmp;
6141
6142 /* Check the Coalescing Timeout in IOC Page 1
6143 */
6144 header.PageVersion = 0;
6145 header.PageLength = 0;
6146 header.PageNumber = 1;
6147 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006148 cfg.cfghdr.hdr = &header;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006149 cfg.physAddr = -1;
6150 cfg.pageAddr = 0;
6151 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
6152 cfg.dir = 0;
6153 cfg.timeout = 0;
6154 if (mpt_config(ioc, &cfg) != 0)
6155 return;
6156
6157 if (header.PageLength == 0)
6158 return;
6159
6160 /* Read Header good, alloc memory
6161 */
6162 iocpage1sz = header.PageLength * 4;
6163 pIoc1 = pci_alloc_consistent(ioc->pcidev, iocpage1sz, &ioc1_dma);
6164 if (!pIoc1)
6165 return;
6166
6167 /* Read the Page and check coalescing timeout
6168 */
6169 cfg.physAddr = ioc1_dma;
6170 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
6171 if (mpt_config(ioc, &cfg) == 0) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05306172
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173 tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
6174 if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
6175 tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
6176
Prakash, Sathya436ace72007-07-24 15:42:08 +05306177 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Coalescing Enabled Timeout = %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178 ioc->name, tmp));
6179
6180 if (tmp > MPT_COALESCING_TIMEOUT) {
6181 pIoc1->CoalescingTimeout = cpu_to_le32(MPT_COALESCING_TIMEOUT);
6182
6183 /* Write NVRAM and current
6184 */
6185 cfg.dir = 1;
6186 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
6187 if (mpt_config(ioc, &cfg) == 0) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05306188 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Reset Current Coalescing Timeout to = %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189 ioc->name, MPT_COALESCING_TIMEOUT));
6190
6191 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
6192 if (mpt_config(ioc, &cfg) == 0) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05306193 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
6194 "Reset NVRAM Coalescing Timeout to = %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195 ioc->name, MPT_COALESCING_TIMEOUT));
6196 } else {
Prakash, Sathya436ace72007-07-24 15:42:08 +05306197 dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
6198 "Reset NVRAM Coalescing Timeout Failed\n",
6199 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200 }
6201
6202 } else {
Prakash, Sathya436ace72007-07-24 15:42:08 +05306203 dprintk(ioc, printk(MYIOC_s_WARN_FMT
6204 "Reset of Current Coalescing Timeout Failed!\n",
6205 ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 }
6207 }
6208
6209 } else {
Prakash, Sathya436ace72007-07-24 15:42:08 +05306210 dprintk(ioc, printk(MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211 }
6212 }
6213
6214 pci_free_consistent(ioc->pcidev, iocpage1sz, pIoc1, ioc1_dma);
6215
6216 return;
6217}
6218
Prakash, Sathyaedb90682007-07-17 14:39:14 +05306219static void
6220mpt_get_manufacturing_pg_0(MPT_ADAPTER *ioc)
6221{
6222 CONFIGPARMS cfg;
6223 ConfigPageHeader_t hdr;
6224 dma_addr_t buf_dma;
6225 ManufacturingPage0_t *pbuf = NULL;
6226
6227 memset(&cfg, 0 , sizeof(CONFIGPARMS));
6228 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
6229
6230 hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
6231 cfg.cfghdr.hdr = &hdr;
6232 cfg.physAddr = -1;
6233 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
6234 cfg.timeout = 10;
6235
6236 if (mpt_config(ioc, &cfg) != 0)
6237 goto out;
6238
6239 if (!cfg.cfghdr.hdr->PageLength)
6240 goto out;
6241
6242 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
6243 pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
6244 if (!pbuf)
6245 goto out;
6246
6247 cfg.physAddr = buf_dma;
6248
6249 if (mpt_config(ioc, &cfg) != 0)
6250 goto out;
6251
6252 memcpy(ioc->board_name, pbuf->BoardName, sizeof(ioc->board_name));
6253 memcpy(ioc->board_assembly, pbuf->BoardAssembly, sizeof(ioc->board_assembly));
6254 memcpy(ioc->board_tracer, pbuf->BoardTracerNumber, sizeof(ioc->board_tracer));
6255
6256 out:
6257
6258 if (pbuf)
6259 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
6260}
6261
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08006263/**
6264 * SendEventNotification - Send EventNotification (on or off) request to adapter
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265 * @ioc: Pointer to MPT_ADAPTER structure
6266 * @EvSwitch: Event switch flags
Kashyap, Desaifd761752009-05-29 16:39:06 +05306267 * @sleepFlag: Specifies whether the process can sleep
Linus Torvalds1da177e2005-04-16 15:20:36 -07006268 */
6269static int
Kashyap, Desaifd761752009-05-29 16:39:06 +05306270SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch, int sleepFlag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271{
Kashyap, Desaifd761752009-05-29 16:39:06 +05306272 EventNotification_t evn;
6273 MPIDefaultReply_t reply_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006274
Kashyap, Desaifd761752009-05-29 16:39:06 +05306275 memset(&evn, 0, sizeof(EventNotification_t));
6276 memset(&reply_buf, 0, sizeof(MPIDefaultReply_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277
Kashyap, Desaifd761752009-05-29 16:39:06 +05306278 evn.Function = MPI_FUNCTION_EVENT_NOTIFICATION;
6279 evn.Switch = EvSwitch;
6280 evn.MsgContext = cpu_to_le32(mpt_base_index << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281
Kashyap, Desaifd761752009-05-29 16:39:06 +05306282 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
6283 "Sending EventNotification (%d) request %p\n",
6284 ioc->name, EvSwitch, &evn));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285
Kashyap, Desaifd761752009-05-29 16:39:06 +05306286 return mpt_handshake_req_reply_wait(ioc, sizeof(EventNotification_t),
6287 (u32 *)&evn, sizeof(MPIDefaultReply_t), (u16 *)&reply_buf, 30,
6288 sleepFlag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289}
6290
6291/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6292/**
6293 * SendEventAck - Send EventAck request to MPT adapter.
6294 * @ioc: Pointer to MPT_ADAPTER structure
6295 * @evnp: Pointer to original EventNotification request
6296 */
6297static int
6298SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
6299{
6300 EventAck_t *pAck;
6301
6302 if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05306303 dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306304 ioc->name, __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305 return -1;
6306 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006307
Prakash, Sathya436ace72007-07-24 15:42:08 +05306308 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending EventAck\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309
6310 pAck->Function = MPI_FUNCTION_EVENT_ACK;
6311 pAck->ChainOffset = 0;
Eric Moore4f766dc2006-07-11 17:24:07 -06006312 pAck->Reserved[0] = pAck->Reserved[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006313 pAck->MsgFlags = 0;
Eric Moore4f766dc2006-07-11 17:24:07 -06006314 pAck->Reserved1[0] = pAck->Reserved1[1] = pAck->Reserved1[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006315 pAck->Event = evnp->Event;
6316 pAck->EventContext = evnp->EventContext;
6317
6318 mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)pAck);
6319
6320 return 0;
6321}
6322
6323/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6324/**
6325 * mpt_config - Generic function to issue config message
Randy Dunlapd9489fb2006-12-06 20:38:43 -08006326 * @ioc: Pointer to an adapter structure
6327 * @pCfg: Pointer to a configuration structure. Struct contains
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328 * action, page address, direction, physical address
6329 * and pointer to a configuration page header
6330 * Page header is updated.
6331 *
6332 * Returns 0 for success
6333 * -EPERM if not allowed due to ISR context
6334 * -EAGAIN if no msg frames currently available
6335 * -EFAULT for non-successful reply or no reply (timeout)
6336 */
6337int
6338mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
6339{
6340 Config_t *pReq;
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306341 ConfigReply_t *pReply;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006342 ConfigExtendedPageHeader_t *pExtHdr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343 MPT_FRAME_HDR *mf;
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306344 int ii;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006345 int flagsLength;
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306346 long timeout;
6347 int ret;
6348 u8 page_type = 0, extend_page;
6349 unsigned long timeleft;
Kashyap, Desai2f187862009-05-29 16:52:37 +05306350 unsigned long flags;
6351 int in_isr;
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306352 u8 issue_hard_reset = 0;
6353 u8 retry_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04006355 /* Prevent calling wait_event() (below), if caller happens
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356 * to be in ISR context, because that is fatal!
6357 */
6358 in_isr = in_interrupt();
6359 if (in_isr) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05306360 dcprintk(ioc, printk(MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361 ioc->name));
6362 return -EPERM;
Kashyap, Desai2f187862009-05-29 16:52:37 +05306363 }
6364
6365 /* don't send a config page during diag reset */
6366 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
6367 if (ioc->ioc_reset_in_progress) {
6368 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
6369 "%s: busy with host reset\n", ioc->name, __func__));
6370 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
6371 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372 }
Kashyap, Desai2f187862009-05-29 16:52:37 +05306373 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306375 /* don't send if no chance of success */
6376 if (!ioc->active ||
6377 mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_OPERATIONAL) {
6378 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
6379 "%s: ioc not operational, %d, %xh\n",
6380 ioc->name, __func__, ioc->active,
6381 mpt_GetIocState(ioc, 0)));
6382 return -EFAULT;
6383 }
6384
6385 retry_config:
6386 mutex_lock(&ioc->mptbase_cmds.mutex);
6387 /* init the internal cmd struct */
6388 memset(ioc->mptbase_cmds.reply, 0 , MPT_DEFAULT_FRAME_SIZE);
6389 INITIALIZE_MGMT_STATUS(ioc->mptbase_cmds.status)
6390
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391 /* Get and Populate a free Frame
6392 */
6393 if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306394 dcprintk(ioc, printk(MYIOC_s_WARN_FMT
6395 "mpt_config: no msg frames!\n", ioc->name));
6396 ret = -EAGAIN;
6397 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398 }
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306399
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400 pReq = (Config_t *)mf;
6401 pReq->Action = pCfg->action;
6402 pReq->Reserved = 0;
6403 pReq->ChainOffset = 0;
6404 pReq->Function = MPI_FUNCTION_CONFIG;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006405
6406 /* Assume page type is not extended and clear "reserved" fields. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407 pReq->ExtPageLength = 0;
6408 pReq->ExtPageType = 0;
6409 pReq->MsgFlags = 0;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006410
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411 for (ii=0; ii < 8; ii++)
6412 pReq->Reserved2[ii] = 0;
6413
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006414 pReq->Header.PageVersion = pCfg->cfghdr.hdr->PageVersion;
6415 pReq->Header.PageLength = pCfg->cfghdr.hdr->PageLength;
6416 pReq->Header.PageNumber = pCfg->cfghdr.hdr->PageNumber;
6417 pReq->Header.PageType = (pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
6418
6419 if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) == MPI_CONFIG_PAGETYPE_EXTENDED) {
6420 pExtHdr = (ConfigExtendedPageHeader_t *)pCfg->cfghdr.ehdr;
6421 pReq->ExtPageLength = cpu_to_le16(pExtHdr->ExtPageLength);
6422 pReq->ExtPageType = pExtHdr->ExtPageType;
6423 pReq->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
6424
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306425 /* Page Length must be treated as a reserved field for the
6426 * extended header.
6427 */
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006428 pReq->Header.PageLength = 0;
6429 }
6430
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
6432
6433 /* Add a SGE to the config request.
6434 */
6435 if (pCfg->dir)
6436 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
6437 else
6438 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
6439
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306440 if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) ==
6441 MPI_CONFIG_PAGETYPE_EXTENDED) {
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006442 flagsLength |= pExtHdr->ExtPageLength * 4;
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306443 page_type = pReq->ExtPageType;
6444 extend_page = 1;
6445 } else {
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006446 flagsLength |= pCfg->cfghdr.hdr->PageLength * 4;
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306447 page_type = pReq->Header.PageType;
6448 extend_page = 0;
Christoph Hellwig69218ee2005-08-18 16:26:15 +02006449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306451 dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT
6452 "Sending Config request type 0x%x, page 0x%x and action %d\n",
6453 ioc->name, page_type, pReq->Header.PageNumber, pReq->Action));
6454
Kashyap, Desai14d0f0b2009-05-29 16:37:04 +05306455 ioc->add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306456 timeout = (pCfg->timeout < 15) ? HZ*15 : HZ*pCfg->timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457 mpt_put_msg_frame(mpt_base_index, ioc, mf);
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306458 timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done,
6459 timeout);
6460 if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
6461 ret = -ETIME;
6462 dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
6463 "Failed Sending Config request type 0x%x, page 0x%x,"
6464 " action %d, status %xh, time left %ld\n\n",
6465 ioc->name, page_type, pReq->Header.PageNumber,
6466 pReq->Action, ioc->mptbase_cmds.status, timeleft));
6467 if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
6468 goto out;
kashyap.desai@lsi.com98cbe372011-08-05 11:04:37 +05306469 if (!timeleft) {
6470 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
6471 if (ioc->ioc_reset_in_progress) {
6472 spin_unlock_irqrestore(&ioc->taskmgmt_lock,
6473 flags);
6474 printk(MYIOC_s_INFO_FMT "%s: host reset in"
6475 " progress mpt_config timed out.!!\n",
6476 __func__, ioc->name);
Dan Carpenter83ff74e2011-08-27 12:59:30 +03006477 mutex_unlock(&ioc->mptbase_cmds.mutex);
kashyap.desai@lsi.com98cbe372011-08-05 11:04:37 +05306478 return -EFAULT;
6479 }
6480 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306481 issue_hard_reset = 1;
kashyap.desai@lsi.com98cbe372011-08-05 11:04:37 +05306482 }
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306483 goto out;
6484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306486 if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
6487 ret = -1;
6488 goto out;
6489 }
6490 pReply = (ConfigReply_t *)ioc->mptbase_cmds.reply;
6491 ret = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
6492 if (ret == MPI_IOCSTATUS_SUCCESS) {
6493 if (extend_page) {
6494 pCfg->cfghdr.ehdr->ExtPageLength =
6495 le16_to_cpu(pReply->ExtPageLength);
6496 pCfg->cfghdr.ehdr->ExtPageType =
6497 pReply->ExtPageType;
6498 }
6499 pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
6500 pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
6501 pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
6502 pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006503
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006505
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306506 if (retry_count)
6507 printk(MYIOC_s_INFO_FMT "Retry completed "
6508 "ret=0x%x timeleft=%ld\n",
6509 ioc->name, ret, timeleft);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306511 dcprintk(ioc, printk(KERN_DEBUG "IOCStatus=%04xh, IOCLogInfo=%08xh\n",
6512 ret, le32_to_cpu(pReply->IOCLogInfo)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306514out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306516 CLEAR_MGMT_STATUS(ioc->mptbase_cmds.status)
6517 mutex_unlock(&ioc->mptbase_cmds.mutex);
6518 if (issue_hard_reset) {
6519 issue_hard_reset = 0;
Kei Tokunaga97009a22010-06-22 19:01:51 +09006520 printk(MYIOC_s_WARN_FMT
6521 "Issuing Reset from %s!!, doorbell=0x%08x\n",
6522 ioc->name, __func__, mpt_GetIocState(ioc, 0));
Kashyap, Desaib3b97312010-03-18 19:14:51 +05306523 if (retry_count == 0) {
6524 if (mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP) != 0)
6525 retry_count++;
6526 } else
6527 mpt_HardResetHandler(ioc, CAN_SLEEP);
6528
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306529 mpt_free_msg_frame(ioc, mf);
6530 /* attempt one retry for a timed out command */
Kashyap, Desaib3b97312010-03-18 19:14:51 +05306531 if (retry_count < 2) {
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306532 printk(MYIOC_s_INFO_FMT
6533 "Attempting Retry Config request"
6534 " type 0x%x, page 0x%x,"
6535 " action %d\n", ioc->name, page_type,
6536 pCfg->cfghdr.hdr->PageNumber, pCfg->action);
6537 retry_count++;
6538 goto retry_config;
6539 }
6540 }
6541 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006542
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543}
6544
6545/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08006546/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 * mpt_ioc_reset - Base cleanup for hard reset
6548 * @ioc: Pointer to the adapter structure
6549 * @reset_phase: Indicates pre- or post-reset functionality
6550 *
Randy Dunlapd9489fb2006-12-06 20:38:43 -08006551 * Remark: Frees resources with internally generated commands.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552 */
6553static int
6554mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
6555{
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306556 switch (reset_phase) {
6557 case MPT_IOC_SETUP_RESET:
Kashyap, Desaie7deff32009-05-29 16:46:07 +05306558 ioc->taskmgmt_quiesce_io = 1;
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306559 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
6560 "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
6561 break;
6562 case MPT_IOC_PRE_RESET:
6563 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
6564 "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
6565 break;
6566 case MPT_IOC_POST_RESET:
6567 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
6568 "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
6569/* wake up mptbase_cmds */
6570 if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
6571 ioc->mptbase_cmds.status |=
6572 MPT_MGMT_STATUS_DID_IOCRESET;
6573 complete(&ioc->mptbase_cmds.done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574 }
Kashyap, Desai2f187862009-05-29 16:52:37 +05306575/* wake up taskmgmt_cmds */
6576 if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
6577 ioc->taskmgmt_cmds.status |=
6578 MPT_MGMT_STATUS_DID_IOCRESET;
6579 complete(&ioc->taskmgmt_cmds.done);
6580 }
Kashyap, Desaif0f09d32009-05-29 16:40:57 +05306581 break;
6582 default:
6583 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584 }
6585
6586 return 1; /* currently means nothing really */
6587}
6588
6589
6590#ifdef CONFIG_PROC_FS /* { */
6591/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6592/*
6593 * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
6594 */
6595/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08006596/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597 * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
6598 *
6599 * Returns 0 for success, non-zero for failure.
6600 */
6601static int
6602procmpt_create(void)
6603{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604 mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
6605 if (mpt_proc_root_dir == NULL)
6606 return -ENOTDIR;
6607
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006608 proc_create("summary", S_IRUGO, mpt_proc_root_dir, &mpt_summary_proc_fops);
6609 proc_create("version", S_IRUGO, mpt_proc_root_dir, &mpt_version_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006610 return 0;
6611}
6612
6613/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08006614/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615 * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
6616 *
6617 * Returns 0 for success, non-zero for failure.
6618 */
6619static void
6620procmpt_destroy(void)
6621{
6622 remove_proc_entry("version", mpt_proc_root_dir);
6623 remove_proc_entry("summary", mpt_proc_root_dir);
6624 remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
6625}
6626
6627/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlap1f5cfe22010-08-14 13:05:50 -07006628/*
Randy Dunlapd9489fb2006-12-06 20:38:43 -08006629 * Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630 */
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006631static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan);
6632
6633static int mpt_summary_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634{
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006635 MPT_ADAPTER *ioc = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006637 if (ioc) {
6638 seq_mpt_print_ioc_summary(ioc, m, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639 } else {
6640 list_for_each_entry(ioc, &ioc_list, list) {
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006641 seq_mpt_print_ioc_summary(ioc, m, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642 }
6643 }
6644
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006645 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006646}
6647
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006648static int mpt_summary_proc_open(struct inode *inode, struct file *file)
6649{
Al Virod9dda782013-03-31 18:16:14 -04006650 return single_open(file, mpt_summary_proc_show, PDE_DATA(inode));
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006651}
6652
6653static const struct file_operations mpt_summary_proc_fops = {
6654 .owner = THIS_MODULE,
6655 .open = mpt_summary_proc_open,
6656 .read = seq_read,
6657 .llseek = seq_lseek,
6658 .release = single_release,
6659};
6660
6661static int mpt_version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662{
Prakash, Sathyaf606f572007-08-14 16:12:53 +05306663 u8 cb_idx;
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04006664 int scsi, fc, sas, lan, ctl, targ, dmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006665 char *drvname;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006667 seq_printf(m, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
6668 seq_printf(m, " Fusion MPT base driver\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04006670 scsi = fc = sas = lan = ctl = targ = dmp = 0;
Eric Moore8d6d83e2007-09-14 18:47:40 -06006671 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672 drvname = NULL;
Prakash, Sathyaf606f572007-08-14 16:12:53 +05306673 if (MptCallbacks[cb_idx]) {
6674 switch (MptDriverClass[cb_idx]) {
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04006675 case MPTSPI_DRIVER:
6676 if (!scsi++) drvname = "SPI host";
6677 break;
6678 case MPTFC_DRIVER:
6679 if (!fc++) drvname = "FC host";
6680 break;
6681 case MPTSAS_DRIVER:
6682 if (!sas++) drvname = "SAS host";
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683 break;
6684 case MPTLAN_DRIVER:
6685 if (!lan++) drvname = "LAN";
6686 break;
6687 case MPTSTM_DRIVER:
6688 if (!targ++) drvname = "SCSI target";
6689 break;
6690 case MPTCTL_DRIVER:
6691 if (!ctl++) drvname = "ioctl";
6692 break;
6693 }
6694
6695 if (drvname)
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006696 seq_printf(m, " Fusion MPT %s driver\n", drvname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697 }
6698 }
6699
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006700 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006701}
6702
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006703static int mpt_version_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006704{
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006705 return single_open(file, mpt_version_proc_show, NULL);
6706}
6707
6708static const struct file_operations mpt_version_proc_fops = {
6709 .owner = THIS_MODULE,
6710 .open = mpt_version_proc_open,
6711 .read = seq_read,
6712 .llseek = seq_lseek,
6713 .release = single_release,
6714};
6715
6716static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
6717{
6718 MPT_ADAPTER *ioc = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006719 char expVer[32];
6720 int sz;
6721 int p;
6722
6723 mpt_get_fw_exp_ver(expVer, ioc);
6724
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006725 seq_printf(m, "%s:", ioc->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006727 seq_printf(m, " (f/w download boot flag set)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006728// if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006729// seq_printf(m, " CONFIG_CHECKSUM_FAIL!");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006730
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006731 seq_printf(m, "\n ProductID = 0x%04x (%s)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006732 ioc->facts.ProductID,
6733 ioc->prod_name);
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006734 seq_printf(m, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006735 if (ioc->facts.FWImageSize)
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006736 seq_printf(m, " (fw_size=%d)", ioc->facts.FWImageSize);
6737 seq_printf(m, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
6738 seq_printf(m, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
6739 seq_printf(m, " EventState = 0x%02x\n", ioc->facts.EventState);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006740
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006741 seq_printf(m, " CurrentHostMfaHighAddr = 0x%08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742 ioc->facts.CurrentHostMfaHighAddr);
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006743 seq_printf(m, " CurrentSenseBufferHighAddr = 0x%08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744 ioc->facts.CurrentSenseBufferHighAddr);
6745
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006746 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
6747 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006749 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006750 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
6751 /*
6752 * Rounding UP to nearest 4-kB boundary here...
6753 */
6754 sz = (ioc->req_sz * ioc->req_depth) + 128;
6755 sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006756 seq_printf(m, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006758 seq_printf(m, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759 4*ioc->facts.RequestFrameSize,
6760 ioc->facts.GlobalCredits);
6761
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006762 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006763 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
6764 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006765 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006767 seq_printf(m, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768 ioc->facts.CurReplyFrameSize,
6769 ioc->facts.ReplyQueueDepth);
6770
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006771 seq_printf(m, " MaxDevices = %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006772 (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006773 seq_printf(m, " MaxBuses = %d\n", ioc->facts.MaxBuses);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006774
6775 /* per-port info */
6776 for (p=0; p < ioc->facts.NumberOfPorts; p++) {
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006777 seq_printf(m, " PortNumber = %d (of %d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778 p+1,
6779 ioc->facts.NumberOfPorts);
6780 if (ioc->bus_type == FC) {
6781 if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
6782 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006783 seq_printf(m, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784 a[5], a[4], a[3], a[2], a[1], a[0]);
6785 }
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006786 seq_printf(m, " WWN = %08X%08X:%08X%08X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07006787 ioc->fc_port_page0[p].WWNN.High,
6788 ioc->fc_port_page0[p].WWNN.Low,
6789 ioc->fc_port_page0[p].WWPN.High,
6790 ioc->fc_port_page0[p].WWPN.Low);
6791 }
6792 }
6793
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006794 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006795}
6796
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006797static int mpt_iocinfo_proc_open(struct inode *inode, struct file *file)
6798{
Al Virod9dda782013-03-31 18:16:14 -04006799 return single_open(file, mpt_iocinfo_proc_show, PDE_DATA(inode));
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006800}
6801
6802static const struct file_operations mpt_iocinfo_proc_fops = {
6803 .owner = THIS_MODULE,
6804 .open = mpt_iocinfo_proc_open,
6805 .read = seq_read,
6806 .llseek = seq_lseek,
6807 .release = single_release,
6808};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006809#endif /* CONFIG_PROC_FS } */
6810
6811/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6812static void
6813mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
6814{
6815 buf[0] ='\0';
6816 if ((ioc->facts.FWVersion.Word >> 24) == 0x0E) {
6817 sprintf(buf, " (Exp %02d%02d)",
6818 (ioc->facts.FWVersion.Word >> 16) & 0x00FF, /* Month */
6819 (ioc->facts.FWVersion.Word >> 8) & 0x1F); /* Day */
6820
6821 /* insider hack! */
6822 if ((ioc->facts.FWVersion.Word >> 8) & 0x80)
6823 strcat(buf, " [MDBG]");
6824 }
6825}
6826
6827/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6828/**
6829 * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
6830 * @ioc: Pointer to MPT_ADAPTER structure
6831 * @buffer: Pointer to buffer where IOC summary info should be written
6832 * @size: Pointer to number of bytes we wrote (set by this routine)
6833 * @len: Offset at which to start writing in buffer
6834 * @showlan: Display LAN stuff?
6835 *
6836 * This routine writes (english readable) ASCII text, which represents
6837 * a summary of IOC information, to a buffer.
6838 */
6839void
6840mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
6841{
6842 char expVer[32];
6843 int y;
6844
6845 mpt_get_fw_exp_ver(expVer, ioc);
6846
6847 /*
6848 * Shorter summary of attached ioc's...
6849 */
6850 y = sprintf(buffer+len, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
6851 ioc->name,
6852 ioc->prod_name,
6853 MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
6854 ioc->facts.FWVersion.Word,
6855 expVer,
6856 ioc->facts.NumberOfPorts,
6857 ioc->req_depth);
6858
6859 if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
6860 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
6861 y += sprintf(buffer+len+y, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
6862 a[5], a[4], a[3], a[2], a[1], a[0]);
6863 }
6864
Linus Torvalds1da177e2005-04-16 15:20:36 -07006865 y += sprintf(buffer+len+y, ", IRQ=%d", ioc->pci_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006866
6867 if (!ioc->active)
6868 y += sprintf(buffer+len+y, " (disabled)");
6869
6870 y += sprintf(buffer+len+y, "\n");
6871
6872 *size = y;
6873}
Alexey Dobriyaneb6edad2010-08-10 18:01:15 -07006874
6875static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan)
6876{
6877 char expVer[32];
6878
6879 mpt_get_fw_exp_ver(expVer, ioc);
6880
6881 /*
6882 * Shorter summary of attached ioc's...
6883 */
6884 seq_printf(m, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
6885 ioc->name,
6886 ioc->prod_name,
6887 MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
6888 ioc->facts.FWVersion.Word,
6889 expVer,
6890 ioc->facts.NumberOfPorts,
6891 ioc->req_depth);
6892
6893 if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
6894 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
6895 seq_printf(m, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
6896 a[5], a[4], a[3], a[2], a[1], a[0]);
6897 }
6898
6899 seq_printf(m, ", IRQ=%d", ioc->pci_irq);
6900
6901 if (!ioc->active)
6902 seq_printf(m, " (disabled)");
6903
6904 seq_putc(m, '\n');
6905}
6906
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05306907/**
Uwe Kleine-Koenig3dbda772009-07-23 08:31:31 +02006908 * mpt_set_taskmgmt_in_progress_flag - set flags associated with task management
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05306909 * @ioc: Pointer to MPT_ADAPTER structure
6910 *
6911 * Returns 0 for SUCCESS or -1 if FAILED.
6912 *
6913 * If -1 is return, then it was not possible to set the flags
6914 **/
6915int
6916mpt_set_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc)
6917{
6918 unsigned long flags;
6919 int retval;
6920
6921 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
6922 if (ioc->ioc_reset_in_progress || ioc->taskmgmt_in_progress ||
6923 (ioc->alt_ioc && ioc->alt_ioc->taskmgmt_in_progress)) {
6924 retval = -1;
6925 goto out;
6926 }
6927 retval = 0;
6928 ioc->taskmgmt_in_progress = 1;
Kashyap, Desaie7deff32009-05-29 16:46:07 +05306929 ioc->taskmgmt_quiesce_io = 1;
6930 if (ioc->alt_ioc) {
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05306931 ioc->alt_ioc->taskmgmt_in_progress = 1;
Kashyap, Desaie7deff32009-05-29 16:46:07 +05306932 ioc->alt_ioc->taskmgmt_quiesce_io = 1;
6933 }
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05306934 out:
6935 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
6936 return retval;
6937}
6938EXPORT_SYMBOL(mpt_set_taskmgmt_in_progress_flag);
6939
6940/**
Uwe Kleine-Koenig3dbda772009-07-23 08:31:31 +02006941 * mpt_clear_taskmgmt_in_progress_flag - clear flags associated with task management
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05306942 * @ioc: Pointer to MPT_ADAPTER structure
6943 *
6944 **/
6945void
6946mpt_clear_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc)
6947{
6948 unsigned long flags;
6949
6950 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
6951 ioc->taskmgmt_in_progress = 0;
Kashyap, Desaie7deff32009-05-29 16:46:07 +05306952 ioc->taskmgmt_quiesce_io = 0;
6953 if (ioc->alt_ioc) {
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05306954 ioc->alt_ioc->taskmgmt_in_progress = 0;
Kashyap, Desaie7deff32009-05-29 16:46:07 +05306955 ioc->alt_ioc->taskmgmt_quiesce_io = 0;
6956 }
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05306957 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
6958}
6959EXPORT_SYMBOL(mpt_clear_taskmgmt_in_progress_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006960
Kashyap, Desai2f4c7822009-01-06 15:03:37 +05306961
6962/**
6963 * mpt_halt_firmware - Halts the firmware if it is operational and panic
6964 * the kernel
6965 * @ioc: Pointer to MPT_ADAPTER structure
6966 *
6967 **/
6968void
6969mpt_halt_firmware(MPT_ADAPTER *ioc)
6970{
6971 u32 ioc_raw_state;
6972
6973 ioc_raw_state = mpt_GetIocState(ioc, 0);
6974
6975 if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
6976 printk(MYIOC_s_ERR_FMT "IOC is in FAULT state (%04xh)!!!\n",
6977 ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
6978 panic("%s: IOC Fault (%04xh)!!!\n", ioc->name,
6979 ioc_raw_state & MPI_DOORBELL_DATA_MASK);
6980 } else {
6981 CHIPREG_WRITE32(&ioc->chip->Doorbell, 0xC0FFEE00);
6982 panic("%s: Firmware is halted due to command timeout\n",
6983 ioc->name);
6984 }
6985}
6986EXPORT_SYMBOL(mpt_halt_firmware);
6987
Kashyap, Desaid0f698c2010-03-18 19:12:17 +05306988/**
6989 * mpt_SoftResetHandler - Issues a less expensive reset
6990 * @ioc: Pointer to MPT_ADAPTER structure
6991 * @sleepFlag: Indicates if sleep or schedule must be called.
Kashyap, Desaid0f698c2010-03-18 19:12:17 +05306992 *
6993 * Returns 0 for SUCCESS or -1 if FAILED.
6994 *
6995 * Message Unit Reset - instructs the IOC to reset the Reply Post and
6996 * Free FIFO's. All the Message Frames on Reply Free FIFO are discarded.
6997 * All posted buffers are freed, and event notification is turned off.
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006998 * IOC doesn't reply to any outstanding request. This will transfer IOC
Kashyap, Desaid0f698c2010-03-18 19:12:17 +05306999 * to READY state.
7000 **/
Joe Lawrence5767d252014-06-25 17:05:49 -04007001static int
Kashyap, Desaid0f698c2010-03-18 19:12:17 +05307002mpt_SoftResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
7003{
7004 int rc;
7005 int ii;
7006 u8 cb_idx;
7007 unsigned long flags;
7008 u32 ioc_state;
7009 unsigned long time_count;
7010
7011 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SoftResetHandler Entered!\n",
7012 ioc->name));
7013
7014 ioc_state = mpt_GetIocState(ioc, 0) & MPI_IOC_STATE_MASK;
7015
7016 if (mpt_fwfault_debug)
7017 mpt_halt_firmware(ioc);
7018
7019 if (ioc_state == MPI_IOC_STATE_FAULT ||
7020 ioc_state == MPI_IOC_STATE_RESET) {
7021 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
7022 "skipping, either in FAULT or RESET state!\n", ioc->name));
7023 return -1;
7024 }
7025
7026 if (ioc->bus_type == FC) {
7027 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
7028 "skipping, because the bus type is FC!\n", ioc->name));
7029 return -1;
7030 }
7031
7032 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
7033 if (ioc->ioc_reset_in_progress) {
7034 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
7035 return -1;
7036 }
7037 ioc->ioc_reset_in_progress = 1;
7038 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
7039
7040 rc = -1;
7041
7042 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
7043 if (MptResetHandlers[cb_idx])
7044 mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
7045 }
7046
7047 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
7048 if (ioc->taskmgmt_in_progress) {
Kashyap, Desaib9a0f872010-06-17 14:42:39 +05307049 ioc->ioc_reset_in_progress = 0;
Kashyap, Desaid0f698c2010-03-18 19:12:17 +05307050 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
7051 return -1;
7052 }
7053 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
7054 /* Disable reply interrupts (also blocks FreeQ) */
7055 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
7056 ioc->active = 0;
7057 time_count = jiffies;
7058
7059 rc = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
7060
7061 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
7062 if (MptResetHandlers[cb_idx])
7063 mpt_signal_reset(cb_idx, ioc, MPT_IOC_PRE_RESET);
7064 }
7065
7066 if (rc)
7067 goto out;
7068
7069 ioc_state = mpt_GetIocState(ioc, 0) & MPI_IOC_STATE_MASK;
7070 if (ioc_state != MPI_IOC_STATE_READY)
7071 goto out;
7072
7073 for (ii = 0; ii < 5; ii++) {
7074 /* Get IOC facts! Allow 5 retries */
7075 rc = GetIocFacts(ioc, sleepFlag,
7076 MPT_HOSTEVENT_IOC_RECOVER);
7077 if (rc == 0)
7078 break;
7079 if (sleepFlag == CAN_SLEEP)
7080 msleep(100);
7081 else
7082 mdelay(100);
7083 }
7084 if (ii == 5)
7085 goto out;
7086
7087 rc = PrimeIocFifos(ioc);
7088 if (rc != 0)
7089 goto out;
7090
7091 rc = SendIocInit(ioc, sleepFlag);
7092 if (rc != 0)
7093 goto out;
7094
7095 rc = SendEventNotification(ioc, 1, sleepFlag);
7096 if (rc != 0)
7097 goto out;
7098
7099 if (ioc->hard_resets < -1)
7100 ioc->hard_resets++;
7101
7102 /*
7103 * At this point, we know soft reset succeeded.
7104 */
7105
7106 ioc->active = 1;
7107 CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
7108
7109 out:
7110 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
7111 ioc->ioc_reset_in_progress = 0;
7112 ioc->taskmgmt_quiesce_io = 0;
7113 ioc->taskmgmt_in_progress = 0;
7114 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
7115
7116 if (ioc->active) { /* otherwise, hard reset coming */
7117 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
7118 if (MptResetHandlers[cb_idx])
7119 mpt_signal_reset(cb_idx, ioc,
7120 MPT_IOC_POST_RESET);
7121 }
7122 }
7123
7124 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
7125 "SoftResetHandler: completed (%d seconds): %s\n",
7126 ioc->name, jiffies_to_msecs(jiffies - time_count)/1000,
7127 ((rc == 0) ? "SUCCESS" : "FAILED")));
7128
7129 return rc;
7130}
7131
7132/**
7133 * mpt_Soft_Hard_ResetHandler - Try less expensive reset
7134 * @ioc: Pointer to MPT_ADAPTER structure
7135 * @sleepFlag: Indicates if sleep or schedule must be called.
Kashyap, Desaid0f698c2010-03-18 19:12:17 +05307136 *
7137 * Returns 0 for SUCCESS or -1 if FAILED.
7138 * Try for softreset first, only if it fails go for expensive
7139 * HardReset.
7140 **/
7141int
7142mpt_Soft_Hard_ResetHandler(MPT_ADAPTER *ioc, int sleepFlag) {
7143 int ret = -1;
7144
7145 ret = mpt_SoftResetHandler(ioc, sleepFlag);
7146 if (ret == 0)
7147 return ret;
7148 ret = mpt_HardResetHandler(ioc, sleepFlag);
7149 return ret;
7150}
7151EXPORT_SYMBOL(mpt_Soft_Hard_ResetHandler);
7152
Linus Torvalds1da177e2005-04-16 15:20:36 -07007153/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
7154/*
7155 * Reset Handling
7156 */
7157/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
7158/**
Randy Dunlapd9489fb2006-12-06 20:38:43 -08007159 * mpt_HardResetHandler - Generic reset handler
Linus Torvalds1da177e2005-04-16 15:20:36 -07007160 * @ioc: Pointer to MPT_ADAPTER structure
7161 * @sleepFlag: Indicates if sleep or schedule must be called.
7162 *
Randy Dunlapd9489fb2006-12-06 20:38:43 -08007163 * Issues SCSI Task Management call based on input arg values.
7164 * If TaskMgmt fails, returns associated SCSI request.
7165 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007166 * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
7167 * or a non-interrupt thread. In the former, must not call schedule().
7168 *
Randy Dunlapd9489fb2006-12-06 20:38:43 -08007169 * Note: A return of -1 is a FATAL error case, as it means a
Linus Torvalds1da177e2005-04-16 15:20:36 -07007170 * FW reload/initialization failed.
7171 *
7172 * Returns 0 for SUCCESS or -1 if FAILED.
7173 */
7174int
7175mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
7176{
Kashyap, Desaid1306912009-08-05 12:53:51 +05307177 int rc;
Kashyap, Desai2f187862009-05-29 16:52:37 +05307178 u8 cb_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007179 unsigned long flags;
Kashyap, Desai2f187862009-05-29 16:52:37 +05307180 unsigned long time_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007181
Prakash, Sathya436ace72007-07-24 15:42:08 +05307182 dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HardResetHandler Entered!\n", ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007183#ifdef MFCNT
7184 printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
7185 printk("MF count 0x%x !\n", ioc->mfcnt);
7186#endif
Kashyap, Desai2f4c7822009-01-06 15:03:37 +05307187 if (mpt_fwfault_debug)
7188 mpt_halt_firmware(ioc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007189
7190 /* Reset the adapter. Prevent more than 1 call to
7191 * mpt_do_ioc_recovery at any instant in time.
7192 */
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05307193 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
7194 if (ioc->ioc_reset_in_progress) {
7195 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
kashyap.desai@lsi.com98cbe372011-08-05 11:04:37 +05307196 ioc->wait_on_reset_completion = 1;
7197 do {
7198 ssleep(1);
7199 } while (ioc->ioc_reset_in_progress == 1);
7200 ioc->wait_on_reset_completion = 0;
7201 return ioc->reset_status;
7202 }
7203 if (ioc->wait_on_reset_completion) {
7204 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
7205 rc = 0;
7206 time_count = jiffies;
7207 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007208 }
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05307209 ioc->ioc_reset_in_progress = 1;
7210 if (ioc->alt_ioc)
7211 ioc->alt_ioc->ioc_reset_in_progress = 1;
7212 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007213
Linus Torvalds1da177e2005-04-16 15:20:36 -07007214
7215 /* The SCSI driver needs to adjust timeouts on all current
7216 * commands prior to the diagnostic reset being issued.
Adrian Bunk80f72282006-06-30 18:27:16 +02007217 * Prevents timeouts occurring during a diagnostic reset...very bad.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007218 * For all other protocol drivers, this is a no-op.
7219 */
Kashyap, Desai2f187862009-05-29 16:52:37 +05307220 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
7221 if (MptResetHandlers[cb_idx]) {
7222 mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
7223 if (ioc->alt_ioc)
7224 mpt_signal_reset(cb_idx, ioc->alt_ioc,
7225 MPT_IOC_SETUP_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007226 }
7227 }
7228
Kashyap, Desai2f187862009-05-29 16:52:37 +05307229 time_count = jiffies;
7230 rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag);
7231 if (rc != 0) {
7232 printk(KERN_WARNING MYNAM
Kei Tokunaga97009a22010-06-22 19:01:51 +09007233 ": WARNING - (%d) Cannot recover %s, doorbell=0x%08x\n",
7234 rc, ioc->name, mpt_GetIocState(ioc, 0));
Kashyap, Desai2f187862009-05-29 16:52:37 +05307235 } else {
7236 if (ioc->hard_resets < -1)
7237 ioc->hard_resets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007239
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05307240 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
7241 ioc->ioc_reset_in_progress = 0;
Kashyap, Desaie7deff32009-05-29 16:46:07 +05307242 ioc->taskmgmt_quiesce_io = 0;
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05307243 ioc->taskmgmt_in_progress = 0;
kashyap.desai@lsi.com98cbe372011-08-05 11:04:37 +05307244 ioc->reset_status = rc;
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05307245 if (ioc->alt_ioc) {
7246 ioc->alt_ioc->ioc_reset_in_progress = 0;
Kashyap, Desaie7deff32009-05-29 16:46:07 +05307247 ioc->alt_ioc->taskmgmt_quiesce_io = 0;
Kashyap, Desai1ba9ab22009-05-29 16:44:48 +05307248 ioc->alt_ioc->taskmgmt_in_progress = 0;
7249 }
7250 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007251
Kashyap, Desaid1306912009-08-05 12:53:51 +05307252 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
7253 if (MptResetHandlers[cb_idx]) {
7254 mpt_signal_reset(cb_idx, ioc, MPT_IOC_POST_RESET);
7255 if (ioc->alt_ioc)
7256 mpt_signal_reset(cb_idx,
7257 ioc->alt_ioc, MPT_IOC_POST_RESET);
7258 }
7259 }
kashyap.desai@lsi.com98cbe372011-08-05 11:04:37 +05307260exit:
Kashyap, Desai2f187862009-05-29 16:52:37 +05307261 dtmprintk(ioc,
7262 printk(MYIOC_s_DEBUG_FMT
7263 "HardResetHandler: completed (%d seconds): %s\n", ioc->name,
7264 jiffies_to_msecs(jiffies - time_count)/1000, ((rc == 0) ?
7265 "SUCCESS" : "FAILED")));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007266
7267 return rc;
7268}
7269
Kashyap, Desai2f187862009-05-29 16:52:37 +05307270#ifdef CONFIG_FUSION_LOGGING
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007271static void
Kashyap, Desai2f187862009-05-29 16:52:37 +05307272mpt_display_event_info(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007273{
Eric Moore509e5e52006-04-26 13:22:37 -06007274 char *ds = NULL;
Kashyap, Desai2f187862009-05-29 16:52:37 +05307275 u32 evData0;
7276 int ii;
7277 u8 event;
7278 char *evStr = ioc->evStr;
7279
7280 event = le32_to_cpu(pEventReply->Event) & 0xFF;
7281 evData0 = le32_to_cpu(pEventReply->Data[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007282
7283 switch(event) {
7284 case MPI_EVENT_NONE:
7285 ds = "None";
7286 break;
7287 case MPI_EVENT_LOG_DATA:
7288 ds = "Log Data";
7289 break;
7290 case MPI_EVENT_STATE_CHANGE:
7291 ds = "State Change";
7292 break;
7293 case MPI_EVENT_UNIT_ATTENTION:
7294 ds = "Unit Attention";
7295 break;
7296 case MPI_EVENT_IOC_BUS_RESET:
7297 ds = "IOC Bus Reset";
7298 break;
7299 case MPI_EVENT_EXT_BUS_RESET:
7300 ds = "External Bus Reset";
7301 break;
7302 case MPI_EVENT_RESCAN:
7303 ds = "Bus Rescan Event";
Linus Torvalds1da177e2005-04-16 15:20:36 -07007304 break;
7305 case MPI_EVENT_LINK_STATUS_CHANGE:
7306 if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
7307 ds = "Link Status(FAILURE) Change";
7308 else
7309 ds = "Link Status(ACTIVE) Change";
7310 break;
7311 case MPI_EVENT_LOOP_STATE_CHANGE:
7312 if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
7313 ds = "Loop State(LIP) Change";
7314 else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
Kashyap, Desai2f187862009-05-29 16:52:37 +05307315 ds = "Loop State(LPE) Change";
Linus Torvalds1da177e2005-04-16 15:20:36 -07007316 else
Kashyap, Desai2f187862009-05-29 16:52:37 +05307317 ds = "Loop State(LPB) Change";
Linus Torvalds1da177e2005-04-16 15:20:36 -07007318 break;
7319 case MPI_EVENT_LOGOUT:
7320 ds = "Logout";
7321 break;
7322 case MPI_EVENT_EVENT_CHANGE:
7323 if (evData0)
Eric Moore4f766dc2006-07-11 17:24:07 -06007324 ds = "Events ON";
Linus Torvalds1da177e2005-04-16 15:20:36 -07007325 else
Eric Moore4f766dc2006-07-11 17:24:07 -06007326 ds = "Events OFF";
Linus Torvalds1da177e2005-04-16 15:20:36 -07007327 break;
7328 case MPI_EVENT_INTEGRATED_RAID:
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007329 {
7330 u8 ReasonCode = (u8)(evData0 >> 16);
7331 switch (ReasonCode) {
7332 case MPI_EVENT_RAID_RC_VOLUME_CREATED :
7333 ds = "Integrated Raid: Volume Created";
7334 break;
7335 case MPI_EVENT_RAID_RC_VOLUME_DELETED :
7336 ds = "Integrated Raid: Volume Deleted";
7337 break;
7338 case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED :
7339 ds = "Integrated Raid: Volume Settings Changed";
7340 break;
7341 case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED :
7342 ds = "Integrated Raid: Volume Status Changed";
7343 break;
7344 case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED :
7345 ds = "Integrated Raid: Volume Physdisk Changed";
7346 break;
7347 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED :
7348 ds = "Integrated Raid: Physdisk Created";
7349 break;
7350 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED :
7351 ds = "Integrated Raid: Physdisk Deleted";
7352 break;
7353 case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED :
7354 ds = "Integrated Raid: Physdisk Settings Changed";
7355 break;
7356 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED :
7357 ds = "Integrated Raid: Physdisk Status Changed";
7358 break;
7359 case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED :
7360 ds = "Integrated Raid: Domain Validation Needed";
7361 break;
7362 case MPI_EVENT_RAID_RC_SMART_DATA :
7363 ds = "Integrated Raid; Smart Data";
7364 break;
7365 case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED :
7366 ds = "Integrated Raid: Replace Action Started";
7367 break;
7368 default:
7369 ds = "Integrated Raid";
Linus Torvalds1da177e2005-04-16 15:20:36 -07007370 break;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007371 }
7372 break;
7373 }
7374 case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE:
7375 ds = "SCSI Device Status Change";
7376 break;
7377 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
7378 {
Moore, Eric3a892be2006-03-14 09:14:03 -07007379 u8 id = (u8)(evData0);
Eric Moorec6c727a2007-01-29 09:44:54 -07007380 u8 channel = (u8)(evData0 >> 8);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007381 u8 ReasonCode = (u8)(evData0 >> 16);
7382 switch (ReasonCode) {
7383 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
Eric Moore509e5e52006-04-26 13:22:37 -06007384 snprintf(evStr, EVENT_DESCR_STR_SZ,
Eric Moorec6c727a2007-01-29 09:44:54 -07007385 "SAS Device Status Change: Added: "
7386 "id=%d channel=%d", id, channel);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007387 break;
7388 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
Eric Moore509e5e52006-04-26 13:22:37 -06007389 snprintf(evStr, EVENT_DESCR_STR_SZ,
Eric Moorec6c727a2007-01-29 09:44:54 -07007390 "SAS Device Status Change: Deleted: "
7391 "id=%d channel=%d", id, channel);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007392 break;
7393 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
Eric Moore509e5e52006-04-26 13:22:37 -06007394 snprintf(evStr, EVENT_DESCR_STR_SZ,
Eric Moorec6c727a2007-01-29 09:44:54 -07007395 "SAS Device Status Change: SMART Data: "
7396 "id=%d channel=%d", id, channel);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007397 break;
7398 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
Eric Moore509e5e52006-04-26 13:22:37 -06007399 snprintf(evStr, EVENT_DESCR_STR_SZ,
Eric Moorec6c727a2007-01-29 09:44:54 -07007400 "SAS Device Status Change: No Persistancy: "
7401 "id=%d channel=%d", id, channel);
7402 break;
7403 case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
7404 snprintf(evStr, EVENT_DESCR_STR_SZ,
7405 "SAS Device Status Change: Unsupported Device "
7406 "Discovered : id=%d channel=%d", id, channel);
Eric Moore4f766dc2006-07-11 17:24:07 -06007407 break;
7408 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
7409 snprintf(evStr, EVENT_DESCR_STR_SZ,
Eric Moorec6c727a2007-01-29 09:44:54 -07007410 "SAS Device Status Change: Internal Device "
7411 "Reset : id=%d channel=%d", id, channel);
Eric Moore4f766dc2006-07-11 17:24:07 -06007412 break;
7413 case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
7414 snprintf(evStr, EVENT_DESCR_STR_SZ,
Eric Moorec6c727a2007-01-29 09:44:54 -07007415 "SAS Device Status Change: Internal Task "
7416 "Abort : id=%d channel=%d", id, channel);
Eric Moore4f766dc2006-07-11 17:24:07 -06007417 break;
7418 case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
7419 snprintf(evStr, EVENT_DESCR_STR_SZ,
Eric Moorec6c727a2007-01-29 09:44:54 -07007420 "SAS Device Status Change: Internal Abort "
7421 "Task Set : id=%d channel=%d", id, channel);
Eric Moore4f766dc2006-07-11 17:24:07 -06007422 break;
7423 case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
7424 snprintf(evStr, EVENT_DESCR_STR_SZ,
Eric Moorec6c727a2007-01-29 09:44:54 -07007425 "SAS Device Status Change: Internal Clear "
7426 "Task Set : id=%d channel=%d", id, channel);
Eric Moore4f766dc2006-07-11 17:24:07 -06007427 break;
7428 case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
7429 snprintf(evStr, EVENT_DESCR_STR_SZ,
Eric Moorec6c727a2007-01-29 09:44:54 -07007430 "SAS Device Status Change: Internal Query "
7431 "Task : id=%d channel=%d", id, channel);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007432 break;
7433 default:
Eric Moore509e5e52006-04-26 13:22:37 -06007434 snprintf(evStr, EVENT_DESCR_STR_SZ,
Eric Moorec6c727a2007-01-29 09:44:54 -07007435 "SAS Device Status Change: Unknown: "
7436 "id=%d channel=%d", id, channel);
Eric Moore509e5e52006-04-26 13:22:37 -06007437 break;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007438 }
7439 break;
7440 }
7441 case MPI_EVENT_ON_BUS_TIMER_EXPIRED:
7442 ds = "Bus Timer Expired";
7443 break;
7444 case MPI_EVENT_QUEUE_FULL:
Eric Moorec6c727a2007-01-29 09:44:54 -07007445 {
7446 u16 curr_depth = (u16)(evData0 >> 16);
7447 u8 channel = (u8)(evData0 >> 8);
7448 u8 id = (u8)(evData0);
7449
7450 snprintf(evStr, EVENT_DESCR_STR_SZ,
7451 "Queue Full: channel=%d id=%d depth=%d",
7452 channel, id, curr_depth);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007453 break;
Eric Moorec6c727a2007-01-29 09:44:54 -07007454 }
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007455 case MPI_EVENT_SAS_SES:
7456 ds = "SAS SES Event";
7457 break;
7458 case MPI_EVENT_PERSISTENT_TABLE_FULL:
7459 ds = "Persistent Table Full";
7460 break;
7461 case MPI_EVENT_SAS_PHY_LINK_STATUS:
Moore, Eric3a892be2006-03-14 09:14:03 -07007462 {
Moore, Eric3a892be2006-03-14 09:14:03 -07007463 u8 LinkRates = (u8)(evData0 >> 8);
7464 u8 PhyNumber = (u8)(evData0);
7465 LinkRates = (LinkRates & MPI_EVENT_SAS_PLS_LR_CURRENT_MASK) >>
7466 MPI_EVENT_SAS_PLS_LR_CURRENT_SHIFT;
7467 switch (LinkRates) {
7468 case MPI_EVENT_SAS_PLS_LR_RATE_UNKNOWN:
Eric Moore509e5e52006-04-26 13:22:37 -06007469 snprintf(evStr, EVENT_DESCR_STR_SZ,
7470 "SAS PHY Link Status: Phy=%d:"
Moore, Eric3a892be2006-03-14 09:14:03 -07007471 " Rate Unknown",PhyNumber);
7472 break;
7473 case MPI_EVENT_SAS_PLS_LR_RATE_PHY_DISABLED:
Eric Moore509e5e52006-04-26 13:22:37 -06007474 snprintf(evStr, EVENT_DESCR_STR_SZ,
7475 "SAS PHY Link Status: Phy=%d:"
Moore, Eric3a892be2006-03-14 09:14:03 -07007476 " Phy Disabled",PhyNumber);
7477 break;
7478 case MPI_EVENT_SAS_PLS_LR_RATE_FAILED_SPEED_NEGOTIATION:
Eric Moore509e5e52006-04-26 13:22:37 -06007479 snprintf(evStr, EVENT_DESCR_STR_SZ,
7480 "SAS PHY Link Status: Phy=%d:"
Moore, Eric3a892be2006-03-14 09:14:03 -07007481 " Failed Speed Nego",PhyNumber);
7482 break;
7483 case MPI_EVENT_SAS_PLS_LR_RATE_SATA_OOB_COMPLETE:
Eric Moore509e5e52006-04-26 13:22:37 -06007484 snprintf(evStr, EVENT_DESCR_STR_SZ,
7485 "SAS PHY Link Status: Phy=%d:"
Moore, Eric3a892be2006-03-14 09:14:03 -07007486 " Sata OOB Completed",PhyNumber);
7487 break;
7488 case MPI_EVENT_SAS_PLS_LR_RATE_1_5:
Eric Moore509e5e52006-04-26 13:22:37 -06007489 snprintf(evStr, EVENT_DESCR_STR_SZ,
7490 "SAS PHY Link Status: Phy=%d:"
Moore, Eric3a892be2006-03-14 09:14:03 -07007491 " Rate 1.5 Gbps",PhyNumber);
7492 break;
7493 case MPI_EVENT_SAS_PLS_LR_RATE_3_0:
Eric Moore509e5e52006-04-26 13:22:37 -06007494 snprintf(evStr, EVENT_DESCR_STR_SZ,
7495 "SAS PHY Link Status: Phy=%d:"
Kashyap, Desaid75733d2011-02-10 11:50:39 +05307496 " Rate 3.0 Gbps", PhyNumber);
7497 break;
7498 case MPI_EVENT_SAS_PLS_LR_RATE_6_0:
7499 snprintf(evStr, EVENT_DESCR_STR_SZ,
7500 "SAS PHY Link Status: Phy=%d:"
7501 " Rate 6.0 Gbps", PhyNumber);
Moore, Eric3a892be2006-03-14 09:14:03 -07007502 break;
7503 default:
Eric Moore509e5e52006-04-26 13:22:37 -06007504 snprintf(evStr, EVENT_DESCR_STR_SZ,
7505 "SAS PHY Link Status: Phy=%d", PhyNumber);
Moore, Eric3a892be2006-03-14 09:14:03 -07007506 break;
7507 }
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007508 break;
Moore, Eric3a892be2006-03-14 09:14:03 -07007509 }
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007510 case MPI_EVENT_SAS_DISCOVERY_ERROR:
7511 ds = "SAS Discovery Error";
7512 break;
Moore, Eric3a892be2006-03-14 09:14:03 -07007513 case MPI_EVENT_IR_RESYNC_UPDATE:
7514 {
7515 u8 resync_complete = (u8)(evData0 >> 16);
Eric Moore509e5e52006-04-26 13:22:37 -06007516 snprintf(evStr, EVENT_DESCR_STR_SZ,
7517 "IR Resync Update: Complete = %d:",resync_complete);
Moore, Eric3a892be2006-03-14 09:14:03 -07007518 break;
7519 }
7520 case MPI_EVENT_IR2:
7521 {
Kashyap, Desai2f187862009-05-29 16:52:37 +05307522 u8 id = (u8)(evData0);
7523 u8 channel = (u8)(evData0 >> 8);
7524 u8 phys_num = (u8)(evData0 >> 24);
Moore, Eric3a892be2006-03-14 09:14:03 -07007525 u8 ReasonCode = (u8)(evData0 >> 16);
Kashyap, Desai2f187862009-05-29 16:52:37 +05307526
Moore, Eric3a892be2006-03-14 09:14:03 -07007527 switch (ReasonCode) {
7528 case MPI_EVENT_IR2_RC_LD_STATE_CHANGED:
Kashyap, Desai2f187862009-05-29 16:52:37 +05307529 snprintf(evStr, EVENT_DESCR_STR_SZ,
7530 "IR2: LD State Changed: "
7531 "id=%d channel=%d phys_num=%d",
7532 id, channel, phys_num);
Moore, Eric3a892be2006-03-14 09:14:03 -07007533 break;
7534 case MPI_EVENT_IR2_RC_PD_STATE_CHANGED:
Kashyap, Desai2f187862009-05-29 16:52:37 +05307535 snprintf(evStr, EVENT_DESCR_STR_SZ,
7536 "IR2: PD State Changed "
7537 "id=%d channel=%d phys_num=%d",
7538 id, channel, phys_num);
Moore, Eric3a892be2006-03-14 09:14:03 -07007539 break;
7540 case MPI_EVENT_IR2_RC_BAD_BLOCK_TABLE_FULL:
Kashyap, Desai2f187862009-05-29 16:52:37 +05307541 snprintf(evStr, EVENT_DESCR_STR_SZ,
7542 "IR2: Bad Block Table Full: "
7543 "id=%d channel=%d phys_num=%d",
7544 id, channel, phys_num);
Moore, Eric3a892be2006-03-14 09:14:03 -07007545 break;
7546 case MPI_EVENT_IR2_RC_PD_INSERTED:
Kashyap, Desai2f187862009-05-29 16:52:37 +05307547 snprintf(evStr, EVENT_DESCR_STR_SZ,
7548 "IR2: PD Inserted: "
7549 "id=%d channel=%d phys_num=%d",
7550 id, channel, phys_num);
Moore, Eric3a892be2006-03-14 09:14:03 -07007551 break;
7552 case MPI_EVENT_IR2_RC_PD_REMOVED:
Kashyap, Desai2f187862009-05-29 16:52:37 +05307553 snprintf(evStr, EVENT_DESCR_STR_SZ,
7554 "IR2: PD Removed: "
7555 "id=%d channel=%d phys_num=%d",
7556 id, channel, phys_num);
Moore, Eric3a892be2006-03-14 09:14:03 -07007557 break;
7558 case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
Kashyap, Desai2f187862009-05-29 16:52:37 +05307559 snprintf(evStr, EVENT_DESCR_STR_SZ,
7560 "IR2: Foreign CFG Detected: "
7561 "id=%d channel=%d phys_num=%d",
7562 id, channel, phys_num);
Moore, Eric3a892be2006-03-14 09:14:03 -07007563 break;
7564 case MPI_EVENT_IR2_RC_REBUILD_MEDIUM_ERROR:
Kashyap, Desai2f187862009-05-29 16:52:37 +05307565 snprintf(evStr, EVENT_DESCR_STR_SZ,
7566 "IR2: Rebuild Medium Error: "
7567 "id=%d channel=%d phys_num=%d",
7568 id, channel, phys_num);
Moore, Eric3a892be2006-03-14 09:14:03 -07007569 break;
Kashyap, Desaia7938b02009-05-29 16:53:56 +05307570 case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED:
7571 snprintf(evStr, EVENT_DESCR_STR_SZ,
7572 "IR2: Dual Port Added: "
7573 "id=%d channel=%d phys_num=%d",
7574 id, channel, phys_num);
7575 break;
7576 case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED:
7577 snprintf(evStr, EVENT_DESCR_STR_SZ,
7578 "IR2: Dual Port Removed: "
7579 "id=%d channel=%d phys_num=%d",
7580 id, channel, phys_num);
7581 break;
Moore, Eric3a892be2006-03-14 09:14:03 -07007582 default:
7583 ds = "IR2";
7584 break;
7585 }
7586 break;
7587 }
7588 case MPI_EVENT_SAS_DISCOVERY:
7589 {
7590 if (evData0)
7591 ds = "SAS Discovery: Start";
7592 else
7593 ds = "SAS Discovery: Stop";
7594 break;
7595 }
7596 case MPI_EVENT_LOG_ENTRY_ADDED:
7597 ds = "SAS Log Entry Added";
7598 break;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007599
Eric Moorec6c727a2007-01-29 09:44:54 -07007600 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
7601 {
7602 u8 phy_num = (u8)(evData0);
7603 u8 port_num = (u8)(evData0 >> 8);
7604 u8 port_width = (u8)(evData0 >> 16);
7605 u8 primative = (u8)(evData0 >> 24);
7606 snprintf(evStr, EVENT_DESCR_STR_SZ,
7607 "SAS Broadcase Primative: phy=%d port=%d "
7608 "width=%d primative=0x%02x",
7609 phy_num, port_num, port_width, primative);
7610 break;
7611 }
7612
7613 case MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
7614 {
7615 u8 reason = (u8)(evData0);
Eric Moorec6c727a2007-01-29 09:44:54 -07007616
Kashyap, Desai2f187862009-05-29 16:52:37 +05307617 switch (reason) {
7618 case MPI_EVENT_SAS_INIT_RC_ADDED:
7619 ds = "SAS Initiator Status Change: Added";
7620 break;
7621 case MPI_EVENT_SAS_INIT_RC_REMOVED:
7622 ds = "SAS Initiator Status Change: Deleted";
7623 break;
7624 default:
7625 ds = "SAS Initiator Status Change";
7626 break;
7627 }
Eric Moorec6c727a2007-01-29 09:44:54 -07007628 break;
7629 }
7630
7631 case MPI_EVENT_SAS_INIT_TABLE_OVERFLOW:
7632 {
7633 u8 max_init = (u8)(evData0);
7634 u8 current_init = (u8)(evData0 >> 8);
7635
7636 snprintf(evStr, EVENT_DESCR_STR_SZ,
7637 "SAS Initiator Device Table Overflow: max initiators=%02d "
7638 "current initators=%02d",
7639 max_init, current_init);
7640 break;
7641 }
7642 case MPI_EVENT_SAS_SMP_ERROR:
7643 {
7644 u8 status = (u8)(evData0);
7645 u8 port_num = (u8)(evData0 >> 8);
7646 u8 result = (u8)(evData0 >> 16);
7647
7648 if (status == MPI_EVENT_SAS_SMP_FUNCTION_RESULT_VALID)
7649 snprintf(evStr, EVENT_DESCR_STR_SZ,
7650 "SAS SMP Error: port=%d result=0x%02x",
7651 port_num, result);
7652 else if (status == MPI_EVENT_SAS_SMP_CRC_ERROR)
7653 snprintf(evStr, EVENT_DESCR_STR_SZ,
7654 "SAS SMP Error: port=%d : CRC Error",
7655 port_num);
7656 else if (status == MPI_EVENT_SAS_SMP_TIMEOUT)
7657 snprintf(evStr, EVENT_DESCR_STR_SZ,
7658 "SAS SMP Error: port=%d : Timeout",
7659 port_num);
7660 else if (status == MPI_EVENT_SAS_SMP_NO_DESTINATION)
7661 snprintf(evStr, EVENT_DESCR_STR_SZ,
7662 "SAS SMP Error: port=%d : No Destination",
7663 port_num);
7664 else if (status == MPI_EVENT_SAS_SMP_BAD_DESTINATION)
7665 snprintf(evStr, EVENT_DESCR_STR_SZ,
7666 "SAS SMP Error: port=%d : Bad Destination",
7667 port_num);
7668 else
7669 snprintf(evStr, EVENT_DESCR_STR_SZ,
7670 "SAS SMP Error: port=%d : status=0x%02x",
7671 port_num, status);
7672 break;
7673 }
7674
Kashyap, Desai2f187862009-05-29 16:52:37 +05307675 case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
7676 {
7677 u8 reason = (u8)(evData0);
7678
7679 switch (reason) {
7680 case MPI_EVENT_SAS_EXP_RC_ADDED:
7681 ds = "Expander Status Change: Added";
7682 break;
7683 case MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING:
7684 ds = "Expander Status Change: Deleted";
7685 break;
7686 default:
7687 ds = "Expander Status Change";
7688 break;
7689 }
7690 break;
7691 }
7692
Linus Torvalds1da177e2005-04-16 15:20:36 -07007693 /*
7694 * MPT base "custom" events may be added here...
7695 */
7696 default:
7697 ds = "Unknown";
7698 break;
7699 }
Eric Moore509e5e52006-04-26 13:22:37 -06007700 if (ds)
7701 strncpy(evStr, ds, EVENT_DESCR_STR_SZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007702
Kashyap, Desai2f187862009-05-29 16:52:37 +05307703
7704 devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
7705 "MPT event:(%02Xh) : %s\n",
7706 ioc->name, event, evStr));
7707
7708 devtverboseprintk(ioc, printk(KERN_DEBUG MYNAM
7709 ": Event data:\n"));
7710 for (ii = 0; ii < le16_to_cpu(pEventReply->EventDataLength); ii++)
7711 devtverboseprintk(ioc, printk(" %08x",
7712 le32_to_cpu(pEventReply->Data[ii])));
7713 devtverboseprintk(ioc, printk(KERN_DEBUG "\n"));
7714}
7715#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07007716/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08007717/**
7718 * ProcessEventNotification - Route EventNotificationReply to all event handlers
Linus Torvalds1da177e2005-04-16 15:20:36 -07007719 * @ioc: Pointer to MPT_ADAPTER structure
7720 * @pEventReply: Pointer to EventNotification reply frame
7721 * @evHandlers: Pointer to integer, number of event handlers
7722 *
Randy Dunlapd9489fb2006-12-06 20:38:43 -08007723 * Routes a received EventNotificationReply to all currently registered
7724 * event handlers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007725 * Returns sum of event handlers return values.
7726 */
7727static int
7728ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
7729{
7730 u16 evDataLen;
7731 u32 evData0 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007732 int ii;
Prakash, Sathyaf606f572007-08-14 16:12:53 +05307733 u8 cb_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007734 int r = 0;
7735 int handlers = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007736 u8 event;
7737
7738 /*
7739 * Do platform normalization of values
7740 */
7741 event = le32_to_cpu(pEventReply->Event) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007742 evDataLen = le16_to_cpu(pEventReply->EventDataLength);
7743 if (evDataLen) {
7744 evData0 = le32_to_cpu(pEventReply->Data[0]);
7745 }
7746
Prakash, Sathya436ace72007-07-24 15:42:08 +05307747#ifdef CONFIG_FUSION_LOGGING
Kashyap, Desai2f187862009-05-29 16:52:37 +05307748 if (evDataLen)
7749 mpt_display_event_info(ioc, pEventReply);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007750#endif
7751
7752 /*
7753 * Do general / base driver event processing
7754 */
7755 switch(event) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007756 case MPI_EVENT_EVENT_CHANGE: /* 0A */
7757 if (evDataLen) {
7758 u8 evState = evData0 & 0xFF;
7759
7760 /* CHECKME! What if evState unexpectedly says OFF (0)? */
7761
7762 /* Update EventState field in cached IocFacts */
7763 if (ioc->facts.Function) {
7764 ioc->facts.EventState = evState;
7765 }
7766 }
7767 break;
Moore, Ericece50912006-01-16 18:53:19 -07007768 case MPI_EVENT_INTEGRATED_RAID:
7769 mptbase_raid_process_event_data(ioc,
7770 (MpiEventDataRaid_t *)pEventReply->Data);
7771 break;
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02007772 default:
7773 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007774 }
7775
7776 /*
7777 * Should this event be logged? Events are written sequentially.
7778 * When buffer is full, start again at the top.
7779 */
7780 if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
7781 int idx;
7782
Moore, Eric5b5ef4f2006-02-02 17:19:40 -07007783 idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007784
7785 ioc->events[idx].event = event;
7786 ioc->events[idx].eventContext = ioc->eventContext;
7787
7788 for (ii = 0; ii < 2; ii++) {
7789 if (ii < evDataLen)
7790 ioc->events[idx].data[ii] = le32_to_cpu(pEventReply->Data[ii]);
7791 else
7792 ioc->events[idx].data[ii] = 0;
7793 }
7794
7795 ioc->eventContext++;
7796 }
7797
7798
7799 /*
7800 * Call each currently registered protocol event handler.
7801 */
Eric Moore8d6d83e2007-09-14 18:47:40 -06007802 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
Prakash, Sathyaf606f572007-08-14 16:12:53 +05307803 if (MptEvHandlers[cb_idx]) {
Kashyap, Desai2f187862009-05-29 16:52:37 +05307804 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
7805 "Routing Event to event handler #%d\n",
7806 ioc->name, cb_idx));
Prakash, Sathyaf606f572007-08-14 16:12:53 +05307807 r += (*(MptEvHandlers[cb_idx]))(ioc, pEventReply);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007808 handlers++;
7809 }
7810 }
7811 /* FIXME? Examine results here? */
7812
7813 /*
7814 * If needed, send (a single) EventAck.
7815 */
7816 if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05307817 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
Christoph Hellwigc6678e02005-08-18 16:24:53 +02007818 "EventAck required\n",ioc->name));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007819 if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
Prakash, Sathya436ace72007-07-24 15:42:08 +05307820 devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SendEventAck returned %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07007821 ioc->name, ii));
7822 }
7823 }
7824
7825 *evHandlers = handlers;
7826 return r;
7827}
7828
7829/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08007830/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007831 * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
7832 * @ioc: Pointer to MPT_ADAPTER structure
7833 * @log_info: U32 LogInfo reply word from the IOC
7834 *
Eric Moore4f766dc2006-07-11 17:24:07 -06007835 * Refer to lsi/mpi_log_fc.h.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007836 */
7837static void
7838mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
7839{
Eric Moore7c431e52007-06-13 16:34:36 -06007840 char *desc = "unknown";
Linus Torvalds1da177e2005-04-16 15:20:36 -07007841
Eric Moore7c431e52007-06-13 16:34:36 -06007842 switch (log_info & 0xFF000000) {
7843 case MPI_IOCLOGINFO_FC_INIT_BASE:
7844 desc = "FCP Initiator";
7845 break;
7846 case MPI_IOCLOGINFO_FC_TARGET_BASE:
7847 desc = "FCP Target";
7848 break;
7849 case MPI_IOCLOGINFO_FC_LAN_BASE:
7850 desc = "LAN";
7851 break;
7852 case MPI_IOCLOGINFO_FC_MSG_BASE:
7853 desc = "MPI Message Layer";
7854 break;
7855 case MPI_IOCLOGINFO_FC_LINK_BASE:
7856 desc = "FC Link";
7857 break;
7858 case MPI_IOCLOGINFO_FC_CTX_BASE:
7859 desc = "Context Manager";
7860 break;
7861 case MPI_IOCLOGINFO_FC_INVALID_FIELD_BYTE_OFFSET:
7862 desc = "Invalid Field Offset";
7863 break;
7864 case MPI_IOCLOGINFO_FC_STATE_CHANGE:
7865 desc = "State Change Info";
7866 break;
7867 }
7868
7869 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): SubClass={%s}, Value=(0x%06x)\n",
7870 ioc->name, log_info, desc, (log_info & 0xFFFFFF));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007871}
7872
7873/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08007874/**
Moore, Eric335a9412006-01-17 17:06:23 -07007875 * mpt_spi_log_info - Log information returned from SCSI Parallel IOC.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007876 * @ioc: Pointer to MPT_ADAPTER structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07007877 * @log_info: U32 LogInfo word from the IOC
7878 *
7879 * Refer to lsi/sp_log.h.
7880 */
7881static void
Moore, Eric335a9412006-01-17 17:06:23 -07007882mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007883{
7884 u32 info = log_info & 0x00FF0000;
7885 char *desc = "unknown";
7886
7887 switch (info) {
7888 case 0x00010000:
7889 desc = "bug! MID not found";
Linus Torvalds1da177e2005-04-16 15:20:36 -07007890 break;
7891
7892 case 0x00020000:
7893 desc = "Parity Error";
7894 break;
7895
7896 case 0x00030000:
7897 desc = "ASYNC Outbound Overrun";
7898 break;
7899
7900 case 0x00040000:
7901 desc = "SYNC Offset Error";
7902 break;
7903
7904 case 0x00050000:
7905 desc = "BM Change";
7906 break;
7907
7908 case 0x00060000:
7909 desc = "Msg In Overflow";
7910 break;
7911
7912 case 0x00070000:
7913 desc = "DMA Error";
7914 break;
7915
7916 case 0x00080000:
7917 desc = "Outbound DMA Overrun";
7918 break;
Christoph Hellwigc6678e02005-08-18 16:24:53 +02007919
Linus Torvalds1da177e2005-04-16 15:20:36 -07007920 case 0x00090000:
7921 desc = "Task Management";
7922 break;
7923
7924 case 0x000A0000:
7925 desc = "Device Problem";
7926 break;
7927
7928 case 0x000B0000:
7929 desc = "Invalid Phase Change";
7930 break;
7931
7932 case 0x000C0000:
7933 desc = "Untagged Table Size";
7934 break;
Christoph Hellwigc6678e02005-08-18 16:24:53 +02007935
Linus Torvalds1da177e2005-04-16 15:20:36 -07007936 }
7937
7938 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
7939}
7940
Moore, Eric Dean466544d2005-09-14 18:09:10 -06007941/* strings for sas loginfo */
7942 static char *originator_str[] = {
7943 "IOP", /* 00h */
7944 "PL", /* 01h */
7945 "IR" /* 02h */
7946 };
7947 static char *iop_code_str[] = {
7948 NULL, /* 00h */
7949 "Invalid SAS Address", /* 01h */
7950 NULL, /* 02h */
7951 "Invalid Page", /* 03h */
Eric Moore4f766dc2006-07-11 17:24:07 -06007952 "Diag Message Error", /* 04h */
7953 "Task Terminated", /* 05h */
7954 "Enclosure Management", /* 06h */
7955 "Target Mode" /* 07h */
Moore, Eric Dean466544d2005-09-14 18:09:10 -06007956 };
7957 static char *pl_code_str[] = {
7958 NULL, /* 00h */
7959 "Open Failure", /* 01h */
7960 "Invalid Scatter Gather List", /* 02h */
7961 "Wrong Relative Offset or Frame Length", /* 03h */
7962 "Frame Transfer Error", /* 04h */
7963 "Transmit Frame Connected Low", /* 05h */
7964 "SATA Non-NCQ RW Error Bit Set", /* 06h */
7965 "SATA Read Log Receive Data Error", /* 07h */
7966 "SATA NCQ Fail All Commands After Error", /* 08h */
7967 "SATA Error in Receive Set Device Bit FIS", /* 09h */
7968 "Receive Frame Invalid Message", /* 0Ah */
7969 "Receive Context Message Valid Error", /* 0Bh */
7970 "Receive Frame Current Frame Error", /* 0Ch */
7971 "SATA Link Down", /* 0Dh */
7972 "Discovery SATA Init W IOS", /* 0Eh */
7973 "Config Invalid Page", /* 0Fh */
7974 "Discovery SATA Init Timeout", /* 10h */
7975 "Reset", /* 11h */
7976 "Abort", /* 12h */
7977 "IO Not Yet Executed", /* 13h */
7978 "IO Executed", /* 14h */
Eric Moorec6c727a2007-01-29 09:44:54 -07007979 "Persistent Reservation Out Not Affiliation "
7980 "Owner", /* 15h */
Moore, Eric5bf52c42006-03-14 09:14:01 -07007981 "Open Transmit DMA Abort", /* 16h */
Eric Moore4f766dc2006-07-11 17:24:07 -06007982 "IO Device Missing Delay Retry", /* 17h */
Lucas De Marchi25985ed2011-03-30 22:57:33 -03007983 "IO Cancelled Due to Receive Error", /* 18h */
Moore, Eric Dean466544d2005-09-14 18:09:10 -06007984 NULL, /* 19h */
7985 NULL, /* 1Ah */
7986 NULL, /* 1Bh */
7987 NULL, /* 1Ch */
7988 NULL, /* 1Dh */
7989 NULL, /* 1Eh */
7990 NULL, /* 1Fh */
7991 "Enclosure Management" /* 20h */
7992 };
Eric Moorec6c727a2007-01-29 09:44:54 -07007993 static char *ir_code_str[] = {
7994 "Raid Action Error", /* 00h */
7995 NULL, /* 00h */
7996 NULL, /* 01h */
7997 NULL, /* 02h */
7998 NULL, /* 03h */
7999 NULL, /* 04h */
8000 NULL, /* 05h */
8001 NULL, /* 06h */
8002 NULL /* 07h */
8003 };
8004 static char *raid_sub_code_str[] = {
8005 NULL, /* 00h */
8006 "Volume Creation Failed: Data Passed too "
8007 "Large", /* 01h */
8008 "Volume Creation Failed: Duplicate Volumes "
8009 "Attempted", /* 02h */
8010 "Volume Creation Failed: Max Number "
8011 "Supported Volumes Exceeded", /* 03h */
8012 "Volume Creation Failed: DMA Error", /* 04h */
8013 "Volume Creation Failed: Invalid Volume Type", /* 05h */
8014 "Volume Creation Failed: Error Reading "
8015 "MFG Page 4", /* 06h */
8016 "Volume Creation Failed: Creating Internal "
8017 "Structures", /* 07h */
8018 NULL, /* 08h */
8019 NULL, /* 09h */
8020 NULL, /* 0Ah */
8021 NULL, /* 0Bh */
8022 NULL, /* 0Ch */
8023 NULL, /* 0Dh */
8024 NULL, /* 0Eh */
8025 NULL, /* 0Fh */
8026 "Activation failed: Already Active Volume", /* 10h */
8027 "Activation failed: Unsupported Volume Type", /* 11h */
8028 "Activation failed: Too Many Active Volumes", /* 12h */
8029 "Activation failed: Volume ID in Use", /* 13h */
8030 "Activation failed: Reported Failure", /* 14h */
8031 "Activation failed: Importing a Volume", /* 15h */
8032 NULL, /* 16h */
8033 NULL, /* 17h */
8034 NULL, /* 18h */
8035 NULL, /* 19h */
8036 NULL, /* 1Ah */
8037 NULL, /* 1Bh */
8038 NULL, /* 1Ch */
8039 NULL, /* 1Dh */
8040 NULL, /* 1Eh */
8041 NULL, /* 1Fh */
8042 "Phys Disk failed: Too Many Phys Disks", /* 20h */
8043 "Phys Disk failed: Data Passed too Large", /* 21h */
8044 "Phys Disk failed: DMA Error", /* 22h */
8045 "Phys Disk failed: Invalid <channel:id>", /* 23h */
8046 "Phys Disk failed: Creating Phys Disk Config "
8047 "Page", /* 24h */
8048 NULL, /* 25h */
8049 NULL, /* 26h */
8050 NULL, /* 27h */
8051 NULL, /* 28h */
8052 NULL, /* 29h */
8053 NULL, /* 2Ah */
8054 NULL, /* 2Bh */
8055 NULL, /* 2Ch */
8056 NULL, /* 2Dh */
8057 NULL, /* 2Eh */
8058 NULL, /* 2Fh */
8059 "Compatibility Error: IR Disabled", /* 30h */
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04008060 "Compatibility Error: Inquiry Command Failed", /* 31h */
Eric Moorec6c727a2007-01-29 09:44:54 -07008061 "Compatibility Error: Device not Direct Access "
8062 "Device ", /* 32h */
8063 "Compatibility Error: Removable Device Found", /* 33h */
8064 "Compatibility Error: Device SCSI Version not "
8065 "2 or Higher", /* 34h */
8066 "Compatibility Error: SATA Device, 48 BIT LBA "
8067 "not Supported", /* 35h */
8068 "Compatibility Error: Device doesn't have "
8069 "512 Byte Block Sizes", /* 36h */
8070 "Compatibility Error: Volume Type Check Failed", /* 37h */
8071 "Compatibility Error: Volume Type is "
8072 "Unsupported by FW", /* 38h */
8073 "Compatibility Error: Disk Drive too Small for "
8074 "use in Volume", /* 39h */
8075 "Compatibility Error: Phys Disk for Create "
8076 "Volume not Found", /* 3Ah */
8077 "Compatibility Error: Too Many or too Few "
8078 "Disks for Volume Type", /* 3Bh */
8079 "Compatibility Error: Disk stripe Sizes "
8080 "Must be 64KB", /* 3Ch */
8081 "Compatibility Error: IME Size Limited to < 2TB", /* 3Dh */
8082 };
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008083
8084/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08008085/**
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008086 * mpt_sas_log_info - Log information returned from SAS IOC.
8087 * @ioc: Pointer to MPT_ADAPTER structure
8088 * @log_info: U32 LogInfo reply word from the IOC
Randy Dunlapfc58fb12010-08-14 13:05:57 -07008089 * @cb_idx: callback function's handle
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008090 *
8091 * Refer to lsi/mpi_log_sas.h.
Eric Moorec6c727a2007-01-29 09:44:54 -07008092 **/
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008093static void
Kashyap, Desai213aaca2010-07-26 18:57:36 +05308094mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info, u8 cb_idx)
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008095{
8096union loginfo_type {
8097 u32 loginfo;
8098 struct {
8099 u32 subcode:16;
8100 u32 code:8;
8101 u32 originator:4;
8102 u32 bus_type:4;
8103 }dw;
8104};
8105 union loginfo_type sas_loginfo;
Eric Moorec6c727a2007-01-29 09:44:54 -07008106 char *originator_desc = NULL;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008107 char *code_desc = NULL;
Eric Moorec6c727a2007-01-29 09:44:54 -07008108 char *sub_code_desc = NULL;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008109
8110 sas_loginfo.loginfo = log_info;
8111 if ((sas_loginfo.dw.bus_type != 3 /*SAS*/) &&
Julia Lawalldd7c34e2008-11-09 17:55:27 +01008112 (sas_loginfo.dw.originator < ARRAY_SIZE(originator_str)))
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008113 return;
Eric Moorec6c727a2007-01-29 09:44:54 -07008114
8115 originator_desc = originator_str[sas_loginfo.dw.originator];
8116
8117 switch (sas_loginfo.dw.originator) {
8118
8119 case 0: /* IOP */
8120 if (sas_loginfo.dw.code <
Julia Lawalldd7c34e2008-11-09 17:55:27 +01008121 ARRAY_SIZE(iop_code_str))
Eric Moorec6c727a2007-01-29 09:44:54 -07008122 code_desc = iop_code_str[sas_loginfo.dw.code];
8123 break;
8124 case 1: /* PL */
8125 if (sas_loginfo.dw.code <
Julia Lawalldd7c34e2008-11-09 17:55:27 +01008126 ARRAY_SIZE(pl_code_str))
Eric Moorec6c727a2007-01-29 09:44:54 -07008127 code_desc = pl_code_str[sas_loginfo.dw.code];
8128 break;
8129 case 2: /* IR */
8130 if (sas_loginfo.dw.code >=
Julia Lawalldd7c34e2008-11-09 17:55:27 +01008131 ARRAY_SIZE(ir_code_str))
Eric Moorec6c727a2007-01-29 09:44:54 -07008132 break;
8133 code_desc = ir_code_str[sas_loginfo.dw.code];
8134 if (sas_loginfo.dw.subcode >=
Julia Lawalldd7c34e2008-11-09 17:55:27 +01008135 ARRAY_SIZE(raid_sub_code_str))
Julia Lawall081f4f42010-08-05 22:27:14 +02008136 break;
Eric Moorec6c727a2007-01-29 09:44:54 -07008137 if (sas_loginfo.dw.code == 0)
8138 sub_code_desc =
8139 raid_sub_code_str[sas_loginfo.dw.subcode];
8140 break;
8141 default:
8142 return;
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008143 }
8144
Eric Moorec6c727a2007-01-29 09:44:54 -07008145 if (sub_code_desc != NULL)
8146 printk(MYIOC_s_INFO_FMT
8147 "LogInfo(0x%08x): Originator={%s}, Code={%s},"
Kashyap, Desai213aaca2010-07-26 18:57:36 +05308148 " SubCode={%s} cb_idx %s\n",
Eric Moorec6c727a2007-01-29 09:44:54 -07008149 ioc->name, log_info, originator_desc, code_desc,
Kashyap, Desai213aaca2010-07-26 18:57:36 +05308150 sub_code_desc, MptCallbacksName[cb_idx]);
Eric Moorec6c727a2007-01-29 09:44:54 -07008151 else if (code_desc != NULL)
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008152 printk(MYIOC_s_INFO_FMT
8153 "LogInfo(0x%08x): Originator={%s}, Code={%s},"
Kashyap, Desai213aaca2010-07-26 18:57:36 +05308154 " SubCode(0x%04x) cb_idx %s\n",
Eric Moorec6c727a2007-01-29 09:44:54 -07008155 ioc->name, log_info, originator_desc, code_desc,
Kashyap, Desai213aaca2010-07-26 18:57:36 +05308156 sas_loginfo.dw.subcode, MptCallbacksName[cb_idx]);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008157 else
8158 printk(MYIOC_s_INFO_FMT
8159 "LogInfo(0x%08x): Originator={%s}, Code=(0x%02x),"
Kashyap, Desai213aaca2010-07-26 18:57:36 +05308160 " SubCode(0x%04x) cb_idx %s\n",
Eric Moorec6c727a2007-01-29 09:44:54 -07008161 ioc->name, log_info, originator_desc,
Kashyap, Desai213aaca2010-07-26 18:57:36 +05308162 sas_loginfo.dw.code, sas_loginfo.dw.subcode,
8163 MptCallbacksName[cb_idx]);
Moore, Eric Dean466544d2005-09-14 18:09:10 -06008164}
8165
Linus Torvalds1da177e2005-04-16 15:20:36 -07008166/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08008167/**
Eric Moorec6c727a2007-01-29 09:44:54 -07008168 * mpt_iocstatus_info_config - IOCSTATUS information for config pages
8169 * @ioc: Pointer to MPT_ADAPTER structure
Randy Dunlap1544d672007-02-20 11:17:03 -08008170 * @ioc_status: U32 IOCStatus word from IOC
Eric Moorec6c727a2007-01-29 09:44:54 -07008171 * @mf: Pointer to MPT request frame
8172 *
8173 * Refer to lsi/mpi.h.
8174 **/
8175static void
8176mpt_iocstatus_info_config(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
8177{
8178 Config_t *pReq = (Config_t *)mf;
8179 char extend_desc[EVENT_DESCR_STR_SZ];
8180 char *desc = NULL;
8181 u32 form;
8182 u8 page_type;
8183
8184 if (pReq->Header.PageType == MPI_CONFIG_PAGETYPE_EXTENDED)
8185 page_type = pReq->ExtPageType;
8186 else
8187 page_type = pReq->Header.PageType;
8188
8189 /*
8190 * ignore invalid page messages for GET_NEXT_HANDLE
8191 */
8192 form = le32_to_cpu(pReq->PageAddress);
8193 if (ioc_status == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
8194 if (page_type == MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE ||
8195 page_type == MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER ||
8196 page_type == MPI_CONFIG_EXTPAGETYPE_ENCLOSURE) {
8197 if ((form >> MPI_SAS_DEVICE_PGAD_FORM_SHIFT) ==
8198 MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE)
8199 return;
8200 }
8201 if (page_type == MPI_CONFIG_PAGETYPE_FC_DEVICE)
8202 if ((form & MPI_FC_DEVICE_PGAD_FORM_MASK) ==
8203 MPI_FC_DEVICE_PGAD_FORM_NEXT_DID)
8204 return;
8205 }
8206
8207 snprintf(extend_desc, EVENT_DESCR_STR_SZ,
8208 "type=%02Xh, page=%02Xh, action=%02Xh, form=%08Xh",
8209 page_type, pReq->Header.PageNumber, pReq->Action, form);
8210
8211 switch (ioc_status) {
8212
8213 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
8214 desc = "Config Page Invalid Action";
8215 break;
8216
8217 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
8218 desc = "Config Page Invalid Type";
8219 break;
8220
8221 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
8222 desc = "Config Page Invalid Page";
8223 break;
8224
8225 case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
8226 desc = "Config Page Invalid Data";
8227 break;
8228
8229 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
8230 desc = "Config Page No Defaults";
8231 break;
8232
8233 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
8234 desc = "Config Page Can't Commit";
8235 break;
8236 }
8237
8238 if (!desc)
8239 return;
8240
Eric Moore29dd3602007-09-14 18:46:51 -06008241 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOCStatus(0x%04X): %s: %s\n",
8242 ioc->name, ioc_status, desc, extend_desc));
Eric Moorec6c727a2007-01-29 09:44:54 -07008243}
8244
8245/**
8246 * mpt_iocstatus_info - IOCSTATUS information returned from IOC.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008247 * @ioc: Pointer to MPT_ADAPTER structure
8248 * @ioc_status: U32 IOCStatus word from IOC
8249 * @mf: Pointer to MPT request frame
8250 *
8251 * Refer to lsi/mpi.h.
Eric Moorec6c727a2007-01-29 09:44:54 -07008252 **/
Linus Torvalds1da177e2005-04-16 15:20:36 -07008253static void
Eric Moorec6c727a2007-01-29 09:44:54 -07008254mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008255{
8256 u32 status = ioc_status & MPI_IOCSTATUS_MASK;
Eric Moore4f766dc2006-07-11 17:24:07 -06008257 char *desc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008258
8259 switch (status) {
Eric Moorec6c727a2007-01-29 09:44:54 -07008260
8261/****************************************************************************/
8262/* Common IOCStatus values for all replies */
8263/****************************************************************************/
8264
Linus Torvalds1da177e2005-04-16 15:20:36 -07008265 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
8266 desc = "Invalid Function";
8267 break;
8268
8269 case MPI_IOCSTATUS_BUSY: /* 0x0002 */
8270 desc = "Busy";
8271 break;
8272
8273 case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
8274 desc = "Invalid SGL";
8275 break;
8276
8277 case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
8278 desc = "Internal Error";
8279 break;
8280
8281 case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
8282 desc = "Reserved";
8283 break;
8284
8285 case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
8286 desc = "Insufficient Resources";
8287 break;
8288
8289 case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
8290 desc = "Invalid Field";
8291 break;
8292
8293 case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
8294 desc = "Invalid State";
8295 break;
8296
Eric Moorec6c727a2007-01-29 09:44:54 -07008297/****************************************************************************/
8298/* Config IOCStatus values */
8299/****************************************************************************/
8300
Linus Torvalds1da177e2005-04-16 15:20:36 -07008301 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
8302 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
8303 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
8304 case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
8305 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
8306 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
Eric Moorec6c727a2007-01-29 09:44:54 -07008307 mpt_iocstatus_info_config(ioc, status, mf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008308 break;
8309
Eric Moorec6c727a2007-01-29 09:44:54 -07008310/****************************************************************************/
8311/* SCSIIO Reply (SPI, FCP, SAS) initiator values */
8312/* */
8313/* Look at mptscsih_iocstatus_info_scsiio in mptscsih.c */
8314/* */
8315/****************************************************************************/
8316
Linus Torvalds1da177e2005-04-16 15:20:36 -07008317 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008318 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
Eric Moorec6c727a2007-01-29 09:44:54 -07008319 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
8320 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
8321 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
8322 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008323 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008324 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008325 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008326 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008327 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008328 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
Eric Moorec6c727a2007-01-29 09:44:54 -07008329 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008330 break;
8331
Eric Moorec6c727a2007-01-29 09:44:54 -07008332/****************************************************************************/
8333/* SCSI Target values */
8334/****************************************************************************/
8335
8336 case MPI_IOCSTATUS_TARGET_PRIORITY_IO: /* 0x0060 */
8337 desc = "Target: Priority IO";
8338 break;
8339
8340 case MPI_IOCSTATUS_TARGET_INVALID_PORT: /* 0x0061 */
8341 desc = "Target: Invalid Port";
8342 break;
8343
8344 case MPI_IOCSTATUS_TARGET_INVALID_IO_INDEX: /* 0x0062 */
8345 desc = "Target Invalid IO Index:";
8346 break;
8347
8348 case MPI_IOCSTATUS_TARGET_ABORTED: /* 0x0063 */
8349 desc = "Target: Aborted";
8350 break;
8351
8352 case MPI_IOCSTATUS_TARGET_NO_CONN_RETRYABLE: /* 0x0064 */
8353 desc = "Target: No Conn Retryable";
8354 break;
8355
8356 case MPI_IOCSTATUS_TARGET_NO_CONNECTION: /* 0x0065 */
8357 desc = "Target: No Connection";
8358 break;
8359
8360 case MPI_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH: /* 0x006A */
8361 desc = "Target: Transfer Count Mismatch";
8362 break;
8363
8364 case MPI_IOCSTATUS_TARGET_STS_DATA_NOT_SENT: /* 0x006B */
8365 desc = "Target: STS Data not Sent";
8366 break;
8367
8368 case MPI_IOCSTATUS_TARGET_DATA_OFFSET_ERROR: /* 0x006D */
8369 desc = "Target: Data Offset Error";
8370 break;
8371
8372 case MPI_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA: /* 0x006E */
8373 desc = "Target: Too Much Write Data";
8374 break;
8375
8376 case MPI_IOCSTATUS_TARGET_IU_TOO_SHORT: /* 0x006F */
8377 desc = "Target: IU Too Short";
8378 break;
8379
8380 case MPI_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT: /* 0x0070 */
8381 desc = "Target: ACK NAK Timeout";
8382 break;
8383
8384 case MPI_IOCSTATUS_TARGET_NAK_RECEIVED: /* 0x0071 */
8385 desc = "Target: Nak Received";
8386 break;
8387
8388/****************************************************************************/
8389/* Fibre Channel Direct Access values */
8390/****************************************************************************/
8391
8392 case MPI_IOCSTATUS_FC_ABORTED: /* 0x0066 */
8393 desc = "FC: Aborted";
8394 break;
8395
8396 case MPI_IOCSTATUS_FC_RX_ID_INVALID: /* 0x0067 */
8397 desc = "FC: RX ID Invalid";
8398 break;
8399
8400 case MPI_IOCSTATUS_FC_DID_INVALID: /* 0x0068 */
8401 desc = "FC: DID Invalid";
8402 break;
8403
8404 case MPI_IOCSTATUS_FC_NODE_LOGGED_OUT: /* 0x0069 */
8405 desc = "FC: Node Logged Out";
8406 break;
8407
8408 case MPI_IOCSTATUS_FC_EXCHANGE_CANCELED: /* 0x006C */
8409 desc = "FC: Exchange Canceled";
8410 break;
8411
8412/****************************************************************************/
8413/* LAN values */
8414/****************************************************************************/
8415
8416 case MPI_IOCSTATUS_LAN_DEVICE_NOT_FOUND: /* 0x0080 */
8417 desc = "LAN: Device not Found";
8418 break;
8419
8420 case MPI_IOCSTATUS_LAN_DEVICE_FAILURE: /* 0x0081 */
8421 desc = "LAN: Device Failure";
8422 break;
8423
8424 case MPI_IOCSTATUS_LAN_TRANSMIT_ERROR: /* 0x0082 */
8425 desc = "LAN: Transmit Error";
8426 break;
8427
8428 case MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED: /* 0x0083 */
8429 desc = "LAN: Transmit Aborted";
8430 break;
8431
8432 case MPI_IOCSTATUS_LAN_RECEIVE_ERROR: /* 0x0084 */
8433 desc = "LAN: Receive Error";
8434 break;
8435
8436 case MPI_IOCSTATUS_LAN_RECEIVE_ABORTED: /* 0x0085 */
8437 desc = "LAN: Receive Aborted";
8438 break;
8439
8440 case MPI_IOCSTATUS_LAN_PARTIAL_PACKET: /* 0x0086 */
8441 desc = "LAN: Partial Packet";
8442 break;
8443
8444 case MPI_IOCSTATUS_LAN_CANCELED: /* 0x0087 */
8445 desc = "LAN: Canceled";
8446 break;
8447
8448/****************************************************************************/
8449/* Serial Attached SCSI values */
8450/****************************************************************************/
8451
8452 case MPI_IOCSTATUS_SAS_SMP_REQUEST_FAILED: /* 0x0090 */
8453 desc = "SAS: SMP Request Failed";
8454 break;
8455
8456 case MPI_IOCSTATUS_SAS_SMP_DATA_OVERRUN: /* 0x0090 */
8457 desc = "SAS: SMP Data Overrun";
Linus Torvalds1da177e2005-04-16 15:20:36 -07008458 break;
8459
8460 default:
8461 desc = "Others";
8462 break;
8463 }
Eric Moorec6c727a2007-01-29 09:44:54 -07008464
8465 if (!desc)
8466 return;
8467
Eric Moore29dd3602007-09-14 18:46:51 -06008468 dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOCStatus(0x%04X): %s\n",
8469 ioc->name, status, desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07008470}
8471
8472/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04008473EXPORT_SYMBOL(mpt_attach);
8474EXPORT_SYMBOL(mpt_detach);
8475#ifdef CONFIG_PM
8476EXPORT_SYMBOL(mpt_resume);
8477EXPORT_SYMBOL(mpt_suspend);
8478#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07008479EXPORT_SYMBOL(ioc_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008480EXPORT_SYMBOL(mpt_register);
8481EXPORT_SYMBOL(mpt_deregister);
8482EXPORT_SYMBOL(mpt_event_register);
8483EXPORT_SYMBOL(mpt_event_deregister);
8484EXPORT_SYMBOL(mpt_reset_register);
8485EXPORT_SYMBOL(mpt_reset_deregister);
8486EXPORT_SYMBOL(mpt_device_driver_register);
8487EXPORT_SYMBOL(mpt_device_driver_deregister);
8488EXPORT_SYMBOL(mpt_get_msg_frame);
8489EXPORT_SYMBOL(mpt_put_msg_frame);
Prakash, Sathya7a195f42007-08-14 16:08:40 +05308490EXPORT_SYMBOL(mpt_put_msg_frame_hi_pri);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008491EXPORT_SYMBOL(mpt_free_msg_frame);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008492EXPORT_SYMBOL(mpt_send_handshake_request);
8493EXPORT_SYMBOL(mpt_verify_adapter);
8494EXPORT_SYMBOL(mpt_GetIocState);
8495EXPORT_SYMBOL(mpt_print_ioc_summary);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008496EXPORT_SYMBOL(mpt_HardResetHandler);
8497EXPORT_SYMBOL(mpt_config);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008498EXPORT_SYMBOL(mpt_findImVolumes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008499EXPORT_SYMBOL(mpt_alloc_fw_memory);
8500EXPORT_SYMBOL(mpt_free_fw_memory);
Christoph Hellwig82ffb6712005-09-09 16:25:54 +02008501EXPORT_SYMBOL(mptbase_sas_persist_operation);
Eric Mooreb506ade2007-01-29 09:45:37 -07008502EXPORT_SYMBOL(mpt_raid_phys_disk_pg0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008503
Linus Torvalds1da177e2005-04-16 15:20:36 -07008504/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08008505/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008506 * fusion_init - Fusion MPT base driver initialization routine.
8507 *
8508 * Returns 0 for success, non-zero for failure.
8509 */
8510static int __init
8511fusion_init(void)
8512{
Prakash, Sathyaf606f572007-08-14 16:12:53 +05308513 u8 cb_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008514
8515 show_mptmod_ver(my_NAME, my_VERSION);
8516 printk(KERN_INFO COPYRIGHT "\n");
8517
Prakash, Sathyaf606f572007-08-14 16:12:53 +05308518 for (cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
8519 MptCallbacks[cb_idx] = NULL;
8520 MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
8521 MptEvHandlers[cb_idx] = NULL;
8522 MptResetHandlers[cb_idx] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008523 }
8524
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04008525 /* Register ourselves (mptbase) in order to facilitate
Linus Torvalds1da177e2005-04-16 15:20:36 -07008526 * EventNotification handling.
8527 */
Kashyap, Desai213aaca2010-07-26 18:57:36 +05308528 mpt_base_index = mpt_register(mptbase_reply, MPTBASE_DRIVER,
8529 "mptbase_reply");
Linus Torvalds1da177e2005-04-16 15:20:36 -07008530
8531 /* Register for hard reset handling callbacks.
8532 */
Prakash, Sathya436ace72007-07-24 15:42:08 +05308533 mpt_reset_register(mpt_base_index, mpt_ioc_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008534
8535#ifdef CONFIG_PROC_FS
8536 (void) procmpt_create();
8537#endif
Moore, Eric Dean 7fadc872005-04-22 18:01:16 -04008538 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008539}
8540
8541/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Randy Dunlapd9489fb2006-12-06 20:38:43 -08008542/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008543 * fusion_exit - Perform driver unload cleanup.
8544 *
8545 * This routine frees all resources associated with each MPT adapter
8546 * and removes all %MPT_PROCFS_MPTBASEDIR entries.
8547 */
8548static void __exit
8549fusion_exit(void)
8550{
8551
Linus Torvalds1da177e2005-04-16 15:20:36 -07008552 mpt_reset_deregister(mpt_base_index);
8553
8554#ifdef CONFIG_PROC_FS
8555 procmpt_destroy();
8556#endif
8557}
8558
Linus Torvalds1da177e2005-04-16 15:20:36 -07008559module_init(fusion_init);
8560module_exit(fusion_exit);