blob: d9afc51af7d3dbc7df2e38865596ba3473a1f708 [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;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600101static unsigned int ipr_number_of_msix = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102static DEFINE_SPINLOCK(ipr_driver_lock);
103
104/* This table describes the differences between DMA controller chips */
105static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
Brian King60e74862006-11-21 10:28:10 -0600106 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 .mailbox = 0x0042C,
Brian King89aad422012-03-14 21:20:10 -0500108 .max_cmds = 100,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 .cache_line_size = 0x20,
Brian King7dd21302012-03-14 21:20:08 -0500110 .clear_isr = 1,
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -0600111 .iopoll_weight = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 {
113 .set_interrupt_mask_reg = 0x0022C,
114 .clr_interrupt_mask_reg = 0x00230,
Wayne Boyer214777b2010-02-19 13:24:26 -0800115 .clr_interrupt_mask_reg32 = 0x00230,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 .sense_interrupt_mask_reg = 0x0022C,
Wayne Boyer214777b2010-02-19 13:24:26 -0800117 .sense_interrupt_mask_reg32 = 0x0022C,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .clr_interrupt_reg = 0x00228,
Wayne Boyer214777b2010-02-19 13:24:26 -0800119 .clr_interrupt_reg32 = 0x00228,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .sense_interrupt_reg = 0x00224,
Wayne Boyer214777b2010-02-19 13:24:26 -0800121 .sense_interrupt_reg32 = 0x00224,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 .ioarrin_reg = 0x00404,
123 .sense_uproc_interrupt_reg = 0x00214,
Wayne Boyer214777b2010-02-19 13:24:26 -0800124 .sense_uproc_interrupt_reg32 = 0x00214,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 .set_uproc_interrupt_reg = 0x00214,
Wayne Boyer214777b2010-02-19 13:24:26 -0800126 .set_uproc_interrupt_reg32 = 0x00214,
127 .clr_uproc_interrupt_reg = 0x00218,
128 .clr_uproc_interrupt_reg32 = 0x00218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
130 },
131 { /* Snipe and Scamp */
132 .mailbox = 0x0052C,
Brian King89aad422012-03-14 21:20:10 -0500133 .max_cmds = 100,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 .cache_line_size = 0x20,
Brian King7dd21302012-03-14 21:20:08 -0500135 .clear_isr = 1,
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -0600136 .iopoll_weight = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 {
138 .set_interrupt_mask_reg = 0x00288,
139 .clr_interrupt_mask_reg = 0x0028C,
Wayne Boyer214777b2010-02-19 13:24:26 -0800140 .clr_interrupt_mask_reg32 = 0x0028C,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 .sense_interrupt_mask_reg = 0x00288,
Wayne Boyer214777b2010-02-19 13:24:26 -0800142 .sense_interrupt_mask_reg32 = 0x00288,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 .clr_interrupt_reg = 0x00284,
Wayne Boyer214777b2010-02-19 13:24:26 -0800144 .clr_interrupt_reg32 = 0x00284,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 .sense_interrupt_reg = 0x00280,
Wayne Boyer214777b2010-02-19 13:24:26 -0800146 .sense_interrupt_reg32 = 0x00280,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 .ioarrin_reg = 0x00504,
148 .sense_uproc_interrupt_reg = 0x00290,
Wayne Boyer214777b2010-02-19 13:24:26 -0800149 .sense_uproc_interrupt_reg32 = 0x00290,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 .set_uproc_interrupt_reg = 0x00290,
Wayne Boyer214777b2010-02-19 13:24:26 -0800151 .set_uproc_interrupt_reg32 = 0x00290,
152 .clr_uproc_interrupt_reg = 0x00294,
153 .clr_uproc_interrupt_reg32 = 0x00294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155 },
Wayne Boyera74c1632010-02-19 13:23:51 -0800156 { /* CRoC */
Wayne Boyer110def82010-11-04 09:36:16 -0700157 .mailbox = 0x00044,
Brian King89aad422012-03-14 21:20:10 -0500158 .max_cmds = 1000,
Wayne Boyera74c1632010-02-19 13:23:51 -0800159 .cache_line_size = 0x20,
Brian King7dd21302012-03-14 21:20:08 -0500160 .clear_isr = 0,
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -0600161 .iopoll_weight = 64,
Wayne Boyera74c1632010-02-19 13:23:51 -0800162 {
163 .set_interrupt_mask_reg = 0x00010,
164 .clr_interrupt_mask_reg = 0x00018,
Wayne Boyer214777b2010-02-19 13:24:26 -0800165 .clr_interrupt_mask_reg32 = 0x0001C,
Wayne Boyera74c1632010-02-19 13:23:51 -0800166 .sense_interrupt_mask_reg = 0x00010,
Wayne Boyer214777b2010-02-19 13:24:26 -0800167 .sense_interrupt_mask_reg32 = 0x00014,
Wayne Boyera74c1632010-02-19 13:23:51 -0800168 .clr_interrupt_reg = 0x00008,
Wayne Boyer214777b2010-02-19 13:24:26 -0800169 .clr_interrupt_reg32 = 0x0000C,
Wayne Boyera74c1632010-02-19 13:23:51 -0800170 .sense_interrupt_reg = 0x00000,
Wayne Boyer214777b2010-02-19 13:24:26 -0800171 .sense_interrupt_reg32 = 0x00004,
Wayne Boyera74c1632010-02-19 13:23:51 -0800172 .ioarrin_reg = 0x00070,
173 .sense_uproc_interrupt_reg = 0x00020,
Wayne Boyer214777b2010-02-19 13:24:26 -0800174 .sense_uproc_interrupt_reg32 = 0x00024,
Wayne Boyera74c1632010-02-19 13:23:51 -0800175 .set_uproc_interrupt_reg = 0x00020,
Wayne Boyer214777b2010-02-19 13:24:26 -0800176 .set_uproc_interrupt_reg32 = 0x00024,
Wayne Boyerdcbad002010-02-19 13:24:14 -0800177 .clr_uproc_interrupt_reg = 0x00028,
Wayne Boyer214777b2010-02-19 13:24:26 -0800178 .clr_uproc_interrupt_reg32 = 0x0002C,
179 .init_feedback_reg = 0x0005C,
Wayne Boyerdcbad002010-02-19 13:24:14 -0800180 .dump_addr_reg = 0x00064,
Wayne Boyer8701f182010-06-04 10:26:50 -0700181 .dump_data_reg = 0x00068,
182 .endian_swap_reg = 0x00084
Wayne Boyera74c1632010-02-19 13:23:51 -0800183 }
184 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185};
186
187static const struct ipr_chip_t ipr_chip[] = {
Wayne Boyercb237ef2010-06-17 11:51:40 -0700188 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
189 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
190 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
191 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
192 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, IPR_USE_MSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
193 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
194 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
195 { 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 -0800196 { 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 -0700197};
198
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -0300199static int ipr_max_bus_speeds[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
201};
202
203MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
204MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
205module_param_named(max_speed, ipr_max_speed, uint, 0);
206MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
207module_param_named(log_level, ipr_log_level, uint, 0);
208MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
209module_param_named(testmode, ipr_testmode, int, 0);
210MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
Wayne Boyer2cf22be2009-02-24 11:36:00 -0800211module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
213module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
214MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
Wayne Boyer2cf22be2009-02-24 11:36:00 -0800215module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
brking@us.ibm.comd3c74872005-11-01 17:01:34 -0600216MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
Brian Kingac09c342007-04-26 16:00:16 -0500217module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
218MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -0800219module_param_named(max_devs, ipr_max_devs, int, 0);
220MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
221 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600222module_param_named(number_of_msix, ipr_number_of_msix, int, 0);
wenxiong@linux.vnet.ibm.com6634ff72013-11-15 10:58:15 -0600223MODULE_PARM_DESC(number_of_msix, "Specify the number of MSIX interrupts to use on capable adapters (1 - 16). (default:2)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224MODULE_LICENSE("GPL");
225MODULE_VERSION(IPR_DRIVER_VERSION);
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227/* A constant array of IOASCs/URCs/Error Messages */
228static const
229struct ipr_error_table_t ipr_error_table[] = {
Brian King933916f2007-03-29 12:43:30 -0500230 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 "8155: An unknown error was received"},
232 {0x00330000, 0, 0,
233 "Soft underlength error"},
234 {0x005A0000, 0, 0,
235 "Command to be cancelled not found"},
236 {0x00808000, 0, 0,
237 "Qualified success"},
Brian King933916f2007-03-29 12:43:30 -0500238 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 "FFFE: Soft device bus error recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500240 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500241 "4101: Soft device bus fabric error"},
Wayne Boyer5aa3a332010-02-19 13:24:32 -0800242 {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
243 "FFFC: Logical block guard error recovered by the device"},
244 {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
245 "FFFC: Logical block reference tag error recovered by the device"},
246 {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
247 "4171: Recovered scatter list tag / sequence number error"},
248 {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
249 "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
250 {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
251 "4171: Recovered logical block sequence number error on IOA to Host transfer"},
252 {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
253 "FFFD: Recovered logical block reference tag error detected by the IOA"},
254 {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
255 "FFFD: Logical block guard error recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500256 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 "FFF9: Device sector reassign successful"},
Brian King933916f2007-03-29 12:43:30 -0500258 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 "FFF7: Media error recovered by device rewrite procedures"},
Brian King933916f2007-03-29 12:43:30 -0500260 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 "7001: IOA sector reassignment successful"},
Brian King933916f2007-03-29 12:43:30 -0500262 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 "FFF9: Soft media error. Sector reassignment recommended"},
Brian King933916f2007-03-29 12:43:30 -0500264 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 "FFF7: Media error recovered by IOA rewrite procedures"},
Brian King933916f2007-03-29 12:43:30 -0500266 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 "FF3D: Soft PCI bus error recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500268 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 "FFF6: Device hardware error recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500270 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 "FFF6: Device hardware error recovered by the device"},
Brian King933916f2007-03-29 12:43:30 -0500272 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 "FF3D: Soft IOA error recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500274 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 "FFFA: Undefined device response recovered by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500276 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 "FFF6: Device bus error, message or command phase"},
Brian King933916f2007-03-29 12:43:30 -0500278 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King35a39692006-09-25 12:39:20 -0500279 "FFFE: Task Management Function failed"},
Brian King933916f2007-03-29 12:43:30 -0500280 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 "FFF6: Failure prediction threshold exceeded"},
Brian King933916f2007-03-29 12:43:30 -0500282 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 "8009: Impending cache battery pack failure"},
wenxiong@linux.vnet.ibm.comed7bd662013-06-04 18:57:35 -0500284 {0x02040100, 0, 0,
285 "Logical Unit in process of becoming ready"},
286 {0x02040200, 0, 0,
287 "Initializing command required"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 {0x02040400, 0, 0,
289 "34FF: Disk device format in progress"},
wenxiong@linux.vnet.ibm.comed7bd662013-06-04 18:57:35 -0500290 {0x02040C00, 0, 0,
291 "Logical unit not accessible, target port in unavailable state"},
Brian King65f56472007-04-26 16:00:12 -0500292 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
293 "9070: IOA requested reset"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 {0x023F0000, 0, 0,
295 "Synchronization required"},
wenxiong@linux.vnet.ibm.comed7bd662013-06-04 18:57:35 -0500296 {0x02408500, 0, 0,
297 "IOA microcode download required"},
298 {0x02408600, 0, 0,
299 "Device bus connection is prohibited by host"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 {0x024E0000, 0, 0,
301 "No ready, IOA shutdown"},
302 {0x025A0000, 0, 0,
303 "Not ready, IOA has been shutdown"},
Brian King933916f2007-03-29 12:43:30 -0500304 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 "3020: Storage subsystem configuration error"},
306 {0x03110B00, 0, 0,
307 "FFF5: Medium error, data unreadable, recommend reassign"},
308 {0x03110C00, 0, 0,
309 "7000: Medium error, data unreadable, do not reassign"},
Brian King933916f2007-03-29 12:43:30 -0500310 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 "FFF3: Disk media format bad"},
Brian King933916f2007-03-29 12:43:30 -0500312 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 "3002: Addressed device failed to respond to selection"},
Brian King933916f2007-03-29 12:43:30 -0500314 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 "3100: Device bus error"},
Brian King933916f2007-03-29 12:43:30 -0500316 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 "3109: IOA timed out a device command"},
318 {0x04088000, 0, 0,
319 "3120: SCSI bus is not operational"},
Brian King933916f2007-03-29 12:43:30 -0500320 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500321 "4100: Hard device bus fabric error"},
Wayne Boyer5aa3a332010-02-19 13:24:32 -0800322 {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
323 "310C: Logical block guard error detected by the device"},
324 {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
325 "310C: Logical block reference tag error detected by the device"},
326 {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
327 "4170: Scatter list tag / sequence number error"},
328 {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
329 "8150: Logical block CRC error on IOA to Host transfer"},
330 {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
331 "4170: Logical block sequence number error on IOA to Host transfer"},
332 {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
333 "310D: Logical block reference tag error detected by the IOA"},
334 {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
335 "310D: Logical block guard error detected by the IOA"},
Brian King933916f2007-03-29 12:43:30 -0500336 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 "9000: IOA reserved area data check"},
Brian King933916f2007-03-29 12:43:30 -0500338 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 "9001: IOA reserved area invalid data pattern"},
Brian King933916f2007-03-29 12:43:30 -0500340 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 "9002: IOA reserved area LRC error"},
Wayne Boyer5aa3a332010-02-19 13:24:32 -0800342 {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
343 "Hardware Error, IOA metadata access error"},
Brian King933916f2007-03-29 12:43:30 -0500344 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 "102E: Out of alternate sectors for disk storage"},
Brian King933916f2007-03-29 12:43:30 -0500346 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 "FFF4: Data transfer underlength error"},
Brian King933916f2007-03-29 12:43:30 -0500348 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 "FFF4: Data transfer overlength error"},
Brian King933916f2007-03-29 12:43:30 -0500350 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 "3400: Logical unit failure"},
Brian King933916f2007-03-29 12:43:30 -0500352 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 "FFF4: Device microcode is corrupt"},
Brian King933916f2007-03-29 12:43:30 -0500354 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 "8150: PCI bus error"},
356 {0x04430000, 1, 0,
357 "Unsupported device bus message received"},
Brian King933916f2007-03-29 12:43:30 -0500358 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 "FFF4: Disk device problem"},
Brian King933916f2007-03-29 12:43:30 -0500360 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 "8150: Permanent IOA failure"},
Brian King933916f2007-03-29 12:43:30 -0500362 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 "3010: Disk device returned wrong response to IOA"},
Brian King933916f2007-03-29 12:43:30 -0500364 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 "8151: IOA microcode error"},
366 {0x04448500, 0, 0,
367 "Device bus status error"},
Brian King933916f2007-03-29 12:43:30 -0500368 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 "8157: IOA error requiring IOA reset to recover"},
Brian King35a39692006-09-25 12:39:20 -0500370 {0x04448700, 0, 0,
371 "ATA device status error"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 {0x04490000, 0, 0,
373 "Message reject received from the device"},
Brian King933916f2007-03-29 12:43:30 -0500374 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 "8008: A permanent cache battery pack failure occurred"},
Brian King933916f2007-03-29 12:43:30 -0500376 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 "9090: Disk unit has been modified after the last known status"},
Brian King933916f2007-03-29 12:43:30 -0500378 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 "9081: IOA detected device error"},
Brian King933916f2007-03-29 12:43:30 -0500380 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 "9082: IOA detected device error"},
Brian King933916f2007-03-29 12:43:30 -0500382 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 "3110: Device bus error, message or command phase"},
Brian King933916f2007-03-29 12:43:30 -0500384 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
Brian King35a39692006-09-25 12:39:20 -0500385 "3110: SAS Command / Task Management Function failed"},
Brian King933916f2007-03-29 12:43:30 -0500386 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 "9091: Incorrect hardware configuration change has been detected"},
Brian King933916f2007-03-29 12:43:30 -0500388 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600389 "9073: Invalid multi-adapter configuration"},
Brian King933916f2007-03-29 12:43:30 -0500390 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500391 "4010: Incorrect connection between cascaded expanders"},
Brian King933916f2007-03-29 12:43:30 -0500392 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500393 "4020: Connections exceed IOA design limits"},
Brian King933916f2007-03-29 12:43:30 -0500394 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500395 "4030: Incorrect multipath connection"},
Brian King933916f2007-03-29 12:43:30 -0500396 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500397 "4110: Unsupported enclosure function"},
wenxiong@linux.vnet.ibm.comed7bd662013-06-04 18:57:35 -0500398 {0x04679800, 0, IPR_DEFAULT_LOG_LEVEL,
399 "4120: SAS cable VPD cannot be read"},
Brian King933916f2007-03-29 12:43:30 -0500400 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 "FFF4: Command to logical unit failed"},
402 {0x05240000, 1, 0,
403 "Illegal request, invalid request type or request packet"},
404 {0x05250000, 0, 0,
405 "Illegal request, invalid resource handle"},
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600406 {0x05258000, 0, 0,
407 "Illegal request, commands not allowed to this device"},
408 {0x05258100, 0, 0,
409 "Illegal request, command not allowed to a secondary adapter"},
Wayne Boyer5aa3a332010-02-19 13:24:32 -0800410 {0x05258200, 0, 0,
411 "Illegal request, command not allowed to a non-optimized resource"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 {0x05260000, 0, 0,
413 "Illegal request, invalid field in parameter list"},
414 {0x05260100, 0, 0,
415 "Illegal request, parameter not supported"},
416 {0x05260200, 0, 0,
417 "Illegal request, parameter value invalid"},
418 {0x052C0000, 0, 0,
419 "Illegal request, command sequence error"},
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600420 {0x052C8000, 1, 0,
421 "Illegal request, dual adapter support not enabled"},
wenxiong@linux.vnet.ibm.comed7bd662013-06-04 18:57:35 -0500422 {0x052C8100, 1, 0,
423 "Illegal request, another cable connector was physically disabled"},
424 {0x054E8000, 1, 0,
425 "Illegal request, inconsistent group id/group count"},
Brian King933916f2007-03-29 12:43:30 -0500426 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 "9031: Array protection temporarily suspended, protection resuming"},
Brian King933916f2007-03-29 12:43:30 -0500428 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 "9040: Array protection temporarily suspended, protection resuming"},
wenxiong@linux.vnet.ibm.comed7bd662013-06-04 18:57:35 -0500430 {0x060B0100, 0, IPR_DEFAULT_LOG_LEVEL,
431 "4080: IOA exceeded maximum operating temperature"},
432 {0x060B8000, 0, IPR_DEFAULT_LOG_LEVEL,
433 "4085: Service required"},
Brian King933916f2007-03-29 12:43:30 -0500434 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500435 "3140: Device bus not ready to ready transition"},
Brian King933916f2007-03-29 12:43:30 -0500436 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 "FFFB: SCSI bus was reset"},
438 {0x06290500, 0, 0,
439 "FFFE: SCSI bus transition to single ended"},
440 {0x06290600, 0, 0,
441 "FFFE: SCSI bus transition to LVD"},
Brian King933916f2007-03-29 12:43:30 -0500442 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 "FFFB: SCSI bus was reset by another initiator"},
Brian King933916f2007-03-29 12:43:30 -0500444 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 "3029: A device replacement has occurred"},
wenxiong@linux.vnet.ibm.comed7bd662013-06-04 18:57:35 -0500446 {0x063F8300, 0, IPR_DEFAULT_LOG_LEVEL,
447 "4102: Device bus fabric performance degradation"},
Brian King933916f2007-03-29 12:43:30 -0500448 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 "9051: IOA cache data exists for a missing or failed device"},
Brian King933916f2007-03-29 12:43:30 -0500450 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600451 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
Brian King933916f2007-03-29 12:43:30 -0500452 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 "9025: Disk unit is not supported at its physical location"},
Brian King933916f2007-03-29 12:43:30 -0500454 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 "3020: IOA detected a SCSI bus configuration error"},
Brian King933916f2007-03-29 12:43:30 -0500456 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 "3150: SCSI bus configuration error"},
Brian King933916f2007-03-29 12:43:30 -0500458 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600459 "9074: Asymmetric advanced function disk configuration"},
Brian King933916f2007-03-29 12:43:30 -0500460 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500461 "4040: Incomplete multipath connection between IOA and enclosure"},
Brian King933916f2007-03-29 12:43:30 -0500462 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500463 "4041: Incomplete multipath connection between enclosure and device"},
Brian King933916f2007-03-29 12:43:30 -0500464 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500465 "9075: Incomplete multipath connection between IOA and remote IOA"},
Brian King933916f2007-03-29 12:43:30 -0500466 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500467 "9076: Configuration error, missing remote IOA"},
Brian King933916f2007-03-29 12:43:30 -0500468 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500469 "4050: Enclosure does not support a required multipath function"},
wenxiong@linux.vnet.ibm.comed7bd662013-06-04 18:57:35 -0500470 {0x06679800, 0, IPR_DEFAULT_LOG_LEVEL,
471 "4121: Configuration error, required cable is missing"},
472 {0x06679900, 0, IPR_DEFAULT_LOG_LEVEL,
473 "4122: Cable is not plugged into the correct location on remote IOA"},
474 {0x06679A00, 0, IPR_DEFAULT_LOG_LEVEL,
475 "4123: Configuration error, invalid cable vital product data"},
476 {0x06679B00, 0, IPR_DEFAULT_LOG_LEVEL,
477 "4124: Configuration error, both cable ends are plugged into the same IOA"},
Wayne Boyerb75424f2009-01-28 08:24:50 -0800478 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
479 "4070: Logically bad block written on device"},
Brian King933916f2007-03-29 12:43:30 -0500480 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 "9041: Array protection temporarily suspended"},
Brian King933916f2007-03-29 12:43:30 -0500482 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 "9042: Corrupt array parity detected on specified device"},
Brian King933916f2007-03-29 12:43:30 -0500484 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 "9030: Array no longer protected due to missing or failed disk unit"},
Brian King933916f2007-03-29 12:43:30 -0500486 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600487 "9071: Link operational transition"},
Brian King933916f2007-03-29 12:43:30 -0500488 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -0600489 "9072: Link not operational transition"},
Brian King933916f2007-03-29 12:43:30 -0500490 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 "9032: Array exposed but still protected"},
Brian Kinge4353402007-03-29 12:43:37 -0500492 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
493 "70DD: Device forced failed by disrupt device command"},
Brian King933916f2007-03-29 12:43:30 -0500494 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500495 "4061: Multipath redundancy level got better"},
Brian King933916f2007-03-29 12:43:30 -0500496 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
Brian King896bbd22006-08-02 14:57:44 -0500497 "4060: Multipath redundancy level got worse"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 {0x07270000, 0, 0,
499 "Failure due to other device"},
Brian King933916f2007-03-29 12:43:30 -0500500 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 "9008: IOA does not support functions expected by devices"},
Brian King933916f2007-03-29 12:43:30 -0500502 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 "9010: Cache data associated with attached devices cannot be found"},
Brian King933916f2007-03-29 12:43:30 -0500504 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 "9011: Cache data belongs to devices other than those attached"},
Brian King933916f2007-03-29 12:43:30 -0500506 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 "9020: Array missing 2 or more devices with only 1 device present"},
Brian King933916f2007-03-29 12:43:30 -0500508 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 "9021: Array missing 2 or more devices with 2 or more devices present"},
Brian King933916f2007-03-29 12:43:30 -0500510 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 "9022: Exposed array is missing a required device"},
Brian King933916f2007-03-29 12:43:30 -0500512 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 "9023: Array member(s) not at required physical locations"},
Brian King933916f2007-03-29 12:43:30 -0500514 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 "9024: Array not functional due to present hardware configuration"},
Brian King933916f2007-03-29 12:43:30 -0500516 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 "9026: Array not functional due to present hardware configuration"},
Brian King933916f2007-03-29 12:43:30 -0500518 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 "9027: Array is missing a device and parity is out of sync"},
Brian King933916f2007-03-29 12:43:30 -0500520 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 "9028: Maximum number of arrays already exist"},
Brian King933916f2007-03-29 12:43:30 -0500522 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 "9050: Required cache data cannot be located for a disk unit"},
Brian King933916f2007-03-29 12:43:30 -0500524 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 "9052: Cache data exists for a device that has been modified"},
Brian King933916f2007-03-29 12:43:30 -0500526 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 "9054: IOA resources not available due to previous problems"},
Brian King933916f2007-03-29 12:43:30 -0500528 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 "9092: Disk unit requires initialization before use"},
Brian King933916f2007-03-29 12:43:30 -0500530 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 "9029: Incorrect hardware configuration change has been detected"},
Brian King933916f2007-03-29 12:43:30 -0500532 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 "9060: One or more disk pairs are missing from an array"},
Brian King933916f2007-03-29 12:43:30 -0500534 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 "9061: One or more disks are missing from an array"},
Brian King933916f2007-03-29 12:43:30 -0500536 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 "9062: One or more disks are missing from an array"},
Brian King933916f2007-03-29 12:43:30 -0500538 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 "9063: Maximum number of functional arrays has been exceeded"},
wenxiong@linux.vnet.ibm.comed7bd662013-06-04 18:57:35 -0500540 {0x07279A00, 0, 0,
541 "Data protect, other volume set problem"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 {0x0B260000, 0, 0,
543 "Aborted command, invalid descriptor"},
wenxiong@linux.vnet.ibm.comed7bd662013-06-04 18:57:35 -0500544 {0x0B3F9000, 0, 0,
545 "Target operating conditions have changed, dual adapter takeover"},
546 {0x0B530200, 0, 0,
547 "Aborted command, medium removal prevented"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 {0x0B5A0000, 0, 0,
wenxiong@linux.vnet.ibm.comed7bd662013-06-04 18:57:35 -0500549 "Command terminated by host"},
550 {0x0B5B8000, 0, 0,
551 "Aborted command, command terminated by host"}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552};
553
554static const struct ipr_ses_table_entry ipr_ses_table[] = {
555 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
556 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
557 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
558 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
559 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
560 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
561 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
562 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
563 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
564 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
565 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
566 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
567 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
568};
569
570/*
571 * Function Prototypes
572 */
573static int ipr_reset_alert(struct ipr_cmnd *);
574static void ipr_process_ccn(struct ipr_cmnd *);
575static void ipr_process_error(struct ipr_cmnd *);
576static void ipr_reset_ioa_job(struct ipr_cmnd *);
577static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
578 enum ipr_shutdown_type);
579
580#ifdef CONFIG_SCSI_IPR_TRACE
581/**
582 * ipr_trc_hook - Add a trace entry to the driver trace
583 * @ipr_cmd: ipr command struct
584 * @type: trace type
585 * @add_data: additional data
586 *
587 * Return value:
588 * none
589 **/
590static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
591 u8 type, u32 add_data)
592{
593 struct ipr_trace_entry *trace_entry;
594 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
595
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -0600596 trace_entry = &ioa_cfg->trace[atomic_add_return
597 (1, &ioa_cfg->trace_index)%IPR_NUM_TRACE_ENTRIES];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 trace_entry->time = jiffies;
599 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
600 trace_entry->type = type;
Wayne Boyera32c0552010-02-19 13:23:36 -0800601 if (ipr_cmd->ioa_cfg->sis64)
602 trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
603 else
604 trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
Brian King35a39692006-09-25 12:39:20 -0500605 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
607 trace_entry->u.add_data = add_data;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -0600608 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}
610#else
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -0300611#define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612#endif
613
614/**
Brian King172cd6e2012-07-17 08:14:40 -0500615 * ipr_lock_and_done - Acquire lock and complete command
616 * @ipr_cmd: ipr command struct
617 *
618 * Return value:
619 * none
620 **/
621static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
622{
623 unsigned long lock_flags;
624 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
625
626 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
627 ipr_cmd->done(ipr_cmd);
628 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
629}
630
631/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
633 * @ipr_cmd: ipr command struct
634 *
635 * Return value:
636 * none
637 **/
638static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
639{
640 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -0700641 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
642 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
Wayne Boyera32c0552010-02-19 13:23:36 -0800643 dma_addr_t dma_addr = ipr_cmd->dma_addr;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600644 int hrrq_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600646 hrrq_id = ioarcb->cmd_pkt.hrrq_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600648 ioarcb->cmd_pkt.hrrq_id = hrrq_id;
Wayne Boyera32c0552010-02-19 13:23:36 -0800649 ioarcb->data_transfer_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 ioarcb->read_data_transfer_length = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -0800651 ioarcb->ioadl_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 ioarcb->read_ioadl_len = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -0800653
Wayne Boyer96d21f02010-05-10 09:13:27 -0700654 if (ipr_cmd->ioa_cfg->sis64) {
Wayne Boyera32c0552010-02-19 13:23:36 -0800655 ioarcb->u.sis64_addr_data.data_ioadl_addr =
656 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
Wayne Boyer96d21f02010-05-10 09:13:27 -0700657 ioasa64->u.gata.status = 0;
658 } else {
Wayne Boyera32c0552010-02-19 13:23:36 -0800659 ioarcb->write_ioadl_addr =
660 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
661 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
Wayne Boyer96d21f02010-05-10 09:13:27 -0700662 ioasa->u.gata.status = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -0800663 }
664
Wayne Boyer96d21f02010-05-10 09:13:27 -0700665 ioasa->hdr.ioasc = 0;
666 ioasa->hdr.residual_data_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 ipr_cmd->scsi_cmd = NULL;
Brian King35a39692006-09-25 12:39:20 -0500668 ipr_cmd->qc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 ipr_cmd->sense_buffer[0] = 0;
670 ipr_cmd->dma_use_sg = 0;
671}
672
673/**
674 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
675 * @ipr_cmd: ipr command struct
676 *
677 * Return value:
678 * none
679 **/
Brian King172cd6e2012-07-17 08:14:40 -0500680static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
681 void (*fast_done) (struct ipr_cmnd *))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
683 ipr_reinit_ipr_cmnd(ipr_cmd);
684 ipr_cmd->u.scratch = 0;
685 ipr_cmd->sibling = NULL;
Brian King6cdb0812014-10-30 17:27:10 -0500686 ipr_cmd->eh_comp = NULL;
Brian King172cd6e2012-07-17 08:14:40 -0500687 ipr_cmd->fast_done = fast_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 init_timer(&ipr_cmd->timer);
689}
690
691/**
Brian King00bfef22012-07-17 08:13:52 -0500692 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 * @ioa_cfg: ioa config struct
694 *
695 * Return value:
696 * pointer to ipr command struct
697 **/
698static
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600699struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_hrr_queue *hrrq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600701 struct ipr_cmnd *ipr_cmd = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600703 if (likely(!list_empty(&hrrq->hrrq_free_q))) {
704 ipr_cmd = list_entry(hrrq->hrrq_free_q.next,
705 struct ipr_cmnd, queue);
706 list_del(&ipr_cmd->queue);
707 }
708
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710 return ipr_cmd;
711}
712
713/**
Brian King00bfef22012-07-17 08:13:52 -0500714 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
715 * @ioa_cfg: ioa config struct
716 *
717 * Return value:
718 * pointer to ipr command struct
719 **/
720static
721struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
722{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600723 struct ipr_cmnd *ipr_cmd =
724 __ipr_get_free_ipr_cmnd(&ioa_cfg->hrrq[IPR_INIT_HRRQ]);
Brian King172cd6e2012-07-17 08:14:40 -0500725 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
Brian King00bfef22012-07-17 08:13:52 -0500726 return ipr_cmd;
727}
728
729/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
731 * @ioa_cfg: ioa config struct
732 * @clr_ints: interrupts to clear
733 *
734 * This function masks all interrupts on the adapter, then clears the
735 * interrupts specified in the mask
736 *
737 * Return value:
738 * none
739 **/
740static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
741 u32 clr_ints)
742{
743 volatile u32 int_reg;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -0600744 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746 /* Stop new interrupts */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -0600747 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
748 spin_lock(&ioa_cfg->hrrq[i]._lock);
749 ioa_cfg->hrrq[i].allow_interrupts = 0;
750 spin_unlock(&ioa_cfg->hrrq[i]._lock);
751 }
752 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 /* Set interrupt mask to stop all new interrupts */
Wayne Boyer214777b2010-02-19 13:24:26 -0800755 if (ioa_cfg->sis64)
756 writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
757 else
758 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760 /* Clear any pending interrupts */
Wayne Boyer214777b2010-02-19 13:24:26 -0800761 if (ioa_cfg->sis64)
762 writel(~0, ioa_cfg->regs.clr_interrupt_reg);
763 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
765}
766
767/**
768 * ipr_save_pcix_cmd_reg - Save PCI-X command register
769 * @ioa_cfg: ioa config struct
770 *
771 * Return value:
772 * 0 on success / -EIO on failure
773 **/
774static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
775{
776 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
777
Brian King7dce0e12007-01-23 11:25:30 -0600778 if (pcix_cmd_reg == 0)
779 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
782 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
783 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
784 return -EIO;
785 }
786
787 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
788 return 0;
789}
790
791/**
792 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
793 * @ioa_cfg: ioa config struct
794 *
795 * Return value:
796 * 0 on success / -EIO on failure
797 **/
798static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
799{
800 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
801
802 if (pcix_cmd_reg) {
803 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
804 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
805 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
806 return -EIO;
807 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 }
809
810 return 0;
811}
812
813/**
Brian King35a39692006-09-25 12:39:20 -0500814 * ipr_sata_eh_done - done function for aborted SATA commands
815 * @ipr_cmd: ipr command struct
816 *
817 * This function is invoked for ops generated to SATA
818 * devices which are being aborted.
819 *
820 * Return value:
821 * none
822 **/
823static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
824{
Brian King35a39692006-09-25 12:39:20 -0500825 struct ata_queued_cmd *qc = ipr_cmd->qc;
826 struct ipr_sata_port *sata_port = qc->ap->private_data;
827
828 qc->err_mask |= AC_ERR_OTHER;
829 sata_port->ioasa.status |= ATA_BUSY;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600830 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Brian King35a39692006-09-25 12:39:20 -0500831 ata_qc_complete(qc);
832}
833
834/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 * ipr_scsi_eh_done - mid-layer done function for aborted ops
836 * @ipr_cmd: ipr command struct
837 *
838 * This function is invoked by the interrupt handler for
839 * ops generated by the SCSI mid-layer which are being aborted.
840 *
841 * Return value:
842 * none
843 **/
844static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
845{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
847
848 scsi_cmd->result |= (DID_ERROR << 16);
849
FUJITA Tomonori63015bc2007-05-26 00:26:59 +0900850 scsi_dma_unmap(ipr_cmd->scsi_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 scsi_cmd->scsi_done(scsi_cmd);
Brian King6cdb0812014-10-30 17:27:10 -0500852 if (ipr_cmd->eh_comp)
853 complete(ipr_cmd->eh_comp);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600854 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855}
856
857/**
858 * ipr_fail_all_ops - Fails all outstanding ops.
859 * @ioa_cfg: ioa config struct
860 *
861 * This function fails all outstanding ops.
862 *
863 * Return value:
864 * none
865 **/
866static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
867{
868 struct ipr_cmnd *ipr_cmd, *temp;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600869 struct ipr_hrr_queue *hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 ENTER;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600872 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -0600873 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600874 list_for_each_entry_safe(ipr_cmd,
875 temp, &hrrq->hrrq_pending_q, queue) {
876 list_del(&ipr_cmd->queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600878 ipr_cmd->s.ioasa.hdr.ioasc =
879 cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
880 ipr_cmd->s.ioasa.hdr.ilid =
881 cpu_to_be32(IPR_DRIVER_ILID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600883 if (ipr_cmd->scsi_cmd)
884 ipr_cmd->done = ipr_scsi_eh_done;
885 else if (ipr_cmd->qc)
886 ipr_cmd->done = ipr_sata_eh_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600888 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH,
889 IPR_IOASC_IOA_WAS_RESET);
890 del_timer(&ipr_cmd->timer);
891 ipr_cmd->done(ipr_cmd);
892 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -0600893 spin_unlock(&hrrq->_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 LEAVE;
896}
897
898/**
Wayne Boyera32c0552010-02-19 13:23:36 -0800899 * ipr_send_command - Send driver initiated requests.
900 * @ipr_cmd: ipr command struct
901 *
902 * This function sends a command to the adapter using the correct write call.
903 * In the case of sis64, calculate the ioarcb size required. Then or in the
904 * appropriate bits.
905 *
906 * Return value:
907 * none
908 **/
909static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
910{
911 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
912 dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
913
914 if (ioa_cfg->sis64) {
915 /* The default size is 256 bytes */
916 send_dma_addr |= 0x1;
917
918 /* If the number of ioadls * size of ioadl > 128 bytes,
919 then use a 512 byte ioarcb */
920 if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
921 send_dma_addr |= 0x4;
922 writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
923 } else
924 writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
925}
926
927/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 * ipr_do_req - Send driver initiated requests.
929 * @ipr_cmd: ipr command struct
930 * @done: done function
931 * @timeout_func: timeout function
932 * @timeout: timeout value
933 *
934 * This function sends the specified command to the adapter with the
935 * timeout given. The done function is invoked on command completion.
936 *
937 * Return value:
938 * none
939 **/
940static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
941 void (*done) (struct ipr_cmnd *),
942 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
943{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600944 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 ipr_cmd->done = done;
947
948 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
949 ipr_cmd->timer.expires = jiffies + timeout;
950 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
951
952 add_timer(&ipr_cmd->timer);
953
954 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
955
Wayne Boyera32c0552010-02-19 13:23:36 -0800956 ipr_send_command(ipr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957}
958
959/**
960 * ipr_internal_cmd_done - Op done function for an internally generated op.
961 * @ipr_cmd: ipr command struct
962 *
963 * This function is the op done function for an internally generated,
964 * blocking op. It simply wakes the sleeping thread.
965 *
966 * Return value:
967 * none
968 **/
969static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
970{
971 if (ipr_cmd->sibling)
972 ipr_cmd->sibling = NULL;
973 else
974 complete(&ipr_cmd->completion);
975}
976
977/**
Wayne Boyera32c0552010-02-19 13:23:36 -0800978 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
979 * @ipr_cmd: ipr command struct
980 * @dma_addr: dma address
981 * @len: transfer length
982 * @flags: ioadl flag value
983 *
984 * This function initializes an ioadl in the case where there is only a single
985 * descriptor.
986 *
987 * Return value:
988 * nothing
989 **/
990static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
991 u32 len, int flags)
992{
993 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
994 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
995
996 ipr_cmd->dma_use_sg = 1;
997
998 if (ipr_cmd->ioa_cfg->sis64) {
999 ioadl64->flags = cpu_to_be32(flags);
1000 ioadl64->data_len = cpu_to_be32(len);
1001 ioadl64->address = cpu_to_be64(dma_addr);
1002
1003 ipr_cmd->ioarcb.ioadl_len =
1004 cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
1005 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1006 } else {
1007 ioadl->flags_and_data_len = cpu_to_be32(flags | len);
1008 ioadl->address = cpu_to_be32(dma_addr);
1009
1010 if (flags == IPR_IOADL_FLAGS_READ_LAST) {
1011 ipr_cmd->ioarcb.read_ioadl_len =
1012 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1013 ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
1014 } else {
1015 ipr_cmd->ioarcb.ioadl_len =
1016 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1017 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1018 }
1019 }
1020}
1021
1022/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 * ipr_send_blocking_cmd - Send command and sleep on its completion.
1024 * @ipr_cmd: ipr command struct
1025 * @timeout_func: function to invoke if command times out
1026 * @timeout: timeout
1027 *
1028 * Return value:
1029 * none
1030 **/
1031static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
1032 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
1033 u32 timeout)
1034{
1035 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1036
1037 init_completion(&ipr_cmd->completion);
1038 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
1039
1040 spin_unlock_irq(ioa_cfg->host->host_lock);
1041 wait_for_completion(&ipr_cmd->completion);
1042 spin_lock_irq(ioa_cfg->host->host_lock);
1043}
1044
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06001045static int ipr_get_hrrq_index(struct ipr_ioa_cfg *ioa_cfg)
1046{
1047 if (ioa_cfg->hrrq_num == 1)
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06001048 return 0;
1049 else
1050 return (atomic_add_return(1, &ioa_cfg->hrrq_index) % (ioa_cfg->hrrq_num - 1)) + 1;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06001051}
1052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053/**
1054 * ipr_send_hcam - Send an HCAM to the adapter.
1055 * @ioa_cfg: ioa config struct
1056 * @type: HCAM type
1057 * @hostrcb: hostrcb struct
1058 *
1059 * This function will send a Host Controlled Async command to the adapter.
1060 * If HCAMs are currently not allowed to be issued to the adapter, it will
1061 * place the hostrcb on the free queue.
1062 *
1063 * Return value:
1064 * none
1065 **/
1066static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
1067 struct ipr_hostrcb *hostrcb)
1068{
1069 struct ipr_cmnd *ipr_cmd;
1070 struct ipr_ioarcb *ioarcb;
1071
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06001072 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06001074 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
1076
1077 ipr_cmd->u.hostrcb = hostrcb;
1078 ioarcb = &ipr_cmd->ioarcb;
1079
1080 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
1081 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
1082 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
1083 ioarcb->cmd_pkt.cdb[1] = type;
1084 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
1085 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
1086
Wayne Boyera32c0552010-02-19 13:23:36 -08001087 ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
1088 sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
1090 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
1091 ipr_cmd->done = ipr_process_ccn;
1092 else
1093 ipr_cmd->done = ipr_process_error;
1094
1095 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
1096
Wayne Boyera32c0552010-02-19 13:23:36 -08001097 ipr_send_command(ipr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 } else {
1099 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
1100 }
1101}
1102
1103/**
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001104 * ipr_update_ata_class - Update the ata class in the resource entry
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 * @res: resource entry struct
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001106 * @proto: cfgte device bus protocol value
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 *
1108 * Return value:
1109 * none
1110 **/
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001111static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112{
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03001113 switch (proto) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001114 case IPR_PROTO_SATA:
1115 case IPR_PROTO_SAS_STP:
1116 res->ata_class = ATA_DEV_ATA;
1117 break;
1118 case IPR_PROTO_SATA_ATAPI:
1119 case IPR_PROTO_SAS_STP_ATAPI:
1120 res->ata_class = ATA_DEV_ATAPI;
1121 break;
1122 default:
1123 res->ata_class = ATA_DEV_UNKNOWN;
1124 break;
1125 };
1126}
1127
1128/**
1129 * ipr_init_res_entry - Initialize a resource entry struct.
1130 * @res: resource entry struct
1131 * @cfgtew: config table entry wrapper struct
1132 *
1133 * Return value:
1134 * none
1135 **/
1136static void ipr_init_res_entry(struct ipr_resource_entry *res,
1137 struct ipr_config_table_entry_wrapper *cfgtew)
1138{
1139 int found = 0;
1140 unsigned int proto;
1141 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1142 struct ipr_resource_entry *gscsi_res = NULL;
1143
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06001144 res->needs_sync_complete = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 res->in_erp = 0;
1146 res->add_to_ml = 0;
1147 res->del_from_ml = 0;
1148 res->resetting_device = 0;
Wendy Xiong0b1f8d42014-01-21 12:16:39 -06001149 res->reset_occurred = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 res->sdev = NULL;
Brian King35a39692006-09-25 12:39:20 -05001151 res->sata_port = NULL;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001152
1153 if (ioa_cfg->sis64) {
1154 proto = cfgtew->u.cfgte64->proto;
1155 res->res_flags = cfgtew->u.cfgte64->res_flags;
1156 res->qmodel = IPR_QUEUEING_MODEL64(res);
Wayne Boyer438b0332010-05-10 09:13:00 -07001157 res->type = cfgtew->u.cfgte64->res_type;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001158
1159 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1160 sizeof(res->res_path));
1161
1162 res->bus = 0;
Wayne Boyer0cb992e2010-11-04 09:35:58 -07001163 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1164 sizeof(res->dev_lun.scsi_lun));
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001165 res->lun = scsilun_to_int(&res->dev_lun);
1166
1167 if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1168 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1169 if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1170 found = 1;
1171 res->target = gscsi_res->target;
1172 break;
1173 }
1174 }
1175 if (!found) {
1176 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1177 ioa_cfg->max_devs_supported);
1178 set_bit(res->target, ioa_cfg->target_ids);
1179 }
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001180 } else if (res->type == IPR_RES_TYPE_IOAFP) {
1181 res->bus = IPR_IOAFP_VIRTUAL_BUS;
1182 res->target = 0;
1183 } else if (res->type == IPR_RES_TYPE_ARRAY) {
1184 res->bus = IPR_ARRAY_VIRTUAL_BUS;
1185 res->target = find_first_zero_bit(ioa_cfg->array_ids,
1186 ioa_cfg->max_devs_supported);
1187 set_bit(res->target, ioa_cfg->array_ids);
1188 } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1189 res->bus = IPR_VSET_VIRTUAL_BUS;
1190 res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1191 ioa_cfg->max_devs_supported);
1192 set_bit(res->target, ioa_cfg->vset_ids);
1193 } else {
1194 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1195 ioa_cfg->max_devs_supported);
1196 set_bit(res->target, ioa_cfg->target_ids);
1197 }
1198 } else {
1199 proto = cfgtew->u.cfgte->proto;
1200 res->qmodel = IPR_QUEUEING_MODEL(res);
1201 res->flags = cfgtew->u.cfgte->flags;
1202 if (res->flags & IPR_IS_IOA_RESOURCE)
1203 res->type = IPR_RES_TYPE_IOAFP;
1204 else
1205 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1206
1207 res->bus = cfgtew->u.cfgte->res_addr.bus;
1208 res->target = cfgtew->u.cfgte->res_addr.target;
1209 res->lun = cfgtew->u.cfgte->res_addr.lun;
Wayne Boyer46d74562010-08-11 07:15:17 -07001210 res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001211 }
1212
1213 ipr_update_ata_class(res, proto);
1214}
1215
1216/**
1217 * ipr_is_same_device - Determine if two devices are the same.
1218 * @res: resource entry struct
1219 * @cfgtew: config table entry wrapper struct
1220 *
1221 * Return value:
1222 * 1 if the devices are the same / 0 otherwise
1223 **/
1224static int ipr_is_same_device(struct ipr_resource_entry *res,
1225 struct ipr_config_table_entry_wrapper *cfgtew)
1226{
1227 if (res->ioa_cfg->sis64) {
1228 if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1229 sizeof(cfgtew->u.cfgte64->dev_id)) &&
Wayne Boyer0cb992e2010-11-04 09:35:58 -07001230 !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001231 sizeof(cfgtew->u.cfgte64->lun))) {
1232 return 1;
1233 }
1234 } else {
1235 if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1236 res->target == cfgtew->u.cfgte->res_addr.target &&
1237 res->lun == cfgtew->u.cfgte->res_addr.lun)
1238 return 1;
1239 }
1240
1241 return 0;
1242}
1243
1244/**
Brian Kingb3b3b402013-01-11 17:43:49 -06001245 * __ipr_format_res_path - Format the resource path for printing.
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001246 * @res_path: resource path
1247 * @buf: buffer
Brian Kingb3b3b402013-01-11 17:43:49 -06001248 * @len: length of buffer provided
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001249 *
1250 * Return value:
1251 * pointer to buffer
1252 **/
Brian Kingb3b3b402013-01-11 17:43:49 -06001253static char *__ipr_format_res_path(u8 *res_path, char *buffer, int len)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001254{
1255 int i;
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001256 char *p = buffer;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001257
Wayne Boyer46d74562010-08-11 07:15:17 -07001258 *p = '\0';
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001259 p += snprintf(p, buffer + len - p, "%02X", res_path[0]);
1260 for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
1261 p += snprintf(p, buffer + len - p, "-%02X", res_path[i]);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001262
1263 return buffer;
1264}
1265
1266/**
Brian Kingb3b3b402013-01-11 17:43:49 -06001267 * ipr_format_res_path - Format the resource path for printing.
1268 * @ioa_cfg: ioa config struct
1269 * @res_path: resource path
1270 * @buf: buffer
1271 * @len: length of buffer provided
1272 *
1273 * Return value:
1274 * pointer to buffer
1275 **/
1276static char *ipr_format_res_path(struct ipr_ioa_cfg *ioa_cfg,
1277 u8 *res_path, char *buffer, int len)
1278{
1279 char *p = buffer;
1280
1281 *p = '\0';
1282 p += snprintf(p, buffer + len - p, "%d/", ioa_cfg->host->host_no);
1283 __ipr_format_res_path(res_path, p, len - (buffer - p));
1284 return buffer;
1285}
1286
1287/**
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001288 * ipr_update_res_entry - Update the resource entry.
1289 * @res: resource entry struct
1290 * @cfgtew: config table entry wrapper struct
1291 *
1292 * Return value:
1293 * none
1294 **/
1295static void ipr_update_res_entry(struct ipr_resource_entry *res,
1296 struct ipr_config_table_entry_wrapper *cfgtew)
1297{
1298 char buffer[IPR_MAX_RES_PATH_LENGTH];
1299 unsigned int proto;
1300 int new_path = 0;
1301
1302 if (res->ioa_cfg->sis64) {
1303 res->flags = cfgtew->u.cfgte64->flags;
1304 res->res_flags = cfgtew->u.cfgte64->res_flags;
Wayne Boyer75576bb2010-07-14 10:50:14 -07001305 res->type = cfgtew->u.cfgte64->res_type;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001306
1307 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1308 sizeof(struct ipr_std_inq_data));
1309
1310 res->qmodel = IPR_QUEUEING_MODEL64(res);
1311 proto = cfgtew->u.cfgte64->proto;
1312 res->res_handle = cfgtew->u.cfgte64->res_handle;
1313 res->dev_id = cfgtew->u.cfgte64->dev_id;
1314
1315 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1316 sizeof(res->dev_lun.scsi_lun));
1317
1318 if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1319 sizeof(res->res_path))) {
1320 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1321 sizeof(res->res_path));
1322 new_path = 1;
1323 }
1324
1325 if (res->sdev && new_path)
1326 sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
Brian Kingb3b3b402013-01-11 17:43:49 -06001327 ipr_format_res_path(res->ioa_cfg,
1328 res->res_path, buffer, sizeof(buffer)));
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001329 } else {
1330 res->flags = cfgtew->u.cfgte->flags;
1331 if (res->flags & IPR_IS_IOA_RESOURCE)
1332 res->type = IPR_RES_TYPE_IOAFP;
1333 else
1334 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1335
1336 memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1337 sizeof(struct ipr_std_inq_data));
1338
1339 res->qmodel = IPR_QUEUEING_MODEL(res);
1340 proto = cfgtew->u.cfgte->proto;
1341 res->res_handle = cfgtew->u.cfgte->res_handle;
1342 }
1343
1344 ipr_update_ata_class(res, proto);
1345}
1346
1347/**
1348 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1349 * for the resource.
1350 * @res: resource entry struct
1351 * @cfgtew: config table entry wrapper struct
1352 *
1353 * Return value:
1354 * none
1355 **/
1356static void ipr_clear_res_target(struct ipr_resource_entry *res)
1357{
1358 struct ipr_resource_entry *gscsi_res = NULL;
1359 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1360
1361 if (!ioa_cfg->sis64)
1362 return;
1363
1364 if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1365 clear_bit(res->target, ioa_cfg->array_ids);
1366 else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1367 clear_bit(res->target, ioa_cfg->vset_ids);
1368 else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1369 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1370 if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1371 return;
1372 clear_bit(res->target, ioa_cfg->target_ids);
1373
1374 } else if (res->bus == 0)
1375 clear_bit(res->target, ioa_cfg->target_ids);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376}
1377
1378/**
1379 * ipr_handle_config_change - Handle a config change from the adapter
1380 * @ioa_cfg: ioa config struct
1381 * @hostrcb: hostrcb
1382 *
1383 * Return value:
1384 * none
1385 **/
1386static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001387 struct ipr_hostrcb *hostrcb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388{
1389 struct ipr_resource_entry *res = NULL;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001390 struct ipr_config_table_entry_wrapper cfgtew;
1391 __be32 cc_res_handle;
1392
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 u32 is_ndn = 1;
1394
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001395 if (ioa_cfg->sis64) {
1396 cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1397 cc_res_handle = cfgtew.u.cfgte64->res_handle;
1398 } else {
1399 cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1400 cc_res_handle = cfgtew.u.cfgte->res_handle;
1401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
1403 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001404 if (res->res_handle == cc_res_handle) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 is_ndn = 0;
1406 break;
1407 }
1408 }
1409
1410 if (is_ndn) {
1411 if (list_empty(&ioa_cfg->free_res_q)) {
1412 ipr_send_hcam(ioa_cfg,
1413 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1414 hostrcb);
1415 return;
1416 }
1417
1418 res = list_entry(ioa_cfg->free_res_q.next,
1419 struct ipr_resource_entry, queue);
1420
1421 list_del(&res->queue);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001422 ipr_init_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1424 }
1425
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001426 ipr_update_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
1428 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1429 if (res->sdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 res->del_from_ml = 1;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001431 res->res_handle = IPR_INVALID_RES_HANDLE;
Brian Kingf688f962014-12-02 12:47:37 -06001432 schedule_work(&ioa_cfg->work_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001433 } else {
1434 ipr_clear_res_target(res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001436 }
Kleber Sacilotto de Souza5767a1c2011-02-14 20:19:31 -02001437 } else if (!res->sdev || res->del_from_ml) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 res->add_to_ml = 1;
Brian Kingf688f962014-12-02 12:47:37 -06001439 schedule_work(&ioa_cfg->work_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 }
1441
1442 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1443}
1444
1445/**
1446 * ipr_process_ccn - Op done function for a CCN.
1447 * @ipr_cmd: ipr command struct
1448 *
1449 * This function is the op done function for a configuration
1450 * change notification host controlled async from the adapter.
1451 *
1452 * Return value:
1453 * none
1454 **/
1455static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1456{
1457 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1458 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07001459 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
1461 list_del(&hostrcb->queue);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06001462 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
1464 if (ioasc) {
1465 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
1466 dev_err(&ioa_cfg->pdev->dev,
1467 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1468
1469 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1470 } else {
1471 ipr_handle_config_change(ioa_cfg, hostrcb);
1472 }
1473}
1474
1475/**
Brian King8cf093e2007-04-26 16:00:14 -05001476 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1477 * @i: index into buffer
1478 * @buf: string to modify
1479 *
1480 * This function will strip all trailing whitespace, pad the end
1481 * of the string with a single space, and NULL terminate the string.
1482 *
1483 * Return value:
1484 * new length of string
1485 **/
1486static int strip_and_pad_whitespace(int i, char *buf)
1487{
1488 while (i && buf[i] == ' ')
1489 i--;
1490 buf[i+1] = ' ';
1491 buf[i+2] = '\0';
1492 return i + 2;
1493}
1494
1495/**
1496 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1497 * @prefix: string to print at start of printk
1498 * @hostrcb: hostrcb pointer
1499 * @vpd: vendor/product id/sn struct
1500 *
1501 * Return value:
1502 * none
1503 **/
1504static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1505 struct ipr_vpd *vpd)
1506{
1507 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
1508 int i = 0;
1509
1510 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1511 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
1512
1513 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
1514 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
1515
1516 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1517 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1518
1519 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1520}
1521
1522/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 * ipr_log_vpd - Log the passed VPD to the error log.
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001524 * @vpd: vendor/product id/sn struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 *
1526 * Return value:
1527 * none
1528 **/
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001529static void ipr_log_vpd(struct ipr_vpd *vpd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530{
1531 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1532 + IPR_SERIAL_NUM_LEN];
1533
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001534 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1535 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 IPR_PROD_ID_LEN);
1537 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1538 ipr_err("Vendor/Product ID: %s\n", buffer);
1539
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001540 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1542 ipr_err(" Serial Number: %s\n", buffer);
1543}
1544
1545/**
Brian King8cf093e2007-04-26 16:00:14 -05001546 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1547 * @prefix: string to print at start of printk
1548 * @hostrcb: hostrcb pointer
1549 * @vpd: vendor/product id/sn/wwn struct
1550 *
1551 * Return value:
1552 * none
1553 **/
1554static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1555 struct ipr_ext_vpd *vpd)
1556{
1557 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1558 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1559 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1560}
1561
1562/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001563 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1564 * @vpd: vendor/product id/sn/wwn struct
1565 *
1566 * Return value:
1567 * none
1568 **/
1569static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1570{
1571 ipr_log_vpd(&vpd->vpd);
1572 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1573 be32_to_cpu(vpd->wwid[1]));
1574}
1575
1576/**
1577 * ipr_log_enhanced_cache_error - Log a cache error.
1578 * @ioa_cfg: ioa config struct
1579 * @hostrcb: hostrcb struct
1580 *
1581 * Return value:
1582 * none
1583 **/
1584static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1585 struct ipr_hostrcb *hostrcb)
1586{
Wayne Boyer4565e372010-02-19 13:24:07 -08001587 struct ipr_hostrcb_type_12_error *error;
1588
1589 if (ioa_cfg->sis64)
1590 error = &hostrcb->hcam.u.error64.u.type_12_error;
1591 else
1592 error = &hostrcb->hcam.u.error.u.type_12_error;
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001593
1594 ipr_err("-----Current Configuration-----\n");
1595 ipr_err("Cache Directory Card Information:\n");
1596 ipr_log_ext_vpd(&error->ioa_vpd);
1597 ipr_err("Adapter Card Information:\n");
1598 ipr_log_ext_vpd(&error->cfc_vpd);
1599
1600 ipr_err("-----Expected Configuration-----\n");
1601 ipr_err("Cache Directory Card Information:\n");
1602 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1603 ipr_err("Adapter Card Information:\n");
1604 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1605
1606 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1607 be32_to_cpu(error->ioa_data[0]),
1608 be32_to_cpu(error->ioa_data[1]),
1609 be32_to_cpu(error->ioa_data[2]));
1610}
1611
1612/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 * ipr_log_cache_error - Log a cache error.
1614 * @ioa_cfg: ioa config struct
1615 * @hostrcb: hostrcb struct
1616 *
1617 * Return value:
1618 * none
1619 **/
1620static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1621 struct ipr_hostrcb *hostrcb)
1622{
1623 struct ipr_hostrcb_type_02_error *error =
1624 &hostrcb->hcam.u.error.u.type_02_error;
1625
1626 ipr_err("-----Current Configuration-----\n");
1627 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001628 ipr_log_vpd(&error->ioa_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001630 ipr_log_vpd(&error->cfc_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
1632 ipr_err("-----Expected Configuration-----\n");
1633 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001634 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001636 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
1638 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1639 be32_to_cpu(error->ioa_data[0]),
1640 be32_to_cpu(error->ioa_data[1]),
1641 be32_to_cpu(error->ioa_data[2]));
1642}
1643
1644/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001645 * ipr_log_enhanced_config_error - Log a configuration error.
1646 * @ioa_cfg: ioa config struct
1647 * @hostrcb: hostrcb struct
1648 *
1649 * Return value:
1650 * none
1651 **/
1652static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1653 struct ipr_hostrcb *hostrcb)
1654{
1655 int errors_logged, i;
1656 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1657 struct ipr_hostrcb_type_13_error *error;
1658
1659 error = &hostrcb->hcam.u.error.u.type_13_error;
1660 errors_logged = be32_to_cpu(error->errors_logged);
1661
1662 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1663 be32_to_cpu(error->errors_detected), errors_logged);
1664
1665 dev_entry = error->dev;
1666
1667 for (i = 0; i < errors_logged; i++, dev_entry++) {
1668 ipr_err_separator;
1669
1670 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1671 ipr_log_ext_vpd(&dev_entry->vpd);
1672
1673 ipr_err("-----New Device Information-----\n");
1674 ipr_log_ext_vpd(&dev_entry->new_vpd);
1675
1676 ipr_err("Cache Directory Card Information:\n");
1677 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1678
1679 ipr_err("Adapter Card Information:\n");
1680 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1681 }
1682}
1683
1684/**
Wayne Boyer4565e372010-02-19 13:24:07 -08001685 * ipr_log_sis64_config_error - Log a device error.
1686 * @ioa_cfg: ioa config struct
1687 * @hostrcb: hostrcb struct
1688 *
1689 * Return value:
1690 * none
1691 **/
1692static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
1693 struct ipr_hostrcb *hostrcb)
1694{
1695 int errors_logged, i;
1696 struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
1697 struct ipr_hostrcb_type_23_error *error;
1698 char buffer[IPR_MAX_RES_PATH_LENGTH];
1699
1700 error = &hostrcb->hcam.u.error64.u.type_23_error;
1701 errors_logged = be32_to_cpu(error->errors_logged);
1702
1703 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1704 be32_to_cpu(error->errors_detected), errors_logged);
1705
1706 dev_entry = error->dev;
1707
1708 for (i = 0; i < errors_logged; i++, dev_entry++) {
1709 ipr_err_separator;
1710
1711 ipr_err("Device %d : %s", i + 1,
Brian Kingb3b3b402013-01-11 17:43:49 -06001712 __ipr_format_res_path(dev_entry->res_path,
1713 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08001714 ipr_log_ext_vpd(&dev_entry->vpd);
1715
1716 ipr_err("-----New Device Information-----\n");
1717 ipr_log_ext_vpd(&dev_entry->new_vpd);
1718
1719 ipr_err("Cache Directory Card Information:\n");
1720 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1721
1722 ipr_err("Adapter Card Information:\n");
1723 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1724 }
1725}
1726
1727/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 * ipr_log_config_error - Log a configuration error.
1729 * @ioa_cfg: ioa config struct
1730 * @hostrcb: hostrcb struct
1731 *
1732 * Return value:
1733 * none
1734 **/
1735static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1736 struct ipr_hostrcb *hostrcb)
1737{
1738 int errors_logged, i;
1739 struct ipr_hostrcb_device_data_entry *dev_entry;
1740 struct ipr_hostrcb_type_03_error *error;
1741
1742 error = &hostrcb->hcam.u.error.u.type_03_error;
1743 errors_logged = be32_to_cpu(error->errors_logged);
1744
1745 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1746 be32_to_cpu(error->errors_detected), errors_logged);
1747
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001748 dev_entry = error->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
1750 for (i = 0; i < errors_logged; i++, dev_entry++) {
1751 ipr_err_separator;
1752
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001753 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001754 ipr_log_vpd(&dev_entry->vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
1756 ipr_err("-----New Device Information-----\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001757 ipr_log_vpd(&dev_entry->new_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
1759 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001760 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
1762 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001763 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
1765 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1766 be32_to_cpu(dev_entry->ioa_data[0]),
1767 be32_to_cpu(dev_entry->ioa_data[1]),
1768 be32_to_cpu(dev_entry->ioa_data[2]),
1769 be32_to_cpu(dev_entry->ioa_data[3]),
1770 be32_to_cpu(dev_entry->ioa_data[4]));
1771 }
1772}
1773
1774/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001775 * ipr_log_enhanced_array_error - Log an array configuration error.
1776 * @ioa_cfg: ioa config struct
1777 * @hostrcb: hostrcb struct
1778 *
1779 * Return value:
1780 * none
1781 **/
1782static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1783 struct ipr_hostrcb *hostrcb)
1784{
1785 int i, num_entries;
1786 struct ipr_hostrcb_type_14_error *error;
1787 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1788 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1789
1790 error = &hostrcb->hcam.u.error.u.type_14_error;
1791
1792 ipr_err_separator;
1793
1794 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1795 error->protection_level,
1796 ioa_cfg->host->host_no,
1797 error->last_func_vset_res_addr.bus,
1798 error->last_func_vset_res_addr.target,
1799 error->last_func_vset_res_addr.lun);
1800
1801 ipr_err_separator;
1802
1803 array_entry = error->array_member;
1804 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
Wayne Boyer72620262010-09-27 10:45:28 -07001805 ARRAY_SIZE(error->array_member));
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001806
1807 for (i = 0; i < num_entries; i++, array_entry++) {
1808 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1809 continue;
1810
1811 if (be32_to_cpu(error->exposed_mode_adn) == i)
1812 ipr_err("Exposed Array Member %d:\n", i);
1813 else
1814 ipr_err("Array Member %d:\n", i);
1815
1816 ipr_log_ext_vpd(&array_entry->vpd);
1817 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1818 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1819 "Expected Location");
1820
1821 ipr_err_separator;
1822 }
1823}
1824
1825/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 * ipr_log_array_error - Log an array configuration error.
1827 * @ioa_cfg: ioa config struct
1828 * @hostrcb: hostrcb struct
1829 *
1830 * Return value:
1831 * none
1832 **/
1833static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1834 struct ipr_hostrcb *hostrcb)
1835{
1836 int i;
1837 struct ipr_hostrcb_type_04_error *error;
1838 struct ipr_hostrcb_array_data_entry *array_entry;
1839 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1840
1841 error = &hostrcb->hcam.u.error.u.type_04_error;
1842
1843 ipr_err_separator;
1844
1845 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1846 error->protection_level,
1847 ioa_cfg->host->host_no,
1848 error->last_func_vset_res_addr.bus,
1849 error->last_func_vset_res_addr.target,
1850 error->last_func_vset_res_addr.lun);
1851
1852 ipr_err_separator;
1853
1854 array_entry = error->array_member;
1855
1856 for (i = 0; i < 18; i++) {
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001857 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 continue;
1859
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001860 if (be32_to_cpu(error->exposed_mode_adn) == i)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 ipr_err("Exposed Array Member %d:\n", i);
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001862 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 ipr_err("Array Member %d:\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001865 ipr_log_vpd(&array_entry->vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001867 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1868 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1869 "Expected Location");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
1871 ipr_err_separator;
1872
1873 if (i == 9)
1874 array_entry = error->array_member2;
1875 else
1876 array_entry++;
1877 }
1878}
1879
1880/**
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001881 * ipr_log_hex_data - Log additional hex IOA error data.
Brian Kingac719ab2006-11-21 10:28:42 -06001882 * @ioa_cfg: ioa config struct
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001883 * @data: IOA error data
1884 * @len: data length
1885 *
1886 * Return value:
1887 * none
1888 **/
Brian Kingac719ab2006-11-21 10:28:42 -06001889static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001890{
1891 int i;
1892
1893 if (len == 0)
1894 return;
1895
Brian Kingac719ab2006-11-21 10:28:42 -06001896 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1897 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1898
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001899 for (i = 0; i < len / 4; i += 4) {
1900 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1901 be32_to_cpu(data[i]),
1902 be32_to_cpu(data[i+1]),
1903 be32_to_cpu(data[i+2]),
1904 be32_to_cpu(data[i+3]));
1905 }
1906}
1907
1908/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001909 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1910 * @ioa_cfg: ioa config struct
1911 * @hostrcb: hostrcb struct
1912 *
1913 * Return value:
1914 * none
1915 **/
1916static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1917 struct ipr_hostrcb *hostrcb)
1918{
1919 struct ipr_hostrcb_type_17_error *error;
1920
Wayne Boyer4565e372010-02-19 13:24:07 -08001921 if (ioa_cfg->sis64)
1922 error = &hostrcb->hcam.u.error64.u.type_17_error;
1923 else
1924 error = &hostrcb->hcam.u.error.u.type_17_error;
1925
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001926 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
KOSAKI Motohiroca54cb82009-12-14 18:01:15 -08001927 strim(error->failure_reason);
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001928
Brian King8cf093e2007-04-26 16:00:14 -05001929 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1930 be32_to_cpu(hostrcb->hcam.u.error.prc));
1931 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
Brian Kingac719ab2006-11-21 10:28:42 -06001932 ipr_log_hex_data(ioa_cfg, error->data,
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001933 be32_to_cpu(hostrcb->hcam.length) -
1934 (offsetof(struct ipr_hostrcb_error, u) +
1935 offsetof(struct ipr_hostrcb_type_17_error, data)));
1936}
1937
1938/**
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001939 * ipr_log_dual_ioa_error - Log a dual adapter error.
1940 * @ioa_cfg: ioa config struct
1941 * @hostrcb: hostrcb struct
1942 *
1943 * Return value:
1944 * none
1945 **/
1946static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1947 struct ipr_hostrcb *hostrcb)
1948{
1949 struct ipr_hostrcb_type_07_error *error;
1950
1951 error = &hostrcb->hcam.u.error.u.type_07_error;
1952 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
KOSAKI Motohiroca54cb82009-12-14 18:01:15 -08001953 strim(error->failure_reason);
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001954
Brian King8cf093e2007-04-26 16:00:14 -05001955 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1956 be32_to_cpu(hostrcb->hcam.u.error.prc));
1957 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
Brian Kingac719ab2006-11-21 10:28:42 -06001958 ipr_log_hex_data(ioa_cfg, error->data,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001959 be32_to_cpu(hostrcb->hcam.length) -
1960 (offsetof(struct ipr_hostrcb_error, u) +
1961 offsetof(struct ipr_hostrcb_type_07_error, data)));
1962}
1963
Brian King49dc6a12006-11-21 10:28:35 -06001964static const struct {
1965 u8 active;
1966 char *desc;
1967} path_active_desc[] = {
1968 { IPR_PATH_NO_INFO, "Path" },
1969 { IPR_PATH_ACTIVE, "Active path" },
1970 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1971};
1972
1973static const struct {
1974 u8 state;
1975 char *desc;
1976} path_state_desc[] = {
1977 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1978 { IPR_PATH_HEALTHY, "is healthy" },
1979 { IPR_PATH_DEGRADED, "is degraded" },
1980 { IPR_PATH_FAILED, "is failed" }
1981};
1982
1983/**
1984 * ipr_log_fabric_path - Log a fabric path error
1985 * @hostrcb: hostrcb struct
1986 * @fabric: fabric descriptor
1987 *
1988 * Return value:
1989 * none
1990 **/
1991static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1992 struct ipr_hostrcb_fabric_desc *fabric)
1993{
1994 int i, j;
1995 u8 path_state = fabric->path_state;
1996 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1997 u8 state = path_state & IPR_PATH_STATE_MASK;
1998
1999 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
2000 if (path_active_desc[i].active != active)
2001 continue;
2002
2003 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2004 if (path_state_desc[j].state != state)
2005 continue;
2006
2007 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
2008 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
2009 path_active_desc[i].desc, path_state_desc[j].desc,
2010 fabric->ioa_port);
2011 } else if (fabric->cascaded_expander == 0xff) {
2012 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
2013 path_active_desc[i].desc, path_state_desc[j].desc,
2014 fabric->ioa_port, fabric->phy);
2015 } else if (fabric->phy == 0xff) {
2016 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
2017 path_active_desc[i].desc, path_state_desc[j].desc,
2018 fabric->ioa_port, fabric->cascaded_expander);
2019 } else {
2020 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
2021 path_active_desc[i].desc, path_state_desc[j].desc,
2022 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2023 }
2024 return;
2025 }
2026 }
2027
2028 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
2029 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2030}
2031
Wayne Boyer4565e372010-02-19 13:24:07 -08002032/**
2033 * ipr_log64_fabric_path - Log a fabric path error
2034 * @hostrcb: hostrcb struct
2035 * @fabric: fabric descriptor
2036 *
2037 * Return value:
2038 * none
2039 **/
2040static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
2041 struct ipr_hostrcb64_fabric_desc *fabric)
2042{
2043 int i, j;
2044 u8 path_state = fabric->path_state;
2045 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
2046 u8 state = path_state & IPR_PATH_STATE_MASK;
2047 char buffer[IPR_MAX_RES_PATH_LENGTH];
2048
2049 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
2050 if (path_active_desc[i].active != active)
2051 continue;
2052
2053 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2054 if (path_state_desc[j].state != state)
2055 continue;
2056
2057 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
2058 path_active_desc[i].desc, path_state_desc[j].desc,
Brian Kingb3b3b402013-01-11 17:43:49 -06002059 ipr_format_res_path(hostrcb->ioa_cfg,
2060 fabric->res_path,
2061 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002062 return;
2063 }
2064 }
2065
2066 ipr_err("Path state=%02X Resource Path=%s\n", path_state,
Brian Kingb3b3b402013-01-11 17:43:49 -06002067 ipr_format_res_path(hostrcb->ioa_cfg, fabric->res_path,
2068 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002069}
2070
Brian King49dc6a12006-11-21 10:28:35 -06002071static const struct {
2072 u8 type;
2073 char *desc;
2074} path_type_desc[] = {
2075 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
2076 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
2077 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
2078 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
2079};
2080
2081static const struct {
2082 u8 status;
2083 char *desc;
2084} path_status_desc[] = {
2085 { IPR_PATH_CFG_NO_PROB, "Functional" },
2086 { IPR_PATH_CFG_DEGRADED, "Degraded" },
2087 { IPR_PATH_CFG_FAILED, "Failed" },
2088 { IPR_PATH_CFG_SUSPECT, "Suspect" },
2089 { IPR_PATH_NOT_DETECTED, "Missing" },
2090 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
2091};
2092
2093static const char *link_rate[] = {
2094 "unknown",
2095 "disabled",
2096 "phy reset problem",
2097 "spinup hold",
2098 "port selector",
2099 "unknown",
2100 "unknown",
2101 "unknown",
2102 "1.5Gbps",
2103 "3.0Gbps",
2104 "unknown",
2105 "unknown",
2106 "unknown",
2107 "unknown",
2108 "unknown",
2109 "unknown"
2110};
2111
2112/**
2113 * ipr_log_path_elem - Log a fabric path element.
2114 * @hostrcb: hostrcb struct
2115 * @cfg: fabric path element struct
2116 *
2117 * Return value:
2118 * none
2119 **/
2120static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
2121 struct ipr_hostrcb_config_element *cfg)
2122{
2123 int i, j;
2124 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2125 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2126
2127 if (type == IPR_PATH_CFG_NOT_EXIST)
2128 return;
2129
2130 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2131 if (path_type_desc[i].type != type)
2132 continue;
2133
2134 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2135 if (path_status_desc[j].status != status)
2136 continue;
2137
2138 if (type == IPR_PATH_CFG_IOA_PORT) {
2139 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
2140 path_status_desc[j].desc, path_type_desc[i].desc,
2141 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2142 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2143 } else {
2144 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
2145 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2146 path_status_desc[j].desc, path_type_desc[i].desc,
2147 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2148 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2149 } else if (cfg->cascaded_expander == 0xff) {
2150 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
2151 "WWN=%08X%08X\n", path_status_desc[j].desc,
2152 path_type_desc[i].desc, cfg->phy,
2153 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2154 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2155 } else if (cfg->phy == 0xff) {
2156 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
2157 "WWN=%08X%08X\n", path_status_desc[j].desc,
2158 path_type_desc[i].desc, cfg->cascaded_expander,
2159 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2160 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2161 } else {
2162 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2163 "WWN=%08X%08X\n", path_status_desc[j].desc,
2164 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
2165 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2166 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2167 }
2168 }
2169 return;
2170 }
2171 }
2172
2173 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2174 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
2175 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2176 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2177}
2178
2179/**
Wayne Boyer4565e372010-02-19 13:24:07 -08002180 * ipr_log64_path_elem - Log a fabric path element.
2181 * @hostrcb: hostrcb struct
2182 * @cfg: fabric path element struct
2183 *
2184 * Return value:
2185 * none
2186 **/
2187static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
2188 struct ipr_hostrcb64_config_element *cfg)
2189{
2190 int i, j;
2191 u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
2192 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2193 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2194 char buffer[IPR_MAX_RES_PATH_LENGTH];
2195
2196 if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
2197 return;
2198
2199 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2200 if (path_type_desc[i].type != type)
2201 continue;
2202
2203 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2204 if (path_status_desc[j].status != status)
2205 continue;
2206
2207 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2208 path_status_desc[j].desc, path_type_desc[i].desc,
Brian Kingb3b3b402013-01-11 17:43:49 -06002209 ipr_format_res_path(hostrcb->ioa_cfg,
2210 cfg->res_path, buffer, sizeof(buffer)),
2211 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2212 be32_to_cpu(cfg->wwid[0]),
2213 be32_to_cpu(cfg->wwid[1]));
Wayne Boyer4565e372010-02-19 13:24:07 -08002214 return;
2215 }
2216 }
2217 ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
2218 "WWN=%08X%08X\n", cfg->type_status,
Brian Kingb3b3b402013-01-11 17:43:49 -06002219 ipr_format_res_path(hostrcb->ioa_cfg,
2220 cfg->res_path, buffer, sizeof(buffer)),
2221 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2222 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
Wayne Boyer4565e372010-02-19 13:24:07 -08002223}
2224
2225/**
Brian King49dc6a12006-11-21 10:28:35 -06002226 * ipr_log_fabric_error - Log a fabric error.
2227 * @ioa_cfg: ioa config struct
2228 * @hostrcb: hostrcb struct
2229 *
2230 * Return value:
2231 * none
2232 **/
2233static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2234 struct ipr_hostrcb *hostrcb)
2235{
2236 struct ipr_hostrcb_type_20_error *error;
2237 struct ipr_hostrcb_fabric_desc *fabric;
2238 struct ipr_hostrcb_config_element *cfg;
2239 int i, add_len;
2240
2241 error = &hostrcb->hcam.u.error.u.type_20_error;
2242 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2243 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2244
2245 add_len = be32_to_cpu(hostrcb->hcam.length) -
2246 (offsetof(struct ipr_hostrcb_error, u) +
2247 offsetof(struct ipr_hostrcb_type_20_error, desc));
2248
2249 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2250 ipr_log_fabric_path(hostrcb, fabric);
2251 for_each_fabric_cfg(fabric, cfg)
2252 ipr_log_path_elem(hostrcb, cfg);
2253
2254 add_len -= be16_to_cpu(fabric->length);
2255 fabric = (struct ipr_hostrcb_fabric_desc *)
2256 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2257 }
2258
Brian Kingac719ab2006-11-21 10:28:42 -06002259 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
Brian King49dc6a12006-11-21 10:28:35 -06002260}
2261
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002262/**
Wayne Boyer4565e372010-02-19 13:24:07 -08002263 * ipr_log_sis64_array_error - Log a sis64 array error.
2264 * @ioa_cfg: ioa config struct
2265 * @hostrcb: hostrcb struct
2266 *
2267 * Return value:
2268 * none
2269 **/
2270static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
2271 struct ipr_hostrcb *hostrcb)
2272{
2273 int i, num_entries;
2274 struct ipr_hostrcb_type_24_error *error;
2275 struct ipr_hostrcb64_array_data_entry *array_entry;
2276 char buffer[IPR_MAX_RES_PATH_LENGTH];
2277 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
2278
2279 error = &hostrcb->hcam.u.error64.u.type_24_error;
2280
2281 ipr_err_separator;
2282
2283 ipr_err("RAID %s Array Configuration: %s\n",
2284 error->protection_level,
Brian Kingb3b3b402013-01-11 17:43:49 -06002285 ipr_format_res_path(ioa_cfg, error->last_res_path,
2286 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002287
2288 ipr_err_separator;
2289
2290 array_entry = error->array_member;
Wayne Boyer72620262010-09-27 10:45:28 -07002291 num_entries = min_t(u32, error->num_entries,
2292 ARRAY_SIZE(error->array_member));
Wayne Boyer4565e372010-02-19 13:24:07 -08002293
2294 for (i = 0; i < num_entries; i++, array_entry++) {
2295
2296 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
2297 continue;
2298
2299 if (error->exposed_mode_adn == i)
2300 ipr_err("Exposed Array Member %d:\n", i);
2301 else
2302 ipr_err("Array Member %d:\n", i);
2303
2304 ipr_err("Array Member %d:\n", i);
2305 ipr_log_ext_vpd(&array_entry->vpd);
Wayne Boyer72620262010-09-27 10:45:28 -07002306 ipr_err("Current Location: %s\n",
Brian Kingb3b3b402013-01-11 17:43:49 -06002307 ipr_format_res_path(ioa_cfg, array_entry->res_path,
2308 buffer, sizeof(buffer)));
Wayne Boyer72620262010-09-27 10:45:28 -07002309 ipr_err("Expected Location: %s\n",
Brian Kingb3b3b402013-01-11 17:43:49 -06002310 ipr_format_res_path(ioa_cfg,
2311 array_entry->expected_res_path,
2312 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002313
2314 ipr_err_separator;
2315 }
2316}
2317
2318/**
2319 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2320 * @ioa_cfg: ioa config struct
2321 * @hostrcb: hostrcb struct
2322 *
2323 * Return value:
2324 * none
2325 **/
2326static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2327 struct ipr_hostrcb *hostrcb)
2328{
2329 struct ipr_hostrcb_type_30_error *error;
2330 struct ipr_hostrcb64_fabric_desc *fabric;
2331 struct ipr_hostrcb64_config_element *cfg;
2332 int i, add_len;
2333
2334 error = &hostrcb->hcam.u.error64.u.type_30_error;
2335
2336 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2337 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2338
2339 add_len = be32_to_cpu(hostrcb->hcam.length) -
2340 (offsetof(struct ipr_hostrcb64_error, u) +
2341 offsetof(struct ipr_hostrcb_type_30_error, desc));
2342
2343 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2344 ipr_log64_fabric_path(hostrcb, fabric);
2345 for_each_fabric_cfg(fabric, cfg)
2346 ipr_log64_path_elem(hostrcb, cfg);
2347
2348 add_len -= be16_to_cpu(fabric->length);
2349 fabric = (struct ipr_hostrcb64_fabric_desc *)
2350 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2351 }
2352
2353 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2354}
2355
2356/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 * ipr_log_generic_error - Log an adapter error.
2358 * @ioa_cfg: ioa config struct
2359 * @hostrcb: hostrcb struct
2360 *
2361 * Return value:
2362 * none
2363 **/
2364static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
2365 struct ipr_hostrcb *hostrcb)
2366{
Brian Kingac719ab2006-11-21 10:28:42 -06002367 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002368 be32_to_cpu(hostrcb->hcam.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369}
2370
2371/**
Wendy Xiong169b9ec2014-03-12 16:08:51 -05002372 * ipr_log_sis64_device_error - Log a cache error.
2373 * @ioa_cfg: ioa config struct
2374 * @hostrcb: hostrcb struct
2375 *
2376 * Return value:
2377 * none
2378 **/
2379static void ipr_log_sis64_device_error(struct ipr_ioa_cfg *ioa_cfg,
2380 struct ipr_hostrcb *hostrcb)
2381{
2382 struct ipr_hostrcb_type_21_error *error;
2383 char buffer[IPR_MAX_RES_PATH_LENGTH];
2384
2385 error = &hostrcb->hcam.u.error64.u.type_21_error;
2386
2387 ipr_err("-----Failing Device Information-----\n");
2388 ipr_err("World Wide Unique ID: %08X%08X%08X%08X\n",
2389 be32_to_cpu(error->wwn[0]), be32_to_cpu(error->wwn[1]),
2390 be32_to_cpu(error->wwn[2]), be32_to_cpu(error->wwn[3]));
2391 ipr_err("Device Resource Path: %s\n",
2392 __ipr_format_res_path(error->res_path,
2393 buffer, sizeof(buffer)));
2394 error->primary_problem_desc[sizeof(error->primary_problem_desc) - 1] = '\0';
2395 error->second_problem_desc[sizeof(error->second_problem_desc) - 1] = '\0';
2396 ipr_err("Primary Problem Description: %s\n", error->primary_problem_desc);
2397 ipr_err("Secondary Problem Description: %s\n", error->second_problem_desc);
2398 ipr_err("SCSI Sense Data:\n");
2399 ipr_log_hex_data(ioa_cfg, error->sense_data, sizeof(error->sense_data));
2400 ipr_err("SCSI Command Descriptor Block: \n");
2401 ipr_log_hex_data(ioa_cfg, error->cdb, sizeof(error->cdb));
2402
2403 ipr_err("Additional IOA Data:\n");
2404 ipr_log_hex_data(ioa_cfg, error->ioa_data, be32_to_cpu(error->length_of_error));
2405}
2406
2407/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2409 * @ioasc: IOASC
2410 *
2411 * This function will return the index of into the ipr_error_table
2412 * for the specified IOASC. If the IOASC is not in the table,
2413 * 0 will be returned, which points to the entry used for unknown errors.
2414 *
2415 * Return value:
2416 * index into the ipr_error_table
2417 **/
2418static u32 ipr_get_error(u32 ioasc)
2419{
2420 int i;
2421
2422 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
Brian King35a39692006-09-25 12:39:20 -05002423 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 return i;
2425
2426 return 0;
2427}
2428
2429/**
2430 * ipr_handle_log_data - Log an adapter error.
2431 * @ioa_cfg: ioa config struct
2432 * @hostrcb: hostrcb struct
2433 *
2434 * This function logs an adapter error to the system.
2435 *
2436 * Return value:
2437 * none
2438 **/
2439static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
2440 struct ipr_hostrcb *hostrcb)
2441{
2442 u32 ioasc;
2443 int error_index;
wenxiong@linux.vnet.ibm.com3185ea62014-09-24 16:25:47 -05002444 struct ipr_hostrcb_type_21_error *error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
2446 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
2447 return;
2448
2449 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
2450 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
2451
Wayne Boyer4565e372010-02-19 13:24:07 -08002452 if (ioa_cfg->sis64)
2453 ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2454 else
2455 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Wayne Boyer4565e372010-02-19 13:24:07 -08002457 if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
2458 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2460 scsi_report_bus_reset(ioa_cfg->host,
Wayne Boyer4565e372010-02-19 13:24:07 -08002461 hostrcb->hcam.u.error.fd_res_addr.bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 }
2463
2464 error_index = ipr_get_error(ioasc);
2465
2466 if (!ipr_error_table[error_index].log_hcam)
2467 return;
2468
wenxiong@linux.vnet.ibm.com3185ea62014-09-24 16:25:47 -05002469 if (ioasc == IPR_IOASC_HW_CMD_FAILED &&
2470 hostrcb->hcam.overlay_id == IPR_HOST_RCB_OVERLAY_ID_21) {
2471 error = &hostrcb->hcam.u.error64.u.type_21_error;
2472
2473 if (((be32_to_cpu(error->sense_data[0]) & 0x0000ff00) >> 8) == ILLEGAL_REQUEST &&
2474 ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
2475 return;
2476 }
2477
Brian King49dc6a12006-11-21 10:28:35 -06002478 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
2480 /* Set indication we have logged an error */
2481 ioa_cfg->errors_logged++;
2482
Brian King933916f2007-03-29 12:43:30 -05002483 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 return;
brking@us.ibm.comcf852032005-11-01 17:00:47 -06002485 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
2486 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
2488 switch (hostrcb->hcam.overlay_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 case IPR_HOST_RCB_OVERLAY_ID_2:
2490 ipr_log_cache_error(ioa_cfg, hostrcb);
2491 break;
2492 case IPR_HOST_RCB_OVERLAY_ID_3:
2493 ipr_log_config_error(ioa_cfg, hostrcb);
2494 break;
2495 case IPR_HOST_RCB_OVERLAY_ID_4:
2496 case IPR_HOST_RCB_OVERLAY_ID_6:
2497 ipr_log_array_error(ioa_cfg, hostrcb);
2498 break;
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002499 case IPR_HOST_RCB_OVERLAY_ID_7:
2500 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
2501 break;
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06002502 case IPR_HOST_RCB_OVERLAY_ID_12:
2503 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
2504 break;
2505 case IPR_HOST_RCB_OVERLAY_ID_13:
2506 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
2507 break;
2508 case IPR_HOST_RCB_OVERLAY_ID_14:
2509 case IPR_HOST_RCB_OVERLAY_ID_16:
2510 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
2511 break;
2512 case IPR_HOST_RCB_OVERLAY_ID_17:
2513 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
2514 break;
Brian King49dc6a12006-11-21 10:28:35 -06002515 case IPR_HOST_RCB_OVERLAY_ID_20:
2516 ipr_log_fabric_error(ioa_cfg, hostrcb);
2517 break;
Wendy Xiong169b9ec2014-03-12 16:08:51 -05002518 case IPR_HOST_RCB_OVERLAY_ID_21:
2519 ipr_log_sis64_device_error(ioa_cfg, hostrcb);
2520 break;
Wayne Boyer4565e372010-02-19 13:24:07 -08002521 case IPR_HOST_RCB_OVERLAY_ID_23:
2522 ipr_log_sis64_config_error(ioa_cfg, hostrcb);
2523 break;
2524 case IPR_HOST_RCB_OVERLAY_ID_24:
2525 case IPR_HOST_RCB_OVERLAY_ID_26:
2526 ipr_log_sis64_array_error(ioa_cfg, hostrcb);
2527 break;
2528 case IPR_HOST_RCB_OVERLAY_ID_30:
2529 ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
2530 break;
brking@us.ibm.comcf852032005-11-01 17:00:47 -06002531 case IPR_HOST_RCB_OVERLAY_ID_1:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 default:
brking@us.ibm.coma9cfca92005-11-01 17:00:41 -06002534 ipr_log_generic_error(ioa_cfg, hostrcb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 break;
2536 }
2537}
2538
2539/**
2540 * ipr_process_error - Op done function for an adapter error log.
2541 * @ipr_cmd: ipr command struct
2542 *
2543 * This function is the op done function for an error log host
2544 * controlled async from the adapter. It will log the error and
2545 * send the HCAM back to the adapter.
2546 *
2547 * Return value:
2548 * none
2549 **/
2550static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2551{
2552 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2553 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07002554 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Wayne Boyer4565e372010-02-19 13:24:07 -08002555 u32 fd_ioasc;
2556
2557 if (ioa_cfg->sis64)
2558 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2559 else
2560 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
2562 list_del(&hostrcb->queue);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06002563 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
2565 if (!ioasc) {
2566 ipr_handle_log_data(ioa_cfg, hostrcb);
Brian King65f56472007-04-26 16:00:12 -05002567 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
2568 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
2570 dev_err(&ioa_cfg->pdev->dev,
2571 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
2572 }
2573
2574 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2575}
2576
2577/**
2578 * ipr_timeout - An internally generated op has timed out.
2579 * @ipr_cmd: ipr command struct
2580 *
2581 * This function blocks host requests and initiates an
2582 * adapter reset.
2583 *
2584 * Return value:
2585 * none
2586 **/
2587static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
2588{
2589 unsigned long lock_flags = 0;
2590 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2591
2592 ENTER;
2593 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2594
2595 ioa_cfg->errors_logged++;
2596 dev_err(&ioa_cfg->pdev->dev,
2597 "Adapter being reset due to command timeout.\n");
2598
2599 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2600 ioa_cfg->sdt_state = GET_DUMP;
2601
2602 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
2603 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2604
2605 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2606 LEAVE;
2607}
2608
2609/**
2610 * ipr_oper_timeout - Adapter timed out transitioning to operational
2611 * @ipr_cmd: ipr command struct
2612 *
2613 * This function blocks host requests and initiates an
2614 * adapter reset.
2615 *
2616 * Return value:
2617 * none
2618 **/
2619static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
2620{
2621 unsigned long lock_flags = 0;
2622 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2623
2624 ENTER;
2625 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2626
2627 ioa_cfg->errors_logged++;
2628 dev_err(&ioa_cfg->pdev->dev,
2629 "Adapter timed out transitioning to operational.\n");
2630
2631 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2632 ioa_cfg->sdt_state = GET_DUMP;
2633
2634 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
2635 if (ipr_fastfail)
2636 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
2637 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2638 }
2639
2640 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2641 LEAVE;
2642}
2643
2644/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 * ipr_find_ses_entry - Find matching SES in SES table
2646 * @res: resource entry struct of SES
2647 *
2648 * Return value:
2649 * pointer to SES table entry / NULL on failure
2650 **/
2651static const struct ipr_ses_table_entry *
2652ipr_find_ses_entry(struct ipr_resource_entry *res)
2653{
2654 int i, j, matches;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002655 struct ipr_std_inq_vpids *vpids;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 const struct ipr_ses_table_entry *ste = ipr_ses_table;
2657
2658 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
2659 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
2660 if (ste->compare_product_id_byte[j] == 'X') {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002661 vpids = &res->std_inq_data.vpids;
2662 if (vpids->product_id[j] == ste->product_id[j])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 matches++;
2664 else
2665 break;
2666 } else
2667 matches++;
2668 }
2669
2670 if (matches == IPR_PROD_ID_LEN)
2671 return ste;
2672 }
2673
2674 return NULL;
2675}
2676
2677/**
2678 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2679 * @ioa_cfg: ioa config struct
2680 * @bus: SCSI bus
2681 * @bus_width: bus width
2682 *
2683 * Return value:
2684 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2685 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2686 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2687 * max 160MHz = max 320MB/sec).
2688 **/
2689static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
2690{
2691 struct ipr_resource_entry *res;
2692 const struct ipr_ses_table_entry *ste;
2693 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
2694
2695 /* Loop through each config table entry in the config table buffer */
2696 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002697 if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 continue;
2699
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002700 if (bus != res->bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 continue;
2702
2703 if (!(ste = ipr_find_ses_entry(res)))
2704 continue;
2705
2706 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
2707 }
2708
2709 return max_xfer_rate;
2710}
2711
2712/**
2713 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2714 * @ioa_cfg: ioa config struct
2715 * @max_delay: max delay in micro-seconds to wait
2716 *
2717 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2718 *
2719 * Return value:
2720 * 0 on success / other on failure
2721 **/
2722static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
2723{
2724 volatile u32 pcii_reg;
2725 int delay = 1;
2726
2727 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2728 while (delay < max_delay) {
2729 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
2730
2731 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
2732 return 0;
2733
2734 /* udelay cannot be used if delay is more than a few milliseconds */
2735 if ((delay / 1000) > MAX_UDELAY_MS)
2736 mdelay(delay / 1000);
2737 else
2738 udelay(delay);
2739
2740 delay += delay;
2741 }
2742 return -EIO;
2743}
2744
2745/**
Wayne Boyerdcbad002010-02-19 13:24:14 -08002746 * ipr_get_sis64_dump_data_section - Dump IOA memory
2747 * @ioa_cfg: ioa config struct
2748 * @start_addr: adapter address to dump
2749 * @dest: destination kernel buffer
2750 * @length_in_words: length to dump in 4 byte words
2751 *
2752 * Return value:
2753 * 0 on success
2754 **/
2755static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2756 u32 start_addr,
2757 __be32 *dest, u32 length_in_words)
2758{
2759 int i;
2760
2761 for (i = 0; i < length_in_words; i++) {
2762 writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
2763 *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
2764 dest++;
2765 }
2766
2767 return 0;
2768}
2769
2770/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 * ipr_get_ldump_data_section - Dump IOA memory
2772 * @ioa_cfg: ioa config struct
2773 * @start_addr: adapter address to dump
2774 * @dest: destination kernel buffer
2775 * @length_in_words: length to dump in 4 byte words
2776 *
2777 * Return value:
2778 * 0 on success / -EIO on failure
2779 **/
2780static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2781 u32 start_addr,
2782 __be32 *dest, u32 length_in_words)
2783{
2784 volatile u32 temp_pcii_reg;
2785 int i, delay = 0;
2786
Wayne Boyerdcbad002010-02-19 13:24:14 -08002787 if (ioa_cfg->sis64)
2788 return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
2789 dest, length_in_words);
2790
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 /* Write IOA interrupt reg starting LDUMP state */
2792 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
Wayne Boyer214777b2010-02-19 13:24:26 -08002793 ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794
2795 /* Wait for IO debug acknowledge */
2796 if (ipr_wait_iodbg_ack(ioa_cfg,
2797 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
2798 dev_err(&ioa_cfg->pdev->dev,
2799 "IOA dump long data transfer timeout\n");
2800 return -EIO;
2801 }
2802
2803 /* Signal LDUMP interlocked - clear IO debug ack */
2804 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2805 ioa_cfg->regs.clr_interrupt_reg);
2806
2807 /* Write Mailbox with starting address */
2808 writel(start_addr, ioa_cfg->ioa_mailbox);
2809
2810 /* Signal address valid - clear IOA Reset alert */
2811 writel(IPR_UPROCI_RESET_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002812 ioa_cfg->regs.clr_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
2814 for (i = 0; i < length_in_words; i++) {
2815 /* Wait for IO debug acknowledge */
2816 if (ipr_wait_iodbg_ack(ioa_cfg,
2817 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2818 dev_err(&ioa_cfg->pdev->dev,
2819 "IOA dump short data transfer timeout\n");
2820 return -EIO;
2821 }
2822
2823 /* Read data from mailbox and increment destination pointer */
2824 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2825 dest++;
2826
2827 /* For all but the last word of data, signal data received */
2828 if (i < (length_in_words - 1)) {
2829 /* Signal dump data received - Clear IO debug Ack */
2830 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2831 ioa_cfg->regs.clr_interrupt_reg);
2832 }
2833 }
2834
2835 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2836 writel(IPR_UPROCI_RESET_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002837 ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838
2839 writel(IPR_UPROCI_IO_DEBUG_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002840 ioa_cfg->regs.clr_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841
2842 /* Signal dump data received - Clear IO debug Ack */
2843 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2844 ioa_cfg->regs.clr_interrupt_reg);
2845
2846 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2847 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2848 temp_pcii_reg =
Wayne Boyer214777b2010-02-19 13:24:26 -08002849 readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850
2851 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2852 return 0;
2853
2854 udelay(10);
2855 delay += 10;
2856 }
2857
2858 return 0;
2859}
2860
2861#ifdef CONFIG_SCSI_IPR_DUMP
2862/**
2863 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2864 * @ioa_cfg: ioa config struct
2865 * @pci_address: adapter address
2866 * @length: length of data to copy
2867 *
2868 * Copy data from PCI adapter to kernel buffer.
2869 * Note: length MUST be a 4 byte multiple
2870 * Return value:
2871 * 0 on success / other on failure
2872 **/
2873static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2874 unsigned long pci_address, u32 length)
2875{
2876 int bytes_copied = 0;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002877 int cur_len, rc, rem_len, rem_page_len, max_dump_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 __be32 *page;
2879 unsigned long lock_flags = 0;
2880 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2881
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002882 if (ioa_cfg->sis64)
2883 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2884 else
2885 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2886
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 while (bytes_copied < length &&
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002888 (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 if (ioa_dump->page_offset >= PAGE_SIZE ||
2890 ioa_dump->page_offset == 0) {
2891 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2892
2893 if (!page) {
2894 ipr_trace;
2895 return bytes_copied;
2896 }
2897
2898 ioa_dump->page_offset = 0;
2899 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2900 ioa_dump->next_page_index++;
2901 } else
2902 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2903
2904 rem_len = length - bytes_copied;
2905 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2906 cur_len = min(rem_len, rem_page_len);
2907
2908 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2909 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2910 rc = -EIO;
2911 } else {
2912 rc = ipr_get_ldump_data_section(ioa_cfg,
2913 pci_address + bytes_copied,
2914 &page[ioa_dump->page_offset / 4],
2915 (cur_len / sizeof(u32)));
2916 }
2917 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2918
2919 if (!rc) {
2920 ioa_dump->page_offset += cur_len;
2921 bytes_copied += cur_len;
2922 } else {
2923 ipr_trace;
2924 break;
2925 }
2926 schedule();
2927 }
2928
2929 return bytes_copied;
2930}
2931
2932/**
2933 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2934 * @hdr: dump entry header struct
2935 *
2936 * Return value:
2937 * nothing
2938 **/
2939static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2940{
2941 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2942 hdr->num_elems = 1;
2943 hdr->offset = sizeof(*hdr);
2944 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2945}
2946
2947/**
2948 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2949 * @ioa_cfg: ioa config struct
2950 * @driver_dump: driver dump struct
2951 *
2952 * Return value:
2953 * nothing
2954 **/
2955static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2956 struct ipr_driver_dump *driver_dump)
2957{
2958 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2959
2960 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2961 driver_dump->ioa_type_entry.hdr.len =
2962 sizeof(struct ipr_dump_ioa_type_entry) -
2963 sizeof(struct ipr_dump_entry_header);
2964 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2965 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2966 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2967 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2968 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2969 ucode_vpd->minor_release[1];
2970 driver_dump->hdr.num_entries++;
2971}
2972
2973/**
2974 * ipr_dump_version_data - Fill in the driver version in the dump.
2975 * @ioa_cfg: ioa config struct
2976 * @driver_dump: driver dump struct
2977 *
2978 * Return value:
2979 * nothing
2980 **/
2981static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2982 struct ipr_driver_dump *driver_dump)
2983{
2984 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2985 driver_dump->version_entry.hdr.len =
2986 sizeof(struct ipr_dump_version_entry) -
2987 sizeof(struct ipr_dump_entry_header);
2988 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2989 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2990 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2991 driver_dump->hdr.num_entries++;
2992}
2993
2994/**
2995 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2996 * @ioa_cfg: ioa config struct
2997 * @driver_dump: driver dump struct
2998 *
2999 * Return value:
3000 * nothing
3001 **/
3002static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
3003 struct ipr_driver_dump *driver_dump)
3004{
3005 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
3006 driver_dump->trace_entry.hdr.len =
3007 sizeof(struct ipr_dump_trace_entry) -
3008 sizeof(struct ipr_dump_entry_header);
3009 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3010 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
3011 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
3012 driver_dump->hdr.num_entries++;
3013}
3014
3015/**
3016 * ipr_dump_location_data - Fill in the IOA location in the dump.
3017 * @ioa_cfg: ioa config struct
3018 * @driver_dump: driver dump struct
3019 *
3020 * Return value:
3021 * nothing
3022 **/
3023static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
3024 struct ipr_driver_dump *driver_dump)
3025{
3026 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
3027 driver_dump->location_entry.hdr.len =
3028 sizeof(struct ipr_dump_location_entry) -
3029 sizeof(struct ipr_dump_entry_header);
3030 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
3031 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
Kay Sievers71610f52008-12-03 22:41:36 +01003032 strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 driver_dump->hdr.num_entries++;
3034}
3035
3036/**
3037 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
3038 * @ioa_cfg: ioa config struct
3039 * @dump: dump struct
3040 *
3041 * Return value:
3042 * nothing
3043 **/
3044static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
3045{
3046 unsigned long start_addr, sdt_word;
3047 unsigned long lock_flags = 0;
3048 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
3049 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003050 u32 num_entries, max_num_entries, start_off, end_off;
3051 u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 struct ipr_sdt *sdt;
Wayne Boyerdcbad002010-02-19 13:24:14 -08003053 int valid = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 int i;
3055
3056 ENTER;
3057
3058 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3059
Brian King41e9a692011-09-21 08:51:11 -05003060 if (ioa_cfg->sdt_state != READ_DUMP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3062 return;
3063 }
3064
Wayne Boyer110def82010-11-04 09:36:16 -07003065 if (ioa_cfg->sis64) {
3066 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3067 ssleep(IPR_DUMP_DELAY_SECONDS);
3068 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3069 }
3070
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 start_addr = readl(ioa_cfg->ioa_mailbox);
3072
Wayne Boyerdcbad002010-02-19 13:24:14 -08003073 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 dev_err(&ioa_cfg->pdev->dev,
3075 "Invalid dump table format: %lx\n", start_addr);
3076 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3077 return;
3078 }
3079
3080 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
3081
3082 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
3083
3084 /* Initialize the overall dump header */
3085 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
3086 driver_dump->hdr.num_entries = 1;
3087 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
3088 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
3089 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
3090 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
3091
3092 ipr_dump_version_data(ioa_cfg, driver_dump);
3093 ipr_dump_location_data(ioa_cfg, driver_dump);
3094 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
3095 ipr_dump_trace_data(ioa_cfg, driver_dump);
3096
3097 /* Update dump_header */
3098 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
3099
3100 /* IOA Dump entry */
3101 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 ioa_dump->hdr.len = 0;
3103 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3104 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
3105
3106 /* First entries in sdt are actually a list of dump addresses and
3107 lengths to gather the real dump data. sdt represents the pointer
3108 to the ioa generated dump table. Dump data will be extracted based
3109 on entries in this table */
3110 sdt = &ioa_dump->sdt;
3111
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003112 if (ioa_cfg->sis64) {
3113 max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
3114 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
3115 } else {
3116 max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
3117 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
3118 }
3119
3120 bytes_to_copy = offsetof(struct ipr_sdt, entry) +
3121 (max_num_entries * sizeof(struct ipr_sdt_entry));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003123 bytes_to_copy / sizeof(__be32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
3125 /* Smart Dump table is ready to use and the first entry is valid */
Wayne Boyerdcbad002010-02-19 13:24:14 -08003126 if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
3127 (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 dev_err(&ioa_cfg->pdev->dev,
3129 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
3130 rc, be32_to_cpu(sdt->hdr.state));
3131 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
3132 ioa_cfg->sdt_state = DUMP_OBTAINED;
3133 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3134 return;
3135 }
3136
3137 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
3138
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003139 if (num_entries > max_num_entries)
3140 num_entries = max_num_entries;
3141
3142 /* Update dump length to the actual data to be copied */
3143 dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
3144 if (ioa_cfg->sis64)
3145 dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
3146 else
3147 dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
3149 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3150
3151 for (i = 0; i < num_entries; i++) {
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003152 if (ioa_dump->hdr.len > max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3154 break;
3155 }
3156
3157 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
Wayne Boyerdcbad002010-02-19 13:24:14 -08003158 sdt_word = be32_to_cpu(sdt->entry[i].start_token);
3159 if (ioa_cfg->sis64)
3160 bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
3161 else {
3162 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
3163 end_off = be32_to_cpu(sdt->entry[i].end_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164
Wayne Boyerdcbad002010-02-19 13:24:14 -08003165 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
3166 bytes_to_copy = end_off - start_off;
3167 else
3168 valid = 0;
3169 }
3170 if (valid) {
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003171 if (bytes_to_copy > max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
3173 continue;
3174 }
3175
3176 /* Copy data from adapter to driver buffers */
3177 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
3178 bytes_to_copy);
3179
3180 ioa_dump->hdr.len += bytes_copied;
3181
3182 if (bytes_copied != bytes_to_copy) {
3183 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3184 break;
3185 }
3186 }
3187 }
3188 }
3189
3190 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
3191
3192 /* Update dump_header */
3193 driver_dump->hdr.len += ioa_dump->hdr.len;
3194 wmb();
3195 ioa_cfg->sdt_state = DUMP_OBTAINED;
3196 LEAVE;
3197}
3198
3199#else
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003200#define ipr_get_ioa_dump(ioa_cfg, dump) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201#endif
3202
3203/**
3204 * ipr_release_dump - Free adapter dump memory
3205 * @kref: kref struct
3206 *
3207 * Return value:
3208 * nothing
3209 **/
3210static void ipr_release_dump(struct kref *kref)
3211{
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003212 struct ipr_dump *dump = container_of(kref, struct ipr_dump, kref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
3214 unsigned long lock_flags = 0;
3215 int i;
3216
3217 ENTER;
3218 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3219 ioa_cfg->dump = NULL;
3220 ioa_cfg->sdt_state = INACTIVE;
3221 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3222
3223 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
3224 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
3225
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003226 vfree(dump->ioa_dump.ioa_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 kfree(dump);
3228 LEAVE;
3229}
3230
3231/**
3232 * ipr_worker_thread - Worker thread
David Howellsc4028952006-11-22 14:57:56 +00003233 * @work: ioa config struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 *
3235 * Called at task level from a work thread. This function takes care
3236 * of adding and removing device from the mid-layer as configuration
3237 * changes are detected by the adapter.
3238 *
3239 * Return value:
3240 * nothing
3241 **/
David Howellsc4028952006-11-22 14:57:56 +00003242static void ipr_worker_thread(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243{
3244 unsigned long lock_flags;
3245 struct ipr_resource_entry *res;
3246 struct scsi_device *sdev;
3247 struct ipr_dump *dump;
David Howellsc4028952006-11-22 14:57:56 +00003248 struct ipr_ioa_cfg *ioa_cfg =
3249 container_of(work, struct ipr_ioa_cfg, work_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 u8 bus, target, lun;
3251 int did_work;
3252
3253 ENTER;
3254 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3255
Brian King41e9a692011-09-21 08:51:11 -05003256 if (ioa_cfg->sdt_state == READ_DUMP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 dump = ioa_cfg->dump;
3258 if (!dump) {
3259 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3260 return;
3261 }
3262 kref_get(&dump->kref);
3263 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3264 ipr_get_ioa_dump(ioa_cfg, dump);
3265 kref_put(&dump->kref, ipr_release_dump);
3266
3267 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King4c647e92011-10-15 09:08:56 -05003268 if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3270 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3271 return;
3272 }
3273
3274restart:
3275 do {
3276 did_work = 0;
Brian Kingf688f962014-12-02 12:47:37 -06003277 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3279 return;
3280 }
3281
3282 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3283 if (res->del_from_ml && res->sdev) {
3284 did_work = 1;
3285 sdev = res->sdev;
3286 if (!scsi_device_get(sdev)) {
Kleber Sacilotto de Souza5767a1c2011-02-14 20:19:31 -02003287 if (!res->add_to_ml)
3288 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
3289 else
3290 res->del_from_ml = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3292 scsi_remove_device(sdev);
3293 scsi_device_put(sdev);
3294 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3295 }
3296 break;
3297 }
3298 }
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003299 } while (did_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300
3301 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3302 if (res->add_to_ml) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08003303 bus = res->bus;
3304 target = res->target;
3305 lun = res->lun;
Brian King1121b792006-03-29 09:37:16 -06003306 res->add_to_ml = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3308 scsi_add_device(ioa_cfg->host, bus, target, lun);
3309 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3310 goto restart;
3311 }
3312 }
3313
Brian Kingf688f962014-12-02 12:47:37 -06003314 ioa_cfg->scan_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Tony Jonesee959b02008-02-22 00:13:36 +01003316 kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 LEAVE;
3318}
3319
3320#ifdef CONFIG_SCSI_IPR_TRACE
3321/**
3322 * ipr_read_trace - Dump the adapter trace
Chris Wright2c3c8be2010-05-12 18:28:57 -07003323 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08003325 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 * @buf: buffer
3327 * @off: offset
3328 * @count: buffer size
3329 *
3330 * Return value:
3331 * number of bytes printed to buffer
3332 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07003333static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08003334 struct bin_attribute *bin_attr,
3335 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336{
Tony Jonesee959b02008-02-22 00:13:36 +01003337 struct device *dev = container_of(kobj, struct device, kobj);
3338 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3340 unsigned long lock_flags = 0;
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003341 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342
3343 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003344 ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
3345 IPR_TRACE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003347
3348 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349}
3350
3351static struct bin_attribute ipr_trace_attr = {
3352 .attr = {
3353 .name = "trace",
3354 .mode = S_IRUGO,
3355 },
3356 .size = 0,
3357 .read = ipr_read_trace,
3358};
3359#endif
3360
3361/**
3362 * ipr_show_fw_version - Show the firmware version
Tony Jonesee959b02008-02-22 00:13:36 +01003363 * @dev: class device struct
3364 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 *
3366 * Return value:
3367 * number of bytes printed to buffer
3368 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003369static ssize_t ipr_show_fw_version(struct device *dev,
3370 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371{
Tony Jonesee959b02008-02-22 00:13:36 +01003372 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3374 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
3375 unsigned long lock_flags = 0;
3376 int len;
3377
3378 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3379 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
3380 ucode_vpd->major_release, ucode_vpd->card_type,
3381 ucode_vpd->minor_release[0],
3382 ucode_vpd->minor_release[1]);
3383 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3384 return len;
3385}
3386
Tony Jonesee959b02008-02-22 00:13:36 +01003387static struct device_attribute ipr_fw_version_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 .attr = {
3389 .name = "fw_version",
3390 .mode = S_IRUGO,
3391 },
3392 .show = ipr_show_fw_version,
3393};
3394
3395/**
3396 * ipr_show_log_level - Show the adapter's error logging level
Tony Jonesee959b02008-02-22 00:13:36 +01003397 * @dev: class device struct
3398 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 *
3400 * Return value:
3401 * number of bytes printed to buffer
3402 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003403static ssize_t ipr_show_log_level(struct device *dev,
3404 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405{
Tony Jonesee959b02008-02-22 00:13:36 +01003406 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3408 unsigned long lock_flags = 0;
3409 int len;
3410
3411 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3412 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
3413 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3414 return len;
3415}
3416
3417/**
3418 * ipr_store_log_level - Change the adapter's error logging level
Tony Jonesee959b02008-02-22 00:13:36 +01003419 * @dev: class device struct
3420 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 *
3422 * Return value:
3423 * number of bytes printed to buffer
3424 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003425static ssize_t ipr_store_log_level(struct device *dev,
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003426 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 const char *buf, size_t count)
3428{
Tony Jonesee959b02008-02-22 00:13:36 +01003429 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3431 unsigned long lock_flags = 0;
3432
3433 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3434 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
3435 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3436 return strlen(buf);
3437}
3438
Tony Jonesee959b02008-02-22 00:13:36 +01003439static struct device_attribute ipr_log_level_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 .attr = {
3441 .name = "log_level",
3442 .mode = S_IRUGO | S_IWUSR,
3443 },
3444 .show = ipr_show_log_level,
3445 .store = ipr_store_log_level
3446};
3447
3448/**
3449 * ipr_store_diagnostics - IOA Diagnostics interface
Tony Jonesee959b02008-02-22 00:13:36 +01003450 * @dev: device struct
3451 * @buf: buffer
3452 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 *
3454 * This function will reset the adapter and wait a reasonable
3455 * amount of time for any errors that the adapter might log.
3456 *
3457 * Return value:
3458 * count on success / other on failure
3459 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003460static ssize_t ipr_store_diagnostics(struct device *dev,
3461 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 const char *buf, size_t count)
3463{
Tony Jonesee959b02008-02-22 00:13:36 +01003464 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3466 unsigned long lock_flags = 0;
3467 int rc = count;
3468
3469 if (!capable(CAP_SYS_ADMIN))
3470 return -EACCES;
3471
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003473 while (ioa_cfg->in_reset_reload) {
Brian King970ea292007-04-26 16:00:06 -05003474 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3475 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3476 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3477 }
3478
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 ioa_cfg->errors_logged = 0;
3480 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3481
3482 if (ioa_cfg->in_reset_reload) {
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 /* Wait for a second for any errors to be logged */
3487 msleep(1000);
3488 } else {
3489 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3490 return -EIO;
3491 }
3492
3493 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3494 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
3495 rc = -EIO;
3496 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3497
3498 return rc;
3499}
3500
Tony Jonesee959b02008-02-22 00:13:36 +01003501static struct device_attribute ipr_diagnostics_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 .attr = {
3503 .name = "run_diagnostics",
3504 .mode = S_IWUSR,
3505 },
3506 .store = ipr_store_diagnostics
3507};
3508
3509/**
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003510 * ipr_show_adapter_state - Show the adapter's state
Tony Jonesee959b02008-02-22 00:13:36 +01003511 * @class_dev: device struct
3512 * @buf: buffer
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003513 *
3514 * Return value:
3515 * number of bytes printed to buffer
3516 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003517static ssize_t ipr_show_adapter_state(struct device *dev,
3518 struct device_attribute *attr, char *buf)
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003519{
Tony Jonesee959b02008-02-22 00:13:36 +01003520 struct Scsi_Host *shost = class_to_shost(dev);
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003521 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3522 unsigned long lock_flags = 0;
3523 int len;
3524
3525 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06003526 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003527 len = snprintf(buf, PAGE_SIZE, "offline\n");
3528 else
3529 len = snprintf(buf, PAGE_SIZE, "online\n");
3530 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3531 return len;
3532}
3533
3534/**
3535 * ipr_store_adapter_state - Change adapter state
Tony Jonesee959b02008-02-22 00:13:36 +01003536 * @dev: device struct
3537 * @buf: buffer
3538 * @count: buffer size
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003539 *
3540 * This function will change the adapter's state.
3541 *
3542 * Return value:
3543 * count on success / other on failure
3544 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003545static ssize_t ipr_store_adapter_state(struct device *dev,
3546 struct device_attribute *attr,
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003547 const char *buf, size_t count)
3548{
Tony Jonesee959b02008-02-22 00:13:36 +01003549 struct Scsi_Host *shost = class_to_shost(dev);
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003550 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3551 unsigned long lock_flags;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06003552 int result = count, i;
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003553
3554 if (!capable(CAP_SYS_ADMIN))
3555 return -EACCES;
3556
3557 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06003558 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead &&
3559 !strncmp(buf, "online", 6)) {
3560 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
3561 spin_lock(&ioa_cfg->hrrq[i]._lock);
3562 ioa_cfg->hrrq[i].ioa_is_dead = 0;
3563 spin_unlock(&ioa_cfg->hrrq[i]._lock);
3564 }
3565 wmb();
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003566 ioa_cfg->reset_retries = 0;
3567 ioa_cfg->in_ioa_bringdown = 0;
3568 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3569 }
3570 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3571 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3572
3573 return result;
3574}
3575
Tony Jonesee959b02008-02-22 00:13:36 +01003576static struct device_attribute ipr_ioa_state_attr = {
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003577 .attr = {
Brian King49dd0962008-04-28 17:36:20 -05003578 .name = "online_state",
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003579 .mode = S_IRUGO | S_IWUSR,
3580 },
3581 .show = ipr_show_adapter_state,
3582 .store = ipr_store_adapter_state
3583};
3584
3585/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 * ipr_store_reset_adapter - Reset the adapter
Tony Jonesee959b02008-02-22 00:13:36 +01003587 * @dev: device struct
3588 * @buf: buffer
3589 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 *
3591 * This function will reset the adapter.
3592 *
3593 * Return value:
3594 * count on success / other on failure
3595 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003596static ssize_t ipr_store_reset_adapter(struct device *dev,
3597 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 const char *buf, size_t count)
3599{
Tony Jonesee959b02008-02-22 00:13:36 +01003600 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3602 unsigned long lock_flags;
3603 int result = count;
3604
3605 if (!capable(CAP_SYS_ADMIN))
3606 return -EACCES;
3607
3608 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3609 if (!ioa_cfg->in_reset_reload)
3610 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3611 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3612 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3613
3614 return result;
3615}
3616
Tony Jonesee959b02008-02-22 00:13:36 +01003617static struct device_attribute ipr_ioa_reset_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 .attr = {
3619 .name = "reset_host",
3620 .mode = S_IWUSR,
3621 },
3622 .store = ipr_store_reset_adapter
3623};
3624
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06003625static int ipr_iopoll(struct blk_iopoll *iop, int budget);
3626 /**
3627 * ipr_show_iopoll_weight - Show ipr polling mode
3628 * @dev: class device struct
3629 * @buf: buffer
3630 *
3631 * Return value:
3632 * number of bytes printed to buffer
3633 **/
3634static ssize_t ipr_show_iopoll_weight(struct device *dev,
3635 struct device_attribute *attr, char *buf)
3636{
3637 struct Scsi_Host *shost = class_to_shost(dev);
3638 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3639 unsigned long lock_flags = 0;
3640 int len;
3641
3642 spin_lock_irqsave(shost->host_lock, lock_flags);
3643 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->iopoll_weight);
3644 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3645
3646 return len;
3647}
3648
3649/**
3650 * ipr_store_iopoll_weight - Change the adapter's polling mode
3651 * @dev: class device struct
3652 * @buf: buffer
3653 *
3654 * Return value:
3655 * number of bytes printed to buffer
3656 **/
3657static ssize_t ipr_store_iopoll_weight(struct device *dev,
3658 struct device_attribute *attr,
3659 const char *buf, size_t count)
3660{
3661 struct Scsi_Host *shost = class_to_shost(dev);
3662 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3663 unsigned long user_iopoll_weight;
3664 unsigned long lock_flags = 0;
3665 int i;
3666
3667 if (!ioa_cfg->sis64) {
3668 dev_info(&ioa_cfg->pdev->dev, "blk-iopoll not supported on this adapter\n");
3669 return -EINVAL;
3670 }
3671 if (kstrtoul(buf, 10, &user_iopoll_weight))
3672 return -EINVAL;
3673
3674 if (user_iopoll_weight > 256) {
3675 dev_info(&ioa_cfg->pdev->dev, "Invalid blk-iopoll weight. It must be less than 256\n");
3676 return -EINVAL;
3677 }
3678
3679 if (user_iopoll_weight == ioa_cfg->iopoll_weight) {
3680 dev_info(&ioa_cfg->pdev->dev, "Current blk-iopoll weight has the same weight\n");
3681 return strlen(buf);
3682 }
3683
Jens Axboe89f8b332014-03-13 09:38:42 -06003684 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06003685 for (i = 1; i < ioa_cfg->hrrq_num; i++)
3686 blk_iopoll_disable(&ioa_cfg->hrrq[i].iopoll);
3687 }
3688
3689 spin_lock_irqsave(shost->host_lock, lock_flags);
3690 ioa_cfg->iopoll_weight = user_iopoll_weight;
Jens Axboe89f8b332014-03-13 09:38:42 -06003691 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06003692 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
3693 blk_iopoll_init(&ioa_cfg->hrrq[i].iopoll,
3694 ioa_cfg->iopoll_weight, ipr_iopoll);
3695 blk_iopoll_enable(&ioa_cfg->hrrq[i].iopoll);
3696 }
3697 }
3698 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3699
3700 return strlen(buf);
3701}
3702
3703static struct device_attribute ipr_iopoll_weight_attr = {
3704 .attr = {
3705 .name = "iopoll_weight",
3706 .mode = S_IRUGO | S_IWUSR,
3707 },
3708 .show = ipr_show_iopoll_weight,
3709 .store = ipr_store_iopoll_weight
3710};
3711
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712/**
3713 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3714 * @buf_len: buffer length
3715 *
3716 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3717 * list to use for microcode download
3718 *
3719 * Return value:
3720 * pointer to sglist / NULL on failure
3721 **/
3722static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
3723{
3724 int sg_size, order, bsize_elem, num_elem, i, j;
3725 struct ipr_sglist *sglist;
3726 struct scatterlist *scatterlist;
3727 struct page *page;
3728
3729 /* Get the minimum size per scatter/gather element */
3730 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
3731
3732 /* Get the actual size per element */
3733 order = get_order(sg_size);
3734
3735 /* Determine the actual number of bytes per element */
3736 bsize_elem = PAGE_SIZE * (1 << order);
3737
3738 /* Determine the actual number of sg entries needed */
3739 if (buf_len % bsize_elem)
3740 num_elem = (buf_len / bsize_elem) + 1;
3741 else
3742 num_elem = buf_len / bsize_elem;
3743
3744 /* Allocate a scatter/gather list for the DMA */
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06003745 sglist = kzalloc(sizeof(struct ipr_sglist) +
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 (sizeof(struct scatterlist) * (num_elem - 1)),
3747 GFP_KERNEL);
3748
3749 if (sglist == NULL) {
3750 ipr_trace;
3751 return NULL;
3752 }
3753
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 scatterlist = sglist->scatterlist;
Jens Axboe45711f12007-10-22 21:19:53 +02003755 sg_init_table(scatterlist, num_elem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756
3757 sglist->order = order;
3758 sglist->num_sg = num_elem;
3759
3760 /* Allocate a bunch of sg elements */
3761 for (i = 0; i < num_elem; i++) {
3762 page = alloc_pages(GFP_KERNEL, order);
3763 if (!page) {
3764 ipr_trace;
3765
3766 /* Free up what we already allocated */
3767 for (j = i - 1; j >= 0; j--)
Jens Axboe45711f12007-10-22 21:19:53 +02003768 __free_pages(sg_page(&scatterlist[j]), order);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 kfree(sglist);
3770 return NULL;
3771 }
3772
Jens Axboe642f1492007-10-24 11:20:47 +02003773 sg_set_page(&scatterlist[i], page, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 }
3775
3776 return sglist;
3777}
3778
3779/**
3780 * ipr_free_ucode_buffer - Frees a microcode download buffer
3781 * @p_dnld: scatter/gather list pointer
3782 *
3783 * Free a DMA'able ucode download buffer previously allocated with
3784 * ipr_alloc_ucode_buffer
3785 *
3786 * Return value:
3787 * nothing
3788 **/
3789static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
3790{
3791 int i;
3792
3793 for (i = 0; i < sglist->num_sg; i++)
Jens Axboe45711f12007-10-22 21:19:53 +02003794 __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795
3796 kfree(sglist);
3797}
3798
3799/**
3800 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3801 * @sglist: scatter/gather list pointer
3802 * @buffer: buffer pointer
3803 * @len: buffer length
3804 *
3805 * Copy a microcode image from a user buffer into a buffer allocated by
3806 * ipr_alloc_ucode_buffer
3807 *
3808 * Return value:
3809 * 0 on success / other on failure
3810 **/
3811static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
3812 u8 *buffer, u32 len)
3813{
3814 int bsize_elem, i, result = 0;
3815 struct scatterlist *scatterlist;
3816 void *kaddr;
3817
3818 /* Determine the actual number of bytes per element */
3819 bsize_elem = PAGE_SIZE * (1 << sglist->order);
3820
3821 scatterlist = sglist->scatterlist;
3822
3823 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
Jens Axboe45711f12007-10-22 21:19:53 +02003824 struct page *page = sg_page(&scatterlist[i]);
3825
3826 kaddr = kmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 memcpy(kaddr, buffer, bsize_elem);
Jens Axboe45711f12007-10-22 21:19:53 +02003828 kunmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829
3830 scatterlist[i].length = bsize_elem;
3831
3832 if (result != 0) {
3833 ipr_trace;
3834 return result;
3835 }
3836 }
3837
3838 if (len % bsize_elem) {
Jens Axboe45711f12007-10-22 21:19:53 +02003839 struct page *page = sg_page(&scatterlist[i]);
3840
3841 kaddr = kmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 memcpy(kaddr, buffer, len % bsize_elem);
Jens Axboe45711f12007-10-22 21:19:53 +02003843 kunmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844
3845 scatterlist[i].length = len % bsize_elem;
3846 }
3847
3848 sglist->buffer_len = len;
3849 return result;
3850}
3851
3852/**
Wayne Boyera32c0552010-02-19 13:23:36 -08003853 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3854 * @ipr_cmd: ipr command struct
3855 * @sglist: scatter/gather list
3856 *
3857 * Builds a microcode download IOA data list (IOADL).
3858 *
3859 **/
3860static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
3861 struct ipr_sglist *sglist)
3862{
3863 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3864 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
3865 struct scatterlist *scatterlist = sglist->scatterlist;
3866 int i;
3867
3868 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3869 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3870 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3871
3872 ioarcb->ioadl_len =
3873 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
3874 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3875 ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
3876 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
3877 ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
3878 }
3879
3880 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3881}
3882
3883/**
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003884 * ipr_build_ucode_ioadl - Build a microcode download IOADL
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 * @ipr_cmd: ipr command struct
3886 * @sglist: scatter/gather list
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 *
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003888 * Builds a microcode download IOA data list (IOADL).
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 **/
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003891static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
3892 struct ipr_sglist *sglist)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08003895 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 struct scatterlist *scatterlist = sglist->scatterlist;
3897 int i;
3898
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003899 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08003901 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3902
3903 ioarcb->ioadl_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3905
3906 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3907 ioadl[i].flags_and_data_len =
3908 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
3909 ioadl[i].address =
3910 cpu_to_be32(sg_dma_address(&scatterlist[i]));
3911 }
3912
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003913 ioadl[i-1].flags_and_data_len |=
3914 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3915}
3916
3917/**
3918 * ipr_update_ioa_ucode - Update IOA's microcode
3919 * @ioa_cfg: ioa config struct
3920 * @sglist: scatter/gather list
3921 *
3922 * Initiate an adapter reset to update the IOA's microcode
3923 *
3924 * Return value:
3925 * 0 on success / -EIO on failure
3926 **/
3927static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3928 struct ipr_sglist *sglist)
3929{
3930 unsigned long lock_flags;
3931
3932 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003933 while (ioa_cfg->in_reset_reload) {
Brian King970ea292007-04-26 16:00:06 -05003934 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3935 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3936 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3937 }
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003938
3939 if (ioa_cfg->ucode_sglist) {
3940 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3941 dev_err(&ioa_cfg->pdev->dev,
3942 "Microcode download already in progress\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 return -EIO;
3944 }
3945
Anton Blanchardd73341b2014-10-30 17:27:08 -05003946 sglist->num_dma_sg = dma_map_sg(&ioa_cfg->pdev->dev,
3947 sglist->scatterlist, sglist->num_sg,
3948 DMA_TO_DEVICE);
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003949
3950 if (!sglist->num_dma_sg) {
3951 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3952 dev_err(&ioa_cfg->pdev->dev,
3953 "Failed to map microcode download buffer!\n");
3954 return -EIO;
3955 }
3956
3957 ioa_cfg->ucode_sglist = sglist;
3958 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3959 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3960 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3961
3962 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3963 ioa_cfg->ucode_sglist = NULL;
3964 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 return 0;
3966}
3967
3968/**
3969 * ipr_store_update_fw - Update the firmware on the adapter
Tony Jonesee959b02008-02-22 00:13:36 +01003970 * @class_dev: device struct
3971 * @buf: buffer
3972 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 *
3974 * This function will update the firmware on the adapter.
3975 *
3976 * Return value:
3977 * count on success / other on failure
3978 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003979static ssize_t ipr_store_update_fw(struct device *dev,
3980 struct device_attribute *attr,
3981 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982{
Tony Jonesee959b02008-02-22 00:13:36 +01003983 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3985 struct ipr_ucode_image_header *image_hdr;
3986 const struct firmware *fw_entry;
3987 struct ipr_sglist *sglist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 char fname[100];
3989 char *src;
3990 int len, result, dnld_size;
3991
3992 if (!capable(CAP_SYS_ADMIN))
3993 return -EACCES;
3994
3995 len = snprintf(fname, 99, "%s", buf);
3996 fname[len-1] = '\0';
3997
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003998 if (request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
4000 return -EIO;
4001 }
4002
4003 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
4004
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
4006 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
4007 sglist = ipr_alloc_ucode_buffer(dnld_size);
4008
4009 if (!sglist) {
4010 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
4011 release_firmware(fw_entry);
4012 return -ENOMEM;
4013 }
4014
4015 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
4016
4017 if (result) {
4018 dev_err(&ioa_cfg->pdev->dev,
4019 "Microcode buffer copy to DMA buffer failed\n");
brking@us.ibm.com12baa422005-11-01 17:01:27 -06004020 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 }
4022
Wayne Boyer14ed9cc2011-10-03 20:54:37 -07004023 ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
4024
brking@us.ibm.com12baa422005-11-01 17:01:27 -06004025 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026
brking@us.ibm.com12baa422005-11-01 17:01:27 -06004027 if (!result)
4028 result = count;
4029out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 ipr_free_ucode_buffer(sglist);
4031 release_firmware(fw_entry);
brking@us.ibm.com12baa422005-11-01 17:01:27 -06004032 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033}
4034
Tony Jonesee959b02008-02-22 00:13:36 +01004035static struct device_attribute ipr_update_fw_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 .attr = {
4037 .name = "update_fw",
4038 .mode = S_IWUSR,
4039 },
4040 .store = ipr_store_update_fw
4041};
4042
Wayne Boyer75576bb2010-07-14 10:50:14 -07004043/**
4044 * ipr_show_fw_type - Show the adapter's firmware type.
4045 * @dev: class device struct
4046 * @buf: buffer
4047 *
4048 * Return value:
4049 * number of bytes printed to buffer
4050 **/
4051static ssize_t ipr_show_fw_type(struct device *dev,
4052 struct device_attribute *attr, char *buf)
4053{
4054 struct Scsi_Host *shost = class_to_shost(dev);
4055 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4056 unsigned long lock_flags = 0;
4057 int len;
4058
4059 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4060 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
4061 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4062 return len;
4063}
4064
4065static struct device_attribute ipr_ioa_fw_type_attr = {
4066 .attr = {
4067 .name = "fw_type",
4068 .mode = S_IRUGO,
4069 },
4070 .show = ipr_show_fw_type
4071};
4072
Tony Jonesee959b02008-02-22 00:13:36 +01004073static struct device_attribute *ipr_ioa_attrs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 &ipr_fw_version_attr,
4075 &ipr_log_level_attr,
4076 &ipr_diagnostics_attr,
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06004077 &ipr_ioa_state_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 &ipr_ioa_reset_attr,
4079 &ipr_update_fw_attr,
Wayne Boyer75576bb2010-07-14 10:50:14 -07004080 &ipr_ioa_fw_type_attr,
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06004081 &ipr_iopoll_weight_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 NULL,
4083};
4084
4085#ifdef CONFIG_SCSI_IPR_DUMP
4086/**
4087 * ipr_read_dump - Dump the adapter
Chris Wright2c3c8be2010-05-12 18:28:57 -07004088 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08004090 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 * @buf: buffer
4092 * @off: offset
4093 * @count: buffer size
4094 *
4095 * Return value:
4096 * number of bytes printed to buffer
4097 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07004098static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08004099 struct bin_attribute *bin_attr,
4100 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101{
Tony Jonesee959b02008-02-22 00:13:36 +01004102 struct device *cdev = container_of(kobj, struct device, kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 struct Scsi_Host *shost = class_to_shost(cdev);
4104 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4105 struct ipr_dump *dump;
4106 unsigned long lock_flags = 0;
4107 char *src;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004108 int len, sdt_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 size_t rc = count;
4110
4111 if (!capable(CAP_SYS_ADMIN))
4112 return -EACCES;
4113
4114 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4115 dump = ioa_cfg->dump;
4116
4117 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
4118 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4119 return 0;
4120 }
4121 kref_get(&dump->kref);
4122 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4123
4124 if (off > dump->driver_dump.hdr.len) {
4125 kref_put(&dump->kref, ipr_release_dump);
4126 return 0;
4127 }
4128
4129 if (off + count > dump->driver_dump.hdr.len) {
4130 count = dump->driver_dump.hdr.len - off;
4131 rc = count;
4132 }
4133
4134 if (count && off < sizeof(dump->driver_dump)) {
4135 if (off + count > sizeof(dump->driver_dump))
4136 len = sizeof(dump->driver_dump) - off;
4137 else
4138 len = count;
4139 src = (u8 *)&dump->driver_dump + off;
4140 memcpy(buf, src, len);
4141 buf += len;
4142 off += len;
4143 count -= len;
4144 }
4145
4146 off -= sizeof(dump->driver_dump);
4147
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004148 if (ioa_cfg->sis64)
4149 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4150 (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
4151 sizeof(struct ipr_sdt_entry));
4152 else
4153 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4154 (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
4155
4156 if (count && off < sdt_end) {
4157 if (off + count > sdt_end)
4158 len = sdt_end - off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 else
4160 len = count;
4161 src = (u8 *)&dump->ioa_dump + off;
4162 memcpy(buf, src, len);
4163 buf += len;
4164 off += len;
4165 count -= len;
4166 }
4167
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004168 off -= sdt_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169
4170 while (count) {
4171 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
4172 len = PAGE_ALIGN(off) - off;
4173 else
4174 len = count;
4175 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
4176 src += off & ~PAGE_MASK;
4177 memcpy(buf, src, len);
4178 buf += len;
4179 off += len;
4180 count -= len;
4181 }
4182
4183 kref_put(&dump->kref, ipr_release_dump);
4184 return rc;
4185}
4186
4187/**
4188 * ipr_alloc_dump - Prepare for adapter dump
4189 * @ioa_cfg: ioa config struct
4190 *
4191 * Return value:
4192 * 0 on success / other on failure
4193 **/
4194static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
4195{
4196 struct ipr_dump *dump;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004197 __be32 **ioa_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 unsigned long lock_flags = 0;
4199
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06004200 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201
4202 if (!dump) {
4203 ipr_err("Dump memory allocation failed\n");
4204 return -ENOMEM;
4205 }
4206
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004207 if (ioa_cfg->sis64)
4208 ioa_data = vmalloc(IPR_FMT3_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
4209 else
4210 ioa_data = vmalloc(IPR_FMT2_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
4211
4212 if (!ioa_data) {
4213 ipr_err("Dump memory allocation failed\n");
4214 kfree(dump);
4215 return -ENOMEM;
4216 }
4217
4218 dump->ioa_dump.ioa_data = ioa_data;
4219
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 kref_init(&dump->kref);
4221 dump->ioa_cfg = ioa_cfg;
4222
4223 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4224
4225 if (INACTIVE != ioa_cfg->sdt_state) {
4226 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004227 vfree(dump->ioa_dump.ioa_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 kfree(dump);
4229 return 0;
4230 }
4231
4232 ioa_cfg->dump = dump;
4233 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06004234 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead && !ioa_cfg->dump_taken) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 ioa_cfg->dump_taken = 1;
4236 schedule_work(&ioa_cfg->work_q);
4237 }
4238 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4239
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 return 0;
4241}
4242
4243/**
4244 * ipr_free_dump - Free adapter dump memory
4245 * @ioa_cfg: ioa config struct
4246 *
4247 * Return value:
4248 * 0 on success / other on failure
4249 **/
4250static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
4251{
4252 struct ipr_dump *dump;
4253 unsigned long lock_flags = 0;
4254
4255 ENTER;
4256
4257 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4258 dump = ioa_cfg->dump;
4259 if (!dump) {
4260 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4261 return 0;
4262 }
4263
4264 ioa_cfg->dump = NULL;
4265 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4266
4267 kref_put(&dump->kref, ipr_release_dump);
4268
4269 LEAVE;
4270 return 0;
4271}
4272
4273/**
4274 * ipr_write_dump - Setup dump state of adapter
Chris Wright2c3c8be2010-05-12 18:28:57 -07004275 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08004277 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 * @buf: buffer
4279 * @off: offset
4280 * @count: buffer size
4281 *
4282 * Return value:
4283 * number of bytes printed to buffer
4284 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07004285static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08004286 struct bin_attribute *bin_attr,
4287 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288{
Tony Jonesee959b02008-02-22 00:13:36 +01004289 struct device *cdev = container_of(kobj, struct device, kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290 struct Scsi_Host *shost = class_to_shost(cdev);
4291 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4292 int rc;
4293
4294 if (!capable(CAP_SYS_ADMIN))
4295 return -EACCES;
4296
4297 if (buf[0] == '1')
4298 rc = ipr_alloc_dump(ioa_cfg);
4299 else if (buf[0] == '0')
4300 rc = ipr_free_dump(ioa_cfg);
4301 else
4302 return -EINVAL;
4303
4304 if (rc)
4305 return rc;
4306 else
4307 return count;
4308}
4309
4310static struct bin_attribute ipr_dump_attr = {
4311 .attr = {
4312 .name = "dump",
4313 .mode = S_IRUSR | S_IWUSR,
4314 },
4315 .size = 0,
4316 .read = ipr_read_dump,
4317 .write = ipr_write_dump
4318};
4319#else
4320static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
4321#endif
4322
4323/**
4324 * ipr_change_queue_depth - Change the device's queue depth
4325 * @sdev: scsi device struct
4326 * @qdepth: depth to set
Mike Christiee881a172009-10-15 17:46:39 -07004327 * @reason: calling context
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 *
4329 * Return value:
4330 * actual depth set
4331 **/
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01004332static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333{
Brian King35a39692006-09-25 12:39:20 -05004334 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4335 struct ipr_resource_entry *res;
4336 unsigned long lock_flags = 0;
4337
4338 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4339 res = (struct ipr_resource_entry *)sdev->hostdata;
4340
4341 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
4342 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
4343 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4344
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01004345 scsi_change_queue_depth(sdev, qdepth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346 return sdev->queue_depth;
4347}
4348
4349/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4351 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004352 * @attr: device attribute structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 * @buf: buffer
4354 *
4355 * Return value:
4356 * number of bytes printed to buffer
4357 **/
Yani Ioannou10523b32005-05-17 06:43:37 -04004358static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359{
4360 struct scsi_device *sdev = to_scsi_device(dev);
4361 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4362 struct ipr_resource_entry *res;
4363 unsigned long lock_flags = 0;
4364 ssize_t len = -ENXIO;
4365
4366 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4367 res = (struct ipr_resource_entry *)sdev->hostdata;
4368 if (res)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004369 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4371 return len;
4372}
4373
4374static struct device_attribute ipr_adapter_handle_attr = {
4375 .attr = {
4376 .name = "adapter_handle",
4377 .mode = S_IRUSR,
4378 },
4379 .show = ipr_show_adapter_handle
4380};
4381
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004382/**
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004383 * ipr_show_resource_path - Show the resource path or the resource address for
4384 * this device.
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004385 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004386 * @attr: device attribute structure
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004387 * @buf: buffer
4388 *
4389 * Return value:
4390 * number of bytes printed to buffer
4391 **/
4392static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
4393{
4394 struct scsi_device *sdev = to_scsi_device(dev);
4395 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4396 struct ipr_resource_entry *res;
4397 unsigned long lock_flags = 0;
4398 ssize_t len = -ENXIO;
4399 char buffer[IPR_MAX_RES_PATH_LENGTH];
4400
4401 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4402 res = (struct ipr_resource_entry *)sdev->hostdata;
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004403 if (res && ioa_cfg->sis64)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004404 len = snprintf(buf, PAGE_SIZE, "%s\n",
Brian Kingb3b3b402013-01-11 17:43:49 -06004405 __ipr_format_res_path(res->res_path, buffer,
4406 sizeof(buffer)));
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004407 else if (res)
4408 len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
4409 res->bus, res->target, res->lun);
4410
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004411 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4412 return len;
4413}
4414
4415static struct device_attribute ipr_resource_path_attr = {
4416 .attr = {
4417 .name = "resource_path",
Wayne Boyer75576bb2010-07-14 10:50:14 -07004418 .mode = S_IRUGO,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004419 },
4420 .show = ipr_show_resource_path
4421};
4422
Wayne Boyer75576bb2010-07-14 10:50:14 -07004423/**
Wayne Boyer46d74562010-08-11 07:15:17 -07004424 * ipr_show_device_id - Show the device_id for this device.
4425 * @dev: device struct
4426 * @attr: device attribute structure
4427 * @buf: buffer
4428 *
4429 * Return value:
4430 * number of bytes printed to buffer
4431 **/
4432static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
4433{
4434 struct scsi_device *sdev = to_scsi_device(dev);
4435 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4436 struct ipr_resource_entry *res;
4437 unsigned long lock_flags = 0;
4438 ssize_t len = -ENXIO;
4439
4440 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4441 res = (struct ipr_resource_entry *)sdev->hostdata;
4442 if (res && ioa_cfg->sis64)
4443 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->dev_id);
4444 else if (res)
4445 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
4446
4447 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4448 return len;
4449}
4450
4451static struct device_attribute ipr_device_id_attr = {
4452 .attr = {
4453 .name = "device_id",
4454 .mode = S_IRUGO,
4455 },
4456 .show = ipr_show_device_id
4457};
4458
4459/**
Wayne Boyer75576bb2010-07-14 10:50:14 -07004460 * ipr_show_resource_type - Show the resource type for this device.
4461 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004462 * @attr: device attribute structure
Wayne Boyer75576bb2010-07-14 10:50:14 -07004463 * @buf: buffer
4464 *
4465 * Return value:
4466 * number of bytes printed to buffer
4467 **/
4468static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
4469{
4470 struct scsi_device *sdev = to_scsi_device(dev);
4471 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4472 struct ipr_resource_entry *res;
4473 unsigned long lock_flags = 0;
4474 ssize_t len = -ENXIO;
4475
4476 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4477 res = (struct ipr_resource_entry *)sdev->hostdata;
4478
4479 if (res)
4480 len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
4481
4482 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4483 return len;
4484}
4485
4486static struct device_attribute ipr_resource_type_attr = {
4487 .attr = {
4488 .name = "resource_type",
4489 .mode = S_IRUGO,
4490 },
4491 .show = ipr_show_resource_type
4492};
4493
Linus Torvalds1da177e2005-04-16 15:20:36 -07004494static struct device_attribute *ipr_dev_attrs[] = {
4495 &ipr_adapter_handle_attr,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004496 &ipr_resource_path_attr,
Wayne Boyer46d74562010-08-11 07:15:17 -07004497 &ipr_device_id_attr,
Wayne Boyer75576bb2010-07-14 10:50:14 -07004498 &ipr_resource_type_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 NULL,
4500};
4501
4502/**
4503 * ipr_biosparam - Return the HSC mapping
4504 * @sdev: scsi device struct
4505 * @block_device: block device pointer
4506 * @capacity: capacity of the device
4507 * @parm: Array containing returned HSC values.
4508 *
4509 * This function generates the HSC parms that fdisk uses.
4510 * We want to make sure we return something that places partitions
4511 * on 4k boundaries for best performance with the IOA.
4512 *
4513 * Return value:
4514 * 0 on success
4515 **/
4516static int ipr_biosparam(struct scsi_device *sdev,
4517 struct block_device *block_device,
4518 sector_t capacity, int *parm)
4519{
4520 int heads, sectors;
4521 sector_t cylinders;
4522
4523 heads = 128;
4524 sectors = 32;
4525
4526 cylinders = capacity;
4527 sector_div(cylinders, (128 * 32));
4528
4529 /* return result */
4530 parm[0] = heads;
4531 parm[1] = sectors;
4532 parm[2] = cylinders;
4533
4534 return 0;
4535}
4536
4537/**
Brian King35a39692006-09-25 12:39:20 -05004538 * ipr_find_starget - Find target based on bus/target.
4539 * @starget: scsi target struct
4540 *
4541 * Return value:
4542 * resource entry pointer if found / NULL if not found
4543 **/
4544static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
4545{
4546 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4547 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4548 struct ipr_resource_entry *res;
4549
4550 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004551 if ((res->bus == starget->channel) &&
Brian King0ee1d712012-03-14 21:20:06 -05004552 (res->target == starget->id)) {
Brian King35a39692006-09-25 12:39:20 -05004553 return res;
4554 }
4555 }
4556
4557 return NULL;
4558}
4559
4560static struct ata_port_info sata_port_info;
4561
4562/**
4563 * ipr_target_alloc - Prepare for commands to a SCSI target
4564 * @starget: scsi target struct
4565 *
4566 * If the device is a SATA device, this function allocates an
4567 * ATA port with libata, else it does nothing.
4568 *
4569 * Return value:
4570 * 0 on success / non-0 on failure
4571 **/
4572static int ipr_target_alloc(struct scsi_target *starget)
4573{
4574 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4575 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4576 struct ipr_sata_port *sata_port;
4577 struct ata_port *ap;
4578 struct ipr_resource_entry *res;
4579 unsigned long lock_flags;
4580
4581 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4582 res = ipr_find_starget(starget);
4583 starget->hostdata = NULL;
4584
4585 if (res && ipr_is_gata(res)) {
4586 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4587 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
4588 if (!sata_port)
4589 return -ENOMEM;
4590
4591 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
4592 if (ap) {
4593 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4594 sata_port->ioa_cfg = ioa_cfg;
4595 sata_port->ap = ap;
4596 sata_port->res = res;
4597
4598 res->sata_port = sata_port;
4599 ap->private_data = sata_port;
4600 starget->hostdata = sata_port;
4601 } else {
4602 kfree(sata_port);
4603 return -ENOMEM;
4604 }
4605 }
4606 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4607
4608 return 0;
4609}
4610
4611/**
4612 * ipr_target_destroy - Destroy a SCSI target
4613 * @starget: scsi target struct
4614 *
4615 * If the device was a SATA device, this function frees the libata
4616 * ATA port, else it does nothing.
4617 *
4618 **/
4619static void ipr_target_destroy(struct scsi_target *starget)
4620{
4621 struct ipr_sata_port *sata_port = starget->hostdata;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004622 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4623 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4624
4625 if (ioa_cfg->sis64) {
Brian King0ee1d712012-03-14 21:20:06 -05004626 if (!ipr_find_starget(starget)) {
4627 if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4628 clear_bit(starget->id, ioa_cfg->array_ids);
4629 else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4630 clear_bit(starget->id, ioa_cfg->vset_ids);
4631 else if (starget->channel == 0)
4632 clear_bit(starget->id, ioa_cfg->target_ids);
4633 }
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004634 }
Brian King35a39692006-09-25 12:39:20 -05004635
4636 if (sata_port) {
4637 starget->hostdata = NULL;
4638 ata_sas_port_destroy(sata_port->ap);
4639 kfree(sata_port);
4640 }
4641}
4642
4643/**
4644 * ipr_find_sdev - Find device based on bus/target/lun.
4645 * @sdev: scsi device struct
4646 *
4647 * Return value:
4648 * resource entry pointer if found / NULL if not found
4649 **/
4650static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
4651{
4652 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4653 struct ipr_resource_entry *res;
4654
4655 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004656 if ((res->bus == sdev->channel) &&
4657 (res->target == sdev->id) &&
4658 (res->lun == sdev->lun))
Brian King35a39692006-09-25 12:39:20 -05004659 return res;
4660 }
4661
4662 return NULL;
4663}
4664
4665/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666 * ipr_slave_destroy - Unconfigure a SCSI device
4667 * @sdev: scsi device struct
4668 *
4669 * Return value:
4670 * nothing
4671 **/
4672static void ipr_slave_destroy(struct scsi_device *sdev)
4673{
4674 struct ipr_resource_entry *res;
4675 struct ipr_ioa_cfg *ioa_cfg;
4676 unsigned long lock_flags = 0;
4677
4678 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4679
4680 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4681 res = (struct ipr_resource_entry *) sdev->hostdata;
4682 if (res) {
Brian King35a39692006-09-25 12:39:20 -05004683 if (res->sata_port)
Tejun Heo3e4ec342010-05-10 21:41:30 +02004684 res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685 sdev->hostdata = NULL;
4686 res->sdev = NULL;
Brian King35a39692006-09-25 12:39:20 -05004687 res->sata_port = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688 }
4689 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4690}
4691
4692/**
4693 * ipr_slave_configure - Configure a SCSI device
4694 * @sdev: scsi device struct
4695 *
4696 * This function configures the specified scsi device.
4697 *
4698 * Return value:
4699 * 0 on success
4700 **/
4701static int ipr_slave_configure(struct scsi_device *sdev)
4702{
4703 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4704 struct ipr_resource_entry *res;
Brian Kingdd406ef2009-04-22 08:58:02 -05004705 struct ata_port *ap = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 unsigned long lock_flags = 0;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004707 char buffer[IPR_MAX_RES_PATH_LENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708
4709 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4710 res = sdev->hostdata;
4711 if (res) {
4712 if (ipr_is_af_dasd_device(res))
4713 sdev->type = TYPE_RAID;
brking@us.ibm.com0726ce22005-11-01 17:01:01 -06004714 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 sdev->scsi_level = 4;
brking@us.ibm.com0726ce22005-11-01 17:01:01 -06004716 sdev->no_uld_attach = 1;
4717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718 if (ipr_is_vset_device(res)) {
Brian King60654e22014-12-02 12:47:46 -06004719 sdev->scsi_level = SCSI_SPC_3;
Jens Axboe242f9dc2008-09-14 05:55:09 -07004720 blk_queue_rq_timeout(sdev->request_queue,
4721 IPR_VSET_RW_TIMEOUT);
Martin K. Petersen086fa5f2010-02-26 00:20:38 -05004722 blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 }
Brian Kingdd406ef2009-04-22 08:58:02 -05004724 if (ipr_is_gata(res) && res->sata_port)
4725 ap = res->sata_port->ap;
4726 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4727
4728 if (ap) {
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01004729 scsi_change_queue_depth(sdev, IPR_MAX_CMD_PER_ATA_LUN);
Brian Kingdd406ef2009-04-22 08:58:02 -05004730 ata_sas_slave_configure(sdev, ap);
Christoph Hellwigc8b09f62014-11-03 20:15:14 +01004731 }
4732
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004733 if (ioa_cfg->sis64)
4734 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
Brian Kingb3b3b402013-01-11 17:43:49 -06004735 ipr_format_res_path(ioa_cfg,
4736 res->res_path, buffer, sizeof(buffer)));
Brian Kingdd406ef2009-04-22 08:58:02 -05004737 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738 }
4739 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4740 return 0;
4741}
4742
4743/**
Brian King35a39692006-09-25 12:39:20 -05004744 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
4745 * @sdev: scsi device struct
4746 *
4747 * This function initializes an ATA port so that future commands
4748 * sent through queuecommand will work.
4749 *
4750 * Return value:
4751 * 0 on success
4752 **/
4753static int ipr_ata_slave_alloc(struct scsi_device *sdev)
4754{
4755 struct ipr_sata_port *sata_port = NULL;
4756 int rc = -ENXIO;
4757
4758 ENTER;
4759 if (sdev->sdev_target)
4760 sata_port = sdev->sdev_target->hostdata;
Dan Williamsb2024452012-03-21 21:09:07 -07004761 if (sata_port) {
Brian King35a39692006-09-25 12:39:20 -05004762 rc = ata_sas_port_init(sata_port->ap);
Dan Williamsb2024452012-03-21 21:09:07 -07004763 if (rc == 0)
4764 rc = ata_sas_sync_probe(sata_port->ap);
4765 }
4766
Brian King35a39692006-09-25 12:39:20 -05004767 if (rc)
4768 ipr_slave_destroy(sdev);
4769
4770 LEAVE;
4771 return rc;
4772}
4773
4774/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775 * ipr_slave_alloc - Prepare for commands to a device.
4776 * @sdev: scsi device struct
4777 *
4778 * This function saves a pointer to the resource entry
4779 * in the scsi device struct if the device exists. We
4780 * can then use this pointer in ipr_queuecommand when
4781 * handling new commands.
4782 *
4783 * Return value:
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004784 * 0 on success / -ENXIO if device does not exist
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 **/
4786static int ipr_slave_alloc(struct scsi_device *sdev)
4787{
4788 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4789 struct ipr_resource_entry *res;
4790 unsigned long lock_flags;
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004791 int rc = -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792
4793 sdev->hostdata = NULL;
4794
4795 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4796
Brian King35a39692006-09-25 12:39:20 -05004797 res = ipr_find_sdev(sdev);
4798 if (res) {
4799 res->sdev = sdev;
4800 res->add_to_ml = 0;
4801 res->in_erp = 0;
4802 sdev->hostdata = res;
4803 if (!ipr_is_naca_model(res))
4804 res->needs_sync_complete = 1;
4805 rc = 0;
4806 if (ipr_is_gata(res)) {
4807 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4808 return ipr_ata_slave_alloc(sdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809 }
4810 }
4811
4812 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4813
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004814 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815}
4816
Brian King6cdb0812014-10-30 17:27:10 -05004817/**
4818 * ipr_match_lun - Match function for specified LUN
4819 * @ipr_cmd: ipr command struct
4820 * @device: device to match (sdev)
4821 *
4822 * Returns:
4823 * 1 if command matches sdev / 0 if command does not match sdev
4824 **/
4825static int ipr_match_lun(struct ipr_cmnd *ipr_cmd, void *device)
4826{
4827 if (ipr_cmd->scsi_cmd && ipr_cmd->scsi_cmd->device == device)
4828 return 1;
4829 return 0;
4830}
4831
4832/**
4833 * ipr_wait_for_ops - Wait for matching commands to complete
4834 * @ipr_cmd: ipr command struct
4835 * @device: device to match (sdev)
4836 * @match: match function to use
4837 *
4838 * Returns:
4839 * SUCCESS / FAILED
4840 **/
4841static int ipr_wait_for_ops(struct ipr_ioa_cfg *ioa_cfg, void *device,
4842 int (*match)(struct ipr_cmnd *, void *))
4843{
4844 struct ipr_cmnd *ipr_cmd;
4845 int wait;
4846 unsigned long flags;
4847 struct ipr_hrr_queue *hrrq;
4848 signed long timeout = IPR_ABORT_TASK_TIMEOUT;
4849 DECLARE_COMPLETION_ONSTACK(comp);
4850
4851 ENTER;
4852 do {
4853 wait = 0;
4854
4855 for_each_hrrq(hrrq, ioa_cfg) {
4856 spin_lock_irqsave(hrrq->lock, flags);
4857 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
4858 if (match(ipr_cmd, device)) {
4859 ipr_cmd->eh_comp = &comp;
4860 wait++;
4861 }
4862 }
4863 spin_unlock_irqrestore(hrrq->lock, flags);
4864 }
4865
4866 if (wait) {
4867 timeout = wait_for_completion_timeout(&comp, timeout);
4868
4869 if (!timeout) {
4870 wait = 0;
4871
4872 for_each_hrrq(hrrq, ioa_cfg) {
4873 spin_lock_irqsave(hrrq->lock, flags);
4874 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
4875 if (match(ipr_cmd, device)) {
4876 ipr_cmd->eh_comp = NULL;
4877 wait++;
4878 }
4879 }
4880 spin_unlock_irqrestore(hrrq->lock, flags);
4881 }
4882
4883 if (wait)
4884 dev_err(&ioa_cfg->pdev->dev, "Timed out waiting for aborted commands\n");
4885 LEAVE;
4886 return wait ? FAILED : SUCCESS;
4887 }
4888 }
4889 } while (wait);
4890
4891 LEAVE;
4892 return SUCCESS;
4893}
4894
wenxiong@linux.vnet.ibm.com70233ac2013-01-11 17:43:54 -06004895static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896{
4897 struct ipr_ioa_cfg *ioa_cfg;
wenxiong@linux.vnet.ibm.com70233ac2013-01-11 17:43:54 -06004898 unsigned long lock_flags = 0;
4899 int rc = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900
4901 ENTER;
wenxiong@linux.vnet.ibm.com70233ac2013-01-11 17:43:54 -06004902 ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
4903 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904
wenxiong@linux.vnet.ibm.com96b04db2013-04-17 09:34:06 -05004905 if (!ioa_cfg->in_reset_reload && !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
wenxiong@linux.vnet.ibm.com70233ac2013-01-11 17:43:54 -06004906 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004907 dev_err(&ioa_cfg->pdev->dev,
4908 "Adapter being reset as a result of error recovery.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004909
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004910 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4911 ioa_cfg->sdt_state = GET_DUMP;
4912 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913
wenxiong@linux.vnet.ibm.com70233ac2013-01-11 17:43:54 -06004914 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4915 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4916 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917
wenxiong@linux.vnet.ibm.com70233ac2013-01-11 17:43:54 -06004918 /* If we got hit with a host reset while we were already resetting
4919 the adapter for some reason, and the reset failed. */
4920 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
4921 ipr_trace;
4922 rc = FAILED;
4923 }
4924
4925 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926 LEAVE;
4927 return rc;
4928}
4929
4930/**
Brian Kingc6513092006-03-29 09:37:43 -06004931 * ipr_device_reset - Reset the device
4932 * @ioa_cfg: ioa config struct
4933 * @res: resource entry struct
4934 *
4935 * This function issues a device reset to the affected device.
4936 * If the device is a SCSI device, a LUN reset will be sent
4937 * to the device first. If that does not work, a target reset
Brian King35a39692006-09-25 12:39:20 -05004938 * will be sent. If the device is a SATA device, a PHY reset will
4939 * be sent.
Brian Kingc6513092006-03-29 09:37:43 -06004940 *
4941 * Return value:
4942 * 0 on success / non-zero on failure
4943 **/
4944static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
4945 struct ipr_resource_entry *res)
4946{
4947 struct ipr_cmnd *ipr_cmd;
4948 struct ipr_ioarcb *ioarcb;
4949 struct ipr_cmd_pkt *cmd_pkt;
Brian King35a39692006-09-25 12:39:20 -05004950 struct ipr_ioarcb_ata_regs *regs;
Brian Kingc6513092006-03-29 09:37:43 -06004951 u32 ioasc;
4952
4953 ENTER;
4954 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4955 ioarcb = &ipr_cmd->ioarcb;
4956 cmd_pkt = &ioarcb->cmd_pkt;
Wayne Boyera32c0552010-02-19 13:23:36 -08004957
4958 if (ipr_cmd->ioa_cfg->sis64) {
4959 regs = &ipr_cmd->i.ata_ioadl.regs;
4960 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
4961 } else
4962 regs = &ioarcb->u.add_data.u.regs;
Brian Kingc6513092006-03-29 09:37:43 -06004963
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004964 ioarcb->res_handle = res->res_handle;
Brian Kingc6513092006-03-29 09:37:43 -06004965 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4966 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
Brian King35a39692006-09-25 12:39:20 -05004967 if (ipr_is_gata(res)) {
4968 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
Wayne Boyera32c0552010-02-19 13:23:36 -08004969 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
Brian King35a39692006-09-25 12:39:20 -05004970 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
4971 }
Brian Kingc6513092006-03-29 09:37:43 -06004972
4973 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
Wayne Boyer96d21f02010-05-10 09:13:27 -07004974 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06004975 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Wayne Boyer96d21f02010-05-10 09:13:27 -07004976 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) {
4977 if (ipr_cmd->ioa_cfg->sis64)
4978 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
4979 sizeof(struct ipr_ioasa_gata));
4980 else
4981 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
4982 sizeof(struct ipr_ioasa_gata));
4983 }
Brian Kingc6513092006-03-29 09:37:43 -06004984
4985 LEAVE;
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03004986 return IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0;
Brian Kingc6513092006-03-29 09:37:43 -06004987}
4988
4989/**
Brian King35a39692006-09-25 12:39:20 -05004990 * ipr_sata_reset - Reset the SATA port
Tejun Heocc0680a2007-08-06 18:36:23 +09004991 * @link: SATA link to reset
Brian King35a39692006-09-25 12:39:20 -05004992 * @classes: class of the attached device
4993 *
Tejun Heocc0680a2007-08-06 18:36:23 +09004994 * This function issues a SATA phy reset to the affected ATA link.
Brian King35a39692006-09-25 12:39:20 -05004995 *
4996 * Return value:
4997 * 0 on success / non-zero on failure
4998 **/
Tejun Heocc0680a2007-08-06 18:36:23 +09004999static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
Andrew Morton120bda32007-03-26 02:17:43 -07005000 unsigned long deadline)
Brian King35a39692006-09-25 12:39:20 -05005001{
Tejun Heocc0680a2007-08-06 18:36:23 +09005002 struct ipr_sata_port *sata_port = link->ap->private_data;
Brian King35a39692006-09-25 12:39:20 -05005003 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5004 struct ipr_resource_entry *res;
5005 unsigned long lock_flags = 0;
5006 int rc = -ENXIO;
5007
5008 ENTER;
5009 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005010 while (ioa_cfg->in_reset_reload) {
Brian King73d98ff2006-11-21 10:27:58 -06005011 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5012 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
5013 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5014 }
5015
Brian King35a39692006-09-25 12:39:20 -05005016 res = sata_port->res;
5017 if (res) {
5018 rc = ipr_device_reset(ioa_cfg, res);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08005019 *classes = res->ata_class;
Brian King35a39692006-09-25 12:39:20 -05005020 }
5021
5022 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5023 LEAVE;
5024 return rc;
5025}
5026
5027/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028 * ipr_eh_dev_reset - Reset the device
5029 * @scsi_cmd: scsi command struct
5030 *
5031 * This function issues a device reset to the affected device.
5032 * A LUN reset will be sent to the device first. If that does
5033 * not work, a target reset will be sent.
5034 *
5035 * Return value:
5036 * SUCCESS / FAILED
5037 **/
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005038static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039{
5040 struct ipr_cmnd *ipr_cmd;
5041 struct ipr_ioa_cfg *ioa_cfg;
5042 struct ipr_resource_entry *res;
Brian King35a39692006-09-25 12:39:20 -05005043 struct ata_port *ap;
5044 int rc = 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005045 struct ipr_hrr_queue *hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046
5047 ENTER;
5048 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
5049 res = scsi_cmd->device->hostdata;
5050
brking@us.ibm.comeeb883072005-11-01 17:02:29 -06005051 if (!res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052 return FAILED;
5053
5054 /*
5055 * If we are currently going through reset/reload, return failed. This will force the
5056 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
5057 * reset to complete
5058 */
5059 if (ioa_cfg->in_reset_reload)
5060 return FAILED;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005061 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062 return FAILED;
5063
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005064 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005065 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005066 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
5067 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
5068 if (ipr_cmd->scsi_cmd)
5069 ipr_cmd->done = ipr_scsi_eh_done;
5070 if (ipr_cmd->qc)
5071 ipr_cmd->done = ipr_sata_eh_done;
5072 if (ipr_cmd->qc &&
5073 !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
5074 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
5075 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
5076 }
Brian King7402ece2006-11-21 10:28:23 -06005077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005079 spin_unlock(&hrrq->_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 res->resetting_device = 1;
Brian Kingfb3ed3c2006-03-29 09:37:37 -06005082 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
Brian King35a39692006-09-25 12:39:20 -05005083
5084 if (ipr_is_gata(res) && res->sata_port) {
5085 ap = res->sata_port->ap;
5086 spin_unlock_irq(scsi_cmd->device->host->host_lock);
Tejun Heoa1efdab2008-03-25 12:22:50 +09005087 ata_std_error_handler(ap);
Brian King35a39692006-09-25 12:39:20 -05005088 spin_lock_irq(scsi_cmd->device->host->host_lock);
Brian King5af23d22007-05-09 15:36:35 -05005089
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005090 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005091 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005092 list_for_each_entry(ipr_cmd,
5093 &hrrq->hrrq_pending_q, queue) {
5094 if (ipr_cmd->ioarcb.res_handle ==
5095 res->res_handle) {
5096 rc = -EIO;
5097 break;
5098 }
Brian King5af23d22007-05-09 15:36:35 -05005099 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005100 spin_unlock(&hrrq->_lock);
Brian King5af23d22007-05-09 15:36:35 -05005101 }
Brian King35a39692006-09-25 12:39:20 -05005102 } else
5103 rc = ipr_device_reset(ioa_cfg, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104 res->resetting_device = 0;
Wendy Xiong0b1f8d42014-01-21 12:16:39 -06005105 res->reset_occurred = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107 LEAVE;
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005108 return rc ? FAILED : SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109}
5110
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005111static int ipr_eh_dev_reset(struct scsi_cmnd *cmd)
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04005112{
5113 int rc;
Brian King6cdb0812014-10-30 17:27:10 -05005114 struct ipr_ioa_cfg *ioa_cfg;
5115
5116 ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04005117
5118 spin_lock_irq(cmd->device->host->host_lock);
5119 rc = __ipr_eh_dev_reset(cmd);
5120 spin_unlock_irq(cmd->device->host->host_lock);
5121
Brian King6cdb0812014-10-30 17:27:10 -05005122 if (rc == SUCCESS)
5123 rc = ipr_wait_for_ops(ioa_cfg, cmd->device, ipr_match_lun);
5124
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04005125 return rc;
5126}
5127
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128/**
5129 * ipr_bus_reset_done - Op done function for bus reset.
5130 * @ipr_cmd: ipr command struct
5131 *
5132 * This function is the op done function for a bus reset
5133 *
5134 * Return value:
5135 * none
5136 **/
5137static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
5138{
5139 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5140 struct ipr_resource_entry *res;
5141
5142 ENTER;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08005143 if (!ioa_cfg->sis64)
5144 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
5145 if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
5146 scsi_report_bus_reset(ioa_cfg->host, res->bus);
5147 break;
5148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150
5151 /*
5152 * If abort has not completed, indicate the reset has, else call the
5153 * abort's done function to wake the sleeping eh thread
5154 */
5155 if (ipr_cmd->sibling->sibling)
5156 ipr_cmd->sibling->sibling = NULL;
5157 else
5158 ipr_cmd->sibling->done(ipr_cmd->sibling);
5159
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005160 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161 LEAVE;
5162}
5163
5164/**
5165 * ipr_abort_timeout - An abort task has timed out
5166 * @ipr_cmd: ipr command struct
5167 *
5168 * This function handles when an abort task times out. If this
5169 * happens we issue a bus reset since we have resources tied
5170 * up that must be freed before returning to the midlayer.
5171 *
5172 * Return value:
5173 * none
5174 **/
5175static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
5176{
5177 struct ipr_cmnd *reset_cmd;
5178 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5179 struct ipr_cmd_pkt *cmd_pkt;
5180 unsigned long lock_flags = 0;
5181
5182 ENTER;
5183 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5184 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
5185 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5186 return;
5187 }
5188
Brian Kingfb3ed3c2006-03-29 09:37:37 -06005189 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5191 ipr_cmd->sibling = reset_cmd;
5192 reset_cmd->sibling = ipr_cmd;
5193 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
5194 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
5195 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5196 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
5197 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
5198
5199 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
5200 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5201 LEAVE;
5202}
5203
5204/**
5205 * ipr_cancel_op - Cancel specified op
5206 * @scsi_cmd: scsi command struct
5207 *
5208 * This function cancels specified op.
5209 *
5210 * Return value:
5211 * SUCCESS / FAILED
5212 **/
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005213static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214{
5215 struct ipr_cmnd *ipr_cmd;
5216 struct ipr_ioa_cfg *ioa_cfg;
5217 struct ipr_resource_entry *res;
5218 struct ipr_cmd_pkt *cmd_pkt;
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02005219 u32 ioasc, int_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 int op_found = 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005221 struct ipr_hrr_queue *hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222
5223 ENTER;
5224 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
5225 res = scsi_cmd->device->hostdata;
5226
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005227 /* If we are currently going through reset/reload, return failed.
5228 * This will force the mid-layer to call ipr_eh_host_reset,
5229 * which will then go to sleep and wait for the reset to complete
5230 */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005231 if (ioa_cfg->in_reset_reload ||
5232 ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005233 return FAILED;
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02005234 if (!res)
5235 return FAILED;
5236
5237 /*
5238 * If we are aborting a timed out op, chances are that the timeout was caused
5239 * by a still not detected EEH error. In such cases, reading a register will
5240 * trigger the EEH recovery infrastructure.
5241 */
5242 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5243
5244 if (!ipr_is_gscsi(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245 return FAILED;
5246
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005247 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005248 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005249 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
5250 if (ipr_cmd->scsi_cmd == scsi_cmd) {
5251 ipr_cmd->done = ipr_scsi_eh_done;
5252 op_found = 1;
5253 break;
5254 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005256 spin_unlock(&hrrq->_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257 }
5258
5259 if (!op_found)
5260 return SUCCESS;
5261
5262 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08005263 ipr_cmd->ioarcb.res_handle = res->res_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5265 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5266 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5267 ipr_cmd->u.sdev = scsi_cmd->device;
5268
Brian Kingfb3ed3c2006-03-29 09:37:37 -06005269 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
5270 scsi_cmd->cmnd[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
Wayne Boyer96d21f02010-05-10 09:13:27 -07005272 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273
5274 /*
5275 * If the abort task timed out and we sent a bus reset, we will get
5276 * one the following responses to the abort
5277 */
5278 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
5279 ioasc = 0;
5280 ipr_trace;
5281 }
5282
Kleber Sacilotto de Souzac4ee22a2013-03-14 13:52:23 -05005283 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005284 if (!ipr_is_naca_model(res))
5285 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286
5287 LEAVE;
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005288 return IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005289}
5290
5291/**
5292 * ipr_eh_abort - Abort a single op
5293 * @scsi_cmd: scsi command struct
5294 *
5295 * Return value:
Brian Kingf688f962014-12-02 12:47:37 -06005296 * 0 if scan in progress / 1 if scan is complete
5297 **/
5298static int ipr_scan_finished(struct Scsi_Host *shost, unsigned long elapsed_time)
5299{
5300 unsigned long lock_flags;
5301 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
5302 int rc = 0;
5303
5304 spin_lock_irqsave(shost->host_lock, lock_flags);
5305 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead || ioa_cfg->scan_done)
5306 rc = 1;
5307 if ((elapsed_time/HZ) > (ioa_cfg->transop_timeout * 2))
5308 rc = 1;
5309 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5310 return rc;
5311}
5312
5313/**
5314 * ipr_eh_host_reset - Reset the host adapter
5315 * @scsi_cmd: scsi command struct
5316 *
5317 * Return value:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005318 * SUCCESS / FAILED
5319 **/
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005320static int ipr_eh_abort(struct scsi_cmnd *scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321{
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005322 unsigned long flags;
5323 int rc;
Brian King6cdb0812014-10-30 17:27:10 -05005324 struct ipr_ioa_cfg *ioa_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325
5326 ENTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327
Brian King6cdb0812014-10-30 17:27:10 -05005328 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
5329
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005330 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
5331 rc = ipr_cancel_op(scsi_cmd);
5332 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333
Brian King6cdb0812014-10-30 17:27:10 -05005334 if (rc == SUCCESS)
5335 rc = ipr_wait_for_ops(ioa_cfg, scsi_cmd->device, ipr_match_lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336 LEAVE;
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005337 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338}
5339
5340/**
5341 * ipr_handle_other_interrupt - Handle "other" interrupts
5342 * @ioa_cfg: ioa config struct
Wayne Boyer634651f2010-08-27 14:45:07 -07005343 * @int_reg: interrupt register
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344 *
5345 * Return value:
5346 * IRQ_NONE / IRQ_HANDLED
5347 **/
Wayne Boyer634651f2010-08-27 14:45:07 -07005348static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
Wayne Boyer630ad8312011-04-07 12:12:30 -07005349 u32 int_reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350{
5351 irqreturn_t rc = IRQ_HANDLED;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005352 u32 int_mask_reg;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005353
Wayne Boyer7dacb642011-04-12 10:29:02 -07005354 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
5355 int_reg &= ~int_mask_reg;
5356
5357 /* If an interrupt on the adapter did not occur, ignore it.
5358 * Or in the case of SIS 64, check for a stage change interrupt.
5359 */
5360 if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
5361 if (ioa_cfg->sis64) {
5362 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
5363 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5364 if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
5365
5366 /* clear stage change */
5367 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
5368 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5369 list_del(&ioa_cfg->reset_cmd->queue);
5370 del_timer(&ioa_cfg->reset_cmd->timer);
5371 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5372 return IRQ_HANDLED;
5373 }
5374 }
5375
5376 return IRQ_NONE;
5377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378
5379 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
5380 /* Mask the interrupt */
5381 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
5382
5383 /* Clear the interrupt */
5384 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
5385 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5386
5387 list_del(&ioa_cfg->reset_cmd->queue);
5388 del_timer(&ioa_cfg->reset_cmd->timer);
5389 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
Wayne Boyer7dacb642011-04-12 10:29:02 -07005390 } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
Brian King7dd21302012-03-14 21:20:08 -05005391 if (ioa_cfg->clear_isr) {
5392 if (ipr_debug && printk_ratelimit())
5393 dev_err(&ioa_cfg->pdev->dev,
5394 "Spurious interrupt detected. 0x%08X\n", int_reg);
5395 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5396 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5397 return IRQ_NONE;
5398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399 } else {
5400 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
5401 ioa_cfg->ioa_unit_checked = 1;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005402 else if (int_reg & IPR_PCII_NO_HOST_RRQ)
5403 dev_err(&ioa_cfg->pdev->dev,
5404 "No Host RRQ. 0x%08X\n", int_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405 else
5406 dev_err(&ioa_cfg->pdev->dev,
5407 "Permanent IOA failure. 0x%08X\n", int_reg);
5408
5409 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5410 ioa_cfg->sdt_state = GET_DUMP;
5411
5412 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
5413 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5414 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005415
Linus Torvalds1da177e2005-04-16 15:20:36 -07005416 return rc;
5417}
5418
5419/**
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005420 * ipr_isr_eh - Interrupt service routine error handler
5421 * @ioa_cfg: ioa config struct
5422 * @msg: message to log
5423 *
5424 * Return value:
5425 * none
5426 **/
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005427static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg, u16 number)
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005428{
5429 ioa_cfg->errors_logged++;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005430 dev_err(&ioa_cfg->pdev->dev, "%s %d\n", msg, number);
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005431
5432 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5433 ioa_cfg->sdt_state = GET_DUMP;
5434
5435 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5436}
5437
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005438static int ipr_process_hrrq(struct ipr_hrr_queue *hrr_queue, int budget,
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005439 struct list_head *doneq)
5440{
5441 u32 ioasc;
5442 u16 cmd_index;
5443 struct ipr_cmnd *ipr_cmd;
5444 struct ipr_ioa_cfg *ioa_cfg = hrr_queue->ioa_cfg;
5445 int num_hrrq = 0;
5446
5447 /* If interrupts are disabled, ignore the interrupt */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005448 if (!hrr_queue->allow_interrupts)
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005449 return 0;
5450
5451 while ((be32_to_cpu(*hrr_queue->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5452 hrr_queue->toggle_bit) {
5453
5454 cmd_index = (be32_to_cpu(*hrr_queue->hrrq_curr) &
5455 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >>
5456 IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
5457
5458 if (unlikely(cmd_index > hrr_queue->max_cmd_id ||
5459 cmd_index < hrr_queue->min_cmd_id)) {
5460 ipr_isr_eh(ioa_cfg,
5461 "Invalid response handle from IOA: ",
5462 cmd_index);
5463 break;
5464 }
5465
5466 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
5467 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5468
5469 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
5470
5471 list_move_tail(&ipr_cmd->queue, doneq);
5472
5473 if (hrr_queue->hrrq_curr < hrr_queue->hrrq_end) {
5474 hrr_queue->hrrq_curr++;
5475 } else {
5476 hrr_queue->hrrq_curr = hrr_queue->hrrq_start;
5477 hrr_queue->toggle_bit ^= 1u;
5478 }
5479 num_hrrq++;
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005480 if (budget > 0 && num_hrrq >= budget)
5481 break;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005482 }
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005483
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005484 return num_hrrq;
5485}
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005486
5487static int ipr_iopoll(struct blk_iopoll *iop, int budget)
5488{
5489 struct ipr_ioa_cfg *ioa_cfg;
5490 struct ipr_hrr_queue *hrrq;
5491 struct ipr_cmnd *ipr_cmd, *temp;
5492 unsigned long hrrq_flags;
5493 int completed_ops;
5494 LIST_HEAD(doneq);
5495
5496 hrrq = container_of(iop, struct ipr_hrr_queue, iopoll);
5497 ioa_cfg = hrrq->ioa_cfg;
5498
5499 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5500 completed_ops = ipr_process_hrrq(hrrq, budget, &doneq);
5501
5502 if (completed_ops < budget)
5503 blk_iopoll_complete(iop);
5504 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5505
5506 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5507 list_del(&ipr_cmd->queue);
5508 del_timer(&ipr_cmd->timer);
5509 ipr_cmd->fast_done(ipr_cmd);
5510 }
5511
5512 return completed_ops;
5513}
5514
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005515/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516 * ipr_isr - Interrupt service routine
5517 * @irq: irq number
5518 * @devp: pointer to ioa config struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005519 *
5520 * Return value:
5521 * IRQ_NONE / IRQ_HANDLED
5522 **/
David Howells7d12e782006-10-05 14:55:46 +01005523static irqreturn_t ipr_isr(int irq, void *devp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005525 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
5526 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005527 unsigned long hrrq_flags = 0;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005528 u32 int_reg = 0;
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005529 int num_hrrq = 0;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005530 int irq_none = 0;
Brian King172cd6e2012-07-17 08:14:40 -05005531 struct ipr_cmnd *ipr_cmd, *temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532 irqreturn_t rc = IRQ_NONE;
Brian King172cd6e2012-07-17 08:14:40 -05005533 LIST_HEAD(doneq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005534
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005535 spin_lock_irqsave(hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005536 /* If interrupts are disabled, ignore the interrupt */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005537 if (!hrrq->allow_interrupts) {
5538 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005539 return IRQ_NONE;
5540 }
5541
Linus Torvalds1da177e2005-04-16 15:20:36 -07005542 while (1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005543 if (ipr_process_hrrq(hrrq, -1, &doneq)) {
5544 rc = IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005545
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005546 if (!ioa_cfg->clear_isr)
5547 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005548
Linus Torvalds1da177e2005-04-16 15:20:36 -07005549 /* Clear the PCI interrupt */
Wayne Boyera5442ba2011-05-17 09:18:53 -07005550 num_hrrq = 0;
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005551 do {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005552 writel(IPR_PCII_HRRQ_UPDATED,
5553 ioa_cfg->regs.clr_interrupt_reg32);
Wayne Boyer7dacb642011-04-12 10:29:02 -07005554 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005555 } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005556 num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005557
Wayne Boyer7dacb642011-04-12 10:29:02 -07005558 } else if (rc == IRQ_NONE && irq_none == 0) {
5559 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5560 irq_none++;
Wayne Boyera5442ba2011-05-17 09:18:53 -07005561 } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
5562 int_reg & IPR_PCII_HRRQ_UPDATED) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005563 ipr_isr_eh(ioa_cfg,
5564 "Error clearing HRRQ: ", num_hrrq);
Brian King172cd6e2012-07-17 08:14:40 -05005565 rc = IRQ_HANDLED;
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005566 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567 } else
5568 break;
5569 }
5570
5571 if (unlikely(rc == IRQ_NONE))
Wayne Boyer634651f2010-08-27 14:45:07 -07005572 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005573
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005574 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King172cd6e2012-07-17 08:14:40 -05005575 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5576 list_del(&ipr_cmd->queue);
5577 del_timer(&ipr_cmd->timer);
5578 ipr_cmd->fast_done(ipr_cmd);
5579 }
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005580 return rc;
5581}
Brian King172cd6e2012-07-17 08:14:40 -05005582
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005583/**
5584 * ipr_isr_mhrrq - Interrupt service routine
5585 * @irq: irq number
5586 * @devp: pointer to ioa config struct
5587 *
5588 * Return value:
5589 * IRQ_NONE / IRQ_HANDLED
5590 **/
5591static irqreturn_t ipr_isr_mhrrq(int irq, void *devp)
5592{
5593 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005594 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005595 unsigned long hrrq_flags = 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005596 struct ipr_cmnd *ipr_cmd, *temp;
5597 irqreturn_t rc = IRQ_NONE;
5598 LIST_HEAD(doneq);
5599
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005600 spin_lock_irqsave(hrrq->lock, hrrq_flags);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005601
5602 /* If interrupts are disabled, ignore the interrupt */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005603 if (!hrrq->allow_interrupts) {
5604 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005605 return IRQ_NONE;
5606 }
5607
Jens Axboe89f8b332014-03-13 09:38:42 -06005608 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005609 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5610 hrrq->toggle_bit) {
5611 if (!blk_iopoll_sched_prep(&hrrq->iopoll))
5612 blk_iopoll_sched(&hrrq->iopoll);
5613 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5614 return IRQ_HANDLED;
5615 }
5616 } else {
5617 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5618 hrrq->toggle_bit)
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005619
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005620 if (ipr_process_hrrq(hrrq, -1, &doneq))
5621 rc = IRQ_HANDLED;
5622 }
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005623
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005624 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005625
5626 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5627 list_del(&ipr_cmd->queue);
5628 del_timer(&ipr_cmd->timer);
5629 ipr_cmd->fast_done(ipr_cmd);
5630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005631 return rc;
5632}
5633
5634/**
Wayne Boyera32c0552010-02-19 13:23:36 -08005635 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07005636 * @ioa_cfg: ioa config struct
5637 * @ipr_cmd: ipr command struct
5638 *
5639 * Return value:
5640 * 0 on success / -1 on failure
5641 **/
Wayne Boyera32c0552010-02-19 13:23:36 -08005642static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
5643 struct ipr_cmnd *ipr_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005644{
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005645 int i, nseg;
5646 struct scatterlist *sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005647 u32 length;
5648 u32 ioadl_flags = 0;
5649 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5650 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08005651 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005652
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005653 length = scsi_bufflen(scsi_cmd);
5654 if (!length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005655 return 0;
5656
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005657 nseg = scsi_dma_map(scsi_cmd);
5658 if (nseg < 0) {
Anton Blanchard51f52a42011-05-09 10:07:40 +10005659 if (printk_ratelimit())
Anton Blanchardd73341b2014-10-30 17:27:08 -05005660 dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005661 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005662 }
5663
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005664 ipr_cmd->dma_use_sg = nseg;
5665
Wayne Boyer438b0332010-05-10 09:13:00 -07005666 ioarcb->data_transfer_length = cpu_to_be32(length);
Wayne Boyerb8803b12010-05-14 08:55:13 -07005667 ioarcb->ioadl_len =
5668 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
Wayne Boyer438b0332010-05-10 09:13:00 -07005669
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005670 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5671 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5672 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08005673 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
5674 ioadl_flags = IPR_IOADL_FLAGS_READ;
5675
5676 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5677 ioadl64[i].flags = cpu_to_be32(ioadl_flags);
5678 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
5679 ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
5680 }
5681
5682 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5683 return 0;
5684}
5685
5686/**
5687 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5688 * @ioa_cfg: ioa config struct
5689 * @ipr_cmd: ipr command struct
5690 *
5691 * Return value:
5692 * 0 on success / -1 on failure
5693 **/
5694static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5695 struct ipr_cmnd *ipr_cmd)
5696{
5697 int i, nseg;
5698 struct scatterlist *sg;
5699 u32 length;
5700 u32 ioadl_flags = 0;
5701 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5702 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5703 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
5704
5705 length = scsi_bufflen(scsi_cmd);
5706 if (!length)
5707 return 0;
5708
5709 nseg = scsi_dma_map(scsi_cmd);
5710 if (nseg < 0) {
Anton Blanchardd73341b2014-10-30 17:27:08 -05005711 dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
Wayne Boyera32c0552010-02-19 13:23:36 -08005712 return -1;
5713 }
5714
5715 ipr_cmd->dma_use_sg = nseg;
5716
5717 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5718 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5719 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5720 ioarcb->data_transfer_length = cpu_to_be32(length);
5721 ioarcb->ioadl_len =
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005722 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5723 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
5724 ioadl_flags = IPR_IOADL_FLAGS_READ;
5725 ioarcb->read_data_transfer_length = cpu_to_be32(length);
5726 ioarcb->read_ioadl_len =
5727 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5728 }
5729
Wayne Boyera32c0552010-02-19 13:23:36 -08005730 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
5731 ioadl = ioarcb->u.add_data.u.ioadl;
5732 ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
5733 offsetof(struct ipr_ioarcb, u.add_data));
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005734 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5735 }
5736
5737 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5738 ioadl[i].flags_and_data_len =
5739 cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5740 ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
5741 }
5742
5743 ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5744 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745}
5746
5747/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005748 * ipr_erp_done - Process completion of ERP for a device
5749 * @ipr_cmd: ipr command struct
5750 *
5751 * This function copies the sense buffer into the scsi_cmd
5752 * struct and pushes the scsi_done function.
5753 *
5754 * Return value:
5755 * nothing
5756 **/
5757static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
5758{
5759 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5760 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005761 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005762
5763 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5764 scsi_cmd->result |= (DID_ERROR << 16);
Brian Kingfb3ed3c2006-03-29 09:37:37 -06005765 scmd_printk(KERN_ERR, scsi_cmd,
5766 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767 } else {
5768 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
5769 SCSI_SENSE_BUFFERSIZE);
5770 }
5771
5772 if (res) {
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005773 if (!ipr_is_naca_model(res))
5774 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005775 res->in_erp = 0;
5776 }
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005777 scsi_dma_unmap(ipr_cmd->scsi_cmd);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005778 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005779 scsi_cmd->scsi_done(scsi_cmd);
5780}
5781
5782/**
5783 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5784 * @ipr_cmd: ipr command struct
5785 *
5786 * Return value:
5787 * none
5788 **/
5789static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
5790{
Brian King51b1c7e2007-03-29 12:43:50 -05005791 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005792 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
Wayne Boyera32c0552010-02-19 13:23:36 -08005793 dma_addr_t dma_addr = ipr_cmd->dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005794
5795 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
Wayne Boyera32c0552010-02-19 13:23:36 -08005796 ioarcb->data_transfer_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005797 ioarcb->read_data_transfer_length = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -08005798 ioarcb->ioadl_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799 ioarcb->read_ioadl_len = 0;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005800 ioasa->hdr.ioasc = 0;
5801 ioasa->hdr.residual_data_len = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -08005802
5803 if (ipr_cmd->ioa_cfg->sis64)
5804 ioarcb->u.sis64_addr_data.data_ioadl_addr =
5805 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
5806 else {
5807 ioarcb->write_ioadl_addr =
5808 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
5809 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5810 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005811}
5812
5813/**
5814 * ipr_erp_request_sense - Send request sense to a device
5815 * @ipr_cmd: ipr command struct
5816 *
5817 * This function sends a request sense to a device as a result
5818 * of a check condition.
5819 *
5820 * Return value:
5821 * nothing
5822 **/
5823static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
5824{
5825 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005826 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005827
5828 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5829 ipr_erp_done(ipr_cmd);
5830 return;
5831 }
5832
5833 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5834
5835 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
5836 cmd_pkt->cdb[0] = REQUEST_SENSE;
5837 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
5838 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
5839 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5840 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
5841
Wayne Boyera32c0552010-02-19 13:23:36 -08005842 ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
5843 SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844
5845 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
5846 IPR_REQUEST_SENSE_TIMEOUT * 2);
5847}
5848
5849/**
5850 * ipr_erp_cancel_all - Send cancel all to a device
5851 * @ipr_cmd: ipr command struct
5852 *
5853 * This function sends a cancel all to a device to clear the
5854 * queue. If we are running TCQ on the device, QERR is set to 1,
5855 * which means all outstanding ops have been dropped on the floor.
5856 * Cancel all will return them to us.
5857 *
5858 * Return value:
5859 * nothing
5860 **/
5861static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
5862{
5863 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5864 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5865 struct ipr_cmd_pkt *cmd_pkt;
5866
5867 res->in_erp = 1;
5868
5869 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5870
Christoph Hellwig17ea0122014-11-24 15:36:20 +01005871 if (!scsi_cmd->device->simple_tags) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005872 ipr_erp_request_sense(ipr_cmd);
5873 return;
5874 }
5875
5876 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5877 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5878 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5879
5880 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
5881 IPR_CANCEL_ALL_TIMEOUT);
5882}
5883
5884/**
5885 * ipr_dump_ioasa - Dump contents of IOASA
5886 * @ioa_cfg: ioa config struct
5887 * @ipr_cmd: ipr command struct
Brian Kingfe964d02006-03-29 09:37:29 -06005888 * @res: resource entry struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889 *
5890 * This function is invoked by the interrupt handler when ops
5891 * fail. It will log the IOASA if appropriate. Only called
5892 * for GPDD ops.
5893 *
5894 * Return value:
5895 * none
5896 **/
5897static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
Brian Kingfe964d02006-03-29 09:37:29 -06005898 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005899{
5900 int i;
5901 u16 data_len;
Brian Kingb0692dd2007-03-29 12:43:09 -05005902 u32 ioasc, fd_ioasc;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005903 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005904 __be32 *ioasa_data = (__be32 *)ioasa;
5905 int error_index;
5906
Wayne Boyer96d21f02010-05-10 09:13:27 -07005907 ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
5908 fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909
5910 if (0 == ioasc)
5911 return;
5912
5913 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
5914 return;
5915
Brian Kingb0692dd2007-03-29 12:43:09 -05005916 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
5917 error_index = ipr_get_error(fd_ioasc);
5918 else
5919 error_index = ipr_get_error(ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005920
5921 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
5922 /* Don't log an error if the IOA already logged one */
Wayne Boyer96d21f02010-05-10 09:13:27 -07005923 if (ioasa->hdr.ilid != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924 return;
5925
Brian Kingcc9bd5d2007-03-29 12:43:01 -05005926 if (!ipr_is_gscsi(res))
5927 return;
5928
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929 if (ipr_error_table[error_index].log_ioasa == 0)
5930 return;
5931 }
5932
Brian Kingfe964d02006-03-29 09:37:29 -06005933 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005934
Wayne Boyer96d21f02010-05-10 09:13:27 -07005935 data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
5936 if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
5937 data_len = sizeof(struct ipr_ioasa64);
5938 else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005939 data_len = sizeof(struct ipr_ioasa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940
5941 ipr_err("IOASA Dump:\n");
5942
5943 for (i = 0; i < data_len / 4; i += 4) {
5944 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
5945 be32_to_cpu(ioasa_data[i]),
5946 be32_to_cpu(ioasa_data[i+1]),
5947 be32_to_cpu(ioasa_data[i+2]),
5948 be32_to_cpu(ioasa_data[i+3]));
5949 }
5950}
5951
5952/**
5953 * ipr_gen_sense - Generate SCSI sense data from an IOASA
5954 * @ioasa: IOASA
5955 * @sense_buf: sense data buffer
5956 *
5957 * Return value:
5958 * none
5959 **/
5960static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
5961{
5962 u32 failing_lba;
5963 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
5964 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005965 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5966 u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967
5968 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
5969
5970 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
5971 return;
5972
5973 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
5974
5975 if (ipr_is_vset_device(res) &&
5976 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
5977 ioasa->u.vset.failing_lba_hi != 0) {
5978 sense_buf[0] = 0x72;
5979 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
5980 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
5981 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
5982
5983 sense_buf[7] = 12;
5984 sense_buf[8] = 0;
5985 sense_buf[9] = 0x0A;
5986 sense_buf[10] = 0x80;
5987
5988 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
5989
5990 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
5991 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
5992 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
5993 sense_buf[15] = failing_lba & 0x000000ff;
5994
5995 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5996
5997 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
5998 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
5999 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
6000 sense_buf[19] = failing_lba & 0x000000ff;
6001 } else {
6002 sense_buf[0] = 0x70;
6003 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
6004 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
6005 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
6006
6007 /* Illegal request */
6008 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
Wayne Boyer96d21f02010-05-10 09:13:27 -07006009 (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010 sense_buf[7] = 10; /* additional length */
6011
6012 /* IOARCB was in error */
6013 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
6014 sense_buf[15] = 0xC0;
6015 else /* Parameter data was invalid */
6016 sense_buf[15] = 0x80;
6017
6018 sense_buf[16] =
6019 ((IPR_FIELD_POINTER_MASK &
Wayne Boyer96d21f02010-05-10 09:13:27 -07006020 be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021 sense_buf[17] =
6022 (IPR_FIELD_POINTER_MASK &
Wayne Boyer96d21f02010-05-10 09:13:27 -07006023 be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 } else {
6025 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
6026 if (ipr_is_vset_device(res))
6027 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
6028 else
6029 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
6030
6031 sense_buf[0] |= 0x80; /* Or in the Valid bit */
6032 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
6033 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
6034 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
6035 sense_buf[6] = failing_lba & 0x000000ff;
6036 }
6037
6038 sense_buf[7] = 6; /* additional length */
6039 }
6040 }
6041}
6042
6043/**
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006044 * ipr_get_autosense - Copy autosense data to sense buffer
6045 * @ipr_cmd: ipr command struct
6046 *
6047 * This function copies the autosense buffer to the buffer
6048 * in the scsi_cmd, if there is autosense available.
6049 *
6050 * Return value:
6051 * 1 if autosense was available / 0 if not
6052 **/
6053static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
6054{
Wayne Boyer96d21f02010-05-10 09:13:27 -07006055 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
6056 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006057
Wayne Boyer96d21f02010-05-10 09:13:27 -07006058 if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006059 return 0;
6060
Wayne Boyer96d21f02010-05-10 09:13:27 -07006061 if (ipr_cmd->ioa_cfg->sis64)
6062 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
6063 min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
6064 SCSI_SENSE_BUFFERSIZE));
6065 else
6066 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
6067 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
6068 SCSI_SENSE_BUFFERSIZE));
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006069 return 1;
6070}
6071
6072/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073 * ipr_erp_start - Process an error response for a SCSI op
6074 * @ioa_cfg: ioa config struct
6075 * @ipr_cmd: ipr command struct
6076 *
6077 * This function determines whether or not to initiate ERP
6078 * on the affected device.
6079 *
6080 * Return value:
6081 * nothing
6082 **/
6083static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
6084 struct ipr_cmnd *ipr_cmd)
6085{
6086 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
6087 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006088 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian King8a048992007-04-26 16:00:10 -05006089 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090
6091 if (!res) {
6092 ipr_scsi_eh_done(ipr_cmd);
6093 return;
6094 }
6095
Brian King8a048992007-04-26 16:00:10 -05006096 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097 ipr_gen_sense(ipr_cmd);
6098
Brian Kingcc9bd5d2007-03-29 12:43:01 -05006099 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6100
Brian King8a048992007-04-26 16:00:10 -05006101 switch (masked_ioasc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006103 if (ipr_is_naca_model(res))
6104 scsi_cmd->result |= (DID_ABORT << 16);
6105 else
6106 scsi_cmd->result |= (DID_IMM_RETRY << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107 break;
6108 case IPR_IOASC_IR_RESOURCE_HANDLE:
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06006109 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110 scsi_cmd->result |= (DID_NO_CONNECT << 16);
6111 break;
6112 case IPR_IOASC_HW_SEL_TIMEOUT:
6113 scsi_cmd->result |= (DID_NO_CONNECT << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006114 if (!ipr_is_naca_model(res))
6115 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116 break;
6117 case IPR_IOASC_SYNC_REQUIRED:
6118 if (!res->in_erp)
6119 res->needs_sync_complete = 1;
6120 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6121 break;
6122 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06006123 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006124 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
6125 break;
6126 case IPR_IOASC_BUS_WAS_RESET:
6127 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
6128 /*
6129 * Report the bus reset and ask for a retry. The device
6130 * will give CC/UA the next command.
6131 */
6132 if (!res->resetting_device)
6133 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
6134 scsi_cmd->result |= (DID_ERROR << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006135 if (!ipr_is_naca_model(res))
6136 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 break;
6138 case IPR_IOASC_HW_DEV_BUS_STATUS:
6139 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
6140 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006141 if (!ipr_get_autosense(ipr_cmd)) {
6142 if (!ipr_is_naca_model(res)) {
6143 ipr_erp_cancel_all(ipr_cmd);
6144 return;
6145 }
6146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147 }
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006148 if (!ipr_is_naca_model(res))
6149 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150 break;
6151 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
6152 break;
6153 default:
Brian King5b7304f2006-08-02 14:57:51 -05006154 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
6155 scsi_cmd->result |= (DID_ERROR << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006156 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157 res->needs_sync_complete = 1;
6158 break;
6159 }
6160
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09006161 scsi_dma_unmap(ipr_cmd->scsi_cmd);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006162 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163 scsi_cmd->scsi_done(scsi_cmd);
6164}
6165
6166/**
6167 * ipr_scsi_done - mid-layer done function
6168 * @ipr_cmd: ipr command struct
6169 *
6170 * This function is invoked by the interrupt handler for
6171 * ops generated by the SCSI mid-layer
6172 *
6173 * Return value:
6174 * none
6175 **/
6176static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
6177{
6178 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6179 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006180 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006181 unsigned long hrrq_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182
Wayne Boyer96d21f02010-05-10 09:13:27 -07006183 scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184
6185 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
Brian King172cd6e2012-07-17 08:14:40 -05006186 scsi_dma_unmap(scsi_cmd);
6187
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006188 spin_lock_irqsave(ipr_cmd->hrrq->lock, hrrq_flags);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006189 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190 scsi_cmd->scsi_done(scsi_cmd);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006191 spin_unlock_irqrestore(ipr_cmd->hrrq->lock, hrrq_flags);
Brian King172cd6e2012-07-17 08:14:40 -05006192 } else {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006193 spin_lock_irqsave(ipr_cmd->hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194 ipr_erp_start(ioa_cfg, ipr_cmd);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006195 spin_unlock_irqrestore(ipr_cmd->hrrq->lock, hrrq_flags);
Brian King172cd6e2012-07-17 08:14:40 -05006196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197}
6198
6199/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200 * ipr_queuecommand - Queue a mid-layer request
Brian King00bfef22012-07-17 08:13:52 -05006201 * @shost: scsi host struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202 * @scsi_cmd: scsi command struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 *
6204 * This function queues a request generated by the mid-layer.
6205 *
6206 * Return value:
6207 * 0 on success
6208 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
6209 * SCSI_MLQUEUE_HOST_BUSY if host is busy
6210 **/
Brian King00bfef22012-07-17 08:13:52 -05006211static int ipr_queuecommand(struct Scsi_Host *shost,
6212 struct scsi_cmnd *scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006213{
6214 struct ipr_ioa_cfg *ioa_cfg;
6215 struct ipr_resource_entry *res;
6216 struct ipr_ioarcb *ioarcb;
6217 struct ipr_cmnd *ipr_cmd;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006218 unsigned long hrrq_flags, lock_flags;
Dan Carpenterd12f1572012-07-30 11:18:22 +03006219 int rc;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006220 struct ipr_hrr_queue *hrrq;
6221 int hrrq_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006222
Brian King00bfef22012-07-17 08:13:52 -05006223 ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
6224
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225 scsi_cmd->result = (DID_OK << 16);
Brian King00bfef22012-07-17 08:13:52 -05006226 res = scsi_cmd->device->hostdata;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006227
6228 if (ipr_is_gata(res) && res->sata_port) {
6229 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6230 rc = ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
6231 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6232 return rc;
6233 }
6234
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006235 hrrq_id = ipr_get_hrrq_index(ioa_cfg);
6236 hrrq = &ioa_cfg->hrrq[hrrq_id];
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006238 spin_lock_irqsave(hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 /*
6240 * We are currently blocking all devices due to a host reset
6241 * We have told the host to stop giving us new requests, but
6242 * ERP ops don't count. FIXME
6243 */
Brian Kingbfae7822013-01-30 23:45:08 -06006244 if (unlikely(!hrrq->allow_cmds && !hrrq->ioa_is_dead && !hrrq->removing_ioa)) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006245 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246 return SCSI_MLQUEUE_HOST_BUSY;
Brian King00bfef22012-07-17 08:13:52 -05006247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248
6249 /*
6250 * FIXME - Create scsi_set_host_offline interface
6251 * and the ioa_is_dead check can be removed
6252 */
Brian Kingbfae7822013-01-30 23:45:08 -06006253 if (unlikely(hrrq->ioa_is_dead || hrrq->removing_ioa || !res)) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006254 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006255 goto err_nodev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006256 }
6257
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006258 ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
6259 if (ipr_cmd == NULL) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006260 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006261 return SCSI_MLQUEUE_HOST_BUSY;
6262 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006263 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006264
Brian King172cd6e2012-07-17 08:14:40 -05006265 ipr_init_ipr_cmnd(ipr_cmd, ipr_scsi_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266 ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267
6268 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
6269 ipr_cmd->scsi_cmd = scsi_cmd;
Brian King172cd6e2012-07-17 08:14:40 -05006270 ipr_cmd->done = ipr_scsi_eh_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271
6272 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
6273 if (scsi_cmd->underflow == 0)
6274 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
6275
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
Wendy Xiong0b1f8d42014-01-21 12:16:39 -06006277 if (ipr_is_gscsi(res) && res->reset_occurred) {
6278 res->reset_occurred = 0;
Wayne Boyerab6c10b2011-03-31 09:56:10 -07006279 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
Wendy Xiong0b1f8d42014-01-21 12:16:39 -06006280 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
Christoph Hellwig50668632014-10-30 14:30:06 +01006282 if (scsi_cmd->flags & SCMD_TAGGED)
6283 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_SIMPLE_TASK;
6284 else
6285 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_UNTAGGED_TASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286 }
6287
6288 if (scsi_cmd->cmnd[0] >= 0xC0 &&
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006289 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292
Dan Carpenterd12f1572012-07-30 11:18:22 +03006293 if (ioa_cfg->sis64)
6294 rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
6295 else
6296 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006298 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6299 if (unlikely(rc || (!hrrq->allow_cmds && !hrrq->ioa_is_dead))) {
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006300 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006301 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006302 if (!rc)
6303 scsi_dma_unmap(scsi_cmd);
Brian Kinga5fb4072012-03-14 21:20:09 -05006304 return SCSI_MLQUEUE_HOST_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305 }
6306
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006307 if (unlikely(hrrq->ioa_is_dead)) {
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006308 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006309 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006310 scsi_dma_unmap(scsi_cmd);
6311 goto err_nodev;
6312 }
6313
6314 ioarcb->res_handle = res->res_handle;
6315 if (res->needs_sync_complete) {
6316 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
6317 res->needs_sync_complete = 0;
6318 }
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006319 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_pending_q);
Brian King00bfef22012-07-17 08:13:52 -05006320 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
Brian Kinga5fb4072012-03-14 21:20:09 -05006321 ipr_send_command(ipr_cmd);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006322 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006323 return 0;
6324
6325err_nodev:
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006326 spin_lock_irqsave(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006327 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
6328 scsi_cmd->result = (DID_NO_CONNECT << 16);
6329 scsi_cmd->scsi_done(scsi_cmd);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006330 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331 return 0;
6332}
6333
6334/**
Brian King35a39692006-09-25 12:39:20 -05006335 * ipr_ioctl - IOCTL handler
6336 * @sdev: scsi device struct
6337 * @cmd: IOCTL cmd
6338 * @arg: IOCTL arg
6339 *
6340 * Return value:
6341 * 0 on success / other on failure
6342 **/
Adrian Bunkbd705f22006-11-21 10:28:48 -06006343static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
Brian King35a39692006-09-25 12:39:20 -05006344{
6345 struct ipr_resource_entry *res;
6346
6347 res = (struct ipr_resource_entry *)sdev->hostdata;
Brian King0ce3a7e2008-07-11 13:37:50 -05006348 if (res && ipr_is_gata(res)) {
6349 if (cmd == HDIO_GET_IDENTITY)
6350 return -ENOTTY;
Jeff Garzik94be9a52009-01-16 10:17:09 -05006351 return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
Brian King0ce3a7e2008-07-11 13:37:50 -05006352 }
Brian King35a39692006-09-25 12:39:20 -05006353
6354 return -EINVAL;
6355}
6356
6357/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 * ipr_info - Get information about the card/driver
6359 * @scsi_host: scsi host struct
6360 *
6361 * Return value:
6362 * pointer to buffer with description string
6363 **/
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03006364static const char *ipr_ioa_info(struct Scsi_Host *host)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365{
6366 static char buffer[512];
6367 struct ipr_ioa_cfg *ioa_cfg;
6368 unsigned long lock_flags = 0;
6369
6370 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
6371
6372 spin_lock_irqsave(host->host_lock, lock_flags);
6373 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
6374 spin_unlock_irqrestore(host->host_lock, lock_flags);
6375
6376 return buffer;
6377}
6378
6379static struct scsi_host_template driver_template = {
6380 .module = THIS_MODULE,
6381 .name = "IPR",
6382 .info = ipr_ioa_info,
Brian King35a39692006-09-25 12:39:20 -05006383 .ioctl = ipr_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384 .queuecommand = ipr_queuecommand,
6385 .eh_abort_handler = ipr_eh_abort,
6386 .eh_device_reset_handler = ipr_eh_dev_reset,
6387 .eh_host_reset_handler = ipr_eh_host_reset,
6388 .slave_alloc = ipr_slave_alloc,
6389 .slave_configure = ipr_slave_configure,
6390 .slave_destroy = ipr_slave_destroy,
Brian Kingf688f962014-12-02 12:47:37 -06006391 .scan_finished = ipr_scan_finished,
Brian King35a39692006-09-25 12:39:20 -05006392 .target_alloc = ipr_target_alloc,
6393 .target_destroy = ipr_target_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394 .change_queue_depth = ipr_change_queue_depth,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006395 .bios_param = ipr_biosparam,
6396 .can_queue = IPR_MAX_COMMANDS,
6397 .this_id = -1,
6398 .sg_tablesize = IPR_MAX_SGLIST,
6399 .max_sectors = IPR_IOA_MAX_SECTORS,
6400 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
6401 .use_clustering = ENABLE_CLUSTERING,
6402 .shost_attrs = ipr_ioa_attrs,
6403 .sdev_attrs = ipr_dev_attrs,
Martin K. Petersen54b2b502013-10-23 06:25:40 -04006404 .proc_name = IPR_NAME,
6405 .no_write_same = 1,
Christoph Hellwig2ecb2042014-11-03 14:09:02 +01006406 .use_blk_tags = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407};
6408
Brian King35a39692006-09-25 12:39:20 -05006409/**
6410 * ipr_ata_phy_reset - libata phy_reset handler
6411 * @ap: ata port to reset
6412 *
6413 **/
6414static void ipr_ata_phy_reset(struct ata_port *ap)
6415{
6416 unsigned long flags;
6417 struct ipr_sata_port *sata_port = ap->private_data;
6418 struct ipr_resource_entry *res = sata_port->res;
6419 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6420 int rc;
6421
6422 ENTER;
6423 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03006424 while (ioa_cfg->in_reset_reload) {
Brian King35a39692006-09-25 12:39:20 -05006425 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6426 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6427 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6428 }
6429
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006430 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
Brian King35a39692006-09-25 12:39:20 -05006431 goto out_unlock;
6432
6433 rc = ipr_device_reset(ioa_cfg, res);
6434
6435 if (rc) {
Tejun Heo3e4ec342010-05-10 21:41:30 +02006436 ap->link.device[0].class = ATA_DEV_NONE;
Brian King35a39692006-09-25 12:39:20 -05006437 goto out_unlock;
6438 }
6439
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006440 ap->link.device[0].class = res->ata_class;
6441 if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
Tejun Heo3e4ec342010-05-10 21:41:30 +02006442 ap->link.device[0].class = ATA_DEV_NONE;
Brian King35a39692006-09-25 12:39:20 -05006443
6444out_unlock:
6445 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6446 LEAVE;
6447}
6448
6449/**
6450 * ipr_ata_post_internal - Cleanup after an internal command
6451 * @qc: ATA queued command
6452 *
6453 * Return value:
6454 * none
6455 **/
6456static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
6457{
6458 struct ipr_sata_port *sata_port = qc->ap->private_data;
6459 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6460 struct ipr_cmnd *ipr_cmd;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006461 struct ipr_hrr_queue *hrrq;
Brian King35a39692006-09-25 12:39:20 -05006462 unsigned long flags;
6463
6464 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03006465 while (ioa_cfg->in_reset_reload) {
Brian King73d98ff2006-11-21 10:27:58 -06006466 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6467 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6468 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6469 }
6470
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006471 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006472 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006473 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
6474 if (ipr_cmd->qc == qc) {
6475 ipr_device_reset(ioa_cfg, sata_port->res);
6476 break;
6477 }
Brian King35a39692006-09-25 12:39:20 -05006478 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006479 spin_unlock(&hrrq->_lock);
Brian King35a39692006-09-25 12:39:20 -05006480 }
6481 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6482}
6483
6484/**
Brian King35a39692006-09-25 12:39:20 -05006485 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
6486 * @regs: destination
6487 * @tf: source ATA taskfile
6488 *
6489 * Return value:
6490 * none
6491 **/
6492static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
6493 struct ata_taskfile *tf)
6494{
6495 regs->feature = tf->feature;
6496 regs->nsect = tf->nsect;
6497 regs->lbal = tf->lbal;
6498 regs->lbam = tf->lbam;
6499 regs->lbah = tf->lbah;
6500 regs->device = tf->device;
6501 regs->command = tf->command;
6502 regs->hob_feature = tf->hob_feature;
6503 regs->hob_nsect = tf->hob_nsect;
6504 regs->hob_lbal = tf->hob_lbal;
6505 regs->hob_lbam = tf->hob_lbam;
6506 regs->hob_lbah = tf->hob_lbah;
6507 regs->ctl = tf->ctl;
6508}
6509
6510/**
6511 * ipr_sata_done - done function for SATA commands
6512 * @ipr_cmd: ipr command struct
6513 *
6514 * This function is invoked by the interrupt handler for
6515 * ops generated by the SCSI mid-layer to SATA devices
6516 *
6517 * Return value:
6518 * none
6519 **/
6520static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
6521{
6522 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6523 struct ata_queued_cmd *qc = ipr_cmd->qc;
6524 struct ipr_sata_port *sata_port = qc->ap->private_data;
6525 struct ipr_resource_entry *res = sata_port->res;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006526 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian King35a39692006-09-25 12:39:20 -05006527
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006528 spin_lock(&ipr_cmd->hrrq->_lock);
Wayne Boyer96d21f02010-05-10 09:13:27 -07006529 if (ipr_cmd->ioa_cfg->sis64)
6530 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
6531 sizeof(struct ipr_ioasa_gata));
6532 else
6533 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
6534 sizeof(struct ipr_ioasa_gata));
Brian King35a39692006-09-25 12:39:20 -05006535 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6536
Wayne Boyer96d21f02010-05-10 09:13:27 -07006537 if (be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006538 scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
Brian King35a39692006-09-25 12:39:20 -05006539
6540 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
Wayne Boyer96d21f02010-05-10 09:13:27 -07006541 qc->err_mask |= __ac_err_mask(sata_port->ioasa.status);
Brian King35a39692006-09-25 12:39:20 -05006542 else
Wayne Boyer96d21f02010-05-10 09:13:27 -07006543 qc->err_mask |= ac_err_mask(sata_port->ioasa.status);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006544 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006545 spin_unlock(&ipr_cmd->hrrq->_lock);
Brian King35a39692006-09-25 12:39:20 -05006546 ata_qc_complete(qc);
6547}
6548
6549/**
Wayne Boyera32c0552010-02-19 13:23:36 -08006550 * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
6551 * @ipr_cmd: ipr command struct
6552 * @qc: ATA queued command
6553 *
6554 **/
6555static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
6556 struct ata_queued_cmd *qc)
6557{
6558 u32 ioadl_flags = 0;
6559 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
wenxiong@linux.vnet.ibm.com1ac7c262013-04-18 21:32:48 -05006560 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ata_ioadl.ioadl64;
Wayne Boyera32c0552010-02-19 13:23:36 -08006561 struct ipr_ioadl64_desc *last_ioadl64 = NULL;
6562 int len = qc->nbytes;
6563 struct scatterlist *sg;
6564 unsigned int si;
6565 dma_addr_t dma_addr = ipr_cmd->dma_addr;
6566
6567 if (len == 0)
6568 return;
6569
6570 if (qc->dma_dir == DMA_TO_DEVICE) {
6571 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6572 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6573 } else if (qc->dma_dir == DMA_FROM_DEVICE)
6574 ioadl_flags = IPR_IOADL_FLAGS_READ;
6575
6576 ioarcb->data_transfer_length = cpu_to_be32(len);
6577 ioarcb->ioadl_len =
6578 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
6579 ioarcb->u.sis64_addr_data.data_ioadl_addr =
wenxiong@linux.vnet.ibm.com1ac7c262013-04-18 21:32:48 -05006580 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl.ioadl64));
Wayne Boyera32c0552010-02-19 13:23:36 -08006581
6582 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6583 ioadl64->flags = cpu_to_be32(ioadl_flags);
6584 ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
6585 ioadl64->address = cpu_to_be64(sg_dma_address(sg));
6586
6587 last_ioadl64 = ioadl64;
6588 ioadl64++;
6589 }
6590
6591 if (likely(last_ioadl64))
6592 last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6593}
6594
6595/**
Brian King35a39692006-09-25 12:39:20 -05006596 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
6597 * @ipr_cmd: ipr command struct
6598 * @qc: ATA queued command
6599 *
6600 **/
6601static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
6602 struct ata_queued_cmd *qc)
6603{
6604 u32 ioadl_flags = 0;
6605 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08006606 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006607 struct ipr_ioadl_desc *last_ioadl = NULL;
James Bottomleydde20202008-02-19 11:36:56 +01006608 int len = qc->nbytes;
Brian King35a39692006-09-25 12:39:20 -05006609 struct scatterlist *sg;
Tejun Heoff2aeb12007-12-05 16:43:11 +09006610 unsigned int si;
Brian King35a39692006-09-25 12:39:20 -05006611
6612 if (len == 0)
6613 return;
6614
6615 if (qc->dma_dir == DMA_TO_DEVICE) {
6616 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6617 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08006618 ioarcb->data_transfer_length = cpu_to_be32(len);
6619 ioarcb->ioadl_len =
Brian King35a39692006-09-25 12:39:20 -05006620 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6621 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
6622 ioadl_flags = IPR_IOADL_FLAGS_READ;
6623 ioarcb->read_data_transfer_length = cpu_to_be32(len);
6624 ioarcb->read_ioadl_len =
6625 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6626 }
6627
Tejun Heoff2aeb12007-12-05 16:43:11 +09006628 for_each_sg(qc->sg, sg, qc->n_elem, si) {
Brian King35a39692006-09-25 12:39:20 -05006629 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
6630 ioadl->address = cpu_to_be32(sg_dma_address(sg));
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006631
6632 last_ioadl = ioadl;
6633 ioadl++;
Brian King35a39692006-09-25 12:39:20 -05006634 }
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006635
6636 if (likely(last_ioadl))
6637 last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
Brian King35a39692006-09-25 12:39:20 -05006638}
6639
6640/**
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006641 * ipr_qc_defer - Get a free ipr_cmd
6642 * @qc: queued command
6643 *
6644 * Return value:
6645 * 0 if success
6646 **/
6647static int ipr_qc_defer(struct ata_queued_cmd *qc)
6648{
6649 struct ata_port *ap = qc->ap;
6650 struct ipr_sata_port *sata_port = ap->private_data;
6651 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6652 struct ipr_cmnd *ipr_cmd;
6653 struct ipr_hrr_queue *hrrq;
6654 int hrrq_id;
6655
6656 hrrq_id = ipr_get_hrrq_index(ioa_cfg);
6657 hrrq = &ioa_cfg->hrrq[hrrq_id];
6658
6659 qc->lldd_task = NULL;
6660 spin_lock(&hrrq->_lock);
6661 if (unlikely(hrrq->ioa_is_dead)) {
6662 spin_unlock(&hrrq->_lock);
6663 return 0;
6664 }
6665
6666 if (unlikely(!hrrq->allow_cmds)) {
6667 spin_unlock(&hrrq->_lock);
6668 return ATA_DEFER_LINK;
6669 }
6670
6671 ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
6672 if (ipr_cmd == NULL) {
6673 spin_unlock(&hrrq->_lock);
6674 return ATA_DEFER_LINK;
6675 }
6676
6677 qc->lldd_task = ipr_cmd;
6678 spin_unlock(&hrrq->_lock);
6679 return 0;
6680}
6681
6682/**
Brian King35a39692006-09-25 12:39:20 -05006683 * ipr_qc_issue - Issue a SATA qc to a device
6684 * @qc: queued command
6685 *
6686 * Return value:
6687 * 0 if success
6688 **/
6689static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
6690{
6691 struct ata_port *ap = qc->ap;
6692 struct ipr_sata_port *sata_port = ap->private_data;
6693 struct ipr_resource_entry *res = sata_port->res;
6694 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6695 struct ipr_cmnd *ipr_cmd;
6696 struct ipr_ioarcb *ioarcb;
6697 struct ipr_ioarcb_ata_regs *regs;
6698
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006699 if (qc->lldd_task == NULL)
6700 ipr_qc_defer(qc);
6701
6702 ipr_cmd = qc->lldd_task;
6703 if (ipr_cmd == NULL)
Brian King0feeed82007-03-29 12:43:43 -05006704 return AC_ERR_SYSTEM;
Brian King35a39692006-09-25 12:39:20 -05006705
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006706 qc->lldd_task = NULL;
6707 spin_lock(&ipr_cmd->hrrq->_lock);
6708 if (unlikely(!ipr_cmd->hrrq->allow_cmds ||
6709 ipr_cmd->hrrq->ioa_is_dead)) {
6710 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6711 spin_unlock(&ipr_cmd->hrrq->_lock);
6712 return AC_ERR_SYSTEM;
6713 }
6714
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006715 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
Brian King35a39692006-09-25 12:39:20 -05006716 ioarcb = &ipr_cmd->ioarcb;
Brian King35a39692006-09-25 12:39:20 -05006717
Wayne Boyera32c0552010-02-19 13:23:36 -08006718 if (ioa_cfg->sis64) {
6719 regs = &ipr_cmd->i.ata_ioadl.regs;
6720 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
6721 } else
6722 regs = &ioarcb->u.add_data.u.regs;
6723
6724 memset(regs, 0, sizeof(*regs));
6725 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
Brian King35a39692006-09-25 12:39:20 -05006726
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006727 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Brian King35a39692006-09-25 12:39:20 -05006728 ipr_cmd->qc = qc;
6729 ipr_cmd->done = ipr_sata_done;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006730 ipr_cmd->ioarcb.res_handle = res->res_handle;
Brian King35a39692006-09-25 12:39:20 -05006731 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
6732 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6733 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
James Bottomleydde20202008-02-19 11:36:56 +01006734 ipr_cmd->dma_use_sg = qc->n_elem;
Brian King35a39692006-09-25 12:39:20 -05006735
Wayne Boyera32c0552010-02-19 13:23:36 -08006736 if (ioa_cfg->sis64)
6737 ipr_build_ata_ioadl64(ipr_cmd, qc);
6738 else
6739 ipr_build_ata_ioadl(ipr_cmd, qc);
6740
Brian King35a39692006-09-25 12:39:20 -05006741 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
6742 ipr_copy_sata_tf(regs, &qc->tf);
6743 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006744 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
Brian King35a39692006-09-25 12:39:20 -05006745
6746 switch (qc->tf.protocol) {
6747 case ATA_PROT_NODATA:
6748 case ATA_PROT_PIO:
6749 break;
6750
6751 case ATA_PROT_DMA:
6752 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6753 break;
6754
Tejun Heo0dc36882007-12-18 16:34:43 -05006755 case ATAPI_PROT_PIO:
6756 case ATAPI_PROT_NODATA:
Brian King35a39692006-09-25 12:39:20 -05006757 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6758 break;
6759
Tejun Heo0dc36882007-12-18 16:34:43 -05006760 case ATAPI_PROT_DMA:
Brian King35a39692006-09-25 12:39:20 -05006761 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6762 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6763 break;
6764
6765 default:
6766 WARN_ON(1);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006767 spin_unlock(&ipr_cmd->hrrq->_lock);
Brian King0feeed82007-03-29 12:43:43 -05006768 return AC_ERR_INVALID;
Brian King35a39692006-09-25 12:39:20 -05006769 }
6770
Wayne Boyera32c0552010-02-19 13:23:36 -08006771 ipr_send_command(ipr_cmd);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006772 spin_unlock(&ipr_cmd->hrrq->_lock);
Wayne Boyera32c0552010-02-19 13:23:36 -08006773
Brian King35a39692006-09-25 12:39:20 -05006774 return 0;
6775}
6776
6777/**
Tejun Heo4c9bf4e2008-04-07 22:47:20 +09006778 * ipr_qc_fill_rtf - Read result TF
6779 * @qc: ATA queued command
6780 *
6781 * Return value:
6782 * true
6783 **/
6784static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
6785{
6786 struct ipr_sata_port *sata_port = qc->ap->private_data;
6787 struct ipr_ioasa_gata *g = &sata_port->ioasa;
6788 struct ata_taskfile *tf = &qc->result_tf;
6789
6790 tf->feature = g->error;
6791 tf->nsect = g->nsect;
6792 tf->lbal = g->lbal;
6793 tf->lbam = g->lbam;
6794 tf->lbah = g->lbah;
6795 tf->device = g->device;
6796 tf->command = g->status;
6797 tf->hob_nsect = g->hob_nsect;
6798 tf->hob_lbal = g->hob_lbal;
6799 tf->hob_lbam = g->hob_lbam;
6800 tf->hob_lbah = g->hob_lbah;
Tejun Heo4c9bf4e2008-04-07 22:47:20 +09006801
6802 return true;
6803}
6804
Brian King35a39692006-09-25 12:39:20 -05006805static struct ata_port_operations ipr_sata_ops = {
Brian King35a39692006-09-25 12:39:20 -05006806 .phy_reset = ipr_ata_phy_reset,
Tejun Heoa1efdab2008-03-25 12:22:50 +09006807 .hardreset = ipr_sata_reset,
Brian King35a39692006-09-25 12:39:20 -05006808 .post_internal_cmd = ipr_ata_post_internal,
Brian King35a39692006-09-25 12:39:20 -05006809 .qc_prep = ata_noop_qc_prep,
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006810 .qc_defer = ipr_qc_defer,
Brian King35a39692006-09-25 12:39:20 -05006811 .qc_issue = ipr_qc_issue,
Tejun Heo4c9bf4e2008-04-07 22:47:20 +09006812 .qc_fill_rtf = ipr_qc_fill_rtf,
Brian King35a39692006-09-25 12:39:20 -05006813 .port_start = ata_sas_port_start,
6814 .port_stop = ata_sas_port_stop
6815};
6816
6817static struct ata_port_info sata_port_info = {
Shaohua Li5067c042015-03-12 10:32:18 -07006818 .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA |
6819 ATA_FLAG_SAS_HOST,
Sergei Shtylyov0f2e0332011-01-21 20:32:01 +03006820 .pio_mask = ATA_PIO4_ONLY,
6821 .mwdma_mask = ATA_MWDMA2,
6822 .udma_mask = ATA_UDMA6,
Brian King35a39692006-09-25 12:39:20 -05006823 .port_ops = &ipr_sata_ops
6824};
6825
Linus Torvalds1da177e2005-04-16 15:20:36 -07006826#ifdef CONFIG_PPC_PSERIES
6827static const u16 ipr_blocked_processors[] = {
Michael Ellermand3dbeef2012-08-19 21:44:01 +00006828 PVR_NORTHSTAR,
6829 PVR_PULSAR,
6830 PVR_POWER4,
6831 PVR_ICESTAR,
6832 PVR_SSTAR,
6833 PVR_POWER4p,
6834 PVR_630,
6835 PVR_630p
Linus Torvalds1da177e2005-04-16 15:20:36 -07006836};
6837
6838/**
6839 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
6840 * @ioa_cfg: ioa cfg struct
6841 *
6842 * Adapters that use Gemstone revision < 3.1 do not work reliably on
6843 * certain pSeries hardware. This function determines if the given
6844 * adapter is in one of these confgurations or not.
6845 *
6846 * Return value:
6847 * 1 if adapter is not supported / 0 if adapter is supported
6848 **/
6849static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
6850{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006851 int i;
6852
Auke Kok44c10132007-06-08 15:46:36 -07006853 if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03006854 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++) {
Michael Ellermand3dbeef2012-08-19 21:44:01 +00006855 if (pvr_version_is(ipr_blocked_processors[i]))
Auke Kok44c10132007-06-08 15:46:36 -07006856 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006857 }
6858 }
6859 return 0;
6860}
6861#else
6862#define ipr_invalid_adapter(ioa_cfg) 0
6863#endif
6864
6865/**
6866 * ipr_ioa_bringdown_done - IOA bring down completion.
6867 * @ipr_cmd: ipr command struct
6868 *
6869 * This function processes the completion of an adapter bring down.
6870 * It wakes any reset sleepers.
6871 *
6872 * Return value:
6873 * IPR_RC_JOB_RETURN
6874 **/
6875static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
6876{
6877 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
wenxiong@linux.vnet.ibm.com96b04db2013-04-17 09:34:06 -05006878 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006879
6880 ENTER;
Brian Kingbfae7822013-01-30 23:45:08 -06006881 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
6882 ipr_trace;
6883 spin_unlock_irq(ioa_cfg->host->host_lock);
6884 scsi_unblock_requests(ioa_cfg->host);
6885 spin_lock_irq(ioa_cfg->host->host_lock);
6886 }
6887
Linus Torvalds1da177e2005-04-16 15:20:36 -07006888 ioa_cfg->in_reset_reload = 0;
6889 ioa_cfg->reset_retries = 0;
wenxiong@linux.vnet.ibm.com96b04db2013-04-17 09:34:06 -05006890 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
6891 spin_lock(&ioa_cfg->hrrq[i]._lock);
6892 ioa_cfg->hrrq[i].ioa_is_dead = 1;
6893 spin_unlock(&ioa_cfg->hrrq[i]._lock);
6894 }
6895 wmb();
6896
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006897 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006898 wake_up_all(&ioa_cfg->reset_wait_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006899 LEAVE;
6900
6901 return IPR_RC_JOB_RETURN;
6902}
6903
6904/**
6905 * ipr_ioa_reset_done - IOA reset completion.
6906 * @ipr_cmd: ipr command struct
6907 *
6908 * This function processes the completion of an adapter reset.
6909 * It schedules any necessary mid-layer add/removes and
6910 * wakes any reset sleepers.
6911 *
6912 * Return value:
6913 * IPR_RC_JOB_RETURN
6914 **/
6915static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
6916{
6917 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6918 struct ipr_resource_entry *res;
6919 struct ipr_hostrcb *hostrcb, *temp;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006920 int i = 0, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006921
6922 ENTER;
6923 ioa_cfg->in_reset_reload = 0;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006924 for (j = 0; j < ioa_cfg->hrrq_num; j++) {
6925 spin_lock(&ioa_cfg->hrrq[j]._lock);
6926 ioa_cfg->hrrq[j].allow_cmds = 1;
6927 spin_unlock(&ioa_cfg->hrrq[j]._lock);
6928 }
6929 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006930 ioa_cfg->reset_cmd = NULL;
brking@us.ibm.com3d1d0da2005-11-01 17:01:54 -06006931 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006932
6933 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Brian Kingf688f962014-12-02 12:47:37 -06006934 if (res->add_to_ml || res->del_from_ml) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006935 ipr_trace;
6936 break;
6937 }
6938 }
6939 schedule_work(&ioa_cfg->work_q);
6940
6941 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
6942 list_del(&hostrcb->queue);
6943 if (i++ < IPR_NUM_LOG_HCAMS)
6944 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
6945 else
6946 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
6947 }
6948
Brian King6bb04172007-04-26 16:00:08 -05006949 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006950 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
6951
6952 ioa_cfg->reset_retries = 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006953 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006954 wake_up_all(&ioa_cfg->reset_wait_q);
6955
Mark Nelson30237852008-12-10 12:23:20 +11006956 spin_unlock(ioa_cfg->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006957 scsi_unblock_requests(ioa_cfg->host);
Mark Nelson30237852008-12-10 12:23:20 +11006958 spin_lock(ioa_cfg->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006959
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006960 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006961 scsi_block_requests(ioa_cfg->host);
6962
Brian Kingf688f962014-12-02 12:47:37 -06006963 schedule_work(&ioa_cfg->work_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006964 LEAVE;
6965 return IPR_RC_JOB_RETURN;
6966}
6967
6968/**
6969 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
6970 * @supported_dev: supported device struct
6971 * @vpids: vendor product id struct
6972 *
6973 * Return value:
6974 * none
6975 **/
6976static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
6977 struct ipr_std_inq_vpids *vpids)
6978{
6979 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
6980 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
6981 supported_dev->num_records = 1;
6982 supported_dev->data_length =
6983 cpu_to_be16(sizeof(struct ipr_supported_device));
6984 supported_dev->reserved = 0;
6985}
6986
6987/**
6988 * ipr_set_supported_devs - Send Set Supported Devices for a device
6989 * @ipr_cmd: ipr command struct
6990 *
Wayne Boyera32c0552010-02-19 13:23:36 -08006991 * This function sends a Set Supported Devices to the adapter
Linus Torvalds1da177e2005-04-16 15:20:36 -07006992 *
6993 * Return value:
6994 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6995 **/
6996static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
6997{
6998 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6999 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007000 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7001 struct ipr_resource_entry *res = ipr_cmd->u.res;
7002
7003 ipr_cmd->job_step = ipr_ioa_reset_done;
7004
7005 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
Brian Kinge4fbf442006-03-29 09:37:22 -06007006 if (!ipr_is_scsi_disk(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07007007 continue;
7008
7009 ipr_cmd->u.res = res;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007010 ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007011
7012 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7013 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
7014 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7015
7016 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007017 ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007018 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
7019 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
7020
Wayne Boyera32c0552010-02-19 13:23:36 -08007021 ipr_init_ioadl(ipr_cmd,
7022 ioa_cfg->vpd_cbs_dma +
7023 offsetof(struct ipr_misc_cbs, supp_dev),
7024 sizeof(struct ipr_supported_device),
7025 IPR_IOADL_FLAGS_WRITE_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007026
7027 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7028 IPR_SET_SUP_DEVICE_TIMEOUT);
7029
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007030 if (!ioa_cfg->sis64)
7031 ipr_cmd->job_step = ipr_set_supported_devs;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007032 LEAVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007033 return IPR_RC_JOB_RETURN;
7034 }
7035
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007036 LEAVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007037 return IPR_RC_JOB_CONTINUE;
7038}
7039
7040/**
7041 * ipr_get_mode_page - Locate specified mode page
7042 * @mode_pages: mode page buffer
7043 * @page_code: page code to find
7044 * @len: minimum required length for mode page
7045 *
7046 * Return value:
7047 * pointer to mode page / NULL on failure
7048 **/
7049static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
7050 u32 page_code, u32 len)
7051{
7052 struct ipr_mode_page_hdr *mode_hdr;
7053 u32 page_length;
7054 u32 length;
7055
7056 if (!mode_pages || (mode_pages->hdr.length == 0))
7057 return NULL;
7058
7059 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
7060 mode_hdr = (struct ipr_mode_page_hdr *)
7061 (mode_pages->data + mode_pages->hdr.block_desc_len);
7062
7063 while (length) {
7064 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
7065 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
7066 return mode_hdr;
7067 break;
7068 } else {
7069 page_length = (sizeof(struct ipr_mode_page_hdr) +
7070 mode_hdr->page_length);
7071 length -= page_length;
7072 mode_hdr = (struct ipr_mode_page_hdr *)
7073 ((unsigned long)mode_hdr + page_length);
7074 }
7075 }
7076 return NULL;
7077}
7078
7079/**
7080 * ipr_check_term_power - Check for term power errors
7081 * @ioa_cfg: ioa config struct
7082 * @mode_pages: IOAFP mode pages buffer
7083 *
7084 * Check the IOAFP's mode page 28 for term power errors
7085 *
7086 * Return value:
7087 * nothing
7088 **/
7089static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
7090 struct ipr_mode_pages *mode_pages)
7091{
7092 int i;
7093 int entry_length;
7094 struct ipr_dev_bus_entry *bus;
7095 struct ipr_mode_page28 *mode_page;
7096
7097 mode_page = ipr_get_mode_page(mode_pages, 0x28,
7098 sizeof(struct ipr_mode_page28));
7099
7100 entry_length = mode_page->entry_length;
7101
7102 bus = mode_page->bus;
7103
7104 for (i = 0; i < mode_page->num_entries; i++) {
7105 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
7106 dev_err(&ioa_cfg->pdev->dev,
7107 "Term power is absent on scsi bus %d\n",
7108 bus->res_addr.bus);
7109 }
7110
7111 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
7112 }
7113}
7114
7115/**
7116 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
7117 * @ioa_cfg: ioa config struct
7118 *
7119 * Looks through the config table checking for SES devices. If
7120 * the SES device is in the SES table indicating a maximum SCSI
7121 * bus speed, the speed is limited for the bus.
7122 *
7123 * Return value:
7124 * none
7125 **/
7126static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
7127{
7128 u32 max_xfer_rate;
7129 int i;
7130
7131 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
7132 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
7133 ioa_cfg->bus_attr[i].bus_width);
7134
7135 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
7136 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
7137 }
7138}
7139
7140/**
7141 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
7142 * @ioa_cfg: ioa config struct
7143 * @mode_pages: mode page 28 buffer
7144 *
7145 * Updates mode page 28 based on driver configuration
7146 *
7147 * Return value:
7148 * none
7149 **/
7150static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03007151 struct ipr_mode_pages *mode_pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007152{
7153 int i, entry_length;
7154 struct ipr_dev_bus_entry *bus;
7155 struct ipr_bus_attributes *bus_attr;
7156 struct ipr_mode_page28 *mode_page;
7157
7158 mode_page = ipr_get_mode_page(mode_pages, 0x28,
7159 sizeof(struct ipr_mode_page28));
7160
7161 entry_length = mode_page->entry_length;
7162
7163 /* Loop for each device bus entry */
7164 for (i = 0, bus = mode_page->bus;
7165 i < mode_page->num_entries;
7166 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
7167 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
7168 dev_err(&ioa_cfg->pdev->dev,
7169 "Invalid resource address reported: 0x%08X\n",
7170 IPR_GET_PHYS_LOC(bus->res_addr));
7171 continue;
7172 }
7173
7174 bus_attr = &ioa_cfg->bus_attr[i];
7175 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
7176 bus->bus_width = bus_attr->bus_width;
7177 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
7178 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
7179 if (bus_attr->qas_enabled)
7180 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
7181 else
7182 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
7183 }
7184}
7185
7186/**
7187 * ipr_build_mode_select - Build a mode select command
7188 * @ipr_cmd: ipr command struct
7189 * @res_handle: resource handle to send command to
7190 * @parm: Byte 2 of Mode Sense command
7191 * @dma_addr: DMA buffer address
7192 * @xfer_len: data transfer length
7193 *
7194 * Return value:
7195 * none
7196 **/
7197static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
Wayne Boyera32c0552010-02-19 13:23:36 -08007198 __be32 res_handle, u8 parm,
7199 dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007200{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007201 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7202
7203 ioarcb->res_handle = res_handle;
7204 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7205 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
7206 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
7207 ioarcb->cmd_pkt.cdb[1] = parm;
7208 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7209
Wayne Boyera32c0552010-02-19 13:23:36 -08007210 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007211}
7212
7213/**
7214 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
7215 * @ipr_cmd: ipr command struct
7216 *
7217 * This function sets up the SCSI bus attributes and sends
7218 * a Mode Select for Page 28 to activate them.
7219 *
7220 * Return value:
7221 * IPR_RC_JOB_RETURN
7222 **/
7223static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
7224{
7225 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7226 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
7227 int length;
7228
7229 ENTER;
Brian King47338042006-02-08 20:57:42 -06007230 ipr_scsi_bus_speed_limit(ioa_cfg);
7231 ipr_check_term_power(ioa_cfg, mode_pages);
7232 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
7233 length = mode_pages->hdr.length + 1;
7234 mode_pages->hdr.length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007235
7236 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
7237 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
7238 length);
7239
Wayne Boyerf72919e2010-02-19 13:24:21 -08007240 ipr_cmd->job_step = ipr_set_supported_devs;
7241 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
7242 struct ipr_resource_entry, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007243 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7244
7245 LEAVE;
7246 return IPR_RC_JOB_RETURN;
7247}
7248
7249/**
7250 * ipr_build_mode_sense - Builds a mode sense command
7251 * @ipr_cmd: ipr command struct
7252 * @res: resource entry struct
7253 * @parm: Byte 2 of mode sense command
7254 * @dma_addr: DMA address of mode sense buffer
7255 * @xfer_len: Size of DMA buffer
7256 *
7257 * Return value:
7258 * none
7259 **/
7260static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
7261 __be32 res_handle,
Wayne Boyera32c0552010-02-19 13:23:36 -08007262 u8 parm, dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007263{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007264 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7265
7266 ioarcb->res_handle = res_handle;
7267 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
7268 ioarcb->cmd_pkt.cdb[2] = parm;
7269 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7270 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7271
Wayne Boyera32c0552010-02-19 13:23:36 -08007272 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007273}
7274
7275/**
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007276 * ipr_reset_cmd_failed - Handle failure of IOA reset command
7277 * @ipr_cmd: ipr command struct
7278 *
7279 * This function handles the failure of an IOA bringup command.
7280 *
7281 * Return value:
7282 * IPR_RC_JOB_RETURN
7283 **/
7284static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
7285{
7286 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer96d21f02010-05-10 09:13:27 -07007287 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007288
7289 dev_err(&ioa_cfg->pdev->dev,
7290 "0x%02X failed with IOASC: 0x%08X\n",
7291 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
7292
7293 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007294 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007295 return IPR_RC_JOB_RETURN;
7296}
7297
7298/**
7299 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
7300 * @ipr_cmd: ipr command struct
7301 *
7302 * This function handles the failure of a Mode Sense to the IOAFP.
7303 * Some adapters do not handle all mode pages.
7304 *
7305 * Return value:
7306 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7307 **/
7308static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
7309{
Wayne Boyerf72919e2010-02-19 13:24:21 -08007310 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer96d21f02010-05-10 09:13:27 -07007311 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007312
7313 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
Wayne Boyerf72919e2010-02-19 13:24:21 -08007314 ipr_cmd->job_step = ipr_set_supported_devs;
7315 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
7316 struct ipr_resource_entry, queue);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007317 return IPR_RC_JOB_CONTINUE;
7318 }
7319
7320 return ipr_reset_cmd_failed(ipr_cmd);
7321}
7322
7323/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007324 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
7325 * @ipr_cmd: ipr command struct
7326 *
7327 * This function send a Page 28 mode sense to the IOA to
7328 * retrieve SCSI bus attributes.
7329 *
7330 * Return value:
7331 * IPR_RC_JOB_RETURN
7332 **/
7333static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
7334{
7335 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7336
7337 ENTER;
7338 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
7339 0x28, ioa_cfg->vpd_cbs_dma +
7340 offsetof(struct ipr_misc_cbs, mode_pages),
7341 sizeof(struct ipr_mode_pages));
7342
7343 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007344 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007345
7346 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7347
7348 LEAVE;
7349 return IPR_RC_JOB_RETURN;
7350}
7351
7352/**
Brian Kingac09c342007-04-26 16:00:16 -05007353 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
7354 * @ipr_cmd: ipr command struct
7355 *
7356 * This function enables dual IOA RAID support if possible.
7357 *
7358 * Return value:
7359 * IPR_RC_JOB_RETURN
7360 **/
7361static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
7362{
7363 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7364 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
7365 struct ipr_mode_page24 *mode_page;
7366 int length;
7367
7368 ENTER;
7369 mode_page = ipr_get_mode_page(mode_pages, 0x24,
7370 sizeof(struct ipr_mode_page24));
7371
7372 if (mode_page)
7373 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
7374
7375 length = mode_pages->hdr.length + 1;
7376 mode_pages->hdr.length = 0;
7377
7378 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
7379 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
7380 length);
7381
7382 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7383 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7384
7385 LEAVE;
7386 return IPR_RC_JOB_RETURN;
7387}
7388
7389/**
7390 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
7391 * @ipr_cmd: ipr command struct
7392 *
7393 * This function handles the failure of a Mode Sense to the IOAFP.
7394 * Some adapters do not handle all mode pages.
7395 *
7396 * Return value:
7397 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7398 **/
7399static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
7400{
Wayne Boyer96d21f02010-05-10 09:13:27 -07007401 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian Kingac09c342007-04-26 16:00:16 -05007402
7403 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
7404 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7405 return IPR_RC_JOB_CONTINUE;
7406 }
7407
7408 return ipr_reset_cmd_failed(ipr_cmd);
7409}
7410
7411/**
7412 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
7413 * @ipr_cmd: ipr command struct
7414 *
7415 * This function send a mode sense to the IOA to retrieve
7416 * the IOA Advanced Function Control mode page.
7417 *
7418 * Return value:
7419 * IPR_RC_JOB_RETURN
7420 **/
7421static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
7422{
7423 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7424
7425 ENTER;
7426 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
7427 0x24, ioa_cfg->vpd_cbs_dma +
7428 offsetof(struct ipr_misc_cbs, mode_pages),
7429 sizeof(struct ipr_mode_pages));
7430
7431 ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
7432 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
7433
7434 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7435
7436 LEAVE;
7437 return IPR_RC_JOB_RETURN;
7438}
7439
7440/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007441 * ipr_init_res_table - Initialize the resource table
7442 * @ipr_cmd: ipr command struct
7443 *
7444 * This function looks through the existing resource table, comparing
7445 * it with the config table. This function will take care of old/new
7446 * devices and schedule adding/removing them from the mid-layer
7447 * as appropriate.
7448 *
7449 * Return value:
7450 * IPR_RC_JOB_CONTINUE
7451 **/
7452static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
7453{
7454 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7455 struct ipr_resource_entry *res, *temp;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007456 struct ipr_config_table_entry_wrapper cfgtew;
7457 int entries, found, flag, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007458 LIST_HEAD(old_res);
7459
7460 ENTER;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007461 if (ioa_cfg->sis64)
7462 flag = ioa_cfg->u.cfg_table64->hdr64.flags;
7463 else
7464 flag = ioa_cfg->u.cfg_table->hdr.flags;
7465
7466 if (flag & IPR_UCODE_DOWNLOAD_REQ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007467 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
7468
7469 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
7470 list_move_tail(&res->queue, &old_res);
7471
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007472 if (ioa_cfg->sis64)
Wayne Boyer438b0332010-05-10 09:13:00 -07007473 entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007474 else
7475 entries = ioa_cfg->u.cfg_table->hdr.num_entries;
7476
7477 for (i = 0; i < entries; i++) {
7478 if (ioa_cfg->sis64)
7479 cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
7480 else
7481 cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07007482 found = 0;
7483
7484 list_for_each_entry_safe(res, temp, &old_res, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007485 if (ipr_is_same_device(res, &cfgtew)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007486 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7487 found = 1;
7488 break;
7489 }
7490 }
7491
7492 if (!found) {
7493 if (list_empty(&ioa_cfg->free_res_q)) {
7494 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
7495 break;
7496 }
7497
7498 found = 1;
7499 res = list_entry(ioa_cfg->free_res_q.next,
7500 struct ipr_resource_entry, queue);
7501 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007502 ipr_init_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007503 res->add_to_ml = 1;
Wayne Boyer56115592010-06-10 14:46:34 -07007504 } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
7505 res->sdev->allow_restart = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007506
7507 if (found)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007508 ipr_update_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007509 }
7510
7511 list_for_each_entry_safe(res, temp, &old_res, queue) {
7512 if (res->sdev) {
7513 res->del_from_ml = 1;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007514 res->res_handle = IPR_INVALID_RES_HANDLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007515 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007516 }
7517 }
7518
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007519 list_for_each_entry_safe(res, temp, &old_res, queue) {
7520 ipr_clear_res_target(res);
7521 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
7522 }
7523
Brian Kingac09c342007-04-26 16:00:16 -05007524 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
7525 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
7526 else
7527 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007528
7529 LEAVE;
7530 return IPR_RC_JOB_CONTINUE;
7531}
7532
7533/**
7534 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
7535 * @ipr_cmd: ipr command struct
7536 *
7537 * This function sends a Query IOA Configuration command
7538 * to the adapter to retrieve the IOA configuration table.
7539 *
7540 * Return value:
7541 * IPR_RC_JOB_RETURN
7542 **/
7543static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
7544{
7545 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7546 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007547 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
Brian Kingac09c342007-04-26 16:00:16 -05007548 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007549
7550 ENTER;
Brian Kingac09c342007-04-26 16:00:16 -05007551 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
7552 ioa_cfg->dual_raid = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007553 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
7554 ucode_vpd->major_release, ucode_vpd->card_type,
7555 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
7556 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7557 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7558
7559 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
Wayne Boyer438b0332010-05-10 09:13:00 -07007560 ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007561 ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
7562 ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007563
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007564 ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
Wayne Boyera32c0552010-02-19 13:23:36 -08007565 IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007566
7567 ipr_cmd->job_step = ipr_init_res_table;
7568
7569 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7570
7571 LEAVE;
7572 return IPR_RC_JOB_RETURN;
7573}
7574
7575/**
7576 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
7577 * @ipr_cmd: ipr command struct
7578 *
7579 * This utility function sends an inquiry to the adapter.
7580 *
7581 * Return value:
7582 * none
7583 **/
7584static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
Wayne Boyera32c0552010-02-19 13:23:36 -08007585 dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007586{
7587 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007588
7589 ENTER;
7590 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7591 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7592
7593 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
7594 ioarcb->cmd_pkt.cdb[1] = flags;
7595 ioarcb->cmd_pkt.cdb[2] = page;
7596 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7597
Wayne Boyera32c0552010-02-19 13:23:36 -08007598 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007599
7600 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7601 LEAVE;
7602}
7603
7604/**
brking@us.ibm.com62275042005-11-01 17:01:14 -06007605 * ipr_inquiry_page_supported - Is the given inquiry page supported
7606 * @page0: inquiry page 0 buffer
7607 * @page: page code.
7608 *
7609 * This function determines if the specified inquiry page is supported.
7610 *
7611 * Return value:
7612 * 1 if page is supported / 0 if not
7613 **/
7614static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
7615{
7616 int i;
7617
7618 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
7619 if (page0->page[i] == page)
7620 return 1;
7621
7622 return 0;
7623}
7624
7625/**
Brian Kingac09c342007-04-26 16:00:16 -05007626 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
7627 * @ipr_cmd: ipr command struct
7628 *
7629 * This function sends a Page 0xD0 inquiry to the adapter
7630 * to retrieve adapter capabilities.
7631 *
7632 * Return value:
7633 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7634 **/
7635static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
7636{
7637 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7638 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
7639 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7640
7641 ENTER;
7642 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
7643 memset(cap, 0, sizeof(*cap));
7644
7645 if (ipr_inquiry_page_supported(page0, 0xD0)) {
7646 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
7647 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
7648 sizeof(struct ipr_inquiry_cap));
7649 return IPR_RC_JOB_RETURN;
7650 }
7651
7652 LEAVE;
7653 return IPR_RC_JOB_CONTINUE;
7654}
7655
7656/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007657 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
7658 * @ipr_cmd: ipr command struct
7659 *
7660 * This function sends a Page 3 inquiry to the adapter
7661 * to retrieve software VPD information.
7662 *
7663 * Return value:
7664 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7665 **/
7666static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
7667{
7668 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007669
7670 ENTER;
7671
Brian Kingac09c342007-04-26 16:00:16 -05007672 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007673
7674 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
7675 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
7676 sizeof(struct ipr_inquiry_page3));
7677
7678 LEAVE;
7679 return IPR_RC_JOB_RETURN;
7680}
7681
7682/**
7683 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
7684 * @ipr_cmd: ipr command struct
7685 *
7686 * This function sends a Page 0 inquiry to the adapter
7687 * to retrieve supported inquiry pages.
7688 *
7689 * Return value:
7690 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7691 **/
7692static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
7693{
7694 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007695 char type[5];
7696
7697 ENTER;
7698
7699 /* Grab the type out of the VPD and store it away */
7700 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
7701 type[4] = '\0';
7702 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
7703
Brian Kingf688f962014-12-02 12:47:37 -06007704 if (ipr_invalid_adapter(ioa_cfg)) {
7705 dev_err(&ioa_cfg->pdev->dev,
7706 "Adapter not supported in this hardware configuration.\n");
7707
7708 if (!ipr_testmode) {
7709 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
7710 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7711 list_add_tail(&ipr_cmd->queue,
7712 &ioa_cfg->hrrq->hrrq_free_q);
7713 return IPR_RC_JOB_RETURN;
7714 }
7715 }
7716
brking@us.ibm.com62275042005-11-01 17:01:14 -06007717 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007718
brking@us.ibm.com62275042005-11-01 17:01:14 -06007719 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
7720 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
7721 sizeof(struct ipr_inquiry_page0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007722
7723 LEAVE;
7724 return IPR_RC_JOB_RETURN;
7725}
7726
7727/**
7728 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
7729 * @ipr_cmd: ipr command struct
7730 *
7731 * This function sends a standard inquiry to the adapter.
7732 *
7733 * Return value:
7734 * IPR_RC_JOB_RETURN
7735 **/
7736static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
7737{
7738 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7739
7740 ENTER;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007741 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007742
7743 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
7744 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
7745 sizeof(struct ipr_ioa_vpd));
7746
7747 LEAVE;
7748 return IPR_RC_JOB_RETURN;
7749}
7750
7751/**
Wayne Boyer214777b2010-02-19 13:24:26 -08007752 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007753 * @ipr_cmd: ipr command struct
7754 *
7755 * This function send an Identify Host Request Response Queue
7756 * command to establish the HRRQ with the adapter.
7757 *
7758 * Return value:
7759 * IPR_RC_JOB_RETURN
7760 **/
Wayne Boyer214777b2010-02-19 13:24:26 -08007761static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007762{
7763 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7764 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007765 struct ipr_hrr_queue *hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007766
7767 ENTER;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007768 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007769 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
7770
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007771 if (ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num) {
7772 hrrq = &ioa_cfg->hrrq[ioa_cfg->identify_hrrq_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07007773
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007774 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
7775 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007776
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007777 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7778 if (ioa_cfg->sis64)
7779 ioarcb->cmd_pkt.cdb[1] = 0x1;
7780
7781 if (ioa_cfg->nvectors == 1)
7782 ioarcb->cmd_pkt.cdb[1] &= ~IPR_ID_HRRQ_SELE_ENABLE;
7783 else
7784 ioarcb->cmd_pkt.cdb[1] |= IPR_ID_HRRQ_SELE_ENABLE;
7785
7786 ioarcb->cmd_pkt.cdb[2] =
7787 ((u64) hrrq->host_rrq_dma >> 24) & 0xff;
7788 ioarcb->cmd_pkt.cdb[3] =
7789 ((u64) hrrq->host_rrq_dma >> 16) & 0xff;
7790 ioarcb->cmd_pkt.cdb[4] =
7791 ((u64) hrrq->host_rrq_dma >> 8) & 0xff;
7792 ioarcb->cmd_pkt.cdb[5] =
7793 ((u64) hrrq->host_rrq_dma) & 0xff;
7794 ioarcb->cmd_pkt.cdb[7] =
7795 ((sizeof(u32) * hrrq->size) >> 8) & 0xff;
7796 ioarcb->cmd_pkt.cdb[8] =
7797 (sizeof(u32) * hrrq->size) & 0xff;
7798
7799 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007800 ioarcb->cmd_pkt.cdb[9] =
7801 ioa_cfg->identify_hrrq_index;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007802
7803 if (ioa_cfg->sis64) {
7804 ioarcb->cmd_pkt.cdb[10] =
7805 ((u64) hrrq->host_rrq_dma >> 56) & 0xff;
7806 ioarcb->cmd_pkt.cdb[11] =
7807 ((u64) hrrq->host_rrq_dma >> 48) & 0xff;
7808 ioarcb->cmd_pkt.cdb[12] =
7809 ((u64) hrrq->host_rrq_dma >> 40) & 0xff;
7810 ioarcb->cmd_pkt.cdb[13] =
7811 ((u64) hrrq->host_rrq_dma >> 32) & 0xff;
7812 }
7813
7814 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007815 ioarcb->cmd_pkt.cdb[14] =
7816 ioa_cfg->identify_hrrq_index;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007817
7818 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7819 IPR_INTERNAL_TIMEOUT);
7820
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007821 if (++ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num)
7822 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007823
7824 LEAVE;
7825 return IPR_RC_JOB_RETURN;
Wayne Boyer214777b2010-02-19 13:24:26 -08007826 }
7827
Linus Torvalds1da177e2005-04-16 15:20:36 -07007828 LEAVE;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007829 return IPR_RC_JOB_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007830}
7831
7832/**
7833 * ipr_reset_timer_done - Adapter reset timer function
7834 * @ipr_cmd: ipr command struct
7835 *
7836 * Description: This function is used in adapter reset processing
7837 * for timing events. If the reset_cmd pointer in the IOA
7838 * config struct is not this adapter's we are doing nested
7839 * resets and fail_all_ops will take care of freeing the
7840 * command block.
7841 *
7842 * Return value:
7843 * none
7844 **/
7845static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
7846{
7847 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7848 unsigned long lock_flags = 0;
7849
7850 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7851
7852 if (ioa_cfg->reset_cmd == ipr_cmd) {
7853 list_del(&ipr_cmd->queue);
7854 ipr_cmd->done(ipr_cmd);
7855 }
7856
7857 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7858}
7859
7860/**
7861 * ipr_reset_start_timer - Start a timer for adapter reset job
7862 * @ipr_cmd: ipr command struct
7863 * @timeout: timeout value
7864 *
7865 * Description: This function is used in adapter reset processing
7866 * for timing events. If the reset_cmd pointer in the IOA
7867 * config struct is not this adapter's we are doing nested
7868 * resets and fail_all_ops will take care of freeing the
7869 * command block.
7870 *
7871 * Return value:
7872 * none
7873 **/
7874static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
7875 unsigned long timeout)
7876{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007877
7878 ENTER;
7879 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007880 ipr_cmd->done = ipr_reset_ioa_job;
7881
7882 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7883 ipr_cmd->timer.expires = jiffies + timeout;
7884 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
7885 add_timer(&ipr_cmd->timer);
7886}
7887
7888/**
7889 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7890 * @ioa_cfg: ioa cfg struct
7891 *
7892 * Return value:
7893 * nothing
7894 **/
7895static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
7896{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007897 struct ipr_hrr_queue *hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007898
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007899 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007900 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007901 memset(hrrq->host_rrq, 0, sizeof(u32) * hrrq->size);
7902
7903 /* Initialize Host RRQ pointers */
7904 hrrq->hrrq_start = hrrq->host_rrq;
7905 hrrq->hrrq_end = &hrrq->host_rrq[hrrq->size - 1];
7906 hrrq->hrrq_curr = hrrq->hrrq_start;
7907 hrrq->toggle_bit = 1;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007908 spin_unlock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007909 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007910 wmb();
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007911
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007912 ioa_cfg->identify_hrrq_index = 0;
7913 if (ioa_cfg->hrrq_num == 1)
7914 atomic_set(&ioa_cfg->hrrq_index, 0);
7915 else
7916 atomic_set(&ioa_cfg->hrrq_index, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007917
7918 /* Zero out config table */
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007919 memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007920}
7921
7922/**
Wayne Boyer214777b2010-02-19 13:24:26 -08007923 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
7924 * @ipr_cmd: ipr command struct
7925 *
7926 * Return value:
7927 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7928 **/
7929static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
7930{
7931 unsigned long stage, stage_time;
7932 u32 feedback;
7933 volatile u32 int_reg;
7934 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7935 u64 maskval = 0;
7936
7937 feedback = readl(ioa_cfg->regs.init_feedback_reg);
7938 stage = feedback & IPR_IPL_INIT_STAGE_MASK;
7939 stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
7940
7941 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
7942
7943 /* sanity check the stage_time value */
Wayne Boyer438b0332010-05-10 09:13:00 -07007944 if (stage_time == 0)
7945 stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
7946 else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
Wayne Boyer214777b2010-02-19 13:24:26 -08007947 stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
7948 else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
7949 stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
7950
7951 if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
7952 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
7953 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7954 stage_time = ioa_cfg->transop_timeout;
7955 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7956 } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
Wayne Boyer1df79ca2010-07-14 10:49:43 -07007957 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
7958 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7959 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7960 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7961 maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
7962 writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
7963 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7964 return IPR_RC_JOB_CONTINUE;
7965 }
Wayne Boyer214777b2010-02-19 13:24:26 -08007966 }
7967
7968 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7969 ipr_cmd->timer.expires = jiffies + stage_time * HZ;
7970 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7971 ipr_cmd->done = ipr_reset_ioa_job;
7972 add_timer(&ipr_cmd->timer);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007973
7974 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Wayne Boyer214777b2010-02-19 13:24:26 -08007975
7976 return IPR_RC_JOB_RETURN;
7977}
7978
7979/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007980 * ipr_reset_enable_ioa - Enable the IOA following a reset.
7981 * @ipr_cmd: ipr command struct
7982 *
7983 * This function reinitializes some control blocks and
7984 * enables destructive diagnostics on the adapter.
7985 *
7986 * Return value:
7987 * IPR_RC_JOB_RETURN
7988 **/
7989static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
7990{
7991 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7992 volatile u32 int_reg;
Wayne Boyer7be96902010-05-10 09:14:07 -07007993 volatile u64 maskval;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007994 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007995
7996 ENTER;
Wayne Boyer214777b2010-02-19 13:24:26 -08007997 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007998 ipr_init_ioa_mem(ioa_cfg);
7999
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008000 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8001 spin_lock(&ioa_cfg->hrrq[i]._lock);
8002 ioa_cfg->hrrq[i].allow_interrupts = 1;
8003 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8004 }
8005 wmb();
Wayne Boyer8701f182010-06-04 10:26:50 -07008006 if (ioa_cfg->sis64) {
8007 /* Set the adapter to the correct endian mode. */
8008 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
8009 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
8010 }
8011
Wayne Boyer7be96902010-05-10 09:14:07 -07008012 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008013
8014 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
8015 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
Wayne Boyer214777b2010-02-19 13:24:26 -08008016 ioa_cfg->regs.clr_interrupt_mask_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008017 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8018 return IPR_RC_JOB_CONTINUE;
8019 }
8020
8021 /* Enable destructive diagnostics on IOA */
Wayne Boyer214777b2010-02-19 13:24:26 -08008022 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008023
Wayne Boyer7be96902010-05-10 09:14:07 -07008024 if (ioa_cfg->sis64) {
8025 maskval = IPR_PCII_IPL_STAGE_CHANGE;
8026 maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
8027 writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
8028 } else
8029 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
Wayne Boyer214777b2010-02-19 13:24:26 -08008030
Linus Torvalds1da177e2005-04-16 15:20:36 -07008031 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8032
8033 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
8034
Wayne Boyer214777b2010-02-19 13:24:26 -08008035 if (ioa_cfg->sis64) {
8036 ipr_cmd->job_step = ipr_reset_next_stage;
8037 return IPR_RC_JOB_CONTINUE;
8038 }
8039
Linus Torvalds1da177e2005-04-16 15:20:36 -07008040 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
Brian King5469cb52007-03-29 12:42:40 -05008041 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008042 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
8043 ipr_cmd->done = ipr_reset_ioa_job;
8044 add_timer(&ipr_cmd->timer);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008045 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008046
8047 LEAVE;
8048 return IPR_RC_JOB_RETURN;
8049}
8050
8051/**
8052 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
8053 * @ipr_cmd: ipr command struct
8054 *
8055 * This function is invoked when an adapter dump has run out
8056 * of processing time.
8057 *
8058 * Return value:
8059 * IPR_RC_JOB_CONTINUE
8060 **/
8061static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
8062{
8063 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8064
8065 if (ioa_cfg->sdt_state == GET_DUMP)
Brian King41e9a692011-09-21 08:51:11 -05008066 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8067 else if (ioa_cfg->sdt_state == READ_DUMP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008068 ioa_cfg->sdt_state = ABORT_DUMP;
8069
Brian King4c647e92011-10-15 09:08:56 -05008070 ioa_cfg->dump_timeout = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008071 ipr_cmd->job_step = ipr_reset_alert;
8072
8073 return IPR_RC_JOB_CONTINUE;
8074}
8075
8076/**
8077 * ipr_unit_check_no_data - Log a unit check/no data error log
8078 * @ioa_cfg: ioa config struct
8079 *
8080 * Logs an error indicating the adapter unit checked, but for some
8081 * reason, we were unable to fetch the unit check buffer.
8082 *
8083 * Return value:
8084 * nothing
8085 **/
8086static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
8087{
8088 ioa_cfg->errors_logged++;
8089 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
8090}
8091
8092/**
8093 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
8094 * @ioa_cfg: ioa config struct
8095 *
8096 * Fetches the unit check buffer from the adapter by clocking the data
8097 * through the mailbox register.
8098 *
8099 * Return value:
8100 * nothing
8101 **/
8102static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
8103{
8104 unsigned long mailbox;
8105 struct ipr_hostrcb *hostrcb;
8106 struct ipr_uc_sdt sdt;
8107 int rc, length;
Brian King65f56472007-04-26 16:00:12 -05008108 u32 ioasc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008109
8110 mailbox = readl(ioa_cfg->ioa_mailbox);
8111
Wayne Boyerdcbad002010-02-19 13:24:14 -08008112 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008113 ipr_unit_check_no_data(ioa_cfg);
8114 return;
8115 }
8116
8117 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
8118 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
8119 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
8120
Wayne Boyerdcbad002010-02-19 13:24:14 -08008121 if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
8122 ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
8123 (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008124 ipr_unit_check_no_data(ioa_cfg);
8125 return;
8126 }
8127
8128 /* Find length of the first sdt entry (UC buffer) */
Wayne Boyerdcbad002010-02-19 13:24:14 -08008129 if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
8130 length = be32_to_cpu(sdt.entry[0].end_token);
8131 else
8132 length = (be32_to_cpu(sdt.entry[0].end_token) -
8133 be32_to_cpu(sdt.entry[0].start_token)) &
8134 IPR_FMT2_MBX_ADDR_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008135
8136 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
8137 struct ipr_hostrcb, queue);
8138 list_del(&hostrcb->queue);
8139 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
8140
8141 rc = ipr_get_ldump_data_section(ioa_cfg,
Wayne Boyerdcbad002010-02-19 13:24:14 -08008142 be32_to_cpu(sdt.entry[0].start_token),
Linus Torvalds1da177e2005-04-16 15:20:36 -07008143 (__be32 *)&hostrcb->hcam,
8144 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
8145
Brian King65f56472007-04-26 16:00:12 -05008146 if (!rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008147 ipr_handle_log_data(ioa_cfg, hostrcb);
Wayne Boyer4565e372010-02-19 13:24:07 -08008148 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Brian King65f56472007-04-26 16:00:12 -05008149 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
8150 ioa_cfg->sdt_state == GET_DUMP)
8151 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8152 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07008153 ipr_unit_check_no_data(ioa_cfg);
8154
8155 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
8156}
8157
8158/**
Wayne Boyer110def82010-11-04 09:36:16 -07008159 * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
8160 * @ipr_cmd: ipr command struct
8161 *
8162 * Description: This function will call to get the unit check buffer.
8163 *
8164 * Return value:
8165 * IPR_RC_JOB_RETURN
8166 **/
8167static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
8168{
8169 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8170
8171 ENTER;
8172 ioa_cfg->ioa_unit_checked = 0;
8173 ipr_get_unit_check_buffer(ioa_cfg);
8174 ipr_cmd->job_step = ipr_reset_alert;
8175 ipr_reset_start_timer(ipr_cmd, 0);
8176
8177 LEAVE;
8178 return IPR_RC_JOB_RETURN;
8179}
8180
8181/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008182 * ipr_reset_restore_cfg_space - Restore PCI config space.
8183 * @ipr_cmd: ipr command struct
8184 *
8185 * Description: This function restores the saved PCI config space of
8186 * the adapter, fails all outstanding ops back to the callers, and
8187 * fetches the dump/unit check if applicable to this reset.
8188 *
8189 * Return value:
8190 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8191 **/
8192static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
8193{
8194 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer630ad8312011-04-07 12:12:30 -07008195 u32 int_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008196
8197 ENTER;
Kleber Sacilotto de Souza99c965d2009-11-25 20:13:43 -02008198 ioa_cfg->pdev->state_saved = true;
Jon Mason1d3c16a2010-11-30 17:43:26 -06008199 pci_restore_state(ioa_cfg->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008200
8201 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
Wayne Boyer96d21f02010-05-10 09:13:27 -07008202 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008203 return IPR_RC_JOB_CONTINUE;
8204 }
8205
8206 ipr_fail_all_ops(ioa_cfg);
8207
Wayne Boyer8701f182010-06-04 10:26:50 -07008208 if (ioa_cfg->sis64) {
8209 /* Set the adapter to the correct endian mode. */
8210 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
8211 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
8212 }
8213
Linus Torvalds1da177e2005-04-16 15:20:36 -07008214 if (ioa_cfg->ioa_unit_checked) {
Wayne Boyer110def82010-11-04 09:36:16 -07008215 if (ioa_cfg->sis64) {
8216 ipr_cmd->job_step = ipr_reset_get_unit_check_job;
8217 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
8218 return IPR_RC_JOB_RETURN;
8219 } else {
8220 ioa_cfg->ioa_unit_checked = 0;
8221 ipr_get_unit_check_buffer(ioa_cfg);
8222 ipr_cmd->job_step = ipr_reset_alert;
8223 ipr_reset_start_timer(ipr_cmd, 0);
8224 return IPR_RC_JOB_RETURN;
8225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008226 }
8227
8228 if (ioa_cfg->in_ioa_bringdown) {
8229 ipr_cmd->job_step = ipr_ioa_bringdown_done;
8230 } else {
8231 ipr_cmd->job_step = ipr_reset_enable_ioa;
8232
8233 if (GET_DUMP == ioa_cfg->sdt_state) {
Brian King41e9a692011-09-21 08:51:11 -05008234 ioa_cfg->sdt_state = READ_DUMP;
Brian King4c647e92011-10-15 09:08:56 -05008235 ioa_cfg->dump_timeout = 0;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03008236 if (ioa_cfg->sis64)
8237 ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
8238 else
8239 ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008240 ipr_cmd->job_step = ipr_reset_wait_for_dump;
8241 schedule_work(&ioa_cfg->work_q);
8242 return IPR_RC_JOB_RETURN;
8243 }
8244 }
8245
Wayne Boyer438b0332010-05-10 09:13:00 -07008246 LEAVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008247 return IPR_RC_JOB_CONTINUE;
8248}
8249
8250/**
Brian Kinge619e1a2007-01-23 11:25:37 -06008251 * ipr_reset_bist_done - BIST has completed on the adapter.
8252 * @ipr_cmd: ipr command struct
8253 *
8254 * Description: Unblock config space and resume the reset process.
8255 *
8256 * Return value:
8257 * IPR_RC_JOB_CONTINUE
8258 **/
8259static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
8260{
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008261 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8262
Brian Kinge619e1a2007-01-23 11:25:37 -06008263 ENTER;
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008264 if (ioa_cfg->cfg_locked)
8265 pci_cfg_access_unlock(ioa_cfg->pdev);
8266 ioa_cfg->cfg_locked = 0;
Brian Kinge619e1a2007-01-23 11:25:37 -06008267 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
8268 LEAVE;
8269 return IPR_RC_JOB_CONTINUE;
8270}
8271
8272/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008273 * ipr_reset_start_bist - Run BIST on the adapter.
8274 * @ipr_cmd: ipr command struct
8275 *
8276 * Description: This function runs BIST on the adapter, then delays 2 seconds.
8277 *
8278 * Return value:
8279 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8280 **/
8281static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
8282{
8283 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyercb237ef2010-06-17 11:51:40 -07008284 int rc = PCIBIOS_SUCCESSFUL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008285
8286 ENTER;
Wayne Boyercb237ef2010-06-17 11:51:40 -07008287 if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
8288 writel(IPR_UPROCI_SIS64_START_BIST,
8289 ioa_cfg->regs.set_uproc_interrupt_reg32);
8290 else
8291 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
8292
8293 if (rc == PCIBIOS_SUCCESSFUL) {
Brian Kinge619e1a2007-01-23 11:25:37 -06008294 ipr_cmd->job_step = ipr_reset_bist_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008295 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
8296 rc = IPR_RC_JOB_RETURN;
Wayne Boyercb237ef2010-06-17 11:51:40 -07008297 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008298 if (ioa_cfg->cfg_locked)
8299 pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
8300 ioa_cfg->cfg_locked = 0;
Wayne Boyercb237ef2010-06-17 11:51:40 -07008301 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
8302 rc = IPR_RC_JOB_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008303 }
8304
8305 LEAVE;
8306 return rc;
8307}
8308
8309/**
Brian King463fc692007-05-07 17:09:05 -05008310 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
8311 * @ipr_cmd: ipr command struct
8312 *
8313 * Description: This clears PCI reset to the adapter and delays two seconds.
8314 *
8315 * Return value:
8316 * IPR_RC_JOB_RETURN
8317 **/
8318static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
8319{
8320 ENTER;
8321 pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
8322 ipr_cmd->job_step = ipr_reset_bist_done;
8323 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
8324 LEAVE;
8325 return IPR_RC_JOB_RETURN;
8326}
8327
8328/**
8329 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
8330 * @ipr_cmd: ipr command struct
8331 *
8332 * Description: This asserts PCI reset to the adapter.
8333 *
8334 * Return value:
8335 * IPR_RC_JOB_RETURN
8336 **/
8337static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
8338{
8339 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8340 struct pci_dev *pdev = ioa_cfg->pdev;
8341
8342 ENTER;
Brian King463fc692007-05-07 17:09:05 -05008343 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
8344 ipr_cmd->job_step = ipr_reset_slot_reset_done;
8345 ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
8346 LEAVE;
8347 return IPR_RC_JOB_RETURN;
8348}
8349
8350/**
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008351 * ipr_reset_block_config_access_wait - Wait for permission to block config access
8352 * @ipr_cmd: ipr command struct
8353 *
8354 * Description: This attempts to block config access to the IOA.
8355 *
8356 * Return value:
8357 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8358 **/
8359static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
8360{
8361 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8362 int rc = IPR_RC_JOB_CONTINUE;
8363
8364 if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
8365 ioa_cfg->cfg_locked = 1;
8366 ipr_cmd->job_step = ioa_cfg->reset;
8367 } else {
8368 if (ipr_cmd->u.time_left) {
8369 rc = IPR_RC_JOB_RETURN;
8370 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8371 ipr_reset_start_timer(ipr_cmd,
8372 IPR_CHECK_FOR_RESET_TIMEOUT);
8373 } else {
8374 ipr_cmd->job_step = ioa_cfg->reset;
8375 dev_err(&ioa_cfg->pdev->dev,
8376 "Timed out waiting to lock config access. Resetting anyway.\n");
8377 }
8378 }
8379
8380 return rc;
8381}
8382
8383/**
8384 * ipr_reset_block_config_access - Block config access to the IOA
8385 * @ipr_cmd: ipr command struct
8386 *
8387 * Description: This attempts to block config access to the IOA
8388 *
8389 * Return value:
8390 * IPR_RC_JOB_CONTINUE
8391 **/
8392static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
8393{
8394 ipr_cmd->ioa_cfg->cfg_locked = 0;
8395 ipr_cmd->job_step = ipr_reset_block_config_access_wait;
8396 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8397 return IPR_RC_JOB_CONTINUE;
8398}
8399
8400/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008401 * ipr_reset_allowed - Query whether or not IOA can be reset
8402 * @ioa_cfg: ioa config struct
8403 *
8404 * Return value:
8405 * 0 if reset not allowed / non-zero if reset is allowed
8406 **/
8407static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
8408{
8409 volatile u32 temp_reg;
8410
8411 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
8412 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
8413}
8414
8415/**
8416 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
8417 * @ipr_cmd: ipr command struct
8418 *
8419 * Description: This function waits for adapter permission to run BIST,
8420 * then runs BIST. If the adapter does not give permission after a
8421 * reasonable time, we will reset the adapter anyway. The impact of
8422 * resetting the adapter without warning the adapter is the risk of
8423 * losing the persistent error log on the adapter. If the adapter is
8424 * reset while it is writing to the flash on the adapter, the flash
8425 * segment will have bad ECC and be zeroed.
8426 *
8427 * Return value:
8428 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8429 **/
8430static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
8431{
8432 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8433 int rc = IPR_RC_JOB_RETURN;
8434
8435 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
8436 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8437 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8438 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008439 ipr_cmd->job_step = ipr_reset_block_config_access;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008440 rc = IPR_RC_JOB_CONTINUE;
8441 }
8442
8443 return rc;
8444}
8445
8446/**
Wayne Boyer8701f182010-06-04 10:26:50 -07008447 * ipr_reset_alert - Alert the adapter of a pending reset
Linus Torvalds1da177e2005-04-16 15:20:36 -07008448 * @ipr_cmd: ipr command struct
8449 *
8450 * Description: This function alerts the adapter that it will be reset.
8451 * If memory space is not currently enabled, proceed directly
8452 * to running BIST on the adapter. The timer must always be started
8453 * so we guarantee we do not run BIST from ipr_isr.
8454 *
8455 * Return value:
8456 * IPR_RC_JOB_RETURN
8457 **/
8458static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
8459{
8460 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8461 u16 cmd_reg;
8462 int rc;
8463
8464 ENTER;
8465 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
8466
8467 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
8468 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
Wayne Boyer214777b2010-02-19 13:24:26 -08008469 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008470 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
8471 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008472 ipr_cmd->job_step = ipr_reset_block_config_access;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008473 }
8474
8475 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8476 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8477
8478 LEAVE;
8479 return IPR_RC_JOB_RETURN;
8480}
8481
8482/**
8483 * ipr_reset_ucode_download_done - Microcode download completion
8484 * @ipr_cmd: ipr command struct
8485 *
8486 * Description: This function unmaps the microcode download buffer.
8487 *
8488 * Return value:
8489 * IPR_RC_JOB_CONTINUE
8490 **/
8491static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
8492{
8493 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8494 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8495
Anton Blanchardd73341b2014-10-30 17:27:08 -05008496 dma_unmap_sg(&ioa_cfg->pdev->dev, sglist->scatterlist,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008497 sglist->num_sg, DMA_TO_DEVICE);
8498
8499 ipr_cmd->job_step = ipr_reset_alert;
8500 return IPR_RC_JOB_CONTINUE;
8501}
8502
8503/**
8504 * ipr_reset_ucode_download - Download microcode to the adapter
8505 * @ipr_cmd: ipr command struct
8506 *
8507 * Description: This function checks to see if it there is microcode
8508 * to download to the adapter. If there is, a download is performed.
8509 *
8510 * Return value:
8511 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8512 **/
8513static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
8514{
8515 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8516 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8517
8518 ENTER;
8519 ipr_cmd->job_step = ipr_reset_alert;
8520
8521 if (!sglist)
8522 return IPR_RC_JOB_CONTINUE;
8523
8524 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8525 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
8526 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
8527 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
8528 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
8529 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
8530 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
8531
Wayne Boyera32c0552010-02-19 13:23:36 -08008532 if (ioa_cfg->sis64)
8533 ipr_build_ucode_ioadl64(ipr_cmd, sglist);
8534 else
8535 ipr_build_ucode_ioadl(ipr_cmd, sglist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008536 ipr_cmd->job_step = ipr_reset_ucode_download_done;
8537
8538 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
8539 IPR_WRITE_BUFFER_TIMEOUT);
8540
8541 LEAVE;
8542 return IPR_RC_JOB_RETURN;
8543}
8544
8545/**
8546 * ipr_reset_shutdown_ioa - Shutdown the adapter
8547 * @ipr_cmd: ipr command struct
8548 *
8549 * Description: This function issues an adapter shutdown of the
8550 * specified type to the specified adapter as part of the
8551 * adapter reset job.
8552 *
8553 * Return value:
8554 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8555 **/
8556static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
8557{
8558 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8559 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
8560 unsigned long timeout;
8561 int rc = IPR_RC_JOB_CONTINUE;
8562
8563 ENTER;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008564 if (shutdown_type != IPR_SHUTDOWN_NONE &&
8565 !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008566 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8567 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8568 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
8569 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
8570
Brian Kingac09c342007-04-26 16:00:16 -05008571 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
8572 timeout = IPR_SHUTDOWN_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008573 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
8574 timeout = IPR_INTERNAL_TIMEOUT;
Brian Kingac09c342007-04-26 16:00:16 -05008575 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
8576 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008577 else
Brian Kingac09c342007-04-26 16:00:16 -05008578 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008579
8580 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
8581
8582 rc = IPR_RC_JOB_RETURN;
8583 ipr_cmd->job_step = ipr_reset_ucode_download;
8584 } else
8585 ipr_cmd->job_step = ipr_reset_alert;
8586
8587 LEAVE;
8588 return rc;
8589}
8590
8591/**
8592 * ipr_reset_ioa_job - Adapter reset job
8593 * @ipr_cmd: ipr command struct
8594 *
8595 * Description: This function is the job router for the adapter reset job.
8596 *
8597 * Return value:
8598 * none
8599 **/
8600static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
8601{
8602 u32 rc, ioasc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008603 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8604
8605 do {
Wayne Boyer96d21f02010-05-10 09:13:27 -07008606 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008607
8608 if (ioa_cfg->reset_cmd != ipr_cmd) {
8609 /*
8610 * We are doing nested adapter resets and this is
8611 * not the current reset job.
8612 */
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008613 list_add_tail(&ipr_cmd->queue,
8614 &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008615 return;
8616 }
8617
8618 if (IPR_IOASC_SENSE_KEY(ioasc)) {
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06008619 rc = ipr_cmd->job_step_failed(ipr_cmd);
8620 if (rc == IPR_RC_JOB_RETURN)
8621 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008622 }
8623
8624 ipr_reinit_ipr_cmnd(ipr_cmd);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06008625 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008626 rc = ipr_cmd->job_step(ipr_cmd);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03008627 } while (rc == IPR_RC_JOB_CONTINUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008628}
8629
8630/**
8631 * _ipr_initiate_ioa_reset - Initiate an adapter reset
8632 * @ioa_cfg: ioa config struct
8633 * @job_step: first job step of reset job
8634 * @shutdown_type: shutdown type
8635 *
8636 * Description: This function will initiate the reset of the given adapter
8637 * starting at the selected job step.
8638 * If the caller needs to wait on the completion of the reset,
8639 * the caller must sleep on the reset_wait_q.
8640 *
8641 * Return value:
8642 * none
8643 **/
8644static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8645 int (*job_step) (struct ipr_cmnd *),
8646 enum ipr_shutdown_type shutdown_type)
8647{
8648 struct ipr_cmnd *ipr_cmd;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008649 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008650
8651 ioa_cfg->in_reset_reload = 1;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008652 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8653 spin_lock(&ioa_cfg->hrrq[i]._lock);
8654 ioa_cfg->hrrq[i].allow_cmds = 0;
8655 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8656 }
8657 wmb();
Brian Kingbfae7822013-01-30 23:45:08 -06008658 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa)
8659 scsi_block_requests(ioa_cfg->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008660
8661 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
8662 ioa_cfg->reset_cmd = ipr_cmd;
8663 ipr_cmd->job_step = job_step;
8664 ipr_cmd->u.shutdown_type = shutdown_type;
8665
8666 ipr_reset_ioa_job(ipr_cmd);
8667}
8668
8669/**
8670 * ipr_initiate_ioa_reset - Initiate an adapter reset
8671 * @ioa_cfg: ioa config struct
8672 * @shutdown_type: shutdown type
8673 *
8674 * Description: This function will initiate the reset of the given adapter.
8675 * If the caller needs to wait on the completion of the reset,
8676 * the caller must sleep on the reset_wait_q.
8677 *
8678 * Return value:
8679 * none
8680 **/
8681static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8682 enum ipr_shutdown_type shutdown_type)
8683{
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008684 int i;
8685
8686 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008687 return;
8688
Brian King41e9a692011-09-21 08:51:11 -05008689 if (ioa_cfg->in_reset_reload) {
8690 if (ioa_cfg->sdt_state == GET_DUMP)
8691 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8692 else if (ioa_cfg->sdt_state == READ_DUMP)
8693 ioa_cfg->sdt_state = ABORT_DUMP;
8694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008695
8696 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
8697 dev_err(&ioa_cfg->pdev->dev,
8698 "IOA taken offline - error recovery failed\n");
8699
8700 ioa_cfg->reset_retries = 0;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008701 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8702 spin_lock(&ioa_cfg->hrrq[i]._lock);
8703 ioa_cfg->hrrq[i].ioa_is_dead = 1;
8704 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8705 }
8706 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07008707
8708 if (ioa_cfg->in_ioa_bringdown) {
8709 ioa_cfg->reset_cmd = NULL;
8710 ioa_cfg->in_reset_reload = 0;
8711 ipr_fail_all_ops(ioa_cfg);
8712 wake_up_all(&ioa_cfg->reset_wait_q);
8713
Brian Kingbfae7822013-01-30 23:45:08 -06008714 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
8715 spin_unlock_irq(ioa_cfg->host->host_lock);
8716 scsi_unblock_requests(ioa_cfg->host);
8717 spin_lock_irq(ioa_cfg->host->host_lock);
8718 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008719 return;
8720 } else {
8721 ioa_cfg->in_ioa_bringdown = 1;
8722 shutdown_type = IPR_SHUTDOWN_NONE;
8723 }
8724 }
8725
8726 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
8727 shutdown_type);
8728}
8729
8730/**
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008731 * ipr_reset_freeze - Hold off all I/O activity
8732 * @ipr_cmd: ipr command struct
8733 *
8734 * Description: If the PCI slot is frozen, hold off all I/O
8735 * activity; then, as soon as the slot is available again,
8736 * initiate an adapter reset.
8737 */
8738static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
8739{
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008740 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8741 int i;
8742
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008743 /* Disallow new interrupts, avoid loop */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008744 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8745 spin_lock(&ioa_cfg->hrrq[i]._lock);
8746 ioa_cfg->hrrq[i].allow_interrupts = 0;
8747 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8748 }
8749 wmb();
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008750 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008751 ipr_cmd->done = ipr_reset_ioa_job;
8752 return IPR_RC_JOB_RETURN;
8753}
8754
8755/**
Brian King6270e592014-01-21 12:16:41 -06008756 * ipr_pci_mmio_enabled - Called when MMIO has been re-enabled
8757 * @pdev: PCI device struct
8758 *
8759 * Description: This routine is called to tell us that the MMIO
8760 * access to the IOA has been restored
8761 */
8762static pci_ers_result_t ipr_pci_mmio_enabled(struct pci_dev *pdev)
8763{
8764 unsigned long flags = 0;
8765 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8766
8767 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8768 if (!ioa_cfg->probe_done)
8769 pci_save_state(pdev);
8770 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8771 return PCI_ERS_RESULT_NEED_RESET;
8772}
8773
8774/**
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008775 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
8776 * @pdev: PCI device struct
8777 *
8778 * Description: This routine is called to tell us that the PCI bus
8779 * is down. Can't do anything here, except put the device driver
8780 * into a holding pattern, waiting for the PCI bus to come back.
8781 */
8782static void ipr_pci_frozen(struct pci_dev *pdev)
8783{
8784 unsigned long flags = 0;
8785 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8786
8787 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Brian King6270e592014-01-21 12:16:41 -06008788 if (ioa_cfg->probe_done)
8789 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008790 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8791}
8792
8793/**
8794 * ipr_pci_slot_reset - Called when PCI slot has been reset.
8795 * @pdev: PCI device struct
8796 *
8797 * Description: This routine is called by the pci error recovery
8798 * code after the PCI slot has been reset, just before we
8799 * should resume normal operations.
8800 */
8801static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
8802{
8803 unsigned long flags = 0;
8804 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8805
8806 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Brian King6270e592014-01-21 12:16:41 -06008807 if (ioa_cfg->probe_done) {
8808 if (ioa_cfg->needs_warm_reset)
8809 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8810 else
8811 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
8812 IPR_SHUTDOWN_NONE);
8813 } else
8814 wake_up_all(&ioa_cfg->eeh_wait_q);
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008815 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8816 return PCI_ERS_RESULT_RECOVERED;
8817}
8818
8819/**
8820 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
8821 * @pdev: PCI device struct
8822 *
8823 * Description: This routine is called when the PCI bus has
8824 * permanently failed.
8825 */
8826static void ipr_pci_perm_failure(struct pci_dev *pdev)
8827{
8828 unsigned long flags = 0;
8829 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008830 int i;
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008831
8832 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Brian King6270e592014-01-21 12:16:41 -06008833 if (ioa_cfg->probe_done) {
8834 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
8835 ioa_cfg->sdt_state = ABORT_DUMP;
8836 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES - 1;
8837 ioa_cfg->in_ioa_bringdown = 1;
8838 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8839 spin_lock(&ioa_cfg->hrrq[i]._lock);
8840 ioa_cfg->hrrq[i].allow_cmds = 0;
8841 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8842 }
8843 wmb();
8844 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8845 } else
8846 wake_up_all(&ioa_cfg->eeh_wait_q);
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008847 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8848}
8849
8850/**
8851 * ipr_pci_error_detected - Called when a PCI error is detected.
8852 * @pdev: PCI device struct
8853 * @state: PCI channel state
8854 *
8855 * Description: Called when a PCI error is detected.
8856 *
8857 * Return value:
8858 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8859 */
8860static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
8861 pci_channel_state_t state)
8862{
8863 switch (state) {
8864 case pci_channel_io_frozen:
8865 ipr_pci_frozen(pdev);
Brian King6270e592014-01-21 12:16:41 -06008866 return PCI_ERS_RESULT_CAN_RECOVER;
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008867 case pci_channel_io_perm_failure:
8868 ipr_pci_perm_failure(pdev);
8869 return PCI_ERS_RESULT_DISCONNECT;
8870 break;
8871 default:
8872 break;
8873 }
8874 return PCI_ERS_RESULT_NEED_RESET;
8875}
8876
8877/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008878 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
8879 * @ioa_cfg: ioa cfg struct
8880 *
8881 * Description: This is the second phase of adapter intialization
8882 * This function takes care of initilizing the adapter to the point
8883 * where it can accept new commands.
8884
8885 * Return value:
Joe Perchesb1c11812008-02-03 17:28:22 +02008886 * 0 on success / -EIO on failure
Linus Torvalds1da177e2005-04-16 15:20:36 -07008887 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008888static int ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008889{
8890 int rc = 0;
8891 unsigned long host_lock_flags = 0;
8892
8893 ENTER;
8894 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8895 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
Brian King6270e592014-01-21 12:16:41 -06008896 ioa_cfg->probe_done = 1;
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06008897 if (ioa_cfg->needs_hard_reset) {
8898 ioa_cfg->needs_hard_reset = 0;
8899 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8900 } else
8901 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
8902 IPR_SHUTDOWN_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008903 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008904
8905 LEAVE;
8906 return rc;
8907}
8908
8909/**
8910 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
8911 * @ioa_cfg: ioa config struct
8912 *
8913 * Return value:
8914 * none
8915 **/
8916static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8917{
8918 int i;
8919
8920 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8921 if (ioa_cfg->ipr_cmnd_list[i])
Anton Blanchardd73341b2014-10-30 17:27:08 -05008922 dma_pool_free(ioa_cfg->ipr_cmd_pool,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008923 ioa_cfg->ipr_cmnd_list[i],
8924 ioa_cfg->ipr_cmnd_list_dma[i]);
8925
8926 ioa_cfg->ipr_cmnd_list[i] = NULL;
8927 }
8928
8929 if (ioa_cfg->ipr_cmd_pool)
Anton Blanchardd73341b2014-10-30 17:27:08 -05008930 dma_pool_destroy(ioa_cfg->ipr_cmd_pool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008931
Brian King89aad422012-03-14 21:20:10 -05008932 kfree(ioa_cfg->ipr_cmnd_list);
8933 kfree(ioa_cfg->ipr_cmnd_list_dma);
8934 ioa_cfg->ipr_cmnd_list = NULL;
8935 ioa_cfg->ipr_cmnd_list_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008936 ioa_cfg->ipr_cmd_pool = NULL;
8937}
8938
8939/**
8940 * ipr_free_mem - Frees memory allocated for an adapter
8941 * @ioa_cfg: ioa cfg struct
8942 *
8943 * Return value:
8944 * nothing
8945 **/
8946static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
8947{
8948 int i;
8949
8950 kfree(ioa_cfg->res_entries);
Anton Blanchardd73341b2014-10-30 17:27:08 -05008951 dma_free_coherent(&ioa_cfg->pdev->dev, sizeof(struct ipr_misc_cbs),
8952 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008953 ipr_free_cmd_blks(ioa_cfg);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008954
8955 for (i = 0; i < ioa_cfg->hrrq_num; i++)
Anton Blanchardd73341b2014-10-30 17:27:08 -05008956 dma_free_coherent(&ioa_cfg->pdev->dev,
8957 sizeof(u32) * ioa_cfg->hrrq[i].size,
8958 ioa_cfg->hrrq[i].host_rrq,
8959 ioa_cfg->hrrq[i].host_rrq_dma);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008960
Anton Blanchardd73341b2014-10-30 17:27:08 -05008961 dma_free_coherent(&ioa_cfg->pdev->dev, ioa_cfg->cfg_table_size,
8962 ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008963
8964 for (i = 0; i < IPR_NUM_HCAMS; i++) {
Anton Blanchardd73341b2014-10-30 17:27:08 -05008965 dma_free_coherent(&ioa_cfg->pdev->dev,
8966 sizeof(struct ipr_hostrcb),
8967 ioa_cfg->hostrcb[i],
8968 ioa_cfg->hostrcb_dma[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008969 }
8970
8971 ipr_free_dump(ioa_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008972 kfree(ioa_cfg->trace);
8973}
8974
8975/**
8976 * ipr_free_all_resources - Free all allocated resources for an adapter.
8977 * @ipr_cmd: ipr command struct
8978 *
8979 * This function frees all allocated resources for the
8980 * specified adapter.
8981 *
8982 * Return value:
8983 * none
8984 **/
8985static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
8986{
8987 struct pci_dev *pdev = ioa_cfg->pdev;
8988
8989 ENTER;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008990 if (ioa_cfg->intr_flag == IPR_USE_MSI ||
8991 ioa_cfg->intr_flag == IPR_USE_MSIX) {
8992 int i;
8993 for (i = 0; i < ioa_cfg->nvectors; i++)
8994 free_irq(ioa_cfg->vectors_info[i].vec,
8995 &ioa_cfg->hrrq[i]);
8996 } else
8997 free_irq(pdev->irq, &ioa_cfg->hrrq[0]);
8998
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008999 if (ioa_cfg->intr_flag == IPR_USE_MSI) {
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009000 pci_disable_msi(pdev);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009001 ioa_cfg->intr_flag &= ~IPR_USE_MSI;
9002 } else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009003 pci_disable_msix(pdev);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009004 ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
9005 }
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009006
Linus Torvalds1da177e2005-04-16 15:20:36 -07009007 iounmap(ioa_cfg->hdw_dma_regs);
9008 pci_release_regions(pdev);
9009 ipr_free_mem(ioa_cfg);
9010 scsi_host_put(ioa_cfg->host);
9011 pci_disable_device(pdev);
9012 LEAVE;
9013}
9014
9015/**
9016 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
9017 * @ioa_cfg: ioa config struct
9018 *
9019 * Return value:
9020 * 0 on success / -ENOMEM on allocation failure
9021 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009022static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009023{
9024 struct ipr_cmnd *ipr_cmd;
9025 struct ipr_ioarcb *ioarcb;
9026 dma_addr_t dma_addr;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009027 int i, entries_each_hrrq, hrrq_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009028
Anton Blanchardd73341b2014-10-30 17:27:08 -05009029 ioa_cfg->ipr_cmd_pool = dma_pool_create(IPR_NAME, &ioa_cfg->pdev->dev,
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03009030 sizeof(struct ipr_cmnd), 512, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009031
9032 if (!ioa_cfg->ipr_cmd_pool)
9033 return -ENOMEM;
9034
Brian King89aad422012-03-14 21:20:10 -05009035 ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
9036 ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
9037
9038 if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
9039 ipr_free_cmd_blks(ioa_cfg);
9040 return -ENOMEM;
9041 }
9042
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009043 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9044 if (ioa_cfg->hrrq_num > 1) {
9045 if (i == 0) {
9046 entries_each_hrrq = IPR_NUM_INTERNAL_CMD_BLKS;
9047 ioa_cfg->hrrq[i].min_cmd_id = 0;
9048 ioa_cfg->hrrq[i].max_cmd_id =
9049 (entries_each_hrrq - 1);
9050 } else {
9051 entries_each_hrrq =
9052 IPR_NUM_BASE_CMD_BLKS/
9053 (ioa_cfg->hrrq_num - 1);
9054 ioa_cfg->hrrq[i].min_cmd_id =
9055 IPR_NUM_INTERNAL_CMD_BLKS +
9056 (i - 1) * entries_each_hrrq;
9057 ioa_cfg->hrrq[i].max_cmd_id =
9058 (IPR_NUM_INTERNAL_CMD_BLKS +
9059 i * entries_each_hrrq - 1);
9060 }
9061 } else {
9062 entries_each_hrrq = IPR_NUM_CMD_BLKS;
9063 ioa_cfg->hrrq[i].min_cmd_id = 0;
9064 ioa_cfg->hrrq[i].max_cmd_id = (entries_each_hrrq - 1);
9065 }
9066 ioa_cfg->hrrq[i].size = entries_each_hrrq;
9067 }
9068
9069 BUG_ON(ioa_cfg->hrrq_num == 0);
9070
9071 i = IPR_NUM_CMD_BLKS -
9072 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id - 1;
9073 if (i > 0) {
9074 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].size += i;
9075 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id += i;
9076 }
9077
Linus Torvalds1da177e2005-04-16 15:20:36 -07009078 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
Anton Blanchardd73341b2014-10-30 17:27:08 -05009079 ipr_cmd = dma_pool_alloc(ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009080
9081 if (!ipr_cmd) {
9082 ipr_free_cmd_blks(ioa_cfg);
9083 return -ENOMEM;
9084 }
9085
9086 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
9087 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
9088 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
9089
9090 ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08009091 ipr_cmd->dma_addr = dma_addr;
9092 if (ioa_cfg->sis64)
9093 ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
9094 else
9095 ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
9096
Linus Torvalds1da177e2005-04-16 15:20:36 -07009097 ioarcb->host_response_handle = cpu_to_be32(i << 2);
Wayne Boyera32c0552010-02-19 13:23:36 -08009098 if (ioa_cfg->sis64) {
9099 ioarcb->u.sis64_addr_data.data_ioadl_addr =
9100 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
9101 ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
Wayne Boyer96d21f02010-05-10 09:13:27 -07009102 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
Wayne Boyera32c0552010-02-19 13:23:36 -08009103 } else {
9104 ioarcb->write_ioadl_addr =
9105 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
9106 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
9107 ioarcb->ioasa_host_pci_addr =
Wayne Boyer96d21f02010-05-10 09:13:27 -07009108 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
Wayne Boyera32c0552010-02-19 13:23:36 -08009109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009110 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
9111 ipr_cmd->cmd_index = i;
9112 ipr_cmd->ioa_cfg = ioa_cfg;
9113 ipr_cmd->sense_buffer_dma = dma_addr +
9114 offsetof(struct ipr_cmnd, sense_buffer);
9115
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009116 ipr_cmd->ioarcb.cmd_pkt.hrrq_id = hrrq_id;
9117 ipr_cmd->hrrq = &ioa_cfg->hrrq[hrrq_id];
9118 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
9119 if (i >= ioa_cfg->hrrq[hrrq_id].max_cmd_id)
9120 hrrq_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009121 }
9122
9123 return 0;
9124}
9125
9126/**
9127 * ipr_alloc_mem - Allocate memory for an adapter
9128 * @ioa_cfg: ioa config struct
9129 *
9130 * Return value:
9131 * 0 on success / non-zero for error
9132 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009133static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009134{
9135 struct pci_dev *pdev = ioa_cfg->pdev;
9136 int i, rc = -ENOMEM;
9137
9138 ENTER;
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06009139 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08009140 ioa_cfg->max_devs_supported, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009141
9142 if (!ioa_cfg->res_entries)
9143 goto out;
9144
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08009145 for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07009146 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08009147 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
9148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009149
Anton Blanchardd73341b2014-10-30 17:27:08 -05009150 ioa_cfg->vpd_cbs = dma_alloc_coherent(&pdev->dev,
9151 sizeof(struct ipr_misc_cbs),
9152 &ioa_cfg->vpd_cbs_dma,
9153 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009154
9155 if (!ioa_cfg->vpd_cbs)
9156 goto out_free_res_entries;
9157
9158 if (ipr_alloc_cmd_blks(ioa_cfg))
9159 goto out_free_vpd_cbs;
9160
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009161 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
Anton Blanchardd73341b2014-10-30 17:27:08 -05009162 ioa_cfg->hrrq[i].host_rrq = dma_alloc_coherent(&pdev->dev,
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009163 sizeof(u32) * ioa_cfg->hrrq[i].size,
Anton Blanchardd73341b2014-10-30 17:27:08 -05009164 &ioa_cfg->hrrq[i].host_rrq_dma,
9165 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009166
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009167 if (!ioa_cfg->hrrq[i].host_rrq) {
9168 while (--i > 0)
Anton Blanchardd73341b2014-10-30 17:27:08 -05009169 dma_free_coherent(&pdev->dev,
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009170 sizeof(u32) * ioa_cfg->hrrq[i].size,
9171 ioa_cfg->hrrq[i].host_rrq,
9172 ioa_cfg->hrrq[i].host_rrq_dma);
9173 goto out_ipr_free_cmd_blocks;
9174 }
9175 ioa_cfg->hrrq[i].ioa_cfg = ioa_cfg;
9176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009177
Anton Blanchardd73341b2014-10-30 17:27:08 -05009178 ioa_cfg->u.cfg_table = dma_alloc_coherent(&pdev->dev,
9179 ioa_cfg->cfg_table_size,
9180 &ioa_cfg->cfg_table_dma,
9181 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009182
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08009183 if (!ioa_cfg->u.cfg_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009184 goto out_free_host_rrq;
9185
9186 for (i = 0; i < IPR_NUM_HCAMS; i++) {
Anton Blanchardd73341b2014-10-30 17:27:08 -05009187 ioa_cfg->hostrcb[i] = dma_alloc_coherent(&pdev->dev,
9188 sizeof(struct ipr_hostrcb),
9189 &ioa_cfg->hostrcb_dma[i],
9190 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009191
9192 if (!ioa_cfg->hostrcb[i])
9193 goto out_free_hostrcb_dma;
9194
9195 ioa_cfg->hostrcb[i]->hostrcb_dma =
9196 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
Brian King49dc6a12006-11-21 10:28:35 -06009197 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009198 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
9199 }
9200
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06009201 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009202 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
9203
9204 if (!ioa_cfg->trace)
9205 goto out_free_hostrcb_dma;
9206
Linus Torvalds1da177e2005-04-16 15:20:36 -07009207 rc = 0;
9208out:
9209 LEAVE;
9210 return rc;
9211
9212out_free_hostrcb_dma:
9213 while (i-- > 0) {
Anton Blanchardd73341b2014-10-30 17:27:08 -05009214 dma_free_coherent(&pdev->dev, sizeof(struct ipr_hostrcb),
9215 ioa_cfg->hostrcb[i],
9216 ioa_cfg->hostrcb_dma[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009217 }
Anton Blanchardd73341b2014-10-30 17:27:08 -05009218 dma_free_coherent(&pdev->dev, ioa_cfg->cfg_table_size,
9219 ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009220out_free_host_rrq:
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009221 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
Anton Blanchardd73341b2014-10-30 17:27:08 -05009222 dma_free_coherent(&pdev->dev,
9223 sizeof(u32) * ioa_cfg->hrrq[i].size,
9224 ioa_cfg->hrrq[i].host_rrq,
9225 ioa_cfg->hrrq[i].host_rrq_dma);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009227out_ipr_free_cmd_blocks:
9228 ipr_free_cmd_blks(ioa_cfg);
9229out_free_vpd_cbs:
Anton Blanchardd73341b2014-10-30 17:27:08 -05009230 dma_free_coherent(&pdev->dev, sizeof(struct ipr_misc_cbs),
9231 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009232out_free_res_entries:
9233 kfree(ioa_cfg->res_entries);
9234 goto out;
9235}
9236
9237/**
9238 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
9239 * @ioa_cfg: ioa config struct
9240 *
9241 * Return value:
9242 * none
9243 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009244static void ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009245{
9246 int i;
9247
9248 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
9249 ioa_cfg->bus_attr[i].bus = i;
9250 ioa_cfg->bus_attr[i].qas_enabled = 0;
9251 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
9252 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
9253 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
9254 else
9255 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
9256 }
9257}
9258
9259/**
Brian King6270e592014-01-21 12:16:41 -06009260 * ipr_init_regs - Initialize IOA registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07009261 * @ioa_cfg: ioa config struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07009262 *
9263 * Return value:
Brian King6270e592014-01-21 12:16:41 -06009264 * none
Linus Torvalds1da177e2005-04-16 15:20:36 -07009265 **/
Brian King6270e592014-01-21 12:16:41 -06009266static void ipr_init_regs(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009267{
9268 const struct ipr_interrupt_offsets *p;
9269 struct ipr_interrupts *t;
9270 void __iomem *base;
9271
Linus Torvalds1da177e2005-04-16 15:20:36 -07009272 p = &ioa_cfg->chip_cfg->regs;
9273 t = &ioa_cfg->regs;
9274 base = ioa_cfg->hdw_dma_regs;
9275
9276 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
9277 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009278 t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009279 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009280 t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009281 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009282 t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009283 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009284 t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009285 t->ioarrin_reg = base + p->ioarrin_reg;
9286 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009287 t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009288 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009289 t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009290 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009291 t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
Wayne Boyerdcbad002010-02-19 13:24:14 -08009292
9293 if (ioa_cfg->sis64) {
Wayne Boyer214777b2010-02-19 13:24:26 -08009294 t->init_feedback_reg = base + p->init_feedback_reg;
Wayne Boyerdcbad002010-02-19 13:24:14 -08009295 t->dump_addr_reg = base + p->dump_addr_reg;
9296 t->dump_data_reg = base + p->dump_data_reg;
Wayne Boyer8701f182010-06-04 10:26:50 -07009297 t->endian_swap_reg = base + p->endian_swap_reg;
Wayne Boyerdcbad002010-02-19 13:24:14 -08009298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009299}
9300
9301/**
Brian King6270e592014-01-21 12:16:41 -06009302 * ipr_init_ioa_cfg - Initialize IOA config struct
9303 * @ioa_cfg: ioa config struct
9304 * @host: scsi host struct
9305 * @pdev: PCI dev struct
9306 *
9307 * Return value:
9308 * none
9309 **/
9310static void ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
9311 struct Scsi_Host *host, struct pci_dev *pdev)
9312{
9313 int i;
9314
9315 ioa_cfg->host = host;
9316 ioa_cfg->pdev = pdev;
9317 ioa_cfg->log_level = ipr_log_level;
9318 ioa_cfg->doorbell = IPR_DOORBELL;
9319 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
9320 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
9321 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
9322 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
9323 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
9324 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
9325
9326 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
9327 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
9328 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
9329 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
9330 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
9331 init_waitqueue_head(&ioa_cfg->reset_wait_q);
9332 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9333 init_waitqueue_head(&ioa_cfg->eeh_wait_q);
9334 ioa_cfg->sdt_state = INACTIVE;
9335
9336 ipr_initialize_bus_attr(ioa_cfg);
9337 ioa_cfg->max_devs_supported = ipr_max_devs;
9338
9339 if (ioa_cfg->sis64) {
9340 host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
9341 host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
9342 if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
9343 ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
9344 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
9345 + ((sizeof(struct ipr_config_table_entry64)
9346 * ioa_cfg->max_devs_supported)));
9347 } else {
9348 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
9349 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
9350 if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
9351 ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
9352 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
9353 + ((sizeof(struct ipr_config_table_entry)
9354 * ioa_cfg->max_devs_supported)));
9355 }
9356
Brian Kingf688f962014-12-02 12:47:37 -06009357 host->max_channel = IPR_VSET_BUS;
Brian King6270e592014-01-21 12:16:41 -06009358 host->unique_id = host->host_no;
9359 host->max_cmd_len = IPR_MAX_CDB_LEN;
9360 host->can_queue = ioa_cfg->max_cmds;
9361 pci_set_drvdata(pdev, ioa_cfg);
9362
9363 for (i = 0; i < ARRAY_SIZE(ioa_cfg->hrrq); i++) {
9364 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_free_q);
9365 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_pending_q);
9366 spin_lock_init(&ioa_cfg->hrrq[i]._lock);
9367 if (i == 0)
9368 ioa_cfg->hrrq[i].lock = ioa_cfg->host->host_lock;
9369 else
9370 ioa_cfg->hrrq[i].lock = &ioa_cfg->hrrq[i]._lock;
9371 }
9372}
9373
9374/**
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009375 * ipr_get_chip_info - Find adapter chip information
Linus Torvalds1da177e2005-04-16 15:20:36 -07009376 * @dev_id: PCI device id struct
9377 *
9378 * Return value:
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009379 * ptr to chip information on success / NULL on failure
Linus Torvalds1da177e2005-04-16 15:20:36 -07009380 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009381static const struct ipr_chip_t *
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009382ipr_get_chip_info(const struct pci_device_id *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009383{
9384 int i;
9385
Linus Torvalds1da177e2005-04-16 15:20:36 -07009386 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
9387 if (ipr_chip[i].vendor == dev_id->vendor &&
9388 ipr_chip[i].device == dev_id->device)
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009389 return &ipr_chip[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07009390 return NULL;
9391}
9392
Brian King6270e592014-01-21 12:16:41 -06009393/**
9394 * ipr_wait_for_pci_err_recovery - Wait for any PCI error recovery to complete
9395 * during probe time
9396 * @ioa_cfg: ioa config struct
9397 *
9398 * Return value:
9399 * None
9400 **/
9401static void ipr_wait_for_pci_err_recovery(struct ipr_ioa_cfg *ioa_cfg)
9402{
9403 struct pci_dev *pdev = ioa_cfg->pdev;
9404
9405 if (pci_channel_offline(pdev)) {
9406 wait_event_timeout(ioa_cfg->eeh_wait_q,
9407 !pci_channel_offline(pdev),
9408 IPR_PCI_ERROR_RECOVERY_TIMEOUT);
9409 pci_restore_state(pdev);
9410 }
9411}
9412
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009413static int ipr_enable_msix(struct ipr_ioa_cfg *ioa_cfg)
9414{
9415 struct msix_entry entries[IPR_MAX_MSIX_VECTORS];
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009416 int i, vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009417
9418 for (i = 0; i < ARRAY_SIZE(entries); ++i)
9419 entries[i].entry = i;
9420
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009421 vectors = pci_enable_msix_range(ioa_cfg->pdev,
9422 entries, 1, ipr_number_of_msix);
9423 if (vectors < 0) {
Brian King6270e592014-01-21 12:16:41 -06009424 ipr_wait_for_pci_err_recovery(ioa_cfg);
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009425 return vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009426 }
9427
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009428 for (i = 0; i < vectors; i++)
9429 ioa_cfg->vectors_info[i].vec = entries[i].vector;
9430 ioa_cfg->nvectors = vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009431
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009432 return 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009433}
9434
9435static int ipr_enable_msi(struct ipr_ioa_cfg *ioa_cfg)
9436{
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009437 int i, vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009438
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009439 vectors = pci_enable_msi_range(ioa_cfg->pdev, 1, ipr_number_of_msix);
9440 if (vectors < 0) {
Brian King6270e592014-01-21 12:16:41 -06009441 ipr_wait_for_pci_err_recovery(ioa_cfg);
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009442 return vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009443 }
9444
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009445 for (i = 0; i < vectors; i++)
9446 ioa_cfg->vectors_info[i].vec = ioa_cfg->pdev->irq + i;
9447 ioa_cfg->nvectors = vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009448
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009449 return 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009450}
9451
9452static void name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
9453{
9454 int vec_idx, n = sizeof(ioa_cfg->vectors_info[0].desc) - 1;
9455
9456 for (vec_idx = 0; vec_idx < ioa_cfg->nvectors; vec_idx++) {
9457 snprintf(ioa_cfg->vectors_info[vec_idx].desc, n,
9458 "host%d-%d", ioa_cfg->host->host_no, vec_idx);
9459 ioa_cfg->vectors_info[vec_idx].
9460 desc[strlen(ioa_cfg->vectors_info[vec_idx].desc)] = 0;
9461 }
9462}
9463
9464static int ipr_request_other_msi_irqs(struct ipr_ioa_cfg *ioa_cfg)
9465{
9466 int i, rc;
9467
9468 for (i = 1; i < ioa_cfg->nvectors; i++) {
9469 rc = request_irq(ioa_cfg->vectors_info[i].vec,
9470 ipr_isr_mhrrq,
9471 0,
9472 ioa_cfg->vectors_info[i].desc,
9473 &ioa_cfg->hrrq[i]);
9474 if (rc) {
9475 while (--i >= 0)
9476 free_irq(ioa_cfg->vectors_info[i].vec,
9477 &ioa_cfg->hrrq[i]);
9478 return rc;
9479 }
9480 }
9481 return 0;
9482}
9483
Linus Torvalds1da177e2005-04-16 15:20:36 -07009484/**
Wayne Boyer95fecd92009-06-16 15:13:28 -07009485 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
9486 * @pdev: PCI device struct
9487 *
9488 * Description: Simply set the msi_received flag to 1 indicating that
9489 * Message Signaled Interrupts are supported.
9490 *
9491 * Return value:
9492 * 0 on success / non-zero on failure
9493 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009494static irqreturn_t ipr_test_intr(int irq, void *devp)
Wayne Boyer95fecd92009-06-16 15:13:28 -07009495{
9496 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
9497 unsigned long lock_flags = 0;
9498 irqreturn_t rc = IRQ_HANDLED;
9499
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009500 dev_info(&ioa_cfg->pdev->dev, "Received IRQ : %d\n", irq);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009501 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9502
9503 ioa_cfg->msi_received = 1;
9504 wake_up(&ioa_cfg->msi_wait_q);
9505
9506 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9507 return rc;
9508}
9509
9510/**
9511 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
9512 * @pdev: PCI device struct
9513 *
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009514 * Description: The return value from pci_enable_msi_range() can not always be
Wayne Boyer95fecd92009-06-16 15:13:28 -07009515 * trusted. This routine sets up and initiates a test interrupt to determine
9516 * if the interrupt is received via the ipr_test_intr() service routine.
9517 * If the tests fails, the driver will fall back to LSI.
9518 *
9519 * Return value:
9520 * 0 on success / non-zero on failure
9521 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009522static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
Wayne Boyer95fecd92009-06-16 15:13:28 -07009523{
9524 int rc;
9525 volatile u32 int_reg;
9526 unsigned long lock_flags = 0;
9527
9528 ENTER;
9529
9530 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9531 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9532 ioa_cfg->msi_received = 0;
9533 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
Wayne Boyer214777b2010-02-19 13:24:26 -08009534 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009535 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
9536 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9537
wenxiong@linux.vnet.ibm.comf19799f2013-02-27 12:37:45 -06009538 if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9539 rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
9540 else
9541 rc = request_irq(pdev->irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009542 if (rc) {
9543 dev_err(&pdev->dev, "Can not assign irq %d\n", pdev->irq);
9544 return rc;
9545 } else if (ipr_debug)
9546 dev_info(&pdev->dev, "IRQ assigned: %d\n", pdev->irq);
9547
Wayne Boyer214777b2010-02-19 13:24:26 -08009548 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009549 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
9550 wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009551 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009552 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9553
Wayne Boyer95fecd92009-06-16 15:13:28 -07009554 if (!ioa_cfg->msi_received) {
9555 /* MSI test failed */
9556 dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
9557 rc = -EOPNOTSUPP;
9558 } else if (ipr_debug)
9559 dev_info(&pdev->dev, "MSI test succeeded.\n");
9560
9561 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9562
wenxiong@linux.vnet.ibm.comf19799f2013-02-27 12:37:45 -06009563 if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9564 free_irq(ioa_cfg->vectors_info[0].vec, ioa_cfg);
9565 else
9566 free_irq(pdev->irq, ioa_cfg);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009567
9568 LEAVE;
9569
9570 return rc;
9571}
9572
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009573 /* ipr_probe_ioa - Allocates memory and does first stage of initialization
Linus Torvalds1da177e2005-04-16 15:20:36 -07009574 * @pdev: PCI device struct
9575 * @dev_id: PCI device id struct
9576 *
9577 * Return value:
9578 * 0 on success / non-zero on failure
9579 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009580static int ipr_probe_ioa(struct pci_dev *pdev,
9581 const struct pci_device_id *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009582{
9583 struct ipr_ioa_cfg *ioa_cfg;
9584 struct Scsi_Host *host;
9585 unsigned long ipr_regs_pci;
9586 void __iomem *ipr_regs;
Eric Sesterhenna2a65a32006-09-25 16:59:07 -07009587 int rc = PCIBIOS_SUCCESSFUL;
Brian King473b1e82007-05-02 10:44:11 -05009588 volatile u32 mask, uproc, interrupts;
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009589 unsigned long lock_flags, driver_lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009590
9591 ENTER;
9592
Linus Torvalds1da177e2005-04-16 15:20:36 -07009593 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009594 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
9595
9596 if (!host) {
9597 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
9598 rc = -ENOMEM;
Brian King6270e592014-01-21 12:16:41 -06009599 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009600 }
9601
9602 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
9603 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
Dan Williams8d8e7d132012-07-09 21:06:08 -07009604 ata_host_init(&ioa_cfg->ata_host, &pdev->dev, &ipr_sata_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009605
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009606 ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009607
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009608 if (!ioa_cfg->ipr_chip) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07009609 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
9610 dev_id->vendor, dev_id->device);
9611 goto out_scsi_host_put;
9612 }
9613
Wayne Boyera32c0552010-02-19 13:23:36 -08009614 /* set SIS 32 or SIS 64 */
9615 ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009616 ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
Brian King7dd21302012-03-14 21:20:08 -05009617 ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
Brian King89aad422012-03-14 21:20:10 -05009618 ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009619
Brian King5469cb52007-03-29 12:42:40 -05009620 if (ipr_transop_timeout)
9621 ioa_cfg->transop_timeout = ipr_transop_timeout;
9622 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
9623 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
9624 else
9625 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
9626
Auke Kok44c10132007-06-08 15:46:36 -07009627 ioa_cfg->revid = pdev->revision;
Brian King463fc692007-05-07 17:09:05 -05009628
Brian King6270e592014-01-21 12:16:41 -06009629 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
9630
Linus Torvalds1da177e2005-04-16 15:20:36 -07009631 ipr_regs_pci = pci_resource_start(pdev, 0);
9632
9633 rc = pci_request_regions(pdev, IPR_NAME);
9634 if (rc < 0) {
9635 dev_err(&pdev->dev,
9636 "Couldn't register memory range of registers\n");
9637 goto out_scsi_host_put;
9638 }
9639
Brian King6270e592014-01-21 12:16:41 -06009640 rc = pci_enable_device(pdev);
9641
9642 if (rc || pci_channel_offline(pdev)) {
9643 if (pci_channel_offline(pdev)) {
9644 ipr_wait_for_pci_err_recovery(ioa_cfg);
9645 rc = pci_enable_device(pdev);
9646 }
9647
9648 if (rc) {
9649 dev_err(&pdev->dev, "Cannot enable adapter\n");
9650 ipr_wait_for_pci_err_recovery(ioa_cfg);
9651 goto out_release_regions;
9652 }
9653 }
9654
Arjan van de Ven25729a72008-09-28 16:18:02 -07009655 ipr_regs = pci_ioremap_bar(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009656
9657 if (!ipr_regs) {
9658 dev_err(&pdev->dev,
9659 "Couldn't map memory range of registers\n");
9660 rc = -ENOMEM;
Brian King6270e592014-01-21 12:16:41 -06009661 goto out_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009662 }
9663
9664 ioa_cfg->hdw_dma_regs = ipr_regs;
9665 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
9666 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
9667
Brian King6270e592014-01-21 12:16:41 -06009668 ipr_init_regs(ioa_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009669
Wayne Boyera32c0552010-02-19 13:23:36 -08009670 if (ioa_cfg->sis64) {
Anton Blanchard869404c2014-10-30 17:27:09 -05009671 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Wayne Boyera32c0552010-02-19 13:23:36 -08009672 if (rc < 0) {
Anton Blanchard869404c2014-10-30 17:27:09 -05009673 dev_dbg(&pdev->dev, "Failed to set 64 bit DMA mask\n");
9674 rc = dma_set_mask_and_coherent(&pdev->dev,
9675 DMA_BIT_MASK(32));
Wayne Boyera32c0552010-02-19 13:23:36 -08009676 }
Wayne Boyera32c0552010-02-19 13:23:36 -08009677 } else
Anton Blanchard869404c2014-10-30 17:27:09 -05009678 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Wayne Boyera32c0552010-02-19 13:23:36 -08009679
Linus Torvalds1da177e2005-04-16 15:20:36 -07009680 if (rc < 0) {
Anton Blanchard869404c2014-10-30 17:27:09 -05009681 dev_err(&pdev->dev, "Failed to set DMA mask\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07009682 goto cleanup_nomem;
9683 }
9684
9685 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
9686 ioa_cfg->chip_cfg->cache_line_size);
9687
9688 if (rc != PCIBIOS_SUCCESSFUL) {
9689 dev_err(&pdev->dev, "Write of cache line size failed\n");
Brian King6270e592014-01-21 12:16:41 -06009690 ipr_wait_for_pci_err_recovery(ioa_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009691 rc = -EIO;
9692 goto cleanup_nomem;
9693 }
9694
Brian King6270e592014-01-21 12:16:41 -06009695 /* Issue MMIO read to ensure card is not in EEH */
9696 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg);
9697 ipr_wait_for_pci_err_recovery(ioa_cfg);
9698
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009699 if (ipr_number_of_msix > IPR_MAX_MSIX_VECTORS) {
9700 dev_err(&pdev->dev, "The max number of MSIX is %d\n",
9701 IPR_MAX_MSIX_VECTORS);
9702 ipr_number_of_msix = IPR_MAX_MSIX_VECTORS;
9703 }
9704
9705 if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009706 ipr_enable_msix(ioa_cfg) == 0)
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009707 ioa_cfg->intr_flag = IPR_USE_MSIX;
9708 else if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009709 ipr_enable_msi(ioa_cfg) == 0)
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009710 ioa_cfg->intr_flag = IPR_USE_MSI;
9711 else {
9712 ioa_cfg->intr_flag = IPR_USE_LSI;
9713 ioa_cfg->nvectors = 1;
9714 dev_info(&pdev->dev, "Cannot enable MSI.\n");
9715 }
9716
Brian King6270e592014-01-21 12:16:41 -06009717 pci_set_master(pdev);
9718
9719 if (pci_channel_offline(pdev)) {
9720 ipr_wait_for_pci_err_recovery(ioa_cfg);
9721 pci_set_master(pdev);
9722 if (pci_channel_offline(pdev)) {
9723 rc = -EIO;
9724 goto out_msi_disable;
9725 }
9726 }
9727
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009728 if (ioa_cfg->intr_flag == IPR_USE_MSI ||
9729 ioa_cfg->intr_flag == IPR_USE_MSIX) {
Wayne Boyer95fecd92009-06-16 15:13:28 -07009730 rc = ipr_test_msi(ioa_cfg, pdev);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009731 if (rc == -EOPNOTSUPP) {
Brian King6270e592014-01-21 12:16:41 -06009732 ipr_wait_for_pci_err_recovery(ioa_cfg);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009733 if (ioa_cfg->intr_flag == IPR_USE_MSI) {
9734 ioa_cfg->intr_flag &= ~IPR_USE_MSI;
9735 pci_disable_msi(pdev);
9736 } else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
9737 ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
9738 pci_disable_msix(pdev);
9739 }
9740
9741 ioa_cfg->intr_flag = IPR_USE_LSI;
9742 ioa_cfg->nvectors = 1;
9743 }
Wayne Boyer95fecd92009-06-16 15:13:28 -07009744 else if (rc)
9745 goto out_msi_disable;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009746 else {
9747 if (ioa_cfg->intr_flag == IPR_USE_MSI)
9748 dev_info(&pdev->dev,
9749 "Request for %d MSIs succeeded with starting IRQ: %d\n",
9750 ioa_cfg->nvectors, pdev->irq);
9751 else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9752 dev_info(&pdev->dev,
9753 "Request for %d MSIXs succeeded.",
9754 ioa_cfg->nvectors);
9755 }
9756 }
9757
9758 ioa_cfg->hrrq_num = min3(ioa_cfg->nvectors,
9759 (unsigned int)num_online_cpus(),
9760 (unsigned int)IPR_MAX_HRRQ_NUM);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009761
Linus Torvalds1da177e2005-04-16 15:20:36 -07009762 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
Julia Lawallf170c682011-07-11 14:08:25 -07009763 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009764
9765 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
Julia Lawallf170c682011-07-11 14:08:25 -07009766 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009767
9768 rc = ipr_alloc_mem(ioa_cfg);
9769 if (rc < 0) {
9770 dev_err(&pdev->dev,
9771 "Couldn't allocate enough memory for device driver!\n");
Julia Lawallf170c682011-07-11 14:08:25 -07009772 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009773 }
9774
Brian King6270e592014-01-21 12:16:41 -06009775 /* Save away PCI config space for use following IOA reset */
9776 rc = pci_save_state(pdev);
9777
9778 if (rc != PCIBIOS_SUCCESSFUL) {
9779 dev_err(&pdev->dev, "Failed to save PCI config space\n");
9780 rc = -EIO;
9781 goto cleanup_nolog;
9782 }
9783
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06009784 /*
9785 * If HRRQ updated interrupt is not masked, or reset alert is set,
9786 * the card is in an unknown state and needs a hard reset
9787 */
Wayne Boyer214777b2010-02-19 13:24:26 -08009788 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
9789 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
9790 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06009791 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
9792 ioa_cfg->needs_hard_reset = 1;
Anton Blanchard5d7c20b2011-08-01 19:43:45 +10009793 if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
Brian King473b1e82007-05-02 10:44:11 -05009794 ioa_cfg->needs_hard_reset = 1;
9795 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
9796 ioa_cfg->ioa_unit_checked = 1;
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06009797
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009798 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009799 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009800 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009801
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009802 if (ioa_cfg->intr_flag == IPR_USE_MSI
9803 || ioa_cfg->intr_flag == IPR_USE_MSIX) {
9804 name_msi_vectors(ioa_cfg);
9805 rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_isr,
9806 0,
9807 ioa_cfg->vectors_info[0].desc,
9808 &ioa_cfg->hrrq[0]);
9809 if (!rc)
9810 rc = ipr_request_other_msi_irqs(ioa_cfg);
9811 } else {
9812 rc = request_irq(pdev->irq, ipr_isr,
9813 IRQF_SHARED,
9814 IPR_NAME, &ioa_cfg->hrrq[0]);
9815 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009816 if (rc) {
9817 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
9818 pdev->irq, rc);
9819 goto cleanup_nolog;
9820 }
9821
Brian King463fc692007-05-07 17:09:05 -05009822 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
9823 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
9824 ioa_cfg->needs_warm_reset = 1;
9825 ioa_cfg->reset = ipr_reset_slot_reset;
9826 } else
9827 ioa_cfg->reset = ipr_reset_start_bist;
9828
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009829 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009830 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009831 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009832
9833 LEAVE;
9834out:
9835 return rc;
9836
9837cleanup_nolog:
9838 ipr_free_mem(ioa_cfg);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009839out_msi_disable:
Brian King6270e592014-01-21 12:16:41 -06009840 ipr_wait_for_pci_err_recovery(ioa_cfg);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009841 if (ioa_cfg->intr_flag == IPR_USE_MSI)
9842 pci_disable_msi(pdev);
9843 else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9844 pci_disable_msix(pdev);
Julia Lawallf170c682011-07-11 14:08:25 -07009845cleanup_nomem:
9846 iounmap(ipr_regs);
Brian King6270e592014-01-21 12:16:41 -06009847out_disable:
9848 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009849out_release_regions:
9850 pci_release_regions(pdev);
9851out_scsi_host_put:
9852 scsi_host_put(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009853 goto out;
9854}
9855
9856/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07009857 * ipr_initiate_ioa_bringdown - Bring down an adapter
9858 * @ioa_cfg: ioa config struct
9859 * @shutdown_type: shutdown type
9860 *
9861 * Description: This function will initiate bringing down the adapter.
9862 * This consists of issuing an IOA shutdown to the adapter
9863 * to flush the cache, and running BIST.
9864 * If the caller needs to wait on the completion of the reset,
9865 * the caller must sleep on the reset_wait_q.
9866 *
9867 * Return value:
9868 * none
9869 **/
9870static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
9871 enum ipr_shutdown_type shutdown_type)
9872{
9873 ENTER;
9874 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
9875 ioa_cfg->sdt_state = ABORT_DUMP;
9876 ioa_cfg->reset_retries = 0;
9877 ioa_cfg->in_ioa_bringdown = 1;
9878 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
9879 LEAVE;
9880}
9881
9882/**
9883 * __ipr_remove - Remove a single adapter
9884 * @pdev: pci device struct
9885 *
9886 * Adapter hot plug remove entry point.
9887 *
9888 * Return value:
9889 * none
9890 **/
9891static void __ipr_remove(struct pci_dev *pdev)
9892{
9893 unsigned long host_lock_flags = 0;
9894 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
Brian Kingbfae7822013-01-30 23:45:08 -06009895 int i;
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009896 unsigned long driver_lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009897 ENTER;
9898
9899 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03009900 while (ioa_cfg->in_reset_reload) {
Brian King970ea292007-04-26 16:00:06 -05009901 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9902 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9903 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9904 }
9905
Brian Kingbfae7822013-01-30 23:45:08 -06009906 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9907 spin_lock(&ioa_cfg->hrrq[i]._lock);
9908 ioa_cfg->hrrq[i].removing_ioa = 1;
9909 spin_unlock(&ioa_cfg->hrrq[i]._lock);
9910 }
9911 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07009912 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9913
9914 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9915 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
Tejun Heo43829732012-08-20 14:51:24 -07009916 flush_work(&ioa_cfg->work_q);
wenxiong@linux.vnet.ibm.com9077a942013-03-14 13:52:24 -05009917 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009918 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9919
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009920 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009921 list_del(&ioa_cfg->queue);
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009922 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009923
9924 if (ioa_cfg->sdt_state == ABORT_DUMP)
9925 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
9926 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9927
9928 ipr_free_all_resources(ioa_cfg);
9929
9930 LEAVE;
9931}
9932
9933/**
9934 * ipr_remove - IOA hot plug remove entry point
9935 * @pdev: pci device struct
9936 *
9937 * Adapter hot plug remove entry point.
9938 *
9939 * Return value:
9940 * none
9941 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009942static void ipr_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009943{
9944 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9945
9946 ENTER;
9947
Tony Jonesee959b02008-02-22 00:13:36 +01009948 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009949 &ipr_trace_attr);
Tony Jonesee959b02008-02-22 00:13:36 +01009950 ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009951 &ipr_dump_attr);
9952 scsi_remove_host(ioa_cfg->host);
9953
9954 __ipr_remove(pdev);
9955
9956 LEAVE;
9957}
9958
9959/**
9960 * ipr_probe - Adapter hot plug add entry point
9961 *
9962 * Return value:
9963 * 0 on success / non-zero on failure
9964 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009965static int ipr_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009966{
9967 struct ipr_ioa_cfg *ioa_cfg;
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06009968 int rc, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009969
9970 rc = ipr_probe_ioa(pdev, dev_id);
9971
9972 if (rc)
9973 return rc;
9974
9975 ioa_cfg = pci_get_drvdata(pdev);
9976 rc = ipr_probe_ioa_part2(ioa_cfg);
9977
9978 if (rc) {
9979 __ipr_remove(pdev);
9980 return rc;
9981 }
9982
9983 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
9984
9985 if (rc) {
9986 __ipr_remove(pdev);
9987 return rc;
9988 }
9989
Tony Jonesee959b02008-02-22 00:13:36 +01009990 rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009991 &ipr_trace_attr);
9992
9993 if (rc) {
9994 scsi_remove_host(ioa_cfg->host);
9995 __ipr_remove(pdev);
9996 return rc;
9997 }
9998
Tony Jonesee959b02008-02-22 00:13:36 +01009999 rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -070010000 &ipr_dump_attr);
10001
10002 if (rc) {
Tony Jonesee959b02008-02-22 00:13:36 +010010003 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -070010004 &ipr_trace_attr);
10005 scsi_remove_host(ioa_cfg->host);
10006 __ipr_remove(pdev);
10007 return rc;
10008 }
10009
10010 scsi_scan_host(ioa_cfg->host);
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -060010011 ioa_cfg->iopoll_weight = ioa_cfg->chip_cfg->iopoll_weight;
10012
Jens Axboe89f8b332014-03-13 09:38:42 -060010013 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -060010014 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
10015 blk_iopoll_init(&ioa_cfg->hrrq[i].iopoll,
10016 ioa_cfg->iopoll_weight, ipr_iopoll);
10017 blk_iopoll_enable(&ioa_cfg->hrrq[i].iopoll);
10018 }
10019 }
10020
Linus Torvalds1da177e2005-04-16 15:20:36 -070010021 schedule_work(&ioa_cfg->work_q);
10022 return 0;
10023}
10024
10025/**
10026 * ipr_shutdown - Shutdown handler.
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -070010027 * @pdev: pci device struct
Linus Torvalds1da177e2005-04-16 15:20:36 -070010028 *
10029 * This function is invoked upon system shutdown/reboot. It will issue
10030 * an adapter shutdown to the adapter to flush the write cache.
10031 *
10032 * Return value:
10033 * none
10034 **/
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -070010035static void ipr_shutdown(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010036{
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -070010037 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010038 unsigned long lock_flags = 0;
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -060010039 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010040
10041 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Jens Axboe89f8b332014-03-13 09:38:42 -060010042 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -060010043 ioa_cfg->iopoll_weight = 0;
10044 for (i = 1; i < ioa_cfg->hrrq_num; i++)
10045 blk_iopoll_disable(&ioa_cfg->hrrq[i].iopoll);
10046 }
10047
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -030010048 while (ioa_cfg->in_reset_reload) {
Brian King970ea292007-04-26 16:00:06 -050010049 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
10050 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
10051 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
10052 }
10053
Linus Torvalds1da177e2005-04-16 15:20:36 -070010054 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
10055 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
10056 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
10057}
10058
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010059static struct pci_device_id ipr_pci_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070010060 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -060010061 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010062 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -060010063 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010064 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -060010065 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010066 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -060010067 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010068 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -060010069 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010070 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -060010071 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010072 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -060010073 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010074 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King5469cb52007-03-29 12:42:40 -050010075 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
10076 IPR_USE_LONG_TRANSOP_TIMEOUT },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010077 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King6d84c942007-01-23 11:25:23 -060010078 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010079 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King22d2e402007-04-26 16:00:13 -050010080 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
10081 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -060010082 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King5469cb52007-03-29 12:42:40 -050010083 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
10084 IPR_USE_LONG_TRANSOP_TIMEOUT },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010085 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King6d84c942007-01-23 11:25:23 -060010086 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010087 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King22d2e402007-04-26 16:00:13 -050010088 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
10089 IPR_USE_LONG_TRANSOP_TIMEOUT},
Brian King60e74862006-11-21 10:28:10 -060010090 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King5469cb52007-03-29 12:42:40 -050010091 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
10092 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -060010093 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King22d2e402007-04-26 16:00:13 -050010094 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
10095 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King185eb312007-03-29 12:42:53 -050010096 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King185eb312007-03-29 12:42:53 -050010097 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
10098 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Wayne Boyerb0f56d32010-06-24 13:34:14 -070010099 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
10100 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King5469cb52007-03-29 12:42:40 -050010101 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
Brian King463fc692007-05-07 17:09:05 -050010102 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010103 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
Brian King6d84c942007-01-23 11:25:23 -060010104 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010105 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King6d84c942007-01-23 11:25:23 -060010106 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010107 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King5469cb52007-03-29 12:42:40 -050010108 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
10109 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -060010110 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King5469cb52007-03-29 12:42:40 -050010111 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
10112 IPR_USE_LONG_TRANSOP_TIMEOUT },
Wayne Boyerd7b46272010-02-19 13:24:38 -080010113 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10114 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
10115 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10116 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
10117 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10118 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
Wayne Boyer32622bd2010-10-18 20:24:34 -070010119 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
wenxiong@linux.vnet.ibm.comb8d5d562013-01-11 17:43:47 -060010120 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C0, 0, 0, 0 },
10121 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
Wayne Boyer5a918352011-10-27 11:58:21 -070010122 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
10123 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
Wayne Boyer32622bd2010-10-18 20:24:34 -070010124 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -080010125 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -080010126 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -080010127 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -080010128 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -080010129 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -080010130 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -080010131 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10132 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
10133 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -080010134 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
wenxiong@linux.vnet.ibm.comb8d5d562013-01-11 17:43:47 -060010135 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10136 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D5, 0, 0, 0 },
10137 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10138 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D6, 0, 0, 0 },
10139 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10140 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D7, 0, 0, 0 },
10141 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10142 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D8, 0, 0, 0 },
wenxiong@linux.vnet.ibm.com43c5fda2013-07-10 10:46:27 -050010143 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10144 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D9, 0, 0, 0 },
10145 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wendy Xiongf94d9962014-01-21 12:16:40 -060010146 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57DA, 0, 0, 0 },
10147 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
wenxiong@linux.vnet.ibm.com43c5fda2013-07-10 10:46:27 -050010148 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EB, 0, 0, 0 },
10149 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10150 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EC, 0, 0, 0 },
10151 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10152 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57ED, 0, 0, 0 },
10153 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10154 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EE, 0, 0, 0 },
10155 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10156 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EF, 0, 0, 0 },
10157 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10158 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57F0, 0, 0, 0 },
Wendy Xiong5eeac3e2014-03-12 16:08:52 -050010159 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10160 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCA, 0, 0, 0 },
10161 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10162 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CD2, 0, 0, 0 },
10163 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10164 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCD, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010165 { }
10166};
10167MODULE_DEVICE_TABLE(pci, ipr_pci_table);
10168
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070010169static const struct pci_error_handlers ipr_err_handler = {
Linas Vepstasf8a88b192006-02-03 16:52:42 -060010170 .error_detected = ipr_pci_error_detected,
Brian King6270e592014-01-21 12:16:41 -060010171 .mmio_enabled = ipr_pci_mmio_enabled,
Linas Vepstasf8a88b192006-02-03 16:52:42 -060010172 .slot_reset = ipr_pci_slot_reset,
10173};
10174
Linus Torvalds1da177e2005-04-16 15:20:36 -070010175static struct pci_driver ipr_driver = {
10176 .name = IPR_NAME,
10177 .id_table = ipr_pci_table,
10178 .probe = ipr_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010179 .remove = ipr_remove,
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -070010180 .shutdown = ipr_shutdown,
Linas Vepstasf8a88b192006-02-03 16:52:42 -060010181 .err_handler = &ipr_err_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -070010182};
10183
10184/**
Wayne Boyerf72919e2010-02-19 13:24:21 -080010185 * ipr_halt_done - Shutdown prepare completion
10186 *
10187 * Return value:
10188 * none
10189 **/
10190static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
10191{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -060010192 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Wayne Boyerf72919e2010-02-19 13:24:21 -080010193}
10194
10195/**
10196 * ipr_halt - Issue shutdown prepare to all adapters
10197 *
10198 * Return value:
10199 * NOTIFY_OK on success / NOTIFY_DONE on failure
10200 **/
10201static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
10202{
10203 struct ipr_cmnd *ipr_cmd;
10204 struct ipr_ioa_cfg *ioa_cfg;
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -050010205 unsigned long flags = 0, driver_lock_flags;
Wayne Boyerf72919e2010-02-19 13:24:21 -080010206
10207 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
10208 return NOTIFY_DONE;
10209
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -050010210 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
Wayne Boyerf72919e2010-02-19 13:24:21 -080010211
10212 list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
10213 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -060010214 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
Wayne Boyerf72919e2010-02-19 13:24:21 -080010215 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10216 continue;
10217 }
10218
10219 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
10220 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
10221 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
10222 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
10223 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
10224
10225 ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
10226 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10227 }
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -050010228 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
Wayne Boyerf72919e2010-02-19 13:24:21 -080010229
10230 return NOTIFY_OK;
10231}
10232
10233static struct notifier_block ipr_notifier = {
10234 ipr_halt, NULL, 0
10235};
10236
10237/**
Linus Torvalds1da177e2005-04-16 15:20:36 -070010238 * ipr_init - Module entry point
10239 *
10240 * Return value:
10241 * 0 on success / negative value on failure
10242 **/
10243static int __init ipr_init(void)
10244{
10245 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
10246 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
10247
Wayne Boyerf72919e2010-02-19 13:24:21 -080010248 register_reboot_notifier(&ipr_notifier);
Henrik Kretzschmardcbccbde2006-09-25 16:58:58 -070010249 return pci_register_driver(&ipr_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010250}
10251
10252/**
10253 * ipr_exit - Module unload
10254 *
10255 * Module unload entry point.
10256 *
10257 * Return value:
10258 * none
10259 **/
10260static void __exit ipr_exit(void)
10261{
Wayne Boyerf72919e2010-02-19 13:24:21 -080010262 unregister_reboot_notifier(&ipr_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010263 pci_unregister_driver(&ipr_driver);
10264}
10265
10266module_init(ipr_init);
10267module_exit(ipr_exit);