blob: 256ef98f5c2910a7f5d83ad06beba9d41c5f4105 [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 King172cd6e2012-07-17 08:14:40 -0500686 ipr_cmd->fast_done = fast_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 init_timer(&ipr_cmd->timer);
688}
689
690/**
Brian King00bfef22012-07-17 08:13:52 -0500691 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 * @ioa_cfg: ioa config struct
693 *
694 * Return value:
695 * pointer to ipr command struct
696 **/
697static
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600698struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_hrr_queue *hrrq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600700 struct ipr_cmnd *ipr_cmd = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600702 if (likely(!list_empty(&hrrq->hrrq_free_q))) {
703 ipr_cmd = list_entry(hrrq->hrrq_free_q.next,
704 struct ipr_cmnd, queue);
705 list_del(&ipr_cmd->queue);
706 }
707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
709 return ipr_cmd;
710}
711
712/**
Brian King00bfef22012-07-17 08:13:52 -0500713 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
714 * @ioa_cfg: ioa config struct
715 *
716 * Return value:
717 * pointer to ipr command struct
718 **/
719static
720struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
721{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600722 struct ipr_cmnd *ipr_cmd =
723 __ipr_get_free_ipr_cmnd(&ioa_cfg->hrrq[IPR_INIT_HRRQ]);
Brian King172cd6e2012-07-17 08:14:40 -0500724 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
Brian King00bfef22012-07-17 08:13:52 -0500725 return ipr_cmd;
726}
727
728/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
730 * @ioa_cfg: ioa config struct
731 * @clr_ints: interrupts to clear
732 *
733 * This function masks all interrupts on the adapter, then clears the
734 * interrupts specified in the mask
735 *
736 * Return value:
737 * none
738 **/
739static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
740 u32 clr_ints)
741{
742 volatile u32 int_reg;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -0600743 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745 /* Stop new interrupts */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -0600746 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
747 spin_lock(&ioa_cfg->hrrq[i]._lock);
748 ioa_cfg->hrrq[i].allow_interrupts = 0;
749 spin_unlock(&ioa_cfg->hrrq[i]._lock);
750 }
751 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 /* Set interrupt mask to stop all new interrupts */
Wayne Boyer214777b2010-02-19 13:24:26 -0800754 if (ioa_cfg->sis64)
755 writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
756 else
757 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
759 /* Clear any pending interrupts */
Wayne Boyer214777b2010-02-19 13:24:26 -0800760 if (ioa_cfg->sis64)
761 writel(~0, ioa_cfg->regs.clr_interrupt_reg);
762 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
764}
765
766/**
767 * ipr_save_pcix_cmd_reg - Save PCI-X command register
768 * @ioa_cfg: ioa config struct
769 *
770 * Return value:
771 * 0 on success / -EIO on failure
772 **/
773static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
774{
775 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
776
Brian King7dce0e12007-01-23 11:25:30 -0600777 if (pcix_cmd_reg == 0)
778 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
780 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
781 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
782 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
783 return -EIO;
784 }
785
786 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
787 return 0;
788}
789
790/**
791 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
792 * @ioa_cfg: ioa config struct
793 *
794 * Return value:
795 * 0 on success / -EIO on failure
796 **/
797static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
798{
799 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
800
801 if (pcix_cmd_reg) {
802 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
803 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
804 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
805 return -EIO;
806 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 }
808
809 return 0;
810}
811
812/**
Brian King35a39692006-09-25 12:39:20 -0500813 * ipr_sata_eh_done - done function for aborted SATA commands
814 * @ipr_cmd: ipr command struct
815 *
816 * This function is invoked for ops generated to SATA
817 * devices which are being aborted.
818 *
819 * Return value:
820 * none
821 **/
822static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
823{
Brian King35a39692006-09-25 12:39:20 -0500824 struct ata_queued_cmd *qc = ipr_cmd->qc;
825 struct ipr_sata_port *sata_port = qc->ap->private_data;
826
827 qc->err_mask |= AC_ERR_OTHER;
828 sata_port->ioasa.status |= ATA_BUSY;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600829 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Brian King35a39692006-09-25 12:39:20 -0500830 ata_qc_complete(qc);
831}
832
833/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 * ipr_scsi_eh_done - mid-layer done function for aborted ops
835 * @ipr_cmd: ipr command struct
836 *
837 * This function is invoked by the interrupt handler for
838 * ops generated by the SCSI mid-layer which are being aborted.
839 *
840 * Return value:
841 * none
842 **/
843static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
844{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
846
847 scsi_cmd->result |= (DID_ERROR << 16);
848
FUJITA Tomonori63015bc2007-05-26 00:26:59 +0900849 scsi_dma_unmap(ipr_cmd->scsi_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 scsi_cmd->scsi_done(scsi_cmd);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600851 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852}
853
854/**
855 * ipr_fail_all_ops - Fails all outstanding ops.
856 * @ioa_cfg: ioa config struct
857 *
858 * This function fails all outstanding ops.
859 *
860 * Return value:
861 * none
862 **/
863static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
864{
865 struct ipr_cmnd *ipr_cmd, *temp;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600866 struct ipr_hrr_queue *hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 ENTER;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600869 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -0600870 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600871 list_for_each_entry_safe(ipr_cmd,
872 temp, &hrrq->hrrq_pending_q, queue) {
873 list_del(&ipr_cmd->queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600875 ipr_cmd->s.ioasa.hdr.ioasc =
876 cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
877 ipr_cmd->s.ioasa.hdr.ilid =
878 cpu_to_be32(IPR_DRIVER_ILID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600880 if (ipr_cmd->scsi_cmd)
881 ipr_cmd->done = ipr_scsi_eh_done;
882 else if (ipr_cmd->qc)
883 ipr_cmd->done = ipr_sata_eh_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600885 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH,
886 IPR_IOASC_IOA_WAS_RESET);
887 del_timer(&ipr_cmd->timer);
888 ipr_cmd->done(ipr_cmd);
889 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -0600890 spin_unlock(&hrrq->_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 LEAVE;
893}
894
895/**
Wayne Boyera32c0552010-02-19 13:23:36 -0800896 * ipr_send_command - Send driver initiated requests.
897 * @ipr_cmd: ipr command struct
898 *
899 * This function sends a command to the adapter using the correct write call.
900 * In the case of sis64, calculate the ioarcb size required. Then or in the
901 * appropriate bits.
902 *
903 * Return value:
904 * none
905 **/
906static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
907{
908 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
909 dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
910
911 if (ioa_cfg->sis64) {
912 /* The default size is 256 bytes */
913 send_dma_addr |= 0x1;
914
915 /* If the number of ioadls * size of ioadl > 128 bytes,
916 then use a 512 byte ioarcb */
917 if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
918 send_dma_addr |= 0x4;
919 writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
920 } else
921 writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
922}
923
924/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 * ipr_do_req - Send driver initiated requests.
926 * @ipr_cmd: ipr command struct
927 * @done: done function
928 * @timeout_func: timeout function
929 * @timeout: timeout value
930 *
931 * This function sends the specified command to the adapter with the
932 * timeout given. The done function is invoked on command completion.
933 *
934 * Return value:
935 * none
936 **/
937static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
938 void (*done) (struct ipr_cmnd *),
939 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
940{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -0600941 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943 ipr_cmd->done = done;
944
945 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
946 ipr_cmd->timer.expires = jiffies + timeout;
947 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
948
949 add_timer(&ipr_cmd->timer);
950
951 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
952
Wayne Boyera32c0552010-02-19 13:23:36 -0800953 ipr_send_command(ipr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954}
955
956/**
957 * ipr_internal_cmd_done - Op done function for an internally generated op.
958 * @ipr_cmd: ipr command struct
959 *
960 * This function is the op done function for an internally generated,
961 * blocking op. It simply wakes the sleeping thread.
962 *
963 * Return value:
964 * none
965 **/
966static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
967{
968 if (ipr_cmd->sibling)
969 ipr_cmd->sibling = NULL;
970 else
971 complete(&ipr_cmd->completion);
972}
973
974/**
Wayne Boyera32c0552010-02-19 13:23:36 -0800975 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
976 * @ipr_cmd: ipr command struct
977 * @dma_addr: dma address
978 * @len: transfer length
979 * @flags: ioadl flag value
980 *
981 * This function initializes an ioadl in the case where there is only a single
982 * descriptor.
983 *
984 * Return value:
985 * nothing
986 **/
987static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
988 u32 len, int flags)
989{
990 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
991 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
992
993 ipr_cmd->dma_use_sg = 1;
994
995 if (ipr_cmd->ioa_cfg->sis64) {
996 ioadl64->flags = cpu_to_be32(flags);
997 ioadl64->data_len = cpu_to_be32(len);
998 ioadl64->address = cpu_to_be64(dma_addr);
999
1000 ipr_cmd->ioarcb.ioadl_len =
1001 cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
1002 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1003 } else {
1004 ioadl->flags_and_data_len = cpu_to_be32(flags | len);
1005 ioadl->address = cpu_to_be32(dma_addr);
1006
1007 if (flags == IPR_IOADL_FLAGS_READ_LAST) {
1008 ipr_cmd->ioarcb.read_ioadl_len =
1009 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1010 ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
1011 } else {
1012 ipr_cmd->ioarcb.ioadl_len =
1013 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1014 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1015 }
1016 }
1017}
1018
1019/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 * ipr_send_blocking_cmd - Send command and sleep on its completion.
1021 * @ipr_cmd: ipr command struct
1022 * @timeout_func: function to invoke if command times out
1023 * @timeout: timeout
1024 *
1025 * Return value:
1026 * none
1027 **/
1028static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
1029 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
1030 u32 timeout)
1031{
1032 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1033
1034 init_completion(&ipr_cmd->completion);
1035 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
1036
1037 spin_unlock_irq(ioa_cfg->host->host_lock);
1038 wait_for_completion(&ipr_cmd->completion);
1039 spin_lock_irq(ioa_cfg->host->host_lock);
1040}
1041
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06001042static int ipr_get_hrrq_index(struct ipr_ioa_cfg *ioa_cfg)
1043{
1044 if (ioa_cfg->hrrq_num == 1)
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06001045 return 0;
1046 else
1047 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 -06001048}
1049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050/**
1051 * ipr_send_hcam - Send an HCAM to the adapter.
1052 * @ioa_cfg: ioa config struct
1053 * @type: HCAM type
1054 * @hostrcb: hostrcb struct
1055 *
1056 * This function will send a Host Controlled Async command to the adapter.
1057 * If HCAMs are currently not allowed to be issued to the adapter, it will
1058 * place the hostrcb on the free queue.
1059 *
1060 * Return value:
1061 * none
1062 **/
1063static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
1064 struct ipr_hostrcb *hostrcb)
1065{
1066 struct ipr_cmnd *ipr_cmd;
1067 struct ipr_ioarcb *ioarcb;
1068
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06001069 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06001071 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
1073
1074 ipr_cmd->u.hostrcb = hostrcb;
1075 ioarcb = &ipr_cmd->ioarcb;
1076
1077 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
1078 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
1079 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
1080 ioarcb->cmd_pkt.cdb[1] = type;
1081 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
1082 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
1083
Wayne Boyera32c0552010-02-19 13:23:36 -08001084 ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
1085 sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
1088 ipr_cmd->done = ipr_process_ccn;
1089 else
1090 ipr_cmd->done = ipr_process_error;
1091
1092 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
1093
Wayne Boyera32c0552010-02-19 13:23:36 -08001094 ipr_send_command(ipr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 } else {
1096 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
1097 }
1098}
1099
1100/**
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001101 * ipr_update_ata_class - Update the ata class in the resource entry
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 * @res: resource entry struct
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001103 * @proto: cfgte device bus protocol value
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 *
1105 * Return value:
1106 * none
1107 **/
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001108static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03001110 switch (proto) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001111 case IPR_PROTO_SATA:
1112 case IPR_PROTO_SAS_STP:
1113 res->ata_class = ATA_DEV_ATA;
1114 break;
1115 case IPR_PROTO_SATA_ATAPI:
1116 case IPR_PROTO_SAS_STP_ATAPI:
1117 res->ata_class = ATA_DEV_ATAPI;
1118 break;
1119 default:
1120 res->ata_class = ATA_DEV_UNKNOWN;
1121 break;
1122 };
1123}
1124
1125/**
1126 * ipr_init_res_entry - Initialize a resource entry struct.
1127 * @res: resource entry struct
1128 * @cfgtew: config table entry wrapper struct
1129 *
1130 * Return value:
1131 * none
1132 **/
1133static void ipr_init_res_entry(struct ipr_resource_entry *res,
1134 struct ipr_config_table_entry_wrapper *cfgtew)
1135{
1136 int found = 0;
1137 unsigned int proto;
1138 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1139 struct ipr_resource_entry *gscsi_res = NULL;
1140
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06001141 res->needs_sync_complete = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 res->in_erp = 0;
1143 res->add_to_ml = 0;
1144 res->del_from_ml = 0;
1145 res->resetting_device = 0;
Wendy Xiong0b1f8d42014-01-21 12:16:39 -06001146 res->reset_occurred = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 res->sdev = NULL;
Brian King35a39692006-09-25 12:39:20 -05001148 res->sata_port = NULL;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001149
1150 if (ioa_cfg->sis64) {
1151 proto = cfgtew->u.cfgte64->proto;
1152 res->res_flags = cfgtew->u.cfgte64->res_flags;
1153 res->qmodel = IPR_QUEUEING_MODEL64(res);
Wayne Boyer438b0332010-05-10 09:13:00 -07001154 res->type = cfgtew->u.cfgte64->res_type;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001155
1156 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1157 sizeof(res->res_path));
1158
1159 res->bus = 0;
Wayne Boyer0cb992ed2010-11-04 09:35:58 -07001160 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1161 sizeof(res->dev_lun.scsi_lun));
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001162 res->lun = scsilun_to_int(&res->dev_lun);
1163
1164 if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1165 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1166 if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1167 found = 1;
1168 res->target = gscsi_res->target;
1169 break;
1170 }
1171 }
1172 if (!found) {
1173 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1174 ioa_cfg->max_devs_supported);
1175 set_bit(res->target, ioa_cfg->target_ids);
1176 }
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001177 } else if (res->type == IPR_RES_TYPE_IOAFP) {
1178 res->bus = IPR_IOAFP_VIRTUAL_BUS;
1179 res->target = 0;
1180 } else if (res->type == IPR_RES_TYPE_ARRAY) {
1181 res->bus = IPR_ARRAY_VIRTUAL_BUS;
1182 res->target = find_first_zero_bit(ioa_cfg->array_ids,
1183 ioa_cfg->max_devs_supported);
1184 set_bit(res->target, ioa_cfg->array_ids);
1185 } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1186 res->bus = IPR_VSET_VIRTUAL_BUS;
1187 res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1188 ioa_cfg->max_devs_supported);
1189 set_bit(res->target, ioa_cfg->vset_ids);
1190 } else {
1191 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1192 ioa_cfg->max_devs_supported);
1193 set_bit(res->target, ioa_cfg->target_ids);
1194 }
1195 } else {
1196 proto = cfgtew->u.cfgte->proto;
1197 res->qmodel = IPR_QUEUEING_MODEL(res);
1198 res->flags = cfgtew->u.cfgte->flags;
1199 if (res->flags & IPR_IS_IOA_RESOURCE)
1200 res->type = IPR_RES_TYPE_IOAFP;
1201 else
1202 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1203
1204 res->bus = cfgtew->u.cfgte->res_addr.bus;
1205 res->target = cfgtew->u.cfgte->res_addr.target;
1206 res->lun = cfgtew->u.cfgte->res_addr.lun;
Wayne Boyer46d74562010-08-11 07:15:17 -07001207 res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001208 }
1209
1210 ipr_update_ata_class(res, proto);
1211}
1212
1213/**
1214 * ipr_is_same_device - Determine if two devices are the same.
1215 * @res: resource entry struct
1216 * @cfgtew: config table entry wrapper struct
1217 *
1218 * Return value:
1219 * 1 if the devices are the same / 0 otherwise
1220 **/
1221static int ipr_is_same_device(struct ipr_resource_entry *res,
1222 struct ipr_config_table_entry_wrapper *cfgtew)
1223{
1224 if (res->ioa_cfg->sis64) {
1225 if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1226 sizeof(cfgtew->u.cfgte64->dev_id)) &&
Wayne Boyer0cb992ed2010-11-04 09:35:58 -07001227 !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001228 sizeof(cfgtew->u.cfgte64->lun))) {
1229 return 1;
1230 }
1231 } else {
1232 if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1233 res->target == cfgtew->u.cfgte->res_addr.target &&
1234 res->lun == cfgtew->u.cfgte->res_addr.lun)
1235 return 1;
1236 }
1237
1238 return 0;
1239}
1240
1241/**
Brian Kingb3b3b402013-01-11 17:43:49 -06001242 * __ipr_format_res_path - Format the resource path for printing.
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001243 * @res_path: resource path
1244 * @buf: buffer
Brian Kingb3b3b402013-01-11 17:43:49 -06001245 * @len: length of buffer provided
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001246 *
1247 * Return value:
1248 * pointer to buffer
1249 **/
Brian Kingb3b3b402013-01-11 17:43:49 -06001250static char *__ipr_format_res_path(u8 *res_path, char *buffer, int len)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001251{
1252 int i;
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001253 char *p = buffer;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001254
Wayne Boyer46d74562010-08-11 07:15:17 -07001255 *p = '\0';
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07001256 p += snprintf(p, buffer + len - p, "%02X", res_path[0]);
1257 for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
1258 p += snprintf(p, buffer + len - p, "-%02X", res_path[i]);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001259
1260 return buffer;
1261}
1262
1263/**
Brian Kingb3b3b402013-01-11 17:43:49 -06001264 * ipr_format_res_path - Format the resource path for printing.
1265 * @ioa_cfg: ioa config struct
1266 * @res_path: resource path
1267 * @buf: buffer
1268 * @len: length of buffer provided
1269 *
1270 * Return value:
1271 * pointer to buffer
1272 **/
1273static char *ipr_format_res_path(struct ipr_ioa_cfg *ioa_cfg,
1274 u8 *res_path, char *buffer, int len)
1275{
1276 char *p = buffer;
1277
1278 *p = '\0';
1279 p += snprintf(p, buffer + len - p, "%d/", ioa_cfg->host->host_no);
1280 __ipr_format_res_path(res_path, p, len - (buffer - p));
1281 return buffer;
1282}
1283
1284/**
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001285 * ipr_update_res_entry - Update the resource entry.
1286 * @res: resource entry struct
1287 * @cfgtew: config table entry wrapper struct
1288 *
1289 * Return value:
1290 * none
1291 **/
1292static void ipr_update_res_entry(struct ipr_resource_entry *res,
1293 struct ipr_config_table_entry_wrapper *cfgtew)
1294{
1295 char buffer[IPR_MAX_RES_PATH_LENGTH];
1296 unsigned int proto;
1297 int new_path = 0;
1298
1299 if (res->ioa_cfg->sis64) {
1300 res->flags = cfgtew->u.cfgte64->flags;
1301 res->res_flags = cfgtew->u.cfgte64->res_flags;
Wayne Boyer75576bb2010-07-14 10:50:14 -07001302 res->type = cfgtew->u.cfgte64->res_type;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001303
1304 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1305 sizeof(struct ipr_std_inq_data));
1306
1307 res->qmodel = IPR_QUEUEING_MODEL64(res);
1308 proto = cfgtew->u.cfgte64->proto;
1309 res->res_handle = cfgtew->u.cfgte64->res_handle;
1310 res->dev_id = cfgtew->u.cfgte64->dev_id;
1311
1312 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1313 sizeof(res->dev_lun.scsi_lun));
1314
1315 if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1316 sizeof(res->res_path))) {
1317 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1318 sizeof(res->res_path));
1319 new_path = 1;
1320 }
1321
1322 if (res->sdev && new_path)
1323 sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
Brian Kingb3b3b402013-01-11 17:43:49 -06001324 ipr_format_res_path(res->ioa_cfg,
1325 res->res_path, buffer, sizeof(buffer)));
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001326 } else {
1327 res->flags = cfgtew->u.cfgte->flags;
1328 if (res->flags & IPR_IS_IOA_RESOURCE)
1329 res->type = IPR_RES_TYPE_IOAFP;
1330 else
1331 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1332
1333 memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1334 sizeof(struct ipr_std_inq_data));
1335
1336 res->qmodel = IPR_QUEUEING_MODEL(res);
1337 proto = cfgtew->u.cfgte->proto;
1338 res->res_handle = cfgtew->u.cfgte->res_handle;
1339 }
1340
1341 ipr_update_ata_class(res, proto);
1342}
1343
1344/**
1345 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1346 * for the resource.
1347 * @res: resource entry struct
1348 * @cfgtew: config table entry wrapper struct
1349 *
1350 * Return value:
1351 * none
1352 **/
1353static void ipr_clear_res_target(struct ipr_resource_entry *res)
1354{
1355 struct ipr_resource_entry *gscsi_res = NULL;
1356 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1357
1358 if (!ioa_cfg->sis64)
1359 return;
1360
1361 if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1362 clear_bit(res->target, ioa_cfg->array_ids);
1363 else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1364 clear_bit(res->target, ioa_cfg->vset_ids);
1365 else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1366 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1367 if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1368 return;
1369 clear_bit(res->target, ioa_cfg->target_ids);
1370
1371 } else if (res->bus == 0)
1372 clear_bit(res->target, ioa_cfg->target_ids);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373}
1374
1375/**
1376 * ipr_handle_config_change - Handle a config change from the adapter
1377 * @ioa_cfg: ioa config struct
1378 * @hostrcb: hostrcb
1379 *
1380 * Return value:
1381 * none
1382 **/
1383static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001384 struct ipr_hostrcb *hostrcb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385{
1386 struct ipr_resource_entry *res = NULL;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001387 struct ipr_config_table_entry_wrapper cfgtew;
1388 __be32 cc_res_handle;
1389
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 u32 is_ndn = 1;
1391
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001392 if (ioa_cfg->sis64) {
1393 cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1394 cc_res_handle = cfgtew.u.cfgte64->res_handle;
1395 } else {
1396 cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1397 cc_res_handle = cfgtew.u.cfgte->res_handle;
1398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
1400 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001401 if (res->res_handle == cc_res_handle) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 is_ndn = 0;
1403 break;
1404 }
1405 }
1406
1407 if (is_ndn) {
1408 if (list_empty(&ioa_cfg->free_res_q)) {
1409 ipr_send_hcam(ioa_cfg,
1410 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1411 hostrcb);
1412 return;
1413 }
1414
1415 res = list_entry(ioa_cfg->free_res_q.next,
1416 struct ipr_resource_entry, queue);
1417
1418 list_del(&res->queue);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001419 ipr_init_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1421 }
1422
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001423 ipr_update_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1426 if (res->sdev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 res->del_from_ml = 1;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001428 res->res_handle = IPR_INVALID_RES_HANDLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 if (ioa_cfg->allow_ml_add_del)
1430 schedule_work(&ioa_cfg->work_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001431 } else {
1432 ipr_clear_res_target(res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08001434 }
Kleber Sacilotto de Souza5767a1c2011-02-14 20:19:31 -02001435 } else if (!res->sdev || res->del_from_ml) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 res->add_to_ml = 1;
1437 if (ioa_cfg->allow_ml_add_del)
1438 schedule_work(&ioa_cfg->work_q);
1439 }
1440
1441 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1442}
1443
1444/**
1445 * ipr_process_ccn - Op done function for a CCN.
1446 * @ipr_cmd: ipr command struct
1447 *
1448 * This function is the op done function for a configuration
1449 * change notification host controlled async from the adapter.
1450 *
1451 * Return value:
1452 * none
1453 **/
1454static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1455{
1456 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1457 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07001458 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
1460 list_del(&hostrcb->queue);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06001461 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
1463 if (ioasc) {
1464 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
1465 dev_err(&ioa_cfg->pdev->dev,
1466 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1467
1468 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1469 } else {
1470 ipr_handle_config_change(ioa_cfg, hostrcb);
1471 }
1472}
1473
1474/**
Brian King8cf093e2007-04-26 16:00:14 -05001475 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1476 * @i: index into buffer
1477 * @buf: string to modify
1478 *
1479 * This function will strip all trailing whitespace, pad the end
1480 * of the string with a single space, and NULL terminate the string.
1481 *
1482 * Return value:
1483 * new length of string
1484 **/
1485static int strip_and_pad_whitespace(int i, char *buf)
1486{
1487 while (i && buf[i] == ' ')
1488 i--;
1489 buf[i+1] = ' ';
1490 buf[i+2] = '\0';
1491 return i + 2;
1492}
1493
1494/**
1495 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1496 * @prefix: string to print at start of printk
1497 * @hostrcb: hostrcb pointer
1498 * @vpd: vendor/product id/sn struct
1499 *
1500 * Return value:
1501 * none
1502 **/
1503static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1504 struct ipr_vpd *vpd)
1505{
1506 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
1507 int i = 0;
1508
1509 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1510 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
1511
1512 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
1513 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
1514
1515 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1516 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1517
1518 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1519}
1520
1521/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 * ipr_log_vpd - Log the passed VPD to the error log.
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001523 * @vpd: vendor/product id/sn struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 *
1525 * Return value:
1526 * none
1527 **/
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001528static void ipr_log_vpd(struct ipr_vpd *vpd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529{
1530 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1531 + IPR_SERIAL_NUM_LEN];
1532
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001533 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1534 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 IPR_PROD_ID_LEN);
1536 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1537 ipr_err("Vendor/Product ID: %s\n", buffer);
1538
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001539 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1541 ipr_err(" Serial Number: %s\n", buffer);
1542}
1543
1544/**
Brian King8cf093e2007-04-26 16:00:14 -05001545 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1546 * @prefix: string to print at start of printk
1547 * @hostrcb: hostrcb pointer
1548 * @vpd: vendor/product id/sn/wwn struct
1549 *
1550 * Return value:
1551 * none
1552 **/
1553static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1554 struct ipr_ext_vpd *vpd)
1555{
1556 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1557 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1558 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1559}
1560
1561/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001562 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1563 * @vpd: vendor/product id/sn/wwn struct
1564 *
1565 * Return value:
1566 * none
1567 **/
1568static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1569{
1570 ipr_log_vpd(&vpd->vpd);
1571 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1572 be32_to_cpu(vpd->wwid[1]));
1573}
1574
1575/**
1576 * ipr_log_enhanced_cache_error - Log a cache error.
1577 * @ioa_cfg: ioa config struct
1578 * @hostrcb: hostrcb struct
1579 *
1580 * Return value:
1581 * none
1582 **/
1583static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1584 struct ipr_hostrcb *hostrcb)
1585{
Wayne Boyer4565e372010-02-19 13:24:07 -08001586 struct ipr_hostrcb_type_12_error *error;
1587
1588 if (ioa_cfg->sis64)
1589 error = &hostrcb->hcam.u.error64.u.type_12_error;
1590 else
1591 error = &hostrcb->hcam.u.error.u.type_12_error;
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001592
1593 ipr_err("-----Current Configuration-----\n");
1594 ipr_err("Cache Directory Card Information:\n");
1595 ipr_log_ext_vpd(&error->ioa_vpd);
1596 ipr_err("Adapter Card Information:\n");
1597 ipr_log_ext_vpd(&error->cfc_vpd);
1598
1599 ipr_err("-----Expected Configuration-----\n");
1600 ipr_err("Cache Directory Card Information:\n");
1601 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1602 ipr_err("Adapter Card Information:\n");
1603 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1604
1605 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1606 be32_to_cpu(error->ioa_data[0]),
1607 be32_to_cpu(error->ioa_data[1]),
1608 be32_to_cpu(error->ioa_data[2]));
1609}
1610
1611/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 * ipr_log_cache_error - Log a cache error.
1613 * @ioa_cfg: ioa config struct
1614 * @hostrcb: hostrcb struct
1615 *
1616 * Return value:
1617 * none
1618 **/
1619static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1620 struct ipr_hostrcb *hostrcb)
1621{
1622 struct ipr_hostrcb_type_02_error *error =
1623 &hostrcb->hcam.u.error.u.type_02_error;
1624
1625 ipr_err("-----Current Configuration-----\n");
1626 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001627 ipr_log_vpd(&error->ioa_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001629 ipr_log_vpd(&error->cfc_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
1631 ipr_err("-----Expected Configuration-----\n");
1632 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001633 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001635 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
1637 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1638 be32_to_cpu(error->ioa_data[0]),
1639 be32_to_cpu(error->ioa_data[1]),
1640 be32_to_cpu(error->ioa_data[2]));
1641}
1642
1643/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001644 * ipr_log_enhanced_config_error - Log a configuration error.
1645 * @ioa_cfg: ioa config struct
1646 * @hostrcb: hostrcb struct
1647 *
1648 * Return value:
1649 * none
1650 **/
1651static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1652 struct ipr_hostrcb *hostrcb)
1653{
1654 int errors_logged, i;
1655 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1656 struct ipr_hostrcb_type_13_error *error;
1657
1658 error = &hostrcb->hcam.u.error.u.type_13_error;
1659 errors_logged = be32_to_cpu(error->errors_logged);
1660
1661 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1662 be32_to_cpu(error->errors_detected), errors_logged);
1663
1664 dev_entry = error->dev;
1665
1666 for (i = 0; i < errors_logged; i++, dev_entry++) {
1667 ipr_err_separator;
1668
1669 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1670 ipr_log_ext_vpd(&dev_entry->vpd);
1671
1672 ipr_err("-----New Device Information-----\n");
1673 ipr_log_ext_vpd(&dev_entry->new_vpd);
1674
1675 ipr_err("Cache Directory Card Information:\n");
1676 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1677
1678 ipr_err("Adapter Card Information:\n");
1679 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1680 }
1681}
1682
1683/**
Wayne Boyer4565e372010-02-19 13:24:07 -08001684 * ipr_log_sis64_config_error - Log a device error.
1685 * @ioa_cfg: ioa config struct
1686 * @hostrcb: hostrcb struct
1687 *
1688 * Return value:
1689 * none
1690 **/
1691static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
1692 struct ipr_hostrcb *hostrcb)
1693{
1694 int errors_logged, i;
1695 struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
1696 struct ipr_hostrcb_type_23_error *error;
1697 char buffer[IPR_MAX_RES_PATH_LENGTH];
1698
1699 error = &hostrcb->hcam.u.error64.u.type_23_error;
1700 errors_logged = be32_to_cpu(error->errors_logged);
1701
1702 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1703 be32_to_cpu(error->errors_detected), errors_logged);
1704
1705 dev_entry = error->dev;
1706
1707 for (i = 0; i < errors_logged; i++, dev_entry++) {
1708 ipr_err_separator;
1709
1710 ipr_err("Device %d : %s", i + 1,
Brian Kingb3b3b402013-01-11 17:43:49 -06001711 __ipr_format_res_path(dev_entry->res_path,
1712 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08001713 ipr_log_ext_vpd(&dev_entry->vpd);
1714
1715 ipr_err("-----New Device Information-----\n");
1716 ipr_log_ext_vpd(&dev_entry->new_vpd);
1717
1718 ipr_err("Cache Directory Card Information:\n");
1719 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1720
1721 ipr_err("Adapter Card Information:\n");
1722 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1723 }
1724}
1725
1726/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 * ipr_log_config_error - Log a configuration error.
1728 * @ioa_cfg: ioa config struct
1729 * @hostrcb: hostrcb struct
1730 *
1731 * Return value:
1732 * none
1733 **/
1734static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1735 struct ipr_hostrcb *hostrcb)
1736{
1737 int errors_logged, i;
1738 struct ipr_hostrcb_device_data_entry *dev_entry;
1739 struct ipr_hostrcb_type_03_error *error;
1740
1741 error = &hostrcb->hcam.u.error.u.type_03_error;
1742 errors_logged = be32_to_cpu(error->errors_logged);
1743
1744 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1745 be32_to_cpu(error->errors_detected), errors_logged);
1746
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001747 dev_entry = error->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
1749 for (i = 0; i < errors_logged; i++, dev_entry++) {
1750 ipr_err_separator;
1751
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001752 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001753 ipr_log_vpd(&dev_entry->vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
1755 ipr_err("-----New Device Information-----\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001756 ipr_log_vpd(&dev_entry->new_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
1758 ipr_err("Cache Directory Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001759 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
1761 ipr_err("Adapter Card Information:\n");
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001762 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
1764 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1765 be32_to_cpu(dev_entry->ioa_data[0]),
1766 be32_to_cpu(dev_entry->ioa_data[1]),
1767 be32_to_cpu(dev_entry->ioa_data[2]),
1768 be32_to_cpu(dev_entry->ioa_data[3]),
1769 be32_to_cpu(dev_entry->ioa_data[4]));
1770 }
1771}
1772
1773/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001774 * ipr_log_enhanced_array_error - Log an array configuration error.
1775 * @ioa_cfg: ioa config struct
1776 * @hostrcb: hostrcb struct
1777 *
1778 * Return value:
1779 * none
1780 **/
1781static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1782 struct ipr_hostrcb *hostrcb)
1783{
1784 int i, num_entries;
1785 struct ipr_hostrcb_type_14_error *error;
1786 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1787 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1788
1789 error = &hostrcb->hcam.u.error.u.type_14_error;
1790
1791 ipr_err_separator;
1792
1793 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1794 error->protection_level,
1795 ioa_cfg->host->host_no,
1796 error->last_func_vset_res_addr.bus,
1797 error->last_func_vset_res_addr.target,
1798 error->last_func_vset_res_addr.lun);
1799
1800 ipr_err_separator;
1801
1802 array_entry = error->array_member;
1803 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
Wayne Boyer72620262010-09-27 10:45:28 -07001804 ARRAY_SIZE(error->array_member));
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001805
1806 for (i = 0; i < num_entries; i++, array_entry++) {
1807 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1808 continue;
1809
1810 if (be32_to_cpu(error->exposed_mode_adn) == i)
1811 ipr_err("Exposed Array Member %d:\n", i);
1812 else
1813 ipr_err("Array Member %d:\n", i);
1814
1815 ipr_log_ext_vpd(&array_entry->vpd);
1816 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1817 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1818 "Expected Location");
1819
1820 ipr_err_separator;
1821 }
1822}
1823
1824/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 * ipr_log_array_error - Log an array configuration error.
1826 * @ioa_cfg: ioa config struct
1827 * @hostrcb: hostrcb struct
1828 *
1829 * Return value:
1830 * none
1831 **/
1832static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1833 struct ipr_hostrcb *hostrcb)
1834{
1835 int i;
1836 struct ipr_hostrcb_type_04_error *error;
1837 struct ipr_hostrcb_array_data_entry *array_entry;
1838 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1839
1840 error = &hostrcb->hcam.u.error.u.type_04_error;
1841
1842 ipr_err_separator;
1843
1844 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1845 error->protection_level,
1846 ioa_cfg->host->host_no,
1847 error->last_func_vset_res_addr.bus,
1848 error->last_func_vset_res_addr.target,
1849 error->last_func_vset_res_addr.lun);
1850
1851 ipr_err_separator;
1852
1853 array_entry = error->array_member;
1854
1855 for (i = 0; i < 18; i++) {
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001856 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 continue;
1858
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001859 if (be32_to_cpu(error->exposed_mode_adn) == i)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 ipr_err("Exposed Array Member %d:\n", i);
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001861 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 ipr_err("Array Member %d:\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
brking@us.ibm.comcfc32132005-11-01 17:00:18 -06001864 ipr_log_vpd(&array_entry->vpd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
brking@us.ibm.comfa15b1f2005-11-01 17:00:27 -06001866 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1867 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1868 "Expected Location");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
1870 ipr_err_separator;
1871
1872 if (i == 9)
1873 array_entry = error->array_member2;
1874 else
1875 array_entry++;
1876 }
1877}
1878
1879/**
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001880 * ipr_log_hex_data - Log additional hex IOA error data.
Brian Kingac719ab2006-11-21 10:28:42 -06001881 * @ioa_cfg: ioa config struct
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001882 * @data: IOA error data
1883 * @len: data length
1884 *
1885 * Return value:
1886 * none
1887 **/
Brian Kingac719ab2006-11-21 10:28:42 -06001888static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001889{
1890 int i;
1891
1892 if (len == 0)
1893 return;
1894
Brian Kingac719ab2006-11-21 10:28:42 -06001895 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1896 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1897
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001898 for (i = 0; i < len / 4; i += 4) {
1899 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1900 be32_to_cpu(data[i]),
1901 be32_to_cpu(data[i+1]),
1902 be32_to_cpu(data[i+2]),
1903 be32_to_cpu(data[i+3]));
1904 }
1905}
1906
1907/**
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001908 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1909 * @ioa_cfg: ioa config struct
1910 * @hostrcb: hostrcb struct
1911 *
1912 * Return value:
1913 * none
1914 **/
1915static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1916 struct ipr_hostrcb *hostrcb)
1917{
1918 struct ipr_hostrcb_type_17_error *error;
1919
Wayne Boyer4565e372010-02-19 13:24:07 -08001920 if (ioa_cfg->sis64)
1921 error = &hostrcb->hcam.u.error64.u.type_17_error;
1922 else
1923 error = &hostrcb->hcam.u.error.u.type_17_error;
1924
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001925 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
KOSAKI Motohiroca54cb82009-12-14 18:01:15 -08001926 strim(error->failure_reason);
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001927
Brian King8cf093e2007-04-26 16:00:14 -05001928 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1929 be32_to_cpu(hostrcb->hcam.u.error.prc));
1930 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
Brian Kingac719ab2006-11-21 10:28:42 -06001931 ipr_log_hex_data(ioa_cfg, error->data,
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06001932 be32_to_cpu(hostrcb->hcam.length) -
1933 (offsetof(struct ipr_hostrcb_error, u) +
1934 offsetof(struct ipr_hostrcb_type_17_error, data)));
1935}
1936
1937/**
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001938 * ipr_log_dual_ioa_error - Log a dual adapter error.
1939 * @ioa_cfg: ioa config struct
1940 * @hostrcb: hostrcb struct
1941 *
1942 * Return value:
1943 * none
1944 **/
1945static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1946 struct ipr_hostrcb *hostrcb)
1947{
1948 struct ipr_hostrcb_type_07_error *error;
1949
1950 error = &hostrcb->hcam.u.error.u.type_07_error;
1951 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
KOSAKI Motohiroca54cb82009-12-14 18:01:15 -08001952 strim(error->failure_reason);
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001953
Brian King8cf093e2007-04-26 16:00:14 -05001954 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1955 be32_to_cpu(hostrcb->hcam.u.error.prc));
1956 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
Brian Kingac719ab2006-11-21 10:28:42 -06001957 ipr_log_hex_data(ioa_cfg, error->data,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06001958 be32_to_cpu(hostrcb->hcam.length) -
1959 (offsetof(struct ipr_hostrcb_error, u) +
1960 offsetof(struct ipr_hostrcb_type_07_error, data)));
1961}
1962
Brian King49dc6a12006-11-21 10:28:35 -06001963static const struct {
1964 u8 active;
1965 char *desc;
1966} path_active_desc[] = {
1967 { IPR_PATH_NO_INFO, "Path" },
1968 { IPR_PATH_ACTIVE, "Active path" },
1969 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1970};
1971
1972static const struct {
1973 u8 state;
1974 char *desc;
1975} path_state_desc[] = {
1976 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1977 { IPR_PATH_HEALTHY, "is healthy" },
1978 { IPR_PATH_DEGRADED, "is degraded" },
1979 { IPR_PATH_FAILED, "is failed" }
1980};
1981
1982/**
1983 * ipr_log_fabric_path - Log a fabric path error
1984 * @hostrcb: hostrcb struct
1985 * @fabric: fabric descriptor
1986 *
1987 * Return value:
1988 * none
1989 **/
1990static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1991 struct ipr_hostrcb_fabric_desc *fabric)
1992{
1993 int i, j;
1994 u8 path_state = fabric->path_state;
1995 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1996 u8 state = path_state & IPR_PATH_STATE_MASK;
1997
1998 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1999 if (path_active_desc[i].active != active)
2000 continue;
2001
2002 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2003 if (path_state_desc[j].state != state)
2004 continue;
2005
2006 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
2007 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
2008 path_active_desc[i].desc, path_state_desc[j].desc,
2009 fabric->ioa_port);
2010 } else if (fabric->cascaded_expander == 0xff) {
2011 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
2012 path_active_desc[i].desc, path_state_desc[j].desc,
2013 fabric->ioa_port, fabric->phy);
2014 } else if (fabric->phy == 0xff) {
2015 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
2016 path_active_desc[i].desc, path_state_desc[j].desc,
2017 fabric->ioa_port, fabric->cascaded_expander);
2018 } else {
2019 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
2020 path_active_desc[i].desc, path_state_desc[j].desc,
2021 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2022 }
2023 return;
2024 }
2025 }
2026
2027 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
2028 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2029}
2030
Wayne Boyer4565e372010-02-19 13:24:07 -08002031/**
2032 * ipr_log64_fabric_path - Log a fabric path error
2033 * @hostrcb: hostrcb struct
2034 * @fabric: fabric descriptor
2035 *
2036 * Return value:
2037 * none
2038 **/
2039static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
2040 struct ipr_hostrcb64_fabric_desc *fabric)
2041{
2042 int i, j;
2043 u8 path_state = fabric->path_state;
2044 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
2045 u8 state = path_state & IPR_PATH_STATE_MASK;
2046 char buffer[IPR_MAX_RES_PATH_LENGTH];
2047
2048 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
2049 if (path_active_desc[i].active != active)
2050 continue;
2051
2052 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2053 if (path_state_desc[j].state != state)
2054 continue;
2055
2056 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
2057 path_active_desc[i].desc, path_state_desc[j].desc,
Brian Kingb3b3b402013-01-11 17:43:49 -06002058 ipr_format_res_path(hostrcb->ioa_cfg,
2059 fabric->res_path,
2060 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002061 return;
2062 }
2063 }
2064
2065 ipr_err("Path state=%02X Resource Path=%s\n", path_state,
Brian Kingb3b3b402013-01-11 17:43:49 -06002066 ipr_format_res_path(hostrcb->ioa_cfg, fabric->res_path,
2067 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002068}
2069
Brian King49dc6a12006-11-21 10:28:35 -06002070static const struct {
2071 u8 type;
2072 char *desc;
2073} path_type_desc[] = {
2074 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
2075 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
2076 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
2077 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
2078};
2079
2080static const struct {
2081 u8 status;
2082 char *desc;
2083} path_status_desc[] = {
2084 { IPR_PATH_CFG_NO_PROB, "Functional" },
2085 { IPR_PATH_CFG_DEGRADED, "Degraded" },
2086 { IPR_PATH_CFG_FAILED, "Failed" },
2087 { IPR_PATH_CFG_SUSPECT, "Suspect" },
2088 { IPR_PATH_NOT_DETECTED, "Missing" },
2089 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
2090};
2091
2092static const char *link_rate[] = {
2093 "unknown",
2094 "disabled",
2095 "phy reset problem",
2096 "spinup hold",
2097 "port selector",
2098 "unknown",
2099 "unknown",
2100 "unknown",
2101 "1.5Gbps",
2102 "3.0Gbps",
2103 "unknown",
2104 "unknown",
2105 "unknown",
2106 "unknown",
2107 "unknown",
2108 "unknown"
2109};
2110
2111/**
2112 * ipr_log_path_elem - Log a fabric path element.
2113 * @hostrcb: hostrcb struct
2114 * @cfg: fabric path element struct
2115 *
2116 * Return value:
2117 * none
2118 **/
2119static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
2120 struct ipr_hostrcb_config_element *cfg)
2121{
2122 int i, j;
2123 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2124 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2125
2126 if (type == IPR_PATH_CFG_NOT_EXIST)
2127 return;
2128
2129 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2130 if (path_type_desc[i].type != type)
2131 continue;
2132
2133 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2134 if (path_status_desc[j].status != status)
2135 continue;
2136
2137 if (type == IPR_PATH_CFG_IOA_PORT) {
2138 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
2139 path_status_desc[j].desc, path_type_desc[i].desc,
2140 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2141 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2142 } else {
2143 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
2144 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2145 path_status_desc[j].desc, path_type_desc[i].desc,
2146 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2147 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2148 } else if (cfg->cascaded_expander == 0xff) {
2149 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
2150 "WWN=%08X%08X\n", path_status_desc[j].desc,
2151 path_type_desc[i].desc, cfg->phy,
2152 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2153 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2154 } else if (cfg->phy == 0xff) {
2155 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
2156 "WWN=%08X%08X\n", path_status_desc[j].desc,
2157 path_type_desc[i].desc, cfg->cascaded_expander,
2158 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2159 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2160 } else {
2161 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2162 "WWN=%08X%08X\n", path_status_desc[j].desc,
2163 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
2164 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2165 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2166 }
2167 }
2168 return;
2169 }
2170 }
2171
2172 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2173 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
2174 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2175 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2176}
2177
2178/**
Wayne Boyer4565e372010-02-19 13:24:07 -08002179 * ipr_log64_path_elem - Log a fabric path element.
2180 * @hostrcb: hostrcb struct
2181 * @cfg: fabric path element struct
2182 *
2183 * Return value:
2184 * none
2185 **/
2186static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
2187 struct ipr_hostrcb64_config_element *cfg)
2188{
2189 int i, j;
2190 u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
2191 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2192 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2193 char buffer[IPR_MAX_RES_PATH_LENGTH];
2194
2195 if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
2196 return;
2197
2198 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2199 if (path_type_desc[i].type != type)
2200 continue;
2201
2202 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2203 if (path_status_desc[j].status != status)
2204 continue;
2205
2206 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2207 path_status_desc[j].desc, path_type_desc[i].desc,
Brian Kingb3b3b402013-01-11 17:43:49 -06002208 ipr_format_res_path(hostrcb->ioa_cfg,
2209 cfg->res_path, buffer, sizeof(buffer)),
2210 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2211 be32_to_cpu(cfg->wwid[0]),
2212 be32_to_cpu(cfg->wwid[1]));
Wayne Boyer4565e372010-02-19 13:24:07 -08002213 return;
2214 }
2215 }
2216 ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
2217 "WWN=%08X%08X\n", cfg->type_status,
Brian Kingb3b3b402013-01-11 17:43:49 -06002218 ipr_format_res_path(hostrcb->ioa_cfg,
2219 cfg->res_path, buffer, sizeof(buffer)),
2220 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2221 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
Wayne Boyer4565e372010-02-19 13:24:07 -08002222}
2223
2224/**
Brian King49dc6a12006-11-21 10:28:35 -06002225 * ipr_log_fabric_error - Log a fabric error.
2226 * @ioa_cfg: ioa config struct
2227 * @hostrcb: hostrcb struct
2228 *
2229 * Return value:
2230 * none
2231 **/
2232static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2233 struct ipr_hostrcb *hostrcb)
2234{
2235 struct ipr_hostrcb_type_20_error *error;
2236 struct ipr_hostrcb_fabric_desc *fabric;
2237 struct ipr_hostrcb_config_element *cfg;
2238 int i, add_len;
2239
2240 error = &hostrcb->hcam.u.error.u.type_20_error;
2241 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2242 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2243
2244 add_len = be32_to_cpu(hostrcb->hcam.length) -
2245 (offsetof(struct ipr_hostrcb_error, u) +
2246 offsetof(struct ipr_hostrcb_type_20_error, desc));
2247
2248 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2249 ipr_log_fabric_path(hostrcb, fabric);
2250 for_each_fabric_cfg(fabric, cfg)
2251 ipr_log_path_elem(hostrcb, cfg);
2252
2253 add_len -= be16_to_cpu(fabric->length);
2254 fabric = (struct ipr_hostrcb_fabric_desc *)
2255 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2256 }
2257
Brian Kingac719ab2006-11-21 10:28:42 -06002258 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
Brian King49dc6a12006-11-21 10:28:35 -06002259}
2260
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002261/**
Wayne Boyer4565e372010-02-19 13:24:07 -08002262 * ipr_log_sis64_array_error - Log a sis64 array error.
2263 * @ioa_cfg: ioa config struct
2264 * @hostrcb: hostrcb struct
2265 *
2266 * Return value:
2267 * none
2268 **/
2269static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
2270 struct ipr_hostrcb *hostrcb)
2271{
2272 int i, num_entries;
2273 struct ipr_hostrcb_type_24_error *error;
2274 struct ipr_hostrcb64_array_data_entry *array_entry;
2275 char buffer[IPR_MAX_RES_PATH_LENGTH];
2276 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
2277
2278 error = &hostrcb->hcam.u.error64.u.type_24_error;
2279
2280 ipr_err_separator;
2281
2282 ipr_err("RAID %s Array Configuration: %s\n",
2283 error->protection_level,
Brian Kingb3b3b402013-01-11 17:43:49 -06002284 ipr_format_res_path(ioa_cfg, error->last_res_path,
2285 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002286
2287 ipr_err_separator;
2288
2289 array_entry = error->array_member;
Wayne Boyer72620262010-09-27 10:45:28 -07002290 num_entries = min_t(u32, error->num_entries,
2291 ARRAY_SIZE(error->array_member));
Wayne Boyer4565e372010-02-19 13:24:07 -08002292
2293 for (i = 0; i < num_entries; i++, array_entry++) {
2294
2295 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
2296 continue;
2297
2298 if (error->exposed_mode_adn == i)
2299 ipr_err("Exposed Array Member %d:\n", i);
2300 else
2301 ipr_err("Array Member %d:\n", i);
2302
2303 ipr_err("Array Member %d:\n", i);
2304 ipr_log_ext_vpd(&array_entry->vpd);
Wayne Boyer72620262010-09-27 10:45:28 -07002305 ipr_err("Current Location: %s\n",
Brian Kingb3b3b402013-01-11 17:43:49 -06002306 ipr_format_res_path(ioa_cfg, array_entry->res_path,
2307 buffer, sizeof(buffer)));
Wayne Boyer72620262010-09-27 10:45:28 -07002308 ipr_err("Expected Location: %s\n",
Brian Kingb3b3b402013-01-11 17:43:49 -06002309 ipr_format_res_path(ioa_cfg,
2310 array_entry->expected_res_path,
2311 buffer, sizeof(buffer)));
Wayne Boyer4565e372010-02-19 13:24:07 -08002312
2313 ipr_err_separator;
2314 }
2315}
2316
2317/**
2318 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2319 * @ioa_cfg: ioa config struct
2320 * @hostrcb: hostrcb struct
2321 *
2322 * Return value:
2323 * none
2324 **/
2325static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2326 struct ipr_hostrcb *hostrcb)
2327{
2328 struct ipr_hostrcb_type_30_error *error;
2329 struct ipr_hostrcb64_fabric_desc *fabric;
2330 struct ipr_hostrcb64_config_element *cfg;
2331 int i, add_len;
2332
2333 error = &hostrcb->hcam.u.error64.u.type_30_error;
2334
2335 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2336 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2337
2338 add_len = be32_to_cpu(hostrcb->hcam.length) -
2339 (offsetof(struct ipr_hostrcb64_error, u) +
2340 offsetof(struct ipr_hostrcb_type_30_error, desc));
2341
2342 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2343 ipr_log64_fabric_path(hostrcb, fabric);
2344 for_each_fabric_cfg(fabric, cfg)
2345 ipr_log64_path_elem(hostrcb, cfg);
2346
2347 add_len -= be16_to_cpu(fabric->length);
2348 fabric = (struct ipr_hostrcb64_fabric_desc *)
2349 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2350 }
2351
2352 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2353}
2354
2355/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 * ipr_log_generic_error - Log an adapter error.
2357 * @ioa_cfg: ioa config struct
2358 * @hostrcb: hostrcb struct
2359 *
2360 * Return value:
2361 * none
2362 **/
2363static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
2364 struct ipr_hostrcb *hostrcb)
2365{
Brian Kingac719ab2006-11-21 10:28:42 -06002366 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002367 be32_to_cpu(hostrcb->hcam.length));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368}
2369
2370/**
Wendy Xiong169b9ec2014-03-12 16:08:51 -05002371 * ipr_log_sis64_device_error - Log a cache error.
2372 * @ioa_cfg: ioa config struct
2373 * @hostrcb: hostrcb struct
2374 *
2375 * Return value:
2376 * none
2377 **/
2378static void ipr_log_sis64_device_error(struct ipr_ioa_cfg *ioa_cfg,
2379 struct ipr_hostrcb *hostrcb)
2380{
2381 struct ipr_hostrcb_type_21_error *error;
2382 char buffer[IPR_MAX_RES_PATH_LENGTH];
2383
2384 error = &hostrcb->hcam.u.error64.u.type_21_error;
2385
2386 ipr_err("-----Failing Device Information-----\n");
2387 ipr_err("World Wide Unique ID: %08X%08X%08X%08X\n",
2388 be32_to_cpu(error->wwn[0]), be32_to_cpu(error->wwn[1]),
2389 be32_to_cpu(error->wwn[2]), be32_to_cpu(error->wwn[3]));
2390 ipr_err("Device Resource Path: %s\n",
2391 __ipr_format_res_path(error->res_path,
2392 buffer, sizeof(buffer)));
2393 error->primary_problem_desc[sizeof(error->primary_problem_desc) - 1] = '\0';
2394 error->second_problem_desc[sizeof(error->second_problem_desc) - 1] = '\0';
2395 ipr_err("Primary Problem Description: %s\n", error->primary_problem_desc);
2396 ipr_err("Secondary Problem Description: %s\n", error->second_problem_desc);
2397 ipr_err("SCSI Sense Data:\n");
2398 ipr_log_hex_data(ioa_cfg, error->sense_data, sizeof(error->sense_data));
2399 ipr_err("SCSI Command Descriptor Block: \n");
2400 ipr_log_hex_data(ioa_cfg, error->cdb, sizeof(error->cdb));
2401
2402 ipr_err("Additional IOA Data:\n");
2403 ipr_log_hex_data(ioa_cfg, error->ioa_data, be32_to_cpu(error->length_of_error));
2404}
2405
2406/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2408 * @ioasc: IOASC
2409 *
2410 * This function will return the index of into the ipr_error_table
2411 * for the specified IOASC. If the IOASC is not in the table,
2412 * 0 will be returned, which points to the entry used for unknown errors.
2413 *
2414 * Return value:
2415 * index into the ipr_error_table
2416 **/
2417static u32 ipr_get_error(u32 ioasc)
2418{
2419 int i;
2420
2421 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
Brian King35a39692006-09-25 12:39:20 -05002422 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 return i;
2424
2425 return 0;
2426}
2427
2428/**
2429 * ipr_handle_log_data - Log an adapter error.
2430 * @ioa_cfg: ioa config struct
2431 * @hostrcb: hostrcb struct
2432 *
2433 * This function logs an adapter error to the system.
2434 *
2435 * Return value:
2436 * none
2437 **/
2438static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
2439 struct ipr_hostrcb *hostrcb)
2440{
2441 u32 ioasc;
2442 int error_index;
wenxiong@linux.vnet.ibm.com3185ea62014-09-24 16:25:47 -05002443 struct ipr_hostrcb_type_21_error *error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
2445 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
2446 return;
2447
2448 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
2449 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
2450
Wayne Boyer4565e372010-02-19 13:24:07 -08002451 if (ioa_cfg->sis64)
2452 ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2453 else
2454 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455
Wayne Boyer4565e372010-02-19 13:24:07 -08002456 if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
2457 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2459 scsi_report_bus_reset(ioa_cfg->host,
Wayne Boyer4565e372010-02-19 13:24:07 -08002460 hostrcb->hcam.u.error.fd_res_addr.bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 }
2462
2463 error_index = ipr_get_error(ioasc);
2464
2465 if (!ipr_error_table[error_index].log_hcam)
2466 return;
2467
wenxiong@linux.vnet.ibm.com3185ea62014-09-24 16:25:47 -05002468 if (ioasc == IPR_IOASC_HW_CMD_FAILED &&
2469 hostrcb->hcam.overlay_id == IPR_HOST_RCB_OVERLAY_ID_21) {
2470 error = &hostrcb->hcam.u.error64.u.type_21_error;
2471
2472 if (((be32_to_cpu(error->sense_data[0]) & 0x0000ff00) >> 8) == ILLEGAL_REQUEST &&
2473 ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
2474 return;
2475 }
2476
Brian King49dc6a12006-11-21 10:28:35 -06002477 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478
2479 /* Set indication we have logged an error */
2480 ioa_cfg->errors_logged++;
2481
Brian King933916f2007-03-29 12:43:30 -05002482 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 return;
brking@us.ibm.comcf852032005-11-01 17:00:47 -06002484 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
2485 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
2487 switch (hostrcb->hcam.overlay_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 case IPR_HOST_RCB_OVERLAY_ID_2:
2489 ipr_log_cache_error(ioa_cfg, hostrcb);
2490 break;
2491 case IPR_HOST_RCB_OVERLAY_ID_3:
2492 ipr_log_config_error(ioa_cfg, hostrcb);
2493 break;
2494 case IPR_HOST_RCB_OVERLAY_ID_4:
2495 case IPR_HOST_RCB_OVERLAY_ID_6:
2496 ipr_log_array_error(ioa_cfg, hostrcb);
2497 break;
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06002498 case IPR_HOST_RCB_OVERLAY_ID_7:
2499 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
2500 break;
brking@us.ibm.comee0f05b2005-11-01 17:02:15 -06002501 case IPR_HOST_RCB_OVERLAY_ID_12:
2502 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
2503 break;
2504 case IPR_HOST_RCB_OVERLAY_ID_13:
2505 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
2506 break;
2507 case IPR_HOST_RCB_OVERLAY_ID_14:
2508 case IPR_HOST_RCB_OVERLAY_ID_16:
2509 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
2510 break;
2511 case IPR_HOST_RCB_OVERLAY_ID_17:
2512 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
2513 break;
Brian King49dc6a12006-11-21 10:28:35 -06002514 case IPR_HOST_RCB_OVERLAY_ID_20:
2515 ipr_log_fabric_error(ioa_cfg, hostrcb);
2516 break;
Wendy Xiong169b9ec2014-03-12 16:08:51 -05002517 case IPR_HOST_RCB_OVERLAY_ID_21:
2518 ipr_log_sis64_device_error(ioa_cfg, hostrcb);
2519 break;
Wayne Boyer4565e372010-02-19 13:24:07 -08002520 case IPR_HOST_RCB_OVERLAY_ID_23:
2521 ipr_log_sis64_config_error(ioa_cfg, hostrcb);
2522 break;
2523 case IPR_HOST_RCB_OVERLAY_ID_24:
2524 case IPR_HOST_RCB_OVERLAY_ID_26:
2525 ipr_log_sis64_array_error(ioa_cfg, hostrcb);
2526 break;
2527 case IPR_HOST_RCB_OVERLAY_ID_30:
2528 ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
2529 break;
brking@us.ibm.comcf852032005-11-01 17:00:47 -06002530 case IPR_HOST_RCB_OVERLAY_ID_1:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 default:
brking@us.ibm.coma9cfca92005-11-01 17:00:41 -06002533 ipr_log_generic_error(ioa_cfg, hostrcb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 break;
2535 }
2536}
2537
2538/**
2539 * ipr_process_error - Op done function for an adapter error log.
2540 * @ipr_cmd: ipr command struct
2541 *
2542 * This function is the op done function for an error log host
2543 * controlled async from the adapter. It will log the error and
2544 * send the HCAM back to the adapter.
2545 *
2546 * Return value:
2547 * none
2548 **/
2549static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2550{
2551 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2552 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07002553 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Wayne Boyer4565e372010-02-19 13:24:07 -08002554 u32 fd_ioasc;
2555
2556 if (ioa_cfg->sis64)
2557 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2558 else
2559 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560
2561 list_del(&hostrcb->queue);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06002562 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
2564 if (!ioasc) {
2565 ipr_handle_log_data(ioa_cfg, hostrcb);
Brian King65f56472007-04-26 16:00:12 -05002566 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
2567 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
2569 dev_err(&ioa_cfg->pdev->dev,
2570 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
2571 }
2572
2573 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2574}
2575
2576/**
2577 * ipr_timeout - An internally generated op has timed out.
2578 * @ipr_cmd: ipr command struct
2579 *
2580 * This function blocks host requests and initiates an
2581 * adapter reset.
2582 *
2583 * Return value:
2584 * none
2585 **/
2586static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
2587{
2588 unsigned long lock_flags = 0;
2589 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2590
2591 ENTER;
2592 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2593
2594 ioa_cfg->errors_logged++;
2595 dev_err(&ioa_cfg->pdev->dev,
2596 "Adapter being reset due to command timeout.\n");
2597
2598 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2599 ioa_cfg->sdt_state = GET_DUMP;
2600
2601 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
2602 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2603
2604 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2605 LEAVE;
2606}
2607
2608/**
2609 * ipr_oper_timeout - Adapter timed out transitioning to operational
2610 * @ipr_cmd: ipr command struct
2611 *
2612 * This function blocks host requests and initiates an
2613 * adapter reset.
2614 *
2615 * Return value:
2616 * none
2617 **/
2618static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
2619{
2620 unsigned long lock_flags = 0;
2621 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2622
2623 ENTER;
2624 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2625
2626 ioa_cfg->errors_logged++;
2627 dev_err(&ioa_cfg->pdev->dev,
2628 "Adapter timed out transitioning to operational.\n");
2629
2630 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2631 ioa_cfg->sdt_state = GET_DUMP;
2632
2633 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
2634 if (ipr_fastfail)
2635 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
2636 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2637 }
2638
2639 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2640 LEAVE;
2641}
2642
2643/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 * ipr_find_ses_entry - Find matching SES in SES table
2645 * @res: resource entry struct of SES
2646 *
2647 * Return value:
2648 * pointer to SES table entry / NULL on failure
2649 **/
2650static const struct ipr_ses_table_entry *
2651ipr_find_ses_entry(struct ipr_resource_entry *res)
2652{
2653 int i, j, matches;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002654 struct ipr_std_inq_vpids *vpids;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 const struct ipr_ses_table_entry *ste = ipr_ses_table;
2656
2657 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
2658 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
2659 if (ste->compare_product_id_byte[j] == 'X') {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002660 vpids = &res->std_inq_data.vpids;
2661 if (vpids->product_id[j] == ste->product_id[j])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 matches++;
2663 else
2664 break;
2665 } else
2666 matches++;
2667 }
2668
2669 if (matches == IPR_PROD_ID_LEN)
2670 return ste;
2671 }
2672
2673 return NULL;
2674}
2675
2676/**
2677 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2678 * @ioa_cfg: ioa config struct
2679 * @bus: SCSI bus
2680 * @bus_width: bus width
2681 *
2682 * Return value:
2683 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2684 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2685 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2686 * max 160MHz = max 320MB/sec).
2687 **/
2688static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
2689{
2690 struct ipr_resource_entry *res;
2691 const struct ipr_ses_table_entry *ste;
2692 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
2693
2694 /* Loop through each config table entry in the config table buffer */
2695 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002696 if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 continue;
2698
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08002699 if (bus != res->bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 continue;
2701
2702 if (!(ste = ipr_find_ses_entry(res)))
2703 continue;
2704
2705 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
2706 }
2707
2708 return max_xfer_rate;
2709}
2710
2711/**
2712 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2713 * @ioa_cfg: ioa config struct
2714 * @max_delay: max delay in micro-seconds to wait
2715 *
2716 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2717 *
2718 * Return value:
2719 * 0 on success / other on failure
2720 **/
2721static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
2722{
2723 volatile u32 pcii_reg;
2724 int delay = 1;
2725
2726 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2727 while (delay < max_delay) {
2728 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
2729
2730 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
2731 return 0;
2732
2733 /* udelay cannot be used if delay is more than a few milliseconds */
2734 if ((delay / 1000) > MAX_UDELAY_MS)
2735 mdelay(delay / 1000);
2736 else
2737 udelay(delay);
2738
2739 delay += delay;
2740 }
2741 return -EIO;
2742}
2743
2744/**
Wayne Boyerdcbad002010-02-19 13:24:14 -08002745 * ipr_get_sis64_dump_data_section - Dump IOA memory
2746 * @ioa_cfg: ioa config struct
2747 * @start_addr: adapter address to dump
2748 * @dest: destination kernel buffer
2749 * @length_in_words: length to dump in 4 byte words
2750 *
2751 * Return value:
2752 * 0 on success
2753 **/
2754static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2755 u32 start_addr,
2756 __be32 *dest, u32 length_in_words)
2757{
2758 int i;
2759
2760 for (i = 0; i < length_in_words; i++) {
2761 writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
2762 *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
2763 dest++;
2764 }
2765
2766 return 0;
2767}
2768
2769/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 * ipr_get_ldump_data_section - Dump IOA memory
2771 * @ioa_cfg: ioa config struct
2772 * @start_addr: adapter address to dump
2773 * @dest: destination kernel buffer
2774 * @length_in_words: length to dump in 4 byte words
2775 *
2776 * Return value:
2777 * 0 on success / -EIO on failure
2778 **/
2779static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2780 u32 start_addr,
2781 __be32 *dest, u32 length_in_words)
2782{
2783 volatile u32 temp_pcii_reg;
2784 int i, delay = 0;
2785
Wayne Boyerdcbad002010-02-19 13:24:14 -08002786 if (ioa_cfg->sis64)
2787 return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
2788 dest, length_in_words);
2789
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 /* Write IOA interrupt reg starting LDUMP state */
2791 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
Wayne Boyer214777b2010-02-19 13:24:26 -08002792 ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793
2794 /* Wait for IO debug acknowledge */
2795 if (ipr_wait_iodbg_ack(ioa_cfg,
2796 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
2797 dev_err(&ioa_cfg->pdev->dev,
2798 "IOA dump long data transfer timeout\n");
2799 return -EIO;
2800 }
2801
2802 /* Signal LDUMP interlocked - clear IO debug ack */
2803 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2804 ioa_cfg->regs.clr_interrupt_reg);
2805
2806 /* Write Mailbox with starting address */
2807 writel(start_addr, ioa_cfg->ioa_mailbox);
2808
2809 /* Signal address valid - clear IOA Reset alert */
2810 writel(IPR_UPROCI_RESET_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002811 ioa_cfg->regs.clr_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812
2813 for (i = 0; i < length_in_words; i++) {
2814 /* Wait for IO debug acknowledge */
2815 if (ipr_wait_iodbg_ack(ioa_cfg,
2816 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2817 dev_err(&ioa_cfg->pdev->dev,
2818 "IOA dump short data transfer timeout\n");
2819 return -EIO;
2820 }
2821
2822 /* Read data from mailbox and increment destination pointer */
2823 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2824 dest++;
2825
2826 /* For all but the last word of data, signal data received */
2827 if (i < (length_in_words - 1)) {
2828 /* Signal dump data received - Clear IO debug Ack */
2829 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2830 ioa_cfg->regs.clr_interrupt_reg);
2831 }
2832 }
2833
2834 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2835 writel(IPR_UPROCI_RESET_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002836 ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837
2838 writel(IPR_UPROCI_IO_DEBUG_ALERT,
Wayne Boyer214777b2010-02-19 13:24:26 -08002839 ioa_cfg->regs.clr_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840
2841 /* Signal dump data received - Clear IO debug Ack */
2842 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2843 ioa_cfg->regs.clr_interrupt_reg);
2844
2845 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2846 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2847 temp_pcii_reg =
Wayne Boyer214777b2010-02-19 13:24:26 -08002848 readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849
2850 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2851 return 0;
2852
2853 udelay(10);
2854 delay += 10;
2855 }
2856
2857 return 0;
2858}
2859
2860#ifdef CONFIG_SCSI_IPR_DUMP
2861/**
2862 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2863 * @ioa_cfg: ioa config struct
2864 * @pci_address: adapter address
2865 * @length: length of data to copy
2866 *
2867 * Copy data from PCI adapter to kernel buffer.
2868 * Note: length MUST be a 4 byte multiple
2869 * Return value:
2870 * 0 on success / other on failure
2871 **/
2872static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2873 unsigned long pci_address, u32 length)
2874{
2875 int bytes_copied = 0;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002876 int cur_len, rc, rem_len, rem_page_len, max_dump_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 __be32 *page;
2878 unsigned long lock_flags = 0;
2879 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2880
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002881 if (ioa_cfg->sis64)
2882 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2883 else
2884 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2885
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 while (bytes_copied < length &&
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03002887 (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 if (ioa_dump->page_offset >= PAGE_SIZE ||
2889 ioa_dump->page_offset == 0) {
2890 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2891
2892 if (!page) {
2893 ipr_trace;
2894 return bytes_copied;
2895 }
2896
2897 ioa_dump->page_offset = 0;
2898 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2899 ioa_dump->next_page_index++;
2900 } else
2901 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2902
2903 rem_len = length - bytes_copied;
2904 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2905 cur_len = min(rem_len, rem_page_len);
2906
2907 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2908 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2909 rc = -EIO;
2910 } else {
2911 rc = ipr_get_ldump_data_section(ioa_cfg,
2912 pci_address + bytes_copied,
2913 &page[ioa_dump->page_offset / 4],
2914 (cur_len / sizeof(u32)));
2915 }
2916 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2917
2918 if (!rc) {
2919 ioa_dump->page_offset += cur_len;
2920 bytes_copied += cur_len;
2921 } else {
2922 ipr_trace;
2923 break;
2924 }
2925 schedule();
2926 }
2927
2928 return bytes_copied;
2929}
2930
2931/**
2932 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2933 * @hdr: dump entry header struct
2934 *
2935 * Return value:
2936 * nothing
2937 **/
2938static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2939{
2940 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2941 hdr->num_elems = 1;
2942 hdr->offset = sizeof(*hdr);
2943 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2944}
2945
2946/**
2947 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2948 * @ioa_cfg: ioa config struct
2949 * @driver_dump: driver dump struct
2950 *
2951 * Return value:
2952 * nothing
2953 **/
2954static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2955 struct ipr_driver_dump *driver_dump)
2956{
2957 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2958
2959 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2960 driver_dump->ioa_type_entry.hdr.len =
2961 sizeof(struct ipr_dump_ioa_type_entry) -
2962 sizeof(struct ipr_dump_entry_header);
2963 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2964 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2965 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2966 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2967 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2968 ucode_vpd->minor_release[1];
2969 driver_dump->hdr.num_entries++;
2970}
2971
2972/**
2973 * ipr_dump_version_data - Fill in the driver version in the dump.
2974 * @ioa_cfg: ioa config struct
2975 * @driver_dump: driver dump struct
2976 *
2977 * Return value:
2978 * nothing
2979 **/
2980static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2981 struct ipr_driver_dump *driver_dump)
2982{
2983 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2984 driver_dump->version_entry.hdr.len =
2985 sizeof(struct ipr_dump_version_entry) -
2986 sizeof(struct ipr_dump_entry_header);
2987 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2988 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2989 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2990 driver_dump->hdr.num_entries++;
2991}
2992
2993/**
2994 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2995 * @ioa_cfg: ioa config struct
2996 * @driver_dump: driver dump struct
2997 *
2998 * Return value:
2999 * nothing
3000 **/
3001static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
3002 struct ipr_driver_dump *driver_dump)
3003{
3004 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
3005 driver_dump->trace_entry.hdr.len =
3006 sizeof(struct ipr_dump_trace_entry) -
3007 sizeof(struct ipr_dump_entry_header);
3008 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3009 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
3010 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
3011 driver_dump->hdr.num_entries++;
3012}
3013
3014/**
3015 * ipr_dump_location_data - Fill in the IOA location in the dump.
3016 * @ioa_cfg: ioa config struct
3017 * @driver_dump: driver dump struct
3018 *
3019 * Return value:
3020 * nothing
3021 **/
3022static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
3023 struct ipr_driver_dump *driver_dump)
3024{
3025 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
3026 driver_dump->location_entry.hdr.len =
3027 sizeof(struct ipr_dump_location_entry) -
3028 sizeof(struct ipr_dump_entry_header);
3029 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
3030 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
Kay Sievers71610f52008-12-03 22:41:36 +01003031 strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 driver_dump->hdr.num_entries++;
3033}
3034
3035/**
3036 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
3037 * @ioa_cfg: ioa config struct
3038 * @dump: dump struct
3039 *
3040 * Return value:
3041 * nothing
3042 **/
3043static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
3044{
3045 unsigned long start_addr, sdt_word;
3046 unsigned long lock_flags = 0;
3047 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
3048 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003049 u32 num_entries, max_num_entries, start_off, end_off;
3050 u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 struct ipr_sdt *sdt;
Wayne Boyerdcbad002010-02-19 13:24:14 -08003052 int valid = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 int i;
3054
3055 ENTER;
3056
3057 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3058
Brian King41e9a692011-09-21 08:51:11 -05003059 if (ioa_cfg->sdt_state != READ_DUMP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3061 return;
3062 }
3063
Wayne Boyer110def82010-11-04 09:36:16 -07003064 if (ioa_cfg->sis64) {
3065 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3066 ssleep(IPR_DUMP_DELAY_SECONDS);
3067 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3068 }
3069
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 start_addr = readl(ioa_cfg->ioa_mailbox);
3071
Wayne Boyerdcbad002010-02-19 13:24:14 -08003072 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 dev_err(&ioa_cfg->pdev->dev,
3074 "Invalid dump table format: %lx\n", start_addr);
3075 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3076 return;
3077 }
3078
3079 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
3080
3081 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
3082
3083 /* Initialize the overall dump header */
3084 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
3085 driver_dump->hdr.num_entries = 1;
3086 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
3087 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
3088 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
3089 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
3090
3091 ipr_dump_version_data(ioa_cfg, driver_dump);
3092 ipr_dump_location_data(ioa_cfg, driver_dump);
3093 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
3094 ipr_dump_trace_data(ioa_cfg, driver_dump);
3095
3096 /* Update dump_header */
3097 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
3098
3099 /* IOA Dump entry */
3100 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 ioa_dump->hdr.len = 0;
3102 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3103 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
3104
3105 /* First entries in sdt are actually a list of dump addresses and
3106 lengths to gather the real dump data. sdt represents the pointer
3107 to the ioa generated dump table. Dump data will be extracted based
3108 on entries in this table */
3109 sdt = &ioa_dump->sdt;
3110
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003111 if (ioa_cfg->sis64) {
3112 max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
3113 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
3114 } else {
3115 max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
3116 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
3117 }
3118
3119 bytes_to_copy = offsetof(struct ipr_sdt, entry) +
3120 (max_num_entries * sizeof(struct ipr_sdt_entry));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003122 bytes_to_copy / sizeof(__be32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123
3124 /* Smart Dump table is ready to use and the first entry is valid */
Wayne Boyerdcbad002010-02-19 13:24:14 -08003125 if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
3126 (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 dev_err(&ioa_cfg->pdev->dev,
3128 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
3129 rc, be32_to_cpu(sdt->hdr.state));
3130 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
3131 ioa_cfg->sdt_state = DUMP_OBTAINED;
3132 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3133 return;
3134 }
3135
3136 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
3137
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003138 if (num_entries > max_num_entries)
3139 num_entries = max_num_entries;
3140
3141 /* Update dump length to the actual data to be copied */
3142 dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
3143 if (ioa_cfg->sis64)
3144 dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
3145 else
3146 dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147
3148 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3149
3150 for (i = 0; i < num_entries; i++) {
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003151 if (ioa_dump->hdr.len > max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3153 break;
3154 }
3155
3156 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
Wayne Boyerdcbad002010-02-19 13:24:14 -08003157 sdt_word = be32_to_cpu(sdt->entry[i].start_token);
3158 if (ioa_cfg->sis64)
3159 bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
3160 else {
3161 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
3162 end_off = be32_to_cpu(sdt->entry[i].end_token);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163
Wayne Boyerdcbad002010-02-19 13:24:14 -08003164 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
3165 bytes_to_copy = end_off - start_off;
3166 else
3167 valid = 0;
3168 }
3169 if (valid) {
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003170 if (bytes_to_copy > max_dump_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
3172 continue;
3173 }
3174
3175 /* Copy data from adapter to driver buffers */
3176 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
3177 bytes_to_copy);
3178
3179 ioa_dump->hdr.len += bytes_copied;
3180
3181 if (bytes_copied != bytes_to_copy) {
3182 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3183 break;
3184 }
3185 }
3186 }
3187 }
3188
3189 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
3190
3191 /* Update dump_header */
3192 driver_dump->hdr.len += ioa_dump->hdr.len;
3193 wmb();
3194 ioa_cfg->sdt_state = DUMP_OBTAINED;
3195 LEAVE;
3196}
3197
3198#else
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003199#define ipr_get_ioa_dump(ioa_cfg, dump) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200#endif
3201
3202/**
3203 * ipr_release_dump - Free adapter dump memory
3204 * @kref: kref struct
3205 *
3206 * Return value:
3207 * nothing
3208 **/
3209static void ipr_release_dump(struct kref *kref)
3210{
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003211 struct ipr_dump *dump = container_of(kref, struct ipr_dump, kref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
3213 unsigned long lock_flags = 0;
3214 int i;
3215
3216 ENTER;
3217 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3218 ioa_cfg->dump = NULL;
3219 ioa_cfg->sdt_state = INACTIVE;
3220 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3221
3222 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
3223 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
3224
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03003225 vfree(dump->ioa_dump.ioa_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 kfree(dump);
3227 LEAVE;
3228}
3229
3230/**
3231 * ipr_worker_thread - Worker thread
David Howellsc4028952006-11-22 14:57:56 +00003232 * @work: ioa config struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 *
3234 * Called at task level from a work thread. This function takes care
3235 * of adding and removing device from the mid-layer as configuration
3236 * changes are detected by the adapter.
3237 *
3238 * Return value:
3239 * nothing
3240 **/
David Howellsc4028952006-11-22 14:57:56 +00003241static void ipr_worker_thread(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242{
3243 unsigned long lock_flags;
3244 struct ipr_resource_entry *res;
3245 struct scsi_device *sdev;
3246 struct ipr_dump *dump;
David Howellsc4028952006-11-22 14:57:56 +00003247 struct ipr_ioa_cfg *ioa_cfg =
3248 container_of(work, struct ipr_ioa_cfg, work_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 u8 bus, target, lun;
3250 int did_work;
3251
3252 ENTER;
3253 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3254
Brian King41e9a692011-09-21 08:51:11 -05003255 if (ioa_cfg->sdt_state == READ_DUMP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 dump = ioa_cfg->dump;
3257 if (!dump) {
3258 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3259 return;
3260 }
3261 kref_get(&dump->kref);
3262 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3263 ipr_get_ioa_dump(ioa_cfg, dump);
3264 kref_put(&dump->kref, ipr_release_dump);
3265
3266 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Brian King4c647e92011-10-15 09:08:56 -05003267 if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3269 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3270 return;
3271 }
3272
3273restart:
3274 do {
3275 did_work = 0;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06003276 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds ||
3277 !ioa_cfg->allow_ml_add_del) {
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
3314 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Tony Jonesee959b02008-02-22 00:13:36 +01003315 kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 LEAVE;
3317}
3318
3319#ifdef CONFIG_SCSI_IPR_TRACE
3320/**
3321 * ipr_read_trace - Dump the adapter trace
Chris Wright2c3c8be2010-05-12 18:28:57 -07003322 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08003324 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 * @buf: buffer
3326 * @off: offset
3327 * @count: buffer size
3328 *
3329 * Return value:
3330 * number of bytes printed to buffer
3331 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07003332static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08003333 struct bin_attribute *bin_attr,
3334 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335{
Tony Jonesee959b02008-02-22 00:13:36 +01003336 struct device *dev = container_of(kobj, struct device, kobj);
3337 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3339 unsigned long lock_flags = 0;
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003340 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341
3342 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003343 ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
3344 IPR_TRACE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Akinobu Mitad777aaf2008-09-22 14:56:47 -07003346
3347 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348}
3349
3350static struct bin_attribute ipr_trace_attr = {
3351 .attr = {
3352 .name = "trace",
3353 .mode = S_IRUGO,
3354 },
3355 .size = 0,
3356 .read = ipr_read_trace,
3357};
3358#endif
3359
3360/**
3361 * ipr_show_fw_version - Show the firmware version
Tony Jonesee959b02008-02-22 00:13:36 +01003362 * @dev: class device struct
3363 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 *
3365 * Return value:
3366 * number of bytes printed to buffer
3367 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003368static ssize_t ipr_show_fw_version(struct device *dev,
3369 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370{
Tony Jonesee959b02008-02-22 00:13:36 +01003371 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3373 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
3374 unsigned long lock_flags = 0;
3375 int len;
3376
3377 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3378 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
3379 ucode_vpd->major_release, ucode_vpd->card_type,
3380 ucode_vpd->minor_release[0],
3381 ucode_vpd->minor_release[1]);
3382 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3383 return len;
3384}
3385
Tony Jonesee959b02008-02-22 00:13:36 +01003386static struct device_attribute ipr_fw_version_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 .attr = {
3388 .name = "fw_version",
3389 .mode = S_IRUGO,
3390 },
3391 .show = ipr_show_fw_version,
3392};
3393
3394/**
3395 * ipr_show_log_level - Show the adapter's error logging level
Tony Jonesee959b02008-02-22 00:13:36 +01003396 * @dev: class device struct
3397 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 *
3399 * Return value:
3400 * number of bytes printed to buffer
3401 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003402static ssize_t ipr_show_log_level(struct device *dev,
3403 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404{
Tony Jonesee959b02008-02-22 00:13:36 +01003405 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3407 unsigned long lock_flags = 0;
3408 int len;
3409
3410 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3411 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
3412 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3413 return len;
3414}
3415
3416/**
3417 * ipr_store_log_level - Change the adapter's error logging level
Tony Jonesee959b02008-02-22 00:13:36 +01003418 * @dev: class device struct
3419 * @buf: buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 *
3421 * Return value:
3422 * number of bytes printed to buffer
3423 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003424static ssize_t ipr_store_log_level(struct device *dev,
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003425 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 const char *buf, size_t count)
3427{
Tony Jonesee959b02008-02-22 00:13:36 +01003428 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3430 unsigned long lock_flags = 0;
3431
3432 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3433 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
3434 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3435 return strlen(buf);
3436}
3437
Tony Jonesee959b02008-02-22 00:13:36 +01003438static struct device_attribute ipr_log_level_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 .attr = {
3440 .name = "log_level",
3441 .mode = S_IRUGO | S_IWUSR,
3442 },
3443 .show = ipr_show_log_level,
3444 .store = ipr_store_log_level
3445};
3446
3447/**
3448 * ipr_store_diagnostics - IOA Diagnostics interface
Tony Jonesee959b02008-02-22 00:13:36 +01003449 * @dev: device struct
3450 * @buf: buffer
3451 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 *
3453 * This function will reset the adapter and wait a reasonable
3454 * amount of time for any errors that the adapter might log.
3455 *
3456 * Return value:
3457 * count on success / other on failure
3458 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003459static ssize_t ipr_store_diagnostics(struct device *dev,
3460 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461 const char *buf, size_t count)
3462{
Tony Jonesee959b02008-02-22 00:13:36 +01003463 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3465 unsigned long lock_flags = 0;
3466 int rc = count;
3467
3468 if (!capable(CAP_SYS_ADMIN))
3469 return -EACCES;
3470
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003472 while (ioa_cfg->in_reset_reload) {
Brian King970ea292007-04-26 16:00:06 -05003473 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3474 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3475 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3476 }
3477
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 ioa_cfg->errors_logged = 0;
3479 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3480
3481 if (ioa_cfg->in_reset_reload) {
3482 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3483 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3484
3485 /* Wait for a second for any errors to be logged */
3486 msleep(1000);
3487 } else {
3488 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3489 return -EIO;
3490 }
3491
3492 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3493 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
3494 rc = -EIO;
3495 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3496
3497 return rc;
3498}
3499
Tony Jonesee959b02008-02-22 00:13:36 +01003500static struct device_attribute ipr_diagnostics_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 .attr = {
3502 .name = "run_diagnostics",
3503 .mode = S_IWUSR,
3504 },
3505 .store = ipr_store_diagnostics
3506};
3507
3508/**
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003509 * ipr_show_adapter_state - Show the adapter's state
Tony Jonesee959b02008-02-22 00:13:36 +01003510 * @class_dev: device struct
3511 * @buf: buffer
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003512 *
3513 * Return value:
3514 * number of bytes printed to buffer
3515 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003516static ssize_t ipr_show_adapter_state(struct device *dev,
3517 struct device_attribute *attr, char *buf)
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003518{
Tony Jonesee959b02008-02-22 00:13:36 +01003519 struct Scsi_Host *shost = class_to_shost(dev);
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003520 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3521 unsigned long lock_flags = 0;
3522 int len;
3523
3524 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06003525 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003526 len = snprintf(buf, PAGE_SIZE, "offline\n");
3527 else
3528 len = snprintf(buf, PAGE_SIZE, "online\n");
3529 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3530 return len;
3531}
3532
3533/**
3534 * ipr_store_adapter_state - Change adapter state
Tony Jonesee959b02008-02-22 00:13:36 +01003535 * @dev: device struct
3536 * @buf: buffer
3537 * @count: buffer size
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003538 *
3539 * This function will change the adapter's state.
3540 *
3541 * Return value:
3542 * count on success / other on failure
3543 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003544static ssize_t ipr_store_adapter_state(struct device *dev,
3545 struct device_attribute *attr,
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003546 const char *buf, size_t count)
3547{
Tony Jonesee959b02008-02-22 00:13:36 +01003548 struct Scsi_Host *shost = class_to_shost(dev);
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003549 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3550 unsigned long lock_flags;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06003551 int result = count, i;
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003552
3553 if (!capable(CAP_SYS_ADMIN))
3554 return -EACCES;
3555
3556 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06003557 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead &&
3558 !strncmp(buf, "online", 6)) {
3559 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
3560 spin_lock(&ioa_cfg->hrrq[i]._lock);
3561 ioa_cfg->hrrq[i].ioa_is_dead = 0;
3562 spin_unlock(&ioa_cfg->hrrq[i]._lock);
3563 }
3564 wmb();
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003565 ioa_cfg->reset_retries = 0;
3566 ioa_cfg->in_ioa_bringdown = 0;
3567 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3568 }
3569 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3570 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3571
3572 return result;
3573}
3574
Tony Jonesee959b02008-02-22 00:13:36 +01003575static struct device_attribute ipr_ioa_state_attr = {
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003576 .attr = {
Brian King49dd0962008-04-28 17:36:20 -05003577 .name = "online_state",
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06003578 .mode = S_IRUGO | S_IWUSR,
3579 },
3580 .show = ipr_show_adapter_state,
3581 .store = ipr_store_adapter_state
3582};
3583
3584/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 * ipr_store_reset_adapter - Reset the adapter
Tony Jonesee959b02008-02-22 00:13:36 +01003586 * @dev: device struct
3587 * @buf: buffer
3588 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589 *
3590 * This function will reset the adapter.
3591 *
3592 * Return value:
3593 * count on success / other on failure
3594 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003595static ssize_t ipr_store_reset_adapter(struct device *dev,
3596 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 const char *buf, size_t count)
3598{
Tony Jonesee959b02008-02-22 00:13:36 +01003599 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3601 unsigned long lock_flags;
3602 int result = count;
3603
3604 if (!capable(CAP_SYS_ADMIN))
3605 return -EACCES;
3606
3607 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3608 if (!ioa_cfg->in_reset_reload)
3609 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3610 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3611 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3612
3613 return result;
3614}
3615
Tony Jonesee959b02008-02-22 00:13:36 +01003616static struct device_attribute ipr_ioa_reset_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 .attr = {
3618 .name = "reset_host",
3619 .mode = S_IWUSR,
3620 },
3621 .store = ipr_store_reset_adapter
3622};
3623
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06003624static int ipr_iopoll(struct blk_iopoll *iop, int budget);
3625 /**
3626 * ipr_show_iopoll_weight - Show ipr polling mode
3627 * @dev: class device struct
3628 * @buf: buffer
3629 *
3630 * Return value:
3631 * number of bytes printed to buffer
3632 **/
3633static ssize_t ipr_show_iopoll_weight(struct device *dev,
3634 struct device_attribute *attr, char *buf)
3635{
3636 struct Scsi_Host *shost = class_to_shost(dev);
3637 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3638 unsigned long lock_flags = 0;
3639 int len;
3640
3641 spin_lock_irqsave(shost->host_lock, lock_flags);
3642 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->iopoll_weight);
3643 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3644
3645 return len;
3646}
3647
3648/**
3649 * ipr_store_iopoll_weight - Change the adapter's polling mode
3650 * @dev: class device struct
3651 * @buf: buffer
3652 *
3653 * Return value:
3654 * number of bytes printed to buffer
3655 **/
3656static ssize_t ipr_store_iopoll_weight(struct device *dev,
3657 struct device_attribute *attr,
3658 const char *buf, size_t count)
3659{
3660 struct Scsi_Host *shost = class_to_shost(dev);
3661 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3662 unsigned long user_iopoll_weight;
3663 unsigned long lock_flags = 0;
3664 int i;
3665
3666 if (!ioa_cfg->sis64) {
3667 dev_info(&ioa_cfg->pdev->dev, "blk-iopoll not supported on this adapter\n");
3668 return -EINVAL;
3669 }
3670 if (kstrtoul(buf, 10, &user_iopoll_weight))
3671 return -EINVAL;
3672
3673 if (user_iopoll_weight > 256) {
3674 dev_info(&ioa_cfg->pdev->dev, "Invalid blk-iopoll weight. It must be less than 256\n");
3675 return -EINVAL;
3676 }
3677
3678 if (user_iopoll_weight == ioa_cfg->iopoll_weight) {
3679 dev_info(&ioa_cfg->pdev->dev, "Current blk-iopoll weight has the same weight\n");
3680 return strlen(buf);
3681 }
3682
Jens Axboe89f8b332014-03-13 09:38:42 -06003683 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06003684 for (i = 1; i < ioa_cfg->hrrq_num; i++)
3685 blk_iopoll_disable(&ioa_cfg->hrrq[i].iopoll);
3686 }
3687
3688 spin_lock_irqsave(shost->host_lock, lock_flags);
3689 ioa_cfg->iopoll_weight = user_iopoll_weight;
Jens Axboe89f8b332014-03-13 09:38:42 -06003690 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06003691 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
3692 blk_iopoll_init(&ioa_cfg->hrrq[i].iopoll,
3693 ioa_cfg->iopoll_weight, ipr_iopoll);
3694 blk_iopoll_enable(&ioa_cfg->hrrq[i].iopoll);
3695 }
3696 }
3697 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3698
3699 return strlen(buf);
3700}
3701
3702static struct device_attribute ipr_iopoll_weight_attr = {
3703 .attr = {
3704 .name = "iopoll_weight",
3705 .mode = S_IRUGO | S_IWUSR,
3706 },
3707 .show = ipr_show_iopoll_weight,
3708 .store = ipr_store_iopoll_weight
3709};
3710
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711/**
3712 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3713 * @buf_len: buffer length
3714 *
3715 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3716 * list to use for microcode download
3717 *
3718 * Return value:
3719 * pointer to sglist / NULL on failure
3720 **/
3721static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
3722{
3723 int sg_size, order, bsize_elem, num_elem, i, j;
3724 struct ipr_sglist *sglist;
3725 struct scatterlist *scatterlist;
3726 struct page *page;
3727
3728 /* Get the minimum size per scatter/gather element */
3729 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
3730
3731 /* Get the actual size per element */
3732 order = get_order(sg_size);
3733
3734 /* Determine the actual number of bytes per element */
3735 bsize_elem = PAGE_SIZE * (1 << order);
3736
3737 /* Determine the actual number of sg entries needed */
3738 if (buf_len % bsize_elem)
3739 num_elem = (buf_len / bsize_elem) + 1;
3740 else
3741 num_elem = buf_len / bsize_elem;
3742
3743 /* Allocate a scatter/gather list for the DMA */
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06003744 sglist = kzalloc(sizeof(struct ipr_sglist) +
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 (sizeof(struct scatterlist) * (num_elem - 1)),
3746 GFP_KERNEL);
3747
3748 if (sglist == NULL) {
3749 ipr_trace;
3750 return NULL;
3751 }
3752
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 scatterlist = sglist->scatterlist;
Jens Axboe45711f12007-10-22 21:19:53 +02003754 sg_init_table(scatterlist, num_elem);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755
3756 sglist->order = order;
3757 sglist->num_sg = num_elem;
3758
3759 /* Allocate a bunch of sg elements */
3760 for (i = 0; i < num_elem; i++) {
3761 page = alloc_pages(GFP_KERNEL, order);
3762 if (!page) {
3763 ipr_trace;
3764
3765 /* Free up what we already allocated */
3766 for (j = i - 1; j >= 0; j--)
Jens Axboe45711f12007-10-22 21:19:53 +02003767 __free_pages(sg_page(&scatterlist[j]), order);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 kfree(sglist);
3769 return NULL;
3770 }
3771
Jens Axboe642f149032007-10-24 11:20:47 +02003772 sg_set_page(&scatterlist[i], page, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 }
3774
3775 return sglist;
3776}
3777
3778/**
3779 * ipr_free_ucode_buffer - Frees a microcode download buffer
3780 * @p_dnld: scatter/gather list pointer
3781 *
3782 * Free a DMA'able ucode download buffer previously allocated with
3783 * ipr_alloc_ucode_buffer
3784 *
3785 * Return value:
3786 * nothing
3787 **/
3788static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
3789{
3790 int i;
3791
3792 for (i = 0; i < sglist->num_sg; i++)
Jens Axboe45711f12007-10-22 21:19:53 +02003793 __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794
3795 kfree(sglist);
3796}
3797
3798/**
3799 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3800 * @sglist: scatter/gather list pointer
3801 * @buffer: buffer pointer
3802 * @len: buffer length
3803 *
3804 * Copy a microcode image from a user buffer into a buffer allocated by
3805 * ipr_alloc_ucode_buffer
3806 *
3807 * Return value:
3808 * 0 on success / other on failure
3809 **/
3810static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
3811 u8 *buffer, u32 len)
3812{
3813 int bsize_elem, i, result = 0;
3814 struct scatterlist *scatterlist;
3815 void *kaddr;
3816
3817 /* Determine the actual number of bytes per element */
3818 bsize_elem = PAGE_SIZE * (1 << sglist->order);
3819
3820 scatterlist = sglist->scatterlist;
3821
3822 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
Jens Axboe45711f12007-10-22 21:19:53 +02003823 struct page *page = sg_page(&scatterlist[i]);
3824
3825 kaddr = kmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 memcpy(kaddr, buffer, bsize_elem);
Jens Axboe45711f12007-10-22 21:19:53 +02003827 kunmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828
3829 scatterlist[i].length = bsize_elem;
3830
3831 if (result != 0) {
3832 ipr_trace;
3833 return result;
3834 }
3835 }
3836
3837 if (len % bsize_elem) {
Jens Axboe45711f12007-10-22 21:19:53 +02003838 struct page *page = sg_page(&scatterlist[i]);
3839
3840 kaddr = kmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 memcpy(kaddr, buffer, len % bsize_elem);
Jens Axboe45711f12007-10-22 21:19:53 +02003842 kunmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843
3844 scatterlist[i].length = len % bsize_elem;
3845 }
3846
3847 sglist->buffer_len = len;
3848 return result;
3849}
3850
3851/**
Wayne Boyera32c0552010-02-19 13:23:36 -08003852 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3853 * @ipr_cmd: ipr command struct
3854 * @sglist: scatter/gather list
3855 *
3856 * Builds a microcode download IOA data list (IOADL).
3857 *
3858 **/
3859static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
3860 struct ipr_sglist *sglist)
3861{
3862 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3863 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
3864 struct scatterlist *scatterlist = sglist->scatterlist;
3865 int i;
3866
3867 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3868 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3869 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3870
3871 ioarcb->ioadl_len =
3872 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
3873 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3874 ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
3875 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
3876 ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
3877 }
3878
3879 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3880}
3881
3882/**
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003883 * ipr_build_ucode_ioadl - Build a microcode download IOADL
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 * @ipr_cmd: ipr command struct
3885 * @sglist: scatter/gather list
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 *
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003887 * Builds a microcode download IOA data list (IOADL).
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 **/
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003890static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
3891 struct ipr_sglist *sglist)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08003894 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 struct scatterlist *scatterlist = sglist->scatterlist;
3896 int i;
3897
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003898 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08003900 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3901
3902 ioarcb->ioadl_len =
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3904
3905 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3906 ioadl[i].flags_and_data_len =
3907 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
3908 ioadl[i].address =
3909 cpu_to_be32(sg_dma_address(&scatterlist[i]));
3910 }
3911
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003912 ioadl[i-1].flags_and_data_len |=
3913 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3914}
3915
3916/**
3917 * ipr_update_ioa_ucode - Update IOA's microcode
3918 * @ioa_cfg: ioa config struct
3919 * @sglist: scatter/gather list
3920 *
3921 * Initiate an adapter reset to update the IOA's microcode
3922 *
3923 * Return value:
3924 * 0 on success / -EIO on failure
3925 **/
3926static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3927 struct ipr_sglist *sglist)
3928{
3929 unsigned long lock_flags;
3930
3931 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003932 while (ioa_cfg->in_reset_reload) {
Brian King970ea292007-04-26 16:00:06 -05003933 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3934 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3935 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3936 }
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003937
3938 if (ioa_cfg->ucode_sglist) {
3939 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3940 dev_err(&ioa_cfg->pdev->dev,
3941 "Microcode download already in progress\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 return -EIO;
3943 }
3944
brking@us.ibm.com12baa422005-11-01 17:01:27 -06003945 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
3946 sglist->num_sg, DMA_TO_DEVICE);
3947
3948 if (!sglist->num_dma_sg) {
3949 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3950 dev_err(&ioa_cfg->pdev->dev,
3951 "Failed to map microcode download buffer!\n");
3952 return -EIO;
3953 }
3954
3955 ioa_cfg->ucode_sglist = sglist;
3956 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3957 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3958 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3959
3960 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3961 ioa_cfg->ucode_sglist = NULL;
3962 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 return 0;
3964}
3965
3966/**
3967 * ipr_store_update_fw - Update the firmware on the adapter
Tony Jonesee959b02008-02-22 00:13:36 +01003968 * @class_dev: device struct
3969 * @buf: buffer
3970 * @count: buffer size
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 *
3972 * This function will update the firmware on the adapter.
3973 *
3974 * Return value:
3975 * count on success / other on failure
3976 **/
Tony Jonesee959b02008-02-22 00:13:36 +01003977static ssize_t ipr_store_update_fw(struct device *dev,
3978 struct device_attribute *attr,
3979 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980{
Tony Jonesee959b02008-02-22 00:13:36 +01003981 struct Scsi_Host *shost = class_to_shost(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3983 struct ipr_ucode_image_header *image_hdr;
3984 const struct firmware *fw_entry;
3985 struct ipr_sglist *sglist;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 char fname[100];
3987 char *src;
3988 int len, result, dnld_size;
3989
3990 if (!capable(CAP_SYS_ADMIN))
3991 return -EACCES;
3992
3993 len = snprintf(fname, 99, "%s", buf);
3994 fname[len-1] = '\0';
3995
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03003996 if (request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3998 return -EIO;
3999 }
4000
4001 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
4002
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
4004 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
4005 sglist = ipr_alloc_ucode_buffer(dnld_size);
4006
4007 if (!sglist) {
4008 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
4009 release_firmware(fw_entry);
4010 return -ENOMEM;
4011 }
4012
4013 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
4014
4015 if (result) {
4016 dev_err(&ioa_cfg->pdev->dev,
4017 "Microcode buffer copy to DMA buffer failed\n");
brking@us.ibm.com12baa422005-11-01 17:01:27 -06004018 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 }
4020
Wayne Boyer14ed9cc2011-10-03 20:54:37 -07004021 ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
4022
brking@us.ibm.com12baa422005-11-01 17:01:27 -06004023 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024
brking@us.ibm.com12baa422005-11-01 17:01:27 -06004025 if (!result)
4026 result = count;
4027out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 ipr_free_ucode_buffer(sglist);
4029 release_firmware(fw_entry);
brking@us.ibm.com12baa422005-11-01 17:01:27 -06004030 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031}
4032
Tony Jonesee959b02008-02-22 00:13:36 +01004033static struct device_attribute ipr_update_fw_attr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 .attr = {
4035 .name = "update_fw",
4036 .mode = S_IWUSR,
4037 },
4038 .store = ipr_store_update_fw
4039};
4040
Wayne Boyer75576bb2010-07-14 10:50:14 -07004041/**
4042 * ipr_show_fw_type - Show the adapter's firmware type.
4043 * @dev: class device struct
4044 * @buf: buffer
4045 *
4046 * Return value:
4047 * number of bytes printed to buffer
4048 **/
4049static ssize_t ipr_show_fw_type(struct device *dev,
4050 struct device_attribute *attr, char *buf)
4051{
4052 struct Scsi_Host *shost = class_to_shost(dev);
4053 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4054 unsigned long lock_flags = 0;
4055 int len;
4056
4057 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4058 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
4059 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4060 return len;
4061}
4062
4063static struct device_attribute ipr_ioa_fw_type_attr = {
4064 .attr = {
4065 .name = "fw_type",
4066 .mode = S_IRUGO,
4067 },
4068 .show = ipr_show_fw_type
4069};
4070
Tony Jonesee959b02008-02-22 00:13:36 +01004071static struct device_attribute *ipr_ioa_attrs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 &ipr_fw_version_attr,
4073 &ipr_log_level_attr,
4074 &ipr_diagnostics_attr,
brking@us.ibm.comf37eb542005-11-01 17:01:40 -06004075 &ipr_ioa_state_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 &ipr_ioa_reset_attr,
4077 &ipr_update_fw_attr,
Wayne Boyer75576bb2010-07-14 10:50:14 -07004078 &ipr_ioa_fw_type_attr,
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06004079 &ipr_iopoll_weight_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 NULL,
4081};
4082
4083#ifdef CONFIG_SCSI_IPR_DUMP
4084/**
4085 * ipr_read_dump - Dump the adapter
Chris Wright2c3c8be2010-05-12 18:28:57 -07004086 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08004088 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 * @buf: buffer
4090 * @off: offset
4091 * @count: buffer size
4092 *
4093 * Return value:
4094 * number of bytes printed to buffer
4095 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07004096static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08004097 struct bin_attribute *bin_attr,
4098 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099{
Tony Jonesee959b02008-02-22 00:13:36 +01004100 struct device *cdev = container_of(kobj, struct device, kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 struct Scsi_Host *shost = class_to_shost(cdev);
4102 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4103 struct ipr_dump *dump;
4104 unsigned long lock_flags = 0;
4105 char *src;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004106 int len, sdt_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 size_t rc = count;
4108
4109 if (!capable(CAP_SYS_ADMIN))
4110 return -EACCES;
4111
4112 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4113 dump = ioa_cfg->dump;
4114
4115 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
4116 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4117 return 0;
4118 }
4119 kref_get(&dump->kref);
4120 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4121
4122 if (off > dump->driver_dump.hdr.len) {
4123 kref_put(&dump->kref, ipr_release_dump);
4124 return 0;
4125 }
4126
4127 if (off + count > dump->driver_dump.hdr.len) {
4128 count = dump->driver_dump.hdr.len - off;
4129 rc = count;
4130 }
4131
4132 if (count && off < sizeof(dump->driver_dump)) {
4133 if (off + count > sizeof(dump->driver_dump))
4134 len = sizeof(dump->driver_dump) - off;
4135 else
4136 len = count;
4137 src = (u8 *)&dump->driver_dump + off;
4138 memcpy(buf, src, len);
4139 buf += len;
4140 off += len;
4141 count -= len;
4142 }
4143
4144 off -= sizeof(dump->driver_dump);
4145
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004146 if (ioa_cfg->sis64)
4147 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4148 (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
4149 sizeof(struct ipr_sdt_entry));
4150 else
4151 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4152 (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
4153
4154 if (count && off < sdt_end) {
4155 if (off + count > sdt_end)
4156 len = sdt_end - off;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 else
4158 len = count;
4159 src = (u8 *)&dump->ioa_dump + off;
4160 memcpy(buf, src, len);
4161 buf += len;
4162 off += len;
4163 count -= len;
4164 }
4165
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004166 off -= sdt_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167
4168 while (count) {
4169 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
4170 len = PAGE_ALIGN(off) - off;
4171 else
4172 len = count;
4173 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
4174 src += off & ~PAGE_MASK;
4175 memcpy(buf, src, len);
4176 buf += len;
4177 off += len;
4178 count -= len;
4179 }
4180
4181 kref_put(&dump->kref, ipr_release_dump);
4182 return rc;
4183}
4184
4185/**
4186 * ipr_alloc_dump - Prepare for adapter dump
4187 * @ioa_cfg: ioa config struct
4188 *
4189 * Return value:
4190 * 0 on success / other on failure
4191 **/
4192static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
4193{
4194 struct ipr_dump *dump;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004195 __be32 **ioa_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 unsigned long lock_flags = 0;
4197
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06004198 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199
4200 if (!dump) {
4201 ipr_err("Dump memory allocation failed\n");
4202 return -ENOMEM;
4203 }
4204
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004205 if (ioa_cfg->sis64)
4206 ioa_data = vmalloc(IPR_FMT3_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
4207 else
4208 ioa_data = vmalloc(IPR_FMT2_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
4209
4210 if (!ioa_data) {
4211 ipr_err("Dump memory allocation failed\n");
4212 kfree(dump);
4213 return -ENOMEM;
4214 }
4215
4216 dump->ioa_dump.ioa_data = ioa_data;
4217
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 kref_init(&dump->kref);
4219 dump->ioa_cfg = ioa_cfg;
4220
4221 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4222
4223 if (INACTIVE != ioa_cfg->sdt_state) {
4224 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03004225 vfree(dump->ioa_dump.ioa_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 kfree(dump);
4227 return 0;
4228 }
4229
4230 ioa_cfg->dump = dump;
4231 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06004232 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead && !ioa_cfg->dump_taken) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233 ioa_cfg->dump_taken = 1;
4234 schedule_work(&ioa_cfg->work_q);
4235 }
4236 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4237
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238 return 0;
4239}
4240
4241/**
4242 * ipr_free_dump - Free adapter dump memory
4243 * @ioa_cfg: ioa config struct
4244 *
4245 * Return value:
4246 * 0 on success / other on failure
4247 **/
4248static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
4249{
4250 struct ipr_dump *dump;
4251 unsigned long lock_flags = 0;
4252
4253 ENTER;
4254
4255 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4256 dump = ioa_cfg->dump;
4257 if (!dump) {
4258 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4259 return 0;
4260 }
4261
4262 ioa_cfg->dump = NULL;
4263 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4264
4265 kref_put(&dump->kref, ipr_release_dump);
4266
4267 LEAVE;
4268 return 0;
4269}
4270
4271/**
4272 * ipr_write_dump - Setup dump state of adapter
Chris Wright2c3c8be2010-05-12 18:28:57 -07004273 * @filp: open sysfs file
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274 * @kobj: kobject struct
Zhang Rui91a69022007-06-09 13:57:22 +08004275 * @bin_attr: bin_attribute struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276 * @buf: buffer
4277 * @off: offset
4278 * @count: buffer size
4279 *
4280 * Return value:
4281 * number of bytes printed to buffer
4282 **/
Chris Wright2c3c8be2010-05-12 18:28:57 -07004283static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
Zhang Rui91a69022007-06-09 13:57:22 +08004284 struct bin_attribute *bin_attr,
4285 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286{
Tony Jonesee959b02008-02-22 00:13:36 +01004287 struct device *cdev = container_of(kobj, struct device, kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288 struct Scsi_Host *shost = class_to_shost(cdev);
4289 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4290 int rc;
4291
4292 if (!capable(CAP_SYS_ADMIN))
4293 return -EACCES;
4294
4295 if (buf[0] == '1')
4296 rc = ipr_alloc_dump(ioa_cfg);
4297 else if (buf[0] == '0')
4298 rc = ipr_free_dump(ioa_cfg);
4299 else
4300 return -EINVAL;
4301
4302 if (rc)
4303 return rc;
4304 else
4305 return count;
4306}
4307
4308static struct bin_attribute ipr_dump_attr = {
4309 .attr = {
4310 .name = "dump",
4311 .mode = S_IRUSR | S_IWUSR,
4312 },
4313 .size = 0,
4314 .read = ipr_read_dump,
4315 .write = ipr_write_dump
4316};
4317#else
4318static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
4319#endif
4320
4321/**
4322 * ipr_change_queue_depth - Change the device's queue depth
4323 * @sdev: scsi device struct
4324 * @qdepth: depth to set
Mike Christiee881a172009-10-15 17:46:39 -07004325 * @reason: calling context
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 *
4327 * Return value:
4328 * actual depth set
4329 **/
Mike Christiee881a172009-10-15 17:46:39 -07004330static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth,
4331 int reason)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332{
Brian King35a39692006-09-25 12:39:20 -05004333 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4334 struct ipr_resource_entry *res;
4335 unsigned long lock_flags = 0;
4336
Mike Christiee881a172009-10-15 17:46:39 -07004337 if (reason != SCSI_QDEPTH_DEFAULT)
4338 return -EOPNOTSUPP;
4339
Brian King35a39692006-09-25 12:39:20 -05004340 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4341 res = (struct ipr_resource_entry *)sdev->hostdata;
4342
4343 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
4344 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
4345 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4346
Christoph Hellwigc8b09f62014-11-03 20:15:14 +01004347 scsi_adjust_queue_depth(sdev, qdepth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348 return sdev->queue_depth;
4349}
4350
4351/**
4352 * ipr_change_queue_type - Change the device's queue type
4353 * @dsev: scsi device struct
4354 * @tag_type: type of tags to use
4355 *
4356 * Return value:
4357 * actual queue type set
4358 **/
4359static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
4360{
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
4365 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4366 res = (struct ipr_resource_entry *)sdev->hostdata;
Christoph Hellwiga62182f2014-10-02 14:39:55 +02004367 if (res && ipr_is_gscsi(res))
4368 tag_type = scsi_change_queue_type(sdev, tag_type);
4369 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370 tag_type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4372 return tag_type;
4373}
4374
4375/**
4376 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4377 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004378 * @attr: device attribute structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379 * @buf: buffer
4380 *
4381 * Return value:
4382 * number of bytes printed to buffer
4383 **/
Yani Ioannou10523b32005-05-17 06:43:37 -04004384static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385{
4386 struct scsi_device *sdev = to_scsi_device(dev);
4387 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4388 struct ipr_resource_entry *res;
4389 unsigned long lock_flags = 0;
4390 ssize_t len = -ENXIO;
4391
4392 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4393 res = (struct ipr_resource_entry *)sdev->hostdata;
4394 if (res)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004395 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4397 return len;
4398}
4399
4400static struct device_attribute ipr_adapter_handle_attr = {
4401 .attr = {
4402 .name = "adapter_handle",
4403 .mode = S_IRUSR,
4404 },
4405 .show = ipr_show_adapter_handle
4406};
4407
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004408/**
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004409 * ipr_show_resource_path - Show the resource path or the resource address for
4410 * this device.
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004411 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004412 * @attr: device attribute structure
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004413 * @buf: buffer
4414 *
4415 * Return value:
4416 * number of bytes printed to buffer
4417 **/
4418static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
4419{
4420 struct scsi_device *sdev = to_scsi_device(dev);
4421 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4422 struct ipr_resource_entry *res;
4423 unsigned long lock_flags = 0;
4424 ssize_t len = -ENXIO;
4425 char buffer[IPR_MAX_RES_PATH_LENGTH];
4426
4427 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4428 res = (struct ipr_resource_entry *)sdev->hostdata;
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004429 if (res && ioa_cfg->sis64)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004430 len = snprintf(buf, PAGE_SIZE, "%s\n",
Brian Kingb3b3b402013-01-11 17:43:49 -06004431 __ipr_format_res_path(res->res_path, buffer,
4432 sizeof(buffer)));
Wayne Boyer5adcbeb2010-06-03 16:02:21 -07004433 else if (res)
4434 len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
4435 res->bus, res->target, res->lun);
4436
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004437 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4438 return len;
4439}
4440
4441static struct device_attribute ipr_resource_path_attr = {
4442 .attr = {
4443 .name = "resource_path",
Wayne Boyer75576bb2010-07-14 10:50:14 -07004444 .mode = S_IRUGO,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004445 },
4446 .show = ipr_show_resource_path
4447};
4448
Wayne Boyer75576bb2010-07-14 10:50:14 -07004449/**
Wayne Boyer46d74562010-08-11 07:15:17 -07004450 * ipr_show_device_id - Show the device_id for this device.
4451 * @dev: device struct
4452 * @attr: device attribute structure
4453 * @buf: buffer
4454 *
4455 * Return value:
4456 * number of bytes printed to buffer
4457 **/
4458static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
4459{
4460 struct scsi_device *sdev = to_scsi_device(dev);
4461 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4462 struct ipr_resource_entry *res;
4463 unsigned long lock_flags = 0;
4464 ssize_t len = -ENXIO;
4465
4466 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4467 res = (struct ipr_resource_entry *)sdev->hostdata;
4468 if (res && ioa_cfg->sis64)
4469 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->dev_id);
4470 else if (res)
4471 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
4472
4473 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4474 return len;
4475}
4476
4477static struct device_attribute ipr_device_id_attr = {
4478 .attr = {
4479 .name = "device_id",
4480 .mode = S_IRUGO,
4481 },
4482 .show = ipr_show_device_id
4483};
4484
4485/**
Wayne Boyer75576bb2010-07-14 10:50:14 -07004486 * ipr_show_resource_type - Show the resource type for this device.
4487 * @dev: device struct
Wayne Boyer46d74562010-08-11 07:15:17 -07004488 * @attr: device attribute structure
Wayne Boyer75576bb2010-07-14 10:50:14 -07004489 * @buf: buffer
4490 *
4491 * Return value:
4492 * number of bytes printed to buffer
4493 **/
4494static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
4495{
4496 struct scsi_device *sdev = to_scsi_device(dev);
4497 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4498 struct ipr_resource_entry *res;
4499 unsigned long lock_flags = 0;
4500 ssize_t len = -ENXIO;
4501
4502 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4503 res = (struct ipr_resource_entry *)sdev->hostdata;
4504
4505 if (res)
4506 len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
4507
4508 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4509 return len;
4510}
4511
4512static struct device_attribute ipr_resource_type_attr = {
4513 .attr = {
4514 .name = "resource_type",
4515 .mode = S_IRUGO,
4516 },
4517 .show = ipr_show_resource_type
4518};
4519
Linus Torvalds1da177e2005-04-16 15:20:36 -07004520static struct device_attribute *ipr_dev_attrs[] = {
4521 &ipr_adapter_handle_attr,
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004522 &ipr_resource_path_attr,
Wayne Boyer46d74562010-08-11 07:15:17 -07004523 &ipr_device_id_attr,
Wayne Boyer75576bb2010-07-14 10:50:14 -07004524 &ipr_resource_type_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 NULL,
4526};
4527
4528/**
4529 * ipr_biosparam - Return the HSC mapping
4530 * @sdev: scsi device struct
4531 * @block_device: block device pointer
4532 * @capacity: capacity of the device
4533 * @parm: Array containing returned HSC values.
4534 *
4535 * This function generates the HSC parms that fdisk uses.
4536 * We want to make sure we return something that places partitions
4537 * on 4k boundaries for best performance with the IOA.
4538 *
4539 * Return value:
4540 * 0 on success
4541 **/
4542static int ipr_biosparam(struct scsi_device *sdev,
4543 struct block_device *block_device,
4544 sector_t capacity, int *parm)
4545{
4546 int heads, sectors;
4547 sector_t cylinders;
4548
4549 heads = 128;
4550 sectors = 32;
4551
4552 cylinders = capacity;
4553 sector_div(cylinders, (128 * 32));
4554
4555 /* return result */
4556 parm[0] = heads;
4557 parm[1] = sectors;
4558 parm[2] = cylinders;
4559
4560 return 0;
4561}
4562
4563/**
Brian King35a39692006-09-25 12:39:20 -05004564 * ipr_find_starget - Find target based on bus/target.
4565 * @starget: scsi target struct
4566 *
4567 * Return value:
4568 * resource entry pointer if found / NULL if not found
4569 **/
4570static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
4571{
4572 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4573 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4574 struct ipr_resource_entry *res;
4575
4576 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004577 if ((res->bus == starget->channel) &&
Brian King0ee1d712012-03-14 21:20:06 -05004578 (res->target == starget->id)) {
Brian King35a39692006-09-25 12:39:20 -05004579 return res;
4580 }
4581 }
4582
4583 return NULL;
4584}
4585
4586static struct ata_port_info sata_port_info;
4587
4588/**
4589 * ipr_target_alloc - Prepare for commands to a SCSI target
4590 * @starget: scsi target struct
4591 *
4592 * If the device is a SATA device, this function allocates an
4593 * ATA port with libata, else it does nothing.
4594 *
4595 * Return value:
4596 * 0 on success / non-0 on failure
4597 **/
4598static int ipr_target_alloc(struct scsi_target *starget)
4599{
4600 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4601 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4602 struct ipr_sata_port *sata_port;
4603 struct ata_port *ap;
4604 struct ipr_resource_entry *res;
4605 unsigned long lock_flags;
4606
4607 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4608 res = ipr_find_starget(starget);
4609 starget->hostdata = NULL;
4610
4611 if (res && ipr_is_gata(res)) {
4612 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4613 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
4614 if (!sata_port)
4615 return -ENOMEM;
4616
4617 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
4618 if (ap) {
4619 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4620 sata_port->ioa_cfg = ioa_cfg;
4621 sata_port->ap = ap;
4622 sata_port->res = res;
4623
4624 res->sata_port = sata_port;
4625 ap->private_data = sata_port;
4626 starget->hostdata = sata_port;
4627 } else {
4628 kfree(sata_port);
4629 return -ENOMEM;
4630 }
4631 }
4632 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4633
4634 return 0;
4635}
4636
4637/**
4638 * ipr_target_destroy - Destroy a SCSI target
4639 * @starget: scsi target struct
4640 *
4641 * If the device was a SATA device, this function frees the libata
4642 * ATA port, else it does nothing.
4643 *
4644 **/
4645static void ipr_target_destroy(struct scsi_target *starget)
4646{
4647 struct ipr_sata_port *sata_port = starget->hostdata;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004648 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4649 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4650
4651 if (ioa_cfg->sis64) {
Brian King0ee1d712012-03-14 21:20:06 -05004652 if (!ipr_find_starget(starget)) {
4653 if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4654 clear_bit(starget->id, ioa_cfg->array_ids);
4655 else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4656 clear_bit(starget->id, ioa_cfg->vset_ids);
4657 else if (starget->channel == 0)
4658 clear_bit(starget->id, ioa_cfg->target_ids);
4659 }
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004660 }
Brian King35a39692006-09-25 12:39:20 -05004661
4662 if (sata_port) {
4663 starget->hostdata = NULL;
4664 ata_sas_port_destroy(sata_port->ap);
4665 kfree(sata_port);
4666 }
4667}
4668
4669/**
4670 * ipr_find_sdev - Find device based on bus/target/lun.
4671 * @sdev: scsi device struct
4672 *
4673 * Return value:
4674 * resource entry pointer if found / NULL if not found
4675 **/
4676static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
4677{
4678 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4679 struct ipr_resource_entry *res;
4680
4681 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004682 if ((res->bus == sdev->channel) &&
4683 (res->target == sdev->id) &&
4684 (res->lun == sdev->lun))
Brian King35a39692006-09-25 12:39:20 -05004685 return res;
4686 }
4687
4688 return NULL;
4689}
4690
4691/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692 * ipr_slave_destroy - Unconfigure a SCSI device
4693 * @sdev: scsi device struct
4694 *
4695 * Return value:
4696 * nothing
4697 **/
4698static void ipr_slave_destroy(struct scsi_device *sdev)
4699{
4700 struct ipr_resource_entry *res;
4701 struct ipr_ioa_cfg *ioa_cfg;
4702 unsigned long lock_flags = 0;
4703
4704 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4705
4706 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4707 res = (struct ipr_resource_entry *) sdev->hostdata;
4708 if (res) {
Brian King35a39692006-09-25 12:39:20 -05004709 if (res->sata_port)
Tejun Heo3e4ec342010-05-10 21:41:30 +02004710 res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 sdev->hostdata = NULL;
4712 res->sdev = NULL;
Brian King35a39692006-09-25 12:39:20 -05004713 res->sata_port = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714 }
4715 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4716}
4717
4718/**
4719 * ipr_slave_configure - Configure a SCSI device
4720 * @sdev: scsi device struct
4721 *
4722 * This function configures the specified scsi device.
4723 *
4724 * Return value:
4725 * 0 on success
4726 **/
4727static int ipr_slave_configure(struct scsi_device *sdev)
4728{
4729 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4730 struct ipr_resource_entry *res;
Brian Kingdd406ef2009-04-22 08:58:02 -05004731 struct ata_port *ap = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732 unsigned long lock_flags = 0;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004733 char buffer[IPR_MAX_RES_PATH_LENGTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734
4735 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4736 res = sdev->hostdata;
4737 if (res) {
4738 if (ipr_is_af_dasd_device(res))
4739 sdev->type = TYPE_RAID;
brking@us.ibm.com0726ce22005-11-01 17:01:01 -06004740 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 sdev->scsi_level = 4;
brking@us.ibm.com0726ce22005-11-01 17:01:01 -06004742 sdev->no_uld_attach = 1;
4743 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 if (ipr_is_vset_device(res)) {
Jens Axboe242f9dc2008-09-14 05:55:09 -07004745 blk_queue_rq_timeout(sdev->request_queue,
4746 IPR_VSET_RW_TIMEOUT);
Martin K. Petersen086fa5f2010-02-26 00:20:38 -05004747 blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 }
Brian Kingdd406ef2009-04-22 08:58:02 -05004749 if (ipr_is_gata(res) && res->sata_port)
4750 ap = res->sata_port->ap;
4751 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4752
4753 if (ap) {
Christoph Hellwigc8b09f62014-11-03 20:15:14 +01004754 scsi_adjust_queue_depth(sdev, IPR_MAX_CMD_PER_ATA_LUN);
Brian Kingdd406ef2009-04-22 08:58:02 -05004755 ata_sas_slave_configure(sdev, ap);
Christoph Hellwigc8b09f62014-11-03 20:15:14 +01004756 }
4757
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004758 if (ioa_cfg->sis64)
4759 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
Brian Kingb3b3b402013-01-11 17:43:49 -06004760 ipr_format_res_path(ioa_cfg,
4761 res->res_path, buffer, sizeof(buffer)));
Brian Kingdd406ef2009-04-22 08:58:02 -05004762 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 }
4764 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4765 return 0;
4766}
4767
4768/**
Brian King35a39692006-09-25 12:39:20 -05004769 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
4770 * @sdev: scsi device struct
4771 *
4772 * This function initializes an ATA port so that future commands
4773 * sent through queuecommand will work.
4774 *
4775 * Return value:
4776 * 0 on success
4777 **/
4778static int ipr_ata_slave_alloc(struct scsi_device *sdev)
4779{
4780 struct ipr_sata_port *sata_port = NULL;
4781 int rc = -ENXIO;
4782
4783 ENTER;
4784 if (sdev->sdev_target)
4785 sata_port = sdev->sdev_target->hostdata;
Dan Williamsb2024452012-03-21 21:09:07 -07004786 if (sata_port) {
Brian King35a39692006-09-25 12:39:20 -05004787 rc = ata_sas_port_init(sata_port->ap);
Dan Williamsb2024452012-03-21 21:09:07 -07004788 if (rc == 0)
4789 rc = ata_sas_sync_probe(sata_port->ap);
4790 }
4791
Brian King35a39692006-09-25 12:39:20 -05004792 if (rc)
4793 ipr_slave_destroy(sdev);
4794
4795 LEAVE;
4796 return rc;
4797}
4798
4799/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 * ipr_slave_alloc - Prepare for commands to a device.
4801 * @sdev: scsi device struct
4802 *
4803 * This function saves a pointer to the resource entry
4804 * in the scsi device struct if the device exists. We
4805 * can then use this pointer in ipr_queuecommand when
4806 * handling new commands.
4807 *
4808 * Return value:
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004809 * 0 on success / -ENXIO if device does not exist
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 **/
4811static int ipr_slave_alloc(struct scsi_device *sdev)
4812{
4813 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4814 struct ipr_resource_entry *res;
4815 unsigned long lock_flags;
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004816 int rc = -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817
4818 sdev->hostdata = NULL;
4819
4820 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4821
Brian King35a39692006-09-25 12:39:20 -05004822 res = ipr_find_sdev(sdev);
4823 if (res) {
4824 res->sdev = sdev;
4825 res->add_to_ml = 0;
4826 res->in_erp = 0;
4827 sdev->hostdata = res;
4828 if (!ipr_is_naca_model(res))
4829 res->needs_sync_complete = 1;
4830 rc = 0;
4831 if (ipr_is_gata(res)) {
4832 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4833 return ipr_ata_slave_alloc(sdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834 }
4835 }
4836
4837 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4838
brking@us.ibm.com692aebf2005-11-01 17:01:07 -06004839 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840}
4841
wenxiong@linux.vnet.ibm.com70233ac2013-01-11 17:43:54 -06004842static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843{
4844 struct ipr_ioa_cfg *ioa_cfg;
wenxiong@linux.vnet.ibm.com70233ac2013-01-11 17:43:54 -06004845 unsigned long lock_flags = 0;
4846 int rc = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847
4848 ENTER;
wenxiong@linux.vnet.ibm.com70233ac2013-01-11 17:43:54 -06004849 ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
4850 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851
wenxiong@linux.vnet.ibm.com96b04db2013-04-17 09:34:06 -05004852 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 -06004853 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004854 dev_err(&ioa_cfg->pdev->dev,
4855 "Adapter being reset as a result of error recovery.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02004857 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4858 ioa_cfg->sdt_state = GET_DUMP;
4859 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860
wenxiong@linux.vnet.ibm.com70233ac2013-01-11 17:43:54 -06004861 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4862 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4863 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864
wenxiong@linux.vnet.ibm.com70233ac2013-01-11 17:43:54 -06004865 /* If we got hit with a host reset while we were already resetting
4866 the adapter for some reason, and the reset failed. */
4867 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
4868 ipr_trace;
4869 rc = FAILED;
4870 }
4871
4872 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 LEAVE;
4874 return rc;
4875}
4876
4877/**
Brian Kingc6513092006-03-29 09:37:43 -06004878 * ipr_device_reset - Reset the device
4879 * @ioa_cfg: ioa config struct
4880 * @res: resource entry struct
4881 *
4882 * This function issues a device reset to the affected device.
4883 * If the device is a SCSI device, a LUN reset will be sent
4884 * to the device first. If that does not work, a target reset
Brian King35a39692006-09-25 12:39:20 -05004885 * will be sent. If the device is a SATA device, a PHY reset will
4886 * be sent.
Brian Kingc6513092006-03-29 09:37:43 -06004887 *
4888 * Return value:
4889 * 0 on success / non-zero on failure
4890 **/
4891static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
4892 struct ipr_resource_entry *res)
4893{
4894 struct ipr_cmnd *ipr_cmd;
4895 struct ipr_ioarcb *ioarcb;
4896 struct ipr_cmd_pkt *cmd_pkt;
Brian King35a39692006-09-25 12:39:20 -05004897 struct ipr_ioarcb_ata_regs *regs;
Brian Kingc6513092006-03-29 09:37:43 -06004898 u32 ioasc;
4899
4900 ENTER;
4901 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4902 ioarcb = &ipr_cmd->ioarcb;
4903 cmd_pkt = &ioarcb->cmd_pkt;
Wayne Boyera32c0552010-02-19 13:23:36 -08004904
4905 if (ipr_cmd->ioa_cfg->sis64) {
4906 regs = &ipr_cmd->i.ata_ioadl.regs;
4907 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
4908 } else
4909 regs = &ioarcb->u.add_data.u.regs;
Brian Kingc6513092006-03-29 09:37:43 -06004910
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004911 ioarcb->res_handle = res->res_handle;
Brian Kingc6513092006-03-29 09:37:43 -06004912 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4913 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
Brian King35a39692006-09-25 12:39:20 -05004914 if (ipr_is_gata(res)) {
4915 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
Wayne Boyera32c0552010-02-19 13:23:36 -08004916 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
Brian King35a39692006-09-25 12:39:20 -05004917 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
4918 }
Brian Kingc6513092006-03-29 09:37:43 -06004919
4920 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
Wayne Boyer96d21f02010-05-10 09:13:27 -07004921 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06004922 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Wayne Boyer96d21f02010-05-10 09:13:27 -07004923 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) {
4924 if (ipr_cmd->ioa_cfg->sis64)
4925 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
4926 sizeof(struct ipr_ioasa_gata));
4927 else
4928 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
4929 sizeof(struct ipr_ioasa_gata));
4930 }
Brian Kingc6513092006-03-29 09:37:43 -06004931
4932 LEAVE;
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03004933 return IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0;
Brian Kingc6513092006-03-29 09:37:43 -06004934}
4935
4936/**
Brian King35a39692006-09-25 12:39:20 -05004937 * ipr_sata_reset - Reset the SATA port
Tejun Heocc0680a2007-08-06 18:36:23 +09004938 * @link: SATA link to reset
Brian King35a39692006-09-25 12:39:20 -05004939 * @classes: class of the attached device
4940 *
Tejun Heocc0680a2007-08-06 18:36:23 +09004941 * This function issues a SATA phy reset to the affected ATA link.
Brian King35a39692006-09-25 12:39:20 -05004942 *
4943 * Return value:
4944 * 0 on success / non-zero on failure
4945 **/
Tejun Heocc0680a2007-08-06 18:36:23 +09004946static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
Andrew Morton120bda32007-03-26 02:17:43 -07004947 unsigned long deadline)
Brian King35a39692006-09-25 12:39:20 -05004948{
Tejun Heocc0680a2007-08-06 18:36:23 +09004949 struct ipr_sata_port *sata_port = link->ap->private_data;
Brian King35a39692006-09-25 12:39:20 -05004950 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4951 struct ipr_resource_entry *res;
4952 unsigned long lock_flags = 0;
4953 int rc = -ENXIO;
4954
4955 ENTER;
4956 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03004957 while (ioa_cfg->in_reset_reload) {
Brian King73d98ff2006-11-21 10:27:58 -06004958 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4959 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4960 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4961 }
4962
Brian King35a39692006-09-25 12:39:20 -05004963 res = sata_port->res;
4964 if (res) {
4965 rc = ipr_device_reset(ioa_cfg, res);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08004966 *classes = res->ata_class;
Brian King35a39692006-09-25 12:39:20 -05004967 }
4968
4969 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4970 LEAVE;
4971 return rc;
4972}
4973
4974/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 * ipr_eh_dev_reset - Reset the device
4976 * @scsi_cmd: scsi command struct
4977 *
4978 * This function issues a device reset to the affected device.
4979 * A LUN reset will be sent to the device first. If that does
4980 * not work, a target reset will be sent.
4981 *
4982 * Return value:
4983 * SUCCESS / FAILED
4984 **/
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03004985static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986{
4987 struct ipr_cmnd *ipr_cmd;
4988 struct ipr_ioa_cfg *ioa_cfg;
4989 struct ipr_resource_entry *res;
Brian King35a39692006-09-25 12:39:20 -05004990 struct ata_port *ap;
4991 int rc = 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06004992 struct ipr_hrr_queue *hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993
4994 ENTER;
4995 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
4996 res = scsi_cmd->device->hostdata;
4997
brking@us.ibm.comeeb883072005-11-01 17:02:29 -06004998 if (!res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999 return FAILED;
5000
5001 /*
5002 * If we are currently going through reset/reload, return failed. This will force the
5003 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
5004 * reset to complete
5005 */
5006 if (ioa_cfg->in_reset_reload)
5007 return FAILED;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005008 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 return FAILED;
5010
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005011 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005012 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005013 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
5014 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
5015 if (ipr_cmd->scsi_cmd)
5016 ipr_cmd->done = ipr_scsi_eh_done;
5017 if (ipr_cmd->qc)
5018 ipr_cmd->done = ipr_sata_eh_done;
5019 if (ipr_cmd->qc &&
5020 !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
5021 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
5022 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
5023 }
Brian King7402ece2006-11-21 10:28:23 -06005024 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005026 spin_unlock(&hrrq->_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028 res->resetting_device = 1;
Brian Kingfb3ed3c2006-03-29 09:37:37 -06005029 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
Brian King35a39692006-09-25 12:39:20 -05005030
5031 if (ipr_is_gata(res) && res->sata_port) {
5032 ap = res->sata_port->ap;
5033 spin_unlock_irq(scsi_cmd->device->host->host_lock);
Tejun Heoa1efdab2008-03-25 12:22:50 +09005034 ata_std_error_handler(ap);
Brian King35a39692006-09-25 12:39:20 -05005035 spin_lock_irq(scsi_cmd->device->host->host_lock);
Brian King5af23d22007-05-09 15:36:35 -05005036
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005037 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005038 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005039 list_for_each_entry(ipr_cmd,
5040 &hrrq->hrrq_pending_q, queue) {
5041 if (ipr_cmd->ioarcb.res_handle ==
5042 res->res_handle) {
5043 rc = -EIO;
5044 break;
5045 }
Brian King5af23d22007-05-09 15:36:35 -05005046 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005047 spin_unlock(&hrrq->_lock);
Brian King5af23d22007-05-09 15:36:35 -05005048 }
Brian King35a39692006-09-25 12:39:20 -05005049 } else
5050 rc = ipr_device_reset(ioa_cfg, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051 res->resetting_device = 0;
Wendy Xiong0b1f8d42014-01-21 12:16:39 -06005052 res->reset_occurred = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054 LEAVE;
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005055 return rc ? FAILED : SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056}
5057
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005058static int ipr_eh_dev_reset(struct scsi_cmnd *cmd)
Jeff Garzik 94d0e7b82005-05-28 07:55:48 -04005059{
5060 int rc;
5061
5062 spin_lock_irq(cmd->device->host->host_lock);
5063 rc = __ipr_eh_dev_reset(cmd);
5064 spin_unlock_irq(cmd->device->host->host_lock);
5065
5066 return rc;
5067}
5068
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069/**
5070 * ipr_bus_reset_done - Op done function for bus reset.
5071 * @ipr_cmd: ipr command struct
5072 *
5073 * This function is the op done function for a bus reset
5074 *
5075 * Return value:
5076 * none
5077 **/
5078static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
5079{
5080 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5081 struct ipr_resource_entry *res;
5082
5083 ENTER;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08005084 if (!ioa_cfg->sis64)
5085 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
5086 if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
5087 scsi_report_bus_reset(ioa_cfg->host, res->bus);
5088 break;
5089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091
5092 /*
5093 * If abort has not completed, indicate the reset has, else call the
5094 * abort's done function to wake the sleeping eh thread
5095 */
5096 if (ipr_cmd->sibling->sibling)
5097 ipr_cmd->sibling->sibling = NULL;
5098 else
5099 ipr_cmd->sibling->done(ipr_cmd->sibling);
5100
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005101 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102 LEAVE;
5103}
5104
5105/**
5106 * ipr_abort_timeout - An abort task has timed out
5107 * @ipr_cmd: ipr command struct
5108 *
5109 * This function handles when an abort task times out. If this
5110 * happens we issue a bus reset since we have resources tied
5111 * up that must be freed before returning to the midlayer.
5112 *
5113 * Return value:
5114 * none
5115 **/
5116static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
5117{
5118 struct ipr_cmnd *reset_cmd;
5119 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5120 struct ipr_cmd_pkt *cmd_pkt;
5121 unsigned long lock_flags = 0;
5122
5123 ENTER;
5124 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5125 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
5126 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5127 return;
5128 }
5129
Brian Kingfb3ed3c2006-03-29 09:37:37 -06005130 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5132 ipr_cmd->sibling = reset_cmd;
5133 reset_cmd->sibling = ipr_cmd;
5134 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
5135 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
5136 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5137 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
5138 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
5139
5140 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
5141 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5142 LEAVE;
5143}
5144
5145/**
5146 * ipr_cancel_op - Cancel specified op
5147 * @scsi_cmd: scsi command struct
5148 *
5149 * This function cancels specified op.
5150 *
5151 * Return value:
5152 * SUCCESS / FAILED
5153 **/
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005154static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155{
5156 struct ipr_cmnd *ipr_cmd;
5157 struct ipr_ioa_cfg *ioa_cfg;
5158 struct ipr_resource_entry *res;
5159 struct ipr_cmd_pkt *cmd_pkt;
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02005160 u32 ioasc, int_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161 int op_found = 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005162 struct ipr_hrr_queue *hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163
5164 ENTER;
5165 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
5166 res = scsi_cmd->device->hostdata;
5167
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005168 /* If we are currently going through reset/reload, return failed.
5169 * This will force the mid-layer to call ipr_eh_host_reset,
5170 * which will then go to sleep and wait for the reset to complete
5171 */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005172 if (ioa_cfg->in_reset_reload ||
5173 ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005174 return FAILED;
Kleber Sacilotto de Souzaa92fa252012-01-16 19:30:25 -02005175 if (!res)
5176 return FAILED;
5177
5178 /*
5179 * If we are aborting a timed out op, chances are that the timeout was caused
5180 * by a still not detected EEH error. In such cases, reading a register will
5181 * trigger the EEH recovery infrastructure.
5182 */
5183 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5184
5185 if (!ipr_is_gscsi(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186 return FAILED;
5187
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005188 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005189 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005190 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
5191 if (ipr_cmd->scsi_cmd == scsi_cmd) {
5192 ipr_cmd->done = ipr_scsi_eh_done;
5193 op_found = 1;
5194 break;
5195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005196 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005197 spin_unlock(&hrrq->_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005198 }
5199
5200 if (!op_found)
5201 return SUCCESS;
5202
5203 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08005204 ipr_cmd->ioarcb.res_handle = res->res_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5206 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5207 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5208 ipr_cmd->u.sdev = scsi_cmd->device;
5209
Brian Kingfb3ed3c2006-03-29 09:37:37 -06005210 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
5211 scsi_cmd->cmnd[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
Wayne Boyer96d21f02010-05-10 09:13:27 -07005213 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214
5215 /*
5216 * If the abort task timed out and we sent a bus reset, we will get
5217 * one the following responses to the abort
5218 */
5219 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
5220 ioasc = 0;
5221 ipr_trace;
5222 }
5223
Kleber Sacilotto de Souzac4ee22a2013-03-14 13:52:23 -05005224 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005225 if (!ipr_is_naca_model(res))
5226 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227
5228 LEAVE;
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005229 return IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230}
5231
5232/**
5233 * ipr_eh_abort - Abort a single op
5234 * @scsi_cmd: scsi command struct
5235 *
5236 * Return value:
5237 * SUCCESS / FAILED
5238 **/
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03005239static int ipr_eh_abort(struct scsi_cmnd *scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240{
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005241 unsigned long flags;
5242 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243
5244 ENTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005246 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
5247 rc = ipr_cancel_op(scsi_cmd);
5248 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249
5250 LEAVE;
Jeff Garzik 8fa728a2005-05-28 07:54:40 -04005251 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252}
5253
5254/**
5255 * ipr_handle_other_interrupt - Handle "other" interrupts
5256 * @ioa_cfg: ioa config struct
Wayne Boyer634651f2010-08-27 14:45:07 -07005257 * @int_reg: interrupt register
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258 *
5259 * Return value:
5260 * IRQ_NONE / IRQ_HANDLED
5261 **/
Wayne Boyer634651f2010-08-27 14:45:07 -07005262static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
Wayne Boyer630ad8312011-04-07 12:12:30 -07005263 u32 int_reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264{
5265 irqreturn_t rc = IRQ_HANDLED;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005266 u32 int_mask_reg;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005267
Wayne Boyer7dacb642011-04-12 10:29:02 -07005268 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
5269 int_reg &= ~int_mask_reg;
5270
5271 /* If an interrupt on the adapter did not occur, ignore it.
5272 * Or in the case of SIS 64, check for a stage change interrupt.
5273 */
5274 if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
5275 if (ioa_cfg->sis64) {
5276 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
5277 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5278 if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
5279
5280 /* clear stage change */
5281 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
5282 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5283 list_del(&ioa_cfg->reset_cmd->queue);
5284 del_timer(&ioa_cfg->reset_cmd->timer);
5285 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5286 return IRQ_HANDLED;
5287 }
5288 }
5289
5290 return IRQ_NONE;
5291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005292
5293 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
5294 /* Mask the interrupt */
5295 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
5296
5297 /* Clear the interrupt */
5298 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
5299 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5300
5301 list_del(&ioa_cfg->reset_cmd->queue);
5302 del_timer(&ioa_cfg->reset_cmd->timer);
5303 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
Wayne Boyer7dacb642011-04-12 10:29:02 -07005304 } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
Brian King7dd21302012-03-14 21:20:08 -05005305 if (ioa_cfg->clear_isr) {
5306 if (ipr_debug && printk_ratelimit())
5307 dev_err(&ioa_cfg->pdev->dev,
5308 "Spurious interrupt detected. 0x%08X\n", int_reg);
5309 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5310 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5311 return IRQ_NONE;
5312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005313 } else {
5314 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
5315 ioa_cfg->ioa_unit_checked = 1;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005316 else if (int_reg & IPR_PCII_NO_HOST_RRQ)
5317 dev_err(&ioa_cfg->pdev->dev,
5318 "No Host RRQ. 0x%08X\n", int_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319 else
5320 dev_err(&ioa_cfg->pdev->dev,
5321 "Permanent IOA failure. 0x%08X\n", int_reg);
5322
5323 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5324 ioa_cfg->sdt_state = GET_DUMP;
5325
5326 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
5327 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5328 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005329
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330 return rc;
5331}
5332
5333/**
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005334 * ipr_isr_eh - Interrupt service routine error handler
5335 * @ioa_cfg: ioa config struct
5336 * @msg: message to log
5337 *
5338 * Return value:
5339 * none
5340 **/
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005341static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg, u16 number)
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005342{
5343 ioa_cfg->errors_logged++;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005344 dev_err(&ioa_cfg->pdev->dev, "%s %d\n", msg, number);
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005345
5346 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5347 ioa_cfg->sdt_state = GET_DUMP;
5348
5349 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5350}
5351
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005352static int ipr_process_hrrq(struct ipr_hrr_queue *hrr_queue, int budget,
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005353 struct list_head *doneq)
5354{
5355 u32 ioasc;
5356 u16 cmd_index;
5357 struct ipr_cmnd *ipr_cmd;
5358 struct ipr_ioa_cfg *ioa_cfg = hrr_queue->ioa_cfg;
5359 int num_hrrq = 0;
5360
5361 /* If interrupts are disabled, ignore the interrupt */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005362 if (!hrr_queue->allow_interrupts)
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005363 return 0;
5364
5365 while ((be32_to_cpu(*hrr_queue->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5366 hrr_queue->toggle_bit) {
5367
5368 cmd_index = (be32_to_cpu(*hrr_queue->hrrq_curr) &
5369 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >>
5370 IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
5371
5372 if (unlikely(cmd_index > hrr_queue->max_cmd_id ||
5373 cmd_index < hrr_queue->min_cmd_id)) {
5374 ipr_isr_eh(ioa_cfg,
5375 "Invalid response handle from IOA: ",
5376 cmd_index);
5377 break;
5378 }
5379
5380 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
5381 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5382
5383 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
5384
5385 list_move_tail(&ipr_cmd->queue, doneq);
5386
5387 if (hrr_queue->hrrq_curr < hrr_queue->hrrq_end) {
5388 hrr_queue->hrrq_curr++;
5389 } else {
5390 hrr_queue->hrrq_curr = hrr_queue->hrrq_start;
5391 hrr_queue->toggle_bit ^= 1u;
5392 }
5393 num_hrrq++;
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005394 if (budget > 0 && num_hrrq >= budget)
5395 break;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005396 }
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005397
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005398 return num_hrrq;
5399}
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005400
5401static int ipr_iopoll(struct blk_iopoll *iop, int budget)
5402{
5403 struct ipr_ioa_cfg *ioa_cfg;
5404 struct ipr_hrr_queue *hrrq;
5405 struct ipr_cmnd *ipr_cmd, *temp;
5406 unsigned long hrrq_flags;
5407 int completed_ops;
5408 LIST_HEAD(doneq);
5409
5410 hrrq = container_of(iop, struct ipr_hrr_queue, iopoll);
5411 ioa_cfg = hrrq->ioa_cfg;
5412
5413 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5414 completed_ops = ipr_process_hrrq(hrrq, budget, &doneq);
5415
5416 if (completed_ops < budget)
5417 blk_iopoll_complete(iop);
5418 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5419
5420 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5421 list_del(&ipr_cmd->queue);
5422 del_timer(&ipr_cmd->timer);
5423 ipr_cmd->fast_done(ipr_cmd);
5424 }
5425
5426 return completed_ops;
5427}
5428
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005429/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005430 * ipr_isr - Interrupt service routine
5431 * @irq: irq number
5432 * @devp: pointer to ioa config struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005433 *
5434 * Return value:
5435 * IRQ_NONE / IRQ_HANDLED
5436 **/
David Howells7d12e782006-10-05 14:55:46 +01005437static irqreturn_t ipr_isr(int irq, void *devp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005439 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
5440 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005441 unsigned long hrrq_flags = 0;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005442 u32 int_reg = 0;
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005443 int num_hrrq = 0;
Wayne Boyer7dacb642011-04-12 10:29:02 -07005444 int irq_none = 0;
Brian King172cd6e2012-07-17 08:14:40 -05005445 struct ipr_cmnd *ipr_cmd, *temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005446 irqreturn_t rc = IRQ_NONE;
Brian King172cd6e2012-07-17 08:14:40 -05005447 LIST_HEAD(doneq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005448
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005449 spin_lock_irqsave(hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005450 /* If interrupts are disabled, ignore the interrupt */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005451 if (!hrrq->allow_interrupts) {
5452 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005453 return IRQ_NONE;
5454 }
5455
Linus Torvalds1da177e2005-04-16 15:20:36 -07005456 while (1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005457 if (ipr_process_hrrq(hrrq, -1, &doneq)) {
5458 rc = IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005460 if (!ioa_cfg->clear_isr)
5461 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462
Linus Torvalds1da177e2005-04-16 15:20:36 -07005463 /* Clear the PCI interrupt */
Wayne Boyera5442ba2011-05-17 09:18:53 -07005464 num_hrrq = 0;
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005465 do {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005466 writel(IPR_PCII_HRRQ_UPDATED,
5467 ioa_cfg->regs.clr_interrupt_reg32);
Wayne Boyer7dacb642011-04-12 10:29:02 -07005468 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005469 } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005470 num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
Wayne Boyer3feeb89d2009-10-20 11:09:00 -07005471
Wayne Boyer7dacb642011-04-12 10:29:02 -07005472 } else if (rc == IRQ_NONE && irq_none == 0) {
5473 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5474 irq_none++;
Wayne Boyera5442ba2011-05-17 09:18:53 -07005475 } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
5476 int_reg & IPR_PCII_HRRQ_UPDATED) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005477 ipr_isr_eh(ioa_cfg,
5478 "Error clearing HRRQ: ", num_hrrq);
Brian King172cd6e2012-07-17 08:14:40 -05005479 rc = IRQ_HANDLED;
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005480 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005481 } else
5482 break;
5483 }
5484
5485 if (unlikely(rc == IRQ_NONE))
Wayne Boyer634651f2010-08-27 14:45:07 -07005486 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005488 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King172cd6e2012-07-17 08:14:40 -05005489 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5490 list_del(&ipr_cmd->queue);
5491 del_timer(&ipr_cmd->timer);
5492 ipr_cmd->fast_done(ipr_cmd);
5493 }
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005494 return rc;
5495}
Brian King172cd6e2012-07-17 08:14:40 -05005496
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005497/**
5498 * ipr_isr_mhrrq - Interrupt service routine
5499 * @irq: irq number
5500 * @devp: pointer to ioa config struct
5501 *
5502 * Return value:
5503 * IRQ_NONE / IRQ_HANDLED
5504 **/
5505static irqreturn_t ipr_isr_mhrrq(int irq, void *devp)
5506{
5507 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005508 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005509 unsigned long hrrq_flags = 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005510 struct ipr_cmnd *ipr_cmd, *temp;
5511 irqreturn_t rc = IRQ_NONE;
5512 LIST_HEAD(doneq);
5513
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005514 spin_lock_irqsave(hrrq->lock, hrrq_flags);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005515
5516 /* If interrupts are disabled, ignore the interrupt */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005517 if (!hrrq->allow_interrupts) {
5518 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005519 return IRQ_NONE;
5520 }
5521
Jens Axboe89f8b332014-03-13 09:38:42 -06005522 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005523 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5524 hrrq->toggle_bit) {
5525 if (!blk_iopoll_sched_prep(&hrrq->iopoll))
5526 blk_iopoll_sched(&hrrq->iopoll);
5527 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5528 return IRQ_HANDLED;
5529 }
5530 } else {
5531 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5532 hrrq->toggle_bit)
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005533
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06005534 if (ipr_process_hrrq(hrrq, -1, &doneq))
5535 rc = IRQ_HANDLED;
5536 }
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005537
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06005538 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005539
5540 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5541 list_del(&ipr_cmd->queue);
5542 del_timer(&ipr_cmd->timer);
5543 ipr_cmd->fast_done(ipr_cmd);
5544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005545 return rc;
5546}
5547
5548/**
Wayne Boyera32c0552010-02-19 13:23:36 -08005549 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -07005550 * @ioa_cfg: ioa config struct
5551 * @ipr_cmd: ipr command struct
5552 *
5553 * Return value:
5554 * 0 on success / -1 on failure
5555 **/
Wayne Boyera32c0552010-02-19 13:23:36 -08005556static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
5557 struct ipr_cmnd *ipr_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005558{
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005559 int i, nseg;
5560 struct scatterlist *sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005561 u32 length;
5562 u32 ioadl_flags = 0;
5563 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5564 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08005565 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005566
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005567 length = scsi_bufflen(scsi_cmd);
5568 if (!length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005569 return 0;
5570
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005571 nseg = scsi_dma_map(scsi_cmd);
5572 if (nseg < 0) {
Anton Blanchard51f52a42011-05-09 10:07:40 +10005573 if (printk_ratelimit())
5574 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005575 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576 }
5577
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005578 ipr_cmd->dma_use_sg = nseg;
5579
Wayne Boyer438b0332010-05-10 09:13:00 -07005580 ioarcb->data_transfer_length = cpu_to_be32(length);
Wayne Boyerb8803b12010-05-14 08:55:13 -07005581 ioarcb->ioadl_len =
5582 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
Wayne Boyer438b0332010-05-10 09:13:00 -07005583
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005584 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5585 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5586 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08005587 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
5588 ioadl_flags = IPR_IOADL_FLAGS_READ;
5589
5590 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5591 ioadl64[i].flags = cpu_to_be32(ioadl_flags);
5592 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
5593 ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
5594 }
5595
5596 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5597 return 0;
5598}
5599
5600/**
5601 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5602 * @ioa_cfg: ioa config struct
5603 * @ipr_cmd: ipr command struct
5604 *
5605 * Return value:
5606 * 0 on success / -1 on failure
5607 **/
5608static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5609 struct ipr_cmnd *ipr_cmd)
5610{
5611 int i, nseg;
5612 struct scatterlist *sg;
5613 u32 length;
5614 u32 ioadl_flags = 0;
5615 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5616 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5617 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
5618
5619 length = scsi_bufflen(scsi_cmd);
5620 if (!length)
5621 return 0;
5622
5623 nseg = scsi_dma_map(scsi_cmd);
5624 if (nseg < 0) {
5625 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
5626 return -1;
5627 }
5628
5629 ipr_cmd->dma_use_sg = nseg;
5630
5631 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5632 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5633 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5634 ioarcb->data_transfer_length = cpu_to_be32(length);
5635 ioarcb->ioadl_len =
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005636 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5637 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
5638 ioadl_flags = IPR_IOADL_FLAGS_READ;
5639 ioarcb->read_data_transfer_length = cpu_to_be32(length);
5640 ioarcb->read_ioadl_len =
5641 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5642 }
5643
Wayne Boyera32c0552010-02-19 13:23:36 -08005644 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
5645 ioadl = ioarcb->u.add_data.u.ioadl;
5646 ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
5647 offsetof(struct ipr_ioarcb, u.add_data));
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005648 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5649 }
5650
5651 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5652 ioadl[i].flags_and_data_len =
5653 cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5654 ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
5655 }
5656
5657 ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5658 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005659}
5660
5661/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005662 * ipr_erp_done - Process completion of ERP for a device
5663 * @ipr_cmd: ipr command struct
5664 *
5665 * This function copies the sense buffer into the scsi_cmd
5666 * struct and pushes the scsi_done function.
5667 *
5668 * Return value:
5669 * nothing
5670 **/
5671static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
5672{
5673 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5674 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005675 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005676
5677 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5678 scsi_cmd->result |= (DID_ERROR << 16);
Brian Kingfb3ed3c2006-03-29 09:37:37 -06005679 scmd_printk(KERN_ERR, scsi_cmd,
5680 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005681 } else {
5682 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
5683 SCSI_SENSE_BUFFERSIZE);
5684 }
5685
5686 if (res) {
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005687 if (!ipr_is_naca_model(res))
5688 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005689 res->in_erp = 0;
5690 }
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09005691 scsi_dma_unmap(ipr_cmd->scsi_cmd);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06005692 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005693 scsi_cmd->scsi_done(scsi_cmd);
5694}
5695
5696/**
5697 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5698 * @ipr_cmd: ipr command struct
5699 *
5700 * Return value:
5701 * none
5702 **/
5703static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
5704{
Brian King51b1c7e2007-03-29 12:43:50 -05005705 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005706 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
Wayne Boyera32c0552010-02-19 13:23:36 -08005707 dma_addr_t dma_addr = ipr_cmd->dma_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005708
5709 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
Wayne Boyera32c0552010-02-19 13:23:36 -08005710 ioarcb->data_transfer_length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711 ioarcb->read_data_transfer_length = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -08005712 ioarcb->ioadl_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005713 ioarcb->read_ioadl_len = 0;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005714 ioasa->hdr.ioasc = 0;
5715 ioasa->hdr.residual_data_len = 0;
Wayne Boyera32c0552010-02-19 13:23:36 -08005716
5717 if (ipr_cmd->ioa_cfg->sis64)
5718 ioarcb->u.sis64_addr_data.data_ioadl_addr =
5719 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
5720 else {
5721 ioarcb->write_ioadl_addr =
5722 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
5723 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5724 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005725}
5726
5727/**
5728 * ipr_erp_request_sense - Send request sense to a device
5729 * @ipr_cmd: ipr command struct
5730 *
5731 * This function sends a request sense to a device as a result
5732 * of a check condition.
5733 *
5734 * Return value:
5735 * nothing
5736 **/
5737static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
5738{
5739 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005740 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005741
5742 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5743 ipr_erp_done(ipr_cmd);
5744 return;
5745 }
5746
5747 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5748
5749 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
5750 cmd_pkt->cdb[0] = REQUEST_SENSE;
5751 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
5752 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
5753 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5754 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
5755
Wayne Boyera32c0552010-02-19 13:23:36 -08005756 ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
5757 SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758
5759 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
5760 IPR_REQUEST_SENSE_TIMEOUT * 2);
5761}
5762
5763/**
5764 * ipr_erp_cancel_all - Send cancel all to a device
5765 * @ipr_cmd: ipr command struct
5766 *
5767 * This function sends a cancel all to a device to clear the
5768 * queue. If we are running TCQ on the device, QERR is set to 1,
5769 * which means all outstanding ops have been dropped on the floor.
5770 * Cancel all will return them to us.
5771 *
5772 * Return value:
5773 * nothing
5774 **/
5775static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
5776{
5777 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5778 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5779 struct ipr_cmd_pkt *cmd_pkt;
5780
5781 res->in_erp = 1;
5782
5783 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5784
5785 if (!scsi_get_tag_type(scsi_cmd->device)) {
5786 ipr_erp_request_sense(ipr_cmd);
5787 return;
5788 }
5789
5790 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5791 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5792 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5793
5794 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
5795 IPR_CANCEL_ALL_TIMEOUT);
5796}
5797
5798/**
5799 * ipr_dump_ioasa - Dump contents of IOASA
5800 * @ioa_cfg: ioa config struct
5801 * @ipr_cmd: ipr command struct
Brian Kingfe964d02006-03-29 09:37:29 -06005802 * @res: resource entry struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07005803 *
5804 * This function is invoked by the interrupt handler when ops
5805 * fail. It will log the IOASA if appropriate. Only called
5806 * for GPDD ops.
5807 *
5808 * Return value:
5809 * none
5810 **/
5811static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
Brian Kingfe964d02006-03-29 09:37:29 -06005812 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813{
5814 int i;
5815 u16 data_len;
Brian Kingb0692dd2007-03-29 12:43:09 -05005816 u32 ioasc, fd_ioasc;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005817 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005818 __be32 *ioasa_data = (__be32 *)ioasa;
5819 int error_index;
5820
Wayne Boyer96d21f02010-05-10 09:13:27 -07005821 ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
5822 fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005823
5824 if (0 == ioasc)
5825 return;
5826
5827 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
5828 return;
5829
Brian Kingb0692dd2007-03-29 12:43:09 -05005830 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
5831 error_index = ipr_get_error(fd_ioasc);
5832 else
5833 error_index = ipr_get_error(ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834
5835 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
5836 /* Don't log an error if the IOA already logged one */
Wayne Boyer96d21f02010-05-10 09:13:27 -07005837 if (ioasa->hdr.ilid != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005838 return;
5839
Brian Kingcc9bd5d2007-03-29 12:43:01 -05005840 if (!ipr_is_gscsi(res))
5841 return;
5842
Linus Torvalds1da177e2005-04-16 15:20:36 -07005843 if (ipr_error_table[error_index].log_ioasa == 0)
5844 return;
5845 }
5846
Brian Kingfe964d02006-03-29 09:37:29 -06005847 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848
Wayne Boyer96d21f02010-05-10 09:13:27 -07005849 data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
5850 if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
5851 data_len = sizeof(struct ipr_ioasa64);
5852 else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853 data_len = sizeof(struct ipr_ioasa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854
5855 ipr_err("IOASA Dump:\n");
5856
5857 for (i = 0; i < data_len / 4; i += 4) {
5858 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
5859 be32_to_cpu(ioasa_data[i]),
5860 be32_to_cpu(ioasa_data[i+1]),
5861 be32_to_cpu(ioasa_data[i+2]),
5862 be32_to_cpu(ioasa_data[i+3]));
5863 }
5864}
5865
5866/**
5867 * ipr_gen_sense - Generate SCSI sense data from an IOASA
5868 * @ioasa: IOASA
5869 * @sense_buf: sense data buffer
5870 *
5871 * Return value:
5872 * none
5873 **/
5874static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
5875{
5876 u32 failing_lba;
5877 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
5878 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
Wayne Boyer96d21f02010-05-10 09:13:27 -07005879 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5880 u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881
5882 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
5883
5884 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
5885 return;
5886
5887 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
5888
5889 if (ipr_is_vset_device(res) &&
5890 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
5891 ioasa->u.vset.failing_lba_hi != 0) {
5892 sense_buf[0] = 0x72;
5893 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
5894 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
5895 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
5896
5897 sense_buf[7] = 12;
5898 sense_buf[8] = 0;
5899 sense_buf[9] = 0x0A;
5900 sense_buf[10] = 0x80;
5901
5902 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
5903
5904 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
5905 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
5906 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
5907 sense_buf[15] = failing_lba & 0x000000ff;
5908
5909 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5910
5911 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
5912 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
5913 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
5914 sense_buf[19] = failing_lba & 0x000000ff;
5915 } else {
5916 sense_buf[0] = 0x70;
5917 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
5918 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
5919 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
5920
5921 /* Illegal request */
5922 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
Wayne Boyer96d21f02010-05-10 09:13:27 -07005923 (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924 sense_buf[7] = 10; /* additional length */
5925
5926 /* IOARCB was in error */
5927 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
5928 sense_buf[15] = 0xC0;
5929 else /* Parameter data was invalid */
5930 sense_buf[15] = 0x80;
5931
5932 sense_buf[16] =
5933 ((IPR_FIELD_POINTER_MASK &
Wayne Boyer96d21f02010-05-10 09:13:27 -07005934 be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005935 sense_buf[17] =
5936 (IPR_FIELD_POINTER_MASK &
Wayne Boyer96d21f02010-05-10 09:13:27 -07005937 be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005938 } else {
5939 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
5940 if (ipr_is_vset_device(res))
5941 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5942 else
5943 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
5944
5945 sense_buf[0] |= 0x80; /* Or in the Valid bit */
5946 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
5947 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
5948 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
5949 sense_buf[6] = failing_lba & 0x000000ff;
5950 }
5951
5952 sense_buf[7] = 6; /* additional length */
5953 }
5954 }
5955}
5956
5957/**
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005958 * ipr_get_autosense - Copy autosense data to sense buffer
5959 * @ipr_cmd: ipr command struct
5960 *
5961 * This function copies the autosense buffer to the buffer
5962 * in the scsi_cmd, if there is autosense available.
5963 *
5964 * Return value:
5965 * 1 if autosense was available / 0 if not
5966 **/
5967static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
5968{
Wayne Boyer96d21f02010-05-10 09:13:27 -07005969 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5970 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005971
Wayne Boyer96d21f02010-05-10 09:13:27 -07005972 if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005973 return 0;
5974
Wayne Boyer96d21f02010-05-10 09:13:27 -07005975 if (ipr_cmd->ioa_cfg->sis64)
5976 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
5977 min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
5978 SCSI_SENSE_BUFFERSIZE));
5979 else
5980 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
5981 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
5982 SCSI_SENSE_BUFFERSIZE));
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06005983 return 1;
5984}
5985
5986/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987 * ipr_erp_start - Process an error response for a SCSI op
5988 * @ioa_cfg: ioa config struct
5989 * @ipr_cmd: ipr command struct
5990 *
5991 * This function determines whether or not to initiate ERP
5992 * on the affected device.
5993 *
5994 * Return value:
5995 * nothing
5996 **/
5997static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
5998 struct ipr_cmnd *ipr_cmd)
5999{
6000 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
6001 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006002 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian King8a048992007-04-26 16:00:10 -05006003 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004
6005 if (!res) {
6006 ipr_scsi_eh_done(ipr_cmd);
6007 return;
6008 }
6009
Brian King8a048992007-04-26 16:00:10 -05006010 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011 ipr_gen_sense(ipr_cmd);
6012
Brian Kingcc9bd5d2007-03-29 12:43:01 -05006013 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6014
Brian King8a048992007-04-26 16:00:10 -05006015 switch (masked_ioasc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006016 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006017 if (ipr_is_naca_model(res))
6018 scsi_cmd->result |= (DID_ABORT << 16);
6019 else
6020 scsi_cmd->result |= (DID_IMM_RETRY << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021 break;
6022 case IPR_IOASC_IR_RESOURCE_HANDLE:
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06006023 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 scsi_cmd->result |= (DID_NO_CONNECT << 16);
6025 break;
6026 case IPR_IOASC_HW_SEL_TIMEOUT:
6027 scsi_cmd->result |= (DID_NO_CONNECT << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006028 if (!ipr_is_naca_model(res))
6029 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 break;
6031 case IPR_IOASC_SYNC_REQUIRED:
6032 if (!res->in_erp)
6033 res->needs_sync_complete = 1;
6034 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6035 break;
6036 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
brking@us.ibm.comb0df54b2005-11-01 17:01:47 -06006037 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006038 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
6039 break;
6040 case IPR_IOASC_BUS_WAS_RESET:
6041 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
6042 /*
6043 * Report the bus reset and ask for a retry. The device
6044 * will give CC/UA the next command.
6045 */
6046 if (!res->resetting_device)
6047 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
6048 scsi_cmd->result |= (DID_ERROR << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006049 if (!ipr_is_naca_model(res))
6050 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051 break;
6052 case IPR_IOASC_HW_DEV_BUS_STATUS:
6053 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
6054 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006055 if (!ipr_get_autosense(ipr_cmd)) {
6056 if (!ipr_is_naca_model(res)) {
6057 ipr_erp_cancel_all(ipr_cmd);
6058 return;
6059 }
6060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061 }
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006062 if (!ipr_is_naca_model(res))
6063 res->needs_sync_complete = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064 break;
6065 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
6066 break;
6067 default:
Brian King5b7304f2006-08-02 14:57:51 -05006068 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
6069 scsi_cmd->result |= (DID_ERROR << 16);
brking@us.ibm.comee0a90f2005-11-01 17:02:22 -06006070 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071 res->needs_sync_complete = 1;
6072 break;
6073 }
6074
FUJITA Tomonori63015bc2007-05-26 00:26:59 +09006075 scsi_dma_unmap(ipr_cmd->scsi_cmd);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006076 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077 scsi_cmd->scsi_done(scsi_cmd);
6078}
6079
6080/**
6081 * ipr_scsi_done - mid-layer done function
6082 * @ipr_cmd: ipr command struct
6083 *
6084 * This function is invoked by the interrupt handler for
6085 * ops generated by the SCSI mid-layer
6086 *
6087 * Return value:
6088 * none
6089 **/
6090static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
6091{
6092 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6093 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006094 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006095 unsigned long hrrq_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096
Wayne Boyer96d21f02010-05-10 09:13:27 -07006097 scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098
6099 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
Brian King172cd6e2012-07-17 08:14:40 -05006100 scsi_dma_unmap(scsi_cmd);
6101
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006102 spin_lock_irqsave(ipr_cmd->hrrq->lock, hrrq_flags);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006103 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104 scsi_cmd->scsi_done(scsi_cmd);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006105 spin_unlock_irqrestore(ipr_cmd->hrrq->lock, hrrq_flags);
Brian King172cd6e2012-07-17 08:14:40 -05006106 } else {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006107 spin_lock_irqsave(ipr_cmd->hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108 ipr_erp_start(ioa_cfg, ipr_cmd);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006109 spin_unlock_irqrestore(ipr_cmd->hrrq->lock, hrrq_flags);
Brian King172cd6e2012-07-17 08:14:40 -05006110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006111}
6112
6113/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114 * ipr_queuecommand - Queue a mid-layer request
Brian King00bfef22012-07-17 08:13:52 -05006115 * @shost: scsi host struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116 * @scsi_cmd: scsi command struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117 *
6118 * This function queues a request generated by the mid-layer.
6119 *
6120 * Return value:
6121 * 0 on success
6122 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
6123 * SCSI_MLQUEUE_HOST_BUSY if host is busy
6124 **/
Brian King00bfef22012-07-17 08:13:52 -05006125static int ipr_queuecommand(struct Scsi_Host *shost,
6126 struct scsi_cmnd *scsi_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127{
6128 struct ipr_ioa_cfg *ioa_cfg;
6129 struct ipr_resource_entry *res;
6130 struct ipr_ioarcb *ioarcb;
6131 struct ipr_cmnd *ipr_cmd;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006132 unsigned long hrrq_flags, lock_flags;
Dan Carpenterd12f1572012-07-30 11:18:22 +03006133 int rc;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006134 struct ipr_hrr_queue *hrrq;
6135 int hrrq_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006136
Brian King00bfef22012-07-17 08:13:52 -05006137 ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
6138
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139 scsi_cmd->result = (DID_OK << 16);
Brian King00bfef22012-07-17 08:13:52 -05006140 res = scsi_cmd->device->hostdata;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006141
6142 if (ipr_is_gata(res) && res->sata_port) {
6143 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6144 rc = ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
6145 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6146 return rc;
6147 }
6148
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006149 hrrq_id = ipr_get_hrrq_index(ioa_cfg);
6150 hrrq = &ioa_cfg->hrrq[hrrq_id];
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006152 spin_lock_irqsave(hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153 /*
6154 * We are currently blocking all devices due to a host reset
6155 * We have told the host to stop giving us new requests, but
6156 * ERP ops don't count. FIXME
6157 */
Brian Kingbfae7822013-01-30 23:45:08 -06006158 if (unlikely(!hrrq->allow_cmds && !hrrq->ioa_is_dead && !hrrq->removing_ioa)) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006159 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160 return SCSI_MLQUEUE_HOST_BUSY;
Brian King00bfef22012-07-17 08:13:52 -05006161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162
6163 /*
6164 * FIXME - Create scsi_set_host_offline interface
6165 * and the ioa_is_dead check can be removed
6166 */
Brian Kingbfae7822013-01-30 23:45:08 -06006167 if (unlikely(hrrq->ioa_is_dead || hrrq->removing_ioa || !res)) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006168 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006169 goto err_nodev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170 }
6171
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006172 ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
6173 if (ipr_cmd == NULL) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006174 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006175 return SCSI_MLQUEUE_HOST_BUSY;
6176 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006177 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006178
Brian King172cd6e2012-07-17 08:14:40 -05006179 ipr_init_ipr_cmnd(ipr_cmd, ipr_scsi_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180 ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181
6182 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
6183 ipr_cmd->scsi_cmd = scsi_cmd;
Brian King172cd6e2012-07-17 08:14:40 -05006184 ipr_cmd->done = ipr_scsi_eh_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185
6186 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
6187 if (scsi_cmd->underflow == 0)
6188 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
6189
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
Wendy Xiong0b1f8d42014-01-21 12:16:39 -06006191 if (ipr_is_gscsi(res) && res->reset_occurred) {
6192 res->reset_occurred = 0;
Wayne Boyerab6c10b2011-03-31 09:56:10 -07006193 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
Wendy Xiong0b1f8d42014-01-21 12:16:39 -06006194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
Christoph Hellwig50668632014-10-30 14:30:06 +01006196 if (scsi_cmd->flags & SCMD_TAGGED)
6197 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_SIMPLE_TASK;
6198 else
6199 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_UNTAGGED_TASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200 }
6201
6202 if (scsi_cmd->cmnd[0] >= 0xC0 &&
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006203 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006205 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206
Dan Carpenterd12f1572012-07-30 11:18:22 +03006207 if (ioa_cfg->sis64)
6208 rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
6209 else
6210 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006212 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6213 if (unlikely(rc || (!hrrq->allow_cmds && !hrrq->ioa_is_dead))) {
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006214 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006215 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006216 if (!rc)
6217 scsi_dma_unmap(scsi_cmd);
Brian Kinga5fb4072012-03-14 21:20:09 -05006218 return SCSI_MLQUEUE_HOST_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219 }
6220
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006221 if (unlikely(hrrq->ioa_is_dead)) {
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006222 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006223 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006224 scsi_dma_unmap(scsi_cmd);
6225 goto err_nodev;
6226 }
6227
6228 ioarcb->res_handle = res->res_handle;
6229 if (res->needs_sync_complete) {
6230 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
6231 res->needs_sync_complete = 0;
6232 }
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006233 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_pending_q);
Brian King00bfef22012-07-17 08:13:52 -05006234 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
Brian Kinga5fb4072012-03-14 21:20:09 -05006235 ipr_send_command(ipr_cmd);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006236 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006237 return 0;
6238
6239err_nodev:
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006240 spin_lock_irqsave(hrrq->lock, hrrq_flags);
Brian King00bfef22012-07-17 08:13:52 -05006241 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
6242 scsi_cmd->result = (DID_NO_CONNECT << 16);
6243 scsi_cmd->scsi_done(scsi_cmd);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006244 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245 return 0;
6246}
6247
6248/**
Brian King35a39692006-09-25 12:39:20 -05006249 * ipr_ioctl - IOCTL handler
6250 * @sdev: scsi device struct
6251 * @cmd: IOCTL cmd
6252 * @arg: IOCTL arg
6253 *
6254 * Return value:
6255 * 0 on success / other on failure
6256 **/
Adrian Bunkbd705f22006-11-21 10:28:48 -06006257static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
Brian King35a39692006-09-25 12:39:20 -05006258{
6259 struct ipr_resource_entry *res;
6260
6261 res = (struct ipr_resource_entry *)sdev->hostdata;
Brian King0ce3a7e2008-07-11 13:37:50 -05006262 if (res && ipr_is_gata(res)) {
6263 if (cmd == HDIO_GET_IDENTITY)
6264 return -ENOTTY;
Jeff Garzik94be9a52009-01-16 10:17:09 -05006265 return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
Brian King0ce3a7e2008-07-11 13:37:50 -05006266 }
Brian King35a39692006-09-25 12:39:20 -05006267
6268 return -EINVAL;
6269}
6270
6271/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272 * ipr_info - Get information about the card/driver
6273 * @scsi_host: scsi host struct
6274 *
6275 * Return value:
6276 * pointer to buffer with description string
6277 **/
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03006278static const char *ipr_ioa_info(struct Scsi_Host *host)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279{
6280 static char buffer[512];
6281 struct ipr_ioa_cfg *ioa_cfg;
6282 unsigned long lock_flags = 0;
6283
6284 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
6285
6286 spin_lock_irqsave(host->host_lock, lock_flags);
6287 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
6288 spin_unlock_irqrestore(host->host_lock, lock_flags);
6289
6290 return buffer;
6291}
6292
6293static struct scsi_host_template driver_template = {
6294 .module = THIS_MODULE,
6295 .name = "IPR",
6296 .info = ipr_ioa_info,
Brian King35a39692006-09-25 12:39:20 -05006297 .ioctl = ipr_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298 .queuecommand = ipr_queuecommand,
6299 .eh_abort_handler = ipr_eh_abort,
6300 .eh_device_reset_handler = ipr_eh_dev_reset,
6301 .eh_host_reset_handler = ipr_eh_host_reset,
6302 .slave_alloc = ipr_slave_alloc,
6303 .slave_configure = ipr_slave_configure,
6304 .slave_destroy = ipr_slave_destroy,
Brian King35a39692006-09-25 12:39:20 -05006305 .target_alloc = ipr_target_alloc,
6306 .target_destroy = ipr_target_destroy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006307 .change_queue_depth = ipr_change_queue_depth,
6308 .change_queue_type = ipr_change_queue_type,
6309 .bios_param = ipr_biosparam,
6310 .can_queue = IPR_MAX_COMMANDS,
6311 .this_id = -1,
6312 .sg_tablesize = IPR_MAX_SGLIST,
6313 .max_sectors = IPR_IOA_MAX_SECTORS,
6314 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
6315 .use_clustering = ENABLE_CLUSTERING,
6316 .shost_attrs = ipr_ioa_attrs,
6317 .sdev_attrs = ipr_dev_attrs,
Martin K. Petersen54b2b502013-10-23 06:25:40 -04006318 .proc_name = IPR_NAME,
6319 .no_write_same = 1,
Christoph Hellwig2ecb2042014-11-03 14:09:02 +01006320 .use_blk_tags = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321};
6322
Brian King35a39692006-09-25 12:39:20 -05006323/**
6324 * ipr_ata_phy_reset - libata phy_reset handler
6325 * @ap: ata port to reset
6326 *
6327 **/
6328static void ipr_ata_phy_reset(struct ata_port *ap)
6329{
6330 unsigned long flags;
6331 struct ipr_sata_port *sata_port = ap->private_data;
6332 struct ipr_resource_entry *res = sata_port->res;
6333 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6334 int rc;
6335
6336 ENTER;
6337 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03006338 while (ioa_cfg->in_reset_reload) {
Brian King35a39692006-09-25 12:39:20 -05006339 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6340 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6341 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6342 }
6343
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006344 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
Brian King35a39692006-09-25 12:39:20 -05006345 goto out_unlock;
6346
6347 rc = ipr_device_reset(ioa_cfg, res);
6348
6349 if (rc) {
Tejun Heo3e4ec342010-05-10 21:41:30 +02006350 ap->link.device[0].class = ATA_DEV_NONE;
Brian King35a39692006-09-25 12:39:20 -05006351 goto out_unlock;
6352 }
6353
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006354 ap->link.device[0].class = res->ata_class;
6355 if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
Tejun Heo3e4ec342010-05-10 21:41:30 +02006356 ap->link.device[0].class = ATA_DEV_NONE;
Brian King35a39692006-09-25 12:39:20 -05006357
6358out_unlock:
6359 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6360 LEAVE;
6361}
6362
6363/**
6364 * ipr_ata_post_internal - Cleanup after an internal command
6365 * @qc: ATA queued command
6366 *
6367 * Return value:
6368 * none
6369 **/
6370static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
6371{
6372 struct ipr_sata_port *sata_port = qc->ap->private_data;
6373 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6374 struct ipr_cmnd *ipr_cmd;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006375 struct ipr_hrr_queue *hrrq;
Brian King35a39692006-09-25 12:39:20 -05006376 unsigned long flags;
6377
6378 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03006379 while (ioa_cfg->in_reset_reload) {
Brian King73d98ff2006-11-21 10:27:58 -06006380 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6381 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6382 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6383 }
6384
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006385 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006386 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006387 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
6388 if (ipr_cmd->qc == qc) {
6389 ipr_device_reset(ioa_cfg, sata_port->res);
6390 break;
6391 }
Brian King35a39692006-09-25 12:39:20 -05006392 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006393 spin_unlock(&hrrq->_lock);
Brian King35a39692006-09-25 12:39:20 -05006394 }
6395 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6396}
6397
6398/**
Brian King35a39692006-09-25 12:39:20 -05006399 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
6400 * @regs: destination
6401 * @tf: source ATA taskfile
6402 *
6403 * Return value:
6404 * none
6405 **/
6406static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
6407 struct ata_taskfile *tf)
6408{
6409 regs->feature = tf->feature;
6410 regs->nsect = tf->nsect;
6411 regs->lbal = tf->lbal;
6412 regs->lbam = tf->lbam;
6413 regs->lbah = tf->lbah;
6414 regs->device = tf->device;
6415 regs->command = tf->command;
6416 regs->hob_feature = tf->hob_feature;
6417 regs->hob_nsect = tf->hob_nsect;
6418 regs->hob_lbal = tf->hob_lbal;
6419 regs->hob_lbam = tf->hob_lbam;
6420 regs->hob_lbah = tf->hob_lbah;
6421 regs->ctl = tf->ctl;
6422}
6423
6424/**
6425 * ipr_sata_done - done function for SATA commands
6426 * @ipr_cmd: ipr command struct
6427 *
6428 * This function is invoked by the interrupt handler for
6429 * ops generated by the SCSI mid-layer to SATA devices
6430 *
6431 * Return value:
6432 * none
6433 **/
6434static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
6435{
6436 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6437 struct ata_queued_cmd *qc = ipr_cmd->qc;
6438 struct ipr_sata_port *sata_port = qc->ap->private_data;
6439 struct ipr_resource_entry *res = sata_port->res;
Wayne Boyer96d21f02010-05-10 09:13:27 -07006440 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian King35a39692006-09-25 12:39:20 -05006441
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006442 spin_lock(&ipr_cmd->hrrq->_lock);
Wayne Boyer96d21f02010-05-10 09:13:27 -07006443 if (ipr_cmd->ioa_cfg->sis64)
6444 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
6445 sizeof(struct ipr_ioasa_gata));
6446 else
6447 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
6448 sizeof(struct ipr_ioasa_gata));
Brian King35a39692006-09-25 12:39:20 -05006449 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6450
Wayne Boyer96d21f02010-05-10 09:13:27 -07006451 if (be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006452 scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
Brian King35a39692006-09-25 12:39:20 -05006453
6454 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
Wayne Boyer96d21f02010-05-10 09:13:27 -07006455 qc->err_mask |= __ac_err_mask(sata_port->ioasa.status);
Brian King35a39692006-09-25 12:39:20 -05006456 else
Wayne Boyer96d21f02010-05-10 09:13:27 -07006457 qc->err_mask |= ac_err_mask(sata_port->ioasa.status);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006458 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006459 spin_unlock(&ipr_cmd->hrrq->_lock);
Brian King35a39692006-09-25 12:39:20 -05006460 ata_qc_complete(qc);
6461}
6462
6463/**
Wayne Boyera32c0552010-02-19 13:23:36 -08006464 * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
6465 * @ipr_cmd: ipr command struct
6466 * @qc: ATA queued command
6467 *
6468 **/
6469static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
6470 struct ata_queued_cmd *qc)
6471{
6472 u32 ioadl_flags = 0;
6473 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
wenxiong@linux.vnet.ibm.com1ac7c262013-04-18 21:32:48 -05006474 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ata_ioadl.ioadl64;
Wayne Boyera32c0552010-02-19 13:23:36 -08006475 struct ipr_ioadl64_desc *last_ioadl64 = NULL;
6476 int len = qc->nbytes;
6477 struct scatterlist *sg;
6478 unsigned int si;
6479 dma_addr_t dma_addr = ipr_cmd->dma_addr;
6480
6481 if (len == 0)
6482 return;
6483
6484 if (qc->dma_dir == DMA_TO_DEVICE) {
6485 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6486 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6487 } else if (qc->dma_dir == DMA_FROM_DEVICE)
6488 ioadl_flags = IPR_IOADL_FLAGS_READ;
6489
6490 ioarcb->data_transfer_length = cpu_to_be32(len);
6491 ioarcb->ioadl_len =
6492 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
6493 ioarcb->u.sis64_addr_data.data_ioadl_addr =
wenxiong@linux.vnet.ibm.com1ac7c262013-04-18 21:32:48 -05006494 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl.ioadl64));
Wayne Boyera32c0552010-02-19 13:23:36 -08006495
6496 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6497 ioadl64->flags = cpu_to_be32(ioadl_flags);
6498 ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
6499 ioadl64->address = cpu_to_be64(sg_dma_address(sg));
6500
6501 last_ioadl64 = ioadl64;
6502 ioadl64++;
6503 }
6504
6505 if (likely(last_ioadl64))
6506 last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6507}
6508
6509/**
Brian King35a39692006-09-25 12:39:20 -05006510 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
6511 * @ipr_cmd: ipr command struct
6512 * @qc: ATA queued command
6513 *
6514 **/
6515static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
6516 struct ata_queued_cmd *qc)
6517{
6518 u32 ioadl_flags = 0;
6519 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08006520 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006521 struct ipr_ioadl_desc *last_ioadl = NULL;
James Bottomleydde20202008-02-19 11:36:56 +01006522 int len = qc->nbytes;
Brian King35a39692006-09-25 12:39:20 -05006523 struct scatterlist *sg;
Tejun Heoff2aeb12007-12-05 16:43:11 +09006524 unsigned int si;
Brian King35a39692006-09-25 12:39:20 -05006525
6526 if (len == 0)
6527 return;
6528
6529 if (qc->dma_dir == DMA_TO_DEVICE) {
6530 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6531 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
Wayne Boyera32c0552010-02-19 13:23:36 -08006532 ioarcb->data_transfer_length = cpu_to_be32(len);
6533 ioarcb->ioadl_len =
Brian King35a39692006-09-25 12:39:20 -05006534 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6535 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
6536 ioadl_flags = IPR_IOADL_FLAGS_READ;
6537 ioarcb->read_data_transfer_length = cpu_to_be32(len);
6538 ioarcb->read_ioadl_len =
6539 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6540 }
6541
Tejun Heoff2aeb12007-12-05 16:43:11 +09006542 for_each_sg(qc->sg, sg, qc->n_elem, si) {
Brian King35a39692006-09-25 12:39:20 -05006543 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
6544 ioadl->address = cpu_to_be32(sg_dma_address(sg));
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006545
6546 last_ioadl = ioadl;
6547 ioadl++;
Brian King35a39692006-09-25 12:39:20 -05006548 }
Jeff Garzik3be6cbd2007-10-18 16:21:18 -04006549
6550 if (likely(last_ioadl))
6551 last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
Brian King35a39692006-09-25 12:39:20 -05006552}
6553
6554/**
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006555 * ipr_qc_defer - Get a free ipr_cmd
6556 * @qc: queued command
6557 *
6558 * Return value:
6559 * 0 if success
6560 **/
6561static int ipr_qc_defer(struct ata_queued_cmd *qc)
6562{
6563 struct ata_port *ap = qc->ap;
6564 struct ipr_sata_port *sata_port = ap->private_data;
6565 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6566 struct ipr_cmnd *ipr_cmd;
6567 struct ipr_hrr_queue *hrrq;
6568 int hrrq_id;
6569
6570 hrrq_id = ipr_get_hrrq_index(ioa_cfg);
6571 hrrq = &ioa_cfg->hrrq[hrrq_id];
6572
6573 qc->lldd_task = NULL;
6574 spin_lock(&hrrq->_lock);
6575 if (unlikely(hrrq->ioa_is_dead)) {
6576 spin_unlock(&hrrq->_lock);
6577 return 0;
6578 }
6579
6580 if (unlikely(!hrrq->allow_cmds)) {
6581 spin_unlock(&hrrq->_lock);
6582 return ATA_DEFER_LINK;
6583 }
6584
6585 ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
6586 if (ipr_cmd == NULL) {
6587 spin_unlock(&hrrq->_lock);
6588 return ATA_DEFER_LINK;
6589 }
6590
6591 qc->lldd_task = ipr_cmd;
6592 spin_unlock(&hrrq->_lock);
6593 return 0;
6594}
6595
6596/**
Brian King35a39692006-09-25 12:39:20 -05006597 * ipr_qc_issue - Issue a SATA qc to a device
6598 * @qc: queued command
6599 *
6600 * Return value:
6601 * 0 if success
6602 **/
6603static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
6604{
6605 struct ata_port *ap = qc->ap;
6606 struct ipr_sata_port *sata_port = ap->private_data;
6607 struct ipr_resource_entry *res = sata_port->res;
6608 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6609 struct ipr_cmnd *ipr_cmd;
6610 struct ipr_ioarcb *ioarcb;
6611 struct ipr_ioarcb_ata_regs *regs;
6612
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006613 if (qc->lldd_task == NULL)
6614 ipr_qc_defer(qc);
6615
6616 ipr_cmd = qc->lldd_task;
6617 if (ipr_cmd == NULL)
Brian King0feeed82007-03-29 12:43:43 -05006618 return AC_ERR_SYSTEM;
Brian King35a39692006-09-25 12:39:20 -05006619
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006620 qc->lldd_task = NULL;
6621 spin_lock(&ipr_cmd->hrrq->_lock);
6622 if (unlikely(!ipr_cmd->hrrq->allow_cmds ||
6623 ipr_cmd->hrrq->ioa_is_dead)) {
6624 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6625 spin_unlock(&ipr_cmd->hrrq->_lock);
6626 return AC_ERR_SYSTEM;
6627 }
6628
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006629 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
Brian King35a39692006-09-25 12:39:20 -05006630 ioarcb = &ipr_cmd->ioarcb;
Brian King35a39692006-09-25 12:39:20 -05006631
Wayne Boyera32c0552010-02-19 13:23:36 -08006632 if (ioa_cfg->sis64) {
6633 regs = &ipr_cmd->i.ata_ioadl.regs;
6634 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
6635 } else
6636 regs = &ioarcb->u.add_data.u.regs;
6637
6638 memset(regs, 0, sizeof(*regs));
6639 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
Brian King35a39692006-09-25 12:39:20 -05006640
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006641 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Brian King35a39692006-09-25 12:39:20 -05006642 ipr_cmd->qc = qc;
6643 ipr_cmd->done = ipr_sata_done;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006644 ipr_cmd->ioarcb.res_handle = res->res_handle;
Brian King35a39692006-09-25 12:39:20 -05006645 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
6646 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6647 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
James Bottomleydde20202008-02-19 11:36:56 +01006648 ipr_cmd->dma_use_sg = qc->n_elem;
Brian King35a39692006-09-25 12:39:20 -05006649
Wayne Boyera32c0552010-02-19 13:23:36 -08006650 if (ioa_cfg->sis64)
6651 ipr_build_ata_ioadl64(ipr_cmd, qc);
6652 else
6653 ipr_build_ata_ioadl(ipr_cmd, qc);
6654
Brian King35a39692006-09-25 12:39:20 -05006655 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
6656 ipr_copy_sata_tf(regs, &qc->tf);
6657 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006658 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
Brian King35a39692006-09-25 12:39:20 -05006659
6660 switch (qc->tf.protocol) {
6661 case ATA_PROT_NODATA:
6662 case ATA_PROT_PIO:
6663 break;
6664
6665 case ATA_PROT_DMA:
6666 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6667 break;
6668
Tejun Heo0dc36882007-12-18 16:34:43 -05006669 case ATAPI_PROT_PIO:
6670 case ATAPI_PROT_NODATA:
Brian King35a39692006-09-25 12:39:20 -05006671 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6672 break;
6673
Tejun Heo0dc36882007-12-18 16:34:43 -05006674 case ATAPI_PROT_DMA:
Brian King35a39692006-09-25 12:39:20 -05006675 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6676 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6677 break;
6678
6679 default:
6680 WARN_ON(1);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006681 spin_unlock(&ipr_cmd->hrrq->_lock);
Brian King0feeed82007-03-29 12:43:43 -05006682 return AC_ERR_INVALID;
Brian King35a39692006-09-25 12:39:20 -05006683 }
6684
Wayne Boyera32c0552010-02-19 13:23:36 -08006685 ipr_send_command(ipr_cmd);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006686 spin_unlock(&ipr_cmd->hrrq->_lock);
Wayne Boyera32c0552010-02-19 13:23:36 -08006687
Brian King35a39692006-09-25 12:39:20 -05006688 return 0;
6689}
6690
6691/**
Tejun Heo4c9bf4e2008-04-07 22:47:20 +09006692 * ipr_qc_fill_rtf - Read result TF
6693 * @qc: ATA queued command
6694 *
6695 * Return value:
6696 * true
6697 **/
6698static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
6699{
6700 struct ipr_sata_port *sata_port = qc->ap->private_data;
6701 struct ipr_ioasa_gata *g = &sata_port->ioasa;
6702 struct ata_taskfile *tf = &qc->result_tf;
6703
6704 tf->feature = g->error;
6705 tf->nsect = g->nsect;
6706 tf->lbal = g->lbal;
6707 tf->lbam = g->lbam;
6708 tf->lbah = g->lbah;
6709 tf->device = g->device;
6710 tf->command = g->status;
6711 tf->hob_nsect = g->hob_nsect;
6712 tf->hob_lbal = g->hob_lbal;
6713 tf->hob_lbam = g->hob_lbam;
6714 tf->hob_lbah = g->hob_lbah;
Tejun Heo4c9bf4e2008-04-07 22:47:20 +09006715
6716 return true;
6717}
6718
Brian King35a39692006-09-25 12:39:20 -05006719static struct ata_port_operations ipr_sata_ops = {
Brian King35a39692006-09-25 12:39:20 -05006720 .phy_reset = ipr_ata_phy_reset,
Tejun Heoa1efdab2008-03-25 12:22:50 +09006721 .hardreset = ipr_sata_reset,
Brian King35a39692006-09-25 12:39:20 -05006722 .post_internal_cmd = ipr_ata_post_internal,
Brian King35a39692006-09-25 12:39:20 -05006723 .qc_prep = ata_noop_qc_prep,
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006724 .qc_defer = ipr_qc_defer,
Brian King35a39692006-09-25 12:39:20 -05006725 .qc_issue = ipr_qc_issue,
Tejun Heo4c9bf4e2008-04-07 22:47:20 +09006726 .qc_fill_rtf = ipr_qc_fill_rtf,
Brian King35a39692006-09-25 12:39:20 -05006727 .port_start = ata_sas_port_start,
6728 .port_stop = ata_sas_port_stop
6729};
6730
6731static struct ata_port_info sata_port_info = {
Sergei Shtylyov9cbe0562011-02-04 22:05:48 +03006732 .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA,
Sergei Shtylyov0f2e0332011-01-21 20:32:01 +03006733 .pio_mask = ATA_PIO4_ONLY,
6734 .mwdma_mask = ATA_MWDMA2,
6735 .udma_mask = ATA_UDMA6,
Brian King35a39692006-09-25 12:39:20 -05006736 .port_ops = &ipr_sata_ops
6737};
6738
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739#ifdef CONFIG_PPC_PSERIES
6740static const u16 ipr_blocked_processors[] = {
Michael Ellermand3dbeef2012-08-19 21:44:01 +00006741 PVR_NORTHSTAR,
6742 PVR_PULSAR,
6743 PVR_POWER4,
6744 PVR_ICESTAR,
6745 PVR_SSTAR,
6746 PVR_POWER4p,
6747 PVR_630,
6748 PVR_630p
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749};
6750
6751/**
6752 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
6753 * @ioa_cfg: ioa cfg struct
6754 *
6755 * Adapters that use Gemstone revision < 3.1 do not work reliably on
6756 * certain pSeries hardware. This function determines if the given
6757 * adapter is in one of these confgurations or not.
6758 *
6759 * Return value:
6760 * 1 if adapter is not supported / 0 if adapter is supported
6761 **/
6762static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
6763{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006764 int i;
6765
Auke Kok44c10132007-06-08 15:46:36 -07006766 if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03006767 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++) {
Michael Ellermand3dbeef2012-08-19 21:44:01 +00006768 if (pvr_version_is(ipr_blocked_processors[i]))
Auke Kok44c10132007-06-08 15:46:36 -07006769 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006770 }
6771 }
6772 return 0;
6773}
6774#else
6775#define ipr_invalid_adapter(ioa_cfg) 0
6776#endif
6777
6778/**
6779 * ipr_ioa_bringdown_done - IOA bring down completion.
6780 * @ipr_cmd: ipr command struct
6781 *
6782 * This function processes the completion of an adapter bring down.
6783 * It wakes any reset sleepers.
6784 *
6785 * Return value:
6786 * IPR_RC_JOB_RETURN
6787 **/
6788static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
6789{
6790 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
wenxiong@linux.vnet.ibm.com96b04db2013-04-17 09:34:06 -05006791 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006792
6793 ENTER;
Brian Kingbfae7822013-01-30 23:45:08 -06006794 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
6795 ipr_trace;
6796 spin_unlock_irq(ioa_cfg->host->host_lock);
6797 scsi_unblock_requests(ioa_cfg->host);
6798 spin_lock_irq(ioa_cfg->host->host_lock);
6799 }
6800
Linus Torvalds1da177e2005-04-16 15:20:36 -07006801 ioa_cfg->in_reset_reload = 0;
6802 ioa_cfg->reset_retries = 0;
wenxiong@linux.vnet.ibm.com96b04db2013-04-17 09:34:06 -05006803 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
6804 spin_lock(&ioa_cfg->hrrq[i]._lock);
6805 ioa_cfg->hrrq[i].ioa_is_dead = 1;
6806 spin_unlock(&ioa_cfg->hrrq[i]._lock);
6807 }
6808 wmb();
6809
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006810 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006811 wake_up_all(&ioa_cfg->reset_wait_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006812 LEAVE;
6813
6814 return IPR_RC_JOB_RETURN;
6815}
6816
6817/**
6818 * ipr_ioa_reset_done - IOA reset completion.
6819 * @ipr_cmd: ipr command struct
6820 *
6821 * This function processes the completion of an adapter reset.
6822 * It schedules any necessary mid-layer add/removes and
6823 * wakes any reset sleepers.
6824 *
6825 * Return value:
6826 * IPR_RC_JOB_RETURN
6827 **/
6828static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
6829{
6830 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6831 struct ipr_resource_entry *res;
6832 struct ipr_hostrcb *hostrcb, *temp;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006833 int i = 0, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006834
6835 ENTER;
6836 ioa_cfg->in_reset_reload = 0;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006837 for (j = 0; j < ioa_cfg->hrrq_num; j++) {
6838 spin_lock(&ioa_cfg->hrrq[j]._lock);
6839 ioa_cfg->hrrq[j].allow_cmds = 1;
6840 spin_unlock(&ioa_cfg->hrrq[j]._lock);
6841 }
6842 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006843 ioa_cfg->reset_cmd = NULL;
brking@us.ibm.com3d1d0da2005-11-01 17:01:54 -06006844 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006845
6846 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
6847 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
6848 ipr_trace;
6849 break;
6850 }
6851 }
6852 schedule_work(&ioa_cfg->work_q);
6853
6854 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
6855 list_del(&hostrcb->queue);
6856 if (i++ < IPR_NUM_LOG_HCAMS)
6857 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
6858 else
6859 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
6860 }
6861
Brian King6bb04172007-04-26 16:00:08 -05006862 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006863 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
6864
6865 ioa_cfg->reset_retries = 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006866 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006867 wake_up_all(&ioa_cfg->reset_wait_q);
6868
Mark Nelson30237852008-12-10 12:23:20 +11006869 spin_unlock(ioa_cfg->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006870 scsi_unblock_requests(ioa_cfg->host);
Mark Nelson30237852008-12-10 12:23:20 +11006871 spin_lock(ioa_cfg->host->host_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006872
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06006873 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006874 scsi_block_requests(ioa_cfg->host);
6875
6876 LEAVE;
6877 return IPR_RC_JOB_RETURN;
6878}
6879
6880/**
6881 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
6882 * @supported_dev: supported device struct
6883 * @vpids: vendor product id struct
6884 *
6885 * Return value:
6886 * none
6887 **/
6888static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
6889 struct ipr_std_inq_vpids *vpids)
6890{
6891 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
6892 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
6893 supported_dev->num_records = 1;
6894 supported_dev->data_length =
6895 cpu_to_be16(sizeof(struct ipr_supported_device));
6896 supported_dev->reserved = 0;
6897}
6898
6899/**
6900 * ipr_set_supported_devs - Send Set Supported Devices for a device
6901 * @ipr_cmd: ipr command struct
6902 *
Wayne Boyera32c0552010-02-19 13:23:36 -08006903 * This function sends a Set Supported Devices to the adapter
Linus Torvalds1da177e2005-04-16 15:20:36 -07006904 *
6905 * Return value:
6906 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6907 **/
6908static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
6909{
6910 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6911 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006912 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6913 struct ipr_resource_entry *res = ipr_cmd->u.res;
6914
6915 ipr_cmd->job_step = ipr_ioa_reset_done;
6916
6917 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
Brian Kinge4fbf442006-03-29 09:37:22 -06006918 if (!ipr_is_scsi_disk(res))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006919 continue;
6920
6921 ipr_cmd->u.res = res;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006922 ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006923
6924 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6925 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6926 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6927
6928 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006929 ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006930 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
6931 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
6932
Wayne Boyera32c0552010-02-19 13:23:36 -08006933 ipr_init_ioadl(ipr_cmd,
6934 ioa_cfg->vpd_cbs_dma +
6935 offsetof(struct ipr_misc_cbs, supp_dev),
6936 sizeof(struct ipr_supported_device),
6937 IPR_IOADL_FLAGS_WRITE_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006938
6939 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
6940 IPR_SET_SUP_DEVICE_TIMEOUT);
6941
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08006942 if (!ioa_cfg->sis64)
6943 ipr_cmd->job_step = ipr_set_supported_devs;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006944 LEAVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006945 return IPR_RC_JOB_RETURN;
6946 }
6947
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06006948 LEAVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006949 return IPR_RC_JOB_CONTINUE;
6950}
6951
6952/**
6953 * ipr_get_mode_page - Locate specified mode page
6954 * @mode_pages: mode page buffer
6955 * @page_code: page code to find
6956 * @len: minimum required length for mode page
6957 *
6958 * Return value:
6959 * pointer to mode page / NULL on failure
6960 **/
6961static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
6962 u32 page_code, u32 len)
6963{
6964 struct ipr_mode_page_hdr *mode_hdr;
6965 u32 page_length;
6966 u32 length;
6967
6968 if (!mode_pages || (mode_pages->hdr.length == 0))
6969 return NULL;
6970
6971 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
6972 mode_hdr = (struct ipr_mode_page_hdr *)
6973 (mode_pages->data + mode_pages->hdr.block_desc_len);
6974
6975 while (length) {
6976 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
6977 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
6978 return mode_hdr;
6979 break;
6980 } else {
6981 page_length = (sizeof(struct ipr_mode_page_hdr) +
6982 mode_hdr->page_length);
6983 length -= page_length;
6984 mode_hdr = (struct ipr_mode_page_hdr *)
6985 ((unsigned long)mode_hdr + page_length);
6986 }
6987 }
6988 return NULL;
6989}
6990
6991/**
6992 * ipr_check_term_power - Check for term power errors
6993 * @ioa_cfg: ioa config struct
6994 * @mode_pages: IOAFP mode pages buffer
6995 *
6996 * Check the IOAFP's mode page 28 for term power errors
6997 *
6998 * Return value:
6999 * nothing
7000 **/
7001static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
7002 struct ipr_mode_pages *mode_pages)
7003{
7004 int i;
7005 int entry_length;
7006 struct ipr_dev_bus_entry *bus;
7007 struct ipr_mode_page28 *mode_page;
7008
7009 mode_page = ipr_get_mode_page(mode_pages, 0x28,
7010 sizeof(struct ipr_mode_page28));
7011
7012 entry_length = mode_page->entry_length;
7013
7014 bus = mode_page->bus;
7015
7016 for (i = 0; i < mode_page->num_entries; i++) {
7017 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
7018 dev_err(&ioa_cfg->pdev->dev,
7019 "Term power is absent on scsi bus %d\n",
7020 bus->res_addr.bus);
7021 }
7022
7023 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
7024 }
7025}
7026
7027/**
7028 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
7029 * @ioa_cfg: ioa config struct
7030 *
7031 * Looks through the config table checking for SES devices. If
7032 * the SES device is in the SES table indicating a maximum SCSI
7033 * bus speed, the speed is limited for the bus.
7034 *
7035 * Return value:
7036 * none
7037 **/
7038static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
7039{
7040 u32 max_xfer_rate;
7041 int i;
7042
7043 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
7044 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
7045 ioa_cfg->bus_attr[i].bus_width);
7046
7047 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
7048 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
7049 }
7050}
7051
7052/**
7053 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
7054 * @ioa_cfg: ioa config struct
7055 * @mode_pages: mode page 28 buffer
7056 *
7057 * Updates mode page 28 based on driver configuration
7058 *
7059 * Return value:
7060 * none
7061 **/
7062static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03007063 struct ipr_mode_pages *mode_pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064{
7065 int i, entry_length;
7066 struct ipr_dev_bus_entry *bus;
7067 struct ipr_bus_attributes *bus_attr;
7068 struct ipr_mode_page28 *mode_page;
7069
7070 mode_page = ipr_get_mode_page(mode_pages, 0x28,
7071 sizeof(struct ipr_mode_page28));
7072
7073 entry_length = mode_page->entry_length;
7074
7075 /* Loop for each device bus entry */
7076 for (i = 0, bus = mode_page->bus;
7077 i < mode_page->num_entries;
7078 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
7079 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
7080 dev_err(&ioa_cfg->pdev->dev,
7081 "Invalid resource address reported: 0x%08X\n",
7082 IPR_GET_PHYS_LOC(bus->res_addr));
7083 continue;
7084 }
7085
7086 bus_attr = &ioa_cfg->bus_attr[i];
7087 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
7088 bus->bus_width = bus_attr->bus_width;
7089 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
7090 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
7091 if (bus_attr->qas_enabled)
7092 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
7093 else
7094 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
7095 }
7096}
7097
7098/**
7099 * ipr_build_mode_select - Build a mode select command
7100 * @ipr_cmd: ipr command struct
7101 * @res_handle: resource handle to send command to
7102 * @parm: Byte 2 of Mode Sense command
7103 * @dma_addr: DMA buffer address
7104 * @xfer_len: data transfer length
7105 *
7106 * Return value:
7107 * none
7108 **/
7109static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
Wayne Boyera32c0552010-02-19 13:23:36 -08007110 __be32 res_handle, u8 parm,
7111 dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007112{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007113 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7114
7115 ioarcb->res_handle = res_handle;
7116 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7117 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
7118 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
7119 ioarcb->cmd_pkt.cdb[1] = parm;
7120 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7121
Wayne Boyera32c0552010-02-19 13:23:36 -08007122 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007123}
7124
7125/**
7126 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
7127 * @ipr_cmd: ipr command struct
7128 *
7129 * This function sets up the SCSI bus attributes and sends
7130 * a Mode Select for Page 28 to activate them.
7131 *
7132 * Return value:
7133 * IPR_RC_JOB_RETURN
7134 **/
7135static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
7136{
7137 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7138 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
7139 int length;
7140
7141 ENTER;
Brian King47338042006-02-08 20:57:42 -06007142 ipr_scsi_bus_speed_limit(ioa_cfg);
7143 ipr_check_term_power(ioa_cfg, mode_pages);
7144 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
7145 length = mode_pages->hdr.length + 1;
7146 mode_pages->hdr.length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007147
7148 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
7149 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
7150 length);
7151
Wayne Boyerf72919e2010-02-19 13:24:21 -08007152 ipr_cmd->job_step = ipr_set_supported_devs;
7153 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
7154 struct ipr_resource_entry, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007155 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7156
7157 LEAVE;
7158 return IPR_RC_JOB_RETURN;
7159}
7160
7161/**
7162 * ipr_build_mode_sense - Builds a mode sense command
7163 * @ipr_cmd: ipr command struct
7164 * @res: resource entry struct
7165 * @parm: Byte 2 of mode sense command
7166 * @dma_addr: DMA address of mode sense buffer
7167 * @xfer_len: Size of DMA buffer
7168 *
7169 * Return value:
7170 * none
7171 **/
7172static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
7173 __be32 res_handle,
Wayne Boyera32c0552010-02-19 13:23:36 -08007174 u8 parm, dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007175{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007176 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7177
7178 ioarcb->res_handle = res_handle;
7179 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
7180 ioarcb->cmd_pkt.cdb[2] = parm;
7181 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7182 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7183
Wayne Boyera32c0552010-02-19 13:23:36 -08007184 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007185}
7186
7187/**
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007188 * ipr_reset_cmd_failed - Handle failure of IOA reset command
7189 * @ipr_cmd: ipr command struct
7190 *
7191 * This function handles the failure of an IOA bringup command.
7192 *
7193 * Return value:
7194 * IPR_RC_JOB_RETURN
7195 **/
7196static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
7197{
7198 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer96d21f02010-05-10 09:13:27 -07007199 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007200
7201 dev_err(&ioa_cfg->pdev->dev,
7202 "0x%02X failed with IOASC: 0x%08X\n",
7203 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
7204
7205 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007206 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007207 return IPR_RC_JOB_RETURN;
7208}
7209
7210/**
7211 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
7212 * @ipr_cmd: ipr command struct
7213 *
7214 * This function handles the failure of a Mode Sense to the IOAFP.
7215 * Some adapters do not handle all mode pages.
7216 *
7217 * Return value:
7218 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7219 **/
7220static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
7221{
Wayne Boyerf72919e2010-02-19 13:24:21 -08007222 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer96d21f02010-05-10 09:13:27 -07007223 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007224
7225 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
Wayne Boyerf72919e2010-02-19 13:24:21 -08007226 ipr_cmd->job_step = ipr_set_supported_devs;
7227 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
7228 struct ipr_resource_entry, queue);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007229 return IPR_RC_JOB_CONTINUE;
7230 }
7231
7232 return ipr_reset_cmd_failed(ipr_cmd);
7233}
7234
7235/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007236 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
7237 * @ipr_cmd: ipr command struct
7238 *
7239 * This function send a Page 28 mode sense to the IOA to
7240 * retrieve SCSI bus attributes.
7241 *
7242 * Return value:
7243 * IPR_RC_JOB_RETURN
7244 **/
7245static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
7246{
7247 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7248
7249 ENTER;
7250 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
7251 0x28, ioa_cfg->vpd_cbs_dma +
7252 offsetof(struct ipr_misc_cbs, mode_pages),
7253 sizeof(struct ipr_mode_pages));
7254
7255 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06007256 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007257
7258 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7259
7260 LEAVE;
7261 return IPR_RC_JOB_RETURN;
7262}
7263
7264/**
Brian Kingac09c342007-04-26 16:00:16 -05007265 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
7266 * @ipr_cmd: ipr command struct
7267 *
7268 * This function enables dual IOA RAID support if possible.
7269 *
7270 * Return value:
7271 * IPR_RC_JOB_RETURN
7272 **/
7273static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
7274{
7275 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7276 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
7277 struct ipr_mode_page24 *mode_page;
7278 int length;
7279
7280 ENTER;
7281 mode_page = ipr_get_mode_page(mode_pages, 0x24,
7282 sizeof(struct ipr_mode_page24));
7283
7284 if (mode_page)
7285 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
7286
7287 length = mode_pages->hdr.length + 1;
7288 mode_pages->hdr.length = 0;
7289
7290 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
7291 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
7292 length);
7293
7294 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7295 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7296
7297 LEAVE;
7298 return IPR_RC_JOB_RETURN;
7299}
7300
7301/**
7302 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
7303 * @ipr_cmd: ipr command struct
7304 *
7305 * This function handles the failure of a Mode Sense to the IOAFP.
7306 * Some adapters do not handle all mode pages.
7307 *
7308 * Return value:
7309 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7310 **/
7311static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
7312{
Wayne Boyer96d21f02010-05-10 09:13:27 -07007313 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Brian Kingac09c342007-04-26 16:00:16 -05007314
7315 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
7316 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7317 return IPR_RC_JOB_CONTINUE;
7318 }
7319
7320 return ipr_reset_cmd_failed(ipr_cmd);
7321}
7322
7323/**
7324 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
7325 * @ipr_cmd: ipr command struct
7326 *
7327 * This function send a mode sense to the IOA to retrieve
7328 * the IOA Advanced Function Control mode page.
7329 *
7330 * Return value:
7331 * IPR_RC_JOB_RETURN
7332 **/
7333static int ipr_ioafp_mode_sense_page24(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 0x24, 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_page24;
7344 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
7345
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/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007353 * ipr_init_res_table - Initialize the resource table
7354 * @ipr_cmd: ipr command struct
7355 *
7356 * This function looks through the existing resource table, comparing
7357 * it with the config table. This function will take care of old/new
7358 * devices and schedule adding/removing them from the mid-layer
7359 * as appropriate.
7360 *
7361 * Return value:
7362 * IPR_RC_JOB_CONTINUE
7363 **/
7364static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
7365{
7366 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7367 struct ipr_resource_entry *res, *temp;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007368 struct ipr_config_table_entry_wrapper cfgtew;
7369 int entries, found, flag, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007370 LIST_HEAD(old_res);
7371
7372 ENTER;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007373 if (ioa_cfg->sis64)
7374 flag = ioa_cfg->u.cfg_table64->hdr64.flags;
7375 else
7376 flag = ioa_cfg->u.cfg_table->hdr.flags;
7377
7378 if (flag & IPR_UCODE_DOWNLOAD_REQ)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007379 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
7380
7381 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
7382 list_move_tail(&res->queue, &old_res);
7383
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007384 if (ioa_cfg->sis64)
Wayne Boyer438b0332010-05-10 09:13:00 -07007385 entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007386 else
7387 entries = ioa_cfg->u.cfg_table->hdr.num_entries;
7388
7389 for (i = 0; i < entries; i++) {
7390 if (ioa_cfg->sis64)
7391 cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
7392 else
7393 cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07007394 found = 0;
7395
7396 list_for_each_entry_safe(res, temp, &old_res, queue) {
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007397 if (ipr_is_same_device(res, &cfgtew)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007398 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7399 found = 1;
7400 break;
7401 }
7402 }
7403
7404 if (!found) {
7405 if (list_empty(&ioa_cfg->free_res_q)) {
7406 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
7407 break;
7408 }
7409
7410 found = 1;
7411 res = list_entry(ioa_cfg->free_res_q.next,
7412 struct ipr_resource_entry, queue);
7413 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007414 ipr_init_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007415 res->add_to_ml = 1;
Wayne Boyer56115592010-06-10 14:46:34 -07007416 } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
7417 res->sdev->allow_restart = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007418
7419 if (found)
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007420 ipr_update_res_entry(res, &cfgtew);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007421 }
7422
7423 list_for_each_entry_safe(res, temp, &old_res, queue) {
7424 if (res->sdev) {
7425 res->del_from_ml = 1;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007426 res->res_handle = IPR_INVALID_RES_HANDLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007427 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007428 }
7429 }
7430
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007431 list_for_each_entry_safe(res, temp, &old_res, queue) {
7432 ipr_clear_res_target(res);
7433 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
7434 }
7435
Brian Kingac09c342007-04-26 16:00:16 -05007436 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
7437 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
7438 else
7439 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007440
7441 LEAVE;
7442 return IPR_RC_JOB_CONTINUE;
7443}
7444
7445/**
7446 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
7447 * @ipr_cmd: ipr command struct
7448 *
7449 * This function sends a Query IOA Configuration command
7450 * to the adapter to retrieve the IOA configuration table.
7451 *
7452 * Return value:
7453 * IPR_RC_JOB_RETURN
7454 **/
7455static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
7456{
7457 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7458 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007459 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
Brian Kingac09c342007-04-26 16:00:16 -05007460 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007461
7462 ENTER;
Brian Kingac09c342007-04-26 16:00:16 -05007463 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
7464 ioa_cfg->dual_raid = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007465 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
7466 ucode_vpd->major_release, ucode_vpd->card_type,
7467 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
7468 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7469 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7470
7471 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
Wayne Boyer438b0332010-05-10 09:13:00 -07007472 ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007473 ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
7474 ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007475
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007476 ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
Wayne Boyera32c0552010-02-19 13:23:36 -08007477 IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007478
7479 ipr_cmd->job_step = ipr_init_res_table;
7480
7481 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7482
7483 LEAVE;
7484 return IPR_RC_JOB_RETURN;
7485}
7486
7487/**
7488 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
7489 * @ipr_cmd: ipr command struct
7490 *
7491 * This utility function sends an inquiry to the adapter.
7492 *
7493 * Return value:
7494 * none
7495 **/
7496static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
Wayne Boyera32c0552010-02-19 13:23:36 -08007497 dma_addr_t dma_addr, u8 xfer_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007498{
7499 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007500
7501 ENTER;
7502 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7503 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7504
7505 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
7506 ioarcb->cmd_pkt.cdb[1] = flags;
7507 ioarcb->cmd_pkt.cdb[2] = page;
7508 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7509
Wayne Boyera32c0552010-02-19 13:23:36 -08007510 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007511
7512 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7513 LEAVE;
7514}
7515
7516/**
brking@us.ibm.com62275042005-11-01 17:01:14 -06007517 * ipr_inquiry_page_supported - Is the given inquiry page supported
7518 * @page0: inquiry page 0 buffer
7519 * @page: page code.
7520 *
7521 * This function determines if the specified inquiry page is supported.
7522 *
7523 * Return value:
7524 * 1 if page is supported / 0 if not
7525 **/
7526static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
7527{
7528 int i;
7529
7530 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
7531 if (page0->page[i] == page)
7532 return 1;
7533
7534 return 0;
7535}
7536
7537/**
Brian Kingac09c342007-04-26 16:00:16 -05007538 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
7539 * @ipr_cmd: ipr command struct
7540 *
7541 * This function sends a Page 0xD0 inquiry to the adapter
7542 * to retrieve adapter capabilities.
7543 *
7544 * Return value:
7545 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7546 **/
7547static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
7548{
7549 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7550 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
7551 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7552
7553 ENTER;
7554 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
7555 memset(cap, 0, sizeof(*cap));
7556
7557 if (ipr_inquiry_page_supported(page0, 0xD0)) {
7558 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
7559 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
7560 sizeof(struct ipr_inquiry_cap));
7561 return IPR_RC_JOB_RETURN;
7562 }
7563
7564 LEAVE;
7565 return IPR_RC_JOB_CONTINUE;
7566}
7567
7568/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007569 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
7570 * @ipr_cmd: ipr command struct
7571 *
7572 * This function sends a Page 3 inquiry to the adapter
7573 * to retrieve software VPD information.
7574 *
7575 * Return value:
7576 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7577 **/
7578static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
7579{
7580 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007581
7582 ENTER;
7583
Brian Kingac09c342007-04-26 16:00:16 -05007584 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007585
7586 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
7587 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
7588 sizeof(struct ipr_inquiry_page3));
7589
7590 LEAVE;
7591 return IPR_RC_JOB_RETURN;
7592}
7593
7594/**
7595 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
7596 * @ipr_cmd: ipr command struct
7597 *
7598 * This function sends a Page 0 inquiry to the adapter
7599 * to retrieve supported inquiry pages.
7600 *
7601 * Return value:
7602 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7603 **/
7604static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
7605{
7606 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007607 char type[5];
7608
7609 ENTER;
7610
7611 /* Grab the type out of the VPD and store it away */
7612 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
7613 type[4] = '\0';
7614 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
7615
brking@us.ibm.com62275042005-11-01 17:01:14 -06007616 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007617
brking@us.ibm.com62275042005-11-01 17:01:14 -06007618 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
7619 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
7620 sizeof(struct ipr_inquiry_page0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07007621
7622 LEAVE;
7623 return IPR_RC_JOB_RETURN;
7624}
7625
7626/**
7627 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
7628 * @ipr_cmd: ipr command struct
7629 *
7630 * This function sends a standard inquiry to the adapter.
7631 *
7632 * Return value:
7633 * IPR_RC_JOB_RETURN
7634 **/
7635static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
7636{
7637 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7638
7639 ENTER;
brking@us.ibm.com62275042005-11-01 17:01:14 -06007640 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007641
7642 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
7643 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
7644 sizeof(struct ipr_ioa_vpd));
7645
7646 LEAVE;
7647 return IPR_RC_JOB_RETURN;
7648}
7649
7650/**
Wayne Boyer214777b2010-02-19 13:24:26 -08007651 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007652 * @ipr_cmd: ipr command struct
7653 *
7654 * This function send an Identify Host Request Response Queue
7655 * command to establish the HRRQ with the adapter.
7656 *
7657 * Return value:
7658 * IPR_RC_JOB_RETURN
7659 **/
Wayne Boyer214777b2010-02-19 13:24:26 -08007660static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007661{
7662 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7663 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007664 struct ipr_hrr_queue *hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007665
7666 ENTER;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007667 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007668 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
7669
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007670 if (ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num) {
7671 hrrq = &ioa_cfg->hrrq[ioa_cfg->identify_hrrq_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07007672
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007673 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
7674 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007675
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007676 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7677 if (ioa_cfg->sis64)
7678 ioarcb->cmd_pkt.cdb[1] = 0x1;
7679
7680 if (ioa_cfg->nvectors == 1)
7681 ioarcb->cmd_pkt.cdb[1] &= ~IPR_ID_HRRQ_SELE_ENABLE;
7682 else
7683 ioarcb->cmd_pkt.cdb[1] |= IPR_ID_HRRQ_SELE_ENABLE;
7684
7685 ioarcb->cmd_pkt.cdb[2] =
7686 ((u64) hrrq->host_rrq_dma >> 24) & 0xff;
7687 ioarcb->cmd_pkt.cdb[3] =
7688 ((u64) hrrq->host_rrq_dma >> 16) & 0xff;
7689 ioarcb->cmd_pkt.cdb[4] =
7690 ((u64) hrrq->host_rrq_dma >> 8) & 0xff;
7691 ioarcb->cmd_pkt.cdb[5] =
7692 ((u64) hrrq->host_rrq_dma) & 0xff;
7693 ioarcb->cmd_pkt.cdb[7] =
7694 ((sizeof(u32) * hrrq->size) >> 8) & 0xff;
7695 ioarcb->cmd_pkt.cdb[8] =
7696 (sizeof(u32) * hrrq->size) & 0xff;
7697
7698 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007699 ioarcb->cmd_pkt.cdb[9] =
7700 ioa_cfg->identify_hrrq_index;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007701
7702 if (ioa_cfg->sis64) {
7703 ioarcb->cmd_pkt.cdb[10] =
7704 ((u64) hrrq->host_rrq_dma >> 56) & 0xff;
7705 ioarcb->cmd_pkt.cdb[11] =
7706 ((u64) hrrq->host_rrq_dma >> 48) & 0xff;
7707 ioarcb->cmd_pkt.cdb[12] =
7708 ((u64) hrrq->host_rrq_dma >> 40) & 0xff;
7709 ioarcb->cmd_pkt.cdb[13] =
7710 ((u64) hrrq->host_rrq_dma >> 32) & 0xff;
7711 }
7712
7713 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007714 ioarcb->cmd_pkt.cdb[14] =
7715 ioa_cfg->identify_hrrq_index;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007716
7717 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7718 IPR_INTERNAL_TIMEOUT);
7719
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007720 if (++ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num)
7721 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007722
7723 LEAVE;
7724 return IPR_RC_JOB_RETURN;
Wayne Boyer214777b2010-02-19 13:24:26 -08007725 }
7726
Linus Torvalds1da177e2005-04-16 15:20:36 -07007727 LEAVE;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007728 return IPR_RC_JOB_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007729}
7730
7731/**
7732 * ipr_reset_timer_done - Adapter reset timer function
7733 * @ipr_cmd: ipr command struct
7734 *
7735 * Description: This function is used in adapter reset processing
7736 * for timing events. If the reset_cmd pointer in the IOA
7737 * config struct is not this adapter's we are doing nested
7738 * resets and fail_all_ops will take care of freeing the
7739 * command block.
7740 *
7741 * Return value:
7742 * none
7743 **/
7744static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
7745{
7746 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7747 unsigned long lock_flags = 0;
7748
7749 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7750
7751 if (ioa_cfg->reset_cmd == ipr_cmd) {
7752 list_del(&ipr_cmd->queue);
7753 ipr_cmd->done(ipr_cmd);
7754 }
7755
7756 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7757}
7758
7759/**
7760 * ipr_reset_start_timer - Start a timer for adapter reset job
7761 * @ipr_cmd: ipr command struct
7762 * @timeout: timeout value
7763 *
7764 * Description: This function is used in adapter reset processing
7765 * for timing events. If the reset_cmd pointer in the IOA
7766 * config struct is not this adapter's we are doing nested
7767 * resets and fail_all_ops will take care of freeing the
7768 * command block.
7769 *
7770 * Return value:
7771 * none
7772 **/
7773static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
7774 unsigned long timeout)
7775{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007776
7777 ENTER;
7778 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007779 ipr_cmd->done = ipr_reset_ioa_job;
7780
7781 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7782 ipr_cmd->timer.expires = jiffies + timeout;
7783 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
7784 add_timer(&ipr_cmd->timer);
7785}
7786
7787/**
7788 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7789 * @ioa_cfg: ioa cfg struct
7790 *
7791 * Return value:
7792 * nothing
7793 **/
7794static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
7795{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007796 struct ipr_hrr_queue *hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007797
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007798 for_each_hrrq(hrrq, ioa_cfg) {
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007799 spin_lock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007800 memset(hrrq->host_rrq, 0, sizeof(u32) * hrrq->size);
7801
7802 /* Initialize Host RRQ pointers */
7803 hrrq->hrrq_start = hrrq->host_rrq;
7804 hrrq->hrrq_end = &hrrq->host_rrq[hrrq->size - 1];
7805 hrrq->hrrq_curr = hrrq->hrrq_start;
7806 hrrq->toggle_bit = 1;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007807 spin_unlock(&hrrq->_lock);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007808 }
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007809 wmb();
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007810
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007811 ioa_cfg->identify_hrrq_index = 0;
7812 if (ioa_cfg->hrrq_num == 1)
7813 atomic_set(&ioa_cfg->hrrq_index, 0);
7814 else
7815 atomic_set(&ioa_cfg->hrrq_index, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007816
7817 /* Zero out config table */
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08007818 memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007819}
7820
7821/**
Wayne Boyer214777b2010-02-19 13:24:26 -08007822 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
7823 * @ipr_cmd: ipr command struct
7824 *
7825 * Return value:
7826 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7827 **/
7828static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
7829{
7830 unsigned long stage, stage_time;
7831 u32 feedback;
7832 volatile u32 int_reg;
7833 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7834 u64 maskval = 0;
7835
7836 feedback = readl(ioa_cfg->regs.init_feedback_reg);
7837 stage = feedback & IPR_IPL_INIT_STAGE_MASK;
7838 stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
7839
7840 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
7841
7842 /* sanity check the stage_time value */
Wayne Boyer438b0332010-05-10 09:13:00 -07007843 if (stage_time == 0)
7844 stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
7845 else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
Wayne Boyer214777b2010-02-19 13:24:26 -08007846 stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
7847 else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
7848 stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
7849
7850 if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
7851 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
7852 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7853 stage_time = ioa_cfg->transop_timeout;
7854 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7855 } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
Wayne Boyer1df79ca2010-07-14 10:49:43 -07007856 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
7857 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7858 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7859 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7860 maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
7861 writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
7862 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7863 return IPR_RC_JOB_CONTINUE;
7864 }
Wayne Boyer214777b2010-02-19 13:24:26 -08007865 }
7866
7867 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7868 ipr_cmd->timer.expires = jiffies + stage_time * HZ;
7869 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7870 ipr_cmd->done = ipr_reset_ioa_job;
7871 add_timer(&ipr_cmd->timer);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007872
7873 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Wayne Boyer214777b2010-02-19 13:24:26 -08007874
7875 return IPR_RC_JOB_RETURN;
7876}
7877
7878/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07007879 * ipr_reset_enable_ioa - Enable the IOA following a reset.
7880 * @ipr_cmd: ipr command struct
7881 *
7882 * This function reinitializes some control blocks and
7883 * enables destructive diagnostics on the adapter.
7884 *
7885 * Return value:
7886 * IPR_RC_JOB_RETURN
7887 **/
7888static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
7889{
7890 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7891 volatile u32 int_reg;
Wayne Boyer7be96902010-05-10 09:14:07 -07007892 volatile u64 maskval;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007893 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007894
7895 ENTER;
Wayne Boyer214777b2010-02-19 13:24:26 -08007896 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007897 ipr_init_ioa_mem(ioa_cfg);
7898
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06007899 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
7900 spin_lock(&ioa_cfg->hrrq[i]._lock);
7901 ioa_cfg->hrrq[i].allow_interrupts = 1;
7902 spin_unlock(&ioa_cfg->hrrq[i]._lock);
7903 }
7904 wmb();
Wayne Boyer8701f182010-06-04 10:26:50 -07007905 if (ioa_cfg->sis64) {
7906 /* Set the adapter to the correct endian mode. */
7907 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
7908 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
7909 }
7910
Wayne Boyer7be96902010-05-10 09:14:07 -07007911 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007912
7913 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7914 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
Wayne Boyer214777b2010-02-19 13:24:26 -08007915 ioa_cfg->regs.clr_interrupt_mask_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007916 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7917 return IPR_RC_JOB_CONTINUE;
7918 }
7919
7920 /* Enable destructive diagnostics on IOA */
Wayne Boyer214777b2010-02-19 13:24:26 -08007921 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007922
Wayne Boyer7be96902010-05-10 09:14:07 -07007923 if (ioa_cfg->sis64) {
7924 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7925 maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
7926 writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
7927 } else
7928 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
Wayne Boyer214777b2010-02-19 13:24:26 -08007929
Linus Torvalds1da177e2005-04-16 15:20:36 -07007930 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7931
7932 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
7933
Wayne Boyer214777b2010-02-19 13:24:26 -08007934 if (ioa_cfg->sis64) {
7935 ipr_cmd->job_step = ipr_reset_next_stage;
7936 return IPR_RC_JOB_CONTINUE;
7937 }
7938
Linus Torvalds1da177e2005-04-16 15:20:36 -07007939 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
Brian King5469cb52007-03-29 12:42:40 -05007940 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007941 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7942 ipr_cmd->done = ipr_reset_ioa_job;
7943 add_timer(&ipr_cmd->timer);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06007944 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007945
7946 LEAVE;
7947 return IPR_RC_JOB_RETURN;
7948}
7949
7950/**
7951 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
7952 * @ipr_cmd: ipr command struct
7953 *
7954 * This function is invoked when an adapter dump has run out
7955 * of processing time.
7956 *
7957 * Return value:
7958 * IPR_RC_JOB_CONTINUE
7959 **/
7960static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
7961{
7962 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7963
7964 if (ioa_cfg->sdt_state == GET_DUMP)
Brian King41e9a692011-09-21 08:51:11 -05007965 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7966 else if (ioa_cfg->sdt_state == READ_DUMP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007967 ioa_cfg->sdt_state = ABORT_DUMP;
7968
Brian King4c647e92011-10-15 09:08:56 -05007969 ioa_cfg->dump_timeout = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007970 ipr_cmd->job_step = ipr_reset_alert;
7971
7972 return IPR_RC_JOB_CONTINUE;
7973}
7974
7975/**
7976 * ipr_unit_check_no_data - Log a unit check/no data error log
7977 * @ioa_cfg: ioa config struct
7978 *
7979 * Logs an error indicating the adapter unit checked, but for some
7980 * reason, we were unable to fetch the unit check buffer.
7981 *
7982 * Return value:
7983 * nothing
7984 **/
7985static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
7986{
7987 ioa_cfg->errors_logged++;
7988 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
7989}
7990
7991/**
7992 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
7993 * @ioa_cfg: ioa config struct
7994 *
7995 * Fetches the unit check buffer from the adapter by clocking the data
7996 * through the mailbox register.
7997 *
7998 * Return value:
7999 * nothing
8000 **/
8001static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
8002{
8003 unsigned long mailbox;
8004 struct ipr_hostrcb *hostrcb;
8005 struct ipr_uc_sdt sdt;
8006 int rc, length;
Brian King65f56472007-04-26 16:00:12 -05008007 u32 ioasc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008008
8009 mailbox = readl(ioa_cfg->ioa_mailbox);
8010
Wayne Boyerdcbad002010-02-19 13:24:14 -08008011 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008012 ipr_unit_check_no_data(ioa_cfg);
8013 return;
8014 }
8015
8016 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
8017 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
8018 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
8019
Wayne Boyerdcbad002010-02-19 13:24:14 -08008020 if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
8021 ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
8022 (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008023 ipr_unit_check_no_data(ioa_cfg);
8024 return;
8025 }
8026
8027 /* Find length of the first sdt entry (UC buffer) */
Wayne Boyerdcbad002010-02-19 13:24:14 -08008028 if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
8029 length = be32_to_cpu(sdt.entry[0].end_token);
8030 else
8031 length = (be32_to_cpu(sdt.entry[0].end_token) -
8032 be32_to_cpu(sdt.entry[0].start_token)) &
8033 IPR_FMT2_MBX_ADDR_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008034
8035 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
8036 struct ipr_hostrcb, queue);
8037 list_del(&hostrcb->queue);
8038 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
8039
8040 rc = ipr_get_ldump_data_section(ioa_cfg,
Wayne Boyerdcbad002010-02-19 13:24:14 -08008041 be32_to_cpu(sdt.entry[0].start_token),
Linus Torvalds1da177e2005-04-16 15:20:36 -07008042 (__be32 *)&hostrcb->hcam,
8043 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
8044
Brian King65f56472007-04-26 16:00:12 -05008045 if (!rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008046 ipr_handle_log_data(ioa_cfg, hostrcb);
Wayne Boyer4565e372010-02-19 13:24:07 -08008047 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
Brian King65f56472007-04-26 16:00:12 -05008048 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
8049 ioa_cfg->sdt_state == GET_DUMP)
8050 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8051 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07008052 ipr_unit_check_no_data(ioa_cfg);
8053
8054 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
8055}
8056
8057/**
Wayne Boyer110def82010-11-04 09:36:16 -07008058 * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
8059 * @ipr_cmd: ipr command struct
8060 *
8061 * Description: This function will call to get the unit check buffer.
8062 *
8063 * Return value:
8064 * IPR_RC_JOB_RETURN
8065 **/
8066static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
8067{
8068 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8069
8070 ENTER;
8071 ioa_cfg->ioa_unit_checked = 0;
8072 ipr_get_unit_check_buffer(ioa_cfg);
8073 ipr_cmd->job_step = ipr_reset_alert;
8074 ipr_reset_start_timer(ipr_cmd, 0);
8075
8076 LEAVE;
8077 return IPR_RC_JOB_RETURN;
8078}
8079
8080/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008081 * ipr_reset_restore_cfg_space - Restore PCI config space.
8082 * @ipr_cmd: ipr command struct
8083 *
8084 * Description: This function restores the saved PCI config space of
8085 * the adapter, fails all outstanding ops back to the callers, and
8086 * fetches the dump/unit check if applicable to this reset.
8087 *
8088 * Return value:
8089 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8090 **/
8091static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
8092{
8093 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyer630ad8312011-04-07 12:12:30 -07008094 u32 int_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008095
8096 ENTER;
Kleber Sacilotto de Souza99c965d2009-11-25 20:13:43 -02008097 ioa_cfg->pdev->state_saved = true;
Jon Mason1d3c16a2010-11-30 17:43:26 -06008098 pci_restore_state(ioa_cfg->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008099
8100 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
Wayne Boyer96d21f02010-05-10 09:13:27 -07008101 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008102 return IPR_RC_JOB_CONTINUE;
8103 }
8104
8105 ipr_fail_all_ops(ioa_cfg);
8106
Wayne Boyer8701f182010-06-04 10:26:50 -07008107 if (ioa_cfg->sis64) {
8108 /* Set the adapter to the correct endian mode. */
8109 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
8110 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
8111 }
8112
Linus Torvalds1da177e2005-04-16 15:20:36 -07008113 if (ioa_cfg->ioa_unit_checked) {
Wayne Boyer110def82010-11-04 09:36:16 -07008114 if (ioa_cfg->sis64) {
8115 ipr_cmd->job_step = ipr_reset_get_unit_check_job;
8116 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
8117 return IPR_RC_JOB_RETURN;
8118 } else {
8119 ioa_cfg->ioa_unit_checked = 0;
8120 ipr_get_unit_check_buffer(ioa_cfg);
8121 ipr_cmd->job_step = ipr_reset_alert;
8122 ipr_reset_start_timer(ipr_cmd, 0);
8123 return IPR_RC_JOB_RETURN;
8124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008125 }
8126
8127 if (ioa_cfg->in_ioa_bringdown) {
8128 ipr_cmd->job_step = ipr_ioa_bringdown_done;
8129 } else {
8130 ipr_cmd->job_step = ipr_reset_enable_ioa;
8131
8132 if (GET_DUMP == ioa_cfg->sdt_state) {
Brian King41e9a692011-09-21 08:51:11 -05008133 ioa_cfg->sdt_state = READ_DUMP;
Brian King4c647e92011-10-15 09:08:56 -05008134 ioa_cfg->dump_timeout = 0;
Kleber Sacilotto de Souza4d4dd702011-04-26 19:23:29 -03008135 if (ioa_cfg->sis64)
8136 ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
8137 else
8138 ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008139 ipr_cmd->job_step = ipr_reset_wait_for_dump;
8140 schedule_work(&ioa_cfg->work_q);
8141 return IPR_RC_JOB_RETURN;
8142 }
8143 }
8144
Wayne Boyer438b0332010-05-10 09:13:00 -07008145 LEAVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008146 return IPR_RC_JOB_CONTINUE;
8147}
8148
8149/**
Brian Kinge619e1a2007-01-23 11:25:37 -06008150 * ipr_reset_bist_done - BIST has completed on the adapter.
8151 * @ipr_cmd: ipr command struct
8152 *
8153 * Description: Unblock config space and resume the reset process.
8154 *
8155 * Return value:
8156 * IPR_RC_JOB_CONTINUE
8157 **/
8158static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
8159{
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008160 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8161
Brian Kinge619e1a2007-01-23 11:25:37 -06008162 ENTER;
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008163 if (ioa_cfg->cfg_locked)
8164 pci_cfg_access_unlock(ioa_cfg->pdev);
8165 ioa_cfg->cfg_locked = 0;
Brian Kinge619e1a2007-01-23 11:25:37 -06008166 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
8167 LEAVE;
8168 return IPR_RC_JOB_CONTINUE;
8169}
8170
8171/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008172 * ipr_reset_start_bist - Run BIST on the adapter.
8173 * @ipr_cmd: ipr command struct
8174 *
8175 * Description: This function runs BIST on the adapter, then delays 2 seconds.
8176 *
8177 * Return value:
8178 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8179 **/
8180static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
8181{
8182 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
Wayne Boyercb237ef2010-06-17 11:51:40 -07008183 int rc = PCIBIOS_SUCCESSFUL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008184
8185 ENTER;
Wayne Boyercb237ef2010-06-17 11:51:40 -07008186 if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
8187 writel(IPR_UPROCI_SIS64_START_BIST,
8188 ioa_cfg->regs.set_uproc_interrupt_reg32);
8189 else
8190 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
8191
8192 if (rc == PCIBIOS_SUCCESSFUL) {
Brian Kinge619e1a2007-01-23 11:25:37 -06008193 ipr_cmd->job_step = ipr_reset_bist_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008194 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
8195 rc = IPR_RC_JOB_RETURN;
Wayne Boyercb237ef2010-06-17 11:51:40 -07008196 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008197 if (ioa_cfg->cfg_locked)
8198 pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
8199 ioa_cfg->cfg_locked = 0;
Wayne Boyercb237ef2010-06-17 11:51:40 -07008200 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
8201 rc = IPR_RC_JOB_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008202 }
8203
8204 LEAVE;
8205 return rc;
8206}
8207
8208/**
Brian King463fc692007-05-07 17:09:05 -05008209 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
8210 * @ipr_cmd: ipr command struct
8211 *
8212 * Description: This clears PCI reset to the adapter and delays two seconds.
8213 *
8214 * Return value:
8215 * IPR_RC_JOB_RETURN
8216 **/
8217static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
8218{
8219 ENTER;
8220 pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
8221 ipr_cmd->job_step = ipr_reset_bist_done;
8222 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
8223 LEAVE;
8224 return IPR_RC_JOB_RETURN;
8225}
8226
8227/**
8228 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
8229 * @ipr_cmd: ipr command struct
8230 *
8231 * Description: This asserts PCI reset to the adapter.
8232 *
8233 * Return value:
8234 * IPR_RC_JOB_RETURN
8235 **/
8236static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
8237{
8238 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8239 struct pci_dev *pdev = ioa_cfg->pdev;
8240
8241 ENTER;
Brian King463fc692007-05-07 17:09:05 -05008242 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
8243 ipr_cmd->job_step = ipr_reset_slot_reset_done;
8244 ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
8245 LEAVE;
8246 return IPR_RC_JOB_RETURN;
8247}
8248
8249/**
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008250 * ipr_reset_block_config_access_wait - Wait for permission to block config access
8251 * @ipr_cmd: ipr command struct
8252 *
8253 * Description: This attempts to block config access to the IOA.
8254 *
8255 * Return value:
8256 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8257 **/
8258static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
8259{
8260 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8261 int rc = IPR_RC_JOB_CONTINUE;
8262
8263 if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
8264 ioa_cfg->cfg_locked = 1;
8265 ipr_cmd->job_step = ioa_cfg->reset;
8266 } else {
8267 if (ipr_cmd->u.time_left) {
8268 rc = IPR_RC_JOB_RETURN;
8269 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8270 ipr_reset_start_timer(ipr_cmd,
8271 IPR_CHECK_FOR_RESET_TIMEOUT);
8272 } else {
8273 ipr_cmd->job_step = ioa_cfg->reset;
8274 dev_err(&ioa_cfg->pdev->dev,
8275 "Timed out waiting to lock config access. Resetting anyway.\n");
8276 }
8277 }
8278
8279 return rc;
8280}
8281
8282/**
8283 * ipr_reset_block_config_access - Block config access to the IOA
8284 * @ipr_cmd: ipr command struct
8285 *
8286 * Description: This attempts to block config access to the IOA
8287 *
8288 * Return value:
8289 * IPR_RC_JOB_CONTINUE
8290 **/
8291static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
8292{
8293 ipr_cmd->ioa_cfg->cfg_locked = 0;
8294 ipr_cmd->job_step = ipr_reset_block_config_access_wait;
8295 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8296 return IPR_RC_JOB_CONTINUE;
8297}
8298
8299/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008300 * ipr_reset_allowed - Query whether or not IOA can be reset
8301 * @ioa_cfg: ioa config struct
8302 *
8303 * Return value:
8304 * 0 if reset not allowed / non-zero if reset is allowed
8305 **/
8306static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
8307{
8308 volatile u32 temp_reg;
8309
8310 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
8311 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
8312}
8313
8314/**
8315 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
8316 * @ipr_cmd: ipr command struct
8317 *
8318 * Description: This function waits for adapter permission to run BIST,
8319 * then runs BIST. If the adapter does not give permission after a
8320 * reasonable time, we will reset the adapter anyway. The impact of
8321 * resetting the adapter without warning the adapter is the risk of
8322 * losing the persistent error log on the adapter. If the adapter is
8323 * reset while it is writing to the flash on the adapter, the flash
8324 * segment will have bad ECC and be zeroed.
8325 *
8326 * Return value:
8327 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8328 **/
8329static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
8330{
8331 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8332 int rc = IPR_RC_JOB_RETURN;
8333
8334 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
8335 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8336 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8337 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008338 ipr_cmd->job_step = ipr_reset_block_config_access;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008339 rc = IPR_RC_JOB_CONTINUE;
8340 }
8341
8342 return rc;
8343}
8344
8345/**
Wayne Boyer8701f182010-06-04 10:26:50 -07008346 * ipr_reset_alert - Alert the adapter of a pending reset
Linus Torvalds1da177e2005-04-16 15:20:36 -07008347 * @ipr_cmd: ipr command struct
8348 *
8349 * Description: This function alerts the adapter that it will be reset.
8350 * If memory space is not currently enabled, proceed directly
8351 * to running BIST on the adapter. The timer must always be started
8352 * so we guarantee we do not run BIST from ipr_isr.
8353 *
8354 * Return value:
8355 * IPR_RC_JOB_RETURN
8356 **/
8357static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
8358{
8359 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8360 u16 cmd_reg;
8361 int rc;
8362
8363 ENTER;
8364 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
8365
8366 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
8367 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
Wayne Boyer214777b2010-02-19 13:24:26 -08008368 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008369 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
8370 } else {
Jan Kiszkafb51ccb2011-11-04 09:45:59 +01008371 ipr_cmd->job_step = ipr_reset_block_config_access;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008372 }
8373
8374 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8375 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8376
8377 LEAVE;
8378 return IPR_RC_JOB_RETURN;
8379}
8380
8381/**
8382 * ipr_reset_ucode_download_done - Microcode download completion
8383 * @ipr_cmd: ipr command struct
8384 *
8385 * Description: This function unmaps the microcode download buffer.
8386 *
8387 * Return value:
8388 * IPR_RC_JOB_CONTINUE
8389 **/
8390static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
8391{
8392 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8393 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8394
8395 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
8396 sglist->num_sg, DMA_TO_DEVICE);
8397
8398 ipr_cmd->job_step = ipr_reset_alert;
8399 return IPR_RC_JOB_CONTINUE;
8400}
8401
8402/**
8403 * ipr_reset_ucode_download - Download microcode to the adapter
8404 * @ipr_cmd: ipr command struct
8405 *
8406 * Description: This function checks to see if it there is microcode
8407 * to download to the adapter. If there is, a download is performed.
8408 *
8409 * Return value:
8410 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8411 **/
8412static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
8413{
8414 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8415 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8416
8417 ENTER;
8418 ipr_cmd->job_step = ipr_reset_alert;
8419
8420 if (!sglist)
8421 return IPR_RC_JOB_CONTINUE;
8422
8423 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8424 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
8425 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
8426 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
8427 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
8428 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
8429 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
8430
Wayne Boyera32c0552010-02-19 13:23:36 -08008431 if (ioa_cfg->sis64)
8432 ipr_build_ucode_ioadl64(ipr_cmd, sglist);
8433 else
8434 ipr_build_ucode_ioadl(ipr_cmd, sglist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008435 ipr_cmd->job_step = ipr_reset_ucode_download_done;
8436
8437 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
8438 IPR_WRITE_BUFFER_TIMEOUT);
8439
8440 LEAVE;
8441 return IPR_RC_JOB_RETURN;
8442}
8443
8444/**
8445 * ipr_reset_shutdown_ioa - Shutdown the adapter
8446 * @ipr_cmd: ipr command struct
8447 *
8448 * Description: This function issues an adapter shutdown of the
8449 * specified type to the specified adapter as part of the
8450 * adapter reset job.
8451 *
8452 * Return value:
8453 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8454 **/
8455static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
8456{
8457 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8458 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
8459 unsigned long timeout;
8460 int rc = IPR_RC_JOB_CONTINUE;
8461
8462 ENTER;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008463 if (shutdown_type != IPR_SHUTDOWN_NONE &&
8464 !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008465 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8466 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8467 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
8468 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
8469
Brian Kingac09c342007-04-26 16:00:16 -05008470 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
8471 timeout = IPR_SHUTDOWN_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008472 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
8473 timeout = IPR_INTERNAL_TIMEOUT;
Brian Kingac09c342007-04-26 16:00:16 -05008474 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
8475 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008476 else
Brian Kingac09c342007-04-26 16:00:16 -05008477 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008478
8479 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
8480
8481 rc = IPR_RC_JOB_RETURN;
8482 ipr_cmd->job_step = ipr_reset_ucode_download;
8483 } else
8484 ipr_cmd->job_step = ipr_reset_alert;
8485
8486 LEAVE;
8487 return rc;
8488}
8489
8490/**
8491 * ipr_reset_ioa_job - Adapter reset job
8492 * @ipr_cmd: ipr command struct
8493 *
8494 * Description: This function is the job router for the adapter reset job.
8495 *
8496 * Return value:
8497 * none
8498 **/
8499static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
8500{
8501 u32 rc, ioasc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008502 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8503
8504 do {
Wayne Boyer96d21f02010-05-10 09:13:27 -07008505 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008506
8507 if (ioa_cfg->reset_cmd != ipr_cmd) {
8508 /*
8509 * We are doing nested adapter resets and this is
8510 * not the current reset job.
8511 */
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008512 list_add_tail(&ipr_cmd->queue,
8513 &ipr_cmd->hrrq->hrrq_free_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008514 return;
8515 }
8516
8517 if (IPR_IOASC_SENSE_KEY(ioasc)) {
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06008518 rc = ipr_cmd->job_step_failed(ipr_cmd);
8519 if (rc == IPR_RC_JOB_RETURN)
8520 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008521 }
8522
8523 ipr_reinit_ipr_cmnd(ipr_cmd);
brking@us.ibm.comdfed8232005-11-01 17:02:55 -06008524 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008525 rc = ipr_cmd->job_step(ipr_cmd);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03008526 } while (rc == IPR_RC_JOB_CONTINUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008527}
8528
8529/**
8530 * _ipr_initiate_ioa_reset - Initiate an adapter reset
8531 * @ioa_cfg: ioa config struct
8532 * @job_step: first job step of reset job
8533 * @shutdown_type: shutdown type
8534 *
8535 * Description: This function will initiate the reset of the given adapter
8536 * starting at the selected job step.
8537 * If the caller needs to wait on the completion of the reset,
8538 * the caller must sleep on the reset_wait_q.
8539 *
8540 * Return value:
8541 * none
8542 **/
8543static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8544 int (*job_step) (struct ipr_cmnd *),
8545 enum ipr_shutdown_type shutdown_type)
8546{
8547 struct ipr_cmnd *ipr_cmd;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008548 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008549
8550 ioa_cfg->in_reset_reload = 1;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008551 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8552 spin_lock(&ioa_cfg->hrrq[i]._lock);
8553 ioa_cfg->hrrq[i].allow_cmds = 0;
8554 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8555 }
8556 wmb();
Brian Kingbfae7822013-01-30 23:45:08 -06008557 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa)
8558 scsi_block_requests(ioa_cfg->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008559
8560 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
8561 ioa_cfg->reset_cmd = ipr_cmd;
8562 ipr_cmd->job_step = job_step;
8563 ipr_cmd->u.shutdown_type = shutdown_type;
8564
8565 ipr_reset_ioa_job(ipr_cmd);
8566}
8567
8568/**
8569 * ipr_initiate_ioa_reset - Initiate an adapter reset
8570 * @ioa_cfg: ioa config struct
8571 * @shutdown_type: shutdown type
8572 *
8573 * Description: This function will initiate the reset of the given adapter.
8574 * If the caller needs to wait on the completion of the reset,
8575 * the caller must sleep on the reset_wait_q.
8576 *
8577 * Return value:
8578 * none
8579 **/
8580static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8581 enum ipr_shutdown_type shutdown_type)
8582{
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008583 int i;
8584
8585 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008586 return;
8587
Brian King41e9a692011-09-21 08:51:11 -05008588 if (ioa_cfg->in_reset_reload) {
8589 if (ioa_cfg->sdt_state == GET_DUMP)
8590 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8591 else if (ioa_cfg->sdt_state == READ_DUMP)
8592 ioa_cfg->sdt_state = ABORT_DUMP;
8593 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008594
8595 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
8596 dev_err(&ioa_cfg->pdev->dev,
8597 "IOA taken offline - error recovery failed\n");
8598
8599 ioa_cfg->reset_retries = 0;
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008600 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8601 spin_lock(&ioa_cfg->hrrq[i]._lock);
8602 ioa_cfg->hrrq[i].ioa_is_dead = 1;
8603 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8604 }
8605 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07008606
8607 if (ioa_cfg->in_ioa_bringdown) {
8608 ioa_cfg->reset_cmd = NULL;
8609 ioa_cfg->in_reset_reload = 0;
8610 ipr_fail_all_ops(ioa_cfg);
8611 wake_up_all(&ioa_cfg->reset_wait_q);
8612
Brian Kingbfae7822013-01-30 23:45:08 -06008613 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
8614 spin_unlock_irq(ioa_cfg->host->host_lock);
8615 scsi_unblock_requests(ioa_cfg->host);
8616 spin_lock_irq(ioa_cfg->host->host_lock);
8617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07008618 return;
8619 } else {
8620 ioa_cfg->in_ioa_bringdown = 1;
8621 shutdown_type = IPR_SHUTDOWN_NONE;
8622 }
8623 }
8624
8625 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
8626 shutdown_type);
8627}
8628
8629/**
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008630 * ipr_reset_freeze - Hold off all I/O activity
8631 * @ipr_cmd: ipr command struct
8632 *
8633 * Description: If the PCI slot is frozen, hold off all I/O
8634 * activity; then, as soon as the slot is available again,
8635 * initiate an adapter reset.
8636 */
8637static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
8638{
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008639 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8640 int i;
8641
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008642 /* Disallow new interrupts, avoid loop */
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008643 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8644 spin_lock(&ioa_cfg->hrrq[i]._lock);
8645 ioa_cfg->hrrq[i].allow_interrupts = 0;
8646 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8647 }
8648 wmb();
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008649 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008650 ipr_cmd->done = ipr_reset_ioa_job;
8651 return IPR_RC_JOB_RETURN;
8652}
8653
8654/**
Brian King6270e592014-01-21 12:16:41 -06008655 * ipr_pci_mmio_enabled - Called when MMIO has been re-enabled
8656 * @pdev: PCI device struct
8657 *
8658 * Description: This routine is called to tell us that the MMIO
8659 * access to the IOA has been restored
8660 */
8661static pci_ers_result_t ipr_pci_mmio_enabled(struct pci_dev *pdev)
8662{
8663 unsigned long flags = 0;
8664 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8665
8666 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8667 if (!ioa_cfg->probe_done)
8668 pci_save_state(pdev);
8669 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8670 return PCI_ERS_RESULT_NEED_RESET;
8671}
8672
8673/**
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008674 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
8675 * @pdev: PCI device struct
8676 *
8677 * Description: This routine is called to tell us that the PCI bus
8678 * is down. Can't do anything here, except put the device driver
8679 * into a holding pattern, waiting for the PCI bus to come back.
8680 */
8681static void ipr_pci_frozen(struct pci_dev *pdev)
8682{
8683 unsigned long flags = 0;
8684 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8685
8686 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Brian King6270e592014-01-21 12:16:41 -06008687 if (ioa_cfg->probe_done)
8688 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008689 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8690}
8691
8692/**
8693 * ipr_pci_slot_reset - Called when PCI slot has been reset.
8694 * @pdev: PCI device struct
8695 *
8696 * Description: This routine is called by the pci error recovery
8697 * code after the PCI slot has been reset, just before we
8698 * should resume normal operations.
8699 */
8700static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
8701{
8702 unsigned long flags = 0;
8703 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8704
8705 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Brian King6270e592014-01-21 12:16:41 -06008706 if (ioa_cfg->probe_done) {
8707 if (ioa_cfg->needs_warm_reset)
8708 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8709 else
8710 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
8711 IPR_SHUTDOWN_NONE);
8712 } else
8713 wake_up_all(&ioa_cfg->eeh_wait_q);
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008714 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8715 return PCI_ERS_RESULT_RECOVERED;
8716}
8717
8718/**
8719 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
8720 * @pdev: PCI device struct
8721 *
8722 * Description: This routine is called when the PCI bus has
8723 * permanently failed.
8724 */
8725static void ipr_pci_perm_failure(struct pci_dev *pdev)
8726{
8727 unsigned long flags = 0;
8728 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008729 int i;
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008730
8731 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
Brian King6270e592014-01-21 12:16:41 -06008732 if (ioa_cfg->probe_done) {
8733 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
8734 ioa_cfg->sdt_state = ABORT_DUMP;
8735 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES - 1;
8736 ioa_cfg->in_ioa_bringdown = 1;
8737 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8738 spin_lock(&ioa_cfg->hrrq[i]._lock);
8739 ioa_cfg->hrrq[i].allow_cmds = 0;
8740 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8741 }
8742 wmb();
8743 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8744 } else
8745 wake_up_all(&ioa_cfg->eeh_wait_q);
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008746 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8747}
8748
8749/**
8750 * ipr_pci_error_detected - Called when a PCI error is detected.
8751 * @pdev: PCI device struct
8752 * @state: PCI channel state
8753 *
8754 * Description: Called when a PCI error is detected.
8755 *
8756 * Return value:
8757 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8758 */
8759static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
8760 pci_channel_state_t state)
8761{
8762 switch (state) {
8763 case pci_channel_io_frozen:
8764 ipr_pci_frozen(pdev);
Brian King6270e592014-01-21 12:16:41 -06008765 return PCI_ERS_RESULT_CAN_RECOVER;
Linas Vepstasf8a88b192006-02-03 16:52:42 -06008766 case pci_channel_io_perm_failure:
8767 ipr_pci_perm_failure(pdev);
8768 return PCI_ERS_RESULT_DISCONNECT;
8769 break;
8770 default:
8771 break;
8772 }
8773 return PCI_ERS_RESULT_NEED_RESET;
8774}
8775
8776/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07008777 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
8778 * @ioa_cfg: ioa cfg struct
8779 *
8780 * Description: This is the second phase of adapter intialization
8781 * This function takes care of initilizing the adapter to the point
8782 * where it can accept new commands.
8783
8784 * Return value:
Joe Perchesb1c11812008-02-03 17:28:22 +02008785 * 0 on success / -EIO on failure
Linus Torvalds1da177e2005-04-16 15:20:36 -07008786 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008787static int ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008788{
8789 int rc = 0;
8790 unsigned long host_lock_flags = 0;
8791
8792 ENTER;
8793 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8794 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
Brian King6270e592014-01-21 12:16:41 -06008795 ioa_cfg->probe_done = 1;
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06008796 if (ioa_cfg->needs_hard_reset) {
8797 ioa_cfg->needs_hard_reset = 0;
8798 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8799 } else
8800 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
8801 IPR_SHUTDOWN_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008802 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8803 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
8804 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8805
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008806 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07008807 rc = -EIO;
8808 } else if (ipr_invalid_adapter(ioa_cfg)) {
8809 if (!ipr_testmode)
8810 rc = -EIO;
8811
8812 dev_err(&ioa_cfg->pdev->dev,
8813 "Adapter not supported in this hardware configuration.\n");
8814 }
8815
8816 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8817
8818 LEAVE;
8819 return rc;
8820}
8821
8822/**
8823 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
8824 * @ioa_cfg: ioa config struct
8825 *
8826 * Return value:
8827 * none
8828 **/
8829static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8830{
8831 int i;
8832
8833 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8834 if (ioa_cfg->ipr_cmnd_list[i])
8835 pci_pool_free(ioa_cfg->ipr_cmd_pool,
8836 ioa_cfg->ipr_cmnd_list[i],
8837 ioa_cfg->ipr_cmnd_list_dma[i]);
8838
8839 ioa_cfg->ipr_cmnd_list[i] = NULL;
8840 }
8841
8842 if (ioa_cfg->ipr_cmd_pool)
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03008843 pci_pool_destroy(ioa_cfg->ipr_cmd_pool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008844
Brian King89aad422012-03-14 21:20:10 -05008845 kfree(ioa_cfg->ipr_cmnd_list);
8846 kfree(ioa_cfg->ipr_cmnd_list_dma);
8847 ioa_cfg->ipr_cmnd_list = NULL;
8848 ioa_cfg->ipr_cmnd_list_dma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008849 ioa_cfg->ipr_cmd_pool = NULL;
8850}
8851
8852/**
8853 * ipr_free_mem - Frees memory allocated for an adapter
8854 * @ioa_cfg: ioa cfg struct
8855 *
8856 * Return value:
8857 * nothing
8858 **/
8859static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
8860{
8861 int i;
8862
8863 kfree(ioa_cfg->res_entries);
8864 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
8865 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8866 ipr_free_cmd_blks(ioa_cfg);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008867
8868 for (i = 0; i < ioa_cfg->hrrq_num; i++)
8869 pci_free_consistent(ioa_cfg->pdev,
8870 sizeof(u32) * ioa_cfg->hrrq[i].size,
8871 ioa_cfg->hrrq[i].host_rrq,
8872 ioa_cfg->hrrq[i].host_rrq_dma);
8873
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08008874 pci_free_consistent(ioa_cfg->pdev, ioa_cfg->cfg_table_size,
8875 ioa_cfg->u.cfg_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008876 ioa_cfg->cfg_table_dma);
8877
8878 for (i = 0; i < IPR_NUM_HCAMS; i++) {
8879 pci_free_consistent(ioa_cfg->pdev,
8880 sizeof(struct ipr_hostrcb),
8881 ioa_cfg->hostrcb[i],
8882 ioa_cfg->hostrcb_dma[i]);
8883 }
8884
8885 ipr_free_dump(ioa_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008886 kfree(ioa_cfg->trace);
8887}
8888
8889/**
8890 * ipr_free_all_resources - Free all allocated resources for an adapter.
8891 * @ipr_cmd: ipr command struct
8892 *
8893 * This function frees all allocated resources for the
8894 * specified adapter.
8895 *
8896 * Return value:
8897 * none
8898 **/
8899static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
8900{
8901 struct pci_dev *pdev = ioa_cfg->pdev;
8902
8903 ENTER;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008904 if (ioa_cfg->intr_flag == IPR_USE_MSI ||
8905 ioa_cfg->intr_flag == IPR_USE_MSIX) {
8906 int i;
8907 for (i = 0; i < ioa_cfg->nvectors; i++)
8908 free_irq(ioa_cfg->vectors_info[i].vec,
8909 &ioa_cfg->hrrq[i]);
8910 } else
8911 free_irq(pdev->irq, &ioa_cfg->hrrq[0]);
8912
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008913 if (ioa_cfg->intr_flag == IPR_USE_MSI) {
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008914 pci_disable_msi(pdev);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008915 ioa_cfg->intr_flag &= ~IPR_USE_MSI;
8916 } else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008917 pci_disable_msix(pdev);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06008918 ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
8919 }
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008920
Linus Torvalds1da177e2005-04-16 15:20:36 -07008921 iounmap(ioa_cfg->hdw_dma_regs);
8922 pci_release_regions(pdev);
8923 ipr_free_mem(ioa_cfg);
8924 scsi_host_put(ioa_cfg->host);
8925 pci_disable_device(pdev);
8926 LEAVE;
8927}
8928
8929/**
8930 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
8931 * @ioa_cfg: ioa config struct
8932 *
8933 * Return value:
8934 * 0 on success / -ENOMEM on allocation failure
8935 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08008936static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008937{
8938 struct ipr_cmnd *ipr_cmd;
8939 struct ipr_ioarcb *ioarcb;
8940 dma_addr_t dma_addr;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008941 int i, entries_each_hrrq, hrrq_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07008942
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03008943 ioa_cfg->ipr_cmd_pool = pci_pool_create(IPR_NAME, ioa_cfg->pdev,
8944 sizeof(struct ipr_cmnd), 512, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008945
8946 if (!ioa_cfg->ipr_cmd_pool)
8947 return -ENOMEM;
8948
Brian King89aad422012-03-14 21:20:10 -05008949 ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
8950 ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
8951
8952 if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
8953 ipr_free_cmd_blks(ioa_cfg);
8954 return -ENOMEM;
8955 }
8956
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06008957 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8958 if (ioa_cfg->hrrq_num > 1) {
8959 if (i == 0) {
8960 entries_each_hrrq = IPR_NUM_INTERNAL_CMD_BLKS;
8961 ioa_cfg->hrrq[i].min_cmd_id = 0;
8962 ioa_cfg->hrrq[i].max_cmd_id =
8963 (entries_each_hrrq - 1);
8964 } else {
8965 entries_each_hrrq =
8966 IPR_NUM_BASE_CMD_BLKS/
8967 (ioa_cfg->hrrq_num - 1);
8968 ioa_cfg->hrrq[i].min_cmd_id =
8969 IPR_NUM_INTERNAL_CMD_BLKS +
8970 (i - 1) * entries_each_hrrq;
8971 ioa_cfg->hrrq[i].max_cmd_id =
8972 (IPR_NUM_INTERNAL_CMD_BLKS +
8973 i * entries_each_hrrq - 1);
8974 }
8975 } else {
8976 entries_each_hrrq = IPR_NUM_CMD_BLKS;
8977 ioa_cfg->hrrq[i].min_cmd_id = 0;
8978 ioa_cfg->hrrq[i].max_cmd_id = (entries_each_hrrq - 1);
8979 }
8980 ioa_cfg->hrrq[i].size = entries_each_hrrq;
8981 }
8982
8983 BUG_ON(ioa_cfg->hrrq_num == 0);
8984
8985 i = IPR_NUM_CMD_BLKS -
8986 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id - 1;
8987 if (i > 0) {
8988 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].size += i;
8989 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id += i;
8990 }
8991
Linus Torvalds1da177e2005-04-16 15:20:36 -07008992 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03008993 ipr_cmd = pci_pool_alloc(ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07008994
8995 if (!ipr_cmd) {
8996 ipr_free_cmd_blks(ioa_cfg);
8997 return -ENOMEM;
8998 }
8999
9000 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
9001 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
9002 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
9003
9004 ioarcb = &ipr_cmd->ioarcb;
Wayne Boyera32c0552010-02-19 13:23:36 -08009005 ipr_cmd->dma_addr = dma_addr;
9006 if (ioa_cfg->sis64)
9007 ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
9008 else
9009 ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
9010
Linus Torvalds1da177e2005-04-16 15:20:36 -07009011 ioarcb->host_response_handle = cpu_to_be32(i << 2);
Wayne Boyera32c0552010-02-19 13:23:36 -08009012 if (ioa_cfg->sis64) {
9013 ioarcb->u.sis64_addr_data.data_ioadl_addr =
9014 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
9015 ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
Wayne Boyer96d21f02010-05-10 09:13:27 -07009016 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
Wayne Boyera32c0552010-02-19 13:23:36 -08009017 } else {
9018 ioarcb->write_ioadl_addr =
9019 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
9020 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
9021 ioarcb->ioasa_host_pci_addr =
Wayne Boyer96d21f02010-05-10 09:13:27 -07009022 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
Wayne Boyera32c0552010-02-19 13:23:36 -08009023 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009024 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
9025 ipr_cmd->cmd_index = i;
9026 ipr_cmd->ioa_cfg = ioa_cfg;
9027 ipr_cmd->sense_buffer_dma = dma_addr +
9028 offsetof(struct ipr_cmnd, sense_buffer);
9029
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009030 ipr_cmd->ioarcb.cmd_pkt.hrrq_id = hrrq_id;
9031 ipr_cmd->hrrq = &ioa_cfg->hrrq[hrrq_id];
9032 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
9033 if (i >= ioa_cfg->hrrq[hrrq_id].max_cmd_id)
9034 hrrq_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009035 }
9036
9037 return 0;
9038}
9039
9040/**
9041 * ipr_alloc_mem - Allocate memory for an adapter
9042 * @ioa_cfg: ioa config struct
9043 *
9044 * Return value:
9045 * 0 on success / non-zero for error
9046 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009047static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009048{
9049 struct pci_dev *pdev = ioa_cfg->pdev;
9050 int i, rc = -ENOMEM;
9051
9052 ENTER;
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06009053 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08009054 ioa_cfg->max_devs_supported, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009055
9056 if (!ioa_cfg->res_entries)
9057 goto out;
9058
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08009059 for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07009060 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08009061 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
9062 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009063
9064 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
9065 sizeof(struct ipr_misc_cbs),
9066 &ioa_cfg->vpd_cbs_dma);
9067
9068 if (!ioa_cfg->vpd_cbs)
9069 goto out_free_res_entries;
9070
9071 if (ipr_alloc_cmd_blks(ioa_cfg))
9072 goto out_free_vpd_cbs;
9073
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009074 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9075 ioa_cfg->hrrq[i].host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
9076 sizeof(u32) * ioa_cfg->hrrq[i].size,
9077 &ioa_cfg->hrrq[i].host_rrq_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009078
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009079 if (!ioa_cfg->hrrq[i].host_rrq) {
9080 while (--i > 0)
9081 pci_free_consistent(pdev,
9082 sizeof(u32) * ioa_cfg->hrrq[i].size,
9083 ioa_cfg->hrrq[i].host_rrq,
9084 ioa_cfg->hrrq[i].host_rrq_dma);
9085 goto out_ipr_free_cmd_blocks;
9086 }
9087 ioa_cfg->hrrq[i].ioa_cfg = ioa_cfg;
9088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009089
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08009090 ioa_cfg->u.cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
9091 ioa_cfg->cfg_table_size,
9092 &ioa_cfg->cfg_table_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009093
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08009094 if (!ioa_cfg->u.cfg_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009095 goto out_free_host_rrq;
9096
9097 for (i = 0; i < IPR_NUM_HCAMS; i++) {
9098 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
9099 sizeof(struct ipr_hostrcb),
9100 &ioa_cfg->hostrcb_dma[i]);
9101
9102 if (!ioa_cfg->hostrcb[i])
9103 goto out_free_hostrcb_dma;
9104
9105 ioa_cfg->hostrcb[i]->hostrcb_dma =
9106 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
Brian King49dc6a12006-11-21 10:28:35 -06009107 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009108 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
9109 }
9110
brking@us.ibm.com0bc42e32005-11-01 17:01:20 -06009111 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009112 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
9113
9114 if (!ioa_cfg->trace)
9115 goto out_free_hostrcb_dma;
9116
Linus Torvalds1da177e2005-04-16 15:20:36 -07009117 rc = 0;
9118out:
9119 LEAVE;
9120 return rc;
9121
9122out_free_hostrcb_dma:
9123 while (i-- > 0) {
9124 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
9125 ioa_cfg->hostrcb[i],
9126 ioa_cfg->hostrcb_dma[i]);
9127 }
Wayne Boyer3e7ebdf2010-02-19 13:23:59 -08009128 pci_free_consistent(pdev, ioa_cfg->cfg_table_size,
9129 ioa_cfg->u.cfg_table,
9130 ioa_cfg->cfg_table_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009131out_free_host_rrq:
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009132 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9133 pci_free_consistent(pdev,
9134 sizeof(u32) * ioa_cfg->hrrq[i].size,
9135 ioa_cfg->hrrq[i].host_rrq,
9136 ioa_cfg->hrrq[i].host_rrq_dma);
9137 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009138out_ipr_free_cmd_blocks:
9139 ipr_free_cmd_blks(ioa_cfg);
9140out_free_vpd_cbs:
9141 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
9142 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
9143out_free_res_entries:
9144 kfree(ioa_cfg->res_entries);
9145 goto out;
9146}
9147
9148/**
9149 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
9150 * @ioa_cfg: ioa config struct
9151 *
9152 * Return value:
9153 * none
9154 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009155static void ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009156{
9157 int i;
9158
9159 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
9160 ioa_cfg->bus_attr[i].bus = i;
9161 ioa_cfg->bus_attr[i].qas_enabled = 0;
9162 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
9163 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
9164 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
9165 else
9166 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
9167 }
9168}
9169
9170/**
Brian King6270e592014-01-21 12:16:41 -06009171 * ipr_init_regs - Initialize IOA registers
Linus Torvalds1da177e2005-04-16 15:20:36 -07009172 * @ioa_cfg: ioa config struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07009173 *
9174 * Return value:
Brian King6270e592014-01-21 12:16:41 -06009175 * none
Linus Torvalds1da177e2005-04-16 15:20:36 -07009176 **/
Brian King6270e592014-01-21 12:16:41 -06009177static void ipr_init_regs(struct ipr_ioa_cfg *ioa_cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009178{
9179 const struct ipr_interrupt_offsets *p;
9180 struct ipr_interrupts *t;
9181 void __iomem *base;
9182
Linus Torvalds1da177e2005-04-16 15:20:36 -07009183 p = &ioa_cfg->chip_cfg->regs;
9184 t = &ioa_cfg->regs;
9185 base = ioa_cfg->hdw_dma_regs;
9186
9187 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
9188 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009189 t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009190 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009191 t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009192 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009193 t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009194 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009195 t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009196 t->ioarrin_reg = base + p->ioarrin_reg;
9197 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009198 t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009199 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009200 t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009201 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
Wayne Boyer214777b2010-02-19 13:24:26 -08009202 t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
Wayne Boyerdcbad002010-02-19 13:24:14 -08009203
9204 if (ioa_cfg->sis64) {
Wayne Boyer214777b2010-02-19 13:24:26 -08009205 t->init_feedback_reg = base + p->init_feedback_reg;
Wayne Boyerdcbad002010-02-19 13:24:14 -08009206 t->dump_addr_reg = base + p->dump_addr_reg;
9207 t->dump_data_reg = base + p->dump_data_reg;
Wayne Boyer8701f182010-06-04 10:26:50 -07009208 t->endian_swap_reg = base + p->endian_swap_reg;
Wayne Boyerdcbad002010-02-19 13:24:14 -08009209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009210}
9211
9212/**
Brian King6270e592014-01-21 12:16:41 -06009213 * ipr_init_ioa_cfg - Initialize IOA config struct
9214 * @ioa_cfg: ioa config struct
9215 * @host: scsi host struct
9216 * @pdev: PCI dev struct
9217 *
9218 * Return value:
9219 * none
9220 **/
9221static void ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
9222 struct Scsi_Host *host, struct pci_dev *pdev)
9223{
9224 int i;
9225
9226 ioa_cfg->host = host;
9227 ioa_cfg->pdev = pdev;
9228 ioa_cfg->log_level = ipr_log_level;
9229 ioa_cfg->doorbell = IPR_DOORBELL;
9230 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
9231 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
9232 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
9233 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
9234 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
9235 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
9236
9237 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
9238 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
9239 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
9240 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
9241 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
9242 init_waitqueue_head(&ioa_cfg->reset_wait_q);
9243 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9244 init_waitqueue_head(&ioa_cfg->eeh_wait_q);
9245 ioa_cfg->sdt_state = INACTIVE;
9246
9247 ipr_initialize_bus_attr(ioa_cfg);
9248 ioa_cfg->max_devs_supported = ipr_max_devs;
9249
9250 if (ioa_cfg->sis64) {
9251 host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
9252 host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
9253 if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
9254 ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
9255 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
9256 + ((sizeof(struct ipr_config_table_entry64)
9257 * ioa_cfg->max_devs_supported)));
9258 } else {
9259 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
9260 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
9261 if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
9262 ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
9263 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
9264 + ((sizeof(struct ipr_config_table_entry)
9265 * ioa_cfg->max_devs_supported)));
9266 }
9267
9268 host->max_channel = IPR_MAX_BUS_TO_SCAN;
9269 host->unique_id = host->host_no;
9270 host->max_cmd_len = IPR_MAX_CDB_LEN;
9271 host->can_queue = ioa_cfg->max_cmds;
9272 pci_set_drvdata(pdev, ioa_cfg);
9273
9274 for (i = 0; i < ARRAY_SIZE(ioa_cfg->hrrq); i++) {
9275 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_free_q);
9276 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_pending_q);
9277 spin_lock_init(&ioa_cfg->hrrq[i]._lock);
9278 if (i == 0)
9279 ioa_cfg->hrrq[i].lock = ioa_cfg->host->host_lock;
9280 else
9281 ioa_cfg->hrrq[i].lock = &ioa_cfg->hrrq[i]._lock;
9282 }
9283}
9284
9285/**
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009286 * ipr_get_chip_info - Find adapter chip information
Linus Torvalds1da177e2005-04-16 15:20:36 -07009287 * @dev_id: PCI device id struct
9288 *
9289 * Return value:
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009290 * ptr to chip information on success / NULL on failure
Linus Torvalds1da177e2005-04-16 15:20:36 -07009291 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009292static const struct ipr_chip_t *
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009293ipr_get_chip_info(const struct pci_device_id *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009294{
9295 int i;
9296
Linus Torvalds1da177e2005-04-16 15:20:36 -07009297 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
9298 if (ipr_chip[i].vendor == dev_id->vendor &&
9299 ipr_chip[i].device == dev_id->device)
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009300 return &ipr_chip[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07009301 return NULL;
9302}
9303
Brian King6270e592014-01-21 12:16:41 -06009304/**
9305 * ipr_wait_for_pci_err_recovery - Wait for any PCI error recovery to complete
9306 * during probe time
9307 * @ioa_cfg: ioa config struct
9308 *
9309 * Return value:
9310 * None
9311 **/
9312static void ipr_wait_for_pci_err_recovery(struct ipr_ioa_cfg *ioa_cfg)
9313{
9314 struct pci_dev *pdev = ioa_cfg->pdev;
9315
9316 if (pci_channel_offline(pdev)) {
9317 wait_event_timeout(ioa_cfg->eeh_wait_q,
9318 !pci_channel_offline(pdev),
9319 IPR_PCI_ERROR_RECOVERY_TIMEOUT);
9320 pci_restore_state(pdev);
9321 }
9322}
9323
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009324static int ipr_enable_msix(struct ipr_ioa_cfg *ioa_cfg)
9325{
9326 struct msix_entry entries[IPR_MAX_MSIX_VECTORS];
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009327 int i, vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009328
9329 for (i = 0; i < ARRAY_SIZE(entries); ++i)
9330 entries[i].entry = i;
9331
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009332 vectors = pci_enable_msix_range(ioa_cfg->pdev,
9333 entries, 1, ipr_number_of_msix);
9334 if (vectors < 0) {
Brian King6270e592014-01-21 12:16:41 -06009335 ipr_wait_for_pci_err_recovery(ioa_cfg);
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009336 return vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009337 }
9338
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009339 for (i = 0; i < vectors; i++)
9340 ioa_cfg->vectors_info[i].vec = entries[i].vector;
9341 ioa_cfg->nvectors = vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009342
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009343 return 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009344}
9345
9346static int ipr_enable_msi(struct ipr_ioa_cfg *ioa_cfg)
9347{
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009348 int i, vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009349
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009350 vectors = pci_enable_msi_range(ioa_cfg->pdev, 1, ipr_number_of_msix);
9351 if (vectors < 0) {
Brian King6270e592014-01-21 12:16:41 -06009352 ipr_wait_for_pci_err_recovery(ioa_cfg);
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009353 return vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009354 }
9355
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009356 for (i = 0; i < vectors; i++)
9357 ioa_cfg->vectors_info[i].vec = ioa_cfg->pdev->irq + i;
9358 ioa_cfg->nvectors = vectors;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009359
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009360 return 0;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009361}
9362
9363static void name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
9364{
9365 int vec_idx, n = sizeof(ioa_cfg->vectors_info[0].desc) - 1;
9366
9367 for (vec_idx = 0; vec_idx < ioa_cfg->nvectors; vec_idx++) {
9368 snprintf(ioa_cfg->vectors_info[vec_idx].desc, n,
9369 "host%d-%d", ioa_cfg->host->host_no, vec_idx);
9370 ioa_cfg->vectors_info[vec_idx].
9371 desc[strlen(ioa_cfg->vectors_info[vec_idx].desc)] = 0;
9372 }
9373}
9374
9375static int ipr_request_other_msi_irqs(struct ipr_ioa_cfg *ioa_cfg)
9376{
9377 int i, rc;
9378
9379 for (i = 1; i < ioa_cfg->nvectors; i++) {
9380 rc = request_irq(ioa_cfg->vectors_info[i].vec,
9381 ipr_isr_mhrrq,
9382 0,
9383 ioa_cfg->vectors_info[i].desc,
9384 &ioa_cfg->hrrq[i]);
9385 if (rc) {
9386 while (--i >= 0)
9387 free_irq(ioa_cfg->vectors_info[i].vec,
9388 &ioa_cfg->hrrq[i]);
9389 return rc;
9390 }
9391 }
9392 return 0;
9393}
9394
Linus Torvalds1da177e2005-04-16 15:20:36 -07009395/**
Wayne Boyer95fecd92009-06-16 15:13:28 -07009396 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
9397 * @pdev: PCI device struct
9398 *
9399 * Description: Simply set the msi_received flag to 1 indicating that
9400 * Message Signaled Interrupts are supported.
9401 *
9402 * Return value:
9403 * 0 on success / non-zero on failure
9404 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009405static irqreturn_t ipr_test_intr(int irq, void *devp)
Wayne Boyer95fecd92009-06-16 15:13:28 -07009406{
9407 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
9408 unsigned long lock_flags = 0;
9409 irqreturn_t rc = IRQ_HANDLED;
9410
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009411 dev_info(&ioa_cfg->pdev->dev, "Received IRQ : %d\n", irq);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009412 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9413
9414 ioa_cfg->msi_received = 1;
9415 wake_up(&ioa_cfg->msi_wait_q);
9416
9417 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9418 return rc;
9419}
9420
9421/**
9422 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
9423 * @pdev: PCI device struct
9424 *
Alexander Gordeev60e76b72014-03-12 16:08:50 -05009425 * Description: The return value from pci_enable_msi_range() can not always be
Wayne Boyer95fecd92009-06-16 15:13:28 -07009426 * trusted. This routine sets up and initiates a test interrupt to determine
9427 * if the interrupt is received via the ipr_test_intr() service routine.
9428 * If the tests fails, the driver will fall back to LSI.
9429 *
9430 * Return value:
9431 * 0 on success / non-zero on failure
9432 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009433static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
Wayne Boyer95fecd92009-06-16 15:13:28 -07009434{
9435 int rc;
9436 volatile u32 int_reg;
9437 unsigned long lock_flags = 0;
9438
9439 ENTER;
9440
9441 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9442 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9443 ioa_cfg->msi_received = 0;
9444 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
Wayne Boyer214777b2010-02-19 13:24:26 -08009445 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009446 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
9447 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9448
wenxiong@linux.vnet.ibm.comf19799f2013-02-27 12:37:45 -06009449 if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9450 rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
9451 else
9452 rc = request_irq(pdev->irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009453 if (rc) {
9454 dev_err(&pdev->dev, "Can not assign irq %d\n", pdev->irq);
9455 return rc;
9456 } else if (ipr_debug)
9457 dev_info(&pdev->dev, "IRQ assigned: %d\n", pdev->irq);
9458
Wayne Boyer214777b2010-02-19 13:24:26 -08009459 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009460 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
9461 wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009462 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009463 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9464
Wayne Boyer95fecd92009-06-16 15:13:28 -07009465 if (!ioa_cfg->msi_received) {
9466 /* MSI test failed */
9467 dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
9468 rc = -EOPNOTSUPP;
9469 } else if (ipr_debug)
9470 dev_info(&pdev->dev, "MSI test succeeded.\n");
9471
9472 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9473
wenxiong@linux.vnet.ibm.comf19799f2013-02-27 12:37:45 -06009474 if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9475 free_irq(ioa_cfg->vectors_info[0].vec, ioa_cfg);
9476 else
9477 free_irq(pdev->irq, ioa_cfg);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009478
9479 LEAVE;
9480
9481 return rc;
9482}
9483
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009484 /* ipr_probe_ioa - Allocates memory and does first stage of initialization
Linus Torvalds1da177e2005-04-16 15:20:36 -07009485 * @pdev: PCI device struct
9486 * @dev_id: PCI device id struct
9487 *
9488 * Return value:
9489 * 0 on success / non-zero on failure
9490 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009491static int ipr_probe_ioa(struct pci_dev *pdev,
9492 const struct pci_device_id *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009493{
9494 struct ipr_ioa_cfg *ioa_cfg;
9495 struct Scsi_Host *host;
9496 unsigned long ipr_regs_pci;
9497 void __iomem *ipr_regs;
Eric Sesterhenna2a65a32006-09-25 16:59:07 -07009498 int rc = PCIBIOS_SUCCESSFUL;
Brian King473b1e82007-05-02 10:44:11 -05009499 volatile u32 mask, uproc, interrupts;
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009500 unsigned long lock_flags, driver_lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009501
9502 ENTER;
9503
Linus Torvalds1da177e2005-04-16 15:20:36 -07009504 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009505 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
9506
9507 if (!host) {
9508 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
9509 rc = -ENOMEM;
Brian King6270e592014-01-21 12:16:41 -06009510 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009511 }
9512
9513 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
9514 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
Dan Williams8d8e7d12012-07-09 21:06:08 -07009515 ata_host_init(&ioa_cfg->ata_host, &pdev->dev, &ipr_sata_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009516
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009517 ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009518
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009519 if (!ioa_cfg->ipr_chip) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07009520 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
9521 dev_id->vendor, dev_id->device);
9522 goto out_scsi_host_put;
9523 }
9524
Wayne Boyera32c0552010-02-19 13:23:36 -08009525 /* set SIS 32 or SIS 64 */
9526 ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009527 ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
Brian King7dd21302012-03-14 21:20:08 -05009528 ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
Brian King89aad422012-03-14 21:20:10 -05009529 ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
Wayne Boyer1be7bd82009-06-17 09:55:35 -07009530
Brian King5469cb52007-03-29 12:42:40 -05009531 if (ipr_transop_timeout)
9532 ioa_cfg->transop_timeout = ipr_transop_timeout;
9533 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
9534 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
9535 else
9536 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
9537
Auke Kok44c10132007-06-08 15:46:36 -07009538 ioa_cfg->revid = pdev->revision;
Brian King463fc692007-05-07 17:09:05 -05009539
Brian King6270e592014-01-21 12:16:41 -06009540 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
9541
Linus Torvalds1da177e2005-04-16 15:20:36 -07009542 ipr_regs_pci = pci_resource_start(pdev, 0);
9543
9544 rc = pci_request_regions(pdev, IPR_NAME);
9545 if (rc < 0) {
9546 dev_err(&pdev->dev,
9547 "Couldn't register memory range of registers\n");
9548 goto out_scsi_host_put;
9549 }
9550
Brian King6270e592014-01-21 12:16:41 -06009551 rc = pci_enable_device(pdev);
9552
9553 if (rc || pci_channel_offline(pdev)) {
9554 if (pci_channel_offline(pdev)) {
9555 ipr_wait_for_pci_err_recovery(ioa_cfg);
9556 rc = pci_enable_device(pdev);
9557 }
9558
9559 if (rc) {
9560 dev_err(&pdev->dev, "Cannot enable adapter\n");
9561 ipr_wait_for_pci_err_recovery(ioa_cfg);
9562 goto out_release_regions;
9563 }
9564 }
9565
Arjan van de Ven25729a72008-09-28 16:18:02 -07009566 ipr_regs = pci_ioremap_bar(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009567
9568 if (!ipr_regs) {
9569 dev_err(&pdev->dev,
9570 "Couldn't map memory range of registers\n");
9571 rc = -ENOMEM;
Brian King6270e592014-01-21 12:16:41 -06009572 goto out_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009573 }
9574
9575 ioa_cfg->hdw_dma_regs = ipr_regs;
9576 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
9577 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
9578
Brian King6270e592014-01-21 12:16:41 -06009579 ipr_init_regs(ioa_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009580
Wayne Boyera32c0552010-02-19 13:23:36 -08009581 if (ioa_cfg->sis64) {
9582 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
9583 if (rc < 0) {
9584 dev_dbg(&pdev->dev, "Failed to set 64 bit PCI DMA mask\n");
9585 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
9586 }
Wayne Boyera32c0552010-02-19 13:23:36 -08009587 } else
9588 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
9589
Linus Torvalds1da177e2005-04-16 15:20:36 -07009590 if (rc < 0) {
9591 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
9592 goto cleanup_nomem;
9593 }
9594
9595 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
9596 ioa_cfg->chip_cfg->cache_line_size);
9597
9598 if (rc != PCIBIOS_SUCCESSFUL) {
9599 dev_err(&pdev->dev, "Write of cache line size failed\n");
Brian King6270e592014-01-21 12:16:41 -06009600 ipr_wait_for_pci_err_recovery(ioa_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009601 rc = -EIO;
9602 goto cleanup_nomem;
9603 }
9604
Brian King6270e592014-01-21 12:16:41 -06009605 /* Issue MMIO read to ensure card is not in EEH */
9606 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg);
9607 ipr_wait_for_pci_err_recovery(ioa_cfg);
9608
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009609 if (ipr_number_of_msix > IPR_MAX_MSIX_VECTORS) {
9610 dev_err(&pdev->dev, "The max number of MSIX is %d\n",
9611 IPR_MAX_MSIX_VECTORS);
9612 ipr_number_of_msix = IPR_MAX_MSIX_VECTORS;
9613 }
9614
9615 if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009616 ipr_enable_msix(ioa_cfg) == 0)
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009617 ioa_cfg->intr_flag = IPR_USE_MSIX;
9618 else if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009619 ipr_enable_msi(ioa_cfg) == 0)
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009620 ioa_cfg->intr_flag = IPR_USE_MSI;
9621 else {
9622 ioa_cfg->intr_flag = IPR_USE_LSI;
9623 ioa_cfg->nvectors = 1;
9624 dev_info(&pdev->dev, "Cannot enable MSI.\n");
9625 }
9626
Brian King6270e592014-01-21 12:16:41 -06009627 pci_set_master(pdev);
9628
9629 if (pci_channel_offline(pdev)) {
9630 ipr_wait_for_pci_err_recovery(ioa_cfg);
9631 pci_set_master(pdev);
9632 if (pci_channel_offline(pdev)) {
9633 rc = -EIO;
9634 goto out_msi_disable;
9635 }
9636 }
9637
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009638 if (ioa_cfg->intr_flag == IPR_USE_MSI ||
9639 ioa_cfg->intr_flag == IPR_USE_MSIX) {
Wayne Boyer95fecd92009-06-16 15:13:28 -07009640 rc = ipr_test_msi(ioa_cfg, pdev);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009641 if (rc == -EOPNOTSUPP) {
Brian King6270e592014-01-21 12:16:41 -06009642 ipr_wait_for_pci_err_recovery(ioa_cfg);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009643 if (ioa_cfg->intr_flag == IPR_USE_MSI) {
9644 ioa_cfg->intr_flag &= ~IPR_USE_MSI;
9645 pci_disable_msi(pdev);
9646 } else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
9647 ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
9648 pci_disable_msix(pdev);
9649 }
9650
9651 ioa_cfg->intr_flag = IPR_USE_LSI;
9652 ioa_cfg->nvectors = 1;
9653 }
Wayne Boyer95fecd92009-06-16 15:13:28 -07009654 else if (rc)
9655 goto out_msi_disable;
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009656 else {
9657 if (ioa_cfg->intr_flag == IPR_USE_MSI)
9658 dev_info(&pdev->dev,
9659 "Request for %d MSIs succeeded with starting IRQ: %d\n",
9660 ioa_cfg->nvectors, pdev->irq);
9661 else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9662 dev_info(&pdev->dev,
9663 "Request for %d MSIXs succeeded.",
9664 ioa_cfg->nvectors);
9665 }
9666 }
9667
9668 ioa_cfg->hrrq_num = min3(ioa_cfg->nvectors,
9669 (unsigned int)num_online_cpus(),
9670 (unsigned int)IPR_MAX_HRRQ_NUM);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009671
Linus Torvalds1da177e2005-04-16 15:20:36 -07009672 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
Julia Lawallf170c682011-07-11 14:08:25 -07009673 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009674
9675 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
Julia Lawallf170c682011-07-11 14:08:25 -07009676 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009677
9678 rc = ipr_alloc_mem(ioa_cfg);
9679 if (rc < 0) {
9680 dev_err(&pdev->dev,
9681 "Couldn't allocate enough memory for device driver!\n");
Julia Lawallf170c682011-07-11 14:08:25 -07009682 goto out_msi_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009683 }
9684
Brian King6270e592014-01-21 12:16:41 -06009685 /* Save away PCI config space for use following IOA reset */
9686 rc = pci_save_state(pdev);
9687
9688 if (rc != PCIBIOS_SUCCESSFUL) {
9689 dev_err(&pdev->dev, "Failed to save PCI config space\n");
9690 rc = -EIO;
9691 goto cleanup_nolog;
9692 }
9693
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06009694 /*
9695 * If HRRQ updated interrupt is not masked, or reset alert is set,
9696 * the card is in an unknown state and needs a hard reset
9697 */
Wayne Boyer214777b2010-02-19 13:24:26 -08009698 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
9699 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
9700 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06009701 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
9702 ioa_cfg->needs_hard_reset = 1;
Anton Blanchard5d7c20b2011-08-01 19:43:45 +10009703 if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
Brian King473b1e82007-05-02 10:44:11 -05009704 ioa_cfg->needs_hard_reset = 1;
9705 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
9706 ioa_cfg->ioa_unit_checked = 1;
brking@us.ibm.comce155cc2005-11-17 09:35:12 -06009707
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009708 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009709 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -06009710 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009711
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009712 if (ioa_cfg->intr_flag == IPR_USE_MSI
9713 || ioa_cfg->intr_flag == IPR_USE_MSIX) {
9714 name_msi_vectors(ioa_cfg);
9715 rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_isr,
9716 0,
9717 ioa_cfg->vectors_info[0].desc,
9718 &ioa_cfg->hrrq[0]);
9719 if (!rc)
9720 rc = ipr_request_other_msi_irqs(ioa_cfg);
9721 } else {
9722 rc = request_irq(pdev->irq, ipr_isr,
9723 IRQF_SHARED,
9724 IPR_NAME, &ioa_cfg->hrrq[0]);
9725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07009726 if (rc) {
9727 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
9728 pdev->irq, rc);
9729 goto cleanup_nolog;
9730 }
9731
Brian King463fc692007-05-07 17:09:05 -05009732 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
9733 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
9734 ioa_cfg->needs_warm_reset = 1;
9735 ioa_cfg->reset = ipr_reset_slot_reset;
9736 } else
9737 ioa_cfg->reset = ipr_reset_start_bist;
9738
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009739 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009740 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009741 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009742
9743 LEAVE;
9744out:
9745 return rc;
9746
9747cleanup_nolog:
9748 ipr_free_mem(ioa_cfg);
Wayne Boyer95fecd92009-06-16 15:13:28 -07009749out_msi_disable:
Brian King6270e592014-01-21 12:16:41 -06009750 ipr_wait_for_pci_err_recovery(ioa_cfg);
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -06009751 if (ioa_cfg->intr_flag == IPR_USE_MSI)
9752 pci_disable_msi(pdev);
9753 else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9754 pci_disable_msix(pdev);
Julia Lawallf170c682011-07-11 14:08:25 -07009755cleanup_nomem:
9756 iounmap(ipr_regs);
Brian King6270e592014-01-21 12:16:41 -06009757out_disable:
9758 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009759out_release_regions:
9760 pci_release_regions(pdev);
9761out_scsi_host_put:
9762 scsi_host_put(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009763 goto out;
9764}
9765
9766/**
9767 * ipr_scan_vsets - Scans for VSET devices
9768 * @ioa_cfg: ioa config struct
9769 *
9770 * Description: Since the VSET resources do not follow SAM in that we can have
9771 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
9772 *
9773 * Return value:
9774 * none
9775 **/
9776static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
9777{
9778 int target, lun;
9779
9780 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03009781 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009782 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
9783}
9784
9785/**
9786 * ipr_initiate_ioa_bringdown - Bring down an adapter
9787 * @ioa_cfg: ioa config struct
9788 * @shutdown_type: shutdown type
9789 *
9790 * Description: This function will initiate bringing down the adapter.
9791 * This consists of issuing an IOA shutdown to the adapter
9792 * to flush the cache, and running BIST.
9793 * If the caller needs to wait on the completion of the reset,
9794 * the caller must sleep on the reset_wait_q.
9795 *
9796 * Return value:
9797 * none
9798 **/
9799static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
9800 enum ipr_shutdown_type shutdown_type)
9801{
9802 ENTER;
9803 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
9804 ioa_cfg->sdt_state = ABORT_DUMP;
9805 ioa_cfg->reset_retries = 0;
9806 ioa_cfg->in_ioa_bringdown = 1;
9807 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
9808 LEAVE;
9809}
9810
9811/**
9812 * __ipr_remove - Remove a single adapter
9813 * @pdev: pci device struct
9814 *
9815 * Adapter hot plug remove entry point.
9816 *
9817 * Return value:
9818 * none
9819 **/
9820static void __ipr_remove(struct pci_dev *pdev)
9821{
9822 unsigned long host_lock_flags = 0;
9823 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
Brian Kingbfae7822013-01-30 23:45:08 -06009824 int i;
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009825 unsigned long driver_lock_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009826 ENTER;
9827
9828 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03009829 while (ioa_cfg->in_reset_reload) {
Brian King970ea292007-04-26 16:00:06 -05009830 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9831 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9832 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9833 }
9834
Brian Kingbfae7822013-01-30 23:45:08 -06009835 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9836 spin_lock(&ioa_cfg->hrrq[i]._lock);
9837 ioa_cfg->hrrq[i].removing_ioa = 1;
9838 spin_unlock(&ioa_cfg->hrrq[i]._lock);
9839 }
9840 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07009841 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9842
9843 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9844 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
Tejun Heo43829732012-08-20 14:51:24 -07009845 flush_work(&ioa_cfg->work_q);
wenxiong@linux.vnet.ibm.com9077a942013-03-14 13:52:24 -05009846 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009847 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9848
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009849 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009850 list_del(&ioa_cfg->queue);
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -05009851 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009852
9853 if (ioa_cfg->sdt_state == ABORT_DUMP)
9854 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
9855 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9856
9857 ipr_free_all_resources(ioa_cfg);
9858
9859 LEAVE;
9860}
9861
9862/**
9863 * ipr_remove - IOA hot plug remove entry point
9864 * @pdev: pci device struct
9865 *
9866 * Adapter hot plug remove entry point.
9867 *
9868 * Return value:
9869 * none
9870 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009871static void ipr_remove(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009872{
9873 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9874
9875 ENTER;
9876
Tony Jonesee959b02008-02-22 00:13:36 +01009877 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009878 &ipr_trace_attr);
Tony Jonesee959b02008-02-22 00:13:36 +01009879 ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009880 &ipr_dump_attr);
9881 scsi_remove_host(ioa_cfg->host);
9882
9883 __ipr_remove(pdev);
9884
9885 LEAVE;
9886}
9887
9888/**
9889 * ipr_probe - Adapter hot plug add entry point
9890 *
9891 * Return value:
9892 * 0 on success / non-zero on failure
9893 **/
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009894static int ipr_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009895{
9896 struct ipr_ioa_cfg *ioa_cfg;
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06009897 int rc, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009898
9899 rc = ipr_probe_ioa(pdev, dev_id);
9900
9901 if (rc)
9902 return rc;
9903
9904 ioa_cfg = pci_get_drvdata(pdev);
9905 rc = ipr_probe_ioa_part2(ioa_cfg);
9906
9907 if (rc) {
9908 __ipr_remove(pdev);
9909 return rc;
9910 }
9911
9912 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
9913
9914 if (rc) {
9915 __ipr_remove(pdev);
9916 return rc;
9917 }
9918
Tony Jonesee959b02008-02-22 00:13:36 +01009919 rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009920 &ipr_trace_attr);
9921
9922 if (rc) {
9923 scsi_remove_host(ioa_cfg->host);
9924 __ipr_remove(pdev);
9925 return rc;
9926 }
9927
Tony Jonesee959b02008-02-22 00:13:36 +01009928 rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009929 &ipr_dump_attr);
9930
9931 if (rc) {
Tony Jonesee959b02008-02-22 00:13:36 +01009932 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -07009933 &ipr_trace_attr);
9934 scsi_remove_host(ioa_cfg->host);
9935 __ipr_remove(pdev);
9936 return rc;
9937 }
9938
9939 scsi_scan_host(ioa_cfg->host);
9940 ipr_scan_vsets(ioa_cfg);
9941 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
9942 ioa_cfg->allow_ml_add_del = 1;
brking@us.ibm.com11cd8f12005-11-01 17:00:11 -06009943 ioa_cfg->host->max_channel = IPR_VSET_BUS;
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06009944 ioa_cfg->iopoll_weight = ioa_cfg->chip_cfg->iopoll_weight;
9945
Jens Axboe89f8b332014-03-13 09:38:42 -06009946 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06009947 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
9948 blk_iopoll_init(&ioa_cfg->hrrq[i].iopoll,
9949 ioa_cfg->iopoll_weight, ipr_iopoll);
9950 blk_iopoll_enable(&ioa_cfg->hrrq[i].iopoll);
9951 }
9952 }
9953
Linus Torvalds1da177e2005-04-16 15:20:36 -07009954 schedule_work(&ioa_cfg->work_q);
9955 return 0;
9956}
9957
9958/**
9959 * ipr_shutdown - Shutdown handler.
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07009960 * @pdev: pci device struct
Linus Torvalds1da177e2005-04-16 15:20:36 -07009961 *
9962 * This function is invoked upon system shutdown/reboot. It will issue
9963 * an adapter shutdown to the adapter to flush the write cache.
9964 *
9965 * Return value:
9966 * none
9967 **/
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07009968static void ipr_shutdown(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009969{
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -07009970 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07009971 unsigned long lock_flags = 0;
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06009972 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009973
9974 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
Jens Axboe89f8b332014-03-13 09:38:42 -06009975 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
wenxiong@linux.vnet.ibm.comb53d1242013-01-11 17:43:52 -06009976 ioa_cfg->iopoll_weight = 0;
9977 for (i = 1; i < ioa_cfg->hrrq_num; i++)
9978 blk_iopoll_disable(&ioa_cfg->hrrq[i].iopoll);
9979 }
9980
Kleber Sacilotto de Souza203fa3f2012-08-22 18:14:14 -03009981 while (ioa_cfg->in_reset_reload) {
Brian King970ea292007-04-26 16:00:06 -05009982 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9983 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9984 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9985 }
9986
Linus Torvalds1da177e2005-04-16 15:20:36 -07009987 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9988 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9989 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9990}
9991
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08009992static struct pci_device_id ipr_pci_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07009993 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -06009994 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009995 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -06009996 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009997 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -06009998 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07009999 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
Brian King6d84c942007-01-23 11:25:23 -060010000 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010001 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -060010002 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010003 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -060010004 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010005 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King6d84c942007-01-23 11:25:23 -060010006 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010007 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
Brian King5469cb52007-03-29 12:42:40 -050010008 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
10009 IPR_USE_LONG_TRANSOP_TIMEOUT },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010010 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King6d84c942007-01-23 11:25:23 -060010011 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010012 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King22d2e402007-04-26 16:00:13 -050010013 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
10014 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -060010015 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
Brian King5469cb52007-03-29 12:42:40 -050010016 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
10017 IPR_USE_LONG_TRANSOP_TIMEOUT },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010018 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King6d84c942007-01-23 11:25:23 -060010019 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010020 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King22d2e402007-04-26 16:00:13 -050010021 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
10022 IPR_USE_LONG_TRANSOP_TIMEOUT},
Brian King60e74862006-11-21 10:28:10 -060010023 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
Brian King5469cb52007-03-29 12:42:40 -050010024 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
10025 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -060010026 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King22d2e402007-04-26 16:00:13 -050010027 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
10028 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King185eb312007-03-29 12:42:53 -050010029 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King185eb312007-03-29 12:42:53 -050010030 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
10031 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Wayne Boyerb0f56d32010-06-24 13:34:14 -070010032 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
10033 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
Brian King5469cb52007-03-29 12:42:40 -050010034 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
Brian King463fc692007-05-07 17:09:05 -050010035 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010036 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
Brian King6d84c942007-01-23 11:25:23 -060010037 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010038 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King6d84c942007-01-23 11:25:23 -060010039 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
brking@us.ibm.com86f51432005-11-01 17:02:42 -060010040 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King5469cb52007-03-29 12:42:40 -050010041 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
10042 IPR_USE_LONG_TRANSOP_TIMEOUT },
Brian King60e74862006-11-21 10:28:10 -060010043 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
Brian King5469cb52007-03-29 12:42:40 -050010044 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
10045 IPR_USE_LONG_TRANSOP_TIMEOUT },
Wayne Boyerd7b46272010-02-19 13:24:38 -080010046 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10047 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
10048 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10049 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
10050 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10051 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
Wayne Boyer32622bd2010-10-18 20:24:34 -070010052 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
wenxiong@linux.vnet.ibm.comb8d5d562013-01-11 17:43:47 -060010053 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C0, 0, 0, 0 },
10054 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
Wayne Boyer5a918352011-10-27 11:58:21 -070010055 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
10056 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
Wayne Boyer32622bd2010-10-18 20:24:34 -070010057 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -080010058 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -080010059 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -080010060 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -080010061 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -080010062 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -080010063 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
Wayne Boyercd9b3d02012-02-23 11:54:55 -080010064 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10065 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
10066 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wayne Boyerd7b46272010-02-19 13:24:38 -080010067 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
wenxiong@linux.vnet.ibm.comb8d5d562013-01-11 17:43:47 -060010068 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10069 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D5, 0, 0, 0 },
10070 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10071 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D6, 0, 0, 0 },
10072 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10073 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D7, 0, 0, 0 },
10074 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10075 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D8, 0, 0, 0 },
wenxiong@linux.vnet.ibm.com43c5fda2013-07-10 10:46:27 -050010076 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10077 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D9, 0, 0, 0 },
10078 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
Wendy Xiongf94d9962014-01-21 12:16:40 -060010079 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57DA, 0, 0, 0 },
10080 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
wenxiong@linux.vnet.ibm.com43c5fda2013-07-10 10:46:27 -050010081 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EB, 0, 0, 0 },
10082 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10083 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EC, 0, 0, 0 },
10084 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10085 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57ED, 0, 0, 0 },
10086 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10087 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EE, 0, 0, 0 },
10088 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10089 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EF, 0, 0, 0 },
10090 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10091 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57F0, 0, 0, 0 },
Wendy Xiong5eeac3e2014-03-12 16:08:52 -050010092 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10093 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCA, 0, 0, 0 },
10094 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10095 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CD2, 0, 0, 0 },
10096 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10097 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCD, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070010098 { }
10099};
10100MODULE_DEVICE_TABLE(pci, ipr_pci_table);
10101
Stephen Hemmingera55b2d22012-09-07 09:33:16 -070010102static const struct pci_error_handlers ipr_err_handler = {
Linas Vepstasf8a88b192006-02-03 16:52:42 -060010103 .error_detected = ipr_pci_error_detected,
Brian King6270e592014-01-21 12:16:41 -060010104 .mmio_enabled = ipr_pci_mmio_enabled,
Linas Vepstasf8a88b192006-02-03 16:52:42 -060010105 .slot_reset = ipr_pci_slot_reset,
10106};
10107
Linus Torvalds1da177e2005-04-16 15:20:36 -070010108static struct pci_driver ipr_driver = {
10109 .name = IPR_NAME,
10110 .id_table = ipr_pci_table,
10111 .probe = ipr_probe,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080010112 .remove = ipr_remove,
Greg Kroah-Hartmand18c3db2005-06-23 17:35:56 -070010113 .shutdown = ipr_shutdown,
Linas Vepstasf8a88b192006-02-03 16:52:42 -060010114 .err_handler = &ipr_err_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -070010115};
10116
10117/**
Wayne Boyerf72919e2010-02-19 13:24:21 -080010118 * ipr_halt_done - Shutdown prepare completion
10119 *
10120 * Return value:
10121 * none
10122 **/
10123static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
10124{
wenxiong@linux.vnet.ibm.com05a65382013-01-11 17:43:50 -060010125 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
Wayne Boyerf72919e2010-02-19 13:24:21 -080010126}
10127
10128/**
10129 * ipr_halt - Issue shutdown prepare to all adapters
10130 *
10131 * Return value:
10132 * NOTIFY_OK on success / NOTIFY_DONE on failure
10133 **/
10134static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
10135{
10136 struct ipr_cmnd *ipr_cmd;
10137 struct ipr_ioa_cfg *ioa_cfg;
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -050010138 unsigned long flags = 0, driver_lock_flags;
Wayne Boyerf72919e2010-02-19 13:24:21 -080010139
10140 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
10141 return NOTIFY_DONE;
10142
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -050010143 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
Wayne Boyerf72919e2010-02-19 13:24:21 -080010144
10145 list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
10146 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
wenxiong@linux.vnet.ibm.com56d6aa32013-01-11 17:43:51 -060010147 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
Wayne Boyerf72919e2010-02-19 13:24:21 -080010148 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10149 continue;
10150 }
10151
10152 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
10153 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
10154 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
10155 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
10156 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
10157
10158 ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
10159 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10160 }
wenxiong@linux.vnet.ibm.comfeccada2013-05-24 09:59:13 -050010161 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
Wayne Boyerf72919e2010-02-19 13:24:21 -080010162
10163 return NOTIFY_OK;
10164}
10165
10166static struct notifier_block ipr_notifier = {
10167 ipr_halt, NULL, 0
10168};
10169
10170/**
Linus Torvalds1da177e2005-04-16 15:20:36 -070010171 * ipr_init - Module entry point
10172 *
10173 * Return value:
10174 * 0 on success / negative value on failure
10175 **/
10176static int __init ipr_init(void)
10177{
10178 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
10179 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
10180
Wayne Boyerf72919e2010-02-19 13:24:21 -080010181 register_reboot_notifier(&ipr_notifier);
Henrik Kretzschmardcbccbde2006-09-25 16:58:58 -070010182 return pci_register_driver(&ipr_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010183}
10184
10185/**
10186 * ipr_exit - Module unload
10187 *
10188 * Module unload entry point.
10189 *
10190 * Return value:
10191 * none
10192 **/
10193static void __exit ipr_exit(void)
10194{
Wayne Boyerf72919e2010-02-19 13:24:21 -080010195 unregister_reboot_notifier(&ipr_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010196 pci_unregister_driver(&ipr_driver);
10197}
10198
10199module_init(ipr_init);
10200module_exit(ipr_exit);