blob: 7a5ccb2c15657b4bcbc8fe6bede90781e3ca1a49 [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/**
Brian King172cd6e2012-07-17 08:14:40 -0500569 * ipr_lock_and_done - Acquire lock and complete command
570 * @ipr_cmd: ipr command struct
571 *
572 * Return value:
573 * none
574 **/
575static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
576{
577 unsigned long lock_flags;
578 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
579
580 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
581 ipr_cmd->done(ipr_cmd);
582 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
583}
584
585/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
587 * @ipr_cmd: ipr command struct
588 *
589 * Return value:
590 * none
591 **/
592static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
593{
594 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -0700595 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
596 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
Wayne Boyera32c0552010-02-19 13:23:36 -0800597 dma_addr_t dma_addr = ipr_cmd->dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
Wayne Boyera32c0552010-02-19 13:23:36 -0800600 ioarcb->data_transfer_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 ioarcb->read_data_transfer_length = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -0800602 ioarcb->ioadl_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 ioarcb->read_ioadl_len = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -0800604
Wayne Boyer96d21f02010-05-10 09:13:27 -0700605 if (ipr_cmd->ioa_cfg->sis64) {
Wayne Boyera32c0552010-02-19 13:23:36 -0800606 ioarcb->u.sis64_addr_data.data_ioadl_addr =
607 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
Wayne Boyer96d21f02010-05-10 09:13:27 -0700608 ioasa64->u.gata.status = 0;
609 } else {
Wayne Boyera32c0552010-02-19 13:23:36 -0800610 ioarcb->write_ioadl_addr =
611 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
612 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
Wayne Boyer96d21f02010-05-10 09:13:27 -0700613 ioasa->u.gata.status = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -0800614 }
615
Wayne Boyer96d21f02010-05-10 09:13:27 -0700616 ioasa->hdr.ioasc = 0;
617 ioasa->hdr.residual_data_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 ipr_cmd->scsi_cmd = NULL;
Brian King35a39692006-09-25 12:39:20 -0500619 ipr_cmd->qc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 ipr_cmd->sense_buffer[0] = 0;
621 ipr_cmd->dma_use_sg = 0;
622}
623
624/**
625 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
626 * @ipr_cmd: ipr command struct
627 *
628 * Return value:
629 * none
630 **/
Brian King172cd6e2012-07-17 08:14:40 -0500631static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
632 void (*fast_done) (struct ipr_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
634 ipr_reinit_ipr_cmnd(ipr_cmd);
635 ipr_cmd->u.scratch = 0;
636 ipr_cmd->sibling = NULL;
Brian King172cd6e2012-07-17 08:14:40 -0500637 ipr_cmd->fast_done = fast_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 init_timer(&ipr_cmd->timer);
639}
640
641/**
Brian King00bfef22012-07-17 08:13:52 -0500642 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 * @ioa_cfg: ioa config struct
644 *
645 * Return value:
646 * pointer to ipr command struct
647 **/
648static
Brian King00bfef22012-07-17 08:13:52 -0500649struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650{
651 struct ipr_cmnd *ipr_cmd;
652
653 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
654 list_del(&ipr_cmd->queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656 return ipr_cmd;
657}
658
659/**
Brian King00bfef22012-07-17 08:13:52 -0500660 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
661 * @ioa_cfg: ioa config struct
662 *
663 * Return value:
664 * pointer to ipr command struct
665 **/
666static
667struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
668{
669 struct ipr_cmnd *ipr_cmd = __ipr_get_free_ipr_cmnd(ioa_cfg);
Brian King172cd6e2012-07-17 08:14:40 -0500670 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
Brian King00bfef22012-07-17 08:13:52 -0500671 return ipr_cmd;
672}
673
674/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
676 * @ioa_cfg: ioa config struct
677 * @clr_ints: interrupts to clear
678 *
679 * This function masks all interrupts on the adapter, then clears the
680 * interrupts specified in the mask
681 *
682 * Return value:
683 * none
684 **/
685static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
686 u32 clr_ints)
687{
688 volatile u32 int_reg;
689
690 /* Stop new interrupts */
691 ioa_cfg->allow_interrupts = 0;
692
693 /* Set interrupt mask to stop all new interrupts */
Wayne Boyer214777b2010-02-19 13:24:26 -0800694 if (ioa_cfg->sis64)
695 writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
696 else
697 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 /* Clear any pending interrupts */
Wayne Boyer214777b2010-02-19 13:24:26 -0800700 if (ioa_cfg->sis64)
701 writel(~0, ioa_cfg->regs.clr_interrupt_reg);
702 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
704}
705
706/**
707 * ipr_save_pcix_cmd_reg - Save PCI-X command register
708 * @ioa_cfg: ioa config struct
709 *
710 * Return value:
711 * 0 on success / -EIO on failure
712 **/
713static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
714{
715 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
716
Brian King7dce0e12007-01-23 11:25:30 -0600717 if (pcix_cmd_reg == 0)
718 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
721 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
722 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
723 return -EIO;
724 }
725
726 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
727 return 0;
728}
729
730/**
731 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
732 * @ioa_cfg: ioa config struct
733 *
734 * Return value:
735 * 0 on success / -EIO on failure
736 **/
737static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
738{
739 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
740
741 if (pcix_cmd_reg) {
742 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
743 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
744 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
745 return -EIO;
746 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 }
748
749 return 0;
750}
751
752/**
Brian King35a39692006-09-25 12:39:20 -0500753 * ipr_sata_eh_done - done function for aborted SATA commands
754 * @ipr_cmd: ipr command struct
755 *
756 * This function is invoked for ops generated to SATA
757 * devices which are being aborted.
758 *
759 * Return value:
760 * none
761 **/
762static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
763{
764 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
765 struct ata_queued_cmd *qc = ipr_cmd->qc;
766 struct ipr_sata_port *sata_port = qc->ap->private_data;
767
768 qc->err_mask |= AC_ERR_OTHER;
769 sata_port->ioasa.status |= ATA_BUSY;
770 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
771 ata_qc_complete(qc);
772}
773
774/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 * ipr_scsi_eh_done - mid-layer done function for aborted ops
776 * @ipr_cmd: ipr command struct
777 *
778 * This function is invoked by the interrupt handler for
779 * ops generated by the SCSI mid-layer which are being aborted.
780 *
781 * Return value:
782 * none
783 **/
784static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
785{
786 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
787 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
788
789 scsi_cmd->result |= (DID_ERROR << 16);
790
FUJITA Tomonori63015bc2007-05-26 00:26:59 +0900791 scsi_dma_unmap(ipr_cmd->scsi_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 scsi_cmd->scsi_done(scsi_cmd);
793 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
794}
795
796/**
797 * ipr_fail_all_ops - Fails all outstanding ops.
798 * @ioa_cfg: ioa config struct
799 *
800 * This function fails all outstanding ops.
801 *
802 * Return value:
803 * none
804 **/
805static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
806{
807 struct ipr_cmnd *ipr_cmd, *temp;
808
809 ENTER;
810 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
811 list_del(&ipr_cmd->queue);
812
Wayne Boyer96d21f02010-05-10 09:13:27 -0700813 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
814 ipr_cmd->s.ioasa.hdr.ilid = cpu_to_be32(IPR_DRIVER_ILID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816 if (ipr_cmd->scsi_cmd)
817 ipr_cmd->done = ipr_scsi_eh_done;
Brian King35a39692006-09-25 12:39:20 -0500818 else if (ipr_cmd->qc)
819 ipr_cmd->done = ipr_sata_eh_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
822 del_timer(&ipr_cmd->timer);
823 ipr_cmd->done(ipr_cmd);
824 }
825
826 LEAVE;
827}
828
829/**
Wayne Boyera32c0552010-02-19 13:23:36 -0800830 * ipr_send_command - Send driver initiated requests.
831 * @ipr_cmd: ipr command struct
832 *
833 * This function sends a command to the adapter using the correct write call.
834 * In the case of sis64, calculate the ioarcb size required. Then or in the
835 * appropriate bits.
836 *
837 * Return value:
838 * none
839 **/
840static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
841{
842 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
843 dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
844
845 if (ioa_cfg->sis64) {
846 /* The default size is 256 bytes */
847 send_dma_addr |= 0x1;
848
849 /* If the number of ioadls * size of ioadl > 128 bytes,
850 then use a 512 byte ioarcb */
851 if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
852 send_dma_addr |= 0x4;
853 writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
854 } else
855 writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
856}
857
858/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 * ipr_do_req - Send driver initiated requests.
860 * @ipr_cmd: ipr command struct
861 * @done: done function
862 * @timeout_func: timeout function
863 * @timeout: timeout value
864 *
865 * This function sends the specified command to the adapter with the
866 * timeout given. The done function is invoked on command completion.
867 *
868 * Return value:
869 * none
870 **/
871static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
872 void (*done) (struct ipr_cmnd *),
873 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
874{
875 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
876
877 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
878
879 ipr_cmd->done = done;
880
881 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
882 ipr_cmd->timer.expires = jiffies + timeout;
883 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
884
885 add_timer(&ipr_cmd->timer);
886
887 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
888
Wayne Boyera32c0552010-02-19 13:23:36 -0800889 ipr_send_command(ipr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890}
891
892/**
893 * ipr_internal_cmd_done - Op done function for an internally generated op.
894 * @ipr_cmd: ipr command struct
895 *
896 * This function is the op done function for an internally generated,
897 * blocking op. It simply wakes the sleeping thread.
898 *
899 * Return value:
900 * none
901 **/
902static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
903{
904 if (ipr_cmd->sibling)
905 ipr_cmd->sibling = NULL;
906 else
907 complete(&ipr_cmd->completion);
908}
909
910/**
Wayne Boyera32c0552010-02-19 13:23:36 -0800911 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
912 * @ipr_cmd: ipr command struct
913 * @dma_addr: dma address
914 * @len: transfer length
915 * @flags: ioadl flag value
916 *
917 * This function initializes an ioadl in the case where there is only a single
918 * descriptor.
919 *
920 * Return value:
921 * nothing
922 **/
923static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
924 u32 len, int flags)
925{
926 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
927 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
928
929 ipr_cmd->dma_use_sg = 1;
930
931 if (ipr_cmd->ioa_cfg->sis64) {
932 ioadl64->flags = cpu_to_be32(flags);
933 ioadl64->data_len = cpu_to_be32(len);
934 ioadl64->address = cpu_to_be64(dma_addr);
935
936 ipr_cmd->ioarcb.ioadl_len =
937 cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
938 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
939 } else {
940 ioadl->flags_and_data_len = cpu_to_be32(flags | len);
941 ioadl->address = cpu_to_be32(dma_addr);
942
943 if (flags == IPR_IOADL_FLAGS_READ_LAST) {
944 ipr_cmd->ioarcb.read_ioadl_len =
945 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
946 ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
947 } else {
948 ipr_cmd->ioarcb.ioadl_len =
949 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
950 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
951 }
952 }
953}
954
955/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 * ipr_send_blocking_cmd - Send command and sleep on its completion.
957 * @ipr_cmd: ipr command struct
958 * @timeout_func: function to invoke if command times out
959 * @timeout: timeout
960 *
961 * Return value:
962 * none
963 **/
964static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
965 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
966 u32 timeout)
967{
968 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
969
970 init_completion(&ipr_cmd->completion);
971 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
972
973 spin_unlock_irq(ioa_cfg->host->host_lock);
974 wait_for_completion(&ipr_cmd->completion);
975 spin_lock_irq(ioa_cfg->host->host_lock);
976}
977
978/**
979 * ipr_send_hcam - Send an HCAM to the adapter.
980 * @ioa_cfg: ioa config struct
981 * @type: HCAM type
982 * @hostrcb: hostrcb struct
983 *
984 * This function will send a Host Controlled Async command to the adapter.
985 * If HCAMs are currently not allowed to be issued to the adapter, it will
986 * place the hostrcb on the free queue.
987 *
988 * Return value:
989 * none
990 **/
991static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
992 struct ipr_hostrcb *hostrcb)
993{
994 struct ipr_cmnd *ipr_cmd;
995 struct ipr_ioarcb *ioarcb;
996
997 if (ioa_cfg->allow_cmds) {
998 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
999 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
1000 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
1001
1002 ipr_cmd->u.hostrcb = hostrcb;
1003 ioarcb = &ipr_cmd->ioarcb;
1004
1005 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
1006 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
1007 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
1008 ioarcb->cmd_pkt.cdb[1] = type;
1009 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
1010 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
1011
Wayne Boyera32c0552010-02-19 13:23:36 -08001012 ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
1013 sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
1016 ipr_cmd->done = ipr_process_ccn;
1017 else
1018 ipr_cmd->done = ipr_process_error;
1019
1020 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
1021
Wayne Boyera32c0552010-02-19 13:23:36 -08001022 ipr_send_command(ipr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 } else {
1024 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
1025 }
1026}
1027
1028/**
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001029 * ipr_update_ata_class - Update the ata class in the resource entry
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 * @res: resource entry struct
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001031 * @proto: cfgte device bus protocol value
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 *
1033 * Return value:
1034 * none
1035 **/
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001036static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037{
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001038 switch(proto) {
1039 case IPR_PROTO_SATA:
1040 case IPR_PROTO_SAS_STP:
1041 res->ata_class = ATA_DEV_ATA;
1042 break;
1043 case IPR_PROTO_SATA_ATAPI:
1044 case IPR_PROTO_SAS_STP_ATAPI:
1045 res->ata_class = ATA_DEV_ATAPI;
1046 break;
1047 default:
1048 res->ata_class = ATA_DEV_UNKNOWN;
1049 break;
1050 };
1051}
1052
1053/**
1054 * ipr_init_res_entry - Initialize a resource entry struct.
1055 * @res: resource entry struct
1056 * @cfgtew: config table entry wrapper struct
1057 *
1058 * Return value:
1059 * none
1060 **/
1061static void ipr_init_res_entry(struct ipr_resource_entry *res,
1062 struct ipr_config_table_entry_wrapper *cfgtew)
1063{
1064 int found = 0;
1065 unsigned int proto;
1066 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1067 struct ipr_resource_entry *gscsi_res = NULL;
1068
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06001069 res->needs_sync_complete = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 res->in_erp = 0;
1071 res->add_to_ml = 0;
1072 res->del_from_ml = 0;
1073 res->resetting_device = 0;
1074 res->sdev = NULL;
Brian King35a39692006-09-25 12:39:20 -05001075 res->sata_port = NULL;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001076
1077 if (ioa_cfg->sis64) {
1078 proto = cfgtew->u.cfgte64->proto;
1079 res->res_flags = cfgtew->u.cfgte64->res_flags;
1080 res->qmodel = IPR_QUEUEING_MODEL64(res);
Wayne Boyer438b0332010-05-10 09:13:00 -07001081 res->type = cfgtew->u.cfgte64->res_type;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001082
1083 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1084 sizeof(res->res_path));
1085
1086 res->bus = 0;
Wayne Boyer0cb992e2010-11-04 09:35:58 -07001087 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1088 sizeof(res->dev_lun.scsi_lun));
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001089 res->lun = scsilun_to_int(&res->dev_lun);
1090
1091 if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1092 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1093 if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1094 found = 1;
1095 res->target = gscsi_res->target;
1096 break;
1097 }
1098 }
1099 if (!found) {
1100 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1101 ioa_cfg->max_devs_supported);
1102 set_bit(res->target, ioa_cfg->target_ids);
1103 }
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001104 } else if (res->type == IPR_RES_TYPE_IOAFP) {
1105 res->bus = IPR_IOAFP_VIRTUAL_BUS;
1106 res->target = 0;
1107 } else if (res->type == IPR_RES_TYPE_ARRAY) {
1108 res->bus = IPR_ARRAY_VIRTUAL_BUS;
1109 res->target = find_first_zero_bit(ioa_cfg->array_ids,
1110 ioa_cfg->max_devs_supported);
1111 set_bit(res->target, ioa_cfg->array_ids);
1112 } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1113 res->bus = IPR_VSET_VIRTUAL_BUS;
1114 res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1115 ioa_cfg->max_devs_supported);
1116 set_bit(res->target, ioa_cfg->vset_ids);
1117 } else {
1118 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1119 ioa_cfg->max_devs_supported);
1120 set_bit(res->target, ioa_cfg->target_ids);
1121 }
1122 } else {
1123 proto = cfgtew->u.cfgte->proto;
1124 res->qmodel = IPR_QUEUEING_MODEL(res);
1125 res->flags = cfgtew->u.cfgte->flags;
1126 if (res->flags & IPR_IS_IOA_RESOURCE)
1127 res->type = IPR_RES_TYPE_IOAFP;
1128 else
1129 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1130
1131 res->bus = cfgtew->u.cfgte->res_addr.bus;
1132 res->target = cfgtew->u.cfgte->res_addr.target;
1133 res->lun = cfgtew->u.cfgte->res_addr.lun;
Wayne Boyer46d74562010-08-11 07:15:17 -07001134 res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001135 }
1136
1137 ipr_update_ata_class(res, proto);
1138}
1139
1140/**
1141 * ipr_is_same_device - Determine if two devices are the same.
1142 * @res: resource entry struct
1143 * @cfgtew: config table entry wrapper struct
1144 *
1145 * Return value:
1146 * 1 if the devices are the same / 0 otherwise
1147 **/
1148static int ipr_is_same_device(struct ipr_resource_entry *res,
1149 struct ipr_config_table_entry_wrapper *cfgtew)
1150{
1151 if (res->ioa_cfg->sis64) {
1152 if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1153 sizeof(cfgtew->u.cfgte64->dev_id)) &&
Wayne Boyer0cb992e2010-11-04 09:35:58 -07001154 !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001155 sizeof(cfgtew->u.cfgte64->lun))) {
1156 return 1;
1157 }
1158 } else {
1159 if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1160 res->target == cfgtew->u.cfgte->res_addr.target &&
1161 res->lun == cfgtew->u.cfgte->res_addr.lun)
1162 return 1;
1163 }
1164
1165 return 0;
1166}
1167
1168/**
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001169 * ipr_format_res_path - Format the resource path for printing.
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001170 * @res_path: resource path
1171 * @buf: buffer
1172 *
1173 * Return value:
1174 * pointer to buffer
1175 **/
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001176static char *ipr_format_res_path(u8 *res_path, char *buffer, int len)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001177{
1178 int i;
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001179 char *p = buffer;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001180
Wayne Boyer46d74562010-08-11 07:15:17 -07001181 *p = '\0';
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001182 p += snprintf(p, buffer + len - p, "%02X", res_path[0]);
1183 for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
1184 p += snprintf(p, buffer + len - p, "-%02X", res_path[i]);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001185
1186 return buffer;
1187}
1188
1189/**
1190 * ipr_update_res_entry - Update the resource entry.
1191 * @res: resource entry struct
1192 * @cfgtew: config table entry wrapper struct
1193 *
1194 * Return value:
1195 * none
1196 **/
1197static void ipr_update_res_entry(struct ipr_resource_entry *res,
1198 struct ipr_config_table_entry_wrapper *cfgtew)
1199{
1200 char buffer[IPR_MAX_RES_PATH_LENGTH];
1201 unsigned int proto;
1202 int new_path = 0;
1203
1204 if (res->ioa_cfg->sis64) {
1205 res->flags = cfgtew->u.cfgte64->flags;
1206 res->res_flags = cfgtew->u.cfgte64->res_flags;
Wayne Boyer75576bb2010-07-14 10:50:14 -07001207 res->type = cfgtew->u.cfgte64->res_type;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001208
1209 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1210 sizeof(struct ipr_std_inq_data));
1211
1212 res->qmodel = IPR_QUEUEING_MODEL64(res);
1213 proto = cfgtew->u.cfgte64->proto;
1214 res->res_handle = cfgtew->u.cfgte64->res_handle;
1215 res->dev_id = cfgtew->u.cfgte64->dev_id;
1216
1217 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1218 sizeof(res->dev_lun.scsi_lun));
1219
1220 if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1221 sizeof(res->res_path))) {
1222 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1223 sizeof(res->res_path));
1224 new_path = 1;
1225 }
1226
1227 if (res->sdev && new_path)
1228 sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001229 ipr_format_res_path(res->res_path, buffer,
1230 sizeof(buffer)));
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001231 } else {
1232 res->flags = cfgtew->u.cfgte->flags;
1233 if (res->flags & IPR_IS_IOA_RESOURCE)
1234 res->type = IPR_RES_TYPE_IOAFP;
1235 else
1236 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1237
1238 memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1239 sizeof(struct ipr_std_inq_data));
1240
1241 res->qmodel = IPR_QUEUEING_MODEL(res);
1242 proto = cfgtew->u.cfgte->proto;
1243 res->res_handle = cfgtew->u.cfgte->res_handle;
1244 }
1245
1246 ipr_update_ata_class(res, proto);
1247}
1248
1249/**
1250 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1251 * for the resource.
1252 * @res: resource entry struct
1253 * @cfgtew: config table entry wrapper struct
1254 *
1255 * Return value:
1256 * none
1257 **/
1258static void ipr_clear_res_target(struct ipr_resource_entry *res)
1259{
1260 struct ipr_resource_entry *gscsi_res = NULL;
1261 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1262
1263 if (!ioa_cfg->sis64)
1264 return;
1265
1266 if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1267 clear_bit(res->target, ioa_cfg->array_ids);
1268 else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1269 clear_bit(res->target, ioa_cfg->vset_ids);
1270 else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1271 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1272 if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1273 return;
1274 clear_bit(res->target, ioa_cfg->target_ids);
1275
1276 } else if (res->bus == 0)
1277 clear_bit(res->target, ioa_cfg->target_ids);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278}
1279
1280/**
1281 * ipr_handle_config_change - Handle a config change from the adapter
1282 * @ioa_cfg: ioa config struct
1283 * @hostrcb: hostrcb
1284 *
1285 * Return value:
1286 * none
1287 **/
1288static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001289 struct ipr_hostrcb *hostrcb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
1291 struct ipr_resource_entry *res = NULL;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001292 struct ipr_config_table_entry_wrapper cfgtew;
1293 __be32 cc_res_handle;
1294
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 u32 is_ndn = 1;
1296
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001297 if (ioa_cfg->sis64) {
1298 cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1299 cc_res_handle = cfgtew.u.cfgte64->res_handle;
1300 } else {
1301 cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1302 cc_res_handle = cfgtew.u.cfgte->res_handle;
1303 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
1305 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001306 if (res->res_handle == cc_res_handle) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 is_ndn = 0;
1308 break;
1309 }
1310 }
1311
1312 if (is_ndn) {
1313 if (list_empty(&ioa_cfg->free_res_q)) {
1314 ipr_send_hcam(ioa_cfg,
1315 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1316 hostrcb);
1317 return;
1318 }
1319
1320 res = list_entry(ioa_cfg->free_res_q.next,
1321 struct ipr_resource_entry, queue);
1322
1323 list_del(&res->queue);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001324 ipr_init_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1326 }
1327
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001328 ipr_update_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
1330 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1331 if (res->sdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 res->del_from_ml = 1;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001333 res->res_handle = IPR_INVALID_RES_HANDLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 if (ioa_cfg->allow_ml_add_del)
1335 schedule_work(&ioa_cfg->work_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001336 } else {
1337 ipr_clear_res_target(res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001339 }
Kleber Sacilotto de Souza5767a1c2011-02-14 20:19:31 -02001340 } else if (!res->sdev || res->del_from_ml) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 res->add_to_ml = 1;
1342 if (ioa_cfg->allow_ml_add_del)
1343 schedule_work(&ioa_cfg->work_q);
1344 }
1345
1346 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1347}
1348
1349/**
1350 * ipr_process_ccn - Op done function for a CCN.
1351 * @ipr_cmd: ipr command struct
1352 *
1353 * This function is the op done function for a configuration
1354 * change notification host controlled async from the adapter.
1355 *
1356 * Return value:
1357 * none
1358 **/
1359static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1360{
1361 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1362 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07001363 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
1365 list_del(&hostrcb->queue);
1366 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1367
1368 if (ioasc) {
1369 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
1370 dev_err(&ioa_cfg->pdev->dev,
1371 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1372
1373 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1374 } else {
1375 ipr_handle_config_change(ioa_cfg, hostrcb);
1376 }
1377}
1378
1379/**
Brian King8cf093e2007-04-26 16:00:14 -05001380 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1381 * @i: index into buffer
1382 * @buf: string to modify
1383 *
1384 * This function will strip all trailing whitespace, pad the end
1385 * of the string with a single space, and NULL terminate the string.
1386 *
1387 * Return value:
1388 * new length of string
1389 **/
1390static int strip_and_pad_whitespace(int i, char *buf)
1391{
1392 while (i && buf[i] == ' ')
1393 i--;
1394 buf[i+1] = ' ';
1395 buf[i+2] = '\0';
1396 return i + 2;
1397}
1398
1399/**
1400 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1401 * @prefix: string to print at start of printk
1402 * @hostrcb: hostrcb pointer
1403 * @vpd: vendor/product id/sn struct
1404 *
1405 * Return value:
1406 * none
1407 **/
1408static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1409 struct ipr_vpd *vpd)
1410{
1411 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
1412 int i = 0;
1413
1414 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1415 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
1416
1417 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
1418 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
1419
1420 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1421 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1422
1423 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1424}
1425
1426/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 * ipr_log_vpd - Log the passed VPD to the error log.
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001428 * @vpd: vendor/product id/sn struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 *
1430 * Return value:
1431 * none
1432 **/
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001433static void ipr_log_vpd(struct ipr_vpd *vpd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434{
1435 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1436 + IPR_SERIAL_NUM_LEN];
1437
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001438 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1439 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 IPR_PROD_ID_LEN);
1441 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1442 ipr_err("Vendor/Product ID: %s\n", buffer);
1443
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001444 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1446 ipr_err(" Serial Number: %s\n", buffer);
1447}
1448
1449/**
Brian King8cf093e2007-04-26 16:00:14 -05001450 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1451 * @prefix: string to print at start of printk
1452 * @hostrcb: hostrcb pointer
1453 * @vpd: vendor/product id/sn/wwn struct
1454 *
1455 * Return value:
1456 * none
1457 **/
1458static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1459 struct ipr_ext_vpd *vpd)
1460{
1461 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1462 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1463 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1464}
1465
1466/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001467 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1468 * @vpd: vendor/product id/sn/wwn struct
1469 *
1470 * Return value:
1471 * none
1472 **/
1473static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1474{
1475 ipr_log_vpd(&vpd->vpd);
1476 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1477 be32_to_cpu(vpd->wwid[1]));
1478}
1479
1480/**
1481 * ipr_log_enhanced_cache_error - Log a cache error.
1482 * @ioa_cfg: ioa config struct
1483 * @hostrcb: hostrcb struct
1484 *
1485 * Return value:
1486 * none
1487 **/
1488static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1489 struct ipr_hostrcb *hostrcb)
1490{
Wayne Boyer4565e372010-02-19 13:24:07 -08001491 struct ipr_hostrcb_type_12_error *error;
1492
1493 if (ioa_cfg->sis64)
1494 error = &hostrcb->hcam.u.error64.u.type_12_error;
1495 else
1496 error = &hostrcb->hcam.u.error.u.type_12_error;
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001497
1498 ipr_err("-----Current Configuration-----\n");
1499 ipr_err("Cache Directory Card Information:\n");
1500 ipr_log_ext_vpd(&error->ioa_vpd);
1501 ipr_err("Adapter Card Information:\n");
1502 ipr_log_ext_vpd(&error->cfc_vpd);
1503
1504 ipr_err("-----Expected Configuration-----\n");
1505 ipr_err("Cache Directory Card Information:\n");
1506 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1507 ipr_err("Adapter Card Information:\n");
1508 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1509
1510 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1511 be32_to_cpu(error->ioa_data[0]),
1512 be32_to_cpu(error->ioa_data[1]),
1513 be32_to_cpu(error->ioa_data[2]));
1514}
1515
1516/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 * ipr_log_cache_error - Log a cache error.
1518 * @ioa_cfg: ioa config struct
1519 * @hostrcb: hostrcb struct
1520 *
1521 * Return value:
1522 * none
1523 **/
1524static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1525 struct ipr_hostrcb *hostrcb)
1526{
1527 struct ipr_hostrcb_type_02_error *error =
1528 &hostrcb->hcam.u.error.u.type_02_error;
1529
1530 ipr_err("-----Current Configuration-----\n");
1531 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001532 ipr_log_vpd(&error->ioa_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001534 ipr_log_vpd(&error->cfc_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
1536 ipr_err("-----Expected Configuration-----\n");
1537 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001538 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001540 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
1542 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1543 be32_to_cpu(error->ioa_data[0]),
1544 be32_to_cpu(error->ioa_data[1]),
1545 be32_to_cpu(error->ioa_data[2]));
1546}
1547
1548/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001549 * ipr_log_enhanced_config_error - Log a configuration error.
1550 * @ioa_cfg: ioa config struct
1551 * @hostrcb: hostrcb struct
1552 *
1553 * Return value:
1554 * none
1555 **/
1556static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1557 struct ipr_hostrcb *hostrcb)
1558{
1559 int errors_logged, i;
1560 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1561 struct ipr_hostrcb_type_13_error *error;
1562
1563 error = &hostrcb->hcam.u.error.u.type_13_error;
1564 errors_logged = be32_to_cpu(error->errors_logged);
1565
1566 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1567 be32_to_cpu(error->errors_detected), errors_logged);
1568
1569 dev_entry = error->dev;
1570
1571 for (i = 0; i < errors_logged; i++, dev_entry++) {
1572 ipr_err_separator;
1573
1574 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1575 ipr_log_ext_vpd(&dev_entry->vpd);
1576
1577 ipr_err("-----New Device Information-----\n");
1578 ipr_log_ext_vpd(&dev_entry->new_vpd);
1579
1580 ipr_err("Cache Directory Card Information:\n");
1581 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1582
1583 ipr_err("Adapter Card Information:\n");
1584 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1585 }
1586}
1587
1588/**
Wayne Boyer4565e372010-02-19 13:24:07 -08001589 * ipr_log_sis64_config_error - Log a device error.
1590 * @ioa_cfg: ioa config struct
1591 * @hostrcb: hostrcb struct
1592 *
1593 * Return value:
1594 * none
1595 **/
1596static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
1597 struct ipr_hostrcb *hostrcb)
1598{
1599 int errors_logged, i;
1600 struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
1601 struct ipr_hostrcb_type_23_error *error;
1602 char buffer[IPR_MAX_RES_PATH_LENGTH];
1603
1604 error = &hostrcb->hcam.u.error64.u.type_23_error;
1605 errors_logged = be32_to_cpu(error->errors_logged);
1606
1607 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1608 be32_to_cpu(error->errors_detected), errors_logged);
1609
1610 dev_entry = error->dev;
1611
1612 for (i = 0; i < errors_logged; i++, dev_entry++) {
1613 ipr_err_separator;
1614
1615 ipr_err("Device %d : %s", i + 1,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001616 ipr_format_res_path(dev_entry->res_path, buffer,
1617 sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08001618 ipr_log_ext_vpd(&dev_entry->vpd);
1619
1620 ipr_err("-----New Device Information-----\n");
1621 ipr_log_ext_vpd(&dev_entry->new_vpd);
1622
1623 ipr_err("Cache Directory Card Information:\n");
1624 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1625
1626 ipr_err("Adapter Card Information:\n");
1627 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1628 }
1629}
1630
1631/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 * ipr_log_config_error - Log a configuration error.
1633 * @ioa_cfg: ioa config struct
1634 * @hostrcb: hostrcb struct
1635 *
1636 * Return value:
1637 * none
1638 **/
1639static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1640 struct ipr_hostrcb *hostrcb)
1641{
1642 int errors_logged, i;
1643 struct ipr_hostrcb_device_data_entry *dev_entry;
1644 struct ipr_hostrcb_type_03_error *error;
1645
1646 error = &hostrcb->hcam.u.error.u.type_03_error;
1647 errors_logged = be32_to_cpu(error->errors_logged);
1648
1649 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1650 be32_to_cpu(error->errors_detected), errors_logged);
1651
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001652 dev_entry = error->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
1654 for (i = 0; i < errors_logged; i++, dev_entry++) {
1655 ipr_err_separator;
1656
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001657 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001658 ipr_log_vpd(&dev_entry->vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
1660 ipr_err("-----New Device Information-----\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001661 ipr_log_vpd(&dev_entry->new_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
1663 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001664 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
1666 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001667 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
1669 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1670 be32_to_cpu(dev_entry->ioa_data[0]),
1671 be32_to_cpu(dev_entry->ioa_data[1]),
1672 be32_to_cpu(dev_entry->ioa_data[2]),
1673 be32_to_cpu(dev_entry->ioa_data[3]),
1674 be32_to_cpu(dev_entry->ioa_data[4]));
1675 }
1676}
1677
1678/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001679 * ipr_log_enhanced_array_error - Log an array configuration error.
1680 * @ioa_cfg: ioa config struct
1681 * @hostrcb: hostrcb struct
1682 *
1683 * Return value:
1684 * none
1685 **/
1686static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1687 struct ipr_hostrcb *hostrcb)
1688{
1689 int i, num_entries;
1690 struct ipr_hostrcb_type_14_error *error;
1691 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1692 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1693
1694 error = &hostrcb->hcam.u.error.u.type_14_error;
1695
1696 ipr_err_separator;
1697
1698 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1699 error->protection_level,
1700 ioa_cfg->host->host_no,
1701 error->last_func_vset_res_addr.bus,
1702 error->last_func_vset_res_addr.target,
1703 error->last_func_vset_res_addr.lun);
1704
1705 ipr_err_separator;
1706
1707 array_entry = error->array_member;
1708 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
Wayne Boyer72620262010-09-27 10:45:28 -07001709 ARRAY_SIZE(error->array_member));
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001710
1711 for (i = 0; i < num_entries; i++, array_entry++) {
1712 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1713 continue;
1714
1715 if (be32_to_cpu(error->exposed_mode_adn) == i)
1716 ipr_err("Exposed Array Member %d:\n", i);
1717 else
1718 ipr_err("Array Member %d:\n", i);
1719
1720 ipr_log_ext_vpd(&array_entry->vpd);
1721 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1722 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1723 "Expected Location");
1724
1725 ipr_err_separator;
1726 }
1727}
1728
1729/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 * ipr_log_array_error - Log an array configuration error.
1731 * @ioa_cfg: ioa config struct
1732 * @hostrcb: hostrcb struct
1733 *
1734 * Return value:
1735 * none
1736 **/
1737static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1738 struct ipr_hostrcb *hostrcb)
1739{
1740 int i;
1741 struct ipr_hostrcb_type_04_error *error;
1742 struct ipr_hostrcb_array_data_entry *array_entry;
1743 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1744
1745 error = &hostrcb->hcam.u.error.u.type_04_error;
1746
1747 ipr_err_separator;
1748
1749 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1750 error->protection_level,
1751 ioa_cfg->host->host_no,
1752 error->last_func_vset_res_addr.bus,
1753 error->last_func_vset_res_addr.target,
1754 error->last_func_vset_res_addr.lun);
1755
1756 ipr_err_separator;
1757
1758 array_entry = error->array_member;
1759
1760 for (i = 0; i < 18; i++) {
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001761 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 continue;
1763
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001764 if (be32_to_cpu(error->exposed_mode_adn) == i)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 ipr_err("Exposed Array Member %d:\n", i);
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001766 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 ipr_err("Array Member %d:\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001769 ipr_log_vpd(&array_entry->vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001771 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1772 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1773 "Expected Location");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
1775 ipr_err_separator;
1776
1777 if (i == 9)
1778 array_entry = error->array_member2;
1779 else
1780 array_entry++;
1781 }
1782}
1783
1784/**
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001785 * ipr_log_hex_data - Log additional hex IOA error data.
Brian Kingac719ab2006-11-21 10:28:42 -06001786 * @ioa_cfg: ioa config struct
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001787 * @data: IOA error data
1788 * @len: data length
1789 *
1790 * Return value:
1791 * none
1792 **/
Brian Kingac719ab2006-11-21 10:28:42 -06001793static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001794{
1795 int i;
1796
1797 if (len == 0)
1798 return;
1799
Brian Kingac719ab2006-11-21 10:28:42 -06001800 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1801 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1802
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001803 for (i = 0; i < len / 4; i += 4) {
1804 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1805 be32_to_cpu(data[i]),
1806 be32_to_cpu(data[i+1]),
1807 be32_to_cpu(data[i+2]),
1808 be32_to_cpu(data[i+3]));
1809 }
1810}
1811
1812/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001813 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1814 * @ioa_cfg: ioa config struct
1815 * @hostrcb: hostrcb struct
1816 *
1817 * Return value:
1818 * none
1819 **/
1820static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1821 struct ipr_hostrcb *hostrcb)
1822{
1823 struct ipr_hostrcb_type_17_error *error;
1824
Wayne Boyer4565e372010-02-19 13:24:07 -08001825 if (ioa_cfg->sis64)
1826 error = &hostrcb->hcam.u.error64.u.type_17_error;
1827 else
1828 error = &hostrcb->hcam.u.error.u.type_17_error;
1829
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001830 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
KOSAKI Motohiroca54cb82009-12-14 18:01:15 -08001831 strim(error->failure_reason);
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001832
Brian King8cf093e2007-04-26 16:00:14 -05001833 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1834 be32_to_cpu(hostrcb->hcam.u.error.prc));
1835 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
Brian Kingac719ab2006-11-21 10:28:42 -06001836 ipr_log_hex_data(ioa_cfg, error->data,
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001837 be32_to_cpu(hostrcb->hcam.length) -
1838 (offsetof(struct ipr_hostrcb_error, u) +
1839 offsetof(struct ipr_hostrcb_type_17_error, data)));
1840}
1841
1842/**
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001843 * ipr_log_dual_ioa_error - Log a dual adapter error.
1844 * @ioa_cfg: ioa config struct
1845 * @hostrcb: hostrcb struct
1846 *
1847 * Return value:
1848 * none
1849 **/
1850static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1851 struct ipr_hostrcb *hostrcb)
1852{
1853 struct ipr_hostrcb_type_07_error *error;
1854
1855 error = &hostrcb->hcam.u.error.u.type_07_error;
1856 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
KOSAKI Motohiroca54cb82009-12-14 18:01:15 -08001857 strim(error->failure_reason);
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001858
Brian King8cf093e2007-04-26 16:00:14 -05001859 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1860 be32_to_cpu(hostrcb->hcam.u.error.prc));
1861 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
Brian Kingac719ab2006-11-21 10:28:42 -06001862 ipr_log_hex_data(ioa_cfg, error->data,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001863 be32_to_cpu(hostrcb->hcam.length) -
1864 (offsetof(struct ipr_hostrcb_error, u) +
1865 offsetof(struct ipr_hostrcb_type_07_error, data)));
1866}
1867
Brian King49dc6a12006-11-21 10:28:35 -06001868static const struct {
1869 u8 active;
1870 char *desc;
1871} path_active_desc[] = {
1872 { IPR_PATH_NO_INFO, "Path" },
1873 { IPR_PATH_ACTIVE, "Active path" },
1874 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1875};
1876
1877static const struct {
1878 u8 state;
1879 char *desc;
1880} path_state_desc[] = {
1881 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1882 { IPR_PATH_HEALTHY, "is healthy" },
1883 { IPR_PATH_DEGRADED, "is degraded" },
1884 { IPR_PATH_FAILED, "is failed" }
1885};
1886
1887/**
1888 * ipr_log_fabric_path - Log a fabric path error
1889 * @hostrcb: hostrcb struct
1890 * @fabric: fabric descriptor
1891 *
1892 * Return value:
1893 * none
1894 **/
1895static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1896 struct ipr_hostrcb_fabric_desc *fabric)
1897{
1898 int i, j;
1899 u8 path_state = fabric->path_state;
1900 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1901 u8 state = path_state & IPR_PATH_STATE_MASK;
1902
1903 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1904 if (path_active_desc[i].active != active)
1905 continue;
1906
1907 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1908 if (path_state_desc[j].state != state)
1909 continue;
1910
1911 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
1912 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
1913 path_active_desc[i].desc, path_state_desc[j].desc,
1914 fabric->ioa_port);
1915 } else if (fabric->cascaded_expander == 0xff) {
1916 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
1917 path_active_desc[i].desc, path_state_desc[j].desc,
1918 fabric->ioa_port, fabric->phy);
1919 } else if (fabric->phy == 0xff) {
1920 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
1921 path_active_desc[i].desc, path_state_desc[j].desc,
1922 fabric->ioa_port, fabric->cascaded_expander);
1923 } else {
1924 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1925 path_active_desc[i].desc, path_state_desc[j].desc,
1926 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1927 }
1928 return;
1929 }
1930 }
1931
1932 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
1933 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1934}
1935
Wayne Boyer4565e372010-02-19 13:24:07 -08001936/**
1937 * ipr_log64_fabric_path - Log a fabric path error
1938 * @hostrcb: hostrcb struct
1939 * @fabric: fabric descriptor
1940 *
1941 * Return value:
1942 * none
1943 **/
1944static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
1945 struct ipr_hostrcb64_fabric_desc *fabric)
1946{
1947 int i, j;
1948 u8 path_state = fabric->path_state;
1949 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1950 u8 state = path_state & IPR_PATH_STATE_MASK;
1951 char buffer[IPR_MAX_RES_PATH_LENGTH];
1952
1953 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1954 if (path_active_desc[i].active != active)
1955 continue;
1956
1957 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1958 if (path_state_desc[j].state != state)
1959 continue;
1960
1961 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
1962 path_active_desc[i].desc, path_state_desc[j].desc,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001963 ipr_format_res_path(fabric->res_path, buffer,
1964 sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08001965 return;
1966 }
1967 }
1968
1969 ipr_err("Path state=%02X Resource Path=%s\n", path_state,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001970 ipr_format_res_path(fabric->res_path, buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08001971}
1972
Brian King49dc6a12006-11-21 10:28:35 -06001973static const struct {
1974 u8 type;
1975 char *desc;
1976} path_type_desc[] = {
1977 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
1978 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
1979 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
1980 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
1981};
1982
1983static const struct {
1984 u8 status;
1985 char *desc;
1986} path_status_desc[] = {
1987 { IPR_PATH_CFG_NO_PROB, "Functional" },
1988 { IPR_PATH_CFG_DEGRADED, "Degraded" },
1989 { IPR_PATH_CFG_FAILED, "Failed" },
1990 { IPR_PATH_CFG_SUSPECT, "Suspect" },
1991 { IPR_PATH_NOT_DETECTED, "Missing" },
1992 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
1993};
1994
1995static const char *link_rate[] = {
1996 "unknown",
1997 "disabled",
1998 "phy reset problem",
1999 "spinup hold",
2000 "port selector",
2001 "unknown",
2002 "unknown",
2003 "unknown",
2004 "1.5Gbps",
2005 "3.0Gbps",
2006 "unknown",
2007 "unknown",
2008 "unknown",
2009 "unknown",
2010 "unknown",
2011 "unknown"
2012};
2013
2014/**
2015 * ipr_log_path_elem - Log a fabric path element.
2016 * @hostrcb: hostrcb struct
2017 * @cfg: fabric path element struct
2018 *
2019 * Return value:
2020 * none
2021 **/
2022static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
2023 struct ipr_hostrcb_config_element *cfg)
2024{
2025 int i, j;
2026 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2027 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2028
2029 if (type == IPR_PATH_CFG_NOT_EXIST)
2030 return;
2031
2032 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2033 if (path_type_desc[i].type != type)
2034 continue;
2035
2036 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2037 if (path_status_desc[j].status != status)
2038 continue;
2039
2040 if (type == IPR_PATH_CFG_IOA_PORT) {
2041 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
2042 path_status_desc[j].desc, path_type_desc[i].desc,
2043 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2044 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2045 } else {
2046 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
2047 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2048 path_status_desc[j].desc, path_type_desc[i].desc,
2049 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2050 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2051 } else if (cfg->cascaded_expander == 0xff) {
2052 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
2053 "WWN=%08X%08X\n", path_status_desc[j].desc,
2054 path_type_desc[i].desc, cfg->phy,
2055 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2056 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2057 } else if (cfg->phy == 0xff) {
2058 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
2059 "WWN=%08X%08X\n", path_status_desc[j].desc,
2060 path_type_desc[i].desc, cfg->cascaded_expander,
2061 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2062 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2063 } else {
2064 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2065 "WWN=%08X%08X\n", path_status_desc[j].desc,
2066 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
2067 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2068 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2069 }
2070 }
2071 return;
2072 }
2073 }
2074
2075 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2076 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
2077 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2078 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2079}
2080
2081/**
Wayne Boyer4565e372010-02-19 13:24:07 -08002082 * ipr_log64_path_elem - Log a fabric path element.
2083 * @hostrcb: hostrcb struct
2084 * @cfg: fabric path element struct
2085 *
2086 * Return value:
2087 * none
2088 **/
2089static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
2090 struct ipr_hostrcb64_config_element *cfg)
2091{
2092 int i, j;
2093 u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
2094 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2095 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2096 char buffer[IPR_MAX_RES_PATH_LENGTH];
2097
2098 if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
2099 return;
2100
2101 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2102 if (path_type_desc[i].type != type)
2103 continue;
2104
2105 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2106 if (path_status_desc[j].status != status)
2107 continue;
2108
2109 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2110 path_status_desc[j].desc, path_type_desc[i].desc,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07002111 ipr_format_res_path(cfg->res_path, buffer,
2112 sizeof(buffer)),
Wayne Boyer4565e372010-02-19 13:24:07 -08002113 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2114 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2115 return;
2116 }
2117 }
2118 ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
2119 "WWN=%08X%08X\n", cfg->type_status,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07002120 ipr_format_res_path(cfg->res_path, buffer, sizeof(buffer)),
Wayne Boyer4565e372010-02-19 13:24:07 -08002121 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2122 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2123}
2124
2125/**
Brian King49dc6a12006-11-21 10:28:35 -06002126 * ipr_log_fabric_error - Log a fabric error.
2127 * @ioa_cfg: ioa config struct
2128 * @hostrcb: hostrcb struct
2129 *
2130 * Return value:
2131 * none
2132 **/
2133static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2134 struct ipr_hostrcb *hostrcb)
2135{
2136 struct ipr_hostrcb_type_20_error *error;
2137 struct ipr_hostrcb_fabric_desc *fabric;
2138 struct ipr_hostrcb_config_element *cfg;
2139 int i, add_len;
2140
2141 error = &hostrcb->hcam.u.error.u.type_20_error;
2142 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2143 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2144
2145 add_len = be32_to_cpu(hostrcb->hcam.length) -
2146 (offsetof(struct ipr_hostrcb_error, u) +
2147 offsetof(struct ipr_hostrcb_type_20_error, desc));
2148
2149 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2150 ipr_log_fabric_path(hostrcb, fabric);
2151 for_each_fabric_cfg(fabric, cfg)
2152 ipr_log_path_elem(hostrcb, cfg);
2153
2154 add_len -= be16_to_cpu(fabric->length);
2155 fabric = (struct ipr_hostrcb_fabric_desc *)
2156 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2157 }
2158
Brian Kingac719ab2006-11-21 10:28:42 -06002159 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
Brian King49dc6a12006-11-21 10:28:35 -06002160}
2161
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002162/**
Wayne Boyer4565e372010-02-19 13:24:07 -08002163 * ipr_log_sis64_array_error - Log a sis64 array error.
2164 * @ioa_cfg: ioa config struct
2165 * @hostrcb: hostrcb struct
2166 *
2167 * Return value:
2168 * none
2169 **/
2170static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
2171 struct ipr_hostrcb *hostrcb)
2172{
2173 int i, num_entries;
2174 struct ipr_hostrcb_type_24_error *error;
2175 struct ipr_hostrcb64_array_data_entry *array_entry;
2176 char buffer[IPR_MAX_RES_PATH_LENGTH];
2177 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
2178
2179 error = &hostrcb->hcam.u.error64.u.type_24_error;
2180
2181 ipr_err_separator;
2182
2183 ipr_err("RAID %s Array Configuration: %s\n",
2184 error->protection_level,
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07002185 ipr_format_res_path(error->last_res_path, buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002186
2187 ipr_err_separator;
2188
2189 array_entry = error->array_member;
Wayne Boyer72620262010-09-27 10:45:28 -07002190 num_entries = min_t(u32, error->num_entries,
2191 ARRAY_SIZE(error->array_member));
Wayne Boyer4565e372010-02-19 13:24:07 -08002192
2193 for (i = 0; i < num_entries; i++, array_entry++) {
2194
2195 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
2196 continue;
2197
2198 if (error->exposed_mode_adn == i)
2199 ipr_err("Exposed Array Member %d:\n", i);
2200 else
2201 ipr_err("Array Member %d:\n", i);
2202
2203 ipr_err("Array Member %d:\n", i);
2204 ipr_log_ext_vpd(&array_entry->vpd);
Wayne Boyer72620262010-09-27 10:45:28 -07002205 ipr_err("Current Location: %s\n",
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07002206 ipr_format_res_path(array_entry->res_path, buffer,
2207 sizeof(buffer)));
Wayne Boyer72620262010-09-27 10:45:28 -07002208 ipr_err("Expected Location: %s\n",
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07002209 ipr_format_res_path(array_entry->expected_res_path,
2210 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002211
2212 ipr_err_separator;
2213 }
2214}
2215
2216/**
2217 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2218 * @ioa_cfg: ioa config struct
2219 * @hostrcb: hostrcb struct
2220 *
2221 * Return value:
2222 * none
2223 **/
2224static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2225 struct ipr_hostrcb *hostrcb)
2226{
2227 struct ipr_hostrcb_type_30_error *error;
2228 struct ipr_hostrcb64_fabric_desc *fabric;
2229 struct ipr_hostrcb64_config_element *cfg;
2230 int i, add_len;
2231
2232 error = &hostrcb->hcam.u.error64.u.type_30_error;
2233
2234 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2235 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2236
2237 add_len = be32_to_cpu(hostrcb->hcam.length) -
2238 (offsetof(struct ipr_hostrcb64_error, u) +
2239 offsetof(struct ipr_hostrcb_type_30_error, desc));
2240
2241 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2242 ipr_log64_fabric_path(hostrcb, fabric);
2243 for_each_fabric_cfg(fabric, cfg)
2244 ipr_log64_path_elem(hostrcb, cfg);
2245
2246 add_len -= be16_to_cpu(fabric->length);
2247 fabric = (struct ipr_hostrcb64_fabric_desc *)
2248 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2249 }
2250
2251 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2252}
2253
2254/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 * ipr_log_generic_error - Log an adapter error.
2256 * @ioa_cfg: ioa config struct
2257 * @hostrcb: hostrcb struct
2258 *
2259 * Return value:
2260 * none
2261 **/
2262static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
2263 struct ipr_hostrcb *hostrcb)
2264{
Brian Kingac719ab2006-11-21 10:28:42 -06002265 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002266 be32_to_cpu(hostrcb->hcam.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267}
2268
2269/**
2270 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2271 * @ioasc: IOASC
2272 *
2273 * This function will return the index of into the ipr_error_table
2274 * for the specified IOASC. If the IOASC is not in the table,
2275 * 0 will be returned, which points to the entry used for unknown errors.
2276 *
2277 * Return value:
2278 * index into the ipr_error_table
2279 **/
2280static u32 ipr_get_error(u32 ioasc)
2281{
2282 int i;
2283
2284 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
Brian King35a39692006-09-25 12:39:20 -05002285 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 return i;
2287
2288 return 0;
2289}
2290
2291/**
2292 * ipr_handle_log_data - Log an adapter error.
2293 * @ioa_cfg: ioa config struct
2294 * @hostrcb: hostrcb struct
2295 *
2296 * This function logs an adapter error to the system.
2297 *
2298 * Return value:
2299 * none
2300 **/
2301static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
2302 struct ipr_hostrcb *hostrcb)
2303{
2304 u32 ioasc;
2305 int error_index;
2306
2307 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
2308 return;
2309
2310 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
2311 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
2312
Wayne Boyer4565e372010-02-19 13:24:07 -08002313 if (ioa_cfg->sis64)
2314 ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2315 else
2316 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Wayne Boyer4565e372010-02-19 13:24:07 -08002318 if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
2319 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2321 scsi_report_bus_reset(ioa_cfg->host,
Wayne Boyer4565e372010-02-19 13:24:07 -08002322 hostrcb->hcam.u.error.fd_res_addr.bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 }
2324
2325 error_index = ipr_get_error(ioasc);
2326
2327 if (!ipr_error_table[error_index].log_hcam)
2328 return;
2329
Brian King49dc6a12006-11-21 10:28:35 -06002330 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
2332 /* Set indication we have logged an error */
2333 ioa_cfg->errors_logged++;
2334
Brian King933916f2007-03-29 12:43:30 -05002335 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 return;
brking@us.ibm.comcf852032005-11-01 17:00:47 -06002337 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
2338 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
2340 switch (hostrcb->hcam.overlay_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 case IPR_HOST_RCB_OVERLAY_ID_2:
2342 ipr_log_cache_error(ioa_cfg, hostrcb);
2343 break;
2344 case IPR_HOST_RCB_OVERLAY_ID_3:
2345 ipr_log_config_error(ioa_cfg, hostrcb);
2346 break;
2347 case IPR_HOST_RCB_OVERLAY_ID_4:
2348 case IPR_HOST_RCB_OVERLAY_ID_6:
2349 ipr_log_array_error(ioa_cfg, hostrcb);
2350 break;
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002351 case IPR_HOST_RCB_OVERLAY_ID_7:
2352 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
2353 break;
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06002354 case IPR_HOST_RCB_OVERLAY_ID_12:
2355 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
2356 break;
2357 case IPR_HOST_RCB_OVERLAY_ID_13:
2358 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
2359 break;
2360 case IPR_HOST_RCB_OVERLAY_ID_14:
2361 case IPR_HOST_RCB_OVERLAY_ID_16:
2362 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
2363 break;
2364 case IPR_HOST_RCB_OVERLAY_ID_17:
2365 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
2366 break;
Brian King49dc6a12006-11-21 10:28:35 -06002367 case IPR_HOST_RCB_OVERLAY_ID_20:
2368 ipr_log_fabric_error(ioa_cfg, hostrcb);
2369 break;
Wayne Boyer4565e372010-02-19 13:24:07 -08002370 case IPR_HOST_RCB_OVERLAY_ID_23:
2371 ipr_log_sis64_config_error(ioa_cfg, hostrcb);
2372 break;
2373 case IPR_HOST_RCB_OVERLAY_ID_24:
2374 case IPR_HOST_RCB_OVERLAY_ID_26:
2375 ipr_log_sis64_array_error(ioa_cfg, hostrcb);
2376 break;
2377 case IPR_HOST_RCB_OVERLAY_ID_30:
2378 ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
2379 break;
brking@us.ibm.comcf852032005-11-01 17:00:47 -06002380 case IPR_HOST_RCB_OVERLAY_ID_1:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 default:
brking@us.ibm.coma9cfca92005-11-01 17:00:41 -06002383 ipr_log_generic_error(ioa_cfg, hostrcb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 break;
2385 }
2386}
2387
2388/**
2389 * ipr_process_error - Op done function for an adapter error log.
2390 * @ipr_cmd: ipr command struct
2391 *
2392 * This function is the op done function for an error log host
2393 * controlled async from the adapter. It will log the error and
2394 * send the HCAM back to the adapter.
2395 *
2396 * Return value:
2397 * none
2398 **/
2399static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2400{
2401 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2402 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07002403 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Wayne Boyer4565e372010-02-19 13:24:07 -08002404 u32 fd_ioasc;
2405
2406 if (ioa_cfg->sis64)
2407 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2408 else
2409 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
2411 list_del(&hostrcb->queue);
2412 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
2413
2414 if (!ioasc) {
2415 ipr_handle_log_data(ioa_cfg, hostrcb);
Brian King65f56472007-04-26 16:00:12 -05002416 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
2417 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
2419 dev_err(&ioa_cfg->pdev->dev,
2420 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
2421 }
2422
2423 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2424}
2425
2426/**
2427 * ipr_timeout - An internally generated op has timed out.
2428 * @ipr_cmd: ipr command struct
2429 *
2430 * This function blocks host requests and initiates an
2431 * adapter reset.
2432 *
2433 * Return value:
2434 * none
2435 **/
2436static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
2437{
2438 unsigned long lock_flags = 0;
2439 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2440
2441 ENTER;
2442 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2443
2444 ioa_cfg->errors_logged++;
2445 dev_err(&ioa_cfg->pdev->dev,
2446 "Adapter being reset due to command timeout.\n");
2447
2448 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2449 ioa_cfg->sdt_state = GET_DUMP;
2450
2451 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
2452 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2453
2454 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2455 LEAVE;
2456}
2457
2458/**
2459 * ipr_oper_timeout - Adapter timed out transitioning to operational
2460 * @ipr_cmd: ipr command struct
2461 *
2462 * This function blocks host requests and initiates an
2463 * adapter reset.
2464 *
2465 * Return value:
2466 * none
2467 **/
2468static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
2469{
2470 unsigned long lock_flags = 0;
2471 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2472
2473 ENTER;
2474 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2475
2476 ioa_cfg->errors_logged++;
2477 dev_err(&ioa_cfg->pdev->dev,
2478 "Adapter timed out transitioning to operational.\n");
2479
2480 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2481 ioa_cfg->sdt_state = GET_DUMP;
2482
2483 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
2484 if (ipr_fastfail)
2485 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
2486 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2487 }
2488
2489 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2490 LEAVE;
2491}
2492
2493/**
2494 * ipr_reset_reload - Reset/Reload the IOA
2495 * @ioa_cfg: ioa config struct
2496 * @shutdown_type: shutdown type
2497 *
2498 * This function resets the adapter and re-initializes it.
2499 * This function assumes that all new host commands have been stopped.
2500 * Return value:
2501 * SUCCESS / FAILED
2502 **/
2503static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
2504 enum ipr_shutdown_type shutdown_type)
2505{
2506 if (!ioa_cfg->in_reset_reload)
2507 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
2508
2509 spin_unlock_irq(ioa_cfg->host->host_lock);
2510 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2511 spin_lock_irq(ioa_cfg->host->host_lock);
2512
2513 /* If we got hit with a host reset while we were already resetting
2514 the adapter for some reason, and the reset failed. */
2515 if (ioa_cfg->ioa_is_dead) {
2516 ipr_trace;
2517 return FAILED;
2518 }
2519
2520 return SUCCESS;
2521}
2522
2523/**
2524 * ipr_find_ses_entry - Find matching SES in SES table
2525 * @res: resource entry struct of SES
2526 *
2527 * Return value:
2528 * pointer to SES table entry / NULL on failure
2529 **/
2530static const struct ipr_ses_table_entry *
2531ipr_find_ses_entry(struct ipr_resource_entry *res)
2532{
2533 int i, j, matches;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002534 struct ipr_std_inq_vpids *vpids;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 const struct ipr_ses_table_entry *ste = ipr_ses_table;
2536
2537 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
2538 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
2539 if (ste->compare_product_id_byte[j] == 'X') {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002540 vpids = &res->std_inq_data.vpids;
2541 if (vpids->product_id[j] == ste->product_id[j])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 matches++;
2543 else
2544 break;
2545 } else
2546 matches++;
2547 }
2548
2549 if (matches == IPR_PROD_ID_LEN)
2550 return ste;
2551 }
2552
2553 return NULL;
2554}
2555
2556/**
2557 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2558 * @ioa_cfg: ioa config struct
2559 * @bus: SCSI bus
2560 * @bus_width: bus width
2561 *
2562 * Return value:
2563 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2564 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2565 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2566 * max 160MHz = max 320MB/sec).
2567 **/
2568static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
2569{
2570 struct ipr_resource_entry *res;
2571 const struct ipr_ses_table_entry *ste;
2572 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
2573
2574 /* Loop through each config table entry in the config table buffer */
2575 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002576 if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 continue;
2578
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002579 if (bus != res->bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 continue;
2581
2582 if (!(ste = ipr_find_ses_entry(res)))
2583 continue;
2584
2585 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
2586 }
2587
2588 return max_xfer_rate;
2589}
2590
2591/**
2592 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2593 * @ioa_cfg: ioa config struct
2594 * @max_delay: max delay in micro-seconds to wait
2595 *
2596 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2597 *
2598 * Return value:
2599 * 0 on success / other on failure
2600 **/
2601static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
2602{
2603 volatile u32 pcii_reg;
2604 int delay = 1;
2605
2606 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2607 while (delay < max_delay) {
2608 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
2609
2610 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
2611 return 0;
2612
2613 /* udelay cannot be used if delay is more than a few milliseconds */
2614 if ((delay / 1000) > MAX_UDELAY_MS)
2615 mdelay(delay / 1000);
2616 else
2617 udelay(delay);
2618
2619 delay += delay;
2620 }
2621 return -EIO;
2622}
2623
2624/**
Wayne Boyerdcbad002010-02-19 13:24:14 -08002625 * ipr_get_sis64_dump_data_section - Dump IOA memory
2626 * @ioa_cfg: ioa config struct
2627 * @start_addr: adapter address to dump
2628 * @dest: destination kernel buffer
2629 * @length_in_words: length to dump in 4 byte words
2630 *
2631 * Return value:
2632 * 0 on success
2633 **/
2634static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2635 u32 start_addr,
2636 __be32 *dest, u32 length_in_words)
2637{
2638 int i;
2639
2640 for (i = 0; i < length_in_words; i++) {
2641 writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
2642 *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
2643 dest++;
2644 }
2645
2646 return 0;
2647}
2648
2649/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 * ipr_get_ldump_data_section - Dump IOA memory
2651 * @ioa_cfg: ioa config struct
2652 * @start_addr: adapter address to dump
2653 * @dest: destination kernel buffer
2654 * @length_in_words: length to dump in 4 byte words
2655 *
2656 * Return value:
2657 * 0 on success / -EIO on failure
2658 **/
2659static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2660 u32 start_addr,
2661 __be32 *dest, u32 length_in_words)
2662{
2663 volatile u32 temp_pcii_reg;
2664 int i, delay = 0;
2665
Wayne Boyerdcbad002010-02-19 13:24:14 -08002666 if (ioa_cfg->sis64)
2667 return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
2668 dest, length_in_words);
2669
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 /* Write IOA interrupt reg starting LDUMP state */
2671 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
Wayne Boyer214777b2010-02-19 13:24:26 -08002672 ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
2674 /* Wait for IO debug acknowledge */
2675 if (ipr_wait_iodbg_ack(ioa_cfg,
2676 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
2677 dev_err(&ioa_cfg->pdev->dev,
2678 "IOA dump long data transfer timeout\n");
2679 return -EIO;
2680 }
2681
2682 /* Signal LDUMP interlocked - clear IO debug ack */
2683 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2684 ioa_cfg->regs.clr_interrupt_reg);
2685
2686 /* Write Mailbox with starting address */
2687 writel(start_addr, ioa_cfg->ioa_mailbox);
2688
2689 /* Signal address valid - clear IOA Reset alert */
2690 writel(IPR_UPROCI_RESET_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002691 ioa_cfg->regs.clr_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
2693 for (i = 0; i < length_in_words; i++) {
2694 /* Wait for IO debug acknowledge */
2695 if (ipr_wait_iodbg_ack(ioa_cfg,
2696 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2697 dev_err(&ioa_cfg->pdev->dev,
2698 "IOA dump short data transfer timeout\n");
2699 return -EIO;
2700 }
2701
2702 /* Read data from mailbox and increment destination pointer */
2703 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2704 dest++;
2705
2706 /* For all but the last word of data, signal data received */
2707 if (i < (length_in_words - 1)) {
2708 /* Signal dump data received - Clear IO debug Ack */
2709 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2710 ioa_cfg->regs.clr_interrupt_reg);
2711 }
2712 }
2713
2714 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2715 writel(IPR_UPROCI_RESET_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002716 ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717
2718 writel(IPR_UPROCI_IO_DEBUG_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002719 ioa_cfg->regs.clr_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
2721 /* Signal dump data received - Clear IO debug Ack */
2722 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2723 ioa_cfg->regs.clr_interrupt_reg);
2724
2725 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2726 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2727 temp_pcii_reg =
Wayne Boyer214777b2010-02-19 13:24:26 -08002728 readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729
2730 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2731 return 0;
2732
2733 udelay(10);
2734 delay += 10;
2735 }
2736
2737 return 0;
2738}
2739
2740#ifdef CONFIG_SCSI_IPR_DUMP
2741/**
2742 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2743 * @ioa_cfg: ioa config struct
2744 * @pci_address: adapter address
2745 * @length: length of data to copy
2746 *
2747 * Copy data from PCI adapter to kernel buffer.
2748 * Note: length MUST be a 4 byte multiple
2749 * Return value:
2750 * 0 on success / other on failure
2751 **/
2752static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2753 unsigned long pci_address, u32 length)
2754{
2755 int bytes_copied = 0;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002756 int cur_len, rc, rem_len, rem_page_len, max_dump_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 __be32 *page;
2758 unsigned long lock_flags = 0;
2759 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2760
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002761 if (ioa_cfg->sis64)
2762 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2763 else
2764 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2765
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 while (bytes_copied < length &&
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002767 (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 if (ioa_dump->page_offset >= PAGE_SIZE ||
2769 ioa_dump->page_offset == 0) {
2770 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2771
2772 if (!page) {
2773 ipr_trace;
2774 return bytes_copied;
2775 }
2776
2777 ioa_dump->page_offset = 0;
2778 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2779 ioa_dump->next_page_index++;
2780 } else
2781 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2782
2783 rem_len = length - bytes_copied;
2784 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2785 cur_len = min(rem_len, rem_page_len);
2786
2787 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2788 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2789 rc = -EIO;
2790 } else {
2791 rc = ipr_get_ldump_data_section(ioa_cfg,
2792 pci_address + bytes_copied,
2793 &page[ioa_dump->page_offset / 4],
2794 (cur_len / sizeof(u32)));
2795 }
2796 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2797
2798 if (!rc) {
2799 ioa_dump->page_offset += cur_len;
2800 bytes_copied += cur_len;
2801 } else {
2802 ipr_trace;
2803 break;
2804 }
2805 schedule();
2806 }
2807
2808 return bytes_copied;
2809}
2810
2811/**
2812 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2813 * @hdr: dump entry header struct
2814 *
2815 * Return value:
2816 * nothing
2817 **/
2818static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2819{
2820 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2821 hdr->num_elems = 1;
2822 hdr->offset = sizeof(*hdr);
2823 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2824}
2825
2826/**
2827 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2828 * @ioa_cfg: ioa config struct
2829 * @driver_dump: driver dump struct
2830 *
2831 * Return value:
2832 * nothing
2833 **/
2834static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2835 struct ipr_driver_dump *driver_dump)
2836{
2837 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2838
2839 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2840 driver_dump->ioa_type_entry.hdr.len =
2841 sizeof(struct ipr_dump_ioa_type_entry) -
2842 sizeof(struct ipr_dump_entry_header);
2843 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2844 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2845 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2846 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2847 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2848 ucode_vpd->minor_release[1];
2849 driver_dump->hdr.num_entries++;
2850}
2851
2852/**
2853 * ipr_dump_version_data - Fill in the driver version in the dump.
2854 * @ioa_cfg: ioa config struct
2855 * @driver_dump: driver dump struct
2856 *
2857 * Return value:
2858 * nothing
2859 **/
2860static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2861 struct ipr_driver_dump *driver_dump)
2862{
2863 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2864 driver_dump->version_entry.hdr.len =
2865 sizeof(struct ipr_dump_version_entry) -
2866 sizeof(struct ipr_dump_entry_header);
2867 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2868 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2869 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2870 driver_dump->hdr.num_entries++;
2871}
2872
2873/**
2874 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2875 * @ioa_cfg: ioa config struct
2876 * @driver_dump: driver dump struct
2877 *
2878 * Return value:
2879 * nothing
2880 **/
2881static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
2882 struct ipr_driver_dump *driver_dump)
2883{
2884 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
2885 driver_dump->trace_entry.hdr.len =
2886 sizeof(struct ipr_dump_trace_entry) -
2887 sizeof(struct ipr_dump_entry_header);
2888 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2889 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
2890 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
2891 driver_dump->hdr.num_entries++;
2892}
2893
2894/**
2895 * ipr_dump_location_data - Fill in the IOA location in the dump.
2896 * @ioa_cfg: ioa config struct
2897 * @driver_dump: driver dump struct
2898 *
2899 * Return value:
2900 * nothing
2901 **/
2902static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
2903 struct ipr_driver_dump *driver_dump)
2904{
2905 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
2906 driver_dump->location_entry.hdr.len =
2907 sizeof(struct ipr_dump_location_entry) -
2908 sizeof(struct ipr_dump_entry_header);
2909 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2910 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
Kay Sievers71610f52008-12-03 22:41:36 +01002911 strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 driver_dump->hdr.num_entries++;
2913}
2914
2915/**
2916 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2917 * @ioa_cfg: ioa config struct
2918 * @dump: dump struct
2919 *
2920 * Return value:
2921 * nothing
2922 **/
2923static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
2924{
2925 unsigned long start_addr, sdt_word;
2926 unsigned long lock_flags = 0;
2927 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
2928 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002929 u32 num_entries, max_num_entries, start_off, end_off;
2930 u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 struct ipr_sdt *sdt;
Wayne Boyerdcbad002010-02-19 13:24:14 -08002932 int valid = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 int i;
2934
2935 ENTER;
2936
2937 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2938
Brian King41e9a692011-09-21 08:51:11 -05002939 if (ioa_cfg->sdt_state != READ_DUMP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2941 return;
2942 }
2943
Wayne Boyer110def82010-11-04 09:36:16 -07002944 if (ioa_cfg->sis64) {
2945 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2946 ssleep(IPR_DUMP_DELAY_SECONDS);
2947 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2948 }
2949
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 start_addr = readl(ioa_cfg->ioa_mailbox);
2951
Wayne Boyerdcbad002010-02-19 13:24:14 -08002952 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 dev_err(&ioa_cfg->pdev->dev,
2954 "Invalid dump table format: %lx\n", start_addr);
2955 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2956 return;
2957 }
2958
2959 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
2960
2961 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
2962
2963 /* Initialize the overall dump header */
2964 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
2965 driver_dump->hdr.num_entries = 1;
2966 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
2967 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
2968 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
2969 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
2970
2971 ipr_dump_version_data(ioa_cfg, driver_dump);
2972 ipr_dump_location_data(ioa_cfg, driver_dump);
2973 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
2974 ipr_dump_trace_data(ioa_cfg, driver_dump);
2975
2976 /* Update dump_header */
2977 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
2978
2979 /* IOA Dump entry */
2980 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 ioa_dump->hdr.len = 0;
2982 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2983 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
2984
2985 /* First entries in sdt are actually a list of dump addresses and
2986 lengths to gather the real dump data. sdt represents the pointer
2987 to the ioa generated dump table. Dump data will be extracted based
2988 on entries in this table */
2989 sdt = &ioa_dump->sdt;
2990
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002991 if (ioa_cfg->sis64) {
2992 max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
2993 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2994 } else {
2995 max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
2996 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2997 }
2998
2999 bytes_to_copy = offsetof(struct ipr_sdt, entry) +
3000 (max_num_entries * sizeof(struct ipr_sdt_entry));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003002 bytes_to_copy / sizeof(__be32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003
3004 /* Smart Dump table is ready to use and the first entry is valid */
Wayne Boyerdcbad002010-02-19 13:24:14 -08003005 if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
3006 (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 dev_err(&ioa_cfg->pdev->dev,
3008 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
3009 rc, be32_to_cpu(sdt->hdr.state));
3010 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
3011 ioa_cfg->sdt_state = DUMP_OBTAINED;
3012 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3013 return;
3014 }
3015
3016 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
3017
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003018 if (num_entries > max_num_entries)
3019 num_entries = max_num_entries;
3020
3021 /* Update dump length to the actual data to be copied */
3022 dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
3023 if (ioa_cfg->sis64)
3024 dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
3025 else
3026 dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027
3028 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3029
3030 for (i = 0; i < num_entries; i++) {
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003031 if (ioa_dump->hdr.len > max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3033 break;
3034 }
3035
3036 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
Wayne Boyerdcbad002010-02-19 13:24:14 -08003037 sdt_word = be32_to_cpu(sdt->entry[i].start_token);
3038 if (ioa_cfg->sis64)
3039 bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
3040 else {
3041 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
3042 end_off = be32_to_cpu(sdt->entry[i].end_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
Wayne Boyerdcbad002010-02-19 13:24:14 -08003044 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
3045 bytes_to_copy = end_off - start_off;
3046 else
3047 valid = 0;
3048 }
3049 if (valid) {
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003050 if (bytes_to_copy > max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
3052 continue;
3053 }
3054
3055 /* Copy data from adapter to driver buffers */
3056 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
3057 bytes_to_copy);
3058
3059 ioa_dump->hdr.len += bytes_copied;
3060
3061 if (bytes_copied != bytes_to_copy) {
3062 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3063 break;
3064 }
3065 }
3066 }
3067 }
3068
3069 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
3070
3071 /* Update dump_header */
3072 driver_dump->hdr.len += ioa_dump->hdr.len;
3073 wmb();
3074 ioa_cfg->sdt_state = DUMP_OBTAINED;
3075 LEAVE;
3076}
3077
3078#else
3079#define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
3080#endif
3081
3082/**
3083 * ipr_release_dump - Free adapter dump memory
3084 * @kref: kref struct
3085 *
3086 * Return value:
3087 * nothing
3088 **/
3089static void ipr_release_dump(struct kref *kref)
3090{
3091 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
3092 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
3093 unsigned long lock_flags = 0;
3094 int i;
3095
3096 ENTER;
3097 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3098 ioa_cfg->dump = NULL;
3099 ioa_cfg->sdt_state = INACTIVE;
3100 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3101
3102 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
3103 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
3104
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003105 vfree(dump->ioa_dump.ioa_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 kfree(dump);
3107 LEAVE;
3108}
3109
3110/**
3111 * ipr_worker_thread - Worker thread
David Howellsc4028952006-11-22 14:57:56 +00003112 * @work: ioa config struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 *
3114 * Called at task level from a work thread. This function takes care
3115 * of adding and removing device from the mid-layer as configuration
3116 * changes are detected by the adapter.
3117 *
3118 * Return value:
3119 * nothing
3120 **/
David Howellsc4028952006-11-22 14:57:56 +00003121static void ipr_worker_thread(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122{
3123 unsigned long lock_flags;
3124 struct ipr_resource_entry *res;
3125 struct scsi_device *sdev;
3126 struct ipr_dump *dump;
David Howellsc4028952006-11-22 14:57:56 +00003127 struct ipr_ioa_cfg *ioa_cfg =
3128 container_of(work, struct ipr_ioa_cfg, work_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 u8 bus, target, lun;
3130 int did_work;
3131
3132 ENTER;
3133 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3134
Brian King41e9a692011-09-21 08:51:11 -05003135 if (ioa_cfg->sdt_state == READ_DUMP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 dump = ioa_cfg->dump;
3137 if (!dump) {
3138 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3139 return;
3140 }
3141 kref_get(&dump->kref);
3142 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3143 ipr_get_ioa_dump(ioa_cfg, dump);
3144 kref_put(&dump->kref, ipr_release_dump);
3145
3146 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King4c647e92011-10-15 09:08:56 -05003147 if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3149 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3150 return;
3151 }
3152
3153restart:
3154 do {
3155 did_work = 0;
3156 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
3157 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3158 return;
3159 }
3160
3161 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3162 if (res->del_from_ml && res->sdev) {
3163 did_work = 1;
3164 sdev = res->sdev;
3165 if (!scsi_device_get(sdev)) {
Kleber Sacilotto de Souza5767a1c2011-02-14 20:19:31 -02003166 if (!res->add_to_ml)
3167 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
3168 else
3169 res->del_from_ml = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3171 scsi_remove_device(sdev);
3172 scsi_device_put(sdev);
3173 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3174 }
3175 break;
3176 }
3177 }
3178 } while(did_work);
3179
3180 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3181 if (res->add_to_ml) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08003182 bus = res->bus;
3183 target = res->target;
3184 lun = res->lun;
Brian King1121b792006-03-29 09:37:16 -06003185 res->add_to_ml = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3187 scsi_add_device(ioa_cfg->host, bus, target, lun);
3188 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3189 goto restart;
3190 }
3191 }
3192
3193 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Tony Jonesee959b02008-02-22 00:13:36 +01003194 kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 LEAVE;
3196}
3197
3198#ifdef CONFIG_SCSI_IPR_TRACE
3199/**
3200 * ipr_read_trace - Dump the adapter trace
Chris Wright2c3c8be2010-05-12 18:28:57 -07003201 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08003203 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 * @buf: buffer
3205 * @off: offset
3206 * @count: buffer size
3207 *
3208 * Return value:
3209 * number of bytes printed to buffer
3210 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07003211static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08003212 struct bin_attribute *bin_attr,
3213 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214{
Tony Jonesee959b02008-02-22 00:13:36 +01003215 struct device *dev = container_of(kobj, struct device, kobj);
3216 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3218 unsigned long lock_flags = 0;
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003219 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220
3221 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003222 ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
3223 IPR_TRACE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003225
3226 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227}
3228
3229static struct bin_attribute ipr_trace_attr = {
3230 .attr = {
3231 .name = "trace",
3232 .mode = S_IRUGO,
3233 },
3234 .size = 0,
3235 .read = ipr_read_trace,
3236};
3237#endif
3238
3239/**
3240 * ipr_show_fw_version - Show the firmware version
Tony Jonesee959b02008-02-22 00:13:36 +01003241 * @dev: class device struct
3242 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 *
3244 * Return value:
3245 * number of bytes printed to buffer
3246 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003247static ssize_t ipr_show_fw_version(struct device *dev,
3248 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249{
Tony Jonesee959b02008-02-22 00:13:36 +01003250 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3252 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
3253 unsigned long lock_flags = 0;
3254 int len;
3255
3256 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3257 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
3258 ucode_vpd->major_release, ucode_vpd->card_type,
3259 ucode_vpd->minor_release[0],
3260 ucode_vpd->minor_release[1]);
3261 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3262 return len;
3263}
3264
Tony Jonesee959b02008-02-22 00:13:36 +01003265static struct device_attribute ipr_fw_version_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 .attr = {
3267 .name = "fw_version",
3268 .mode = S_IRUGO,
3269 },
3270 .show = ipr_show_fw_version,
3271};
3272
3273/**
3274 * ipr_show_log_level - Show the adapter's error logging level
Tony Jonesee959b02008-02-22 00:13:36 +01003275 * @dev: class device struct
3276 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 *
3278 * Return value:
3279 * number of bytes printed to buffer
3280 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003281static ssize_t ipr_show_log_level(struct device *dev,
3282 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283{
Tony Jonesee959b02008-02-22 00:13:36 +01003284 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3286 unsigned long lock_flags = 0;
3287 int len;
3288
3289 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3290 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
3291 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3292 return len;
3293}
3294
3295/**
3296 * ipr_store_log_level - Change the adapter's error logging level
Tony Jonesee959b02008-02-22 00:13:36 +01003297 * @dev: class device struct
3298 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 *
3300 * Return value:
3301 * number of bytes printed to buffer
3302 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003303static ssize_t ipr_store_log_level(struct device *dev,
3304 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 const char *buf, size_t count)
3306{
Tony Jonesee959b02008-02-22 00:13:36 +01003307 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3309 unsigned long lock_flags = 0;
3310
3311 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3312 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
3313 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3314 return strlen(buf);
3315}
3316
Tony Jonesee959b02008-02-22 00:13:36 +01003317static struct device_attribute ipr_log_level_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 .attr = {
3319 .name = "log_level",
3320 .mode = S_IRUGO | S_IWUSR,
3321 },
3322 .show = ipr_show_log_level,
3323 .store = ipr_store_log_level
3324};
3325
3326/**
3327 * ipr_store_diagnostics - IOA Diagnostics interface
Tony Jonesee959b02008-02-22 00:13:36 +01003328 * @dev: device struct
3329 * @buf: buffer
3330 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 *
3332 * This function will reset the adapter and wait a reasonable
3333 * amount of time for any errors that the adapter might log.
3334 *
3335 * Return value:
3336 * count on success / other on failure
3337 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003338static ssize_t ipr_store_diagnostics(struct device *dev,
3339 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 const char *buf, size_t count)
3341{
Tony Jonesee959b02008-02-22 00:13:36 +01003342 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3344 unsigned long lock_flags = 0;
3345 int rc = count;
3346
3347 if (!capable(CAP_SYS_ADMIN))
3348 return -EACCES;
3349
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King970ea292007-04-26 16:00:06 -05003351 while(ioa_cfg->in_reset_reload) {
3352 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3353 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3354 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3355 }
3356
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 ioa_cfg->errors_logged = 0;
3358 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3359
3360 if (ioa_cfg->in_reset_reload) {
3361 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3362 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3363
3364 /* Wait for a second for any errors to be logged */
3365 msleep(1000);
3366 } else {
3367 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3368 return -EIO;
3369 }
3370
3371 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3372 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
3373 rc = -EIO;
3374 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3375
3376 return rc;
3377}
3378
Tony Jonesee959b02008-02-22 00:13:36 +01003379static struct device_attribute ipr_diagnostics_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 .attr = {
3381 .name = "run_diagnostics",
3382 .mode = S_IWUSR,
3383 },
3384 .store = ipr_store_diagnostics
3385};
3386
3387/**
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003388 * ipr_show_adapter_state - Show the adapter's state
Tony Jonesee959b02008-02-22 00:13:36 +01003389 * @class_dev: device struct
3390 * @buf: buffer
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003391 *
3392 * Return value:
3393 * number of bytes printed to buffer
3394 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003395static ssize_t ipr_show_adapter_state(struct device *dev,
3396 struct device_attribute *attr, char *buf)
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003397{
Tony Jonesee959b02008-02-22 00:13:36 +01003398 struct Scsi_Host *shost = class_to_shost(dev);
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003399 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3400 unsigned long lock_flags = 0;
3401 int len;
3402
3403 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3404 if (ioa_cfg->ioa_is_dead)
3405 len = snprintf(buf, PAGE_SIZE, "offline\n");
3406 else
3407 len = snprintf(buf, PAGE_SIZE, "online\n");
3408 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3409 return len;
3410}
3411
3412/**
3413 * ipr_store_adapter_state - Change adapter state
Tony Jonesee959b02008-02-22 00:13:36 +01003414 * @dev: device struct
3415 * @buf: buffer
3416 * @count: buffer size
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003417 *
3418 * This function will change the adapter's state.
3419 *
3420 * Return value:
3421 * count on success / other on failure
3422 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003423static ssize_t ipr_store_adapter_state(struct device *dev,
3424 struct device_attribute *attr,
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003425 const char *buf, size_t count)
3426{
Tony Jonesee959b02008-02-22 00:13:36 +01003427 struct Scsi_Host *shost = class_to_shost(dev);
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003428 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3429 unsigned long lock_flags;
3430 int result = count;
3431
3432 if (!capable(CAP_SYS_ADMIN))
3433 return -EACCES;
3434
3435 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3436 if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
3437 ioa_cfg->ioa_is_dead = 0;
3438 ioa_cfg->reset_retries = 0;
3439 ioa_cfg->in_ioa_bringdown = 0;
3440 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3441 }
3442 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3443 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3444
3445 return result;
3446}
3447
Tony Jonesee959b02008-02-22 00:13:36 +01003448static struct device_attribute ipr_ioa_state_attr = {
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003449 .attr = {
Brian King49dd0962008-04-28 17:36:20 -05003450 .name = "online_state",
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003451 .mode = S_IRUGO | S_IWUSR,
3452 },
3453 .show = ipr_show_adapter_state,
3454 .store = ipr_store_adapter_state
3455};
3456
3457/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 * ipr_store_reset_adapter - Reset the adapter
Tony Jonesee959b02008-02-22 00:13:36 +01003459 * @dev: device struct
3460 * @buf: buffer
3461 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 *
3463 * This function will reset the adapter.
3464 *
3465 * Return value:
3466 * count on success / other on failure
3467 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003468static ssize_t ipr_store_reset_adapter(struct device *dev,
3469 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 const char *buf, size_t count)
3471{
Tony Jonesee959b02008-02-22 00:13:36 +01003472 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3474 unsigned long lock_flags;
3475 int result = count;
3476
3477 if (!capable(CAP_SYS_ADMIN))
3478 return -EACCES;
3479
3480 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3481 if (!ioa_cfg->in_reset_reload)
3482 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3483 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3484 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3485
3486 return result;
3487}
3488
Tony Jonesee959b02008-02-22 00:13:36 +01003489static struct device_attribute ipr_ioa_reset_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 .attr = {
3491 .name = "reset_host",
3492 .mode = S_IWUSR,
3493 },
3494 .store = ipr_store_reset_adapter
3495};
3496
3497/**
3498 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3499 * @buf_len: buffer length
3500 *
3501 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3502 * list to use for microcode download
3503 *
3504 * Return value:
3505 * pointer to sglist / NULL on failure
3506 **/
3507static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
3508{
3509 int sg_size, order, bsize_elem, num_elem, i, j;
3510 struct ipr_sglist *sglist;
3511 struct scatterlist *scatterlist;
3512 struct page *page;
3513
3514 /* Get the minimum size per scatter/gather element */
3515 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
3516
3517 /* Get the actual size per element */
3518 order = get_order(sg_size);
3519
3520 /* Determine the actual number of bytes per element */
3521 bsize_elem = PAGE_SIZE * (1 << order);
3522
3523 /* Determine the actual number of sg entries needed */
3524 if (buf_len % bsize_elem)
3525 num_elem = (buf_len / bsize_elem) + 1;
3526 else
3527 num_elem = buf_len / bsize_elem;
3528
3529 /* Allocate a scatter/gather list for the DMA */
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06003530 sglist = kzalloc(sizeof(struct ipr_sglist) +
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 (sizeof(struct scatterlist) * (num_elem - 1)),
3532 GFP_KERNEL);
3533
3534 if (sglist == NULL) {
3535 ipr_trace;
3536 return NULL;
3537 }
3538
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 scatterlist = sglist->scatterlist;
Jens Axboe45711f12007-10-22 21:19:53 +02003540 sg_init_table(scatterlist, num_elem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541
3542 sglist->order = order;
3543 sglist->num_sg = num_elem;
3544
3545 /* Allocate a bunch of sg elements */
3546 for (i = 0; i < num_elem; i++) {
3547 page = alloc_pages(GFP_KERNEL, order);
3548 if (!page) {
3549 ipr_trace;
3550
3551 /* Free up what we already allocated */
3552 for (j = i - 1; j >= 0; j--)
Jens Axboe45711f12007-10-22 21:19:53 +02003553 __free_pages(sg_page(&scatterlist[j]), order);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 kfree(sglist);
3555 return NULL;
3556 }
3557
Jens Axboe642f149032007-10-24 11:20:47 +02003558 sg_set_page(&scatterlist[i], page, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 }
3560
3561 return sglist;
3562}
3563
3564/**
3565 * ipr_free_ucode_buffer - Frees a microcode download buffer
3566 * @p_dnld: scatter/gather list pointer
3567 *
3568 * Free a DMA'able ucode download buffer previously allocated with
3569 * ipr_alloc_ucode_buffer
3570 *
3571 * Return value:
3572 * nothing
3573 **/
3574static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
3575{
3576 int i;
3577
3578 for (i = 0; i < sglist->num_sg; i++)
Jens Axboe45711f12007-10-22 21:19:53 +02003579 __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580
3581 kfree(sglist);
3582}
3583
3584/**
3585 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3586 * @sglist: scatter/gather list pointer
3587 * @buffer: buffer pointer
3588 * @len: buffer length
3589 *
3590 * Copy a microcode image from a user buffer into a buffer allocated by
3591 * ipr_alloc_ucode_buffer
3592 *
3593 * Return value:
3594 * 0 on success / other on failure
3595 **/
3596static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
3597 u8 *buffer, u32 len)
3598{
3599 int bsize_elem, i, result = 0;
3600 struct scatterlist *scatterlist;
3601 void *kaddr;
3602
3603 /* Determine the actual number of bytes per element */
3604 bsize_elem = PAGE_SIZE * (1 << sglist->order);
3605
3606 scatterlist = sglist->scatterlist;
3607
3608 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
Jens Axboe45711f12007-10-22 21:19:53 +02003609 struct page *page = sg_page(&scatterlist[i]);
3610
3611 kaddr = kmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 memcpy(kaddr, buffer, bsize_elem);
Jens Axboe45711f12007-10-22 21:19:53 +02003613 kunmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614
3615 scatterlist[i].length = bsize_elem;
3616
3617 if (result != 0) {
3618 ipr_trace;
3619 return result;
3620 }
3621 }
3622
3623 if (len % bsize_elem) {
Jens Axboe45711f12007-10-22 21:19:53 +02003624 struct page *page = sg_page(&scatterlist[i]);
3625
3626 kaddr = kmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 memcpy(kaddr, buffer, len % bsize_elem);
Jens Axboe45711f12007-10-22 21:19:53 +02003628 kunmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629
3630 scatterlist[i].length = len % bsize_elem;
3631 }
3632
3633 sglist->buffer_len = len;
3634 return result;
3635}
3636
3637/**
Wayne Boyera32c0552010-02-19 13:23:36 -08003638 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3639 * @ipr_cmd: ipr command struct
3640 * @sglist: scatter/gather list
3641 *
3642 * Builds a microcode download IOA data list (IOADL).
3643 *
3644 **/
3645static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
3646 struct ipr_sglist *sglist)
3647{
3648 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3649 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
3650 struct scatterlist *scatterlist = sglist->scatterlist;
3651 int i;
3652
3653 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3654 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3655 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3656
3657 ioarcb->ioadl_len =
3658 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
3659 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3660 ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
3661 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
3662 ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
3663 }
3664
3665 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3666}
3667
3668/**
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003669 * ipr_build_ucode_ioadl - Build a microcode download IOADL
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 * @ipr_cmd: ipr command struct
3671 * @sglist: scatter/gather list
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 *
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003673 * Builds a microcode download IOA data list (IOADL).
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 **/
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003676static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
3677 struct ipr_sglist *sglist)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08003680 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 struct scatterlist *scatterlist = sglist->scatterlist;
3682 int i;
3683
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003684 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08003686 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3687
3688 ioarcb->ioadl_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3690
3691 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3692 ioadl[i].flags_and_data_len =
3693 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
3694 ioadl[i].address =
3695 cpu_to_be32(sg_dma_address(&scatterlist[i]));
3696 }
3697
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003698 ioadl[i-1].flags_and_data_len |=
3699 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3700}
3701
3702/**
3703 * ipr_update_ioa_ucode - Update IOA's microcode
3704 * @ioa_cfg: ioa config struct
3705 * @sglist: scatter/gather list
3706 *
3707 * Initiate an adapter reset to update the IOA's microcode
3708 *
3709 * Return value:
3710 * 0 on success / -EIO on failure
3711 **/
3712static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3713 struct ipr_sglist *sglist)
3714{
3715 unsigned long lock_flags;
3716
3717 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King970ea292007-04-26 16:00:06 -05003718 while(ioa_cfg->in_reset_reload) {
3719 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3720 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3721 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3722 }
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003723
3724 if (ioa_cfg->ucode_sglist) {
3725 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3726 dev_err(&ioa_cfg->pdev->dev,
3727 "Microcode download already in progress\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 return -EIO;
3729 }
3730
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003731 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
3732 sglist->num_sg, DMA_TO_DEVICE);
3733
3734 if (!sglist->num_dma_sg) {
3735 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3736 dev_err(&ioa_cfg->pdev->dev,
3737 "Failed to map microcode download buffer!\n");
3738 return -EIO;
3739 }
3740
3741 ioa_cfg->ucode_sglist = sglist;
3742 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3743 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3744 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3745
3746 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3747 ioa_cfg->ucode_sglist = NULL;
3748 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 return 0;
3750}
3751
3752/**
3753 * ipr_store_update_fw - Update the firmware on the adapter
Tony Jonesee959b02008-02-22 00:13:36 +01003754 * @class_dev: device struct
3755 * @buf: buffer
3756 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 *
3758 * This function will update the firmware on the adapter.
3759 *
3760 * Return value:
3761 * count on success / other on failure
3762 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003763static ssize_t ipr_store_update_fw(struct device *dev,
3764 struct device_attribute *attr,
3765 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766{
Tony Jonesee959b02008-02-22 00:13:36 +01003767 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3769 struct ipr_ucode_image_header *image_hdr;
3770 const struct firmware *fw_entry;
3771 struct ipr_sglist *sglist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 char fname[100];
3773 char *src;
3774 int len, result, dnld_size;
3775
3776 if (!capable(CAP_SYS_ADMIN))
3777 return -EACCES;
3778
3779 len = snprintf(fname, 99, "%s", buf);
3780 fname[len-1] = '\0';
3781
3782 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3783 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3784 return -EIO;
3785 }
3786
3787 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
3788
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
3790 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
3791 sglist = ipr_alloc_ucode_buffer(dnld_size);
3792
3793 if (!sglist) {
3794 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
3795 release_firmware(fw_entry);
3796 return -ENOMEM;
3797 }
3798
3799 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
3800
3801 if (result) {
3802 dev_err(&ioa_cfg->pdev->dev,
3803 "Microcode buffer copy to DMA buffer failed\n");
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003804 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 }
3806
Wayne Boyer14ed9cc2011-10-03 20:54:37 -07003807 ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
3808
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003809 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003811 if (!result)
3812 result = count;
3813out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 ipr_free_ucode_buffer(sglist);
3815 release_firmware(fw_entry);
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003816 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817}
3818
Tony Jonesee959b02008-02-22 00:13:36 +01003819static struct device_attribute ipr_update_fw_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 .attr = {
3821 .name = "update_fw",
3822 .mode = S_IWUSR,
3823 },
3824 .store = ipr_store_update_fw
3825};
3826
Wayne Boyer75576bb2010-07-14 10:50:14 -07003827/**
3828 * ipr_show_fw_type - Show the adapter's firmware type.
3829 * @dev: class device struct
3830 * @buf: buffer
3831 *
3832 * Return value:
3833 * number of bytes printed to buffer
3834 **/
3835static ssize_t ipr_show_fw_type(struct device *dev,
3836 struct device_attribute *attr, char *buf)
3837{
3838 struct Scsi_Host *shost = class_to_shost(dev);
3839 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3840 unsigned long lock_flags = 0;
3841 int len;
3842
3843 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3844 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
3845 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3846 return len;
3847}
3848
3849static struct device_attribute ipr_ioa_fw_type_attr = {
3850 .attr = {
3851 .name = "fw_type",
3852 .mode = S_IRUGO,
3853 },
3854 .show = ipr_show_fw_type
3855};
3856
Tony Jonesee959b02008-02-22 00:13:36 +01003857static struct device_attribute *ipr_ioa_attrs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 &ipr_fw_version_attr,
3859 &ipr_log_level_attr,
3860 &ipr_diagnostics_attr,
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003861 &ipr_ioa_state_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 &ipr_ioa_reset_attr,
3863 &ipr_update_fw_attr,
Wayne Boyer75576bb2010-07-14 10:50:14 -07003864 &ipr_ioa_fw_type_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 NULL,
3866};
3867
3868#ifdef CONFIG_SCSI_IPR_DUMP
3869/**
3870 * ipr_read_dump - Dump the adapter
Chris Wright2c3c8be2010-05-12 18:28:57 -07003871 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08003873 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 * @buf: buffer
3875 * @off: offset
3876 * @count: buffer size
3877 *
3878 * Return value:
3879 * number of bytes printed to buffer
3880 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07003881static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08003882 struct bin_attribute *bin_attr,
3883 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884{
Tony Jonesee959b02008-02-22 00:13:36 +01003885 struct device *cdev = container_of(kobj, struct device, kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 struct Scsi_Host *shost = class_to_shost(cdev);
3887 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3888 struct ipr_dump *dump;
3889 unsigned long lock_flags = 0;
3890 char *src;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003891 int len, sdt_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 size_t rc = count;
3893
3894 if (!capable(CAP_SYS_ADMIN))
3895 return -EACCES;
3896
3897 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3898 dump = ioa_cfg->dump;
3899
3900 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
3901 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3902 return 0;
3903 }
3904 kref_get(&dump->kref);
3905 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3906
3907 if (off > dump->driver_dump.hdr.len) {
3908 kref_put(&dump->kref, ipr_release_dump);
3909 return 0;
3910 }
3911
3912 if (off + count > dump->driver_dump.hdr.len) {
3913 count = dump->driver_dump.hdr.len - off;
3914 rc = count;
3915 }
3916
3917 if (count && off < sizeof(dump->driver_dump)) {
3918 if (off + count > sizeof(dump->driver_dump))
3919 len = sizeof(dump->driver_dump) - off;
3920 else
3921 len = count;
3922 src = (u8 *)&dump->driver_dump + off;
3923 memcpy(buf, src, len);
3924 buf += len;
3925 off += len;
3926 count -= len;
3927 }
3928
3929 off -= sizeof(dump->driver_dump);
3930
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003931 if (ioa_cfg->sis64)
3932 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
3933 (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
3934 sizeof(struct ipr_sdt_entry));
3935 else
3936 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
3937 (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
3938
3939 if (count && off < sdt_end) {
3940 if (off + count > sdt_end)
3941 len = sdt_end - off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 else
3943 len = count;
3944 src = (u8 *)&dump->ioa_dump + off;
3945 memcpy(buf, src, len);
3946 buf += len;
3947 off += len;
3948 count -= len;
3949 }
3950
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003951 off -= sdt_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952
3953 while (count) {
3954 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
3955 len = PAGE_ALIGN(off) - off;
3956 else
3957 len = count;
3958 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
3959 src += off & ~PAGE_MASK;
3960 memcpy(buf, src, len);
3961 buf += len;
3962 off += len;
3963 count -= len;
3964 }
3965
3966 kref_put(&dump->kref, ipr_release_dump);
3967 return rc;
3968}
3969
3970/**
3971 * ipr_alloc_dump - Prepare for adapter dump
3972 * @ioa_cfg: ioa config struct
3973 *
3974 * Return value:
3975 * 0 on success / other on failure
3976 **/
3977static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
3978{
3979 struct ipr_dump *dump;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003980 __be32 **ioa_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 unsigned long lock_flags = 0;
3982
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06003983 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984
3985 if (!dump) {
3986 ipr_err("Dump memory allocation failed\n");
3987 return -ENOMEM;
3988 }
3989
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003990 if (ioa_cfg->sis64)
3991 ioa_data = vmalloc(IPR_FMT3_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
3992 else
3993 ioa_data = vmalloc(IPR_FMT2_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
3994
3995 if (!ioa_data) {
3996 ipr_err("Dump memory allocation failed\n");
3997 kfree(dump);
3998 return -ENOMEM;
3999 }
4000
4001 dump->ioa_dump.ioa_data = ioa_data;
4002
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 kref_init(&dump->kref);
4004 dump->ioa_cfg = ioa_cfg;
4005
4006 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4007
4008 if (INACTIVE != ioa_cfg->sdt_state) {
4009 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004010 vfree(dump->ioa_dump.ioa_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 kfree(dump);
4012 return 0;
4013 }
4014
4015 ioa_cfg->dump = dump;
4016 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
4017 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
4018 ioa_cfg->dump_taken = 1;
4019 schedule_work(&ioa_cfg->work_q);
4020 }
4021 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4022
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023 return 0;
4024}
4025
4026/**
4027 * ipr_free_dump - Free adapter dump memory
4028 * @ioa_cfg: ioa config struct
4029 *
4030 * Return value:
4031 * 0 on success / other on failure
4032 **/
4033static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
4034{
4035 struct ipr_dump *dump;
4036 unsigned long lock_flags = 0;
4037
4038 ENTER;
4039
4040 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4041 dump = ioa_cfg->dump;
4042 if (!dump) {
4043 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4044 return 0;
4045 }
4046
4047 ioa_cfg->dump = NULL;
4048 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4049
4050 kref_put(&dump->kref, ipr_release_dump);
4051
4052 LEAVE;
4053 return 0;
4054}
4055
4056/**
4057 * ipr_write_dump - Setup dump state of adapter
Chris Wright2c3c8be2010-05-12 18:28:57 -07004058 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08004060 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 * @buf: buffer
4062 * @off: offset
4063 * @count: buffer size
4064 *
4065 * Return value:
4066 * number of bytes printed to buffer
4067 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07004068static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08004069 struct bin_attribute *bin_attr,
4070 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071{
Tony Jonesee959b02008-02-22 00:13:36 +01004072 struct device *cdev = container_of(kobj, struct device, kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 struct Scsi_Host *shost = class_to_shost(cdev);
4074 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4075 int rc;
4076
4077 if (!capable(CAP_SYS_ADMIN))
4078 return -EACCES;
4079
4080 if (buf[0] == '1')
4081 rc = ipr_alloc_dump(ioa_cfg);
4082 else if (buf[0] == '0')
4083 rc = ipr_free_dump(ioa_cfg);
4084 else
4085 return -EINVAL;
4086
4087 if (rc)
4088 return rc;
4089 else
4090 return count;
4091}
4092
4093static struct bin_attribute ipr_dump_attr = {
4094 .attr = {
4095 .name = "dump",
4096 .mode = S_IRUSR | S_IWUSR,
4097 },
4098 .size = 0,
4099 .read = ipr_read_dump,
4100 .write = ipr_write_dump
4101};
4102#else
4103static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
4104#endif
4105
4106/**
4107 * ipr_change_queue_depth - Change the device's queue depth
4108 * @sdev: scsi device struct
4109 * @qdepth: depth to set
Mike Christiee881a172009-10-15 17:46:39 -07004110 * @reason: calling context
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 *
4112 * Return value:
4113 * actual depth set
4114 **/
Mike Christiee881a172009-10-15 17:46:39 -07004115static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth,
4116 int reason)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117{
Brian King35a39692006-09-25 12:39:20 -05004118 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4119 struct ipr_resource_entry *res;
4120 unsigned long lock_flags = 0;
4121
Mike Christiee881a172009-10-15 17:46:39 -07004122 if (reason != SCSI_QDEPTH_DEFAULT)
4123 return -EOPNOTSUPP;
4124
Brian King35a39692006-09-25 12:39:20 -05004125 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4126 res = (struct ipr_resource_entry *)sdev->hostdata;
4127
4128 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
4129 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
4130 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4131
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
4133 return sdev->queue_depth;
4134}
4135
4136/**
4137 * ipr_change_queue_type - Change the device's queue type
4138 * @dsev: scsi device struct
4139 * @tag_type: type of tags to use
4140 *
4141 * Return value:
4142 * actual queue type set
4143 **/
4144static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
4145{
4146 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4147 struct ipr_resource_entry *res;
4148 unsigned long lock_flags = 0;
4149
4150 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4151 res = (struct ipr_resource_entry *)sdev->hostdata;
4152
4153 if (res) {
4154 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
4155 /*
4156 * We don't bother quiescing the device here since the
4157 * adapter firmware does it for us.
4158 */
4159 scsi_set_tag_type(sdev, tag_type);
4160
4161 if (tag_type)
4162 scsi_activate_tcq(sdev, sdev->queue_depth);
4163 else
4164 scsi_deactivate_tcq(sdev, sdev->queue_depth);
4165 } else
4166 tag_type = 0;
4167 } else
4168 tag_type = 0;
4169
4170 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4171 return tag_type;
4172}
4173
4174/**
4175 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4176 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004177 * @attr: device attribute structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 * @buf: buffer
4179 *
4180 * Return value:
4181 * number of bytes printed to buffer
4182 **/
Yani Ioannou10523b32005-05-17 06:43:37 -04004183static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184{
4185 struct scsi_device *sdev = to_scsi_device(dev);
4186 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4187 struct ipr_resource_entry *res;
4188 unsigned long lock_flags = 0;
4189 ssize_t len = -ENXIO;
4190
4191 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4192 res = (struct ipr_resource_entry *)sdev->hostdata;
4193 if (res)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004194 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4196 return len;
4197}
4198
4199static struct device_attribute ipr_adapter_handle_attr = {
4200 .attr = {
4201 .name = "adapter_handle",
4202 .mode = S_IRUSR,
4203 },
4204 .show = ipr_show_adapter_handle
4205};
4206
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004207/**
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004208 * ipr_show_resource_path - Show the resource path or the resource address for
4209 * this device.
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004210 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004211 * @attr: device attribute structure
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004212 * @buf: buffer
4213 *
4214 * Return value:
4215 * number of bytes printed to buffer
4216 **/
4217static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
4218{
4219 struct scsi_device *sdev = to_scsi_device(dev);
4220 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4221 struct ipr_resource_entry *res;
4222 unsigned long lock_flags = 0;
4223 ssize_t len = -ENXIO;
4224 char buffer[IPR_MAX_RES_PATH_LENGTH];
4225
4226 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4227 res = (struct ipr_resource_entry *)sdev->hostdata;
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004228 if (res && ioa_cfg->sis64)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004229 len = snprintf(buf, PAGE_SIZE, "%s\n",
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004230 ipr_format_res_path(res->res_path, buffer,
4231 sizeof(buffer)));
4232 else if (res)
4233 len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
4234 res->bus, res->target, res->lun);
4235
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004236 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4237 return len;
4238}
4239
4240static struct device_attribute ipr_resource_path_attr = {
4241 .attr = {
4242 .name = "resource_path",
Wayne Boyer75576bb2010-07-14 10:50:14 -07004243 .mode = S_IRUGO,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004244 },
4245 .show = ipr_show_resource_path
4246};
4247
Wayne Boyer75576bb2010-07-14 10:50:14 -07004248/**
Wayne Boyer46d74562010-08-11 07:15:17 -07004249 * ipr_show_device_id - Show the device_id for this device.
4250 * @dev: device struct
4251 * @attr: device attribute structure
4252 * @buf: buffer
4253 *
4254 * Return value:
4255 * number of bytes printed to buffer
4256 **/
4257static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
4258{
4259 struct scsi_device *sdev = to_scsi_device(dev);
4260 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4261 struct ipr_resource_entry *res;
4262 unsigned long lock_flags = 0;
4263 ssize_t len = -ENXIO;
4264
4265 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4266 res = (struct ipr_resource_entry *)sdev->hostdata;
4267 if (res && ioa_cfg->sis64)
4268 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->dev_id);
4269 else if (res)
4270 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
4271
4272 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4273 return len;
4274}
4275
4276static struct device_attribute ipr_device_id_attr = {
4277 .attr = {
4278 .name = "device_id",
4279 .mode = S_IRUGO,
4280 },
4281 .show = ipr_show_device_id
4282};
4283
4284/**
Wayne Boyer75576bb2010-07-14 10:50:14 -07004285 * ipr_show_resource_type - Show the resource type for this device.
4286 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004287 * @attr: device attribute structure
Wayne Boyer75576bb2010-07-14 10:50:14 -07004288 * @buf: buffer
4289 *
4290 * Return value:
4291 * number of bytes printed to buffer
4292 **/
4293static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
4294{
4295 struct scsi_device *sdev = to_scsi_device(dev);
4296 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4297 struct ipr_resource_entry *res;
4298 unsigned long lock_flags = 0;
4299 ssize_t len = -ENXIO;
4300
4301 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4302 res = (struct ipr_resource_entry *)sdev->hostdata;
4303
4304 if (res)
4305 len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
4306
4307 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4308 return len;
4309}
4310
4311static struct device_attribute ipr_resource_type_attr = {
4312 .attr = {
4313 .name = "resource_type",
4314 .mode = S_IRUGO,
4315 },
4316 .show = ipr_show_resource_type
4317};
4318
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319static struct device_attribute *ipr_dev_attrs[] = {
4320 &ipr_adapter_handle_attr,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004321 &ipr_resource_path_attr,
Wayne Boyer46d74562010-08-11 07:15:17 -07004322 &ipr_device_id_attr,
Wayne Boyer75576bb2010-07-14 10:50:14 -07004323 &ipr_resource_type_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324 NULL,
4325};
4326
4327/**
4328 * ipr_biosparam - Return the HSC mapping
4329 * @sdev: scsi device struct
4330 * @block_device: block device pointer
4331 * @capacity: capacity of the device
4332 * @parm: Array containing returned HSC values.
4333 *
4334 * This function generates the HSC parms that fdisk uses.
4335 * We want to make sure we return something that places partitions
4336 * on 4k boundaries for best performance with the IOA.
4337 *
4338 * Return value:
4339 * 0 on success
4340 **/
4341static int ipr_biosparam(struct scsi_device *sdev,
4342 struct block_device *block_device,
4343 sector_t capacity, int *parm)
4344{
4345 int heads, sectors;
4346 sector_t cylinders;
4347
4348 heads = 128;
4349 sectors = 32;
4350
4351 cylinders = capacity;
4352 sector_div(cylinders, (128 * 32));
4353
4354 /* return result */
4355 parm[0] = heads;
4356 parm[1] = sectors;
4357 parm[2] = cylinders;
4358
4359 return 0;
4360}
4361
4362/**
Brian King35a39692006-09-25 12:39:20 -05004363 * ipr_find_starget - Find target based on bus/target.
4364 * @starget: scsi target struct
4365 *
4366 * Return value:
4367 * resource entry pointer if found / NULL if not found
4368 **/
4369static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
4370{
4371 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4372 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4373 struct ipr_resource_entry *res;
4374
4375 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004376 if ((res->bus == starget->channel) &&
Brian King0ee1d712012-03-14 21:20:06 -05004377 (res->target == starget->id)) {
Brian King35a39692006-09-25 12:39:20 -05004378 return res;
4379 }
4380 }
4381
4382 return NULL;
4383}
4384
4385static struct ata_port_info sata_port_info;
4386
4387/**
4388 * ipr_target_alloc - Prepare for commands to a SCSI target
4389 * @starget: scsi target struct
4390 *
4391 * If the device is a SATA device, this function allocates an
4392 * ATA port with libata, else it does nothing.
4393 *
4394 * Return value:
4395 * 0 on success / non-0 on failure
4396 **/
4397static int ipr_target_alloc(struct scsi_target *starget)
4398{
4399 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4400 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4401 struct ipr_sata_port *sata_port;
4402 struct ata_port *ap;
4403 struct ipr_resource_entry *res;
4404 unsigned long lock_flags;
4405
4406 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4407 res = ipr_find_starget(starget);
4408 starget->hostdata = NULL;
4409
4410 if (res && ipr_is_gata(res)) {
4411 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4412 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
4413 if (!sata_port)
4414 return -ENOMEM;
4415
4416 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
4417 if (ap) {
4418 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4419 sata_port->ioa_cfg = ioa_cfg;
4420 sata_port->ap = ap;
4421 sata_port->res = res;
4422
4423 res->sata_port = sata_port;
4424 ap->private_data = sata_port;
4425 starget->hostdata = sata_port;
4426 } else {
4427 kfree(sata_port);
4428 return -ENOMEM;
4429 }
4430 }
4431 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4432
4433 return 0;
4434}
4435
4436/**
4437 * ipr_target_destroy - Destroy a SCSI target
4438 * @starget: scsi target struct
4439 *
4440 * If the device was a SATA device, this function frees the libata
4441 * ATA port, else it does nothing.
4442 *
4443 **/
4444static void ipr_target_destroy(struct scsi_target *starget)
4445{
4446 struct ipr_sata_port *sata_port = starget->hostdata;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004447 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4448 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4449
4450 if (ioa_cfg->sis64) {
Brian King0ee1d712012-03-14 21:20:06 -05004451 if (!ipr_find_starget(starget)) {
4452 if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4453 clear_bit(starget->id, ioa_cfg->array_ids);
4454 else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4455 clear_bit(starget->id, ioa_cfg->vset_ids);
4456 else if (starget->channel == 0)
4457 clear_bit(starget->id, ioa_cfg->target_ids);
4458 }
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004459 }
Brian King35a39692006-09-25 12:39:20 -05004460
4461 if (sata_port) {
4462 starget->hostdata = NULL;
4463 ata_sas_port_destroy(sata_port->ap);
4464 kfree(sata_port);
4465 }
4466}
4467
4468/**
4469 * ipr_find_sdev - Find device based on bus/target/lun.
4470 * @sdev: scsi device struct
4471 *
4472 * Return value:
4473 * resource entry pointer if found / NULL if not found
4474 **/
4475static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
4476{
4477 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4478 struct ipr_resource_entry *res;
4479
4480 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004481 if ((res->bus == sdev->channel) &&
4482 (res->target == sdev->id) &&
4483 (res->lun == sdev->lun))
Brian King35a39692006-09-25 12:39:20 -05004484 return res;
4485 }
4486
4487 return NULL;
4488}
4489
4490/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491 * ipr_slave_destroy - Unconfigure a SCSI device
4492 * @sdev: scsi device struct
4493 *
4494 * Return value:
4495 * nothing
4496 **/
4497static void ipr_slave_destroy(struct scsi_device *sdev)
4498{
4499 struct ipr_resource_entry *res;
4500 struct ipr_ioa_cfg *ioa_cfg;
4501 unsigned long lock_flags = 0;
4502
4503 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4504
4505 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4506 res = (struct ipr_resource_entry *) sdev->hostdata;
4507 if (res) {
Brian King35a39692006-09-25 12:39:20 -05004508 if (res->sata_port)
Tejun Heo3e4ec342010-05-10 21:41:30 +02004509 res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510 sdev->hostdata = NULL;
4511 res->sdev = NULL;
Brian King35a39692006-09-25 12:39:20 -05004512 res->sata_port = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513 }
4514 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4515}
4516
4517/**
4518 * ipr_slave_configure - Configure a SCSI device
4519 * @sdev: scsi device struct
4520 *
4521 * This function configures the specified scsi device.
4522 *
4523 * Return value:
4524 * 0 on success
4525 **/
4526static int ipr_slave_configure(struct scsi_device *sdev)
4527{
4528 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4529 struct ipr_resource_entry *res;
Brian Kingdd406ef2009-04-22 08:58:02 -05004530 struct ata_port *ap = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531 unsigned long lock_flags = 0;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004532 char buffer[IPR_MAX_RES_PATH_LENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533
4534 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4535 res = sdev->hostdata;
4536 if (res) {
4537 if (ipr_is_af_dasd_device(res))
4538 sdev->type = TYPE_RAID;
brking@us.ibm.com0726ce22005-11-01 17:01:01 -06004539 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540 sdev->scsi_level = 4;
brking@us.ibm.com0726ce22005-11-01 17:01:01 -06004541 sdev->no_uld_attach = 1;
4542 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 if (ipr_is_vset_device(res)) {
Jens Axboe242f9dc2008-09-14 05:55:09 -07004544 blk_queue_rq_timeout(sdev->request_queue,
4545 IPR_VSET_RW_TIMEOUT);
Martin K. Petersen086fa5f2010-02-26 00:20:38 -05004546 blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547 }
Brian Kingdd406ef2009-04-22 08:58:02 -05004548 if (ipr_is_gata(res) && res->sata_port)
4549 ap = res->sata_port->ap;
4550 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4551
4552 if (ap) {
Brian King35a39692006-09-25 12:39:20 -05004553 scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
Brian Kingdd406ef2009-04-22 08:58:02 -05004554 ata_sas_slave_configure(sdev, ap);
4555 } else
Brian King35a39692006-09-25 12:39:20 -05004556 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004557 if (ioa_cfg->sis64)
4558 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004559 ipr_format_res_path(res->res_path, buffer,
4560 sizeof(buffer)));
Brian Kingdd406ef2009-04-22 08:58:02 -05004561 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 }
4563 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4564 return 0;
4565}
4566
4567/**
Brian King35a39692006-09-25 12:39:20 -05004568 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
4569 * @sdev: scsi device struct
4570 *
4571 * This function initializes an ATA port so that future commands
4572 * sent through queuecommand will work.
4573 *
4574 * Return value:
4575 * 0 on success
4576 **/
4577static int ipr_ata_slave_alloc(struct scsi_device *sdev)
4578{
4579 struct ipr_sata_port *sata_port = NULL;
4580 int rc = -ENXIO;
4581
4582 ENTER;
4583 if (sdev->sdev_target)
4584 sata_port = sdev->sdev_target->hostdata;
Dan Williamsb2024452012-03-21 21:09:07 -07004585 if (sata_port) {
Brian King35a39692006-09-25 12:39:20 -05004586 rc = ata_sas_port_init(sata_port->ap);
Dan Williamsb2024452012-03-21 21:09:07 -07004587 if (rc == 0)
4588 rc = ata_sas_sync_probe(sata_port->ap);
4589 }
4590
Brian King35a39692006-09-25 12:39:20 -05004591 if (rc)
4592 ipr_slave_destroy(sdev);
4593
4594 LEAVE;
4595 return rc;
4596}
4597
4598/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599 * ipr_slave_alloc - Prepare for commands to a device.
4600 * @sdev: scsi device struct
4601 *
4602 * This function saves a pointer to the resource entry
4603 * in the scsi device struct if the device exists. We
4604 * can then use this pointer in ipr_queuecommand when
4605 * handling new commands.
4606 *
4607 * Return value:
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004608 * 0 on success / -ENXIO if device does not exist
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609 **/
4610static int ipr_slave_alloc(struct scsi_device *sdev)
4611{
4612 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4613 struct ipr_resource_entry *res;
4614 unsigned long lock_flags;
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004615 int rc = -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616
4617 sdev->hostdata = NULL;
4618
4619 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4620
Brian King35a39692006-09-25 12:39:20 -05004621 res = ipr_find_sdev(sdev);
4622 if (res) {
4623 res->sdev = sdev;
4624 res->add_to_ml = 0;
4625 res->in_erp = 0;
4626 sdev->hostdata = res;
4627 if (!ipr_is_naca_model(res))
4628 res->needs_sync_complete = 1;
4629 rc = 0;
4630 if (ipr_is_gata(res)) {
4631 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4632 return ipr_ata_slave_alloc(sdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633 }
4634 }
4635
4636 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4637
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004638 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639}
4640
4641/**
4642 * ipr_eh_host_reset - Reset the host adapter
4643 * @scsi_cmd: scsi command struct
4644 *
4645 * Return value:
4646 * SUCCESS / FAILED
4647 **/
Jeff Garzik df0ae242005-05-28 07:57:14 -04004648static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649{
4650 struct ipr_ioa_cfg *ioa_cfg;
4651 int rc;
4652
4653 ENTER;
4654 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
4655
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004656 if (!ioa_cfg->in_reset_reload) {
4657 dev_err(&ioa_cfg->pdev->dev,
4658 "Adapter being reset as a result of error recovery.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004660 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4661 ioa_cfg->sdt_state = GET_DUMP;
4662 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004663
4664 rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
4665
4666 LEAVE;
4667 return rc;
4668}
4669
Jeff Garzik df0ae242005-05-28 07:57:14 -04004670static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
4671{
4672 int rc;
4673
4674 spin_lock_irq(cmd->device->host->host_lock);
4675 rc = __ipr_eh_host_reset(cmd);
4676 spin_unlock_irq(cmd->device->host->host_lock);
4677
4678 return rc;
4679}
4680
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681/**
Brian Kingc6513092006-03-29 09:37:43 -06004682 * ipr_device_reset - Reset the device
4683 * @ioa_cfg: ioa config struct
4684 * @res: resource entry struct
4685 *
4686 * This function issues a device reset to the affected device.
4687 * If the device is a SCSI device, a LUN reset will be sent
4688 * to the device first. If that does not work, a target reset
Brian King35a39692006-09-25 12:39:20 -05004689 * will be sent. If the device is a SATA device, a PHY reset will
4690 * be sent.
Brian Kingc6513092006-03-29 09:37:43 -06004691 *
4692 * Return value:
4693 * 0 on success / non-zero on failure
4694 **/
4695static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
4696 struct ipr_resource_entry *res)
4697{
4698 struct ipr_cmnd *ipr_cmd;
4699 struct ipr_ioarcb *ioarcb;
4700 struct ipr_cmd_pkt *cmd_pkt;
Brian King35a39692006-09-25 12:39:20 -05004701 struct ipr_ioarcb_ata_regs *regs;
Brian Kingc6513092006-03-29 09:37:43 -06004702 u32 ioasc;
4703
4704 ENTER;
4705 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4706 ioarcb = &ipr_cmd->ioarcb;
4707 cmd_pkt = &ioarcb->cmd_pkt;
Wayne Boyera32c0552010-02-19 13:23:36 -08004708
4709 if (ipr_cmd->ioa_cfg->sis64) {
4710 regs = &ipr_cmd->i.ata_ioadl.regs;
4711 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
4712 } else
4713 regs = &ioarcb->u.add_data.u.regs;
Brian Kingc6513092006-03-29 09:37:43 -06004714
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004715 ioarcb->res_handle = res->res_handle;
Brian Kingc6513092006-03-29 09:37:43 -06004716 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4717 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
Brian King35a39692006-09-25 12:39:20 -05004718 if (ipr_is_gata(res)) {
4719 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
Wayne Boyera32c0552010-02-19 13:23:36 -08004720 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
Brian King35a39692006-09-25 12:39:20 -05004721 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
4722 }
Brian Kingc6513092006-03-29 09:37:43 -06004723
4724 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
Wayne Boyer96d21f02010-05-10 09:13:27 -07004725 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian Kingc6513092006-03-29 09:37:43 -06004726 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
Wayne Boyer96d21f02010-05-10 09:13:27 -07004727 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) {
4728 if (ipr_cmd->ioa_cfg->sis64)
4729 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
4730 sizeof(struct ipr_ioasa_gata));
4731 else
4732 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
4733 sizeof(struct ipr_ioasa_gata));
4734 }
Brian Kingc6513092006-03-29 09:37:43 -06004735
4736 LEAVE;
4737 return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0);
4738}
4739
4740/**
Brian King35a39692006-09-25 12:39:20 -05004741 * ipr_sata_reset - Reset the SATA port
Tejun Heocc0680a2007-08-06 18:36:23 +09004742 * @link: SATA link to reset
Brian King35a39692006-09-25 12:39:20 -05004743 * @classes: class of the attached device
4744 *
Tejun Heocc0680a2007-08-06 18:36:23 +09004745 * This function issues a SATA phy reset to the affected ATA link.
Brian King35a39692006-09-25 12:39:20 -05004746 *
4747 * Return value:
4748 * 0 on success / non-zero on failure
4749 **/
Tejun Heocc0680a2007-08-06 18:36:23 +09004750static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
Andrew Morton120bda32007-03-26 02:17:43 -07004751 unsigned long deadline)
Brian King35a39692006-09-25 12:39:20 -05004752{
Tejun Heocc0680a2007-08-06 18:36:23 +09004753 struct ipr_sata_port *sata_port = link->ap->private_data;
Brian King35a39692006-09-25 12:39:20 -05004754 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4755 struct ipr_resource_entry *res;
4756 unsigned long lock_flags = 0;
4757 int rc = -ENXIO;
4758
4759 ENTER;
4760 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King73d98ff2006-11-21 10:27:58 -06004761 while(ioa_cfg->in_reset_reload) {
4762 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4763 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4764 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4765 }
4766
Brian King35a39692006-09-25 12:39:20 -05004767 res = sata_port->res;
4768 if (res) {
4769 rc = ipr_device_reset(ioa_cfg, res);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004770 *classes = res->ata_class;
Brian King35a39692006-09-25 12:39:20 -05004771 }
4772
4773 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4774 LEAVE;
4775 return rc;
4776}
4777
4778/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779 * ipr_eh_dev_reset - Reset the device
4780 * @scsi_cmd: scsi command struct
4781 *
4782 * This function issues a device reset to the affected device.
4783 * A LUN reset will be sent to the device first. If that does
4784 * not work, a target reset will be sent.
4785 *
4786 * Return value:
4787 * SUCCESS / FAILED
4788 **/
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04004789static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790{
4791 struct ipr_cmnd *ipr_cmd;
4792 struct ipr_ioa_cfg *ioa_cfg;
4793 struct ipr_resource_entry *res;
Brian King35a39692006-09-25 12:39:20 -05004794 struct ata_port *ap;
4795 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796
4797 ENTER;
4798 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
4799 res = scsi_cmd->device->hostdata;
4800
brking@us.ibm.comeeb883072005-11-01 17:02:29 -06004801 if (!res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 return FAILED;
4803
4804 /*
4805 * If we are currently going through reset/reload, return failed. This will force the
4806 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
4807 * reset to complete
4808 */
4809 if (ioa_cfg->in_reset_reload)
4810 return FAILED;
4811 if (ioa_cfg->ioa_is_dead)
4812 return FAILED;
4813
4814 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004815 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816 if (ipr_cmd->scsi_cmd)
4817 ipr_cmd->done = ipr_scsi_eh_done;
Brian King24d6f2b2007-03-29 12:43:17 -05004818 if (ipr_cmd->qc)
4819 ipr_cmd->done = ipr_sata_eh_done;
Brian King7402ece2006-11-21 10:28:23 -06004820 if (ipr_cmd->qc && !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
4821 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
4822 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
4823 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824 }
4825 }
4826
4827 res->resetting_device = 1;
Brian Kingfb3ed3c2006-03-29 09:37:37 -06004828 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
Brian King35a39692006-09-25 12:39:20 -05004829
4830 if (ipr_is_gata(res) && res->sata_port) {
4831 ap = res->sata_port->ap;
4832 spin_unlock_irq(scsi_cmd->device->host->host_lock);
Tejun Heoa1efdab2008-03-25 12:22:50 +09004833 ata_std_error_handler(ap);
Brian King35a39692006-09-25 12:39:20 -05004834 spin_lock_irq(scsi_cmd->device->host->host_lock);
Brian King5af23d22007-05-09 15:36:35 -05004835
4836 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004837 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
Brian King5af23d22007-05-09 15:36:35 -05004838 rc = -EIO;
4839 break;
4840 }
4841 }
Brian King35a39692006-09-25 12:39:20 -05004842 } else
4843 rc = ipr_device_reset(ioa_cfg, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 res->resetting_device = 0;
4845
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846 LEAVE;
Brian Kingc6513092006-03-29 09:37:43 -06004847 return (rc ? FAILED : SUCCESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848}
4849
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04004850static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
4851{
4852 int rc;
4853
4854 spin_lock_irq(cmd->device->host->host_lock);
4855 rc = __ipr_eh_dev_reset(cmd);
4856 spin_unlock_irq(cmd->device->host->host_lock);
4857
4858 return rc;
4859}
4860
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861/**
4862 * ipr_bus_reset_done - Op done function for bus reset.
4863 * @ipr_cmd: ipr command struct
4864 *
4865 * This function is the op done function for a bus reset
4866 *
4867 * Return value:
4868 * none
4869 **/
4870static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
4871{
4872 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4873 struct ipr_resource_entry *res;
4874
4875 ENTER;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004876 if (!ioa_cfg->sis64)
4877 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4878 if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
4879 scsi_report_bus_reset(ioa_cfg->host, res->bus);
4880 break;
4881 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883
4884 /*
4885 * If abort has not completed, indicate the reset has, else call the
4886 * abort's done function to wake the sleeping eh thread
4887 */
4888 if (ipr_cmd->sibling->sibling)
4889 ipr_cmd->sibling->sibling = NULL;
4890 else
4891 ipr_cmd->sibling->done(ipr_cmd->sibling);
4892
4893 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4894 LEAVE;
4895}
4896
4897/**
4898 * ipr_abort_timeout - An abort task has timed out
4899 * @ipr_cmd: ipr command struct
4900 *
4901 * This function handles when an abort task times out. If this
4902 * happens we issue a bus reset since we have resources tied
4903 * up that must be freed before returning to the midlayer.
4904 *
4905 * Return value:
4906 * none
4907 **/
4908static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
4909{
4910 struct ipr_cmnd *reset_cmd;
4911 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4912 struct ipr_cmd_pkt *cmd_pkt;
4913 unsigned long lock_flags = 0;
4914
4915 ENTER;
4916 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4917 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
4918 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4919 return;
4920 }
4921
Brian Kingfb3ed3c2006-03-29 09:37:37 -06004922 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4924 ipr_cmd->sibling = reset_cmd;
4925 reset_cmd->sibling = ipr_cmd;
4926 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
4927 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
4928 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4929 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
4930 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
4931
4932 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
4933 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4934 LEAVE;
4935}
4936
4937/**
4938 * ipr_cancel_op - Cancel specified op
4939 * @scsi_cmd: scsi command struct
4940 *
4941 * This function cancels specified op.
4942 *
4943 * Return value:
4944 * SUCCESS / FAILED
4945 **/
4946static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
4947{
4948 struct ipr_cmnd *ipr_cmd;
4949 struct ipr_ioa_cfg *ioa_cfg;
4950 struct ipr_resource_entry *res;
4951 struct ipr_cmd_pkt *cmd_pkt;
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004952 u32 ioasc, int_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953 int op_found = 0;
4954
4955 ENTER;
4956 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4957 res = scsi_cmd->device->hostdata;
4958
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04004959 /* If we are currently going through reset/reload, return failed.
4960 * This will force the mid-layer to call ipr_eh_host_reset,
4961 * which will then go to sleep and wait for the reset to complete
4962 */
4963 if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
4964 return FAILED;
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004965 if (!res)
4966 return FAILED;
4967
4968 /*
4969 * If we are aborting a timed out op, chances are that the timeout was caused
4970 * by a still not detected EEH error. In such cases, reading a register will
4971 * trigger the EEH recovery infrastructure.
4972 */
4973 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
4974
4975 if (!ipr_is_gscsi(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 return FAILED;
4977
4978 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4979 if (ipr_cmd->scsi_cmd == scsi_cmd) {
4980 ipr_cmd->done = ipr_scsi_eh_done;
4981 op_found = 1;
4982 break;
4983 }
4984 }
4985
4986 if (!op_found)
4987 return SUCCESS;
4988
4989 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004990 ipr_cmd->ioarcb.res_handle = res->res_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4992 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4993 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
4994 ipr_cmd->u.sdev = scsi_cmd->device;
4995
Brian Kingfb3ed3c2006-03-29 09:37:37 -06004996 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
4997 scsi_cmd->cmnd[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
Wayne Boyer96d21f02010-05-10 09:13:27 -07004999 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000
5001 /*
5002 * If the abort task timed out and we sent a bus reset, we will get
5003 * one the following responses to the abort
5004 */
5005 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
5006 ioasc = 0;
5007 ipr_trace;
5008 }
5009
5010 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005011 if (!ipr_is_naca_model(res))
5012 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013
5014 LEAVE;
5015 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
5016}
5017
5018/**
5019 * ipr_eh_abort - Abort a single op
5020 * @scsi_cmd: scsi command struct
5021 *
5022 * Return value:
5023 * SUCCESS / FAILED
5024 **/
5025static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
5026{
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005027 unsigned long flags;
5028 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029
5030 ENTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005032 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
5033 rc = ipr_cancel_op(scsi_cmd);
5034 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035
5036 LEAVE;
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005037 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038}
5039
5040/**
5041 * ipr_handle_other_interrupt - Handle "other" interrupts
5042 * @ioa_cfg: ioa config struct
Wayne Boyer634651f2010-08-27 14:45:07 -07005043 * @int_reg: interrupt register
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044 *
5045 * Return value:
5046 * IRQ_NONE / IRQ_HANDLED
5047 **/
Wayne Boyer634651f2010-08-27 14:45:07 -07005048static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
Wayne Boyer630ad8312011-04-07 12:12:30 -07005049 u32 int_reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050{
5051 irqreturn_t rc = IRQ_HANDLED;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005052 u32 int_mask_reg;
5053
5054 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
5055 int_reg &= ~int_mask_reg;
5056
5057 /* If an interrupt on the adapter did not occur, ignore it.
5058 * Or in the case of SIS 64, check for a stage change interrupt.
5059 */
5060 if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
5061 if (ioa_cfg->sis64) {
5062 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
5063 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5064 if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
5065
5066 /* clear stage change */
5067 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
5068 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5069 list_del(&ioa_cfg->reset_cmd->queue);
5070 del_timer(&ioa_cfg->reset_cmd->timer);
5071 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5072 return IRQ_HANDLED;
5073 }
5074 }
5075
5076 return IRQ_NONE;
5077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078
5079 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
5080 /* Mask the interrupt */
5081 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
5082
5083 /* Clear the interrupt */
5084 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
5085 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5086
5087 list_del(&ioa_cfg->reset_cmd->queue);
5088 del_timer(&ioa_cfg->reset_cmd->timer);
5089 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
Wayne Boyer7dacb642011-04-12 10:29:02 -07005090 } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
Brian King7dd21302012-03-14 21:20:08 -05005091 if (ioa_cfg->clear_isr) {
5092 if (ipr_debug && printk_ratelimit())
5093 dev_err(&ioa_cfg->pdev->dev,
5094 "Spurious interrupt detected. 0x%08X\n", int_reg);
5095 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5096 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5097 return IRQ_NONE;
5098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099 } else {
5100 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
5101 ioa_cfg->ioa_unit_checked = 1;
5102 else
5103 dev_err(&ioa_cfg->pdev->dev,
5104 "Permanent IOA failure. 0x%08X\n", int_reg);
5105
5106 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5107 ioa_cfg->sdt_state = GET_DUMP;
5108
5109 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
5110 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5111 }
5112
5113 return rc;
5114}
5115
5116/**
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005117 * ipr_isr_eh - Interrupt service routine error handler
5118 * @ioa_cfg: ioa config struct
5119 * @msg: message to log
5120 *
5121 * Return value:
5122 * none
5123 **/
5124static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg)
5125{
5126 ioa_cfg->errors_logged++;
5127 dev_err(&ioa_cfg->pdev->dev, "%s\n", msg);
5128
5129 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5130 ioa_cfg->sdt_state = GET_DUMP;
5131
5132 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5133}
5134
5135/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 * ipr_isr - Interrupt service routine
5137 * @irq: irq number
5138 * @devp: pointer to ioa config struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139 *
5140 * Return value:
5141 * IRQ_NONE / IRQ_HANDLED
5142 **/
David Howells7d12e782006-10-05 14:55:46 +01005143static irqreturn_t ipr_isr(int irq, void *devp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144{
5145 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
5146 unsigned long lock_flags = 0;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005147 u32 int_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148 u32 ioasc;
5149 u16 cmd_index;
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005150 int num_hrrq = 0;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005151 int irq_none = 0;
Brian King172cd6e2012-07-17 08:14:40 -05005152 struct ipr_cmnd *ipr_cmd, *temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153 irqreturn_t rc = IRQ_NONE;
Brian King172cd6e2012-07-17 08:14:40 -05005154 LIST_HEAD(doneq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155
5156 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5157
5158 /* If interrupts are disabled, ignore the interrupt */
5159 if (!ioa_cfg->allow_interrupts) {
5160 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5161 return IRQ_NONE;
5162 }
5163
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164 while (1) {
5165 ipr_cmd = NULL;
5166
5167 while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5168 ioa_cfg->toggle_bit) {
5169
5170 cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
5171 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
5172
5173 if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005174 ipr_isr_eh(ioa_cfg, "Invalid response handle from IOA");
Brian King172cd6e2012-07-17 08:14:40 -05005175 rc = IRQ_HANDLED;
5176 goto unlock_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177 }
5178
5179 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
5180
Wayne Boyer96d21f02010-05-10 09:13:27 -07005181 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182
5183 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
5184
Brian King172cd6e2012-07-17 08:14:40 -05005185 list_move_tail(&ipr_cmd->queue, &doneq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186
5187 rc = IRQ_HANDLED;
5188
5189 if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
5190 ioa_cfg->hrrq_curr++;
5191 } else {
5192 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
5193 ioa_cfg->toggle_bit ^= 1u;
5194 }
5195 }
5196
Brian King7dd21302012-03-14 21:20:08 -05005197 if (ipr_cmd && !ioa_cfg->clear_isr)
5198 break;
5199
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200 if (ipr_cmd != NULL) {
5201 /* Clear the PCI interrupt */
Wayne Boyera5442ba2011-05-17 09:18:53 -07005202 num_hrrq = 0;
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005203 do {
Wayne Boyer214777b2010-02-19 13:24:26 -08005204 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
Wayne Boyer7dacb642011-04-12 10:29:02 -07005205 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005206 } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
5207 num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
5208
Wayne Boyer7dacb642011-04-12 10:29:02 -07005209 } else if (rc == IRQ_NONE && irq_none == 0) {
5210 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5211 irq_none++;
Wayne Boyera5442ba2011-05-17 09:18:53 -07005212 } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
5213 int_reg & IPR_PCII_HRRQ_UPDATED) {
5214 ipr_isr_eh(ioa_cfg, "Error clearing HRRQ");
Brian King172cd6e2012-07-17 08:14:40 -05005215 rc = IRQ_HANDLED;
5216 goto unlock_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005217 } else
5218 break;
5219 }
5220
5221 if (unlikely(rc == IRQ_NONE))
Wayne Boyer634651f2010-08-27 14:45:07 -07005222 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223
Brian King172cd6e2012-07-17 08:14:40 -05005224unlock_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005225 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Brian King172cd6e2012-07-17 08:14:40 -05005226 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5227 list_del(&ipr_cmd->queue);
5228 del_timer(&ipr_cmd->timer);
5229 ipr_cmd->fast_done(ipr_cmd);
5230 }
5231
Linus Torvalds1da177e2005-04-16 15:20:36 -07005232 return rc;
5233}
5234
5235/**
Wayne Boyera32c0552010-02-19 13:23:36 -08005236 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237 * @ioa_cfg: ioa config struct
5238 * @ipr_cmd: ipr command struct
5239 *
5240 * Return value:
5241 * 0 on success / -1 on failure
5242 **/
Wayne Boyera32c0552010-02-19 13:23:36 -08005243static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
5244 struct ipr_cmnd *ipr_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245{
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005246 int i, nseg;
5247 struct scatterlist *sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248 u32 length;
5249 u32 ioadl_flags = 0;
5250 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5251 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08005252 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005254 length = scsi_bufflen(scsi_cmd);
5255 if (!length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256 return 0;
5257
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005258 nseg = scsi_dma_map(scsi_cmd);
5259 if (nseg < 0) {
Anton Blanchard51f52a42011-05-09 10:07:40 +10005260 if (printk_ratelimit())
5261 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005262 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263 }
5264
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005265 ipr_cmd->dma_use_sg = nseg;
5266
Wayne Boyer438b0332010-05-10 09:13:00 -07005267 ioarcb->data_transfer_length = cpu_to_be32(length);
Wayne Boyerb8803b12010-05-14 08:55:13 -07005268 ioarcb->ioadl_len =
5269 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
Wayne Boyer438b0332010-05-10 09:13:00 -07005270
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005271 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5272 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5273 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08005274 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
5275 ioadl_flags = IPR_IOADL_FLAGS_READ;
5276
5277 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5278 ioadl64[i].flags = cpu_to_be32(ioadl_flags);
5279 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
5280 ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
5281 }
5282
5283 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5284 return 0;
5285}
5286
5287/**
5288 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5289 * @ioa_cfg: ioa config struct
5290 * @ipr_cmd: ipr command struct
5291 *
5292 * Return value:
5293 * 0 on success / -1 on failure
5294 **/
5295static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5296 struct ipr_cmnd *ipr_cmd)
5297{
5298 int i, nseg;
5299 struct scatterlist *sg;
5300 u32 length;
5301 u32 ioadl_flags = 0;
5302 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5303 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5304 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
5305
5306 length = scsi_bufflen(scsi_cmd);
5307 if (!length)
5308 return 0;
5309
5310 nseg = scsi_dma_map(scsi_cmd);
5311 if (nseg < 0) {
5312 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
5313 return -1;
5314 }
5315
5316 ipr_cmd->dma_use_sg = nseg;
5317
5318 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5319 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5320 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5321 ioarcb->data_transfer_length = cpu_to_be32(length);
5322 ioarcb->ioadl_len =
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005323 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5324 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
5325 ioadl_flags = IPR_IOADL_FLAGS_READ;
5326 ioarcb->read_data_transfer_length = cpu_to_be32(length);
5327 ioarcb->read_ioadl_len =
5328 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5329 }
5330
Wayne Boyera32c0552010-02-19 13:23:36 -08005331 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
5332 ioadl = ioarcb->u.add_data.u.ioadl;
5333 ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
5334 offsetof(struct ipr_ioarcb, u.add_data));
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005335 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5336 }
5337
5338 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5339 ioadl[i].flags_and_data_len =
5340 cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5341 ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
5342 }
5343
5344 ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5345 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005346}
5347
5348/**
5349 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
5350 * @scsi_cmd: scsi command struct
5351 *
5352 * Return value:
5353 * task attributes
5354 **/
5355static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
5356{
5357 u8 tag[2];
5358 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
5359
5360 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
5361 switch (tag[0]) {
5362 case MSG_SIMPLE_TAG:
5363 rc = IPR_FLAGS_LO_SIMPLE_TASK;
5364 break;
5365 case MSG_HEAD_TAG:
5366 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
5367 break;
5368 case MSG_ORDERED_TAG:
5369 rc = IPR_FLAGS_LO_ORDERED_TASK;
5370 break;
5371 };
5372 }
5373
5374 return rc;
5375}
5376
5377/**
5378 * ipr_erp_done - Process completion of ERP for a device
5379 * @ipr_cmd: ipr command struct
5380 *
5381 * This function copies the sense buffer into the scsi_cmd
5382 * struct and pushes the scsi_done function.
5383 *
5384 * Return value:
5385 * nothing
5386 **/
5387static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
5388{
5389 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5390 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5391 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005392 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005393
5394 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5395 scsi_cmd->result |= (DID_ERROR << 16);
Brian Kingfb3ed3c2006-03-29 09:37:37 -06005396 scmd_printk(KERN_ERR, scsi_cmd,
5397 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398 } else {
5399 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
5400 SCSI_SENSE_BUFFERSIZE);
5401 }
5402
5403 if (res) {
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005404 if (!ipr_is_naca_model(res))
5405 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406 res->in_erp = 0;
5407 }
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005408 scsi_dma_unmap(ipr_cmd->scsi_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5410 scsi_cmd->scsi_done(scsi_cmd);
5411}
5412
5413/**
5414 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5415 * @ipr_cmd: ipr command struct
5416 *
5417 * Return value:
5418 * none
5419 **/
5420static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
5421{
Brian King51b1c7e2007-03-29 12:43:50 -05005422 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005423 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
Wayne Boyera32c0552010-02-19 13:23:36 -08005424 dma_addr_t dma_addr = ipr_cmd->dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005425
5426 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
Wayne Boyera32c0552010-02-19 13:23:36 -08005427 ioarcb->data_transfer_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005428 ioarcb->read_data_transfer_length = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -08005429 ioarcb->ioadl_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005430 ioarcb->read_ioadl_len = 0;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005431 ioasa->hdr.ioasc = 0;
5432 ioasa->hdr.residual_data_len = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -08005433
5434 if (ipr_cmd->ioa_cfg->sis64)
5435 ioarcb->u.sis64_addr_data.data_ioadl_addr =
5436 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
5437 else {
5438 ioarcb->write_ioadl_addr =
5439 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
5440 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442}
5443
5444/**
5445 * ipr_erp_request_sense - Send request sense to a device
5446 * @ipr_cmd: ipr command struct
5447 *
5448 * This function sends a request sense to a device as a result
5449 * of a check condition.
5450 *
5451 * Return value:
5452 * nothing
5453 **/
5454static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
5455{
5456 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005457 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005458
5459 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5460 ipr_erp_done(ipr_cmd);
5461 return;
5462 }
5463
5464 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5465
5466 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
5467 cmd_pkt->cdb[0] = REQUEST_SENSE;
5468 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
5469 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
5470 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5471 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
5472
Wayne Boyera32c0552010-02-19 13:23:36 -08005473 ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
5474 SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475
5476 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
5477 IPR_REQUEST_SENSE_TIMEOUT * 2);
5478}
5479
5480/**
5481 * ipr_erp_cancel_all - Send cancel all to a device
5482 * @ipr_cmd: ipr command struct
5483 *
5484 * This function sends a cancel all to a device to clear the
5485 * queue. If we are running TCQ on the device, QERR is set to 1,
5486 * which means all outstanding ops have been dropped on the floor.
5487 * Cancel all will return them to us.
5488 *
5489 * Return value:
5490 * nothing
5491 **/
5492static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
5493{
5494 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5495 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5496 struct ipr_cmd_pkt *cmd_pkt;
5497
5498 res->in_erp = 1;
5499
5500 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5501
5502 if (!scsi_get_tag_type(scsi_cmd->device)) {
5503 ipr_erp_request_sense(ipr_cmd);
5504 return;
5505 }
5506
5507 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5508 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5509 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5510
5511 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
5512 IPR_CANCEL_ALL_TIMEOUT);
5513}
5514
5515/**
5516 * ipr_dump_ioasa - Dump contents of IOASA
5517 * @ioa_cfg: ioa config struct
5518 * @ipr_cmd: ipr command struct
Brian Kingfe964d02006-03-29 09:37:29 -06005519 * @res: resource entry struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005520 *
5521 * This function is invoked by the interrupt handler when ops
5522 * fail. It will log the IOASA if appropriate. Only called
5523 * for GPDD ops.
5524 *
5525 * Return value:
5526 * none
5527 **/
5528static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
Brian Kingfe964d02006-03-29 09:37:29 -06005529 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005530{
5531 int i;
5532 u16 data_len;
Brian Kingb0692dd2007-03-29 12:43:09 -05005533 u32 ioasc, fd_ioasc;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005534 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005535 __be32 *ioasa_data = (__be32 *)ioasa;
5536 int error_index;
5537
Wayne Boyer96d21f02010-05-10 09:13:27 -07005538 ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
5539 fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540
5541 if (0 == ioasc)
5542 return;
5543
5544 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
5545 return;
5546
Brian Kingb0692dd2007-03-29 12:43:09 -05005547 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
5548 error_index = ipr_get_error(fd_ioasc);
5549 else
5550 error_index = ipr_get_error(ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005551
5552 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
5553 /* Don't log an error if the IOA already logged one */
Wayne Boyer96d21f02010-05-10 09:13:27 -07005554 if (ioasa->hdr.ilid != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005555 return;
5556
Brian Kingcc9bd5d2007-03-29 12:43:01 -05005557 if (!ipr_is_gscsi(res))
5558 return;
5559
Linus Torvalds1da177e2005-04-16 15:20:36 -07005560 if (ipr_error_table[error_index].log_ioasa == 0)
5561 return;
5562 }
5563
Brian Kingfe964d02006-03-29 09:37:29 -06005564 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005565
Wayne Boyer96d21f02010-05-10 09:13:27 -07005566 data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
5567 if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
5568 data_len = sizeof(struct ipr_ioasa64);
5569 else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005570 data_len = sizeof(struct ipr_ioasa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005571
5572 ipr_err("IOASA Dump:\n");
5573
5574 for (i = 0; i < data_len / 4; i += 4) {
5575 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
5576 be32_to_cpu(ioasa_data[i]),
5577 be32_to_cpu(ioasa_data[i+1]),
5578 be32_to_cpu(ioasa_data[i+2]),
5579 be32_to_cpu(ioasa_data[i+3]));
5580 }
5581}
5582
5583/**
5584 * ipr_gen_sense - Generate SCSI sense data from an IOASA
5585 * @ioasa: IOASA
5586 * @sense_buf: sense data buffer
5587 *
5588 * Return value:
5589 * none
5590 **/
5591static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
5592{
5593 u32 failing_lba;
5594 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
5595 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005596 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5597 u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598
5599 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
5600
5601 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
5602 return;
5603
5604 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
5605
5606 if (ipr_is_vset_device(res) &&
5607 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
5608 ioasa->u.vset.failing_lba_hi != 0) {
5609 sense_buf[0] = 0x72;
5610 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
5611 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
5612 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
5613
5614 sense_buf[7] = 12;
5615 sense_buf[8] = 0;
5616 sense_buf[9] = 0x0A;
5617 sense_buf[10] = 0x80;
5618
5619 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
5620
5621 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
5622 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
5623 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
5624 sense_buf[15] = failing_lba & 0x000000ff;
5625
5626 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5627
5628 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
5629 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
5630 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
5631 sense_buf[19] = failing_lba & 0x000000ff;
5632 } else {
5633 sense_buf[0] = 0x70;
5634 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
5635 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
5636 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
5637
5638 /* Illegal request */
5639 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
Wayne Boyer96d21f02010-05-10 09:13:27 -07005640 (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005641 sense_buf[7] = 10; /* additional length */
5642
5643 /* IOARCB was in error */
5644 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
5645 sense_buf[15] = 0xC0;
5646 else /* Parameter data was invalid */
5647 sense_buf[15] = 0x80;
5648
5649 sense_buf[16] =
5650 ((IPR_FIELD_POINTER_MASK &
Wayne Boyer96d21f02010-05-10 09:13:27 -07005651 be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005652 sense_buf[17] =
5653 (IPR_FIELD_POINTER_MASK &
Wayne Boyer96d21f02010-05-10 09:13:27 -07005654 be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005655 } else {
5656 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
5657 if (ipr_is_vset_device(res))
5658 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5659 else
5660 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
5661
5662 sense_buf[0] |= 0x80; /* Or in the Valid bit */
5663 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
5664 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
5665 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
5666 sense_buf[6] = failing_lba & 0x000000ff;
5667 }
5668
5669 sense_buf[7] = 6; /* additional length */
5670 }
5671 }
5672}
5673
5674/**
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005675 * ipr_get_autosense - Copy autosense data to sense buffer
5676 * @ipr_cmd: ipr command struct
5677 *
5678 * This function copies the autosense buffer to the buffer
5679 * in the scsi_cmd, if there is autosense available.
5680 *
5681 * Return value:
5682 * 1 if autosense was available / 0 if not
5683 **/
5684static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
5685{
Wayne Boyer96d21f02010-05-10 09:13:27 -07005686 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5687 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005688
Wayne Boyer96d21f02010-05-10 09:13:27 -07005689 if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005690 return 0;
5691
Wayne Boyer96d21f02010-05-10 09:13:27 -07005692 if (ipr_cmd->ioa_cfg->sis64)
5693 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
5694 min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
5695 SCSI_SENSE_BUFFERSIZE));
5696 else
5697 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
5698 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
5699 SCSI_SENSE_BUFFERSIZE));
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005700 return 1;
5701}
5702
5703/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005704 * ipr_erp_start - Process an error response for a SCSI op
5705 * @ioa_cfg: ioa config struct
5706 * @ipr_cmd: ipr command struct
5707 *
5708 * This function determines whether or not to initiate ERP
5709 * on the affected device.
5710 *
5711 * Return value:
5712 * nothing
5713 **/
5714static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
5715 struct ipr_cmnd *ipr_cmd)
5716{
5717 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5718 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005719 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian King8a048992007-04-26 16:00:10 -05005720 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005721
5722 if (!res) {
5723 ipr_scsi_eh_done(ipr_cmd);
5724 return;
5725 }
5726
Brian King8a048992007-04-26 16:00:10 -05005727 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005728 ipr_gen_sense(ipr_cmd);
5729
Brian Kingcc9bd5d2007-03-29 12:43:01 -05005730 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
5731
Brian King8a048992007-04-26 16:00:10 -05005732 switch (masked_ioasc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005733 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005734 if (ipr_is_naca_model(res))
5735 scsi_cmd->result |= (DID_ABORT << 16);
5736 else
5737 scsi_cmd->result |= (DID_IMM_RETRY << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005738 break;
5739 case IPR_IOASC_IR_RESOURCE_HANDLE:
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06005740 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005741 scsi_cmd->result |= (DID_NO_CONNECT << 16);
5742 break;
5743 case IPR_IOASC_HW_SEL_TIMEOUT:
5744 scsi_cmd->result |= (DID_NO_CONNECT << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005745 if (!ipr_is_naca_model(res))
5746 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005747 break;
5748 case IPR_IOASC_SYNC_REQUIRED:
5749 if (!res->in_erp)
5750 res->needs_sync_complete = 1;
5751 scsi_cmd->result |= (DID_IMM_RETRY << 16);
5752 break;
5753 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06005754 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
5756 break;
5757 case IPR_IOASC_BUS_WAS_RESET:
5758 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
5759 /*
5760 * Report the bus reset and ask for a retry. The device
5761 * will give CC/UA the next command.
5762 */
5763 if (!res->resetting_device)
5764 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
5765 scsi_cmd->result |= (DID_ERROR << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005766 if (!ipr_is_naca_model(res))
5767 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005768 break;
5769 case IPR_IOASC_HW_DEV_BUS_STATUS:
5770 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
5771 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005772 if (!ipr_get_autosense(ipr_cmd)) {
5773 if (!ipr_is_naca_model(res)) {
5774 ipr_erp_cancel_all(ipr_cmd);
5775 return;
5776 }
5777 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005778 }
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005779 if (!ipr_is_naca_model(res))
5780 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005781 break;
5782 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
5783 break;
5784 default:
Brian King5b7304f2006-08-02 14:57:51 -05005785 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
5786 scsi_cmd->result |= (DID_ERROR << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005787 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788 res->needs_sync_complete = 1;
5789 break;
5790 }
5791
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005792 scsi_dma_unmap(ipr_cmd->scsi_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5794 scsi_cmd->scsi_done(scsi_cmd);
5795}
5796
5797/**
5798 * ipr_scsi_done - mid-layer done function
5799 * @ipr_cmd: ipr command struct
5800 *
5801 * This function is invoked by the interrupt handler for
5802 * ops generated by the SCSI mid-layer
5803 *
5804 * Return value:
5805 * none
5806 **/
5807static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
5808{
5809 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5810 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005811 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian King172cd6e2012-07-17 08:14:40 -05005812 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813
Wayne Boyer96d21f02010-05-10 09:13:27 -07005814 scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005815
5816 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
Brian King172cd6e2012-07-17 08:14:40 -05005817 scsi_dma_unmap(scsi_cmd);
5818
5819 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005820 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5821 scsi_cmd->scsi_done(scsi_cmd);
Brian King172cd6e2012-07-17 08:14:40 -05005822 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5823 } else {
5824 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825 ipr_erp_start(ioa_cfg, ipr_cmd);
Brian King172cd6e2012-07-17 08:14:40 -05005826 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005828}
5829
5830/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831 * ipr_queuecommand - Queue a mid-layer request
Brian King00bfef22012-07-17 08:13:52 -05005832 * @shost: scsi host struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005833 * @scsi_cmd: scsi command struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834 *
5835 * This function queues a request generated by the mid-layer.
5836 *
5837 * Return value:
5838 * 0 on success
5839 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
5840 * SCSI_MLQUEUE_HOST_BUSY if host is busy
5841 **/
Brian King00bfef22012-07-17 08:13:52 -05005842static int ipr_queuecommand(struct Scsi_Host *shost,
5843 struct scsi_cmnd *scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844{
5845 struct ipr_ioa_cfg *ioa_cfg;
5846 struct ipr_resource_entry *res;
5847 struct ipr_ioarcb *ioarcb;
5848 struct ipr_cmnd *ipr_cmd;
Brian King00bfef22012-07-17 08:13:52 -05005849 unsigned long lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 int rc = 0;
5851
Brian King00bfef22012-07-17 08:13:52 -05005852 ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
5853
5854 spin_lock_irqsave(shost->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855 scsi_cmd->result = (DID_OK << 16);
Brian King00bfef22012-07-17 08:13:52 -05005856 res = scsi_cmd->device->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857
5858 /*
5859 * We are currently blocking all devices due to a host reset
5860 * We have told the host to stop giving us new requests, but
5861 * ERP ops don't count. FIXME
5862 */
Brian King00bfef22012-07-17 08:13:52 -05005863 if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead)) {
5864 spin_unlock_irqrestore(shost->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865 return SCSI_MLQUEUE_HOST_BUSY;
Brian King00bfef22012-07-17 08:13:52 -05005866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867
5868 /*
5869 * FIXME - Create scsi_set_host_offline interface
5870 * and the ioa_is_dead check can be removed
5871 */
5872 if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
Brian King00bfef22012-07-17 08:13:52 -05005873 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5874 goto err_nodev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005875 }
5876
Dan Carpenterd995e1b2012-07-30 11:16:35 +03005877 if (ipr_is_gata(res) && res->sata_port) {
5878 rc = ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
5879 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5880 return rc;
5881 }
Brian King35a39692006-09-25 12:39:20 -05005882
Brian King00bfef22012-07-17 08:13:52 -05005883 ipr_cmd = __ipr_get_free_ipr_cmnd(ioa_cfg);
5884 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5885
Brian King172cd6e2012-07-17 08:14:40 -05005886 ipr_init_ipr_cmnd(ipr_cmd, ipr_scsi_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005887 ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888
5889 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
5890 ipr_cmd->scsi_cmd = scsi_cmd;
Brian King172cd6e2012-07-17 08:14:40 -05005891 ipr_cmd->done = ipr_scsi_eh_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892
5893 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
5894 if (scsi_cmd->underflow == 0)
5895 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5896
Linus Torvalds1da177e2005-04-16 15:20:36 -07005897 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
Wayne Boyerab6c10b2011-03-31 09:56:10 -07005898 if (ipr_is_gscsi(res))
5899 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005900 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
5901 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
5902 }
5903
5904 if (scsi_cmd->cmnd[0] >= 0xC0 &&
5905 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
5906 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5907
Wayne Boyera32c0552010-02-19 13:23:36 -08005908 if (likely(rc == 0)) {
5909 if (ioa_cfg->sis64)
5910 rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
5911 else
5912 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
5913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005914
Brian King00bfef22012-07-17 08:13:52 -05005915 spin_lock_irqsave(shost->host_lock, lock_flags);
5916 if (unlikely(rc || (!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))) {
5917 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5918 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5919 if (!rc)
5920 scsi_dma_unmap(scsi_cmd);
Brian Kinga5fb4072012-03-14 21:20:09 -05005921 return SCSI_MLQUEUE_HOST_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005922 }
5923
Brian King00bfef22012-07-17 08:13:52 -05005924 if (unlikely(ioa_cfg->ioa_is_dead)) {
5925 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5926 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5927 scsi_dma_unmap(scsi_cmd);
5928 goto err_nodev;
5929 }
5930
5931 ioarcb->res_handle = res->res_handle;
5932 if (res->needs_sync_complete) {
5933 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
5934 res->needs_sync_complete = 0;
5935 }
5936 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
5937 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
Brian Kinga5fb4072012-03-14 21:20:09 -05005938 ipr_send_command(ipr_cmd);
Brian King00bfef22012-07-17 08:13:52 -05005939 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5940 return 0;
5941
5942err_nodev:
5943 spin_lock_irqsave(shost->host_lock, lock_flags);
5944 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
5945 scsi_cmd->result = (DID_NO_CONNECT << 16);
5946 scsi_cmd->scsi_done(scsi_cmd);
5947 spin_unlock_irqrestore(shost->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948 return 0;
5949}
5950
5951/**
Brian King35a39692006-09-25 12:39:20 -05005952 * ipr_ioctl - IOCTL handler
5953 * @sdev: scsi device struct
5954 * @cmd: IOCTL cmd
5955 * @arg: IOCTL arg
5956 *
5957 * Return value:
5958 * 0 on success / other on failure
5959 **/
Adrian Bunkbd705f22006-11-21 10:28:48 -06005960static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
Brian King35a39692006-09-25 12:39:20 -05005961{
5962 struct ipr_resource_entry *res;
5963
5964 res = (struct ipr_resource_entry *)sdev->hostdata;
Brian King0ce3a7e2008-07-11 13:37:50 -05005965 if (res && ipr_is_gata(res)) {
5966 if (cmd == HDIO_GET_IDENTITY)
5967 return -ENOTTY;
Jeff Garzik94be9a52009-01-16 10:17:09 -05005968 return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
Brian King0ce3a7e2008-07-11 13:37:50 -05005969 }
Brian King35a39692006-09-25 12:39:20 -05005970
5971 return -EINVAL;
5972}
5973
5974/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005975 * ipr_info - Get information about the card/driver
5976 * @scsi_host: scsi host struct
5977 *
5978 * Return value:
5979 * pointer to buffer with description string
5980 **/
5981static const char * ipr_ioa_info(struct Scsi_Host *host)
5982{
5983 static char buffer[512];
5984 struct ipr_ioa_cfg *ioa_cfg;
5985 unsigned long lock_flags = 0;
5986
5987 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
5988
5989 spin_lock_irqsave(host->host_lock, lock_flags);
5990 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
5991 spin_unlock_irqrestore(host->host_lock, lock_flags);
5992
5993 return buffer;
5994}
5995
5996static struct scsi_host_template driver_template = {
5997 .module = THIS_MODULE,
5998 .name = "IPR",
5999 .info = ipr_ioa_info,
Brian King35a39692006-09-25 12:39:20 -05006000 .ioctl = ipr_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001 .queuecommand = ipr_queuecommand,
6002 .eh_abort_handler = ipr_eh_abort,
6003 .eh_device_reset_handler = ipr_eh_dev_reset,
6004 .eh_host_reset_handler = ipr_eh_host_reset,
6005 .slave_alloc = ipr_slave_alloc,
6006 .slave_configure = ipr_slave_configure,
6007 .slave_destroy = ipr_slave_destroy,
Brian King35a39692006-09-25 12:39:20 -05006008 .target_alloc = ipr_target_alloc,
6009 .target_destroy = ipr_target_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010 .change_queue_depth = ipr_change_queue_depth,
6011 .change_queue_type = ipr_change_queue_type,
6012 .bios_param = ipr_biosparam,
6013 .can_queue = IPR_MAX_COMMANDS,
6014 .this_id = -1,
6015 .sg_tablesize = IPR_MAX_SGLIST,
6016 .max_sectors = IPR_IOA_MAX_SECTORS,
6017 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
6018 .use_clustering = ENABLE_CLUSTERING,
6019 .shost_attrs = ipr_ioa_attrs,
6020 .sdev_attrs = ipr_dev_attrs,
6021 .proc_name = IPR_NAME
6022};
6023
Brian King35a39692006-09-25 12:39:20 -05006024/**
6025 * ipr_ata_phy_reset - libata phy_reset handler
6026 * @ap: ata port to reset
6027 *
6028 **/
6029static void ipr_ata_phy_reset(struct ata_port *ap)
6030{
6031 unsigned long flags;
6032 struct ipr_sata_port *sata_port = ap->private_data;
6033 struct ipr_resource_entry *res = sata_port->res;
6034 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6035 int rc;
6036
6037 ENTER;
6038 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6039 while(ioa_cfg->in_reset_reload) {
6040 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6041 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6042 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6043 }
6044
6045 if (!ioa_cfg->allow_cmds)
6046 goto out_unlock;
6047
6048 rc = ipr_device_reset(ioa_cfg, res);
6049
6050 if (rc) {
Tejun Heo3e4ec342010-05-10 21:41:30 +02006051 ap->link.device[0].class = ATA_DEV_NONE;
Brian King35a39692006-09-25 12:39:20 -05006052 goto out_unlock;
6053 }
6054
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006055 ap->link.device[0].class = res->ata_class;
6056 if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
Tejun Heo3e4ec342010-05-10 21:41:30 +02006057 ap->link.device[0].class = ATA_DEV_NONE;
Brian King35a39692006-09-25 12:39:20 -05006058
6059out_unlock:
6060 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6061 LEAVE;
6062}
6063
6064/**
6065 * ipr_ata_post_internal - Cleanup after an internal command
6066 * @qc: ATA queued command
6067 *
6068 * Return value:
6069 * none
6070 **/
6071static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
6072{
6073 struct ipr_sata_port *sata_port = qc->ap->private_data;
6074 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6075 struct ipr_cmnd *ipr_cmd;
6076 unsigned long flags;
6077
6078 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Brian King73d98ff2006-11-21 10:27:58 -06006079 while(ioa_cfg->in_reset_reload) {
6080 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6081 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6082 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6083 }
6084
Brian King35a39692006-09-25 12:39:20 -05006085 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
6086 if (ipr_cmd->qc == qc) {
6087 ipr_device_reset(ioa_cfg, sata_port->res);
6088 break;
6089 }
6090 }
6091 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6092}
6093
6094/**
Brian King35a39692006-09-25 12:39:20 -05006095 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
6096 * @regs: destination
6097 * @tf: source ATA taskfile
6098 *
6099 * Return value:
6100 * none
6101 **/
6102static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
6103 struct ata_taskfile *tf)
6104{
6105 regs->feature = tf->feature;
6106 regs->nsect = tf->nsect;
6107 regs->lbal = tf->lbal;
6108 regs->lbam = tf->lbam;
6109 regs->lbah = tf->lbah;
6110 regs->device = tf->device;
6111 regs->command = tf->command;
6112 regs->hob_feature = tf->hob_feature;
6113 regs->hob_nsect = tf->hob_nsect;
6114 regs->hob_lbal = tf->hob_lbal;
6115 regs->hob_lbam = tf->hob_lbam;
6116 regs->hob_lbah = tf->hob_lbah;
6117 regs->ctl = tf->ctl;
6118}
6119
6120/**
6121 * ipr_sata_done - done function for SATA commands
6122 * @ipr_cmd: ipr command struct
6123 *
6124 * This function is invoked by the interrupt handler for
6125 * ops generated by the SCSI mid-layer to SATA devices
6126 *
6127 * Return value:
6128 * none
6129 **/
6130static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
6131{
6132 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6133 struct ata_queued_cmd *qc = ipr_cmd->qc;
6134 struct ipr_sata_port *sata_port = qc->ap->private_data;
6135 struct ipr_resource_entry *res = sata_port->res;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006136 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian King35a39692006-09-25 12:39:20 -05006137
Wayne Boyer96d21f02010-05-10 09:13:27 -07006138 if (ipr_cmd->ioa_cfg->sis64)
6139 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
6140 sizeof(struct ipr_ioasa_gata));
6141 else
6142 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
6143 sizeof(struct ipr_ioasa_gata));
Brian King35a39692006-09-25 12:39:20 -05006144 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6145
Wayne Boyer96d21f02010-05-10 09:13:27 -07006146 if (be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006147 scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
Brian King35a39692006-09-25 12:39:20 -05006148
6149 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
Wayne Boyer96d21f02010-05-10 09:13:27 -07006150 qc->err_mask |= __ac_err_mask(sata_port->ioasa.status);
Brian King35a39692006-09-25 12:39:20 -05006151 else
Wayne Boyer96d21f02010-05-10 09:13:27 -07006152 qc->err_mask |= ac_err_mask(sata_port->ioasa.status);
Brian King35a39692006-09-25 12:39:20 -05006153 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6154 ata_qc_complete(qc);
6155}
6156
6157/**
Wayne Boyera32c0552010-02-19 13:23:36 -08006158 * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
6159 * @ipr_cmd: ipr command struct
6160 * @qc: ATA queued command
6161 *
6162 **/
6163static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
6164 struct ata_queued_cmd *qc)
6165{
6166 u32 ioadl_flags = 0;
6167 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6168 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
6169 struct ipr_ioadl64_desc *last_ioadl64 = NULL;
6170 int len = qc->nbytes;
6171 struct scatterlist *sg;
6172 unsigned int si;
6173 dma_addr_t dma_addr = ipr_cmd->dma_addr;
6174
6175 if (len == 0)
6176 return;
6177
6178 if (qc->dma_dir == DMA_TO_DEVICE) {
6179 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6180 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6181 } else if (qc->dma_dir == DMA_FROM_DEVICE)
6182 ioadl_flags = IPR_IOADL_FLAGS_READ;
6183
6184 ioarcb->data_transfer_length = cpu_to_be32(len);
6185 ioarcb->ioadl_len =
6186 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
6187 ioarcb->u.sis64_addr_data.data_ioadl_addr =
6188 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl));
6189
6190 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6191 ioadl64->flags = cpu_to_be32(ioadl_flags);
6192 ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
6193 ioadl64->address = cpu_to_be64(sg_dma_address(sg));
6194
6195 last_ioadl64 = ioadl64;
6196 ioadl64++;
6197 }
6198
6199 if (likely(last_ioadl64))
6200 last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6201}
6202
6203/**
Brian King35a39692006-09-25 12:39:20 -05006204 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
6205 * @ipr_cmd: ipr command struct
6206 * @qc: ATA queued command
6207 *
6208 **/
6209static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
6210 struct ata_queued_cmd *qc)
6211{
6212 u32 ioadl_flags = 0;
6213 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08006214 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006215 struct ipr_ioadl_desc *last_ioadl = NULL;
James Bottomleydde20202008-02-19 11:36:56 +01006216 int len = qc->nbytes;
Brian King35a39692006-09-25 12:39:20 -05006217 struct scatterlist *sg;
Tejun Heoff2aeb12007-12-05 16:43:11 +09006218 unsigned int si;
Brian King35a39692006-09-25 12:39:20 -05006219
6220 if (len == 0)
6221 return;
6222
6223 if (qc->dma_dir == DMA_TO_DEVICE) {
6224 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6225 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08006226 ioarcb->data_transfer_length = cpu_to_be32(len);
6227 ioarcb->ioadl_len =
Brian King35a39692006-09-25 12:39:20 -05006228 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6229 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
6230 ioadl_flags = IPR_IOADL_FLAGS_READ;
6231 ioarcb->read_data_transfer_length = cpu_to_be32(len);
6232 ioarcb->read_ioadl_len =
6233 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6234 }
6235
Tejun Heoff2aeb12007-12-05 16:43:11 +09006236 for_each_sg(qc->sg, sg, qc->n_elem, si) {
Brian King35a39692006-09-25 12:39:20 -05006237 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
6238 ioadl->address = cpu_to_be32(sg_dma_address(sg));
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006239
6240 last_ioadl = ioadl;
6241 ioadl++;
Brian King35a39692006-09-25 12:39:20 -05006242 }
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006243
6244 if (likely(last_ioadl))
6245 last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
Brian King35a39692006-09-25 12:39:20 -05006246}
6247
6248/**
6249 * ipr_qc_issue - Issue a SATA qc to a device
6250 * @qc: queued command
6251 *
6252 * Return value:
6253 * 0 if success
6254 **/
6255static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
6256{
6257 struct ata_port *ap = qc->ap;
6258 struct ipr_sata_port *sata_port = ap->private_data;
6259 struct ipr_resource_entry *res = sata_port->res;
6260 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6261 struct ipr_cmnd *ipr_cmd;
6262 struct ipr_ioarcb *ioarcb;
6263 struct ipr_ioarcb_ata_regs *regs;
6264
6265 if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead))
Brian King0feeed82007-03-29 12:43:43 -05006266 return AC_ERR_SYSTEM;
Brian King35a39692006-09-25 12:39:20 -05006267
6268 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
6269 ioarcb = &ipr_cmd->ioarcb;
Brian King35a39692006-09-25 12:39:20 -05006270
Wayne Boyera32c0552010-02-19 13:23:36 -08006271 if (ioa_cfg->sis64) {
6272 regs = &ipr_cmd->i.ata_ioadl.regs;
6273 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
6274 } else
6275 regs = &ioarcb->u.add_data.u.regs;
6276
6277 memset(regs, 0, sizeof(*regs));
6278 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
Brian King35a39692006-09-25 12:39:20 -05006279
6280 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
6281 ipr_cmd->qc = qc;
6282 ipr_cmd->done = ipr_sata_done;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006283 ipr_cmd->ioarcb.res_handle = res->res_handle;
Brian King35a39692006-09-25 12:39:20 -05006284 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
6285 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6286 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
James Bottomleydde20202008-02-19 11:36:56 +01006287 ipr_cmd->dma_use_sg = qc->n_elem;
Brian King35a39692006-09-25 12:39:20 -05006288
Wayne Boyera32c0552010-02-19 13:23:36 -08006289 if (ioa_cfg->sis64)
6290 ipr_build_ata_ioadl64(ipr_cmd, qc);
6291 else
6292 ipr_build_ata_ioadl(ipr_cmd, qc);
6293
Brian King35a39692006-09-25 12:39:20 -05006294 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
6295 ipr_copy_sata_tf(regs, &qc->tf);
6296 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006297 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
Brian King35a39692006-09-25 12:39:20 -05006298
6299 switch (qc->tf.protocol) {
6300 case ATA_PROT_NODATA:
6301 case ATA_PROT_PIO:
6302 break;
6303
6304 case ATA_PROT_DMA:
6305 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6306 break;
6307
Tejun Heo0dc36882007-12-18 16:34:43 -05006308 case ATAPI_PROT_PIO:
6309 case ATAPI_PROT_NODATA:
Brian King35a39692006-09-25 12:39:20 -05006310 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6311 break;
6312
Tejun Heo0dc36882007-12-18 16:34:43 -05006313 case ATAPI_PROT_DMA:
Brian King35a39692006-09-25 12:39:20 -05006314 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6315 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6316 break;
6317
6318 default:
6319 WARN_ON(1);
Brian King0feeed82007-03-29 12:43:43 -05006320 return AC_ERR_INVALID;
Brian King35a39692006-09-25 12:39:20 -05006321 }
6322
Wayne Boyera32c0552010-02-19 13:23:36 -08006323 ipr_send_command(ipr_cmd);
6324
Brian King35a39692006-09-25 12:39:20 -05006325 return 0;
6326}
6327
6328/**
Tejun Heo4c9bf4e2008-04-07 22:47:20 +09006329 * ipr_qc_fill_rtf - Read result TF
6330 * @qc: ATA queued command
6331 *
6332 * Return value:
6333 * true
6334 **/
6335static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
6336{
6337 struct ipr_sata_port *sata_port = qc->ap->private_data;
6338 struct ipr_ioasa_gata *g = &sata_port->ioasa;
6339 struct ata_taskfile *tf = &qc->result_tf;
6340
6341 tf->feature = g->error;
6342 tf->nsect = g->nsect;
6343 tf->lbal = g->lbal;
6344 tf->lbam = g->lbam;
6345 tf->lbah = g->lbah;
6346 tf->device = g->device;
6347 tf->command = g->status;
6348 tf->hob_nsect = g->hob_nsect;
6349 tf->hob_lbal = g->hob_lbal;
6350 tf->hob_lbam = g->hob_lbam;
6351 tf->hob_lbah = g->hob_lbah;
6352 tf->ctl = g->alt_status;
6353
6354 return true;
6355}
6356
Brian King35a39692006-09-25 12:39:20 -05006357static struct ata_port_operations ipr_sata_ops = {
Brian King35a39692006-09-25 12:39:20 -05006358 .phy_reset = ipr_ata_phy_reset,
Tejun Heoa1efdab2008-03-25 12:22:50 +09006359 .hardreset = ipr_sata_reset,
Brian King35a39692006-09-25 12:39:20 -05006360 .post_internal_cmd = ipr_ata_post_internal,
Brian King35a39692006-09-25 12:39:20 -05006361 .qc_prep = ata_noop_qc_prep,
6362 .qc_issue = ipr_qc_issue,
Tejun Heo4c9bf4e2008-04-07 22:47:20 +09006363 .qc_fill_rtf = ipr_qc_fill_rtf,
Brian King35a39692006-09-25 12:39:20 -05006364 .port_start = ata_sas_port_start,
6365 .port_stop = ata_sas_port_stop
6366};
6367
6368static struct ata_port_info sata_port_info = {
Sergei Shtylyov9cbe0562011-02-04 22:05:48 +03006369 .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA,
Sergei Shtylyov0f2e0332011-01-21 20:32:01 +03006370 .pio_mask = ATA_PIO4_ONLY,
6371 .mwdma_mask = ATA_MWDMA2,
6372 .udma_mask = ATA_UDMA6,
Brian King35a39692006-09-25 12:39:20 -05006373 .port_ops = &ipr_sata_ops
6374};
6375
Linus Torvalds1da177e2005-04-16 15:20:36 -07006376#ifdef CONFIG_PPC_PSERIES
6377static const u16 ipr_blocked_processors[] = {
6378 PV_NORTHSTAR,
6379 PV_PULSAR,
6380 PV_POWER4,
6381 PV_ICESTAR,
6382 PV_SSTAR,
6383 PV_POWER4p,
6384 PV_630,
6385 PV_630p
6386};
6387
6388/**
6389 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
6390 * @ioa_cfg: ioa cfg struct
6391 *
6392 * Adapters that use Gemstone revision < 3.1 do not work reliably on
6393 * certain pSeries hardware. This function determines if the given
6394 * adapter is in one of these confgurations or not.
6395 *
6396 * Return value:
6397 * 1 if adapter is not supported / 0 if adapter is supported
6398 **/
6399static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
6400{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006401 int i;
6402
Auke Kok44c10132007-06-08 15:46:36 -07006403 if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
6404 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
6405 if (__is_processor(ipr_blocked_processors[i]))
6406 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407 }
6408 }
6409 return 0;
6410}
6411#else
6412#define ipr_invalid_adapter(ioa_cfg) 0
6413#endif
6414
6415/**
6416 * ipr_ioa_bringdown_done - IOA bring down completion.
6417 * @ipr_cmd: ipr command struct
6418 *
6419 * This function processes the completion of an adapter bring down.
6420 * It wakes any reset sleepers.
6421 *
6422 * Return value:
6423 * IPR_RC_JOB_RETURN
6424 **/
6425static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
6426{
6427 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6428
6429 ENTER;
6430 ioa_cfg->in_reset_reload = 0;
6431 ioa_cfg->reset_retries = 0;
6432 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6433 wake_up_all(&ioa_cfg->reset_wait_q);
6434
6435 spin_unlock_irq(ioa_cfg->host->host_lock);
6436 scsi_unblock_requests(ioa_cfg->host);
6437 spin_lock_irq(ioa_cfg->host->host_lock);
6438 LEAVE;
6439
6440 return IPR_RC_JOB_RETURN;
6441}
6442
6443/**
6444 * ipr_ioa_reset_done - IOA reset completion.
6445 * @ipr_cmd: ipr command struct
6446 *
6447 * This function processes the completion of an adapter reset.
6448 * It schedules any necessary mid-layer add/removes and
6449 * wakes any reset sleepers.
6450 *
6451 * Return value:
6452 * IPR_RC_JOB_RETURN
6453 **/
6454static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
6455{
6456 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6457 struct ipr_resource_entry *res;
6458 struct ipr_hostrcb *hostrcb, *temp;
6459 int i = 0;
6460
6461 ENTER;
6462 ioa_cfg->in_reset_reload = 0;
6463 ioa_cfg->allow_cmds = 1;
6464 ioa_cfg->reset_cmd = NULL;
brking@us.ibm.com3d1d0da2005-11-01 17:01:54 -06006465 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466
6467 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
6468 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
6469 ipr_trace;
6470 break;
6471 }
6472 }
6473 schedule_work(&ioa_cfg->work_q);
6474
6475 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
6476 list_del(&hostrcb->queue);
6477 if (i++ < IPR_NUM_LOG_HCAMS)
6478 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
6479 else
6480 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
6481 }
6482
Brian King6bb04172007-04-26 16:00:08 -05006483 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
6485
6486 ioa_cfg->reset_retries = 0;
6487 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6488 wake_up_all(&ioa_cfg->reset_wait_q);
6489
Mark Nelson30237852008-12-10 12:23:20 +11006490 spin_unlock(ioa_cfg->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 scsi_unblock_requests(ioa_cfg->host);
Mark Nelson30237852008-12-10 12:23:20 +11006492 spin_lock(ioa_cfg->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493
6494 if (!ioa_cfg->allow_cmds)
6495 scsi_block_requests(ioa_cfg->host);
6496
6497 LEAVE;
6498 return IPR_RC_JOB_RETURN;
6499}
6500
6501/**
6502 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
6503 * @supported_dev: supported device struct
6504 * @vpids: vendor product id struct
6505 *
6506 * Return value:
6507 * none
6508 **/
6509static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
6510 struct ipr_std_inq_vpids *vpids)
6511{
6512 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
6513 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
6514 supported_dev->num_records = 1;
6515 supported_dev->data_length =
6516 cpu_to_be16(sizeof(struct ipr_supported_device));
6517 supported_dev->reserved = 0;
6518}
6519
6520/**
6521 * ipr_set_supported_devs - Send Set Supported Devices for a device
6522 * @ipr_cmd: ipr command struct
6523 *
Wayne Boyera32c0552010-02-19 13:23:36 -08006524 * This function sends a Set Supported Devices to the adapter
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525 *
6526 * Return value:
6527 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6528 **/
6529static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
6530{
6531 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6532 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6534 struct ipr_resource_entry *res = ipr_cmd->u.res;
6535
6536 ipr_cmd->job_step = ipr_ioa_reset_done;
6537
6538 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
Brian Kinge4fbf442006-03-29 09:37:22 -06006539 if (!ipr_is_scsi_disk(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006540 continue;
6541
6542 ipr_cmd->u.res = res;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006543 ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544
6545 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6546 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6547 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6548
6549 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006550 ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
6552 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
6553
Wayne Boyera32c0552010-02-19 13:23:36 -08006554 ipr_init_ioadl(ipr_cmd,
6555 ioa_cfg->vpd_cbs_dma +
6556 offsetof(struct ipr_misc_cbs, supp_dev),
6557 sizeof(struct ipr_supported_device),
6558 IPR_IOADL_FLAGS_WRITE_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559
6560 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
6561 IPR_SET_SUP_DEVICE_TIMEOUT);
6562
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006563 if (!ioa_cfg->sis64)
6564 ipr_cmd->job_step = ipr_set_supported_devs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565 return IPR_RC_JOB_RETURN;
6566 }
6567
6568 return IPR_RC_JOB_CONTINUE;
6569}
6570
6571/**
6572 * ipr_get_mode_page - Locate specified mode page
6573 * @mode_pages: mode page buffer
6574 * @page_code: page code to find
6575 * @len: minimum required length for mode page
6576 *
6577 * Return value:
6578 * pointer to mode page / NULL on failure
6579 **/
6580static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
6581 u32 page_code, u32 len)
6582{
6583 struct ipr_mode_page_hdr *mode_hdr;
6584 u32 page_length;
6585 u32 length;
6586
6587 if (!mode_pages || (mode_pages->hdr.length == 0))
6588 return NULL;
6589
6590 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
6591 mode_hdr = (struct ipr_mode_page_hdr *)
6592 (mode_pages->data + mode_pages->hdr.block_desc_len);
6593
6594 while (length) {
6595 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
6596 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
6597 return mode_hdr;
6598 break;
6599 } else {
6600 page_length = (sizeof(struct ipr_mode_page_hdr) +
6601 mode_hdr->page_length);
6602 length -= page_length;
6603 mode_hdr = (struct ipr_mode_page_hdr *)
6604 ((unsigned long)mode_hdr + page_length);
6605 }
6606 }
6607 return NULL;
6608}
6609
6610/**
6611 * ipr_check_term_power - Check for term power errors
6612 * @ioa_cfg: ioa config struct
6613 * @mode_pages: IOAFP mode pages buffer
6614 *
6615 * Check the IOAFP's mode page 28 for term power errors
6616 *
6617 * Return value:
6618 * nothing
6619 **/
6620static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
6621 struct ipr_mode_pages *mode_pages)
6622{
6623 int i;
6624 int entry_length;
6625 struct ipr_dev_bus_entry *bus;
6626 struct ipr_mode_page28 *mode_page;
6627
6628 mode_page = ipr_get_mode_page(mode_pages, 0x28,
6629 sizeof(struct ipr_mode_page28));
6630
6631 entry_length = mode_page->entry_length;
6632
6633 bus = mode_page->bus;
6634
6635 for (i = 0; i < mode_page->num_entries; i++) {
6636 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
6637 dev_err(&ioa_cfg->pdev->dev,
6638 "Term power is absent on scsi bus %d\n",
6639 bus->res_addr.bus);
6640 }
6641
6642 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
6643 }
6644}
6645
6646/**
6647 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
6648 * @ioa_cfg: ioa config struct
6649 *
6650 * Looks through the config table checking for SES devices. If
6651 * the SES device is in the SES table indicating a maximum SCSI
6652 * bus speed, the speed is limited for the bus.
6653 *
6654 * Return value:
6655 * none
6656 **/
6657static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
6658{
6659 u32 max_xfer_rate;
6660 int i;
6661
6662 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
6663 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
6664 ioa_cfg->bus_attr[i].bus_width);
6665
6666 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
6667 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
6668 }
6669}
6670
6671/**
6672 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
6673 * @ioa_cfg: ioa config struct
6674 * @mode_pages: mode page 28 buffer
6675 *
6676 * Updates mode page 28 based on driver configuration
6677 *
6678 * Return value:
6679 * none
6680 **/
6681static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
6682 struct ipr_mode_pages *mode_pages)
6683{
6684 int i, entry_length;
6685 struct ipr_dev_bus_entry *bus;
6686 struct ipr_bus_attributes *bus_attr;
6687 struct ipr_mode_page28 *mode_page;
6688
6689 mode_page = ipr_get_mode_page(mode_pages, 0x28,
6690 sizeof(struct ipr_mode_page28));
6691
6692 entry_length = mode_page->entry_length;
6693
6694 /* Loop for each device bus entry */
6695 for (i = 0, bus = mode_page->bus;
6696 i < mode_page->num_entries;
6697 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
6698 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
6699 dev_err(&ioa_cfg->pdev->dev,
6700 "Invalid resource address reported: 0x%08X\n",
6701 IPR_GET_PHYS_LOC(bus->res_addr));
6702 continue;
6703 }
6704
6705 bus_attr = &ioa_cfg->bus_attr[i];
6706 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
6707 bus->bus_width = bus_attr->bus_width;
6708 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
6709 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
6710 if (bus_attr->qas_enabled)
6711 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
6712 else
6713 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
6714 }
6715}
6716
6717/**
6718 * ipr_build_mode_select - Build a mode select command
6719 * @ipr_cmd: ipr command struct
6720 * @res_handle: resource handle to send command to
6721 * @parm: Byte 2 of Mode Sense command
6722 * @dma_addr: DMA buffer address
6723 * @xfer_len: data transfer length
6724 *
6725 * Return value:
6726 * none
6727 **/
6728static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
Wayne Boyera32c0552010-02-19 13:23:36 -08006729 __be32 res_handle, u8 parm,
6730 dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006731{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006732 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6733
6734 ioarcb->res_handle = res_handle;
6735 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6736 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6737 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
6738 ioarcb->cmd_pkt.cdb[1] = parm;
6739 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6740
Wayne Boyera32c0552010-02-19 13:23:36 -08006741 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742}
6743
6744/**
6745 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
6746 * @ipr_cmd: ipr command struct
6747 *
6748 * This function sets up the SCSI bus attributes and sends
6749 * a Mode Select for Page 28 to activate them.
6750 *
6751 * Return value:
6752 * IPR_RC_JOB_RETURN
6753 **/
6754static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
6755{
6756 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6757 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
6758 int length;
6759
6760 ENTER;
Brian King47338042006-02-08 20:57:42 -06006761 ipr_scsi_bus_speed_limit(ioa_cfg);
6762 ipr_check_term_power(ioa_cfg, mode_pages);
6763 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
6764 length = mode_pages->hdr.length + 1;
6765 mode_pages->hdr.length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766
6767 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
6768 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
6769 length);
6770
Wayne Boyerf72919e2010-02-19 13:24:21 -08006771 ipr_cmd->job_step = ipr_set_supported_devs;
6772 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
6773 struct ipr_resource_entry, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006774 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6775
6776 LEAVE;
6777 return IPR_RC_JOB_RETURN;
6778}
6779
6780/**
6781 * ipr_build_mode_sense - Builds a mode sense command
6782 * @ipr_cmd: ipr command struct
6783 * @res: resource entry struct
6784 * @parm: Byte 2 of mode sense command
6785 * @dma_addr: DMA address of mode sense buffer
6786 * @xfer_len: Size of DMA buffer
6787 *
6788 * Return value:
6789 * none
6790 **/
6791static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
6792 __be32 res_handle,
Wayne Boyera32c0552010-02-19 13:23:36 -08006793 u8 parm, dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006794{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006795 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6796
6797 ioarcb->res_handle = res_handle;
6798 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
6799 ioarcb->cmd_pkt.cdb[2] = parm;
6800 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6801 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6802
Wayne Boyera32c0552010-02-19 13:23:36 -08006803 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006804}
6805
6806/**
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06006807 * ipr_reset_cmd_failed - Handle failure of IOA reset command
6808 * @ipr_cmd: ipr command struct
6809 *
6810 * This function handles the failure of an IOA bringup command.
6811 *
6812 * Return value:
6813 * IPR_RC_JOB_RETURN
6814 **/
6815static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
6816{
6817 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006818 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06006819
6820 dev_err(&ioa_cfg->pdev->dev,
6821 "0x%02X failed with IOASC: 0x%08X\n",
6822 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
6823
6824 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
6825 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6826 return IPR_RC_JOB_RETURN;
6827}
6828
6829/**
6830 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
6831 * @ipr_cmd: ipr command struct
6832 *
6833 * This function handles the failure of a Mode Sense to the IOAFP.
6834 * Some adapters do not handle all mode pages.
6835 *
6836 * Return value:
6837 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6838 **/
6839static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
6840{
Wayne Boyerf72919e2010-02-19 13:24:21 -08006841 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006842 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06006843
6844 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
Wayne Boyerf72919e2010-02-19 13:24:21 -08006845 ipr_cmd->job_step = ipr_set_supported_devs;
6846 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
6847 struct ipr_resource_entry, queue);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06006848 return IPR_RC_JOB_CONTINUE;
6849 }
6850
6851 return ipr_reset_cmd_failed(ipr_cmd);
6852}
6853
6854/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006855 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
6856 * @ipr_cmd: ipr command struct
6857 *
6858 * This function send a Page 28 mode sense to the IOA to
6859 * retrieve SCSI bus attributes.
6860 *
6861 * Return value:
6862 * IPR_RC_JOB_RETURN
6863 **/
6864static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
6865{
6866 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6867
6868 ENTER;
6869 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
6870 0x28, ioa_cfg->vpd_cbs_dma +
6871 offsetof(struct ipr_misc_cbs, mode_pages),
6872 sizeof(struct ipr_mode_pages));
6873
6874 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06006875 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006876
6877 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6878
6879 LEAVE;
6880 return IPR_RC_JOB_RETURN;
6881}
6882
6883/**
Brian Kingac09c342007-04-26 16:00:16 -05006884 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
6885 * @ipr_cmd: ipr command struct
6886 *
6887 * This function enables dual IOA RAID support if possible.
6888 *
6889 * Return value:
6890 * IPR_RC_JOB_RETURN
6891 **/
6892static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
6893{
6894 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6895 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
6896 struct ipr_mode_page24 *mode_page;
6897 int length;
6898
6899 ENTER;
6900 mode_page = ipr_get_mode_page(mode_pages, 0x24,
6901 sizeof(struct ipr_mode_page24));
6902
6903 if (mode_page)
6904 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
6905
6906 length = mode_pages->hdr.length + 1;
6907 mode_pages->hdr.length = 0;
6908
6909 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
6910 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
6911 length);
6912
6913 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6914 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6915
6916 LEAVE;
6917 return IPR_RC_JOB_RETURN;
6918}
6919
6920/**
6921 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
6922 * @ipr_cmd: ipr command struct
6923 *
6924 * This function handles the failure of a Mode Sense to the IOAFP.
6925 * Some adapters do not handle all mode pages.
6926 *
6927 * Return value:
6928 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6929 **/
6930static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
6931{
Wayne Boyer96d21f02010-05-10 09:13:27 -07006932 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian Kingac09c342007-04-26 16:00:16 -05006933
6934 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
6935 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6936 return IPR_RC_JOB_CONTINUE;
6937 }
6938
6939 return ipr_reset_cmd_failed(ipr_cmd);
6940}
6941
6942/**
6943 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
6944 * @ipr_cmd: ipr command struct
6945 *
6946 * This function send a mode sense to the IOA to retrieve
6947 * the IOA Advanced Function Control mode page.
6948 *
6949 * Return value:
6950 * IPR_RC_JOB_RETURN
6951 **/
6952static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
6953{
6954 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6955
6956 ENTER;
6957 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
6958 0x24, ioa_cfg->vpd_cbs_dma +
6959 offsetof(struct ipr_misc_cbs, mode_pages),
6960 sizeof(struct ipr_mode_pages));
6961
6962 ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
6963 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
6964
6965 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6966
6967 LEAVE;
6968 return IPR_RC_JOB_RETURN;
6969}
6970
6971/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006972 * ipr_init_res_table - Initialize the resource table
6973 * @ipr_cmd: ipr command struct
6974 *
6975 * This function looks through the existing resource table, comparing
6976 * it with the config table. This function will take care of old/new
6977 * devices and schedule adding/removing them from the mid-layer
6978 * as appropriate.
6979 *
6980 * Return value:
6981 * IPR_RC_JOB_CONTINUE
6982 **/
6983static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
6984{
6985 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6986 struct ipr_resource_entry *res, *temp;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006987 struct ipr_config_table_entry_wrapper cfgtew;
6988 int entries, found, flag, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006989 LIST_HEAD(old_res);
6990
6991 ENTER;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006992 if (ioa_cfg->sis64)
6993 flag = ioa_cfg->u.cfg_table64->hdr64.flags;
6994 else
6995 flag = ioa_cfg->u.cfg_table->hdr.flags;
6996
6997 if (flag & IPR_UCODE_DOWNLOAD_REQ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006998 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
6999
7000 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
7001 list_move_tail(&res->queue, &old_res);
7002
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007003 if (ioa_cfg->sis64)
Wayne Boyer438b0332010-05-10 09:13:00 -07007004 entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007005 else
7006 entries = ioa_cfg->u.cfg_table->hdr.num_entries;
7007
7008 for (i = 0; i < entries; i++) {
7009 if (ioa_cfg->sis64)
7010 cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
7011 else
7012 cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07007013 found = 0;
7014
7015 list_for_each_entry_safe(res, temp, &old_res, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007016 if (ipr_is_same_device(res, &cfgtew)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007017 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7018 found = 1;
7019 break;
7020 }
7021 }
7022
7023 if (!found) {
7024 if (list_empty(&ioa_cfg->free_res_q)) {
7025 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
7026 break;
7027 }
7028
7029 found = 1;
7030 res = list_entry(ioa_cfg->free_res_q.next,
7031 struct ipr_resource_entry, queue);
7032 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007033 ipr_init_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007034 res->add_to_ml = 1;
Wayne Boyer56115592010-06-10 14:46:34 -07007035 } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
7036 res->sdev->allow_restart = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007037
7038 if (found)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007039 ipr_update_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007040 }
7041
7042 list_for_each_entry_safe(res, temp, &old_res, queue) {
7043 if (res->sdev) {
7044 res->del_from_ml = 1;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007045 res->res_handle = IPR_INVALID_RES_HANDLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007046 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007047 }
7048 }
7049
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007050 list_for_each_entry_safe(res, temp, &old_res, queue) {
7051 ipr_clear_res_target(res);
7052 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
7053 }
7054
Brian Kingac09c342007-04-26 16:00:16 -05007055 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
7056 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
7057 else
7058 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059
7060 LEAVE;
7061 return IPR_RC_JOB_CONTINUE;
7062}
7063
7064/**
7065 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
7066 * @ipr_cmd: ipr command struct
7067 *
7068 * This function sends a Query IOA Configuration command
7069 * to the adapter to retrieve the IOA configuration table.
7070 *
7071 * Return value:
7072 * IPR_RC_JOB_RETURN
7073 **/
7074static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
7075{
7076 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7077 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007078 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
Brian Kingac09c342007-04-26 16:00:16 -05007079 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007080
7081 ENTER;
Brian Kingac09c342007-04-26 16:00:16 -05007082 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
7083 ioa_cfg->dual_raid = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007084 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
7085 ucode_vpd->major_release, ucode_vpd->card_type,
7086 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
7087 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7088 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7089
7090 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
Wayne Boyer438b0332010-05-10 09:13:00 -07007091 ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007092 ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
7093 ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007094
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007095 ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
Wayne Boyera32c0552010-02-19 13:23:36 -08007096 IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007097
7098 ipr_cmd->job_step = ipr_init_res_table;
7099
7100 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7101
7102 LEAVE;
7103 return IPR_RC_JOB_RETURN;
7104}
7105
7106/**
7107 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
7108 * @ipr_cmd: ipr command struct
7109 *
7110 * This utility function sends an inquiry to the adapter.
7111 *
7112 * Return value:
7113 * none
7114 **/
7115static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
Wayne Boyera32c0552010-02-19 13:23:36 -08007116 dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007117{
7118 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007119
7120 ENTER;
7121 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7122 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7123
7124 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
7125 ioarcb->cmd_pkt.cdb[1] = flags;
7126 ioarcb->cmd_pkt.cdb[2] = page;
7127 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7128
Wayne Boyera32c0552010-02-19 13:23:36 -08007129 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007130
7131 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7132 LEAVE;
7133}
7134
7135/**
brking@us.ibm.com62275042005-11-01 17:01:14 -06007136 * ipr_inquiry_page_supported - Is the given inquiry page supported
7137 * @page0: inquiry page 0 buffer
7138 * @page: page code.
7139 *
7140 * This function determines if the specified inquiry page is supported.
7141 *
7142 * Return value:
7143 * 1 if page is supported / 0 if not
7144 **/
7145static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
7146{
7147 int i;
7148
7149 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
7150 if (page0->page[i] == page)
7151 return 1;
7152
7153 return 0;
7154}
7155
7156/**
Brian Kingac09c342007-04-26 16:00:16 -05007157 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
7158 * @ipr_cmd: ipr command struct
7159 *
7160 * This function sends a Page 0xD0 inquiry to the adapter
7161 * to retrieve adapter capabilities.
7162 *
7163 * Return value:
7164 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7165 **/
7166static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
7167{
7168 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7169 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
7170 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7171
7172 ENTER;
7173 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
7174 memset(cap, 0, sizeof(*cap));
7175
7176 if (ipr_inquiry_page_supported(page0, 0xD0)) {
7177 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
7178 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
7179 sizeof(struct ipr_inquiry_cap));
7180 return IPR_RC_JOB_RETURN;
7181 }
7182
7183 LEAVE;
7184 return IPR_RC_JOB_CONTINUE;
7185}
7186
7187/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007188 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
7189 * @ipr_cmd: ipr command struct
7190 *
7191 * This function sends a Page 3 inquiry to the adapter
7192 * to retrieve software VPD information.
7193 *
7194 * Return value:
7195 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7196 **/
7197static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
7198{
7199 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007200
7201 ENTER;
7202
Brian Kingac09c342007-04-26 16:00:16 -05007203 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007204
7205 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
7206 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
7207 sizeof(struct ipr_inquiry_page3));
7208
7209 LEAVE;
7210 return IPR_RC_JOB_RETURN;
7211}
7212
7213/**
7214 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
7215 * @ipr_cmd: ipr command struct
7216 *
7217 * This function sends a Page 0 inquiry to the adapter
7218 * to retrieve supported inquiry pages.
7219 *
7220 * Return value:
7221 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7222 **/
7223static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
7224{
7225 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007226 char type[5];
7227
7228 ENTER;
7229
7230 /* Grab the type out of the VPD and store it away */
7231 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
7232 type[4] = '\0';
7233 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
7234
brking@us.ibm.com62275042005-11-01 17:01:14 -06007235 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007236
brking@us.ibm.com62275042005-11-01 17:01:14 -06007237 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
7238 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
7239 sizeof(struct ipr_inquiry_page0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007240
7241 LEAVE;
7242 return IPR_RC_JOB_RETURN;
7243}
7244
7245/**
7246 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
7247 * @ipr_cmd: ipr command struct
7248 *
7249 * This function sends a standard inquiry to the adapter.
7250 *
7251 * Return value:
7252 * IPR_RC_JOB_RETURN
7253 **/
7254static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
7255{
7256 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7257
7258 ENTER;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007259 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007260
7261 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
7262 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
7263 sizeof(struct ipr_ioa_vpd));
7264
7265 LEAVE;
7266 return IPR_RC_JOB_RETURN;
7267}
7268
7269/**
Wayne Boyer214777b2010-02-19 13:24:26 -08007270 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007271 * @ipr_cmd: ipr command struct
7272 *
7273 * This function send an Identify Host Request Response Queue
7274 * command to establish the HRRQ with the adapter.
7275 *
7276 * Return value:
7277 * IPR_RC_JOB_RETURN
7278 **/
Wayne Boyer214777b2010-02-19 13:24:26 -08007279static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007280{
7281 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7282 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7283
7284 ENTER;
7285 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
7286
7287 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
7288 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7289
7290 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
Wayne Boyer214777b2010-02-19 13:24:26 -08007291 if (ioa_cfg->sis64)
7292 ioarcb->cmd_pkt.cdb[1] = 0x1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007293 ioarcb->cmd_pkt.cdb[2] =
Wayne Boyer214777b2010-02-19 13:24:26 -08007294 ((u64) ioa_cfg->host_rrq_dma >> 24) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007295 ioarcb->cmd_pkt.cdb[3] =
Wayne Boyer214777b2010-02-19 13:24:26 -08007296 ((u64) ioa_cfg->host_rrq_dma >> 16) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007297 ioarcb->cmd_pkt.cdb[4] =
Wayne Boyer214777b2010-02-19 13:24:26 -08007298 ((u64) ioa_cfg->host_rrq_dma >> 8) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007299 ioarcb->cmd_pkt.cdb[5] =
Wayne Boyer214777b2010-02-19 13:24:26 -08007300 ((u64) ioa_cfg->host_rrq_dma) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007301 ioarcb->cmd_pkt.cdb[7] =
7302 ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
7303 ioarcb->cmd_pkt.cdb[8] =
7304 (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
7305
Wayne Boyer214777b2010-02-19 13:24:26 -08007306 if (ioa_cfg->sis64) {
7307 ioarcb->cmd_pkt.cdb[10] =
7308 ((u64) ioa_cfg->host_rrq_dma >> 56) & 0xff;
7309 ioarcb->cmd_pkt.cdb[11] =
7310 ((u64) ioa_cfg->host_rrq_dma >> 48) & 0xff;
7311 ioarcb->cmd_pkt.cdb[12] =
7312 ((u64) ioa_cfg->host_rrq_dma >> 40) & 0xff;
7313 ioarcb->cmd_pkt.cdb[13] =
7314 ((u64) ioa_cfg->host_rrq_dma >> 32) & 0xff;
7315 }
7316
Linus Torvalds1da177e2005-04-16 15:20:36 -07007317 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
7318
7319 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7320
7321 LEAVE;
7322 return IPR_RC_JOB_RETURN;
7323}
7324
7325/**
7326 * ipr_reset_timer_done - Adapter reset timer function
7327 * @ipr_cmd: ipr command struct
7328 *
7329 * Description: This function is used in adapter reset processing
7330 * for timing events. If the reset_cmd pointer in the IOA
7331 * config struct is not this adapter's we are doing nested
7332 * resets and fail_all_ops will take care of freeing the
7333 * command block.
7334 *
7335 * Return value:
7336 * none
7337 **/
7338static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
7339{
7340 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7341 unsigned long lock_flags = 0;
7342
7343 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7344
7345 if (ioa_cfg->reset_cmd == ipr_cmd) {
7346 list_del(&ipr_cmd->queue);
7347 ipr_cmd->done(ipr_cmd);
7348 }
7349
7350 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7351}
7352
7353/**
7354 * ipr_reset_start_timer - Start a timer for adapter reset job
7355 * @ipr_cmd: ipr command struct
7356 * @timeout: timeout value
7357 *
7358 * Description: This function is used in adapter reset processing
7359 * for timing events. If the reset_cmd pointer in the IOA
7360 * config struct is not this adapter's we are doing nested
7361 * resets and fail_all_ops will take care of freeing the
7362 * command block.
7363 *
7364 * Return value:
7365 * none
7366 **/
7367static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
7368 unsigned long timeout)
7369{
7370 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
7371 ipr_cmd->done = ipr_reset_ioa_job;
7372
7373 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7374 ipr_cmd->timer.expires = jiffies + timeout;
7375 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
7376 add_timer(&ipr_cmd->timer);
7377}
7378
7379/**
7380 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7381 * @ioa_cfg: ioa cfg struct
7382 *
7383 * Return value:
7384 * nothing
7385 **/
7386static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
7387{
7388 memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
7389
7390 /* Initialize Host RRQ pointers */
7391 ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
7392 ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
7393 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
7394 ioa_cfg->toggle_bit = 1;
7395
7396 /* Zero out config table */
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007397 memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007398}
7399
7400/**
Wayne Boyer214777b2010-02-19 13:24:26 -08007401 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
7402 * @ipr_cmd: ipr command struct
7403 *
7404 * Return value:
7405 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7406 **/
7407static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
7408{
7409 unsigned long stage, stage_time;
7410 u32 feedback;
7411 volatile u32 int_reg;
7412 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7413 u64 maskval = 0;
7414
7415 feedback = readl(ioa_cfg->regs.init_feedback_reg);
7416 stage = feedback & IPR_IPL_INIT_STAGE_MASK;
7417 stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
7418
7419 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
7420
7421 /* sanity check the stage_time value */
Wayne Boyer438b0332010-05-10 09:13:00 -07007422 if (stage_time == 0)
7423 stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
7424 else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
Wayne Boyer214777b2010-02-19 13:24:26 -08007425 stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
7426 else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
7427 stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
7428
7429 if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
7430 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
7431 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7432 stage_time = ioa_cfg->transop_timeout;
7433 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7434 } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
Wayne Boyer1df79ca2010-07-14 10:49:43 -07007435 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
7436 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7437 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7438 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7439 maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
7440 writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
7441 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7442 return IPR_RC_JOB_CONTINUE;
7443 }
Wayne Boyer214777b2010-02-19 13:24:26 -08007444 }
7445
7446 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7447 ipr_cmd->timer.expires = jiffies + stage_time * HZ;
7448 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7449 ipr_cmd->done = ipr_reset_ioa_job;
7450 add_timer(&ipr_cmd->timer);
7451 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
7452
7453 return IPR_RC_JOB_RETURN;
7454}
7455
7456/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007457 * ipr_reset_enable_ioa - Enable the IOA following a reset.
7458 * @ipr_cmd: ipr command struct
7459 *
7460 * This function reinitializes some control blocks and
7461 * enables destructive diagnostics on the adapter.
7462 *
7463 * Return value:
7464 * IPR_RC_JOB_RETURN
7465 **/
7466static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
7467{
7468 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7469 volatile u32 int_reg;
Wayne Boyer7be96902010-05-10 09:14:07 -07007470 volatile u64 maskval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007471
7472 ENTER;
Wayne Boyer214777b2010-02-19 13:24:26 -08007473 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007474 ipr_init_ioa_mem(ioa_cfg);
7475
7476 ioa_cfg->allow_interrupts = 1;
Wayne Boyer8701f182010-06-04 10:26:50 -07007477 if (ioa_cfg->sis64) {
7478 /* Set the adapter to the correct endian mode. */
7479 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
7480 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
7481 }
7482
Wayne Boyer7be96902010-05-10 09:14:07 -07007483 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007484
7485 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7486 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
Wayne Boyer214777b2010-02-19 13:24:26 -08007487 ioa_cfg->regs.clr_interrupt_mask_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007488 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7489 return IPR_RC_JOB_CONTINUE;
7490 }
7491
7492 /* Enable destructive diagnostics on IOA */
Wayne Boyer214777b2010-02-19 13:24:26 -08007493 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007494
Wayne Boyer7be96902010-05-10 09:14:07 -07007495 if (ioa_cfg->sis64) {
7496 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7497 maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
7498 writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
7499 } else
7500 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
Wayne Boyer214777b2010-02-19 13:24:26 -08007501
Linus Torvalds1da177e2005-04-16 15:20:36 -07007502 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7503
7504 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
7505
Wayne Boyer214777b2010-02-19 13:24:26 -08007506 if (ioa_cfg->sis64) {
7507 ipr_cmd->job_step = ipr_reset_next_stage;
7508 return IPR_RC_JOB_CONTINUE;
7509 }
7510
Linus Torvalds1da177e2005-04-16 15:20:36 -07007511 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
Brian King5469cb52007-03-29 12:42:40 -05007512 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007513 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7514 ipr_cmd->done = ipr_reset_ioa_job;
7515 add_timer(&ipr_cmd->timer);
7516 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
7517
7518 LEAVE;
7519 return IPR_RC_JOB_RETURN;
7520}
7521
7522/**
7523 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
7524 * @ipr_cmd: ipr command struct
7525 *
7526 * This function is invoked when an adapter dump has run out
7527 * of processing time.
7528 *
7529 * Return value:
7530 * IPR_RC_JOB_CONTINUE
7531 **/
7532static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
7533{
7534 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7535
7536 if (ioa_cfg->sdt_state == GET_DUMP)
Brian King41e9a692011-09-21 08:51:11 -05007537 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7538 else if (ioa_cfg->sdt_state == READ_DUMP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007539 ioa_cfg->sdt_state = ABORT_DUMP;
7540
Brian King4c647e92011-10-15 09:08:56 -05007541 ioa_cfg->dump_timeout = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007542 ipr_cmd->job_step = ipr_reset_alert;
7543
7544 return IPR_RC_JOB_CONTINUE;
7545}
7546
7547/**
7548 * ipr_unit_check_no_data - Log a unit check/no data error log
7549 * @ioa_cfg: ioa config struct
7550 *
7551 * Logs an error indicating the adapter unit checked, but for some
7552 * reason, we were unable to fetch the unit check buffer.
7553 *
7554 * Return value:
7555 * nothing
7556 **/
7557static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
7558{
7559 ioa_cfg->errors_logged++;
7560 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
7561}
7562
7563/**
7564 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
7565 * @ioa_cfg: ioa config struct
7566 *
7567 * Fetches the unit check buffer from the adapter by clocking the data
7568 * through the mailbox register.
7569 *
7570 * Return value:
7571 * nothing
7572 **/
7573static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
7574{
7575 unsigned long mailbox;
7576 struct ipr_hostrcb *hostrcb;
7577 struct ipr_uc_sdt sdt;
7578 int rc, length;
Brian King65f56472007-04-26 16:00:12 -05007579 u32 ioasc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007580
7581 mailbox = readl(ioa_cfg->ioa_mailbox);
7582
Wayne Boyerdcbad002010-02-19 13:24:14 -08007583 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007584 ipr_unit_check_no_data(ioa_cfg);
7585 return;
7586 }
7587
7588 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
7589 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
7590 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
7591
Wayne Boyerdcbad002010-02-19 13:24:14 -08007592 if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
7593 ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
7594 (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007595 ipr_unit_check_no_data(ioa_cfg);
7596 return;
7597 }
7598
7599 /* Find length of the first sdt entry (UC buffer) */
Wayne Boyerdcbad002010-02-19 13:24:14 -08007600 if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
7601 length = be32_to_cpu(sdt.entry[0].end_token);
7602 else
7603 length = (be32_to_cpu(sdt.entry[0].end_token) -
7604 be32_to_cpu(sdt.entry[0].start_token)) &
7605 IPR_FMT2_MBX_ADDR_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007606
7607 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
7608 struct ipr_hostrcb, queue);
7609 list_del(&hostrcb->queue);
7610 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
7611
7612 rc = ipr_get_ldump_data_section(ioa_cfg,
Wayne Boyerdcbad002010-02-19 13:24:14 -08007613 be32_to_cpu(sdt.entry[0].start_token),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007614 (__be32 *)&hostrcb->hcam,
7615 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
7616
Brian King65f56472007-04-26 16:00:12 -05007617 if (!rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007618 ipr_handle_log_data(ioa_cfg, hostrcb);
Wayne Boyer4565e372010-02-19 13:24:07 -08007619 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Brian King65f56472007-04-26 16:00:12 -05007620 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
7621 ioa_cfg->sdt_state == GET_DUMP)
7622 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7623 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07007624 ipr_unit_check_no_data(ioa_cfg);
7625
7626 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
7627}
7628
7629/**
Wayne Boyer110def82010-11-04 09:36:16 -07007630 * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
7631 * @ipr_cmd: ipr command struct
7632 *
7633 * Description: This function will call to get the unit check buffer.
7634 *
7635 * Return value:
7636 * IPR_RC_JOB_RETURN
7637 **/
7638static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
7639{
7640 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7641
7642 ENTER;
7643 ioa_cfg->ioa_unit_checked = 0;
7644 ipr_get_unit_check_buffer(ioa_cfg);
7645 ipr_cmd->job_step = ipr_reset_alert;
7646 ipr_reset_start_timer(ipr_cmd, 0);
7647
7648 LEAVE;
7649 return IPR_RC_JOB_RETURN;
7650}
7651
7652/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007653 * ipr_reset_restore_cfg_space - Restore PCI config space.
7654 * @ipr_cmd: ipr command struct
7655 *
7656 * Description: This function restores the saved PCI config space of
7657 * the adapter, fails all outstanding ops back to the callers, and
7658 * fetches the dump/unit check if applicable to this reset.
7659 *
7660 * Return value:
7661 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7662 **/
7663static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
7664{
7665 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer630ad8312011-04-07 12:12:30 -07007666 u32 int_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007667
7668 ENTER;
Kleber Sacilotto de Souza99c965d2009-11-25 20:13:43 -02007669 ioa_cfg->pdev->state_saved = true;
Jon Mason1d3c16a2010-11-30 17:43:26 -06007670 pci_restore_state(ioa_cfg->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007671
7672 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
Wayne Boyer96d21f02010-05-10 09:13:27 -07007673 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007674 return IPR_RC_JOB_CONTINUE;
7675 }
7676
7677 ipr_fail_all_ops(ioa_cfg);
7678
Wayne Boyer8701f182010-06-04 10:26:50 -07007679 if (ioa_cfg->sis64) {
7680 /* Set the adapter to the correct endian mode. */
7681 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
7682 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
7683 }
7684
Linus Torvalds1da177e2005-04-16 15:20:36 -07007685 if (ioa_cfg->ioa_unit_checked) {
Wayne Boyer110def82010-11-04 09:36:16 -07007686 if (ioa_cfg->sis64) {
7687 ipr_cmd->job_step = ipr_reset_get_unit_check_job;
7688 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
7689 return IPR_RC_JOB_RETURN;
7690 } else {
7691 ioa_cfg->ioa_unit_checked = 0;
7692 ipr_get_unit_check_buffer(ioa_cfg);
7693 ipr_cmd->job_step = ipr_reset_alert;
7694 ipr_reset_start_timer(ipr_cmd, 0);
7695 return IPR_RC_JOB_RETURN;
7696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007697 }
7698
7699 if (ioa_cfg->in_ioa_bringdown) {
7700 ipr_cmd->job_step = ipr_ioa_bringdown_done;
7701 } else {
7702 ipr_cmd->job_step = ipr_reset_enable_ioa;
7703
7704 if (GET_DUMP == ioa_cfg->sdt_state) {
Brian King41e9a692011-09-21 08:51:11 -05007705 ioa_cfg->sdt_state = READ_DUMP;
Brian King4c647e92011-10-15 09:08:56 -05007706 ioa_cfg->dump_timeout = 0;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03007707 if (ioa_cfg->sis64)
7708 ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
7709 else
7710 ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007711 ipr_cmd->job_step = ipr_reset_wait_for_dump;
7712 schedule_work(&ioa_cfg->work_q);
7713 return IPR_RC_JOB_RETURN;
7714 }
7715 }
7716
Wayne Boyer438b0332010-05-10 09:13:00 -07007717 LEAVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007718 return IPR_RC_JOB_CONTINUE;
7719}
7720
7721/**
Brian Kinge619e1a2007-01-23 11:25:37 -06007722 * ipr_reset_bist_done - BIST has completed on the adapter.
7723 * @ipr_cmd: ipr command struct
7724 *
7725 * Description: Unblock config space and resume the reset process.
7726 *
7727 * Return value:
7728 * IPR_RC_JOB_CONTINUE
7729 **/
7730static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
7731{
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007732 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7733
Brian Kinge619e1a2007-01-23 11:25:37 -06007734 ENTER;
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007735 if (ioa_cfg->cfg_locked)
7736 pci_cfg_access_unlock(ioa_cfg->pdev);
7737 ioa_cfg->cfg_locked = 0;
Brian Kinge619e1a2007-01-23 11:25:37 -06007738 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
7739 LEAVE;
7740 return IPR_RC_JOB_CONTINUE;
7741}
7742
7743/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007744 * ipr_reset_start_bist - Run BIST on the adapter.
7745 * @ipr_cmd: ipr command struct
7746 *
7747 * Description: This function runs BIST on the adapter, then delays 2 seconds.
7748 *
7749 * Return value:
7750 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7751 **/
7752static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
7753{
7754 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyercb237ef2010-06-17 11:51:40 -07007755 int rc = PCIBIOS_SUCCESSFUL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007756
7757 ENTER;
Wayne Boyercb237ef2010-06-17 11:51:40 -07007758 if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
7759 writel(IPR_UPROCI_SIS64_START_BIST,
7760 ioa_cfg->regs.set_uproc_interrupt_reg32);
7761 else
7762 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
7763
7764 if (rc == PCIBIOS_SUCCESSFUL) {
Brian Kinge619e1a2007-01-23 11:25:37 -06007765 ipr_cmd->job_step = ipr_reset_bist_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007766 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
7767 rc = IPR_RC_JOB_RETURN;
Wayne Boyercb237ef2010-06-17 11:51:40 -07007768 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007769 if (ioa_cfg->cfg_locked)
7770 pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
7771 ioa_cfg->cfg_locked = 0;
Wayne Boyercb237ef2010-06-17 11:51:40 -07007772 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
7773 rc = IPR_RC_JOB_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007774 }
7775
7776 LEAVE;
7777 return rc;
7778}
7779
7780/**
Brian King463fc692007-05-07 17:09:05 -05007781 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
7782 * @ipr_cmd: ipr command struct
7783 *
7784 * Description: This clears PCI reset to the adapter and delays two seconds.
7785 *
7786 * Return value:
7787 * IPR_RC_JOB_RETURN
7788 **/
7789static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
7790{
7791 ENTER;
7792 pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
7793 ipr_cmd->job_step = ipr_reset_bist_done;
7794 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
7795 LEAVE;
7796 return IPR_RC_JOB_RETURN;
7797}
7798
7799/**
7800 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
7801 * @ipr_cmd: ipr command struct
7802 *
7803 * Description: This asserts PCI reset to the adapter.
7804 *
7805 * Return value:
7806 * IPR_RC_JOB_RETURN
7807 **/
7808static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
7809{
7810 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7811 struct pci_dev *pdev = ioa_cfg->pdev;
7812
7813 ENTER;
Brian King463fc692007-05-07 17:09:05 -05007814 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
7815 ipr_cmd->job_step = ipr_reset_slot_reset_done;
7816 ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
7817 LEAVE;
7818 return IPR_RC_JOB_RETURN;
7819}
7820
7821/**
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007822 * ipr_reset_block_config_access_wait - Wait for permission to block config access
7823 * @ipr_cmd: ipr command struct
7824 *
7825 * Description: This attempts to block config access to the IOA.
7826 *
7827 * Return value:
7828 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7829 **/
7830static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
7831{
7832 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7833 int rc = IPR_RC_JOB_CONTINUE;
7834
7835 if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
7836 ioa_cfg->cfg_locked = 1;
7837 ipr_cmd->job_step = ioa_cfg->reset;
7838 } else {
7839 if (ipr_cmd->u.time_left) {
7840 rc = IPR_RC_JOB_RETURN;
7841 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
7842 ipr_reset_start_timer(ipr_cmd,
7843 IPR_CHECK_FOR_RESET_TIMEOUT);
7844 } else {
7845 ipr_cmd->job_step = ioa_cfg->reset;
7846 dev_err(&ioa_cfg->pdev->dev,
7847 "Timed out waiting to lock config access. Resetting anyway.\n");
7848 }
7849 }
7850
7851 return rc;
7852}
7853
7854/**
7855 * ipr_reset_block_config_access - Block config access to the IOA
7856 * @ipr_cmd: ipr command struct
7857 *
7858 * Description: This attempts to block config access to the IOA
7859 *
7860 * Return value:
7861 * IPR_RC_JOB_CONTINUE
7862 **/
7863static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
7864{
7865 ipr_cmd->ioa_cfg->cfg_locked = 0;
7866 ipr_cmd->job_step = ipr_reset_block_config_access_wait;
7867 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
7868 return IPR_RC_JOB_CONTINUE;
7869}
7870
7871/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007872 * ipr_reset_allowed - Query whether or not IOA can be reset
7873 * @ioa_cfg: ioa config struct
7874 *
7875 * Return value:
7876 * 0 if reset not allowed / non-zero if reset is allowed
7877 **/
7878static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
7879{
7880 volatile u32 temp_reg;
7881
7882 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
7883 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
7884}
7885
7886/**
7887 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
7888 * @ipr_cmd: ipr command struct
7889 *
7890 * Description: This function waits for adapter permission to run BIST,
7891 * then runs BIST. If the adapter does not give permission after a
7892 * reasonable time, we will reset the adapter anyway. The impact of
7893 * resetting the adapter without warning the adapter is the risk of
7894 * losing the persistent error log on the adapter. If the adapter is
7895 * reset while it is writing to the flash on the adapter, the flash
7896 * segment will have bad ECC and be zeroed.
7897 *
7898 * Return value:
7899 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7900 **/
7901static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
7902{
7903 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7904 int rc = IPR_RC_JOB_RETURN;
7905
7906 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
7907 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
7908 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
7909 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007910 ipr_cmd->job_step = ipr_reset_block_config_access;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007911 rc = IPR_RC_JOB_CONTINUE;
7912 }
7913
7914 return rc;
7915}
7916
7917/**
Wayne Boyer8701f182010-06-04 10:26:50 -07007918 * ipr_reset_alert - Alert the adapter of a pending reset
Linus Torvalds1da177e2005-04-16 15:20:36 -07007919 * @ipr_cmd: ipr command struct
7920 *
7921 * Description: This function alerts the adapter that it will be reset.
7922 * If memory space is not currently enabled, proceed directly
7923 * to running BIST on the adapter. The timer must always be started
7924 * so we guarantee we do not run BIST from ipr_isr.
7925 *
7926 * Return value:
7927 * IPR_RC_JOB_RETURN
7928 **/
7929static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
7930{
7931 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7932 u16 cmd_reg;
7933 int rc;
7934
7935 ENTER;
7936 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
7937
7938 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
7939 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
Wayne Boyer214777b2010-02-19 13:24:26 -08007940 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007941 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
7942 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01007943 ipr_cmd->job_step = ipr_reset_block_config_access;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007944 }
7945
7946 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
7947 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
7948
7949 LEAVE;
7950 return IPR_RC_JOB_RETURN;
7951}
7952
7953/**
7954 * ipr_reset_ucode_download_done - Microcode download completion
7955 * @ipr_cmd: ipr command struct
7956 *
7957 * Description: This function unmaps the microcode download buffer.
7958 *
7959 * Return value:
7960 * IPR_RC_JOB_CONTINUE
7961 **/
7962static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
7963{
7964 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7965 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
7966
7967 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
7968 sglist->num_sg, DMA_TO_DEVICE);
7969
7970 ipr_cmd->job_step = ipr_reset_alert;
7971 return IPR_RC_JOB_CONTINUE;
7972}
7973
7974/**
7975 * ipr_reset_ucode_download - Download microcode to the adapter
7976 * @ipr_cmd: ipr command struct
7977 *
7978 * Description: This function checks to see if it there is microcode
7979 * to download to the adapter. If there is, a download is performed.
7980 *
7981 * Return value:
7982 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7983 **/
7984static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
7985{
7986 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7987 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
7988
7989 ENTER;
7990 ipr_cmd->job_step = ipr_reset_alert;
7991
7992 if (!sglist)
7993 return IPR_RC_JOB_CONTINUE;
7994
7995 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7996 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7997 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
7998 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
7999 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
8000 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
8001 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
8002
Wayne Boyera32c0552010-02-19 13:23:36 -08008003 if (ioa_cfg->sis64)
8004 ipr_build_ucode_ioadl64(ipr_cmd, sglist);
8005 else
8006 ipr_build_ucode_ioadl(ipr_cmd, sglist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008007 ipr_cmd->job_step = ipr_reset_ucode_download_done;
8008
8009 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
8010 IPR_WRITE_BUFFER_TIMEOUT);
8011
8012 LEAVE;
8013 return IPR_RC_JOB_RETURN;
8014}
8015
8016/**
8017 * ipr_reset_shutdown_ioa - Shutdown the adapter
8018 * @ipr_cmd: ipr command struct
8019 *
8020 * Description: This function issues an adapter shutdown of the
8021 * specified type to the specified adapter as part of the
8022 * adapter reset job.
8023 *
8024 * Return value:
8025 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8026 **/
8027static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
8028{
8029 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8030 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
8031 unsigned long timeout;
8032 int rc = IPR_RC_JOB_CONTINUE;
8033
8034 ENTER;
8035 if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
8036 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8037 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8038 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
8039 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
8040
Brian Kingac09c342007-04-26 16:00:16 -05008041 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
8042 timeout = IPR_SHUTDOWN_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008043 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
8044 timeout = IPR_INTERNAL_TIMEOUT;
Brian Kingac09c342007-04-26 16:00:16 -05008045 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
8046 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008047 else
Brian Kingac09c342007-04-26 16:00:16 -05008048 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008049
8050 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
8051
8052 rc = IPR_RC_JOB_RETURN;
8053 ipr_cmd->job_step = ipr_reset_ucode_download;
8054 } else
8055 ipr_cmd->job_step = ipr_reset_alert;
8056
8057 LEAVE;
8058 return rc;
8059}
8060
8061/**
8062 * ipr_reset_ioa_job - Adapter reset job
8063 * @ipr_cmd: ipr command struct
8064 *
8065 * Description: This function is the job router for the adapter reset job.
8066 *
8067 * Return value:
8068 * none
8069 **/
8070static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
8071{
8072 u32 rc, ioasc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008073 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8074
8075 do {
Wayne Boyer96d21f02010-05-10 09:13:27 -07008076 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008077
8078 if (ioa_cfg->reset_cmd != ipr_cmd) {
8079 /*
8080 * We are doing nested adapter resets and this is
8081 * not the current reset job.
8082 */
8083 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
8084 return;
8085 }
8086
8087 if (IPR_IOASC_SENSE_KEY(ioasc)) {
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06008088 rc = ipr_cmd->job_step_failed(ipr_cmd);
8089 if (rc == IPR_RC_JOB_RETURN)
8090 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008091 }
8092
8093 ipr_reinit_ipr_cmnd(ipr_cmd);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06008094 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008095 rc = ipr_cmd->job_step(ipr_cmd);
8096 } while(rc == IPR_RC_JOB_CONTINUE);
8097}
8098
8099/**
8100 * _ipr_initiate_ioa_reset - Initiate an adapter reset
8101 * @ioa_cfg: ioa config struct
8102 * @job_step: first job step of reset job
8103 * @shutdown_type: shutdown type
8104 *
8105 * Description: This function will initiate the reset of the given adapter
8106 * starting at the selected job step.
8107 * If the caller needs to wait on the completion of the reset,
8108 * the caller must sleep on the reset_wait_q.
8109 *
8110 * Return value:
8111 * none
8112 **/
8113static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8114 int (*job_step) (struct ipr_cmnd *),
8115 enum ipr_shutdown_type shutdown_type)
8116{
8117 struct ipr_cmnd *ipr_cmd;
8118
8119 ioa_cfg->in_reset_reload = 1;
8120 ioa_cfg->allow_cmds = 0;
8121 scsi_block_requests(ioa_cfg->host);
8122
8123 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
8124 ioa_cfg->reset_cmd = ipr_cmd;
8125 ipr_cmd->job_step = job_step;
8126 ipr_cmd->u.shutdown_type = shutdown_type;
8127
8128 ipr_reset_ioa_job(ipr_cmd);
8129}
8130
8131/**
8132 * ipr_initiate_ioa_reset - Initiate an adapter reset
8133 * @ioa_cfg: ioa config struct
8134 * @shutdown_type: shutdown type
8135 *
8136 * Description: This function will initiate the reset of the given adapter.
8137 * If the caller needs to wait on the completion of the reset,
8138 * the caller must sleep on the reset_wait_q.
8139 *
8140 * Return value:
8141 * none
8142 **/
8143static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8144 enum ipr_shutdown_type shutdown_type)
8145{
8146 if (ioa_cfg->ioa_is_dead)
8147 return;
8148
Brian King41e9a692011-09-21 08:51:11 -05008149 if (ioa_cfg->in_reset_reload) {
8150 if (ioa_cfg->sdt_state == GET_DUMP)
8151 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8152 else if (ioa_cfg->sdt_state == READ_DUMP)
8153 ioa_cfg->sdt_state = ABORT_DUMP;
8154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008155
8156 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
8157 dev_err(&ioa_cfg->pdev->dev,
8158 "IOA taken offline - error recovery failed\n");
8159
8160 ioa_cfg->reset_retries = 0;
8161 ioa_cfg->ioa_is_dead = 1;
8162
8163 if (ioa_cfg->in_ioa_bringdown) {
8164 ioa_cfg->reset_cmd = NULL;
8165 ioa_cfg->in_reset_reload = 0;
8166 ipr_fail_all_ops(ioa_cfg);
8167 wake_up_all(&ioa_cfg->reset_wait_q);
8168
8169 spin_unlock_irq(ioa_cfg->host->host_lock);
8170 scsi_unblock_requests(ioa_cfg->host);
8171 spin_lock_irq(ioa_cfg->host->host_lock);
8172 return;
8173 } else {
8174 ioa_cfg->in_ioa_bringdown = 1;
8175 shutdown_type = IPR_SHUTDOWN_NONE;
8176 }
8177 }
8178
8179 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
8180 shutdown_type);
8181}
8182
8183/**
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008184 * ipr_reset_freeze - Hold off all I/O activity
8185 * @ipr_cmd: ipr command struct
8186 *
8187 * Description: If the PCI slot is frozen, hold off all I/O
8188 * activity; then, as soon as the slot is available again,
8189 * initiate an adapter reset.
8190 */
8191static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
8192{
8193 /* Disallow new interrupts, avoid loop */
8194 ipr_cmd->ioa_cfg->allow_interrupts = 0;
8195 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
8196 ipr_cmd->done = ipr_reset_ioa_job;
8197 return IPR_RC_JOB_RETURN;
8198}
8199
8200/**
8201 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
8202 * @pdev: PCI device struct
8203 *
8204 * Description: This routine is called to tell us that the PCI bus
8205 * is down. Can't do anything here, except put the device driver
8206 * into a holding pattern, waiting for the PCI bus to come back.
8207 */
8208static void ipr_pci_frozen(struct pci_dev *pdev)
8209{
8210 unsigned long flags = 0;
8211 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8212
8213 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8214 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
8215 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8216}
8217
8218/**
8219 * ipr_pci_slot_reset - Called when PCI slot has been reset.
8220 * @pdev: PCI device struct
8221 *
8222 * Description: This routine is called by the pci error recovery
8223 * code after the PCI slot has been reset, just before we
8224 * should resume normal operations.
8225 */
8226static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
8227{
8228 unsigned long flags = 0;
8229 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8230
8231 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Brian King463fc692007-05-07 17:09:05 -05008232 if (ioa_cfg->needs_warm_reset)
8233 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8234 else
8235 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
8236 IPR_SHUTDOWN_NONE);
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008237 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8238 return PCI_ERS_RESULT_RECOVERED;
8239}
8240
8241/**
8242 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
8243 * @pdev: PCI device struct
8244 *
8245 * Description: This routine is called when the PCI bus has
8246 * permanently failed.
8247 */
8248static void ipr_pci_perm_failure(struct pci_dev *pdev)
8249{
8250 unsigned long flags = 0;
8251 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8252
8253 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8254 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
8255 ioa_cfg->sdt_state = ABORT_DUMP;
8256 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES;
8257 ioa_cfg->in_ioa_bringdown = 1;
Kleber S. Souza6ff63892009-05-04 10:41:02 -03008258 ioa_cfg->allow_cmds = 0;
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008259 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8260 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8261}
8262
8263/**
8264 * ipr_pci_error_detected - Called when a PCI error is detected.
8265 * @pdev: PCI device struct
8266 * @state: PCI channel state
8267 *
8268 * Description: Called when a PCI error is detected.
8269 *
8270 * Return value:
8271 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8272 */
8273static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
8274 pci_channel_state_t state)
8275{
8276 switch (state) {
8277 case pci_channel_io_frozen:
8278 ipr_pci_frozen(pdev);
8279 return PCI_ERS_RESULT_NEED_RESET;
8280 case pci_channel_io_perm_failure:
8281 ipr_pci_perm_failure(pdev);
8282 return PCI_ERS_RESULT_DISCONNECT;
8283 break;
8284 default:
8285 break;
8286 }
8287 return PCI_ERS_RESULT_NEED_RESET;
8288}
8289
8290/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008291 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
8292 * @ioa_cfg: ioa cfg struct
8293 *
8294 * Description: This is the second phase of adapter intialization
8295 * This function takes care of initilizing the adapter to the point
8296 * where it can accept new commands.
8297
8298 * Return value:
Joe Perchesb1c11812008-02-03 17:28:22 +02008299 * 0 on success / -EIO on failure
Linus Torvalds1da177e2005-04-16 15:20:36 -07008300 **/
8301static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
8302{
8303 int rc = 0;
8304 unsigned long host_lock_flags = 0;
8305
8306 ENTER;
8307 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8308 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06008309 if (ioa_cfg->needs_hard_reset) {
8310 ioa_cfg->needs_hard_reset = 0;
8311 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8312 } else
8313 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
8314 IPR_SHUTDOWN_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008315
8316 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8317 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
8318 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8319
8320 if (ioa_cfg->ioa_is_dead) {
8321 rc = -EIO;
8322 } else if (ipr_invalid_adapter(ioa_cfg)) {
8323 if (!ipr_testmode)
8324 rc = -EIO;
8325
8326 dev_err(&ioa_cfg->pdev->dev,
8327 "Adapter not supported in this hardware configuration.\n");
8328 }
8329
8330 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8331
8332 LEAVE;
8333 return rc;
8334}
8335
8336/**
8337 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
8338 * @ioa_cfg: ioa config struct
8339 *
8340 * Return value:
8341 * none
8342 **/
8343static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8344{
8345 int i;
8346
8347 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8348 if (ioa_cfg->ipr_cmnd_list[i])
8349 pci_pool_free(ioa_cfg->ipr_cmd_pool,
8350 ioa_cfg->ipr_cmnd_list[i],
8351 ioa_cfg->ipr_cmnd_list_dma[i]);
8352
8353 ioa_cfg->ipr_cmnd_list[i] = NULL;
8354 }
8355
8356 if (ioa_cfg->ipr_cmd_pool)
8357 pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
8358
Brian King89aad422012-03-14 21:20:10 -05008359 kfree(ioa_cfg->ipr_cmnd_list);
8360 kfree(ioa_cfg->ipr_cmnd_list_dma);
8361 ioa_cfg->ipr_cmnd_list = NULL;
8362 ioa_cfg->ipr_cmnd_list_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008363 ioa_cfg->ipr_cmd_pool = NULL;
8364}
8365
8366/**
8367 * ipr_free_mem - Frees memory allocated for an adapter
8368 * @ioa_cfg: ioa cfg struct
8369 *
8370 * Return value:
8371 * nothing
8372 **/
8373static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
8374{
8375 int i;
8376
8377 kfree(ioa_cfg->res_entries);
8378 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
8379 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8380 ipr_free_cmd_blks(ioa_cfg);
8381 pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
8382 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008383 pci_free_consistent(ioa_cfg->pdev, ioa_cfg->cfg_table_size,
8384 ioa_cfg->u.cfg_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008385 ioa_cfg->cfg_table_dma);
8386
8387 for (i = 0; i < IPR_NUM_HCAMS; i++) {
8388 pci_free_consistent(ioa_cfg->pdev,
8389 sizeof(struct ipr_hostrcb),
8390 ioa_cfg->hostrcb[i],
8391 ioa_cfg->hostrcb_dma[i]);
8392 }
8393
8394 ipr_free_dump(ioa_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008395 kfree(ioa_cfg->trace);
8396}
8397
8398/**
8399 * ipr_free_all_resources - Free all allocated resources for an adapter.
8400 * @ipr_cmd: ipr command struct
8401 *
8402 * This function frees all allocated resources for the
8403 * specified adapter.
8404 *
8405 * Return value:
8406 * none
8407 **/
8408static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
8409{
8410 struct pci_dev *pdev = ioa_cfg->pdev;
8411
8412 ENTER;
8413 free_irq(pdev->irq, ioa_cfg);
Wayne Boyer5a9ef252009-01-23 09:17:35 -08008414 pci_disable_msi(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008415 iounmap(ioa_cfg->hdw_dma_regs);
8416 pci_release_regions(pdev);
8417 ipr_free_mem(ioa_cfg);
8418 scsi_host_put(ioa_cfg->host);
8419 pci_disable_device(pdev);
8420 LEAVE;
8421}
8422
8423/**
8424 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
8425 * @ioa_cfg: ioa config struct
8426 *
8427 * Return value:
8428 * 0 on success / -ENOMEM on allocation failure
8429 **/
8430static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8431{
8432 struct ipr_cmnd *ipr_cmd;
8433 struct ipr_ioarcb *ioarcb;
8434 dma_addr_t dma_addr;
8435 int i;
8436
8437 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
Brian King1bfff2f2012-03-14 21:20:12 -05008438 sizeof(struct ipr_cmnd), 512, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008439
8440 if (!ioa_cfg->ipr_cmd_pool)
8441 return -ENOMEM;
8442
Brian King89aad422012-03-14 21:20:10 -05008443 ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
8444 ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
8445
8446 if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
8447 ipr_free_cmd_blks(ioa_cfg);
8448 return -ENOMEM;
8449 }
8450
Linus Torvalds1da177e2005-04-16 15:20:36 -07008451 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
Christoph Lametere94b1762006-12-06 20:33:17 -08008452 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008453
8454 if (!ipr_cmd) {
8455 ipr_free_cmd_blks(ioa_cfg);
8456 return -ENOMEM;
8457 }
8458
8459 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
8460 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
8461 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
8462
8463 ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08008464 ipr_cmd->dma_addr = dma_addr;
8465 if (ioa_cfg->sis64)
8466 ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
8467 else
8468 ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
8469
Linus Torvalds1da177e2005-04-16 15:20:36 -07008470 ioarcb->host_response_handle = cpu_to_be32(i << 2);
Wayne Boyera32c0552010-02-19 13:23:36 -08008471 if (ioa_cfg->sis64) {
8472 ioarcb->u.sis64_addr_data.data_ioadl_addr =
8473 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
8474 ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
Wayne Boyer96d21f02010-05-10 09:13:27 -07008475 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
Wayne Boyera32c0552010-02-19 13:23:36 -08008476 } else {
8477 ioarcb->write_ioadl_addr =
8478 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
8479 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
8480 ioarcb->ioasa_host_pci_addr =
Wayne Boyer96d21f02010-05-10 09:13:27 -07008481 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
Wayne Boyera32c0552010-02-19 13:23:36 -08008482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008483 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
8484 ipr_cmd->cmd_index = i;
8485 ipr_cmd->ioa_cfg = ioa_cfg;
8486 ipr_cmd->sense_buffer_dma = dma_addr +
8487 offsetof(struct ipr_cmnd, sense_buffer);
8488
8489 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
8490 }
8491
8492 return 0;
8493}
8494
8495/**
8496 * ipr_alloc_mem - Allocate memory for an adapter
8497 * @ioa_cfg: ioa config struct
8498 *
8499 * Return value:
8500 * 0 on success / non-zero for error
8501 **/
8502static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
8503{
8504 struct pci_dev *pdev = ioa_cfg->pdev;
8505 int i, rc = -ENOMEM;
8506
8507 ENTER;
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06008508 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008509 ioa_cfg->max_devs_supported, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008510
8511 if (!ioa_cfg->res_entries)
8512 goto out;
8513
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008514 if (ioa_cfg->sis64) {
8515 ioa_cfg->target_ids = kzalloc(sizeof(unsigned long) *
8516 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8517 ioa_cfg->array_ids = kzalloc(sizeof(unsigned long) *
8518 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8519 ioa_cfg->vset_ids = kzalloc(sizeof(unsigned long) *
8520 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8521 }
8522
8523 for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008524 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008525 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
8526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008527
8528 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
8529 sizeof(struct ipr_misc_cbs),
8530 &ioa_cfg->vpd_cbs_dma);
8531
8532 if (!ioa_cfg->vpd_cbs)
8533 goto out_free_res_entries;
8534
8535 if (ipr_alloc_cmd_blks(ioa_cfg))
8536 goto out_free_vpd_cbs;
8537
8538 ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
8539 sizeof(u32) * IPR_NUM_CMD_BLKS,
8540 &ioa_cfg->host_rrq_dma);
8541
8542 if (!ioa_cfg->host_rrq)
8543 goto out_ipr_free_cmd_blocks;
8544
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008545 ioa_cfg->u.cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
8546 ioa_cfg->cfg_table_size,
8547 &ioa_cfg->cfg_table_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008548
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008549 if (!ioa_cfg->u.cfg_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008550 goto out_free_host_rrq;
8551
8552 for (i = 0; i < IPR_NUM_HCAMS; i++) {
8553 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
8554 sizeof(struct ipr_hostrcb),
8555 &ioa_cfg->hostrcb_dma[i]);
8556
8557 if (!ioa_cfg->hostrcb[i])
8558 goto out_free_hostrcb_dma;
8559
8560 ioa_cfg->hostrcb[i]->hostrcb_dma =
8561 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
Brian King49dc6a12006-11-21 10:28:35 -06008562 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008563 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
8564 }
8565
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06008566 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008567 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
8568
8569 if (!ioa_cfg->trace)
8570 goto out_free_hostrcb_dma;
8571
Linus Torvalds1da177e2005-04-16 15:20:36 -07008572 rc = 0;
8573out:
8574 LEAVE;
8575 return rc;
8576
8577out_free_hostrcb_dma:
8578 while (i-- > 0) {
8579 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
8580 ioa_cfg->hostrcb[i],
8581 ioa_cfg->hostrcb_dma[i]);
8582 }
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008583 pci_free_consistent(pdev, ioa_cfg->cfg_table_size,
8584 ioa_cfg->u.cfg_table,
8585 ioa_cfg->cfg_table_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008586out_free_host_rrq:
8587 pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
8588 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
8589out_ipr_free_cmd_blocks:
8590 ipr_free_cmd_blks(ioa_cfg);
8591out_free_vpd_cbs:
8592 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
8593 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8594out_free_res_entries:
8595 kfree(ioa_cfg->res_entries);
8596 goto out;
8597}
8598
8599/**
8600 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
8601 * @ioa_cfg: ioa config struct
8602 *
8603 * Return value:
8604 * none
8605 **/
8606static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
8607{
8608 int i;
8609
8610 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
8611 ioa_cfg->bus_attr[i].bus = i;
8612 ioa_cfg->bus_attr[i].qas_enabled = 0;
8613 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
8614 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
8615 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
8616 else
8617 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
8618 }
8619}
8620
8621/**
8622 * ipr_init_ioa_cfg - Initialize IOA config struct
8623 * @ioa_cfg: ioa config struct
8624 * @host: scsi host struct
8625 * @pdev: PCI dev struct
8626 *
8627 * Return value:
8628 * none
8629 **/
8630static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
8631 struct Scsi_Host *host, struct pci_dev *pdev)
8632{
8633 const struct ipr_interrupt_offsets *p;
8634 struct ipr_interrupts *t;
8635 void __iomem *base;
8636
8637 ioa_cfg->host = host;
8638 ioa_cfg->pdev = pdev;
8639 ioa_cfg->log_level = ipr_log_level;
brking@us.ibm.com3d1d0da2005-11-01 17:01:54 -06008640 ioa_cfg->doorbell = IPR_DOORBELL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008641 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
8642 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
8643 sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
8644 sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
8645 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
8646 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
8647 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
8648 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
8649
8650 INIT_LIST_HEAD(&ioa_cfg->free_q);
8651 INIT_LIST_HEAD(&ioa_cfg->pending_q);
8652 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
8653 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
8654 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
8655 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
David Howellsc4028952006-11-22 14:57:56 +00008656 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008657 init_waitqueue_head(&ioa_cfg->reset_wait_q);
Wayne Boyer95fecd92009-06-16 15:13:28 -07008658 init_waitqueue_head(&ioa_cfg->msi_wait_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008659 ioa_cfg->sdt_state = INACTIVE;
8660
8661 ipr_initialize_bus_attr(ioa_cfg);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008662 ioa_cfg->max_devs_supported = ipr_max_devs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008663
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008664 if (ioa_cfg->sis64) {
8665 host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
8666 host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
8667 if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
8668 ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
8669 } else {
8670 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
8671 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
8672 if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
8673 ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
8674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008675 host->max_channel = IPR_MAX_BUS_TO_SCAN;
8676 host->unique_id = host->host_no;
8677 host->max_cmd_len = IPR_MAX_CDB_LEN;
Brian King89aad422012-03-14 21:20:10 -05008678 host->can_queue = ioa_cfg->max_cmds;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008679 pci_set_drvdata(pdev, ioa_cfg);
8680
8681 p = &ioa_cfg->chip_cfg->regs;
8682 t = &ioa_cfg->regs;
8683 base = ioa_cfg->hdw_dma_regs;
8684
8685 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
8686 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008687 t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008688 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008689 t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008690 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008691 t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008692 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008693 t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008694 t->ioarrin_reg = base + p->ioarrin_reg;
8695 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008696 t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008697 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008698 t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008699 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08008700 t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
Wayne Boyerdcbad002010-02-19 13:24:14 -08008701
8702 if (ioa_cfg->sis64) {
Wayne Boyer214777b2010-02-19 13:24:26 -08008703 t->init_feedback_reg = base + p->init_feedback_reg;
Wayne Boyerdcbad002010-02-19 13:24:14 -08008704 t->dump_addr_reg = base + p->dump_addr_reg;
8705 t->dump_data_reg = base + p->dump_data_reg;
Wayne Boyer8701f182010-06-04 10:26:50 -07008706 t->endian_swap_reg = base + p->endian_swap_reg;
Wayne Boyerdcbad002010-02-19 13:24:14 -08008707 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008708}
8709
8710/**
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008711 * ipr_get_chip_info - Find adapter chip information
Linus Torvalds1da177e2005-04-16 15:20:36 -07008712 * @dev_id: PCI device id struct
8713 *
8714 * Return value:
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008715 * ptr to chip information on success / NULL on failure
Linus Torvalds1da177e2005-04-16 15:20:36 -07008716 **/
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008717static const struct ipr_chip_t * __devinit
8718ipr_get_chip_info(const struct pci_device_id *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008719{
8720 int i;
8721
Linus Torvalds1da177e2005-04-16 15:20:36 -07008722 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
8723 if (ipr_chip[i].vendor == dev_id->vendor &&
8724 ipr_chip[i].device == dev_id->device)
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008725 return &ipr_chip[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07008726 return NULL;
8727}
8728
8729/**
Wayne Boyer95fecd92009-06-16 15:13:28 -07008730 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
8731 * @pdev: PCI device struct
8732 *
8733 * Description: Simply set the msi_received flag to 1 indicating that
8734 * Message Signaled Interrupts are supported.
8735 *
8736 * Return value:
8737 * 0 on success / non-zero on failure
8738 **/
8739static irqreturn_t __devinit ipr_test_intr(int irq, void *devp)
8740{
8741 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
8742 unsigned long lock_flags = 0;
8743 irqreturn_t rc = IRQ_HANDLED;
8744
8745 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8746
8747 ioa_cfg->msi_received = 1;
8748 wake_up(&ioa_cfg->msi_wait_q);
8749
8750 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8751 return rc;
8752}
8753
8754/**
8755 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
8756 * @pdev: PCI device struct
8757 *
8758 * Description: The return value from pci_enable_msi() can not always be
8759 * trusted. This routine sets up and initiates a test interrupt to determine
8760 * if the interrupt is received via the ipr_test_intr() service routine.
8761 * If the tests fails, the driver will fall back to LSI.
8762 *
8763 * Return value:
8764 * 0 on success / non-zero on failure
8765 **/
8766static int __devinit ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg,
8767 struct pci_dev *pdev)
8768{
8769 int rc;
8770 volatile u32 int_reg;
8771 unsigned long lock_flags = 0;
8772
8773 ENTER;
8774
8775 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8776 init_waitqueue_head(&ioa_cfg->msi_wait_q);
8777 ioa_cfg->msi_received = 0;
8778 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
Wayne Boyer214777b2010-02-19 13:24:26 -08008779 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
Wayne Boyer95fecd92009-06-16 15:13:28 -07008780 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8781 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8782
8783 rc = request_irq(pdev->irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
8784 if (rc) {
8785 dev_err(&pdev->dev, "Can not assign irq %d\n", pdev->irq);
8786 return rc;
8787 } else if (ipr_debug)
8788 dev_info(&pdev->dev, "IRQ assigned: %d\n", pdev->irq);
8789
Wayne Boyer214777b2010-02-19 13:24:26 -08008790 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
Wayne Boyer95fecd92009-06-16 15:13:28 -07008791 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
8792 wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
8793 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
8794
8795 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8796 if (!ioa_cfg->msi_received) {
8797 /* MSI test failed */
8798 dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
8799 rc = -EOPNOTSUPP;
8800 } else if (ipr_debug)
8801 dev_info(&pdev->dev, "MSI test succeeded.\n");
8802
8803 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8804
8805 free_irq(pdev->irq, ioa_cfg);
8806
8807 LEAVE;
8808
8809 return rc;
8810}
8811
8812/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008813 * ipr_probe_ioa - Allocates memory and does first stage of initialization
8814 * @pdev: PCI device struct
8815 * @dev_id: PCI device id struct
8816 *
8817 * Return value:
8818 * 0 on success / non-zero on failure
8819 **/
8820static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
8821 const struct pci_device_id *dev_id)
8822{
8823 struct ipr_ioa_cfg *ioa_cfg;
8824 struct Scsi_Host *host;
8825 unsigned long ipr_regs_pci;
8826 void __iomem *ipr_regs;
Eric Sesterhenna2a65a32006-09-25 16:59:07 -07008827 int rc = PCIBIOS_SUCCESSFUL;
Brian King473b1e82007-05-02 10:44:11 -05008828 volatile u32 mask, uproc, interrupts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008829
8830 ENTER;
8831
8832 if ((rc = pci_enable_device(pdev))) {
8833 dev_err(&pdev->dev, "Cannot enable adapter\n");
8834 goto out;
8835 }
8836
8837 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
8838
8839 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
8840
8841 if (!host) {
8842 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
8843 rc = -ENOMEM;
8844 goto out_disable;
8845 }
8846
8847 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
8848 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
Dan Williams8d8e7d12012-07-09 21:06:08 -07008849 ata_host_init(&ioa_cfg->ata_host, &pdev->dev, &ipr_sata_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008850
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008851 ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008852
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008853 if (!ioa_cfg->ipr_chip) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008854 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
8855 dev_id->vendor, dev_id->device);
8856 goto out_scsi_host_put;
8857 }
8858
Wayne Boyera32c0552010-02-19 13:23:36 -08008859 /* set SIS 32 or SIS 64 */
8860 ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008861 ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
Brian King7dd21302012-03-14 21:20:08 -05008862 ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
Brian King89aad422012-03-14 21:20:10 -05008863 ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008864
Brian King5469cb52007-03-29 12:42:40 -05008865 if (ipr_transop_timeout)
8866 ioa_cfg->transop_timeout = ipr_transop_timeout;
8867 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
8868 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
8869 else
8870 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
8871
Auke Kok44c10132007-06-08 15:46:36 -07008872 ioa_cfg->revid = pdev->revision;
Brian King463fc692007-05-07 17:09:05 -05008873
Linus Torvalds1da177e2005-04-16 15:20:36 -07008874 ipr_regs_pci = pci_resource_start(pdev, 0);
8875
8876 rc = pci_request_regions(pdev, IPR_NAME);
8877 if (rc < 0) {
8878 dev_err(&pdev->dev,
8879 "Couldn't register memory range of registers\n");
8880 goto out_scsi_host_put;
8881 }
8882
Arjan van de Ven25729a72008-09-28 16:18:02 -07008883 ipr_regs = pci_ioremap_bar(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008884
8885 if (!ipr_regs) {
8886 dev_err(&pdev->dev,
8887 "Couldn't map memory range of registers\n");
8888 rc = -ENOMEM;
8889 goto out_release_regions;
8890 }
8891
8892 ioa_cfg->hdw_dma_regs = ipr_regs;
8893 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
8894 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
8895
8896 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
8897
8898 pci_set_master(pdev);
8899
Wayne Boyera32c0552010-02-19 13:23:36 -08008900 if (ioa_cfg->sis64) {
8901 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
8902 if (rc < 0) {
8903 dev_dbg(&pdev->dev, "Failed to set 64 bit PCI DMA mask\n");
8904 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
8905 }
8906
8907 } else
8908 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
8909
Linus Torvalds1da177e2005-04-16 15:20:36 -07008910 if (rc < 0) {
8911 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
8912 goto cleanup_nomem;
8913 }
8914
8915 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
8916 ioa_cfg->chip_cfg->cache_line_size);
8917
8918 if (rc != PCIBIOS_SUCCESSFUL) {
8919 dev_err(&pdev->dev, "Write of cache line size failed\n");
8920 rc = -EIO;
8921 goto cleanup_nomem;
8922 }
8923
Wayne Boyer95fecd92009-06-16 15:13:28 -07008924 /* Enable MSI style interrupts if they are supported. */
Wayne Boyer1be7bd82009-06-17 09:55:35 -07008925 if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI && !pci_enable_msi(pdev)) {
Wayne Boyer95fecd92009-06-16 15:13:28 -07008926 rc = ipr_test_msi(ioa_cfg, pdev);
8927 if (rc == -EOPNOTSUPP)
8928 pci_disable_msi(pdev);
8929 else if (rc)
8930 goto out_msi_disable;
8931 else
8932 dev_info(&pdev->dev, "MSI enabled with IRQ: %d\n", pdev->irq);
8933 } else if (ipr_debug)
8934 dev_info(&pdev->dev, "Cannot enable MSI.\n");
8935
Linus Torvalds1da177e2005-04-16 15:20:36 -07008936 /* Save away PCI config space for use following IOA reset */
8937 rc = pci_save_state(pdev);
8938
8939 if (rc != PCIBIOS_SUCCESSFUL) {
8940 dev_err(&pdev->dev, "Failed to save PCI config space\n");
8941 rc = -EIO;
Julia Lawallf170c682011-07-11 14:08:25 -07008942 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008943 }
8944
8945 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
Julia Lawallf170c682011-07-11 14:08:25 -07008946 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008947
8948 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
Julia Lawallf170c682011-07-11 14:08:25 -07008949 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008950
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008951 if (ioa_cfg->sis64)
8952 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
8953 + ((sizeof(struct ipr_config_table_entry64)
8954 * ioa_cfg->max_devs_supported)));
8955 else
8956 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
8957 + ((sizeof(struct ipr_config_table_entry)
8958 * ioa_cfg->max_devs_supported)));
8959
Linus Torvalds1da177e2005-04-16 15:20:36 -07008960 rc = ipr_alloc_mem(ioa_cfg);
8961 if (rc < 0) {
8962 dev_err(&pdev->dev,
8963 "Couldn't allocate enough memory for device driver!\n");
Julia Lawallf170c682011-07-11 14:08:25 -07008964 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008965 }
8966
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06008967 /*
8968 * If HRRQ updated interrupt is not masked, or reset alert is set,
8969 * the card is in an unknown state and needs a hard reset
8970 */
Wayne Boyer214777b2010-02-19 13:24:26 -08008971 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
8972 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
8973 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06008974 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
8975 ioa_cfg->needs_hard_reset = 1;
Anton Blanchard5d7c20b2011-08-01 19:43:45 +10008976 if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
Brian King473b1e82007-05-02 10:44:11 -05008977 ioa_cfg->needs_hard_reset = 1;
8978 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
8979 ioa_cfg->ioa_unit_checked = 1;
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06008980
Linus Torvalds1da177e2005-04-16 15:20:36 -07008981 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
Wayne Boyer95fecd92009-06-16 15:13:28 -07008982 rc = request_irq(pdev->irq, ipr_isr,
8983 ioa_cfg->msi_received ? 0 : IRQF_SHARED,
8984 IPR_NAME, ioa_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008985
8986 if (rc) {
8987 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
8988 pdev->irq, rc);
8989 goto cleanup_nolog;
8990 }
8991
Brian King463fc692007-05-07 17:09:05 -05008992 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
8993 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
8994 ioa_cfg->needs_warm_reset = 1;
8995 ioa_cfg->reset = ipr_reset_slot_reset;
8996 } else
8997 ioa_cfg->reset = ipr_reset_start_bist;
8998
Linus Torvalds1da177e2005-04-16 15:20:36 -07008999 spin_lock(&ipr_driver_lock);
9000 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
9001 spin_unlock(&ipr_driver_lock);
9002
9003 LEAVE;
9004out:
9005 return rc;
9006
9007cleanup_nolog:
9008 ipr_free_mem(ioa_cfg);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009009out_msi_disable:
9010 pci_disable_msi(pdev);
Julia Lawallf170c682011-07-11 14:08:25 -07009011cleanup_nomem:
9012 iounmap(ipr_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009013out_release_regions:
9014 pci_release_regions(pdev);
9015out_scsi_host_put:
9016 scsi_host_put(host);
9017out_disable:
9018 pci_disable_device(pdev);
9019 goto out;
9020}
9021
9022/**
9023 * ipr_scan_vsets - Scans for VSET devices
9024 * @ioa_cfg: ioa config struct
9025 *
9026 * Description: Since the VSET resources do not follow SAM in that we can have
9027 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
9028 *
9029 * Return value:
9030 * none
9031 **/
9032static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
9033{
9034 int target, lun;
9035
9036 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
9037 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
9038 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
9039}
9040
9041/**
9042 * ipr_initiate_ioa_bringdown - Bring down an adapter
9043 * @ioa_cfg: ioa config struct
9044 * @shutdown_type: shutdown type
9045 *
9046 * Description: This function will initiate bringing down the adapter.
9047 * This consists of issuing an IOA shutdown to the adapter
9048 * to flush the cache, and running BIST.
9049 * If the caller needs to wait on the completion of the reset,
9050 * the caller must sleep on the reset_wait_q.
9051 *
9052 * Return value:
9053 * none
9054 **/
9055static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
9056 enum ipr_shutdown_type shutdown_type)
9057{
9058 ENTER;
9059 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
9060 ioa_cfg->sdt_state = ABORT_DUMP;
9061 ioa_cfg->reset_retries = 0;
9062 ioa_cfg->in_ioa_bringdown = 1;
9063 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
9064 LEAVE;
9065}
9066
9067/**
9068 * __ipr_remove - Remove a single adapter
9069 * @pdev: pci device struct
9070 *
9071 * Adapter hot plug remove entry point.
9072 *
9073 * Return value:
9074 * none
9075 **/
9076static void __ipr_remove(struct pci_dev *pdev)
9077{
9078 unsigned long host_lock_flags = 0;
9079 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9080 ENTER;
9081
9082 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
Brian King970ea292007-04-26 16:00:06 -05009083 while(ioa_cfg->in_reset_reload) {
9084 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9085 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9086 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9087 }
9088
Linus Torvalds1da177e2005-04-16 15:20:36 -07009089 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9090
9091 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9092 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
Tejun Heoa684b8d2011-01-24 14:57:28 +01009093 flush_work_sync(&ioa_cfg->work_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009094 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9095
9096 spin_lock(&ipr_driver_lock);
9097 list_del(&ioa_cfg->queue);
9098 spin_unlock(&ipr_driver_lock);
9099
9100 if (ioa_cfg->sdt_state == ABORT_DUMP)
9101 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
9102 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9103
9104 ipr_free_all_resources(ioa_cfg);
9105
9106 LEAVE;
9107}
9108
9109/**
9110 * ipr_remove - IOA hot plug remove entry point
9111 * @pdev: pci device struct
9112 *
9113 * Adapter hot plug remove entry point.
9114 *
9115 * Return value:
9116 * none
9117 **/
Kleber S. Souzaf3816422009-04-22 10:50:28 -03009118static void __devexit ipr_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009119{
9120 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9121
9122 ENTER;
9123
Tony Jonesee959b02008-02-22 00:13:36 +01009124 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009125 &ipr_trace_attr);
Tony Jonesee959b02008-02-22 00:13:36 +01009126 ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009127 &ipr_dump_attr);
9128 scsi_remove_host(ioa_cfg->host);
9129
9130 __ipr_remove(pdev);
9131
9132 LEAVE;
9133}
9134
9135/**
9136 * ipr_probe - Adapter hot plug add entry point
9137 *
9138 * Return value:
9139 * 0 on success / non-zero on failure
9140 **/
9141static int __devinit ipr_probe(struct pci_dev *pdev,
9142 const struct pci_device_id *dev_id)
9143{
9144 struct ipr_ioa_cfg *ioa_cfg;
9145 int rc;
9146
9147 rc = ipr_probe_ioa(pdev, dev_id);
9148
9149 if (rc)
9150 return rc;
9151
9152 ioa_cfg = pci_get_drvdata(pdev);
9153 rc = ipr_probe_ioa_part2(ioa_cfg);
9154
9155 if (rc) {
9156 __ipr_remove(pdev);
9157 return rc;
9158 }
9159
9160 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
9161
9162 if (rc) {
9163 __ipr_remove(pdev);
9164 return rc;
9165 }
9166
Tony Jonesee959b02008-02-22 00:13:36 +01009167 rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009168 &ipr_trace_attr);
9169
9170 if (rc) {
9171 scsi_remove_host(ioa_cfg->host);
9172 __ipr_remove(pdev);
9173 return rc;
9174 }
9175
Tony Jonesee959b02008-02-22 00:13:36 +01009176 rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009177 &ipr_dump_attr);
9178
9179 if (rc) {
Tony Jonesee959b02008-02-22 00:13:36 +01009180 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009181 &ipr_trace_attr);
9182 scsi_remove_host(ioa_cfg->host);
9183 __ipr_remove(pdev);
9184 return rc;
9185 }
9186
9187 scsi_scan_host(ioa_cfg->host);
9188 ipr_scan_vsets(ioa_cfg);
9189 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
9190 ioa_cfg->allow_ml_add_del = 1;
brking@us.ibm.com11cd8f12005-11-01 17:00:11 -06009191 ioa_cfg->host->max_channel = IPR_VSET_BUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009192 schedule_work(&ioa_cfg->work_q);
9193 return 0;
9194}
9195
9196/**
9197 * ipr_shutdown - Shutdown handler.
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07009198 * @pdev: pci device struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07009199 *
9200 * This function is invoked upon system shutdown/reboot. It will issue
9201 * an adapter shutdown to the adapter to flush the write cache.
9202 *
9203 * Return value:
9204 * none
9205 **/
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07009206static void ipr_shutdown(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009207{
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07009208 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009209 unsigned long lock_flags = 0;
9210
9211 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King970ea292007-04-26 16:00:06 -05009212 while(ioa_cfg->in_reset_reload) {
9213 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9214 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9215 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9216 }
9217
Linus Torvalds1da177e2005-04-16 15:20:36 -07009218 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9219 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9220 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9221}
9222
9223static struct pci_device_id ipr_pci_table[] __devinitdata = {
9224 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -06009225 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009226 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -06009227 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009228 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -06009229 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009230 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -06009231 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009232 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -06009233 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009234 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -06009235 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009236 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -06009237 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009238 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King5469cb52007-03-29 12:42:40 -05009239 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
9240 IPR_USE_LONG_TRANSOP_TIMEOUT },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009241 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King6d84c942007-01-23 11:25:23 -06009242 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009243 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King22d2e402007-04-26 16:00:13 -05009244 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
9245 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -06009246 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King5469cb52007-03-29 12:42:40 -05009247 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
9248 IPR_USE_LONG_TRANSOP_TIMEOUT },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009249 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King6d84c942007-01-23 11:25:23 -06009250 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009251 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King22d2e402007-04-26 16:00:13 -05009252 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
9253 IPR_USE_LONG_TRANSOP_TIMEOUT},
Brian King60e74862006-11-21 10:28:10 -06009254 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King5469cb52007-03-29 12:42:40 -05009255 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
9256 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -06009257 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King22d2e402007-04-26 16:00:13 -05009258 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
9259 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King185eb312007-03-29 12:42:53 -05009260 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King185eb312007-03-29 12:42:53 -05009261 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
9262 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Wayne Boyerb0f56d32010-06-24 13:34:14 -07009263 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
9264 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King5469cb52007-03-29 12:42:40 -05009265 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
Brian King463fc692007-05-07 17:09:05 -05009266 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009267 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
Brian King6d84c942007-01-23 11:25:23 -06009268 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009269 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King6d84c942007-01-23 11:25:23 -06009270 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -06009271 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King5469cb52007-03-29 12:42:40 -05009272 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
9273 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -06009274 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King5469cb52007-03-29 12:42:40 -05009275 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
9276 IPR_USE_LONG_TRANSOP_TIMEOUT },
Wayne Boyerd7b46272010-02-19 13:24:38 -08009277 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9278 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
9279 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9280 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
9281 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9282 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
Wayne Boyer32622bd2010-10-18 20:24:34 -07009283 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
Wayne Boyer5a918352011-10-27 11:58:21 -07009284 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
9285 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
Wayne Boyer32622bd2010-10-18 20:24:34 -07009286 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -08009287 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -08009288 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -08009289 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -08009290 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -08009291 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -08009292 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -08009293 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9294 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
9295 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -08009296 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009297 { }
9298};
9299MODULE_DEVICE_TABLE(pci, ipr_pci_table);
9300
Linas Vepstasf8a88b192006-02-03 16:52:42 -06009301static struct pci_error_handlers ipr_err_handler = {
9302 .error_detected = ipr_pci_error_detected,
9303 .slot_reset = ipr_pci_slot_reset,
9304};
9305
Linus Torvalds1da177e2005-04-16 15:20:36 -07009306static struct pci_driver ipr_driver = {
9307 .name = IPR_NAME,
9308 .id_table = ipr_pci_table,
9309 .probe = ipr_probe,
Kleber S. Souzaf3816422009-04-22 10:50:28 -03009310 .remove = __devexit_p(ipr_remove),
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07009311 .shutdown = ipr_shutdown,
Linas Vepstasf8a88b192006-02-03 16:52:42 -06009312 .err_handler = &ipr_err_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009313};
9314
9315/**
Wayne Boyerf72919e2010-02-19 13:24:21 -08009316 * ipr_halt_done - Shutdown prepare completion
9317 *
9318 * Return value:
9319 * none
9320 **/
9321static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
9322{
9323 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
9324
9325 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
9326}
9327
9328/**
9329 * ipr_halt - Issue shutdown prepare to all adapters
9330 *
9331 * Return value:
9332 * NOTIFY_OK on success / NOTIFY_DONE on failure
9333 **/
9334static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
9335{
9336 struct ipr_cmnd *ipr_cmd;
9337 struct ipr_ioa_cfg *ioa_cfg;
9338 unsigned long flags = 0;
9339
9340 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
9341 return NOTIFY_DONE;
9342
9343 spin_lock(&ipr_driver_lock);
9344
9345 list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
9346 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
9347 if (!ioa_cfg->allow_cmds) {
9348 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
9349 continue;
9350 }
9351
9352 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
9353 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
9354 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
9355 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
9356 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
9357
9358 ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
9359 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
9360 }
9361 spin_unlock(&ipr_driver_lock);
9362
9363 return NOTIFY_OK;
9364}
9365
9366static struct notifier_block ipr_notifier = {
9367 ipr_halt, NULL, 0
9368};
9369
9370/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07009371 * ipr_init - Module entry point
9372 *
9373 * Return value:
9374 * 0 on success / negative value on failure
9375 **/
9376static int __init ipr_init(void)
9377{
9378 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
9379 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
9380
Wayne Boyerf72919e2010-02-19 13:24:21 -08009381 register_reboot_notifier(&ipr_notifier);
Henrik Kretzschmardcbccbde2006-09-25 16:58:58 -07009382 return pci_register_driver(&ipr_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009383}
9384
9385/**
9386 * ipr_exit - Module unload
9387 *
9388 * Module unload entry point.
9389 *
9390 * Return value:
9391 * none
9392 **/
9393static void __exit ipr_exit(void)
9394{
Wayne Boyerf72919e2010-02-19 13:24:21 -08009395 unregister_reboot_notifier(&ipr_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009396 pci_unregister_driver(&ipr_driver);
9397}
9398
9399module_init(ipr_init);
9400module_exit(ipr_exit);