1/*
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
57#include <linux/fs.h>
58#include <linux/init.h>
59#include <linux/types.h>
60#include <linux/errno.h>
61#include <linux/kernel.h>
62#include <linux/slab.h>
63#include <linux/vmalloc.h>
64#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>
75#include <linux/libata.h>
76#include <linux/hdreg.h>
77#include <linux/reboot.h>
78#include <linux/stringify.h>
79#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>
87#include "ipr.h"
88
89/*
90 * Global Data
91 */
92static LIST_HEAD(ipr_ioa_head);
93static 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;
97static unsigned int ipr_transop_timeout = 0;
98static unsigned int ipr_debug = 0;
99static unsigned int ipr_max_devs = IPR_DEFAULT_SIS64_DEVS;
100static unsigned int ipr_dual_ioa_raid = 1;
101static unsigned int ipr_number_of_msix = 16;
102static unsigned int ipr_fast_reboot;
103static DEFINE_SPINLOCK(ipr_driver_lock);
104
105/* This table describes the differences between DMA controller chips */
106static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
107 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
108 .mailbox = 0x0042C,
109 .max_cmds = 100,
110 .cache_line_size = 0x20,
111 .clear_isr = 1,
112 .iopoll_weight = 0,
113 {
114 .set_interrupt_mask_reg = 0x0022C,
115 .clr_interrupt_mask_reg = 0x00230,
116 .clr_interrupt_mask_reg32 = 0x00230,
117 .sense_interrupt_mask_reg = 0x0022C,
118 .sense_interrupt_mask_reg32 = 0x0022C,
119 .clr_interrupt_reg = 0x00228,
120 .clr_interrupt_reg32 = 0x00228,
121 .sense_interrupt_reg = 0x00224,
122 .sense_interrupt_reg32 = 0x00224,
123 .ioarrin_reg = 0x00404,
124 .sense_uproc_interrupt_reg = 0x00214,
125 .sense_uproc_interrupt_reg32 = 0x00214,
126 .set_uproc_interrupt_reg = 0x00214,
127 .set_uproc_interrupt_reg32 = 0x00214,
128 .clr_uproc_interrupt_reg = 0x00218,
129 .clr_uproc_interrupt_reg32 = 0x00218
130 }
131 },
132 { /* Snipe and Scamp */
133 .mailbox = 0x0052C,
134 .max_cmds = 100,
135 .cache_line_size = 0x20,
136 .clear_isr = 1,
137 .iopoll_weight = 0,
138 {
139 .set_interrupt_mask_reg = 0x00288,
140 .clr_interrupt_mask_reg = 0x0028C,
141 .clr_interrupt_mask_reg32 = 0x0028C,
142 .sense_interrupt_mask_reg = 0x00288,
143 .sense_interrupt_mask_reg32 = 0x00288,
144 .clr_interrupt_reg = 0x00284,
145 .clr_interrupt_reg32 = 0x00284,
146 .sense_interrupt_reg = 0x00280,
147 .sense_interrupt_reg32 = 0x00280,
148 .ioarrin_reg = 0x00504,
149 .sense_uproc_interrupt_reg = 0x00290,
150 .sense_uproc_interrupt_reg32 = 0x00290,
151 .set_uproc_interrupt_reg = 0x00290,
152 .set_uproc_interrupt_reg32 = 0x00290,
153 .clr_uproc_interrupt_reg = 0x00294,
154 .clr_uproc_interrupt_reg32 = 0x00294
155 }
156 },
157 { /* CRoC */
158 .mailbox = 0x00044,
159 .max_cmds = 1000,
160 .cache_line_size = 0x20,
161 .clear_isr = 0,
162 .iopoll_weight = 64,
163 {
164 .set_interrupt_mask_reg = 0x00010,
165 .clr_interrupt_mask_reg = 0x00018,
166 .clr_interrupt_mask_reg32 = 0x0001C,
167 .sense_interrupt_mask_reg = 0x00010,
168 .sense_interrupt_mask_reg32 = 0x00014,
169 .clr_interrupt_reg = 0x00008,
170 .clr_interrupt_reg32 = 0x0000C,
171 .sense_interrupt_reg = 0x00000,
172 .sense_interrupt_reg32 = 0x00004,
173 .ioarrin_reg = 0x00070,
174 .sense_uproc_interrupt_reg = 0x00020,
175 .sense_uproc_interrupt_reg32 = 0x00024,
176 .set_uproc_interrupt_reg = 0x00020,
177 .set_uproc_interrupt_reg32 = 0x00024,
178 .clr_uproc_interrupt_reg = 0x00028,
179 .clr_uproc_interrupt_reg32 = 0x0002C,
180 .init_feedback_reg = 0x0005C,
181 .dump_addr_reg = 0x00064,
182 .dump_data_reg = 0x00068,
183 .endian_swap_reg = 0x00084
184 }
185 },
186};
187
188static const struct ipr_chip_t ipr_chip[] = {
189 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
190 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
191 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
192 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
193 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, true, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
194 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
195 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
196 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
197 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
198 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
199};
200
201static int ipr_max_bus_speeds[] = {
202 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
203};
204
205MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
206MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
207module_param_named(max_speed, ipr_max_speed, uint, 0);
208MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
209module_param_named(log_level, ipr_log_level, uint, 0);
210MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
211module_param_named(testmode, ipr_testmode, int, 0);
212MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
213module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
214MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
215module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
216MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
217module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
218MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
219module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
220MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
221module_param_named(max_devs, ipr_max_devs, int, 0);
222MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
223 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
224module_param_named(number_of_msix, ipr_number_of_msix, int, 0);
225MODULE_PARM_DESC(number_of_msix, "Specify the number of MSIX interrupts to use on capable adapters (1 - 16). (default:16)");
226module_param_named(fast_reboot, ipr_fast_reboot, int, S_IRUGO | S_IWUSR);
227MODULE_PARM_DESC(fast_reboot, "Skip adapter shutdown during reboot. Set to 1 to enable. (default: 0)");
228MODULE_LICENSE("GPL");
229MODULE_VERSION(IPR_DRIVER_VERSION);
230
231/* A constant array of IOASCs/URCs/Error Messages */
232static const
233struct ipr_error_table_t ipr_error_table[] = {
234 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
235 "8155: An unknown error was received"},
236 {0x00330000, 0, 0,
237 "Soft underlength error"},
238 {0x005A0000, 0, 0,
239 "Command to be cancelled not found"},
240 {0x00808000, 0, 0,
241 "Qualified success"},
242 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
243 "FFFE: Soft device bus error recovered by the IOA"},
244 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
245 "4101: Soft device bus fabric error"},
246 {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
247 "FFFC: Logical block guard error recovered by the device"},
248 {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
249 "FFFC: Logical block reference tag error recovered by the device"},
250 {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
251 "4171: Recovered scatter list tag / sequence number error"},
252 {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
253 "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
254 {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
255 "4171: Recovered logical block sequence number error on IOA to Host transfer"},
256 {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
257 "FFFD: Recovered logical block reference tag error detected by the IOA"},
258 {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
259 "FFFD: Logical block guard error recovered by the IOA"},
260 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
261 "FFF9: Device sector reassign successful"},
262 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
263 "FFF7: Media error recovered by device rewrite procedures"},
264 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
265 "7001: IOA sector reassignment successful"},
266 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
267 "FFF9: Soft media error. Sector reassignment recommended"},
268 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
269 "FFF7: Media error recovered by IOA rewrite procedures"},
270 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
271 "FF3D: Soft PCI bus error recovered by the IOA"},
272 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
273 "FFF6: Device hardware error recovered by the IOA"},
274 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
275 "FFF6: Device hardware error recovered by the device"},
276 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
277 "FF3D: Soft IOA error recovered by the IOA"},
278 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
279 "FFFA: Undefined device response recovered by the IOA"},
280 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
281 "FFF6: Device bus error, message or command phase"},
282 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
283 "FFFE: Task Management Function failed"},
284 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
285 "FFF6: Failure prediction threshold exceeded"},
286 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
287 "8009: Impending cache battery pack failure"},
288 {0x02040100, 0, 0,
289 "Logical Unit in process of becoming ready"},
290 {0x02040200, 0, 0,
291 "Initializing command required"},
292 {0x02040400, 0, 0,
293 "34FF: Disk device format in progress"},
294 {0x02040C00, 0, 0,
295 "Logical unit not accessible, target port in unavailable state"},
296 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
297 "9070: IOA requested reset"},
298 {0x023F0000, 0, 0,
299 "Synchronization required"},
300 {0x02408500, 0, 0,
301 "IOA microcode download required"},
302 {0x02408600, 0, 0,
303 "Device bus connection is prohibited by host"},
304 {0x024E0000, 0, 0,
305 "No ready, IOA shutdown"},
306 {0x025A0000, 0, 0,
307 "Not ready, IOA has been shutdown"},
308 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
309 "3020: Storage subsystem configuration error"},
310 {0x03110B00, 0, 0,
311 "FFF5: Medium error, data unreadable, recommend reassign"},
312 {0x03110C00, 0, 0,
313 "7000: Medium error, data unreadable, do not reassign"},
314 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
315 "FFF3: Disk media format bad"},
316 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
317 "3002: Addressed device failed to respond to selection"},
318 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
319 "3100: Device bus error"},
320 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
321 "3109: IOA timed out a device command"},
322 {0x04088000, 0, 0,
323 "3120: SCSI bus is not operational"},
324 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
325 "4100: Hard device bus fabric error"},
326 {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
327 "310C: Logical block guard error detected by the device"},
328 {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
329 "310C: Logical block reference tag error detected by the device"},
330 {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
331 "4170: Scatter list tag / sequence number error"},
332 {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
333 "8150: Logical block CRC error on IOA to Host transfer"},
334 {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
335 "4170: Logical block sequence number error on IOA to Host transfer"},
336 {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
337 "310D: Logical block reference tag error detected by the IOA"},
338 {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
339 "310D: Logical block guard error detected by the IOA"},
340 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
341 "9000: IOA reserved area data check"},
342 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
343 "9001: IOA reserved area invalid data pattern"},
344 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
345 "9002: IOA reserved area LRC error"},
346 {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
347 "Hardware Error, IOA metadata access error"},
348 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
349 "102E: Out of alternate sectors for disk storage"},
350 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
351 "FFF4: Data transfer underlength error"},
352 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
353 "FFF4: Data transfer overlength error"},
354 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
355 "3400: Logical unit failure"},
356 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
357 "FFF4: Device microcode is corrupt"},
358 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
359 "8150: PCI bus error"},
360 {0x04430000, 1, 0,
361 "Unsupported device bus message received"},
362 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
363 "FFF4: Disk device problem"},
364 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
365 "8150: Permanent IOA failure"},
366 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
367 "3010: Disk device returned wrong response to IOA"},
368 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
369 "8151: IOA microcode error"},
370 {0x04448500, 0, 0,
371 "Device bus status error"},
372 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
373 "8157: IOA error requiring IOA reset to recover"},
374 {0x04448700, 0, 0,
375 "ATA device status error"},
376 {0x04490000, 0, 0,
377 "Message reject received from the device"},
378 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
379 "8008: A permanent cache battery pack failure occurred"},
380 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
381 "9090: Disk unit has been modified after the last known status"},
382 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
383 "9081: IOA detected device error"},
384 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
385 "9082: IOA detected device error"},
386 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
387 "3110: Device bus error, message or command phase"},
388 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
389 "3110: SAS Command / Task Management Function failed"},
390 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
391 "9091: Incorrect hardware configuration change has been detected"},
392 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
393 "9073: Invalid multi-adapter configuration"},
394 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
395 "4010: Incorrect connection between cascaded expanders"},
396 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
397 "4020: Connections exceed IOA design limits"},
398 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
399 "4030: Incorrect multipath connection"},
400 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
401 "4110: Unsupported enclosure function"},
402 {0x04679800, 0, IPR_DEFAULT_LOG_LEVEL,
403 "4120: SAS cable VPD cannot be read"},
404 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
405 "FFF4: Command to logical unit failed"},
406 {0x05240000, 1, 0,
407 "Illegal request, invalid request type or request packet"},
408 {0x05250000, 0, 0,
409 "Illegal request, invalid resource handle"},
410 {0x05258000, 0, 0,
411 "Illegal request, commands not allowed to this device"},
412 {0x05258100, 0, 0,
413 "Illegal request, command not allowed to a secondary adapter"},
414 {0x05258200, 0, 0,
415 "Illegal request, command not allowed to a non-optimized resource"},
416 {0x05260000, 0, 0,
417 "Illegal request, invalid field in parameter list"},
418 {0x05260100, 0, 0,
419 "Illegal request, parameter not supported"},
420 {0x05260200, 0, 0,
421 "Illegal request, parameter value invalid"},
422 {0x052C0000, 0, 0,
423 "Illegal request, command sequence error"},
424 {0x052C8000, 1, 0,
425 "Illegal request, dual adapter support not enabled"},
426 {0x052C8100, 1, 0,
427 "Illegal request, another cable connector was physically disabled"},
428 {0x054E8000, 1, 0,
429 "Illegal request, inconsistent group id/group count"},
430 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
431 "9031: Array protection temporarily suspended, protection resuming"},
432 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
433 "9040: Array protection temporarily suspended, protection resuming"},
434 {0x060B0100, 0, IPR_DEFAULT_LOG_LEVEL,
435 "4080: IOA exceeded maximum operating temperature"},
436 {0x060B8000, 0, IPR_DEFAULT_LOG_LEVEL,
437 "4085: Service required"},
438 {0x060B8100, 0, IPR_DEFAULT_LOG_LEVEL,
439 "4086: SAS Adapter Hardware Configuration Error"},
440 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
441 "3140: Device bus not ready to ready transition"},
442 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
443 "FFFB: SCSI bus was reset"},
444 {0x06290500, 0, 0,
445 "FFFE: SCSI bus transition to single ended"},
446 {0x06290600, 0, 0,
447 "FFFE: SCSI bus transition to LVD"},
448 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
449 "FFFB: SCSI bus was reset by another initiator"},
450 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
451 "3029: A device replacement has occurred"},
452 {0x063F8300, 0, IPR_DEFAULT_LOG_LEVEL,
453 "4102: Device bus fabric performance degradation"},
454 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
455 "9051: IOA cache data exists for a missing or failed device"},
456 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
457 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
458 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
459 "9025: Disk unit is not supported at its physical location"},
460 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
461 "3020: IOA detected a SCSI bus configuration error"},
462 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
463 "3150: SCSI bus configuration error"},
464 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
465 "9074: Asymmetric advanced function disk configuration"},
466 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
467 "4040: Incomplete multipath connection between IOA and enclosure"},
468 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
469 "4041: Incomplete multipath connection between enclosure and device"},
470 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
471 "9075: Incomplete multipath connection between IOA and remote IOA"},
472 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
473 "9076: Configuration error, missing remote IOA"},
474 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
475 "4050: Enclosure does not support a required multipath function"},
476 {0x06679800, 0, IPR_DEFAULT_LOG_LEVEL,
477 "4121: Configuration error, required cable is missing"},
478 {0x06679900, 0, IPR_DEFAULT_LOG_LEVEL,
479 "4122: Cable is not plugged into the correct location on remote IOA"},
480 {0x06679A00, 0, IPR_DEFAULT_LOG_LEVEL,
481 "4123: Configuration error, invalid cable vital product data"},
482 {0x06679B00, 0, IPR_DEFAULT_LOG_LEVEL,
483 "4124: Configuration error, both cable ends are plugged into the same IOA"},
484 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
485 "4070: Logically bad block written on device"},
486 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
487 "9041: Array protection temporarily suspended"},
488 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
489 "9042: Corrupt array parity detected on specified device"},
490 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
491 "9030: Array no longer protected due to missing or failed disk unit"},
492 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
493 "9071: Link operational transition"},
494 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
495 "9072: Link not operational transition"},
496 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
497 "9032: Array exposed but still protected"},
498 {0x066B8300, 0, IPR_DEBUG_LOG_LEVEL,
499 "70DD: Device forced failed by disrupt device command"},
500 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
501 "4061: Multipath redundancy level got better"},
502 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
503 "4060: Multipath redundancy level got worse"},
504 {0x06808100, 0, IPR_DEBUG_LOG_LEVEL,
505 "9083: Device raw mode enabled"},
506 {0x06808200, 0, IPR_DEBUG_LOG_LEVEL,
507 "9084: Device raw mode disabled"},
508 {0x07270000, 0, 0,
509 "Failure due to other device"},
510 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
511 "9008: IOA does not support functions expected by devices"},
512 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
513 "9010: Cache data associated with attached devices cannot be found"},
514 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
515 "9011: Cache data belongs to devices other than those attached"},
516 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
517 "9020: Array missing 2 or more devices with only 1 device present"},
518 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
519 "9021: Array missing 2 or more devices with 2 or more devices present"},
520 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
521 "9022: Exposed array is missing a required device"},
522 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
523 "9023: Array member(s) not at required physical locations"},
524 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
525 "9024: Array not functional due to present hardware configuration"},
526 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
527 "9026: Array not functional due to present hardware configuration"},
528 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
529 "9027: Array is missing a device and parity is out of sync"},
530 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
531 "9028: Maximum number of arrays already exist"},
532 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
533 "9050: Required cache data cannot be located for a disk unit"},
534 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
535 "9052: Cache data exists for a device that has been modified"},
536 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
537 "9054: IOA resources not available due to previous problems"},
538 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
539 "9092: Disk unit requires initialization before use"},
540 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
541 "9029: Incorrect hardware configuration change has been detected"},
542 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
543 "9060: One or more disk pairs are missing from an array"},
544 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
545 "9061: One or more disks are missing from an array"},
546 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
547 "9062: One or more disks are missing from an array"},
548 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
549 "9063: Maximum number of functional arrays has been exceeded"},
550 {0x07279A00, 0, 0,
551 "Data protect, other volume set problem"},
552 {0x0B260000, 0, 0,
553 "Aborted command, invalid descriptor"},
554 {0x0B3F9000, 0, 0,
555 "Target operating conditions have changed, dual adapter takeover"},
556 {0x0B530200, 0, 0,
557 "Aborted command, medium removal prevented"},
558 {0x0B5A0000, 0, 0,
559 "Command terminated by host"},
560 {0x0B5B8000, 0, 0,
561 "Aborted command, command terminated by host"}
562};
563
564static const struct ipr_ses_table_entry ipr_ses_table[] = {
565 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
566 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
567 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
568 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
569 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
570 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
571 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
572 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
573 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
574 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
575 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
576 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
577 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
578};
579
580/*
581 * Function Prototypes
582 */
583static int ipr_reset_alert(struct ipr_cmnd *);
584static void ipr_process_ccn(struct ipr_cmnd *);
585static void ipr_process_error(struct ipr_cmnd *);
586static void ipr_reset_ioa_job(struct ipr_cmnd *);
587static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
588 enum ipr_shutdown_type);
589
590#ifdef CONFIG_SCSI_IPR_TRACE
591/**
592 * ipr_trc_hook - Add a trace entry to the driver trace
593 * @ipr_cmd: ipr command struct
594 * @type: trace type
595 * @add_data: additional data
596 *
597 * Return value:
598 * none
599 **/
600static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
601 u8 type, u32 add_data)
602{
603 struct ipr_trace_entry *trace_entry;
604 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
605 unsigned int trace_index;
606
607 trace_index = atomic_add_return(1, &ioa_cfg->trace_index) & IPR_TRACE_INDEX_MASK;
608 trace_entry = &ioa_cfg->trace[trace_index];
609 trace_entry->time = jiffies;
610 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
611 trace_entry->type = type;
612 if (ipr_cmd->ioa_cfg->sis64)
613 trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
614 else
615 trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
616 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
617 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
618 trace_entry->u.add_data = add_data;
619 wmb();
620}
621#else
622#define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
623#endif
624
625/**
626 * ipr_lock_and_done - Acquire lock and complete command
627 * @ipr_cmd: ipr command struct
628 *
629 * Return value:
630 * none
631 **/
632static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
633{
634 unsigned long lock_flags;
635 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
636
637 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
638 ipr_cmd->done(ipr_cmd);
639 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
640}
641
642/**
643 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
644 * @ipr_cmd: ipr command struct
645 *
646 * Return value:
647 * none
648 **/
649static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
650{
651 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
652 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
653 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
654 dma_addr_t dma_addr = ipr_cmd->dma_addr;
655 int hrrq_id;
656
657 hrrq_id = ioarcb->cmd_pkt.hrrq_id;
658 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
659 ioarcb->cmd_pkt.hrrq_id = hrrq_id;
660 ioarcb->data_transfer_length = 0;
661 ioarcb->read_data_transfer_length = 0;
662 ioarcb->ioadl_len = 0;
663 ioarcb->read_ioadl_len = 0;
664
665 if (ipr_cmd->ioa_cfg->sis64) {
666 ioarcb->u.sis64_addr_data.data_ioadl_addr =
667 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
668 ioasa64->u.gata.status = 0;
669 } else {
670 ioarcb->write_ioadl_addr =
671 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
672 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
673 ioasa->u.gata.status = 0;
674 }
675
676 ioasa->hdr.ioasc = 0;
677 ioasa->hdr.residual_data_len = 0;
678 ipr_cmd->scsi_cmd = NULL;
679 ipr_cmd->qc = NULL;
680 ipr_cmd->sense_buffer[0] = 0;
681 ipr_cmd->dma_use_sg = 0;
682}
683
684/**
685 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
686 * @ipr_cmd: ipr command struct
687 *
688 * Return value:
689 * none
690 **/
691static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
692 void (*fast_done) (struct ipr_cmnd *))
693{
694 ipr_reinit_ipr_cmnd(ipr_cmd);
695 ipr_cmd->u.scratch = 0;
696 ipr_cmd->sibling = NULL;
697 ipr_cmd->eh_comp = NULL;
698 ipr_cmd->fast_done = fast_done;
699 timer_setup(&ipr_cmd->timer, NULL, 0);
700}
701
702/**
703 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
704 * @ioa_cfg: ioa config struct
705 *
706 * Return value:
707 * pointer to ipr command struct
708 **/
709static
710struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_hrr_queue *hrrq)
711{
712 struct ipr_cmnd *ipr_cmd = NULL;
713
714 if (likely(!list_empty(&hrrq->hrrq_free_q))) {
715 ipr_cmd = list_entry(hrrq->hrrq_free_q.next,
716 struct ipr_cmnd, queue);
717 list_del(&ipr_cmd->queue);
718 }
719
720
721 return ipr_cmd;
722}
723
724/**
725 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
726 * @ioa_cfg: ioa config struct
727 *
728 * Return value:
729 * pointer to ipr command struct
730 **/
731static
732struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
733{
734 struct ipr_cmnd *ipr_cmd =
735 __ipr_get_free_ipr_cmnd(&ioa_cfg->hrrq[IPR_INIT_HRRQ]);
736 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
737 return ipr_cmd;
738}
739
740/**
741 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
742 * @ioa_cfg: ioa config struct
743 * @clr_ints: interrupts to clear
744 *
745 * This function masks all interrupts on the adapter, then clears the
746 * interrupts specified in the mask
747 *
748 * Return value:
749 * none
750 **/
751static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
752 u32 clr_ints)
753{
754 volatile u32 int_reg;
755 int i;
756
757 /* Stop new interrupts */
758 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
759 spin_lock(&ioa_cfg->hrrq[i]._lock);
760 ioa_cfg->hrrq[i].allow_interrupts = 0;
761 spin_unlock(&ioa_cfg->hrrq[i]._lock);
762 }
763
764 /* Set interrupt mask to stop all new interrupts */
765 if (ioa_cfg->sis64)
766 writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
767 else
768 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
769
770 /* Clear any pending interrupts */
771 if (ioa_cfg->sis64)
772 writel(~0, ioa_cfg->regs.clr_interrupt_reg);
773 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
774 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
775}
776
777/**
778 * ipr_save_pcix_cmd_reg - Save PCI-X command register
779 * @ioa_cfg: ioa config struct
780 *
781 * Return value:
782 * 0 on success / -EIO on failure
783 **/
784static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
785{
786 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
787
788 if (pcix_cmd_reg == 0)
789 return 0;
790
791 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
792 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
793 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
794 return -EIO;
795 }
796
797 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
798 return 0;
799}
800
801/**
802 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
803 * @ioa_cfg: ioa config struct
804 *
805 * Return value:
806 * 0 on success / -EIO on failure
807 **/
808static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
809{
810 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
811
812 if (pcix_cmd_reg) {
813 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
814 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
815 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
816 return -EIO;
817 }
818 }
819
820 return 0;
821}
822
823/**
824 * __ipr_sata_eh_done - done function for aborted SATA commands
825 * @ipr_cmd: ipr command struct
826 *
827 * This function is invoked for ops generated to SATA
828 * devices which are being aborted.
829 *
830 * Return value:
831 * none
832 **/
833static void __ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
834{
835 struct ata_queued_cmd *qc = ipr_cmd->qc;
836 struct ipr_sata_port *sata_port = qc->ap->private_data;
837
838 qc->err_mask |= AC_ERR_OTHER;
839 sata_port->ioasa.status |= ATA_BUSY;
840 ata_qc_complete(qc);
841 if (ipr_cmd->eh_comp)
842 complete(ipr_cmd->eh_comp);
843 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
844}
845
846/**
847 * ipr_sata_eh_done - done function for aborted SATA commands
848 * @ipr_cmd: ipr command struct
849 *
850 * This function is invoked for ops generated to SATA
851 * devices which are being aborted.
852 *
853 * Return value:
854 * none
855 **/
856static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
857{
858 struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
859 unsigned long hrrq_flags;
860
861 spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
862 __ipr_sata_eh_done(ipr_cmd);
863 spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
864}
865
866/**
867 * __ipr_scsi_eh_done - mid-layer done function for aborted ops
868 * @ipr_cmd: ipr command struct
869 *
870 * This function is invoked by the interrupt handler for
871 * ops generated by the SCSI mid-layer which are being aborted.
872 *
873 * Return value:
874 * none
875 **/
876static void __ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
877{
878 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
879
880 scsi_cmd->result |= (DID_ERROR << 16);
881
882 scsi_dma_unmap(ipr_cmd->scsi_cmd);
883 scsi_cmd->scsi_done(scsi_cmd);
884 if (ipr_cmd->eh_comp)
885 complete(ipr_cmd->eh_comp);
886 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
887}
888
889/**
890 * ipr_scsi_eh_done - mid-layer done function for aborted ops
891 * @ipr_cmd: ipr command struct
892 *
893 * This function is invoked by the interrupt handler for
894 * ops generated by the SCSI mid-layer which are being aborted.
895 *
896 * Return value:
897 * none
898 **/
899static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
900{
901 unsigned long hrrq_flags;
902 struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
903
904 spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
905 __ipr_scsi_eh_done(ipr_cmd);
906 spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
907}
908
909/**
910 * ipr_fail_all_ops - Fails all outstanding ops.
911 * @ioa_cfg: ioa config struct
912 *
913 * This function fails all outstanding ops.
914 *
915 * Return value:
916 * none
917 **/
918static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
919{
920 struct ipr_cmnd *ipr_cmd, *temp;
921 struct ipr_hrr_queue *hrrq;
922
923 ENTER;
924 for_each_hrrq(hrrq, ioa_cfg) {
925 spin_lock(&hrrq->_lock);
926 list_for_each_entry_safe(ipr_cmd,
927 temp, &hrrq->hrrq_pending_q, queue) {
928 list_del(&ipr_cmd->queue);
929
930 ipr_cmd->s.ioasa.hdr.ioasc =
931 cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
932 ipr_cmd->s.ioasa.hdr.ilid =
933 cpu_to_be32(IPR_DRIVER_ILID);
934
935 if (ipr_cmd->scsi_cmd)
936 ipr_cmd->done = __ipr_scsi_eh_done;
937 else if (ipr_cmd->qc)
938 ipr_cmd->done = __ipr_sata_eh_done;
939
940 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH,
941 IPR_IOASC_IOA_WAS_RESET);
942 del_timer(&ipr_cmd->timer);
943 ipr_cmd->done(ipr_cmd);
944 }
945 spin_unlock(&hrrq->_lock);
946 }
947 LEAVE;
948}
949
950/**
951 * ipr_send_command - Send driver initiated requests.
952 * @ipr_cmd: ipr command struct
953 *
954 * This function sends a command to the adapter using the correct write call.
955 * In the case of sis64, calculate the ioarcb size required. Then or in the
956 * appropriate bits.
957 *
958 * Return value:
959 * none
960 **/
961static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
962{
963 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
964 dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
965
966 if (ioa_cfg->sis64) {
967 /* The default size is 256 bytes */
968 send_dma_addr |= 0x1;
969
970 /* If the number of ioadls * size of ioadl > 128 bytes,
971 then use a 512 byte ioarcb */
972 if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
973 send_dma_addr |= 0x4;
974 writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
975 } else
976 writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
977}
978
979/**
980 * ipr_do_req - Send driver initiated requests.
981 * @ipr_cmd: ipr command struct
982 * @done: done function
983 * @timeout_func: timeout function
984 * @timeout: timeout value
985 *
986 * This function sends the specified command to the adapter with the
987 * timeout given. The done function is invoked on command completion.
988 *
989 * Return value:
990 * none
991 **/
992static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
993 void (*done) (struct ipr_cmnd *),
994 void (*timeout_func) (struct timer_list *), u32 timeout)
995{
996 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
997
998 ipr_cmd->done = done;
999
1000 ipr_cmd->timer.expires = jiffies + timeout;
1001 ipr_cmd->timer.function = timeout_func;
1002
1003 add_timer(&ipr_cmd->timer);
1004
1005 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
1006
1007 ipr_send_command(ipr_cmd);
1008}
1009
1010/**
1011 * ipr_internal_cmd_done - Op done function for an internally generated op.
1012 * @ipr_cmd: ipr command struct
1013 *
1014 * This function is the op done function for an internally generated,
1015 * blocking op. It simply wakes the sleeping thread.
1016 *
1017 * Return value:
1018 * none
1019 **/
1020static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
1021{
1022 if (ipr_cmd->sibling)
1023 ipr_cmd->sibling = NULL;
1024 else
1025 complete(&ipr_cmd->completion);
1026}
1027
1028/**
1029 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
1030 * @ipr_cmd: ipr command struct
1031 * @dma_addr: dma address
1032 * @len: transfer length
1033 * @flags: ioadl flag value
1034 *
1035 * This function initializes an ioadl in the case where there is only a single
1036 * descriptor.
1037 *
1038 * Return value:
1039 * nothing
1040 **/
1041static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
1042 u32 len, int flags)
1043{
1044 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
1045 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
1046
1047 ipr_cmd->dma_use_sg = 1;
1048
1049 if (ipr_cmd->ioa_cfg->sis64) {
1050 ioadl64->flags = cpu_to_be32(flags);
1051 ioadl64->data_len = cpu_to_be32(len);
1052 ioadl64->address = cpu_to_be64(dma_addr);
1053
1054 ipr_cmd->ioarcb.ioadl_len =
1055 cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
1056 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1057 } else {
1058 ioadl->flags_and_data_len = cpu_to_be32(flags | len);
1059 ioadl->address = cpu_to_be32(dma_addr);
1060
1061 if (flags == IPR_IOADL_FLAGS_READ_LAST) {
1062 ipr_cmd->ioarcb.read_ioadl_len =
1063 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1064 ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
1065 } else {
1066 ipr_cmd->ioarcb.ioadl_len =
1067 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1068 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1069 }
1070 }
1071}
1072
1073/**
1074 * ipr_send_blocking_cmd - Send command and sleep on its completion.
1075 * @ipr_cmd: ipr command struct
1076 * @timeout_func: function to invoke if command times out
1077 * @timeout: timeout
1078 *
1079 * Return value:
1080 * none
1081 **/
1082static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
1083 void (*timeout_func) (struct timer_list *),
1084 u32 timeout)
1085{
1086 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1087
1088 init_completion(&ipr_cmd->completion);
1089 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
1090
1091 spin_unlock_irq(ioa_cfg->host->host_lock);
1092 wait_for_completion(&ipr_cmd->completion);
1093 spin_lock_irq(ioa_cfg->host->host_lock);
1094}
1095
1096static int ipr_get_hrrq_index(struct ipr_ioa_cfg *ioa_cfg)
1097{
1098 unsigned int hrrq;
1099
1100 if (ioa_cfg->hrrq_num == 1)
1101 hrrq = 0;
1102 else {
1103 hrrq = atomic_add_return(1, &ioa_cfg->hrrq_index);
1104 hrrq = (hrrq % (ioa_cfg->hrrq_num - 1)) + 1;
1105 }
1106 return hrrq;
1107}
1108
1109/**
1110 * ipr_send_hcam - Send an HCAM to the adapter.
1111 * @ioa_cfg: ioa config struct
1112 * @type: HCAM type
1113 * @hostrcb: hostrcb struct
1114 *
1115 * This function will send a Host Controlled Async command to the adapter.
1116 * If HCAMs are currently not allowed to be issued to the adapter, it will
1117 * place the hostrcb on the free queue.
1118 *
1119 * Return value:
1120 * none
1121 **/
1122static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
1123 struct ipr_hostrcb *hostrcb)
1124{
1125 struct ipr_cmnd *ipr_cmd;
1126 struct ipr_ioarcb *ioarcb;
1127
1128 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
1129 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
1130 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
1131 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
1132
1133 ipr_cmd->u.hostrcb = hostrcb;
1134 ioarcb = &ipr_cmd->ioarcb;
1135
1136 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
1137 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
1138 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
1139 ioarcb->cmd_pkt.cdb[1] = type;
1140 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
1141 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
1142
1143 ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
1144 sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
1145
1146 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
1147 ipr_cmd->done = ipr_process_ccn;
1148 else
1149 ipr_cmd->done = ipr_process_error;
1150
1151 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
1152
1153 ipr_send_command(ipr_cmd);
1154 } else {
1155 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
1156 }
1157}
1158
1159/**
1160 * ipr_update_ata_class - Update the ata class in the resource entry
1161 * @res: resource entry struct
1162 * @proto: cfgte device bus protocol value
1163 *
1164 * Return value:
1165 * none
1166 **/
1167static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
1168{
1169 switch (proto) {
1170 case IPR_PROTO_SATA:
1171 case IPR_PROTO_SAS_STP:
1172 res->ata_class = ATA_DEV_ATA;
1173 break;
1174 case IPR_PROTO_SATA_ATAPI:
1175 case IPR_PROTO_SAS_STP_ATAPI:
1176 res->ata_class = ATA_DEV_ATAPI;
1177 break;
1178 default:
1179 res->ata_class = ATA_DEV_UNKNOWN;
1180 break;
1181 };
1182}
1183
1184/**
1185 * ipr_init_res_entry - Initialize a resource entry struct.
1186 * @res: resource entry struct
1187 * @cfgtew: config table entry wrapper struct
1188 *
1189 * Return value:
1190 * none
1191 **/
1192static void ipr_init_res_entry(struct ipr_resource_entry *res,
1193 struct ipr_config_table_entry_wrapper *cfgtew)
1194{
1195 int found = 0;
1196 unsigned int proto;
1197 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1198 struct ipr_resource_entry *gscsi_res = NULL;
1199
1200 res->needs_sync_complete = 0;
1201 res->in_erp = 0;
1202 res->add_to_ml = 0;
1203 res->del_from_ml = 0;
1204 res->resetting_device = 0;
1205 res->reset_occurred = 0;
1206 res->sdev = NULL;
1207 res->sata_port = NULL;
1208
1209 if (ioa_cfg->sis64) {
1210 proto = cfgtew->u.cfgte64->proto;
1211 res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
1212 res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
1213 res->qmodel = IPR_QUEUEING_MODEL64(res);
1214 res->type = cfgtew->u.cfgte64->res_type;
1215
1216 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1217 sizeof(res->res_path));
1218
1219 res->bus = 0;
1220 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1221 sizeof(res->dev_lun.scsi_lun));
1222 res->lun = scsilun_to_int(&res->dev_lun);
1223
1224 if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1225 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1226 if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1227 found = 1;
1228 res->target = gscsi_res->target;
1229 break;
1230 }
1231 }
1232 if (!found) {
1233 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1234 ioa_cfg->max_devs_supported);
1235 set_bit(res->target, ioa_cfg->target_ids);
1236 }
1237 } else if (res->type == IPR_RES_TYPE_IOAFP) {
1238 res->bus = IPR_IOAFP_VIRTUAL_BUS;
1239 res->target = 0;
1240 } else if (res->type == IPR_RES_TYPE_ARRAY) {
1241 res->bus = IPR_ARRAY_VIRTUAL_BUS;
1242 res->target = find_first_zero_bit(ioa_cfg->array_ids,
1243 ioa_cfg->max_devs_supported);
1244 set_bit(res->target, ioa_cfg->array_ids);
1245 } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1246 res->bus = IPR_VSET_VIRTUAL_BUS;
1247 res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1248 ioa_cfg->max_devs_supported);
1249 set_bit(res->target, ioa_cfg->vset_ids);
1250 } else {
1251 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1252 ioa_cfg->max_devs_supported);
1253 set_bit(res->target, ioa_cfg->target_ids);
1254 }
1255 } else {
1256 proto = cfgtew->u.cfgte->proto;
1257 res->qmodel = IPR_QUEUEING_MODEL(res);
1258 res->flags = cfgtew->u.cfgte->flags;
1259 if (res->flags & IPR_IS_IOA_RESOURCE)
1260 res->type = IPR_RES_TYPE_IOAFP;
1261 else
1262 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1263
1264 res->bus = cfgtew->u.cfgte->res_addr.bus;
1265 res->target = cfgtew->u.cfgte->res_addr.target;
1266 res->lun = cfgtew->u.cfgte->res_addr.lun;
1267 res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
1268 }
1269
1270 ipr_update_ata_class(res, proto);
1271}
1272
1273/**
1274 * ipr_is_same_device - Determine if two devices are the same.
1275 * @res: resource entry struct
1276 * @cfgtew: config table entry wrapper struct
1277 *
1278 * Return value:
1279 * 1 if the devices are the same / 0 otherwise
1280 **/
1281static int ipr_is_same_device(struct ipr_resource_entry *res,
1282 struct ipr_config_table_entry_wrapper *cfgtew)
1283{
1284 if (res->ioa_cfg->sis64) {
1285 if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1286 sizeof(cfgtew->u.cfgte64->dev_id)) &&
1287 !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1288 sizeof(cfgtew->u.cfgte64->lun))) {
1289 return 1;
1290 }
1291 } else {
1292 if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1293 res->target == cfgtew->u.cfgte->res_addr.target &&
1294 res->lun == cfgtew->u.cfgte->res_addr.lun)
1295 return 1;
1296 }
1297
1298 return 0;
1299}
1300
1301/**
1302 * __ipr_format_res_path - Format the resource path for printing.
1303 * @res_path: resource path
1304 * @buf: buffer
1305 * @len: length of buffer provided
1306 *
1307 * Return value:
1308 * pointer to buffer
1309 **/
1310static char *__ipr_format_res_path(u8 *res_path, char *buffer, int len)
1311{
1312 int i;
1313 char *p = buffer;
1314
1315 *p = '\0';
1316 p += snprintf(p, buffer + len - p, "%02X", res_path[0]);
1317 for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
1318 p += snprintf(p, buffer + len - p, "-%02X", res_path[i]);
1319
1320 return buffer;
1321}
1322
1323/**
1324 * ipr_format_res_path - Format the resource path for printing.
1325 * @ioa_cfg: ioa config struct
1326 * @res_path: resource path
1327 * @buf: buffer
1328 * @len: length of buffer provided
1329 *
1330 * Return value:
1331 * pointer to buffer
1332 **/
1333static char *ipr_format_res_path(struct ipr_ioa_cfg *ioa_cfg,
1334 u8 *res_path, char *buffer, int len)
1335{
1336 char *p = buffer;
1337
1338 *p = '\0';
1339 p += snprintf(p, buffer + len - p, "%d/", ioa_cfg->host->host_no);
1340 __ipr_format_res_path(res_path, p, len - (buffer - p));
1341 return buffer;
1342}
1343
1344/**
1345 * ipr_update_res_entry - Update the resource entry.
1346 * @res: resource entry struct
1347 * @cfgtew: config table entry wrapper struct
1348 *
1349 * Return value:
1350 * none
1351 **/
1352static void ipr_update_res_entry(struct ipr_resource_entry *res,
1353 struct ipr_config_table_entry_wrapper *cfgtew)
1354{
1355 char buffer[IPR_MAX_RES_PATH_LENGTH];
1356 unsigned int proto;
1357 int new_path = 0;
1358
1359 if (res->ioa_cfg->sis64) {
1360 res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
1361 res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
1362 res->type = cfgtew->u.cfgte64->res_type;
1363
1364 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1365 sizeof(struct ipr_std_inq_data));
1366
1367 res->qmodel = IPR_QUEUEING_MODEL64(res);
1368 proto = cfgtew->u.cfgte64->proto;
1369 res->res_handle = cfgtew->u.cfgte64->res_handle;
1370 res->dev_id = cfgtew->u.cfgte64->dev_id;
1371
1372 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1373 sizeof(res->dev_lun.scsi_lun));
1374
1375 if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1376 sizeof(res->res_path))) {
1377 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1378 sizeof(res->res_path));
1379 new_path = 1;
1380 }
1381
1382 if (res->sdev && new_path)
1383 sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
1384 ipr_format_res_path(res->ioa_cfg,
1385 res->res_path, buffer, sizeof(buffer)));
1386 } else {
1387 res->flags = cfgtew->u.cfgte->flags;
1388 if (res->flags & IPR_IS_IOA_RESOURCE)
1389 res->type = IPR_RES_TYPE_IOAFP;
1390 else
1391 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1392
1393 memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1394 sizeof(struct ipr_std_inq_data));
1395
1396 res->qmodel = IPR_QUEUEING_MODEL(res);
1397 proto = cfgtew->u.cfgte->proto;
1398 res->res_handle = cfgtew->u.cfgte->res_handle;
1399 }
1400
1401 ipr_update_ata_class(res, proto);
1402}
1403
1404/**
1405 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1406 * for the resource.
1407 * @res: resource entry struct
1408 * @cfgtew: config table entry wrapper struct
1409 *
1410 * Return value:
1411 * none
1412 **/
1413static void ipr_clear_res_target(struct ipr_resource_entry *res)
1414{
1415 struct ipr_resource_entry *gscsi_res = NULL;
1416 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1417
1418 if (!ioa_cfg->sis64)
1419 return;
1420
1421 if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1422 clear_bit(res->target, ioa_cfg->array_ids);
1423 else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1424 clear_bit(res->target, ioa_cfg->vset_ids);
1425 else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1426 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1427 if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1428 return;
1429 clear_bit(res->target, ioa_cfg->target_ids);
1430
1431 } else if (res->bus == 0)
1432 clear_bit(res->target, ioa_cfg->target_ids);
1433}
1434
1435/**
1436 * ipr_handle_config_change - Handle a config change from the adapter
1437 * @ioa_cfg: ioa config struct
1438 * @hostrcb: hostrcb
1439 *
1440 * Return value:
1441 * none
1442 **/
1443static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
1444 struct ipr_hostrcb *hostrcb)
1445{
1446 struct ipr_resource_entry *res = NULL;
1447 struct ipr_config_table_entry_wrapper cfgtew;
1448 __be32 cc_res_handle;
1449
1450 u32 is_ndn = 1;
1451
1452 if (ioa_cfg->sis64) {
1453 cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1454 cc_res_handle = cfgtew.u.cfgte64->res_handle;
1455 } else {
1456 cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1457 cc_res_handle = cfgtew.u.cfgte->res_handle;
1458 }
1459
1460 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1461 if (res->res_handle == cc_res_handle) {
1462 is_ndn = 0;
1463 break;
1464 }
1465 }
1466
1467 if (is_ndn) {
1468 if (list_empty(&ioa_cfg->free_res_q)) {
1469 ipr_send_hcam(ioa_cfg,
1470 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1471 hostrcb);
1472 return;
1473 }
1474
1475 res = list_entry(ioa_cfg->free_res_q.next,
1476 struct ipr_resource_entry, queue);
1477
1478 list_del(&res->queue);
1479 ipr_init_res_entry(res, &cfgtew);
1480 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1481 }
1482
1483 ipr_update_res_entry(res, &cfgtew);
1484
1485 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1486 if (res->sdev) {
1487 res->del_from_ml = 1;
1488 res->res_handle = IPR_INVALID_RES_HANDLE;
1489 schedule_work(&ioa_cfg->work_q);
1490 } else {
1491 ipr_clear_res_target(res);
1492 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
1493 }
1494 } else if (!res->sdev || res->del_from_ml) {
1495 res->add_to_ml = 1;
1496 schedule_work(&ioa_cfg->work_q);
1497 }
1498
1499 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1500}
1501
1502/**
1503 * ipr_process_ccn - Op done function for a CCN.
1504 * @ipr_cmd: ipr command struct
1505 *
1506 * This function is the op done function for a configuration
1507 * change notification host controlled async from the adapter.
1508 *
1509 * Return value:
1510 * none
1511 **/
1512static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1513{
1514 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1515 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1516 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
1517
1518 list_del_init(&hostrcb->queue);
1519 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
1520
1521 if (ioasc) {
1522 if (ioasc != IPR_IOASC_IOA_WAS_RESET &&
1523 ioasc != IPR_IOASC_ABORTED_CMD_TERM_BY_HOST)
1524 dev_err(&ioa_cfg->pdev->dev,
1525 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1526
1527 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1528 } else {
1529 ipr_handle_config_change(ioa_cfg, hostrcb);
1530 }
1531}
1532
1533/**
1534 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1535 * @i: index into buffer
1536 * @buf: string to modify
1537 *
1538 * This function will strip all trailing whitespace, pad the end
1539 * of the string with a single space, and NULL terminate the string.
1540 *
1541 * Return value:
1542 * new length of string
1543 **/
1544static int strip_and_pad_whitespace(int i, char *buf)
1545{
1546 while (i && buf[i] == ' ')
1547 i--;
1548 buf[i+1] = ' ';
1549 buf[i+2] = '\0';
1550 return i + 2;
1551}
1552
1553/**
1554 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1555 * @prefix: string to print at start of printk
1556 * @hostrcb: hostrcb pointer
1557 * @vpd: vendor/product id/sn struct
1558 *
1559 * Return value:
1560 * none
1561 **/
1562static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1563 struct ipr_vpd *vpd)
1564{
1565 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
1566 int i = 0;
1567
1568 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1569 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
1570
1571 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
1572 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
1573
1574 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1575 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1576
1577 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1578}
1579
1580/**
1581 * ipr_log_vpd - Log the passed VPD to the error log.
1582 * @vpd: vendor/product id/sn struct
1583 *
1584 * Return value:
1585 * none
1586 **/
1587static void ipr_log_vpd(struct ipr_vpd *vpd)
1588{
1589 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1590 + IPR_SERIAL_NUM_LEN];
1591
1592 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1593 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
1594 IPR_PROD_ID_LEN);
1595 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1596 ipr_err("Vendor/Product ID: %s\n", buffer);
1597
1598 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
1599 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1600 ipr_err(" Serial Number: %s\n", buffer);
1601}
1602
1603/**
1604 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1605 * @prefix: string to print at start of printk
1606 * @hostrcb: hostrcb pointer
1607 * @vpd: vendor/product id/sn/wwn struct
1608 *
1609 * Return value:
1610 * none
1611 **/
1612static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1613 struct ipr_ext_vpd *vpd)
1614{
1615 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1616 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1617 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1618}
1619
1620/**
1621 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1622 * @vpd: vendor/product id/sn/wwn struct
1623 *
1624 * Return value:
1625 * none
1626 **/
1627static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1628{
1629 ipr_log_vpd(&vpd->vpd);
1630 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1631 be32_to_cpu(vpd->wwid[1]));
1632}
1633
1634/**
1635 * ipr_log_enhanced_cache_error - Log a cache error.
1636 * @ioa_cfg: ioa config struct
1637 * @hostrcb: hostrcb struct
1638 *
1639 * Return value:
1640 * none
1641 **/
1642static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1643 struct ipr_hostrcb *hostrcb)
1644{
1645 struct ipr_hostrcb_type_12_error *error;
1646
1647 if (ioa_cfg->sis64)
1648 error = &hostrcb->hcam.u.error64.u.type_12_error;
1649 else
1650 error = &hostrcb->hcam.u.error.u.type_12_error;
1651
1652 ipr_err("-----Current Configuration-----\n");
1653 ipr_err("Cache Directory Card Information:\n");
1654 ipr_log_ext_vpd(&error->ioa_vpd);
1655 ipr_err("Adapter Card Information:\n");
1656 ipr_log_ext_vpd(&error->cfc_vpd);
1657
1658 ipr_err("-----Expected Configuration-----\n");
1659 ipr_err("Cache Directory Card Information:\n");
1660 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1661 ipr_err("Adapter Card Information:\n");
1662 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1663
1664 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1665 be32_to_cpu(error->ioa_data[0]),
1666 be32_to_cpu(error->ioa_data[1]),
1667 be32_to_cpu(error->ioa_data[2]));
1668}
1669
1670/**
1671 * ipr_log_cache_error - Log a cache error.
1672 * @ioa_cfg: ioa config struct
1673 * @hostrcb: hostrcb struct
1674 *
1675 * Return value:
1676 * none
1677 **/
1678static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1679 struct ipr_hostrcb *hostrcb)
1680{
1681 struct ipr_hostrcb_type_02_error *error =
1682 &hostrcb->hcam.u.error.u.type_02_error;
1683
1684 ipr_err("-----Current Configuration-----\n");
1685 ipr_err("Cache Directory Card Information:\n");
1686 ipr_log_vpd(&error->ioa_vpd);
1687 ipr_err("Adapter Card Information:\n");
1688 ipr_log_vpd(&error->cfc_vpd);
1689
1690 ipr_err("-----Expected Configuration-----\n");
1691 ipr_err("Cache Directory Card Information:\n");
1692 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1693 ipr_err("Adapter Card Information:\n");
1694 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1695
1696 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1697 be32_to_cpu(error->ioa_data[0]),
1698 be32_to_cpu(error->ioa_data[1]),
1699 be32_to_cpu(error->ioa_data[2]));
1700}
1701
1702/**
1703 * ipr_log_enhanced_config_error - Log a configuration error.
1704 * @ioa_cfg: ioa config struct
1705 * @hostrcb: hostrcb struct
1706 *
1707 * Return value:
1708 * none
1709 **/
1710static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1711 struct ipr_hostrcb *hostrcb)
1712{
1713 int errors_logged, i;
1714 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1715 struct ipr_hostrcb_type_13_error *error;
1716
1717 error = &hostrcb->hcam.u.error.u.type_13_error;
1718 errors_logged = be32_to_cpu(error->errors_logged);
1719
1720 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1721 be32_to_cpu(error->errors_detected), errors_logged);
1722
1723 dev_entry = error->dev;
1724
1725 for (i = 0; i < errors_logged; i++, dev_entry++) {
1726 ipr_err_separator;
1727
1728 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1729 ipr_log_ext_vpd(&dev_entry->vpd);
1730
1731 ipr_err("-----New Device Information-----\n");
1732 ipr_log_ext_vpd(&dev_entry->new_vpd);
1733
1734 ipr_err("Cache Directory Card Information:\n");
1735 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1736
1737 ipr_err("Adapter Card Information:\n");
1738 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1739 }
1740}
1741
1742/**
1743 * ipr_log_sis64_config_error - Log a device error.
1744 * @ioa_cfg: ioa config struct
1745 * @hostrcb: hostrcb struct
1746 *
1747 * Return value:
1748 * none
1749 **/
1750static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
1751 struct ipr_hostrcb *hostrcb)
1752{
1753 int errors_logged, i;
1754 struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
1755 struct ipr_hostrcb_type_23_error *error;
1756 char buffer[IPR_MAX_RES_PATH_LENGTH];
1757
1758 error = &hostrcb->hcam.u.error64.u.type_23_error;
1759 errors_logged = be32_to_cpu(error->errors_logged);
1760
1761 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1762 be32_to_cpu(error->errors_detected), errors_logged);
1763
1764 dev_entry = error->dev;
1765
1766 for (i = 0; i < errors_logged; i++, dev_entry++) {
1767 ipr_err_separator;
1768
1769 ipr_err("Device %d : %s", i + 1,
1770 __ipr_format_res_path(dev_entry->res_path,
1771 buffer, sizeof(buffer)));
1772 ipr_log_ext_vpd(&dev_entry->vpd);
1773
1774 ipr_err("-----New Device Information-----\n");
1775 ipr_log_ext_vpd(&dev_entry->new_vpd);
1776
1777 ipr_err("Cache Directory Card Information:\n");
1778 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1779
1780 ipr_err("Adapter Card Information:\n");
1781 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1782 }
1783}
1784
1785/**
1786 * ipr_log_config_error - Log a configuration error.
1787 * @ioa_cfg: ioa config struct
1788 * @hostrcb: hostrcb struct
1789 *
1790 * Return value:
1791 * none
1792 **/
1793static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1794 struct ipr_hostrcb *hostrcb)
1795{
1796 int errors_logged, i;
1797 struct ipr_hostrcb_device_data_entry *dev_entry;
1798 struct ipr_hostrcb_type_03_error *error;
1799
1800 error = &hostrcb->hcam.u.error.u.type_03_error;
1801 errors_logged = be32_to_cpu(error->errors_logged);
1802
1803 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1804 be32_to_cpu(error->errors_detected), errors_logged);
1805
1806 dev_entry = error->dev;
1807
1808 for (i = 0; i < errors_logged; i++, dev_entry++) {
1809 ipr_err_separator;
1810
1811 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1812 ipr_log_vpd(&dev_entry->vpd);
1813
1814 ipr_err("-----New Device Information-----\n");
1815 ipr_log_vpd(&dev_entry->new_vpd);
1816
1817 ipr_err("Cache Directory Card Information:\n");
1818 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1819
1820 ipr_err("Adapter Card Information:\n");
1821 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1822
1823 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1824 be32_to_cpu(dev_entry->ioa_data[0]),
1825 be32_to_cpu(dev_entry->ioa_data[1]),
1826 be32_to_cpu(dev_entry->ioa_data[2]),
1827 be32_to_cpu(dev_entry->ioa_data[3]),
1828 be32_to_cpu(dev_entry->ioa_data[4]));
1829 }
1830}
1831
1832/**
1833 * ipr_log_enhanced_array_error - Log an array configuration error.
1834 * @ioa_cfg: ioa config struct
1835 * @hostrcb: hostrcb struct
1836 *
1837 * Return value:
1838 * none
1839 **/
1840static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1841 struct ipr_hostrcb *hostrcb)
1842{
1843 int i, num_entries;
1844 struct ipr_hostrcb_type_14_error *error;
1845 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1846 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1847
1848 error = &hostrcb->hcam.u.error.u.type_14_error;
1849
1850 ipr_err_separator;
1851
1852 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1853 error->protection_level,
1854 ioa_cfg->host->host_no,
1855 error->last_func_vset_res_addr.bus,
1856 error->last_func_vset_res_addr.target,
1857 error->last_func_vset_res_addr.lun);
1858
1859 ipr_err_separator;
1860
1861 array_entry = error->array_member;
1862 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1863 ARRAY_SIZE(error->array_member));
1864
1865 for (i = 0; i < num_entries; i++, array_entry++) {
1866 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1867 continue;
1868
1869 if (be32_to_cpu(error->exposed_mode_adn) == i)
1870 ipr_err("Exposed Array Member %d:\n", i);
1871 else
1872 ipr_err("Array Member %d:\n", i);
1873
1874 ipr_log_ext_vpd(&array_entry->vpd);
1875 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1876 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1877 "Expected Location");
1878
1879 ipr_err_separator;
1880 }
1881}
1882
1883/**
1884 * ipr_log_array_error - Log an array configuration error.
1885 * @ioa_cfg: ioa config struct
1886 * @hostrcb: hostrcb struct
1887 *
1888 * Return value:
1889 * none
1890 **/
1891static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1892 struct ipr_hostrcb *hostrcb)
1893{
1894 int i;
1895 struct ipr_hostrcb_type_04_error *error;
1896 struct ipr_hostrcb_array_data_entry *array_entry;
1897 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1898
1899 error = &hostrcb->hcam.u.error.u.type_04_error;
1900
1901 ipr_err_separator;
1902
1903 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1904 error->protection_level,
1905 ioa_cfg->host->host_no,
1906 error->last_func_vset_res_addr.bus,
1907 error->last_func_vset_res_addr.target,
1908 error->last_func_vset_res_addr.lun);
1909
1910 ipr_err_separator;
1911
1912 array_entry = error->array_member;
1913
1914 for (i = 0; i < 18; i++) {
1915 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1916 continue;
1917
1918 if (be32_to_cpu(error->exposed_mode_adn) == i)
1919 ipr_err("Exposed Array Member %d:\n", i);
1920 else
1921 ipr_err("Array Member %d:\n", i);
1922
1923 ipr_log_vpd(&array_entry->vpd);
1924
1925 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1926 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1927 "Expected Location");
1928
1929 ipr_err_separator;
1930
1931 if (i == 9)
1932 array_entry = error->array_member2;
1933 else
1934 array_entry++;
1935 }
1936}
1937
1938/**
1939 * ipr_log_hex_data - Log additional hex IOA error data.
1940 * @ioa_cfg: ioa config struct
1941 * @data: IOA error data
1942 * @len: data length
1943 *
1944 * Return value:
1945 * none
1946 **/
1947static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, __be32 *data, int len)
1948{
1949 int i;
1950
1951 if (len == 0)
1952 return;
1953
1954 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1955 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1956
1957 for (i = 0; i < len / 4; i += 4) {
1958 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1959 be32_to_cpu(data[i]),
1960 be32_to_cpu(data[i+1]),
1961 be32_to_cpu(data[i+2]),
1962 be32_to_cpu(data[i+3]));
1963 }
1964}
1965
1966/**
1967 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1968 * @ioa_cfg: ioa config struct
1969 * @hostrcb: hostrcb struct
1970 *
1971 * Return value:
1972 * none
1973 **/
1974static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1975 struct ipr_hostrcb *hostrcb)
1976{
1977 struct ipr_hostrcb_type_17_error *error;
1978
1979 if (ioa_cfg->sis64)
1980 error = &hostrcb->hcam.u.error64.u.type_17_error;
1981 else
1982 error = &hostrcb->hcam.u.error.u.type_17_error;
1983
1984 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1985 strim(error->failure_reason);
1986
1987 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1988 be32_to_cpu(hostrcb->hcam.u.error.prc));
1989 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1990 ipr_log_hex_data(ioa_cfg, error->data,
1991 be32_to_cpu(hostrcb->hcam.length) -
1992 (offsetof(struct ipr_hostrcb_error, u) +
1993 offsetof(struct ipr_hostrcb_type_17_error, data)));
1994}
1995
1996/**
1997 * ipr_log_dual_ioa_error - Log a dual adapter error.
1998 * @ioa_cfg: ioa config struct
1999 * @hostrcb: hostrcb struct
2000 *
2001 * Return value:
2002 * none
2003 **/
2004static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
2005 struct ipr_hostrcb *hostrcb)
2006{
2007 struct ipr_hostrcb_type_07_error *error;
2008
2009 error = &hostrcb->hcam.u.error.u.type_07_error;
2010 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2011 strim(error->failure_reason);
2012
2013 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
2014 be32_to_cpu(hostrcb->hcam.u.error.prc));
2015 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
2016 ipr_log_hex_data(ioa_cfg, error->data,
2017 be32_to_cpu(hostrcb->hcam.length) -
2018 (offsetof(struct ipr_hostrcb_error, u) +
2019 offsetof(struct ipr_hostrcb_type_07_error, data)));
2020}
2021
2022static const struct {
2023 u8 active;
2024 char *desc;
2025} path_active_desc[] = {
2026 { IPR_PATH_NO_INFO, "Path" },
2027 { IPR_PATH_ACTIVE, "Active path" },
2028 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
2029};
2030
2031static const struct {
2032 u8 state;
2033 char *desc;
2034} path_state_desc[] = {
2035 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
2036 { IPR_PATH_HEALTHY, "is healthy" },
2037 { IPR_PATH_DEGRADED, "is degraded" },
2038 { IPR_PATH_FAILED, "is failed" }
2039};
2040
2041/**
2042 * ipr_log_fabric_path - Log a fabric path error
2043 * @hostrcb: hostrcb struct
2044 * @fabric: fabric descriptor
2045 *
2046 * Return value:
2047 * none
2048 **/
2049static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
2050 struct ipr_hostrcb_fabric_desc *fabric)
2051{
2052 int i, j;
2053 u8 path_state = fabric->path_state;
2054 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
2055 u8 state = path_state & IPR_PATH_STATE_MASK;
2056
2057 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
2058 if (path_active_desc[i].active != active)
2059 continue;
2060
2061 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2062 if (path_state_desc[j].state != state)
2063 continue;
2064
2065 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
2066 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
2067 path_active_desc[i].desc, path_state_desc[j].desc,
2068 fabric->ioa_port);
2069 } else if (fabric->cascaded_expander == 0xff) {
2070 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
2071 path_active_desc[i].desc, path_state_desc[j].desc,
2072 fabric->ioa_port, fabric->phy);
2073 } else if (fabric->phy == 0xff) {
2074 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
2075 path_active_desc[i].desc, path_state_desc[j].desc,
2076 fabric->ioa_port, fabric->cascaded_expander);
2077 } else {
2078 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
2079 path_active_desc[i].desc, path_state_desc[j].desc,
2080 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2081 }
2082 return;
2083 }
2084 }
2085
2086 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
2087 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2088}
2089
2090/**
2091 * ipr_log64_fabric_path - Log a fabric path error
2092 * @hostrcb: hostrcb struct
2093 * @fabric: fabric descriptor
2094 *
2095 * Return value:
2096 * none
2097 **/
2098static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
2099 struct ipr_hostrcb64_fabric_desc *fabric)
2100{
2101 int i, j;
2102 u8 path_state = fabric->path_state;
2103 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
2104 u8 state = path_state & IPR_PATH_STATE_MASK;
2105 char buffer[IPR_MAX_RES_PATH_LENGTH];
2106
2107 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
2108 if (path_active_desc[i].active != active)
2109 continue;
2110
2111 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2112 if (path_state_desc[j].state != state)
2113 continue;
2114
2115 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
2116 path_active_desc[i].desc, path_state_desc[j].desc,
2117 ipr_format_res_path(hostrcb->ioa_cfg,
2118 fabric->res_path,
2119 buffer, sizeof(buffer)));
2120 return;
2121 }
2122 }
2123
2124 ipr_err("Path state=%02X Resource Path=%s\n", path_state,
2125 ipr_format_res_path(hostrcb->ioa_cfg, fabric->res_path,
2126 buffer, sizeof(buffer)));
2127}
2128
2129static const struct {
2130 u8 type;
2131 char *desc;
2132} path_type_desc[] = {
2133 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
2134 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
2135 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
2136 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
2137};
2138
2139static const struct {
2140 u8 status;
2141 char *desc;
2142} path_status_desc[] = {
2143 { IPR_PATH_CFG_NO_PROB, "Functional" },
2144 { IPR_PATH_CFG_DEGRADED, "Degraded" },
2145 { IPR_PATH_CFG_FAILED, "Failed" },
2146 { IPR_PATH_CFG_SUSPECT, "Suspect" },
2147 { IPR_PATH_NOT_DETECTED, "Missing" },
2148 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
2149};
2150
2151static const char *link_rate[] = {
2152 "unknown",
2153 "disabled",
2154 "phy reset problem",
2155 "spinup hold",
2156 "port selector",
2157 "unknown",
2158 "unknown",
2159 "unknown",
2160 "1.5Gbps",
2161 "3.0Gbps",
2162 "unknown",
2163 "unknown",
2164 "unknown",
2165 "unknown",
2166 "unknown",
2167 "unknown"
2168};
2169
2170/**
2171 * ipr_log_path_elem - Log a fabric path element.
2172 * @hostrcb: hostrcb struct
2173 * @cfg: fabric path element struct
2174 *
2175 * Return value:
2176 * none
2177 **/
2178static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
2179 struct ipr_hostrcb_config_element *cfg)
2180{
2181 int i, j;
2182 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2183 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2184
2185 if (type == IPR_PATH_CFG_NOT_EXIST)
2186 return;
2187
2188 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2189 if (path_type_desc[i].type != type)
2190 continue;
2191
2192 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2193 if (path_status_desc[j].status != status)
2194 continue;
2195
2196 if (type == IPR_PATH_CFG_IOA_PORT) {
2197 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
2198 path_status_desc[j].desc, path_type_desc[i].desc,
2199 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2200 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2201 } else {
2202 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
2203 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2204 path_status_desc[j].desc, path_type_desc[i].desc,
2205 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2206 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2207 } else if (cfg->cascaded_expander == 0xff) {
2208 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
2209 "WWN=%08X%08X\n", path_status_desc[j].desc,
2210 path_type_desc[i].desc, cfg->phy,
2211 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2212 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2213 } else if (cfg->phy == 0xff) {
2214 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
2215 "WWN=%08X%08X\n", path_status_desc[j].desc,
2216 path_type_desc[i].desc, cfg->cascaded_expander,
2217 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2218 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2219 } else {
2220 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2221 "WWN=%08X%08X\n", path_status_desc[j].desc,
2222 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
2223 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2224 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2225 }
2226 }
2227 return;
2228 }
2229 }
2230
2231 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2232 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
2233 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2234 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2235}
2236
2237/**
2238 * ipr_log64_path_elem - Log a fabric path element.
2239 * @hostrcb: hostrcb struct
2240 * @cfg: fabric path element struct
2241 *
2242 * Return value:
2243 * none
2244 **/
2245static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
2246 struct ipr_hostrcb64_config_element *cfg)
2247{
2248 int i, j;
2249 u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
2250 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2251 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2252 char buffer[IPR_MAX_RES_PATH_LENGTH];
2253
2254 if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
2255 return;
2256
2257 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2258 if (path_type_desc[i].type != type)
2259 continue;
2260
2261 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2262 if (path_status_desc[j].status != status)
2263 continue;
2264
2265 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2266 path_status_desc[j].desc, path_type_desc[i].desc,
2267 ipr_format_res_path(hostrcb->ioa_cfg,
2268 cfg->res_path, buffer, sizeof(buffer)),
2269 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2270 be32_to_cpu(cfg->wwid[0]),
2271 be32_to_cpu(cfg->wwid[1]));
2272 return;
2273 }
2274 }
2275 ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
2276 "WWN=%08X%08X\n", cfg->type_status,
2277 ipr_format_res_path(hostrcb->ioa_cfg,
2278 cfg->res_path, buffer, sizeof(buffer)),
2279 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2280 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2281}
2282
2283/**
2284 * ipr_log_fabric_error - Log a fabric error.
2285 * @ioa_cfg: ioa config struct
2286 * @hostrcb: hostrcb struct
2287 *
2288 * Return value:
2289 * none
2290 **/
2291static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2292 struct ipr_hostrcb *hostrcb)
2293{
2294 struct ipr_hostrcb_type_20_error *error;
2295 struct ipr_hostrcb_fabric_desc *fabric;
2296 struct ipr_hostrcb_config_element *cfg;
2297 int i, add_len;
2298
2299 error = &hostrcb->hcam.u.error.u.type_20_error;
2300 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2301 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2302
2303 add_len = be32_to_cpu(hostrcb->hcam.length) -
2304 (offsetof(struct ipr_hostrcb_error, u) +
2305 offsetof(struct ipr_hostrcb_type_20_error, desc));
2306
2307 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2308 ipr_log_fabric_path(hostrcb, fabric);
2309 for_each_fabric_cfg(fabric, cfg)
2310 ipr_log_path_elem(hostrcb, cfg);
2311
2312 add_len -= be16_to_cpu(fabric->length);
2313 fabric = (struct ipr_hostrcb_fabric_desc *)
2314 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2315 }
2316
2317 ipr_log_hex_data(ioa_cfg, (__be32 *)fabric, add_len);
2318}
2319
2320/**
2321 * ipr_log_sis64_array_error - Log a sis64 array error.
2322 * @ioa_cfg: ioa config struct
2323 * @hostrcb: hostrcb struct
2324 *
2325 * Return value:
2326 * none
2327 **/
2328static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
2329 struct ipr_hostrcb *hostrcb)
2330{
2331 int i, num_entries;
2332 struct ipr_hostrcb_type_24_error *error;
2333 struct ipr_hostrcb64_array_data_entry *array_entry;
2334 char buffer[IPR_MAX_RES_PATH_LENGTH];
2335 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
2336
2337 error = &hostrcb->hcam.u.error64.u.type_24_error;
2338
2339 ipr_err_separator;
2340
2341 ipr_err("RAID %s Array Configuration: %s\n",
2342 error->protection_level,
2343 ipr_format_res_path(ioa_cfg, error->last_res_path,
2344 buffer, sizeof(buffer)));
2345
2346 ipr_err_separator;
2347
2348 array_entry = error->array_member;
2349 num_entries = min_t(u32, error->num_entries,
2350 ARRAY_SIZE(error->array_member));
2351
2352 for (i = 0; i < num_entries; i++, array_entry++) {
2353
2354 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
2355 continue;
2356
2357 if (error->exposed_mode_adn == i)
2358 ipr_err("Exposed Array Member %d:\n", i);
2359 else
2360 ipr_err("Array Member %d:\n", i);
2361
2362 ipr_err("Array Member %d:\n", i);
2363 ipr_log_ext_vpd(&array_entry->vpd);
2364 ipr_err("Current Location: %s\n",
2365 ipr_format_res_path(ioa_cfg, array_entry->res_path,
2366 buffer, sizeof(buffer)));
2367 ipr_err("Expected Location: %s\n",
2368 ipr_format_res_path(ioa_cfg,
2369 array_entry->expected_res_path,
2370 buffer, sizeof(buffer)));
2371
2372 ipr_err_separator;
2373 }
2374}
2375
2376/**
2377 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2378 * @ioa_cfg: ioa config struct
2379 * @hostrcb: hostrcb struct
2380 *
2381 * Return value:
2382 * none
2383 **/
2384static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2385 struct ipr_hostrcb *hostrcb)
2386{
2387 struct ipr_hostrcb_type_30_error *error;
2388 struct ipr_hostrcb64_fabric_desc *fabric;
2389 struct ipr_hostrcb64_config_element *cfg;
2390 int i, add_len;
2391
2392 error = &hostrcb->hcam.u.error64.u.type_30_error;
2393
2394 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2395 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2396
2397 add_len = be32_to_cpu(hostrcb->hcam.length) -
2398 (offsetof(struct ipr_hostrcb64_error, u) +
2399 offsetof(struct ipr_hostrcb_type_30_error, desc));
2400
2401 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2402 ipr_log64_fabric_path(hostrcb, fabric);
2403 for_each_fabric_cfg(fabric, cfg)
2404 ipr_log64_path_elem(hostrcb, cfg);
2405
2406 add_len -= be16_to_cpu(fabric->length);
2407 fabric = (struct ipr_hostrcb64_fabric_desc *)
2408 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2409 }
2410
2411 ipr_log_hex_data(ioa_cfg, (__be32 *)fabric, add_len);
2412}
2413
2414/**
2415 * ipr_log_sis64_service_required_error - Log a sis64 service required error.
2416 * @ioa_cfg: ioa config struct
2417 * @hostrcb: hostrcb struct
2418 *
2419 * Return value:
2420 * none
2421 **/
2422static void ipr_log_sis64_service_required_error(struct ipr_ioa_cfg *ioa_cfg,
2423 struct ipr_hostrcb *hostrcb)
2424{
2425 struct ipr_hostrcb_type_41_error *error;
2426
2427 error = &hostrcb->hcam.u.error64.u.type_41_error;
2428
2429 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2430 ipr_err("Primary Failure Reason: %s\n", error->failure_reason);
2431 ipr_log_hex_data(ioa_cfg, error->data,
2432 be32_to_cpu(hostrcb->hcam.length) -
2433 (offsetof(struct ipr_hostrcb_error, u) +
2434 offsetof(struct ipr_hostrcb_type_41_error, data)));
2435}
2436/**
2437 * ipr_log_generic_error - Log an adapter error.
2438 * @ioa_cfg: ioa config struct
2439 * @hostrcb: hostrcb struct
2440 *
2441 * Return value:
2442 * none
2443 **/
2444static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
2445 struct ipr_hostrcb *hostrcb)
2446{
2447 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
2448 be32_to_cpu(hostrcb->hcam.length));
2449}
2450
2451/**
2452 * ipr_log_sis64_device_error - Log a cache error.
2453 * @ioa_cfg: ioa config struct
2454 * @hostrcb: hostrcb struct
2455 *
2456 * Return value:
2457 * none
2458 **/
2459static void ipr_log_sis64_device_error(struct ipr_ioa_cfg *ioa_cfg,
2460 struct ipr_hostrcb *hostrcb)
2461{
2462 struct ipr_hostrcb_type_21_error *error;
2463 char buffer[IPR_MAX_RES_PATH_LENGTH];
2464
2465 error = &hostrcb->hcam.u.error64.u.type_21_error;
2466
2467 ipr_err("-----Failing Device Information-----\n");
2468 ipr_err("World Wide Unique ID: %08X%08X%08X%08X\n",
2469 be32_to_cpu(error->wwn[0]), be32_to_cpu(error->wwn[1]),
2470 be32_to_cpu(error->wwn[2]), be32_to_cpu(error->wwn[3]));
2471 ipr_err("Device Resource Path: %s\n",
2472 __ipr_format_res_path(error->res_path,
2473 buffer, sizeof(buffer)));
2474 error->primary_problem_desc[sizeof(error->primary_problem_desc) - 1] = '\0';
2475 error->second_problem_desc[sizeof(error->second_problem_desc) - 1] = '\0';
2476 ipr_err("Primary Problem Description: %s\n", error->primary_problem_desc);
2477 ipr_err("Secondary Problem Description: %s\n", error->second_problem_desc);
2478 ipr_err("SCSI Sense Data:\n");
2479 ipr_log_hex_data(ioa_cfg, error->sense_data, sizeof(error->sense_data));
2480 ipr_err("SCSI Command Descriptor Block: \n");
2481 ipr_log_hex_data(ioa_cfg, error->cdb, sizeof(error->cdb));
2482
2483 ipr_err("Additional IOA Data:\n");
2484 ipr_log_hex_data(ioa_cfg, error->ioa_data, be32_to_cpu(error->length_of_error));
2485}
2486
2487/**
2488 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2489 * @ioasc: IOASC
2490 *
2491 * This function will return the index of into the ipr_error_table
2492 * for the specified IOASC. If the IOASC is not in the table,
2493 * 0 will be returned, which points to the entry used for unknown errors.
2494 *
2495 * Return value:
2496 * index into the ipr_error_table
2497 **/
2498static u32 ipr_get_error(u32 ioasc)
2499{
2500 int i;
2501
2502 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
2503 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
2504 return i;
2505
2506 return 0;
2507}
2508
2509/**
2510 * ipr_handle_log_data - Log an adapter error.
2511 * @ioa_cfg: ioa config struct
2512 * @hostrcb: hostrcb struct
2513 *
2514 * This function logs an adapter error to the system.
2515 *
2516 * Return value:
2517 * none
2518 **/
2519static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
2520 struct ipr_hostrcb *hostrcb)
2521{
2522 u32 ioasc;
2523 int error_index;
2524 struct ipr_hostrcb_type_21_error *error;
2525
2526 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
2527 return;
2528
2529 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
2530 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
2531
2532 if (ioa_cfg->sis64)
2533 ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2534 else
2535 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2536
2537 if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
2538 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
2539 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2540 scsi_report_bus_reset(ioa_cfg->host,
2541 hostrcb->hcam.u.error.fd_res_addr.bus);
2542 }
2543
2544 error_index = ipr_get_error(ioasc);
2545
2546 if (!ipr_error_table[error_index].log_hcam)
2547 return;
2548
2549 if (ioasc == IPR_IOASC_HW_CMD_FAILED &&
2550 hostrcb->hcam.overlay_id == IPR_HOST_RCB_OVERLAY_ID_21) {
2551 error = &hostrcb->hcam.u.error64.u.type_21_error;
2552
2553 if (((be32_to_cpu(error->sense_data[0]) & 0x0000ff00) >> 8) == ILLEGAL_REQUEST &&
2554 ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
2555 return;
2556 }
2557
2558 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
2559
2560 /* Set indication we have logged an error */
2561 ioa_cfg->errors_logged++;
2562
2563 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
2564 return;
2565 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
2566 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
2567
2568 switch (hostrcb->hcam.overlay_id) {
2569 case IPR_HOST_RCB_OVERLAY_ID_2:
2570 ipr_log_cache_error(ioa_cfg, hostrcb);
2571 break;
2572 case IPR_HOST_RCB_OVERLAY_ID_3:
2573 ipr_log_config_error(ioa_cfg, hostrcb);
2574 break;
2575 case IPR_HOST_RCB_OVERLAY_ID_4:
2576 case IPR_HOST_RCB_OVERLAY_ID_6:
2577 ipr_log_array_error(ioa_cfg, hostrcb);
2578 break;
2579 case IPR_HOST_RCB_OVERLAY_ID_7:
2580 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
2581 break;
2582 case IPR_HOST_RCB_OVERLAY_ID_12:
2583 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
2584 break;
2585 case IPR_HOST_RCB_OVERLAY_ID_13:
2586 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
2587 break;
2588 case IPR_HOST_RCB_OVERLAY_ID_14:
2589 case IPR_HOST_RCB_OVERLAY_ID_16:
2590 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
2591 break;
2592 case IPR_HOST_RCB_OVERLAY_ID_17:
2593 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
2594 break;
2595 case IPR_HOST_RCB_OVERLAY_ID_20:
2596 ipr_log_fabric_error(ioa_cfg, hostrcb);
2597 break;
2598 case IPR_HOST_RCB_OVERLAY_ID_21:
2599 ipr_log_sis64_device_error(ioa_cfg, hostrcb);
2600 break;
2601 case IPR_HOST_RCB_OVERLAY_ID_23:
2602 ipr_log_sis64_config_error(ioa_cfg, hostrcb);
2603 break;
2604 case IPR_HOST_RCB_OVERLAY_ID_24:
2605 case IPR_HOST_RCB_OVERLAY_ID_26:
2606 ipr_log_sis64_array_error(ioa_cfg, hostrcb);
2607 break;
2608 case IPR_HOST_RCB_OVERLAY_ID_30:
2609 ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
2610 break;
2611 case IPR_HOST_RCB_OVERLAY_ID_41:
2612 ipr_log_sis64_service_required_error(ioa_cfg, hostrcb);
2613 break;
2614 case IPR_HOST_RCB_OVERLAY_ID_1:
2615 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
2616 default:
2617 ipr_log_generic_error(ioa_cfg, hostrcb);
2618 break;
2619 }
2620}
2621
2622static struct ipr_hostrcb *ipr_get_free_hostrcb(struct ipr_ioa_cfg *ioa)
2623{
2624 struct ipr_hostrcb *hostrcb;
2625
2626 hostrcb = list_first_entry_or_null(&ioa->hostrcb_free_q,
2627 struct ipr_hostrcb, queue);
2628
2629 if (unlikely(!hostrcb)) {
2630 dev_info(&ioa->pdev->dev, "Reclaiming async error buffers.");
2631 hostrcb = list_first_entry_or_null(&ioa->hostrcb_report_q,
2632 struct ipr_hostrcb, queue);
2633 }
2634
2635 list_del_init(&hostrcb->queue);
2636 return hostrcb;
2637}
2638
2639/**
2640 * ipr_process_error - Op done function for an adapter error log.
2641 * @ipr_cmd: ipr command struct
2642 *
2643 * This function is the op done function for an error log host
2644 * controlled async from the adapter. It will log the error and
2645 * send the HCAM back to the adapter.
2646 *
2647 * Return value:
2648 * none
2649 **/
2650static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2651{
2652 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2653 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
2654 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
2655 u32 fd_ioasc;
2656
2657 if (ioa_cfg->sis64)
2658 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2659 else
2660 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2661
2662 list_del_init(&hostrcb->queue);
2663 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
2664
2665 if (!ioasc) {
2666 ipr_handle_log_data(ioa_cfg, hostrcb);
2667 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
2668 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
2669 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET &&
2670 ioasc != IPR_IOASC_ABORTED_CMD_TERM_BY_HOST) {
2671 dev_err(&ioa_cfg->pdev->dev,
2672 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
2673 }
2674
2675 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_report_q);
2676 schedule_work(&ioa_cfg->work_q);
2677 hostrcb = ipr_get_free_hostrcb(ioa_cfg);
2678
2679 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2680}
2681
2682/**
2683 * ipr_timeout - An internally generated op has timed out.
2684 * @ipr_cmd: ipr command struct
2685 *
2686 * This function blocks host requests and initiates an
2687 * adapter reset.
2688 *
2689 * Return value:
2690 * none
2691 **/
2692static void ipr_timeout(struct timer_list *t)
2693{
2694 struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
2695 unsigned long lock_flags = 0;
2696 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2697
2698 ENTER;
2699 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2700
2701 ioa_cfg->errors_logged++;
2702 dev_err(&ioa_cfg->pdev->dev,
2703 "Adapter being reset due to command timeout.\n");
2704
2705 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2706 ioa_cfg->sdt_state = GET_DUMP;
2707
2708 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
2709 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2710
2711 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2712 LEAVE;
2713}
2714
2715/**
2716 * ipr_oper_timeout - Adapter timed out transitioning to operational
2717 * @ipr_cmd: ipr command struct
2718 *
2719 * This function blocks host requests and initiates an
2720 * adapter reset.
2721 *
2722 * Return value:
2723 * none
2724 **/
2725static void ipr_oper_timeout(struct timer_list *t)
2726{
2727 struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
2728 unsigned long lock_flags = 0;
2729 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2730
2731 ENTER;
2732 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2733
2734 ioa_cfg->errors_logged++;
2735 dev_err(&ioa_cfg->pdev->dev,
2736 "Adapter timed out transitioning to operational.\n");
2737
2738 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2739 ioa_cfg->sdt_state = GET_DUMP;
2740
2741 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
2742 if (ipr_fastfail)
2743 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
2744 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2745 }
2746
2747 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2748 LEAVE;
2749}
2750
2751/**
2752 * ipr_find_ses_entry - Find matching SES in SES table
2753 * @res: resource entry struct of SES
2754 *
2755 * Return value:
2756 * pointer to SES table entry / NULL on failure
2757 **/
2758static const struct ipr_ses_table_entry *
2759ipr_find_ses_entry(struct ipr_resource_entry *res)
2760{
2761 int i, j, matches;
2762 struct ipr_std_inq_vpids *vpids;
2763 const struct ipr_ses_table_entry *ste = ipr_ses_table;
2764
2765 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
2766 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
2767 if (ste->compare_product_id_byte[j] == 'X') {
2768 vpids = &res->std_inq_data.vpids;
2769 if (vpids->product_id[j] == ste->product_id[j])
2770 matches++;
2771 else
2772 break;
2773 } else
2774 matches++;
2775 }
2776
2777 if (matches == IPR_PROD_ID_LEN)
2778 return ste;
2779 }
2780
2781 return NULL;
2782}
2783
2784/**
2785 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2786 * @ioa_cfg: ioa config struct
2787 * @bus: SCSI bus
2788 * @bus_width: bus width
2789 *
2790 * Return value:
2791 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2792 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2793 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2794 * max 160MHz = max 320MB/sec).
2795 **/
2796static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
2797{
2798 struct ipr_resource_entry *res;
2799 const struct ipr_ses_table_entry *ste;
2800 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
2801
2802 /* Loop through each config table entry in the config table buffer */
2803 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2804 if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
2805 continue;
2806
2807 if (bus != res->bus)
2808 continue;
2809
2810 if (!(ste = ipr_find_ses_entry(res)))
2811 continue;
2812
2813 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
2814 }
2815
2816 return max_xfer_rate;
2817}
2818
2819/**
2820 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2821 * @ioa_cfg: ioa config struct
2822 * @max_delay: max delay in micro-seconds to wait
2823 *
2824 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2825 *
2826 * Return value:
2827 * 0 on success / other on failure
2828 **/
2829static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
2830{
2831 volatile u32 pcii_reg;
2832 int delay = 1;
2833
2834 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2835 while (delay < max_delay) {
2836 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
2837
2838 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
2839 return 0;
2840
2841 /* udelay cannot be used if delay is more than a few milliseconds */
2842 if ((delay / 1000) > MAX_UDELAY_MS)
2843 mdelay(delay / 1000);
2844 else
2845 udelay(delay);
2846
2847 delay += delay;
2848 }
2849 return -EIO;
2850}
2851
2852/**
2853 * ipr_get_sis64_dump_data_section - Dump IOA memory
2854 * @ioa_cfg: ioa config struct
2855 * @start_addr: adapter address to dump
2856 * @dest: destination kernel buffer
2857 * @length_in_words: length to dump in 4 byte words
2858 *
2859 * Return value:
2860 * 0 on success
2861 **/
2862static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2863 u32 start_addr,
2864 __be32 *dest, u32 length_in_words)
2865{
2866 int i;
2867
2868 for (i = 0; i < length_in_words; i++) {
2869 writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
2870 *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
2871 dest++;
2872 }
2873
2874 return 0;
2875}
2876
2877/**
2878 * ipr_get_ldump_data_section - Dump IOA memory
2879 * @ioa_cfg: ioa config struct
2880 * @start_addr: adapter address to dump
2881 * @dest: destination kernel buffer
2882 * @length_in_words: length to dump in 4 byte words
2883 *
2884 * Return value:
2885 * 0 on success / -EIO on failure
2886 **/
2887static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2888 u32 start_addr,
2889 __be32 *dest, u32 length_in_words)
2890{
2891 volatile u32 temp_pcii_reg;
2892 int i, delay = 0;
2893
2894 if (ioa_cfg->sis64)
2895 return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
2896 dest, length_in_words);
2897
2898 /* Write IOA interrupt reg starting LDUMP state */
2899 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
2900 ioa_cfg->regs.set_uproc_interrupt_reg32);
2901
2902 /* Wait for IO debug acknowledge */
2903 if (ipr_wait_iodbg_ack(ioa_cfg,
2904 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
2905 dev_err(&ioa_cfg->pdev->dev,
2906 "IOA dump long data transfer timeout\n");
2907 return -EIO;
2908 }
2909
2910 /* Signal LDUMP interlocked - clear IO debug ack */
2911 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2912 ioa_cfg->regs.clr_interrupt_reg);
2913
2914 /* Write Mailbox with starting address */
2915 writel(start_addr, ioa_cfg->ioa_mailbox);
2916
2917 /* Signal address valid - clear IOA Reset alert */
2918 writel(IPR_UPROCI_RESET_ALERT,
2919 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2920
2921 for (i = 0; i < length_in_words; i++) {
2922 /* Wait for IO debug acknowledge */
2923 if (ipr_wait_iodbg_ack(ioa_cfg,
2924 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2925 dev_err(&ioa_cfg->pdev->dev,
2926 "IOA dump short data transfer timeout\n");
2927 return -EIO;
2928 }
2929
2930 /* Read data from mailbox and increment destination pointer */
2931 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2932 dest++;
2933
2934 /* For all but the last word of data, signal data received */
2935 if (i < (length_in_words - 1)) {
2936 /* Signal dump data received - Clear IO debug Ack */
2937 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2938 ioa_cfg->regs.clr_interrupt_reg);
2939 }
2940 }
2941
2942 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2943 writel(IPR_UPROCI_RESET_ALERT,
2944 ioa_cfg->regs.set_uproc_interrupt_reg32);
2945
2946 writel(IPR_UPROCI_IO_DEBUG_ALERT,
2947 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2948
2949 /* Signal dump data received - Clear IO debug Ack */
2950 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2951 ioa_cfg->regs.clr_interrupt_reg);
2952
2953 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2954 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2955 temp_pcii_reg =
2956 readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
2957
2958 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2959 return 0;
2960
2961 udelay(10);
2962 delay += 10;
2963 }
2964
2965 return 0;
2966}
2967
2968#ifdef CONFIG_SCSI_IPR_DUMP
2969/**
2970 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2971 * @ioa_cfg: ioa config struct
2972 * @pci_address: adapter address
2973 * @length: length of data to copy
2974 *
2975 * Copy data from PCI adapter to kernel buffer.
2976 * Note: length MUST be a 4 byte multiple
2977 * Return value:
2978 * 0 on success / other on failure
2979 **/
2980static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2981 unsigned long pci_address, u32 length)
2982{
2983 int bytes_copied = 0;
2984 int cur_len, rc, rem_len, rem_page_len, max_dump_size;
2985 __be32 *page;
2986 unsigned long lock_flags = 0;
2987 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2988
2989 if (ioa_cfg->sis64)
2990 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2991 else
2992 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2993
2994 while (bytes_copied < length &&
2995 (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
2996 if (ioa_dump->page_offset >= PAGE_SIZE ||
2997 ioa_dump->page_offset == 0) {
2998 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2999
3000 if (!page) {
3001 ipr_trace;
3002 return bytes_copied;
3003 }
3004
3005 ioa_dump->page_offset = 0;
3006 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
3007 ioa_dump->next_page_index++;
3008 } else
3009 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
3010
3011 rem_len = length - bytes_copied;
3012 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
3013 cur_len = min(rem_len, rem_page_len);
3014
3015 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3016 if (ioa_cfg->sdt_state == ABORT_DUMP) {
3017 rc = -EIO;
3018 } else {
3019 rc = ipr_get_ldump_data_section(ioa_cfg,
3020 pci_address + bytes_copied,
3021 &page[ioa_dump->page_offset / 4],
3022 (cur_len / sizeof(u32)));
3023 }
3024 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3025
3026 if (!rc) {
3027 ioa_dump->page_offset += cur_len;
3028 bytes_copied += cur_len;
3029 } else {
3030 ipr_trace;
3031 break;
3032 }
3033 schedule();
3034 }
3035
3036 return bytes_copied;
3037}
3038
3039/**
3040 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
3041 * @hdr: dump entry header struct
3042 *
3043 * Return value:
3044 * nothing
3045 **/
3046static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
3047{
3048 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
3049 hdr->num_elems = 1;
3050 hdr->offset = sizeof(*hdr);
3051 hdr->status = IPR_DUMP_STATUS_SUCCESS;
3052}
3053
3054/**
3055 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
3056 * @ioa_cfg: ioa config struct
3057 * @driver_dump: driver dump struct
3058 *
3059 * Return value:
3060 * nothing
3061 **/
3062static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
3063 struct ipr_driver_dump *driver_dump)
3064{
3065 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
3066
3067 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
3068 driver_dump->ioa_type_entry.hdr.len =
3069 sizeof(struct ipr_dump_ioa_type_entry) -
3070 sizeof(struct ipr_dump_entry_header);
3071 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3072 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
3073 driver_dump->ioa_type_entry.type = ioa_cfg->type;
3074 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
3075 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
3076 ucode_vpd->minor_release[1];
3077 driver_dump->hdr.num_entries++;
3078}
3079
3080/**
3081 * ipr_dump_version_data - Fill in the driver version in the dump.
3082 * @ioa_cfg: ioa config struct
3083 * @driver_dump: driver dump struct
3084 *
3085 * Return value:
3086 * nothing
3087 **/
3088static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
3089 struct ipr_driver_dump *driver_dump)
3090{
3091 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
3092 driver_dump->version_entry.hdr.len =
3093 sizeof(struct ipr_dump_version_entry) -
3094 sizeof(struct ipr_dump_entry_header);
3095 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
3096 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
3097 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
3098 driver_dump->hdr.num_entries++;
3099}
3100
3101/**
3102 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
3103 * @ioa_cfg: ioa config struct
3104 * @driver_dump: driver dump struct
3105 *
3106 * Return value:
3107 * nothing
3108 **/
3109static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
3110 struct ipr_driver_dump *driver_dump)
3111{
3112 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
3113 driver_dump->trace_entry.hdr.len =
3114 sizeof(struct ipr_dump_trace_entry) -
3115 sizeof(struct ipr_dump_entry_header);
3116 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3117 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
3118 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
3119 driver_dump->hdr.num_entries++;
3120}
3121
3122/**
3123 * ipr_dump_location_data - Fill in the IOA location in the dump.
3124 * @ioa_cfg: ioa config struct
3125 * @driver_dump: driver dump struct
3126 *
3127 * Return value:
3128 * nothing
3129 **/
3130static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
3131 struct ipr_driver_dump *driver_dump)
3132{
3133 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
3134 driver_dump->location_entry.hdr.len =
3135 sizeof(struct ipr_dump_location_entry) -
3136 sizeof(struct ipr_dump_entry_header);
3137 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
3138 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
3139 strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
3140 driver_dump->hdr.num_entries++;
3141}
3142
3143/**
3144 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
3145 * @ioa_cfg: ioa config struct
3146 * @dump: dump struct
3147 *
3148 * Return value:
3149 * nothing
3150 **/
3151static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
3152{
3153 unsigned long start_addr, sdt_word;
3154 unsigned long lock_flags = 0;
3155 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
3156 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
3157 u32 num_entries, max_num_entries, start_off, end_off;
3158 u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
3159 struct ipr_sdt *sdt;
3160 int valid = 1;
3161 int i;
3162
3163 ENTER;
3164
3165 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3166
3167 if (ioa_cfg->sdt_state != READ_DUMP) {
3168 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3169 return;
3170 }
3171
3172 if (ioa_cfg->sis64) {
3173 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3174 ssleep(IPR_DUMP_DELAY_SECONDS);
3175 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3176 }
3177
3178 start_addr = readl(ioa_cfg->ioa_mailbox);
3179
3180 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
3181 dev_err(&ioa_cfg->pdev->dev,
3182 "Invalid dump table format: %lx\n", start_addr);
3183 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3184 return;
3185 }
3186
3187 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
3188
3189 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
3190
3191 /* Initialize the overall dump header */
3192 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
3193 driver_dump->hdr.num_entries = 1;
3194 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
3195 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
3196 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
3197 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
3198
3199 ipr_dump_version_data(ioa_cfg, driver_dump);
3200 ipr_dump_location_data(ioa_cfg, driver_dump);
3201 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
3202 ipr_dump_trace_data(ioa_cfg, driver_dump);
3203
3204 /* Update dump_header */
3205 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
3206
3207 /* IOA Dump entry */
3208 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
3209 ioa_dump->hdr.len = 0;
3210 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3211 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
3212
3213 /* First entries in sdt are actually a list of dump addresses and
3214 lengths to gather the real dump data. sdt represents the pointer
3215 to the ioa generated dump table. Dump data will be extracted based
3216 on entries in this table */
3217 sdt = &ioa_dump->sdt;
3218
3219 if (ioa_cfg->sis64) {
3220 max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
3221 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
3222 } else {
3223 max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
3224 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
3225 }
3226
3227 bytes_to_copy = offsetof(struct ipr_sdt, entry) +
3228 (max_num_entries * sizeof(struct ipr_sdt_entry));
3229 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
3230 bytes_to_copy / sizeof(__be32));
3231
3232 /* Smart Dump table is ready to use and the first entry is valid */
3233 if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
3234 (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
3235 dev_err(&ioa_cfg->pdev->dev,
3236 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
3237 rc, be32_to_cpu(sdt->hdr.state));
3238 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
3239 ioa_cfg->sdt_state = DUMP_OBTAINED;
3240 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3241 return;
3242 }
3243
3244 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
3245
3246 if (num_entries > max_num_entries)
3247 num_entries = max_num_entries;
3248
3249 /* Update dump length to the actual data to be copied */
3250 dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
3251 if (ioa_cfg->sis64)
3252 dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
3253 else
3254 dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
3255
3256 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3257
3258 for (i = 0; i < num_entries; i++) {
3259 if (ioa_dump->hdr.len > max_dump_size) {
3260 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3261 break;
3262 }
3263
3264 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
3265 sdt_word = be32_to_cpu(sdt->