1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ipr.c -- driver for IBM Power Linux RAID adapters
5 * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
7 * Copyright (C) 2003, 2004 IBM Corporation
13 * This driver is used to control the following SCSI adapters:
15 * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
17 * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
18 * PCI-X Dual Channel Ultra 320 SCSI Adapter
19 * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
20 * Embedded SCSI adapter on p615 and p655 systems
22 * Supported Hardware Features:
23 * - Ultra 320 SCSI controller
24 * - PCI-X host interface
25 * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
26 * - Non-Volatile Write Cache
27 * - Supports attachment of non-RAID disks, tape, and optical devices
28 * - RAID Levels 0, 5, 10
30 * - Background Parity Checking
31 * - Background Data Scrubbing
32 * - Ability to increase the capacity of an existing RAID 5 disk array
36 * - Tagged command queuing
37 * - Adapter microcode download
39 * - SCSI device hot plug
44 #include <linux/init.h>
45 #include <linux/types.h>
46 #include <linux/errno.h>
47 #include <linux/kernel.h>
48 #include <linux/slab.h>
49 #include <linux/vmalloc.h>
50 #include <linux/ioport.h>
51 #include <linux/delay.h>
52 #include <linux/pci.h>
53 #include <linux/wait.h>
54 #include <linux/spinlock.h>
55 #include <linux/sched.h>
56 #include <linux/interrupt.h>
57 #include <linux/blkdev.h>
58 #include <linux/firmware.h>
59 #include <linux/module.h>
60 #include <linux/moduleparam.h>
61 #include <linux/hdreg.h>
62 #include <linux/reboot.h>
63 #include <linux/stringify.h>
66 #include <asm/processor.h>
67 #include <scsi/scsi.h>
68 #include <scsi/scsi_host.h>
69 #include <scsi/scsi_tcq.h>
70 #include <scsi/scsi_eh.h>
71 #include <scsi/scsi_cmnd.h>
77 static LIST_HEAD(ipr_ioa_head);
78 static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
79 static unsigned int ipr_max_speed = 1;
80 static unsigned int ipr_fastfail = 0;
81 static unsigned int ipr_transop_timeout = 0;
82 static unsigned int ipr_debug = 0;
83 static unsigned int ipr_max_devs = IPR_DEFAULT_SIS64_DEVS;
84 static unsigned int ipr_dual_ioa_raid = 1;
85 static unsigned int ipr_number_of_msix = 16;
86 static unsigned int ipr_fast_reboot;
87 static DEFINE_SPINLOCK(ipr_driver_lock);
89 /* This table describes the differences between DMA controller chips */
90 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
91 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
94 .cache_line_size = 0x20,
98 .set_interrupt_mask_reg = 0x0022C,
99 .clr_interrupt_mask_reg = 0x00230,
100 .clr_interrupt_mask_reg32 = 0x00230,
101 .sense_interrupt_mask_reg = 0x0022C,
102 .sense_interrupt_mask_reg32 = 0x0022C,
103 .clr_interrupt_reg = 0x00228,
104 .clr_interrupt_reg32 = 0x00228,
105 .sense_interrupt_reg = 0x00224,
106 .sense_interrupt_reg32 = 0x00224,
107 .ioarrin_reg = 0x00404,
108 .sense_uproc_interrupt_reg = 0x00214,
109 .sense_uproc_interrupt_reg32 = 0x00214,
110 .set_uproc_interrupt_reg = 0x00214,
111 .set_uproc_interrupt_reg32 = 0x00214,
112 .clr_uproc_interrupt_reg = 0x00218,
113 .clr_uproc_interrupt_reg32 = 0x00218
116 { /* Snipe and Scamp */
119 .cache_line_size = 0x20,
123 .set_interrupt_mask_reg = 0x00288,
124 .clr_interrupt_mask_reg = 0x0028C,
125 .clr_interrupt_mask_reg32 = 0x0028C,
126 .sense_interrupt_mask_reg = 0x00288,
127 .sense_interrupt_mask_reg32 = 0x00288,
128 .clr_interrupt_reg = 0x00284,
129 .clr_interrupt_reg32 = 0x00284,
130 .sense_interrupt_reg = 0x00280,
131 .sense_interrupt_reg32 = 0x00280,
132 .ioarrin_reg = 0x00504,
133 .sense_uproc_interrupt_reg = 0x00290,
134 .sense_uproc_interrupt_reg32 = 0x00290,
135 .set_uproc_interrupt_reg = 0x00290,
136 .set_uproc_interrupt_reg32 = 0x00290,
137 .clr_uproc_interrupt_reg = 0x00294,
138 .clr_uproc_interrupt_reg32 = 0x00294
144 .cache_line_size = 0x20,
148 .set_interrupt_mask_reg = 0x00010,
149 .clr_interrupt_mask_reg = 0x00018,
150 .clr_interrupt_mask_reg32 = 0x0001C,
151 .sense_interrupt_mask_reg = 0x00010,
152 .sense_interrupt_mask_reg32 = 0x00014,
153 .clr_interrupt_reg = 0x00008,
154 .clr_interrupt_reg32 = 0x0000C,
155 .sense_interrupt_reg = 0x00000,
156 .sense_interrupt_reg32 = 0x00004,
157 .ioarrin_reg = 0x00070,
158 .sense_uproc_interrupt_reg = 0x00020,
159 .sense_uproc_interrupt_reg32 = 0x00024,
160 .set_uproc_interrupt_reg = 0x00020,
161 .set_uproc_interrupt_reg32 = 0x00024,
162 .clr_uproc_interrupt_reg = 0x00028,
163 .clr_uproc_interrupt_reg32 = 0x0002C,
164 .init_feedback_reg = 0x0005C,
165 .dump_addr_reg = 0x00064,
166 .dump_data_reg = 0x00068,
167 .endian_swap_reg = 0x00084
172 static const struct ipr_chip_t ipr_chip[] = {
173 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
174 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
175 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
176 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
177 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, true, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
178 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
179 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
180 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
181 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
182 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
185 static int ipr_max_bus_speeds[] = {
186 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
189 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
190 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
191 module_param_named(max_speed, ipr_max_speed, uint, 0);
192 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
193 module_param_named(log_level, ipr_log_level, uint, 0);
194 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
195 module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
196 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
197 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
198 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
199 module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
200 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
201 module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
202 MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
203 module_param_named(max_devs, ipr_max_devs, int, 0);
204 MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
205 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
206 module_param_named(number_of_msix, ipr_number_of_msix, int, 0);
207 MODULE_PARM_DESC(number_of_msix, "Specify the number of MSIX interrupts to use on capable adapters (1 - 16). (default:16)");
208 module_param_named(fast_reboot, ipr_fast_reboot, int, S_IRUGO | S_IWUSR);
209 MODULE_PARM_DESC(fast_reboot, "Skip adapter shutdown during reboot. Set to 1 to enable. (default: 0)");
210 MODULE_LICENSE("GPL");
211 MODULE_VERSION(IPR_DRIVER_VERSION);
213 /* A constant array of IOASCs/URCs/Error Messages */
215 struct ipr_error_table_t ipr_error_table[] = {
216 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
217 "8155: An unknown error was received"},
219 "Soft underlength error"},
221 "Command to be cancelled not found"},
223 "Qualified success"},
224 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
225 "FFFE: Soft device bus error recovered by the IOA"},
226 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
227 "4101: Soft device bus fabric error"},
228 {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
229 "FFFC: Logical block guard error recovered by the device"},
230 {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
231 "FFFC: Logical block reference tag error recovered by the device"},
232 {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
233 "4171: Recovered scatter list tag / sequence number error"},
234 {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
235 "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
236 {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
237 "4171: Recovered logical block sequence number error on IOA to Host transfer"},
238 {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
239 "FFFD: Recovered logical block reference tag error detected by the IOA"},
240 {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
241 "FFFD: Logical block guard error recovered by the IOA"},
242 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
243 "FFF9: Device sector reassign successful"},
244 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
245 "FFF7: Media error recovered by device rewrite procedures"},
246 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
247 "7001: IOA sector reassignment successful"},
248 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
249 "FFF9: Soft media error. Sector reassignment recommended"},
250 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
251 "FFF7: Media error recovered by IOA rewrite procedures"},
252 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
253 "FF3D: Soft PCI bus error recovered by the IOA"},
254 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
255 "FFF6: Device hardware error recovered by the IOA"},
256 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
257 "FFF6: Device hardware error recovered by the device"},
258 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
259 "FF3D: Soft IOA error recovered by the IOA"},
260 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
261 "FFFA: Undefined device response recovered by the IOA"},
262 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
263 "FFF6: Device bus error, message or command phase"},
264 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
265 "FFFE: Task Management Function failed"},
266 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
267 "FFF6: Failure prediction threshold exceeded"},
268 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
269 "8009: Impending cache battery pack failure"},
271 "Logical Unit in process of becoming ready"},
273 "Initializing command required"},
275 "34FF: Disk device format in progress"},
277 "Logical unit not accessible, target port in unavailable state"},
278 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
279 "9070: IOA requested reset"},
281 "Synchronization required"},
283 "IOA microcode download required"},
285 "Device bus connection is prohibited by host"},
287 "No ready, IOA shutdown"},
289 "Not ready, IOA has been shutdown"},
290 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
291 "3020: Storage subsystem configuration error"},
293 "FFF5: Medium error, data unreadable, recommend reassign"},
295 "7000: Medium error, data unreadable, do not reassign"},
296 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
297 "FFF3: Disk media format bad"},
298 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
299 "3002: Addressed device failed to respond to selection"},
300 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
301 "3100: Device bus error"},
302 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
303 "3109: IOA timed out a device command"},
305 "3120: SCSI bus is not operational"},
306 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
307 "4100: Hard device bus fabric error"},
308 {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
309 "310C: Logical block guard error detected by the device"},
310 {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
311 "310C: Logical block reference tag error detected by the device"},
312 {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
313 "4170: Scatter list tag / sequence number error"},
314 {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
315 "8150: Logical block CRC error on IOA to Host transfer"},
316 {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
317 "4170: Logical block sequence number error on IOA to Host transfer"},
318 {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
319 "310D: Logical block reference tag error detected by the IOA"},
320 {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
321 "310D: Logical block guard error detected by the IOA"},
322 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
323 "9000: IOA reserved area data check"},
324 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
325 "9001: IOA reserved area invalid data pattern"},
326 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
327 "9002: IOA reserved area LRC error"},
328 {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
329 "Hardware Error, IOA metadata access error"},
330 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
331 "102E: Out of alternate sectors for disk storage"},
332 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
333 "FFF4: Data transfer underlength error"},
334 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
335 "FFF4: Data transfer overlength error"},
336 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
337 "3400: Logical unit failure"},
338 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
339 "FFF4: Device microcode is corrupt"},
340 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
341 "8150: PCI bus error"},
343 "Unsupported device bus message received"},
344 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
345 "FFF4: Disk device problem"},
346 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
347 "8150: Permanent IOA failure"},
348 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
349 "3010: Disk device returned wrong response to IOA"},
350 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
351 "8151: IOA microcode error"},
353 "Device bus status error"},
354 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
355 "8157: IOA error requiring IOA reset to recover"},
357 "ATA device status error"},
359 "Message reject received from the device"},
360 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
361 "8008: A permanent cache battery pack failure occurred"},
362 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
363 "9090: Disk unit has been modified after the last known status"},
364 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
365 "9081: IOA detected device error"},
366 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
367 "9082: IOA detected device error"},
368 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
369 "3110: Device bus error, message or command phase"},
370 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
371 "3110: SAS Command / Task Management Function failed"},
372 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
373 "9091: Incorrect hardware configuration change has been detected"},
374 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
375 "9073: Invalid multi-adapter configuration"},
376 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
377 "4010: Incorrect connection between cascaded expanders"},
378 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
379 "4020: Connections exceed IOA design limits"},
380 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
381 "4030: Incorrect multipath connection"},
382 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
383 "4110: Unsupported enclosure function"},
384 {0x04679800, 0, IPR_DEFAULT_LOG_LEVEL,
385 "4120: SAS cable VPD cannot be read"},
386 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
387 "FFF4: Command to logical unit failed"},
389 "Illegal request, invalid request type or request packet"},
391 "Illegal request, invalid resource handle"},
393 "Illegal request, commands not allowed to this device"},
395 "Illegal request, command not allowed to a secondary adapter"},
397 "Illegal request, command not allowed to a non-optimized resource"},
399 "Illegal request, invalid field in parameter list"},
401 "Illegal request, parameter not supported"},
403 "Illegal request, parameter value invalid"},
405 "Illegal request, command sequence error"},
407 "Illegal request, dual adapter support not enabled"},
409 "Illegal request, another cable connector was physically disabled"},
411 "Illegal request, inconsistent group id/group count"},
412 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
413 "9031: Array protection temporarily suspended, protection resuming"},
414 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
415 "9040: Array protection temporarily suspended, protection resuming"},
416 {0x060B0100, 0, IPR_DEFAULT_LOG_LEVEL,
417 "4080: IOA exceeded maximum operating temperature"},
418 {0x060B8000, 0, IPR_DEFAULT_LOG_LEVEL,
419 "4085: Service required"},
420 {0x060B8100, 0, IPR_DEFAULT_LOG_LEVEL,
421 "4086: SAS Adapter Hardware Configuration Error"},
422 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
423 "3140: Device bus not ready to ready transition"},
424 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
425 "FFFB: SCSI bus was reset"},
427 "FFFE: SCSI bus transition to single ended"},
429 "FFFE: SCSI bus transition to LVD"},
430 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
431 "FFFB: SCSI bus was reset by another initiator"},
432 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
433 "3029: A device replacement has occurred"},
434 {0x063F8300, 0, IPR_DEFAULT_LOG_LEVEL,
435 "4102: Device bus fabric performance degradation"},
436 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
437 "9051: IOA cache data exists for a missing or failed device"},
438 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
439 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
440 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
441 "9025: Disk unit is not supported at its physical location"},
442 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
443 "3020: IOA detected a SCSI bus configuration error"},
444 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
445 "3150: SCSI bus configuration error"},
446 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
447 "9074: Asymmetric advanced function disk configuration"},
448 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
449 "4040: Incomplete multipath connection between IOA and enclosure"},
450 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
451 "4041: Incomplete multipath connection between enclosure and device"},
452 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
453 "9075: Incomplete multipath connection between IOA and remote IOA"},
454 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
455 "9076: Configuration error, missing remote IOA"},
456 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
457 "4050: Enclosure does not support a required multipath function"},
458 {0x06679800, 0, IPR_DEFAULT_LOG_LEVEL,
459 "4121: Configuration error, required cable is missing"},
460 {0x06679900, 0, IPR_DEFAULT_LOG_LEVEL,
461 "4122: Cable is not plugged into the correct location on remote IOA"},
462 {0x06679A00, 0, IPR_DEFAULT_LOG_LEVEL,
463 "4123: Configuration error, invalid cable vital product data"},
464 {0x06679B00, 0, IPR_DEFAULT_LOG_LEVEL,
465 "4124: Configuration error, both cable ends are plugged into the same IOA"},
466 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
467 "4070: Logically bad block written on device"},
468 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
469 "9041: Array protection temporarily suspended"},
470 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
471 "9042: Corrupt array parity detected on specified device"},
472 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
473 "9030: Array no longer protected due to missing or failed disk unit"},
474 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
475 "9071: Link operational transition"},
476 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
477 "9072: Link not operational transition"},
478 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
479 "9032: Array exposed but still protected"},
480 {0x066B8300, 0, IPR_DEBUG_LOG_LEVEL,
481 "70DD: Device forced failed by disrupt device command"},
482 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
483 "4061: Multipath redundancy level got better"},
484 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
485 "4060: Multipath redundancy level got worse"},
486 {0x06808100, 0, IPR_DEBUG_LOG_LEVEL,
487 "9083: Device raw mode enabled"},
488 {0x06808200, 0, IPR_DEBUG_LOG_LEVEL,
489 "9084: Device raw mode disabled"},
491 "Failure due to other device"},
492 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
493 "9008: IOA does not support functions expected by devices"},
494 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
495 "9010: Cache data associated with attached devices cannot be found"},
496 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
497 "9011: Cache data belongs to devices other than those attached"},
498 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
499 "9020: Array missing 2 or more devices with only 1 device present"},
500 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
501 "9021: Array missing 2 or more devices with 2 or more devices present"},
502 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
503 "9022: Exposed array is missing a required device"},
504 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
505 "9023: Array member(s) not at required physical locations"},
506 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
507 "9024: Array not functional due to present hardware configuration"},
508 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
509 "9026: Array not functional due to present hardware configuration"},
510 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
511 "9027: Array is missing a device and parity is out of sync"},
512 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
513 "9028: Maximum number of arrays already exist"},
514 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
515 "9050: Required cache data cannot be located for a disk unit"},
516 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
517 "9052: Cache data exists for a device that has been modified"},
518 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
519 "9054: IOA resources not available due to previous problems"},
520 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
521 "9092: Disk unit requires initialization before use"},
522 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
523 "9029: Incorrect hardware configuration change has been detected"},
524 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
525 "9060: One or more disk pairs are missing from an array"},
526 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
527 "9061: One or more disks are missing from an array"},
528 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
529 "9062: One or more disks are missing from an array"},
530 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
531 "9063: Maximum number of functional arrays has been exceeded"},
533 "Data protect, other volume set problem"},
535 "Aborted command, invalid descriptor"},
537 "Target operating conditions have changed, dual adapter takeover"},
539 "Aborted command, medium removal prevented"},
541 "Command terminated by host"},
543 "Aborted command, command terminated by host"}
546 static const struct ipr_ses_table_entry ipr_ses_table[] = {
547 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
548 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
549 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
550 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
551 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
552 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
553 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
554 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
555 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
556 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
557 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
558 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
559 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
563 * Function Prototypes
565 static int ipr_reset_alert(struct ipr_cmnd *);
566 static void ipr_process_ccn(struct ipr_cmnd *);
567 static void ipr_process_error(struct ipr_cmnd *);
568 static void ipr_reset_ioa_job(struct ipr_cmnd *);
569 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
570 enum ipr_shutdown_type);
572 #ifdef CONFIG_SCSI_IPR_TRACE
574 * ipr_trc_hook - Add a trace entry to the driver trace
575 * @ipr_cmd: ipr command struct
577 * @add_data: additional data
582 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
583 u8 type, u32 add_data)
585 struct ipr_trace_entry *trace_entry;
586 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
587 unsigned int trace_index;
589 trace_index = atomic_add_return(1, &ioa_cfg->trace_index) & IPR_TRACE_INDEX_MASK;
590 trace_entry = &ioa_cfg->trace[trace_index];
591 trace_entry->time = jiffies;
592 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
593 trace_entry->type = type;
594 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
595 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
596 trace_entry->u.add_data = add_data;
600 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
604 * ipr_lock_and_done - Acquire lock and complete command
605 * @ipr_cmd: ipr command struct
610 static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
612 unsigned long lock_flags;
613 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
615 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
616 ipr_cmd->done(ipr_cmd);
617 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
621 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
622 * @ipr_cmd: ipr command struct
627 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
629 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
630 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
631 dma_addr_t dma_addr = ipr_cmd->dma_addr;
634 hrrq_id = ioarcb->cmd_pkt.hrrq_id;
635 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
636 ioarcb->cmd_pkt.hrrq_id = hrrq_id;
637 ioarcb->data_transfer_length = 0;
638 ioarcb->read_data_transfer_length = 0;
639 ioarcb->ioadl_len = 0;
640 ioarcb->read_ioadl_len = 0;
642 if (ipr_cmd->ioa_cfg->sis64) {
643 ioarcb->u.sis64_addr_data.data_ioadl_addr =
644 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
646 ioarcb->write_ioadl_addr =
647 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
648 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
651 ioasa->hdr.ioasc = 0;
652 ioasa->hdr.residual_data_len = 0;
653 ipr_cmd->scsi_cmd = NULL;
654 ipr_cmd->sense_buffer[0] = 0;
655 ipr_cmd->dma_use_sg = 0;
659 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
660 * @ipr_cmd: ipr command struct
661 * @fast_done: fast done function call-back
666 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
667 void (*fast_done) (struct ipr_cmnd *))
669 ipr_reinit_ipr_cmnd(ipr_cmd);
670 ipr_cmd->u.scratch = 0;
671 ipr_cmd->sibling = NULL;
672 ipr_cmd->eh_comp = NULL;
673 ipr_cmd->fast_done = fast_done;
674 timer_setup(&ipr_cmd->timer, NULL, 0);
678 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
682 * pointer to ipr command struct
685 struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_hrr_queue *hrrq)
687 struct ipr_cmnd *ipr_cmd = NULL;
689 if (likely(!list_empty(&hrrq->hrrq_free_q))) {
690 ipr_cmd = list_entry(hrrq->hrrq_free_q.next,
691 struct ipr_cmnd, queue);
692 list_del(&ipr_cmd->queue);
700 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
701 * @ioa_cfg: ioa config struct
704 * pointer to ipr command struct
707 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
709 struct ipr_cmnd *ipr_cmd =
710 __ipr_get_free_ipr_cmnd(&ioa_cfg->hrrq[IPR_INIT_HRRQ]);
711 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
716 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
717 * @ioa_cfg: ioa config struct
718 * @clr_ints: interrupts to clear
720 * This function masks all interrupts on the adapter, then clears the
721 * interrupts specified in the mask
726 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
731 /* Stop new interrupts */
732 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
733 spin_lock(&ioa_cfg->hrrq[i]._lock);
734 ioa_cfg->hrrq[i].allow_interrupts = 0;
735 spin_unlock(&ioa_cfg->hrrq[i]._lock);
738 /* Set interrupt mask to stop all new interrupts */
740 writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
742 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
744 /* Clear any pending interrupts */
746 writel(~0, ioa_cfg->regs.clr_interrupt_reg);
747 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
748 readl(ioa_cfg->regs.sense_interrupt_reg);
752 * ipr_save_pcix_cmd_reg - Save PCI-X command register
753 * @ioa_cfg: ioa config struct
756 * 0 on success / -EIO on failure
758 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
760 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
763 if (pcix_cmd_reg == 0)
766 rc = pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
767 &ioa_cfg->saved_pcix_cmd_reg);
768 if (rc != PCIBIOS_SUCCESSFUL) {
769 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
773 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
778 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
779 * @ioa_cfg: ioa config struct
782 * 0 on success / -EIO on failure
784 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
786 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
790 rc = pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
791 ioa_cfg->saved_pcix_cmd_reg);
792 if (rc != PCIBIOS_SUCCESSFUL) {
793 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
803 * __ipr_scsi_eh_done - mid-layer done function for aborted ops
804 * @ipr_cmd: ipr command struct
806 * This function is invoked by the interrupt handler for
807 * ops generated by the SCSI mid-layer which are being aborted.
812 static void __ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
814 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
816 scsi_cmd->result |= (DID_ERROR << 16);
818 scsi_dma_unmap(ipr_cmd->scsi_cmd);
820 if (ipr_cmd->eh_comp)
821 complete(ipr_cmd->eh_comp);
822 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
826 * ipr_scsi_eh_done - mid-layer done function for aborted ops
827 * @ipr_cmd: ipr command struct
829 * This function is invoked by the interrupt handler for
830 * ops generated by the SCSI mid-layer which are being aborted.
835 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
837 unsigned long hrrq_flags;
838 struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
840 spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
841 __ipr_scsi_eh_done(ipr_cmd);
842 spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
846 * ipr_fail_all_ops - Fails all outstanding ops.
847 * @ioa_cfg: ioa config struct
849 * This function fails all outstanding ops.
854 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
856 struct ipr_cmnd *ipr_cmd, *temp;
857 struct ipr_hrr_queue *hrrq;
860 for_each_hrrq(hrrq, ioa_cfg) {
861 spin_lock(&hrrq->_lock);
862 list_for_each_entry_safe(ipr_cmd,
863 temp, &hrrq->hrrq_pending_q, queue) {
864 list_del(&ipr_cmd->queue);
866 ipr_cmd->s.ioasa.hdr.ioasc =
867 cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
868 ipr_cmd->s.ioasa.hdr.ilid =
869 cpu_to_be32(IPR_DRIVER_ILID);
871 if (ipr_cmd->scsi_cmd)
872 ipr_cmd->done = __ipr_scsi_eh_done;
874 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH,
875 IPR_IOASC_IOA_WAS_RESET);
876 del_timer(&ipr_cmd->timer);
877 ipr_cmd->done(ipr_cmd);
879 spin_unlock(&hrrq->_lock);
885 * ipr_send_command - Send driver initiated requests.
886 * @ipr_cmd: ipr command struct
888 * This function sends a command to the adapter using the correct write call.
889 * In the case of sis64, calculate the ioarcb size required. Then or in the
895 static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
897 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
898 dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
900 if (ioa_cfg->sis64) {
901 /* The default size is 256 bytes */
902 send_dma_addr |= 0x1;
904 /* If the number of ioadls * size of ioadl > 128 bytes,
905 then use a 512 byte ioarcb */
906 if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
907 send_dma_addr |= 0x4;
908 writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
910 writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
914 * ipr_do_req - Send driver initiated requests.
915 * @ipr_cmd: ipr command struct
916 * @done: done function
917 * @timeout_func: timeout function
918 * @timeout: timeout value
920 * This function sends the specified command to the adapter with the
921 * timeout given. The done function is invoked on command completion.
926 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
927 void (*done) (struct ipr_cmnd *),
928 void (*timeout_func) (struct timer_list *), u32 timeout)
930 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
932 ipr_cmd->done = done;
934 ipr_cmd->timer.expires = jiffies + timeout;
935 ipr_cmd->timer.function = timeout_func;
937 add_timer(&ipr_cmd->timer);
939 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
941 ipr_send_command(ipr_cmd);
945 * ipr_internal_cmd_done - Op done function for an internally generated op.
946 * @ipr_cmd: ipr command struct
948 * This function is the op done function for an internally generated,
949 * blocking op. It simply wakes the sleeping thread.
954 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
956 if (ipr_cmd->sibling)
957 ipr_cmd->sibling = NULL;
959 complete(&ipr_cmd->completion);
963 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
964 * @ipr_cmd: ipr command struct
965 * @dma_addr: dma address
966 * @len: transfer length
967 * @flags: ioadl flag value
969 * This function initializes an ioadl in the case where there is only a single
975 static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
978 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
979 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
981 ipr_cmd->dma_use_sg = 1;
983 if (ipr_cmd->ioa_cfg->sis64) {
984 ioadl64->flags = cpu_to_be32(flags);
985 ioadl64->data_len = cpu_to_be32(len);
986 ioadl64->address = cpu_to_be64(dma_addr);
988 ipr_cmd->ioarcb.ioadl_len =
989 cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
990 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
992 ioadl->flags_and_data_len = cpu_to_be32(flags | len);
993 ioadl->address = cpu_to_be32(dma_addr);
995 if (flags == IPR_IOADL_FLAGS_READ_LAST) {
996 ipr_cmd->ioarcb.read_ioadl_len =
997 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
998 ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
1000 ipr_cmd->ioarcb.ioadl_len =
1001 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1002 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1008 * ipr_send_blocking_cmd - Send command and sleep on its completion.
1009 * @ipr_cmd: ipr command struct
1010 * @timeout_func: function to invoke if command times out
1016 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
1017 void (*timeout_func) (struct timer_list *),
1020 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1022 init_completion(&ipr_cmd->completion);
1023 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
1025 spin_unlock_irq(ioa_cfg->host->host_lock);
1026 wait_for_completion(&ipr_cmd->completion);
1027 spin_lock_irq(ioa_cfg->host->host_lock);
1030 static int ipr_get_hrrq_index(struct ipr_ioa_cfg *ioa_cfg)
1034 if (ioa_cfg->hrrq_num == 1)
1037 hrrq = atomic_add_return(1, &ioa_cfg->hrrq_index);
1038 hrrq = (hrrq % (ioa_cfg->hrrq_num - 1)) + 1;
1044 * ipr_send_hcam - Send an HCAM to the adapter.
1045 * @ioa_cfg: ioa config struct
1047 * @hostrcb: hostrcb struct
1049 * This function will send a Host Controlled Async command to the adapter.
1050 * If HCAMs are currently not allowed to be issued to the adapter, it will
1051 * place the hostrcb on the free queue.
1056 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
1057 struct ipr_hostrcb *hostrcb)
1059 struct ipr_cmnd *ipr_cmd;
1060 struct ipr_ioarcb *ioarcb;
1062 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
1063 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
1064 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
1065 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
1067 ipr_cmd->u.hostrcb = hostrcb;
1068 ioarcb = &ipr_cmd->ioarcb;
1070 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
1071 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
1072 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
1073 ioarcb->cmd_pkt.cdb[1] = type;
1074 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
1075 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
1077 ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
1078 sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
1080 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
1081 ipr_cmd->done = ipr_process_ccn;
1083 ipr_cmd->done = ipr_process_error;
1085 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
1087 ipr_send_command(ipr_cmd);
1089 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
1094 * ipr_init_res_entry - Initialize a resource entry struct.
1095 * @res: resource entry struct
1096 * @cfgtew: config table entry wrapper struct
1101 static void ipr_init_res_entry(struct ipr_resource_entry *res,
1102 struct ipr_config_table_entry_wrapper *cfgtew)
1105 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1106 struct ipr_resource_entry *gscsi_res = NULL;
1108 res->needs_sync_complete = 0;
1111 res->del_from_ml = 0;
1112 res->resetting_device = 0;
1113 res->reset_occurred = 0;
1116 if (ioa_cfg->sis64) {
1117 res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
1118 res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
1119 res->qmodel = IPR_QUEUEING_MODEL64(res);
1120 res->type = cfgtew->u.cfgte64->res_type;
1122 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1123 sizeof(res->res_path));
1126 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1127 sizeof(res->dev_lun.scsi_lun));
1128 res->lun = scsilun_to_int(&res->dev_lun);
1130 if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1131 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1132 if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1134 res->target = gscsi_res->target;
1139 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1140 ioa_cfg->max_devs_supported);
1141 set_bit(res->target, ioa_cfg->target_ids);
1143 } else if (res->type == IPR_RES_TYPE_IOAFP) {
1144 res->bus = IPR_IOAFP_VIRTUAL_BUS;
1146 } else if (res->type == IPR_RES_TYPE_ARRAY) {
1147 res->bus = IPR_ARRAY_VIRTUAL_BUS;
1148 res->target = find_first_zero_bit(ioa_cfg->array_ids,
1149 ioa_cfg->max_devs_supported);
1150 set_bit(res->target, ioa_cfg->array_ids);
1151 } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1152 res->bus = IPR_VSET_VIRTUAL_BUS;
1153 res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1154 ioa_cfg->max_devs_supported);
1155 set_bit(res->target, ioa_cfg->vset_ids);
1157 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1158 ioa_cfg->max_devs_supported);
1159 set_bit(res->target, ioa_cfg->target_ids);
1162 res->qmodel = IPR_QUEUEING_MODEL(res);
1163 res->flags = cfgtew->u.cfgte->flags;
1164 if (res->flags & IPR_IS_IOA_RESOURCE)
1165 res->type = IPR_RES_TYPE_IOAFP;
1167 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1169 res->bus = cfgtew->u.cfgte->res_addr.bus;
1170 res->target = cfgtew->u.cfgte->res_addr.target;
1171 res->lun = cfgtew->u.cfgte->res_addr.lun;
1172 res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
1177 * ipr_is_same_device - Determine if two devices are the same.
1178 * @res: resource entry struct
1179 * @cfgtew: config table entry wrapper struct
1182 * 1 if the devices are the same / 0 otherwise
1184 static int ipr_is_same_device(struct ipr_resource_entry *res,
1185 struct ipr_config_table_entry_wrapper *cfgtew)
1187 if (res->ioa_cfg->sis64) {
1188 if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1189 sizeof(cfgtew->u.cfgte64->dev_id)) &&
1190 !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1191 sizeof(cfgtew->u.cfgte64->lun))) {
1195 if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1196 res->target == cfgtew->u.cfgte->res_addr.target &&
1197 res->lun == cfgtew->u.cfgte->res_addr.lun)
1205 * __ipr_format_res_path - Format the resource path for printing.
1206 * @res_path: resource path
1208 * @len: length of buffer provided
1213 static char *__ipr_format_res_path(u8 *res_path, char *buffer, int len)
1219 p += scnprintf(p, buffer + len - p, "%02X", res_path[0]);
1220 for (i = 1; res_path[i] != 0xff && i < IPR_RES_PATH_BYTES; i++)
1221 p += scnprintf(p, buffer + len - p, "-%02X", res_path[i]);
1227 * ipr_format_res_path - Format the resource path for printing.
1228 * @ioa_cfg: ioa config struct
1229 * @res_path: resource path
1231 * @len: length of buffer provided
1236 static char *ipr_format_res_path(struct ipr_ioa_cfg *ioa_cfg,
1237 u8 *res_path, char *buffer, int len)
1242 p += scnprintf(p, buffer + len - p, "%d/", ioa_cfg->host->host_no);
1243 __ipr_format_res_path(res_path, p, len - (p - buffer));
1248 * ipr_update_res_entry - Update the resource entry.
1249 * @res: resource entry struct
1250 * @cfgtew: config table entry wrapper struct
1255 static void ipr_update_res_entry(struct ipr_resource_entry *res,
1256 struct ipr_config_table_entry_wrapper *cfgtew)
1258 char buffer[IPR_MAX_RES_PATH_LENGTH];
1261 if (res->ioa_cfg->sis64) {
1262 res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
1263 res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
1264 res->type = cfgtew->u.cfgte64->res_type;
1266 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1267 sizeof(struct ipr_std_inq_data));
1269 res->qmodel = IPR_QUEUEING_MODEL64(res);
1270 res->res_handle = cfgtew->u.cfgte64->res_handle;
1271 res->dev_id = cfgtew->u.cfgte64->dev_id;
1273 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1274 sizeof(res->dev_lun.scsi_lun));
1276 if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1277 sizeof(res->res_path))) {
1278 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1279 sizeof(res->res_path));
1283 if (res->sdev && new_path)
1284 sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
1285 ipr_format_res_path(res->ioa_cfg,
1286 res->res_path, buffer, sizeof(buffer)));
1288 res->flags = cfgtew->u.cfgte->flags;
1289 if (res->flags & IPR_IS_IOA_RESOURCE)
1290 res->type = IPR_RES_TYPE_IOAFP;
1292 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1294 memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1295 sizeof(struct ipr_std_inq_data));
1297 res->qmodel = IPR_QUEUEING_MODEL(res);
1298 res->res_handle = cfgtew->u.cfgte->res_handle;
1303 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1305 * @res: resource entry struct
1310 static void ipr_clear_res_target(struct ipr_resource_entry *res)
1312 struct ipr_resource_entry *gscsi_res = NULL;
1313 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1315 if (!ioa_cfg->sis64)
1318 if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1319 clear_bit(res->target, ioa_cfg->array_ids);
1320 else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1321 clear_bit(res->target, ioa_cfg->vset_ids);
1322 else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1323 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1324 if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1326 clear_bit(res->target, ioa_cfg->target_ids);
1328 } else if (res->bus == 0)
1329 clear_bit(res->target, ioa_cfg->target_ids);
1333 * ipr_handle_config_change - Handle a config change from the adapter
1334 * @ioa_cfg: ioa config struct
1340 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
1341 struct ipr_hostrcb *hostrcb)
1343 struct ipr_resource_entry *res = NULL;
1344 struct ipr_config_table_entry_wrapper cfgtew;
1345 __be32 cc_res_handle;
1349 if (ioa_cfg->sis64) {
1350 cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1351 cc_res_handle = cfgtew.u.cfgte64->res_handle;
1353 cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1354 cc_res_handle = cfgtew.u.cfgte->res_handle;
1357 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1358 if (res->res_handle == cc_res_handle) {
1365 if (list_empty(&ioa_cfg->free_res_q)) {
1366 ipr_send_hcam(ioa_cfg,
1367 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1372 res = list_entry(ioa_cfg->free_res_q.next,
1373 struct ipr_resource_entry, queue);
1375 list_del(&res->queue);
1376 ipr_init_res_entry(res, &cfgtew);
1377 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1380 ipr_update_res_entry(res, &cfgtew);
1382 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1384 res->del_from_ml = 1;
1385 res->res_handle = IPR_INVALID_RES_HANDLE;
1386 schedule_work(&ioa_cfg->work_q);
1388 ipr_clear_res_target(res);
1389 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
1391 } else if (!res->sdev || res->del_from_ml) {
1393 schedule_work(&ioa_cfg->work_q);
1396 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1400 * ipr_process_ccn - Op done function for a CCN.
1401 * @ipr_cmd: ipr command struct
1403 * This function is the op done function for a configuration
1404 * change notification host controlled async from the adapter.
1409 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1411 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1412 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1413 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
1415 list_del_init(&hostrcb->queue);
1416 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
1419 if (ioasc != IPR_IOASC_IOA_WAS_RESET &&
1420 ioasc != IPR_IOASC_ABORTED_CMD_TERM_BY_HOST)
1421 dev_err(&ioa_cfg->pdev->dev,
1422 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1424 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1426 ipr_handle_config_change(ioa_cfg, hostrcb);
1431 * strip_whitespace - Strip and pad trailing whitespace.
1432 * @i: size of buffer
1433 * @buf: string to modify
1435 * This function will strip all trailing whitespace and
1436 * NUL terminate the string.
1439 static void strip_whitespace(int i, char *buf)
1444 while (i && buf[i] == ' ')
1450 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1451 * @prefix: string to print at start of printk
1452 * @hostrcb: hostrcb pointer
1453 * @vpd: vendor/product id/sn struct
1458 static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1459 struct ipr_vpd *vpd)
1461 char vendor_id[IPR_VENDOR_ID_LEN + 1];
1462 char product_id[IPR_PROD_ID_LEN + 1];
1463 char sn[IPR_SERIAL_NUM_LEN + 1];
1465 memcpy(vendor_id, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1466 strip_whitespace(IPR_VENDOR_ID_LEN, vendor_id);
1468 memcpy(product_id, vpd->vpids.product_id, IPR_PROD_ID_LEN);
1469 strip_whitespace(IPR_PROD_ID_LEN, product_id);
1471 memcpy(sn, vpd->sn, IPR_SERIAL_NUM_LEN);
1472 strip_whitespace(IPR_SERIAL_NUM_LEN, sn);
1474 ipr_hcam_err(hostrcb, "%s VPID/SN: %s %s %s\n", prefix,
1475 vendor_id, product_id, sn);
1479 * ipr_log_vpd - Log the passed VPD to the error log.
1480 * @vpd: vendor/product id/sn struct
1485 static void ipr_log_vpd(struct ipr_vpd *vpd)
1487 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1488 + IPR_SERIAL_NUM_LEN];
1490 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1491 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
1493 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1494 ipr_err("Vendor/Product ID: %s\n", buffer);
1496 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
1497 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1498 ipr_err(" Serial Number: %s\n", buffer);
1502 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1503 * @prefix: string to print at start of printk
1504 * @hostrcb: hostrcb pointer
1505 * @vpd: vendor/product id/sn/wwn struct
1510 static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1511 struct ipr_ext_vpd *vpd)
1513 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1514 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1515 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1519 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1520 * @vpd: vendor/product id/sn/wwn struct
1525 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1527 ipr_log_vpd(&vpd->vpd);
1528 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1529 be32_to_cpu(vpd->wwid[1]));
1533 * ipr_log_enhanced_cache_error - Log a cache error.
1534 * @ioa_cfg: ioa config struct
1535 * @hostrcb: hostrcb struct
1540 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1541 struct ipr_hostrcb *hostrcb)
1543 struct ipr_hostrcb_type_12_error *error;
1546 error = &hostrcb->hcam.u.error64.u.type_12_error;
1548 error = &hostrcb->hcam.u.error.u.type_12_error;
1550 ipr_err("-----Current Configuration-----\n");
1551 ipr_err("Cache Directory Card Information:\n");
1552 ipr_log_ext_vpd(&error->ioa_vpd);
1553 ipr_err("Adapter Card Information:\n");
1554 ipr_log_ext_vpd(&error->cfc_vpd);
1556 ipr_err("-----Expected Configuration-----\n");
1557 ipr_err("Cache Directory Card Information:\n");
1558 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1559 ipr_err("Adapter Card Information:\n");
1560 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1562 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1563 be32_to_cpu(error->ioa_data[0]),
1564 be32_to_cpu(error->ioa_data[1]),
1565 be32_to_cpu(error->ioa_data[2]));
1569 * ipr_log_cache_error - Log a cache error.
1570 * @ioa_cfg: ioa config struct
1571 * @hostrcb: hostrcb struct
1576 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1577 struct ipr_hostrcb *hostrcb)
1579 struct ipr_hostrcb_type_02_error *error =
1580 &hostrcb->hcam.u.error.u.type_02_error;
1582 ipr_err("-----Current Configuration-----\n");
1583 ipr_err("Cache Directory Card Information:\n");
1584 ipr_log_vpd(&error->ioa_vpd);
1585 ipr_err("Adapter Card Information:\n");
1586 ipr_log_vpd(&error->cfc_vpd);
1588 ipr_err("-----Expected Configuration-----\n");
1589 ipr_err("Cache Directory Card Information:\n");
1590 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1591 ipr_err("Adapter Card Information:\n");
1592 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1594 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1595 be32_to_cpu(error->ioa_data[0]),
1596 be32_to_cpu(error->ioa_data[1]),
1597 be32_to_cpu(error->ioa_data[2]));
1601 * ipr_log_enhanced_config_error - Log a configuration error.
1602 * @ioa_cfg: ioa config struct
1603 * @hostrcb: hostrcb struct
1608 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1609 struct ipr_hostrcb *hostrcb)
1611 int errors_logged, i;
1612 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1613 struct ipr_hostrcb_type_13_error *error;
1615 error = &hostrcb->hcam.u.error.u.type_13_error;
1616 errors_logged = be32_to_cpu(error->errors_logged);
1618 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1619 be32_to_cpu(error->errors_detected), errors_logged);
1621 dev_entry = error->dev;
1623 for (i = 0; i < errors_logged; i++, dev_entry++) {
1626 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1627 ipr_log_ext_vpd(&dev_entry->vpd);
1629 ipr_err("-----New Device Information-----\n");
1630 ipr_log_ext_vpd(&dev_entry->new_vpd);
1632 ipr_err("Cache Directory Card Information:\n");
1633 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1635 ipr_err("Adapter Card Information:\n");
1636 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1641 * ipr_log_sis64_config_error - Log a device error.
1642 * @ioa_cfg: ioa config struct
1643 * @hostrcb: hostrcb struct
1648 static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
1649 struct ipr_hostrcb *hostrcb)
1651 int errors_logged, i;
1652 struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
1653 struct ipr_hostrcb_type_23_error *error;
1654 char buffer[IPR_MAX_RES_PATH_LENGTH];
1656 error = &hostrcb->hcam.u.error64.u.type_23_error;
1657 errors_logged = be32_to_cpu(error->errors_logged);
1659 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1660 be32_to_cpu(error->errors_detected), errors_logged);
1662 dev_entry = error->dev;
1664 for (i = 0; i < errors_logged; i++, dev_entry++) {
1667 ipr_err("Device %d : %s", i + 1,
1668 __ipr_format_res_path(dev_entry->res_path,
1669 buffer, sizeof(buffer)));
1670 ipr_log_ext_vpd(&dev_entry->vpd);
1672 ipr_err("-----New Device Information-----\n");
1673 ipr_log_ext_vpd(&dev_entry->new_vpd);
1675 ipr_err("Cache Directory Card Information:\n");
1676 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1678 ipr_err("Adapter Card Information:\n");
1679 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1684 * ipr_log_config_error - Log a configuration error.
1685 * @ioa_cfg: ioa config struct
1686 * @hostrcb: hostrcb struct
1691 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1692 struct ipr_hostrcb *hostrcb)
1694 int errors_logged, i;
1695 struct ipr_hostrcb_device_data_entry *dev_entry;
1696 struct ipr_hostrcb_type_03_error *error;
1698 error = &hostrcb->hcam.u.error.u.type_03_error;
1699 errors_logged = be32_to_cpu(error->errors_logged);
1701 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1702 be32_to_cpu(error->errors_detected), errors_logged);
1704 dev_entry = error->dev;
1706 for (i = 0; i < errors_logged; i++, dev_entry++) {
1709 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1710 ipr_log_vpd(&dev_entry->vpd);
1712 ipr_err("-----New Device Information-----\n");
1713 ipr_log_vpd(&dev_entry->new_vpd);
1715 ipr_err("Cache Directory Card Information:\n");
1716 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1718 ipr_err("Adapter Card Information:\n");
1719 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1721 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1722 be32_to_cpu(dev_entry->ioa_data[0]),
1723 be32_to_cpu(dev_entry->ioa_data[1]),
1724 be32_to_cpu(dev_entry->ioa_data[2]),
1725 be32_to_cpu(dev_entry->ioa_data[3]),
1726 be32_to_cpu(dev_entry->ioa_data[4]));
1731 * ipr_log_enhanced_array_error - Log an array configuration error.
1732 * @ioa_cfg: ioa config struct
1733 * @hostrcb: hostrcb struct
1738 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1739 struct ipr_hostrcb *hostrcb)
1742 struct ipr_hostrcb_type_14_error *error;
1743 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1744 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1746 error = &hostrcb->hcam.u.error.u.type_14_error;
1750 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1751 error->protection_level,
1752 ioa_cfg->host->host_no,
1753 error->last_func_vset_res_addr.bus,
1754 error->last_func_vset_res_addr.target,
1755 error->last_func_vset_res_addr.lun);
1759 array_entry = error->array_member;
1760 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1761 ARRAY_SIZE(error->array_member));
1763 for (i = 0; i < num_entries; i++, array_entry++) {
1764 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1767 if (be32_to_cpu(error->exposed_mode_adn) == i)
1768 ipr_err("Exposed Array Member %d:\n", i);
1770 ipr_err("Array Member %d:\n", i);
1772 ipr_log_ext_vpd(&array_entry->vpd);
1773 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1774 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1775 "Expected Location");
1782 * ipr_log_array_error - Log an array configuration error.
1783 * @ioa_cfg: ioa config struct
1784 * @hostrcb: hostrcb struct
1789 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1790 struct ipr_hostrcb *hostrcb)
1793 struct ipr_hostrcb_type_04_error *error;
1794 struct ipr_hostrcb_array_data_entry *array_entry;
1795 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1797 error = &hostrcb->hcam.u.error.u.type_04_error;
1801 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1802 error->protection_level,
1803 ioa_cfg->host->host_no,
1804 error->last_func_vset_res_addr.bus,
1805 error->last_func_vset_res_addr.target,
1806 error->last_func_vset_res_addr.lun);
1810 array_entry = error->array_member;
1812 for (i = 0; i < 18; i++) {
1813 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1816 if (be32_to_cpu(error->exposed_mode_adn) == i)
1817 ipr_err("Exposed Array Member %d:\n", i);
1819 ipr_err("Array Member %d:\n", i);
1821 ipr_log_vpd(&array_entry->vpd);
1823 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1824 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1825 "Expected Location");
1830 array_entry = error->array_member2;
1837 * ipr_log_hex_data - Log additional hex IOA error data.
1838 * @ioa_cfg: ioa config struct
1839 * @data: IOA error data
1845 static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, __be32 *data, int len)
1852 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1853 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1855 for (i = 0; i < len / 4; i += 4) {
1856 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1857 be32_to_cpu(data[i]),
1858 be32_to_cpu(data[i+1]),
1859 be32_to_cpu(data[i+2]),
1860 be32_to_cpu(data[i+3]));
1865 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1866 * @ioa_cfg: ioa config struct
1867 * @hostrcb: hostrcb struct
1872 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1873 struct ipr_hostrcb *hostrcb)
1875 struct ipr_hostrcb_type_17_error *error;
1878 error = &hostrcb->hcam.u.error64.u.type_17_error;
1880 error = &hostrcb->hcam.u.error.u.type_17_error;
1882 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1883 strim(error->failure_reason);
1885 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1886 be32_to_cpu(hostrcb->hcam.u.error.prc));
1887 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1888 ipr_log_hex_data(ioa_cfg, error->data,
1889 be32_to_cpu(hostrcb->hcam.length) -
1890 (offsetof(struct ipr_hostrcb_error, u) +
1891 offsetof(struct ipr_hostrcb_type_17_error, data)));
1895 * ipr_log_dual_ioa_error - Log a dual adapter error.
1896 * @ioa_cfg: ioa config struct
1897 * @hostrcb: hostrcb struct
1902 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1903 struct ipr_hostrcb *hostrcb)
1905 struct ipr_hostrcb_type_07_error *error;
1907 error = &hostrcb->hcam.u.error.u.type_07_error;
1908 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1909 strim(error->failure_reason);
1911 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1912 be32_to_cpu(hostrcb->hcam.u.error.prc));
1913 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1914 ipr_log_hex_data(ioa_cfg, error->data,
1915 be32_to_cpu(hostrcb->hcam.length) -
1916 (offsetof(struct ipr_hostrcb_error, u) +
1917 offsetof(struct ipr_hostrcb_type_07_error, data)));
1920 static const struct {
1923 } path_active_desc[] = {
1924 { IPR_PATH_NO_INFO, "Path" },
1925 { IPR_PATH_ACTIVE, "Active path" },
1926 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1929 static const struct {
1932 } path_state_desc[] = {
1933 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1934 { IPR_PATH_HEALTHY, "is healthy" },
1935 { IPR_PATH_DEGRADED, "is degraded" },
1936 { IPR_PATH_FAILED, "is failed" }
1940 * ipr_log_fabric_path - Log a fabric path error
1941 * @hostrcb: hostrcb struct
1942 * @fabric: fabric descriptor
1947 static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1948 struct ipr_hostrcb_fabric_desc *fabric)
1951 u8 path_state = fabric->path_state;
1952 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1953 u8 state = path_state & IPR_PATH_STATE_MASK;
1955 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1956 if (path_active_desc[i].active != active)
1959 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1960 if (path_state_desc[j].state != state)
1963 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
1964 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
1965 path_active_desc[i].desc, path_state_desc[j].desc,
1967 } else if (fabric->cascaded_expander == 0xff) {
1968 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
1969 path_active_desc[i].desc, path_state_desc[j].desc,
1970 fabric->ioa_port, fabric->phy);
1971 } else if (fabric->phy == 0xff) {
1972 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
1973 path_active_desc[i].desc, path_state_desc[j].desc,
1974 fabric->ioa_port, fabric->cascaded_expander);
1976 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1977 path_active_desc[i].desc, path_state_desc[j].desc,
1978 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1984 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
1985 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1989 * ipr_log64_fabric_path - Log a fabric path error
1990 * @hostrcb: hostrcb struct
1991 * @fabric: fabric descriptor
1996 static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
1997 struct ipr_hostrcb64_fabric_desc *fabric)
2000 u8 path_state = fabric->path_state;
2001 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
2002 u8 state = path_state & IPR_PATH_STATE_MASK;
2003 char buffer[IPR_MAX_RES_PATH_LENGTH];
2005 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
2006 if (path_active_desc[i].active != active)
2009 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2010 if (path_state_desc[j].state != state)
2013 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
2014 path_active_desc[i].desc, path_state_desc[j].desc,
2015 ipr_format_res_path(hostrcb->ioa_cfg,
2017 buffer, sizeof(buffer)));
2022 ipr_err("Path state=%02X Resource Path=%s\n", path_state,
2023 ipr_format_res_path(hostrcb->ioa_cfg, fabric->res_path,
2024 buffer, sizeof(buffer)));
2027 static const struct {
2030 } path_type_desc[] = {
2031 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
2032 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
2033 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
2034 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
2037 static const struct {
2040 } path_status_desc[] = {
2041 { IPR_PATH_CFG_NO_PROB, "Functional" },
2042 { IPR_PATH_CFG_DEGRADED, "Degraded" },
2043 { IPR_PATH_CFG_FAILED, "Failed" },
2044 { IPR_PATH_CFG_SUSPECT, "Suspect" },
2045 { IPR_PATH_NOT_DETECTED, "Missing" },
2046 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
2049 static const char *link_rate[] = {
2052 "phy reset problem",
2069 * ipr_log_path_elem - Log a fabric path element.
2070 * @hostrcb: hostrcb struct
2071 * @cfg: fabric path element struct
2076 static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
2077 struct ipr_hostrcb_config_element *cfg)
2080 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2081 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2083 if (type == IPR_PATH_CFG_NOT_EXIST)
2086 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2087 if (path_type_desc[i].type != type)
2090 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2091 if (path_status_desc[j].status != status)
2094 if (type == IPR_PATH_CFG_IOA_PORT) {
2095 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
2096 path_status_desc[j].desc, path_type_desc[i].desc,
2097 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2098 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2100 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
2101 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2102 path_status_desc[j].desc, path_type_desc[i].desc,
2103 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2104 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2105 } else if (cfg->cascaded_expander == 0xff) {
2106 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
2107 "WWN=%08X%08X\n", path_status_desc[j].desc,
2108 path_type_desc[i].desc, cfg->phy,
2109 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2110 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2111 } else if (cfg->phy == 0xff) {
2112 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
2113 "WWN=%08X%08X\n", path_status_desc[j].desc,
2114 path_type_desc[i].desc, cfg->cascaded_expander,
2115 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2116 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2118 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2119 "WWN=%08X%08X\n", path_status_desc[j].desc,
2120 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
2121 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2122 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2129 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2130 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
2131 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2132 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2136 * ipr_log64_path_elem - Log a fabric path element.
2137 * @hostrcb: hostrcb struct
2138 * @cfg: fabric path element struct
2143 static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
2144 struct ipr_hostrcb64_config_element *cfg)
2147 u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
2148 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2149 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2150 char buffer[IPR_MAX_RES_PATH_LENGTH];
2152 if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
2155 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2156 if (path_type_desc[i].type != type)
2159 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2160 if (path_status_desc[j].status != status)
2163 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2164 path_status_desc[j].desc, path_type_desc[i].desc,
2165 ipr_format_res_path(hostrcb->ioa_cfg,
2166 cfg->res_path, buffer, sizeof(buffer)),
2167 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2168 be32_to_cpu(cfg->wwid[0]),
2169 be32_to_cpu(cfg->wwid[1]));
2173 ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
2174 "WWN=%08X%08X\n", cfg->type_status,
2175 ipr_format_res_path(hostrcb->ioa_cfg,
2176 cfg->res_path, buffer, sizeof(buffer)),
2177 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2178 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2182 * ipr_log_fabric_error - Log a fabric error.
2183 * @ioa_cfg: ioa config struct
2184 * @hostrcb: hostrcb struct
2189 static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2190 struct ipr_hostrcb *hostrcb)
2192 struct ipr_hostrcb_type_20_error *error;
2193 struct ipr_hostrcb_fabric_desc *fabric;
2194 struct ipr_hostrcb_config_element *cfg;
2197 error = &hostrcb->hcam.u.error.u.type_20_error;
2198 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2199 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2201 add_len = be32_to_cpu(hostrcb->hcam.length) -
2202 (offsetof(struct ipr_hostrcb_error, u) +
2203 offsetof(struct ipr_hostrcb_type_20_error, desc));
2205 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2206 ipr_log_fabric_path(hostrcb, fabric);
2207 for_each_fabric_cfg(fabric, cfg)
2208 ipr_log_path_elem(hostrcb, cfg);
2210 add_len -= be16_to_cpu(fabric->length);
2211 fabric = (struct ipr_hostrcb_fabric_desc *)
2212 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2215 ipr_log_hex_data(ioa_cfg, (__be32 *)fabric, add_len);
2219 * ipr_log_sis64_array_error - Log a sis64 array error.
2220 * @ioa_cfg: ioa config struct
2221 * @hostrcb: hostrcb struct
2226 static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
2227 struct ipr_hostrcb *hostrcb)
2230 struct ipr_hostrcb_type_24_error *error;
2231 struct ipr_hostrcb64_array_data_entry *array_entry;
2232 char buffer[IPR_MAX_RES_PATH_LENGTH];
2233 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
2235 error = &hostrcb->hcam.u.error64.u.type_24_error;
2239 ipr_err("RAID %s Array Configuration: %s\n",
2240 error->protection_level,
2241 ipr_format_res_path(ioa_cfg, error->last_res_path,
2242 buffer, sizeof(buffer)));
2246 array_entry = error->array_member;
2247 num_entries = min_t(u32, error->num_entries,
2248 ARRAY_SIZE(error->array_member));
2250 for (i = 0; i < num_entries; i++, array_entry++) {
2252 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
2255 if (error->exposed_mode_adn == i)
2256 ipr_err("Exposed Array Member %d:\n", i);
2258 ipr_err("Array Member %d:\n", i);
2260 ipr_err("Array Member %d:\n", i);
2261 ipr_log_ext_vpd(&array_entry->vpd);
2262 ipr_err("Current Location: %s\n",
2263 ipr_format_res_path(ioa_cfg, array_entry->res_path,
2264 buffer, sizeof(buffer)));
2265 ipr_err("Expected Location: %s\n",
2266 ipr_format_res_path(ioa_cfg,
2267 array_entry->expected_res_path,
2268 buffer, sizeof(buffer)));
2275 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2276 * @ioa_cfg: ioa config struct
2277 * @hostrcb: hostrcb struct
2282 static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2283 struct ipr_hostrcb *hostrcb)
2285 struct ipr_hostrcb_type_30_error *error;
2286 struct ipr_hostrcb64_fabric_desc *fabric;
2287 struct ipr_hostrcb64_config_element *cfg;
2290 error = &hostrcb->hcam.u.error64.u.type_30_error;
2292 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2293 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2295 add_len = be32_to_cpu(hostrcb->hcam.length) -
2296 (offsetof(struct ipr_hostrcb64_error, u) +
2297 offsetof(struct ipr_hostrcb_type_30_error, desc));
2299 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2300 ipr_log64_fabric_path(hostrcb, fabric);
2301 for_each_fabric_cfg(fabric, cfg)
2302 ipr_log64_path_elem(hostrcb, cfg);
2304 add_len -= be16_to_cpu(fabric->length);
2305 fabric = (struct ipr_hostrcb64_fabric_desc *)
2306 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2309 ipr_log_hex_data(ioa_cfg, (__be32 *)fabric, add_len);
2313 * ipr_log_sis64_service_required_error - Log a sis64 service required error.
2314 * @ioa_cfg: ioa config struct
2315 * @hostrcb: hostrcb struct
2320 static void ipr_log_sis64_service_required_error(struct ipr_ioa_cfg *ioa_cfg,
2321 struct ipr_hostrcb *hostrcb)
2323 struct ipr_hostrcb_type_41_error *error;
2325 error = &hostrcb->hcam.u.error64.u.type_41_error;
2327 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2328 ipr_err("Primary Failure Reason: %s\n", error->failure_reason);
2329 ipr_log_hex_data(ioa_cfg, error->data,
2330 be32_to_cpu(hostrcb->hcam.length) -
2331 (offsetof(struct ipr_hostrcb_error, u) +
2332 offsetof(struct ipr_hostrcb_type_41_error, data)));
2335 * ipr_log_generic_error - Log an adapter error.
2336 * @ioa_cfg: ioa config struct
2337 * @hostrcb: hostrcb struct
2342 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
2343 struct ipr_hostrcb *hostrcb)
2345 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
2346 be32_to_cpu(hostrcb->hcam.length));
2350 * ipr_log_sis64_device_error - Log a cache error.
2351 * @ioa_cfg: ioa config struct
2352 * @hostrcb: hostrcb struct
2357 static void ipr_log_sis64_device_error(struct ipr_ioa_cfg *ioa_cfg,
2358 struct ipr_hostrcb *hostrcb)
2360 struct ipr_hostrcb_type_21_error *error;
2361 char buffer[IPR_MAX_RES_PATH_LENGTH];
2363 error = &hostrcb->hcam.u.error64.u.type_21_error;
2365 ipr_err("-----Failing Device Information-----\n");
2366 ipr_err("World Wide Unique ID: %08X%08X%08X%08X\n",
2367 be32_to_cpu(error->wwn[0]), be32_to_cpu(error->wwn[1]),
2368 be32_to_cpu(error->wwn[2]), be32_to_cpu(error->wwn[3]));
2369 ipr_err("Device Resource Path: %s\n",
2370 __ipr_format_res_path(error->res_path,
2371 buffer, sizeof(buffer)));
2372 error->primary_problem_desc[sizeof(error->primary_problem_desc) - 1] = '\0';
2373 error->second_problem_desc[sizeof(error->second_problem_desc) - 1] = '\0';
2374 ipr_err("Primary Problem Description: %s\n", error->primary_problem_desc);
2375 ipr_err("Secondary Problem Description: %s\n", error->second_problem_desc);
2376 ipr_err("SCSI Sense Data:\n");
2377 ipr_log_hex_data(ioa_cfg, error->sense_data, sizeof(error->sense_data));
2378 ipr_err("SCSI Command Descriptor Block: \n");
2379 ipr_log_hex_data(ioa_cfg, error->cdb, sizeof(error->cdb));
2381 ipr_err("Additional IOA Data:\n");
2382 ipr_log_hex_data(ioa_cfg, error->ioa_data, be32_to_cpu(error->length_of_error));
2386 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2389 * This function will return the index of into the ipr_error_table
2390 * for the specified IOASC. If the IOASC is not in the table,
2391 * 0 will be returned, which points to the entry used for unknown errors.
2394 * index into the ipr_error_table
2396 static u32 ipr_get_error(u32 ioasc)
2400 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
2401 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
2408 * ipr_handle_log_data - Log an adapter error.
2409 * @ioa_cfg: ioa config struct
2410 * @hostrcb: hostrcb struct
2412 * This function logs an adapter error to the system.
2417 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
2418 struct ipr_hostrcb *hostrcb)
2422 struct ipr_hostrcb_type_21_error *error;
2424 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
2427 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
2428 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
2431 ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2433 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2435 if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
2436 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
2437 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2438 scsi_report_bus_reset(ioa_cfg->host,
2439 hostrcb->hcam.u.error.fd_res_addr.bus);
2442 error_index = ipr_get_error(ioasc);
2444 if (!ipr_error_table[error_index].log_hcam)
2447 if (ioasc == IPR_IOASC_HW_CMD_FAILED &&
2448 hostrcb->hcam.overlay_id == IPR_HOST_RCB_OVERLAY_ID_21) {
2449 error = &hostrcb->hcam.u.error64.u.type_21_error;
2451 if (((be32_to_cpu(error->sense_data[0]) & 0x0000ff00) >> 8) == ILLEGAL_REQUEST &&
2452 ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
2456 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
2458 /* Set indication we have logged an error */
2459 ioa_cfg->errors_logged++;
2461 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
2463 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
2464 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
2466 switch (hostrcb->hcam.overlay_id) {
2467 case IPR_HOST_RCB_OVERLAY_ID_2:
2468 ipr_log_cache_error(ioa_cfg, hostrcb);
2470 case IPR_HOST_RCB_OVERLAY_ID_3:
2471 ipr_log_config_error(ioa_cfg, hostrcb);
2473 case IPR_HOST_RCB_OVERLAY_ID_4:
2474 case IPR_HOST_RCB_OVERLAY_ID_6:
2475 ipr_log_array_error(ioa_cfg, hostrcb);
2477 case IPR_HOST_RCB_OVERLAY_ID_7:
2478 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
2480 case IPR_HOST_RCB_OVERLAY_ID_12:
2481 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
2483 case IPR_HOST_RCB_OVERLAY_ID_13:
2484 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
2486 case IPR_HOST_RCB_OVERLAY_ID_14:
2487 case IPR_HOST_RCB_OVERLAY_ID_16:
2488 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
2490 case IPR_HOST_RCB_OVERLAY_ID_17:
2491 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
2493 case IPR_HOST_RCB_OVERLAY_ID_20:
2494 ipr_log_fabric_error(ioa_cfg, hostrcb);
2496 case IPR_HOST_RCB_OVERLAY_ID_21:
2497 ipr_log_sis64_device_error(ioa_cfg, hostrcb);
2499 case IPR_HOST_RCB_OVERLAY_ID_23:
2500 ipr_log_sis64_config_error(ioa_cfg, hostrcb);
2502 case IPR_HOST_RCB_OVERLAY_ID_24:
2503 case IPR_HOST_RCB_OVERLAY_ID_26:
2504 ipr_log_sis64_array_error(ioa_cfg, hostrcb);
2506 case IPR_HOST_RCB_OVERLAY_ID_30:
2507 ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
2509 case IPR_HOST_RCB_OVERLAY_ID_41:
2510 ipr_log_sis64_service_required_error(ioa_cfg, hostrcb);
2512 case IPR_HOST_RCB_OVERLAY_ID_1:
2513 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
2515 ipr_log_generic_error(ioa_cfg, hostrcb);
2520 static struct ipr_hostrcb *ipr_get_free_hostrcb(struct ipr_ioa_cfg *ioa)
2522 struct ipr_hostrcb *hostrcb;
2524 hostrcb = list_first_entry_or_null(&ioa->hostrcb_free_q,
2525 struct ipr_hostrcb, queue);
2527 if (unlikely(!hostrcb)) {
2528 dev_info(&ioa->pdev->dev, "Reclaiming async error buffers.");
2529 hostrcb = list_first_entry_or_null(&ioa->hostrcb_report_q,
2530 struct ipr_hostrcb, queue);
2533 list_del_init(&hostrcb->queue);
2538 * ipr_process_error - Op done function for an adapter error log.
2539 * @ipr_cmd: ipr command struct
2541 * This function is the op done function for an error log host
2542 * controlled async from the adapter. It will log the error and
2543 * send the HCAM back to the adapter.
2548 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2550 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2551 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
2552 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
2556 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2558 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2560 list_del_init(&hostrcb->queue);
2561 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
2564 ipr_handle_log_data(ioa_cfg, hostrcb);
2565 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
2566 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
2567 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET &&
2568 ioasc != IPR_IOASC_ABORTED_CMD_TERM_BY_HOST) {
2569 dev_err(&ioa_cfg->pdev->dev,
2570 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
2573 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_report_q);
2574 schedule_work(&ioa_cfg->work_q);
2575 hostrcb = ipr_get_free_hostrcb(ioa_cfg);
2577 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2581 * ipr_timeout - An internally generated op has timed out.
2582 * @t: Timer context used to fetch ipr command struct
2584 * This function blocks host requests and initiates an
2590 static void ipr_timeout(struct timer_list *t)
2592 struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
2593 unsigned long lock_flags = 0;
2594 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2597 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2599 ioa_cfg->errors_logged++;
2600 dev_err(&ioa_cfg->pdev->dev,
2601 "Adapter being reset due to command timeout.\n");
2603 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2604 ioa_cfg->sdt_state = GET_DUMP;
2606 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
2607 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2609 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2614 * ipr_oper_timeout - Adapter timed out transitioning to operational
2615 * @t: Timer context used to fetch ipr command struct
2617 * This function blocks host requests and initiates an
2623 static void ipr_oper_timeout(struct timer_list *t)
2625 struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
2626 unsigned long lock_flags = 0;
2627 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2630 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2632 ioa_cfg->errors_logged++;
2633 dev_err(&ioa_cfg->pdev->dev,
2634 "Adapter timed out transitioning to operational.\n");
2636 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2637 ioa_cfg->sdt_state = GET_DUMP;
2639 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
2641 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
2642 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2645 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2650 * ipr_find_ses_entry - Find matching SES in SES table
2651 * @res: resource entry struct of SES
2654 * pointer to SES table entry / NULL on failure
2656 static const struct ipr_ses_table_entry *
2657 ipr_find_ses_entry(struct ipr_resource_entry *res)
2660 struct ipr_std_inq_vpids *vpids;
2661 const struct ipr_ses_table_entry *ste = ipr_ses_table;
2663 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
2664 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
2665 if (ste->compare_product_id_byte[j] == 'X') {
2666 vpids = &res->std_inq_data.vpids;
2667 if (vpids->product_id[j] == ste->product_id[j])
2675 if (matches == IPR_PROD_ID_LEN)
2683 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2684 * @ioa_cfg: ioa config struct
2686 * @bus_width: bus width
2689 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2690 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2691 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2692 * max 160MHz = max 320MB/sec).
2694 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
2696 struct ipr_resource_entry *res;
2697 const struct ipr_ses_table_entry *ste;
2698 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
2700 /* Loop through each config table entry in the config table buffer */
2701 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2702 if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
2705 if (bus != res->bus)
2708 if (!(ste = ipr_find_ses_entry(res)))
2711 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
2714 return max_xfer_rate;
2718 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2719 * @ioa_cfg: ioa config struct
2720 * @max_delay: max delay in micro-seconds to wait
2722 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2725 * 0 on success / other on failure
2727 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
2729 volatile u32 pcii_reg;
2732 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2733 while (delay < max_delay) {
2734 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
2736 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
2739 /* udelay cannot be used if delay is more than a few milliseconds */
2740 if ((delay / 1000) > MAX_UDELAY_MS)
2741 mdelay(delay / 1000);
2751 * ipr_get_sis64_dump_data_section - Dump IOA memory
2752 * @ioa_cfg: ioa config struct
2753 * @start_addr: adapter address to dump
2754 * @dest: destination kernel buffer
2755 * @length_in_words: length to dump in 4 byte words
2760 static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2762 __be32 *dest, u32 length_in_words)
2766 for (i = 0; i < length_in_words; i++) {
2767 writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
2768 *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
2776 * ipr_get_ldump_data_section - Dump IOA memory
2777 * @ioa_cfg: ioa config struct
2778 * @start_addr: adapter address to dump
2779 * @dest: destination kernel buffer
2780 * @length_in_words: length to dump in 4 byte words
2783 * 0 on success / -EIO on failure
2785 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2787 __be32 *dest, u32 length_in_words)
2789 volatile u32 temp_pcii_reg;
2793 return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
2794 dest, length_in_words);
2796 /* Write IOA interrupt reg starting LDUMP state */
2797 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
2798 ioa_cfg->regs.set_uproc_interrupt_reg32);
2800 /* Wait for IO debug acknowledge */
2801 if (ipr_wait_iodbg_ack(ioa_cfg,
2802 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
2803 dev_err(&ioa_cfg->pdev->dev,
2804 "IOA dump long data transfer timeout\n");
2808 /* Signal LDUMP interlocked - clear IO debug ack */
2809 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2810 ioa_cfg->regs.clr_interrupt_reg);
2812 /* Write Mailbox with starting address */
2813 writel(start_addr, ioa_cfg->ioa_mailbox);
2815 /* Signal address valid - clear IOA Reset alert */
2816 writel(IPR_UPROCI_RESET_ALERT,
2817 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2819 for (i = 0; i < length_in_words; i++) {
2820 /* Wait for IO debug acknowledge */
2821 if (ipr_wait_iodbg_ack(ioa_cfg,
2822 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2823 dev_err(&ioa_cfg->pdev->dev,
2824 "IOA dump short data transfer timeout\n");
2828 /* Read data from mailbox and increment destination pointer */
2829 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2832 /* For all but the last word of data, signal data received */
2833 if (i < (length_in_words - 1)) {
2834 /* Signal dump data received - Clear IO debug Ack */
2835 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2836 ioa_cfg->regs.clr_interrupt_reg);
2840 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2841 writel(IPR_UPROCI_RESET_ALERT,
2842 ioa_cfg->regs.set_uproc_interrupt_reg32);
2844 writel(IPR_UPROCI_IO_DEBUG_ALERT,
2845 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2847 /* Signal dump data received - Clear IO debug Ack */
2848 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2849 ioa_cfg->regs.clr_interrupt_reg);
2851 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2852 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2854 readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
2856 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2866 #ifdef CONFIG_SCSI_IPR_DUMP
2868 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2869 * @ioa_cfg: ioa config struct
2870 * @pci_address: adapter address
2871 * @length: length of data to copy
2873 * Copy data from PCI adapter to kernel buffer.
2874 * Note: length MUST be a 4 byte multiple
2876 * 0 on success / other on failure
2878 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2879 unsigned long pci_address, u32 length)
2881 int bytes_copied = 0;
2882 int cur_len, rc, rem_len, rem_page_len, max_dump_size;
2884 unsigned long lock_flags = 0;
2885 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2888 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2890 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2892 while (bytes_copied < length &&
2893 (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
2894 if (ioa_dump->page_offset >= PAGE_SIZE ||
2895 ioa_dump->page_offset == 0) {
2896 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2900 return bytes_copied;
2903 ioa_dump->page_offset = 0;
2904 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2905 ioa_dump->next_page_index++;
2907 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2909 rem_len = length - bytes_copied;
2910 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2911 cur_len = min(rem_len, rem_page_len);
2913 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2914 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2917 rc = ipr_get_ldump_data_section(ioa_cfg,
2918 pci_address + bytes_copied,
2919 &page[ioa_dump->page_offset / 4],
2920 (cur_len / sizeof(u32)));
2922 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2925 ioa_dump->page_offset += cur_len;
2926 bytes_copied += cur_len;
2934 return bytes_copied;
2938 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2939 * @hdr: dump entry header struct
2944 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2946 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2948 hdr->offset = sizeof(*hdr);
2949 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2953 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2954 * @ioa_cfg: ioa config struct
2955 * @driver_dump: driver dump struct
2960 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2961 struct ipr_driver_dump *driver_dump)
2963 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2965 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2966 driver_dump->ioa_type_entry.hdr.len =
2967 sizeof(struct ipr_dump_ioa_type_entry) -
2968 sizeof(struct ipr_dump_entry_header);
2969 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2970 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2971 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2972 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2973 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2974 ucode_vpd->minor_release[1];
2975 driver_dump->hdr.num_entries++;
2979 * ipr_dump_version_data - Fill in the driver version in the dump.
2980 * @ioa_cfg: ioa config struct
2981 * @driver_dump: driver dump struct
2986 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2987 struct ipr_driver_dump *driver_dump)
2989 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2990 driver_dump->version_entry.hdr.len =
2991 sizeof(struct ipr_dump_version_entry) -
2992 sizeof(struct ipr_dump_entry_header);
2993 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2994 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2995 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2996 driver_dump->hdr.num_entries++;
3000 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
3001 * @ioa_cfg: ioa config struct
3002 * @driver_dump: driver dump struct
3007 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
3008 struct ipr_driver_dump *driver_dump)
3010 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
3011 driver_dump->trace_entry.hdr.len =
3012 sizeof(struct ipr_dump_trace_entry) -
3013 sizeof(struct ipr_dump_entry_header);
3014 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3015 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
3016 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
3017 driver_dump->hdr.num_entries++;
3021 * ipr_dump_location_data - Fill in the IOA location in the dump.
3022 * @ioa_cfg: ioa config struct
3023 * @driver_dump: driver dump struct
3028 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
3029 struct ipr_driver_dump *driver_dump)
3031 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
3032 driver_dump->location_entry.hdr.len =
3033 sizeof(struct ipr_dump_location_entry) -
3034 sizeof(struct ipr_dump_entry_header);
3035 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
3036 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
3037 strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
3038 driver_dump->hdr.num_entries++;
3042 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
3043 * @ioa_cfg: ioa config struct
3044 * @dump: dump struct
3049 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
3051 unsigned long start_addr, sdt_word;
3052 unsigned long lock_flags = 0;
3053 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
3054 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
3055 u32 num_entries, max_num_entries, start_off, end_off;
3056 u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
3057 struct ipr_sdt *sdt;
3063 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3065 if (ioa_cfg->sdt_state != READ_DUMP) {
3066 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3070 if (ioa_cfg->sis64) {
3071 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3072 ssleep(IPR_DUMP_DELAY_SECONDS);
3073 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3076 start_addr = readl(ioa_cfg->ioa_mailbox);
3078 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
3079 dev_err(&ioa_cfg->pdev->dev,
3080 "Invalid dump table format: %lx\n", start_addr);
3081 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3085 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
3087 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
3089 /* Initialize the overall dump header */
3090 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
3091 driver_dump->hdr.num_entries = 1;
3092 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
3093 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
3094 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
3095 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
3097 ipr_dump_version_data(ioa_cfg, driver_dump);
3098 ipr_dump_location_data(ioa_cfg, driver_dump);
3099 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
3100 ipr_dump_trace_data(ioa_cfg, driver_dump);
3102 /* Update dump_header */
3103 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
3105 /* IOA Dump entry */
3106 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
3107 ioa_dump->hdr.len = 0;
3108 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3109 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
3111 /* First entries in sdt are actually a list of dump addresses and
3112 lengths to gather the real dump data. sdt represents the pointer
3113 to the ioa generated dump table. Dump data will be extracted based
3114 on entries in this table */
3115 sdt = &ioa_dump->sdt;
3117 if (ioa_cfg->sis64) {
3118 max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
3119 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
3121 max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
3122 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
3125 bytes_to_copy = offsetof(struct ipr_sdt, entry) +
3126 (max_num_entries * sizeof(struct ipr_sdt_entry));
3127 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
3128 bytes_to_copy / sizeof(__be32));
3130 /* Smart Dump table is ready to use and the first entry is valid */
3131 if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
3132 (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
3133 dev_err(&ioa_cfg->pdev->dev,
3134 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
3135 rc, be32_to_cpu(sdt->hdr.state));
3136 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
3137 ioa_cfg->sdt_state = DUMP_OBTAINED;
3138 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3142 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
3144 if (num_entries > max_num_entries)
3145 num_entries = max_num_entries;
3147 /* Update dump length to the actual data to be copied */
3148 dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
3150 dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
3152 dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
3154 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3156 for (i = 0; i < num_entries; i++) {
3157 if (ioa_dump->hdr.len > max_dump_size) {
3158 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3162 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
3163 sdt_word = be32_to_cpu(sdt->entry[i].start_token);
3165 bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
3167 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
3168 end_off = be32_to_cpu(sdt->entry[i].end_token);
3170 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
3171 bytes_to_copy = end_off - start_off;
3176 if (bytes_to_copy > max_dump_size) {
3177 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
3181 /* Copy data from adapter to driver buffers */
3182 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
3185 ioa_dump->hdr.len += bytes_copied;
3187 if (bytes_copied != bytes_to_copy) {
3188 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3195 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
3197 /* Update dump_header */
3198 driver_dump->hdr.len += ioa_dump->hdr.len;
3200 ioa_cfg->sdt_state = DUMP_OBTAINED;
3205 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while (0)
3209 * ipr_release_dump - Free adapter dump memory
3210 * @kref: kref struct
3215 static void ipr_release_dump(struct kref *kref)
3217 struct ipr_dump *dump = container_of(kref, struct ipr_dump, kref);
3218 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
3219 unsigned long lock_flags = 0;
3223 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3224 ioa_cfg->dump = NULL;
3225 ioa_cfg->sdt_state = INACTIVE;
3226 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3228 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
3229 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
3231 vfree(dump->ioa_dump.ioa_data);
3236 static void ipr_add_remove_thread(struct work_struct *work)
3238 unsigned long lock_flags;
3239 struct ipr_resource_entry *res;
3240 struct scsi_device *sdev;
3241 struct ipr_ioa_cfg *ioa_cfg =
3242 container_of(work, struct ipr_ioa_cfg, scsi_add_work_q);
3243 u8 bus, target, lun;
3247 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3252 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
3253 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3257 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3258 if (res->del_from_ml && res->sdev) {
3261 if (!scsi_device_get(sdev)) {
3262 if (!res->add_to_ml)
3263 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
3265 res->del_from_ml = 0;
3266 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3267 scsi_remove_device(sdev);
3268 scsi_device_put(sdev);
3269 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3276 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3277 if (res->add_to_ml) {
3279 target = res->target;
3282 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3283 scsi_add_device(ioa_cfg->host, bus, target, lun);
3284 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3289 ioa_cfg->scan_done = 1;
3290 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3291 kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
3296 * ipr_worker_thread - Worker thread
3297 * @work: ioa config struct
3299 * Called at task level from a work thread. This function takes care
3300 * of adding and removing device from the mid-layer as configuration
3301 * changes are detected by the adapter.
3306 static void ipr_worker_thread(struct work_struct *work)
3308 unsigned long lock_flags;
3309 struct ipr_dump *dump;
3310 struct ipr_ioa_cfg *ioa_cfg =
3311 container_of(work, struct ipr_ioa_cfg, work_q);
3314 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3316 if (ioa_cfg->sdt_state == READ_DUMP) {
3317 dump = ioa_cfg->dump;
3319 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3322 kref_get(&dump->kref);
3323 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3324 ipr_get_ioa_dump(ioa_cfg, dump);
3325 kref_put(&dump->kref, ipr_release_dump);
3327 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3328 if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
3329 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3330 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3334 if (ioa_cfg->scsi_unblock) {
3335 ioa_cfg->scsi_unblock = 0;
3336 ioa_cfg->scsi_blocked = 0;
3337 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3338 scsi_unblock_requests(ioa_cfg->host);
3339 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3340 if (ioa_cfg->scsi_blocked)
3341 scsi_block_requests(ioa_cfg->host);
3344 if (!ioa_cfg->scan_enabled) {
3345 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3349 schedule_work(&ioa_cfg->scsi_add_work_q);
3351 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3355 #ifdef CONFIG_SCSI_IPR_TRACE
3357 * ipr_read_trace - Dump the adapter trace
3358 * @filp: open sysfs file
3359 * @kobj: kobject struct
3360 * @bin_attr: bin_attribute struct
3363 * @count: buffer size
3366 * number of bytes printed to buffer
3368 static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
3369 struct bin_attribute *bin_attr,
3370 char *buf, loff_t off, size_t count)
3372 struct device *dev = kobj_to_dev(kobj);
3373 struct Scsi_Host *shost = class_to_shost(dev);
3374 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3375 unsigned long lock_flags = 0;
3378 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3379 ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
3381 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3386 static struct bin_attribute ipr_trace_attr = {
3392 .read = ipr_read_trace,
3397 * ipr_show_fw_version - Show the firmware version
3398 * @dev: class device struct
3399 * @attr: device attribute (unused)
3403 * number of bytes printed to buffer
3405 static ssize_t ipr_show_fw_version(struct device *dev,
3406 struct device_attribute *attr, char *buf)
3408 struct Scsi_Host *shost = class_to_shost(dev);
3409 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3410 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
3411 unsigned long lock_flags = 0;
3414 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3415 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
3416 ucode_vpd->major_release, ucode_vpd->card_type,
3417 ucode_vpd->minor_release[0],
3418 ucode_vpd->minor_release[1]);
3419 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3423 static struct device_attribute ipr_fw_version_attr = {
3425 .name = "fw_version",
3428 .show = ipr_show_fw_version,
3432 * ipr_show_log_level - Show the adapter's error logging level
3433 * @dev: class device struct
3434 * @attr: device attribute (unused)
3438 * number of bytes printed to buffer
3440 static ssize_t ipr_show_log_level(struct device *dev,
3441 struct device_attribute *attr, char *buf)
3443 struct Scsi_Host *shost = class_to_shost(dev);
3444 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3445 unsigned long lock_flags = 0;
3448 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3449 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
3450 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3455 * ipr_store_log_level - Change the adapter's error logging level
3456 * @dev: class device struct
3457 * @attr: device attribute (unused)
3459 * @count: buffer size
3462 * number of bytes printed to buffer
3464 static ssize_t ipr_store_log_level(struct device *dev,
3465 struct device_attribute *attr,
3466 const char *buf, size_t count)
3468 struct Scsi_Host *shost = class_to_shost(dev);
3469 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3470 unsigned long lock_flags = 0;
3472 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3473 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
3474 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3478 static struct device_attribute ipr_log_level_attr = {
3480 .name = "log_level",
3481 .mode = S_IRUGO | S_IWUSR,
3483 .show = ipr_show_log_level,
3484 .store = ipr_store_log_level
3488 * ipr_store_diagnostics - IOA Diagnostics interface
3489 * @dev: device struct
3490 * @attr: device attribute (unused)
3492 * @count: buffer size
3494 * This function will reset the adapter and wait a reasonable
3495 * amount of time for any errors that the adapter might log.
3498 * count on success / other on failure
3500 static ssize_t ipr_store_diagnostics(struct device *dev,
3501 struct device_attribute *attr,
3502 const char *buf, size_t count)
3504 struct Scsi_Host *shost = class_to_shost(dev);
3505 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3506 unsigned long lock_flags = 0;
3509 if (!capable(CAP_SYS_ADMIN))
3512 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3513 while (ioa_cfg->in_reset_reload) {
3514 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3515 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3516 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3519 ioa_cfg->errors_logged = 0;
3520 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3522 if (ioa_cfg->in_reset_reload) {
3523 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3524 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3526 /* Wait for a second for any errors to be logged */
3529 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3533 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3534 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
3536 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3541 static struct device_attribute ipr_diagnostics_attr = {
3543 .name = "run_diagnostics",
3546 .store = ipr_store_diagnostics
3550 * ipr_show_adapter_state - Show the adapter's state
3551 * @dev: device struct
3552 * @attr: device attribute (unused)
3556 * number of bytes printed to buffer
3558 static ssize_t ipr_show_adapter_state(struct device *dev,
3559 struct device_attribute *attr, char *buf)
3561 struct Scsi_Host *shost = class_to_shost(dev);
3562 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3563 unsigned long lock_flags = 0;
3566 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3567 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
3568 len = snprintf(buf, PAGE_SIZE, "offline\n");
3570 len = snprintf(buf, PAGE_SIZE, "online\n");
3571 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3576 * ipr_store_adapter_state - Change adapter state
3577 * @dev: device struct
3578 * @attr: device attribute (unused)
3580 * @count: buffer size
3582 * This function will change the adapter's state.
3585 * count on success / other on failure
3587 static ssize_t ipr_store_adapter_state(struct device *dev,
3588 struct device_attribute *attr,
3589 const char *buf, size_t count)
3591 struct Scsi_Host *shost = class_to_shost(dev);
3592 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3593 unsigned long lock_flags;
3594 int result = count, i;
3596 if (!capable(CAP_SYS_ADMIN))
3599 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3600 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead &&
3601 !strncmp(buf, "online", 6)) {
3602 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
3603 spin_lock(&ioa_cfg->hrrq[i]._lock);
3604 ioa_cfg->hrrq[i].ioa_is_dead = 0;
3605 spin_unlock(&ioa_cfg->hrrq[i]._lock);
3608 ioa_cfg->reset_retries = 0;
3609 ioa_cfg->in_ioa_bringdown = 0;
3610 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3612 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3613 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3618 static struct device_attribute ipr_ioa_state_attr = {
3620 .name = "online_state",
3621 .mode = S_IRUGO | S_IWUSR,
3623 .show = ipr_show_adapter_state,
3624 .store = ipr_store_adapter_state
3628 * ipr_store_reset_adapter - Reset the adapter
3629 * @dev: device struct
3630 * @attr: device attribute (unused)
3632 * @count: buffer size
3634 * This function will reset the adapter.
3637 * count on success / other on failure
3639 static ssize_t ipr_store_reset_adapter(struct device *dev,
3640 struct device_attribute *attr,
3641 const char *buf, size_t count)
3643 struct Scsi_Host *shost = class_to_shost(dev);
3644 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3645 unsigned long lock_flags;
3648 if (!capable(CAP_SYS_ADMIN))
3651 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3652 if (!ioa_cfg->in_reset_reload)
3653 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3654 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3655 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3660 static struct device_attribute ipr_ioa_reset_attr = {
3662 .name = "reset_host",
3665 .store = ipr_store_reset_adapter
3668 static int ipr_iopoll(struct irq_poll *iop, int budget);
3670 * ipr_show_iopoll_weight - Show ipr polling mode
3671 * @dev: class device struct
3672 * @attr: device attribute (unused)
3676 * number of bytes printed to buffer
3678 static ssize_t ipr_show_iopoll_weight(struct device *dev,
3679 struct device_attribute *attr, char *buf)
3681 struct Scsi_Host *shost = class_to_shost(dev);
3682 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3683 unsigned long lock_flags = 0;
3686 spin_lock_irqsave(shost->host_lock, lock_flags);
3687 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->iopoll_weight);
3688 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3694 * ipr_store_iopoll_weight - Change the adapter's polling mode
3695 * @dev: class device struct
3696 * @attr: device attribute (unused)
3698 * @count: buffer size
3701 * number of bytes printed to buffer
3703 static ssize_t ipr_store_iopoll_weight(struct device *dev,
3704 struct device_attribute *attr,
3705 const char *buf, size_t count)
3707 struct Scsi_Host *shost = class_to_shost(dev);
3708 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3709 unsigned long user_iopoll_weight;
3710 unsigned long lock_flags = 0;
3713 if (!ioa_cfg->sis64) {
3714 dev_info(&ioa_cfg->pdev->dev, "irq_poll not supported on this adapter\n");
3717 if (kstrtoul(buf, 10, &user_iopoll_weight))
3720 if (user_iopoll_weight > 256) {
3721 dev_info(&ioa_cfg->pdev->dev, "Invalid irq_poll weight. It must be less than 256\n");
3725 if (user_iopoll_weight == ioa_cfg->iopoll_weight) {
3726 dev_info(&ioa_cfg->pdev->dev, "Current irq_poll weight has the same weight\n");
3730 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
3731 for (i = 1; i < ioa_cfg->hrrq_num; i++)
3732 irq_poll_disable(&ioa_cfg->hrrq[i].iopoll);
3735 spin_lock_irqsave(shost->host_lock, lock_flags);
3736 ioa_cfg->iopoll_weight = user_iopoll_weight;
3737 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
3738 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
3739 irq_poll_init(&ioa_cfg->hrrq[i].iopoll,
3740 ioa_cfg->iopoll_weight, ipr_iopoll);
3743 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3748 static struct device_attribute ipr_iopoll_weight_attr = {
3750 .name = "iopoll_weight",
3751 .mode = S_IRUGO | S_IWUSR,
3753 .show = ipr_show_iopoll_weight,
3754 .store = ipr_store_iopoll_weight
3758 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3759 * @buf_len: buffer length
3761 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3762 * list to use for microcode download
3765 * pointer to sglist / NULL on failure
3767 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
3770 struct ipr_sglist *sglist;
3772 /* Get the minimum size per scatter/gather element */
3773 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
3775 /* Get the actual size per element */
3776 order = get_order(sg_size);
3778 /* Allocate a scatter/gather list for the DMA */
3779 sglist = kzalloc(sizeof(struct ipr_sglist), GFP_KERNEL);
3780 if (sglist == NULL) {
3784 sglist->order = order;
3785 sglist->scatterlist = sgl_alloc_order(buf_len, order, false, GFP_KERNEL,
3787 if (!sglist->scatterlist) {
3796 * ipr_free_ucode_buffer - Frees a microcode download buffer
3797 * @sglist: scatter/gather list pointer
3799 * Free a DMA'able ucode download buffer previously allocated with
3800 * ipr_alloc_ucode_buffer
3805 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
3807 sgl_free_order(sglist->scatterlist, sglist->order);
3812 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3813 * @sglist: scatter/gather list pointer
3814 * @buffer: buffer pointer
3815 * @len: buffer length
3817 * Copy a microcode image from a user buffer into a buffer allocated by
3818 * ipr_alloc_ucode_buffer
3821 * 0 on success / other on failure
3823 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
3824 u8 *buffer, u32 len)
3826 int bsize_elem, i, result = 0;
3827 struct scatterlist *sg;
3829 /* Determine the actual number of bytes per element */
3830 bsize_elem = PAGE_SIZE * (1 << sglist->order);
3832 sg = sglist->scatterlist;
3834 for (i = 0; i < (len / bsize_elem); i++, sg = sg_next(sg),
3835 buffer += bsize_elem) {
3836 struct page *page = sg_page(sg);
3838 memcpy_to_page(page, 0, buffer, bsize_elem);
3840 sg->length = bsize_elem;
3848 if (len % bsize_elem) {
3849 struct page *page = sg_page(sg);
3851 memcpy_to_page(page, 0, buffer, len % bsize_elem);
3853 sg->length = len % bsize_elem;
3856 sglist->buffer_len = len;
3861 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3862 * @ipr_cmd: ipr command struct
3863 * @sglist: scatter/gather list
3865 * Builds a microcode download IOA data list (IOADL).
3868 static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
3869 struct ipr_sglist *sglist)
3871 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3872 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
3873 struct scatterlist *scatterlist = sglist->scatterlist;
3874 struct scatterlist *sg;
3877 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3878 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3879 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3882 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
3883 for_each_sg(scatterlist, sg, ipr_cmd->dma_use_sg, i) {
3884 ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
3885 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
3886 ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
3889 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3893 * ipr_build_ucode_ioadl - Build a microcode download IOADL
3894 * @ipr_cmd: ipr command struct
3895 * @sglist: scatter/gather list
3897 * Builds a microcode download IOA data list (IOADL).
3900 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
3901 struct ipr_sglist *sglist)
3903 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3904 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
3905 struct scatterlist *scatterlist = sglist->scatterlist;
3906 struct scatterlist *sg;
3909 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3910 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3911 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3914 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3916 for_each_sg(scatterlist, sg, ipr_cmd->dma_use_sg, i) {
3917 ioadl[i].flags_and_data_len =
3918 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(sg));
3920 cpu_to_be32(sg_dma_address(sg));
3923 ioadl[i-1].flags_and_data_len |=
3924 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3928 * ipr_update_ioa_ucode - Update IOA's microcode
3929 * @ioa_cfg: ioa config struct
3930 * @sglist: scatter/gather list
3932 * Initiate an adapter reset to update the IOA's microcode
3935 * 0 on success / -EIO on failure
3937 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3938 struct ipr_sglist *sglist)
3940 unsigned long lock_flags;
3942 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3943 while (ioa_cfg->in_reset_reload) {
3944 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3945 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3946 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3949 if (ioa_cfg->ucode_sglist) {
3950 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3951 dev_err(&ioa_cfg->pdev->dev,
3952 "Microcode download already in progress\n");
3956 sglist->num_dma_sg = dma_map_sg(&ioa_cfg->pdev->dev,
3957 sglist->scatterlist, sglist->num_sg,
3960 if (!sglist->num_dma_sg) {
3961 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3962 dev_err(&ioa_cfg->pdev->dev,
3963 "Failed to map microcode download buffer!\n");
3967 ioa_cfg->ucode_sglist = sglist;
3968 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3969 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3970 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3972 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3973 ioa_cfg->ucode_sglist = NULL;
3974 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3979 * ipr_store_update_fw - Update the firmware on the adapter
3980 * @dev: device struct
3981 * @attr: device attribute (unused)
3983 * @count: buffer size
3985 * This function will update the firmware on the adapter.
3988 * count on success / other on failure
3990 static ssize_t ipr_store_update_fw(struct device *dev,
3991 struct device_attribute *attr,
3992 const char *buf, size_t count)
3994 struct Scsi_Host *shost = class_to_shost(dev);
3995 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3996 struct ipr_ucode_image_header *image_hdr;
3997 const struct firmware *fw_entry;
3998 struct ipr_sglist *sglist;
4002 int result, dnld_size;
4004 if (!capable(CAP_SYS_ADMIN))
4007 snprintf(fname, sizeof(fname), "%s", buf);
4009 endline = strchr(fname, '\n');
4013 if (request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
4014 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
4018 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
4020 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
4021 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
4022 sglist = ipr_alloc_ucode_buffer(dnld_size);
4025 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
4026 release_firmware(fw_entry);
4030 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
4033 dev_err(&ioa_cfg->pdev->dev,
4034 "Microcode buffer copy to DMA buffer failed\n");
4038 ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
4040 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
4045 ipr_free_ucode_buffer(sglist);
4046 release_firmware(fw_entry);
4050 static struct device_attribute ipr_update_fw_attr = {
4052 .name = "update_fw",
4055 .store = ipr_store_update_fw
4059 * ipr_show_fw_type - Show the adapter's firmware type.
4060 * @dev: class device struct
4061 * @attr: device attribute (unused)
4065 * number of bytes printed to buffer
4067 static ssize_t ipr_show_fw_type(struct device *dev,
4068 struct device_attribute *attr, char *buf)
4070 struct Scsi_Host *shost = class_to_shost(dev);
4071 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4072 unsigned long lock_flags = 0;
4075 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4076 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
4077 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4081 static struct device_attribute ipr_ioa_fw_type_attr = {
4086 .show = ipr_show_fw_type
4089 static ssize_t ipr_read_async_err_log(struct file *filep, struct kobject *kobj,
4090 struct bin_attribute *bin_attr, char *buf,
4091 loff_t off, size_t count)
4093 struct device *cdev = kobj_to_dev(kobj);
4094 struct Scsi_Host *shost = class_to_shost(cdev);
4095 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4096 struct ipr_hostrcb *hostrcb;
4097 unsigned long lock_flags = 0;
4100 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4101 hostrcb = list_first_entry_or_null(&ioa_cfg->hostrcb_report_q,
4102 struct ipr_hostrcb, queue);
4104 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4107 ret = memory_read_from_buffer(buf, count, &off, &hostrcb->hcam,
4108 sizeof(hostrcb->hcam));
4109 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4113 static ssize_t ipr_next_async_err_log(struct file *filep, struct kobject *kobj,
4114 struct bin_attribute *bin_attr, char *buf,
4115 loff_t off, size_t count)
4117 struct device *cdev = kobj_to_dev(kobj);
4118 struct Scsi_Host *shost = class_to_shost(cdev);
4119 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4120 struct ipr_hostrcb *hostrcb;
4121 unsigned long lock_flags = 0;
4123 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4124 hostrcb = list_first_entry_or_null(&ioa_cfg->hostrcb_report_q,
4125 struct ipr_hostrcb, queue);
4127 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4131 /* Reclaim hostrcb before exit */
4132 list_move_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
4133 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4137 static struct bin_attribute ipr_ioa_async_err_log = {
4139 .name = "async_err_log",
4140 .mode = S_IRUGO | S_IWUSR,
4143 .read = ipr_read_async_err_log,
4144 .write = ipr_next_async_err_log
4147 static struct attribute *ipr_ioa_attrs[] = {
4148 &ipr_fw_version_attr.attr,
4149 &ipr_log_level_attr.attr,
4150 &ipr_diagnostics_attr.attr,
4151 &ipr_ioa_state_attr.attr,
4152 &ipr_ioa_reset_attr.attr,
4153 &ipr_update_fw_attr.attr,
4154 &ipr_ioa_fw_type_attr.attr,
4155 &ipr_iopoll_weight_attr.attr,
4159 ATTRIBUTE_GROUPS(ipr_ioa);
4161 #ifdef CONFIG_SCSI_IPR_DUMP
4163 * ipr_read_dump - Dump the adapter
4164 * @filp: open sysfs file
4165 * @kobj: kobject struct
4166 * @bin_attr: bin_attribute struct
4169 * @count: buffer size
4172 * number of bytes printed to buffer
4174 static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
4175 struct bin_attribute *bin_attr,
4176 char *buf, loff_t off, size_t count)
4178 struct device *cdev = kobj_to_dev(kobj);
4179 struct Scsi_Host *shost = class_to_shost(cdev);
4180 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4181 struct ipr_dump *dump;
4182 unsigned long lock_flags = 0;
4187 if (!capable(CAP_SYS_ADMIN))
4190 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4191 dump = ioa_cfg->dump;
4193 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
4194 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4197 kref_get(&dump->kref);
4198 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4200 if (off > dump->driver_dump.hdr.len) {
4201 kref_put(&dump->kref, ipr_release_dump);
4205 if (off + count > dump->driver_dump.hdr.len) {
4206 count = dump->driver_dump.hdr.len - off;
4210 if (count && off < sizeof(dump->driver_dump)) {
4211 if (off + count > sizeof(dump->driver_dump))
4212 len = sizeof(dump->driver_dump) - off;
4215 src = (u8 *)&dump->driver_dump + off;
4216 memcpy(buf, src, len);
4222 off -= sizeof(dump->driver_dump);
4225 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4226 (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
4227 sizeof(struct ipr_sdt_entry));
4229 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4230 (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
4232 if (count && off < sdt_end) {
4233 if (off + count > sdt_end)
4234 len = sdt_end - off;
4237 src = (u8 *)&dump->ioa_dump + off;
4238 memcpy(buf, src, len);
4247 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
4248 len = PAGE_ALIGN(off) - off;
4251 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
4252 src += off & ~PAGE_MASK;
4253 memcpy(buf, src, len);
4259 kref_put(&dump->kref, ipr_release_dump);
4264 * ipr_alloc_dump - Prepare for adapter dump
4265 * @ioa_cfg: ioa config struct
4268 * 0 on success / other on failure
4270 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
4272 struct ipr_dump *dump;
4274 unsigned long lock_flags = 0;
4276 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
4279 ipr_err("Dump memory allocation failed\n");
4284 ioa_data = vmalloc(array_size(IPR_FMT3_MAX_NUM_DUMP_PAGES,
4287 ioa_data = vmalloc(array_size(IPR_FMT2_MAX_NUM_DUMP_PAGES,
4291 ipr_err("Dump memory allocation failed\n");
4296 dump->ioa_dump.ioa_data = ioa_data;
4298 kref_init(&dump->kref);
4299 dump->ioa_cfg = ioa_cfg;
4301 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4303 if (INACTIVE != ioa_cfg->sdt_state) {
4304 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4305 vfree(dump->ioa_dump.ioa_data);
4310 ioa_cfg->dump = dump;
4311 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
4312 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead && !ioa_cfg->dump_taken) {
4313 ioa_cfg->dump_taken = 1;
4314 schedule_work(&ioa_cfg->work_q);
4316 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4322 * ipr_free_dump - Free adapter dump memory
4323 * @ioa_cfg: ioa config struct
4326 * 0 on success / other on failure
4328 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
4330 struct ipr_dump *dump;
4331 unsigned long lock_flags = 0;
4335 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4336 dump = ioa_cfg->dump;
4338 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4342 ioa_cfg->dump = NULL;
4343 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4345 kref_put(&dump->kref, ipr_release_dump);
4352 * ipr_write_dump - Setup dump state of adapter
4353 * @filp: open sysfs file
4354 * @kobj: kobject struct
4355 * @bin_attr: bin_attribute struct
4358 * @count: buffer size
4361 * number of bytes printed to buffer
4363 static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
4364 struct bin_attribute *bin_attr,
4365 char *buf, loff_t off, size_t count)
4367 struct device *cdev = kobj_to_dev(kobj);
4368 struct Scsi_Host *shost = class_to_shost(cdev);
4369 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4372 if (!capable(CAP_SYS_ADMIN))
4376 rc = ipr_alloc_dump(ioa_cfg);
4377 else if (buf[0] == '0')
4378 rc = ipr_free_dump(ioa_cfg);
4388 static struct bin_attribute ipr_dump_attr = {
4391 .mode = S_IRUSR | S_IWUSR,
4394 .read = ipr_read_dump,
4395 .write = ipr_write_dump
4398 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
4402 * ipr_change_queue_depth - Change the device's queue depth
4403 * @sdev: scsi device struct
4404 * @qdepth: depth to set
4409 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
4411 scsi_change_queue_depth(sdev, qdepth);
4412 return sdev->queue_depth;
4416 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4417 * @dev: device struct
4418 * @attr: device attribute structure
4422 * number of bytes printed to buffer
4424 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
4426 struct scsi_device *sdev = to_scsi_device(dev);
4427 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4428 struct ipr_resource_entry *res;
4429 unsigned long lock_flags = 0;
4430 ssize_t len = -ENXIO;
4432 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4433 res = (struct ipr_resource_entry *)sdev->hostdata;
4435 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
4436 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4440 static struct device_attribute ipr_adapter_handle_attr = {
4442 .name = "adapter_handle",
4445 .show = ipr_show_adapter_handle
4449 * ipr_show_resource_path - Show the resource path or the resource address for
4451 * @dev: device struct
4452 * @attr: device attribute structure
4456 * number of bytes printed to buffer
4458 static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
4460 struct scsi_device *sdev = to_scsi_device(dev);
4461 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4462 struct ipr_resource_entry *res;
4463 unsigned long lock_flags = 0;
4464 ssize_t len = -ENXIO;
4465 char buffer[IPR_MAX_RES_PATH_LENGTH];
4467 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4468 res = (struct ipr_resource_entry *)sdev->hostdata;
4469 if (res && ioa_cfg->sis64)
4470 len = snprintf(buf, PAGE_SIZE, "%s\n",
4471 __ipr_format_res_path(res->res_path, buffer,
4474 len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
4475 res->bus, res->target, res->lun);
4477 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4481 static struct device_attribute ipr_resource_path_attr = {
4483 .name = "resource_path",
4486 .show = ipr_show_resource_path
4490 * ipr_show_device_id - Show the device_id for this device.
4491 * @dev: device struct
4492 * @attr: device attribute structure
4496 * number of bytes printed to buffer
4498 static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
4500 struct scsi_device *sdev = to_scsi_device(dev);
4501 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4502 struct ipr_resource_entry *res;
4503 unsigned long lock_flags = 0;
4504 ssize_t len = -ENXIO;
4506 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4507 res = (struct ipr_resource_entry *)sdev->hostdata;
4508 if (res && ioa_cfg->sis64)
4509 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", be64_to_cpu(res->dev_id));
4511 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
4513 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4517 static struct device_attribute ipr_device_id_attr = {
4519 .name = "device_id",
4522 .show = ipr_show_device_id
4526 * ipr_show_resource_type - Show the resource type for this device.
4527 * @dev: device struct
4528 * @attr: device attribute structure
4532 * number of bytes printed to buffer
4534 static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
4536 struct scsi_device *sdev = to_scsi_device(dev);
4537 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4538 struct ipr_resource_entry *res;
4539 unsigned long lock_flags = 0;
4540 ssize_t len = -ENXIO;
4542 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4543 res = (struct ipr_resource_entry *)sdev->hostdata;
4546 len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
4548 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4552 static struct device_attribute ipr_resource_type_attr = {
4554 .name = "resource_type",
4557 .show = ipr_show_resource_type
4561 * ipr_show_raw_mode - Show the adapter's raw mode
4562 * @dev: class device struct
4563 * @attr: device attribute (unused)
4567 * number of bytes printed to buffer
4569 static ssize_t ipr_show_raw_mode(struct device *dev,
4570 struct device_attribute *attr, char *buf)
4572 struct scsi_device *sdev = to_scsi_device(dev);
4573 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4574 struct ipr_resource_entry *res;
4575 unsigned long lock_flags = 0;
4578 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4579 res = (struct ipr_resource_entry *)sdev->hostdata;
4581 len = snprintf(buf, PAGE_SIZE, "%d\n", res->raw_mode);
4584 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4589 * ipr_store_raw_mode - Change the adapter's raw mode
4590 * @dev: class device struct
4591 * @attr: device attribute (unused)
4593 * @count: buffer size
4596 * number of bytes printed to buffer
4598 static ssize_t ipr_store_raw_mode(struct device *dev,
4599 struct device_attribute *attr,
4600 const char *buf, size_t count)
4602 struct scsi_device *sdev = to_scsi_device(dev);
4603 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4604 struct ipr_resource_entry *res;
4605 unsigned long lock_flags = 0;
4608 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4609 res = (struct ipr_resource_entry *)sdev->hostdata;
4611 if (ipr_is_af_dasd_device(res)) {
4612 res->raw_mode = simple_strtoul(buf, NULL, 10);
4615 sdev_printk(KERN_INFO, res->sdev, "raw mode is %s\n",
4616 res->raw_mode ? "enabled" : "disabled");
4621 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4625 static struct device_attribute ipr_raw_mode_attr = {
4628 .mode = S_IRUGO | S_IWUSR,
4630 .show = ipr_show_raw_mode,
4631 .store = ipr_store_raw_mode
4634 static struct attribute *ipr_dev_attrs[] = {
4635 &ipr_adapter_handle_attr.attr,
4636 &ipr_resource_path_attr.attr,
4637 &ipr_device_id_attr.attr,
4638 &ipr_resource_type_attr.attr,
4639 &ipr_raw_mode_attr.attr,
4643 ATTRIBUTE_GROUPS(ipr_dev);
4646 * ipr_biosparam - Return the HSC mapping
4647 * @sdev: scsi device struct
4648 * @block_device: block device pointer
4649 * @capacity: capacity of the device
4650 * @parm: Array containing returned HSC values.
4652 * This function generates the HSC parms that fdisk uses.
4653 * We want to make sure we return something that places partitions
4654 * on 4k boundaries for best performance with the IOA.
4659 static int ipr_biosparam(struct scsi_device *sdev,
4660 struct block_device *block_device,
4661 sector_t capacity, int *parm)
4669 cylinders = capacity;
4670 sector_div(cylinders, (128 * 32));
4675 parm[2] = cylinders;
4681 * ipr_find_starget - Find target based on bus/target.
4682 * @starget: scsi target struct
4685 * resource entry pointer if found / NULL if not found
4687 static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
4689 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4690 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4691 struct ipr_resource_entry *res;
4693 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4694 if ((res->bus == starget->channel) &&
4695 (res->target == starget->id)) {
4704 * ipr_target_destroy - Destroy a SCSI target
4705 * @starget: scsi target struct
4708 static void ipr_target_destroy(struct scsi_target *starget)
4710 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4711 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4713 if (ioa_cfg->sis64) {
4714 if (!ipr_find_starget(starget)) {
4715 if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4716 clear_bit(starget->id, ioa_cfg->array_ids);
4717 else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4718 clear_bit(starget->id, ioa_cfg->vset_ids);
4719 else if (starget->channel == 0)
4720 clear_bit(starget->id, ioa_cfg->target_ids);
4726 * ipr_find_sdev - Find device based on bus/target/lun.
4727 * @sdev: scsi device struct
4730 * resource entry pointer if found / NULL if not found
4732 static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
4734 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4735 struct ipr_resource_entry *res;
4737 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4738 if ((res->bus == sdev->channel) &&
4739 (res->target == sdev->id) &&
4740 (res->lun == sdev->lun))
4748 * ipr_slave_destroy - Unconfigure a SCSI device
4749 * @sdev: scsi device struct
4754 static void ipr_slave_destroy(struct scsi_device *sdev)
4756 struct ipr_resource_entry *res;
4757 struct ipr_ioa_cfg *ioa_cfg;
4758 unsigned long lock_flags = 0;
4760 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4762 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4763 res = (struct ipr_resource_entry *) sdev->hostdata;
4765 sdev->hostdata = NULL;
4768 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4772 * ipr_slave_configure - Configure a SCSI device
4773 * @sdev: scsi device struct
4775 * This function configures the specified scsi device.
4780 static int ipr_slave_configure(struct scsi_device *sdev)
4782 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4783 struct ipr_resource_entry *res;
4784 unsigned long lock_flags = 0;
4785 char buffer[IPR_MAX_RES_PATH_LENGTH];
4787 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4788 res = sdev->hostdata;
4790 if (ipr_is_af_dasd_device(res))
4791 sdev->type = TYPE_RAID;
4792 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
4793 sdev->scsi_level = 4;
4794 sdev->no_uld_attach = 1;
4796 if (ipr_is_vset_device(res)) {
4797 sdev->scsi_level = SCSI_SPC_3;
4798 sdev->no_report_opcodes = 1;
4799 blk_queue_rq_timeout(sdev->request_queue,
4800 IPR_VSET_RW_TIMEOUT);
4801 blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
4803 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4806 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
4807 ipr_format_res_path(ioa_cfg,
4808 res->res_path, buffer, sizeof(buffer)));
4811 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4816 * ipr_slave_alloc - Prepare for commands to a device.
4817 * @sdev: scsi device struct
4819 * This function saves a pointer to the resource entry
4820 * in the scsi device struct if the device exists. We
4821 * can then use this pointer in ipr_queuecommand when
4822 * handling new commands.
4825 * 0 on success / -ENXIO if device does not exist
4827 static int ipr_slave_alloc(struct scsi_device *sdev)
4829 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4830 struct ipr_resource_entry *res;
4831 unsigned long lock_flags;
4834 sdev->hostdata = NULL;
4836 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4838 res = ipr_find_sdev(sdev);
4843 sdev->hostdata = res;
4844 if (!ipr_is_naca_model(res))
4845 res->needs_sync_complete = 1;
4847 if (ipr_is_gata(res)) {
4848 sdev_printk(KERN_ERR, sdev, "SATA devices are no longer "
4849 "supported by this driver. Skipping device.\n");
4850 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4855 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4861 * ipr_match_lun - Match function for specified LUN
4862 * @ipr_cmd: ipr command struct
4863 * @device: device to match (sdev)
4866 * 1 if command matches sdev / 0 if command does not match sdev
4868 static int ipr_match_lun(struct ipr_cmnd *ipr_cmd, void *device)
4870 if (ipr_cmd->scsi_cmd && ipr_cmd->scsi_cmd->device == device)
4876 * ipr_cmnd_is_free - Check if a command is free or not
4877 * @ipr_cmd: ipr command struct
4882 static bool ipr_cmnd_is_free(struct ipr_cmnd *ipr_cmd)
4884 struct ipr_cmnd *loop_cmd;
4886 list_for_each_entry(loop_cmd, &ipr_cmd->hrrq->hrrq_free_q, queue) {
4887 if (loop_cmd == ipr_cmd)
4895 * ipr_wait_for_ops - Wait for matching commands to complete
4896 * @ioa_cfg: ioa config struct
4897 * @device: device to match (sdev)
4898 * @match: match function to use
4903 static int ipr_wait_for_ops(struct ipr_ioa_cfg *ioa_cfg, void *device,
4904 int (*match)(struct ipr_cmnd *, void *))
4906 struct ipr_cmnd *ipr_cmd;
4908 unsigned long flags;
4909 struct ipr_hrr_queue *hrrq;
4910 signed long timeout = IPR_ABORT_TASK_TIMEOUT;
4911 DECLARE_COMPLETION_ONSTACK(comp);
4917 for_each_hrrq(hrrq, ioa_cfg) {
4918 spin_lock_irqsave(hrrq->lock, flags);
4919 for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) {
4920 ipr_cmd = ioa_cfg->ipr_cmnd_list[i];
4921 if (!ipr_cmnd_is_free(ipr_cmd)) {
4922 if (match(ipr_cmd, device)) {
4923 ipr_cmd->eh_comp = ∁
4928 spin_unlock_irqrestore(hrrq->lock, flags);
4932 timeout = wait_for_completion_timeout(&comp, timeout);
4937 for_each_hrrq(hrrq, ioa_cfg) {
4938 spin_lock_irqsave(hrrq->lock, flags);
4939 for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) {
4940 ipr_cmd = ioa_cfg->ipr_cmnd_list[i];
4941 if (!ipr_cmnd_is_free(ipr_cmd)) {
4942 if (match(ipr_cmd, device)) {
4943 ipr_cmd->eh_comp = NULL;
4948 spin_unlock_irqrestore(hrrq->lock, flags);
4952 dev_err(&ioa_cfg->pdev->dev, "Timed out waiting for aborted commands\n");
4954 return wait ? FAILED : SUCCESS;
4963 static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
4965 struct ipr_ioa_cfg *ioa_cfg;
4966 unsigned long lock_flags = 0;
4970 ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
4971 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4973 if (!ioa_cfg->in_reset_reload && !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
4974 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
4975 dev_err(&ioa_cfg->pdev->dev,
4976 "Adapter being reset as a result of error recovery.\n");
4978 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4979 ioa_cfg->sdt_state = GET_DUMP;
4982 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4983 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4984 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4986 /* If we got hit with a host reset while we were already resetting
4987 the adapter for some reason, and the reset failed. */
4988 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
4993 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4999 * ipr_device_reset - Reset the device
5000 * @ioa_cfg: ioa config struct
5001 * @res: resource entry struct
5003 * This function issues a device reset to the affected device.
5004 * If the device is a SCSI device, a LUN reset will be sent
5005 * to the device first. If that does not work, a target reset
5009 * 0 on success / non-zero on failure
5011 static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
5012 struct ipr_resource_entry *res)
5014 struct ipr_cmnd *ipr_cmd;
5015 struct ipr_ioarcb *ioarcb;
5016 struct ipr_cmd_pkt *cmd_pkt;
5020 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5021 ioarcb = &ipr_cmd->ioarcb;
5022 cmd_pkt = &ioarcb->cmd_pkt;
5024 if (ipr_cmd->ioa_cfg->sis64)
5025 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
5027 ioarcb->res_handle = res->res_handle;
5028 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5029 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
5031 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
5032 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5033 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5036 return IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0;
5040 * __ipr_eh_dev_reset - Reset the device
5041 * @scsi_cmd: scsi command struct
5043 * This function issues a device reset to the affected device.
5044 * A LUN reset will be sent to the device first. If that does
5045 * not work, a target reset will be sent.
5050 static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
5052 struct ipr_ioa_cfg *ioa_cfg;
5053 struct ipr_resource_entry *res;
5057 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
5058 res = scsi_cmd->device->hostdata;
5061 * If we are currently going through reset/reload, return failed. This will force the
5062 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
5065 if (ioa_cfg->in_reset_reload)
5067 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
5070 res->resetting_device = 1;
5071 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
5073 rc = ipr_device_reset(ioa_cfg, res);
5074 res->resetting_device = 0;
5075 res->reset_occurred = 1;
5078 return rc ? FAILED : SUCCESS;
5081 static int ipr_eh_dev_reset(struct scsi_cmnd *cmd)
5084 struct ipr_ioa_cfg *ioa_cfg;
5085 struct ipr_resource_entry *res;
5087 ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
5088 res = cmd->device->hostdata;
5093 spin_lock_irq(cmd->device->host->host_lock);
5094 rc = __ipr_eh_dev_reset(cmd);
5095 spin_unlock_irq(cmd->device->host->host_lock);
5098 rc = ipr_wait_for_ops(ioa_cfg, cmd->device, ipr_match_lun);
5104 * ipr_bus_reset_done - Op done function for bus reset.
5105 * @ipr_cmd: ipr command struct
5107 * This function is the op done function for a bus reset
5112 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
5114 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5115 struct ipr_resource_entry *res;
5118 if (!ioa_cfg->sis64)
5119 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
5120 if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
5121 scsi_report_bus_reset(ioa_cfg->host, res->bus);
5127 * If abort has not completed, indicate the reset has, else call the
5128 * abort's done function to wake the sleeping eh thread
5130 if (ipr_cmd->sibling->sibling)
5131 ipr_cmd->sibling->sibling = NULL;
5133 ipr_cmd->sibling->done(ipr_cmd->sibling);
5135 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5140 * ipr_abort_timeout - An abort task has timed out
5141 * @t: Timer context used to fetch ipr command struct
5143 * This function handles when an abort task times out. If this
5144 * happens we issue a bus reset since we have resources tied
5145 * up that must be freed before returning to the midlayer.
5150 static void ipr_abort_timeout(struct timer_list *t)
5152 struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
5153 struct ipr_cmnd *reset_cmd;
5154 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5155 struct ipr_cmd_pkt *cmd_pkt;
5156 unsigned long lock_flags = 0;
5159 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5160 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
5161 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5165 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
5166 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5167 ipr_cmd->sibling = reset_cmd;
5168 reset_cmd->sibling = ipr_cmd;
5169 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
5170 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
5171 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5172 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
5173 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
5175 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
5176 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5181 * ipr_cancel_op - Cancel specified op
5182 * @scsi_cmd: scsi command struct
5184 * This function cancels specified op.
5189 static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
5191 struct ipr_cmnd *ipr_cmd;
5192 struct ipr_ioa_cfg *ioa_cfg;
5193 struct ipr_resource_entry *res;
5194 struct ipr_cmd_pkt *cmd_pkt;
5196 int i, op_found = 0;
5197 struct ipr_hrr_queue *hrrq;
5200 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
5201 res = scsi_cmd->device->hostdata;
5203 /* If we are currently going through reset/reload, return failed.
5204 * This will force the mid-layer to call ipr_eh_host_reset,
5205 * which will then go to sleep and wait for the reset to complete
5207 if (ioa_cfg->in_reset_reload ||
5208 ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
5214 * If we are aborting a timed out op, chances are that the timeout was caused
5215 * by a still not detected EEH error. In such cases, reading a register will
5216 * trigger the EEH recovery infrastructure.
5218 readl(ioa_cfg->regs.sense_interrupt_reg);
5220 if (!ipr_is_gscsi(res))
5223 for_each_hrrq(hrrq, ioa_cfg) {
5224 spin_lock(&hrrq->_lock);
5225 for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) {
5226 if (ioa_cfg->ipr_cmnd_list[i]->scsi_cmd == scsi_cmd) {
5227 if (!ipr_cmnd_is_free(ioa_cfg->ipr_cmnd_list[i])) {
5233 spin_unlock(&hrrq->_lock);
5239 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5240 ipr_cmd->ioarcb.res_handle = res->res_handle;
5241 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5242 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5243 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5244 ipr_cmd->u.sdev = scsi_cmd->device;
5246 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
5248 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
5249 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5252 * If the abort task timed out and we sent a bus reset, we will get
5253 * one the following responses to the abort
5255 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
5260 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5261 if (!ipr_is_naca_model(res))
5262 res->needs_sync_complete = 1;
5265 return IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS;
5269 * ipr_scan_finished - Report whether scan is done
5270 * @shost: scsi host struct
5271 * @elapsed_time: elapsed time
5274 * 0 if scan in progress / 1 if scan is complete
5276 static int ipr_scan_finished(struct Scsi_Host *shost, unsigned long elapsed_time)
5278 unsigned long lock_flags;
5279 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
5282 spin_lock_irqsave(shost->host_lock, lock_flags);
5283 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead || ioa_cfg->scan_done)
5285 if ((elapsed_time/HZ) > (ioa_cfg->transop_timeout * 2))
5287 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5292 * ipr_eh_abort - Reset the host adapter
5293 * @scsi_cmd: scsi command struct
5298 static int ipr_eh_abort(struct scsi_cmnd *scsi_cmd)
5300 unsigned long flags;
5302 struct ipr_ioa_cfg *ioa_cfg;
5306 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
5308 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
5309 rc = ipr_cancel_op(scsi_cmd);
5310 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
5313 rc = ipr_wait_for_ops(ioa_cfg, scsi_cmd->device, ipr_match_lun);
5319 * ipr_handle_other_interrupt - Handle "other" interrupts
5320 * @ioa_cfg: ioa config struct
5321 * @int_reg: interrupt register
5324 * IRQ_NONE / IRQ_HANDLED
5326 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
5329 irqreturn_t rc = IRQ_HANDLED;
5332 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
5333 int_reg &= ~int_mask_reg;
5335 /* If an interrupt on the adapter did not occur, ignore it.
5336 * Or in the case of SIS 64, check for a stage change interrupt.
5338 if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
5339 if (ioa_cfg->sis64) {
5340 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
5341 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5342 if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
5344 /* clear stage change */
5345 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
5346 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5347 list_del(&ioa_cfg->reset_cmd->queue);
5348 del_timer(&ioa_cfg->reset_cmd->timer);
5349 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5357 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
5358 /* Mask the interrupt */
5359 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
5360 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5362 list_del(&ioa_cfg->reset_cmd->queue);
5363 del_timer(&ioa_cfg->reset_cmd->timer);
5364 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5365 } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
5366 if (ioa_cfg->clear_isr) {
5367 if (ipr_debug && printk_ratelimit())
5368 dev_err(&ioa_cfg->pdev->dev,
5369 "Spurious interrupt detected. 0x%08X\n", int_reg);
5370 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5371 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5375 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
5376 ioa_cfg->ioa_unit_checked = 1;
5377 else if (int_reg & IPR_PCII_NO_HOST_RRQ)
5378 dev_err(&ioa_cfg->pdev->dev,
5379 "No Host RRQ. 0x%08X\n", int_reg);
5381 dev_err(&ioa_cfg->pdev->dev,
5382 "Permanent IOA failure. 0x%08X\n", int_reg);
5384 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5385 ioa_cfg->sdt_state = GET_DUMP;
5387 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
5388 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5395 * ipr_isr_eh - Interrupt service routine error handler
5396 * @ioa_cfg: ioa config struct
5397 * @msg: message to log
5398 * @number: various meanings depending on the caller/message
5403 static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg, u16 number)
5405 ioa_cfg->errors_logged++;
5406 dev_err(&ioa_cfg->pdev->dev, "%s %d\n", msg, number);
5408 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5409 ioa_cfg->sdt_state = GET_DUMP;
5411 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5414 static int ipr_process_hrrq(struct ipr_hrr_queue *hrr_queue, int budget,
5415 struct list_head *doneq)
5419 struct ipr_cmnd *ipr_cmd;
5420 struct ipr_ioa_cfg *ioa_cfg = hrr_queue->ioa_cfg;
5423 /* If interrupts are disabled, ignore the interrupt */
5424 if (!hrr_queue->allow_interrupts)
5427 while ((be32_to_cpu(*hrr_queue->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5428 hrr_queue->toggle_bit) {
5430 cmd_index = (be32_to_cpu(*hrr_queue->hrrq_curr) &
5431 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >>
5432 IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
5434 if (unlikely(cmd_index > hrr_queue->max_cmd_id ||
5435 cmd_index < hrr_queue->min_cmd_id)) {
5437 "Invalid response handle from IOA: ",
5442 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
5443 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5445 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
5447 list_move_tail(&ipr_cmd->queue, doneq);
5449 if (hrr_queue->hrrq_curr < hrr_queue->hrrq_end) {
5450 hrr_queue->hrrq_curr++;
5452 hrr_queue->hrrq_curr = hrr_queue->hrrq_start;
5453 hrr_queue->toggle_bit ^= 1u;
5456 if (budget > 0 && num_hrrq >= budget)
5463 static int ipr_iopoll(struct irq_poll *iop, int budget)
5465 struct ipr_hrr_queue *hrrq;
5466 struct ipr_cmnd *ipr_cmd, *temp;
5467 unsigned long hrrq_flags;
5471 hrrq = container_of(iop, struct ipr_hrr_queue, iopoll);
5473 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5474 completed_ops = ipr_process_hrrq(hrrq, budget, &doneq);
5476 if (completed_ops < budget)
5477 irq_poll_complete(iop);
5478 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5480 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5481 list_del(&ipr_cmd->queue);
5482 del_timer(&ipr_cmd->timer);
5483 ipr_cmd->fast_done(ipr_cmd);
5486 return completed_ops;
5490 * ipr_isr - Interrupt service routine
5492 * @devp: pointer to ioa config struct
5495 * IRQ_NONE / IRQ_HANDLED
5497 static irqreturn_t ipr_isr(int irq, void *devp)
5499 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
5500 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
5501 unsigned long hrrq_flags = 0;
5505 struct ipr_cmnd *ipr_cmd, *temp;
5506 irqreturn_t rc = IRQ_NONE;
5509 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5510 /* If interrupts are disabled, ignore the interrupt */
5511 if (!hrrq->allow_interrupts) {
5512 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5517 if (ipr_process_hrrq(hrrq, -1, &doneq)) {
5520 if (!ioa_cfg->clear_isr)
5523 /* Clear the PCI interrupt */
5526 writel(IPR_PCII_HRRQ_UPDATED,
5527 ioa_cfg->regs.clr_interrupt_reg32);
5528 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5529 } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
5530 num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
5532 } else if (rc == IRQ_NONE && irq_none == 0) {
5533 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5535 } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
5536 int_reg & IPR_PCII_HRRQ_UPDATED) {
5538 "Error clearing HRRQ: ", num_hrrq);
5545 if (unlikely(rc == IRQ_NONE))
5546 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
5548 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5549 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5550 list_del(&ipr_cmd->queue);
5551 del_timer(&ipr_cmd->timer);
5552 ipr_cmd->fast_done(ipr_cmd);
5558 * ipr_isr_mhrrq - Interrupt service routine
5560 * @devp: pointer to ioa config struct
5563 * IRQ_NONE / IRQ_HANDLED
5565 static irqreturn_t ipr_isr_mhrrq(int irq, void *devp)
5567 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
5568 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
5569 unsigned long hrrq_flags = 0;
5570 struct ipr_cmnd *ipr_cmd, *temp;
5571 irqreturn_t rc = IRQ_NONE;
5574 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5576 /* If interrupts are disabled, ignore the interrupt */
5577 if (!hrrq->allow_interrupts) {
5578 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5582 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
5583 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5585 irq_poll_sched(&hrrq->iopoll);
5586 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5590 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5593 if (ipr_process_hrrq(hrrq, -1, &doneq))
5597 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5599 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5600 list_del(&ipr_cmd->queue);
5601 del_timer(&ipr_cmd->timer);
5602 ipr_cmd->fast_done(ipr_cmd);
5608 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
5609 * @ioa_cfg: ioa config struct
5610 * @ipr_cmd: ipr command struct
5613 * 0 on success / -1 on failure
5615 static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
5616 struct ipr_cmnd *ipr_cmd)
5619 struct scatterlist *sg;
5621 u32 ioadl_flags = 0;
5622 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5623 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5624 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
5626 length = scsi_bufflen(scsi_cmd);
5630 nseg = scsi_dma_map(scsi_cmd);
5632 if (printk_ratelimit())
5633 dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
5637 ipr_cmd->dma_use_sg = nseg;
5639 ioarcb->data_transfer_length = cpu_to_be32(length);
5641 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
5643 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5644 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5645 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5646 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
5647 ioadl_flags = IPR_IOADL_FLAGS_READ;
5649 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5650 ioadl64[i].flags = cpu_to_be32(ioadl_flags);
5651 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
5652 ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
5655 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5660 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5661 * @ioa_cfg: ioa config struct
5662 * @ipr_cmd: ipr command struct
5665 * 0 on success / -1 on failure
5667 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5668 struct ipr_cmnd *ipr_cmd)
5671 struct scatterlist *sg;
5673 u32 ioadl_flags = 0;
5674 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5675 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5676 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
5678 length = scsi_bufflen(scsi_cmd);
5682 nseg = scsi_dma_map(scsi_cmd);
5684 dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
5688 ipr_cmd->dma_use_sg = nseg;
5690 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5691 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5692 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5693 ioarcb->data_transfer_length = cpu_to_be32(length);
5695 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5696 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
5697 ioadl_flags = IPR_IOADL_FLAGS_READ;
5698 ioarcb->read_data_transfer_length = cpu_to_be32(length);
5699 ioarcb->read_ioadl_len =
5700 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5703 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
5704 ioadl = ioarcb->u.add_data.u.ioadl;
5705 ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
5706 offsetof(struct ipr_ioarcb, u.add_data));
5707 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5710 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5711 ioadl[i].flags_and_data_len =
5712 cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5713 ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
5716 ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5721 * __ipr_erp_done - Process completion of ERP for a device
5722 * @ipr_cmd: ipr command struct
5724 * This function copies the sense buffer into the scsi_cmd
5725 * struct and pushes the scsi_done function.
5730 static void __ipr_erp_done(struct ipr_cmnd *ipr_cmd)
5732 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5733 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5734 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5736 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5737 scsi_cmd->result |= (DID_ERROR << 16);
5738 scmd_printk(KERN_ERR, scsi_cmd,
5739 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
5741 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
5742 SCSI_SENSE_BUFFERSIZE);
5746 if (!ipr_is_naca_model(res))
5747 res->needs_sync_complete = 1;
5750 scsi_dma_unmap(ipr_cmd->scsi_cmd);
5751 scsi_done(scsi_cmd);
5752 if (ipr_cmd->eh_comp)
5753 complete(ipr_cmd->eh_comp);
5754 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5758 * ipr_erp_done - Process completion of ERP for a device
5759 * @ipr_cmd: ipr command struct
5761 * This function copies the sense buffer into the scsi_cmd
5762 * struct and pushes the scsi_done function.
5767 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
5769 struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
5770 unsigned long hrrq_flags;
5772 spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
5773 __ipr_erp_done(ipr_cmd);
5774 spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
5778 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5779 * @ipr_cmd: ipr command struct
5784 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
5786 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5787 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5788 dma_addr_t dma_addr = ipr_cmd->dma_addr;
5790 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
5791 ioarcb->data_transfer_length = 0;
5792 ioarcb->read_data_transfer_length = 0;
5793 ioarcb->ioadl_len = 0;
5794 ioarcb->read_ioadl_len = 0;
5795 ioasa->hdr.ioasc = 0;
5796 ioasa->hdr.residual_data_len = 0;
5798 if (ipr_cmd->ioa_cfg->sis64)
5799 ioarcb->u.sis64_addr_data.data_ioadl_addr =
5800 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
5802 ioarcb->write_ioadl_addr =
5803 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
5804 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5809 * __ipr_erp_request_sense - Send request sense to a device
5810 * @ipr_cmd: ipr command struct
5812 * This function sends a request sense to a device as a result
5813 * of a check condition.
5818 static void __ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
5820 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5821 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5823 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5824 __ipr_erp_done(ipr_cmd);
5828 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5830 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
5831 cmd_pkt->cdb[0] = REQUEST_SENSE;
5832 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
5833 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
5834 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5835 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
5837 ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
5838 SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
5840 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
5841 IPR_REQUEST_SENSE_TIMEOUT * 2);
5845 * ipr_erp_request_sense - Send request sense to a device
5846 * @ipr_cmd: ipr command struct
5848 * This function sends a request sense to a device as a result
5849 * of a check condition.
5854 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
5856 struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
5857 unsigned long hrrq_flags;
5859 spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
5860 __ipr_erp_request_sense(ipr_cmd);
5861 spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
5865 * ipr_erp_cancel_all - Send cancel all to a device
5866 * @ipr_cmd: ipr command struct
5868 * This function sends a cancel all to a device to clear the
5869 * queue. If we are running TCQ on the device, QERR is set to 1,
5870 * which means all outstanding ops have been dropped on the floor.
5871 * Cancel all will return them to us.
5876 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
5878 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5879 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5880 struct ipr_cmd_pkt *cmd_pkt;
5884 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5886 if (!scsi_cmd->device->simple_tags) {
5887 __ipr_erp_request_sense(ipr_cmd);
5891 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5892 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5893 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5895 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
5896 IPR_CANCEL_ALL_TIMEOUT);
5900 * ipr_dump_ioasa - Dump contents of IOASA
5901 * @ioa_cfg: ioa config struct
5902 * @ipr_cmd: ipr command struct
5903 * @res: resource entry struct
5905 * This function is invoked by the interrupt handler when ops
5906 * fail. It will log the IOASA if appropriate. Only called
5912 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
5913 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
5917 u32 ioasc, fd_ioasc;
5918 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5919 __be32 *ioasa_data = (__be32 *)ioasa;
5922 ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
5923 fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
5928 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
5931 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
5932 error_index = ipr_get_error(fd_ioasc);
5934 error_index = ipr_get_error(ioasc);
5936 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
5937 /* Don't log an error if the IOA already logged one */
5938 if (ioasa->hdr.ilid != 0)
5941 if (!ipr_is_gscsi(res))
5944 if (ipr_error_table[error_index].log_ioasa == 0)
5948 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
5950 data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
5951 if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
5952 data_len = sizeof(struct ipr_ioasa64);
5953 else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
5954 data_len = sizeof(struct ipr_ioasa);
5956 ipr_err("IOASA Dump:\n");
5958 for (i = 0; i < data_len / 4; i += 4) {
5959 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
5960 be32_to_cpu(ioasa_data[i]),
5961 be32_to_cpu(ioasa_data[i+1]),
5962 be32_to_cpu(ioasa_data[i+2]),
5963 be32_to_cpu(ioasa_data[i+3]));
5968 * ipr_gen_sense - Generate SCSI sense data from an IOASA
5969 * @ipr_cmd: ipr command struct
5974 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
5977 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
5978 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
5979 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5980 u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
5982 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
5984 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
5987 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
5989 if (ipr_is_vset_device(res) &&
5990 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
5991 ioasa->u.vset.failing_lba_hi != 0) {
5992 sense_buf[0] = 0x72;
5993 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
5994 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
5995 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
5999 sense_buf[9] = 0x0A;
6000 sense_buf[10] = 0x80;
6002 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
6004 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
6005 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
6006 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
6007 sense_buf[15] = failing_lba & 0x000000ff;
6009 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
6011 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
6012 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
6013 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
6014 sense_buf[19] = failing_lba & 0x000000ff;
6016 sense_buf[0] = 0x70;
6017 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
6018 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
6019 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
6021 /* Illegal request */
6022 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
6023 (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
6024 sense_buf[7] = 10; /* additional length */
6026 /* IOARCB was in error */
6027 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
6028 sense_buf[15] = 0xC0;
6029 else /* Parameter data was invalid */
6030 sense_buf[15] = 0x80;
6033 ((IPR_FIELD_POINTER_MASK &
6034 be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
6036 (IPR_FIELD_POINTER_MASK &
6037 be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
6039 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
6040 if (ipr_is_vset_device(res))
6041 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
6043 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
6045 sense_buf[0] |= 0x80; /* Or in the Valid bit */
6046 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
6047 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
6048 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
6049 sense_buf[6] = failing_lba & 0x000000ff;
6052 sense_buf[7] = 6; /* additional length */
6058 * ipr_get_autosense - Copy autosense data to sense buffer
6059 * @ipr_cmd: ipr command struct
6061 * This function copies the autosense buffer to the buffer
6062 * in the scsi_cmd, if there is autosense available.
6065 * 1 if autosense was available / 0 if not
6067 static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
6069 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
6070 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
6072 if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
6075 if (ipr_cmd->ioa_cfg->sis64)
6076 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
6077 min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
6078 SCSI_SENSE_BUFFERSIZE));
6080 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
6081 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
6082 SCSI_SENSE_BUFFERSIZE));
6087 * ipr_erp_start - Process an error response for a SCSI op
6088 * @ioa_cfg: ioa config struct
6089 * @ipr_cmd: ipr command struct
6091 * This function determines whether or not to initiate ERP
6092 * on the affected device.
6097 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
6098 struct ipr_cmnd *ipr_cmd)
6100 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
6101 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
6102 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6103 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
6106 __ipr_scsi_eh_done(ipr_cmd);
6110 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
6111 ipr_gen_sense(ipr_cmd);
6113 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6115 switch (masked_ioasc) {
6116 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
6117 if (ipr_is_naca_model(res))
6118 scsi_cmd->result |= (DID_ABORT << 16);
6120 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6122 case IPR_IOASC_IR_RESOURCE_HANDLE:
6123 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
6124 scsi_cmd->result |= (DID_NO_CONNECT << 16);
6126 case IPR_IOASC_HW_SEL_TIMEOUT:
6127 scsi_cmd->result |= (DID_NO_CONNECT << 16);
6128 if (!ipr_is_naca_model(res))
6129 res->needs_sync_complete = 1;
6131 case IPR_IOASC_SYNC_REQUIRED:
6133 res->needs_sync_complete = 1;
6134 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6136 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
6137 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
6139 * exception: do not set DID_PASSTHROUGH on CHECK CONDITION
6140 * so SCSI mid-layer and upper layers handle it accordingly.
6142 if (scsi_cmd->result != SAM_STAT_CHECK_CONDITION)
6143 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
6145 case IPR_IOASC_BUS_WAS_RESET:
6146 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
6148 * Report the bus reset and ask for a retry. The device
6149 * will give CC/UA the next command.
6151 if (!res->resetting_device)
6152 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
6153 scsi_cmd->result |= (DID_ERROR << 16);
6154 if (!ipr_is_naca_model(res))
6155 res->needs_sync_complete = 1;
6157 case IPR_IOASC_HW_DEV_BUS_STATUS:
6158 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
6159 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
6160 if (!ipr_get_autosense(ipr_cmd)) {
6161 if (!ipr_is_naca_model(res)) {
6162 ipr_erp_cancel_all(ipr_cmd);
6167 if (!ipr_is_naca_model(res))
6168 res->needs_sync_complete = 1;
6170 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
6172 case IPR_IOASC_IR_NON_OPTIMIZED:
6173 if (res->raw_mode) {
6175 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6177 scsi_cmd->result |= (DID_ERROR << 16);
6180 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
6181 scsi_cmd->result |= (DID_ERROR << 16);
6182 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
6183 res->needs_sync_complete = 1;
6187 scsi_dma_unmap(ipr_cmd->scsi_cmd);
6188 scsi_done(scsi_cmd);
6189 if (ipr_cmd->eh_comp)
6190 complete(ipr_cmd->eh_comp);
6191 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6195 * ipr_scsi_done - mid-layer done function
6196 * @ipr_cmd: ipr command struct
6198 * This function is invoked by the interrupt handler for
6199 * ops generated by the SCSI mid-layer
6204 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
6206 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6207 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
6208 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6209 unsigned long lock_flags;
6211 scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
6213 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
6214 scsi_dma_unmap(scsi_cmd);
6216 spin_lock_irqsave(ipr_cmd->hrrq->lock, lock_flags);
6217 scsi_done(scsi_cmd);
6218 if (ipr_cmd->eh_comp)
6219 complete(ipr_cmd->eh_comp);
6220 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6221 spin_unlock_irqrestore(ipr_cmd->hrrq->lock, lock_flags);
6223 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6224 spin_lock(&ipr_cmd->hrrq->_lock);
6225 ipr_erp_start(ioa_cfg, ipr_cmd);
6226 spin_unlock(&ipr_cmd->hrrq->_lock);
6227 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6232 * ipr_queuecommand - Queue a mid-layer request
6233 * @shost: scsi host struct
6234 * @scsi_cmd: scsi command struct
6236 * This function queues a request generated by the mid-layer.
6240 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
6241 * SCSI_MLQUEUE_HOST_BUSY if host is busy
6243 static int ipr_queuecommand(struct Scsi_Host *shost,
6244 struct scsi_cmnd *scsi_cmd)
6246 struct ipr_ioa_cfg *ioa_cfg;
6247 struct ipr_resource_entry *res;
6248 struct ipr_ioarcb *ioarcb;
6249 struct ipr_cmnd *ipr_cmd;
6250 unsigned long hrrq_flags;
6252 struct ipr_hrr_queue *hrrq;
6255 ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
6257 scsi_cmd->result = (DID_OK << 16);
6258 res = scsi_cmd->device->hostdata;
6260 hrrq_id = ipr_get_hrrq_index(ioa_cfg);
6261 hrrq = &ioa_cfg->hrrq[hrrq_id];
6263 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6265 * We are currently blocking all devices due to a host reset
6266 * We have told the host to stop giving us new requests, but
6267 * ERP ops don't count. FIXME
6269 if (unlikely(!hrrq->allow_cmds && !hrrq->ioa_is_dead && !hrrq->removing_ioa)) {
6270 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6271 return SCSI_MLQUEUE_HOST_BUSY;
6275 * FIXME - Create scsi_set_host_offline interface
6276 * and the ioa_is_dead check can be removed
6278 if (unlikely(hrrq->ioa_is_dead || hrrq->removing_ioa || !res)) {
6279 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6283 ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
6284 if (ipr_cmd == NULL) {
6285 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6286 return SCSI_MLQUEUE_HOST_BUSY;
6288 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6290 ipr_init_ipr_cmnd(ipr_cmd, ipr_scsi_done);
6291 ioarcb = &ipr_cmd->ioarcb;
6293 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
6294 ipr_cmd->scsi_cmd = scsi_cmd;
6295 ipr_cmd->done = ipr_scsi_eh_done;
6297 if (ipr_is_gscsi(res)) {
6298 if (scsi_cmd->underflow == 0)
6299 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
6301 if (res->reset_occurred) {
6302 res->reset_occurred = 0;
6303 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
6307 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
6308 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6310 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
6311 if (scsi_cmd->flags & SCMD_TAGGED)
6312 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_SIMPLE_TASK;
6314 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_UNTAGGED_TASK;
6317 if (scsi_cmd->cmnd[0] >= 0xC0 &&
6318 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE)) {
6319 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6321 if (res->raw_mode && ipr_is_af_dasd_device(res)) {
6322 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_PIPE;
6324 if (scsi_cmd->underflow == 0)
6325 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
6329 rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
6331 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
6333 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6334 if (unlikely(rc || (!hrrq->allow_cmds && !hrrq->ioa_is_dead))) {
6335 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
6336 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6338 scsi_dma_unmap(scsi_cmd);
6339 return SCSI_MLQUEUE_HOST_BUSY;
6342 if (unlikely(hrrq->ioa_is_dead)) {
6343 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
6344 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6345 scsi_dma_unmap(scsi_cmd);
6349 ioarcb->res_handle = res->res_handle;
6350 if (res->needs_sync_complete) {
6351 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
6352 res->needs_sync_complete = 0;
6354 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_pending_q);
6355 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
6356 ipr_send_command(ipr_cmd);
6357 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6361 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6362 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
6363 scsi_cmd->result = (DID_NO_CONNECT << 16);
6364 scsi_done(scsi_cmd);
6365 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6370 * ipr_ioa_info - Get information about the card/driver
6371 * @host: scsi host struct
6374 * pointer to buffer with description string
6376 static const char *ipr_ioa_info(struct Scsi_Host *host)
6378 static char buffer[512];
6379 struct ipr_ioa_cfg *ioa_cfg;
6380 unsigned long lock_flags = 0;
6382 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
6384 spin_lock_irqsave(host->host_lock, lock_flags);
6385 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
6386 spin_unlock_irqrestore(host->host_lock, lock_flags);
6391 static const struct scsi_host_template driver_template = {
6392 .module = THIS_MODULE,
6394 .info = ipr_ioa_info,
6395 .queuecommand = ipr_queuecommand,
6396 .eh_abort_handler = ipr_eh_abort,
6397 .eh_device_reset_handler = ipr_eh_dev_reset,
6398 .eh_host_reset_handler = ipr_eh_host_reset,
6399 .slave_alloc = ipr_slave_alloc,
6400 .slave_configure = ipr_slave_configure,
6401 .slave_destroy = ipr_slave_destroy,
6402 .scan_finished = ipr_scan_finished,
6403 .target_destroy = ipr_target_destroy,
6404 .change_queue_depth = ipr_change_queue_depth,
6405 .bios_param = ipr_biosparam,
6406 .can_queue = IPR_MAX_COMMANDS,
6408 .sg_tablesize = IPR_MAX_SGLIST,
6409 .max_sectors = IPR_IOA_MAX_SECTORS,
6410 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
6411 .shost_groups = ipr_ioa_groups,
6412 .sdev_groups = ipr_dev_groups,
6413 .proc_name = IPR_NAME,
6417 * ipr_ioa_bringdown_done - IOA bring down completion.
6418 * @ipr_cmd: ipr command struct
6420 * This function processes the completion of an adapter bring down.
6421 * It wakes any reset sleepers.
6426 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
6428 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6432 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
6434 ioa_cfg->scsi_unblock = 1;
6435 schedule_work(&ioa_cfg->work_q);
6438 ioa_cfg->in_reset_reload = 0;
6439 ioa_cfg->reset_retries = 0;
6440 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
6441 spin_lock(&ioa_cfg->hrrq[i]._lock);
6442 ioa_cfg->hrrq[i].ioa_is_dead = 1;
6443 spin_unlock(&ioa_cfg->hrrq[i]._lock);
6447 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6448 wake_up_all(&ioa_cfg->reset_wait_q);
6451 return IPR_RC_JOB_RETURN;
6455 * ipr_ioa_reset_done - IOA reset completion.
6456 * @ipr_cmd: ipr command struct
6458 * This function processes the completion of an adapter reset.
6459 * It schedules any necessary mid-layer add/removes and
6460 * wakes any reset sleepers.
6465 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
6467 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6468 struct ipr_resource_entry *res;
6472 ioa_cfg->in_reset_reload = 0;
6473 for (j = 0; j < ioa_cfg->hrrq_num; j++) {
6474 spin_lock(&ioa_cfg->hrrq[j]._lock);
6475 ioa_cfg->hrrq[j].allow_cmds = 1;
6476 spin_unlock(&ioa_cfg->hrrq[j]._lock);
6479 ioa_cfg->reset_cmd = NULL;
6480 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
6482 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
6483 if (res->add_to_ml || res->del_from_ml) {
6488 schedule_work(&ioa_cfg->work_q);
6490 for (j = 0; j < IPR_NUM_HCAMS; j++) {
6491 list_del_init(&ioa_cfg->hostrcb[j]->queue);
6492 if (j < IPR_NUM_LOG_HCAMS)
6493 ipr_send_hcam(ioa_cfg,
6494 IPR_HCAM_CDB_OP_CODE_LOG_DATA,
6495 ioa_cfg->hostrcb[j]);
6497 ipr_send_hcam(ioa_cfg,
6498 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
6499 ioa_cfg->hostrcb[j]);
6502 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
6503 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
6505 ioa_cfg->reset_retries = 0;
6506 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6507 wake_up_all(&ioa_cfg->reset_wait_q);
6509 ioa_cfg->scsi_unblock = 1;
6510 schedule_work(&ioa_cfg->work_q);
6512 return IPR_RC_JOB_RETURN;
6516 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
6517 * @supported_dev: supported device struct
6518 * @vpids: vendor product id struct
6523 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
6524 struct ipr_std_inq_vpids *vpids)
6526 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
6527 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
6528 supported_dev->num_records = 1;
6529 supported_dev->data_length =
6530 cpu_to_be16(sizeof(struct ipr_supported_device));
6531 supported_dev->reserved = 0;
6535 * ipr_set_supported_devs - Send Set Supported Devices for a device
6536 * @ipr_cmd: ipr command struct
6538 * This function sends a Set Supported Devices to the adapter
6541 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6543 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
6545 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6546 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
6547 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6548 struct ipr_resource_entry *res = ipr_cmd->u.res;
6550 ipr_cmd->job_step = ipr_ioa_reset_done;
6552 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
6553 if (!ipr_is_scsi_disk(res))
6556 ipr_cmd->u.res = res;
6557 ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
6559 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6560 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6561 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6563 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
6564 ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
6565 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
6566 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
6568 ipr_init_ioadl(ipr_cmd,
6569 ioa_cfg->vpd_cbs_dma +
6570 offsetof(struct ipr_misc_cbs, supp_dev),
6571 sizeof(struct ipr_supported_device),
6572 IPR_IOADL_FLAGS_WRITE_LAST);
6574 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
6575 IPR_SET_SUP_DEVICE_TIMEOUT);
6577 if (!ioa_cfg->sis64)
6578 ipr_cmd->job_step = ipr_set_supported_devs;
6580 return IPR_RC_JOB_RETURN;
6584 return IPR_RC_JOB_CONTINUE;
6588 * ipr_get_mode_page - Locate specified mode page
6589 * @mode_pages: mode page buffer
6590 * @page_code: page code to find
6591 * @len: minimum required length for mode page
6594 * pointer to mode page / NULL on failure
6596 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
6597 u32 page_code, u32 len)
6599 struct ipr_mode_page_hdr *mode_hdr;
6603 if (!mode_pages || (mode_pages->hdr.length == 0))
6606 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
6607 mode_hdr = (struct ipr_mode_page_hdr *)
6608 (mode_pages->data + mode_pages->hdr.block_desc_len);
6611 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
6612 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
6616 page_length = (sizeof(struct ipr_mode_page_hdr) +
6617 mode_hdr->page_length);
6618 length -= page_length;
6619 mode_hdr = (struct ipr_mode_page_hdr *)
6620 ((unsigned long)mode_hdr + page_length);
6627 * ipr_check_term_power - Check for term power errors
6628 * @ioa_cfg: ioa config struct
6629 * @mode_pages: IOAFP mode pages buffer
6631 * Check the IOAFP's mode page 28 for term power errors
6636 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
6637 struct ipr_mode_pages *mode_pages)
6641 struct ipr_dev_bus_entry *bus;
6642 struct ipr_mode_page28 *mode_page;
6644 mode_page = ipr_get_mode_page(mode_pages, 0x28,
6645 sizeof(struct ipr_mode_page28));
6647 entry_length = mode_page->entry_length;
6649 bus = mode_page->bus;
6651 for (i = 0; i < mode_page->num_entries; i++) {
6652 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
6653 dev_err(&ioa_cfg->pdev->dev,
6654 "Term power is absent on scsi bus %d\n",
6658 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
6663 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
6664 * @ioa_cfg: ioa config struct
6666 * Looks through the config table checking for SES devices. If
6667 * the SES device is in the SES table indicating a maximum SCSI
6668 * bus speed, the speed is limited for the bus.
6673 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
6678 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
6679 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
6680 ioa_cfg->bus_attr[i].bus_width);
6682 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
6683 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
6688 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
6689 * @ioa_cfg: ioa config struct
6690 * @mode_pages: mode page 28 buffer
6692 * Updates mode page 28 based on driver configuration
6697 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
6698 struct ipr_mode_pages *mode_pages)
6700 int i, entry_length;
6701 struct ipr_dev_bus_entry *bus;
6702 struct ipr_bus_attributes *bus_attr;
6703 struct ipr_mode_page28 *mode_page;
6705 mode_page = ipr_get_mode_page(mode_pages, 0x28,
6706 sizeof(struct ipr_mode_page28));
6708 entry_length = mode_page->entry_length;
6710 /* Loop for each device bus entry */
6711 for (i = 0, bus = mode_page->bus;
6712 i < mode_page->num_entries;
6713 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
6714 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
6715 dev_err(&ioa_cfg->pdev->dev,
6716 "Invalid resource address reported: 0x%08X\n",
6717 IPR_GET_PHYS_LOC(bus->res_addr));
6721 bus_attr = &ioa_cfg->bus_attr[i];
6722 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
6723 bus->bus_width = bus_attr->bus_width;
6724 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
6725 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
6726 if (bus_attr->qas_enabled)
6727 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
6729 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
6734 * ipr_build_mode_select - Build a mode select command
6735 * @ipr_cmd: ipr command struct
6736 * @res_handle: resource handle to send command to
6737 * @parm: Byte 2 of Mode Sense command
6738 * @dma_addr: DMA buffer address
6739 * @xfer_len: data transfer length
6744 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
6745 __be32 res_handle, u8 parm,
6746 dma_addr_t dma_addr, u8 xfer_len)
6748 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6750 ioarcb->res_handle = res_handle;
6751 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6752 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6753 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
6754 ioarcb->cmd_pkt.cdb[1] = parm;
6755 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6757 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
6761 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
6762 * @ipr_cmd: ipr command struct
6764 * This function sets up the SCSI bus attributes and sends
6765 * a Mode Select for Page 28 to activate them.
6770 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
6772 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6773 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
6777 ipr_scsi_bus_speed_limit(ioa_cfg);
6778 ipr_check_term_power(ioa_cfg, mode_pages);
6779 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
6780 length = mode_pages->hdr.length + 1;
6781 mode_pages->hdr.length = 0;
6783 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
6784 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
6787 ipr_cmd->job_step = ipr_set_supported_devs;
6788 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
6789 struct ipr_resource_entry, queue);
6790 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6793 return IPR_RC_JOB_RETURN;
6797 * ipr_build_mode_sense - Builds a mode sense command
6798 * @ipr_cmd: ipr command struct
6799 * @res_handle: resource entry struct
6800 * @parm: Byte 2 of mode sense command
6801 * @dma_addr: DMA address of mode sense buffer
6802 * @xfer_len: Size of DMA buffer
6807 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
6809 u8 parm, dma_addr_t dma_addr, u8 xfer_len)
6811 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6813 ioarcb->res_handle = res_handle;
6814 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
6815 ioarcb->cmd_pkt.cdb[2] = parm;
6816 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6817 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6819 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
6823 * ipr_reset_cmd_failed - Handle failure of IOA reset command
6824 * @ipr_cmd: ipr command struct
6826 * This function handles the failure of an IOA bringup command.
6831 static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
6833 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6834 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6836 dev_err(&ioa_cfg->pdev->dev,
6837 "0x%02X failed with IOASC: 0x%08X\n",
6838 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
6840 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
6841 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6842 return IPR_RC_JOB_RETURN;
6846 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
6847 * @ipr_cmd: ipr command struct
6849 * This function handles the failure of a Mode Sense to the IOAFP.
6850 * Some adapters do not handle all mode pages.
6853 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6855 static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
6857 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6858 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6860 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
6861 ipr_cmd->job_step = ipr_set_supported_devs;
6862 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
6863 struct ipr_resource_entry, queue);
6864 return IPR_RC_JOB_CONTINUE;
6867 return ipr_reset_cmd_failed(ipr_cmd);
6871 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
6872 * @ipr_cmd: ipr command struct
6874 * This function send a Page 28 mode sense to the IOA to
6875 * retrieve SCSI bus attributes.
6880 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
6882 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6885 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
6886 0x28, ioa_cfg->vpd_cbs_dma +
6887 offsetof(struct ipr_misc_cbs, mode_pages),
6888 sizeof(struct ipr_mode_pages));
6890 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
6891 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
6893 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6896 return IPR_RC_JOB_RETURN;
6900 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
6901 * @ipr_cmd: ipr command struct
6903 * This function enables dual IOA RAID support if possible.
6908 static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
6910 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6911 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
6912 struct ipr_mode_page24 *mode_page;
6916 mode_page = ipr_get_mode_page(mode_pages, 0x24,
6917 sizeof(struct ipr_mode_page24));
6920 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
6922 length = mode_pages->hdr.length + 1;
6923 mode_pages->hdr.length = 0;
6925 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
6926 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
6929 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6930 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6933 return IPR_RC_JOB_RETURN;
6937 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
6938 * @ipr_cmd: ipr command struct
6940 * This function handles the failure of a Mode Sense to the IOAFP.
6941 * Some adapters do not handle all mode pages.
6944 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6946 static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
6948 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6950 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
6951 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6952 return IPR_RC_JOB_CONTINUE;
6955 return ipr_reset_cmd_failed(ipr_cmd);
6959 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
6960 * @ipr_cmd: ipr command struct
6962 * This function send a mode sense to the IOA to retrieve
6963 * the IOA Advanced Function Control mode page.
6968 static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
6970 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6973 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
6974 0x24, ioa_cfg->vpd_cbs_dma +
6975 offsetof(struct ipr_misc_cbs, mode_pages),
6976 sizeof(struct ipr_mode_pages));
6978 ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
6979 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
6981 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6984 return IPR_RC_JOB_RETURN;
6988 * ipr_init_res_table - Initialize the resource table
6989 * @ipr_cmd: ipr command struct
6991 * This function looks through the existing resource table, comparing
6992 * it with the config table. This function will take care of old/new
6993 * devices and schedule adding/removing them from the mid-layer
6997 * IPR_RC_JOB_CONTINUE
6999 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
7001 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7002 struct ipr_resource_entry *res, *temp;
7003 struct ipr_config_table_entry_wrapper cfgtew;
7004 int entries, found, flag, i;
7009 flag = ioa_cfg->u.cfg_table64->hdr64.flags;
7011 flag = ioa_cfg->u.cfg_table->hdr.flags;
7013 if (flag & IPR_UCODE_DOWNLOAD_REQ)
7014 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
7016 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
7017 list_move_tail(&res->queue, &old_res);
7020 entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
7022 entries = ioa_cfg->u.cfg_table->hdr.num_entries;
7024 for (i = 0; i < entries; i++) {
7026 cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
7028 cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
7031 list_for_each_entry_safe(res, temp, &old_res, queue) {
7032 if (ipr_is_same_device(res, &cfgtew)) {
7033 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7040 if (list_empty(&ioa_cfg->free_res_q)) {
7041 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
7046 res = list_entry(ioa_cfg->free_res_q.next,
7047 struct ipr_resource_entry, queue);
7048 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7049 ipr_init_res_entry(res, &cfgtew);
7051 } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
7052 res->sdev->allow_restart = 1;
7055 ipr_update_res_entry(res, &cfgtew);
7058 list_for_each_entry_safe(res, temp, &old_res, queue) {
7060 res->del_from_ml = 1;
7061 res->res_handle = IPR_INVALID_RES_HANDLE;
7062 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7066 list_for_each_entry_safe(res, temp, &old_res, queue) {
7067 ipr_clear_res_target(res);
7068 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
7071 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
7072 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
7074 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7077 return IPR_RC_JOB_CONTINUE;
7081 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
7082 * @ipr_cmd: ipr command struct
7084 * This function sends a Query IOA Configuration command
7085 * to the adapter to retrieve the IOA configuration table.
7090 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
7092 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7093 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7094 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
7095 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7098 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
7099 ioa_cfg->dual_raid = 1;
7100 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
7101 ucode_vpd->major_release, ucode_vpd->card_type,
7102 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
7103 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7104 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7106 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
7107 ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
7108 ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
7109 ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
7111 ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
7112 IPR_IOADL_FLAGS_READ_LAST);
7114 ipr_cmd->job_step = ipr_init_res_table;
7116 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7119 return IPR_RC_JOB_RETURN;
7122 static int ipr_ioa_service_action_failed(struct ipr_cmnd *ipr_cmd)
7124 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
7126 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT)
7127 return IPR_RC_JOB_CONTINUE;
7129 return ipr_reset_cmd_failed(ipr_cmd);
7132 static void ipr_build_ioa_service_action(struct ipr_cmnd *ipr_cmd,
7133 __be32 res_handle, u8 sa_code)
7135 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7137 ioarcb->res_handle = res_handle;
7138 ioarcb->cmd_pkt.cdb[0] = IPR_IOA_SERVICE_ACTION;
7139 ioarcb->cmd_pkt.cdb[1] = sa_code;
7140 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7144 * ipr_ioafp_set_caching_parameters - Issue Set Cache parameters service
7146 * @ipr_cmd: ipr command struct
7151 static int ipr_ioafp_set_caching_parameters(struct ipr_cmnd *ipr_cmd)
7153 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7154 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7155 struct ipr_inquiry_pageC4 *pageC4 = &ioa_cfg->vpd_cbs->pageC4_data;
7159 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
7161 if (pageC4->cache_cap[0] & IPR_CAP_SYNC_CACHE) {
7162 ipr_build_ioa_service_action(ipr_cmd,
7163 cpu_to_be32(IPR_IOA_RES_HANDLE),
7164 IPR_IOA_SA_CHANGE_CACHE_PARAMS);
7166 ioarcb->cmd_pkt.cdb[2] = 0x40;
7168 ipr_cmd->job_step_failed = ipr_ioa_service_action_failed;
7169 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7170 IPR_SET_SUP_DEVICE_TIMEOUT);
7173 return IPR_RC_JOB_RETURN;
7177 return IPR_RC_JOB_CONTINUE;
7181 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
7182 * @ipr_cmd: ipr command struct
7183 * @flags: flags to send
7184 * @page: page to inquire
7185 * @dma_addr: DMA address
7186 * @xfer_len: transfer data length
7188 * This utility function sends an inquiry to the adapter.
7193 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
7194 dma_addr_t dma_addr, u8 xfer_len)
7196 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7199 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7200 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7202 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
7203 ioarcb->cmd_pkt.cdb[1] = flags;
7204 ioarcb->cmd_pkt.cdb[2] = page;
7205 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7207 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
7209 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7214 * ipr_inquiry_page_supported - Is the given inquiry page supported
7215 * @page0: inquiry page 0 buffer
7218 * This function determines if the specified inquiry page is supported.
7221 * 1 if page is supported / 0 if not
7223 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
7227 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
7228 if (page0->page[i] == page)
7235 * ipr_ioafp_pageC4_inquiry - Send a Page 0xC4 Inquiry to the adapter.
7236 * @ipr_cmd: ipr command struct
7238 * This function sends a Page 0xC4 inquiry to the adapter
7239 * to retrieve software VPD information.
7242 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7244 static int ipr_ioafp_pageC4_inquiry(struct ipr_cmnd *ipr_cmd)
7246 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7247 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
7248 struct ipr_inquiry_pageC4 *pageC4 = &ioa_cfg->vpd_cbs->pageC4_data;
7251 ipr_cmd->job_step = ipr_ioafp_set_caching_parameters;
7252 memset(pageC4, 0, sizeof(*pageC4));
7254 if (ipr_inquiry_page_supported(page0, 0xC4)) {
7255 ipr_ioafp_inquiry(ipr_cmd, 1, 0xC4,
7256 (ioa_cfg->vpd_cbs_dma
7257 + offsetof(struct ipr_misc_cbs,
7259 sizeof(struct ipr_inquiry_pageC4));
7260 return IPR_RC_JOB_RETURN;
7264 return IPR_RC_JOB_CONTINUE;
7268 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
7269 * @ipr_cmd: ipr command struct
7271 * This function sends a Page 0xD0 inquiry to the adapter
7272 * to retrieve adapter capabilities.
7275 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7277 static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
7279 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7280 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
7281 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7284 ipr_cmd->job_step = ipr_ioafp_pageC4_inquiry;
7285 memset(cap, 0, sizeof(*cap));
7287 if (ipr_inquiry_page_supported(page0, 0xD0)) {
7288 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
7289 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
7290 sizeof(struct ipr_inquiry_cap));
7291 return IPR_RC_JOB_RETURN;
7295 return IPR_RC_JOB_CONTINUE;
7299 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
7300 * @ipr_cmd: ipr command struct
7302 * This function sends a Page 3 inquiry to the adapter
7303 * to retrieve software VPD information.
7306 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7308 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
7310 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7314 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
7316 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
7317 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
7318 sizeof(struct ipr_inquiry_page3));
7321 return IPR_RC_JOB_RETURN;
7325 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
7326 * @ipr_cmd: ipr command struct
7328 * This function sends a Page 0 inquiry to the adapter
7329 * to retrieve supported inquiry pages.
7332 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7334 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
7336 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7341 /* Grab the type out of the VPD and store it away */
7342 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
7344 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
7346 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
7348 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
7349 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
7350 sizeof(struct ipr_inquiry_page0));
7353 return IPR_RC_JOB_RETURN;
7357 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
7358 * @ipr_cmd: ipr command struct
7360 * This function sends a standard inquiry to the adapter.
7365 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
7367 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7370 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
7372 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
7373 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
7374 sizeof(struct ipr_ioa_vpd));
7377 return IPR_RC_JOB_RETURN;
7381 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
7382 * @ipr_cmd: ipr command struct
7384 * This function send an Identify Host Request Response Queue
7385 * command to establish the HRRQ with the adapter.
7390 static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
7392 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7393 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7394 struct ipr_hrr_queue *hrrq;
7397 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
7398 if (ioa_cfg->identify_hrrq_index == 0)
7399 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
7401 if (ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num) {
7402 hrrq = &ioa_cfg->hrrq[ioa_cfg->identify_hrrq_index];
7404 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
7405 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7407 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7409 ioarcb->cmd_pkt.cdb[1] = 0x1;
7411 if (ioa_cfg->nvectors == 1)
7412 ioarcb->cmd_pkt.cdb[1] &= ~IPR_ID_HRRQ_SELE_ENABLE;
7414 ioarcb->cmd_pkt.cdb[1] |= IPR_ID_HRRQ_SELE_ENABLE;
7416 ioarcb->cmd_pkt.cdb[2] =
7417 ((u64) hrrq->host_rrq_dma >> 24) & 0xff;
7418 ioarcb->cmd_pkt.cdb[3] =
7419 ((u64) hrrq->host_rrq_dma >> 16) & 0xff;
7420 ioarcb->cmd_pkt.cdb[4] =
7421 ((u64) hrrq->host_rrq_dma >> 8) & 0xff;
7422 ioarcb->cmd_pkt.cdb[5] =
7423 ((u64) hrrq->host_rrq_dma) & 0xff;
7424 ioarcb->cmd_pkt.cdb[7] =
7425 ((sizeof(u32) * hrrq->size) >> 8) & 0xff;
7426 ioarcb->cmd_pkt.cdb[8] =
7427 (sizeof(u32) * hrrq->size) & 0xff;
7429 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
7430 ioarcb->cmd_pkt.cdb[9] =
7431 ioa_cfg->identify_hrrq_index;
7433 if (ioa_cfg->sis64) {
7434 ioarcb->cmd_pkt.cdb[10] =
7435 ((u64) hrrq->host_rrq_dma >> 56) & 0xff;
7436 ioarcb->cmd_pkt.cdb[11] =
7437 ((u64) hrrq->host_rrq_dma >> 48) & 0xff;
7438 ioarcb->cmd_pkt.cdb[12] =
7439 ((u64) hrrq->host_rrq_dma >> 40) & 0xff;
7440 ioarcb->cmd_pkt.cdb[13] =
7441 ((u64) hrrq->host_rrq_dma >> 32) & 0xff;
7444 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
7445 ioarcb->cmd_pkt.cdb[14] =
7446 ioa_cfg->identify_hrrq_index;
7448 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7449 IPR_INTERNAL_TIMEOUT);
7451 if (++ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num)
7452 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7455 return IPR_RC_JOB_RETURN;
7459 return IPR_RC_JOB_CONTINUE;
7463 * ipr_reset_timer_done - Adapter reset timer function
7464 * @t: Timer context used to fetch ipr command struct
7466 * Description: This function is used in adapter reset processing
7467 * for timing events. If the reset_cmd pointer in the IOA
7468 * config struct is not this adapter's we are doing nested
7469 * resets and fail_all_ops will take care of freeing the
7475 static void ipr_reset_timer_done(struct timer_list *t)
7477 struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
7478 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7479 unsigned long lock_flags = 0;
7481 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7483 if (ioa_cfg->reset_cmd == ipr_cmd) {
7484 list_del(&ipr_cmd->queue);
7485 ipr_cmd->done(ipr_cmd);
7488 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7492 * ipr_reset_start_timer - Start a timer for adapter reset job
7493 * @ipr_cmd: ipr command struct
7494 * @timeout: timeout value
7496 * Description: This function is used in adapter reset processing
7497 * for timing events. If the reset_cmd pointer in the IOA
7498 * config struct is not this adapter's we are doing nested
7499 * resets and fail_all_ops will take care of freeing the
7505 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
7506 unsigned long timeout)
7510 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
7511 ipr_cmd->done = ipr_reset_ioa_job;
7513 ipr_cmd->timer.expires = jiffies + timeout;
7514 ipr_cmd->timer.function = ipr_reset_timer_done;
7515 add_timer(&ipr_cmd->timer);
7519 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7520 * @ioa_cfg: ioa cfg struct
7525 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
7527 struct ipr_hrr_queue *hrrq;
7529 for_each_hrrq(hrrq, ioa_cfg) {
7530 spin_lock(&hrrq->_lock);
7531 memset(hrrq->host_rrq, 0, sizeof(u32) * hrrq->size);
7533 /* Initialize Host RRQ pointers */
7534 hrrq->hrrq_start = hrrq->host_rrq;
7535 hrrq->hrrq_end = &hrrq->host_rrq[hrrq->size - 1];
7536 hrrq->hrrq_curr = hrrq->hrrq_start;
7537 hrrq->toggle_bit = 1;
7538 spin_unlock(&hrrq->_lock);
7542 ioa_cfg->identify_hrrq_index = 0;
7543 if (ioa_cfg->hrrq_num == 1)
7544 atomic_set(&ioa_cfg->hrrq_index, 0);
7546 atomic_set(&ioa_cfg->hrrq_index, 1);
7548 /* Zero out config table */
7549 memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
7553 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
7554 * @ipr_cmd: ipr command struct
7557 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7559 static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
7561 unsigned long stage, stage_time;
7563 volatile u32 int_reg;
7564 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7567 feedback = readl(ioa_cfg->regs.init_feedback_reg);
7568 stage = feedback & IPR_IPL_INIT_STAGE_MASK;
7569 stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
7571 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
7573 /* sanity check the stage_time value */
7574 if (stage_time == 0)
7575 stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
7576 else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
7577 stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
7578 else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
7579 stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
7581 if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
7582 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
7583 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7584 stage_time = ioa_cfg->transop_timeout;
7585 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7586 } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
7587 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
7588 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7589 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7590 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7591 maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
7592 writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
7593 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7594 return IPR_RC_JOB_CONTINUE;
7598 ipr_cmd->timer.expires = jiffies + stage_time * HZ;
7599 ipr_cmd->timer.function = ipr_oper_timeout;
7600 ipr_cmd->done = ipr_reset_ioa_job;
7601 add_timer(&ipr_cmd->timer);
7603 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
7605 return IPR_RC_JOB_RETURN;
7609 * ipr_reset_enable_ioa - Enable the IOA following a reset.
7610 * @ipr_cmd: ipr command struct
7612 * This function reinitializes some control blocks and
7613 * enables destructive diagnostics on the adapter.
7618 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
7620 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7621 volatile u32 int_reg;
7622 volatile u64 maskval;
7626 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7627 ipr_init_ioa_mem(ioa_cfg);
7629 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
7630 spin_lock(&ioa_cfg->hrrq[i]._lock);
7631 ioa_cfg->hrrq[i].allow_interrupts = 1;
7632 spin_unlock(&ioa_cfg->hrrq[i]._lock);
7634 if (ioa_cfg->sis64) {
7635 /* Set the adapter to the correct endian mode. */
7636 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
7637 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
7640 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
7642 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7643 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
7644 ioa_cfg->regs.clr_interrupt_mask_reg32);
7645 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7646 return IPR_RC_JOB_CONTINUE;
7649 /* Enable destructive diagnostics on IOA */
7650 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
7652 if (ioa_cfg->sis64) {
7653 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7654 maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
7655 writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
7657 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
7659 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7661 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
7663 if (ioa_cfg->sis64) {
7664 ipr_cmd->job_step = ipr_reset_next_stage;
7665 return IPR_RC_JOB_CONTINUE;
7668 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
7669 ipr_cmd->timer.function = ipr_oper_timeout;
7670 ipr_cmd->done = ipr_reset_ioa_job;
7671 add_timer(&ipr_cmd->timer);
7672 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
7675 return IPR_RC_JOB_RETURN;
7679 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
7680 * @ipr_cmd: ipr command struct
7682 * This function is invoked when an adapter dump has run out
7683 * of processing time.
7686 * IPR_RC_JOB_CONTINUE
7688 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
7690 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7692 if (ioa_cfg->sdt_state == GET_DUMP)
7693 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7694 else if (ioa_cfg->sdt_state == READ_DUMP)
7695 ioa_cfg->sdt_state = ABORT_DUMP;
7697 ioa_cfg->dump_timeout = 1;
7698 ipr_cmd->job_step = ipr_reset_alert;
7700 return IPR_RC_JOB_CONTINUE;
7704 * ipr_unit_check_no_data - Log a unit check/no data error log
7705 * @ioa_cfg: ioa config struct
7707 * Logs an error indicating the adapter unit checked, but for some
7708 * reason, we were unable to fetch the unit check buffer.
7713 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
7715 ioa_cfg->errors_logged++;
7716 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
7720 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
7721 * @ioa_cfg: ioa config struct
7723 * Fetches the unit check buffer from the adapter by clocking the data
7724 * through the mailbox register.
7729 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
7731 unsigned long mailbox;
7732 struct ipr_hostrcb *hostrcb;
7733 struct ipr_uc_sdt sdt;
7737 mailbox = readl(ioa_cfg->ioa_mailbox);
7739 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
7740 ipr_unit_check_no_data(ioa_cfg);
7744 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
7745 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
7746 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
7748 if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
7749 ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
7750 (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
7751 ipr_unit_check_no_data(ioa_cfg);
7755 /* Find length of the first sdt entry (UC buffer) */
7756 if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
7757 length = be32_to_cpu(sdt.entry[0].end_token);
7759 length = (be32_to_cpu(sdt.entry[0].end_token) -
7760 be32_to_cpu(sdt.entry[0].start_token)) &
7761 IPR_FMT2_MBX_ADDR_MASK;
7763 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
7764 struct ipr_hostrcb, queue);
7765 list_del_init(&hostrcb->queue);
7766 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
7768 rc = ipr_get_ldump_data_section(ioa_cfg,
7769 be32_to_cpu(sdt.entry[0].start_token),
7770 (__be32 *)&hostrcb->hcam,
7771 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
7774 ipr_handle_log_data(ioa_cfg, hostrcb);
7775 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
7776 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
7777 ioa_cfg->sdt_state == GET_DUMP)
7778 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7780 ipr_unit_check_no_data(ioa_cfg);
7782 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
7786 * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
7787 * @ipr_cmd: ipr command struct
7789 * Description: This function will call to get the unit check buffer.
7794 static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
7796 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7799 ioa_cfg->ioa_unit_checked = 0;
7800 ipr_get_unit_check_buffer(ioa_cfg);
7801 ipr_cmd->job_step = ipr_reset_alert;
7802 ipr_reset_start_timer(ipr_cmd, 0);
7805 return IPR_RC_JOB_RETURN;
7808 static int ipr_dump_mailbox_wait(struct ipr_cmnd *ipr_cmd)
7810 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7814 if (ioa_cfg->sdt_state != GET_DUMP)
7815 return IPR_RC_JOB_RETURN;
7817 if (!ioa_cfg->sis64 || !ipr_cmd->u.time_left ||
7818 (readl(ioa_cfg->regs.sense_interrupt_reg) &
7819 IPR_PCII_MAILBOX_STABLE)) {
7821 if (!ipr_cmd->u.time_left)
7822 dev_err(&ioa_cfg->pdev->dev,
7823 "Timed out waiting for Mailbox register.\n");
7825 ioa_cfg->sdt_state = READ_DUMP;
7826 ioa_cfg->dump_timeout = 0;
7828 ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
7830 ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
7831 ipr_cmd->job_step = ipr_reset_wait_for_dump;
7832 schedule_work(&ioa_cfg->work_q);
7835 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
7836 ipr_reset_start_timer(ipr_cmd,
7837 IPR_CHECK_FOR_RESET_TIMEOUT);
7841 return IPR_RC_JOB_RETURN;
7845 * ipr_reset_restore_cfg_space - Restore PCI config space.
7846 * @ipr_cmd: ipr command struct
7848 * Description: This function restores the saved PCI config space of
7849 * the adapter, fails all outstanding ops back to the callers, and
7850 * fetches the dump/unit check if applicable to this reset.
7853 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7855 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
7857 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7860 ioa_cfg->pdev->state_saved = true;
7861 pci_restore_state(ioa_cfg->pdev);
7863 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
7864 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
7865 return IPR_RC_JOB_CONTINUE;
7868 ipr_fail_all_ops(ioa_cfg);
7870 if (ioa_cfg->sis64) {
7871 /* Set the adapter to the correct endian mode. */
7872 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
7873 readl(ioa_cfg->regs.endian_swap_reg);
7876 if (ioa_cfg->ioa_unit_checked) {
7877 if (ioa_cfg->sis64) {
7878 ipr_cmd->job_step = ipr_reset_get_unit_check_job;
7879 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
7880 return IPR_RC_JOB_RETURN;
7882 ioa_cfg->ioa_unit_checked = 0;
7883 ipr_get_unit_check_buffer(ioa_cfg);
7884 ipr_cmd->job_step = ipr_reset_alert;
7885 ipr_reset_start_timer(ipr_cmd, 0);
7886 return IPR_RC_JOB_RETURN;
7890 if (ioa_cfg->in_ioa_bringdown) {
7891 ipr_cmd->job_step = ipr_ioa_bringdown_done;
7892 } else if (ioa_cfg->sdt_state == GET_DUMP) {
7893 ipr_cmd->job_step = ipr_dump_mailbox_wait;
7894 ipr_cmd->u.time_left = IPR_WAIT_FOR_MAILBOX;
7896 ipr_cmd->job_step = ipr_reset_enable_ioa;
7900 return IPR_RC_JOB_CONTINUE;
7904 * ipr_reset_bist_done - BIST has completed on the adapter.
7905 * @ipr_cmd: ipr command struct
7907 * Description: Unblock config space and resume the reset process.
7910 * IPR_RC_JOB_CONTINUE
7912 static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
7914 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7917 if (ioa_cfg->cfg_locked)
7918 pci_cfg_access_unlock(ioa_cfg->pdev);
7919 ioa_cfg->cfg_locked = 0;
7920 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
7922 return IPR_RC_JOB_CONTINUE;
7926 * ipr_reset_start_bist - Run BIST on the adapter.
7927 * @ipr_cmd: ipr command struct
7929 * Description: This function runs BIST on the adapter, then delays 2 seconds.
7932 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7934 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
7936 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7937 int rc = PCIBIOS_SUCCESSFUL;
7940 if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
7941 writel(IPR_UPROCI_SIS64_START_BIST,
7942 ioa_cfg->regs.set_uproc_interrupt_reg32);
7944 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
7946 if (rc == PCIBIOS_SUCCESSFUL) {
7947 ipr_cmd->job_step = ipr_reset_bist_done;
7948 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
7949 rc = IPR_RC_JOB_RETURN;
7951 if (ioa_cfg->cfg_locked)
7952 pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
7953 ioa_cfg->cfg_locked = 0;
7954 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
7955 rc = IPR_RC_JOB_CONTINUE;
7963 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
7964 * @ipr_cmd: ipr command struct
7966 * Description: This clears PCI reset to the adapter and delays two seconds.
7971 static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
7974 ipr_cmd->job_step = ipr_reset_bist_done;
7975 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
7977 return IPR_RC_JOB_RETURN;
7981 * ipr_reset_reset_work - Pulse a PCIe fundamental reset
7982 * @work: work struct
7984 * Description: This pulses warm reset to a slot.
7987 static void ipr_reset_reset_work(struct work_struct *work)
7989 struct ipr_cmnd *ipr_cmd = container_of(work, struct ipr_cmnd, work);
7990 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7991 struct pci_dev *pdev = ioa_cfg->pdev;
7992 unsigned long lock_flags = 0;
7995 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
7996 msleep(jiffies_to_msecs(IPR_PCI_RESET_TIMEOUT));
7997 pci_set_pcie_reset_state(pdev, pcie_deassert_reset);
7999 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8000 if (ioa_cfg->reset_cmd == ipr_cmd)
8001 ipr_reset_ioa_job(ipr_cmd);
8002 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8007 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
8008 * @ipr_cmd: ipr command struct
8010 * Description: This asserts PCI reset to the adapter.
8015 static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
8017 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8020 INIT_WORK(&ipr_cmd->work, ipr_reset_reset_work);
8021 queue_work(ioa_cfg->reset_work_q, &ipr_cmd->work);
8022 ipr_cmd->job_step = ipr_reset_slot_reset_done;
8024 return IPR_RC_JOB_RETURN;
8028 * ipr_reset_block_config_access_wait - Wait for permission to block config access
8029 * @ipr_cmd: ipr command struct
8031 * Description: This attempts to block config access to the IOA.
8034 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8036 static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
8038 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8039 int rc = IPR_RC_JOB_CONTINUE;
8041 if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
8042 ioa_cfg->cfg_locked = 1;
8043 ipr_cmd->job_step = ioa_cfg->reset;
8045 if (ipr_cmd->u.time_left) {
8046 rc = IPR_RC_JOB_RETURN;
8047 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8048 ipr_reset_start_timer(ipr_cmd,
8049 IPR_CHECK_FOR_RESET_TIMEOUT);
8051 ipr_cmd->job_step = ioa_cfg->reset;
8052 dev_err(&ioa_cfg->pdev->dev,
8053 "Timed out waiting to lock config access. Resetting anyway.\n");
8061 * ipr_reset_block_config_access - Block config access to the IOA
8062 * @ipr_cmd: ipr command struct
8064 * Description: This attempts to block config access to the IOA
8067 * IPR_RC_JOB_CONTINUE
8069 static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
8071 ipr_cmd->ioa_cfg->cfg_locked = 0;
8072 ipr_cmd->job_step = ipr_reset_block_config_access_wait;
8073 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8074 return IPR_RC_JOB_CONTINUE;
8078 * ipr_reset_allowed - Query whether or not IOA can be reset
8079 * @ioa_cfg: ioa config struct
8082 * 0 if reset not allowed / non-zero if reset is allowed
8084 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
8086 volatile u32 temp_reg;
8088 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
8089 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
8093 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
8094 * @ipr_cmd: ipr command struct
8096 * Description: This function waits for adapter permission to run BIST,
8097 * then runs BIST. If the adapter does not give permission after a
8098 * reasonable time, we will reset the adapter anyway. The impact of
8099 * resetting the adapter without warning the adapter is the risk of
8100 * losing the persistent error log on the adapter. If the adapter is
8101 * reset while it is writing to the flash on the adapter, the flash
8102 * segment will have bad ECC and be zeroed.
8105 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8107 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
8109 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8110 int rc = IPR_RC_JOB_RETURN;
8112 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
8113 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8114 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8116 ipr_cmd->job_step = ipr_reset_block_config_access;
8117 rc = IPR_RC_JOB_CONTINUE;
8124 * ipr_reset_alert - Alert the adapter of a pending reset
8125 * @ipr_cmd: ipr command struct
8127 * Description: This function alerts the adapter that it will be reset.
8128 * If memory space is not currently enabled, proceed directly
8129 * to running BIST on the adapter. The timer must always be started
8130 * so we guarantee we do not run BIST from ipr_isr.
8135 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
8137 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8142 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
8144 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
8145 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
8146 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
8147 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
8149 ipr_cmd->job_step = ipr_reset_block_config_access;
8152 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8153 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8156 return IPR_RC_JOB_RETURN;
8160 * ipr_reset_quiesce_done - Complete IOA disconnect
8161 * @ipr_cmd: ipr command struct
8163 * Description: Freeze the adapter to complete quiesce processing
8166 * IPR_RC_JOB_CONTINUE
8168 static int ipr_reset_quiesce_done(struct ipr_cmnd *ipr_cmd)
8170 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8173 ipr_cmd->job_step = ipr_ioa_bringdown_done;
8174 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
8176 return IPR_RC_JOB_CONTINUE;
8180 * ipr_reset_cancel_hcam_done - Check for outstanding commands
8181 * @ipr_cmd: ipr command struct
8183 * Description: Ensure nothing is outstanding to the IOA and
8184 * proceed with IOA disconnect. Otherwise reset the IOA.
8187 * IPR_RC_JOB_RETURN / IPR_RC_JOB_CONTINUE
8189 static int ipr_reset_cancel_hcam_done(struct ipr_cmnd *ipr_cmd)
8191 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8192 struct ipr_cmnd *loop_cmd;
8193 struct ipr_hrr_queue *hrrq;
8194 int rc = IPR_RC_JOB_CONTINUE;
8198 ipr_cmd->job_step = ipr_reset_quiesce_done;
8200 for_each_hrrq(hrrq, ioa_cfg) {
8201 spin_lock(&hrrq->_lock);
8202 list_for_each_entry(loop_cmd, &hrrq->hrrq_pending_q, queue) {
8204 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8205 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
8206 rc = IPR_RC_JOB_RETURN;
8209 spin_unlock(&hrrq->_lock);
8220 * ipr_reset_cancel_hcam - Cancel outstanding HCAMs
8221 * @ipr_cmd: ipr command struct
8223 * Description: Cancel any oustanding HCAMs to the IOA.
8226 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8228 static int ipr_reset_cancel_hcam(struct ipr_cmnd *ipr_cmd)
8230 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8231 int rc = IPR_RC_JOB_CONTINUE;
8232 struct ipr_cmd_pkt *cmd_pkt;
8233 struct ipr_cmnd *hcam_cmd;
8234 struct ipr_hrr_queue *hrrq = &ioa_cfg->hrrq[IPR_INIT_HRRQ];
8237 ipr_cmd->job_step = ipr_reset_cancel_hcam_done;
8239 if (!hrrq->ioa_is_dead) {
8240 if (!list_empty(&ioa_cfg->hostrcb_pending_q)) {
8241 list_for_each_entry(hcam_cmd, &hrrq->hrrq_pending_q, queue) {
8242 if (hcam_cmd->ioarcb.cmd_pkt.cdb[0] != IPR_HOST_CONTROLLED_ASYNC)
8245 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8246 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8247 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
8248 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
8249 cmd_pkt->cdb[0] = IPR_CANCEL_REQUEST;
8250 cmd_pkt->cdb[1] = IPR_CANCEL_64BIT_IOARCB;
8251 cmd_pkt->cdb[10] = ((u64) hcam_cmd->dma_addr >> 56) & 0xff;
8252 cmd_pkt->cdb[11] = ((u64) hcam_cmd->dma_addr >> 48) & 0xff;
8253 cmd_pkt->cdb[12] = ((u64) hcam_cmd->dma_addr >> 40) & 0xff;
8254 cmd_pkt->cdb[13] = ((u64) hcam_cmd->dma_addr >> 32) & 0xff;
8255 cmd_pkt->cdb[2] = ((u64) hcam_cmd->dma_addr >> 24) & 0xff;
8256 cmd_pkt->cdb[3] = ((u64) hcam_cmd->dma_addr >> 16) & 0xff;
8257 cmd_pkt->cdb[4] = ((u64) hcam_cmd->dma_addr >> 8) & 0xff;
8258 cmd_pkt->cdb[5] = ((u64) hcam_cmd->dma_addr) & 0xff;
8260 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
8261 IPR_CANCEL_TIMEOUT);
8263 rc = IPR_RC_JOB_RETURN;
8264 ipr_cmd->job_step = ipr_reset_cancel_hcam;
8269 ipr_cmd->job_step = ipr_reset_alert;
8276 * ipr_reset_ucode_download_done - Microcode download completion
8277 * @ipr_cmd: ipr command struct
8279 * Description: This function unmaps the microcode download buffer.
8282 * IPR_RC_JOB_CONTINUE
8284 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
8286 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8287 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8289 dma_unmap_sg(&ioa_cfg->pdev->dev, sglist->scatterlist,
8290 sglist->num_sg, DMA_TO_DEVICE);
8292 ipr_cmd->job_step = ipr_reset_alert;
8293 return IPR_RC_JOB_CONTINUE;
8297 * ipr_reset_ucode_download - Download microcode to the adapter
8298 * @ipr_cmd: ipr command struct
8300 * Description: This function checks to see if it there is microcode
8301 * to download to the adapter. If there is, a download is performed.
8304 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8306 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
8308 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8309 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8312 ipr_cmd->job_step = ipr_reset_alert;
8315 return IPR_RC_JOB_CONTINUE;
8317 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8318 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
8319 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
8320 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
8321 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
8322 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
8323 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
8326 ipr_build_ucode_ioadl64(ipr_cmd, sglist);
8328 ipr_build_ucode_ioadl(ipr_cmd, sglist);
8329 ipr_cmd->job_step = ipr_reset_ucode_download_done;
8331 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
8332 IPR_WRITE_BUFFER_TIMEOUT);
8335 return IPR_RC_JOB_RETURN;
8339 * ipr_reset_shutdown_ioa - Shutdown the adapter
8340 * @ipr_cmd: ipr command struct
8342 * Description: This function issues an adapter shutdown of the
8343 * specified type to the specified adapter as part of the
8344 * adapter reset job.
8347 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8349 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
8351 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8352 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
8353 unsigned long timeout;
8354 int rc = IPR_RC_JOB_CONTINUE;
8357 if (shutdown_type == IPR_SHUTDOWN_QUIESCE)
8358 ipr_cmd->job_step = ipr_reset_cancel_hcam;
8359 else if (shutdown_type != IPR_SHUTDOWN_NONE &&
8360 !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
8361 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8362 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8363 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
8364 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
8366 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
8367 timeout = IPR_SHUTDOWN_TIMEOUT;
8368 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
8369 timeout = IPR_INTERNAL_TIMEOUT;
8370 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
8371 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
8373 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
8375 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
8377 rc = IPR_RC_JOB_RETURN;
8378 ipr_cmd->job_step = ipr_reset_ucode_download;
8380 ipr_cmd->job_step = ipr_reset_alert;
8387 * ipr_reset_ioa_job - Adapter reset job
8388 * @ipr_cmd: ipr command struct
8390 * Description: This function is the job router for the adapter reset job.
8395 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
8398 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8401 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
8403 if (ioa_cfg->reset_cmd != ipr_cmd) {
8405 * We are doing nested adapter resets and this is
8406 * not the current reset job.
8408 list_add_tail(&ipr_cmd->queue,
8409 &ipr_cmd->hrrq->hrrq_free_q);
8413 if (IPR_IOASC_SENSE_KEY(ioasc)) {
8414 rc = ipr_cmd->job_step_failed(ipr_cmd);
8415 if (rc == IPR_RC_JOB_RETURN)
8419 ipr_reinit_ipr_cmnd(ipr_cmd);
8420 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
8421 rc = ipr_cmd->job_step(ipr_cmd);
8422 } while (rc == IPR_RC_JOB_CONTINUE);
8426 * _ipr_initiate_ioa_reset - Initiate an adapter reset
8427 * @ioa_cfg: ioa config struct
8428 * @job_step: first job step of reset job
8429 * @shutdown_type: shutdown type
8431 * Description: This function will initiate the reset of the given adapter
8432 * starting at the selected job step.
8433 * If the caller needs to wait on the completion of the reset,
8434 * the caller must sleep on the reset_wait_q.
8439 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8440 int (*job_step) (struct ipr_cmnd *),
8441 enum ipr_shutdown_type shutdown_type)
8443 struct ipr_cmnd *ipr_cmd;
8446 ioa_cfg->in_reset_reload = 1;
8447 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8448 spin_lock(&ioa_cfg->hrrq[i]._lock);
8449 ioa_cfg->hrrq[i].allow_cmds = 0;
8450 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8453 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
8454 ioa_cfg->scsi_unblock = 0;
8455 ioa_cfg->scsi_blocked = 1;
8456 scsi_block_requests(ioa_cfg->host);
8459 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
8460 ioa_cfg->reset_cmd = ipr_cmd;
8461 ipr_cmd->job_step = job_step;
8462 ipr_cmd->u.shutdown_type = shutdown_type;
8464 ipr_reset_ioa_job(ipr_cmd);
8468 * ipr_initiate_ioa_reset - Initiate an adapter reset
8469 * @ioa_cfg: ioa config struct
8470 * @shutdown_type: shutdown type
8472 * Description: This function will initiate the reset of the given adapter.
8473 * If the caller needs to wait on the completion of the reset,
8474 * the caller must sleep on the reset_wait_q.
8479 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8480 enum ipr_shutdown_type shutdown_type)
8484 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
8487 if (ioa_cfg->in_reset_reload) {
8488 if (ioa_cfg->sdt_state == GET_DUMP)
8489 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8490 else if (ioa_cfg->sdt_state == READ_DUMP)
8491 ioa_cfg->sdt_state = ABORT_DUMP;
8494 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
8495 dev_err(&ioa_cfg->pdev->dev,
8496 "IOA taken offline - error recovery failed\n");
8498 ioa_cfg->reset_retries = 0;
8499 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8500 spin_lock(&ioa_cfg->hrrq[i]._lock);
8501 ioa_cfg->hrrq[i].ioa_is_dead = 1;
8502 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8506 if (ioa_cfg->in_ioa_bringdown) {
8507 ioa_cfg->reset_cmd = NULL;
8508 ioa_cfg->in_reset_reload = 0;
8509 ipr_fail_all_ops(ioa_cfg);
8510 wake_up_all(&ioa_cfg->reset_wait_q);
8512 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
8513 ioa_cfg->scsi_unblock = 1;
8514 schedule_work(&ioa_cfg->work_q);
8518 ioa_cfg->in_ioa_bringdown = 1;
8519 shutdown_type = IPR_SHUTDOWN_NONE;
8523 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
8528 * ipr_reset_freeze - Hold off all I/O activity
8529 * @ipr_cmd: ipr command struct
8531 * Description: If the PCI slot is frozen, hold off all I/O
8532 * activity; then, as soon as the slot is available again,
8533 * initiate an adapter reset.
8535 static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
8537 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8540 /* Disallow new interrupts, avoid loop */
8541 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8542 spin_lock(&ioa_cfg->hrrq[i]._lock);
8543 ioa_cfg->hrrq[i].allow_interrupts = 0;
8544 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8547 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
8548 ipr_cmd->done = ipr_reset_ioa_job;
8549 return IPR_RC_JOB_RETURN;
8553 * ipr_pci_mmio_enabled - Called when MMIO has been re-enabled
8554 * @pdev: PCI device struct
8556 * Description: This routine is called to tell us that the MMIO
8557 * access to the IOA has been restored
8559 static pci_ers_result_t ipr_pci_mmio_enabled(struct pci_dev *pdev)
8561 unsigned long flags = 0;
8562 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8564 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8565 if (!ioa_cfg->probe_done)
8566 pci_save_state(pdev);
8567 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8568 return PCI_ERS_RESULT_NEED_RESET;
8572 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
8573 * @pdev: PCI device struct
8575 * Description: This routine is called to tell us that the PCI bus
8576 * is down. Can't do anything here, except put the device driver
8577 * into a holding pattern, waiting for the PCI bus to come back.
8579 static void ipr_pci_frozen(struct pci_dev *pdev)
8581 unsigned long flags = 0;
8582 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8584 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8585 if (ioa_cfg->probe_done)
8586 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
8587 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8591 * ipr_pci_slot_reset - Called when PCI slot has been reset.
8592 * @pdev: PCI device struct
8594 * Description: This routine is called by the pci error recovery
8595 * code after the PCI slot has been reset, just before we
8596 * should resume normal operations.
8598 static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
8600 unsigned long flags = 0;
8601 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8603 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8604 if (ioa_cfg->probe_done) {
8605 if (ioa_cfg->needs_warm_reset)
8606 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8608 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
8611 wake_up_all(&ioa_cfg->eeh_wait_q);
8612 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8613 return PCI_ERS_RESULT_RECOVERED;
8617 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
8618 * @pdev: PCI device struct
8620 * Description: This routine is called when the PCI bus has
8621 * permanently failed.
8623 static void ipr_pci_perm_failure(struct pci_dev *pdev)
8625 unsigned long flags = 0;
8626 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8629 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8630 if (ioa_cfg->probe_done) {
8631 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
8632 ioa_cfg->sdt_state = ABORT_DUMP;
8633 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES - 1;
8634 ioa_cfg->in_ioa_bringdown = 1;
8635 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8636 spin_lock(&ioa_cfg->hrrq[i]._lock);
8637 ioa_cfg->hrrq[i].allow_cmds = 0;
8638 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8641 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8643 wake_up_all(&ioa_cfg->eeh_wait_q);
8644 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8648 * ipr_pci_error_detected - Called when a PCI error is detected.
8649 * @pdev: PCI device struct
8650 * @state: PCI channel state
8652 * Description: Called when a PCI error is detected.
8655 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8657 static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
8658 pci_channel_state_t state)
8661 case pci_channel_io_frozen:
8662 ipr_pci_frozen(pdev);
8663 return PCI_ERS_RESULT_CAN_RECOVER;
8664 case pci_channel_io_perm_failure:
8665 ipr_pci_perm_failure(pdev);
8666 return PCI_ERS_RESULT_DISCONNECT;
8670 return PCI_ERS_RESULT_NEED_RESET;
8674 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
8675 * @ioa_cfg: ioa cfg struct
8677 * Description: This is the second phase of adapter initialization
8678 * This function takes care of initilizing the adapter to the point
8679 * where it can accept new commands.
8683 static void ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
8685 unsigned long host_lock_flags = 0;
8688 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8689 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
8690 ioa_cfg->probe_done = 1;
8691 if (ioa_cfg->needs_hard_reset) {
8692 ioa_cfg->needs_hard_reset = 0;
8693 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8695 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
8697 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8703 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
8704 * @ioa_cfg: ioa config struct
8709 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8713 if (ioa_cfg->ipr_cmnd_list) {
8714 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8715 if (ioa_cfg->ipr_cmnd_list[i])
8716 dma_pool_free(ioa_cfg->ipr_cmd_pool,
8717 ioa_cfg->ipr_cmnd_list[i],
8718 ioa_cfg->ipr_cmnd_list_dma[i]);
8720 ioa_cfg->ipr_cmnd_list[i] = NULL;
8724 dma_pool_destroy(ioa_cfg->ipr_cmd_pool);
8726 kfree(ioa_cfg->ipr_cmnd_list);
8727 kfree(ioa_cfg->ipr_cmnd_list_dma);
8728 ioa_cfg->ipr_cmnd_list = NULL;
8729 ioa_cfg->ipr_cmnd_list_dma = NULL;
8730 ioa_cfg->ipr_cmd_pool = NULL;
8734 * ipr_free_mem - Frees memory allocated for an adapter
8735 * @ioa_cfg: ioa cfg struct
8740 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
8744 kfree(ioa_cfg->res_entries);
8745 dma_free_coherent(&ioa_cfg->pdev->dev, sizeof(struct ipr_misc_cbs),
8746 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8747 ipr_free_cmd_blks(ioa_cfg);
8749 for (i = 0; i < ioa_cfg->hrrq_num; i++)
8750 dma_free_coherent(&ioa_cfg->pdev->dev,
8751 sizeof(u32) * ioa_cfg->hrrq[i].size,
8752 ioa_cfg->hrrq[i].host_rrq,
8753 ioa_cfg->hrrq[i].host_rrq_dma);
8755 dma_free_coherent(&ioa_cfg->pdev->dev, ioa_cfg->cfg_table_size,
8756 ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
8758 for (i = 0; i < IPR_MAX_HCAMS; i++) {
8759 dma_free_coherent(&ioa_cfg->pdev->dev,
8760 sizeof(struct ipr_hostrcb),
8761 ioa_cfg->hostrcb[i],
8762 ioa_cfg->hostrcb_dma[i]);
8765 ipr_free_dump(ioa_cfg);
8766 kfree(ioa_cfg->trace);
8770 * ipr_free_irqs - Free all allocated IRQs for the adapter.
8771 * @ioa_cfg: ipr cfg struct
8773 * This function frees all allocated IRQs for the
8774 * specified adapter.
8779 static void ipr_free_irqs(struct ipr_ioa_cfg *ioa_cfg)
8781 struct pci_dev *pdev = ioa_cfg->pdev;
8784 for (i = 0; i < ioa_cfg->nvectors; i++)
8785 free_irq(pci_irq_vector(pdev, i), &ioa_cfg->hrrq[i]);
8786 pci_free_irq_vectors(pdev);
8790 * ipr_free_all_resources - Free all allocated resources for an adapter.
8791 * @ioa_cfg: ioa config struct
8793 * This function frees all allocated resources for the
8794 * specified adapter.
8799 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
8801 struct pci_dev *pdev = ioa_cfg->pdev;
8804 ipr_free_irqs(ioa_cfg);
8805 if (ioa_cfg->reset_work_q)
8806 destroy_workqueue(ioa_cfg->reset_work_q);
8807 iounmap(ioa_cfg->hdw_dma_regs);
8808 pci_release_regions(pdev);
8809 ipr_free_mem(ioa_cfg);
8810 scsi_host_put(ioa_cfg->host);
8811 pci_disable_device(pdev);
8816 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
8817 * @ioa_cfg: ioa config struct
8820 * 0 on success / -ENOMEM on allocation failure
8822 static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8824 struct ipr_cmnd *ipr_cmd;
8825 struct ipr_ioarcb *ioarcb;
8826 dma_addr_t dma_addr;
8827 int i, entries_each_hrrq, hrrq_id = 0;
8829 ioa_cfg->ipr_cmd_pool = dma_pool_create(IPR_NAME, &ioa_cfg->pdev->dev,
8830 sizeof(struct ipr_cmnd), 512, 0);
8832 if (!ioa_cfg->ipr_cmd_pool)
8835 ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
8836 ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
8838 if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
8839 ipr_free_cmd_blks(ioa_cfg);
8843 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8844 if (ioa_cfg->hrrq_num > 1) {
8846 entries_each_hrrq = IPR_NUM_INTERNAL_CMD_BLKS;
8847 ioa_cfg->hrrq[i].min_cmd_id = 0;
8848 ioa_cfg->hrrq[i].max_cmd_id =
8849 (entries_each_hrrq - 1);
8852 IPR_NUM_BASE_CMD_BLKS/
8853 (ioa_cfg->hrrq_num - 1);
8854 ioa_cfg->hrrq[i].min_cmd_id =
8855 IPR_NUM_INTERNAL_CMD_BLKS +
8856 (i - 1) * entries_each_hrrq;
8857 ioa_cfg->hrrq[i].max_cmd_id =
8858 (IPR_NUM_INTERNAL_CMD_BLKS +
8859 i * entries_each_hrrq - 1);
8862 entries_each_hrrq = IPR_NUM_CMD_BLKS;
8863 ioa_cfg->hrrq[i].min_cmd_id = 0;
8864 ioa_cfg->hrrq[i].max_cmd_id = (entries_each_hrrq - 1);
8866 ioa_cfg->hrrq[i].size = entries_each_hrrq;
8869 BUG_ON(ioa_cfg->hrrq_num == 0);
8871 i = IPR_NUM_CMD_BLKS -
8872 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id - 1;
8874 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].size += i;
8875 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id += i;
8878 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8879 ipr_cmd = dma_pool_zalloc(ioa_cfg->ipr_cmd_pool,
8880 GFP_KERNEL, &dma_addr);
8883 ipr_free_cmd_blks(ioa_cfg);
8887 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
8888 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
8890 ioarcb = &ipr_cmd->ioarcb;
8891 ipr_cmd->dma_addr = dma_addr;
8893 ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
8895 ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
8897 ioarcb->host_response_handle = cpu_to_be32(i << 2);
8898 if (ioa_cfg->sis64) {
8899 ioarcb->u.sis64_addr_data.data_ioadl_addr =
8900 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
8901 ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
8902 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
8904 ioarcb->write_ioadl_addr =
8905 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
8906 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
8907 ioarcb->ioasa_host_pci_addr =
8908 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
8910 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
8911 ipr_cmd->cmd_index = i;
8912 ipr_cmd->ioa_cfg = ioa_cfg;
8913 ipr_cmd->sense_buffer_dma = dma_addr +
8914 offsetof(struct ipr_cmnd, sense_buffer);
8916 ipr_cmd->ioarcb.cmd_pkt.hrrq_id = hrrq_id;
8917 ipr_cmd->hrrq = &ioa_cfg->hrrq[hrrq_id];
8918 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
8919 if (i >= ioa_cfg->hrrq[hrrq_id].max_cmd_id)
8927 * ipr_alloc_mem - Allocate memory for an adapter
8928 * @ioa_cfg: ioa config struct
8931 * 0 on success / non-zero for error
8933 static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
8935 struct pci_dev *pdev = ioa_cfg->pdev;
8936 int i, rc = -ENOMEM;
8939 ioa_cfg->res_entries = kcalloc(ioa_cfg->max_devs_supported,
8940 sizeof(struct ipr_resource_entry),
8943 if (!ioa_cfg->res_entries)
8946 for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
8947 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
8948 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
8951 ioa_cfg->vpd_cbs = dma_alloc_coherent(&pdev->dev,
8952 sizeof(struct ipr_misc_cbs),
8953 &ioa_cfg->vpd_cbs_dma,
8956 if (!ioa_cfg->vpd_cbs)
8957 goto out_free_res_entries;
8959 if (ipr_alloc_cmd_blks(ioa_cfg))
8960 goto out_free_vpd_cbs;
8962 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8963 ioa_cfg->hrrq[i].host_rrq = dma_alloc_coherent(&pdev->dev,
8964 sizeof(u32) * ioa_cfg->hrrq[i].size,
8965 &ioa_cfg->hrrq[i].host_rrq_dma,
8968 if (!ioa_cfg->hrrq[i].host_rrq) {
8970 dma_free_coherent(&pdev->dev,
8971 sizeof(u32) * ioa_cfg->hrrq[i].size,
8972 ioa_cfg->hrrq[i].host_rrq,
8973 ioa_cfg->hrrq[i].host_rrq_dma);
8974 goto out_ipr_free_cmd_blocks;
8976 ioa_cfg->hrrq[i].ioa_cfg = ioa_cfg;
8979 ioa_cfg->u.cfg_table = dma_alloc_coherent(&pdev->dev,
8980 ioa_cfg->cfg_table_size,
8981 &ioa_cfg->cfg_table_dma,
8984 if (!ioa_cfg->u.cfg_table)
8985 goto out_free_host_rrq;
8987 for (i = 0; i < IPR_MAX_HCAMS; i++) {
8988 ioa_cfg->hostrcb[i] = dma_alloc_coherent(&pdev->dev,
8989 sizeof(struct ipr_hostrcb),
8990 &ioa_cfg->hostrcb_dma[i],
8993 if (!ioa_cfg->hostrcb[i])
8994 goto out_free_hostrcb_dma;
8996 ioa_cfg->hostrcb[i]->hostrcb_dma =
8997 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
8998 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
8999 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
9002 ioa_cfg->trace = kcalloc(IPR_NUM_TRACE_ENTRIES,
9003 sizeof(struct ipr_trace_entry),
9006 if (!ioa_cfg->trace)
9007 goto out_free_hostrcb_dma;
9014 out_free_hostrcb_dma:
9016 dma_free_coherent(&pdev->dev, sizeof(struct ipr_hostrcb),
9017 ioa_cfg->hostrcb[i],
9018 ioa_cfg->hostrcb_dma[i]);
9020 dma_free_coherent(&pdev->dev, ioa_cfg->cfg_table_size,
9021 ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
9023 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9024 dma_free_coherent(&pdev->dev,
9025 sizeof(u32) * ioa_cfg->hrrq[i].size,
9026 ioa_cfg->hrrq[i].host_rrq,
9027 ioa_cfg->hrrq[i].host_rrq_dma);
9029 out_ipr_free_cmd_blocks:
9030 ipr_free_cmd_blks(ioa_cfg);
9032 dma_free_coherent(&pdev->dev, sizeof(struct ipr_misc_cbs),
9033 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
9034 out_free_res_entries:
9035 kfree(ioa_cfg->res_entries);
9040 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
9041 * @ioa_cfg: ioa config struct
9046 static void ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
9050 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
9051 ioa_cfg->bus_attr[i].bus = i;
9052 ioa_cfg->bus_attr[i].qas_enabled = 0;
9053 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
9054 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
9055 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
9057 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
9062 * ipr_init_regs - Initialize IOA registers
9063 * @ioa_cfg: ioa config struct
9068 static void ipr_init_regs(struct ipr_ioa_cfg *ioa_cfg)
9070 const struct ipr_interrupt_offsets *p;
9071 struct ipr_interrupts *t;
9074 p = &ioa_cfg->chip_cfg->regs;
9076 base = ioa_cfg->hdw_dma_regs;
9078 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
9079 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
9080 t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
9081 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
9082 t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
9083 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
9084 t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
9085 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
9086 t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
9087 t->ioarrin_reg = base + p->ioarrin_reg;
9088 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
9089 t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
9090 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
9091 t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
9092 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
9093 t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
9095 if (ioa_cfg->sis64) {
9096 t->init_feedback_reg = base + p->init_feedback_reg;
9097 t->dump_addr_reg = base + p->dump_addr_reg;
9098 t->dump_data_reg = base + p->dump_data_reg;
9099 t->endian_swap_reg = base + p->endian_swap_reg;
9104 * ipr_init_ioa_cfg - Initialize IOA config struct
9105 * @ioa_cfg: ioa config struct
9106 * @host: scsi host struct
9107 * @pdev: PCI dev struct
9112 static void ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
9113 struct Scsi_Host *host, struct pci_dev *pdev)
9117 ioa_cfg->host = host;
9118 ioa_cfg->pdev = pdev;
9119 ioa_cfg->log_level = ipr_log_level;
9120 ioa_cfg->doorbell = IPR_DOORBELL;
9121 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
9122 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
9123 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
9124 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
9125 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
9126 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
9128 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
9129 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
9130 INIT_LIST_HEAD(&ioa_cfg->hostrcb_report_q);
9131 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
9132 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
9133 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
9134 INIT_WORK(&ioa_cfg->scsi_add_work_q, ipr_add_remove_thread);
9135 init_waitqueue_head(&ioa_cfg->reset_wait_q);
9136 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9137 init_waitqueue_head(&ioa_cfg->eeh_wait_q);
9138 ioa_cfg->sdt_state = INACTIVE;
9140 ipr_initialize_bus_attr(ioa_cfg);
9141 ioa_cfg->max_devs_supported = ipr_max_devs;
9143 if (ioa_cfg->sis64) {
9144 host->max_channel = IPR_MAX_SIS64_BUSES;
9145 host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
9146 host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
9147 if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
9148 ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
9149 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
9150 + ((sizeof(struct ipr_config_table_entry64)
9151 * ioa_cfg->max_devs_supported)));
9153 host->max_channel = IPR_VSET_BUS;
9154 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
9155 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
9156 if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
9157 ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
9158 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
9159 + ((sizeof(struct ipr_config_table_entry)
9160 * ioa_cfg->max_devs_supported)));
9163 host->unique_id = host->host_no;
9164 host->max_cmd_len = IPR_MAX_CDB_LEN;
9165 host->can_queue = ioa_cfg->max_cmds;
9166 pci_set_drvdata(pdev, ioa_cfg);
9168 for (i = 0; i < ARRAY_SIZE(ioa_cfg->hrrq); i++) {
9169 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_free_q);
9170 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_pending_q);
9171 spin_lock_init(&ioa_cfg->hrrq[i]._lock);
9173 ioa_cfg->hrrq[i].lock = ioa_cfg->host->host_lock;
9175 ioa_cfg->hrrq[i].lock = &ioa_cfg->hrrq[i]._lock;
9180 * ipr_get_chip_info - Find adapter chip information
9181 * @dev_id: PCI device id struct
9184 * ptr to chip information on success / NULL on failure
9186 static const struct ipr_chip_t *
9187 ipr_get_chip_info(const struct pci_device_id *dev_id)
9191 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
9192 if (ipr_chip[i].vendor == dev_id->vendor &&
9193 ipr_chip[i].device == dev_id->device)
9194 return &ipr_chip[i];
9199 * ipr_wait_for_pci_err_recovery - Wait for any PCI error recovery to complete
9201 * @ioa_cfg: ioa config struct
9206 static void ipr_wait_for_pci_err_recovery(struct ipr_ioa_cfg *ioa_cfg)
9208 struct pci_dev *pdev = ioa_cfg->pdev;
9210 if (pci_channel_offline(pdev)) {
9211 wait_event_timeout(ioa_cfg->eeh_wait_q,
9212 !pci_channel_offline(pdev),
9213 IPR_PCI_ERROR_RECOVERY_TIMEOUT);
9214 pci_restore_state(pdev);
9218 static void name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
9220 int vec_idx, n = sizeof(ioa_cfg->vectors_info[0].desc) - 1;
9222 for (vec_idx = 0; vec_idx < ioa_cfg->nvectors; vec_idx++) {
9223 snprintf(ioa_cfg->vectors_info[vec_idx].desc, n,
9224 "host%d-%d", ioa_cfg->host->host_no, vec_idx);
9225 ioa_cfg->vectors_info[vec_idx].
9226 desc[strlen(ioa_cfg->vectors_info[vec_idx].desc)] = 0;
9230 static int ipr_request_other_msi_irqs(struct ipr_ioa_cfg *ioa_cfg,
9231 struct pci_dev *pdev)
9235 for (i = 1; i < ioa_cfg->nvectors; i++) {
9236 rc = request_irq(pci_irq_vector(pdev, i),
9239 ioa_cfg->vectors_info[i].desc,
9243 free_irq(pci_irq_vector(pdev, i),
9252 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
9253 * @devp: PCI device struct
9256 * Description: Simply set the msi_received flag to 1 indicating that
9257 * Message Signaled Interrupts are supported.
9260 * 0 on success / non-zero on failure
9262 static irqreturn_t ipr_test_intr(int irq, void *devp)
9264 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
9265 unsigned long lock_flags = 0;
9267 dev_info(&ioa_cfg->pdev->dev, "Received IRQ : %d\n", irq);
9268 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9270 ioa_cfg->msi_received = 1;
9271 wake_up(&ioa_cfg->msi_wait_q);
9273 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9278 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
9279 * @ioa_cfg: ioa config struct
9280 * @pdev: PCI device struct
9282 * Description: This routine sets up and initiates a test interrupt to determine
9283 * if the interrupt is received via the ipr_test_intr() service routine.
9284 * If the tests fails, the driver will fall back to LSI.
9287 * 0 on success / non-zero on failure
9289 static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
9292 unsigned long lock_flags = 0;
9293 int irq = pci_irq_vector(pdev, 0);
9297 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9298 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9299 ioa_cfg->msi_received = 0;
9300 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9301 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
9302 readl(ioa_cfg->regs.sense_interrupt_mask_reg);
9303 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9305 rc = request_irq(irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
9307 dev_err(&pdev->dev, "Can not assign irq %d\n", irq);
9309 } else if (ipr_debug)
9310 dev_info(&pdev->dev, "IRQ assigned: %d\n", irq);
9312 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
9313 readl(ioa_cfg->regs.sense_interrupt_reg);
9314 wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
9315 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9316 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9318 if (!ioa_cfg->msi_received) {
9319 /* MSI test failed */
9320 dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
9322 } else if (ipr_debug)
9323 dev_info(&pdev->dev, "MSI test succeeded.\n");
9325 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9327 free_irq(irq, ioa_cfg);
9334 /* ipr_probe_ioa - Allocates memory and does first stage of initialization
9335 * @pdev: PCI device struct
9336 * @dev_id: PCI device id struct
9339 * 0 on success / non-zero on failure
9341 static int ipr_probe_ioa(struct pci_dev *pdev,
9342 const struct pci_device_id *dev_id)
9344 struct ipr_ioa_cfg *ioa_cfg;
9345 struct Scsi_Host *host;
9346 unsigned long ipr_regs_pci;
9347 void __iomem *ipr_regs;
9348 int rc = PCIBIOS_SUCCESSFUL;
9349 volatile u32 mask, uproc, interrupts;
9350 unsigned long lock_flags, driver_lock_flags;
9351 unsigned int irq_flag;
9355 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
9356 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
9359 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
9364 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
9365 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
9367 ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
9369 if (!ioa_cfg->ipr_chip) {
9370 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
9371 dev_id->vendor, dev_id->device);
9372 goto out_scsi_host_put;
9375 /* set SIS 32 or SIS 64 */
9376 ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
9377 ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
9378 ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
9379 ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
9381 if (ipr_transop_timeout)
9382 ioa_cfg->transop_timeout = ipr_transop_timeout;
9383 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
9384 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
9386 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
9388 ioa_cfg->revid = pdev->revision;
9390 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
9392 ipr_regs_pci = pci_resource_start(pdev, 0);
9394 rc = pci_request_regions(pdev, IPR_NAME);
9397 "Couldn't register memory range of registers\n");
9398 goto out_scsi_host_put;
9401 rc = pci_enable_device(pdev);
9403 if (rc || pci_channel_offline(pdev)) {
9404 if (pci_channel_offline(pdev)) {
9405 ipr_wait_for_pci_err_recovery(ioa_cfg);
9406 rc = pci_enable_device(pdev);
9410 dev_err(&pdev->dev, "Cannot enable adapter\n");
9411 ipr_wait_for_pci_err_recovery(ioa_cfg);
9412 goto out_release_regions;
9416 ipr_regs = pci_ioremap_bar(pdev, 0);
9420 "Couldn't map memory range of registers\n");
9425 ioa_cfg->hdw_dma_regs = ipr_regs;
9426 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
9427 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
9429 ipr_init_regs(ioa_cfg);
9431 if (ioa_cfg->sis64) {
9432 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
9434 dev_dbg(&pdev->dev, "Failed to set 64 bit DMA mask\n");
9435 rc = dma_set_mask_and_coherent(&pdev->dev,
9439 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
9442 dev_err(&pdev->dev, "Failed to set DMA mask\n");
9446 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
9447 ioa_cfg->chip_cfg->cache_line_size);
9449 if (rc != PCIBIOS_SUCCESSFUL) {
9450 dev_err(&pdev->dev, "Write of cache line size failed\n");
9451 ipr_wait_for_pci_err_recovery(ioa_cfg);
9456 /* Issue MMIO read to ensure card is not in EEH */
9457 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg);
9458 ipr_wait_for_pci_err_recovery(ioa_cfg);
9460 if (ipr_number_of_msix > IPR_MAX_MSIX_VECTORS) {
9461 dev_err(&pdev->dev, "The max number of MSIX is %d\n",
9462 IPR_MAX_MSIX_VECTORS);
9463 ipr_number_of_msix = IPR_MAX_MSIX_VECTORS;
9466 irq_flag = PCI_IRQ_LEGACY;
9467 if (ioa_cfg->ipr_chip->has_msi)
9468 irq_flag |= PCI_IRQ_MSI | PCI_IRQ_MSIX;
9469 rc = pci_alloc_irq_vectors(pdev, 1, ipr_number_of_msix, irq_flag);
9471 ipr_wait_for_pci_err_recovery(ioa_cfg);
9474 ioa_cfg->nvectors = rc;
9476 if (!pdev->msi_enabled && !pdev->msix_enabled)
9477 ioa_cfg->clear_isr = 1;
9479 pci_set_master(pdev);
9481 if (pci_channel_offline(pdev)) {
9482 ipr_wait_for_pci_err_recovery(ioa_cfg);
9483 pci_set_master(pdev);
9484 if (pci_channel_offline(pdev)) {
9486 goto out_msi_disable;
9490 if (pdev->msi_enabled || pdev->msix_enabled) {
9491 rc = ipr_test_msi(ioa_cfg, pdev);
9494 dev_info(&pdev->dev,
9495 "Request for %d MSI%ss succeeded.", ioa_cfg->nvectors,
9496 pdev->msix_enabled ? "-X" : "");
9499 ipr_wait_for_pci_err_recovery(ioa_cfg);
9500 pci_free_irq_vectors(pdev);
9502 ioa_cfg->nvectors = 1;
9503 ioa_cfg->clear_isr = 1;
9506 goto out_msi_disable;
9510 ioa_cfg->hrrq_num = min3(ioa_cfg->nvectors,
9511 (unsigned int)num_online_cpus(),
9512 (unsigned int)IPR_MAX_HRRQ_NUM);
9514 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
9515 goto out_msi_disable;
9517 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
9518 goto out_msi_disable;
9520 rc = ipr_alloc_mem(ioa_cfg);
9523 "Couldn't allocate enough memory for device driver!\n");
9524 goto out_msi_disable;
9527 /* Save away PCI config space for use following IOA reset */
9528 rc = pci_save_state(pdev);
9530 if (rc != PCIBIOS_SUCCESSFUL) {
9531 dev_err(&pdev->dev, "Failed to save PCI config space\n");
9537 * If HRRQ updated interrupt is not masked, or reset alert is set,
9538 * the card is in an unknown state and needs a hard reset
9540 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
9541 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
9542 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
9543 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
9544 ioa_cfg->needs_hard_reset = 1;
9545 if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
9546 ioa_cfg->needs_hard_reset = 1;
9547 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
9548 ioa_cfg->ioa_unit_checked = 1;
9550 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9551 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9552 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9554 if (pdev->msi_enabled || pdev->msix_enabled) {
9555 name_msi_vectors(ioa_cfg);
9556 rc = request_irq(pci_irq_vector(pdev, 0), ipr_isr, 0,
9557 ioa_cfg->vectors_info[0].desc,
9560 rc = ipr_request_other_msi_irqs(ioa_cfg, pdev);
9562 rc = request_irq(pdev->irq, ipr_isr,
9564 IPR_NAME, &ioa_cfg->hrrq[0]);
9567 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
9572 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
9573 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
9574 ioa_cfg->needs_warm_reset = 1;
9575 ioa_cfg->reset = ipr_reset_slot_reset;
9577 ioa_cfg->reset_work_q = alloc_ordered_workqueue("ipr_reset_%d",
9578 WQ_MEM_RECLAIM, host->host_no);
9580 if (!ioa_cfg->reset_work_q) {
9581 dev_err(&pdev->dev, "Couldn't register reset workqueue\n");
9586 ioa_cfg->reset = ipr_reset_start_bist;
9588 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
9589 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
9590 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
9597 ipr_free_irqs(ioa_cfg);
9599 ipr_free_mem(ioa_cfg);
9601 ipr_wait_for_pci_err_recovery(ioa_cfg);
9602 pci_free_irq_vectors(pdev);
9606 pci_disable_device(pdev);
9607 out_release_regions:
9608 pci_release_regions(pdev);
9610 scsi_host_put(host);
9615 * ipr_initiate_ioa_bringdown - Bring down an adapter
9616 * @ioa_cfg: ioa config struct
9617 * @shutdown_type: shutdown type
9619 * Description: This function will initiate bringing down the adapter.
9620 * This consists of issuing an IOA shutdown to the adapter
9621 * to flush the cache, and running BIST.
9622 * If the caller needs to wait on the completion of the reset,
9623 * the caller must sleep on the reset_wait_q.
9628 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
9629 enum ipr_shutdown_type shutdown_type)
9632 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
9633 ioa_cfg->sdt_state = ABORT_DUMP;
9634 ioa_cfg->reset_retries = 0;
9635 ioa_cfg->in_ioa_bringdown = 1;
9636 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
9641 * __ipr_remove - Remove a single adapter
9642 * @pdev: pci device struct
9644 * Adapter hot plug remove entry point.
9649 static void __ipr_remove(struct pci_dev *pdev)
9651 unsigned long host_lock_flags = 0;
9652 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9654 unsigned long driver_lock_flags;
9657 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9658 while (ioa_cfg->in_reset_reload) {
9659 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9660 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9661 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9664 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9665 spin_lock(&ioa_cfg->hrrq[i]._lock);
9666 ioa_cfg->hrrq[i].removing_ioa = 1;
9667 spin_unlock(&ioa_cfg->hrrq[i]._lock);
9670 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9672 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9673 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9674 flush_work(&ioa_cfg->work_q);
9675 if (ioa_cfg->reset_work_q)
9676 flush_workqueue(ioa_cfg->reset_work_q);
9677 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
9678 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9680 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
9681 list_del(&ioa_cfg->queue);
9682 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
9684 if (ioa_cfg->sdt_state == ABORT_DUMP)
9685 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
9686 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9688 ipr_free_all_resources(ioa_cfg);
9694 * ipr_remove - IOA hot plug remove entry point
9695 * @pdev: pci device struct
9697 * Adapter hot plug remove entry point.
9702 static void ipr_remove(struct pci_dev *pdev)
9704 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9708 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
9710 ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
9712 sysfs_remove_bin_file(&ioa_cfg->host->shost_dev.kobj,
9713 &ipr_ioa_async_err_log);
9714 scsi_remove_host(ioa_cfg->host);
9722 * ipr_probe - Adapter hot plug add entry point
9723 * @pdev: pci device struct
9724 * @dev_id: pci device ID
9727 * 0 on success / non-zero on failure
9729 static int ipr_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
9731 struct ipr_ioa_cfg *ioa_cfg;
9732 unsigned long flags;
9735 rc = ipr_probe_ioa(pdev, dev_id);
9740 ioa_cfg = pci_get_drvdata(pdev);
9741 ipr_probe_ioa_part2(ioa_cfg);
9743 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
9750 rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
9754 scsi_remove_host(ioa_cfg->host);
9759 rc = sysfs_create_bin_file(&ioa_cfg->host->shost_dev.kobj,
9760 &ipr_ioa_async_err_log);
9763 ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
9765 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
9767 scsi_remove_host(ioa_cfg->host);
9772 rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
9776 sysfs_remove_bin_file(&ioa_cfg->host->shost_dev.kobj,
9777 &ipr_ioa_async_err_log);
9778 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
9780 scsi_remove_host(ioa_cfg->host);
9784 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
9785 ioa_cfg->scan_enabled = 1;
9786 schedule_work(&ioa_cfg->work_q);
9787 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
9789 ioa_cfg->iopoll_weight = ioa_cfg->chip_cfg->iopoll_weight;
9791 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
9792 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
9793 irq_poll_init(&ioa_cfg->hrrq[i].iopoll,
9794 ioa_cfg->iopoll_weight, ipr_iopoll);
9798 scsi_scan_host(ioa_cfg->host);
9804 * ipr_shutdown - Shutdown handler.
9805 * @pdev: pci device struct
9807 * This function is invoked upon system shutdown/reboot. It will issue
9808 * an adapter shutdown to the adapter to flush the write cache.
9813 static void ipr_shutdown(struct pci_dev *pdev)
9815 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9816 unsigned long lock_flags = 0;
9817 enum ipr_shutdown_type shutdown_type = IPR_SHUTDOWN_NORMAL;
9820 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9821 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
9822 ioa_cfg->iopoll_weight = 0;
9823 for (i = 1; i < ioa_cfg->hrrq_num; i++)
9824 irq_poll_disable(&ioa_cfg->hrrq[i].iopoll);
9827 while (ioa_cfg->in_reset_reload) {
9828 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9829 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9830 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9833 if (ipr_fast_reboot && system_state == SYSTEM_RESTART && ioa_cfg->sis64)
9834 shutdown_type = IPR_SHUTDOWN_QUIESCE;
9836 ipr_initiate_ioa_bringdown(ioa_cfg, shutdown_type);
9837 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9838 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9839 if (ipr_fast_reboot && system_state == SYSTEM_RESTART && ioa_cfg->sis64) {
9840 ipr_free_irqs(ioa_cfg);
9841 pci_disable_device(ioa_cfg->pdev);
9845 static struct pci_device_id ipr_pci_table[] = {
9846 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9847 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
9848 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9849 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
9850 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9851 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
9852 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9853 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
9854 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9855 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
9856 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9857 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
9858 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9859 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
9860 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9861 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
9862 IPR_USE_LONG_TRANSOP_TIMEOUT },
9863 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
9864 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
9865 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
9866 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
9867 IPR_USE_LONG_TRANSOP_TIMEOUT },
9868 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
9869 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
9870 IPR_USE_LONG_TRANSOP_TIMEOUT },
9871 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
9872 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
9873 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
9874 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
9875 IPR_USE_LONG_TRANSOP_TIMEOUT},
9876 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
9877 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
9878 IPR_USE_LONG_TRANSOP_TIMEOUT },
9879 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9880 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
9881 IPR_USE_LONG_TRANSOP_TIMEOUT },
9882 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9883 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
9884 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9885 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
9886 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9887 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
9888 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
9889 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
9890 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
9891 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
9892 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
9893 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
9894 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
9895 IPR_USE_LONG_TRANSOP_TIMEOUT },
9896 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
9897 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
9898 IPR_USE_LONG_TRANSOP_TIMEOUT },
9899 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9900 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
9901 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9902 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
9903 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9904 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
9905 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9906 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C0, 0, 0, 0 },
9907 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9908 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
9909 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9910 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
9911 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9912 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
9913 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9914 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
9915 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9916 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
9917 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9918 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
9919 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9920 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
9921 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9922 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D5, 0, 0, 0 },
9923 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9924 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D6, 0, 0, 0 },
9925 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9926 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D7, 0, 0, 0 },
9927 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9928 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D8, 0, 0, 0 },
9929 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9930 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D9, 0, 0, 0 },
9931 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9932 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57DA, 0, 0, 0 },
9933 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9934 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EB, 0, 0, 0 },
9935 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9936 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EC, 0, 0, 0 },
9937 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9938 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57ED, 0, 0, 0 },
9939 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9940 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EE, 0, 0, 0 },
9941 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9942 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EF, 0, 0, 0 },
9943 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9944 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57F0, 0, 0, 0 },
9945 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9946 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCA, 0, 0, 0 },
9947 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9948 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CD2, 0, 0, 0 },
9949 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9950 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCD, 0, 0, 0 },
9951 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE,
9952 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_580A, 0, 0, 0 },
9953 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE,
9954 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_580B, 0, 0, 0 },
9957 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
9959 static const struct pci_error_handlers ipr_err_handler = {
9960 .error_detected = ipr_pci_error_detected,
9961 .mmio_enabled = ipr_pci_mmio_enabled,
9962 .slot_reset = ipr_pci_slot_reset,
9965 static struct pci_driver ipr_driver = {
9967 .id_table = ipr_pci_table,
9969 .remove = ipr_remove,
9970 .shutdown = ipr_shutdown,
9971 .err_handler = &ipr_err_handler,
9975 * ipr_halt_done - Shutdown prepare completion
9976 * @ipr_cmd: ipr command struct
9981 static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
9983 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
9987 * ipr_halt - Issue shutdown prepare to all adapters
9988 * @nb: Notifier block
9989 * @event: Notifier event
9990 * @buf: Notifier data (unused)
9993 * NOTIFY_OK on success / NOTIFY_DONE on failure
9995 static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
9997 struct ipr_cmnd *ipr_cmd;
9998 struct ipr_ioa_cfg *ioa_cfg;
9999 unsigned long flags = 0, driver_lock_flags;
10001 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
10002 return NOTIFY_DONE;
10004 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
10006 list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
10007 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
10008 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds ||
10009 (ipr_fast_reboot && event == SYS_RESTART && ioa_cfg->sis64)) {
10010 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10014 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
10015 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
10016 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
10017 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
10018 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
10020 ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
10021 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10023 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
10028 static struct notifier_block ipr_notifier = {
10033 * ipr_init - Module entry point
10036 * 0 on success / negative value on failure
10038 static int __init ipr_init(void)
10042 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
10043 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
10045 register_reboot_notifier(&ipr_notifier);
10046 rc = pci_register_driver(&ipr_driver);
10048 unregister_reboot_notifier(&ipr_notifier);
10056 * ipr_exit - Module unload
10058 * Module unload entry point.
10063 static void __exit ipr_exit(void)
10065 unregister_reboot_notifier(&ipr_notifier);
10066 pci_unregister_driver(&ipr_driver);
10069 module_init(ipr_init);
10070 module_exit(ipr_exit);