blob: b2994e2cf01762181bcb5e4b1d209b95ce7a4b14 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ipr.c -- driver for IBM Power Linux RAID adapters
3 *
4 * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
5 *
6 * Copyright (C) 2003, 2004 IBM Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24/*
25 * Notes:
26 *
27 * This driver is used to control the following SCSI adapters:
28 *
29 * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
30 *
31 * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
32 * PCI-X Dual Channel Ultra 320 SCSI Adapter
33 * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
34 * Embedded SCSI adapter on p615 and p655 systems
35 *
36 * Supported Hardware Features:
37 * - Ultra 320 SCSI controller
38 * - PCI-X host interface
39 * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
40 * - Non-Volatile Write Cache
41 * - Supports attachment of non-RAID disks, tape, and optical devices
42 * - RAID Levels 0, 5, 10
43 * - Hot spare
44 * - Background Parity Checking
45 * - Background Data Scrubbing
46 * - Ability to increase the capacity of an existing RAID 5 disk array
47 * by adding disks
48 *
49 * Driver Features:
50 * - Tagged command queuing
51 * - Adapter microcode download
52 * - PCI hot plug
53 * - SCSI device hot plug
54 *
55 */
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include <linux/fs.h>
58#include <linux/init.h>
59#include <linux/types.h>
60#include <linux/errno.h>
61#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090062#include <linux/slab.h>
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -030063#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#include <linux/ioport.h>
65#include <linux/delay.h>
66#include <linux/pci.h>
67#include <linux/wait.h>
68#include <linux/spinlock.h>
69#include <linux/sched.h>
70#include <linux/interrupt.h>
71#include <linux/blkdev.h>
72#include <linux/firmware.h>
73#include <linux/module.h>
74#include <linux/moduleparam.h>
Brian King35a39692006-09-25 12:39:20 -050075#include <linux/libata.h>
Brian King0ce3a7e2008-07-11 13:37:50 -050076#include <linux/hdreg.h>
Wayne Boyerf72919e2010-02-19 13:24:21 -080077#include <linux/reboot.h>
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -080078#include <linux/stringify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#include <asm/io.h>
80#include <asm/irq.h>
81#include <asm/processor.h>
82#include <scsi/scsi.h>
83#include <scsi/scsi_host.h>
84#include <scsi/scsi_tcq.h>
85#include <scsi/scsi_eh.h>
86#include <scsi/scsi_cmnd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#include "ipr.h"
88
89/*
90 * Global Data
91 */
Denis Chengb7d68ca2007-12-13 16:14:27 -080092static LIST_HEAD(ipr_ioa_head);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
94static unsigned int ipr_max_speed = 1;
95static int ipr_testmode = 0;
96static unsigned int ipr_fastfail = 0;
Brian King5469cb52007-03-29 12:42:40 -050097static unsigned int ipr_transop_timeout = 0;
brking@us.ibm.comd3c74872005-11-01 17:01:34 -060098static unsigned int ipr_debug = 0;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -080099static unsigned int ipr_max_devs = IPR_DEFAULT_SIS64_DEVS;
Brian Kingac09c342007-04-26 16:00:16 -0500100static unsigned int ipr_dual_ioa_raid = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static DEFINE_SPINLOCK(ipr_driver_lock);
102
103/* This table describes the differences between DMA controller chips */
104static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
Brian King60e74862006-11-21 10:28:10 -0600105 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 .mailbox = 0x0042C,
Brian King89aad422012-03-14 21:20:10 -0500107 .max_cmds = 100,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 .cache_line_size = 0x20,
Brian King7dd21302012-03-14 21:20:08 -0500109 .clear_isr = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 {
111 .set_interrupt_mask_reg = 0x0022C,
112 .clr_interrupt_mask_reg = 0x00230,
Wayne Boyer214777b2010-02-19 13:24:26 -0800113 .clr_interrupt_mask_reg32 = 0x00230,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 .sense_interrupt_mask_reg = 0x0022C,
Wayne Boyer214777b2010-02-19 13:24:26 -0800115 .sense_interrupt_mask_reg32 = 0x0022C,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 .clr_interrupt_reg = 0x00228,
Wayne Boyer214777b2010-02-19 13:24:26 -0800117 .clr_interrupt_reg32 = 0x00228,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .sense_interrupt_reg = 0x00224,
Wayne Boyer214777b2010-02-19 13:24:26 -0800119 .sense_interrupt_reg32 = 0x00224,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .ioarrin_reg = 0x00404,
121 .sense_uproc_interrupt_reg = 0x00214,
Wayne Boyer214777b2010-02-19 13:24:26 -0800122 .sense_uproc_interrupt_reg32 = 0x00214,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .set_uproc_interrupt_reg = 0x00214,
Wayne Boyer214777b2010-02-19 13:24:26 -0800124 .set_uproc_interrupt_reg32 = 0x00214,
125 .clr_uproc_interrupt_reg = 0x00218,
126 .clr_uproc_interrupt_reg32 = 0x00218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128 },
129 { /* Snipe and Scamp */
130 .mailbox = 0x0052C,
Brian King89aad422012-03-14 21:20:10 -0500131 .max_cmds = 100,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 .cache_line_size = 0x20,
Brian King7dd21302012-03-14 21:20:08 -0500133 .clear_isr = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 {
135 .set_interrupt_mask_reg = 0x00288,
136 .clr_interrupt_mask_reg = 0x0028C,
Wayne Boyer214777b2010-02-19 13:24:26 -0800137 .clr_interrupt_mask_reg32 = 0x0028C,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 .sense_interrupt_mask_reg = 0x00288,
Wayne Boyer214777b2010-02-19 13:24:26 -0800139 .sense_interrupt_mask_reg32 = 0x00288,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 .clr_interrupt_reg = 0x00284,
Wayne Boyer214777b2010-02-19 13:24:26 -0800141 .clr_interrupt_reg32 = 0x00284,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 .sense_interrupt_reg = 0x00280,
Wayne Boyer214777b2010-02-19 13:24:26 -0800143 .sense_interrupt_reg32 = 0x00280,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 .ioarrin_reg = 0x00504,
145 .sense_uproc_interrupt_reg = 0x00290,
Wayne Boyer214777b2010-02-19 13:24:26 -0800146 .sense_uproc_interrupt_reg32 = 0x00290,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 .set_uproc_interrupt_reg = 0x00290,
Wayne Boyer214777b2010-02-19 13:24:26 -0800148 .set_uproc_interrupt_reg32 = 0x00290,
149 .clr_uproc_interrupt_reg = 0x00294,
150 .clr_uproc_interrupt_reg32 = 0x00294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
152 },
Wayne Boyera74c1632010-02-19 13:23:51 -0800153 { /* CRoC */
Wayne Boyer110def82010-11-04 09:36:16 -0700154 .mailbox = 0x00044,
Brian King89aad422012-03-14 21:20:10 -0500155 .max_cmds = 1000,
Wayne Boyera74c1632010-02-19 13:23:51 -0800156 .cache_line_size = 0x20,
Brian King7dd21302012-03-14 21:20:08 -0500157 .clear_isr = 0,
Wayne Boyera74c1632010-02-19 13:23:51 -0800158 {
159 .set_interrupt_mask_reg = 0x00010,
160 .clr_interrupt_mask_reg = 0x00018,
Wayne Boyer214777b2010-02-19 13:24:26 -0800161 .clr_interrupt_mask_reg32 = 0x0001C,
Wayne Boyera74c1632010-02-19 13:23:51 -0800162 .sense_interrupt_mask_reg = 0x00010,
Wayne Boyer214777b2010-02-19 13:24:26 -0800163 .sense_interrupt_mask_reg32 = 0x00014,
Wayne Boyera74c1632010-02-19 13:23:51 -0800164 .clr_interrupt_reg = 0x00008,
Wayne Boyer214777b2010-02-19 13:24:26 -0800165 .clr_interrupt_reg32 = 0x0000C,
Wayne Boyera74c1632010-02-19 13:23:51 -0800166 .sense_interrupt_reg = 0x00000,
Wayne Boyer214777b2010-02-19 13:24:26 -0800167 .sense_interrupt_reg32 = 0x00004,
Wayne Boyera74c1632010-02-19 13:23:51 -0800168 .ioarrin_reg = 0x00070,
169 .sense_uproc_interrupt_reg = 0x00020,
Wayne Boyer214777b2010-02-19 13:24:26 -0800170 .sense_uproc_interrupt_reg32 = 0x00024,
Wayne Boyera74c1632010-02-19 13:23:51 -0800171 .set_uproc_interrupt_reg = 0x00020,
Wayne Boyer214777b2010-02-19 13:24:26 -0800172 .set_uproc_interrupt_reg32 = 0x00024,
Wayne Boyerdcbad002010-02-19 13:24:14 -0800173 .clr_uproc_interrupt_reg = 0x00028,
Wayne Boyer214777b2010-02-19 13:24:26 -0800174 .clr_uproc_interrupt_reg32 = 0x0002C,
175 .init_feedback_reg = 0x0005C,
Wayne Boyerdcbad002010-02-19 13:24:14 -0800176 .dump_addr_reg = 0x00064,
Wayne Boyer8701f182010-06-04 10:26:50 -0700177 .dump_data_reg = 0x00068,
178 .endian_swap_reg = 0x00084
Wayne Boyera74c1632010-02-19 13:23:51 -0800179 }
180 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181};
182
183static const struct ipr_chip_t ipr_chip[] = {
Wayne Boyercb237ef2010-06-17 11:51:40 -0700184 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
185 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
186 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
187 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
188 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, IPR_USE_MSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
189 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
190 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
191 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
Wayne Boyercd9b3d02012-02-23 11:54:55 -0800192 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193};
194
195static int ipr_max_bus_speeds [] = {
196 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
197};
198
199MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
200MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
201module_param_named(max_speed, ipr_max_speed, uint, 0);
202MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
203module_param_named(log_level, ipr_log_level, uint, 0);
204MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
205module_param_named(testmode, ipr_testmode, int, 0);
206MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
Wayne Boyer2cf22be2009-02-24 11:36:00 -0800207module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
209module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
210MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
Wayne Boyer2cf22be2009-02-24 11:36:00 -0800211module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
brking@us.ibm.comd3c74872005-11-01 17:01:34 -0600212MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
Brian Kingac09c342007-04-26 16:00:16 -0500213module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
214MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -0800215module_param_named(max_devs, ipr_max_devs, int, 0);
216MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
217 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218MODULE_LICENSE("GPL");
219MODULE_VERSION(IPR_DRIVER_VERSION);
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/* A constant array of IOASCs/URCs/Error Messages */
222static const
223struct ipr_error_table_t ipr_error_table[] = {
Brian King933916f2007-03-29 12:43:30 -0500224 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 "8155: An unknown error was received"},
226 {0x00330000, 0, 0,
227 "Soft underlength error"},
228 {0x005A0000, 0, 0,
229 "Command to be cancelled not found"},
230 {0x00808000, 0, 0,
231 "Qualified success"},
Brian King933916f2007-03-29 12:43:30 -0500232 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 "FFFE: Soft device bus error recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500234 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500235 "4101: Soft device bus fabric error"},
Wayne Boyer5aa3a332010-02-19 13:24:32 -0800236 {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
237 "FFFC: Logical block guard error recovered by the device"},
238 {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
239 "FFFC: Logical block reference tag error recovered by the device"},
240 {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
241 "4171: Recovered scatter list tag / sequence number error"},
242 {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
243 "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
244 {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
245 "4171: Recovered logical block sequence number error on IOA to Host transfer"},
246 {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
247 "FFFD: Recovered logical block reference tag error detected by the IOA"},
248 {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
249 "FFFD: Logical block guard error recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500250 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 "FFF9: Device sector reassign successful"},
Brian King933916f2007-03-29 12:43:30 -0500252 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 "FFF7: Media error recovered by device rewrite procedures"},
Brian King933916f2007-03-29 12:43:30 -0500254 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 "7001: IOA sector reassignment successful"},
Brian King933916f2007-03-29 12:43:30 -0500256 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 "FFF9: Soft media error. Sector reassignment recommended"},
Brian King933916f2007-03-29 12:43:30 -0500258 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 "FFF7: Media error recovered by IOA rewrite procedures"},
Brian King933916f2007-03-29 12:43:30 -0500260 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 "FF3D: Soft PCI bus error recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500262 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 "FFF6: Device hardware error recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500264 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 "FFF6: Device hardware error recovered by the device"},
Brian King933916f2007-03-29 12:43:30 -0500266 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 "FF3D: Soft IOA error recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500268 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 "FFFA: Undefined device response recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500270 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 "FFF6: Device bus error, message or command phase"},
Brian King933916f2007-03-29 12:43:30 -0500272 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King35a39692006-09-25 12:39:20 -0500273 "FFFE: Task Management Function failed"},
Brian King933916f2007-03-29 12:43:30 -0500274 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 "FFF6: Failure prediction threshold exceeded"},
Brian King933916f2007-03-29 12:43:30 -0500276 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 "8009: Impending cache battery pack failure"},
278 {0x02040400, 0, 0,
279 "34FF: Disk device format in progress"},
Brian King65f56472007-04-26 16:00:12 -0500280 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
281 "9070: IOA requested reset"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 {0x023F0000, 0, 0,
283 "Synchronization required"},
284 {0x024E0000, 0, 0,
285 "No ready, IOA shutdown"},
286 {0x025A0000, 0, 0,
287 "Not ready, IOA has been shutdown"},
Brian King933916f2007-03-29 12:43:30 -0500288 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 "3020: Storage subsystem configuration error"},
290 {0x03110B00, 0, 0,
291 "FFF5: Medium error, data unreadable, recommend reassign"},
292 {0x03110C00, 0, 0,
293 "7000: Medium error, data unreadable, do not reassign"},
Brian King933916f2007-03-29 12:43:30 -0500294 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 "FFF3: Disk media format bad"},
Brian King933916f2007-03-29 12:43:30 -0500296 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 "3002: Addressed device failed to respond to selection"},
Brian King933916f2007-03-29 12:43:30 -0500298 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 "3100: Device bus error"},
Brian King933916f2007-03-29 12:43:30 -0500300 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 "3109: IOA timed out a device command"},
302 {0x04088000, 0, 0,
303 "3120: SCSI bus is not operational"},
Brian King933916f2007-03-29 12:43:30 -0500304 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500305 "4100: Hard device bus fabric error"},
Wayne Boyer5aa3a332010-02-19 13:24:32 -0800306 {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
307 "310C: Logical block guard error detected by the device"},
308 {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
309 "310C: Logical block reference tag error detected by the device"},
310 {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
311 "4170: Scatter list tag / sequence number error"},
312 {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
313 "8150: Logical block CRC error on IOA to Host transfer"},
314 {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
315 "4170: Logical block sequence number error on IOA to Host transfer"},
316 {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
317 "310D: Logical block reference tag error detected by the IOA"},
318 {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
319 "310D: Logical block guard error detected by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500320 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 "9000: IOA reserved area data check"},
Brian King933916f2007-03-29 12:43:30 -0500322 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 "9001: IOA reserved area invalid data pattern"},
Brian King933916f2007-03-29 12:43:30 -0500324 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 "9002: IOA reserved area LRC error"},
Wayne Boyer5aa3a332010-02-19 13:24:32 -0800326 {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
327 "Hardware Error, IOA metadata access error"},
Brian King933916f2007-03-29 12:43:30 -0500328 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 "102E: Out of alternate sectors for disk storage"},
Brian King933916f2007-03-29 12:43:30 -0500330 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 "FFF4: Data transfer underlength error"},
Brian King933916f2007-03-29 12:43:30 -0500332 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 "FFF4: Data transfer overlength error"},
Brian King933916f2007-03-29 12:43:30 -0500334 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 "3400: Logical unit failure"},
Brian King933916f2007-03-29 12:43:30 -0500336 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 "FFF4: Device microcode is corrupt"},
Brian King933916f2007-03-29 12:43:30 -0500338 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 "8150: PCI bus error"},
340 {0x04430000, 1, 0,
341 "Unsupported device bus message received"},
Brian King933916f2007-03-29 12:43:30 -0500342 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 "FFF4: Disk device problem"},
Brian King933916f2007-03-29 12:43:30 -0500344 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 "8150: Permanent IOA failure"},
Brian King933916f2007-03-29 12:43:30 -0500346 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 "3010: Disk device returned wrong response to IOA"},
Brian King933916f2007-03-29 12:43:30 -0500348 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 "8151: IOA microcode error"},
350 {0x04448500, 0, 0,
351 "Device bus status error"},
Brian King933916f2007-03-29 12:43:30 -0500352 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 "8157: IOA error requiring IOA reset to recover"},
Brian King35a39692006-09-25 12:39:20 -0500354 {0x04448700, 0, 0,
355 "ATA device status error"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 {0x04490000, 0, 0,
357 "Message reject received from the device"},
Brian King933916f2007-03-29 12:43:30 -0500358 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 "8008: A permanent cache battery pack failure occurred"},
Brian King933916f2007-03-29 12:43:30 -0500360 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 "9090: Disk unit has been modified after the last known status"},
Brian King933916f2007-03-29 12:43:30 -0500362 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 "9081: IOA detected device error"},
Brian King933916f2007-03-29 12:43:30 -0500364 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 "9082: IOA detected device error"},
Brian King933916f2007-03-29 12:43:30 -0500366 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 "3110: Device bus error, message or command phase"},
Brian King933916f2007-03-29 12:43:30 -0500368 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
Brian King35a39692006-09-25 12:39:20 -0500369 "3110: SAS Command / Task Management Function failed"},
Brian King933916f2007-03-29 12:43:30 -0500370 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 "9091: Incorrect hardware configuration change has been detected"},
Brian King933916f2007-03-29 12:43:30 -0500372 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600373 "9073: Invalid multi-adapter configuration"},
Brian King933916f2007-03-29 12:43:30 -0500374 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500375 "4010: Incorrect connection between cascaded expanders"},
Brian King933916f2007-03-29 12:43:30 -0500376 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500377 "4020: Connections exceed IOA design limits"},
Brian King933916f2007-03-29 12:43:30 -0500378 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500379 "4030: Incorrect multipath connection"},
Brian King933916f2007-03-29 12:43:30 -0500380 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500381 "4110: Unsupported enclosure function"},
Brian King933916f2007-03-29 12:43:30 -0500382 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 "FFF4: Command to logical unit failed"},
384 {0x05240000, 1, 0,
385 "Illegal request, invalid request type or request packet"},
386 {0x05250000, 0, 0,
387 "Illegal request, invalid resource handle"},
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600388 {0x05258000, 0, 0,
389 "Illegal request, commands not allowed to this device"},
390 {0x05258100, 0, 0,
391 "Illegal request, command not allowed to a secondary adapter"},
Wayne Boyer5aa3a332010-02-19 13:24:32 -0800392 {0x05258200, 0, 0,
393 "Illegal request, command not allowed to a non-optimized resource"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 {0x05260000, 0, 0,
395 "Illegal request, invalid field in parameter list"},
396 {0x05260100, 0, 0,
397 "Illegal request, parameter not supported"},
398 {0x05260200, 0, 0,
399 "Illegal request, parameter value invalid"},
400 {0x052C0000, 0, 0,
401 "Illegal request, command sequence error"},
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600402 {0x052C8000, 1, 0,
403 "Illegal request, dual adapter support not enabled"},
Brian King933916f2007-03-29 12:43:30 -0500404 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 "9031: Array protection temporarily suspended, protection resuming"},
Brian King933916f2007-03-29 12:43:30 -0500406 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 "9040: Array protection temporarily suspended, protection resuming"},
Brian King933916f2007-03-29 12:43:30 -0500408 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500409 "3140: Device bus not ready to ready transition"},
Brian King933916f2007-03-29 12:43:30 -0500410 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 "FFFB: SCSI bus was reset"},
412 {0x06290500, 0, 0,
413 "FFFE: SCSI bus transition to single ended"},
414 {0x06290600, 0, 0,
415 "FFFE: SCSI bus transition to LVD"},
Brian King933916f2007-03-29 12:43:30 -0500416 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 "FFFB: SCSI bus was reset by another initiator"},
Brian King933916f2007-03-29 12:43:30 -0500418 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 "3029: A device replacement has occurred"},
Brian King933916f2007-03-29 12:43:30 -0500420 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 "9051: IOA cache data exists for a missing or failed device"},
Brian King933916f2007-03-29 12:43:30 -0500422 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600423 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
Brian King933916f2007-03-29 12:43:30 -0500424 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 "9025: Disk unit is not supported at its physical location"},
Brian King933916f2007-03-29 12:43:30 -0500426 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 "3020: IOA detected a SCSI bus configuration error"},
Brian King933916f2007-03-29 12:43:30 -0500428 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 "3150: SCSI bus configuration error"},
Brian King933916f2007-03-29 12:43:30 -0500430 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600431 "9074: Asymmetric advanced function disk configuration"},
Brian King933916f2007-03-29 12:43:30 -0500432 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500433 "4040: Incomplete multipath connection between IOA and enclosure"},
Brian King933916f2007-03-29 12:43:30 -0500434 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500435 "4041: Incomplete multipath connection between enclosure and device"},
Brian King933916f2007-03-29 12:43:30 -0500436 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500437 "9075: Incomplete multipath connection between IOA and remote IOA"},
Brian King933916f2007-03-29 12:43:30 -0500438 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500439 "9076: Configuration error, missing remote IOA"},
Brian King933916f2007-03-29 12:43:30 -0500440 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500441 "4050: Enclosure does not support a required multipath function"},
Wayne Boyerb75424f2009-01-28 08:24:50 -0800442 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
443 "4070: Logically bad block written on device"},
Brian King933916f2007-03-29 12:43:30 -0500444 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 "9041: Array protection temporarily suspended"},
Brian King933916f2007-03-29 12:43:30 -0500446 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 "9042: Corrupt array parity detected on specified device"},
Brian King933916f2007-03-29 12:43:30 -0500448 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 "9030: Array no longer protected due to missing or failed disk unit"},
Brian King933916f2007-03-29 12:43:30 -0500450 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600451 "9071: Link operational transition"},
Brian King933916f2007-03-29 12:43:30 -0500452 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600453 "9072: Link not operational transition"},
Brian King933916f2007-03-29 12:43:30 -0500454 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 "9032: Array exposed but still protected"},
Brian Kinge4353402007-03-29 12:43:37 -0500456 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
457 "70DD: Device forced failed by disrupt device command"},
Brian King933916f2007-03-29 12:43:30 -0500458 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500459 "4061: Multipath redundancy level got better"},
Brian King933916f2007-03-29 12:43:30 -0500460 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500461 "4060: Multipath redundancy level got worse"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 {0x07270000, 0, 0,
463 "Failure due to other device"},
Brian King933916f2007-03-29 12:43:30 -0500464 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 "9008: IOA does not support functions expected by devices"},
Brian King933916f2007-03-29 12:43:30 -0500466 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 "9010: Cache data associated with attached devices cannot be found"},
Brian King933916f2007-03-29 12:43:30 -0500468 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 "9011: Cache data belongs to devices other than those attached"},
Brian King933916f2007-03-29 12:43:30 -0500470 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 "9020: Array missing 2 or more devices with only 1 device present"},
Brian King933916f2007-03-29 12:43:30 -0500472 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 "9021: Array missing 2 or more devices with 2 or more devices present"},
Brian King933916f2007-03-29 12:43:30 -0500474 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 "9022: Exposed array is missing a required device"},
Brian King933916f2007-03-29 12:43:30 -0500476 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 "9023: Array member(s) not at required physical locations"},
Brian King933916f2007-03-29 12:43:30 -0500478 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 "9024: Array not functional due to present hardware configuration"},
Brian King933916f2007-03-29 12:43:30 -0500480 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 "9026: Array not functional due to present hardware configuration"},
Brian King933916f2007-03-29 12:43:30 -0500482 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 "9027: Array is missing a device and parity is out of sync"},
Brian King933916f2007-03-29 12:43:30 -0500484 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 "9028: Maximum number of arrays already exist"},
Brian King933916f2007-03-29 12:43:30 -0500486 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 "9050: Required cache data cannot be located for a disk unit"},
Brian King933916f2007-03-29 12:43:30 -0500488 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 "9052: Cache data exists for a device that has been modified"},
Brian King933916f2007-03-29 12:43:30 -0500490 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 "9054: IOA resources not available due to previous problems"},
Brian King933916f2007-03-29 12:43:30 -0500492 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 "9092: Disk unit requires initialization before use"},
Brian King933916f2007-03-29 12:43:30 -0500494 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 "9029: Incorrect hardware configuration change has been detected"},
Brian King933916f2007-03-29 12:43:30 -0500496 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 "9060: One or more disk pairs are missing from an array"},
Brian King933916f2007-03-29 12:43:30 -0500498 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 "9061: One or more disks are missing from an array"},
Brian King933916f2007-03-29 12:43:30 -0500500 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 "9062: One or more disks are missing from an array"},
Brian King933916f2007-03-29 12:43:30 -0500502 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 "9063: Maximum number of functional arrays has been exceeded"},
504 {0x0B260000, 0, 0,
505 "Aborted command, invalid descriptor"},
506 {0x0B5A0000, 0, 0,
507 "Command terminated by host"}
508};
509
510static const struct ipr_ses_table_entry ipr_ses_table[] = {
511 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
512 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
513 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
514 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
515 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
516 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
517 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
518 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
519 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
520 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
521 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
522 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
523 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
524};
525
526/*
527 * Function Prototypes
528 */
529static int ipr_reset_alert(struct ipr_cmnd *);
530static void ipr_process_ccn(struct ipr_cmnd *);
531static void ipr_process_error(struct ipr_cmnd *);
532static void ipr_reset_ioa_job(struct ipr_cmnd *);
533static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
534 enum ipr_shutdown_type);
535
536#ifdef CONFIG_SCSI_IPR_TRACE
537/**
538 * ipr_trc_hook - Add a trace entry to the driver trace
539 * @ipr_cmd: ipr command struct
540 * @type: trace type
541 * @add_data: additional data
542 *
543 * Return value:
544 * none
545 **/
546static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
547 u8 type, u32 add_data)
548{
549 struct ipr_trace_entry *trace_entry;
550 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
551
552 trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
553 trace_entry->time = jiffies;
554 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
555 trace_entry->type = type;
Wayne Boyera32c0552010-02-19 13:23:36 -0800556 if (ipr_cmd->ioa_cfg->sis64)
557 trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
558 else
559 trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
Brian King35a39692006-09-25 12:39:20 -0500560 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
562 trace_entry->u.add_data = add_data;
563}
564#else
565#define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
566#endif
567
568/**
569 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
570 * @ipr_cmd: ipr command struct
571 *
572 * Return value:
573 * none
574 **/
575static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
576{
577 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -0700578 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
579 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
Wayne Boyera32c0552010-02-19 13:23:36 -0800580 dma_addr_t dma_addr = ipr_cmd->dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
582 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
Wayne Boyera32c0552010-02-19 13:23:36 -0800583 ioarcb->data_transfer_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 ioarcb->read_data_transfer_length = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -0800585 ioarcb->ioadl_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 ioarcb->read_ioadl_len = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -0800587
Wayne Boyer96d21f02010-05-10 09:13:27 -0700588 if (ipr_cmd->ioa_cfg->sis64) {
Wayne Boyera32c0552010-02-19 13:23:36 -0800589 ioarcb->u.sis64_addr_data.data_ioadl_addr =
590 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
Wayne Boyer96d21f02010-05-10 09:13:27 -0700591 ioasa64->u.gata.status = 0;
592 } else {
Wayne Boyera32c0552010-02-19 13:23:36 -0800593 ioarcb->write_ioadl_addr =
594 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
595 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
Wayne Boyer96d21f02010-05-10 09:13:27 -0700596 ioasa->u.gata.status = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -0800597 }
598
Wayne Boyer96d21f02010-05-10 09:13:27 -0700599 ioasa->hdr.ioasc = 0;
600 ioasa->hdr.residual_data_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 ipr_cmd->scsi_cmd = NULL;
Brian King35a39692006-09-25 12:39:20 -0500602 ipr_cmd->qc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 ipr_cmd->sense_buffer[0] = 0;
604 ipr_cmd->dma_use_sg = 0;
605}
606
607/**
608 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
609 * @ipr_cmd: ipr command struct
610 *
611 * Return value:
612 * none
613 **/
614static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
615{
616 ipr_reinit_ipr_cmnd(ipr_cmd);
617 ipr_cmd->u.scratch = 0;
618 ipr_cmd->sibling = NULL;
619 init_timer(&ipr_cmd->timer);
620}
621
622/**
Brian King00bfef22012-07-17 08:13:52 -0500623 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 * @ioa_cfg: ioa config struct
625 *
626 * Return value:
627 * pointer to ipr command struct
628 **/
629static
Brian King00bfef22012-07-17 08:13:52 -0500630struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631{
632 struct ipr_cmnd *ipr_cmd;
633
634 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
635 list_del(&ipr_cmd->queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 return ipr_cmd;
638}
639
640/**
Brian King00bfef22012-07-17 08:13:52 -0500641 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
642 * @ioa_cfg: ioa config struct
643 *
644 * Return value:
645 * pointer to ipr command struct
646 **/
647static
648struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
649{
650 struct ipr_cmnd *ipr_cmd = __ipr_get_free_ipr_cmnd(ioa_cfg);
651 ipr_init_ipr_cmnd(ipr_cmd);
652 return ipr_cmd;
653}
654
655/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
657 * @ioa_cfg: ioa config struct
658 * @clr_ints: interrupts to clear
659 *
660 * This function masks all interrupts on the adapter, then clears the
661 * interrupts specified in the mask
662 *
663 * Return value:
664 * none
665 **/
666static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
667 u32 clr_ints)
668{
669 volatile u32 int_reg;
670
671 /* Stop new interrupts */
672 ioa_cfg->allow_interrupts = 0;
673
674 /* Set interrupt mask to stop all new interrupts */
Wayne Boyer214777b2010-02-19 13:24:26 -0800675 if (ioa_cfg->sis64)
676 writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
677 else
678 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680 /* Clear any pending interrupts */
Wayne Boyer214777b2010-02-19 13:24:26 -0800681 if (ioa_cfg->sis64)
682 writel(~0, ioa_cfg->regs.clr_interrupt_reg);
683 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
685}
686
687/**
688 * ipr_save_pcix_cmd_reg - Save PCI-X command register
689 * @ioa_cfg: ioa config struct
690 *
691 * Return value:
692 * 0 on success / -EIO on failure
693 **/
694static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
695{
696 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
697
Brian King7dce0e12007-01-23 11:25:30 -0600698 if (pcix_cmd_reg == 0)
699 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
701 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
702 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
703 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
704 return -EIO;
705 }
706
707 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
708 return 0;
709}
710
711/**
712 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
713 * @ioa_cfg: ioa config struct
714 *
715 * Return value:
716 * 0 on success / -EIO on failure
717 **/
718static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
719{
720 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
721
722 if (pcix_cmd_reg) {
723 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
724 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
725 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
726 return -EIO;
727 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 }
729
730 return 0;
731}
732
733/**
Brian King35a39692006-09-25 12:39:20 -0500734 * ipr_sata_eh_done - done function for aborted SATA commands
735 * @ipr_cmd: ipr command struct
736 *
737 * This function is invoked for ops generated to SATA
738 * devices which are being aborted.
739 *
740 * Return value:
741 * none
742 **/
743static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
744{
745 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
746 struct ata_queued_cmd *qc = ipr_cmd->qc;
747 struct ipr_sata_port *sata_port = qc->ap->private_data;
748
749 qc->err_mask |= AC_ERR_OTHER;
750 sata_port->ioasa.status |= ATA_BUSY;
751 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
752 ata_qc_complete(qc);
753}
754
755/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 * ipr_scsi_eh_done - mid-layer done function for aborted ops
757 * @ipr_cmd: ipr command struct
758 *
759 * This function is invoked by the interrupt handler for
760 * ops generated by the SCSI mid-layer which are being aborted.
761 *
762 * Return value:
763 * none
764 **/
765static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
766{
767 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
768 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
769
770 scsi_cmd->result |= (DID_ERROR << 16);
771
FUJITA Tomonori63015bc2007-05-26 00:26:59 +0900772 scsi_dma_unmap(ipr_cmd->scsi_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 scsi_cmd->scsi_done(scsi_cmd);
774 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
775}
776
777/**
778 * ipr_fail_all_ops - Fails all outstanding ops.
779 * @ioa_cfg: ioa config struct
780 *
781 * This function fails all outstanding ops.
782 *
783 * Return value:
784 * none
785 **/
786static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
787{
788 struct ipr_cmnd *ipr_cmd, *temp;
789
790 ENTER;
791 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
792 list_del(&ipr_cmd->queue);
793
Wayne Boyer96d21f02010-05-10 09:13:27 -0700794 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
795 ipr_cmd->s.ioasa.hdr.ilid = cpu_to_be32(IPR_DRIVER_ILID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 if (ipr_cmd->scsi_cmd)
798 ipr_cmd->done = ipr_scsi_eh_done;
Brian King35a39692006-09-25 12:39:20 -0500799 else if (ipr_cmd->qc)
800 ipr_cmd->done = ipr_sata_eh_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
803 del_timer(&ipr_cmd->timer);
804 ipr_cmd->done(ipr_cmd);
805 }
806
807 LEAVE;
808}
809
810/**
Wayne Boyera32c0552010-02-19 13:23:36 -0800811 * ipr_send_command - Send driver initiated requests.
812 * @ipr_cmd: ipr command struct
813 *
814 * This function sends a command to the adapter using the correct write call.
815 * In the case of sis64, calculate the ioarcb size required. Then or in the
816 * appropriate bits.
817 *
818 * Return value:
819 * none
820 **/
821static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
822{
823 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
824 dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
825
826 if (ioa_cfg->sis64) {
827 /* The default size is 256 bytes */
828 send_dma_addr |= 0x1;
829
830 /* If the number of ioadls * size of ioadl > 128 bytes,
831 then use a 512 byte ioarcb */
832 if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
833 send_dma_addr |= 0x4;
834 writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
835 } else
836 writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
837}
838
839/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 * ipr_do_req - Send driver initiated requests.
841 * @ipr_cmd: ipr command struct
842 * @done: done function
843 * @timeout_func: timeout function
844 * @timeout: timeout value
845 *
846 * This function sends the specified command to the adapter with the
847 * timeout given. The done function is invoked on command completion.
848 *
849 * Return value:
850 * none
851 **/
852static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
853 void (*done) (struct ipr_cmnd *),
854 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
855{
856 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
857
858 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
859
860 ipr_cmd->done = done;
861
862 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
863 ipr_cmd->timer.expires = jiffies + timeout;
864 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
865
866 add_timer(&ipr_cmd->timer);
867
868 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
869
Wayne Boyera32c0552010-02-19 13:23:36 -0800870 ipr_send_command(ipr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871}
872
873/**
874 * ipr_internal_cmd_done - Op done function for an internally generated op.
875 * @ipr_cmd: ipr command struct
876 *
877 * This function is the op done function for an internally generated,
878 * blocking op. It simply wakes the sleeping thread.
879 *
880 * Return value:
881 * none
882 **/
883static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
884{
885 if (ipr_cmd->sibling)
886 ipr_cmd->sibling = NULL;
887 else
888 complete(&ipr_cmd->completion);
889}
890
891/**
Wayne Boyera32c0552010-02-19 13:23:36 -0800892 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
893 * @ipr_cmd: ipr command struct
894 * @dma_addr: dma address
895 * @len: transfer length
896 * @flags: ioadl flag value
897 *
898 * This function initializes an ioadl in the case where there is only a single
899 * descriptor.
900 *
901 * Return value:
902 * nothing
903 **/
904static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
905 u32 len, int flags)
906{
907 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
908 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
909
910 ipr_cmd->dma_use_sg = 1;
911
912 if (ipr_cmd->ioa_cfg->sis64) {
913 ioadl64->flags = cpu_to_be32(flags);
914 ioadl64->data_len = cpu_to_be32(len);
915 ioadl64->address = cpu_to_be64(dma_addr);
916
917 ipr_cmd->ioarcb.ioadl_len =
918 cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
919 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
920 } else {
921 ioadl->flags_and_data_len = cpu_to_be32(flags | len);
922 ioadl->address = cpu_to_be32(dma_addr);
923
924 if (flags == IPR_IOADL_FLAGS_READ_LAST) {
925 ipr_cmd->ioarcb.read_ioadl_len =
926 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
927 ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
928 } else {
929 ipr_cmd->ioarcb.ioadl_len =
930 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
931 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
932 }
933 }
934}
935
936/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 * ipr_send_blocking_cmd - Send command and sleep on its completion.
938 * @ipr_cmd: ipr command struct
939 * @timeout_func: function to invoke if command times out
940 * @timeout: timeout
941 *
942 * Return value:
943 * none
944 **/
945static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
946 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
947 u32 timeout)
948{
949 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
950
951 init_completion(&ipr_cmd->completion);
952 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
953
954 spin_unlock_irq(ioa_cfg->host->host_lock);
955 wait_for_completion(&ipr_cmd->completion);
956 spin_lock_irq(ioa_cfg->host->host_lock);
957}
958
959/**
960 * ipr_send_hcam - Send an HCAM to the adapter.
961 * @ioa_cfg: ioa config struct
962 * @type: HCAM type
963 * @hostrcb: hostrcb struct
964 *
965 * This function will send a Host Controlled Async command to the adapter.
966 * If HCAMs are currently not allowed to be issued to the adapter, it will
967 * place the hostrcb on the free queue.
968 *
969 * Return value:
970 * none
971 **/
972static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
973 struct ipr_hostrcb *hostrcb)
974{
975 struct ipr_cmnd *ipr_cmd;
976 struct ipr_ioarcb *ioarcb;
977
978 if (ioa_cfg->allow_cmds) {
979 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
980 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
981 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
982
983 ipr_cmd->u.hostrcb = hostrcb;
984 ioarcb = &ipr_cmd->ioarcb;
985
986 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
987 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
988 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
989 ioarcb->cmd_pkt.cdb[1] = type;
990 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
991 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
992
Wayne Boyera32c0552010-02-19 13:23:36 -0800993 ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
994 sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
996 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
997 ipr_cmd->done = ipr_process_ccn;
998 else
999 ipr_cmd->done = ipr_process_error;
1000
1001 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
1002
Wayne Boyera32c0552010-02-19 13:23:36 -08001003 ipr_send_command(ipr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 } else {
1005 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
1006 }
1007}
1008
1009/**
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001010 * ipr_update_ata_class - Update the ata class in the resource entry
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 * @res: resource entry struct
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001012 * @proto: cfgte device bus protocol value
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 *
1014 * Return value:
1015 * none
1016 **/
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001017static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001019 switch(proto) {
1020 case IPR_PROTO_SATA:
1021 case IPR_PROTO_SAS_STP:
1022 res->ata_class = ATA_DEV_ATA;
1023 break;
1024 case IPR_PROTO_SATA_ATAPI:
1025 case IPR_PROTO_SAS_STP_ATAPI:
1026 res->ata_class = ATA_DEV_ATAPI;
1027 break;
1028 default:
1029 res->ata_class = ATA_DEV_UNKNOWN;
1030 break;
1031 };
1032}
1033
1034/**
1035 * ipr_init_res_entry - Initialize a resource entry struct.
1036 * @res: resource entry struct
1037 * @cfgtew: config table entry wrapper struct
1038 *
1039 * Return value:
1040 * none
1041 **/
1042static void ipr_init_res_entry(struct ipr_resource_entry *res,
1043 struct ipr_config_table_entry_wrapper *cfgtew)
1044{
1045 int found = 0;
1046 unsigned int proto;
1047 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1048 struct ipr_resource_entry *gscsi_res = NULL;
1049
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06001050 res->needs_sync_complete = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 res->in_erp = 0;
1052 res->add_to_ml = 0;
1053 res->del_from_ml = 0;
1054 res->resetting_device = 0;
1055 res->sdev = NULL;
Brian King35a39692006-09-25 12:39:20 -05001056 res->sata_port = NULL;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001057
1058 if (ioa_cfg->sis64) {
1059 proto = cfgtew->u.cfgte64->proto;
1060 res->res_flags = cfgtew->u.cfgte64->res_flags;
1061 res->qmodel = IPR_QUEUEING_MODEL64(res);
Wayne Boyer438b0332010-05-10 09:13:00 -07001062 res->type = cfgtew->u.cfgte64->res_type;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001063
1064 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1065 sizeof(res->res_path));
1066
1067 res->bus = 0;
Wayne Boyer0cb992e2010-11-04 09:35:58 -07001068 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1069 sizeof(res->dev_lun.scsi_lun));
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001070 res->lun = scsilun_to_int(&res->dev_lun);
1071
1072 if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1073 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1074 if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1075 found = 1;
1076 res->target = gscsi_res->target;
1077 break;
1078 }
1079 }
1080 if (!found) {
1081 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1082 ioa_cfg->max_devs_supported);
1083 set_bit(res->target, ioa_cfg->target_ids);
1084 }
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001085 } else if (res->type == IPR_RES_TYPE_IOAFP) {
1086 res->bus = IPR_IOAFP_VIRTUAL_BUS;
1087 res->target = 0;
1088 } else if (res->type == IPR_RES_TYPE_ARRAY) {
1089 res->bus = IPR_ARRAY_VIRTUAL_BUS;
1090 res->target = find_first_zero_bit(ioa_cfg->array_ids,
1091 ioa_cfg->max_devs_supported);
1092 set_bit(res->target, ioa_cfg->array_ids);
1093 } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1094 res->bus = IPR_VSET_VIRTUAL_BUS;
1095 res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1096 ioa_cfg->max_devs_supported);
1097 set_bit(res->target, ioa_cfg->vset_ids);
1098 } else {
1099 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1100 ioa_cfg->max_devs_supported);
1101 set_bit(res->target, ioa_cfg->target_ids);
1102 }
1103 } else {
1104 proto = cfgtew->u.cfgte->proto;
1105 res->qmodel = IPR_QUEUEING_MODEL(res);
1106 res->flags = cfgtew->u.cfgte->flags;
1107 if (res->flags & IPR_IS_IOA_RESOURCE)
1108 res->type = IPR_RES_TYPE_IOAFP;
1109 else
1110 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1111
1112 res->bus = cfgtew->u.cfgte->res_addr.bus;
1113 res->target = cfgtew->u.cfgte->res_addr.target;
1114 res->lun = cfgtew->u.cfgte->res_addr.lun;
Wayne Boyer46d74562010-08-11 07:15:17 -07001115 res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001116 }
1117
1118 ipr_update_ata_class(res, proto);
1119}
1120
1121/**
1122 * ipr_is_same_device - Determine if two devices are the same.
1123 * @res: resource entry struct
1124 * @cfgtew: config table entry wrapper struct
1125 *
1126 * Return value:
1127 * 1 if the devices are the same / 0 otherwise
1128 **/
1129static int ipr_is_same_device(struct ipr_resource_entry *res,
1130 struct ipr_config_table_entry_wrapper *cfgtew)
1131{
1132 if (res->ioa_cfg->sis64) {
1133 if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1134 sizeof(cfgtew->u.cfgte64->dev_id)) &&
Wayne Boyer0cb992e2010-11-04 09:35:58 -07001135 !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001136 sizeof(cfgtew->u.cfgte64->lun))) {
1137 return 1;
1138 }
1139 } else {
1140 if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1141 res->target == cfgtew->u.cfgte->res_addr.target &&
1142 res->lun == cfgtew->u.cfgte->res_addr.lun)
1143 return 1;
1144 }
1145
1146 return 0;
1147}
1148
1149/**
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001150 * ipr_format_res_path - Format the resource path for printing.
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001151 * @res_path: resource path
1152 * @buf: buffer
1153 *
1154 * Return value:
1155 * pointer to buffer
1156 **/
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001157static char *ipr_format_res_path(u8 *res_path, char *buffer, int len)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001158{
1159 int i;
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001160 char *p = buffer;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001161
Wayne Boyer46d74562010-08-11 07:15:17 -07001162 *p = '\0';
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001163 p += snprintf(p, buffer + len - p, "%02X", res_path[0]);
1164 for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
1165 p += snprintf(p, buffer + len - p, "-%02X", res_path[i]);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001166
1167 return buffer;
1168}
1169
1170/**
1171 * ipr_update_res_entry - Update the resource entry.
1172 * @res: resource entry struct
1173 * @cfgtew: config table entry wrapper struct
1174 *
1175 * Return value:
1176 * none
1177 **/
1178static void ipr_update_res_entry(struct ipr_resource_entry *res,
1179 struct ipr_config_table_entry_wrapper *cfgtew)
1180{
1181 char buffer[IPR_MAX_RES_PATH_LENGTH];
1182 unsigned int proto;
1183 int new_path = 0;
1184
1185 if (res->ioa_cfg->sis64) {
1186 res->flags = cfgtew->u.cfgte64->flags;
1187 res->res_flags = cfgtew->u.cfgte64->res_flags;
Wayne Boyer75576bb2010-07-14 10:50:14 -07001188 res->type = cfgtew->u.cfgte64->res_type;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001189
1190 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1191 sizeof(struct ipr_std_inq_data));
1192
1193 res->qmodel = IPR_QUEUEING_MODEL64(res);
1194 proto = cfgtew->u.cfgte64->proto;
1195 res->res_handle = cfgtew->u.cfgte64->res_handle;
1196 res->dev_id = cfgtew->u.cfgte64->dev_id;
1197
1198 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1199 sizeof(res->dev_lun.scsi_lun));
1200
1201 if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1202 sizeof(res->res_path))) {
1203 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1204 sizeof(res->res_path));
1205 new_path = 1;
1206 }
1207
1208 if (res->sdev && new_path)
1209 sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001210 ipr_format_res_path(res->res_path, buffer,
1211 sizeof(buffer)));
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001212 } else {
1213 res->flags = cfgtew->u.cfgte->flags;
1214 if (res->flags & IPR_IS_IOA_RESOURCE)
1215 res->type = IPR_RES_TYPE_IOAFP;
1216 else
1217 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1218
1219 memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1220 sizeof(struct ipr_std_inq_data));
1221
1222 res->qmodel = IPR_QUEUEING_MODEL(res);
1223 proto = cfgtew->u.cfgte->proto;
1224 res->res_handle = cfgtew->u.cfgte->res_handle;
1225 }
1226
1227 ipr_update_ata_class(res, proto);
1228}
1229
1230/**
1231 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1232 * for the resource.
1233 * @res: resource entry struct
1234 * @cfgtew: config table entry wrapper struct
1235 *
1236 * Return value:
1237 * none
1238 **/
1239static void ipr_clear_res_target(struct ipr_resource_entry *res)
1240{
1241 struct ipr_resource_entry *gscsi_res = NULL;
1242 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1243
1244 if (!ioa_cfg->sis64)
1245 return;
1246
1247 if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1248 clear_bit(res->target, ioa_cfg->array_ids);
1249 else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1250 clear_bit(res->target, ioa_cfg->vset_ids);
1251 else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1252 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1253 if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1254 return;
1255 clear_bit(res->target, ioa_cfg->target_ids);
1256
1257 } else if (res->bus == 0)
1258 clear_bit(res->target, ioa_cfg->target_ids);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259}
1260
1261/**
1262 * ipr_handle_config_change - Handle a config change from the adapter
1263 * @ioa_cfg: ioa config struct
1264 * @hostrcb: hostrcb
1265 *
1266 * Return value:
1267 * none
1268 **/
1269static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001270 struct ipr_hostrcb *hostrcb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
1272 struct ipr_resource_entry *res = NULL;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001273 struct ipr_config_table_entry_wrapper cfgtew;
1274 __be32 cc_res_handle;
1275
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 u32 is_ndn = 1;
1277
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001278 if (ioa_cfg->sis64) {
1279 cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1280 cc_res_handle = cfgtew.u.cfgte64->res_handle;
1281 } else {
1282 cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1283 cc_res_handle = cfgtew.u.cfgte->res_handle;
1284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001287 if (res->res_handle == cc_res_handle) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 is_ndn = 0;
1289 break;
1290 }
1291 }
1292
1293 if (is_ndn) {
1294 if (list_empty(&ioa_cfg->free_res_q)) {
1295 ipr_send_hcam(ioa_cfg,
1296 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1297 hostrcb);
1298 return;
1299 }
1300
1301 res = list_entry(ioa_cfg->free_res_q.next,
1302 struct ipr_resource_entry, queue);
1303
1304 list_del(&res->queue);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001305 ipr_init_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1307 }
1308
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001309 ipr_update_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
1311 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1312 if (res->sdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 res->del_from_ml = 1;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001314 res->res_handle = IPR_INVALID_RES_HANDLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 if (ioa_cfg->allow_ml_add_del)
1316 schedule_work(&ioa_cfg->work_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001317 } else {
1318 ipr_clear_res_target(res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001320 }
Kleber Sacilotto de Souza5767a1c2011-02-14 20:19:31 -02001321 } else if (!res->sdev || res->del_from_ml) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 res->add_to_ml = 1;
1323 if (ioa_cfg->allow_ml_add_del)
1324 schedule_work(&ioa_cfg->work_q);
1325 }
1326
1327 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1328}
1329
1330/**
1331 * ipr_process_ccn - Op done function for a CCN.
1332 * @ipr_cmd: ipr command struct
1333 *
1334 * This function is the op done function for a configuration
1335 * change notification host controlled async from the adapter.
1336 *
1337 * Return value:
1338 * none
1339 **/
1340static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1341{
1342 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1343 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07001344 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
1346 list_del(&hostrcb->queue);
1347 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1348
1349 if (ioasc) {
1350 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
1351 dev_err(&ioa_cfg->pdev->dev,
1352 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1353
1354 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1355 } else {
1356 ipr_handle_config_change(ioa_cfg, hostrcb);
1357 }
1358}
1359
1360/**
Brian King8cf093e2007-04-26 16:00:14 -05001361 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1362 * @i: index into buffer
1363 * @buf: string to modify
1364 *
1365 * This function will strip all trailing whitespace, pad the end
1366 * of the string with a single space, and NULL terminate the string.
1367 *
1368 * Return value:
1369 * new length of string
1370 **/
1371static int strip_and_pad_whitespace(int i, char *buf)
1372{
1373 while (i && buf[i] == ' ')
1374 i--;
1375 buf[i+1] = ' ';
1376 buf[i+2] = '\0';
1377 return i + 2;
1378}
1379
1380/**
1381 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1382 * @prefix: string to print at start of printk
1383 * @hostrcb: hostrcb pointer
1384 * @vpd: vendor/product id/sn struct
1385 *
1386 * Return value:
1387 * none
1388 **/
1389static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1390 struct ipr_vpd *vpd)
1391{
1392 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
1393 int i = 0;
1394
1395 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1396 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
1397
1398 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
1399 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
1400
1401 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1402 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1403
1404 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1405}
1406
1407/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 * ipr_log_vpd - Log the passed VPD to the error log.
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001409 * @vpd: vendor/product id/sn struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 *
1411 * Return value:
1412 * none
1413 **/
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001414static void ipr_log_vpd(struct ipr_vpd *vpd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415{
1416 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1417 + IPR_SERIAL_NUM_LEN];
1418
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001419 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1420 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 IPR_PROD_ID_LEN);
1422 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1423 ipr_err("Vendor/Product ID: %s\n", buffer);
1424
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001425 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1427 ipr_err(" Serial Number: %s\n", buffer);
1428}
1429
1430/**
Brian King8cf093e2007-04-26 16:00:14 -05001431 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1432 * @prefix: string to print at start of printk
1433 * @hostrcb: hostrcb pointer
1434 * @vpd: vendor/product id/sn/wwn struct
1435 *
1436 * Return value:
1437 * none
1438 **/
1439static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1440 struct ipr_ext_vpd *vpd)
1441{
1442 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1443 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1444 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1445}
1446
1447/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001448 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1449 * @vpd: vendor/product id/sn/wwn struct
1450 *
1451 * Return value:
1452 * none
1453 **/
1454static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1455{
1456 ipr_log_vpd(&vpd->vpd);
1457 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1458 be32_to_cpu(vpd->wwid[1]));
1459}
1460
1461/**
1462 * ipr_log_enhanced_cache_error - Log a cache error.
1463 * @ioa_cfg: ioa config struct
1464 * @hostrcb: hostrcb struct
1465 *
1466 * Return value:
1467 * none
1468 **/
1469static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1470 struct ipr_hostrcb *hostrcb)
1471{
Wayne Boyer4565e372010-02-19 13:24:07 -08001472 struct ipr_hostrcb_type_12_error *error;
1473
1474 if (ioa_cfg->sis64)
1475 error = &hostrcb->hcam.u.error64.u.type_12_error;
1476 else
1477 error = &hostrcb->hcam.u.error.u.type_12_error;
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001478
1479 ipr_err("-----Current Configuration-----\n");
1480 ipr_err("Cache Directory Card Information:\n");
1481 ipr_log_ext_vpd(&error->ioa_vpd);
1482 ipr_err("Adapter Card Information:\n");
1483 ipr_log_ext_vpd(&error->cfc_vpd);
1484
1485 ipr_err("-----Expected Configuration-----\n");
1486 ipr_err("Cache Directory Card Information:\n");
1487 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1488 ipr_err("Adapter Card Information:\n");
1489 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1490
1491 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1492 be32_to_cpu(error->ioa_data[0]),
1493 be32_to_cpu(error->ioa_data[1]),
1494 be32_to_cpu(error->ioa_data[2]));
1495}
1496
1497/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 * ipr_log_cache_error - Log a cache error.
1499 * @ioa_cfg: ioa config struct
1500 * @hostrcb: hostrcb struct
1501 *
1502 * Return value:
1503 * none
1504 **/
1505static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1506 struct ipr_hostrcb *hostrcb)
1507{
1508 struct ipr_hostrcb_type_02_error *error =
1509 &hostrcb->hcam.u.error.u.type_02_error;
1510
1511 ipr_err("-----Current Configuration-----\n");
1512 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001513 ipr_log_vpd(&error->ioa_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001515 ipr_log_vpd(&error->cfc_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
1517 ipr_err("-----Expected Configuration-----\n");
1518 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001519 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001521 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
1523 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1524 be32_to_cpu(error->ioa_data[0]),
1525 be32_to_cpu(error->ioa_data[1]),
1526 be32_to_cpu(error->ioa_data[2]));
1527}
1528
1529/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001530 * ipr_log_enhanced_config_error - Log a configuration error.
1531 * @ioa_cfg: ioa config struct
1532 * @hostrcb: hostrcb struct
1533 *
1534 * Return value:
1535 * none
1536 **/
1537static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1538 struct ipr_hostrcb *hostrcb)
1539{
1540 int errors_logged, i;
1541 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1542 struct ipr_hostrcb_type_13_error *error;
1543
1544 error = &hostrcb->hcam.u.error.u.type_13_error;
1545 errors_logged = be32_to_cpu(error->errors_logged);
1546
1547 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1548 be32_to_cpu(error->errors_detected), errors_logged);
1549
1550 dev_entry = error->dev;
1551
1552 for (i = 0; i < errors_logged; i++, dev_entry++) {
1553 ipr_err_separator;
1554
1555 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1556 ipr_log_ext_vpd(&dev_entry->vpd);
1557
1558 ipr_err("-----New Device Information-----\n");
1559 ipr_log_ext_vpd(&dev_entry->new_vpd);
1560
1561 ipr_err("Cache Directory Card Information:\n");
1562 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1563
1564 ipr_err("Adapter Card Information:\n");
1565 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1566 }
1567}
1568
1569/**
Wayne Boyer4565e372010-02-19 13:24:07 -08001570 * ipr_log_sis64_config_error - Log a device error.
1571 * @ioa_cfg: ioa config struct
1572 * @hostrcb: hostrcb struct
1573 *
1574 * Return value:
1575 * none
1576 **/
1577static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
1578 struct ipr_hostrcb *hostrcb)
1579{
1580 int errors_logged, i;
1581 struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
1582 struct ipr_hostrcb_type_23_error *error;
1583 char buffer[IPR_MAX_RES_PATH_LENGTH];
1584
1585 error = &hostrcb->hcam.u.error64.u.type_23_error;
1586 errors_logged = be32_to_cpu(error->errors_logged);
1587
1588 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1589 be32_to_cpu(error->errors_detected), errors_logged);
1590
1591 dev_entry = error->dev;
1592
1593 for (i = 0; i < errors_logged; i++, dev_entry++) {
1594 ipr_err_separator;
1595
1596 ipr_err("Device %d : %s", i + 1,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001597 ipr_format_res_path(dev_entry->res_path, buffer,
1598 sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08001599 ipr_log_ext_vpd(&dev_entry->vpd);
1600
1601 ipr_err("-----New Device Information-----\n");
1602 ipr_log_ext_vpd(&dev_entry->new_vpd);
1603
1604 ipr_err("Cache Directory Card Information:\n");
1605 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1606
1607 ipr_err("Adapter Card Information:\n");
1608 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1609 }
1610}
1611
1612/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 * ipr_log_config_error - Log a configuration error.
1614 * @ioa_cfg: ioa config struct
1615 * @hostrcb: hostrcb struct
1616 *
1617 * Return value:
1618 * none
1619 **/
1620static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1621 struct ipr_hostrcb *hostrcb)
1622{
1623 int errors_logged, i;
1624 struct ipr_hostrcb_device_data_entry *dev_entry;
1625 struct ipr_hostrcb_type_03_error *error;
1626
1627 error = &hostrcb->hcam.u.error.u.type_03_error;
1628 errors_logged = be32_to_cpu(error->errors_logged);
1629
1630 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1631 be32_to_cpu(error->errors_detected), errors_logged);
1632
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001633 dev_entry = error->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
1635 for (i = 0; i < errors_logged; i++, dev_entry++) {
1636 ipr_err_separator;
1637
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001638 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001639 ipr_log_vpd(&dev_entry->vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641 ipr_err("-----New Device Information-----\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001642 ipr_log_vpd(&dev_entry->new_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
1644 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001645 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
1647 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001648 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
1650 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1651 be32_to_cpu(dev_entry->ioa_data[0]),
1652 be32_to_cpu(dev_entry->ioa_data[1]),
1653 be32_to_cpu(dev_entry->ioa_data[2]),
1654 be32_to_cpu(dev_entry->ioa_data[3]),
1655 be32_to_cpu(dev_entry->ioa_data[4]));
1656 }
1657}
1658
1659/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001660 * ipr_log_enhanced_array_error - Log an array configuration error.
1661 * @ioa_cfg: ioa config struct
1662 * @hostrcb: hostrcb struct
1663 *
1664 * Return value:
1665 * none
1666 **/
1667static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1668 struct ipr_hostrcb *hostrcb)
1669{
1670 int i, num_entries;
1671 struct ipr_hostrcb_type_14_error *error;
1672 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1673 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1674
1675 error = &hostrcb->hcam.u.error.u.type_14_error;
1676
1677 ipr_err_separator;
1678
1679 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1680 error->protection_level,
1681 ioa_cfg->host->host_no,
1682 error->last_func_vset_res_addr.bus,
1683 error->last_func_vset_res_addr.target,
1684 error->last_func_vset_res_addr.lun);
1685
1686 ipr_err_separator;
1687
1688 array_entry = error->array_member;
1689 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
Wayne Boyer72620262010-09-27 10:45:28 -07001690 ARRAY_SIZE(error->array_member));
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001691
1692 for (i = 0; i < num_entries; i++, array_entry++) {
1693 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1694 continue;
1695
1696 if (be32_to_cpu(error->exposed_mode_adn) == i)
1697 ipr_err("Exposed Array Member %d:\n", i);
1698 else
1699 ipr_err("Array Member %d:\n", i);
1700
1701 ipr_log_ext_vpd(&array_entry->vpd);
1702 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1703 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1704 "Expected Location");
1705
1706 ipr_err_separator;
1707 }
1708}
1709
1710/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 * ipr_log_array_error - Log an array configuration error.
1712 * @ioa_cfg: ioa config struct
1713 * @hostrcb: hostrcb struct
1714 *
1715 * Return value:
1716 * none
1717 **/
1718static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1719 struct ipr_hostrcb *hostrcb)
1720{
1721 int i;
1722 struct ipr_hostrcb_type_04_error *error;
1723 struct ipr_hostrcb_array_data_entry *array_entry;
1724 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1725
1726 error = &hostrcb->hcam.u.error.u.type_04_error;
1727
1728 ipr_err_separator;
1729
1730 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1731 error->protection_level,
1732 ioa_cfg->host->host_no,
1733 error->last_func_vset_res_addr.bus,
1734 error->last_func_vset_res_addr.target,
1735 error->last_func_vset_res_addr.lun);
1736
1737 ipr_err_separator;
1738
1739 array_entry = error->array_member;
1740
1741 for (i = 0; i < 18; i++) {
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001742 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 continue;
1744
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001745 if (be32_to_cpu(error->exposed_mode_adn) == i)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 ipr_err("Exposed Array Member %d:\n", i);
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001747 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 ipr_err("Array Member %d:\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001750 ipr_log_vpd(&array_entry->vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001752 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1753 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1754 "Expected Location");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
1756 ipr_err_separator;
1757
1758 if (i == 9)
1759 array_entry = error->array_member2;
1760 else
1761 array_entry++;
1762 }
1763}
1764
1765/**
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001766 * ipr_log_hex_data - Log additional hex IOA error data.
Brian Kingac719ab2006-11-21 10:28:42 -06001767 * @ioa_cfg: ioa config struct
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001768 * @data: IOA error data
1769 * @len: data length
1770 *
1771 * Return value:
1772 * none
1773 **/
Brian Kingac719ab2006-11-21 10:28:42 -06001774static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001775{
1776 int i;
1777
1778 if (len == 0)
1779 return;
1780
Brian Kingac719ab2006-11-21 10:28:42 -06001781 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1782 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1783
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001784 for (i = 0; i < len / 4; i += 4) {
1785 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1786 be32_to_cpu(data[i]),
1787 be32_to_cpu(data[i+1]),
1788 be32_to_cpu(data[i+2]),
1789 be32_to_cpu(data[i+3]));
1790 }
1791}
1792
1793/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001794 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1795 * @ioa_cfg: ioa config struct
1796 * @hostrcb: hostrcb struct
1797 *
1798 * Return value:
1799 * none
1800 **/
1801static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1802 struct ipr_hostrcb *hostrcb)
1803{
1804 struct ipr_hostrcb_type_17_error *error;
1805
Wayne Boyer4565e372010-02-19 13:24:07 -08001806 if (ioa_cfg->sis64)
1807 error = &hostrcb->hcam.u.error64.u.type_17_error;
1808 else
1809 error = &hostrcb->hcam.u.error.u.type_17_error;
1810
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001811 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
KOSAKI Motohiroca54cb82009-12-14 18:01:15 -08001812 strim(error->failure_reason);
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001813
Brian King8cf093e2007-04-26 16:00:14 -05001814 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1815 be32_to_cpu(hostrcb->hcam.u.error.prc));
1816 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
Brian Kingac719ab2006-11-21 10:28:42 -06001817 ipr_log_hex_data(ioa_cfg, error->data,
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001818 be32_to_cpu(hostrcb->hcam.length) -
1819 (offsetof(struct ipr_hostrcb_error, u) +
1820 offsetof(struct ipr_hostrcb_type_17_error, data)));
1821}
1822
1823/**
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001824 * ipr_log_dual_ioa_error - Log a dual adapter error.
1825 * @ioa_cfg: ioa config struct
1826 * @hostrcb: hostrcb struct
1827 *
1828 * Return value:
1829 * none
1830 **/
1831static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1832 struct ipr_hostrcb *hostrcb)
1833{
1834 struct ipr_hostrcb_type_07_error *error;
1835
1836 error = &hostrcb->hcam.u.error.u.type_07_error;
1837 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
KOSAKI Motohiroca54cb82009-12-14 18:01:15 -08001838 strim(error->failure_reason);
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001839
Brian King8cf093e2007-04-26 16:00:14 -05001840 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1841 be32_to_cpu(hostrcb->hcam.u.error.prc));
1842 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
Brian Kingac719ab2006-11-21 10:28:42 -06001843 ipr_log_hex_data(ioa_cfg, error->data,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001844 be32_to_cpu(hostrcb->hcam.length) -
1845 (offsetof(struct ipr_hostrcb_error, u) +
1846 offsetof(struct ipr_hostrcb_type_07_error, data)));
1847}
1848
Brian King49dc6a12006-11-21 10:28:35 -06001849static const struct {
1850 u8 active;
1851 char *desc;
1852} path_active_desc[] = {
1853 { IPR_PATH_NO_INFO, "Path" },
1854 { IPR_PATH_ACTIVE, "Active path" },
1855 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1856};
1857
1858static const struct {
1859 u8 state;
1860 char *desc;
1861} path_state_desc[] = {
1862 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1863 { IPR_PATH_HEALTHY, "is healthy" },
1864 { IPR_PATH_DEGRADED, "is degraded" },
1865 { IPR_PATH_FAILED, "is failed" }
1866};
1867
1868/**
1869 * ipr_log_fabric_path - Log a fabric path error
1870 * @hostrcb: hostrcb struct
1871 * @fabric: fabric descriptor
1872 *
1873 * Return value:
1874 * none
1875 **/
1876static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1877 struct ipr_hostrcb_fabric_desc *fabric)
1878{
1879 int i, j;
1880 u8 path_state = fabric->path_state;
1881 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1882 u8 state = path_state & IPR_PATH_STATE_MASK;
1883
1884 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1885 if (path_active_desc[i].active != active)
1886 continue;
1887
1888 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1889 if (path_state_desc[j].state != state)
1890 continue;
1891
1892 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
1893 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
1894 path_active_desc[i].desc, path_state_desc[j].desc,
1895 fabric->ioa_port);
1896 } else if (fabric->cascaded_expander == 0xff) {
1897 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
1898 path_active_desc[i].desc, path_state_desc[j].desc,
1899 fabric->ioa_port, fabric->phy);
1900 } else if (fabric->phy == 0xff) {
1901 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
1902 path_active_desc[i].desc, path_state_desc[j].desc,
1903 fabric->ioa_port, fabric->cascaded_expander);
1904 } else {
1905 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1906 path_active_desc[i].desc, path_state_desc[j].desc,
1907 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1908 }
1909 return;
1910 }
1911 }
1912
1913 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
1914 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1915}
1916
Wayne Boyer4565e372010-02-19 13:24:07 -08001917/**
1918 * ipr_log64_fabric_path - Log a fabric path error
1919 * @hostrcb: hostrcb struct
1920 * @fabric: fabric descriptor
1921 *
1922 * Return value:
1923 * none
1924 **/
1925static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
1926 struct ipr_hostrcb64_fabric_desc *fabric)
1927{
1928 int i, j;
1929 u8 path_state = fabric->path_state;
1930 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1931 u8 state = path_state & IPR_PATH_STATE_MASK;
1932 char buffer[IPR_MAX_RES_PATH_LENGTH];
1933
1934 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1935 if (path_active_desc[i].active != active)
1936 continue;
1937
1938 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1939 if (path_state_desc[j].state != state)
1940 continue;
1941
1942 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
1943 path_active_desc[i].desc, path_state_desc[j].desc,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001944 ipr_format_res_path(fabric->res_path, buffer,
1945 sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08001946 return;
1947 }
1948 }
1949
1950 ipr_err("Path state=%02X Resource Path=%s\n", path_state,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001951 ipr_format_res_path(fabric->res_path, buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08001952}
1953
Brian King49dc6a12006-11-21 10:28:35 -06001954static const struct {
1955 u8 type;
1956 char *desc;
1957} path_type_desc[] = {
1958 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
1959 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
1960 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
1961 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
1962};
1963
1964static const struct {
1965 u8 status;
1966 char *desc;
1967} path_status_desc[] = {
1968 { IPR_PATH_CFG_NO_PROB, "Functional" },
1969 { IPR_PATH_CFG_DEGRADED, "Degraded" },
1970 { IPR_PATH_CFG_FAILED, "Failed" },
1971 { IPR_PATH_CFG_SUSPECT, "Suspect" },
1972 { IPR_PATH_NOT_DETECTED, "Missing" },
1973 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
1974};
1975
1976static const char *link_rate[] = {
1977 "unknown",
1978 "disabled",
1979 "phy reset problem",
1980 "spinup hold",
1981 "port selector",
1982 "unknown",
1983 "unknown",
1984 "unknown",
1985 "1.5Gbps",
1986 "3.0Gbps",
1987 "unknown",
1988 "unknown",
1989 "unknown",
1990 "unknown",
1991 "unknown",
1992 "unknown"
1993};
1994
1995/**
1996 * ipr_log_path_elem - Log a fabric path element.
1997 * @hostrcb: hostrcb struct
1998 * @cfg: fabric path element struct
1999 *
2000 * Return value:
2001 * none
2002 **/
2003static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
2004 struct ipr_hostrcb_config_element *cfg)
2005{
2006 int i, j;
2007 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2008 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2009
2010 if (type == IPR_PATH_CFG_NOT_EXIST)
2011 return;
2012
2013 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2014 if (path_type_desc[i].type != type)
2015 continue;
2016
2017 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2018 if (path_status_desc[j].status != status)
2019 continue;
2020
2021 if (type == IPR_PATH_CFG_IOA_PORT) {
2022 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
2023 path_status_desc[j].desc, path_type_desc[i].desc,
2024 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2025 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2026 } else {
2027 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
2028 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2029 path_status_desc[j].desc, path_type_desc[i].desc,
2030 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2031 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2032 } else if (cfg->cascaded_expander == 0xff) {
2033 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
2034 "WWN=%08X%08X\n", path_status_desc[j].desc,
2035 path_type_desc[i].desc, cfg->phy,
2036 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2037 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2038 } else if (cfg->phy == 0xff) {
2039 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
2040 "WWN=%08X%08X\n", path_status_desc[j].desc,
2041 path_type_desc[i].desc, cfg->cascaded_expander,
2042 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2043 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2044 } else {
2045 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2046 "WWN=%08X%08X\n", path_status_desc[j].desc,
2047 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
2048 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2049 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2050 }
2051 }
2052 return;
2053 }
2054 }
2055
2056 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2057 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
2058 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2059 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2060}
2061
2062/**
Wayne Boyer4565e372010-02-19 13:24:07 -08002063 * ipr_log64_path_elem - Log a fabric path element.
2064 * @hostrcb: hostrcb struct
2065 * @cfg: fabric path element struct
2066 *
2067 * Return value:
2068 * none
2069 **/
2070static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
2071 struct ipr_hostrcb64_config_element *cfg)
2072{
2073 int i, j;
2074 u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
2075 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2076 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2077 char buffer[IPR_MAX_RES_PATH_LENGTH];
2078
2079 if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
2080 return;
2081
2082 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2083 if (path_type_desc[i].type != type)
2084 continue;
2085
2086 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2087 if (path_status_desc[j].status != status)
2088 continue;
2089
2090 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2091 path_status_desc[j].desc, path_type_desc[i].desc,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07002092 ipr_format_res_path(cfg->res_path, buffer,
2093 sizeof(buffer)),
Wayne Boyer4565e372010-02-19 13:24:07 -08002094 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2095 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2096 return;
2097 }
2098 }
2099 ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
2100 "WWN=%08X%08X\n", cfg->type_status,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07002101 ipr_format_res_path(cfg->res_path, buffer, sizeof(buffer)),
Wayne Boyer4565e372010-02-19 13:24:07 -08002102 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2103 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2104}
2105
2106/**
Brian King49dc6a12006-11-21 10:28:35 -06002107 * ipr_log_fabric_error - Log a fabric error.
2108 * @ioa_cfg: ioa config struct
2109 * @hostrcb: hostrcb struct
2110 *
2111 * Return value:
2112 * none
2113 **/
2114static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2115 struct ipr_hostrcb *hostrcb)
2116{
2117 struct ipr_hostrcb_type_20_error *error;
2118 struct ipr_hostrcb_fabric_desc *fabric;
2119 struct ipr_hostrcb_config_element *cfg;
2120 int i, add_len;
2121
2122 error = &hostrcb->hcam.u.error.u.type_20_error;
2123 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2124 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2125
2126 add_len = be32_to_cpu(hostrcb->hcam.length) -
2127 (offsetof(struct ipr_hostrcb_error, u) +
2128 offsetof(struct ipr_hostrcb_type_20_error, desc));
2129
2130 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2131 ipr_log_fabric_path(hostrcb, fabric);
2132 for_each_fabric_cfg(fabric, cfg)
2133 ipr_log_path_elem(hostrcb, cfg);
2134
2135 add_len -= be16_to_cpu(fabric->length);
2136 fabric = (struct ipr_hostrcb_fabric_desc *)
2137 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2138 }
2139
Brian Kingac719ab2006-11-21 10:28:42 -06002140 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
Brian King49dc6a12006-11-21 10:28:35 -06002141}
2142
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002143/**
Wayne Boyer4565e372010-02-19 13:24:07 -08002144 * ipr_log_sis64_array_error - Log a sis64 array error.
2145 * @ioa_cfg: ioa config struct
2146 * @hostrcb: hostrcb struct
2147 *
2148 * Return value:
2149 * none
2150 **/
2151static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
2152 struct ipr_hostrcb *hostrcb)
2153{
2154 int i, num_entries;
2155 struct ipr_hostrcb_type_24_error *error;
2156 struct ipr_hostrcb64_array_data_entry *array_entry;
2157 char buffer[IPR_MAX_RES_PATH_LENGTH];
2158 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
2159
2160 error = &hostrcb->hcam.u.error64.u.type_24_error;
2161
2162 ipr_err_separator;
2163
2164 ipr_err("RAID %s Array Configuration: %s\n",
2165 error->protection_level,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07002166 ipr_format_res_path(error->last_res_path, buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002167
2168 ipr_err_separator;
2169
2170 array_entry = error->array_member;
Wayne Boyer72620262010-09-27 10:45:28 -07002171 num_entries = min_t(u32, error->num_entries,
2172 ARRAY_SIZE(error->array_member));
Wayne Boyer4565e372010-02-19 13:24:07 -08002173
2174 for (i = 0; i < num_entries; i++, array_entry++) {
2175
2176 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
2177 continue;
2178
2179 if (error->exposed_mode_adn == i)
2180 ipr_err("Exposed Array Member %d:\n", i);
2181 else
2182 ipr_err("Array Member %d:\n", i);
2183
2184 ipr_err("Array Member %d:\n", i);
2185 ipr_log_ext_vpd(&array_entry->vpd);
Wayne Boyer72620262010-09-27 10:45:28 -07002186 ipr_err("Current Location: %s\n",
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07002187 ipr_format_res_path(array_entry->res_path, buffer,
2188 sizeof(buffer)));
Wayne Boyer72620262010-09-27 10:45:28 -07002189 ipr_err("Expected Location: %s\n",
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07002190 ipr_format_res_path(array_entry->expected_res_path,
2191 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002192
2193 ipr_err_separator;
2194 }
2195}
2196
2197/**
2198 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2199 * @ioa_cfg: ioa config struct
2200 * @hostrcb: hostrcb struct
2201 *
2202 * Return value:
2203 * none
2204 **/
2205static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2206 struct ipr_hostrcb *hostrcb)
2207{
2208 struct ipr_hostrcb_type_30_error *error;
2209 struct ipr_hostrcb64_fabric_desc *fabric;
2210 struct ipr_hostrcb64_config_element *cfg;
2211 int i, add_len;
2212
2213 error = &hostrcb->hcam.u.error64.u.type_30_error;
2214
2215 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2216 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2217
2218 add_len = be32_to_cpu(hostrcb->hcam.length) -
2219 (offsetof(struct ipr_hostrcb64_error, u) +
2220 offsetof(struct ipr_hostrcb_type_30_error, desc));
2221
2222 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2223 ipr_log64_fabric_path(hostrcb, fabric);
2224 for_each_fabric_cfg(fabric, cfg)
2225 ipr_log64_path_elem(hostrcb, cfg);
2226
2227 add_len -= be16_to_cpu(fabric->length);
2228 fabric = (struct ipr_hostrcb64_fabric_desc *)
2229 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2230 }
2231
2232 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2233}
2234
2235/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 * ipr_log_generic_error - Log an adapter error.
2237 * @ioa_cfg: ioa config struct
2238 * @hostrcb: hostrcb struct
2239 *
2240 * Return value:
2241 * none
2242 **/
2243static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
2244 struct ipr_hostrcb *hostrcb)
2245{
Brian Kingac719ab2006-11-21 10:28:42 -06002246 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002247 be32_to_cpu(hostrcb->hcam.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248}
2249
2250/**
2251 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2252 * @ioasc: IOASC
2253 *
2254 * This function will return the index of into the ipr_error_table
2255 * for the specified IOASC. If the IOASC is not in the table,
2256 * 0 will be returned, which points to the entry used for unknown errors.
2257 *
2258 * Return value:
2259 * index into the ipr_error_table
2260 **/
2261static u32 ipr_get_error(u32 ioasc)
2262{
2263 int i;
2264
2265 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
Brian King35a39692006-09-25 12:39:20 -05002266 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 return i;
2268
2269 return 0;
2270}
2271
2272/**
2273 * ipr_handle_log_data - Log an adapter error.
2274 * @ioa_cfg: ioa config struct
2275 * @hostrcb: hostrcb struct
2276 *
2277 * This function logs an adapter error to the system.
2278 *
2279 * Return value:
2280 * none
2281 **/
2282static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
2283 struct ipr_hostrcb *hostrcb)
2284{
2285 u32 ioasc;
2286 int error_index;
2287
2288 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
2289 return;
2290
2291 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
2292 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
2293
Wayne Boyer4565e372010-02-19 13:24:07 -08002294 if (ioa_cfg->sis64)
2295 ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2296 else
2297 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Wayne Boyer4565e372010-02-19 13:24:07 -08002299 if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
2300 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2302 scsi_report_bus_reset(ioa_cfg->host,
Wayne Boyer4565e372010-02-19 13:24:07 -08002303 hostrcb->hcam.u.error.fd_res_addr.bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 }
2305
2306 error_index = ipr_get_error(ioasc);
2307
2308 if (!ipr_error_table[error_index].log_hcam)
2309 return;
2310
Brian King49dc6a12006-11-21 10:28:35 -06002311 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
2313 /* Set indication we have logged an error */
2314 ioa_cfg->errors_logged++;
2315
Brian King933916f2007-03-29 12:43:30 -05002316 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 return;
brking@us.ibm.comcf852032005-11-01 17:00:47 -06002318 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
2319 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
2321 switch (hostrcb->hcam.overlay_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 case IPR_HOST_RCB_OVERLAY_ID_2:
2323 ipr_log_cache_error(ioa_cfg, hostrcb);
2324 break;
2325 case IPR_HOST_RCB_OVERLAY_ID_3:
2326 ipr_log_config_error(ioa_cfg, hostrcb);
2327 break;
2328 case IPR_HOST_RCB_OVERLAY_ID_4:
2329 case IPR_HOST_RCB_OVERLAY_ID_6:
2330 ipr_log_array_error(ioa_cfg, hostrcb);
2331 break;
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002332 case IPR_HOST_RCB_OVERLAY_ID_7:
2333 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
2334 break;
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06002335 case IPR_HOST_RCB_OVERLAY_ID_12:
2336 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
2337 break;
2338 case IPR_HOST_RCB_OVERLAY_ID_13:
2339 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
2340 break;
2341 case IPR_HOST_RCB_OVERLAY_ID_14:
2342 case IPR_HOST_RCB_OVERLAY_ID_16:
2343 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
2344 break;
2345 case IPR_HOST_RCB_OVERLAY_ID_17:
2346 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
2347 break;
Brian King49dc6a12006-11-21 10:28:35 -06002348 case IPR_HOST_RCB_OVERLAY_ID_20:
2349 ipr_log_fabric_error(ioa_cfg, hostrcb);
2350 break;
Wayne Boyer4565e372010-02-19 13:24:07 -08002351 case IPR_HOST_RCB_OVERLAY_ID_23:
2352 ipr_log_sis64_config_error(ioa_cfg, hostrcb);
2353 break;
2354 case IPR_HOST_RCB_OVERLAY_ID_24:
2355 case IPR_HOST_RCB_OVERLAY_ID_26:
2356 ipr_log_sis64_array_error(ioa_cfg, hostrcb);
2357 break;
2358 case IPR_HOST_RCB_OVERLAY_ID_30:
2359 ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
2360 break;
brking@us.ibm.comcf852032005-11-01 17:00:47 -06002361 case IPR_HOST_RCB_OVERLAY_ID_1:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 default:
brking@us.ibm.coma9cfca92005-11-01 17:00:41 -06002364 ipr_log_generic_error(ioa_cfg, hostrcb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 break;
2366 }
2367}
2368
2369/**
2370 * ipr_process_error - Op done function for an adapter error log.
2371 * @ipr_cmd: ipr command struct
2372 *
2373 * This function is the op done function for an error log host
2374 * controlled async from the adapter. It will log the error and
2375 * send the HCAM back to the adapter.
2376 *
2377 * Return value:
2378 * none
2379 **/
2380static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2381{
2382 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2383 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07002384 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Wayne Boyer4565e372010-02-19 13:24:07 -08002385 u32 fd_ioasc;
2386
2387 if (ioa_cfg->sis64)
2388 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2389 else
2390 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391
2392 list_del(&hostrcb->queue);
2393 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
2394
2395 if (!ioasc) {
2396 ipr_handle_log_data(ioa_cfg, hostrcb);
Brian King65f56472007-04-26 16:00:12 -05002397 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
2398 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
2400 dev_err(&ioa_cfg->pdev->dev,
2401 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
2402 }
2403
2404 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2405}
2406
2407/**
2408 * ipr_timeout - An internally generated op has timed out.
2409 * @ipr_cmd: ipr command struct
2410 *
2411 * This function blocks host requests and initiates an
2412 * adapter reset.
2413 *
2414 * Return value:
2415 * none
2416 **/
2417static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
2418{
2419 unsigned long lock_flags = 0;
2420 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2421
2422 ENTER;
2423 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2424
2425 ioa_cfg->errors_logged++;
2426 dev_err(&ioa_cfg->pdev->dev,
2427 "Adapter being reset due to command timeout.\n");
2428
2429 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2430 ioa_cfg->sdt_state = GET_DUMP;
2431
2432 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
2433 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2434
2435 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2436 LEAVE;
2437}
2438
2439/**
2440 * ipr_oper_timeout - Adapter timed out transitioning to operational
2441 * @ipr_cmd: ipr command struct
2442 *
2443 * This function blocks host requests and initiates an
2444 * adapter reset.
2445 *
2446 * Return value:
2447 * none
2448 **/
2449static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
2450{
2451 unsigned long lock_flags = 0;
2452 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2453
2454 ENTER;
2455 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2456
2457 ioa_cfg->errors_logged++;
2458 dev_err(&ioa_cfg->pdev->dev,
2459 "Adapter timed out transitioning to operational.\n");
2460
2461 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2462 ioa_cfg->sdt_state = GET_DUMP;
2463
2464 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
2465 if (ipr_fastfail)
2466 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
2467 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2468 }
2469
2470 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2471 LEAVE;
2472}
2473
2474/**
2475 * ipr_reset_reload - Reset/Reload the IOA
2476 * @ioa_cfg: ioa config struct
2477 * @shutdown_type: shutdown type
2478 *
2479 * This function resets the adapter and re-initializes it.
2480 * This function assumes that all new host commands have been stopped.
2481 * Return value:
2482 * SUCCESS / FAILED
2483 **/
2484static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
2485 enum ipr_shutdown_type shutdown_type)
2486{
2487 if (!ioa_cfg->in_reset_reload)
2488 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
2489
2490 spin_unlock_irq(ioa_cfg->host->host_lock);
2491 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2492 spin_lock_irq(ioa_cfg->host->host_lock);
2493
2494 /* If we got hit with a host reset while we were already resetting
2495 the adapter for some reason, and the reset failed. */
2496 if (ioa_cfg->ioa_is_dead) {
2497 ipr_trace;
2498 return FAILED;
2499 }
2500
2501 return SUCCESS;
2502}
2503
2504/**
2505 * ipr_find_ses_entry - Find matching SES in SES table
2506 * @res: resource entry struct of SES
2507 *
2508 * Return value:
2509 * pointer to SES table entry / NULL on failure
2510 **/
2511static const struct ipr_ses_table_entry *
2512ipr_find_ses_entry(struct ipr_resource_entry *res)
2513{
2514 int i, j, matches;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002515 struct ipr_std_inq_vpids *vpids;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 const struct ipr_ses_table_entry *ste = ipr_ses_table;
2517
2518 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
2519 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
2520 if (ste->compare_product_id_byte[j] == 'X') {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002521 vpids = &res->std_inq_data.vpids;
2522 if (vpids->product_id[j] == ste->product_id[j])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 matches++;
2524 else
2525 break;
2526 } else
2527 matches++;
2528 }
2529
2530 if (matches == IPR_PROD_ID_LEN)
2531 return ste;
2532 }
2533
2534 return NULL;
2535}
2536
2537/**
2538 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2539 * @ioa_cfg: ioa config struct
2540 * @bus: SCSI bus
2541 * @bus_width: bus width
2542 *
2543 * Return value:
2544 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2545 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2546 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2547 * max 160MHz = max 320MB/sec).
2548 **/
2549static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
2550{
2551 struct ipr_resource_entry *res;
2552 const struct ipr_ses_table_entry *ste;
2553 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
2554
2555 /* Loop through each config table entry in the config table buffer */
2556 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002557 if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 continue;
2559
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002560 if (bus != res->bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 continue;
2562
2563 if (!(ste = ipr_find_ses_entry(res)))
2564 continue;
2565
2566 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
2567 }
2568
2569 return max_xfer_rate;
2570}
2571
2572/**
2573 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2574 * @ioa_cfg: ioa config struct
2575 * @max_delay: max delay in micro-seconds to wait
2576 *
2577 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2578 *
2579 * Return value:
2580 * 0 on success / other on failure
2581 **/
2582static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
2583{
2584 volatile u32 pcii_reg;
2585 int delay = 1;
2586
2587 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2588 while (delay < max_delay) {
2589 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
2590
2591 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
2592 return 0;
2593
2594 /* udelay cannot be used if delay is more than a few milliseconds */
2595 if ((delay / 1000) > MAX_UDELAY_MS)
2596 mdelay(delay / 1000);
2597 else
2598 udelay(delay);
2599
2600 delay += delay;
2601 }
2602 return -EIO;
2603}
2604
2605/**
Wayne Boyerdcbad002010-02-19 13:24:14 -08002606 * ipr_get_sis64_dump_data_section - Dump IOA memory
2607 * @ioa_cfg: ioa config struct
2608 * @start_addr: adapter address to dump
2609 * @dest: destination kernel buffer
2610 * @length_in_words: length to dump in 4 byte words
2611 *
2612 * Return value:
2613 * 0 on success
2614 **/
2615static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2616 u32 start_addr,
2617 __be32 *dest, u32 length_in_words)
2618{
2619 int i;
2620
2621 for (i = 0; i < length_in_words; i++) {
2622 writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
2623 *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
2624 dest++;
2625 }
2626
2627 return 0;
2628}
2629
2630/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 * ipr_get_ldump_data_section - Dump IOA memory
2632 * @ioa_cfg: ioa config struct
2633 * @start_addr: adapter address to dump
2634 * @dest: destination kernel buffer
2635 * @length_in_words: length to dump in 4 byte words
2636 *
2637 * Return value:
2638 * 0 on success / -EIO on failure
2639 **/
2640static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2641 u32 start_addr,
2642 __be32 *dest, u32 length_in_words)
2643{
2644 volatile u32 temp_pcii_reg;
2645 int i, delay = 0;
2646
Wayne Boyerdcbad002010-02-19 13:24:14 -08002647 if (ioa_cfg->sis64)
2648 return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
2649 dest, length_in_words);
2650
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 /* Write IOA interrupt reg starting LDUMP state */
2652 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
Wayne Boyer214777b2010-02-19 13:24:26 -08002653 ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
2655 /* Wait for IO debug acknowledge */
2656 if (ipr_wait_iodbg_ack(ioa_cfg,
2657 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
2658 dev_err(&ioa_cfg->pdev->dev,
2659 "IOA dump long data transfer timeout\n");
2660 return -EIO;
2661 }
2662
2663 /* Signal LDUMP interlocked - clear IO debug ack */
2664 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2665 ioa_cfg->regs.clr_interrupt_reg);
2666
2667 /* Write Mailbox with starting address */
2668 writel(start_addr, ioa_cfg->ioa_mailbox);
2669
2670 /* Signal address valid - clear IOA Reset alert */
2671 writel(IPR_UPROCI_RESET_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002672 ioa_cfg->regs.clr_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
2674 for (i = 0; i < length_in_words; i++) {
2675 /* Wait for IO debug acknowledge */
2676 if (ipr_wait_iodbg_ack(ioa_cfg,
2677 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2678 dev_err(&ioa_cfg->pdev->dev,
2679 "IOA dump short data transfer timeout\n");
2680 return -EIO;
2681 }
2682
2683 /* Read data from mailbox and increment destination pointer */
2684 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2685 dest++;
2686
2687 /* For all but the last word of data, signal data received */
2688 if (i < (length_in_words - 1)) {
2689 /* Signal dump data received - Clear IO debug Ack */
2690 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2691 ioa_cfg->regs.clr_interrupt_reg);
2692 }
2693 }
2694
2695 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2696 writel(IPR_UPROCI_RESET_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002697 ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
2699 writel(IPR_UPROCI_IO_DEBUG_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002700 ioa_cfg->regs.clr_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
2702 /* Signal dump data received - Clear IO debug Ack */
2703 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2704 ioa_cfg->regs.clr_interrupt_reg);
2705
2706 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2707 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2708 temp_pcii_reg =
Wayne Boyer214777b2010-02-19 13:24:26 -08002709 readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710
2711 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2712 return 0;
2713
2714 udelay(10);
2715 delay += 10;
2716 }
2717
2718 return 0;
2719}
2720
2721#ifdef CONFIG_SCSI_IPR_DUMP
2722/**
2723 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2724 * @ioa_cfg: ioa config struct
2725 * @pci_address: adapter address
2726 * @length: length of data to copy
2727 *
2728 * Copy data from PCI adapter to kernel buffer.
2729 * Note: length MUST be a 4 byte multiple
2730 * Return value:
2731 * 0 on success / other on failure
2732 **/
2733static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2734 unsigned long pci_address, u32 length)
2735{
2736 int bytes_copied = 0;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002737 int cur_len, rc, rem_len, rem_page_len, max_dump_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 __be32 *page;
2739 unsigned long lock_flags = 0;
2740 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2741
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002742 if (ioa_cfg->sis64)
2743 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2744 else
2745 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2746
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 while (bytes_copied < length &&
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002748 (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 if (ioa_dump->page_offset >= PAGE_SIZE ||
2750 ioa_dump->page_offset == 0) {
2751 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2752
2753 if (!page) {
2754 ipr_trace;
2755 return bytes_copied;
2756 }
2757
2758 ioa_dump->page_offset = 0;
2759 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2760 ioa_dump->next_page_index++;
2761 } else
2762 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2763
2764 rem_len = length - bytes_copied;
2765 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2766 cur_len = min(rem_len, rem_page_len);
2767
2768 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2769 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2770 rc = -EIO;
2771 } else {
2772 rc = ipr_get_ldump_data_section(ioa_cfg,
2773 pci_address + bytes_copied,
2774 &page[ioa_dump->page_offset / 4],
2775 (cur_len / sizeof(u32)));
2776 }
2777 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2778
2779 if (!rc) {
2780 ioa_dump->page_offset += cur_len;
2781 bytes_copied += cur_len;
2782 } else {
2783 ipr_trace;
2784 break;
2785 }
2786 schedule();
2787 }
2788
2789 return bytes_copied;
2790}
2791
2792/**
2793 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2794 * @hdr: dump entry header struct
2795 *
2796 * Return value:
2797 * nothing
2798 **/
2799static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2800{
2801 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2802 hdr->num_elems = 1;
2803 hdr->offset = sizeof(*hdr);
2804 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2805}
2806
2807/**
2808 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2809 * @ioa_cfg: ioa config struct
2810 * @driver_dump: driver dump struct
2811 *
2812 * Return value:
2813 * nothing
2814 **/
2815static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2816 struct ipr_driver_dump *driver_dump)
2817{
2818 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2819
2820 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2821 driver_dump->ioa_type_entry.hdr.len =
2822 sizeof(struct ipr_dump_ioa_type_entry) -
2823 sizeof(struct ipr_dump_entry_header);
2824 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2825 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2826 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2827 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2828 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2829 ucode_vpd->minor_release[1];
2830 driver_dump->hdr.num_entries++;
2831}
2832
2833/**
2834 * ipr_dump_version_data - Fill in the driver version in the dump.
2835 * @ioa_cfg: ioa config struct
2836 * @driver_dump: driver dump struct
2837 *
2838 * Return value:
2839 * nothing
2840 **/
2841static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2842 struct ipr_driver_dump *driver_dump)
2843{
2844 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2845 driver_dump->version_entry.hdr.len =
2846 sizeof(struct ipr_dump_version_entry) -
2847 sizeof(struct ipr_dump_entry_header);
2848 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2849 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2850 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2851 driver_dump->hdr.num_entries++;
2852}
2853
2854/**
2855 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2856 * @ioa_cfg: ioa config struct
2857 * @driver_dump: driver dump struct
2858 *
2859 * Return value:
2860 * nothing
2861 **/
2862static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
2863 struct ipr_driver_dump *driver_dump)
2864{
2865 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
2866 driver_dump->trace_entry.hdr.len =
2867 sizeof(struct ipr_dump_trace_entry) -
2868 sizeof(struct ipr_dump_entry_header);
2869 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2870 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
2871 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
2872 driver_dump->hdr.num_entries++;
2873}
2874
2875/**
2876 * ipr_dump_location_data - Fill in the IOA location in the dump.
2877 * @ioa_cfg: ioa config struct
2878 * @driver_dump: driver dump struct
2879 *
2880 * Return value:
2881 * nothing
2882 **/
2883static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
2884 struct ipr_driver_dump *driver_dump)
2885{
2886 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
2887 driver_dump->location_entry.hdr.len =
2888 sizeof(struct ipr_dump_location_entry) -
2889 sizeof(struct ipr_dump_entry_header);
2890 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2891 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
Kay Sievers71610f52008-12-03 22:41:36 +01002892 strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 driver_dump->hdr.num_entries++;
2894}
2895
2896/**
2897 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2898 * @ioa_cfg: ioa config struct
2899 * @dump: dump struct
2900 *
2901 * Return value:
2902 * nothing
2903 **/
2904static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
2905{
2906 unsigned long start_addr, sdt_word;
2907 unsigned long lock_flags = 0;
2908 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
2909 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002910 u32 num_entries, max_num_entries, start_off, end_off;
2911 u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 struct ipr_sdt *sdt;
Wayne Boyerdcbad002010-02-19 13:24:14 -08002913 int valid = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 int i;
2915
2916 ENTER;
2917
2918 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2919
Brian King41e9a692011-09-21 08:51:11 -05002920 if (ioa_cfg->sdt_state != READ_DUMP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2922 return;
2923 }
2924
Wayne Boyer110def82010-11-04 09:36:16 -07002925 if (ioa_cfg->sis64) {
2926 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2927 ssleep(IPR_DUMP_DELAY_SECONDS);
2928 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2929 }
2930
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 start_addr = readl(ioa_cfg->ioa_mailbox);
2932
Wayne Boyerdcbad002010-02-19 13:24:14 -08002933 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 dev_err(&ioa_cfg->pdev->dev,
2935 "Invalid dump table format: %lx\n", start_addr);
2936 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2937 return;
2938 }
2939
2940 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
2941
2942 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
2943
2944 /* Initialize the overall dump header */
2945 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
2946 driver_dump->hdr.num_entries = 1;
2947 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
2948 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
2949 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
2950 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
2951
2952 ipr_dump_version_data(ioa_cfg, driver_dump);
2953 ipr_dump_location_data(ioa_cfg, driver_dump);
2954 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
2955 ipr_dump_trace_data(ioa_cfg, driver_dump);
2956
2957 /* Update dump_header */
2958 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
2959
2960 /* IOA Dump entry */
2961 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 ioa_dump->hdr.len = 0;
2963 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2964 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
2965
2966 /* First entries in sdt are actually a list of dump addresses and
2967 lengths to gather the real dump data. sdt represents the pointer
2968 to the ioa generated dump table. Dump data will be extracted based
2969 on entries in this table */
2970 sdt = &ioa_dump->sdt;
2971
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002972 if (ioa_cfg->sis64) {
2973 max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
2974 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2975 } else {
2976 max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
2977 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2978 }
2979
2980 bytes_to_copy = offsetof(struct ipr_sdt, entry) +
2981 (max_num_entries * sizeof(struct ipr_sdt_entry));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002983 bytes_to_copy / sizeof(__be32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984
2985 /* Smart Dump table is ready to use and the first entry is valid */
Wayne Boyerdcbad002010-02-19 13:24:14 -08002986 if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
2987 (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 dev_err(&ioa_cfg->pdev->dev,
2989 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
2990 rc, be32_to_cpu(sdt->hdr.state));
2991 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
2992 ioa_cfg->sdt_state = DUMP_OBTAINED;
2993 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2994 return;
2995 }
2996
2997 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
2998
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002999 if (num_entries > max_num_entries)
3000 num_entries = max_num_entries;
3001
3002 /* Update dump length to the actual data to be copied */
3003 dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
3004 if (ioa_cfg->sis64)
3005 dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
3006 else
3007 dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008
3009 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3010
3011 for (i = 0; i < num_entries; i++) {
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003012 if (ioa_dump->hdr.len > max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3014 break;
3015 }
3016
3017 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
Wayne Boyerdcbad002010-02-19 13:24:14 -08003018 sdt_word = be32_to_cpu(sdt->entry[i].start_token);
3019 if (ioa_cfg->sis64)
3020 bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
3021 else {
3022 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
3023 end_off = be32_to_cpu(sdt->entry[i].end_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024
Wayne Boyerdcbad002010-02-19 13:24:14 -08003025 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
3026 bytes_to_copy = end_off - start_off;
3027 else
3028 valid = 0;
3029 }
3030 if (valid) {
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003031 if (bytes_to_copy > max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
3033 continue;
3034 }
3035
3036 /* Copy data from adapter to driver buffers */
3037 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
3038 bytes_to_copy);
3039
3040 ioa_dump->hdr.len += bytes_copied;
3041
3042 if (bytes_copied != bytes_to_copy) {
3043 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3044 break;
3045 }
3046 }
3047 }
3048 }
3049
3050 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
3051
3052 /* Update dump_header */
3053 driver_dump->hdr.len += ioa_dump->hdr.len;
3054 wmb();
3055 ioa_cfg->sdt_state = DUMP_OBTAINED;
3056 LEAVE;
3057}
3058
3059#else
3060#define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
3061#endif
3062
3063/**
3064 * ipr_release_dump - Free adapter dump memory
3065 * @kref: kref struct
3066 *
3067 * Return value:
3068 * nothing
3069 **/
3070static void ipr_release_dump(struct kref *kref)
3071{
3072 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
3073 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
3074 unsigned long lock_flags = 0;
3075 int i;
3076
3077 ENTER;
3078 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3079 ioa_cfg->dump = NULL;
3080 ioa_cfg->sdt_state = INACTIVE;
3081 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3082
3083 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
3084 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
3085
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003086 vfree(dump->ioa_dump.ioa_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 kfree(dump);
3088 LEAVE;
3089}
3090
3091/**
3092 * ipr_worker_thread - Worker thread
David Howellsc4028952006-11-22 14:57:56 +00003093 * @work: ioa config struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 *
3095 * Called at task level from a work thread. This function takes care
3096 * of adding and removing device from the mid-layer as configuration
3097 * changes are detected by the adapter.
3098 *
3099 * Return value:
3100 * nothing
3101 **/
David Howellsc4028952006-11-22 14:57:56 +00003102static void ipr_worker_thread(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103{
3104 unsigned long lock_flags;
3105 struct ipr_resource_entry *res;
3106 struct scsi_device *sdev;
3107 struct ipr_dump *dump;
David Howellsc4028952006-11-22 14:57:56 +00003108 struct ipr_ioa_cfg *ioa_cfg =
3109 container_of(work, struct ipr_ioa_cfg, work_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 u8 bus, target, lun;
3111 int did_work;
3112
3113 ENTER;
3114 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3115
Brian King41e9a692011-09-21 08:51:11 -05003116 if (ioa_cfg->sdt_state == READ_DUMP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 dump = ioa_cfg->dump;
3118 if (!dump) {
3119 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3120 return;
3121 }
3122 kref_get(&dump->kref);
3123 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3124 ipr_get_ioa_dump(ioa_cfg, dump);
3125 kref_put(&dump->kref, ipr_release_dump);
3126
3127 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King4c647e92011-10-15 09:08:56 -05003128 if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3130 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3131 return;
3132 }
3133
3134restart:
3135 do {
3136 did_work = 0;
3137 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
3138 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3139 return;
3140 }
3141
3142 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3143 if (res->del_from_ml && res->sdev) {
3144 did_work = 1;
3145 sdev = res->sdev;
3146 if (!scsi_device_get(sdev)) {
Kleber Sacilotto de Souza5767a1c2011-02-14 20:19:31 -02003147 if (!res->add_to_ml)
3148 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
3149 else
3150 res->del_from_ml = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3152 scsi_remove_device(sdev);
3153 scsi_device_put(sdev);
3154 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3155 }
3156 break;
3157 }
3158 }
3159 } while(did_work);
3160
3161 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3162 if (res->add_to_ml) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08003163 bus = res->bus;
3164 target = res->target;
3165 lun = res->lun;
Brian King1121b792006-03-29 09:37:16 -06003166 res->add_to_ml = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3168 scsi_add_device(ioa_cfg->host, bus, target, lun);
3169 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3170 goto restart;
3171 }
3172 }
3173
3174 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Tony Jonesee959b02008-02-22 00:13:36 +01003175 kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 LEAVE;
3177}
3178
3179#ifdef CONFIG_SCSI_IPR_TRACE
3180/**
3181 * ipr_read_trace - Dump the adapter trace
Chris Wright2c3c8be2010-05-12 18:28:57 -07003182 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08003184 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 * @buf: buffer
3186 * @off: offset
3187 * @count: buffer size
3188 *
3189 * Return value:
3190 * number of bytes printed to buffer
3191 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07003192static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08003193 struct bin_attribute *bin_attr,
3194 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195{
Tony Jonesee959b02008-02-22 00:13:36 +01003196 struct device *dev = container_of(kobj, struct device, kobj);
3197 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3199 unsigned long lock_flags = 0;
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003200 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201
3202 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003203 ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
3204 IPR_TRACE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003206
3207 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208}
3209
3210static struct bin_attribute ipr_trace_attr = {
3211 .attr = {
3212 .name = "trace",
3213 .mode = S_IRUGO,
3214 },
3215 .size = 0,
3216 .read = ipr_read_trace,
3217};
3218#endif
3219
3220/**
3221 * ipr_show_fw_version - Show the firmware version
Tony Jonesee959b02008-02-22 00:13:36 +01003222 * @dev: class device struct
3223 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 *
3225 * Return value:
3226 * number of bytes printed to buffer
3227 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003228static ssize_t ipr_show_fw_version(struct device *dev,
3229 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230{
Tony Jonesee959b02008-02-22 00:13:36 +01003231 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3233 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
3234 unsigned long lock_flags = 0;
3235 int len;
3236
3237 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3238 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
3239 ucode_vpd->major_release, ucode_vpd->card_type,
3240 ucode_vpd->minor_release[0],
3241 ucode_vpd->minor_release[1]);
3242 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3243 return len;
3244}
3245
Tony Jonesee959b02008-02-22 00:13:36 +01003246static struct device_attribute ipr_fw_version_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 .attr = {
3248 .name = "fw_version",
3249 .mode = S_IRUGO,
3250 },
3251 .show = ipr_show_fw_version,
3252};
3253
3254/**
3255 * ipr_show_log_level - Show the adapter's error logging level
Tony Jonesee959b02008-02-22 00:13:36 +01003256 * @dev: class device struct
3257 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 *
3259 * Return value:
3260 * number of bytes printed to buffer
3261 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003262static ssize_t ipr_show_log_level(struct device *dev,
3263 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264{
Tony Jonesee959b02008-02-22 00:13:36 +01003265 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3267 unsigned long lock_flags = 0;
3268 int len;
3269
3270 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3271 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
3272 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3273 return len;
3274}
3275
3276/**
3277 * ipr_store_log_level - Change the adapter's error logging level
Tony Jonesee959b02008-02-22 00:13:36 +01003278 * @dev: class device struct
3279 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 *
3281 * Return value:
3282 * number of bytes printed to buffer
3283 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003284static ssize_t ipr_store_log_level(struct device *dev,
3285 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 const char *buf, size_t count)
3287{
Tony Jonesee959b02008-02-22 00:13:36 +01003288 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3290 unsigned long lock_flags = 0;
3291
3292 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3293 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
3294 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3295 return strlen(buf);
3296}
3297
Tony Jonesee959b02008-02-22 00:13:36 +01003298static struct device_attribute ipr_log_level_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 .attr = {
3300 .name = "log_level",
3301 .mode = S_IRUGO | S_IWUSR,
3302 },
3303 .show = ipr_show_log_level,
3304 .store = ipr_store_log_level
3305};
3306
3307/**
3308 * ipr_store_diagnostics - IOA Diagnostics interface
Tony Jonesee959b02008-02-22 00:13:36 +01003309 * @dev: device struct
3310 * @buf: buffer
3311 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 *
3313 * This function will reset the adapter and wait a reasonable
3314 * amount of time for any errors that the adapter might log.
3315 *
3316 * Return value:
3317 * count on success / other on failure
3318 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003319static ssize_t ipr_store_diagnostics(struct device *dev,
3320 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 const char *buf, size_t count)
3322{
Tony Jonesee959b02008-02-22 00:13:36 +01003323 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3325 unsigned long lock_flags = 0;
3326 int rc = count;
3327
3328 if (!capable(CAP_SYS_ADMIN))
3329 return -EACCES;
3330
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King970ea292007-04-26 16:00:06 -05003332 while(ioa_cfg->in_reset_reload) {
3333 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3334 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3335 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3336 }
3337
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 ioa_cfg->errors_logged = 0;
3339 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3340
3341 if (ioa_cfg->in_reset_reload) {
3342 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3343 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3344
3345 /* Wait for a second for any errors to be logged */
3346 msleep(1000);
3347 } else {
3348 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3349 return -EIO;
3350 }
3351
3352 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3353 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
3354 rc = -EIO;
3355 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3356
3357 return rc;
3358}
3359
Tony Jonesee959b02008-02-22 00:13:36 +01003360static struct device_attribute ipr_diagnostics_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 .attr = {
3362 .name = "run_diagnostics",
3363 .mode = S_IWUSR,
3364 },
3365 .store = ipr_store_diagnostics
3366};
3367
3368/**
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003369 * ipr_show_adapter_state - Show the adapter's state
Tony Jonesee959b02008-02-22 00:13:36 +01003370 * @class_dev: device struct
3371 * @buf: buffer
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003372 *
3373 * Return value:
3374 * number of bytes printed to buffer
3375 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003376static ssize_t ipr_show_adapter_state(struct device *dev,
3377 struct device_attribute *attr, char *buf)
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003378{
Tony Jonesee959b02008-02-22 00:13:36 +01003379 struct Scsi_Host *shost = class_to_shost(dev);
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003380 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3381 unsigned long lock_flags = 0;
3382 int len;
3383
3384 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3385 if (ioa_cfg->ioa_is_dead)
3386 len = snprintf(buf, PAGE_SIZE, "offline\n");
3387 else
3388 len = snprintf(buf, PAGE_SIZE, "online\n");
3389 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3390 return len;
3391}
3392
3393/**
3394 * ipr_store_adapter_state - Change adapter state
Tony Jonesee959b02008-02-22 00:13:36 +01003395 * @dev: device struct
3396 * @buf: buffer
3397 * @count: buffer size
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003398 *
3399 * This function will change the adapter's state.
3400 *
3401 * Return value:
3402 * count on success / other on failure
3403 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003404static ssize_t ipr_store_adapter_state(struct device *dev,
3405 struct device_attribute *attr,
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003406 const char *buf, size_t count)
3407{
Tony Jonesee959b02008-02-22 00:13:36 +01003408 struct Scsi_Host *shost = class_to_shost(dev);
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003409 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3410 unsigned long lock_flags;
3411 int result = count;
3412
3413 if (!capable(CAP_SYS_ADMIN))
3414 return -EACCES;
3415
3416 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3417 if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
3418 ioa_cfg->ioa_is_dead = 0;
3419 ioa_cfg->reset_retries = 0;
3420 ioa_cfg->in_ioa_bringdown = 0;
3421 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3422 }
3423 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3424 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3425
3426 return result;
3427}
3428
Tony Jonesee959b02008-02-22 00:13:36 +01003429static struct device_attribute ipr_ioa_state_attr = {
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003430 .attr = {
Brian King49dd0962008-04-28 17:36:20 -05003431 .name = "online_state",
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003432 .mode = S_IRUGO | S_IWUSR,
3433 },
3434 .show = ipr_show_adapter_state,
3435 .store = ipr_store_adapter_state
3436};
3437
3438/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 * ipr_store_reset_adapter - Reset the adapter
Tony Jonesee959b02008-02-22 00:13:36 +01003440 * @dev: device struct
3441 * @buf: buffer
3442 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 *
3444 * This function will reset the adapter.
3445 *
3446 * Return value:
3447 * count on success / other on failure
3448 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003449static ssize_t ipr_store_reset_adapter(struct device *dev,
3450 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 const char *buf, size_t count)
3452{
Tony Jonesee959b02008-02-22 00:13:36 +01003453 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3455 unsigned long lock_flags;
3456 int result = count;
3457
3458 if (!capable(CAP_SYS_ADMIN))
3459 return -EACCES;
3460
3461 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3462 if (!ioa_cfg->in_reset_reload)
3463 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3464 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3465 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3466
3467 return result;
3468}
3469
Tony Jonesee959b02008-02-22 00:13:36 +01003470static struct device_attribute ipr_ioa_reset_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 .attr = {
3472 .name = "reset_host",
3473 .mode = S_IWUSR,
3474 },
3475 .store = ipr_store_reset_adapter
3476};
3477
3478/**
3479 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3480 * @buf_len: buffer length
3481 *
3482 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3483 * list to use for microcode download
3484 *
3485 * Return value:
3486 * pointer to sglist / NULL on failure
3487 **/
3488static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
3489{
3490 int sg_size, order, bsize_elem, num_elem, i, j;
3491 struct ipr_sglist *sglist;
3492 struct scatterlist *scatterlist;
3493 struct page *page;
3494
3495 /* Get the minimum size per scatter/gather element */
3496 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
3497
3498 /* Get the actual size per element */
3499 order = get_order(sg_size);
3500
3501 /* Determine the actual number of bytes per element */
3502 bsize_elem = PAGE_SIZE * (1 << order);
3503
3504 /* Determine the actual number of sg entries needed */
3505 if (buf_len % bsize_elem)
3506 num_elem = (buf_len / bsize_elem) + 1;
3507 else
3508 num_elem = buf_len / bsize_elem;
3509
3510 /* Allocate a scatter/gather list for the DMA */
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06003511 sglist = kzalloc(sizeof(struct ipr_sglist) +
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 (sizeof(struct scatterlist) * (num_elem - 1)),
3513 GFP_KERNEL);
3514
3515 if (sglist == NULL) {
3516 ipr_trace;
3517 return NULL;
3518 }
3519
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 scatterlist = sglist->scatterlist;
Jens Axboe45711f12007-10-22 21:19:53 +02003521 sg_init_table(scatterlist, num_elem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522
3523 sglist->order = order;
3524 sglist->num_sg = num_elem;
3525
3526 /* Allocate a bunch of sg elements */
3527 for (i = 0; i < num_elem; i++) {
3528 page = alloc_pages(GFP_KERNEL, order);
3529 if (!page) {
3530 ipr_trace;
3531
3532 /* Free up what we already allocated */
3533 for (j = i - 1; j >= 0; j--)
Jens Axboe45711f12007-10-22 21:19:53 +02003534 __free_pages(sg_page(&scatterlist[j]), order);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 kfree(sglist);
3536 return NULL;
3537 }
3538
Jens Axboe642f1492007-10-24 11:20:47 +02003539 sg_set_page(&scatterlist[i], page, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 }
3541
3542 return sglist;
3543}
3544
3545/**
3546 * ipr_free_ucode_buffer - Frees a microcode download buffer
3547 * @p_dnld: scatter/gather list pointer
3548 *
3549 * Free a DMA'able ucode download buffer previously allocated with
3550 * ipr_alloc_ucode_buffer
3551 *
3552 * Return value:
3553 * nothing
3554 **/
3555static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
3556{
3557 int i;
3558
3559 for (i = 0; i < sglist->num_sg; i++)
Jens Axboe45711f12007-10-22 21:19:53 +02003560 __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561
3562 kfree(sglist);
3563}
3564
3565/**
3566 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3567 * @sglist: scatter/gather list pointer
3568 * @buffer: buffer pointer
3569 * @len: buffer length
3570 *
3571 * Copy a microcode image from a user buffer into a buffer allocated by
3572 * ipr_alloc_ucode_buffer
3573 *
3574 * Return value:
3575 * 0 on success / other on failure
3576 **/
3577static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
3578 u8 *buffer, u32 len)
3579{
3580 int bsize_elem, i, result = 0;
3581 struct scatterlist *scatterlist;
3582 void *kaddr;
3583
3584 /* Determine the actual number of bytes per element */
3585 bsize_elem = PAGE_SIZE * (1 << sglist->order);
3586
3587 scatterlist = sglist->scatterlist;
3588
3589 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
Jens Axboe45711f12007-10-22 21:19:53 +02003590 struct page *page = sg_page(&scatterlist[i]);
3591
3592 kaddr = kmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 memcpy(kaddr, buffer, bsize_elem);
Jens Axboe45711f12007-10-22 21:19:53 +02003594 kunmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595
3596 scatterlist[i].length = bsize_elem;
3597
3598 if (result != 0) {
3599 ipr_trace;
3600 return result;
3601 }
3602 }
3603
3604 if (len % bsize_elem) {
Jens Axboe45711f12007-10-22 21:19:53 +02003605 struct page *page = sg_page(&scatterlist[i]);
3606
3607 kaddr = kmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 memcpy(kaddr, buffer, len % bsize_elem);
Jens Axboe45711f12007-10-22 21:19:53 +02003609 kunmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610
3611 scatterlist[i].length = len % bsize_elem;
3612 }
3613
3614 sglist->buffer_len = len;
3615 return result;
3616}
3617
3618/**
Wayne Boyera32c0552010-02-19 13:23:36 -08003619 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3620 * @ipr_cmd: ipr command struct
3621 * @sglist: scatter/gather list
3622 *
3623 * Builds a microcode download IOA data list (IOADL).
3624 *
3625 **/
3626static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
3627 struct ipr_sglist *sglist)
3628{
3629 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3630 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
3631 struct scatterlist *scatterlist = sglist->scatterlist;
3632 int i;
3633
3634 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3635 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3636 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3637
3638 ioarcb->ioadl_len =
3639 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
3640 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3641 ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
3642 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
3643 ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
3644 }
3645
3646 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3647}
3648
3649/**
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003650 * ipr_build_ucode_ioadl - Build a microcode download IOADL
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 * @ipr_cmd: ipr command struct
3652 * @sglist: scatter/gather list
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 *
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003654 * Builds a microcode download IOA data list (IOADL).
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656 **/
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003657static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
3658 struct ipr_sglist *sglist)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08003661 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 struct scatterlist *scatterlist = sglist->scatterlist;
3663 int i;
3664
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003665 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08003667 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3668
3669 ioarcb->ioadl_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3671
3672 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3673 ioadl[i].flags_and_data_len =
3674 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
3675 ioadl[i].address =
3676 cpu_to_be32(sg_dma_address(&scatterlist[i]));
3677 }
3678
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003679 ioadl[i-1].flags_and_data_len |=
3680 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3681}
3682
3683/**
3684 * ipr_update_ioa_ucode - Update IOA's microcode
3685 * @ioa_cfg: ioa config struct
3686 * @sglist: scatter/gather list
3687 *
3688 * Initiate an adapter reset to update the IOA's microcode
3689 *
3690 * Return value:
3691 * 0 on success / -EIO on failure
3692 **/
3693static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3694 struct ipr_sglist *sglist)
3695{
3696 unsigned long lock_flags;
3697
3698 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King970ea292007-04-26 16:00:06 -05003699 while(ioa_cfg->in_reset_reload) {
3700 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3701 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3702 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3703 }
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003704
3705 if (ioa_cfg->ucode_sglist) {
3706 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3707 dev_err(&ioa_cfg->pdev->dev,
3708 "Microcode download already in progress\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 return -EIO;
3710 }
3711
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003712 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
3713 sglist->num_sg, DMA_TO_DEVICE);
3714
3715 if (!sglist->num_dma_sg) {
3716 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3717 dev_err(&ioa_cfg->pdev->dev,
3718 "Failed to map microcode download buffer!\n");
3719 return -EIO;
3720 }
3721
3722 ioa_cfg->ucode_sglist = sglist;
3723 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3724 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3725 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3726
3727 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3728 ioa_cfg->ucode_sglist = NULL;
3729 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 return 0;
3731}
3732
3733/**
3734 * ipr_store_update_fw - Update the firmware on the adapter
Tony Jonesee959b02008-02-22 00:13:36 +01003735 * @class_dev: device struct
3736 * @buf: buffer
3737 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 *
3739 * This function will update the firmware on the adapter.
3740 *
3741 * Return value:
3742 * count on success / other on failure
3743 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003744static ssize_t ipr_store_update_fw(struct device *dev,
3745 struct device_attribute *attr,
3746 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747{
Tony Jonesee959b02008-02-22 00:13:36 +01003748 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3750 struct ipr_ucode_image_header *image_hdr;
3751 const struct firmware *fw_entry;
3752 struct ipr_sglist *sglist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 char fname[100];
3754 char *src;
3755 int len, result, dnld_size;
3756
3757 if (!capable(CAP_SYS_ADMIN))
3758 return -EACCES;
3759
3760 len = snprintf(fname, 99, "%s", buf);
3761 fname[len-1] = '\0';
3762
3763 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3764 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3765 return -EIO;
3766 }
3767
3768 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
3769
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
3771 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
3772 sglist = ipr_alloc_ucode_buffer(dnld_size);
3773
3774 if (!sglist) {
3775 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
3776 release_firmware(fw_entry);
3777 return -ENOMEM;
3778 }
3779
3780 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
3781
3782 if (result) {
3783 dev_err(&ioa_cfg->pdev->dev,
3784 "Microcode buffer copy to DMA buffer failed\n");
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003785 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 }
3787
Wayne Boyer14ed9cc2011-10-03 20:54:37 -07003788 ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
3789
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003790 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003792 if (!result)
3793 result = count;
3794out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 ipr_free_ucode_buffer(sglist);
3796 release_firmware(fw_entry);
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003797 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798}
3799
Tony Jonesee959b02008-02-22 00:13:36 +01003800static struct device_attribute ipr_update_fw_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 .attr = {
3802 .name = "update_fw",
3803 .mode = S_IWUSR,
3804 },
3805 .store = ipr_store_update_fw
3806};
3807
Wayne Boyer75576bb2010-07-14 10:50:14 -07003808/**
3809 * ipr_show_fw_type - Show the adapter's firmware type.
3810 * @dev: class device struct
3811 * @buf: buffer
3812 *
3813 * Return value:
3814 * number of bytes printed to buffer
3815 **/
3816static ssize_t ipr_show_fw_type(struct device *dev,
3817 struct device_attribute *attr, char *buf)
3818{
3819 struct Scsi_Host *shost = class_to_shost(dev);
3820 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3821 unsigned long lock_flags = 0;
3822 int len;
3823
3824 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3825 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
3826 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3827 return len;
3828}
3829
3830static struct device_attribute ipr_ioa_fw_type_attr = {
3831 .attr = {
3832 .name = "fw_type",
3833 .mode = S_IRUGO,
3834 },
3835 .show = ipr_show_fw_type
3836};
3837
Tony Jonesee959b02008-02-22 00:13:36 +01003838static struct device_attribute *ipr_ioa_attrs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 &ipr_fw_version_attr,
3840 &ipr_log_level_attr,
3841 &ipr_diagnostics_attr,
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003842 &ipr_ioa_state_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 &ipr_ioa_reset_attr,
3844 &ipr_update_fw_attr,
Wayne Boyer75576bb2010-07-14 10:50:14 -07003845 &ipr_ioa_fw_type_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 NULL,
3847};
3848
3849#ifdef CONFIG_SCSI_IPR_DUMP
3850/**
3851 * ipr_read_dump - Dump the adapter
Chris Wright2c3c8be2010-05-12 18:28:57 -07003852 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08003854 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 * @buf: buffer
3856 * @off: offset
3857 * @count: buffer size
3858 *
3859 * Return value:
3860 * number of bytes printed to buffer
3861 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07003862static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08003863 struct bin_attribute *bin_attr,
3864 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865{
Tony Jonesee959b02008-02-22 00:13:36 +01003866 struct device *cdev = container_of(kobj, struct device, kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 struct Scsi_Host *shost = class_to_shost(cdev);
3868 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3869 struct ipr_dump *dump;
3870 unsigned long lock_flags = 0;
3871 char *src;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003872 int len, sdt_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 size_t rc = count;
3874
3875 if (!capable(CAP_SYS_ADMIN))
3876 return -EACCES;
3877
3878 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3879 dump = ioa_cfg->dump;
3880
3881 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
3882 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3883 return 0;
3884 }
3885 kref_get(&dump->kref);
3886 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3887
3888 if (off > dump->driver_dump.hdr.len) {
3889 kref_put(&dump->kref, ipr_release_dump);
3890 return 0;
3891 }
3892
3893 if (off + count > dump->driver_dump.hdr.len) {
3894 count = dump->driver_dump.hdr.len - off;
3895 rc = count;
3896 }
3897
3898 if (count && off < sizeof(dump->driver_dump)) {
3899 if (off + count > sizeof(dump->driver_dump))
3900 len = sizeof(dump->driver_dump) - off;
3901 else
3902 len = count;
3903 src = (u8 *)&dump->driver_dump + off;
3904 memcpy(buf, src, len);
3905 buf += len;
3906 off += len;
3907 count -= len;
3908 }
3909
3910 off -= sizeof(dump->driver_dump);
3911
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003912 if (ioa_cfg->sis64)
3913 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
3914 (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
3915 sizeof(struct ipr_sdt_entry));
3916 else
3917 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
3918 (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
3919
3920 if (count && off < sdt_end) {
3921 if (off + count > sdt_end)
3922 len = sdt_end - off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 else
3924 len = count;
3925 src = (u8 *)&dump->ioa_dump + off;
3926 memcpy(buf, src, len);
3927 buf += len;
3928 off += len;
3929 count -= len;
3930 }
3931
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003932 off -= sdt_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933
3934 while (count) {
3935 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
3936 len = PAGE_ALIGN(off) - off;
3937 else
3938 len = count;
3939 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
3940 src += off & ~PAGE_MASK;
3941 memcpy(buf, src, len);
3942 buf += len;
3943 off += len;
3944 count -= len;
3945 }
3946
3947 kref_put(&dump->kref, ipr_release_dump);
3948 return rc;
3949}
3950
3951/**
3952 * ipr_alloc_dump - Prepare for adapter dump
3953 * @ioa_cfg: ioa config struct
3954 *
3955 * Return value:
3956 * 0 on success / other on failure
3957 **/
3958static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
3959{
3960 struct ipr_dump *dump;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003961 __be32 **ioa_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 unsigned long lock_flags = 0;
3963
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06003964 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965
3966 if (!dump) {
3967 ipr_err("Dump memory allocation failed\n");
3968 return -ENOMEM;
3969 }
3970
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003971 if (ioa_cfg->sis64)
3972 ioa_data = vmalloc(IPR_FMT3_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
3973 else
3974 ioa_data = vmalloc(IPR_FMT2_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
3975
3976 if (!ioa_data) {
3977 ipr_err("Dump memory allocation failed\n");
3978 kfree(dump);
3979 return -ENOMEM;
3980 }
3981
3982 dump->ioa_dump.ioa_data = ioa_data;
3983
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 kref_init(&dump->kref);
3985 dump->ioa_cfg = ioa_cfg;
3986
3987 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3988
3989 if (INACTIVE != ioa_cfg->sdt_state) {
3990 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003991 vfree(dump->ioa_dump.ioa_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 kfree(dump);
3993 return 0;
3994 }
3995
3996 ioa_cfg->dump = dump;
3997 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
3998 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
3999 ioa_cfg->dump_taken = 1;
4000 schedule_work(&ioa_cfg->work_q);
4001 }
4002 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4003
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 return 0;
4005}
4006
4007/**
4008 * ipr_free_dump - Free adapter dump memory
4009 * @ioa_cfg: ioa config struct
4010 *
4011 * Return value:
4012 * 0 on success / other on failure
4013 **/
4014static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
4015{
4016 struct ipr_dump *dump;
4017 unsigned long lock_flags = 0;
4018
4019 ENTER;
4020
4021 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4022 dump = ioa_cfg->dump;
4023 if (!dump) {
4024 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4025 return 0;
4026 }
4027
4028 ioa_cfg->dump = NULL;
4029 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4030
4031 kref_put(&dump->kref, ipr_release_dump);
4032
4033 LEAVE;
4034 return 0;
4035}
4036
4037/**
4038 * ipr_write_dump - Setup dump state of adapter
Chris Wright2c3c8be2010-05-12 18:28:57 -07004039 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08004041 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 * @buf: buffer
4043 * @off: offset
4044 * @count: buffer size
4045 *
4046 * Return value:
4047 * number of bytes printed to buffer
4048 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07004049static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08004050 struct bin_attribute *bin_attr,
4051 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052{
Tony Jonesee959b02008-02-22 00:13:36 +01004053 struct device *cdev = container_of(kobj, struct device, kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054 struct Scsi_Host *shost = class_to_shost(cdev);
4055 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4056 int rc;
4057
4058 if (!capable(CAP_SYS_ADMIN))
4059 return -EACCES;
4060
4061 if (buf[0] == '1')
4062 rc = ipr_alloc_dump(ioa_cfg);
4063 else if (buf[0] == '0')
4064 rc = ipr_free_dump(ioa_cfg);
4065 else
4066 return -EINVAL;
4067
4068 if (rc)
4069 return rc;
4070 else
4071 return count;
4072}
4073
4074static struct bin_attribute ipr_dump_attr = {
4075 .attr = {
4076 .name = "dump",
4077 .mode = S_IRUSR | S_IWUSR,
4078 },
4079 .size = 0,
4080 .read = ipr_read_dump,
4081 .write = ipr_write_dump
4082};
4083#else
4084static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
4085#endif
4086
4087/**
4088 * ipr_change_queue_depth - Change the device's queue depth
4089 * @sdev: scsi device struct
4090 * @qdepth: depth to set
Mike Christiee881a172009-10-15 17:46:39 -07004091 * @reason: calling context
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 *
4093 * Return value:
4094 * actual depth set
4095 **/
Mike Christiee881a172009-10-15 17:46:39 -07004096static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth,
4097 int reason)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098{
Brian King35a39692006-09-25 12:39:20 -05004099 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4100 struct ipr_resource_entry *res;
4101 unsigned long lock_flags = 0;
4102
Mike Christiee881a172009-10-15 17:46:39 -07004103 if (reason != SCSI_QDEPTH_DEFAULT)
4104 return -EOPNOTSUPP;
4105
Brian King35a39692006-09-25 12:39:20 -05004106 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4107 res = (struct ipr_resource_entry *)sdev->hostdata;
4108
4109 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
4110 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
4111 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4112
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
4114 return sdev->queue_depth;
4115}
4116
4117/**
4118 * ipr_change_queue_type - Change the device's queue type
4119 * @dsev: scsi device struct
4120 * @tag_type: type of tags to use
4121 *
4122 * Return value:
4123 * actual queue type set
4124 **/
4125static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
4126{
4127 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4128 struct ipr_resource_entry *res;
4129 unsigned long lock_flags = 0;
4130
4131 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4132 res = (struct ipr_resource_entry *)sdev->hostdata;
4133
4134 if (res) {
4135 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
4136 /*
4137 * We don't bother quiescing the device here since the
4138 * adapter firmware does it for us.
4139 */
4140 scsi_set_tag_type(sdev, tag_type);
4141
4142 if (tag_type)
4143 scsi_activate_tcq(sdev, sdev->queue_depth);
4144 else
4145 scsi_deactivate_tcq(sdev, sdev->queue_depth);
4146 } else
4147 tag_type = 0;
4148 } else
4149 tag_type = 0;
4150
4151 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4152 return tag_type;
4153}
4154
4155/**
4156 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4157 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004158 * @attr: device attribute structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 * @buf: buffer
4160 *
4161 * Return value:
4162 * number of bytes printed to buffer
4163 **/
Yani Ioannou10523b32005-05-17 06:43:37 -04004164static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165{
4166 struct scsi_device *sdev = to_scsi_device(dev);
4167 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4168 struct ipr_resource_entry *res;
4169 unsigned long lock_flags = 0;
4170 ssize_t len = -ENXIO;
4171
4172 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4173 res = (struct ipr_resource_entry *)sdev->hostdata;
4174 if (res)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004175 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4177 return len;
4178}
4179
4180static struct device_attribute ipr_adapter_handle_attr = {
4181 .attr = {
4182 .name = "adapter_handle",
4183 .mode = S_IRUSR,
4184 },
4185 .show = ipr_show_adapter_handle
4186};
4187
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004188/**
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004189 * ipr_show_resource_path - Show the resource path or the resource address for
4190 * this device.
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004191 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004192 * @attr: device attribute structure
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004193 * @buf: buffer
4194 *
4195 * Return value:
4196 * number of bytes printed to buffer
4197 **/
4198static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
4199{
4200 struct scsi_device *sdev = to_scsi_device(dev);
4201 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4202 struct ipr_resource_entry *res;
4203 unsigned long lock_flags = 0;
4204 ssize_t len = -ENXIO;
4205 char buffer[IPR_MAX_RES_PATH_LENGTH];
4206
4207 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4208 res = (struct ipr_resource_entry *)sdev->hostdata;
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004209 if (res && ioa_cfg->sis64)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004210 len = snprintf(buf, PAGE_SIZE, "%s\n",
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004211 ipr_format_res_path(res->res_path, buffer,
4212 sizeof(buffer)));
4213 else if (res)
4214 len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
4215 res->bus, res->target, res->lun);
4216
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004217 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4218 return len;
4219}
4220
4221static struct device_attribute ipr_resource_path_attr = {
4222 .attr = {
4223 .name = "resource_path",
Wayne Boyer75576bb2010-07-14 10:50:14 -07004224 .mode = S_IRUGO,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004225 },
4226 .show = ipr_show_resource_path
4227};
4228
Wayne Boyer75576bb2010-07-14 10:50:14 -07004229/**
Wayne Boyer46d74562010-08-11 07:15:17 -07004230 * ipr_show_device_id - Show the device_id for this device.
4231 * @dev: device struct
4232 * @attr: device attribute structure
4233 * @buf: buffer
4234 *
4235 * Return value:
4236 * number of bytes printed to buffer
4237 **/
4238static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
4239{
4240 struct scsi_device *sdev = to_scsi_device(dev);
4241 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4242 struct ipr_resource_entry *res;
4243 unsigned long lock_flags = 0;
4244 ssize_t len = -ENXIO;
4245
4246 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4247 res = (struct ipr_resource_entry *)sdev->hostdata;
4248 if (res && ioa_cfg->sis64)
4249 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->dev_id);
4250 else if (res)
4251 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
4252
4253 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4254 return len;
4255}
4256
4257static struct device_attribute ipr_device_id_attr = {
4258 .attr = {
4259 .name = "device_id",
4260 .mode = S_IRUGO,
4261 },
4262 .show = ipr_show_device_id
4263};
4264
4265/**
Wayne Boyer75576bb2010-07-14 10:50:14 -07004266 * ipr_show_resource_type - Show the resource type for this device.
4267 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004268 * @attr: device attribute structure
Wayne Boyer75576bb2010-07-14 10:50:14 -07004269 * @buf: buffer
4270 *
4271 * Return value:
4272 * number of bytes printed to buffer
4273 **/
4274static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
4275{
4276 struct scsi_device *sdev = to_scsi_device(dev);
4277 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4278 struct ipr_resource_entry *res;
4279 unsigned long lock_flags = 0;
4280 ssize_t len = -ENXIO;
4281
4282 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4283 res = (struct ipr_resource_entry *)sdev->hostdata;
4284
4285 if (res)
4286 len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
4287
4288 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4289 return len;
4290}
4291
4292static struct device_attribute ipr_resource_type_attr = {
4293 .attr = {
4294 .name = "resource_type",
4295 .mode = S_IRUGO,
4296 },
4297 .show = ipr_show_resource_type
4298};
4299
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300static struct device_attribute *ipr_dev_attrs[] = {
4301 &ipr_adapter_handle_attr,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004302 &ipr_resource_path_attr,
Wayne Boyer46d74562010-08-11 07:15:17 -07004303 &ipr_device_id_attr,
Wayne Boyer75576bb2010-07-14 10:50:14 -07004304 &ipr_resource_type_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305 NULL,
4306};
4307
4308/**
4309 * ipr_biosparam - Return the HSC mapping
4310 * @sdev: scsi device struct
4311 * @block_device: block device pointer
4312 * @capacity: capacity of the device
4313 * @parm: Array containing returned HSC values.
4314 *
4315 * This function generates the HSC parms that fdisk uses.
4316 * We want to make sure we return something that places partitions
4317 * on 4k boundaries for best performance with the IOA.
4318 *
4319 * Return value:
4320 * 0 on success
4321 **/
4322static int ipr_biosparam(struct scsi_device *sdev,
4323 struct block_device *block_device,
4324 sector_t capacity, int *parm)
4325{
4326 int heads, sectors;
4327 sector_t cylinders;
4328
4329 heads = 128;
4330 sectors = 32;
4331
4332 cylinders = capacity;
4333 sector_div(cylinders, (128 * 32));
4334
4335 /* return result */
4336 parm[0] = heads;
4337 parm[1] = sectors;
4338 parm[2] = cylinders;
4339
4340 return 0;
4341}
4342
4343/**
Brian King35a39692006-09-25 12:39:20 -05004344 * ipr_find_starget - Find target based on bus/target.
4345 * @starget: scsi target struct
4346 *
4347 * Return value:
4348 * resource entry pointer if found / NULL if not found
4349 **/
4350static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
4351{
4352 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4353 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4354 struct ipr_resource_entry *res;
4355
4356 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004357 if ((res->bus == starget->channel) &&
Brian King0ee1d712012-03-14 21:20:06 -05004358 (res->target == starget->id)) {
Brian King35a39692006-09-25 12:39:20 -05004359 return res;
4360 }
4361 }
4362
4363 return NULL;
4364}
4365
4366static struct ata_port_info sata_port_info;
4367
4368/**
4369 * ipr_target_alloc - Prepare for commands to a SCSI target
4370 * @starget: scsi target struct
4371 *
4372 * If the device is a SATA device, this function allocates an
4373 * ATA port with libata, else it does nothing.
4374 *
4375 * Return value:
4376 * 0 on success / non-0 on failure
4377 **/
4378static int ipr_target_alloc(struct scsi_target *starget)
4379{
4380 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4381 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4382 struct ipr_sata_port *sata_port;
4383 struct ata_port *ap;
4384 struct ipr_resource_entry *res;
4385 unsigned long lock_flags;
4386
4387 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4388 res = ipr_find_starget(starget);
4389 starget->hostdata = NULL;
4390
4391 if (res && ipr_is_gata(res)) {
4392 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4393 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
4394 if (!sata_port)
4395 return -ENOMEM;
4396
4397 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
4398 if (ap) {
4399 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4400 sata_port->ioa_cfg = ioa_cfg;
4401 sata_port->ap = ap;
4402 sata_port->res = res;
4403
4404 res->sata_port = sata_port;
4405 ap->private_data = sata_port;
4406 starget->hostdata = sata_port;
4407 } else {
4408 kfree(sata_port);
4409 return -ENOMEM;
4410 }
4411 }
4412 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4413
4414 return 0;
4415}
4416
4417/**
4418 * ipr_target_destroy - Destroy a SCSI target
4419 * @starget: scsi target struct
4420 *
4421 * If the device was a SATA device, this function frees the libata
4422 * ATA port, else it does nothing.
4423 *
4424 **/
4425static void ipr_target_destroy(struct scsi_target *starget)
4426{
4427 struct ipr_sata_port *sata_port = starget->hostdata;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004428 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4429 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4430
4431 if (ioa_cfg->sis64) {
Brian King0ee1d712012-03-14 21:20:06 -05004432 if (!ipr_find_starget(starget)) {
4433 if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4434 clear_bit(starget->id, ioa_cfg->array_ids);
4435 else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4436 clear_bit(starget->id, ioa_cfg->vset_ids);
4437 else if (starget->channel == 0)
4438 clear_bit(starget->id, ioa_cfg->target_ids);
4439 }
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004440 }
Brian King35a39692006-09-25 12:39:20 -05004441
4442 if (sata_port) {
4443 starget->hostdata = NULL;
4444 ata_sas_port_destroy(sata_port->ap);
4445 kfree(sata_port);
4446 }
4447}
4448
4449/**
4450 * ipr_find_sdev - Find device based on bus/target/lun.
4451 * @sdev: scsi device struct
4452 *
4453 * Return value:
4454 * resource entry pointer if found / NULL if not found
4455 **/
4456static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
4457{
4458 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4459 struct ipr_resource_entry *res;
4460
4461 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004462 if ((res->bus == sdev->channel) &&
4463 (res->target == sdev->id) &&
4464 (res->lun == sdev->lun))
Brian King35a39692006-09-25 12:39:20 -05004465 return res;
4466 }
4467
4468 return NULL;
4469}
4470
4471/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472 * ipr_slave_destroy - Unconfigure a SCSI device
4473 * @sdev: scsi device struct
4474 *
4475 * Return value:
4476 * nothing
4477 **/
4478static void ipr_slave_destroy(struct scsi_device *sdev)
4479{
4480 struct ipr_resource_entry *res;
4481 struct ipr_ioa_cfg *ioa_cfg;
4482 unsigned long lock_flags = 0;
4483
4484 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4485
4486 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4487 res = (struct ipr_resource_entry *) sdev->hostdata;
4488 if (res) {
Brian King35a39692006-09-25 12:39:20 -05004489 if (res->sata_port)
Tejun Heo3e4ec342010-05-10 21:41:30 +02004490 res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491 sdev->hostdata = NULL;
4492 res->sdev = NULL;
Brian King35a39692006-09-25 12:39:20 -05004493 res->sata_port = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004494 }
4495 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4496}
4497
4498/**
4499 * ipr_slave_configure - Configure a SCSI device
4500 * @sdev: scsi device struct
4501 *
4502 * This function configures the specified scsi device.
4503 *
4504 * Return value:
4505 * 0 on success
4506 **/
4507static int ipr_slave_configure(struct scsi_device *sdev)
4508{
4509 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4510 struct ipr_resource_entry *res;
Brian Kingdd406ef2009-04-22 08:58:02 -05004511 struct ata_port *ap = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512 unsigned long lock_flags = 0;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004513 char buffer[IPR_MAX_RES_PATH_LENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514
4515 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4516 res = sdev->hostdata;
4517 if (res) {
4518 if (ipr_is_af_dasd_device(res))
4519 sdev->type = TYPE_RAID;
brking@us.ibm.com0726ce22005-11-01 17:01:01 -06004520 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 sdev->scsi_level = 4;
brking@us.ibm.com0726ce22005-11-01 17:01:01 -06004522 sdev->no_uld_attach = 1;
4523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524 if (ipr_is_vset_device(res)) {
Jens Axboe242f9dc2008-09-14 05:55:09 -07004525 blk_queue_rq_timeout(sdev->request_queue,
4526 IPR_VSET_RW_TIMEOUT);
Martin K. Petersen086fa5f2010-02-26 00:20:38 -05004527 blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 }
Brian Kingdd406ef2009-04-22 08:58:02 -05004529 if (ipr_is_gata(res) && res->sata_port)
4530 ap = res->sata_port->ap;
4531 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4532
4533 if (ap) {
Brian King35a39692006-09-25 12:39:20 -05004534 scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
Brian Kingdd406ef2009-04-22 08:58:02 -05004535 ata_sas_slave_configure(sdev, ap);
4536 } else
Brian King35a39692006-09-25 12:39:20 -05004537 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004538 if (ioa_cfg->sis64)
4539 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004540 ipr_format_res_path(res->res_path, buffer,
4541 sizeof(buffer)));
Brian Kingdd406ef2009-04-22 08:58:02 -05004542 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 }
4544 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4545 return 0;
4546}
4547
4548/**
Brian King35a39692006-09-25 12:39:20 -05004549 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
4550 * @sdev: scsi device struct
4551 *
4552 * This function initializes an ATA port so that future commands
4553 * sent through queuecommand will work.
4554 *
4555 * Return value:
4556 * 0 on success
4557 **/
4558static int ipr_ata_slave_alloc(struct scsi_device *sdev)
4559{
4560 struct ipr_sata_port *sata_port = NULL;
4561 int rc = -ENXIO;
4562
4563 ENTER;
4564 if (sdev->sdev_target)
4565 sata_port = sdev->sdev_target->hostdata;
Dan Williamsb2024452012-03-21 21:09:07 -07004566 if (sata_port) {
Brian King35a39692006-09-25 12:39:20 -05004567 rc = ata_sas_port_init(sata_port->ap);
Dan Williamsb2024452012-03-21 21:09:07 -07004568 if (rc == 0)
4569 rc = ata_sas_sync_probe(sata_port->ap);
4570 }
4571
Brian King35a39692006-09-25 12:39:20 -05004572 if (rc)
4573 ipr_slave_destroy(sdev);
4574
4575 LEAVE;
4576 return rc;
4577}
4578
4579/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580 * ipr_slave_alloc - Prepare for commands to a device.
4581 * @sdev: scsi device struct
4582 *
4583 * This function saves a pointer to the resource entry
4584 * in the scsi device struct if the device exists. We
4585 * can then use this pointer in ipr_queuecommand when
4586 * handling new commands.
4587 *
4588 * Return value:
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004589 * 0 on success / -ENXIO if device does not exist
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 **/
4591static int ipr_slave_alloc(struct scsi_device *sdev)
4592{
4593 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4594 struct ipr_resource_entry *res;
4595 unsigned long lock_flags;
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004596 int rc = -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597
4598 sdev->hostdata = NULL;
4599
4600 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4601
Brian King35a39692006-09-25 12:39:20 -05004602 res = ipr_find_sdev(sdev);
4603 if (res) {
4604 res->sdev = sdev;
4605 res->add_to_ml = 0;
4606 res->in_erp = 0;
4607 sdev->hostdata = res;
4608 if (!ipr_is_naca_model(res))
4609 res->needs_sync_complete = 1;
4610 rc = 0;
4611 if (ipr_is_gata(res)) {
4612 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4613 return ipr_ata_slave_alloc(sdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614 }
4615 }
4616
4617 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4618
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004619 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620}
4621
4622/**
4623 * ipr_eh_host_reset - Reset the host adapter
4624 * @scsi_cmd: scsi command struct
4625 *
4626 * Return value:
4627 * SUCCESS / FAILED
4628 **/
Jeff Garzik df0ae242005-05-28 07:57:14 -04004629static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630{
4631 struct ipr_ioa_cfg *ioa_cfg;
4632 int rc;
4633
4634 ENTER;
4635 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
4636
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004637 if (!ioa_cfg->in_reset_reload) {
4638 dev_err(&ioa_cfg->pdev->dev,
4639 "Adapter being reset as a result of error recovery.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004641 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4642 ioa_cfg->sdt_state = GET_DUMP;
4643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644
4645 rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
4646
4647 LEAVE;
4648 return rc;
4649}
4650
Jeff Garzik df0ae242005-05-28 07:57:14 -04004651static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
4652{
4653 int rc;
4654
4655 spin_lock_irq(cmd->device->host->host_lock);
4656 rc = __ipr_eh_host_reset(cmd);
4657 spin_unlock_irq(cmd->device->host->host_lock);
4658
4659 return rc;
4660}
4661
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662/**
Brian Kingc6513092006-03-29 09:37:43 -06004663 * ipr_device_reset - Reset the device
4664 * @ioa_cfg: ioa config struct
4665 * @res: resource entry struct
4666 *
4667 * This function issues a device reset to the affected device.
4668 * If the device is a SCSI device, a LUN reset will be sent
4669 * to the device first. If that does not work, a target reset
Brian King35a39692006-09-25 12:39:20 -05004670 * will be sent. If the device is a SATA device, a PHY reset will
4671 * be sent.
Brian Kingc6513092006-03-29 09:37:43 -06004672 *
4673 * Return value:
4674 * 0 on success / non-zero on failure
4675 **/
4676static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
4677 struct ipr_resource_entry *res)
4678{
4679 struct ipr_cmnd *ipr_cmd;
4680 struct ipr_ioarcb *ioarcb;
4681 struct ipr_cmd_pkt *cmd_pkt;
Brian King35a39692006-09-25 12:39:20 -05004682 struct ipr_ioarcb_ata_regs *regs;
Brian Kingc6513092006-03-29 09:37:43 -06004683 u32 ioasc;
4684
4685 ENTER;
4686 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4687 ioarcb = &ipr_cmd->ioarcb;
4688 cmd_pkt = &ioarcb->cmd_pkt;
Wayne Boyera32c0552010-02-19 13:23:36 -08004689
4690 if (ipr_cmd->ioa_cfg->sis64) {
4691 regs = &ipr_cmd->i.ata_ioadl.regs;
4692 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
4693 } else
4694 regs = &ioarcb->u.add_data.u.regs;
Brian Kingc6513092006-03-29 09:37:43 -06004695
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004696 ioarcb->res_handle = res->res_handle;
Brian Kingc6513092006-03-29 09:37:43 -06004697 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4698 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
Brian King35a39692006-09-25 12:39:20 -05004699 if (ipr_is_gata(res)) {
4700 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
Wayne Boyera32c0552010-02-19 13:23:36 -08004701 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
Brian King35a39692006-09-25 12:39:20 -05004702 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
4703 }
Brian Kingc6513092006-03-29 09:37:43 -06004704
4705 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
Wayne Boyer96d21f02010-05-10 09:13:27 -07004706 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian Kingc6513092006-03-29 09:37:43 -06004707 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
Wayne Boyer96d21f02010-05-10 09:13:27 -07004708 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) {
4709 if (ipr_cmd->ioa_cfg->sis64)
4710 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
4711 sizeof(struct ipr_ioasa_gata));
4712 else
4713 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
4714 sizeof(struct ipr_ioasa_gata));
4715 }
Brian Kingc6513092006-03-29 09:37:43 -06004716
4717 LEAVE;
4718 return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0);
4719}
4720
4721/**
Brian King35a39692006-09-25 12:39:20 -05004722 * ipr_sata_reset - Reset the SATA port
Tejun Heocc0680a2007-08-06 18:36:23 +09004723 * @link: SATA link to reset
Brian King35a39692006-09-25 12:39:20 -05004724 * @classes: class of the attached device
4725 *
Tejun Heocc0680a2007-08-06 18:36:23 +09004726 * This function issues a SATA phy reset to the affected ATA link.
Brian King35a39692006-09-25 12:39:20 -05004727 *
4728 * Return value:
4729 * 0 on success / non-zero on failure
4730 **/
Tejun Heocc0680a2007-08-06 18:36:23 +09004731static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
Andrew Morton120bda32007-03-26 02:17:43 -07004732 unsigned long deadline)
Brian King35a39692006-09-25 12:39:20 -05004733{
Tejun Heocc0680a2007-08-06 18:36:23 +09004734 struct ipr_sata_port *sata_port = link->ap->private_data;
Brian King35a39692006-09-25 12:39:20 -05004735 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4736 struct ipr_resource_entry *res;
4737 unsigned long lock_flags = 0;
4738 int rc = -ENXIO;
4739
4740 ENTER;
4741 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King73d98ff2006-11-21 10:27:58 -06004742 while(ioa_cfg->in_reset_reload) {
4743 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4744 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4745 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4746 }
4747
Brian King35a39692006-09-25 12:39:20 -05004748 res = sata_port->res;
4749 if (res) {
4750 rc = ipr_device_reset(ioa_cfg, res);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004751 *classes = res->ata_class;
Brian King35a39692006-09-25 12:39:20 -05004752 }
4753
4754 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4755 LEAVE;
4756 return rc;
4757}
4758
4759/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 * ipr_eh_dev_reset - Reset the device
4761 * @scsi_cmd: scsi command struct
4762 *
4763 * This function issues a device reset to the affected device.
4764 * A LUN reset will be sent to the device first. If that does
4765 * not work, a target reset will be sent.
4766 *
4767 * Return value:
4768 * SUCCESS / FAILED
4769 **/
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04004770static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771{
4772 struct ipr_cmnd *ipr_cmd;
4773 struct ipr_ioa_cfg *ioa_cfg;
4774 struct ipr_resource_entry *res;
Brian King35a39692006-09-25 12:39:20 -05004775 struct ata_port *ap;
4776 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777
4778 ENTER;
4779 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
4780 res = scsi_cmd->device->hostdata;
4781
brking@us.ibm.comeeb883072005-11-01 17:02:29 -06004782 if (!res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 return FAILED;
4784
4785 /*
4786 * If we are currently going through reset/reload, return failed. This will force the
4787 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
4788 * reset to complete
4789 */
4790 if (ioa_cfg->in_reset_reload)
4791 return FAILED;
4792 if (ioa_cfg->ioa_is_dead)
4793 return FAILED;
4794
4795 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004796 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 if (ipr_cmd->scsi_cmd)
4798 ipr_cmd->done = ipr_scsi_eh_done;
Brian King24d6f2b2007-03-29 12:43:17 -05004799 if (ipr_cmd->qc)
4800 ipr_cmd->done = ipr_sata_eh_done;
Brian King7402ece2006-11-21 10:28:23 -06004801 if (ipr_cmd->qc && !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
4802 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
4803 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
4804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805 }
4806 }
4807
4808 res->resetting_device = 1;
Brian Kingfb3ed3c2006-03-29 09:37:37 -06004809 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
Brian King35a39692006-09-25 12:39:20 -05004810
4811 if (ipr_is_gata(res) && res->sata_port) {
4812 ap = res->sata_port->ap;
4813 spin_unlock_irq(scsi_cmd->device->host->host_lock);
Tejun Heoa1efdab2008-03-25 12:22:50 +09004814 ata_std_error_handler(ap);
Brian King35a39692006-09-25 12:39:20 -05004815 spin_lock_irq(scsi_cmd->device->host->host_lock);
Brian King5af23d22007-05-09 15:36:35 -05004816
4817 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004818 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
Brian King5af23d22007-05-09 15:36:35 -05004819 rc = -EIO;
4820 break;
4821 }
4822 }
Brian King35a39692006-09-25 12:39:20 -05004823 } else
4824 rc = ipr_device_reset(ioa_cfg, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825 res->resetting_device = 0;
4826
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827 LEAVE;
Brian Kingc6513092006-03-29 09:37:43 -06004828 return (rc ? FAILED : SUCCESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829}
4830
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04004831static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
4832{
4833 int rc;
4834
4835 spin_lock_irq(cmd->device->host->host_lock);
4836 rc = __ipr_eh_dev_reset(cmd);
4837 spin_unlock_irq(cmd->device->host->host_lock);
4838
4839 return rc;
4840}
4841
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842/**
4843 * ipr_bus_reset_done - Op done function for bus reset.
4844 * @ipr_cmd: ipr command struct
4845 *
4846 * This function is the op done function for a bus reset
4847 *
4848 * Return value:
4849 * none
4850 **/
4851static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
4852{
4853 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4854 struct ipr_resource_entry *res;
4855
4856 ENTER;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004857 if (!ioa_cfg->sis64)
4858 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4859 if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
4860 scsi_report_bus_reset(ioa_cfg->host, res->bus);
4861 break;
4862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864
4865 /*
4866 * If abort has not completed, indicate the reset has, else call the
4867 * abort's done function to wake the sleeping eh thread
4868 */
4869 if (ipr_cmd->sibling->sibling)
4870 ipr_cmd->sibling->sibling = NULL;
4871 else
4872 ipr_cmd->sibling->done(ipr_cmd->sibling);
4873
4874 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4875 LEAVE;
4876}
4877
4878/**
4879 * ipr_abort_timeout - An abort task has timed out
4880 * @ipr_cmd: ipr command struct
4881 *
4882 * This function handles when an abort task times out. If this
4883 * happens we issue a bus reset since we have resources tied
4884 * up that must be freed before returning to the midlayer.
4885 *
4886 * Return value:
4887 * none
4888 **/
4889static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
4890{
4891 struct ipr_cmnd *reset_cmd;
4892 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4893 struct ipr_cmd_pkt *cmd_pkt;
4894 unsigned long lock_flags = 0;
4895
4896 ENTER;
4897 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4898 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
4899 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4900 return;
4901 }
4902
Brian Kingfb3ed3c2006-03-29 09:37:37 -06004903 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4905 ipr_cmd->sibling = reset_cmd;
4906 reset_cmd->sibling = ipr_cmd;
4907 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
4908 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
4909 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4910 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
4911 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
4912
4913 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
4914 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4915 LEAVE;
4916}
4917
4918/**
4919 * ipr_cancel_op - Cancel specified op
4920 * @scsi_cmd: scsi command struct
4921 *
4922 * This function cancels specified op.
4923 *
4924 * Return value:
4925 * SUCCESS / FAILED
4926 **/
4927static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
4928{
4929 struct ipr_cmnd *ipr_cmd;
4930 struct ipr_ioa_cfg *ioa_cfg;
4931 struct ipr_resource_entry *res;
4932 struct ipr_cmd_pkt *cmd_pkt;
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004933 u32 ioasc, int_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004934 int op_found = 0;
4935
4936 ENTER;
4937 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4938 res = scsi_cmd->device->hostdata;
4939
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04004940 /* If we are currently going through reset/reload, return failed.
4941 * This will force the mid-layer to call ipr_eh_host_reset,
4942 * which will then go to sleep and wait for the reset to complete
4943 */
4944 if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
4945 return FAILED;
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004946 if (!res)
4947 return FAILED;
4948
4949 /*
4950 * If we are aborting a timed out op, chances are that the timeout was caused
4951 * by a still not detected EEH error. In such cases, reading a register will
4952 * trigger the EEH recovery infrastructure.
4953 */
4954 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
4955
4956 if (!ipr_is_gscsi(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 return FAILED;
4958
4959 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4960 if (ipr_cmd->scsi_cmd == scsi_cmd) {
4961 ipr_cmd->done = ipr_scsi_eh_done;
4962 op_found = 1;
4963 break;
4964 }
4965 }
4966
4967 if (!op_found)
4968 return SUCCESS;
4969
4970 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004971 ipr_cmd->ioarcb.res_handle = res->res_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4973 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4974 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
4975 ipr_cmd->u.sdev = scsi_cmd->device;
4976
Brian Kingfb3ed3c2006-03-29 09:37:37 -06004977 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
4978 scsi_cmd->cmnd[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
Wayne Boyer96d21f02010-05-10 09:13:27 -07004980 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981
4982 /*
4983 * If the abort task timed out and we sent a bus reset, we will get
4984 * one the following responses to the abort
4985 */
4986 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
4987 ioasc = 0;
4988 ipr_trace;
4989 }
4990
4991 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06004992 if (!ipr_is_naca_model(res))
4993 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994
4995 LEAVE;
4996 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
4997}
4998
4999/**
5000 * ipr_eh_abort - Abort a single op
5001 * @scsi_cmd: scsi command struct
5002 *
5003 * Return value:
5004 * SUCCESS / FAILED
5005 **/
5006static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
5007{
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005008 unsigned long flags;
5009 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010
5011 ENTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005013 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
5014 rc = ipr_cancel_op(scsi_cmd);
5015 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016
5017 LEAVE;
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005018 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019}
5020
5021/**
5022 * ipr_handle_other_interrupt - Handle "other" interrupts
5023 * @ioa_cfg: ioa config struct
Wayne Boyer634651f2010-08-27 14:45:07 -07005024 * @int_reg: interrupt register
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 *
5026 * Return value:
5027 * IRQ_NONE / IRQ_HANDLED
5028 **/
Wayne Boyer634651f2010-08-27 14:45:07 -07005029static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
Wayne Boyer630ad8312011-04-07 12:12:30 -07005030 u32 int_reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031{
5032 irqreturn_t rc = IRQ_HANDLED;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005033 u32 int_mask_reg;
5034
5035 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
5036 int_reg &= ~int_mask_reg;
5037
5038 /* If an interrupt on the adapter did not occur, ignore it.
5039 * Or in the case of SIS 64, check for a stage change interrupt.
5040 */
5041 if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
5042 if (ioa_cfg->sis64) {
5043 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
5044 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5045 if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
5046
5047 /* clear stage change */
5048 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
5049 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5050 list_del(&ioa_cfg->reset_cmd->queue);
5051 del_timer(&ioa_cfg->reset_cmd->timer);
5052 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5053 return IRQ_HANDLED;
5054 }
5055 }
5056
5057 return IRQ_NONE;
5058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005059
5060 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
5061 /* Mask the interrupt */
5062 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
5063
5064 /* Clear the interrupt */
5065 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
5066 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5067
5068 list_del(&ioa_cfg->reset_cmd->queue);
5069 del_timer(&ioa_cfg->reset_cmd->timer);
5070 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
Wayne Boyer7dacb642011-04-12 10:29:02 -07005071 } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
Brian King7dd21302012-03-14 21:20:08 -05005072 if (ioa_cfg->clear_isr) {
5073 if (ipr_debug && printk_ratelimit())
5074 dev_err(&ioa_cfg->pdev->dev,
5075 "Spurious interrupt detected. 0x%08X\n", int_reg);
5076 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5077 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5078 return IRQ_NONE;
5079 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080 } else {
5081 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
5082 ioa_cfg->ioa_unit_checked = 1;
5083 else
5084 dev_err(&ioa_cfg->pdev->dev,
5085 "Permanent IOA failure. 0x%08X\n", int_reg);
5086
5087 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5088 ioa_cfg->sdt_state = GET_DUMP;
5089
5090 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
5091 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5092 }
5093
5094 return rc;
5095}
5096
5097/**
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005098 * ipr_isr_eh - Interrupt service routine error handler
5099 * @ioa_cfg: ioa config struct
5100 * @msg: message to log
5101 *
5102 * Return value:
5103 * none
5104 **/
5105static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg)
5106{
5107 ioa_cfg->errors_logged++;
5108 dev_err(&ioa_cfg->pdev->dev, "%s\n", msg);
5109
5110 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5111 ioa_cfg->sdt_state = GET_DUMP;
5112
5113 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5114}
5115
5116/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117 * ipr_isr - Interrupt service routine
5118 * @irq: irq number
5119 * @devp: pointer to ioa config struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 *
5121 * Return value:
5122 * IRQ_NONE / IRQ_HANDLED
5123 **/
David Howells7d12e782006-10-05 14:55:46 +01005124static irqreturn_t ipr_isr(int irq, void *devp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125{
5126 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
5127 unsigned long lock_flags = 0;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005128 u32 int_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129 u32 ioasc;
5130 u16 cmd_index;
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005131 int num_hrrq = 0;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005132 int irq_none = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133 struct ipr_cmnd *ipr_cmd;
5134 irqreturn_t rc = IRQ_NONE;
5135
5136 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5137
5138 /* If interrupts are disabled, ignore the interrupt */
5139 if (!ioa_cfg->allow_interrupts) {
5140 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5141 return IRQ_NONE;
5142 }
5143
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144 while (1) {
5145 ipr_cmd = NULL;
5146
5147 while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5148 ioa_cfg->toggle_bit) {
5149
5150 cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
5151 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
5152
5153 if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005154 ipr_isr_eh(ioa_cfg, "Invalid response handle from IOA");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5156 return IRQ_HANDLED;
5157 }
5158
5159 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
5160
Wayne Boyer96d21f02010-05-10 09:13:27 -07005161 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162
5163 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
5164
5165 list_del(&ipr_cmd->queue);
5166 del_timer(&ipr_cmd->timer);
5167 ipr_cmd->done(ipr_cmd);
5168
5169 rc = IRQ_HANDLED;
5170
5171 if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
5172 ioa_cfg->hrrq_curr++;
5173 } else {
5174 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
5175 ioa_cfg->toggle_bit ^= 1u;
5176 }
5177 }
5178
Brian King7dd21302012-03-14 21:20:08 -05005179 if (ipr_cmd && !ioa_cfg->clear_isr)
5180 break;
5181
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182 if (ipr_cmd != NULL) {
5183 /* Clear the PCI interrupt */
Wayne Boyera5442ba2011-05-17 09:18:53 -07005184 num_hrrq = 0;
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005185 do {
Wayne Boyer214777b2010-02-19 13:24:26 -08005186 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
Wayne Boyer7dacb642011-04-12 10:29:02 -07005187 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005188 } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
5189 num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
5190
Wayne Boyer7dacb642011-04-12 10:29:02 -07005191 } else if (rc == IRQ_NONE && irq_none == 0) {
5192 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5193 irq_none++;
Wayne Boyera5442ba2011-05-17 09:18:53 -07005194 } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
5195 int_reg & IPR_PCII_HRRQ_UPDATED) {
5196 ipr_isr_eh(ioa_cfg, "Error clearing HRRQ");
5197 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5198 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199 } else
5200 break;
5201 }
5202
5203 if (unlikely(rc == IRQ_NONE))
Wayne Boyer634651f2010-08-27 14:45:07 -07005204 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205
5206 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5207 return rc;
5208}
5209
5210/**
Wayne Boyera32c0552010-02-19 13:23:36 -08005211 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212 * @ioa_cfg: ioa config struct
5213 * @ipr_cmd: ipr command struct
5214 *
5215 * Return value:
5216 * 0 on success / -1 on failure
5217 **/
Wayne Boyera32c0552010-02-19 13:23:36 -08005218static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
5219 struct ipr_cmnd *ipr_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220{
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005221 int i, nseg;
5222 struct scatterlist *sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 u32 length;
5224 u32 ioadl_flags = 0;
5225 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5226 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08005227 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005229 length = scsi_bufflen(scsi_cmd);
5230 if (!length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231 return 0;
5232
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005233 nseg = scsi_dma_map(scsi_cmd);
5234 if (nseg < 0) {
Anton Blanchard51f52a42011-05-09 10:07:40 +10005235 if (printk_ratelimit())
5236 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005237 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238 }
5239
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005240 ipr_cmd->dma_use_sg = nseg;
5241
Wayne Boyer438b0332010-05-10 09:13:00 -07005242 ioarcb->data_transfer_length = cpu_to_be32(length);
Wayne Boyerb8803b12010-05-14 08:55:13 -07005243 ioarcb->ioadl_len =
5244 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
Wayne Boyer438b0332010-05-10 09:13:00 -07005245
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005246 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5247 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5248 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08005249 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
5250 ioadl_flags = IPR_IOADL_FLAGS_READ;
5251
5252 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5253 ioadl64[i].flags = cpu_to_be32(ioadl_flags);
5254 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
5255 ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
5256 }
5257
5258 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5259 return 0;
5260}
5261
5262/**
5263 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5264 * @ioa_cfg: ioa config struct
5265 * @ipr_cmd: ipr command struct
5266 *
5267 * Return value:
5268 * 0 on success / -1 on failure
5269 **/
5270static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5271 struct ipr_cmnd *ipr_cmd)
5272{
5273 int i, nseg;
5274 struct scatterlist *sg;
5275 u32 length;
5276 u32 ioadl_flags = 0;
5277 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5278 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5279 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
5280
5281 length = scsi_bufflen(scsi_cmd);
5282 if (!length)
5283 return 0;
5284
5285 nseg = scsi_dma_map(scsi_cmd);
5286 if (nseg < 0) {
5287 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
5288 return -1;
5289 }
5290
5291 ipr_cmd->dma_use_sg = nseg;
5292
5293 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5294 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5295 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5296 ioarcb->data_transfer_length = cpu_to_be32(length);
5297 ioarcb->ioadl_len =
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005298 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5299 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
5300 ioadl_flags = IPR_IOADL_FLAGS_READ;
5301 ioarcb->read_data_transfer_length = cpu_to_be32(length);
5302 ioarcb->read_ioadl_len =
5303 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5304 }
5305
Wayne Boyera32c0552010-02-19 13:23:36 -08005306 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
5307 ioadl = ioarcb->u.add_data.u.ioadl;
5308 ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
5309 offsetof(struct ipr_ioarcb, u.add_data));
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005310 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5311 }
5312
5313 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5314 ioadl[i].flags_and_data_len =
5315 cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5316 ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
5317 }
5318
5319 ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5320 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321}
5322
5323/**
5324 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
5325 * @scsi_cmd: scsi command struct
5326 *
5327 * Return value:
5328 * task attributes
5329 **/
5330static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
5331{
5332 u8 tag[2];
5333 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
5334
5335 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
5336 switch (tag[0]) {
5337 case MSG_SIMPLE_TAG:
5338 rc = IPR_FLAGS_LO_SIMPLE_TASK;
5339 break;
5340 case MSG_HEAD_TAG:
5341 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
5342 break;
5343 case MSG_ORDERED_TAG:
5344 rc = IPR_FLAGS_LO_ORDERED_TASK;
5345 break;
5346 };
5347 }
5348
5349 return rc;
5350}
5351
5352/**
5353 * ipr_erp_done - Process completion of ERP for a device
5354 * @ipr_cmd: ipr command struct
5355 *
5356 * This function copies the sense buffer into the scsi_cmd
5357 * struct and pushes the scsi_done function.
5358 *
5359 * Return value:
5360 * nothing
5361 **/
5362static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
5363{
5364 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5365 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5366 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005367 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005368
5369 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5370 scsi_cmd->result |= (DID_ERROR << 16);
Brian Kingfb3ed3c2006-03-29 09:37:37 -06005371 scmd_printk(KERN_ERR, scsi_cmd,
5372 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373 } else {
5374 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
5375 SCSI_SENSE_BUFFERSIZE);
5376 }
5377
5378 if (res) {
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005379 if (!ipr_is_naca_model(res))
5380 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381 res->in_erp = 0;
5382 }
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005383 scsi_dma_unmap(ipr_cmd->scsi_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5385 scsi_cmd->scsi_done(scsi_cmd);
5386}
5387
5388/**
5389 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5390 * @ipr_cmd: ipr command struct
5391 *
5392 * Return value:
5393 * none
5394 **/
5395static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
5396{
Brian King51b1c7e2007-03-29 12:43:50 -05005397 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005398 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
Wayne Boyera32c0552010-02-19 13:23:36 -08005399 dma_addr_t dma_addr = ipr_cmd->dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005400
5401 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
Wayne Boyera32c0552010-02-19 13:23:36 -08005402 ioarcb->data_transfer_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403 ioarcb->read_data_transfer_length = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -08005404 ioarcb->ioadl_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405 ioarcb->read_ioadl_len = 0;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005406 ioasa->hdr.ioasc = 0;
5407 ioasa->hdr.residual_data_len = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -08005408
5409 if (ipr_cmd->ioa_cfg->sis64)
5410 ioarcb->u.sis64_addr_data.data_ioadl_addr =
5411 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
5412 else {
5413 ioarcb->write_ioadl_addr =
5414 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
5415 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005417}
5418
5419/**
5420 * ipr_erp_request_sense - Send request sense to a device
5421 * @ipr_cmd: ipr command struct
5422 *
5423 * This function sends a request sense to a device as a result
5424 * of a check condition.
5425 *
5426 * Return value:
5427 * nothing
5428 **/
5429static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
5430{
5431 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005432 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005433
5434 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5435 ipr_erp_done(ipr_cmd);
5436 return;
5437 }
5438
5439 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5440
5441 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
5442 cmd_pkt->cdb[0] = REQUEST_SENSE;
5443 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
5444 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
5445 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5446 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
5447
Wayne Boyera32c0552010-02-19 13:23:36 -08005448 ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
5449 SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005450
5451 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
5452 IPR_REQUEST_SENSE_TIMEOUT * 2);
5453}
5454
5455/**
5456 * ipr_erp_cancel_all - Send cancel all to a device
5457 * @ipr_cmd: ipr command struct
5458 *
5459 * This function sends a cancel all to a device to clear the
5460 * queue. If we are running TCQ on the device, QERR is set to 1,
5461 * which means all outstanding ops have been dropped on the floor.
5462 * Cancel all will return them to us.
5463 *
5464 * Return value:
5465 * nothing
5466 **/
5467static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
5468{
5469 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5470 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5471 struct ipr_cmd_pkt *cmd_pkt;
5472
5473 res->in_erp = 1;
5474
5475 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5476
5477 if (!scsi_get_tag_type(scsi_cmd->device)) {
5478 ipr_erp_request_sense(ipr_cmd);
5479 return;
5480 }
5481
5482 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5483 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5484 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5485
5486 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
5487 IPR_CANCEL_ALL_TIMEOUT);
5488}
5489
5490/**
5491 * ipr_dump_ioasa - Dump contents of IOASA
5492 * @ioa_cfg: ioa config struct
5493 * @ipr_cmd: ipr command struct
Brian Kingfe964d02006-03-29 09:37:29 -06005494 * @res: resource entry struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005495 *
5496 * This function is invoked by the interrupt handler when ops
5497 * fail. It will log the IOASA if appropriate. Only called
5498 * for GPDD ops.
5499 *
5500 * Return value:
5501 * none
5502 **/
5503static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
Brian Kingfe964d02006-03-29 09:37:29 -06005504 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005505{
5506 int i;
5507 u16 data_len;
Brian Kingb0692dd2007-03-29 12:43:09 -05005508 u32 ioasc, fd_ioasc;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005509 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005510 __be32 *ioasa_data = (__be32 *)ioasa;
5511 int error_index;
5512
Wayne Boyer96d21f02010-05-10 09:13:27 -07005513 ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
5514 fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515
5516 if (0 == ioasc)
5517 return;
5518
5519 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
5520 return;
5521
Brian Kingb0692dd2007-03-29 12:43:09 -05005522 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
5523 error_index = ipr_get_error(fd_ioasc);
5524 else
5525 error_index = ipr_get_error(ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005526
5527 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
5528 /* Don't log an error if the IOA already logged one */
Wayne Boyer96d21f02010-05-10 09:13:27 -07005529 if (ioasa->hdr.ilid != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005530 return;
5531
Brian Kingcc9bd5d2007-03-29 12:43:01 -05005532 if (!ipr_is_gscsi(res))
5533 return;
5534
Linus Torvalds1da177e2005-04-16 15:20:36 -07005535 if (ipr_error_table[error_index].log_ioasa == 0)
5536 return;
5537 }
5538
Brian Kingfe964d02006-03-29 09:37:29 -06005539 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540
Wayne Boyer96d21f02010-05-10 09:13:27 -07005541 data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
5542 if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
5543 data_len = sizeof(struct ipr_ioasa64);
5544 else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005545 data_len = sizeof(struct ipr_ioasa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546
5547 ipr_err("IOASA Dump:\n");
5548
5549 for (i = 0; i < data_len / 4; i += 4) {
5550 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
5551 be32_to_cpu(ioasa_data[i]),
5552 be32_to_cpu(ioasa_data[i+1]),
5553 be32_to_cpu(ioasa_data[i+2]),
5554 be32_to_cpu(ioasa_data[i+3]));
5555 }
5556}
5557
5558/**
5559 * ipr_gen_sense - Generate SCSI sense data from an IOASA
5560 * @ioasa: IOASA
5561 * @sense_buf: sense data buffer
5562 *
5563 * Return value:
5564 * none
5565 **/
5566static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
5567{
5568 u32 failing_lba;
5569 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
5570 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005571 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5572 u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005573
5574 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
5575
5576 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
5577 return;
5578
5579 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
5580
5581 if (ipr_is_vset_device(res) &&
5582 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
5583 ioasa->u.vset.failing_lba_hi != 0) {
5584 sense_buf[0] = 0x72;
5585 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
5586 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
5587 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
5588
5589 sense_buf[7] = 12;
5590 sense_buf[8] = 0;
5591 sense_buf[9] = 0x0A;
5592 sense_buf[10] = 0x80;
5593
5594 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
5595
5596 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
5597 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
5598 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
5599 sense_buf[15] = failing_lba & 0x000000ff;
5600
5601 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5602
5603 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
5604 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
5605 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
5606 sense_buf[19] = failing_lba & 0x000000ff;
5607 } else {
5608 sense_buf[0] = 0x70;
5609 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
5610 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
5611 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
5612
5613 /* Illegal request */
5614 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
Wayne Boyer96d21f02010-05-10 09:13:27 -07005615 (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005616 sense_buf[7] = 10; /* additional length */
5617
5618 /* IOARCB was in error */
5619 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
5620 sense_buf[15] = 0xC0;
5621 else /* Parameter data was invalid */
5622 sense_buf[15] = 0x80;
5623
5624 sense_buf[16] =
5625 ((IPR_FIELD_POINTER_MASK &
Wayne Boyer96d21f02010-05-10 09:13:27 -07005626 be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005627 sense_buf[17] =
5628 (IPR_FIELD_POINTER_MASK &
Wayne Boyer96d21f02010-05-10 09:13:27 -07005629 be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005630 } else {
5631 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
5632 if (ipr_is_vset_device(res))
5633 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5634 else
5635 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
5636
5637 sense_buf[0] |= 0x80; /* Or in the Valid bit */
5638 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
5639 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
5640 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
5641 sense_buf[6] = failing_lba & 0x000000ff;
5642 }
5643
5644 sense_buf[7] = 6; /* additional length */
5645 }
5646 }
5647}
5648
5649/**
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005650 * ipr_get_autosense - Copy autosense data to sense buffer
5651 * @ipr_cmd: ipr command struct
5652 *
5653 * This function copies the autosense buffer to the buffer
5654 * in the scsi_cmd, if there is autosense available.
5655 *
5656 * Return value:
5657 * 1 if autosense was available / 0 if not
5658 **/
5659static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
5660{
Wayne Boyer96d21f02010-05-10 09:13:27 -07005661 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5662 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005663
Wayne Boyer96d21f02010-05-10 09:13:27 -07005664 if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005665 return 0;
5666
Wayne Boyer96d21f02010-05-10 09:13:27 -07005667 if (ipr_cmd->ioa_cfg->sis64)
5668 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
5669 min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
5670 SCSI_SENSE_BUFFERSIZE));
5671 else
5672 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
5673 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
5674 SCSI_SENSE_BUFFERSIZE));
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005675 return 1;
5676}
5677
5678/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005679 * ipr_erp_start - Process an error response for a SCSI op
5680 * @ioa_cfg: ioa config struct
5681 * @ipr_cmd: ipr command struct
5682 *
5683 * This function determines whether or not to initiate ERP
5684 * on the affected device.
5685 *
5686 * Return value:
5687 * nothing
5688 **/
5689static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
5690 struct ipr_cmnd *ipr_cmd)
5691{
5692 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5693 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005694 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian King8a048992007-04-26 16:00:10 -05005695 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005696
5697 if (!res) {
5698 ipr_scsi_eh_done(ipr_cmd);
5699 return;
5700 }
5701
Brian King8a048992007-04-26 16:00:10 -05005702 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005703 ipr_gen_sense(ipr_cmd);
5704
Brian Kingcc9bd5d2007-03-29 12:43:01 -05005705 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
5706
Brian King8a048992007-04-26 16:00:10 -05005707 switch (masked_ioasc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005708 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005709 if (ipr_is_naca_model(res))
5710 scsi_cmd->result |= (DID_ABORT << 16);
5711 else
5712 scsi_cmd->result |= (DID_IMM_RETRY << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005713 break;
5714 case IPR_IOASC_IR_RESOURCE_HANDLE:
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06005715 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005716 scsi_cmd->result |= (DID_NO_CONNECT << 16);
5717 break;
5718 case IPR_IOASC_HW_SEL_TIMEOUT:
5719 scsi_cmd->result |= (DID_NO_CONNECT << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005720 if (!ipr_is_naca_model(res))
5721 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005722 break;
5723 case IPR_IOASC_SYNC_REQUIRED:
5724 if (!res->in_erp)
5725 res->needs_sync_complete = 1;
5726 scsi_cmd->result |= (DID_IMM_RETRY << 16);
5727 break;
5728 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06005729 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005730 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
5731 break;
5732 case IPR_IOASC_BUS_WAS_RESET:
5733 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
5734 /*
5735 * Report the bus reset and ask for a retry. The device
5736 * will give CC/UA the next command.
5737 */
5738 if (!res->resetting_device)
5739 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
5740 scsi_cmd->result |= (DID_ERROR << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005741 if (!ipr_is_naca_model(res))
5742 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005743 break;
5744 case IPR_IOASC_HW_DEV_BUS_STATUS:
5745 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
5746 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005747 if (!ipr_get_autosense(ipr_cmd)) {
5748 if (!ipr_is_naca_model(res)) {
5749 ipr_erp_cancel_all(ipr_cmd);
5750 return;
5751 }
5752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753 }
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005754 if (!ipr_is_naca_model(res))
5755 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005756 break;
5757 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
5758 break;
5759 default:
Brian King5b7304f2006-08-02 14:57:51 -05005760 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
5761 scsi_cmd->result |= (DID_ERROR << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005762 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763 res->needs_sync_complete = 1;
5764 break;
5765 }
5766
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005767 scsi_dma_unmap(ipr_cmd->scsi_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005768 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5769 scsi_cmd->scsi_done(scsi_cmd);
5770}
5771
5772/**
5773 * ipr_scsi_done - mid-layer done function
5774 * @ipr_cmd: ipr command struct
5775 *
5776 * This function is invoked by the interrupt handler for
5777 * ops generated by the SCSI mid-layer
5778 *
5779 * Return value:
5780 * none
5781 **/
5782static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
5783{
5784 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5785 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005786 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005787
Wayne Boyer96d21f02010-05-10 09:13:27 -07005788 scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005789
5790 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005791 scsi_dma_unmap(ipr_cmd->scsi_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005792 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5793 scsi_cmd->scsi_done(scsi_cmd);
5794 } else
5795 ipr_erp_start(ioa_cfg, ipr_cmd);
5796}
5797
5798/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799 * ipr_queuecommand - Queue a mid-layer request
Brian King00bfef22012-07-17 08:13:52 -05005800 * @shost: scsi host struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005801 * @scsi_cmd: scsi command struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802 *
5803 * This function queues a request generated by the mid-layer.
5804 *
5805 * Return value:
5806 * 0 on success
5807 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
5808 * SCSI_MLQUEUE_HOST_BUSY if host is busy
5809 **/
Brian King00bfef22012-07-17 08:13:52 -05005810static int ipr_queuecommand(struct Scsi_Host *shost,
5811 struct scsi_cmnd *scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005812{
5813 struct ipr_ioa_cfg *ioa_cfg;
5814 struct ipr_resource_entry *res;
5815 struct ipr_ioarcb *ioarcb;
5816 struct ipr_cmnd *ipr_cmd;
Brian King00bfef22012-07-17 08:13:52 -05005817 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005818 int rc = 0;
5819
Brian King00bfef22012-07-17 08:13:52 -05005820 ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
5821
5822 spin_lock_irqsave(shost->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005823 scsi_cmd->result = (DID_OK << 16);
Brian King00bfef22012-07-17 08:13:52 -05005824 res = scsi_cmd->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825
5826 /*
5827 * We are currently blocking all devices due to a host reset
5828 * We have told the host to stop giving us new requests, but
5829 * ERP ops don't count. FIXME
5830 */
Brian King00bfef22012-07-17 08:13:52 -05005831 if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead)) {
5832 spin_unlock_irqrestore(shost->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005833 return SCSI_MLQUEUE_HOST_BUSY;
Brian King00bfef22012-07-17 08:13:52 -05005834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835
5836 /*
5837 * FIXME - Create scsi_set_host_offline interface
5838 * and the ioa_is_dead check can be removed
5839 */
5840 if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
Brian King00bfef22012-07-17 08:13:52 -05005841 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5842 goto err_nodev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843 }
5844
Brian King35a39692006-09-25 12:39:20 -05005845 if (ipr_is_gata(res) && res->sata_port)
Jeff Garzikb27dcfb2010-11-17 22:56:48 -05005846 return ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
Brian King35a39692006-09-25 12:39:20 -05005847
Brian King00bfef22012-07-17 08:13:52 -05005848 ipr_cmd = __ipr_get_free_ipr_cmnd(ioa_cfg);
5849 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5850
5851 ipr_init_ipr_cmnd(ipr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852 ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853
5854 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
5855 ipr_cmd->scsi_cmd = scsi_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005856 ipr_cmd->done = ipr_scsi_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857
5858 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
5859 if (scsi_cmd->underflow == 0)
5860 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5861
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
Wayne Boyerab6c10b2011-03-31 09:56:10 -07005863 if (ipr_is_gscsi(res))
5864 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
5866 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
5867 }
5868
5869 if (scsi_cmd->cmnd[0] >= 0xC0 &&
5870 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
5871 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5872
Wayne Boyera32c0552010-02-19 13:23:36 -08005873 if (likely(rc == 0)) {
5874 if (ioa_cfg->sis64)
5875 rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
5876 else
5877 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
5878 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879
Brian King00bfef22012-07-17 08:13:52 -05005880 spin_lock_irqsave(shost->host_lock, lock_flags);
5881 if (unlikely(rc || (!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))) {
5882 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5883 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5884 if (!rc)
5885 scsi_dma_unmap(scsi_cmd);
Brian Kinga5fb4072012-03-14 21:20:09 -05005886 return SCSI_MLQUEUE_HOST_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005887 }
5888
Brian King00bfef22012-07-17 08:13:52 -05005889 if (unlikely(ioa_cfg->ioa_is_dead)) {
5890 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5891 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5892 scsi_dma_unmap(scsi_cmd);
5893 goto err_nodev;
5894 }
5895
5896 ioarcb->res_handle = res->res_handle;
5897 if (res->needs_sync_complete) {
5898 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
5899 res->needs_sync_complete = 0;
5900 }
5901 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
5902 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
Brian Kinga5fb4072012-03-14 21:20:09 -05005903 ipr_send_command(ipr_cmd);
Brian King00bfef22012-07-17 08:13:52 -05005904 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5905 return 0;
5906
5907err_nodev:
5908 spin_lock_irqsave(shost->host_lock, lock_flags);
5909 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
5910 scsi_cmd->result = (DID_NO_CONNECT << 16);
5911 scsi_cmd->scsi_done(scsi_cmd);
5912 spin_unlock_irqrestore(shost->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005913 return 0;
5914}
5915
5916/**
Brian King35a39692006-09-25 12:39:20 -05005917 * ipr_ioctl - IOCTL handler
5918 * @sdev: scsi device struct
5919 * @cmd: IOCTL cmd
5920 * @arg: IOCTL arg
5921 *
5922 * Return value:
5923 * 0 on success / other on failure
5924 **/
Adrian Bunkbd705f22006-11-21 10:28:48 -06005925static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
Brian King35a39692006-09-25 12:39:20 -05005926{
5927 struct ipr_resource_entry *res;
5928
5929 res = (struct ipr_resource_entry *)sdev->hostdata;
Brian King0ce3a7e2008-07-11 13:37:50 -05005930 if (res && ipr_is_gata(res)) {
5931 if (cmd == HDIO_GET_IDENTITY)
5932 return -ENOTTY;
Jeff Garzik94be9a52009-01-16 10:17:09 -05005933 return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
Brian King0ce3a7e2008-07-11 13:37:50 -05005934 }
Brian King35a39692006-09-25 12:39:20 -05005935
5936 return -EINVAL;
5937}
5938
5939/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940 * ipr_info - Get information about the card/driver
5941 * @scsi_host: scsi host struct
5942 *
5943 * Return value:
5944 * pointer to buffer with description string
5945 **/
5946static const char * ipr_ioa_info(struct Scsi_Host *host)
5947{
5948 static char buffer[512];
5949 struct ipr_ioa_cfg *ioa_cfg;
5950 unsigned long lock_flags = 0;
5951
5952 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
5953
5954 spin_lock_irqsave(host->host_lock, lock_flags);
5955 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
5956 spin_unlock_irqrestore(host->host_lock, lock_flags);
5957
5958 return buffer;
5959}
5960
5961static struct scsi_host_template driver_template = {
5962 .module = THIS_MODULE,
5963 .name = "IPR",
5964 .info = ipr_ioa_info,
Brian King35a39692006-09-25 12:39:20 -05005965 .ioctl = ipr_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 .queuecommand = ipr_queuecommand,
5967 .eh_abort_handler = ipr_eh_abort,
5968 .eh_device_reset_handler = ipr_eh_dev_reset,
5969 .eh_host_reset_handler = ipr_eh_host_reset,
5970 .slave_alloc = ipr_slave_alloc,
5971 .slave_configure = ipr_slave_configure,
5972 .slave_destroy = ipr_slave_destroy,
Brian King35a39692006-09-25 12:39:20 -05005973 .target_alloc = ipr_target_alloc,
5974 .target_destroy = ipr_target_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005975 .change_queue_depth = ipr_change_queue_depth,
5976 .change_queue_type = ipr_change_queue_type,
5977 .bios_param = ipr_biosparam,
5978 .can_queue = IPR_MAX_COMMANDS,
5979 .this_id = -1,
5980 .sg_tablesize = IPR_MAX_SGLIST,
5981 .max_sectors = IPR_IOA_MAX_SECTORS,
5982 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
5983 .use_clustering = ENABLE_CLUSTERING,
5984 .shost_attrs = ipr_ioa_attrs,
5985 .sdev_attrs = ipr_dev_attrs,
5986 .proc_name = IPR_NAME
5987};
5988
Brian King35a39692006-09-25 12:39:20 -05005989/**
5990 * ipr_ata_phy_reset - libata phy_reset handler
5991 * @ap: ata port to reset
5992 *
5993 **/
5994static void ipr_ata_phy_reset(struct ata_port *ap)
5995{
5996 unsigned long flags;
5997 struct ipr_sata_port *sata_port = ap->private_data;
5998 struct ipr_resource_entry *res = sata_port->res;
5999 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6000 int rc;
6001
6002 ENTER;
6003 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6004 while(ioa_cfg->in_reset_reload) {
6005 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6006 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6007 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6008 }
6009
6010 if (!ioa_cfg->allow_cmds)
6011 goto out_unlock;
6012
6013 rc = ipr_device_reset(ioa_cfg, res);
6014
6015 if (rc) {
Tejun Heo3e4ec342010-05-10 21:41:30 +02006016 ap->link.device[0].class = ATA_DEV_NONE;
Brian King35a39692006-09-25 12:39:20 -05006017 goto out_unlock;
6018 }
6019
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006020 ap->link.device[0].class = res->ata_class;
6021 if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
Tejun Heo3e4ec342010-05-10 21:41:30 +02006022 ap->link.device[0].class = ATA_DEV_NONE;
Brian King35a39692006-09-25 12:39:20 -05006023
6024out_unlock:
6025 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6026 LEAVE;
6027}
6028
6029/**
6030 * ipr_ata_post_internal - Cleanup after an internal command
6031 * @qc: ATA queued command
6032 *
6033 * Return value:
6034 * none
6035 **/
6036static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
6037{
6038 struct ipr_sata_port *sata_port = qc->ap->private_data;
6039 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6040 struct ipr_cmnd *ipr_cmd;
6041 unsigned long flags;
6042
6043 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Brian King73d98ff2006-11-21 10:27:58 -06006044 while(ioa_cfg->in_reset_reload) {
6045 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6046 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6047 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6048 }
6049
Brian King35a39692006-09-25 12:39:20 -05006050 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
6051 if (ipr_cmd->qc == qc) {
6052 ipr_device_reset(ioa_cfg, sata_port->res);
6053 break;
6054 }
6055 }
6056 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6057}
6058
6059/**
Brian King35a39692006-09-25 12:39:20 -05006060 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
6061 * @regs: destination
6062 * @tf: source ATA taskfile
6063 *
6064 * Return value:
6065 * none
6066 **/
6067static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
6068 struct ata_taskfile *tf)
6069{
6070 regs->feature = tf->feature;
6071 regs->nsect = tf->nsect;
6072 regs->lbal = tf->lbal;
6073 regs->lbam = tf->lbam;
6074 regs->lbah = tf->lbah;
6075 regs->device = tf->device;
6076 regs->command = tf->command;
6077 regs->hob_feature = tf->hob_feature;
6078 regs->hob_nsect = tf->hob_nsect;
6079 regs->hob_lbal = tf->hob_lbal;
6080 regs->hob_lbam = tf->hob_lbam;
6081 regs->hob_lbah = tf->hob_lbah;
6082 regs->ctl = tf->ctl;
6083}
6084
6085/**
6086 * ipr_sata_done - done function for SATA commands
6087 * @ipr_cmd: ipr command struct
6088 *
6089 * This function is invoked by the interrupt handler for
6090 * ops generated by the SCSI mid-layer to SATA devices
6091 *
6092 * Return value:
6093 * none
6094 **/
6095static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
6096{
6097 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6098 struct ata_queued_cmd *qc = ipr_cmd->qc;
6099 struct ipr_sata_port *sata_port = qc->ap->private_data;
6100 struct ipr_resource_entry *res = sata_port->res;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006101 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian King35a39692006-09-25 12:39:20 -05006102
Wayne Boyer96d21f02010-05-10 09:13:27 -07006103 if (ipr_cmd->ioa_cfg->sis64)
6104 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
6105 sizeof(struct ipr_ioasa_gata));
6106 else
6107 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
6108 sizeof(struct ipr_ioasa_gata));
Brian King35a39692006-09-25 12:39:20 -05006109 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6110
Wayne Boyer96d21f02010-05-10 09:13:27 -07006111 if (be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006112 scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
Brian King35a39692006-09-25 12:39:20 -05006113
6114 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
Wayne Boyer96d21f02010-05-10 09:13:27 -07006115 qc->err_mask |= __ac_err_mask(sata_port->ioasa.status);
Brian King35a39692006-09-25 12:39:20 -05006116 else
Wayne Boyer96d21f02010-05-10 09:13:27 -07006117 qc->err_mask |= ac_err_mask(sata_port->ioasa.status);
Brian King35a39692006-09-25 12:39:20 -05006118 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6119 ata_qc_complete(qc);
6120}
6121
6122/**
Wayne Boyera32c0552010-02-19 13:23:36 -08006123 * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
6124 * @ipr_cmd: ipr command struct
6125 * @qc: ATA queued command
6126 *
6127 **/
6128static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
6129 struct ata_queued_cmd *qc)
6130{
6131 u32 ioadl_flags = 0;
6132 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6133 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
6134 struct ipr_ioadl64_desc *last_ioadl64 = NULL;
6135 int len = qc->nbytes;
6136 struct scatterlist *sg;
6137 unsigned int si;
6138 dma_addr_t dma_addr = ipr_cmd->dma_addr;
6139
6140 if (len == 0)
6141 return;
6142
6143 if (qc->dma_dir == DMA_TO_DEVICE) {
6144 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6145 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6146 } else if (qc->dma_dir == DMA_FROM_DEVICE)
6147 ioadl_flags = IPR_IOADL_FLAGS_READ;
6148
6149 ioarcb->data_transfer_length = cpu_to_be32(len);
6150 ioarcb->ioadl_len =
6151 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
6152 ioarcb->u.sis64_addr_data.data_ioadl_addr =
6153 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl));
6154
6155 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6156 ioadl64->flags = cpu_to_be32(ioadl_flags);
6157 ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
6158 ioadl64->address = cpu_to_be64(sg_dma_address(sg));
6159
6160 last_ioadl64 = ioadl64;
6161 ioadl64++;
6162 }
6163
6164 if (likely(last_ioadl64))
6165 last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6166}
6167
6168/**
Brian King35a39692006-09-25 12:39:20 -05006169 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
6170 * @ipr_cmd: ipr command struct
6171 * @qc: ATA queued command
6172 *
6173 **/
6174static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
6175 struct ata_queued_cmd *qc)
6176{
6177 u32 ioadl_flags = 0;
6178 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08006179 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006180 struct ipr_ioadl_desc *last_ioadl = NULL;
James Bottomleydde20202008-02-19 11:36:56 +01006181 int len = qc->nbytes;
Brian King35a39692006-09-25 12:39:20 -05006182 struct scatterlist *sg;
Tejun Heoff2aeb12007-12-05 16:43:11 +09006183 unsigned int si;
Brian King35a39692006-09-25 12:39:20 -05006184
6185 if (len == 0)
6186 return;
6187
6188 if (qc->dma_dir == DMA_TO_DEVICE) {
6189 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6190 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08006191 ioarcb->data_transfer_length = cpu_to_be32(len);
6192 ioarcb->ioadl_len =
Brian King35a39692006-09-25 12:39:20 -05006193 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6194 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
6195 ioadl_flags = IPR_IOADL_FLAGS_READ;
6196 ioarcb->read_data_transfer_length = cpu_to_be32(len);
6197 ioarcb->read_ioadl_len =
6198 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6199 }
6200
Tejun Heoff2aeb12007-12-05 16:43:11 +09006201 for_each_sg(qc->sg, sg, qc->n_elem, si) {
Brian King35a39692006-09-25 12:39:20 -05006202 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
6203 ioadl->address = cpu_to_be32(sg_dma_address(sg));
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006204
6205 last_ioadl = ioadl;
6206 ioadl++;
Brian King35a39692006-09-25 12:39:20 -05006207 }
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006208
6209 if (likely(last_ioadl))
6210 last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
Brian King35a39692006-09-25 12:39:20 -05006211}
6212
6213/**
6214 * ipr_qc_issue - Issue a SATA qc to a device
6215 * @qc: queued command
6216 *
6217 * Return value:
6218 * 0 if success
6219 **/
6220static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
6221{
6222 struct ata_port *ap = qc->ap;
6223 struct ipr_sata_port *sata_port = ap->private_data;
6224 struct ipr_resource_entry *res = sata_port->res;
6225 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6226 struct ipr_cmnd *ipr_cmd;
6227 struct ipr_ioarcb *ioarcb;
6228 struct ipr_ioarcb_ata_regs *regs;
6229
6230 if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead))
Brian King0feeed82007-03-29 12:43:43 -05006231 return AC_ERR_SYSTEM;
Brian King35a39692006-09-25 12:39:20 -05006232
6233 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
6234 ioarcb = &ipr_cmd->ioarcb;
Brian King35a39692006-09-25 12:39:20 -05006235
Wayne Boyera32c0552010-02-19 13:23:36 -08006236 if (ioa_cfg->sis64) {
6237 regs = &ipr_cmd->i.ata_ioadl.regs;
6238 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
6239 } else
6240 regs = &ioarcb->u.add_data.u.regs;
6241
6242 memset(regs, 0, sizeof(*regs));
6243 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
Brian King35a39692006-09-25 12:39:20 -05006244
6245 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
6246 ipr_cmd->qc = qc;
6247 ipr_cmd->done = ipr_sata_done;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006248 ipr_cmd->ioarcb.res_handle = res->res_handle;
Brian King35a39692006-09-25 12:39:20 -05006249 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
6250 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6251 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
James Bottomleydde20202008-02-19 11:36:56 +01006252 ipr_cmd->dma_use_sg = qc->n_elem;
Brian King35a39692006-09-25 12:39:20 -05006253
Wayne Boyera32c0552010-02-19 13:23:36 -08006254 if (ioa_cfg->sis64)
6255 ipr_build_ata_ioadl64(ipr_cmd, qc);
6256 else
6257 ipr_build_ata_ioadl(ipr_cmd, qc);
6258
Brian King35a39692006-09-25 12:39:20 -05006259 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
6260 ipr_copy_sata_tf(regs, &qc->tf);
6261 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006262 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
Brian King35a39692006-09-25 12:39:20 -05006263
6264 switch (qc->tf.protocol) {
6265 case ATA_PROT_NODATA:
6266 case ATA_PROT_PIO:
6267 break;
6268
6269 case ATA_PROT_DMA:
6270 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6271 break;
6272
Tejun Heo0dc36882007-12-18 16:34:43 -05006273 case ATAPI_PROT_PIO:
6274 case ATAPI_PROT_NODATA:
Brian King35a39692006-09-25 12:39:20 -05006275 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6276 break;
6277
Tejun Heo0dc36882007-12-18 16:34:43 -05006278 case ATAPI_PROT_DMA:
Brian King35a39692006-09-25 12:39:20 -05006279 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6280 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6281 break;
6282
6283 default:
6284 WARN_ON(1);
Brian King0feeed82007-03-29 12:43:43 -05006285 return AC_ERR_INVALID;
Brian King35a39692006-09-25 12:39:20 -05006286 }
6287
Wayne Boyera32c0552010-02-19 13:23:36 -08006288 ipr_send_command(ipr_cmd);
6289
Brian King35a39692006-09-25 12:39:20 -05006290 return 0;
6291}
6292
6293/**
Tejun Heo4c9bf4e2008-04-07 22:47:20 +09006294 * ipr_qc_fill_rtf - Read result TF
6295 * @qc: ATA queued command
6296 *
6297 * Return value:
6298 * true
6299 **/
6300static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
6301{
6302 struct ipr_sata_port *sata_port = qc->ap->private_data;
6303 struct ipr_ioasa_gata *g = &sata_port->ioasa;
6304 struct ata_taskfile *tf = &qc->result_tf;
6305
6306 tf->feature = g->error;
6307 tf->nsect = g->nsect;
6308 tf->lbal = g->lbal;
6309 tf->lbam = g->lbam;
6310 tf->lbah = g->lbah;
6311 tf->device = g->device;
6312 tf->command = g->status;
6313 tf->hob_nsect = g->hob_nsect;
6314 tf->hob_lbal = g->hob_lbal;
6315 tf->hob_lbam = g->hob_lbam;
6316 tf->hob_lbah = g->hob_lbah;
6317 tf->ctl = g->alt_status;
6318
6319 return true;
6320}
6321
Brian King35a39692006-09-25 12:39:20 -05006322static struct ata_port_operations ipr_sata_ops = {
Brian King35a39692006-09-25 12:39:20 -05006323 .phy_reset = ipr_ata_phy_reset,
Tejun Heoa1efdab2008-03-25 12:22:50 +09006324 .hardreset = ipr_sata_reset,
Brian King35a39692006-09-25 12:39:20 -05006325 .post_internal_cmd = ipr_ata_post_internal,
Brian King35a39692006-09-25 12:39:20 -05006326 .qc_prep = ata_noop_qc_prep,
6327 .qc_issue = ipr_qc_issue,
Tejun Heo4c9bf4e2008-04-07 22:47:20 +09006328 .qc_fill_rtf = ipr_qc_fill_rtf,
Brian King35a39692006-09-25 12:39:20 -05006329 .port_start = ata_sas_port_start,
6330 .port_stop = ata_sas_port_stop
6331};
6332
6333static struct ata_port_info sata_port_info = {
Sergei Shtylyov9cbe0562011-02-04 22:05:48 +03006334 .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA,
Sergei Shtylyov0f2e0332011-01-21 20:32:01 +03006335 .pio_mask = ATA_PIO4_ONLY,
6336 .mwdma_mask = ATA_MWDMA2,
6337 .udma_mask = ATA_UDMA6,
Brian King35a39692006-09-25 12:39:20 -05006338 .port_ops = &ipr_sata_ops
6339};
6340
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341#ifdef CONFIG_PPC_PSERIES
6342static const u16 ipr_blocked_processors[] = {
6343 PV_NORTHSTAR,
6344 PV_PULSAR,
6345 PV_POWER4,
6346 PV_ICESTAR,
6347 PV_SSTAR,
6348 PV_POWER4p,
6349 PV_630,
6350 PV_630p
6351};
6352
6353/**
6354 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
6355 * @ioa_cfg: ioa cfg struct
6356 *
6357 * Adapters that use Gemstone revision < 3.1 do not work reliably on
6358 * certain pSeries hardware. This function determines if the given
6359 * adapter is in one of these confgurations or not.
6360 *
6361 * Return value:
6362 * 1 if adapter is not supported / 0 if adapter is supported
6363 **/
6364static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
6365{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006366 int i;
6367
Auke Kok44c10132007-06-08 15:46:36 -07006368 if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
6369 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
6370 if (__is_processor(ipr_blocked_processors[i]))
6371 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372 }
6373 }
6374 return 0;
6375}
6376#else
6377#define ipr_invalid_adapter(ioa_cfg) 0
6378#endif
6379
6380/**
6381 * ipr_ioa_bringdown_done - IOA bring down completion.
6382 * @ipr_cmd: ipr command struct
6383 *
6384 * This function processes the completion of an adapter bring down.
6385 * It wakes any reset sleepers.
6386 *
6387 * Return value:
6388 * IPR_RC_JOB_RETURN
6389 **/
6390static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
6391{
6392 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6393
6394 ENTER;
6395 ioa_cfg->in_reset_reload = 0;
6396 ioa_cfg->reset_retries = 0;
6397 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6398 wake_up_all(&ioa_cfg->reset_wait_q);
6399
6400 spin_unlock_irq(ioa_cfg->host->host_lock);
6401 scsi_unblock_requests(ioa_cfg->host);
6402 spin_lock_irq(ioa_cfg->host->host_lock);
6403 LEAVE;
6404
6405 return IPR_RC_JOB_RETURN;
6406}
6407
6408/**
6409 * ipr_ioa_reset_done - IOA reset completion.
6410 * @ipr_cmd: ipr command struct
6411 *
6412 * This function processes the completion of an adapter reset.
6413 * It schedules any necessary mid-layer add/removes and
6414 * wakes any reset sleepers.
6415 *
6416 * Return value:
6417 * IPR_RC_JOB_RETURN
6418 **/
6419static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
6420{
6421 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6422 struct ipr_resource_entry *res;
6423 struct ipr_hostrcb *hostrcb, *temp;
6424 int i = 0;
6425
6426 ENTER;
6427 ioa_cfg->in_reset_reload = 0;
6428 ioa_cfg->allow_cmds = 1;
6429 ioa_cfg->reset_cmd = NULL;
brking@us.ibm.com3d1d0da2005-11-01 17:01:54 -06006430 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431
6432 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
6433 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
6434 ipr_trace;
6435 break;
6436 }
6437 }
6438 schedule_work(&ioa_cfg->work_q);
6439
6440 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
6441 list_del(&hostrcb->queue);
6442 if (i++ < IPR_NUM_LOG_HCAMS)
6443 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
6444 else
6445 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
6446 }
6447
Brian King6bb04172007-04-26 16:00:08 -05006448 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006449 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
6450
6451 ioa_cfg->reset_retries = 0;
6452 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6453 wake_up_all(&ioa_cfg->reset_wait_q);
6454
Mark Nelson30237852008-12-10 12:23:20 +11006455 spin_unlock(ioa_cfg->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456 scsi_unblock_requests(ioa_cfg->host);
Mark Nelson30237852008-12-10 12:23:20 +11006457 spin_lock(ioa_cfg->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458
6459 if (!ioa_cfg->allow_cmds)
6460 scsi_block_requests(ioa_cfg->host);
6461
6462 LEAVE;
6463 return IPR_RC_JOB_RETURN;
6464}
6465
6466/**
6467 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
6468 * @supported_dev: supported device struct
6469 * @vpids: vendor product id struct
6470 *
6471 * Return value:
6472 * none
6473 **/
6474static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
6475 struct ipr_std_inq_vpids *vpids)
6476{
6477 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
6478 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
6479 supported_dev->num_records = 1;
6480 supported_dev->data_length =
6481 cpu_to_be16(sizeof(struct ipr_supported_device));
6482 supported_dev->reserved = 0;
6483}
6484
6485/**
6486 * ipr_set_supported_devs - Send Set Supported Devices for a device
6487 * @ipr_cmd: ipr command struct
6488 *
Wayne Boyera32c0552010-02-19 13:23:36 -08006489 * This function sends a Set Supported Devices to the adapter
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490 *
6491 * Return value:
6492 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6493 **/
6494static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
6495{
6496 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6497 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6499 struct ipr_resource_entry *res = ipr_cmd->u.res;
6500
6501 ipr_cmd->job_step = ipr_ioa_reset_done;
6502
6503 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
Brian Kinge4fbf442006-03-29 09:37:22 -06006504 if (!ipr_is_scsi_disk(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006505 continue;
6506
6507 ipr_cmd->u.res = res;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006508 ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509
6510 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6511 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6512 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6513
6514 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006515 ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
6517 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
6518
Wayne Boyera32c0552010-02-19 13:23:36 -08006519 ipr_init_ioadl(ipr_cmd,
6520 ioa_cfg->vpd_cbs_dma +
6521 offsetof(struct ipr_misc_cbs, supp_dev),
6522 sizeof(struct ipr_supported_device),
6523 IPR_IOADL_FLAGS_WRITE_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524
6525 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
6526 IPR_SET_SUP_DEVICE_TIMEOUT);
6527
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006528 if (!ioa_cfg->sis64)
6529 ipr_cmd->job_step = ipr_set_supported_devs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 return IPR_RC_JOB_RETURN;
6531 }
6532
6533 return IPR_RC_JOB_CONTINUE;
6534}
6535
6536/**
6537 * ipr_get_mode_page - Locate specified mode page
6538 * @mode_pages: mode page buffer
6539 * @page_code: page code to find
6540 * @len: minimum required length for mode page
6541 *
6542 * Return value:
6543 * pointer to mode page / NULL on failure
6544 **/
6545static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
6546 u32 page_code, u32 len)
6547{
6548 struct ipr_mode_page_hdr *mode_hdr;
6549 u32 page_length;
6550 u32 length;
6551
6552 if (!mode_pages || (mode_pages->hdr.length == 0))
6553 return NULL;
6554
6555 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
6556 mode_hdr = (struct ipr_mode_page_hdr *)
6557 (mode_pages->data + mode_pages->hdr.block_desc_len);
6558
6559 while (length) {
6560 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
6561 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
6562 return mode_hdr;
6563 break;
6564 } else {
6565 page_length = (sizeof(struct ipr_mode_page_hdr) +
6566 mode_hdr->page_length);
6567 length -= page_length;
6568 mode_hdr = (struct ipr_mode_page_hdr *)
6569 ((unsigned long)mode_hdr + page_length);
6570 }
6571 }
6572 return NULL;
6573}
6574
6575/**
6576 * ipr_check_term_power - Check for term power errors
6577 * @ioa_cfg: ioa config struct
6578 * @mode_pages: IOAFP mode pages buffer
6579 *
6580 * Check the IOAFP's mode page 28 for term power errors
6581 *
6582 * Return value:
6583 * nothing
6584 **/
6585static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
6586 struct ipr_mode_pages *mode_pages)
6587{
6588 int i;
6589 int entry_length;
6590 struct ipr_dev_bus_entry *bus;
6591 struct ipr_mode_page28 *mode_page;
6592
6593 mode_page = ipr_get_mode_page(mode_pages, 0x28,
6594 sizeof(struct ipr_mode_page28));
6595
6596 entry_length = mode_page->entry_length;
6597
6598 bus = mode_page->bus;
6599
6600 for (i = 0; i < mode_page->num_entries; i++) {
6601 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
6602 dev_err(&ioa_cfg->pdev->dev,
6603 "Term power is absent on scsi bus %d\n",
6604 bus->res_addr.bus);
6605 }
6606
6607 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
6608 }
6609}
6610
6611/**
6612 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
6613 * @ioa_cfg: ioa config struct
6614 *
6615 * Looks through the config table checking for SES devices. If
6616 * the SES device is in the SES table indicating a maximum SCSI
6617 * bus speed, the speed is limited for the bus.
6618 *
6619 * Return value:
6620 * none
6621 **/
6622static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
6623{
6624 u32 max_xfer_rate;
6625 int i;
6626
6627 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
6628 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
6629 ioa_cfg->bus_attr[i].bus_width);
6630
6631 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
6632 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
6633 }
6634}
6635
6636/**
6637 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
6638 * @ioa_cfg: ioa config struct
6639 * @mode_pages: mode page 28 buffer
6640 *
6641 * Updates mode page 28 based on driver configuration
6642 *
6643 * Return value:
6644 * none
6645 **/
6646static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
6647 struct ipr_mode_pages *mode_pages)
6648{
6649 int i, entry_length;
6650 struct ipr_dev_bus_entry *bus;
6651 struct ipr_bus_attributes *bus_attr;
6652 struct ipr_mode_page28 *mode_page;
6653
6654 mode_page = ipr_get_mode_page(mode_pages, 0x28,
6655 sizeof(struct ipr_mode_page28));
6656
6657 entry_length = mode_page->entry_length;
6658
6659 /* Loop for each device bus entry */
6660 for (i = 0, bus = mode_page->bus;
6661 i < mode_page->num_entries;
6662 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
6663 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
6664 dev_err(&ioa_cfg->pdev->dev,
6665 "Invalid resource address reported: 0x%08X\n",
6666 IPR_GET_PHYS_LOC(bus->res_addr));
6667 continue;
6668 }
6669
6670 bus_attr = &ioa_cfg->bus_attr[i];
6671 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
6672 bus->bus_width = bus_attr->bus_width;
6673 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
6674 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
6675 if (bus_attr->qas_enabled)
6676 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
6677 else
6678 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
6679 }
6680}
6681
6682/**
6683 * ipr_build_mode_select - Build a mode select command
6684 * @ipr_cmd: ipr command struct
6685 * @res_handle: resource handle to send command to
6686 * @parm: Byte 2 of Mode Sense command
6687 * @dma_addr: DMA buffer address
6688 * @xfer_len: data transfer length
6689 *
6690 * Return value:
6691 * none
6692 **/
6693static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
Wayne Boyera32c0552010-02-19 13:23:36 -08006694 __be32 res_handle, u8 parm,
6695 dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6698
6699 ioarcb->res_handle = res_handle;
6700 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6701 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6702 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
6703 ioarcb->cmd_pkt.cdb[1] = parm;
6704 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6705
Wayne Boyera32c0552010-02-19 13:23:36 -08006706 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006707}
6708
6709/**
6710 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
6711 * @ipr_cmd: ipr command struct
6712 *
6713 * This function sets up the SCSI bus attributes and sends
6714 * a Mode Select for Page 28 to activate them.
6715 *
6716 * Return value:
6717 * IPR_RC_JOB_RETURN
6718 **/
6719static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
6720{
6721 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6722 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
6723 int length;
6724
6725 ENTER;
Brian King47338042006-02-08 20:57:42 -06006726 ipr_scsi_bus_speed_limit(ioa_cfg);
6727 ipr_check_term_power(ioa_cfg, mode_pages);
6728 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
6729 length = mode_pages->hdr.length + 1;
6730 mode_pages->hdr.length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006731
6732 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
6733 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
6734 length);
6735
Wayne Boyerf72919e2010-02-19 13:24:21 -08006736 ipr_cmd->job_step = ipr_set_supported_devs;
6737 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
6738 struct ipr_resource_entry, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6740
6741 LEAVE;
6742 return IPR_RC_JOB_RETURN;
6743}
6744
6745/**
6746 * ipr_build_mode_sense - Builds a mode sense command
6747 * @ipr_cmd: ipr command struct
6748 * @res: resource entry struct
6749 * @parm: Byte 2 of mode sense command
6750 * @dma_addr: DMA address of mode sense buffer
6751 * @xfer_len: Size of DMA buffer
6752 *
6753 * Return value:
6754 * none
6755 **/
6756static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
6757 __be32 res_handle,
Wayne Boyera32c0552010-02-19 13:23:36 -08006758 u8 parm, dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6761
6762 ioarcb->res_handle = res_handle;
6763 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
6764 ioarcb->cmd_pkt.cdb[2] = parm;
6765 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6766 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6767
Wayne Boyera32c0552010-02-19 13:23:36 -08006768 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769}
6770
6771/**
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06006772 * ipr_reset_cmd_failed - Handle failure of IOA reset command
6773 * @ipr_cmd: ipr command struct
6774 *
6775 * This function handles the failure of an IOA bringup command.
6776 *
6777 * Return value:
6778 * IPR_RC_JOB_RETURN
6779 **/
6780static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
6781{
6782 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006783 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06006784
6785 dev_err(&ioa_cfg->pdev->dev,
6786 "0x%02X failed with IOASC: 0x%08X\n",
6787 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
6788
6789 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
6790 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6791 return IPR_RC_JOB_RETURN;
6792}
6793
6794/**
6795 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
6796 * @ipr_cmd: ipr command struct
6797 *
6798 * This function handles the failure of a Mode Sense to the IOAFP.
6799 * Some adapters do not handle all mode pages.
6800 *
6801 * Return value:
6802 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6803 **/
6804static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
6805{
Wayne Boyerf72919e2010-02-19 13:24:21 -08006806 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006807 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06006808
6809 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
Wayne Boyerf72919e2010-02-19 13:24:21 -08006810 ipr_cmd->job_step = ipr_set_supported_devs;
6811 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
6812 struct ipr_resource_entry, queue);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06006813 return IPR_RC_JOB_CONTINUE;
6814 }
6815
6816 return ipr_reset_cmd_failed(ipr_cmd);
6817}
6818
6819/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006820 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
6821 * @ipr_cmd: ipr command struct
6822 *
6823 * This function send a Page 28 mode sense to the IOA to
6824 * retrieve SCSI bus attributes.
6825 *
6826 * Return value:
6827 * IPR_RC_JOB_RETURN
6828 **/
6829static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
6830{
6831 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6832
6833 ENTER;
6834 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
6835 0x28, ioa_cfg->vpd_cbs_dma +
6836 offsetof(struct ipr_misc_cbs, mode_pages),
6837 sizeof(struct ipr_mode_pages));
6838
6839 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06006840 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006841
6842 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6843
6844 LEAVE;
6845 return IPR_RC_JOB_RETURN;
6846}
6847
6848/**
Brian Kingac09c342007-04-26 16:00:16 -05006849 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
6850 * @ipr_cmd: ipr command struct
6851 *
6852 * This function enables dual IOA RAID support if possible.
6853 *
6854 * Return value:
6855 * IPR_RC_JOB_RETURN
6856 **/
6857static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
6858{
6859 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6860 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
6861 struct ipr_mode_page24 *mode_page;
6862 int length;
6863
6864 ENTER;
6865 mode_page = ipr_get_mode_page(mode_pages, 0x24,
6866 sizeof(struct ipr_mode_page24));
6867
6868 if (mode_page)
6869 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
6870
6871 length = mode_pages->hdr.length + 1;
6872 mode_pages->hdr.length = 0;
6873
6874 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
6875 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
6876 length);
6877
6878 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6879 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6880
6881 LEAVE;
6882 return IPR_RC_JOB_RETURN;
6883}
6884
6885/**
6886 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
6887 * @ipr_cmd: ipr command struct
6888 *
6889 * This function handles the failure of a Mode Sense to the IOAFP.
6890 * Some adapters do not handle all mode pages.
6891 *
6892 * Return value:
6893 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6894 **/
6895static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
6896{
Wayne Boyer96d21f02010-05-10 09:13:27 -07006897 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian Kingac09c342007-04-26 16:00:16 -05006898
6899 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
6900 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6901 return IPR_RC_JOB_CONTINUE;
6902 }
6903
6904 return ipr_reset_cmd_failed(ipr_cmd);
6905}
6906
6907/**
6908 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
6909 * @ipr_cmd: ipr command struct
6910 *
6911 * This function send a mode sense to the IOA to retrieve
6912 * the IOA Advanced Function Control mode page.
6913 *
6914 * Return value:
6915 * IPR_RC_JOB_RETURN
6916 **/
6917static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
6918{
6919 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6920
6921 ENTER;
6922 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
6923 0x24, ioa_cfg->vpd_cbs_dma +
6924 offsetof(struct ipr_misc_cbs, mode_pages),
6925 sizeof(struct ipr_mode_pages));
6926
6927 ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
6928 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
6929
6930 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6931
6932 LEAVE;
6933 return IPR_RC_JOB_RETURN;
6934}
6935
6936/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006937 * ipr_init_res_table - Initialize the resource table
6938 * @ipr_cmd: ipr command struct
6939 *
6940 * This function looks through the existing resource table, comparing
6941 * it with the config table. This function will take care of old/new
6942 * devices and schedule adding/removing them from the mid-layer
6943 * as appropriate.
6944 *
6945 * Return value:
6946 * IPR_RC_JOB_CONTINUE
6947 **/
6948static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
6949{
6950 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6951 struct ipr_resource_entry *res, *temp;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006952 struct ipr_config_table_entry_wrapper cfgtew;
6953 int entries, found, flag, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006954 LIST_HEAD(old_res);
6955
6956 ENTER;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006957 if (ioa_cfg->sis64)
6958 flag = ioa_cfg->u.cfg_table64->hdr64.flags;
6959 else
6960 flag = ioa_cfg->u.cfg_table->hdr.flags;
6961
6962 if (flag & IPR_UCODE_DOWNLOAD_REQ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006963 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
6964
6965 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
6966 list_move_tail(&res->queue, &old_res);
6967
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006968 if (ioa_cfg->sis64)
Wayne Boyer438b0332010-05-10 09:13:00 -07006969 entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006970 else
6971 entries = ioa_cfg->u.cfg_table->hdr.num_entries;
6972
6973 for (i = 0; i < entries; i++) {
6974 if (ioa_cfg->sis64)
6975 cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
6976 else
6977 cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07006978 found = 0;
6979
6980 list_for_each_entry_safe(res, temp, &old_res, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006981 if (ipr_is_same_device(res, &cfgtew)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006982 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
6983 found = 1;
6984 break;
6985 }
6986 }
6987
6988 if (!found) {
6989 if (list_empty(&ioa_cfg->free_res_q)) {
6990 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
6991 break;
6992 }
6993
6994 found = 1;
6995 res = list_entry(ioa_cfg->free_res_q.next,
6996 struct ipr_resource_entry, queue);
6997 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006998 ipr_init_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006999 res->add_to_ml = 1;
Wayne Boyer56115592010-06-10 14:46:34 -07007000 } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
7001 res->sdev->allow_restart = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007002
7003 if (found)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007004 ipr_update_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007005 }
7006
7007 list_for_each_entry_safe(res, temp, &old_res, queue) {
7008 if (res->sdev) {
7009 res->del_from_ml = 1;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007010 res->res_handle = IPR_INVALID_RES_HANDLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007011 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007012 }
7013 }
7014
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007015 list_for_each_entry_safe(res, temp, &old_res, queue) {
7016 ipr_clear_res_target(res);
7017 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
7018 }
7019
Brian Kingac09c342007-04-26 16:00:16 -05007020 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
7021 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
7022 else
7023 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007024
7025 LEAVE;
7026 return IPR_RC_JOB_CONTINUE;
7027}
7028
7029/**
7030 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
7031 * @ipr_cmd: ipr command struct
7032 *
7033 * This function sends a Query IOA Configuration command
7034 * to the adapter to retrieve the IOA configuration table.
7035 *
7036 * Return value:
7037 * IPR_RC_JOB_RETURN
7038 **/
7039static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
7040{
7041 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7042 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007043 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
Brian Kingac09c342007-04-26 16:00:16 -05007044 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007045
7046 ENTER;
Brian Kingac09c342007-04-26 16:00:16 -05007047 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
7048 ioa_cfg->dual_raid = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007049 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
7050 ucode_vpd->major_release, ucode_vpd->card_type,
7051 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
7052 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7053 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7054
7055 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
Wayne Boyer438b0332010-05-10 09:13:00 -07007056 ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007057 ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
7058 ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007060 ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
Wayne Boyera32c0552010-02-19 13:23:36 -08007061 IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007062
7063 ipr_cmd->job_step = ipr_init_res_table;
7064
7065 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7066
7067 LEAVE;
7068 return IPR_RC_JOB_RETURN;
7069}
7070
7071/**
7072 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
7073 * @ipr_cmd: ipr command struct
7074 *
7075 * This utility function sends an inquiry to the adapter.
7076 *
7077 * Return value:
7078 * none
7079 **/
7080static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
Wayne Boyera32c0552010-02-19 13:23:36 -08007081 dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007082{
7083 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007084
7085 ENTER;
7086 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7087 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7088
7089 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
7090 ioarcb->cmd_pkt.cdb[1] = flags;
7091 ioarcb->cmd_pkt.cdb[2] = page;
7092 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7093
Wayne Boyera32c0552010-02-19 13:23:36 -08007094 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007095
7096 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7097 LEAVE;
7098}
7099
7100/**
brking@us.ibm.com62275042005-11-01 17:01:14 -06007101 * ipr_inquiry_page_supported - Is the given inquiry page supported
7102 * @page0: inquiry page 0 buffer
7103 * @page: page code.
7104 *
7105 * This function determines if the specified inquiry page is supported.
7106 *
7107 * Return value:
7108 * 1 if page is supported / 0 if not
7109 **/
7110static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
7111{
7112 int i;
7113
7114 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
7115 if (page0->page[i] == page)
7116 return 1;
7117
7118 return 0;
7119}
7120
7121/**
Brian Kingac09c342007-04-26 16:00:16 -05007122 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
7123 * @ipr_cmd: ipr command struct
7124 *
7125 * This function sends a Page 0xD0 inquiry to the adapter
7126 * to retrieve adapter capabilities.
7127 *
7128 * Return value:
7129 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7130 **/
7131static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
7132{
7133 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7134 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
7135 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7136
7137 ENTER;
7138 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
7139 memset(cap, 0, sizeof(*cap));
7140
7141 if (ipr_inquiry_page_supported(page0, 0xD0)) {
7142 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
7143 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
7144 sizeof(struct ipr_inquiry_cap));
7145 return IPR_RC_JOB_RETURN;
7146 }
7147
7148 LEAVE;
7149 return IPR_RC_JOB_CONTINUE;
7150}
7151
7152/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007153 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
7154 * @ipr_cmd: ipr command struct
7155 *
7156 * This function sends a Page 3 inquiry to the adapter
7157 * to retrieve software VPD information.
7158 *
7159 * Return value:
7160 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7161 **/
7162static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
7163{
7164 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007165
7166 ENTER;
7167
Brian Kingac09c342007-04-26 16:00:16 -05007168 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007169
7170 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
7171 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
7172 sizeof(struct ipr_inquiry_page3));
7173
7174 LEAVE;
7175 return IPR_RC_JOB_RETURN;
7176}
7177
7178/**
7179 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
7180 * @ipr_cmd: ipr command struct
7181 *
7182 * This function sends a Page 0 inquiry to the adapter
7183 * to retrieve supported inquiry pages.
7184 *
7185 * Return value:
7186 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7187 **/
7188static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
7189{
7190 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007191 char type[5];
7192
7193 ENTER;
7194
7195 /* Grab the type out of the VPD and store it away */
7196 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
7197 type[4] = '\0';
7198 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
7199
brking@us.ibm.com62275042005-11-01 17:01:14 -06007200 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007201
brking@us.ibm.com62275042005-11-01 17:01:14 -06007202 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
7203 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
7204 sizeof(struct ipr_inquiry_page0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007205
7206 LEAVE;
7207 return IPR_RC_JOB_RETURN;
7208}
7209
7210/**
7211 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
7212 * @ipr_cmd: ipr command struct
7213 *
7214 * This function sends a standard inquiry to the adapter.
7215 *
7216 * Return value:
7217 * IPR_RC_JOB_RETURN
7218 **/
7219static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
7220{
7221 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7222
7223 ENTER;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007224 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007225
7226 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
7227 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
7228 sizeof(struct ipr_ioa_vpd));
7229
7230 LEAVE;
7231 return IPR_RC_JOB_RETURN;
7232}
7233
7234/**
Wayne Boyer214777b2010-02-19 13:24:26 -08007235 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007236 * @ipr_cmd: ipr command struct
7237 *
7238 * This function send an Identify Host Request Response Queue
7239 * command to establish the HRRQ with the adapter.
7240 *
7241 * Return value:
7242 * IPR_RC_JOB_RETURN
7243 **/
Wayne Boyer214777b2010-02-19 13:24:26 -08007244static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007245{
7246 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7247 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7248
7249 ENTER;
7250 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
7251
7252 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
7253 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7254
7255 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
Wayne Boyer214777b2010-02-19 13:24:26 -08007256 if (ioa_cfg->sis64)
7257 ioarcb->cmd_pkt.cdb[1] = 0x1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007258 ioarcb->cmd_pkt.cdb[2] =
Wayne Boyer214777b2010-02-19 13:24:26 -08007259 ((u64) ioa_cfg->host_rrq_dma >> 24) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007260 ioarcb->cmd_pkt.cdb[3] =
Wayne Boyer214777b2010-02-19 13:24:26 -08007261 ((u64) ioa_cfg->host_rrq_dma >> 16) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007262 ioarcb->cmd_pkt.cdb[4] =
Wayne Boyer214777b2010-02-19 13:24:26 -08007263 ((u64) ioa_cfg->host_rrq_dma >> 8) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007264 ioarcb->cmd_pkt.cdb[5] =
Wayne Boyer214777b2010-02-19 13:24:26 -08007265 ((u64) ioa_cfg->host_rrq_dma) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007266 ioarcb->cmd_pkt.cdb[7] =
7267 ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
7268 ioarcb->cmd_pkt.cdb[8] =
7269 (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
7270
Wayne Boyer214777b2010-02-19 13:24:26 -08007271 if (ioa_cfg->sis64) {
7272 ioarcb->cmd_pkt.cdb[10] =
7273 ((u64) ioa_cfg->host_rrq_dma >> 56) & 0xff;
7274 ioarcb->cmd_pkt.cdb[11] =
7275 ((u64) ioa_cfg->host_rrq_dma >> 48) & 0xff;
7276 ioarcb->cmd_pkt.cdb[12] =
7277 ((u64) ioa_cfg->host_rrq_dma >> 40) & 0xff;
7278 ioarcb->cmd_pkt.cdb[13] =
7279 ((u64) ioa_cfg->host_rrq_dma >> 32) & 0xff;
7280 }
7281
Linus Torvalds1da177e2005-04-16 15:20:36 -07007282 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
7283
7284 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7285
7286 LEAVE;
7287 return IPR_RC_JOB_RETURN;
7288}
7289
7290/**
7291 * ipr_reset_timer_done - Adapter reset timer function
7292 * @ipr_cmd: ipr command struct
7293 *
7294 * Description: This function is used in adapter reset processing
7295 * for timing events. If the reset_cmd pointer in the IOA
7296 * config struct is not this adapter's we are doing nested
7297 * resets and fail_all_ops will take care of freeing the
7298 * command block.
7299 *
7300 * Return value:
7301 * none
7302 **/
7303static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
7304{
7305 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7306 unsigned long lock_flags = 0;
7307
7308 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7309
7310 if (ioa_cfg->reset_cmd == ipr_cmd) {
7311 list_del(&ipr_cmd->queue);
7312 ipr_cmd->done(ipr_cmd);
7313 }
7314
7315 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7316}
7317
7318/**
7319 * ipr_reset_start_timer - Start a timer for adapter reset job
7320 * @ipr_cmd: ipr command struct
7321 * @timeout: timeout value
7322 *
7323 * Description: This function is used in adapter reset processing
7324 * for timing events. If the reset_cmd pointer in the IOA
7325 * config struct is not this adapter's we are doing nested
7326 * resets and fail_all_ops will take care of freeing the
7327 * command block.
7328 *
7329 * Return value:
7330 * none
7331 **/
7332static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
7333 unsigned long timeout)
7334{
7335 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
7336 ipr_cmd->done = ipr_reset_ioa_job;
7337
7338 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7339 ipr_cmd->timer.expires = jiffies + timeout;
7340 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
7341 add_timer(&ipr_cmd->timer);
7342}
7343
7344/**
7345 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7346 * @ioa_cfg: ioa cfg struct
7347 *
7348 * Return value:
7349 * nothing
7350 **/
7351static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
7352{
7353 memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
7354
7355 /* Initialize Host RRQ pointers */
7356 ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
7357 ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
7358 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
7359 ioa_cfg->toggle_bit = 1;
7360
7361 /* Zero out config table */
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007362 memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007363}
7364
7365/**
Wayne Boyer214777b2010-02-19 13:24:26 -08007366 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
7367 * @ipr_cmd: ipr command struct
7368 *
7369 * Return value:
7370 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7371 **/
7372static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
7373{
7374 unsigned long stage, stage_time;
7375 u32 feedback;
7376 volatile u32 int_reg;
7377 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7378 u64 maskval = 0;
7379
7380 feedback = readl(ioa_cfg->regs.init_feedback_reg);
7381 stage = feedback & IPR_IPL_INIT_STAGE_MASK;
7382 stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
7383
7384 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
7385
7386 /* sanity check the stage_time value */
Wayne Boyer438b0332010-05-10 09:13:00 -07007387 if (stage_time == 0)
7388 stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
7389 else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
Wayne Boyer214777b2010-02-19 13:24:26 -08007390 stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
7391 else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
7392 stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
7393
7394 if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
7395 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
7396 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7397 stage_time = ioa_cfg->transop_timeout;
7398 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7399 } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
Wayne Boyer1df79ca2010-07-14 10:49:43 -07007400 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
7401 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7402 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7403 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7404 maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
7405 writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
7406 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7407 return IPR_RC_JOB_CONTINUE;
7408 }
Wayne Boyer214777b2010-02-19 13:24:26 -08007409 }
7410
7411 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7412 ipr_cmd->timer.expires = jiffies + stage_time * HZ;
7413 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7414 ipr_cmd->done = ipr_reset_ioa_job;
7415 add_timer(&ipr_cmd->timer);
7416 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
7417
7418 return IPR_RC_JOB_RETURN;
7419}
7420
7421/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007422 * ipr_reset_enable_ioa - Enable the IOA following a reset.
7423 * @ipr_cmd: ipr command struct
7424 *
7425 * This function reinitializes some control blocks and
7426 * enables destructive diagnostics on the adapter.
7427 *
7428 * Return value:
7429 * IPR_RC_JOB_RETURN
7430 **/
7431static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
7432{
7433 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7434 volatile u32 int_reg;
Wayne Boyer7be96902010-05-10 09:14:07 -07007435 volatile u64 maskval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007436
7437 ENTER;
Wayne Boyer214777b2010-02-19 13:24:26 -08007438 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007439 ipr_init_ioa_mem(ioa_cfg);
7440
7441 ioa_cfg->allow_interrupts = 1;
Wayne Boyer8701f182010-06-04 10:26:50 -07007442 if (ioa_cfg->sis64) {
7443 /* Set the adapter to the correct endian mode. */
7444 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
7445 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
7446 }
7447
Wayne Boyer7be96902010-05-10 09:14:07 -07007448 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007449
7450 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7451 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
Wayne Boyer214777b2010-02-19 13:24:26 -08007452 ioa_cfg->regs.clr_interrupt_mask_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007453 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7454 return IPR_RC_JOB_CONTINUE;
7455 }
7456
7457 /* Enable destructive diagnostics on IOA */
Wayne Boyer214777b2010-02-19 13:24:26 -08007458 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007459
Wayne Boyer7be96902010-05-10 09:14:07 -07007460 if (ioa_cfg->sis64) {
7461 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7462 maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
7463 writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
7464 } else
7465 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
Wayne Boyer214777b2010-02-19 13:24:26 -08007466
Linus Torvalds1da177e2005-04-16 15:20:36 -07007467 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7468
7469 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
7470
Wayne Boyer214777b2010-02-19 13:24:26 -08007471 if (ioa_cfg->sis64) {
7472 ipr_cmd->job_step = ipr_reset_next_stage;
7473 return IPR_RC_JOB_CONTINUE;
7474 }
7475
Linus Torvalds1da177e2005-04-16 15:20:36 -07007476 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
Brian King5469cb52007-03-29 12:42:40 -05007477 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007478 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7479 ipr_cmd->done = ipr_reset_ioa_job;
7480 add_timer(&ipr_cmd->timer);
7481 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
7482
7483 LEAVE;
7484 return IPR_RC_JOB_RETURN;
7485}
7486
7487/**
7488 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
7489 * @ipr_cmd: ipr command struct
7490 *
7491 * This function is invoked when an adapter dump has run out
7492 * of processing time.
7493 *
7494 * Return value:
7495 * IPR_RC_JOB_CONTINUE
7496 **/
7497static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
7498{
7499 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7500
7501 if (ioa_cfg->sdt_state == GET_DUMP)
Brian King41e9a692011-09-21 08:51:11 -05007502 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7503 else if (ioa_cfg->sdt_state == READ_DUMP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007504 ioa_cfg->sdt_state = ABORT_DUMP;
7505
Brian King4c647e92011-10-15 09:08:56 -05007506 ioa_cfg->dump_timeout = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007507 ipr_cmd->job_step = ipr_reset_alert;
7508
7509 return IPR_RC_JOB_CONTINUE;
7510}
7511
7512/**
7513 * ipr_unit_check_no_data - Log a unit check/no data error log
7514 * @ioa_cfg: ioa config struct
7515 *
7516 * Logs an error indicating the adapter unit checked, but for some
7517 * reason, we were unable to fetch the unit check buffer.
7518 *
7519 * Return value:
7520 * nothing
7521 **/
7522static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
7523{
7524 ioa_cfg->errors_logged++;
7525 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
7526}
7527
7528/**
7529 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
7530 * @ioa_cfg: ioa config struct
7531 *
7532 * Fetches the unit check buffer from the adapter by clocking the data
7533 * through the mailbox register.
7534 *
7535 * Return value:
7536 * nothing
7537 **/
7538static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
7539{
7540 unsigned long mailbox;
7541 struct ipr_hostrcb *hostrcb;
7542 struct ipr_uc_sdt sdt;
7543 int rc, length;
Brian King65f56472007-04-26 16:00:12 -05007544 u32 ioasc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007545
7546 mailbox = readl(ioa_cfg->ioa_mailbox);
7547
Wayne Boyerdcbad002010-02-19 13:24:14 -08007548 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007549 ipr_unit_check_no_data(ioa_cfg);
7550 return;
7551 }
7552
7553 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
7554 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
7555 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
7556
Wayne Boyerdcbad002010-02-19 13:24:14 -08007557 if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
7558 ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
7559 (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007560 ipr_unit_check_no_data(ioa_cfg);
7561 return;
7562 }
7563
7564 /* Find length of the first sdt entry (UC buffer) */
Wayne Boyerdcbad002010-02-19 13:24:14 -08007565 if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
7566 length = be32_to_cpu(sdt.entry[0].end_token);
7567 else
7568 length = (be32_to_cpu(sdt.entry[0].end_token) -
7569 be32_to_cpu(sdt.entry[0].start_token)) &
7570 IPR_FMT2_MBX_ADDR_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007571
7572 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
7573 struct ipr_hostrcb, queue);
7574 list_del(&hostrcb->queue);
7575 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
7576
7577 rc = ipr_get_ldump_data_section(ioa_cfg,
Wayne Boyerdcbad002010-02-19 13:24:14 -08007578 be32_to_cpu(sdt.entry[0].start_token),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007579 (__be32 *)&hostrcb->hcam,
7580 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
7581
Brian King65f56472007-04-26 16:00:12 -05007582 if (!rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007583 ipr_handle_log_data(ioa_cfg, hostrcb);
Wayne Boyer4565e372010-02-19 13:24:07 -08007584 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Brian King65f56472007-04-26 16:00:12 -05007585 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
7586 ioa_cfg->sdt_state == GET_DUMP)
7587 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7588 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07007589 ipr_unit_check_no_data(ioa_cfg);
7590
7591 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
7592}
7593
7594/**
Wayne Boyer110def82010-11-04 09:36:16 -07007595 * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
7596 * @ipr_cmd: ipr command struct
7597 *
7598 * Description: This function will call to get the unit check buffer.
7599 *
7600 * Return value:
7601 * IPR_RC_JOB_RETURN
7602 **/
7603static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
7604{
7605 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7606
7607 ENTER;
7608 ioa_cfg->ioa_unit_checked = 0;
7609 ipr_get_unit_check_buffer(ioa_cfg);
7610 ipr_cmd->job_step = ipr_reset_alert;
7611 ipr_reset_start_timer(ipr_cmd, 0);
7612
7613 LEAVE;
7614 return IPR_RC_JOB_RETURN;
7615}
7616
7617/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007618 * ipr_reset_restore_cfg_space - Restore PCI config space.
7619 * @ipr_cmd: ipr command struct
7620 *
7621 * Description: This function restores the saved PCI config space of
7622 * the adapter, fails all outstanding ops back to the callers, and
7623 * fetches the dump/unit check if applicable to this reset.
7624 *
7625 * Return value:
7626 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7627 **/
7628static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
7629{
7630 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer630ad8312011-04-07 12:12:30 -07007631 u32 int_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007632
7633 ENTER;
Kleber Sacilotto de Souza99c965d2009-11-25 20:13:43 -02007634 ioa_cfg->pdev->state_saved = true;
Jon Mason1d3c16a2010-11-30 17:43:26 -06007635 pci_restore_state(ioa_cfg->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007636
7637 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
Wayne Boyer96d21f02010-05-10 09:13:27 -07007638 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007639 return IPR_RC_JOB_CONTINUE;
7640 }
7641
7642 ipr_fail_all_ops(ioa_cfg);
7643
Wayne Boyer8701f182010-06-04 10:26:50 -07007644 if (ioa_cfg->sis64) {
7645 /* Set the adapter to the correct endian mode. */
7646 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
7647 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
7648 }
7649
Linus Torvalds1da177e2005-04-16 15:20:36 -07007650 if (ioa_cfg->ioa_unit_checked) {
Wayne Boyer110def82010-11-04 09:36:16 -07007651 if (ioa_cfg->sis64) {
7652 ipr_cmd->job_step = ipr_reset_get_unit_check_job;
7653 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
7654 return IPR_RC_JOB_RETURN;
7655 } else {
7656 ioa_cfg->ioa_unit_checked = 0;
7657 ipr_get_unit_check_buffer(ioa_cfg);
7658 ipr_cmd->job_step = ipr_reset_alert;
7659 ipr_reset_start_timer(ipr_cmd, 0);
7660 return IPR_RC_JOB_RETURN;
7661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007662 }
7663
7664 if (ioa_cfg->in_ioa_bringdown) {
7665 ipr_cmd->job_step = ipr_ioa_bringdown_done;
7666 } else {
7667 ipr_cmd->job_step = ipr_reset_enable_ioa;
7668
7669 if (GET_DUMP == ioa_cfg->sdt_state) {
Brian King41e9a692011-09-21 08:51:11 -05007670 ioa_cfg->sdt_state = READ_DUMP;
Brian King4c647e92011-10-15 09:08:56 -05007671 ioa_cfg->dump_timeout = 0;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03007672 if (ioa_cfg->sis64)
7673 ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
7674 else
7675 ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007676 ipr_cmd->job_step = ipr_reset_wait_for_dump;
7677 schedule_work(&ioa_cfg->work_q);
7678 return IPR_RC_JOB_RETURN;
7679 }
7680 }
7681
Wayne Boyer438b0332010-05-10 09:13:00 -07007682 LEAVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007683 return IPR_RC_JOB_CONTINUE;
7684}
7685
7686/**
Brian Kinge619e1a2007-01-23 11:25:37 -06007687 * ipr_reset_bist_done - BIST has completed on the adapter.
7688 * @ipr_cmd: ipr command struct
7689 *
7690 * Description: Unblock config space and resume the reset process.
7691 *
7692 * Return value:
7693 * IPR_RC_JOB_CONTINUE
7694 **/
7695static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
7696{
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007697 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7698
Brian Kinge619e1a2007-01-23 11:25:37 -06007699 ENTER;
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007700 if (ioa_cfg->cfg_locked)
7701 pci_cfg_access_unlock(ioa_cfg->pdev);
7702 ioa_cfg->cfg_locked = 0;
Brian Kinge619e1a2007-01-23 11:25:37 -06007703 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
7704 LEAVE;
7705 return IPR_RC_JOB_CONTINUE;
7706}
7707
7708/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007709 * ipr_reset_start_bist - Run BIST on the adapter.
7710 * @ipr_cmd: ipr command struct
7711 *
7712 * Description: This function runs BIST on the adapter, then delays 2 seconds.
7713 *
7714 * Return value:
7715 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7716 **/
7717static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
7718{
7719 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyercb237ef2010-06-17 11:51:40 -07007720 int rc = PCIBIOS_SUCCESSFUL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007721
7722 ENTER;
Wayne Boyercb237ef2010-06-17 11:51:40 -07007723 if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
7724 writel(IPR_UPROCI_SIS64_START_BIST,
7725 ioa_cfg->regs.set_uproc_interrupt_reg32);
7726 else
7727 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
7728
7729 if (rc == PCIBIOS_SUCCESSFUL) {
Brian Kinge619e1a2007-01-23 11:25:37 -06007730 ipr_cmd->job_step = ipr_reset_bist_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007731 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
7732 rc = IPR_RC_JOB_RETURN;
Wayne Boyercb237ef2010-06-17 11:51:40 -07007733 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007734 if (ioa_cfg->cfg_locked)
7735 pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
7736 ioa_cfg->cfg_locked = 0;
Wayne Boyercb237ef2010-06-17 11:51:40 -07007737 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
7738 rc = IPR_RC_JOB_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007739 }
7740
7741 LEAVE;
7742 return rc;
7743}
7744
7745/**
Brian King463fc692007-05-07 17:09:05 -05007746 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
7747 * @ipr_cmd: ipr command struct
7748 *
7749 * Description: This clears PCI reset to the adapter and delays two seconds.
7750 *
7751 * Return value:
7752 * IPR_RC_JOB_RETURN
7753 **/
7754static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
7755{
7756 ENTER;
7757 pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
7758 ipr_cmd->job_step = ipr_reset_bist_done;
7759 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
7760 LEAVE;
7761 return IPR_RC_JOB_RETURN;
7762}
7763
7764/**
7765 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
7766 * @ipr_cmd: ipr command struct
7767 *
7768 * Description: This asserts PCI reset to the adapter.
7769 *
7770 * Return value:
7771 * IPR_RC_JOB_RETURN
7772 **/
7773static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
7774{
7775 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7776 struct pci_dev *pdev = ioa_cfg->pdev;
7777
7778 ENTER;
Brian King463fc692007-05-07 17:09:05 -05007779 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
7780 ipr_cmd->job_step = ipr_reset_slot_reset_done;
7781 ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
7782 LEAVE;
7783 return IPR_RC_JOB_RETURN;
7784}
7785
7786/**
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007787 * ipr_reset_block_config_access_wait - Wait for permission to block config access
7788 * @ipr_cmd: ipr command struct
7789 *
7790 * Description: This attempts to block config access to the IOA.
7791 *
7792 * Return value:
7793 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7794 **/
7795static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
7796{
7797 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7798 int rc = IPR_RC_JOB_CONTINUE;
7799
7800 if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
7801 ioa_cfg->cfg_locked = 1;
7802 ipr_cmd->job_step = ioa_cfg->reset;
7803 } else {
7804 if (ipr_cmd->u.time_left) {
7805 rc = IPR_RC_JOB_RETURN;
7806 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
7807 ipr_reset_start_timer(ipr_cmd,
7808 IPR_CHECK_FOR_RESET_TIMEOUT);
7809 } else {
7810 ipr_cmd->job_step = ioa_cfg->reset;
7811 dev_err(&ioa_cfg->pdev->dev,
7812 "Timed out waiting to lock config access. Resetting anyway.\n");
7813 }
7814 }
7815
7816 return rc;
7817}
7818
7819/**
7820 * ipr_reset_block_config_access - Block config access to the IOA
7821 * @ipr_cmd: ipr command struct
7822 *
7823 * Description: This attempts to block config access to the IOA
7824 *
7825 * Return value:
7826 * IPR_RC_JOB_CONTINUE
7827 **/
7828static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
7829{
7830 ipr_cmd->ioa_cfg->cfg_locked = 0;
7831 ipr_cmd->job_step = ipr_reset_block_config_access_wait;
7832 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
7833 return IPR_RC_JOB_CONTINUE;
7834}
7835
7836/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007837 * ipr_reset_allowed - Query whether or not IOA can be reset
7838 * @ioa_cfg: ioa config struct
7839 *
7840 * Return value:
7841 * 0 if reset not allowed / non-zero if reset is allowed
7842 **/
7843static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
7844{
7845 volatile u32 temp_reg;
7846
7847 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
7848 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
7849}
7850
7851/**
7852 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
7853 * @ipr_cmd: ipr command struct
7854 *
7855 * Description: This function waits for adapter permission to run BIST,
7856 * then runs BIST. If the adapter does not give permission after a
7857 * reasonable time, we will reset the adapter anyway. The impact of
7858 * resetting the adapter without warning the adapter is the risk of
7859 * losing the persistent error log on the adapter. If the adapter is
7860 * reset while it is writing to the flash on the adapter, the flash
7861 * segment will have bad ECC and be zeroed.
7862 *
7863 * Return value:
7864 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7865 **/
7866static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
7867{
7868 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7869 int rc = IPR_RC_JOB_RETURN;
7870
7871 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
7872 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
7873 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
7874 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007875 ipr_cmd->job_step = ipr_reset_block_config_access;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007876 rc = IPR_RC_JOB_CONTINUE;
7877 }
7878
7879 return rc;
7880}
7881
7882/**
Wayne Boyer8701f182010-06-04 10:26:50 -07007883 * ipr_reset_alert - Alert the adapter of a pending reset
Linus Torvalds1da177e2005-04-16 15:20:36 -07007884 * @ipr_cmd: ipr command struct
7885 *
7886 * Description: This function alerts the adapter that it will be reset.
7887 * If memory space is not currently enabled, proceed directly
7888 * to running BIST on the adapter. The timer must always be started
7889 * so we guarantee we do not run BIST from ipr_isr.
7890 *
7891 * Return value:
7892 * IPR_RC_JOB_RETURN
7893 **/
7894static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
7895{
7896 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7897 u16 cmd_reg;
7898 int rc;
7899
7900 ENTER;
7901 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
7902
7903 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
7904 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
Wayne Boyer214777b2010-02-19 13:24:26 -08007905 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007906 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
7907 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007908 ipr_cmd->job_step = ipr_reset_block_config_access;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007909 }
7910
7911 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
7912 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
7913
7914 LEAVE;
7915 return IPR_RC_JOB_RETURN;
7916}
7917
7918/**
7919 * ipr_reset_ucode_download_done - Microcode download completion
7920 * @ipr_cmd: ipr command struct
7921 *
7922 * Description: This function unmaps the microcode download buffer.
7923 *
7924 * Return value:
7925 * IPR_RC_JOB_CONTINUE
7926 **/
7927static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
7928{
7929 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7930 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
7931
7932 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
7933 sglist->num_sg, DMA_TO_DEVICE);
7934
7935 ipr_cmd->job_step = ipr_reset_alert;
7936 return IPR_RC_JOB_CONTINUE;
7937}
7938
7939/**
7940 * ipr_reset_ucode_download - Download microcode to the adapter
7941 * @ipr_cmd: ipr command struct
7942 *
7943 * Description: This function checks to see if it there is microcode
7944 * to download to the adapter. If there is, a download is performed.
7945 *
7946 * Return value:
7947 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7948 **/
7949static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
7950{
7951 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7952 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
7953
7954 ENTER;
7955 ipr_cmd->job_step = ipr_reset_alert;
7956
7957 if (!sglist)
7958 return IPR_RC_JOB_CONTINUE;
7959
7960 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7961 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7962 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
7963 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
7964 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
7965 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
7966 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
7967
Wayne Boyera32c0552010-02-19 13:23:36 -08007968 if (ioa_cfg->sis64)
7969 ipr_build_ucode_ioadl64(ipr_cmd, sglist);
7970 else
7971 ipr_build_ucode_ioadl(ipr_cmd, sglist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007972 ipr_cmd->job_step = ipr_reset_ucode_download_done;
7973
7974 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7975 IPR_WRITE_BUFFER_TIMEOUT);
7976
7977 LEAVE;
7978 return IPR_RC_JOB_RETURN;
7979}
7980
7981/**
7982 * ipr_reset_shutdown_ioa - Shutdown the adapter
7983 * @ipr_cmd: ipr command struct
7984 *
7985 * Description: This function issues an adapter shutdown of the
7986 * specified type to the specified adapter as part of the
7987 * adapter reset job.
7988 *
7989 * Return value:
7990 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7991 **/
7992static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
7993{
7994 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7995 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
7996 unsigned long timeout;
7997 int rc = IPR_RC_JOB_CONTINUE;
7998
7999 ENTER;
8000 if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
8001 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8002 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8003 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
8004 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
8005
Brian Kingac09c342007-04-26 16:00:16 -05008006 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
8007 timeout = IPR_SHUTDOWN_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008008 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
8009 timeout = IPR_INTERNAL_TIMEOUT;
Brian Kingac09c342007-04-26 16:00:16 -05008010 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
8011 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008012 else
Brian Kingac09c342007-04-26 16:00:16 -05008013 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008014
8015 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
8016
8017 rc = IPR_RC_JOB_RETURN;
8018 ipr_cmd->job_step = ipr_reset_ucode_download;
8019 } else
8020 ipr_cmd->job_step = ipr_reset_alert;
8021
8022 LEAVE;
8023 return rc;
8024}
8025
8026/**
8027 * ipr_reset_ioa_job - Adapter reset job
8028 * @ipr_cmd: ipr command struct
8029 *
8030 * Description: This function is the job router for the adapter reset job.
8031 *
8032 * Return value:
8033 * none
8034 **/
8035static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
8036{
8037 u32 rc, ioasc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008038 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8039
8040 do {
Wayne Boyer96d21f02010-05-10 09:13:27 -07008041 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008042
8043 if (ioa_cfg->reset_cmd != ipr_cmd) {
8044 /*
8045 * We are doing nested adapter resets and this is
8046 * not the current reset job.
8047 */
8048 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
8049 return;
8050 }
8051
8052 if (IPR_IOASC_SENSE_KEY(ioasc)) {
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06008053 rc = ipr_cmd->job_step_failed(ipr_cmd);
8054 if (rc == IPR_RC_JOB_RETURN)
8055 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008056 }
8057
8058 ipr_reinit_ipr_cmnd(ipr_cmd);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06008059 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008060 rc = ipr_cmd->job_step(ipr_cmd);
8061 } while(rc == IPR_RC_JOB_CONTINUE);
8062}
8063
8064/**
8065 * _ipr_initiate_ioa_reset - Initiate an adapter reset
8066 * @ioa_cfg: ioa config struct
8067 * @job_step: first job step of reset job
8068 * @shutdown_type: shutdown type
8069 *
8070 * Description: This function will initiate the reset of the given adapter
8071 * starting at the selected job step.
8072 * If the caller needs to wait on the completion of the reset,
8073 * the caller must sleep on the reset_wait_q.
8074 *
8075 * Return value:
8076 * none
8077 **/
8078static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8079 int (*job_step) (struct ipr_cmnd *),
8080 enum ipr_shutdown_type shutdown_type)
8081{
8082 struct ipr_cmnd *ipr_cmd;
8083
8084 ioa_cfg->in_reset_reload = 1;
8085 ioa_cfg->allow_cmds = 0;
8086 scsi_block_requests(ioa_cfg->host);
8087
8088 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
8089 ioa_cfg->reset_cmd = ipr_cmd;
8090 ipr_cmd->job_step = job_step;
8091 ipr_cmd->u.shutdown_type = shutdown_type;
8092
8093 ipr_reset_ioa_job(ipr_cmd);
8094}
8095
8096/**
8097 * ipr_initiate_ioa_reset - Initiate an adapter reset
8098 * @ioa_cfg: ioa config struct
8099 * @shutdown_type: shutdown type
8100 *
8101 * Description: This function will initiate the reset of the given adapter.
8102 * If the caller needs to wait on the completion of the reset,
8103 * the caller must sleep on the reset_wait_q.
8104 *
8105 * Return value:
8106 * none
8107 **/
8108static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8109 enum ipr_shutdown_type shutdown_type)
8110{
8111 if (ioa_cfg->ioa_is_dead)
8112 return;
8113
Brian King41e9a692011-09-21 08:51:11 -05008114 if (ioa_cfg->in_reset_reload) {
8115 if (ioa_cfg->sdt_state == GET_DUMP)
8116 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8117 else if (ioa_cfg->sdt_state == READ_DUMP)
8118 ioa_cfg->sdt_state = ABORT_DUMP;
8119 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008120
8121 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
8122 dev_err(&ioa_cfg->pdev->dev,
8123 "IOA taken offline - error recovery failed\n");
8124
8125 ioa_cfg->reset_retries = 0;
8126 ioa_cfg->ioa_is_dead = 1;
8127
8128 if (ioa_cfg->in_ioa_bringdown) {
8129 ioa_cfg->reset_cmd = NULL;
8130 ioa_cfg->in_reset_reload = 0;
8131 ipr_fail_all_ops(ioa_cfg);
8132 wake_up_all(&ioa_cfg->reset_wait_q);
8133
8134 spin_unlock_irq(ioa_cfg->host->host_lock);
8135 scsi_unblock_requests(ioa_cfg->host);
8136 spin_lock_irq(ioa_cfg->host->host_lock);
8137 return;
8138 } else {
8139 ioa_cfg->in_ioa_bringdown = 1;
8140 shutdown_type = IPR_SHUTDOWN_NONE;
8141 }
8142 }
8143
8144 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
8145 shutdown_type);
8146}
8147
8148/**
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008149 * ipr_reset_freeze - Hold off all I/O activity
8150 * @ipr_cmd: ipr command struct
8151 *
8152 * Description: If the PCI slot is frozen, hold off all I/O
8153 * activity; then, as soon as the slot is available again,
8154 * initiate an adapter reset.
8155 */
8156static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
8157{
8158 /* Disallow new interrupts, avoid loop */
8159 ipr_cmd->ioa_cfg->allow_interrupts = 0;
8160 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
8161 ipr_cmd->done = ipr_reset_ioa_job;
8162 return IPR_RC_JOB_RETURN;
8163}
8164
8165/**
8166 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
8167 * @pdev: PCI device struct
8168 *
8169 * Description: This routine is called to tell us that the PCI bus
8170 * is down. Can't do anything here, except put the device driver
8171 * into a holding pattern, waiting for the PCI bus to come back.
8172 */
8173static void ipr_pci_frozen(struct pci_dev *pdev)
8174{
8175 unsigned long flags = 0;
8176 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8177
8178 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8179 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
8180 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8181}
8182
8183/**
8184 * ipr_pci_slot_reset - Called when PCI slot has been reset.
8185 * @pdev: PCI device struct
8186 *
8187 * Description: This routine is called by the pci error recovery
8188 * code after the PCI slot has been reset, just before we
8189 * should resume normal operations.
8190 */
8191static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
8192{
8193 unsigned long flags = 0;
8194 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8195
8196 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Brian King463fc692007-05-07 17:09:05 -05008197 if (ioa_cfg->needs_warm_reset)
8198 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8199 else
8200 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
8201 IPR_SHUTDOWN_NONE);
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008202 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8203 return PCI_ERS_RESULT_RECOVERED;
8204}
8205
8206/**
8207 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
8208 * @pdev: PCI device struct
8209 *
8210 * Description: This routine is called when the PCI bus has
8211 * permanently failed.
8212 */
8213static void ipr_pci_perm_failure(struct pci_dev *pdev)
8214{
8215 unsigned long flags = 0;
8216 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8217
8218 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8219 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
8220 ioa_cfg->sdt_state = ABORT_DUMP;
8221 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES;
8222 ioa_cfg->in_ioa_bringdown = 1;
Kleber S. Souza6ff63892009-05-04 10:41:02 -03008223 ioa_cfg->allow_cmds = 0;
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008224 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8225 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8226}
8227
8228/**
8229 * ipr_pci_error_detected - Called when a PCI error is detected.
8230 * @pdev: PCI device struct
8231 * @state: PCI channel state
8232 *
8233 * Description: Called when a PCI error is detected.
8234 *
8235 * Return value:
8236 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8237 */
8238static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
8239 pci_channel_state_t state)
8240{
8241 switch (state) {
8242 case pci_channel_io_frozen:
8243 ipr_pci_frozen(pdev);
8244 return PCI_ERS_RESULT_NEED_RESET;
8245 case pci_channel_io_perm_failure:
8246 ipr_pci_perm_failure(pdev);
8247 return PCI_ERS_RESULT_DISCONNECT;
8248 break;
8249 default:
8250 break;
8251 }
8252 return PCI_ERS_RESULT_NEED_RESET;
8253}
8254
8255/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008256 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
8257 * @ioa_cfg: ioa cfg struct
8258 *
8259 * Description: This is the second phase of adapter intialization
8260 * This function takes care of initilizing the adapter to the point
8261 * where it can accept new commands.
8262
8263 * Return value:
Joe Perchesb1c11812008-02-03 17:28:22 +02008264 * 0 on success / -EIO on failure
Linus Torvalds1da177e2005-04-16 15:20:36 -07008265 **/
8266static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
8267{
8268 int rc = 0;
8269 unsigned long host_lock_flags = 0;
8270
8271 ENTER;
8272 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8273 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06008274 if (ioa_cfg->needs_hard_reset) {
8275 ioa_cfg->needs_hard_reset = 0;
8276 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8277 } else
8278 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
8279 IPR_SHUTDOWN_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008280
8281 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8282 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
8283 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8284
8285 if (ioa_cfg->ioa_is_dead) {
8286 rc = -EIO;
8287 } else if (ipr_invalid_adapter(ioa_cfg)) {
8288 if (!ipr_testmode)
8289 rc = -EIO;
8290
8291 dev_err(&ioa_cfg->pdev->dev,
8292 "Adapter not supported in this hardware configuration.\n");
8293 }
8294
8295 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8296
8297 LEAVE;
8298 return rc;
8299}
8300
8301/**
8302 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
8303 * @ioa_cfg: ioa config struct
8304 *
8305 * Return value:
8306 * none
8307 **/
8308static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8309{
8310 int i;
8311
8312 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8313 if (ioa_cfg->ipr_cmnd_list[i])
8314 pci_pool_free(ioa_cfg->ipr_cmd_pool,
8315 ioa_cfg->ipr_cmnd_list[i],
8316 ioa_cfg->ipr_cmnd_list_dma[i]);
8317
8318 ioa_cfg->ipr_cmnd_list[i] = NULL;
8319 }
8320
8321 if (ioa_cfg->ipr_cmd_pool)
8322 pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
8323
Brian King89aad422012-03-14 21:20:10 -05008324 kfree(ioa_cfg->ipr_cmnd_list);
8325 kfree(ioa_cfg->ipr_cmnd_list_dma);
8326 ioa_cfg->ipr_cmnd_list = NULL;
8327 ioa_cfg->ipr_cmnd_list_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008328 ioa_cfg->ipr_cmd_pool = NULL;
8329}
8330
8331/**
8332 * ipr_free_mem - Frees memory allocated for an adapter
8333 * @ioa_cfg: ioa cfg struct
8334 *
8335 * Return value:
8336 * nothing
8337 **/
8338static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
8339{
8340 int i;
8341
8342 kfree(ioa_cfg->res_entries);
8343 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
8344 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8345 ipr_free_cmd_blks(ioa_cfg);
8346 pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
8347 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008348 pci_free_consistent(ioa_cfg->pdev, ioa_cfg->cfg_table_size,
8349 ioa_cfg->u.cfg_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008350 ioa_cfg->cfg_table_dma);
8351
8352 for (i = 0; i < IPR_NUM_HCAMS; i++) {
8353 pci_free_consistent(ioa_cfg->pdev,
8354 sizeof(struct ipr_hostrcb),
8355 ioa_cfg->hostrcb[i],
8356 ioa_cfg->hostrcb_dma[i]);
8357 }
8358
8359 ipr_free_dump(ioa_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008360 kfree(ioa_cfg->trace);
8361}
8362
8363/**
8364 * ipr_free_all_resources - Free all allocated resources for an adapter.
8365 * @ipr_cmd: ipr command struct
8366 *
8367 * This function frees all allocated resources for the
8368 * specified adapter.
8369 *
8370 * Return value:
8371 * none
8372 **/
8373static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
8374{
8375 struct pci_dev *pdev = ioa_cfg->pdev;
8376
8377 ENTER;
8378 free_irq(pdev->irq, ioa_cfg);
Wayne Boyer5a9ef252009-01-23 09:17:35 -08008379 pci_disable_msi(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008380 iounmap(ioa_cfg->hdw_dma_regs);
8381 pci_release_regions(pdev);
8382 ipr_free_mem(ioa_cfg);
8383 scsi_host_put(ioa_cfg->host);
8384 pci_disable_device(pdev);
8385 LEAVE;
8386}
8387
8388/**
8389 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
8390 * @ioa_cfg: ioa config struct
8391 *
8392 * Return value:
8393 * 0 on success / -ENOMEM on allocation failure
8394 **/
8395static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8396{
8397 struct ipr_cmnd *ipr_cmd;
8398 struct ipr_ioarcb *ioarcb;
8399 dma_addr_t dma_addr;
8400 int i;
8401
8402 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
Brian King1bfff2f2012-03-14 21:20:12 -05008403 sizeof(struct ipr_cmnd), 512, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008404
8405 if (!ioa_cfg->ipr_cmd_pool)
8406 return -ENOMEM;
8407
Brian King89aad422012-03-14 21:20:10 -05008408 ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
8409 ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
8410
8411 if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
8412 ipr_free_cmd_blks(ioa_cfg);
8413 return -ENOMEM;
8414 }
8415
Linus Torvalds1da177e2005-04-16 15:20:36 -07008416 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
Christoph Lametere94b1762006-12-06 20:33:17 -08008417 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008418
8419 if (!ipr_cmd) {
8420 ipr_free_cmd_blks(ioa_cfg);
8421 return -ENOMEM;
8422 }
8423
8424 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
8425 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
8426 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
8427
8428 ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08008429 ipr_cmd->dma_addr = dma_addr;
8430 if (ioa_cfg->sis64)
8431 ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
8432 else
8433 ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
8434
Linus Torvalds1da177e2005-04-16 15:20:36 -07008435 ioarcb->host_response_handle = cpu_to_be32(i << 2);
Wayne Boyera32c0552010-02-19 13:23:36 -08008436 if (ioa_cfg->sis64) {
8437 ioarcb->u.sis64_addr_data.data_ioadl_addr =
8438 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
8439 ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
Wayne Boyer96d21f02010-05-10 09:13:27 -07008440 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
Wayne Boyera32c0552010-02-19 13:23:36 -08008441 } else {
8442 ioarcb->write_ioadl_addr =
8443 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
8444 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
8445 ioarcb->ioasa_host_pci_addr =
Wayne Boyer96d21f02010-05-10 09:13:27 -07008446 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
Wayne Boyera32c0552010-02-19 13:23:36 -08008447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008448 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
8449 ipr_cmd->cmd_index = i;
8450 ipr_cmd->ioa_cfg = ioa_cfg;
8451 ipr_cmd->sense_buffer_dma = dma_addr +
8452 offsetof(struct ipr_cmnd, sense_buffer);
8453
8454 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
8455 }
8456
8457 return 0;
8458}
8459
8460/**
8461 * ipr_alloc_mem - Allocate memory for an adapter
8462 * @ioa_cfg: ioa config struct
8463 *
8464 * Return value:
8465 * 0 on success / non-zero for error
8466 **/
8467static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
8468{
8469 struct pci_dev *pdev = ioa_cfg->pdev;
8470 int i, rc = -ENOMEM;
8471
8472 ENTER;
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06008473 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008474 ioa_cfg->max_devs_supported, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008475
8476 if (!ioa_cfg->res_entries)
8477 goto out;
8478
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008479 if (ioa_cfg->sis64) {
8480 ioa_cfg->target_ids = kzalloc(sizeof(unsigned long) *
8481 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8482 ioa_cfg->array_ids = kzalloc(sizeof(unsigned long) *
8483 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8484 ioa_cfg->vset_ids = kzalloc(sizeof(unsigned long) *
8485 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8486 }
8487
8488 for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008489 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008490 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
8491 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008492
8493 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
8494 sizeof(struct ipr_misc_cbs),
8495 &ioa_cfg->vpd_cbs_dma);
8496
8497 if (!ioa_cfg->vpd_cbs)
8498 goto out_free_res_entries;
8499
8500 if (ipr_alloc_cmd_blks(ioa_cfg))
8501 goto out_free_vpd_cbs;
8502
8503 ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
8504 sizeof(u32) * IPR_NUM_CMD_BLKS,
8505 &ioa_cfg->host_rrq_dma);
8506
8507 if (!ioa_cfg->host_rrq)
8508 goto out_ipr_free_cmd_blocks;
8509
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008510 ioa_cfg->u.cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
8511 ioa_cfg->cfg_table_size,
8512 &ioa_cfg->cfg_table_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008513
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008514 if (!ioa_cfg->u.cfg_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008515 goto out_free_host_rrq;
8516
8517 for (i = 0; i < IPR_NUM_HCAMS; i++) {
8518 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
8519 sizeof(struct ipr_hostrcb),
8520 &ioa_cfg->hostrcb_dma[i]);
8521
8522 if (!ioa_cfg->hostrcb[i])
8523 goto out_free_hostrcb_dma;
8524
8525 ioa_cfg->hostrcb[i]->hostrcb_dma =
8526 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
Brian King49dc6a12006-11-21 10:28:35 -06008527 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008528 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
8529 }
8530
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06008531 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008532 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
8533
8534 if (!ioa_cfg->trace)
8535 goto out_free_hostrcb_dma;
8536
Linus Torvalds1da177e2005-04-16 15:20:36 -07008537 rc = 0;
8538out:
8539 LEAVE;
8540 return rc;
8541
8542out_free_hostrcb_dma:
8543 while (i-- > 0) {
8544 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
8545 ioa_cfg->hostrcb[i],
8546 ioa_cfg->hostrcb_dma[i]);
8547 }
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008548 pci_free_consistent(pdev, ioa_cfg->cfg_table_size,
8549 ioa_cfg->u.cfg_table,
8550 ioa_cfg->cfg_table_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008551out_free_host_rrq:
8552 pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
8553 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
8554out_ipr_free_cmd_blocks:
8555 ipr_free_cmd_blks(ioa_cfg);
8556out_free_vpd_cbs:
8557 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
8558 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8559out_free_res_entries:
8560 kfree(ioa_cfg->res_entries);
8561 goto out;
8562}
8563
8564/**
8565 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
8566 * @ioa_cfg: ioa config struct
8567 *
8568 * Return value:
8569 * none
8570 **/
8571static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
8572{
8573 int i;
8574
8575 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
8576 ioa_cfg->bus_attr[i].bus = i;
8577 ioa_cfg->bus_attr[i].qas_enabled = 0;
8578 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
8579 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
8580 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
8581 else
8582 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
8583 }
8584}
8585
8586/**
8587 * ipr_init_ioa_cfg - Initialize IOA config struct
8588 * @ioa_cfg: ioa config struct
8589 * @host: scsi host struct
8590 * @pdev: PCI dev struct
8591 *
8592 * Return value:
8593 * none
8594 **/
8595static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
8596 struct Scsi_Host *host, struct pci_dev *pdev)
8597{
8598 const struct ipr_interrupt_offsets *p;
8599 struct ipr_interrupts *t;
8600 void __iomem *base;
8601
8602 ioa_cfg->host = host;
8603 ioa_cfg->pdev = pdev;
8604 ioa_cfg->log_level = ipr_log_level;
brking@us.ibm.com3d1d0da2005-11-01 17:01:54 -06008605 ioa_cfg->doorbell = IPR_DOORBELL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008606 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
8607 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
8608 sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
8609 sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
8610 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
8611 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
8612 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
8613 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
8614
8615 INIT_LIST_HEAD(&ioa_cfg->free_q);
8616 INIT_LIST_HEAD(&ioa_cfg->pending_q);
8617 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
8618 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
8619 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
8620 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
David Howellsc4028952006-11-22 14:57:56 +00008621 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008622 init_waitqueue_head(&ioa_cfg->reset_wait_q);
Wayne Boyer95fecd92009-06-16 15:13:28 -07008623 init_waitqueue_head(&ioa_cfg->msi_wait_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008624 ioa_cfg->sdt_state = INACTIVE;
8625
8626 ipr_initialize_bus_attr(ioa_cfg);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008627 ioa_cfg->max_devs_supported = ipr_max_devs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008628
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008629 if (ioa_cfg->sis64) {
8630 host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
8631 host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
8632 if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
8633 ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
8634 } else {
8635 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
8636 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
8637 if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
8638 ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
8639 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008640 host->max_channel = IPR_MAX_BUS_TO_SCAN;
8641 host->unique_id = host->host_no;
8642 host->max_cmd_len = IPR_MAX_CDB_LEN;
Brian King89aad422012-03-14 21:20:10 -05008643 host->can_queue = ioa_cfg->max_cmds;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008644 pci_set_drvdata(pdev, ioa_cfg);
8645
8646 p = &ioa_cfg->chip_cfg->regs;
8647 t = &ioa_cfg->regs;
8648 base = ioa_cfg->hdw_dma_regs;
8649
8650 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
8651 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008652 t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008653 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008654 t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008655 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008656 t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008657 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008658 t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008659 t->ioarrin_reg = base + p->ioarrin_reg;
8660 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008661 t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008662 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008663 t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008664 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008665 t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
Wayne Boyerdcbad002010-02-19 13:24:14 -08008666
8667 if (ioa_cfg->sis64) {
Wayne Boyer214777b2010-02-19 13:24:26 -08008668 t->init_feedback_reg = base + p->init_feedback_reg;
Wayne Boyerdcbad002010-02-19 13:24:14 -08008669 t->dump_addr_reg = base + p->dump_addr_reg;
8670 t->dump_data_reg = base + p->dump_data_reg;
Wayne Boyer8701f182010-06-04 10:26:50 -07008671 t->endian_swap_reg = base + p->endian_swap_reg;
Wayne Boyerdcbad002010-02-19 13:24:14 -08008672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008673}
8674
8675/**
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008676 * ipr_get_chip_info - Find adapter chip information
Linus Torvalds1da177e2005-04-16 15:20:36 -07008677 * @dev_id: PCI device id struct
8678 *
8679 * Return value:
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008680 * ptr to chip information on success / NULL on failure
Linus Torvalds1da177e2005-04-16 15:20:36 -07008681 **/
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008682static const struct ipr_chip_t * __devinit
8683ipr_get_chip_info(const struct pci_device_id *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008684{
8685 int i;
8686
Linus Torvalds1da177e2005-04-16 15:20:36 -07008687 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
8688 if (ipr_chip[i].vendor == dev_id->vendor &&
8689 ipr_chip[i].device == dev_id->device)
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008690 return &ipr_chip[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07008691 return NULL;
8692}
8693
8694/**
Wayne Boyer95fecd92009-06-16 15:13:28 -07008695 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
8696 * @pdev: PCI device struct
8697 *
8698 * Description: Simply set the msi_received flag to 1 indicating that
8699 * Message Signaled Interrupts are supported.
8700 *
8701 * Return value:
8702 * 0 on success / non-zero on failure
8703 **/
8704static irqreturn_t __devinit ipr_test_intr(int irq, void *devp)
8705{
8706 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
8707 unsigned long lock_flags = 0;
8708 irqreturn_t rc = IRQ_HANDLED;
8709
8710 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8711
8712 ioa_cfg->msi_received = 1;
8713 wake_up(&ioa_cfg->msi_wait_q);
8714
8715 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8716 return rc;
8717}
8718
8719/**
8720 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
8721 * @pdev: PCI device struct
8722 *
8723 * Description: The return value from pci_enable_msi() can not always be
8724 * trusted. This routine sets up and initiates a test interrupt to determine
8725 * if the interrupt is received via the ipr_test_intr() service routine.
8726 * If the tests fails, the driver will fall back to LSI.
8727 *
8728 * Return value:
8729 * 0 on success / non-zero on failure
8730 **/
8731static int __devinit ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg,
8732 struct pci_dev *pdev)
8733{
8734 int rc;
8735 volatile u32 int_reg;
8736 unsigned long lock_flags = 0;
8737
8738 ENTER;
8739
8740 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8741 init_waitqueue_head(&ioa_cfg->msi_wait_q);
8742 ioa_cfg->msi_received = 0;
8743 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
Wayne Boyer214777b2010-02-19 13:24:26 -08008744 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
Wayne Boyer95fecd92009-06-16 15:13:28 -07008745 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8746 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8747
8748 rc = request_irq(pdev->irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
8749 if (rc) {
8750 dev_err(&pdev->dev, "Can not assign irq %d\n", pdev->irq);
8751 return rc;
8752 } else if (ipr_debug)
8753 dev_info(&pdev->dev, "IRQ assigned: %d\n", pdev->irq);
8754
Wayne Boyer214777b2010-02-19 13:24:26 -08008755 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
Wayne Boyer95fecd92009-06-16 15:13:28 -07008756 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
8757 wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
8758 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
8759
8760 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8761 if (!ioa_cfg->msi_received) {
8762 /* MSI test failed */
8763 dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
8764 rc = -EOPNOTSUPP;
8765 } else if (ipr_debug)
8766 dev_info(&pdev->dev, "MSI test succeeded.\n");
8767
8768 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8769
8770 free_irq(pdev->irq, ioa_cfg);
8771
8772 LEAVE;
8773
8774 return rc;
8775}
8776
8777/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008778 * ipr_probe_ioa - Allocates memory and does first stage of initialization
8779 * @pdev: PCI device struct
8780 * @dev_id: PCI device id struct
8781 *
8782 * Return value:
8783 * 0 on success / non-zero on failure
8784 **/
8785static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
8786 const struct pci_device_id *dev_id)
8787{
8788 struct ipr_ioa_cfg *ioa_cfg;
8789 struct Scsi_Host *host;
8790 unsigned long ipr_regs_pci;
8791 void __iomem *ipr_regs;
Eric Sesterhenna2a65a32006-09-25 16:59:07 -07008792 int rc = PCIBIOS_SUCCESSFUL;
Brian King473b1e82007-05-02 10:44:11 -05008793 volatile u32 mask, uproc, interrupts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008794
8795 ENTER;
8796
8797 if ((rc = pci_enable_device(pdev))) {
8798 dev_err(&pdev->dev, "Cannot enable adapter\n");
8799 goto out;
8800 }
8801
8802 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
8803
8804 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
8805
8806 if (!host) {
8807 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
8808 rc = -ENOMEM;
8809 goto out_disable;
8810 }
8811
8812 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
8813 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
Dan Williams8d8e7d132012-07-09 21:06:08 -07008814 ata_host_init(&ioa_cfg->ata_host, &pdev->dev, &ipr_sata_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008815
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008816 ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008817
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008818 if (!ioa_cfg->ipr_chip) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008819 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
8820 dev_id->vendor, dev_id->device);
8821 goto out_scsi_host_put;
8822 }
8823
Wayne Boyera32c0552010-02-19 13:23:36 -08008824 /* set SIS 32 or SIS 64 */
8825 ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008826 ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
Brian King7dd21302012-03-14 21:20:08 -05008827 ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
Brian King89aad422012-03-14 21:20:10 -05008828 ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008829
Brian King5469cb52007-03-29 12:42:40 -05008830 if (ipr_transop_timeout)
8831 ioa_cfg->transop_timeout = ipr_transop_timeout;
8832 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
8833 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
8834 else
8835 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
8836
Auke Kok44c10132007-06-08 15:46:36 -07008837 ioa_cfg->revid = pdev->revision;
Brian King463fc692007-05-07 17:09:05 -05008838
Linus Torvalds1da177e2005-04-16 15:20:36 -07008839 ipr_regs_pci = pci_resource_start(pdev, 0);
8840
8841 rc = pci_request_regions(pdev, IPR_NAME);
8842 if (rc < 0) {
8843 dev_err(&pdev->dev,
8844 "Couldn't register memory range of registers\n");
8845 goto out_scsi_host_put;
8846 }
8847
Arjan van de Ven25729a72008-09-28 16:18:02 -07008848 ipr_regs = pci_ioremap_bar(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008849
8850 if (!ipr_regs) {
8851 dev_err(&pdev->dev,
8852 "Couldn't map memory range of registers\n");
8853 rc = -ENOMEM;
8854 goto out_release_regions;
8855 }
8856
8857 ioa_cfg->hdw_dma_regs = ipr_regs;
8858 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
8859 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
8860
8861 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
8862
8863 pci_set_master(pdev);
8864
Wayne Boyera32c0552010-02-19 13:23:36 -08008865 if (ioa_cfg->sis64) {
8866 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
8867 if (rc < 0) {
8868 dev_dbg(&pdev->dev, "Failed to set 64 bit PCI DMA mask\n");
8869 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
8870 }
8871
8872 } else
8873 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
8874
Linus Torvalds1da177e2005-04-16 15:20:36 -07008875 if (rc < 0) {
8876 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
8877 goto cleanup_nomem;
8878 }
8879
8880 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
8881 ioa_cfg->chip_cfg->cache_line_size);
8882
8883 if (rc != PCIBIOS_SUCCESSFUL) {
8884 dev_err(&pdev->dev, "Write of cache line size failed\n");
8885 rc = -EIO;
8886 goto cleanup_nomem;
8887 }
8888
Wayne Boyer95fecd92009-06-16 15:13:28 -07008889 /* Enable MSI style interrupts if they are supported. */
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008890 if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI && !pci_enable_msi(pdev)) {
Wayne Boyer95fecd92009-06-16 15:13:28 -07008891 rc = ipr_test_msi(ioa_cfg, pdev);
8892 if (rc == -EOPNOTSUPP)
8893 pci_disable_msi(pdev);
8894 else if (rc)
8895 goto out_msi_disable;
8896 else
8897 dev_info(&pdev->dev, "MSI enabled with IRQ: %d\n", pdev->irq);
8898 } else if (ipr_debug)
8899 dev_info(&pdev->dev, "Cannot enable MSI.\n");
8900
Linus Torvalds1da177e2005-04-16 15:20:36 -07008901 /* Save away PCI config space for use following IOA reset */
8902 rc = pci_save_state(pdev);
8903
8904 if (rc != PCIBIOS_SUCCESSFUL) {
8905 dev_err(&pdev->dev, "Failed to save PCI config space\n");
8906 rc = -EIO;
Julia Lawallf170c682011-07-11 14:08:25 -07008907 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008908 }
8909
8910 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
Julia Lawallf170c682011-07-11 14:08:25 -07008911 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008912
8913 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
Julia Lawallf170c682011-07-11 14:08:25 -07008914 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008915
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008916 if (ioa_cfg->sis64)
8917 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
8918 + ((sizeof(struct ipr_config_table_entry64)
8919 * ioa_cfg->max_devs_supported)));
8920 else
8921 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
8922 + ((sizeof(struct ipr_config_table_entry)
8923 * ioa_cfg->max_devs_supported)));
8924
Linus Torvalds1da177e2005-04-16 15:20:36 -07008925 rc = ipr_alloc_mem(ioa_cfg);
8926 if (rc < 0) {
8927 dev_err(&pdev->dev,
8928 "Couldn't allocate enough memory for device driver!\n");
Julia Lawallf170c682011-07-11 14:08:25 -07008929 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008930 }
8931
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06008932 /*
8933 * If HRRQ updated interrupt is not masked, or reset alert is set,
8934 * the card is in an unknown state and needs a hard reset
8935 */
Wayne Boyer214777b2010-02-19 13:24:26 -08008936 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
8937 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
8938 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06008939 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
8940 ioa_cfg->needs_hard_reset = 1;
Anton Blanchard5d7c20b2011-08-01 19:43:45 +10008941 if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
Brian King473b1e82007-05-02 10:44:11 -05008942 ioa_cfg->needs_hard_reset = 1;
8943 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
8944 ioa_cfg->ioa_unit_checked = 1;
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06008945
Linus Torvalds1da177e2005-04-16 15:20:36 -07008946 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
Wayne Boyer95fecd92009-06-16 15:13:28 -07008947 rc = request_irq(pdev->irq, ipr_isr,
8948 ioa_cfg->msi_received ? 0 : IRQF_SHARED,
8949 IPR_NAME, ioa_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008950
8951 if (rc) {
8952 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
8953 pdev->irq, rc);
8954 goto cleanup_nolog;
8955 }
8956
Brian King463fc692007-05-07 17:09:05 -05008957 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
8958 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
8959 ioa_cfg->needs_warm_reset = 1;
8960 ioa_cfg->reset = ipr_reset_slot_reset;
8961 } else
8962 ioa_cfg->reset = ipr_reset_start_bist;
8963
Linus Torvalds1da177e2005-04-16 15:20:36 -07008964 spin_lock(&ipr_driver_lock);
8965 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
8966 spin_unlock(&ipr_driver_lock);
8967
8968 LEAVE;
8969out:
8970 return rc;
8971
8972cleanup_nolog:
8973 ipr_free_mem(ioa_cfg);
Wayne Boyer95fecd92009-06-16 15:13:28 -07008974out_msi_disable:
8975 pci_disable_msi(pdev);
Julia Lawallf170c682011-07-11 14:08:25 -07008976cleanup_nomem:
8977 iounmap(ipr_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008978out_release_regions:
8979 pci_release_regions(pdev);
8980out_scsi_host_put:
8981 scsi_host_put(host);
8982out_disable:
8983 pci_disable_device(pdev);
8984 goto out;
8985}
8986
8987/**
8988 * ipr_scan_vsets - Scans for VSET devices
8989 * @ioa_cfg: ioa config struct
8990 *
8991 * Description: Since the VSET resources do not follow SAM in that we can have
8992 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
8993 *
8994 * Return value:
8995 * none
8996 **/
8997static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
8998{
8999 int target, lun;
9000
9001 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
9002 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
9003 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
9004}
9005
9006/**
9007 * ipr_initiate_ioa_bringdown - Bring down an adapter
9008 * @ioa_cfg: ioa config struct
9009 * @shutdown_type: shutdown type
9010 *
9011 * Description: This function will initiate bringing down the adapter.
9012 * This consists of issuing an IOA shutdown to the adapter
9013 * to flush the cache, and running BIST.
9014 * If the caller needs to wait on the completion of the reset,
9015 * the caller must sleep on the reset_wait_q.
9016 *
9017 * Return value:
9018 * none
9019 **/
9020static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
9021 enum ipr_shutdown_type shutdown_type)
9022{
9023 ENTER;
9024 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
9025 ioa_cfg->sdt_state = ABORT_DUMP;
9026 ioa_cfg->reset_retries = 0;
9027 ioa_cfg->in_ioa_bringdown = 1;
9028 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
9029 LEAVE;
9030}
9031
9032/**
9033 * __ipr_remove - Remove a single adapter
9034 * @pdev: pci device struct
9035 *
9036 * Adapter hot plug remove entry point.
9037 *
9038 * Return value:
9039 * none
9040 **/
9041static void __ipr_remove(struct pci_dev *pdev)
9042{
9043 unsigned long host_lock_flags = 0;
9044 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9045 ENTER;
9046
9047 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
Brian King970ea292007-04-26 16:00:06 -05009048 while(ioa_cfg->in_reset_reload) {
9049 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9050 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9051 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9052 }
9053
Linus Torvalds1da177e2005-04-16 15:20:36 -07009054 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9055
9056 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9057 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
Tejun Heoa684b8d2011-01-24 14:57:28 +01009058 flush_work_sync(&ioa_cfg->work_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009059 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9060
9061 spin_lock(&ipr_driver_lock);
9062 list_del(&ioa_cfg->queue);
9063 spin_unlock(&ipr_driver_lock);
9064
9065 if (ioa_cfg->sdt_state == ABORT_DUMP)
9066 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
9067 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9068
9069 ipr_free_all_resources(ioa_cfg);
9070
9071 LEAVE;
9072}
9073
9074/**
9075 * ipr_remove - IOA hot plug remove entry point
9076 * @pdev: pci device struct
9077 *
9078 * Adapter hot plug remove entry point.
9079 *
9080 * Return value:
9081 * none
9082 **/
Kleber S. Souzaf3816422009-04-22 10:50:28 -03009083static void __devexit ipr_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009084{
9085 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9086
9087 ENTER;
9088
Tony Jonesee959b02008-02-22 00:13:36 +01009089 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009090 &ipr_trace_attr);
Tony Jonesee959b02008-02-22 00:13:36 +01009091 ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009092 &ipr_dump_attr);
9093 scsi_remove_host(ioa_cfg->host);
9094
9095 __ipr_remove(pdev);
9096
9097 LEAVE;
9098}
9099
9100/**
9101 * ipr_probe - Adapter hot plug add entry point
9102 *
9103 * Return value:
9104 * 0 on success / non-zero on failure
9105 **/
9106static int __devinit ipr_probe(struct pci_dev *pdev,
9107 const struct pci_device_id *dev_id)
9108{
9109 struct ipr_ioa_cfg *ioa_cfg;
9110 int rc;
9111
9112 rc = ipr_probe_ioa(pdev, dev_id);
9113
9114 if (rc)
9115 return rc;
9116
9117 ioa_cfg = pci_get_drvdata(pdev);
9118 rc = ipr_probe_ioa_part2(ioa_cfg);
9119
9120 if (rc) {
9121 __ipr_remove(pdev);
9122 return rc;
9123 }
9124
9125 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
9126
9127 if (rc) {
9128 __ipr_remove(pdev);
9129 return rc;
9130 }
9131
Tony Jonesee959b02008-02-22 00:13:36 +01009132 rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009133 &ipr_trace_attr);
9134
9135 if (rc) {
9136 scsi_remove_host(ioa_cfg->host);
9137 __ipr_remove(pdev);
9138 return rc;
9139 }
9140
Tony Jonesee959b02008-02-22 00:13:36 +01009141 rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009142 &ipr_dump_attr);
9143
9144 if (rc) {
Tony Jonesee959b02008-02-22 00:13:36 +01009145 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009146 &ipr_trace_attr);
9147 scsi_remove_host(ioa_cfg->host);
9148 __ipr_remove(pdev);
9149 return rc;
9150 }
9151
9152 scsi_scan_host(ioa_cfg->host);
9153 ipr_scan_vsets(ioa_cfg);
9154 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
9155 ioa_cfg->allow_ml_add_del = 1;
brking@us.ibm.com11cd8f12005-11-01 17:00:11 -06009156 ioa_cfg->host->max_channel = IPR_VSET_BUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009157 schedule_work(&ioa_cfg->work_q);
9158 return 0;
9159}
9160
9161/**
9162 * ipr_shutdown - Shutdown handler.
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07009163 * @pdev: pci device struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07009164 *
9165 * This function is invoked upon system shutdown/reboot. It will issue
9166 * an adapter shutdown to the adapter to flush the write cache.
9167 *
9168 * Return value:
9169 * none
9170 **/
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07009171static void ipr_shutdown(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009172{
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07009173 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009174 unsigned long lock_flags = 0;
9175
9176 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King970ea292007-04-26 16:00:06 -05009177 while(ioa_cfg->in_reset_reload) {
9178 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9179 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9180 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9181 }
9182
Linus Torvalds1da177e2005-04-16 15:20:36 -07009183 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9184 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9185 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9186}
9187
9188static struct pci_device_id ipr_pci_table[] __devinitdata = {
9189 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -06009190 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009191 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -06009192 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009193 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -06009194 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009195 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -06009196 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009197 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -06009198 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009199 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -06009200 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009201 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -06009202 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009203 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King5469cb52007-03-29 12:42:40 -05009204 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
9205 IPR_USE_LONG_TRANSOP_TIMEOUT },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009206 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King6d84c942007-01-23 11:25:23 -06009207 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009208 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King22d2e402007-04-26 16:00:13 -05009209 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
9210 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -06009211 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King5469cb52007-03-29 12:42:40 -05009212 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
9213 IPR_USE_LONG_TRANSOP_TIMEOUT },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009214 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King6d84c942007-01-23 11:25:23 -06009215 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009216 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King22d2e402007-04-26 16:00:13 -05009217 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
9218 IPR_USE_LONG_TRANSOP_TIMEOUT},
Brian King60e74862006-11-21 10:28:10 -06009219 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King5469cb52007-03-29 12:42:40 -05009220 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
9221 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -06009222 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King22d2e402007-04-26 16:00:13 -05009223 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
9224 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King185eb312007-03-29 12:42:53 -05009225 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King185eb312007-03-29 12:42:53 -05009226 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
9227 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Wayne Boyerb0f56d32010-06-24 13:34:14 -07009228 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
9229 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King5469cb52007-03-29 12:42:40 -05009230 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
Brian King463fc692007-05-07 17:09:05 -05009231 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009232 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
Brian King6d84c942007-01-23 11:25:23 -06009233 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009234 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King6d84c942007-01-23 11:25:23 -06009235 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009236 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King5469cb52007-03-29 12:42:40 -05009237 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
9238 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -06009239 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King5469cb52007-03-29 12:42:40 -05009240 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
9241 IPR_USE_LONG_TRANSOP_TIMEOUT },
Wayne Boyerd7b46272010-02-19 13:24:38 -08009242 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9243 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
9244 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9245 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
9246 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9247 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
Wayne Boyer32622bd2010-10-18 20:24:34 -07009248 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
Wayne Boyer5a918352011-10-27 11:58:21 -07009249 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
9250 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
Wayne Boyer32622bd2010-10-18 20:24:34 -07009251 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -08009252 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -08009253 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -08009254 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -08009255 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -08009256 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -08009257 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -08009258 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9259 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
9260 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -08009261 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009262 { }
9263};
9264MODULE_DEVICE_TABLE(pci, ipr_pci_table);
9265
Linas Vepstasf8a88b192006-02-03 16:52:42 -06009266static struct pci_error_handlers ipr_err_handler = {
9267 .error_detected = ipr_pci_error_detected,
9268 .slot_reset = ipr_pci_slot_reset,
9269};
9270
Linus Torvalds1da177e2005-04-16 15:20:36 -07009271static struct pci_driver ipr_driver = {
9272 .name = IPR_NAME,
9273 .id_table = ipr_pci_table,
9274 .probe = ipr_probe,
Kleber S. Souzaf3816422009-04-22 10:50:28 -03009275 .remove = __devexit_p(ipr_remove),
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07009276 .shutdown = ipr_shutdown,
Linas Vepstasf8a88b192006-02-03 16:52:42 -06009277 .err_handler = &ipr_err_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009278};
9279
9280/**
Wayne Boyerf72919e2010-02-19 13:24:21 -08009281 * ipr_halt_done - Shutdown prepare completion
9282 *
9283 * Return value:
9284 * none
9285 **/
9286static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
9287{
9288 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
9289
9290 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
9291}
9292
9293/**
9294 * ipr_halt - Issue shutdown prepare to all adapters
9295 *
9296 * Return value:
9297 * NOTIFY_OK on success / NOTIFY_DONE on failure
9298 **/
9299static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
9300{
9301 struct ipr_cmnd *ipr_cmd;
9302 struct ipr_ioa_cfg *ioa_cfg;
9303 unsigned long flags = 0;
9304
9305 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
9306 return NOTIFY_DONE;
9307
9308 spin_lock(&ipr_driver_lock);
9309
9310 list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
9311 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
9312 if (!ioa_cfg->allow_cmds) {
9313 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
9314 continue;
9315 }
9316
9317 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
9318 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
9319 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
9320 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
9321 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
9322
9323 ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
9324 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
9325 }
9326 spin_unlock(&ipr_driver_lock);
9327
9328 return NOTIFY_OK;
9329}
9330
9331static struct notifier_block ipr_notifier = {
9332 ipr_halt, NULL, 0
9333};
9334
9335/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07009336 * ipr_init - Module entry point
9337 *
9338 * Return value:
9339 * 0 on success / negative value on failure
9340 **/
9341static int __init ipr_init(void)
9342{
9343 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
9344 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
9345
Wayne Boyerf72919e2010-02-19 13:24:21 -08009346 register_reboot_notifier(&ipr_notifier);
Henrik Kretzschmardcbccbde2006-09-25 16:58:58 -07009347 return pci_register_driver(&ipr_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009348}
9349
9350/**
9351 * ipr_exit - Module unload
9352 *
9353 * Module unload entry point.
9354 *
9355 * Return value:
9356 * none
9357 **/
9358static void __exit ipr_exit(void)
9359{
Wayne Boyerf72919e2010-02-19 13:24:21 -08009360 unregister_reboot_notifier(&ipr_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009361 pci_unregister_driver(&ipr_driver);
9362}
9363
9364module_init(ipr_init);
9365module_exit(ipr_exit);