2 * ipr.c -- driver for IBM Power Linux RAID adapters
4 * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
6 * Copyright (C) 2003, 2004 IBM Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * This driver is used to control the following SCSI adapters:
29 * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
31 * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
32 * PCI-X Dual Channel Ultra 320 SCSI Adapter
33 * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
34 * Embedded SCSI adapter on p615 and p655 systems
36 * Supported Hardware Features:
37 * - Ultra 320 SCSI controller
38 * - PCI-X host interface
39 * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
40 * - Non-Volatile Write Cache
41 * - Supports attachment of non-RAID disks, tape, and optical devices
42 * - RAID Levels 0, 5, 10
44 * - Background Parity Checking
45 * - Background Data Scrubbing
46 * - Ability to increase the capacity of an existing RAID 5 disk array
50 * - Tagged command queuing
51 * - Adapter microcode download
53 * - SCSI device hot plug
58 #include <linux/init.h>
59 #include <linux/types.h>
60 #include <linux/errno.h>
61 #include <linux/kernel.h>
62 #include <linux/slab.h>
63 #include <linux/vmalloc.h>
64 #include <linux/ioport.h>
65 #include <linux/delay.h>
66 #include <linux/pci.h>
67 #include <linux/wait.h>
68 #include <linux/spinlock.h>
69 #include <linux/sched.h>
70 #include <linux/interrupt.h>
71 #include <linux/blkdev.h>
72 #include <linux/firmware.h>
73 #include <linux/module.h>
74 #include <linux/moduleparam.h>
75 #include <linux/libata.h>
76 #include <linux/hdreg.h>
77 #include <linux/reboot.h>
78 #include <linux/stringify.h>
81 #include <asm/processor.h>
82 #include <scsi/scsi.h>
83 #include <scsi/scsi_host.h>
84 #include <scsi/scsi_tcq.h>
85 #include <scsi/scsi_eh.h>
86 #include <scsi/scsi_cmnd.h>
92 static LIST_HEAD(ipr_ioa_head);
93 static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
94 static unsigned int ipr_max_speed = 1;
95 static int ipr_testmode = 0;
96 static unsigned int ipr_fastfail = 0;
97 static unsigned int ipr_transop_timeout = 0;
98 static unsigned int ipr_debug = 0;
99 static unsigned int ipr_max_devs = IPR_DEFAULT_SIS64_DEVS;
100 static unsigned int ipr_dual_ioa_raid = 1;
101 static unsigned int ipr_number_of_msix = 2;
102 static unsigned int ipr_fast_reboot;
103 static DEFINE_SPINLOCK(ipr_driver_lock);
105 /* This table describes the differences between DMA controller chips */
106 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
107 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
110 .cache_line_size = 0x20,
114 .set_interrupt_mask_reg = 0x0022C,
115 .clr_interrupt_mask_reg = 0x00230,
116 .clr_interrupt_mask_reg32 = 0x00230,
117 .sense_interrupt_mask_reg = 0x0022C,
118 .sense_interrupt_mask_reg32 = 0x0022C,
119 .clr_interrupt_reg = 0x00228,
120 .clr_interrupt_reg32 = 0x00228,
121 .sense_interrupt_reg = 0x00224,
122 .sense_interrupt_reg32 = 0x00224,
123 .ioarrin_reg = 0x00404,
124 .sense_uproc_interrupt_reg = 0x00214,
125 .sense_uproc_interrupt_reg32 = 0x00214,
126 .set_uproc_interrupt_reg = 0x00214,
127 .set_uproc_interrupt_reg32 = 0x00214,
128 .clr_uproc_interrupt_reg = 0x00218,
129 .clr_uproc_interrupt_reg32 = 0x00218
132 { /* Snipe and Scamp */
135 .cache_line_size = 0x20,
139 .set_interrupt_mask_reg = 0x00288,
140 .clr_interrupt_mask_reg = 0x0028C,
141 .clr_interrupt_mask_reg32 = 0x0028C,
142 .sense_interrupt_mask_reg = 0x00288,
143 .sense_interrupt_mask_reg32 = 0x00288,
144 .clr_interrupt_reg = 0x00284,
145 .clr_interrupt_reg32 = 0x00284,
146 .sense_interrupt_reg = 0x00280,
147 .sense_interrupt_reg32 = 0x00280,
148 .ioarrin_reg = 0x00504,
149 .sense_uproc_interrupt_reg = 0x00290,
150 .sense_uproc_interrupt_reg32 = 0x00290,
151 .set_uproc_interrupt_reg = 0x00290,
152 .set_uproc_interrupt_reg32 = 0x00290,
153 .clr_uproc_interrupt_reg = 0x00294,
154 .clr_uproc_interrupt_reg32 = 0x00294
160 .cache_line_size = 0x20,
164 .set_interrupt_mask_reg = 0x00010,
165 .clr_interrupt_mask_reg = 0x00018,
166 .clr_interrupt_mask_reg32 = 0x0001C,
167 .sense_interrupt_mask_reg = 0x00010,
168 .sense_interrupt_mask_reg32 = 0x00014,
169 .clr_interrupt_reg = 0x00008,
170 .clr_interrupt_reg32 = 0x0000C,
171 .sense_interrupt_reg = 0x00000,
172 .sense_interrupt_reg32 = 0x00004,
173 .ioarrin_reg = 0x00070,
174 .sense_uproc_interrupt_reg = 0x00020,
175 .sense_uproc_interrupt_reg32 = 0x00024,
176 .set_uproc_interrupt_reg = 0x00020,
177 .set_uproc_interrupt_reg32 = 0x00024,
178 .clr_uproc_interrupt_reg = 0x00028,
179 .clr_uproc_interrupt_reg32 = 0x0002C,
180 .init_feedback_reg = 0x0005C,
181 .dump_addr_reg = 0x00064,
182 .dump_data_reg = 0x00068,
183 .endian_swap_reg = 0x00084
188 static const struct ipr_chip_t ipr_chip[] = {
189 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
190 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
191 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
192 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
193 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, IPR_USE_MSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
194 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
195 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
196 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
197 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
200 static int ipr_max_bus_speeds[] = {
201 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
204 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
205 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
206 module_param_named(max_speed, ipr_max_speed, uint, 0);
207 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
208 module_param_named(log_level, ipr_log_level, uint, 0);
209 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
210 module_param_named(testmode, ipr_testmode, int, 0);
211 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
212 module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
213 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
214 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
215 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
216 module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
217 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
218 module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
219 MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
220 module_param_named(max_devs, ipr_max_devs, int, 0);
221 MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
222 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
223 module_param_named(number_of_msix, ipr_number_of_msix, int, 0);
224 MODULE_PARM_DESC(number_of_msix, "Specify the number of MSIX interrupts to use on capable adapters (1 - 16). (default:2)");
225 module_param_named(fast_reboot, ipr_fast_reboot, int, S_IRUGO | S_IWUSR);
226 MODULE_PARM_DESC(fast_reboot, "Skip adapter shutdown during reboot. Set to 1 to enable. (default: 0)");
227 MODULE_LICENSE("GPL");
228 MODULE_VERSION(IPR_DRIVER_VERSION);
230 /* A constant array of IOASCs/URCs/Error Messages */
232 struct ipr_error_table_t ipr_error_table[] = {
233 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
234 "8155: An unknown error was received"},
236 "Soft underlength error"},
238 "Command to be cancelled not found"},
240 "Qualified success"},
241 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
242 "FFFE: Soft device bus error recovered by the IOA"},
243 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
244 "4101: Soft device bus fabric error"},
245 {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
246 "FFFC: Logical block guard error recovered by the device"},
247 {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
248 "FFFC: Logical block reference tag error recovered by the device"},
249 {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
250 "4171: Recovered scatter list tag / sequence number error"},
251 {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
252 "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
253 {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
254 "4171: Recovered logical block sequence number error on IOA to Host transfer"},
255 {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
256 "FFFD: Recovered logical block reference tag error detected by the IOA"},
257 {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
258 "FFFD: Logical block guard error recovered by the IOA"},
259 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
260 "FFF9: Device sector reassign successful"},
261 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
262 "FFF7: Media error recovered by device rewrite procedures"},
263 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
264 "7001: IOA sector reassignment successful"},
265 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
266 "FFF9: Soft media error. Sector reassignment recommended"},
267 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
268 "FFF7: Media error recovered by IOA rewrite procedures"},
269 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
270 "FF3D: Soft PCI bus error recovered by the IOA"},
271 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
272 "FFF6: Device hardware error recovered by the IOA"},
273 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
274 "FFF6: Device hardware error recovered by the device"},
275 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
276 "FF3D: Soft IOA error recovered by the IOA"},
277 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
278 "FFFA: Undefined device response recovered by the IOA"},
279 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
280 "FFF6: Device bus error, message or command phase"},
281 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
282 "FFFE: Task Management Function failed"},
283 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
284 "FFF6: Failure prediction threshold exceeded"},
285 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
286 "8009: Impending cache battery pack failure"},
288 "Logical Unit in process of becoming ready"},
290 "Initializing command required"},
292 "34FF: Disk device format in progress"},
294 "Logical unit not accessible, target port in unavailable state"},
295 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
296 "9070: IOA requested reset"},
298 "Synchronization required"},
300 "IOA microcode download required"},
302 "Device bus connection is prohibited by host"},
304 "No ready, IOA shutdown"},
306 "Not ready, IOA has been shutdown"},
307 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
308 "3020: Storage subsystem configuration error"},
310 "FFF5: Medium error, data unreadable, recommend reassign"},
312 "7000: Medium error, data unreadable, do not reassign"},
313 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
314 "FFF3: Disk media format bad"},
315 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
316 "3002: Addressed device failed to respond to selection"},
317 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
318 "3100: Device bus error"},
319 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
320 "3109: IOA timed out a device command"},
322 "3120: SCSI bus is not operational"},
323 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
324 "4100: Hard device bus fabric error"},
325 {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
326 "310C: Logical block guard error detected by the device"},
327 {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
328 "310C: Logical block reference tag error detected by the device"},
329 {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
330 "4170: Scatter list tag / sequence number error"},
331 {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
332 "8150: Logical block CRC error on IOA to Host transfer"},
333 {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
334 "4170: Logical block sequence number error on IOA to Host transfer"},
335 {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
336 "310D: Logical block reference tag error detected by the IOA"},
337 {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
338 "310D: Logical block guard error detected by the IOA"},
339 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
340 "9000: IOA reserved area data check"},
341 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
342 "9001: IOA reserved area invalid data pattern"},
343 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
344 "9002: IOA reserved area LRC error"},
345 {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
346 "Hardware Error, IOA metadata access error"},
347 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
348 "102E: Out of alternate sectors for disk storage"},
349 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
350 "FFF4: Data transfer underlength error"},
351 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
352 "FFF4: Data transfer overlength error"},
353 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
354 "3400: Logical unit failure"},
355 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
356 "FFF4: Device microcode is corrupt"},
357 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
358 "8150: PCI bus error"},
360 "Unsupported device bus message received"},
361 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
362 "FFF4: Disk device problem"},
363 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
364 "8150: Permanent IOA failure"},
365 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
366 "3010: Disk device returned wrong response to IOA"},
367 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
368 "8151: IOA microcode error"},
370 "Device bus status error"},
371 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
372 "8157: IOA error requiring IOA reset to recover"},
374 "ATA device status error"},
376 "Message reject received from the device"},
377 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
378 "8008: A permanent cache battery pack failure occurred"},
379 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
380 "9090: Disk unit has been modified after the last known status"},
381 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
382 "9081: IOA detected device error"},
383 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
384 "9082: IOA detected device error"},
385 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
386 "3110: Device bus error, message or command phase"},
387 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
388 "3110: SAS Command / Task Management Function failed"},
389 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
390 "9091: Incorrect hardware configuration change has been detected"},
391 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
392 "9073: Invalid multi-adapter configuration"},
393 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
394 "4010: Incorrect connection between cascaded expanders"},
395 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
396 "4020: Connections exceed IOA design limits"},
397 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
398 "4030: Incorrect multipath connection"},
399 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
400 "4110: Unsupported enclosure function"},
401 {0x04679800, 0, IPR_DEFAULT_LOG_LEVEL,
402 "4120: SAS cable VPD cannot be read"},
403 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
404 "FFF4: Command to logical unit failed"},
406 "Illegal request, invalid request type or request packet"},
408 "Illegal request, invalid resource handle"},
410 "Illegal request, commands not allowed to this device"},
412 "Illegal request, command not allowed to a secondary adapter"},
414 "Illegal request, command not allowed to a non-optimized resource"},
416 "Illegal request, invalid field in parameter list"},
418 "Illegal request, parameter not supported"},
420 "Illegal request, parameter value invalid"},
422 "Illegal request, command sequence error"},
424 "Illegal request, dual adapter support not enabled"},
426 "Illegal request, another cable connector was physically disabled"},
428 "Illegal request, inconsistent group id/group count"},
429 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
430 "9031: Array protection temporarily suspended, protection resuming"},
431 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
432 "9040: Array protection temporarily suspended, protection resuming"},
433 {0x060B0100, 0, IPR_DEFAULT_LOG_LEVEL,
434 "4080: IOA exceeded maximum operating temperature"},
435 {0x060B8000, 0, IPR_DEFAULT_LOG_LEVEL,
436 "4085: Service required"},
437 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
438 "3140: Device bus not ready to ready transition"},
439 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
440 "FFFB: SCSI bus was reset"},
442 "FFFE: SCSI bus transition to single ended"},
444 "FFFE: SCSI bus transition to LVD"},
445 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
446 "FFFB: SCSI bus was reset by another initiator"},
447 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
448 "3029: A device replacement has occurred"},
449 {0x063F8300, 0, IPR_DEFAULT_LOG_LEVEL,
450 "4102: Device bus fabric performance degradation"},
451 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
452 "9051: IOA cache data exists for a missing or failed device"},
453 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
454 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
455 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
456 "9025: Disk unit is not supported at its physical location"},
457 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
458 "3020: IOA detected a SCSI bus configuration error"},
459 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
460 "3150: SCSI bus configuration error"},
461 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
462 "9074: Asymmetric advanced function disk configuration"},
463 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
464 "4040: Incomplete multipath connection between IOA and enclosure"},
465 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
466 "4041: Incomplete multipath connection between enclosure and device"},
467 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
468 "9075: Incomplete multipath connection between IOA and remote IOA"},
469 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
470 "9076: Configuration error, missing remote IOA"},
471 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
472 "4050: Enclosure does not support a required multipath function"},
473 {0x06679800, 0, IPR_DEFAULT_LOG_LEVEL,
474 "4121: Configuration error, required cable is missing"},
475 {0x06679900, 0, IPR_DEFAULT_LOG_LEVEL,
476 "4122: Cable is not plugged into the correct location on remote IOA"},
477 {0x06679A00, 0, IPR_DEFAULT_LOG_LEVEL,
478 "4123: Configuration error, invalid cable vital product data"},
479 {0x06679B00, 0, IPR_DEFAULT_LOG_LEVEL,
480 "4124: Configuration error, both cable ends are plugged into the same IOA"},
481 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
482 "4070: Logically bad block written on device"},
483 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
484 "9041: Array protection temporarily suspended"},
485 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
486 "9042: Corrupt array parity detected on specified device"},
487 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
488 "9030: Array no longer protected due to missing or failed disk unit"},
489 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
490 "9071: Link operational transition"},
491 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
492 "9072: Link not operational transition"},
493 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
494 "9032: Array exposed but still protected"},
495 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
496 "70DD: Device forced failed by disrupt device command"},
497 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
498 "4061: Multipath redundancy level got better"},
499 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
500 "4060: Multipath redundancy level got worse"},
501 {0x06808100, 0, IPR_DEFAULT_LOG_LEVEL,
502 "9083: Device raw mode enabled"},
503 {0x06808200, 0, IPR_DEFAULT_LOG_LEVEL,
504 "9084: Device raw mode disabled"},
506 "Failure due to other device"},
507 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
508 "9008: IOA does not support functions expected by devices"},
509 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
510 "9010: Cache data associated with attached devices cannot be found"},
511 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
512 "9011: Cache data belongs to devices other than those attached"},
513 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
514 "9020: Array missing 2 or more devices with only 1 device present"},
515 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
516 "9021: Array missing 2 or more devices with 2 or more devices present"},
517 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
518 "9022: Exposed array is missing a required device"},
519 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
520 "9023: Array member(s) not at required physical locations"},
521 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
522 "9024: Array not functional due to present hardware configuration"},
523 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
524 "9026: Array not functional due to present hardware configuration"},
525 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
526 "9027: Array is missing a device and parity is out of sync"},
527 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
528 "9028: Maximum number of arrays already exist"},
529 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
530 "9050: Required cache data cannot be located for a disk unit"},
531 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
532 "9052: Cache data exists for a device that has been modified"},
533 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
534 "9054: IOA resources not available due to previous problems"},
535 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
536 "9092: Disk unit requires initialization before use"},
537 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
538 "9029: Incorrect hardware configuration change has been detected"},
539 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
540 "9060: One or more disk pairs are missing from an array"},
541 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
542 "9061: One or more disks are missing from an array"},
543 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
544 "9062: One or more disks are missing from an array"},
545 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
546 "9063: Maximum number of functional arrays has been exceeded"},
548 "Data protect, other volume set problem"},
550 "Aborted command, invalid descriptor"},
552 "Target operating conditions have changed, dual adapter takeover"},
554 "Aborted command, medium removal prevented"},
556 "Command terminated by host"},
558 "Aborted command, command terminated by host"}
561 static const struct ipr_ses_table_entry ipr_ses_table[] = {
562 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
563 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
564 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
565 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
566 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
567 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
568 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
569 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
570 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
571 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
572 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
573 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
574 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
578 * Function Prototypes
580 static int ipr_reset_alert(struct ipr_cmnd *);
581 static void ipr_process_ccn(struct ipr_cmnd *);
582 static void ipr_process_error(struct ipr_cmnd *);
583 static void ipr_reset_ioa_job(struct ipr_cmnd *);
584 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
585 enum ipr_shutdown_type);
587 #ifdef CONFIG_SCSI_IPR_TRACE
589 * ipr_trc_hook - Add a trace entry to the driver trace
590 * @ipr_cmd: ipr command struct
592 * @add_data: additional data
597 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
598 u8 type, u32 add_data)
600 struct ipr_trace_entry *trace_entry;
601 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
603 trace_entry = &ioa_cfg->trace[atomic_add_return
604 (1, &ioa_cfg->trace_index)%IPR_NUM_TRACE_ENTRIES];
605 trace_entry->time = jiffies;
606 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
607 trace_entry->type = type;
608 if (ipr_cmd->ioa_cfg->sis64)
609 trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
611 trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
612 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
613 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
614 trace_entry->u.add_data = add_data;
618 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
622 * ipr_lock_and_done - Acquire lock and complete command
623 * @ipr_cmd: ipr command struct
628 static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
630 unsigned long lock_flags;
631 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
633 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
634 ipr_cmd->done(ipr_cmd);
635 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
639 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
640 * @ipr_cmd: ipr command struct
645 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
647 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
648 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
649 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
650 dma_addr_t dma_addr = ipr_cmd->dma_addr;
653 hrrq_id = ioarcb->cmd_pkt.hrrq_id;
654 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
655 ioarcb->cmd_pkt.hrrq_id = hrrq_id;
656 ioarcb->data_transfer_length = 0;
657 ioarcb->read_data_transfer_length = 0;
658 ioarcb->ioadl_len = 0;
659 ioarcb->read_ioadl_len = 0;
661 if (ipr_cmd->ioa_cfg->sis64) {
662 ioarcb->u.sis64_addr_data.data_ioadl_addr =
663 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
664 ioasa64->u.gata.status = 0;
666 ioarcb->write_ioadl_addr =
667 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
668 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
669 ioasa->u.gata.status = 0;
672 ioasa->hdr.ioasc = 0;
673 ioasa->hdr.residual_data_len = 0;
674 ipr_cmd->scsi_cmd = NULL;
676 ipr_cmd->sense_buffer[0] = 0;
677 ipr_cmd->dma_use_sg = 0;
681 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
682 * @ipr_cmd: ipr command struct
687 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
688 void (*fast_done) (struct ipr_cmnd *))
690 ipr_reinit_ipr_cmnd(ipr_cmd);
691 ipr_cmd->u.scratch = 0;
692 ipr_cmd->sibling = NULL;
693 ipr_cmd->eh_comp = NULL;
694 ipr_cmd->fast_done = fast_done;
695 init_timer(&ipr_cmd->timer);
699 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
700 * @ioa_cfg: ioa config struct
703 * pointer to ipr command struct
706 struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_hrr_queue *hrrq)
708 struct ipr_cmnd *ipr_cmd = NULL;
710 if (likely(!list_empty(&hrrq->hrrq_free_q))) {
711 ipr_cmd = list_entry(hrrq->hrrq_free_q.next,
712 struct ipr_cmnd, queue);
713 list_del(&ipr_cmd->queue);
721 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
722 * @ioa_cfg: ioa config struct
725 * pointer to ipr command struct
728 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
730 struct ipr_cmnd *ipr_cmd =
731 __ipr_get_free_ipr_cmnd(&ioa_cfg->hrrq[IPR_INIT_HRRQ]);
732 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
737 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
738 * @ioa_cfg: ioa config struct
739 * @clr_ints: interrupts to clear
741 * This function masks all interrupts on the adapter, then clears the
742 * interrupts specified in the mask
747 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
750 volatile u32 int_reg;
753 /* Stop new interrupts */
754 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
755 spin_lock(&ioa_cfg->hrrq[i]._lock);
756 ioa_cfg->hrrq[i].allow_interrupts = 0;
757 spin_unlock(&ioa_cfg->hrrq[i]._lock);
761 /* Set interrupt mask to stop all new interrupts */
763 writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
765 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
767 /* Clear any pending interrupts */
769 writel(~0, ioa_cfg->regs.clr_interrupt_reg);
770 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
771 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
775 * ipr_save_pcix_cmd_reg - Save PCI-X command register
776 * @ioa_cfg: ioa config struct
779 * 0 on success / -EIO on failure
781 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
783 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
785 if (pcix_cmd_reg == 0)
788 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
789 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
790 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
794 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
799 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
800 * @ioa_cfg: ioa config struct
803 * 0 on success / -EIO on failure
805 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
807 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
810 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
811 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
812 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
821 * ipr_sata_eh_done - done function for aborted SATA commands
822 * @ipr_cmd: ipr command struct
824 * This function is invoked for ops generated to SATA
825 * devices which are being aborted.
830 static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
832 struct ata_queued_cmd *qc = ipr_cmd->qc;
833 struct ipr_sata_port *sata_port = qc->ap->private_data;
835 qc->err_mask |= AC_ERR_OTHER;
836 sata_port->ioasa.status |= ATA_BUSY;
837 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
842 * ipr_scsi_eh_done - mid-layer done function for aborted ops
843 * @ipr_cmd: ipr command struct
845 * This function is invoked by the interrupt handler for
846 * ops generated by the SCSI mid-layer which are being aborted.
851 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
853 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
855 scsi_cmd->result |= (DID_ERROR << 16);
857 scsi_dma_unmap(ipr_cmd->scsi_cmd);
858 scsi_cmd->scsi_done(scsi_cmd);
859 if (ipr_cmd->eh_comp)
860 complete(ipr_cmd->eh_comp);
861 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
865 * ipr_fail_all_ops - Fails all outstanding ops.
866 * @ioa_cfg: ioa config struct
868 * This function fails all outstanding ops.
873 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
875 struct ipr_cmnd *ipr_cmd, *temp;
876 struct ipr_hrr_queue *hrrq;
879 for_each_hrrq(hrrq, ioa_cfg) {
880 spin_lock(&hrrq->_lock);
881 list_for_each_entry_safe(ipr_cmd,
882 temp, &hrrq->hrrq_pending_q, queue) {
883 list_del(&ipr_cmd->queue);
885 ipr_cmd->s.ioasa.hdr.ioasc =
886 cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
887 ipr_cmd->s.ioasa.hdr.ilid =
888 cpu_to_be32(IPR_DRIVER_ILID);
890 if (ipr_cmd->scsi_cmd)
891 ipr_cmd->done = ipr_scsi_eh_done;
892 else if (ipr_cmd->qc)
893 ipr_cmd->done = ipr_sata_eh_done;
895 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH,
896 IPR_IOASC_IOA_WAS_RESET);
897 del_timer(&ipr_cmd->timer);
898 ipr_cmd->done(ipr_cmd);
900 spin_unlock(&hrrq->_lock);
906 * ipr_send_command - Send driver initiated requests.
907 * @ipr_cmd: ipr command struct
909 * This function sends a command to the adapter using the correct write call.
910 * In the case of sis64, calculate the ioarcb size required. Then or in the
916 static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
918 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
919 dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
921 if (ioa_cfg->sis64) {
922 /* The default size is 256 bytes */
923 send_dma_addr |= 0x1;
925 /* If the number of ioadls * size of ioadl > 128 bytes,
926 then use a 512 byte ioarcb */
927 if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
928 send_dma_addr |= 0x4;
929 writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
931 writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
935 * ipr_do_req - Send driver initiated requests.
936 * @ipr_cmd: ipr command struct
937 * @done: done function
938 * @timeout_func: timeout function
939 * @timeout: timeout value
941 * This function sends the specified command to the adapter with the
942 * timeout given. The done function is invoked on command completion.
947 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
948 void (*done) (struct ipr_cmnd *),
949 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
951 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
953 ipr_cmd->done = done;
955 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
956 ipr_cmd->timer.expires = jiffies + timeout;
957 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
959 add_timer(&ipr_cmd->timer);
961 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
963 ipr_send_command(ipr_cmd);
967 * ipr_internal_cmd_done - Op done function for an internally generated op.
968 * @ipr_cmd: ipr command struct
970 * This function is the op done function for an internally generated,
971 * blocking op. It simply wakes the sleeping thread.
976 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
978 if (ipr_cmd->sibling)
979 ipr_cmd->sibling = NULL;
981 complete(&ipr_cmd->completion);
985 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
986 * @ipr_cmd: ipr command struct
987 * @dma_addr: dma address
988 * @len: transfer length
989 * @flags: ioadl flag value
991 * This function initializes an ioadl in the case where there is only a single
997 static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
1000 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
1001 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
1003 ipr_cmd->dma_use_sg = 1;
1005 if (ipr_cmd->ioa_cfg->sis64) {
1006 ioadl64->flags = cpu_to_be32(flags);
1007 ioadl64->data_len = cpu_to_be32(len);
1008 ioadl64->address = cpu_to_be64(dma_addr);
1010 ipr_cmd->ioarcb.ioadl_len =
1011 cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
1012 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1014 ioadl->flags_and_data_len = cpu_to_be32(flags | len);
1015 ioadl->address = cpu_to_be32(dma_addr);
1017 if (flags == IPR_IOADL_FLAGS_READ_LAST) {
1018 ipr_cmd->ioarcb.read_ioadl_len =
1019 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1020 ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
1022 ipr_cmd->ioarcb.ioadl_len =
1023 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1024 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1030 * ipr_send_blocking_cmd - Send command and sleep on its completion.
1031 * @ipr_cmd: ipr command struct
1032 * @timeout_func: function to invoke if command times out
1038 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
1039 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
1042 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1044 init_completion(&ipr_cmd->completion);
1045 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
1047 spin_unlock_irq(ioa_cfg->host->host_lock);
1048 wait_for_completion(&ipr_cmd->completion);
1049 spin_lock_irq(ioa_cfg->host->host_lock);
1052 static int ipr_get_hrrq_index(struct ipr_ioa_cfg *ioa_cfg)
1054 if (ioa_cfg->hrrq_num == 1)
1057 return (atomic_add_return(1, &ioa_cfg->hrrq_index) % (ioa_cfg->hrrq_num - 1)) + 1;
1061 * ipr_send_hcam - Send an HCAM to the adapter.
1062 * @ioa_cfg: ioa config struct
1064 * @hostrcb: hostrcb struct
1066 * This function will send a Host Controlled Async command to the adapter.
1067 * If HCAMs are currently not allowed to be issued to the adapter, it will
1068 * place the hostrcb on the free queue.
1073 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
1074 struct ipr_hostrcb *hostrcb)
1076 struct ipr_cmnd *ipr_cmd;
1077 struct ipr_ioarcb *ioarcb;
1079 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
1080 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
1081 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
1082 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
1084 ipr_cmd->u.hostrcb = hostrcb;
1085 ioarcb = &ipr_cmd->ioarcb;
1087 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
1088 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
1089 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
1090 ioarcb->cmd_pkt.cdb[1] = type;
1091 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
1092 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
1094 ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
1095 sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
1097 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
1098 ipr_cmd->done = ipr_process_ccn;
1100 ipr_cmd->done = ipr_process_error;
1102 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
1104 ipr_send_command(ipr_cmd);
1106 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
1111 * ipr_update_ata_class - Update the ata class in the resource entry
1112 * @res: resource entry struct
1113 * @proto: cfgte device bus protocol value
1118 static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
1121 case IPR_PROTO_SATA:
1122 case IPR_PROTO_SAS_STP:
1123 res->ata_class = ATA_DEV_ATA;
1125 case IPR_PROTO_SATA_ATAPI:
1126 case IPR_PROTO_SAS_STP_ATAPI:
1127 res->ata_class = ATA_DEV_ATAPI;
1130 res->ata_class = ATA_DEV_UNKNOWN;
1136 * ipr_init_res_entry - Initialize a resource entry struct.
1137 * @res: resource entry struct
1138 * @cfgtew: config table entry wrapper struct
1143 static void ipr_init_res_entry(struct ipr_resource_entry *res,
1144 struct ipr_config_table_entry_wrapper *cfgtew)
1148 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1149 struct ipr_resource_entry *gscsi_res = NULL;
1151 res->needs_sync_complete = 0;
1154 res->del_from_ml = 0;
1155 res->resetting_device = 0;
1156 res->reset_occurred = 0;
1158 res->sata_port = NULL;
1160 if (ioa_cfg->sis64) {
1161 proto = cfgtew->u.cfgte64->proto;
1162 res->res_flags = cfgtew->u.cfgte64->res_flags;
1163 res->qmodel = IPR_QUEUEING_MODEL64(res);
1164 res->type = cfgtew->u.cfgte64->res_type;
1166 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1167 sizeof(res->res_path));
1170 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1171 sizeof(res->dev_lun.scsi_lun));
1172 res->lun = scsilun_to_int(&res->dev_lun);
1174 if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1175 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1176 if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1178 res->target = gscsi_res->target;
1183 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1184 ioa_cfg->max_devs_supported);
1185 set_bit(res->target, ioa_cfg->target_ids);
1187 } else if (res->type == IPR_RES_TYPE_IOAFP) {
1188 res->bus = IPR_IOAFP_VIRTUAL_BUS;
1190 } else if (res->type == IPR_RES_TYPE_ARRAY) {
1191 res->bus = IPR_ARRAY_VIRTUAL_BUS;
1192 res->target = find_first_zero_bit(ioa_cfg->array_ids,
1193 ioa_cfg->max_devs_supported);
1194 set_bit(res->target, ioa_cfg->array_ids);
1195 } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1196 res->bus = IPR_VSET_VIRTUAL_BUS;
1197 res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1198 ioa_cfg->max_devs_supported);
1199 set_bit(res->target, ioa_cfg->vset_ids);
1201 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1202 ioa_cfg->max_devs_supported);
1203 set_bit(res->target, ioa_cfg->target_ids);
1206 proto = cfgtew->u.cfgte->proto;
1207 res->qmodel = IPR_QUEUEING_MODEL(res);
1208 res->flags = cfgtew->u.cfgte->flags;
1209 if (res->flags & IPR_IS_IOA_RESOURCE)
1210 res->type = IPR_RES_TYPE_IOAFP;
1212 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1214 res->bus = cfgtew->u.cfgte->res_addr.bus;
1215 res->target = cfgtew->u.cfgte->res_addr.target;
1216 res->lun = cfgtew->u.cfgte->res_addr.lun;
1217 res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
1220 ipr_update_ata_class(res, proto);
1224 * ipr_is_same_device - Determine if two devices are the same.
1225 * @res: resource entry struct
1226 * @cfgtew: config table entry wrapper struct
1229 * 1 if the devices are the same / 0 otherwise
1231 static int ipr_is_same_device(struct ipr_resource_entry *res,
1232 struct ipr_config_table_entry_wrapper *cfgtew)
1234 if (res->ioa_cfg->sis64) {
1235 if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1236 sizeof(cfgtew->u.cfgte64->dev_id)) &&
1237 !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1238 sizeof(cfgtew->u.cfgte64->lun))) {
1242 if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1243 res->target == cfgtew->u.cfgte->res_addr.target &&
1244 res->lun == cfgtew->u.cfgte->res_addr.lun)
1252 * __ipr_format_res_path - Format the resource path for printing.
1253 * @res_path: resource path
1255 * @len: length of buffer provided
1260 static char *__ipr_format_res_path(u8 *res_path, char *buffer, int len)
1266 p += snprintf(p, buffer + len - p, "%02X", res_path[0]);
1267 for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
1268 p += snprintf(p, buffer + len - p, "-%02X", res_path[i]);
1274 * ipr_format_res_path - Format the resource path for printing.
1275 * @ioa_cfg: ioa config struct
1276 * @res_path: resource path
1278 * @len: length of buffer provided
1283 static char *ipr_format_res_path(struct ipr_ioa_cfg *ioa_cfg,
1284 u8 *res_path, char *buffer, int len)
1289 p += snprintf(p, buffer + len - p, "%d/", ioa_cfg->host->host_no);
1290 __ipr_format_res_path(res_path, p, len - (buffer - p));
1295 * ipr_update_res_entry - Update the resource entry.
1296 * @res: resource entry struct
1297 * @cfgtew: config table entry wrapper struct
1302 static void ipr_update_res_entry(struct ipr_resource_entry *res,
1303 struct ipr_config_table_entry_wrapper *cfgtew)
1305 char buffer[IPR_MAX_RES_PATH_LENGTH];
1309 if (res->ioa_cfg->sis64) {
1310 res->flags = cfgtew->u.cfgte64->flags;
1311 res->res_flags = cfgtew->u.cfgte64->res_flags;
1312 res->type = cfgtew->u.cfgte64->res_type;
1314 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1315 sizeof(struct ipr_std_inq_data));
1317 res->qmodel = IPR_QUEUEING_MODEL64(res);
1318 proto = cfgtew->u.cfgte64->proto;
1319 res->res_handle = cfgtew->u.cfgte64->res_handle;
1320 res->dev_id = cfgtew->u.cfgte64->dev_id;
1322 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1323 sizeof(res->dev_lun.scsi_lun));
1325 if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1326 sizeof(res->res_path))) {
1327 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1328 sizeof(res->res_path));
1332 if (res->sdev && new_path)
1333 sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
1334 ipr_format_res_path(res->ioa_cfg,
1335 res->res_path, buffer, sizeof(buffer)));
1337 res->flags = cfgtew->u.cfgte->flags;
1338 if (res->flags & IPR_IS_IOA_RESOURCE)
1339 res->type = IPR_RES_TYPE_IOAFP;
1341 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1343 memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1344 sizeof(struct ipr_std_inq_data));
1346 res->qmodel = IPR_QUEUEING_MODEL(res);
1347 proto = cfgtew->u.cfgte->proto;
1348 res->res_handle = cfgtew->u.cfgte->res_handle;
1351 ipr_update_ata_class(res, proto);
1355 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1357 * @res: resource entry struct
1358 * @cfgtew: config table entry wrapper struct
1363 static void ipr_clear_res_target(struct ipr_resource_entry *res)
1365 struct ipr_resource_entry *gscsi_res = NULL;
1366 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1368 if (!ioa_cfg->sis64)
1371 if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1372 clear_bit(res->target, ioa_cfg->array_ids);
1373 else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1374 clear_bit(res->target, ioa_cfg->vset_ids);
1375 else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1376 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1377 if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1379 clear_bit(res->target, ioa_cfg->target_ids);
1381 } else if (res->bus == 0)
1382 clear_bit(res->target, ioa_cfg->target_ids);
1386 * ipr_handle_config_change - Handle a config change from the adapter
1387 * @ioa_cfg: ioa config struct
1393 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
1394 struct ipr_hostrcb *hostrcb)
1396 struct ipr_resource_entry *res = NULL;
1397 struct ipr_config_table_entry_wrapper cfgtew;
1398 __be32 cc_res_handle;
1402 if (ioa_cfg->sis64) {
1403 cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1404 cc_res_handle = cfgtew.u.cfgte64->res_handle;
1406 cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1407 cc_res_handle = cfgtew.u.cfgte->res_handle;
1410 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1411 if (res->res_handle == cc_res_handle) {
1418 if (list_empty(&ioa_cfg->free_res_q)) {
1419 ipr_send_hcam(ioa_cfg,
1420 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1425 res = list_entry(ioa_cfg->free_res_q.next,
1426 struct ipr_resource_entry, queue);
1428 list_del(&res->queue);
1429 ipr_init_res_entry(res, &cfgtew);
1430 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1433 ipr_update_res_entry(res, &cfgtew);
1435 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1437 res->del_from_ml = 1;
1438 res->res_handle = IPR_INVALID_RES_HANDLE;
1439 schedule_work(&ioa_cfg->work_q);
1441 ipr_clear_res_target(res);
1442 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
1444 } else if (!res->sdev || res->del_from_ml) {
1446 schedule_work(&ioa_cfg->work_q);
1449 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1453 * ipr_process_ccn - Op done function for a CCN.
1454 * @ipr_cmd: ipr command struct
1456 * This function is the op done function for a configuration
1457 * change notification host controlled async from the adapter.
1462 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1464 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1465 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1466 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
1468 list_del(&hostrcb->queue);
1469 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
1472 if (ioasc != IPR_IOASC_IOA_WAS_RESET &&
1473 ioasc != IPR_IOASC_ABORTED_CMD_TERM_BY_HOST)
1474 dev_err(&ioa_cfg->pdev->dev,
1475 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1477 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1479 ipr_handle_config_change(ioa_cfg, hostrcb);
1484 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1485 * @i: index into buffer
1486 * @buf: string to modify
1488 * This function will strip all trailing whitespace, pad the end
1489 * of the string with a single space, and NULL terminate the string.
1492 * new length of string
1494 static int strip_and_pad_whitespace(int i, char *buf)
1496 while (i && buf[i] == ' ')
1504 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1505 * @prefix: string to print at start of printk
1506 * @hostrcb: hostrcb pointer
1507 * @vpd: vendor/product id/sn struct
1512 static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1513 struct ipr_vpd *vpd)
1515 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
1518 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1519 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
1521 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
1522 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
1524 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1525 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1527 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1531 * ipr_log_vpd - Log the passed VPD to the error log.
1532 * @vpd: vendor/product id/sn struct
1537 static void ipr_log_vpd(struct ipr_vpd *vpd)
1539 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1540 + IPR_SERIAL_NUM_LEN];
1542 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1543 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
1545 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1546 ipr_err("Vendor/Product ID: %s\n", buffer);
1548 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
1549 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1550 ipr_err(" Serial Number: %s\n", buffer);
1554 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1555 * @prefix: string to print at start of printk
1556 * @hostrcb: hostrcb pointer
1557 * @vpd: vendor/product id/sn/wwn struct
1562 static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1563 struct ipr_ext_vpd *vpd)
1565 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1566 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1567 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1571 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1572 * @vpd: vendor/product id/sn/wwn struct
1577 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1579 ipr_log_vpd(&vpd->vpd);
1580 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1581 be32_to_cpu(vpd->wwid[1]));
1585 * ipr_log_enhanced_cache_error - Log a cache error.
1586 * @ioa_cfg: ioa config struct
1587 * @hostrcb: hostrcb struct
1592 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1593 struct ipr_hostrcb *hostrcb)
1595 struct ipr_hostrcb_type_12_error *error;
1598 error = &hostrcb->hcam.u.error64.u.type_12_error;
1600 error = &hostrcb->hcam.u.error.u.type_12_error;
1602 ipr_err("-----Current Configuration-----\n");
1603 ipr_err("Cache Directory Card Information:\n");
1604 ipr_log_ext_vpd(&error->ioa_vpd);
1605 ipr_err("Adapter Card Information:\n");
1606 ipr_log_ext_vpd(&error->cfc_vpd);
1608 ipr_err("-----Expected Configuration-----\n");
1609 ipr_err("Cache Directory Card Information:\n");
1610 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1611 ipr_err("Adapter Card Information:\n");
1612 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1614 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1615 be32_to_cpu(error->ioa_data[0]),
1616 be32_to_cpu(error->ioa_data[1]),
1617 be32_to_cpu(error->ioa_data[2]));
1621 * ipr_log_cache_error - Log a cache error.
1622 * @ioa_cfg: ioa config struct
1623 * @hostrcb: hostrcb struct
1628 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1629 struct ipr_hostrcb *hostrcb)
1631 struct ipr_hostrcb_type_02_error *error =
1632 &hostrcb->hcam.u.error.u.type_02_error;
1634 ipr_err("-----Current Configuration-----\n");
1635 ipr_err("Cache Directory Card Information:\n");
1636 ipr_log_vpd(&error->ioa_vpd);
1637 ipr_err("Adapter Card Information:\n");
1638 ipr_log_vpd(&error->cfc_vpd);
1640 ipr_err("-----Expected Configuration-----\n");
1641 ipr_err("Cache Directory Card Information:\n");
1642 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1643 ipr_err("Adapter Card Information:\n");
1644 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1646 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1647 be32_to_cpu(error->ioa_data[0]),
1648 be32_to_cpu(error->ioa_data[1]),
1649 be32_to_cpu(error->ioa_data[2]));
1653 * ipr_log_enhanced_config_error - Log a configuration error.
1654 * @ioa_cfg: ioa config struct
1655 * @hostrcb: hostrcb struct
1660 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1661 struct ipr_hostrcb *hostrcb)
1663 int errors_logged, i;
1664 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1665 struct ipr_hostrcb_type_13_error *error;
1667 error = &hostrcb->hcam.u.error.u.type_13_error;
1668 errors_logged = be32_to_cpu(error->errors_logged);
1670 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1671 be32_to_cpu(error->errors_detected), errors_logged);
1673 dev_entry = error->dev;
1675 for (i = 0; i < errors_logged; i++, dev_entry++) {
1678 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1679 ipr_log_ext_vpd(&dev_entry->vpd);
1681 ipr_err("-----New Device Information-----\n");
1682 ipr_log_ext_vpd(&dev_entry->new_vpd);
1684 ipr_err("Cache Directory Card Information:\n");
1685 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1687 ipr_err("Adapter Card Information:\n");
1688 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1693 * ipr_log_sis64_config_error - Log a device error.
1694 * @ioa_cfg: ioa config struct
1695 * @hostrcb: hostrcb struct
1700 static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
1701 struct ipr_hostrcb *hostrcb)
1703 int errors_logged, i;
1704 struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
1705 struct ipr_hostrcb_type_23_error *error;
1706 char buffer[IPR_MAX_RES_PATH_LENGTH];
1708 error = &hostrcb->hcam.u.error64.u.type_23_error;
1709 errors_logged = be32_to_cpu(error->errors_logged);
1711 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1712 be32_to_cpu(error->errors_detected), errors_logged);
1714 dev_entry = error->dev;
1716 for (i = 0; i < errors_logged; i++, dev_entry++) {
1719 ipr_err("Device %d : %s", i + 1,
1720 __ipr_format_res_path(dev_entry->res_path,
1721 buffer, sizeof(buffer)));
1722 ipr_log_ext_vpd(&dev_entry->vpd);
1724 ipr_err("-----New Device Information-----\n");
1725 ipr_log_ext_vpd(&dev_entry->new_vpd);
1727 ipr_err("Cache Directory Card Information:\n");
1728 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1730 ipr_err("Adapter Card Information:\n");
1731 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1736 * ipr_log_config_error - Log a configuration error.
1737 * @ioa_cfg: ioa config struct
1738 * @hostrcb: hostrcb struct
1743 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1744 struct ipr_hostrcb *hostrcb)
1746 int errors_logged, i;
1747 struct ipr_hostrcb_device_data_entry *dev_entry;
1748 struct ipr_hostrcb_type_03_error *error;
1750 error = &hostrcb->hcam.u.error.u.type_03_error;
1751 errors_logged = be32_to_cpu(error->errors_logged);
1753 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1754 be32_to_cpu(error->errors_detected), errors_logged);
1756 dev_entry = error->dev;
1758 for (i = 0; i < errors_logged; i++, dev_entry++) {
1761 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1762 ipr_log_vpd(&dev_entry->vpd);
1764 ipr_err("-----New Device Information-----\n");
1765 ipr_log_vpd(&dev_entry->new_vpd);
1767 ipr_err("Cache Directory Card Information:\n");
1768 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1770 ipr_err("Adapter Card Information:\n");
1771 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1773 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1774 be32_to_cpu(dev_entry->ioa_data[0]),
1775 be32_to_cpu(dev_entry->ioa_data[1]),
1776 be32_to_cpu(dev_entry->ioa_data[2]),
1777 be32_to_cpu(dev_entry->ioa_data[3]),
1778 be32_to_cpu(dev_entry->ioa_data[4]));
1783 * ipr_log_enhanced_array_error - Log an array configuration error.
1784 * @ioa_cfg: ioa config struct
1785 * @hostrcb: hostrcb struct
1790 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1791 struct ipr_hostrcb *hostrcb)
1794 struct ipr_hostrcb_type_14_error *error;
1795 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1796 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1798 error = &hostrcb->hcam.u.error.u.type_14_error;
1802 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1803 error->protection_level,
1804 ioa_cfg->host->host_no,
1805 error->last_func_vset_res_addr.bus,
1806 error->last_func_vset_res_addr.target,
1807 error->last_func_vset_res_addr.lun);
1811 array_entry = error->array_member;
1812 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1813 ARRAY_SIZE(error->array_member));
1815 for (i = 0; i < num_entries; i++, array_entry++) {
1816 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1819 if (be32_to_cpu(error->exposed_mode_adn) == i)
1820 ipr_err("Exposed Array Member %d:\n", i);
1822 ipr_err("Array Member %d:\n", i);
1824 ipr_log_ext_vpd(&array_entry->vpd);
1825 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1826 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1827 "Expected Location");
1834 * ipr_log_array_error - Log an array configuration error.
1835 * @ioa_cfg: ioa config struct
1836 * @hostrcb: hostrcb struct
1841 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1842 struct ipr_hostrcb *hostrcb)
1845 struct ipr_hostrcb_type_04_error *error;
1846 struct ipr_hostrcb_array_data_entry *array_entry;
1847 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1849 error = &hostrcb->hcam.u.error.u.type_04_error;
1853 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1854 error->protection_level,
1855 ioa_cfg->host->host_no,
1856 error->last_func_vset_res_addr.bus,
1857 error->last_func_vset_res_addr.target,
1858 error->last_func_vset_res_addr.lun);
1862 array_entry = error->array_member;
1864 for (i = 0; i < 18; i++) {
1865 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1868 if (be32_to_cpu(error->exposed_mode_adn) == i)
1869 ipr_err("Exposed Array Member %d:\n", i);
1871 ipr_err("Array Member %d:\n", i);
1873 ipr_log_vpd(&array_entry->vpd);
1875 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1876 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1877 "Expected Location");
1882 array_entry = error->array_member2;
1889 * ipr_log_hex_data - Log additional hex IOA error data.
1890 * @ioa_cfg: ioa config struct
1891 * @data: IOA error data
1897 static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
1904 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1905 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1907 for (i = 0; i < len / 4; i += 4) {
1908 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1909 be32_to_cpu(data[i]),
1910 be32_to_cpu(data[i+1]),
1911 be32_to_cpu(data[i+2]),
1912 be32_to_cpu(data[i+3]));
1917 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1918 * @ioa_cfg: ioa config struct
1919 * @hostrcb: hostrcb struct
1924 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1925 struct ipr_hostrcb *hostrcb)
1927 struct ipr_hostrcb_type_17_error *error;
1930 error = &hostrcb->hcam.u.error64.u.type_17_error;
1932 error = &hostrcb->hcam.u.error.u.type_17_error;
1934 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1935 strim(error->failure_reason);
1937 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1938 be32_to_cpu(hostrcb->hcam.u.error.prc));
1939 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1940 ipr_log_hex_data(ioa_cfg, error->data,
1941 be32_to_cpu(hostrcb->hcam.length) -
1942 (offsetof(struct ipr_hostrcb_error, u) +
1943 offsetof(struct ipr_hostrcb_type_17_error, data)));
1947 * ipr_log_dual_ioa_error - Log a dual adapter error.
1948 * @ioa_cfg: ioa config struct
1949 * @hostrcb: hostrcb struct
1954 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1955 struct ipr_hostrcb *hostrcb)
1957 struct ipr_hostrcb_type_07_error *error;
1959 error = &hostrcb->hcam.u.error.u.type_07_error;
1960 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1961 strim(error->failure_reason);
1963 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1964 be32_to_cpu(hostrcb->hcam.u.error.prc));
1965 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1966 ipr_log_hex_data(ioa_cfg, error->data,
1967 be32_to_cpu(hostrcb->hcam.length) -
1968 (offsetof(struct ipr_hostrcb_error, u) +
1969 offsetof(struct ipr_hostrcb_type_07_error, data)));
1972 static const struct {
1975 } path_active_desc[] = {
1976 { IPR_PATH_NO_INFO, "Path" },
1977 { IPR_PATH_ACTIVE, "Active path" },
1978 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1981 static const struct {
1984 } path_state_desc[] = {
1985 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1986 { IPR_PATH_HEALTHY, "is healthy" },
1987 { IPR_PATH_DEGRADED, "is degraded" },
1988 { IPR_PATH_FAILED, "is failed" }
1992 * ipr_log_fabric_path - Log a fabric path error
1993 * @hostrcb: hostrcb struct
1994 * @fabric: fabric descriptor
1999 static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
2000 struct ipr_hostrcb_fabric_desc *fabric)
2003 u8 path_state = fabric->path_state;
2004 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
2005 u8 state = path_state & IPR_PATH_STATE_MASK;
2007 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
2008 if (path_active_desc[i].active != active)
2011 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2012 if (path_state_desc[j].state != state)
2015 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
2016 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
2017 path_active_desc[i].desc, path_state_desc[j].desc,
2019 } else if (fabric->cascaded_expander == 0xff) {
2020 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
2021 path_active_desc[i].desc, path_state_desc[j].desc,
2022 fabric->ioa_port, fabric->phy);
2023 } else if (fabric->phy == 0xff) {
2024 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
2025 path_active_desc[i].desc, path_state_desc[j].desc,
2026 fabric->ioa_port, fabric->cascaded_expander);
2028 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
2029 path_active_desc[i].desc, path_state_desc[j].desc,
2030 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2036 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
2037 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2041 * ipr_log64_fabric_path - Log a fabric path error
2042 * @hostrcb: hostrcb struct
2043 * @fabric: fabric descriptor
2048 static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
2049 struct ipr_hostrcb64_fabric_desc *fabric)
2052 u8 path_state = fabric->path_state;
2053 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
2054 u8 state = path_state & IPR_PATH_STATE_MASK;
2055 char buffer[IPR_MAX_RES_PATH_LENGTH];
2057 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
2058 if (path_active_desc[i].active != active)
2061 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2062 if (path_state_desc[j].state != state)
2065 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
2066 path_active_desc[i].desc, path_state_desc[j].desc,
2067 ipr_format_res_path(hostrcb->ioa_cfg,
2069 buffer, sizeof(buffer)));
2074 ipr_err("Path state=%02X Resource Path=%s\n", path_state,
2075 ipr_format_res_path(hostrcb->ioa_cfg, fabric->res_path,
2076 buffer, sizeof(buffer)));
2079 static const struct {
2082 } path_type_desc[] = {
2083 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
2084 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
2085 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
2086 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
2089 static const struct {
2092 } path_status_desc[] = {
2093 { IPR_PATH_CFG_NO_PROB, "Functional" },
2094 { IPR_PATH_CFG_DEGRADED, "Degraded" },
2095 { IPR_PATH_CFG_FAILED, "Failed" },
2096 { IPR_PATH_CFG_SUSPECT, "Suspect" },
2097 { IPR_PATH_NOT_DETECTED, "Missing" },
2098 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
2101 static const char *link_rate[] = {
2104 "phy reset problem",
2121 * ipr_log_path_elem - Log a fabric path element.
2122 * @hostrcb: hostrcb struct
2123 * @cfg: fabric path element struct
2128 static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
2129 struct ipr_hostrcb_config_element *cfg)
2132 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2133 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2135 if (type == IPR_PATH_CFG_NOT_EXIST)
2138 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2139 if (path_type_desc[i].type != type)
2142 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2143 if (path_status_desc[j].status != status)
2146 if (type == IPR_PATH_CFG_IOA_PORT) {
2147 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
2148 path_status_desc[j].desc, path_type_desc[i].desc,
2149 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2150 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2152 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
2153 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2154 path_status_desc[j].desc, path_type_desc[i].desc,
2155 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2156 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2157 } else if (cfg->cascaded_expander == 0xff) {
2158 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
2159 "WWN=%08X%08X\n", path_status_desc[j].desc,
2160 path_type_desc[i].desc, cfg->phy,
2161 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2162 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2163 } else if (cfg->phy == 0xff) {
2164 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
2165 "WWN=%08X%08X\n", path_status_desc[j].desc,
2166 path_type_desc[i].desc, cfg->cascaded_expander,
2167 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2168 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2170 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2171 "WWN=%08X%08X\n", path_status_desc[j].desc,
2172 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
2173 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2174 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2181 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2182 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
2183 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2184 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2188 * ipr_log64_path_elem - Log a fabric path element.
2189 * @hostrcb: hostrcb struct
2190 * @cfg: fabric path element struct
2195 static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
2196 struct ipr_hostrcb64_config_element *cfg)
2199 u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
2200 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2201 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2202 char buffer[IPR_MAX_RES_PATH_LENGTH];
2204 if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
2207 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2208 if (path_type_desc[i].type != type)
2211 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2212 if (path_status_desc[j].status != status)
2215 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2216 path_status_desc[j].desc, path_type_desc[i].desc,
2217 ipr_format_res_path(hostrcb->ioa_cfg,
2218 cfg->res_path, buffer, sizeof(buffer)),
2219 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2220 be32_to_cpu(cfg->wwid[0]),
2221 be32_to_cpu(cfg->wwid[1]));
2225 ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
2226 "WWN=%08X%08X\n", cfg->type_status,
2227 ipr_format_res_path(hostrcb->ioa_cfg,
2228 cfg->res_path, buffer, sizeof(buffer)),
2229 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2230 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2234 * ipr_log_fabric_error - Log a fabric error.
2235 * @ioa_cfg: ioa config struct
2236 * @hostrcb: hostrcb struct
2241 static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2242 struct ipr_hostrcb *hostrcb)
2244 struct ipr_hostrcb_type_20_error *error;
2245 struct ipr_hostrcb_fabric_desc *fabric;
2246 struct ipr_hostrcb_config_element *cfg;
2249 error = &hostrcb->hcam.u.error.u.type_20_error;
2250 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2251 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2253 add_len = be32_to_cpu(hostrcb->hcam.length) -
2254 (offsetof(struct ipr_hostrcb_error, u) +
2255 offsetof(struct ipr_hostrcb_type_20_error, desc));
2257 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2258 ipr_log_fabric_path(hostrcb, fabric);
2259 for_each_fabric_cfg(fabric, cfg)
2260 ipr_log_path_elem(hostrcb, cfg);
2262 add_len -= be16_to_cpu(fabric->length);
2263 fabric = (struct ipr_hostrcb_fabric_desc *)
2264 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2267 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2271 * ipr_log_sis64_array_error - Log a sis64 array error.
2272 * @ioa_cfg: ioa config struct
2273 * @hostrcb: hostrcb struct
2278 static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
2279 struct ipr_hostrcb *hostrcb)
2282 struct ipr_hostrcb_type_24_error *error;
2283 struct ipr_hostrcb64_array_data_entry *array_entry;
2284 char buffer[IPR_MAX_RES_PATH_LENGTH];
2285 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
2287 error = &hostrcb->hcam.u.error64.u.type_24_error;
2291 ipr_err("RAID %s Array Configuration: %s\n",
2292 error->protection_level,
2293 ipr_format_res_path(ioa_cfg, error->last_res_path,
2294 buffer, sizeof(buffer)));
2298 array_entry = error->array_member;
2299 num_entries = min_t(u32, error->num_entries,
2300 ARRAY_SIZE(error->array_member));
2302 for (i = 0; i < num_entries; i++, array_entry++) {
2304 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
2307 if (error->exposed_mode_adn == i)
2308 ipr_err("Exposed Array Member %d:\n", i);
2310 ipr_err("Array Member %d:\n", i);
2312 ipr_err("Array Member %d:\n", i);
2313 ipr_log_ext_vpd(&array_entry->vpd);
2314 ipr_err("Current Location: %s\n",
2315 ipr_format_res_path(ioa_cfg, array_entry->res_path,
2316 buffer, sizeof(buffer)));
2317 ipr_err("Expected Location: %s\n",
2318 ipr_format_res_path(ioa_cfg,
2319 array_entry->expected_res_path,
2320 buffer, sizeof(buffer)));
2327 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2328 * @ioa_cfg: ioa config struct
2329 * @hostrcb: hostrcb struct
2334 static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2335 struct ipr_hostrcb *hostrcb)
2337 struct ipr_hostrcb_type_30_error *error;
2338 struct ipr_hostrcb64_fabric_desc *fabric;
2339 struct ipr_hostrcb64_config_element *cfg;
2342 error = &hostrcb->hcam.u.error64.u.type_30_error;
2344 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2345 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2347 add_len = be32_to_cpu(hostrcb->hcam.length) -
2348 (offsetof(struct ipr_hostrcb64_error, u) +
2349 offsetof(struct ipr_hostrcb_type_30_error, desc));
2351 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2352 ipr_log64_fabric_path(hostrcb, fabric);
2353 for_each_fabric_cfg(fabric, cfg)
2354 ipr_log64_path_elem(hostrcb, cfg);
2356 add_len -= be16_to_cpu(fabric->length);
2357 fabric = (struct ipr_hostrcb64_fabric_desc *)
2358 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2361 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2365 * ipr_log_generic_error - Log an adapter error.
2366 * @ioa_cfg: ioa config struct
2367 * @hostrcb: hostrcb struct
2372 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
2373 struct ipr_hostrcb *hostrcb)
2375 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
2376 be32_to_cpu(hostrcb->hcam.length));
2380 * ipr_log_sis64_device_error - Log a cache error.
2381 * @ioa_cfg: ioa config struct
2382 * @hostrcb: hostrcb struct
2387 static void ipr_log_sis64_device_error(struct ipr_ioa_cfg *ioa_cfg,
2388 struct ipr_hostrcb *hostrcb)
2390 struct ipr_hostrcb_type_21_error *error;
2391 char buffer[IPR_MAX_RES_PATH_LENGTH];
2393 error = &hostrcb->hcam.u.error64.u.type_21_error;
2395 ipr_err("-----Failing Device Information-----\n");
2396 ipr_err("World Wide Unique ID: %08X%08X%08X%08X\n",
2397 be32_to_cpu(error->wwn[0]), be32_to_cpu(error->wwn[1]),
2398 be32_to_cpu(error->wwn[2]), be32_to_cpu(error->wwn[3]));
2399 ipr_err("Device Resource Path: %s\n",
2400 __ipr_format_res_path(error->res_path,
2401 buffer, sizeof(buffer)));
2402 error->primary_problem_desc[sizeof(error->primary_problem_desc) - 1] = '\0';
2403 error->second_problem_desc[sizeof(error->second_problem_desc) - 1] = '\0';
2404 ipr_err("Primary Problem Description: %s\n", error->primary_problem_desc);
2405 ipr_err("Secondary Problem Description: %s\n", error->second_problem_desc);
2406 ipr_err("SCSI Sense Data:\n");
2407 ipr_log_hex_data(ioa_cfg, error->sense_data, sizeof(error->sense_data));
2408 ipr_err("SCSI Command Descriptor Block: \n");
2409 ipr_log_hex_data(ioa_cfg, error->cdb, sizeof(error->cdb));
2411 ipr_err("Additional IOA Data:\n");
2412 ipr_log_hex_data(ioa_cfg, error->ioa_data, be32_to_cpu(error->length_of_error));
2416 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2419 * This function will return the index of into the ipr_error_table
2420 * for the specified IOASC. If the IOASC is not in the table,
2421 * 0 will be returned, which points to the entry used for unknown errors.
2424 * index into the ipr_error_table
2426 static u32 ipr_get_error(u32 ioasc)
2430 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
2431 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
2438 * ipr_handle_log_data - Log an adapter error.
2439 * @ioa_cfg: ioa config struct
2440 * @hostrcb: hostrcb struct
2442 * This function logs an adapter error to the system.
2447 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
2448 struct ipr_hostrcb *hostrcb)
2452 struct ipr_hostrcb_type_21_error *error;
2454 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
2457 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
2458 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
2461 ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2463 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2465 if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
2466 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
2467 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2468 scsi_report_bus_reset(ioa_cfg->host,
2469 hostrcb->hcam.u.error.fd_res_addr.bus);
2472 error_index = ipr_get_error(ioasc);
2474 if (!ipr_error_table[error_index].log_hcam)
2477 if (ioasc == IPR_IOASC_HW_CMD_FAILED &&
2478 hostrcb->hcam.overlay_id == IPR_HOST_RCB_OVERLAY_ID_21) {
2479 error = &hostrcb->hcam.u.error64.u.type_21_error;
2481 if (((be32_to_cpu(error->sense_data[0]) & 0x0000ff00) >> 8) == ILLEGAL_REQUEST &&
2482 ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
2486 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
2488 /* Set indication we have logged an error */
2489 ioa_cfg->errors_logged++;
2491 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
2493 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
2494 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
2496 switch (hostrcb->hcam.overlay_id) {
2497 case IPR_HOST_RCB_OVERLAY_ID_2:
2498 ipr_log_cache_error(ioa_cfg, hostrcb);
2500 case IPR_HOST_RCB_OVERLAY_ID_3:
2501 ipr_log_config_error(ioa_cfg, hostrcb);
2503 case IPR_HOST_RCB_OVERLAY_ID_4:
2504 case IPR_HOST_RCB_OVERLAY_ID_6:
2505 ipr_log_array_error(ioa_cfg, hostrcb);
2507 case IPR_HOST_RCB_OVERLAY_ID_7:
2508 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
2510 case IPR_HOST_RCB_OVERLAY_ID_12:
2511 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
2513 case IPR_HOST_RCB_OVERLAY_ID_13:
2514 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
2516 case IPR_HOST_RCB_OVERLAY_ID_14:
2517 case IPR_HOST_RCB_OVERLAY_ID_16:
2518 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
2520 case IPR_HOST_RCB_OVERLAY_ID_17:
2521 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
2523 case IPR_HOST_RCB_OVERLAY_ID_20:
2524 ipr_log_fabric_error(ioa_cfg, hostrcb);
2526 case IPR_HOST_RCB_OVERLAY_ID_21:
2527 ipr_log_sis64_device_error(ioa_cfg, hostrcb);
2529 case IPR_HOST_RCB_OVERLAY_ID_23:
2530 ipr_log_sis64_config_error(ioa_cfg, hostrcb);
2532 case IPR_HOST_RCB_OVERLAY_ID_24:
2533 case IPR_HOST_RCB_OVERLAY_ID_26:
2534 ipr_log_sis64_array_error(ioa_cfg, hostrcb);
2536 case IPR_HOST_RCB_OVERLAY_ID_30:
2537 ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
2539 case IPR_HOST_RCB_OVERLAY_ID_1:
2540 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
2542 ipr_log_generic_error(ioa_cfg, hostrcb);
2548 * ipr_process_error - Op done function for an adapter error log.
2549 * @ipr_cmd: ipr command struct
2551 * This function is the op done function for an error log host
2552 * controlled async from the adapter. It will log the error and
2553 * send the HCAM back to the adapter.
2558 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2560 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2561 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
2562 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
2566 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2568 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2570 list_del(&hostrcb->queue);
2571 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
2574 ipr_handle_log_data(ioa_cfg, hostrcb);
2575 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
2576 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
2577 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET &&
2578 ioasc != IPR_IOASC_ABORTED_CMD_TERM_BY_HOST) {
2579 dev_err(&ioa_cfg->pdev->dev,
2580 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
2583 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2587 * ipr_timeout - An internally generated op has timed out.
2588 * @ipr_cmd: ipr command struct
2590 * This function blocks host requests and initiates an
2596 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
2598 unsigned long lock_flags = 0;
2599 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2602 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2604 ioa_cfg->errors_logged++;
2605 dev_err(&ioa_cfg->pdev->dev,
2606 "Adapter being reset due to command timeout.\n");
2608 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2609 ioa_cfg->sdt_state = GET_DUMP;
2611 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
2612 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2614 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2619 * ipr_oper_timeout - Adapter timed out transitioning to operational
2620 * @ipr_cmd: ipr command struct
2622 * This function blocks host requests and initiates an
2628 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
2630 unsigned long lock_flags = 0;
2631 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2634 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2636 ioa_cfg->errors_logged++;
2637 dev_err(&ioa_cfg->pdev->dev,
2638 "Adapter timed out transitioning to operational.\n");
2640 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2641 ioa_cfg->sdt_state = GET_DUMP;
2643 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
2645 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
2646 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2649 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2654 * ipr_find_ses_entry - Find matching SES in SES table
2655 * @res: resource entry struct of SES
2658 * pointer to SES table entry / NULL on failure
2660 static const struct ipr_ses_table_entry *
2661 ipr_find_ses_entry(struct ipr_resource_entry *res)
2664 struct ipr_std_inq_vpids *vpids;
2665 const struct ipr_ses_table_entry *ste = ipr_ses_table;
2667 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
2668 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
2669 if (ste->compare_product_id_byte[j] == 'X') {
2670 vpids = &res->std_inq_data.vpids;
2671 if (vpids->product_id[j] == ste->product_id[j])
2679 if (matches == IPR_PROD_ID_LEN)
2687 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2688 * @ioa_cfg: ioa config struct
2690 * @bus_width: bus width
2693 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2694 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2695 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2696 * max 160MHz = max 320MB/sec).
2698 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
2700 struct ipr_resource_entry *res;
2701 const struct ipr_ses_table_entry *ste;
2702 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
2704 /* Loop through each config table entry in the config table buffer */
2705 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2706 if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
2709 if (bus != res->bus)
2712 if (!(ste = ipr_find_ses_entry(res)))
2715 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
2718 return max_xfer_rate;
2722 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2723 * @ioa_cfg: ioa config struct
2724 * @max_delay: max delay in micro-seconds to wait
2726 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2729 * 0 on success / other on failure
2731 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
2733 volatile u32 pcii_reg;
2736 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2737 while (delay < max_delay) {
2738 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
2740 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
2743 /* udelay cannot be used if delay is more than a few milliseconds */
2744 if ((delay / 1000) > MAX_UDELAY_MS)
2745 mdelay(delay / 1000);
2755 * ipr_get_sis64_dump_data_section - Dump IOA memory
2756 * @ioa_cfg: ioa config struct
2757 * @start_addr: adapter address to dump
2758 * @dest: destination kernel buffer
2759 * @length_in_words: length to dump in 4 byte words
2764 static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2766 __be32 *dest, u32 length_in_words)
2770 for (i = 0; i < length_in_words; i++) {
2771 writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
2772 *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
2780 * ipr_get_ldump_data_section - Dump IOA memory
2781 * @ioa_cfg: ioa config struct
2782 * @start_addr: adapter address to dump
2783 * @dest: destination kernel buffer
2784 * @length_in_words: length to dump in 4 byte words
2787 * 0 on success / -EIO on failure
2789 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2791 __be32 *dest, u32 length_in_words)
2793 volatile u32 temp_pcii_reg;
2797 return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
2798 dest, length_in_words);
2800 /* Write IOA interrupt reg starting LDUMP state */
2801 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
2802 ioa_cfg->regs.set_uproc_interrupt_reg32);
2804 /* Wait for IO debug acknowledge */
2805 if (ipr_wait_iodbg_ack(ioa_cfg,
2806 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
2807 dev_err(&ioa_cfg->pdev->dev,
2808 "IOA dump long data transfer timeout\n");
2812 /* Signal LDUMP interlocked - clear IO debug ack */
2813 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2814 ioa_cfg->regs.clr_interrupt_reg);
2816 /* Write Mailbox with starting address */
2817 writel(start_addr, ioa_cfg->ioa_mailbox);
2819 /* Signal address valid - clear IOA Reset alert */
2820 writel(IPR_UPROCI_RESET_ALERT,
2821 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2823 for (i = 0; i < length_in_words; i++) {
2824 /* Wait for IO debug acknowledge */
2825 if (ipr_wait_iodbg_ack(ioa_cfg,
2826 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2827 dev_err(&ioa_cfg->pdev->dev,
2828 "IOA dump short data transfer timeout\n");
2832 /* Read data from mailbox and increment destination pointer */
2833 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2836 /* For all but the last word of data, signal data received */
2837 if (i < (length_in_words - 1)) {
2838 /* Signal dump data received - Clear IO debug Ack */
2839 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2840 ioa_cfg->regs.clr_interrupt_reg);
2844 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2845 writel(IPR_UPROCI_RESET_ALERT,
2846 ioa_cfg->regs.set_uproc_interrupt_reg32);
2848 writel(IPR_UPROCI_IO_DEBUG_ALERT,
2849 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2851 /* Signal dump data received - Clear IO debug Ack */
2852 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2853 ioa_cfg->regs.clr_interrupt_reg);
2855 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2856 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2858 readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
2860 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2870 #ifdef CONFIG_SCSI_IPR_DUMP
2872 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2873 * @ioa_cfg: ioa config struct
2874 * @pci_address: adapter address
2875 * @length: length of data to copy
2877 * Copy data from PCI adapter to kernel buffer.
2878 * Note: length MUST be a 4 byte multiple
2880 * 0 on success / other on failure
2882 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2883 unsigned long pci_address, u32 length)
2885 int bytes_copied = 0;
2886 int cur_len, rc, rem_len, rem_page_len, max_dump_size;
2888 unsigned long lock_flags = 0;
2889 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2892 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2894 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2896 while (bytes_copied < length &&
2897 (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
2898 if (ioa_dump->page_offset >= PAGE_SIZE ||
2899 ioa_dump->page_offset == 0) {
2900 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2904 return bytes_copied;
2907 ioa_dump->page_offset = 0;
2908 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2909 ioa_dump->next_page_index++;
2911 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2913 rem_len = length - bytes_copied;
2914 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2915 cur_len = min(rem_len, rem_page_len);
2917 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2918 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2921 rc = ipr_get_ldump_data_section(ioa_cfg,
2922 pci_address + bytes_copied,
2923 &page[ioa_dump->page_offset / 4],
2924 (cur_len / sizeof(u32)));
2926 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2929 ioa_dump->page_offset += cur_len;
2930 bytes_copied += cur_len;
2938 return bytes_copied;
2942 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2943 * @hdr: dump entry header struct
2948 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2950 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2952 hdr->offset = sizeof(*hdr);
2953 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2957 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2958 * @ioa_cfg: ioa config struct
2959 * @driver_dump: driver dump struct
2964 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2965 struct ipr_driver_dump *driver_dump)
2967 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2969 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2970 driver_dump->ioa_type_entry.hdr.len =
2971 sizeof(struct ipr_dump_ioa_type_entry) -
2972 sizeof(struct ipr_dump_entry_header);
2973 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2974 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2975 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2976 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2977 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2978 ucode_vpd->minor_release[1];
2979 driver_dump->hdr.num_entries++;
2983 * ipr_dump_version_data - Fill in the driver version in the dump.
2984 * @ioa_cfg: ioa config struct
2985 * @driver_dump: driver dump struct
2990 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2991 struct ipr_driver_dump *driver_dump)
2993 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2994 driver_dump->version_entry.hdr.len =
2995 sizeof(struct ipr_dump_version_entry) -
2996 sizeof(struct ipr_dump_entry_header);
2997 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2998 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2999 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
3000 driver_dump->hdr.num_entries++;
3004 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
3005 * @ioa_cfg: ioa config struct
3006 * @driver_dump: driver dump struct
3011 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
3012 struct ipr_driver_dump *driver_dump)
3014 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
3015 driver_dump->trace_entry.hdr.len =
3016 sizeof(struct ipr_dump_trace_entry) -
3017 sizeof(struct ipr_dump_entry_header);
3018 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3019 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
3020 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
3021 driver_dump->hdr.num_entries++;
3025 * ipr_dump_location_data - Fill in the IOA location in the dump.
3026 * @ioa_cfg: ioa config struct
3027 * @driver_dump: driver dump struct
3032 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
3033 struct ipr_driver_dump *driver_dump)
3035 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
3036 driver_dump->location_entry.hdr.len =
3037 sizeof(struct ipr_dump_location_entry) -
3038 sizeof(struct ipr_dump_entry_header);
3039 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
3040 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
3041 strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
3042 driver_dump->hdr.num_entries++;
3046 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
3047 * @ioa_cfg: ioa config struct
3048 * @dump: dump struct
3053 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
3055 unsigned long start_addr, sdt_word;
3056 unsigned long lock_flags = 0;
3057 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
3058 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
3059 u32 num_entries, max_num_entries, start_off, end_off;
3060 u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
3061 struct ipr_sdt *sdt;
3067 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3069 if (ioa_cfg->sdt_state != READ_DUMP) {
3070 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3074 if (ioa_cfg->sis64) {
3075 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3076 ssleep(IPR_DUMP_DELAY_SECONDS);
3077 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3080 start_addr = readl(ioa_cfg->ioa_mailbox);
3082 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
3083 dev_err(&ioa_cfg->pdev->dev,
3084 "Invalid dump table format: %lx\n", start_addr);
3085 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3089 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
3091 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
3093 /* Initialize the overall dump header */
3094 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
3095 driver_dump->hdr.num_entries = 1;
3096 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
3097 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
3098 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
3099 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
3101 ipr_dump_version_data(ioa_cfg, driver_dump);
3102 ipr_dump_location_data(ioa_cfg, driver_dump);
3103 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
3104 ipr_dump_trace_data(ioa_cfg, driver_dump);
3106 /* Update dump_header */
3107 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
3109 /* IOA Dump entry */
3110 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
3111 ioa_dump->hdr.len = 0;
3112 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3113 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
3115 /* First entries in sdt are actually a list of dump addresses and
3116 lengths to gather the real dump data. sdt represents the pointer
3117 to the ioa generated dump table. Dump data will be extracted based
3118 on entries in this table */
3119 sdt = &ioa_dump->sdt;
3121 if (ioa_cfg->sis64) {
3122 max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
3123 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
3125 max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
3126 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
3129 bytes_to_copy = offsetof(struct ipr_sdt, entry) +
3130 (max_num_entries * sizeof(struct ipr_sdt_entry));
3131 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
3132 bytes_to_copy / sizeof(__be32));
3134 /* Smart Dump table is ready to use and the first entry is valid */
3135 if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
3136 (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
3137 dev_err(&ioa_cfg->pdev->dev,
3138 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
3139 rc, be32_to_cpu(sdt->hdr.state));
3140 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
3141 ioa_cfg->sdt_state = DUMP_OBTAINED;
3142 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3146 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
3148 if (num_entries > max_num_entries)
3149 num_entries = max_num_entries;
3151 /* Update dump length to the actual data to be copied */
3152 dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
3154 dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
3156 dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
3158 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3160 for (i = 0; i < num_entries; i++) {
3161 if (ioa_dump->hdr.len > max_dump_size) {
3162 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3166 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
3167 sdt_word = be32_to_cpu(sdt->entry[i].start_token);
3169 bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
3171 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
3172 end_off = be32_to_cpu(sdt->entry[i].end_token);
3174 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
3175 bytes_to_copy = end_off - start_off;
3180 if (bytes_to_copy > max_dump_size) {
3181 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
3185 /* Copy data from adapter to driver buffers */
3186 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
3189 ioa_dump->hdr.len += bytes_copied;
3191 if (bytes_copied != bytes_to_copy) {
3192 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3199 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
3201 /* Update dump_header */
3202 driver_dump->hdr.len += ioa_dump->hdr.len;
3204 ioa_cfg->sdt_state = DUMP_OBTAINED;
3209 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while (0)
3213 * ipr_release_dump - Free adapter dump memory
3214 * @kref: kref struct
3219 static void ipr_release_dump(struct kref *kref)
3221 struct ipr_dump *dump = container_of(kref, struct ipr_dump, kref);
3222 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
3223 unsigned long lock_flags = 0;
3227 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3228 ioa_cfg->dump = NULL;
3229 ioa_cfg->sdt_state = INACTIVE;
3230 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3232 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
3233 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
3235 vfree(dump->ioa_dump.ioa_data);
3241 * ipr_worker_thread - Worker thread
3242 * @work: ioa config struct
3244 * Called at task level from a work thread. This function takes care
3245 * of adding and removing device from the mid-layer as configuration
3246 * changes are detected by the adapter.
3251 static void ipr_worker_thread(struct work_struct *work)
3253 unsigned long lock_flags;
3254 struct ipr_resource_entry *res;
3255 struct scsi_device *sdev;
3256 struct ipr_dump *dump;
3257 struct ipr_ioa_cfg *ioa_cfg =
3258 container_of(work, struct ipr_ioa_cfg, work_q);
3259 u8 bus, target, lun;
3263 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3265 if (ioa_cfg->sdt_state == READ_DUMP) {
3266 dump = ioa_cfg->dump;
3268 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3271 kref_get(&dump->kref);
3272 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3273 ipr_get_ioa_dump(ioa_cfg, dump);
3274 kref_put(&dump->kref, ipr_release_dump);
3276 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3277 if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
3278 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3279 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3286 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
3287 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3291 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3292 if (res->del_from_ml && res->sdev) {
3295 if (!scsi_device_get(sdev)) {
3296 if (!res->add_to_ml)
3297 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
3299 res->del_from_ml = 0;
3300 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3301 scsi_remove_device(sdev);
3302 scsi_device_put(sdev);
3303 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3310 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3311 if (res->add_to_ml) {
3313 target = res->target;
3316 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3317 scsi_add_device(ioa_cfg->host, bus, target, lun);
3318 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3323 ioa_cfg->scan_done = 1;
3324 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3325 kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
3329 #ifdef CONFIG_SCSI_IPR_TRACE
3331 * ipr_read_trace - Dump the adapter trace
3332 * @filp: open sysfs file
3333 * @kobj: kobject struct
3334 * @bin_attr: bin_attribute struct
3337 * @count: buffer size
3340 * number of bytes printed to buffer
3342 static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
3343 struct bin_attribute *bin_attr,
3344 char *buf, loff_t off, size_t count)
3346 struct device *dev = container_of(kobj, struct device, kobj);
3347 struct Scsi_Host *shost = class_to_shost(dev);
3348 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3349 unsigned long lock_flags = 0;
3352 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3353 ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
3355 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3360 static struct bin_attribute ipr_trace_attr = {
3366 .read = ipr_read_trace,
3371 * ipr_show_fw_version - Show the firmware version
3372 * @dev: class device struct
3376 * number of bytes printed to buffer
3378 static ssize_t ipr_show_fw_version(struct device *dev,
3379 struct device_attribute *attr, char *buf)
3381 struct Scsi_Host *shost = class_to_shost(dev);
3382 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3383 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
3384 unsigned long lock_flags = 0;
3387 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3388 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
3389 ucode_vpd->major_release, ucode_vpd->card_type,
3390 ucode_vpd->minor_release[0],
3391 ucode_vpd->minor_release[1]);
3392 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3396 static struct device_attribute ipr_fw_version_attr = {
3398 .name = "fw_version",
3401 .show = ipr_show_fw_version,
3405 * ipr_show_log_level - Show the adapter's error logging level
3406 * @dev: class device struct
3410 * number of bytes printed to buffer
3412 static ssize_t ipr_show_log_level(struct device *dev,
3413 struct device_attribute *attr, char *buf)
3415 struct Scsi_Host *shost = class_to_shost(dev);
3416 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3417 unsigned long lock_flags = 0;
3420 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3421 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
3422 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3427 * ipr_store_log_level - Change the adapter's error logging level
3428 * @dev: class device struct
3432 * number of bytes printed to buffer
3434 static ssize_t ipr_store_log_level(struct device *dev,
3435 struct device_attribute *attr,
3436 const char *buf, size_t count)
3438 struct Scsi_Host *shost = class_to_shost(dev);
3439 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3440 unsigned long lock_flags = 0;
3442 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3443 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
3444 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3448 static struct device_attribute ipr_log_level_attr = {
3450 .name = "log_level",
3451 .mode = S_IRUGO | S_IWUSR,
3453 .show = ipr_show_log_level,
3454 .store = ipr_store_log_level
3458 * ipr_store_diagnostics - IOA Diagnostics interface
3459 * @dev: device struct
3461 * @count: buffer size
3463 * This function will reset the adapter and wait a reasonable
3464 * amount of time for any errors that the adapter might log.
3467 * count on success / other on failure
3469 static ssize_t ipr_store_diagnostics(struct device *dev,
3470 struct device_attribute *attr,
3471 const char *buf, size_t count)
3473 struct Scsi_Host *shost = class_to_shost(dev);
3474 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3475 unsigned long lock_flags = 0;
3478 if (!capable(CAP_SYS_ADMIN))
3481 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3482 while (ioa_cfg->in_reset_reload) {
3483 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3484 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3485 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3488 ioa_cfg->errors_logged = 0;
3489 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3491 if (ioa_cfg->in_reset_reload) {
3492 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3493 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3495 /* Wait for a second for any errors to be logged */
3498 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3502 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3503 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
3505 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3510 static struct device_attribute ipr_diagnostics_attr = {
3512 .name = "run_diagnostics",
3515 .store = ipr_store_diagnostics
3519 * ipr_show_adapter_state - Show the adapter's state
3520 * @class_dev: device struct
3524 * number of bytes printed to buffer
3526 static ssize_t ipr_show_adapter_state(struct device *dev,
3527 struct device_attribute *attr, char *buf)
3529 struct Scsi_Host *shost = class_to_shost(dev);
3530 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3531 unsigned long lock_flags = 0;
3534 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3535 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
3536 len = snprintf(buf, PAGE_SIZE, "offline\n");
3538 len = snprintf(buf, PAGE_SIZE, "online\n");
3539 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3544 * ipr_store_adapter_state - Change adapter state
3545 * @dev: device struct
3547 * @count: buffer size
3549 * This function will change the adapter's state.
3552 * count on success / other on failure
3554 static ssize_t ipr_store_adapter_state(struct device *dev,
3555 struct device_attribute *attr,
3556 const char *buf, size_t count)
3558 struct Scsi_Host *shost = class_to_shost(dev);
3559 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3560 unsigned long lock_flags;
3561 int result = count, i;
3563 if (!capable(CAP_SYS_ADMIN))
3566 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3567 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead &&
3568 !strncmp(buf, "online", 6)) {
3569 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
3570 spin_lock(&ioa_cfg->hrrq[i]._lock);
3571 ioa_cfg->hrrq[i].ioa_is_dead = 0;
3572 spin_unlock(&ioa_cfg->hrrq[i]._lock);
3575 ioa_cfg->reset_retries = 0;
3576 ioa_cfg->in_ioa_bringdown = 0;
3577 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3579 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3580 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3585 static struct device_attribute ipr_ioa_state_attr = {
3587 .name = "online_state",
3588 .mode = S_IRUGO | S_IWUSR,
3590 .show = ipr_show_adapter_state,
3591 .store = ipr_store_adapter_state
3595 * ipr_store_reset_adapter - Reset the adapter
3596 * @dev: device struct
3598 * @count: buffer size
3600 * This function will reset the adapter.
3603 * count on success / other on failure
3605 static ssize_t ipr_store_reset_adapter(struct device *dev,
3606 struct device_attribute *attr,
3607 const char *buf, size_t count)
3609 struct Scsi_Host *shost = class_to_shost(dev);
3610 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3611 unsigned long lock_flags;
3614 if (!capable(CAP_SYS_ADMIN))
3617 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3618 if (!ioa_cfg->in_reset_reload)
3619 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3620 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3621 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3626 static struct device_attribute ipr_ioa_reset_attr = {
3628 .name = "reset_host",
3631 .store = ipr_store_reset_adapter
3634 static int ipr_iopoll(struct blk_iopoll *iop, int budget);
3636 * ipr_show_iopoll_weight - Show ipr polling mode
3637 * @dev: class device struct
3641 * number of bytes printed to buffer
3643 static ssize_t ipr_show_iopoll_weight(struct device *dev,
3644 struct device_attribute *attr, char *buf)
3646 struct Scsi_Host *shost = class_to_shost(dev);
3647 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3648 unsigned long lock_flags = 0;
3651 spin_lock_irqsave(shost->host_lock, lock_flags);
3652 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->iopoll_weight);
3653 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3659 * ipr_store_iopoll_weight - Change the adapter's polling mode
3660 * @dev: class device struct
3664 * number of bytes printed to buffer
3666 static ssize_t ipr_store_iopoll_weight(struct device *dev,
3667 struct device_attribute *attr,
3668 const char *buf, size_t count)
3670 struct Scsi_Host *shost = class_to_shost(dev);
3671 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3672 unsigned long user_iopoll_weight;
3673 unsigned long lock_flags = 0;
3676 if (!ioa_cfg->sis64) {
3677 dev_info(&ioa_cfg->pdev->dev, "blk-iopoll not supported on this adapter\n");
3680 if (kstrtoul(buf, 10, &user_iopoll_weight))
3683 if (user_iopoll_weight > 256) {
3684 dev_info(&ioa_cfg->pdev->dev, "Invalid blk-iopoll weight. It must be less than 256\n");
3688 if (user_iopoll_weight == ioa_cfg->iopoll_weight) {
3689 dev_info(&ioa_cfg->pdev->dev, "Current blk-iopoll weight has the same weight\n");
3693 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
3694 for (i = 1; i < ioa_cfg->hrrq_num; i++)
3695 blk_iopoll_disable(&ioa_cfg->hrrq[i].iopoll);
3698 spin_lock_irqsave(shost->host_lock, lock_flags);
3699 ioa_cfg->iopoll_weight = user_iopoll_weight;
3700 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
3701 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
3702 blk_iopoll_init(&ioa_cfg->hrrq[i].iopoll,
3703 ioa_cfg->iopoll_weight, ipr_iopoll);
3704 blk_iopoll_enable(&ioa_cfg->hrrq[i].iopoll);
3707 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3712 static struct device_attribute ipr_iopoll_weight_attr = {
3714 .name = "iopoll_weight",
3715 .mode = S_IRUGO | S_IWUSR,
3717 .show = ipr_show_iopoll_weight,
3718 .store = ipr_store_iopoll_weight
3722 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3723 * @buf_len: buffer length
3725 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3726 * list to use for microcode download
3729 * pointer to sglist / NULL on failure
3731 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
3733 int sg_size, order, bsize_elem, num_elem, i, j;
3734 struct ipr_sglist *sglist;
3735 struct scatterlist *scatterlist;
3738 /* Get the minimum size per scatter/gather element */
3739 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
3741 /* Get the actual size per element */
3742 order = get_order(sg_size);
3744 /* Determine the actual number of bytes per element */
3745 bsize_elem = PAGE_SIZE * (1 << order);
3747 /* Determine the actual number of sg entries needed */
3748 if (buf_len % bsize_elem)
3749 num_elem = (buf_len / bsize_elem) + 1;
3751 num_elem = buf_len / bsize_elem;
3753 /* Allocate a scatter/gather list for the DMA */
3754 sglist = kzalloc(sizeof(struct ipr_sglist) +
3755 (sizeof(struct scatterlist) * (num_elem - 1)),
3758 if (sglist == NULL) {
3763 scatterlist = sglist->scatterlist;
3764 sg_init_table(scatterlist, num_elem);
3766 sglist->order = order;
3767 sglist->num_sg = num_elem;
3769 /* Allocate a bunch of sg elements */
3770 for (i = 0; i < num_elem; i++) {
3771 page = alloc_pages(GFP_KERNEL, order);
3775 /* Free up what we already allocated */
3776 for (j = i - 1; j >= 0; j--)
3777 __free_pages(sg_page(&scatterlist[j]), order);
3782 sg_set_page(&scatterlist[i], page, 0, 0);
3789 * ipr_free_ucode_buffer - Frees a microcode download buffer
3790 * @p_dnld: scatter/gather list pointer
3792 * Free a DMA'able ucode download buffer previously allocated with
3793 * ipr_alloc_ucode_buffer
3798 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
3802 for (i = 0; i < sglist->num_sg; i++)
3803 __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
3809 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3810 * @sglist: scatter/gather list pointer
3811 * @buffer: buffer pointer
3812 * @len: buffer length
3814 * Copy a microcode image from a user buffer into a buffer allocated by
3815 * ipr_alloc_ucode_buffer
3818 * 0 on success / other on failure
3820 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
3821 u8 *buffer, u32 len)
3823 int bsize_elem, i, result = 0;
3824 struct scatterlist *scatterlist;
3827 /* Determine the actual number of bytes per element */
3828 bsize_elem = PAGE_SIZE * (1 << sglist->order);
3830 scatterlist = sglist->scatterlist;
3832 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
3833 struct page *page = sg_page(&scatterlist[i]);
3836 memcpy(kaddr, buffer, bsize_elem);
3839 scatterlist[i].length = bsize_elem;
3847 if (len % bsize_elem) {
3848 struct page *page = sg_page(&scatterlist[i]);
3851 memcpy(kaddr, buffer, len % bsize_elem);
3854 scatterlist[i].length = len % bsize_elem;
3857 sglist->buffer_len = len;
3862 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3863 * @ipr_cmd: ipr command struct
3864 * @sglist: scatter/gather list
3866 * Builds a microcode download IOA data list (IOADL).
3869 static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
3870 struct ipr_sglist *sglist)
3872 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3873 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
3874 struct scatterlist *scatterlist = sglist->scatterlist;
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 (i = 0; i < 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(&scatterlist[i]));
3886 ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
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;
3908 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3909 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3910 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3913 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3915 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3916 ioadl[i].flags_and_data_len =
3917 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
3919 cpu_to_be32(sg_dma_address(&scatterlist[i]));
3922 ioadl[i-1].flags_and_data_len |=
3923 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3927 * ipr_update_ioa_ucode - Update IOA's microcode
3928 * @ioa_cfg: ioa config struct
3929 * @sglist: scatter/gather list
3931 * Initiate an adapter reset to update the IOA's microcode
3934 * 0 on success / -EIO on failure
3936 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3937 struct ipr_sglist *sglist)
3939 unsigned long lock_flags;
3941 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3942 while (ioa_cfg->in_reset_reload) {
3943 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3944 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3945 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3948 if (ioa_cfg->ucode_sglist) {
3949 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3950 dev_err(&ioa_cfg->pdev->dev,
3951 "Microcode download already in progress\n");
3955 sglist->num_dma_sg = dma_map_sg(&ioa_cfg->pdev->dev,
3956 sglist->scatterlist, sglist->num_sg,
3959 if (!sglist->num_dma_sg) {
3960 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3961 dev_err(&ioa_cfg->pdev->dev,
3962 "Failed to map microcode download buffer!\n");
3966 ioa_cfg->ucode_sglist = sglist;
3967 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3968 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3969 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3971 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3972 ioa_cfg->ucode_sglist = NULL;
3973 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3978 * ipr_store_update_fw - Update the firmware on the adapter
3979 * @class_dev: device struct
3981 * @count: buffer size
3983 * This function will update the firmware on the adapter.
3986 * count on success / other on failure
3988 static ssize_t ipr_store_update_fw(struct device *dev,
3989 struct device_attribute *attr,
3990 const char *buf, size_t count)
3992 struct Scsi_Host *shost = class_to_shost(dev);
3993 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3994 struct ipr_ucode_image_header *image_hdr;
3995 const struct firmware *fw_entry;
3996 struct ipr_sglist *sglist;
3999 int len, result, dnld_size;
4001 if (!capable(CAP_SYS_ADMIN))
4004 len = snprintf(fname, 99, "%s", buf);
4005 fname[len-1] = '\0';
4007 if (request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
4008 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
4012 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
4014 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
4015 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
4016 sglist = ipr_alloc_ucode_buffer(dnld_size);
4019 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
4020 release_firmware(fw_entry);
4024 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
4027 dev_err(&ioa_cfg->pdev->dev,
4028 "Microcode buffer copy to DMA buffer failed\n");
4032 ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
4034 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
4039 ipr_free_ucode_buffer(sglist);
4040 release_firmware(fw_entry);
4044 static struct device_attribute ipr_update_fw_attr = {
4046 .name = "update_fw",
4049 .store = ipr_store_update_fw
4053 * ipr_show_fw_type - Show the adapter's firmware type.
4054 * @dev: class device struct
4058 * number of bytes printed to buffer
4060 static ssize_t ipr_show_fw_type(struct device *dev,
4061 struct device_attribute *attr, char *buf)
4063 struct Scsi_Host *shost = class_to_shost(dev);
4064 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4065 unsigned long lock_flags = 0;
4068 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4069 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
4070 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4074 static struct device_attribute ipr_ioa_fw_type_attr = {
4079 .show = ipr_show_fw_type
4082 static struct device_attribute *ipr_ioa_attrs[] = {
4083 &ipr_fw_version_attr,
4084 &ipr_log_level_attr,
4085 &ipr_diagnostics_attr,
4086 &ipr_ioa_state_attr,
4087 &ipr_ioa_reset_attr,
4088 &ipr_update_fw_attr,
4089 &ipr_ioa_fw_type_attr,
4090 &ipr_iopoll_weight_attr,
4094 #ifdef CONFIG_SCSI_IPR_DUMP
4096 * ipr_read_dump - Dump the adapter
4097 * @filp: open sysfs file
4098 * @kobj: kobject struct
4099 * @bin_attr: bin_attribute struct
4102 * @count: buffer size
4105 * number of bytes printed to buffer
4107 static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
4108 struct bin_attribute *bin_attr,
4109 char *buf, loff_t off, size_t count)
4111 struct device *cdev = container_of(kobj, struct device, kobj);
4112 struct Scsi_Host *shost = class_to_shost(cdev);
4113 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4114 struct ipr_dump *dump;
4115 unsigned long lock_flags = 0;
4120 if (!capable(CAP_SYS_ADMIN))
4123 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4124 dump = ioa_cfg->dump;
4126 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
4127 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4130 kref_get(&dump->kref);
4131 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4133 if (off > dump->driver_dump.hdr.len) {
4134 kref_put(&dump->kref, ipr_release_dump);
4138 if (off + count > dump->driver_dump.hdr.len) {
4139 count = dump->driver_dump.hdr.len - off;
4143 if (count && off < sizeof(dump->driver_dump)) {
4144 if (off + count > sizeof(dump->driver_dump))
4145 len = sizeof(dump->driver_dump) - off;
4148 src = (u8 *)&dump->driver_dump + off;
4149 memcpy(buf, src, len);
4155 off -= sizeof(dump->driver_dump);
4158 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4159 (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
4160 sizeof(struct ipr_sdt_entry));
4162 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4163 (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
4165 if (count && off < sdt_end) {
4166 if (off + count > sdt_end)
4167 len = sdt_end - off;
4170 src = (u8 *)&dump->ioa_dump + off;
4171 memcpy(buf, src, len);
4180 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
4181 len = PAGE_ALIGN(off) - off;
4184 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
4185 src += off & ~PAGE_MASK;
4186 memcpy(buf, src, len);
4192 kref_put(&dump->kref, ipr_release_dump);
4197 * ipr_alloc_dump - Prepare for adapter dump
4198 * @ioa_cfg: ioa config struct
4201 * 0 on success / other on failure
4203 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
4205 struct ipr_dump *dump;
4207 unsigned long lock_flags = 0;
4209 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
4212 ipr_err("Dump memory allocation failed\n");
4217 ioa_data = vmalloc(IPR_FMT3_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
4219 ioa_data = vmalloc(IPR_FMT2_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
4222 ipr_err("Dump memory allocation failed\n");
4227 dump->ioa_dump.ioa_data = ioa_data;
4229 kref_init(&dump->kref);
4230 dump->ioa_cfg = ioa_cfg;
4232 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4234 if (INACTIVE != ioa_cfg->sdt_state) {
4235 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4236 vfree(dump->ioa_dump.ioa_data);
4241 ioa_cfg->dump = dump;
4242 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
4243 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead && !ioa_cfg->dump_taken) {
4244 ioa_cfg->dump_taken = 1;
4245 schedule_work(&ioa_cfg->work_q);
4247 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4253 * ipr_free_dump - Free adapter dump memory
4254 * @ioa_cfg: ioa config struct
4257 * 0 on success / other on failure
4259 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
4261 struct ipr_dump *dump;
4262 unsigned long lock_flags = 0;
4266 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4267 dump = ioa_cfg->dump;
4269 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4273 ioa_cfg->dump = NULL;
4274 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4276 kref_put(&dump->kref, ipr_release_dump);
4283 * ipr_write_dump - Setup dump state of adapter
4284 * @filp: open sysfs file
4285 * @kobj: kobject struct
4286 * @bin_attr: bin_attribute struct
4289 * @count: buffer size
4292 * number of bytes printed to buffer
4294 static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
4295 struct bin_attribute *bin_attr,
4296 char *buf, loff_t off, size_t count)
4298 struct device *cdev = container_of(kobj, struct device, kobj);
4299 struct Scsi_Host *shost = class_to_shost(cdev);
4300 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4303 if (!capable(CAP_SYS_ADMIN))
4307 rc = ipr_alloc_dump(ioa_cfg);
4308 else if (buf[0] == '0')
4309 rc = ipr_free_dump(ioa_cfg);
4319 static struct bin_attribute ipr_dump_attr = {
4322 .mode = S_IRUSR | S_IWUSR,
4325 .read = ipr_read_dump,
4326 .write = ipr_write_dump
4329 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
4333 * ipr_change_queue_depth - Change the device's queue depth
4334 * @sdev: scsi device struct
4335 * @qdepth: depth to set
4336 * @reason: calling context
4341 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
4343 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4344 struct ipr_resource_entry *res;
4345 unsigned long lock_flags = 0;
4347 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4348 res = (struct ipr_resource_entry *)sdev->hostdata;
4350 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
4351 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
4352 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4354 scsi_change_queue_depth(sdev, qdepth);
4355 return sdev->queue_depth;
4359 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4360 * @dev: device struct
4361 * @attr: device attribute structure
4365 * number of bytes printed to buffer
4367 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
4369 struct scsi_device *sdev = to_scsi_device(dev);
4370 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4371 struct ipr_resource_entry *res;
4372 unsigned long lock_flags = 0;
4373 ssize_t len = -ENXIO;
4375 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4376 res = (struct ipr_resource_entry *)sdev->hostdata;
4378 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
4379 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4383 static struct device_attribute ipr_adapter_handle_attr = {
4385 .name = "adapter_handle",
4388 .show = ipr_show_adapter_handle
4392 * ipr_show_resource_path - Show the resource path or the resource address for
4394 * @dev: device struct
4395 * @attr: device attribute structure
4399 * number of bytes printed to buffer
4401 static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
4403 struct scsi_device *sdev = to_scsi_device(dev);
4404 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4405 struct ipr_resource_entry *res;
4406 unsigned long lock_flags = 0;
4407 ssize_t len = -ENXIO;
4408 char buffer[IPR_MAX_RES_PATH_LENGTH];
4410 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4411 res = (struct ipr_resource_entry *)sdev->hostdata;
4412 if (res && ioa_cfg->sis64)
4413 len = snprintf(buf, PAGE_SIZE, "%s\n",
4414 __ipr_format_res_path(res->res_path, buffer,
4417 len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
4418 res->bus, res->target, res->lun);
4420 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4424 static struct device_attribute ipr_resource_path_attr = {
4426 .name = "resource_path",
4429 .show = ipr_show_resource_path
4433 * ipr_show_device_id - Show the device_id for this device.
4434 * @dev: device struct
4435 * @attr: device attribute structure
4439 * number of bytes printed to buffer
4441 static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
4443 struct scsi_device *sdev = to_scsi_device(dev);
4444 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4445 struct ipr_resource_entry *res;
4446 unsigned long lock_flags = 0;
4447 ssize_t len = -ENXIO;
4449 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4450 res = (struct ipr_resource_entry *)sdev->hostdata;
4451 if (res && ioa_cfg->sis64)
4452 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->dev_id);
4454 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
4456 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4460 static struct device_attribute ipr_device_id_attr = {
4462 .name = "device_id",
4465 .show = ipr_show_device_id
4469 * ipr_show_resource_type - Show the resource type for this device.
4470 * @dev: device struct
4471 * @attr: device attribute structure
4475 * number of bytes printed to buffer
4477 static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
4479 struct scsi_device *sdev = to_scsi_device(dev);
4480 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4481 struct ipr_resource_entry *res;
4482 unsigned long lock_flags = 0;
4483 ssize_t len = -ENXIO;
4485 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4486 res = (struct ipr_resource_entry *)sdev->hostdata;
4489 len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
4491 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4495 static struct device_attribute ipr_resource_type_attr = {
4497 .name = "resource_type",
4500 .show = ipr_show_resource_type
4504 * ipr_show_raw_mode - Show the adapter's raw mode
4505 * @dev: class device struct
4509 * number of bytes printed to buffer
4511 static ssize_t ipr_show_raw_mode(struct device *dev,
4512 struct device_attribute *attr, char *buf)
4514 struct scsi_device *sdev = to_scsi_device(dev);
4515 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4516 struct ipr_resource_entry *res;
4517 unsigned long lock_flags = 0;
4520 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4521 res = (struct ipr_resource_entry *)sdev->hostdata;
4523 len = snprintf(buf, PAGE_SIZE, "%d\n", res->raw_mode);
4526 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4531 * ipr_store_raw_mode - Change the adapter's raw mode
4532 * @dev: class device struct
4536 * number of bytes printed to buffer
4538 static ssize_t ipr_store_raw_mode(struct device *dev,
4539 struct device_attribute *attr,
4540 const char *buf, size_t count)
4542 struct scsi_device *sdev = to_scsi_device(dev);
4543 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4544 struct ipr_resource_entry *res;
4545 unsigned long lock_flags = 0;
4548 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4549 res = (struct ipr_resource_entry *)sdev->hostdata;
4551 if (ioa_cfg->sis64 && ipr_is_af_dasd_device(res)) {
4552 res->raw_mode = simple_strtoul(buf, NULL, 10);
4555 sdev_printk(KERN_INFO, res->sdev, "raw mode is %s\n",
4556 res->raw_mode ? "enabled" : "disabled");
4561 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4565 static struct device_attribute ipr_raw_mode_attr = {
4568 .mode = S_IRUGO | S_IWUSR,
4570 .show = ipr_show_raw_mode,
4571 .store = ipr_store_raw_mode
4574 static struct device_attribute *ipr_dev_attrs[] = {
4575 &ipr_adapter_handle_attr,
4576 &ipr_resource_path_attr,
4577 &ipr_device_id_attr,
4578 &ipr_resource_type_attr,
4584 * ipr_biosparam - Return the HSC mapping
4585 * @sdev: scsi device struct
4586 * @block_device: block device pointer
4587 * @capacity: capacity of the device
4588 * @parm: Array containing returned HSC values.
4590 * This function generates the HSC parms that fdisk uses.
4591 * We want to make sure we return something that places partitions
4592 * on 4k boundaries for best performance with the IOA.
4597 static int ipr_biosparam(struct scsi_device *sdev,
4598 struct block_device *block_device,
4599 sector_t capacity, int *parm)
4607 cylinders = capacity;
4608 sector_div(cylinders, (128 * 32));
4613 parm[2] = cylinders;
4619 * ipr_find_starget - Find target based on bus/target.
4620 * @starget: scsi target struct
4623 * resource entry pointer if found / NULL if not found
4625 static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
4627 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4628 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4629 struct ipr_resource_entry *res;
4631 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4632 if ((res->bus == starget->channel) &&
4633 (res->target == starget->id)) {
4641 static struct ata_port_info sata_port_info;
4644 * ipr_target_alloc - Prepare for commands to a SCSI target
4645 * @starget: scsi target struct
4647 * If the device is a SATA device, this function allocates an
4648 * ATA port with libata, else it does nothing.
4651 * 0 on success / non-0 on failure
4653 static int ipr_target_alloc(struct scsi_target *starget)
4655 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4656 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4657 struct ipr_sata_port *sata_port;
4658 struct ata_port *ap;
4659 struct ipr_resource_entry *res;
4660 unsigned long lock_flags;
4662 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4663 res = ipr_find_starget(starget);
4664 starget->hostdata = NULL;
4666 if (res && ipr_is_gata(res)) {
4667 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4668 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
4672 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
4674 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4675 sata_port->ioa_cfg = ioa_cfg;
4677 sata_port->res = res;
4679 res->sata_port = sata_port;
4680 ap->private_data = sata_port;
4681 starget->hostdata = sata_port;
4687 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4693 * ipr_target_destroy - Destroy a SCSI target
4694 * @starget: scsi target struct
4696 * If the device was a SATA device, this function frees the libata
4697 * ATA port, else it does nothing.
4700 static void ipr_target_destroy(struct scsi_target *starget)
4702 struct ipr_sata_port *sata_port = starget->hostdata;
4703 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4704 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4706 if (ioa_cfg->sis64) {
4707 if (!ipr_find_starget(starget)) {
4708 if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4709 clear_bit(starget->id, ioa_cfg->array_ids);
4710 else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4711 clear_bit(starget->id, ioa_cfg->vset_ids);
4712 else if (starget->channel == 0)
4713 clear_bit(starget->id, ioa_cfg->target_ids);
4718 starget->hostdata = NULL;
4719 ata_sas_port_destroy(sata_port->ap);
4725 * ipr_find_sdev - Find device based on bus/target/lun.
4726 * @sdev: scsi device struct
4729 * resource entry pointer if found / NULL if not found
4731 static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
4733 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4734 struct ipr_resource_entry *res;
4736 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4737 if ((res->bus == sdev->channel) &&
4738 (res->target == sdev->id) &&
4739 (res->lun == sdev->lun))
4747 * ipr_slave_destroy - Unconfigure a SCSI device
4748 * @sdev: scsi device struct
4753 static void ipr_slave_destroy(struct scsi_device *sdev)
4755 struct ipr_resource_entry *res;
4756 struct ipr_ioa_cfg *ioa_cfg;
4757 unsigned long lock_flags = 0;
4759 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4761 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4762 res = (struct ipr_resource_entry *) sdev->hostdata;
4765 res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
4766 sdev->hostdata = NULL;
4768 res->sata_port = NULL;
4770 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4774 * ipr_slave_configure - Configure a SCSI device
4775 * @sdev: scsi device struct
4777 * This function configures the specified scsi device.
4782 static int ipr_slave_configure(struct scsi_device *sdev)
4784 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4785 struct ipr_resource_entry *res;
4786 struct ata_port *ap = NULL;
4787 unsigned long lock_flags = 0;
4788 char buffer[IPR_MAX_RES_PATH_LENGTH];
4790 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4791 res = sdev->hostdata;
4793 if (ipr_is_af_dasd_device(res))
4794 sdev->type = TYPE_RAID;
4795 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
4796 sdev->scsi_level = 4;
4797 sdev->no_uld_attach = 1;
4799 if (ipr_is_vset_device(res)) {
4800 sdev->scsi_level = SCSI_SPC_3;
4801 blk_queue_rq_timeout(sdev->request_queue,
4802 IPR_VSET_RW_TIMEOUT);
4803 blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
4805 if (ipr_is_gata(res) && res->sata_port)
4806 ap = res->sata_port->ap;
4807 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4810 scsi_change_queue_depth(sdev, IPR_MAX_CMD_PER_ATA_LUN);
4811 ata_sas_slave_configure(sdev, ap);
4815 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
4816 ipr_format_res_path(ioa_cfg,
4817 res->res_path, buffer, sizeof(buffer)));
4820 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4825 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
4826 * @sdev: scsi device struct
4828 * This function initializes an ATA port so that future commands
4829 * sent through queuecommand will work.
4834 static int ipr_ata_slave_alloc(struct scsi_device *sdev)
4836 struct ipr_sata_port *sata_port = NULL;
4840 if (sdev->sdev_target)
4841 sata_port = sdev->sdev_target->hostdata;
4843 rc = ata_sas_port_init(sata_port->ap);
4845 rc = ata_sas_sync_probe(sata_port->ap);
4849 ipr_slave_destroy(sdev);
4856 * ipr_slave_alloc - Prepare for commands to a device.
4857 * @sdev: scsi device struct
4859 * This function saves a pointer to the resource entry
4860 * in the scsi device struct if the device exists. We
4861 * can then use this pointer in ipr_queuecommand when
4862 * handling new commands.
4865 * 0 on success / -ENXIO if device does not exist
4867 static int ipr_slave_alloc(struct scsi_device *sdev)
4869 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4870 struct ipr_resource_entry *res;
4871 unsigned long lock_flags;
4874 sdev->hostdata = NULL;
4876 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4878 res = ipr_find_sdev(sdev);
4883 sdev->hostdata = res;
4884 if (!ipr_is_naca_model(res))
4885 res->needs_sync_complete = 1;
4887 if (ipr_is_gata(res)) {
4888 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4889 return ipr_ata_slave_alloc(sdev);
4893 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4899 * ipr_match_lun - Match function for specified LUN
4900 * @ipr_cmd: ipr command struct
4901 * @device: device to match (sdev)
4904 * 1 if command matches sdev / 0 if command does not match sdev
4906 static int ipr_match_lun(struct ipr_cmnd *ipr_cmd, void *device)
4908 if (ipr_cmd->scsi_cmd && ipr_cmd->scsi_cmd->device == device)
4914 * ipr_wait_for_ops - Wait for matching commands to complete
4915 * @ipr_cmd: ipr command struct
4916 * @device: device to match (sdev)
4917 * @match: match function to use
4922 static int ipr_wait_for_ops(struct ipr_ioa_cfg *ioa_cfg, void *device,
4923 int (*match)(struct ipr_cmnd *, void *))
4925 struct ipr_cmnd *ipr_cmd;
4927 unsigned long flags;
4928 struct ipr_hrr_queue *hrrq;
4929 signed long timeout = IPR_ABORT_TASK_TIMEOUT;
4930 DECLARE_COMPLETION_ONSTACK(comp);
4936 for_each_hrrq(hrrq, ioa_cfg) {
4937 spin_lock_irqsave(hrrq->lock, flags);
4938 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
4939 if (match(ipr_cmd, device)) {
4940 ipr_cmd->eh_comp = ∁
4944 spin_unlock_irqrestore(hrrq->lock, flags);
4948 timeout = wait_for_completion_timeout(&comp, timeout);
4953 for_each_hrrq(hrrq, ioa_cfg) {
4954 spin_lock_irqsave(hrrq->lock, flags);
4955 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
4956 if (match(ipr_cmd, device)) {
4957 ipr_cmd->eh_comp = NULL;
4961 spin_unlock_irqrestore(hrrq->lock, flags);
4965 dev_err(&ioa_cfg->pdev->dev, "Timed out waiting for aborted commands\n");
4967 return wait ? FAILED : SUCCESS;
4976 static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
4978 struct ipr_ioa_cfg *ioa_cfg;
4979 unsigned long lock_flags = 0;
4983 ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
4984 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4986 if (!ioa_cfg->in_reset_reload && !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
4987 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
4988 dev_err(&ioa_cfg->pdev->dev,
4989 "Adapter being reset as a result of error recovery.\n");
4991 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4992 ioa_cfg->sdt_state = GET_DUMP;
4995 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4996 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4997 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4999 /* If we got hit with a host reset while we were already resetting
5000 the adapter for some reason, and the reset failed. */
5001 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
5006 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5012 * ipr_device_reset - Reset the device
5013 * @ioa_cfg: ioa config struct
5014 * @res: resource entry struct
5016 * This function issues a device reset to the affected device.
5017 * If the device is a SCSI device, a LUN reset will be sent
5018 * to the device first. If that does not work, a target reset
5019 * will be sent. If the device is a SATA device, a PHY reset will
5023 * 0 on success / non-zero on failure
5025 static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
5026 struct ipr_resource_entry *res)
5028 struct ipr_cmnd *ipr_cmd;
5029 struct ipr_ioarcb *ioarcb;
5030 struct ipr_cmd_pkt *cmd_pkt;
5031 struct ipr_ioarcb_ata_regs *regs;
5035 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5036 ioarcb = &ipr_cmd->ioarcb;
5037 cmd_pkt = &ioarcb->cmd_pkt;
5039 if (ipr_cmd->ioa_cfg->sis64) {
5040 regs = &ipr_cmd->i.ata_ioadl.regs;
5041 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
5043 regs = &ioarcb->u.add_data.u.regs;
5045 ioarcb->res_handle = res->res_handle;
5046 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5047 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
5048 if (ipr_is_gata(res)) {
5049 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
5050 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
5051 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
5054 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
5055 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5056 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5057 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) {
5058 if (ipr_cmd->ioa_cfg->sis64)
5059 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
5060 sizeof(struct ipr_ioasa_gata));
5062 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
5063 sizeof(struct ipr_ioasa_gata));
5067 return IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0;
5071 * ipr_sata_reset - Reset the SATA port
5072 * @link: SATA link to reset
5073 * @classes: class of the attached device
5075 * This function issues a SATA phy reset to the affected ATA link.
5078 * 0 on success / non-zero on failure
5080 static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
5081 unsigned long deadline)
5083 struct ipr_sata_port *sata_port = link->ap->private_data;
5084 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5085 struct ipr_resource_entry *res;
5086 unsigned long lock_flags = 0;
5090 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5091 while (ioa_cfg->in_reset_reload) {
5092 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5093 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
5094 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5097 res = sata_port->res;
5099 rc = ipr_device_reset(ioa_cfg, res);
5100 *classes = res->ata_class;
5103 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5109 * ipr_eh_dev_reset - Reset the device
5110 * @scsi_cmd: scsi command struct
5112 * This function issues a device reset to the affected device.
5113 * A LUN reset will be sent to the device first. If that does
5114 * not work, a target reset will be sent.
5119 static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
5121 struct ipr_cmnd *ipr_cmd;
5122 struct ipr_ioa_cfg *ioa_cfg;
5123 struct ipr_resource_entry *res;
5124 struct ata_port *ap;
5126 struct ipr_hrr_queue *hrrq;
5129 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
5130 res = scsi_cmd->device->hostdata;
5136 * If we are currently going through reset/reload, return failed. This will force the
5137 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
5140 if (ioa_cfg->in_reset_reload)
5142 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
5145 for_each_hrrq(hrrq, ioa_cfg) {
5146 spin_lock(&hrrq->_lock);
5147 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
5148 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
5149 if (ipr_cmd->scsi_cmd)
5150 ipr_cmd->done = ipr_scsi_eh_done;
5152 ipr_cmd->done = ipr_sata_eh_done;
5154 !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
5155 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
5156 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
5160 spin_unlock(&hrrq->_lock);
5162 res->resetting_device = 1;
5163 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
5165 if (ipr_is_gata(res) && res->sata_port) {
5166 ap = res->sata_port->ap;
5167 spin_unlock_irq(scsi_cmd->device->host->host_lock);
5168 ata_std_error_handler(ap);
5169 spin_lock_irq(scsi_cmd->device->host->host_lock);
5171 for_each_hrrq(hrrq, ioa_cfg) {
5172 spin_lock(&hrrq->_lock);
5173 list_for_each_entry(ipr_cmd,
5174 &hrrq->hrrq_pending_q, queue) {
5175 if (ipr_cmd->ioarcb.res_handle ==
5181 spin_unlock(&hrrq->_lock);
5184 rc = ipr_device_reset(ioa_cfg, res);
5185 res->resetting_device = 0;
5186 res->reset_occurred = 1;
5189 return rc ? FAILED : SUCCESS;
5192 static int ipr_eh_dev_reset(struct scsi_cmnd *cmd)
5195 struct ipr_ioa_cfg *ioa_cfg;
5197 ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
5199 spin_lock_irq(cmd->device->host->host_lock);
5200 rc = __ipr_eh_dev_reset(cmd);
5201 spin_unlock_irq(cmd->device->host->host_lock);
5204 rc = ipr_wait_for_ops(ioa_cfg, cmd->device, ipr_match_lun);
5210 * ipr_bus_reset_done - Op done function for bus reset.
5211 * @ipr_cmd: ipr command struct
5213 * This function is the op done function for a bus reset
5218 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
5220 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5221 struct ipr_resource_entry *res;
5224 if (!ioa_cfg->sis64)
5225 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
5226 if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
5227 scsi_report_bus_reset(ioa_cfg->host, res->bus);
5233 * If abort has not completed, indicate the reset has, else call the
5234 * abort's done function to wake the sleeping eh thread
5236 if (ipr_cmd->sibling->sibling)
5237 ipr_cmd->sibling->sibling = NULL;
5239 ipr_cmd->sibling->done(ipr_cmd->sibling);
5241 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5246 * ipr_abort_timeout - An abort task has timed out
5247 * @ipr_cmd: ipr command struct
5249 * This function handles when an abort task times out. If this
5250 * happens we issue a bus reset since we have resources tied
5251 * up that must be freed before returning to the midlayer.
5256 static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
5258 struct ipr_cmnd *reset_cmd;
5259 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5260 struct ipr_cmd_pkt *cmd_pkt;
5261 unsigned long lock_flags = 0;
5264 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5265 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
5266 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5270 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
5271 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5272 ipr_cmd->sibling = reset_cmd;
5273 reset_cmd->sibling = ipr_cmd;
5274 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
5275 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
5276 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5277 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
5278 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
5280 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
5281 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5286 * ipr_cancel_op - Cancel specified op
5287 * @scsi_cmd: scsi command struct
5289 * This function cancels specified op.
5294 static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
5296 struct ipr_cmnd *ipr_cmd;
5297 struct ipr_ioa_cfg *ioa_cfg;
5298 struct ipr_resource_entry *res;
5299 struct ipr_cmd_pkt *cmd_pkt;
5302 struct ipr_hrr_queue *hrrq;
5305 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
5306 res = scsi_cmd->device->hostdata;
5308 /* If we are currently going through reset/reload, return failed.
5309 * This will force the mid-layer to call ipr_eh_host_reset,
5310 * which will then go to sleep and wait for the reset to complete
5312 if (ioa_cfg->in_reset_reload ||
5313 ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
5319 * If we are aborting a timed out op, chances are that the timeout was caused
5320 * by a still not detected EEH error. In such cases, reading a register will
5321 * trigger the EEH recovery infrastructure.
5323 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5325 if (!ipr_is_gscsi(res))
5328 for_each_hrrq(hrrq, ioa_cfg) {
5329 spin_lock(&hrrq->_lock);
5330 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
5331 if (ipr_cmd->scsi_cmd == scsi_cmd) {
5332 ipr_cmd->done = ipr_scsi_eh_done;
5337 spin_unlock(&hrrq->_lock);
5343 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5344 ipr_cmd->ioarcb.res_handle = res->res_handle;
5345 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5346 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5347 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5348 ipr_cmd->u.sdev = scsi_cmd->device;
5350 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
5352 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
5353 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5356 * If the abort task timed out and we sent a bus reset, we will get
5357 * one the following responses to the abort
5359 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
5364 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5365 if (!ipr_is_naca_model(res))
5366 res->needs_sync_complete = 1;
5369 return IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS;
5373 * ipr_eh_abort - Abort a single op
5374 * @scsi_cmd: scsi command struct
5377 * 0 if scan in progress / 1 if scan is complete
5379 static int ipr_scan_finished(struct Scsi_Host *shost, unsigned long elapsed_time)
5381 unsigned long lock_flags;
5382 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
5385 spin_lock_irqsave(shost->host_lock, lock_flags);
5386 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead || ioa_cfg->scan_done)
5388 if ((elapsed_time/HZ) > (ioa_cfg->transop_timeout * 2))
5390 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5395 * ipr_eh_host_reset - Reset the host adapter
5396 * @scsi_cmd: scsi command struct
5401 static int ipr_eh_abort(struct scsi_cmnd *scsi_cmd)
5403 unsigned long flags;
5405 struct ipr_ioa_cfg *ioa_cfg;
5409 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
5411 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
5412 rc = ipr_cancel_op(scsi_cmd);
5413 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
5416 rc = ipr_wait_for_ops(ioa_cfg, scsi_cmd->device, ipr_match_lun);
5422 * ipr_handle_other_interrupt - Handle "other" interrupts
5423 * @ioa_cfg: ioa config struct
5424 * @int_reg: interrupt register
5427 * IRQ_NONE / IRQ_HANDLED
5429 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
5432 irqreturn_t rc = IRQ_HANDLED;
5435 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
5436 int_reg &= ~int_mask_reg;
5438 /* If an interrupt on the adapter did not occur, ignore it.
5439 * Or in the case of SIS 64, check for a stage change interrupt.
5441 if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
5442 if (ioa_cfg->sis64) {
5443 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
5444 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5445 if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
5447 /* clear stage change */
5448 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
5449 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5450 list_del(&ioa_cfg->reset_cmd->queue);
5451 del_timer(&ioa_cfg->reset_cmd->timer);
5452 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5460 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
5461 /* Mask the interrupt */
5462 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
5463 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5465 list_del(&ioa_cfg->reset_cmd->queue);
5466 del_timer(&ioa_cfg->reset_cmd->timer);
5467 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5468 } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
5469 if (ioa_cfg->clear_isr) {
5470 if (ipr_debug && printk_ratelimit())
5471 dev_err(&ioa_cfg->pdev->dev,
5472 "Spurious interrupt detected. 0x%08X\n", int_reg);
5473 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5474 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5478 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
5479 ioa_cfg->ioa_unit_checked = 1;
5480 else if (int_reg & IPR_PCII_NO_HOST_RRQ)
5481 dev_err(&ioa_cfg->pdev->dev,
5482 "No Host RRQ. 0x%08X\n", int_reg);
5484 dev_err(&ioa_cfg->pdev->dev,
5485 "Permanent IOA failure. 0x%08X\n", int_reg);
5487 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5488 ioa_cfg->sdt_state = GET_DUMP;
5490 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
5491 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5498 * ipr_isr_eh - Interrupt service routine error handler
5499 * @ioa_cfg: ioa config struct
5500 * @msg: message to log
5505 static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg, u16 number)
5507 ioa_cfg->errors_logged++;
5508 dev_err(&ioa_cfg->pdev->dev, "%s %d\n", msg, number);
5510 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5511 ioa_cfg->sdt_state = GET_DUMP;
5513 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5516 static int ipr_process_hrrq(struct ipr_hrr_queue *hrr_queue, int budget,
5517 struct list_head *doneq)
5521 struct ipr_cmnd *ipr_cmd;
5522 struct ipr_ioa_cfg *ioa_cfg = hrr_queue->ioa_cfg;
5525 /* If interrupts are disabled, ignore the interrupt */
5526 if (!hrr_queue->allow_interrupts)
5529 while ((be32_to_cpu(*hrr_queue->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5530 hrr_queue->toggle_bit) {
5532 cmd_index = (be32_to_cpu(*hrr_queue->hrrq_curr) &
5533 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >>
5534 IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
5536 if (unlikely(cmd_index > hrr_queue->max_cmd_id ||
5537 cmd_index < hrr_queue->min_cmd_id)) {
5539 "Invalid response handle from IOA: ",
5544 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
5545 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5547 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
5549 list_move_tail(&ipr_cmd->queue, doneq);
5551 if (hrr_queue->hrrq_curr < hrr_queue->hrrq_end) {
5552 hrr_queue->hrrq_curr++;
5554 hrr_queue->hrrq_curr = hrr_queue->hrrq_start;
5555 hrr_queue->toggle_bit ^= 1u;
5558 if (budget > 0 && num_hrrq >= budget)
5565 static int ipr_iopoll(struct blk_iopoll *iop, int budget)
5567 struct ipr_ioa_cfg *ioa_cfg;
5568 struct ipr_hrr_queue *hrrq;
5569 struct ipr_cmnd *ipr_cmd, *temp;
5570 unsigned long hrrq_flags;
5574 hrrq = container_of(iop, struct ipr_hrr_queue, iopoll);
5575 ioa_cfg = hrrq->ioa_cfg;
5577 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5578 completed_ops = ipr_process_hrrq(hrrq, budget, &doneq);
5580 if (completed_ops < budget)
5581 blk_iopoll_complete(iop);
5582 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5584 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5585 list_del(&ipr_cmd->queue);
5586 del_timer(&ipr_cmd->timer);
5587 ipr_cmd->fast_done(ipr_cmd);
5590 return completed_ops;
5594 * ipr_isr - Interrupt service routine
5596 * @devp: pointer to ioa config struct
5599 * IRQ_NONE / IRQ_HANDLED
5601 static irqreturn_t ipr_isr(int irq, void *devp)
5603 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
5604 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
5605 unsigned long hrrq_flags = 0;
5609 struct ipr_cmnd *ipr_cmd, *temp;
5610 irqreturn_t rc = IRQ_NONE;
5613 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5614 /* If interrupts are disabled, ignore the interrupt */
5615 if (!hrrq->allow_interrupts) {
5616 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5621 if (ipr_process_hrrq(hrrq, -1, &doneq)) {
5624 if (!ioa_cfg->clear_isr)
5627 /* Clear the PCI interrupt */
5630 writel(IPR_PCII_HRRQ_UPDATED,
5631 ioa_cfg->regs.clr_interrupt_reg32);
5632 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5633 } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
5634 num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
5636 } else if (rc == IRQ_NONE && irq_none == 0) {
5637 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5639 } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
5640 int_reg & IPR_PCII_HRRQ_UPDATED) {
5642 "Error clearing HRRQ: ", num_hrrq);
5649 if (unlikely(rc == IRQ_NONE))
5650 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
5652 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5653 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5654 list_del(&ipr_cmd->queue);
5655 del_timer(&ipr_cmd->timer);
5656 ipr_cmd->fast_done(ipr_cmd);
5662 * ipr_isr_mhrrq - Interrupt service routine
5664 * @devp: pointer to ioa config struct
5667 * IRQ_NONE / IRQ_HANDLED
5669 static irqreturn_t ipr_isr_mhrrq(int irq, void *devp)
5671 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
5672 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
5673 unsigned long hrrq_flags = 0;
5674 struct ipr_cmnd *ipr_cmd, *temp;
5675 irqreturn_t rc = IRQ_NONE;
5678 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5680 /* If interrupts are disabled, ignore the interrupt */
5681 if (!hrrq->allow_interrupts) {
5682 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5686 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
5687 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5689 if (!blk_iopoll_sched_prep(&hrrq->iopoll))
5690 blk_iopoll_sched(&hrrq->iopoll);
5691 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5695 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5698 if (ipr_process_hrrq(hrrq, -1, &doneq))
5702 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5704 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5705 list_del(&ipr_cmd->queue);
5706 del_timer(&ipr_cmd->timer);
5707 ipr_cmd->fast_done(ipr_cmd);
5713 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
5714 * @ioa_cfg: ioa config struct
5715 * @ipr_cmd: ipr command struct
5718 * 0 on success / -1 on failure
5720 static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
5721 struct ipr_cmnd *ipr_cmd)
5724 struct scatterlist *sg;
5726 u32 ioadl_flags = 0;
5727 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5728 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5729 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
5731 length = scsi_bufflen(scsi_cmd);
5735 nseg = scsi_dma_map(scsi_cmd);
5737 if (printk_ratelimit())
5738 dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
5742 ipr_cmd->dma_use_sg = nseg;
5744 ioarcb->data_transfer_length = cpu_to_be32(length);
5746 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
5748 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5749 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5750 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5751 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
5752 ioadl_flags = IPR_IOADL_FLAGS_READ;
5754 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5755 ioadl64[i].flags = cpu_to_be32(ioadl_flags);
5756 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
5757 ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
5760 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5765 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5766 * @ioa_cfg: ioa config struct
5767 * @ipr_cmd: ipr command struct
5770 * 0 on success / -1 on failure
5772 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5773 struct ipr_cmnd *ipr_cmd)
5776 struct scatterlist *sg;
5778 u32 ioadl_flags = 0;
5779 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5780 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5781 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
5783 length = scsi_bufflen(scsi_cmd);
5787 nseg = scsi_dma_map(scsi_cmd);
5789 dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
5793 ipr_cmd->dma_use_sg = nseg;
5795 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5796 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5797 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5798 ioarcb->data_transfer_length = cpu_to_be32(length);
5800 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5801 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
5802 ioadl_flags = IPR_IOADL_FLAGS_READ;
5803 ioarcb->read_data_transfer_length = cpu_to_be32(length);
5804 ioarcb->read_ioadl_len =
5805 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5808 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
5809 ioadl = ioarcb->u.add_data.u.ioadl;
5810 ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
5811 offsetof(struct ipr_ioarcb, u.add_data));
5812 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5815 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5816 ioadl[i].flags_and_data_len =
5817 cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5818 ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
5821 ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5826 * ipr_erp_done - Process completion of ERP for a device
5827 * @ipr_cmd: ipr command struct
5829 * This function copies the sense buffer into the scsi_cmd
5830 * struct and pushes the scsi_done function.
5835 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
5837 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5838 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5839 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5841 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5842 scsi_cmd->result |= (DID_ERROR << 16);
5843 scmd_printk(KERN_ERR, scsi_cmd,
5844 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
5846 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
5847 SCSI_SENSE_BUFFERSIZE);
5851 if (!ipr_is_naca_model(res))
5852 res->needs_sync_complete = 1;
5855 scsi_dma_unmap(ipr_cmd->scsi_cmd);
5856 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5857 scsi_cmd->scsi_done(scsi_cmd);
5861 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5862 * @ipr_cmd: ipr command struct
5867 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
5869 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5870 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5871 dma_addr_t dma_addr = ipr_cmd->dma_addr;
5873 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
5874 ioarcb->data_transfer_length = 0;
5875 ioarcb->read_data_transfer_length = 0;
5876 ioarcb->ioadl_len = 0;
5877 ioarcb->read_ioadl_len = 0;
5878 ioasa->hdr.ioasc = 0;
5879 ioasa->hdr.residual_data_len = 0;
5881 if (ipr_cmd->ioa_cfg->sis64)
5882 ioarcb->u.sis64_addr_data.data_ioadl_addr =
5883 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
5885 ioarcb->write_ioadl_addr =
5886 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
5887 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5892 * ipr_erp_request_sense - Send request sense to a device
5893 * @ipr_cmd: ipr command struct
5895 * This function sends a request sense to a device as a result
5896 * of a check condition.
5901 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
5903 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5904 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5906 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5907 ipr_erp_done(ipr_cmd);
5911 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5913 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
5914 cmd_pkt->cdb[0] = REQUEST_SENSE;
5915 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
5916 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
5917 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5918 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
5920 ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
5921 SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
5923 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
5924 IPR_REQUEST_SENSE_TIMEOUT * 2);
5928 * ipr_erp_cancel_all - Send cancel all to a device
5929 * @ipr_cmd: ipr command struct
5931 * This function sends a cancel all to a device to clear the
5932 * queue. If we are running TCQ on the device, QERR is set to 1,
5933 * which means all outstanding ops have been dropped on the floor.
5934 * Cancel all will return them to us.
5939 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
5941 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5942 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5943 struct ipr_cmd_pkt *cmd_pkt;
5947 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5949 if (!scsi_cmd->device->simple_tags) {
5950 ipr_erp_request_sense(ipr_cmd);
5954 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5955 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5956 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5958 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
5959 IPR_CANCEL_ALL_TIMEOUT);
5963 * ipr_dump_ioasa - Dump contents of IOASA
5964 * @ioa_cfg: ioa config struct
5965 * @ipr_cmd: ipr command struct
5966 * @res: resource entry struct
5968 * This function is invoked by the interrupt handler when ops
5969 * fail. It will log the IOASA if appropriate. Only called
5975 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
5976 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
5980 u32 ioasc, fd_ioasc;
5981 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5982 __be32 *ioasa_data = (__be32 *)ioasa;
5985 ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
5986 fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
5991 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
5994 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
5995 error_index = ipr_get_error(fd_ioasc);
5997 error_index = ipr_get_error(ioasc);
5999 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
6000 /* Don't log an error if the IOA already logged one */
6001 if (ioasa->hdr.ilid != 0)
6004 if (!ipr_is_gscsi(res))
6007 if (ipr_error_table[error_index].log_ioasa == 0)
6011 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
6013 data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
6014 if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
6015 data_len = sizeof(struct ipr_ioasa64);
6016 else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
6017 data_len = sizeof(struct ipr_ioasa);
6019 ipr_err("IOASA Dump:\n");
6021 for (i = 0; i < data_len / 4; i += 4) {
6022 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
6023 be32_to_cpu(ioasa_data[i]),
6024 be32_to_cpu(ioasa_data[i+1]),
6025 be32_to_cpu(ioasa_data[i+2]),
6026 be32_to_cpu(ioasa_data[i+3]));
6031 * ipr_gen_sense - Generate SCSI sense data from an IOASA
6033 * @sense_buf: sense data buffer
6038 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
6041 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
6042 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
6043 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
6044 u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
6046 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
6048 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
6051 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
6053 if (ipr_is_vset_device(res) &&
6054 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
6055 ioasa->u.vset.failing_lba_hi != 0) {
6056 sense_buf[0] = 0x72;
6057 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
6058 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
6059 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
6063 sense_buf[9] = 0x0A;
6064 sense_buf[10] = 0x80;
6066 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
6068 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
6069 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
6070 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
6071 sense_buf[15] = failing_lba & 0x000000ff;
6073 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
6075 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
6076 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
6077 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
6078 sense_buf[19] = failing_lba & 0x000000ff;
6080 sense_buf[0] = 0x70;
6081 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
6082 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
6083 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
6085 /* Illegal request */
6086 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
6087 (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
6088 sense_buf[7] = 10; /* additional length */
6090 /* IOARCB was in error */
6091 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
6092 sense_buf[15] = 0xC0;
6093 else /* Parameter data was invalid */
6094 sense_buf[15] = 0x80;
6097 ((IPR_FIELD_POINTER_MASK &
6098 be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
6100 (IPR_FIELD_POINTER_MASK &
6101 be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
6103 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
6104 if (ipr_is_vset_device(res))
6105 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
6107 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
6109 sense_buf[0] |= 0x80; /* Or in the Valid bit */
6110 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
6111 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
6112 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
6113 sense_buf[6] = failing_lba & 0x000000ff;
6116 sense_buf[7] = 6; /* additional length */
6122 * ipr_get_autosense - Copy autosense data to sense buffer
6123 * @ipr_cmd: ipr command struct
6125 * This function copies the autosense buffer to the buffer
6126 * in the scsi_cmd, if there is autosense available.
6129 * 1 if autosense was available / 0 if not
6131 static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
6133 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
6134 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
6136 if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
6139 if (ipr_cmd->ioa_cfg->sis64)
6140 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
6141 min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
6142 SCSI_SENSE_BUFFERSIZE));
6144 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
6145 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
6146 SCSI_SENSE_BUFFERSIZE));
6151 * ipr_erp_start - Process an error response for a SCSI op
6152 * @ioa_cfg: ioa config struct
6153 * @ipr_cmd: ipr command struct
6155 * This function determines whether or not to initiate ERP
6156 * on the affected device.
6161 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
6162 struct ipr_cmnd *ipr_cmd)
6164 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
6165 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
6166 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6167 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
6170 ipr_scsi_eh_done(ipr_cmd);
6174 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
6175 ipr_gen_sense(ipr_cmd);
6177 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6179 switch (masked_ioasc) {
6180 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
6181 if (ipr_is_naca_model(res))
6182 scsi_cmd->result |= (DID_ABORT << 16);
6184 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6186 case IPR_IOASC_IR_RESOURCE_HANDLE:
6187 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
6188 scsi_cmd->result |= (DID_NO_CONNECT << 16);
6190 case IPR_IOASC_HW_SEL_TIMEOUT:
6191 scsi_cmd->result |= (DID_NO_CONNECT << 16);
6192 if (!ipr_is_naca_model(res))
6193 res->needs_sync_complete = 1;
6195 case IPR_IOASC_SYNC_REQUIRED:
6197 res->needs_sync_complete = 1;
6198 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6200 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
6201 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
6202 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
6204 case IPR_IOASC_BUS_WAS_RESET:
6205 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
6207 * Report the bus reset and ask for a retry. The device
6208 * will give CC/UA the next command.
6210 if (!res->resetting_device)
6211 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
6212 scsi_cmd->result |= (DID_ERROR << 16);
6213 if (!ipr_is_naca_model(res))
6214 res->needs_sync_complete = 1;
6216 case IPR_IOASC_HW_DEV_BUS_STATUS:
6217 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
6218 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
6219 if (!ipr_get_autosense(ipr_cmd)) {
6220 if (!ipr_is_naca_model(res)) {
6221 ipr_erp_cancel_all(ipr_cmd);
6226 if (!ipr_is_naca_model(res))
6227 res->needs_sync_complete = 1;
6229 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
6231 case IPR_IOASC_IR_NON_OPTIMIZED:
6232 if (res->raw_mode) {
6234 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6236 scsi_cmd->result |= (DID_ERROR << 16);
6239 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
6240 scsi_cmd->result |= (DID_ERROR << 16);
6241 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
6242 res->needs_sync_complete = 1;
6246 scsi_dma_unmap(ipr_cmd->scsi_cmd);
6247 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6248 scsi_cmd->scsi_done(scsi_cmd);
6252 * ipr_scsi_done - mid-layer done function
6253 * @ipr_cmd: ipr command struct
6255 * This function is invoked by the interrupt handler for
6256 * ops generated by the SCSI mid-layer
6261 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
6263 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6264 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
6265 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6266 unsigned long lock_flags;
6268 scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
6270 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
6271 scsi_dma_unmap(scsi_cmd);
6273 spin_lock_irqsave(ipr_cmd->hrrq->lock, lock_flags);
6274 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6275 scsi_cmd->scsi_done(scsi_cmd);
6276 spin_unlock_irqrestore(ipr_cmd->hrrq->lock, lock_flags);
6278 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6279 spin_lock(&ipr_cmd->hrrq->_lock);
6280 ipr_erp_start(ioa_cfg, ipr_cmd);
6281 spin_unlock(&ipr_cmd->hrrq->_lock);
6282 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6287 * ipr_queuecommand - Queue a mid-layer request
6288 * @shost: scsi host struct
6289 * @scsi_cmd: scsi command struct
6291 * This function queues a request generated by the mid-layer.
6295 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
6296 * SCSI_MLQUEUE_HOST_BUSY if host is busy
6298 static int ipr_queuecommand(struct Scsi_Host *shost,
6299 struct scsi_cmnd *scsi_cmd)
6301 struct ipr_ioa_cfg *ioa_cfg;
6302 struct ipr_resource_entry *res;
6303 struct ipr_ioarcb *ioarcb;
6304 struct ipr_cmnd *ipr_cmd;
6305 unsigned long hrrq_flags, lock_flags;
6307 struct ipr_hrr_queue *hrrq;
6310 ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
6312 scsi_cmd->result = (DID_OK << 16);
6313 res = scsi_cmd->device->hostdata;
6315 if (ipr_is_gata(res) && res->sata_port) {
6316 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6317 rc = ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
6318 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6322 hrrq_id = ipr_get_hrrq_index(ioa_cfg);
6323 hrrq = &ioa_cfg->hrrq[hrrq_id];
6325 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6327 * We are currently blocking all devices due to a host reset
6328 * We have told the host to stop giving us new requests, but
6329 * ERP ops don't count. FIXME
6331 if (unlikely(!hrrq->allow_cmds && !hrrq->ioa_is_dead && !hrrq->removing_ioa)) {
6332 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6333 return SCSI_MLQUEUE_HOST_BUSY;
6337 * FIXME - Create scsi_set_host_offline interface
6338 * and the ioa_is_dead check can be removed
6340 if (unlikely(hrrq->ioa_is_dead || hrrq->removing_ioa || !res)) {
6341 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6345 ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
6346 if (ipr_cmd == NULL) {
6347 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6348 return SCSI_MLQUEUE_HOST_BUSY;
6350 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6352 ipr_init_ipr_cmnd(ipr_cmd, ipr_scsi_done);
6353 ioarcb = &ipr_cmd->ioarcb;
6355 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
6356 ipr_cmd->scsi_cmd = scsi_cmd;
6357 ipr_cmd->done = ipr_scsi_eh_done;
6359 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
6360 if (scsi_cmd->underflow == 0)
6361 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
6363 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6364 if (ipr_is_gscsi(res) && res->reset_occurred) {
6365 res->reset_occurred = 0;
6366 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
6368 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
6369 if (scsi_cmd->flags & SCMD_TAGGED)
6370 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_SIMPLE_TASK;
6372 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_UNTAGGED_TASK;
6375 if (scsi_cmd->cmnd[0] >= 0xC0 &&
6376 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE)) {
6377 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6379 if (res->raw_mode && ipr_is_af_dasd_device(res))
6380 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_PIPE;
6383 rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
6385 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
6387 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6388 if (unlikely(rc || (!hrrq->allow_cmds && !hrrq->ioa_is_dead))) {
6389 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
6390 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6392 scsi_dma_unmap(scsi_cmd);
6393 return SCSI_MLQUEUE_HOST_BUSY;
6396 if (unlikely(hrrq->ioa_is_dead)) {
6397 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
6398 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6399 scsi_dma_unmap(scsi_cmd);
6403 ioarcb->res_handle = res->res_handle;
6404 if (res->needs_sync_complete) {
6405 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
6406 res->needs_sync_complete = 0;
6408 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_pending_q);
6409 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
6410 ipr_send_command(ipr_cmd);
6411 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6415 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6416 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
6417 scsi_cmd->result = (DID_NO_CONNECT << 16);
6418 scsi_cmd->scsi_done(scsi_cmd);
6419 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6424 * ipr_ioctl - IOCTL handler
6425 * @sdev: scsi device struct
6430 * 0 on success / other on failure
6432 static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
6434 struct ipr_resource_entry *res;
6436 res = (struct ipr_resource_entry *)sdev->hostdata;
6437 if (res && ipr_is_gata(res)) {
6438 if (cmd == HDIO_GET_IDENTITY)
6440 return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
6447 * ipr_info - Get information about the card/driver
6448 * @scsi_host: scsi host struct
6451 * pointer to buffer with description string
6453 static const char *ipr_ioa_info(struct Scsi_Host *host)
6455 static char buffer[512];
6456 struct ipr_ioa_cfg *ioa_cfg;
6457 unsigned long lock_flags = 0;
6459 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
6461 spin_lock_irqsave(host->host_lock, lock_flags);
6462 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
6463 spin_unlock_irqrestore(host->host_lock, lock_flags);
6468 static struct scsi_host_template driver_template = {
6469 .module = THIS_MODULE,
6471 .info = ipr_ioa_info,
6473 .queuecommand = ipr_queuecommand,
6474 .eh_abort_handler = ipr_eh_abort,
6475 .eh_device_reset_handler = ipr_eh_dev_reset,
6476 .eh_host_reset_handler = ipr_eh_host_reset,
6477 .slave_alloc = ipr_slave_alloc,
6478 .slave_configure = ipr_slave_configure,
6479 .slave_destroy = ipr_slave_destroy,
6480 .scan_finished = ipr_scan_finished,
6481 .target_alloc = ipr_target_alloc,
6482 .target_destroy = ipr_target_destroy,
6483 .change_queue_depth = ipr_change_queue_depth,
6484 .bios_param = ipr_biosparam,
6485 .can_queue = IPR_MAX_COMMANDS,
6487 .sg_tablesize = IPR_MAX_SGLIST,
6488 .max_sectors = IPR_IOA_MAX_SECTORS,
6489 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
6490 .use_clustering = ENABLE_CLUSTERING,
6491 .shost_attrs = ipr_ioa_attrs,
6492 .sdev_attrs = ipr_dev_attrs,
6493 .proc_name = IPR_NAME,
6498 * ipr_ata_phy_reset - libata phy_reset handler
6499 * @ap: ata port to reset
6502 static void ipr_ata_phy_reset(struct ata_port *ap)
6504 unsigned long flags;
6505 struct ipr_sata_port *sata_port = ap->private_data;
6506 struct ipr_resource_entry *res = sata_port->res;
6507 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6511 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6512 while (ioa_cfg->in_reset_reload) {
6513 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6514 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6515 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6518 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
6521 rc = ipr_device_reset(ioa_cfg, res);
6524 ap->link.device[0].class = ATA_DEV_NONE;
6528 ap->link.device[0].class = res->ata_class;
6529 if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
6530 ap->link.device[0].class = ATA_DEV_NONE;
6533 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6538 * ipr_ata_post_internal - Cleanup after an internal command
6539 * @qc: ATA queued command
6544 static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
6546 struct ipr_sata_port *sata_port = qc->ap->private_data;
6547 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6548 struct ipr_cmnd *ipr_cmd;
6549 struct ipr_hrr_queue *hrrq;
6550 unsigned long flags;
6552 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6553 while (ioa_cfg->in_reset_reload) {
6554 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6555 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6556 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6559 for_each_hrrq(hrrq, ioa_cfg) {
6560 spin_lock(&hrrq->_lock);
6561 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
6562 if (ipr_cmd->qc == qc) {
6563 ipr_device_reset(ioa_cfg, sata_port->res);
6567 spin_unlock(&hrrq->_lock);
6569 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6573 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
6574 * @regs: destination
6575 * @tf: source ATA taskfile
6580 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
6581 struct ata_taskfile *tf)
6583 regs->feature = tf->feature;
6584 regs->nsect = tf->nsect;
6585 regs->lbal = tf->lbal;
6586 regs->lbam = tf->lbam;
6587 regs->lbah = tf->lbah;
6588 regs->device = tf->device;
6589 regs->command = tf->command;
6590 regs->hob_feature = tf->hob_feature;
6591 regs->hob_nsect = tf->hob_nsect;
6592 regs->hob_lbal = tf->hob_lbal;
6593 regs->hob_lbam = tf->hob_lbam;
6594 regs->hob_lbah = tf->hob_lbah;
6595 regs->ctl = tf->ctl;
6599 * ipr_sata_done - done function for SATA commands
6600 * @ipr_cmd: ipr command struct
6602 * This function is invoked by the interrupt handler for
6603 * ops generated by the SCSI mid-layer to SATA devices
6608 static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
6610 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6611 struct ata_queued_cmd *qc = ipr_cmd->qc;
6612 struct ipr_sata_port *sata_port = qc->ap->private_data;
6613 struct ipr_resource_entry *res = sata_port->res;
6614 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6616 spin_lock(&ipr_cmd->hrrq->_lock);
6617 if (ipr_cmd->ioa_cfg->sis64)
6618 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
6619 sizeof(struct ipr_ioasa_gata));
6621 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
6622 sizeof(struct ipr_ioasa_gata));
6623 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6625 if (be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
6626 scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
6628 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
6629 qc->err_mask |= __ac_err_mask(sata_port->ioasa.status);
6631 qc->err_mask |= ac_err_mask(sata_port->ioasa.status);
6632 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6633 spin_unlock(&ipr_cmd->hrrq->_lock);
6634 ata_qc_complete(qc);
6638 * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
6639 * @ipr_cmd: ipr command struct
6640 * @qc: ATA queued command
6643 static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
6644 struct ata_queued_cmd *qc)
6646 u32 ioadl_flags = 0;
6647 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6648 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ata_ioadl.ioadl64;
6649 struct ipr_ioadl64_desc *last_ioadl64 = NULL;
6650 int len = qc->nbytes;
6651 struct scatterlist *sg;
6653 dma_addr_t dma_addr = ipr_cmd->dma_addr;
6658 if (qc->dma_dir == DMA_TO_DEVICE) {
6659 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6660 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6661 } else if (qc->dma_dir == DMA_FROM_DEVICE)
6662 ioadl_flags = IPR_IOADL_FLAGS_READ;
6664 ioarcb->data_transfer_length = cpu_to_be32(len);
6666 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
6667 ioarcb->u.sis64_addr_data.data_ioadl_addr =
6668 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl.ioadl64));
6670 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6671 ioadl64->flags = cpu_to_be32(ioadl_flags);
6672 ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
6673 ioadl64->address = cpu_to_be64(sg_dma_address(sg));
6675 last_ioadl64 = ioadl64;
6679 if (likely(last_ioadl64))
6680 last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6684 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
6685 * @ipr_cmd: ipr command struct
6686 * @qc: ATA queued command
6689 static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
6690 struct ata_queued_cmd *qc)
6692 u32 ioadl_flags = 0;
6693 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6694 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
6695 struct ipr_ioadl_desc *last_ioadl = NULL;
6696 int len = qc->nbytes;
6697 struct scatterlist *sg;
6703 if (qc->dma_dir == DMA_TO_DEVICE) {
6704 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6705 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6706 ioarcb->data_transfer_length = cpu_to_be32(len);
6708 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6709 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
6710 ioadl_flags = IPR_IOADL_FLAGS_READ;
6711 ioarcb->read_data_transfer_length = cpu_to_be32(len);
6712 ioarcb->read_ioadl_len =
6713 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6716 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6717 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
6718 ioadl->address = cpu_to_be32(sg_dma_address(sg));
6724 if (likely(last_ioadl))
6725 last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6729 * ipr_qc_defer - Get a free ipr_cmd
6730 * @qc: queued command
6735 static int ipr_qc_defer(struct ata_queued_cmd *qc)
6737 struct ata_port *ap = qc->ap;
6738 struct ipr_sata_port *sata_port = ap->private_data;
6739 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6740 struct ipr_cmnd *ipr_cmd;
6741 struct ipr_hrr_queue *hrrq;
6744 hrrq_id = ipr_get_hrrq_index(ioa_cfg);
6745 hrrq = &ioa_cfg->hrrq[hrrq_id];
6747 qc->lldd_task = NULL;
6748 spin_lock(&hrrq->_lock);
6749 if (unlikely(hrrq->ioa_is_dead)) {
6750 spin_unlock(&hrrq->_lock);
6754 if (unlikely(!hrrq->allow_cmds)) {
6755 spin_unlock(&hrrq->_lock);
6756 return ATA_DEFER_LINK;
6759 ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
6760 if (ipr_cmd == NULL) {
6761 spin_unlock(&hrrq->_lock);
6762 return ATA_DEFER_LINK;
6765 qc->lldd_task = ipr_cmd;
6766 spin_unlock(&hrrq->_lock);
6771 * ipr_qc_issue - Issue a SATA qc to a device
6772 * @qc: queued command
6777 static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
6779 struct ata_port *ap = qc->ap;
6780 struct ipr_sata_port *sata_port = ap->private_data;
6781 struct ipr_resource_entry *res = sata_port->res;
6782 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6783 struct ipr_cmnd *ipr_cmd;
6784 struct ipr_ioarcb *ioarcb;
6785 struct ipr_ioarcb_ata_regs *regs;
6787 if (qc->lldd_task == NULL)
6790 ipr_cmd = qc->lldd_task;
6791 if (ipr_cmd == NULL)
6792 return AC_ERR_SYSTEM;
6794 qc->lldd_task = NULL;
6795 spin_lock(&ipr_cmd->hrrq->_lock);
6796 if (unlikely(!ipr_cmd->hrrq->allow_cmds ||
6797 ipr_cmd->hrrq->ioa_is_dead)) {
6798 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6799 spin_unlock(&ipr_cmd->hrrq->_lock);
6800 return AC_ERR_SYSTEM;
6803 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
6804 ioarcb = &ipr_cmd->ioarcb;
6806 if (ioa_cfg->sis64) {
6807 regs = &ipr_cmd->i.ata_ioadl.regs;
6808 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
6810 regs = &ioarcb->u.add_data.u.regs;
6812 memset(regs, 0, sizeof(*regs));
6813 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
6815 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
6817 ipr_cmd->done = ipr_sata_done;
6818 ipr_cmd->ioarcb.res_handle = res->res_handle;
6819 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
6820 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6821 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
6822 ipr_cmd->dma_use_sg = qc->n_elem;
6825 ipr_build_ata_ioadl64(ipr_cmd, qc);
6827 ipr_build_ata_ioadl(ipr_cmd, qc);
6829 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
6830 ipr_copy_sata_tf(regs, &qc->tf);
6831 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
6832 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
6834 switch (qc->tf.protocol) {
6835 case ATA_PROT_NODATA:
6840 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6843 case ATAPI_PROT_PIO:
6844 case ATAPI_PROT_NODATA:
6845 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6848 case ATAPI_PROT_DMA:
6849 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6850 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6855 spin_unlock(&ipr_cmd->hrrq->_lock);
6856 return AC_ERR_INVALID;
6859 ipr_send_command(ipr_cmd);
6860 spin_unlock(&ipr_cmd->hrrq->_lock);
6866 * ipr_qc_fill_rtf - Read result TF
6867 * @qc: ATA queued command
6872 static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
6874 struct ipr_sata_port *sata_port = qc->ap->private_data;
6875 struct ipr_ioasa_gata *g = &sata_port->ioasa;
6876 struct ata_taskfile *tf = &qc->result_tf;
6878 tf->feature = g->error;
6879 tf->nsect = g->nsect;
6883 tf->device = g->device;
6884 tf->command = g->status;
6885 tf->hob_nsect = g->hob_nsect;
6886 tf->hob_lbal = g->hob_lbal;
6887 tf->hob_lbam = g->hob_lbam;
6888 tf->hob_lbah = g->hob_lbah;
6893 static struct ata_port_operations ipr_sata_ops = {
6894 .phy_reset = ipr_ata_phy_reset,
6895 .hardreset = ipr_sata_reset,
6896 .post_internal_cmd = ipr_ata_post_internal,
6897 .qc_prep = ata_noop_qc_prep,
6898 .qc_defer = ipr_qc_defer,
6899 .qc_issue = ipr_qc_issue,
6900 .qc_fill_rtf = ipr_qc_fill_rtf,
6901 .port_start = ata_sas_port_start,
6902 .port_stop = ata_sas_port_stop
6905 static struct ata_port_info sata_port_info = {
6906 .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA |
6908 .pio_mask = ATA_PIO4_ONLY,
6909 .mwdma_mask = ATA_MWDMA2,
6910 .udma_mask = ATA_UDMA6,
6911 .port_ops = &ipr_sata_ops
6914 #ifdef CONFIG_PPC_PSERIES
6915 static const u16 ipr_blocked_processors[] = {
6927 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
6928 * @ioa_cfg: ioa cfg struct
6930 * Adapters that use Gemstone revision < 3.1 do not work reliably on
6931 * certain pSeries hardware. This function determines if the given
6932 * adapter is in one of these confgurations or not.
6935 * 1 if adapter is not supported / 0 if adapter is supported
6937 static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
6941 if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
6942 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++) {
6943 if (pvr_version_is(ipr_blocked_processors[i]))
6950 #define ipr_invalid_adapter(ioa_cfg) 0
6954 * ipr_ioa_bringdown_done - IOA bring down completion.
6955 * @ipr_cmd: ipr command struct
6957 * This function processes the completion of an adapter bring down.
6958 * It wakes any reset sleepers.
6963 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
6965 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6969 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
6971 spin_unlock_irq(ioa_cfg->host->host_lock);
6972 scsi_unblock_requests(ioa_cfg->host);
6973 spin_lock_irq(ioa_cfg->host->host_lock);
6976 ioa_cfg->in_reset_reload = 0;
6977 ioa_cfg->reset_retries = 0;
6978 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
6979 spin_lock(&ioa_cfg->hrrq[i]._lock);
6980 ioa_cfg->hrrq[i].ioa_is_dead = 1;
6981 spin_unlock(&ioa_cfg->hrrq[i]._lock);
6985 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6986 wake_up_all(&ioa_cfg->reset_wait_q);
6989 return IPR_RC_JOB_RETURN;
6993 * ipr_ioa_reset_done - IOA reset completion.
6994 * @ipr_cmd: ipr command struct
6996 * This function processes the completion of an adapter reset.
6997 * It schedules any necessary mid-layer add/removes and
6998 * wakes any reset sleepers.
7003 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
7005 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7006 struct ipr_resource_entry *res;
7007 struct ipr_hostrcb *hostrcb, *temp;
7011 ioa_cfg->in_reset_reload = 0;
7012 for (j = 0; j < ioa_cfg->hrrq_num; j++) {
7013 spin_lock(&ioa_cfg->hrrq[j]._lock);
7014 ioa_cfg->hrrq[j].allow_cmds = 1;
7015 spin_unlock(&ioa_cfg->hrrq[j]._lock);
7018 ioa_cfg->reset_cmd = NULL;
7019 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
7021 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
7022 if (res->add_to_ml || res->del_from_ml) {
7027 schedule_work(&ioa_cfg->work_q);
7029 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
7030 list_del(&hostrcb->queue);
7031 if (i++ < IPR_NUM_LOG_HCAMS)
7032 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
7034 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
7037 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
7038 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
7040 ioa_cfg->reset_retries = 0;
7041 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
7042 wake_up_all(&ioa_cfg->reset_wait_q);
7044 spin_unlock(ioa_cfg->host->host_lock);
7045 scsi_unblock_requests(ioa_cfg->host);
7046 spin_lock(ioa_cfg->host->host_lock);
7048 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
7049 scsi_block_requests(ioa_cfg->host);
7051 schedule_work(&ioa_cfg->work_q);
7053 return IPR_RC_JOB_RETURN;
7057 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
7058 * @supported_dev: supported device struct
7059 * @vpids: vendor product id struct
7064 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
7065 struct ipr_std_inq_vpids *vpids)
7067 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
7068 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
7069 supported_dev->num_records = 1;
7070 supported_dev->data_length =
7071 cpu_to_be16(sizeof(struct ipr_supported_device));
7072 supported_dev->reserved = 0;
7076 * ipr_set_supported_devs - Send Set Supported Devices for a device
7077 * @ipr_cmd: ipr command struct
7079 * This function sends a Set Supported Devices to the adapter
7082 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7084 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
7086 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7087 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
7088 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7089 struct ipr_resource_entry *res = ipr_cmd->u.res;
7091 ipr_cmd->job_step = ipr_ioa_reset_done;
7093 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
7094 if (!ipr_is_scsi_disk(res))
7097 ipr_cmd->u.res = res;
7098 ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
7100 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7101 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
7102 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7104 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
7105 ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
7106 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
7107 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
7109 ipr_init_ioadl(ipr_cmd,
7110 ioa_cfg->vpd_cbs_dma +
7111 offsetof(struct ipr_misc_cbs, supp_dev),
7112 sizeof(struct ipr_supported_device),
7113 IPR_IOADL_FLAGS_WRITE_LAST);
7115 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7116 IPR_SET_SUP_DEVICE_TIMEOUT);
7118 if (!ioa_cfg->sis64)
7119 ipr_cmd->job_step = ipr_set_supported_devs;
7121 return IPR_RC_JOB_RETURN;
7125 return IPR_RC_JOB_CONTINUE;
7129 * ipr_get_mode_page - Locate specified mode page
7130 * @mode_pages: mode page buffer
7131 * @page_code: page code to find
7132 * @len: minimum required length for mode page
7135 * pointer to mode page / NULL on failure
7137 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
7138 u32 page_code, u32 len)
7140 struct ipr_mode_page_hdr *mode_hdr;
7144 if (!mode_pages || (mode_pages->hdr.length == 0))
7147 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
7148 mode_hdr = (struct ipr_mode_page_hdr *)
7149 (mode_pages->data + mode_pages->hdr.block_desc_len);
7152 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
7153 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
7157 page_length = (sizeof(struct ipr_mode_page_hdr) +
7158 mode_hdr->page_length);
7159 length -= page_length;
7160 mode_hdr = (struct ipr_mode_page_hdr *)
7161 ((unsigned long)mode_hdr + page_length);
7168 * ipr_check_term_power - Check for term power errors
7169 * @ioa_cfg: ioa config struct
7170 * @mode_pages: IOAFP mode pages buffer
7172 * Check the IOAFP's mode page 28 for term power errors
7177 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
7178 struct ipr_mode_pages *mode_pages)
7182 struct ipr_dev_bus_entry *bus;
7183 struct ipr_mode_page28 *mode_page;
7185 mode_page = ipr_get_mode_page(mode_pages, 0x28,
7186 sizeof(struct ipr_mode_page28));
7188 entry_length = mode_page->entry_length;
7190 bus = mode_page->bus;
7192 for (i = 0; i < mode_page->num_entries; i++) {
7193 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
7194 dev_err(&ioa_cfg->pdev->dev,
7195 "Term power is absent on scsi bus %d\n",
7199 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
7204 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
7205 * @ioa_cfg: ioa config struct
7207 * Looks through the config table checking for SES devices. If
7208 * the SES device is in the SES table indicating a maximum SCSI
7209 * bus speed, the speed is limited for the bus.
7214 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
7219 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
7220 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
7221 ioa_cfg->bus_attr[i].bus_width);
7223 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
7224 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
7229 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
7230 * @ioa_cfg: ioa config struct
7231 * @mode_pages: mode page 28 buffer
7233 * Updates mode page 28 based on driver configuration
7238 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
7239 struct ipr_mode_pages *mode_pages)
7241 int i, entry_length;
7242 struct ipr_dev_bus_entry *bus;
7243 struct ipr_bus_attributes *bus_attr;
7244 struct ipr_mode_page28 *mode_page;
7246 mode_page = ipr_get_mode_page(mode_pages, 0x28,
7247 sizeof(struct ipr_mode_page28));
7249 entry_length = mode_page->entry_length;
7251 /* Loop for each device bus entry */
7252 for (i = 0, bus = mode_page->bus;
7253 i < mode_page->num_entries;
7254 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
7255 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
7256 dev_err(&ioa_cfg->pdev->dev,
7257 "Invalid resource address reported: 0x%08X\n",
7258 IPR_GET_PHYS_LOC(bus->res_addr));
7262 bus_attr = &ioa_cfg->bus_attr[i];
7263 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
7264 bus->bus_width = bus_attr->bus_width;
7265 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
7266 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
7267 if (bus_attr->qas_enabled)
7268 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
7270 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
7275 * ipr_build_mode_select - Build a mode select command
7276 * @ipr_cmd: ipr command struct
7277 * @res_handle: resource handle to send command to
7278 * @parm: Byte 2 of Mode Sense command
7279 * @dma_addr: DMA buffer address
7280 * @xfer_len: data transfer length
7285 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
7286 __be32 res_handle, u8 parm,
7287 dma_addr_t dma_addr, u8 xfer_len)
7289 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7291 ioarcb->res_handle = res_handle;
7292 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7293 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
7294 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
7295 ioarcb->cmd_pkt.cdb[1] = parm;
7296 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7298 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
7302 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
7303 * @ipr_cmd: ipr command struct
7305 * This function sets up the SCSI bus attributes and sends
7306 * a Mode Select for Page 28 to activate them.
7311 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
7313 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7314 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
7318 ipr_scsi_bus_speed_limit(ioa_cfg);
7319 ipr_check_term_power(ioa_cfg, mode_pages);
7320 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
7321 length = mode_pages->hdr.length + 1;
7322 mode_pages->hdr.length = 0;
7324 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
7325 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
7328 ipr_cmd->job_step = ipr_set_supported_devs;
7329 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
7330 struct ipr_resource_entry, queue);
7331 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7334 return IPR_RC_JOB_RETURN;
7338 * ipr_build_mode_sense - Builds a mode sense command
7339 * @ipr_cmd: ipr command struct
7340 * @res: resource entry struct
7341 * @parm: Byte 2 of mode sense command
7342 * @dma_addr: DMA address of mode sense buffer
7343 * @xfer_len: Size of DMA buffer
7348 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
7350 u8 parm, dma_addr_t dma_addr, u8 xfer_len)
7352 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7354 ioarcb->res_handle = res_handle;
7355 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
7356 ioarcb->cmd_pkt.cdb[2] = parm;
7357 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7358 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7360 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
7364 * ipr_reset_cmd_failed - Handle failure of IOA reset command
7365 * @ipr_cmd: ipr command struct
7367 * This function handles the failure of an IOA bringup command.
7372 static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
7374 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7375 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
7377 dev_err(&ioa_cfg->pdev->dev,
7378 "0x%02X failed with IOASC: 0x%08X\n",
7379 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
7381 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7382 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
7383 return IPR_RC_JOB_RETURN;
7387 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
7388 * @ipr_cmd: ipr command struct
7390 * This function handles the failure of a Mode Sense to the IOAFP.
7391 * Some adapters do not handle all mode pages.
7394 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7396 static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
7398 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7399 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
7401 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
7402 ipr_cmd->job_step = ipr_set_supported_devs;
7403 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
7404 struct ipr_resource_entry, queue);
7405 return IPR_RC_JOB_CONTINUE;
7408 return ipr_reset_cmd_failed(ipr_cmd);
7412 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
7413 * @ipr_cmd: ipr command struct
7415 * This function send a Page 28 mode sense to the IOA to
7416 * retrieve SCSI bus attributes.
7421 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
7423 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7426 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
7427 0x28, ioa_cfg->vpd_cbs_dma +
7428 offsetof(struct ipr_misc_cbs, mode_pages),
7429 sizeof(struct ipr_mode_pages));
7431 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
7432 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
7434 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7437 return IPR_RC_JOB_RETURN;
7441 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
7442 * @ipr_cmd: ipr command struct
7444 * This function enables dual IOA RAID support if possible.
7449 static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
7451 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7452 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
7453 struct ipr_mode_page24 *mode_page;
7457 mode_page = ipr_get_mode_page(mode_pages, 0x24,
7458 sizeof(struct ipr_mode_page24));
7461 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
7463 length = mode_pages->hdr.length + 1;
7464 mode_pages->hdr.length = 0;
7466 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
7467 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
7470 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7471 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7474 return IPR_RC_JOB_RETURN;
7478 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
7479 * @ipr_cmd: ipr command struct
7481 * This function handles the failure of a Mode Sense to the IOAFP.
7482 * Some adapters do not handle all mode pages.
7485 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7487 static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
7489 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
7491 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
7492 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7493 return IPR_RC_JOB_CONTINUE;
7496 return ipr_reset_cmd_failed(ipr_cmd);
7500 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
7501 * @ipr_cmd: ipr command struct
7503 * This function send a mode sense to the IOA to retrieve
7504 * the IOA Advanced Function Control mode page.
7509 static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
7511 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7514 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
7515 0x24, ioa_cfg->vpd_cbs_dma +
7516 offsetof(struct ipr_misc_cbs, mode_pages),
7517 sizeof(struct ipr_mode_pages));
7519 ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
7520 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
7522 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7525 return IPR_RC_JOB_RETURN;
7529 * ipr_init_res_table - Initialize the resource table
7530 * @ipr_cmd: ipr command struct
7532 * This function looks through the existing resource table, comparing
7533 * it with the config table. This function will take care of old/new
7534 * devices and schedule adding/removing them from the mid-layer
7538 * IPR_RC_JOB_CONTINUE
7540 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
7542 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7543 struct ipr_resource_entry *res, *temp;
7544 struct ipr_config_table_entry_wrapper cfgtew;
7545 int entries, found, flag, i;
7550 flag = ioa_cfg->u.cfg_table64->hdr64.flags;
7552 flag = ioa_cfg->u.cfg_table->hdr.flags;
7554 if (flag & IPR_UCODE_DOWNLOAD_REQ)
7555 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
7557 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
7558 list_move_tail(&res->queue, &old_res);
7561 entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
7563 entries = ioa_cfg->u.cfg_table->hdr.num_entries;
7565 for (i = 0; i < entries; i++) {
7567 cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
7569 cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
7572 list_for_each_entry_safe(res, temp, &old_res, queue) {
7573 if (ipr_is_same_device(res, &cfgtew)) {
7574 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7581 if (list_empty(&ioa_cfg->free_res_q)) {
7582 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
7587 res = list_entry(ioa_cfg->free_res_q.next,
7588 struct ipr_resource_entry, queue);
7589 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7590 ipr_init_res_entry(res, &cfgtew);
7592 } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
7593 res->sdev->allow_restart = 1;
7596 ipr_update_res_entry(res, &cfgtew);
7599 list_for_each_entry_safe(res, temp, &old_res, queue) {
7601 res->del_from_ml = 1;
7602 res->res_handle = IPR_INVALID_RES_HANDLE;
7603 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7607 list_for_each_entry_safe(res, temp, &old_res, queue) {
7608 ipr_clear_res_target(res);
7609 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
7612 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
7613 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
7615 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7618 return IPR_RC_JOB_CONTINUE;
7622 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
7623 * @ipr_cmd: ipr command struct
7625 * This function sends a Query IOA Configuration command
7626 * to the adapter to retrieve the IOA configuration table.
7631 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
7633 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7634 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7635 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
7636 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7639 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
7640 ioa_cfg->dual_raid = 1;
7641 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
7642 ucode_vpd->major_release, ucode_vpd->card_type,
7643 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
7644 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7645 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7647 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
7648 ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
7649 ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
7650 ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
7652 ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
7653 IPR_IOADL_FLAGS_READ_LAST);
7655 ipr_cmd->job_step = ipr_init_res_table;
7657 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7660 return IPR_RC_JOB_RETURN;
7664 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
7665 * @ipr_cmd: ipr command struct
7667 * This utility function sends an inquiry to the adapter.
7672 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
7673 dma_addr_t dma_addr, u8 xfer_len)
7675 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7678 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7679 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7681 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
7682 ioarcb->cmd_pkt.cdb[1] = flags;
7683 ioarcb->cmd_pkt.cdb[2] = page;
7684 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7686 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
7688 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7693 * ipr_inquiry_page_supported - Is the given inquiry page supported
7694 * @page0: inquiry page 0 buffer
7697 * This function determines if the specified inquiry page is supported.
7700 * 1 if page is supported / 0 if not
7702 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
7706 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
7707 if (page0->page[i] == page)
7714 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
7715 * @ipr_cmd: ipr command struct
7717 * This function sends a Page 0xD0 inquiry to the adapter
7718 * to retrieve adapter capabilities.
7721 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7723 static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
7725 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7726 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
7727 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7730 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
7731 memset(cap, 0, sizeof(*cap));
7733 if (ipr_inquiry_page_supported(page0, 0xD0)) {
7734 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
7735 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
7736 sizeof(struct ipr_inquiry_cap));
7737 return IPR_RC_JOB_RETURN;
7741 return IPR_RC_JOB_CONTINUE;
7745 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
7746 * @ipr_cmd: ipr command struct
7748 * This function sends a Page 3 inquiry to the adapter
7749 * to retrieve software VPD information.
7752 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7754 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
7756 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7760 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
7762 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
7763 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
7764 sizeof(struct ipr_inquiry_page3));
7767 return IPR_RC_JOB_RETURN;
7771 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
7772 * @ipr_cmd: ipr command struct
7774 * This function sends a Page 0 inquiry to the adapter
7775 * to retrieve supported inquiry pages.
7778 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7780 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
7782 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7787 /* Grab the type out of the VPD and store it away */
7788 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
7790 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
7792 if (ipr_invalid_adapter(ioa_cfg)) {
7793 dev_err(&ioa_cfg->pdev->dev,
7794 "Adapter not supported in this hardware configuration.\n");
7796 if (!ipr_testmode) {
7797 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
7798 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7799 list_add_tail(&ipr_cmd->queue,
7800 &ioa_cfg->hrrq->hrrq_free_q);
7801 return IPR_RC_JOB_RETURN;
7805 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
7807 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
7808 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
7809 sizeof(struct ipr_inquiry_page0));
7812 return IPR_RC_JOB_RETURN;
7816 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
7817 * @ipr_cmd: ipr command struct
7819 * This function sends a standard inquiry to the adapter.
7824 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
7826 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7829 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
7831 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
7832 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
7833 sizeof(struct ipr_ioa_vpd));
7836 return IPR_RC_JOB_RETURN;
7840 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
7841 * @ipr_cmd: ipr command struct
7843 * This function send an Identify Host Request Response Queue
7844 * command to establish the HRRQ with the adapter.
7849 static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
7851 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7852 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7853 struct ipr_hrr_queue *hrrq;
7856 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
7857 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
7859 if (ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num) {
7860 hrrq = &ioa_cfg->hrrq[ioa_cfg->identify_hrrq_index];
7862 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
7863 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7865 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7867 ioarcb->cmd_pkt.cdb[1] = 0x1;
7869 if (ioa_cfg->nvectors == 1)
7870 ioarcb->cmd_pkt.cdb[1] &= ~IPR_ID_HRRQ_SELE_ENABLE;
7872 ioarcb->cmd_pkt.cdb[1] |= IPR_ID_HRRQ_SELE_ENABLE;
7874 ioarcb->cmd_pkt.cdb[2] =
7875 ((u64) hrrq->host_rrq_dma >> 24) & 0xff;
7876 ioarcb->cmd_pkt.cdb[3] =
7877 ((u64) hrrq->host_rrq_dma >> 16) & 0xff;
7878 ioarcb->cmd_pkt.cdb[4] =
7879 ((u64) hrrq->host_rrq_dma >> 8) & 0xff;
7880 ioarcb->cmd_pkt.cdb[5] =
7881 ((u64) hrrq->host_rrq_dma) & 0xff;
7882 ioarcb->cmd_pkt.cdb[7] =
7883 ((sizeof(u32) * hrrq->size) >> 8) & 0xff;
7884 ioarcb->cmd_pkt.cdb[8] =
7885 (sizeof(u32) * hrrq->size) & 0xff;
7887 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
7888 ioarcb->cmd_pkt.cdb[9] =
7889 ioa_cfg->identify_hrrq_index;
7891 if (ioa_cfg->sis64) {
7892 ioarcb->cmd_pkt.cdb[10] =
7893 ((u64) hrrq->host_rrq_dma >> 56) & 0xff;
7894 ioarcb->cmd_pkt.cdb[11] =
7895 ((u64) hrrq->host_rrq_dma >> 48) & 0xff;
7896 ioarcb->cmd_pkt.cdb[12] =
7897 ((u64) hrrq->host_rrq_dma >> 40) & 0xff;
7898 ioarcb->cmd_pkt.cdb[13] =
7899 ((u64) hrrq->host_rrq_dma >> 32) & 0xff;
7902 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
7903 ioarcb->cmd_pkt.cdb[14] =
7904 ioa_cfg->identify_hrrq_index;
7906 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7907 IPR_INTERNAL_TIMEOUT);
7909 if (++ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num)
7910 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7913 return IPR_RC_JOB_RETURN;
7917 return IPR_RC_JOB_CONTINUE;
7921 * ipr_reset_timer_done - Adapter reset timer function
7922 * @ipr_cmd: ipr command struct
7924 * Description: This function is used in adapter reset processing
7925 * for timing events. If the reset_cmd pointer in the IOA
7926 * config struct is not this adapter's we are doing nested
7927 * resets and fail_all_ops will take care of freeing the
7933 static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
7935 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7936 unsigned long lock_flags = 0;
7938 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7940 if (ioa_cfg->reset_cmd == ipr_cmd) {
7941 list_del(&ipr_cmd->queue);
7942 ipr_cmd->done(ipr_cmd);
7945 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7949 * ipr_reset_start_timer - Start a timer for adapter reset job
7950 * @ipr_cmd: ipr command struct
7951 * @timeout: timeout value
7953 * Description: This function is used in adapter reset processing
7954 * for timing events. If the reset_cmd pointer in the IOA
7955 * config struct is not this adapter's we are doing nested
7956 * resets and fail_all_ops will take care of freeing the
7962 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
7963 unsigned long timeout)
7967 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
7968 ipr_cmd->done = ipr_reset_ioa_job;
7970 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7971 ipr_cmd->timer.expires = jiffies + timeout;
7972 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
7973 add_timer(&ipr_cmd->timer);
7977 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7978 * @ioa_cfg: ioa cfg struct
7983 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
7985 struct ipr_hrr_queue *hrrq;
7987 for_each_hrrq(hrrq, ioa_cfg) {
7988 spin_lock(&hrrq->_lock);
7989 memset(hrrq->host_rrq, 0, sizeof(u32) * hrrq->size);
7991 /* Initialize Host RRQ pointers */
7992 hrrq->hrrq_start = hrrq->host_rrq;
7993 hrrq->hrrq_end = &hrrq->host_rrq[hrrq->size - 1];
7994 hrrq->hrrq_curr = hrrq->hrrq_start;
7995 hrrq->toggle_bit = 1;
7996 spin_unlock(&hrrq->_lock);
8000 ioa_cfg->identify_hrrq_index = 0;
8001 if (ioa_cfg->hrrq_num == 1)
8002 atomic_set(&ioa_cfg->hrrq_index, 0);
8004 atomic_set(&ioa_cfg->hrrq_index, 1);
8006 /* Zero out config table */
8007 memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
8011 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
8012 * @ipr_cmd: ipr command struct
8015 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8017 static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
8019 unsigned long stage, stage_time;
8021 volatile u32 int_reg;
8022 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8025 feedback = readl(ioa_cfg->regs.init_feedback_reg);
8026 stage = feedback & IPR_IPL_INIT_STAGE_MASK;
8027 stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
8029 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
8031 /* sanity check the stage_time value */
8032 if (stage_time == 0)
8033 stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
8034 else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
8035 stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
8036 else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
8037 stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
8039 if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
8040 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
8041 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8042 stage_time = ioa_cfg->transop_timeout;
8043 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
8044 } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
8045 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
8046 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
8047 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
8048 maskval = IPR_PCII_IPL_STAGE_CHANGE;
8049 maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
8050 writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
8051 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8052 return IPR_RC_JOB_CONTINUE;
8056 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
8057 ipr_cmd->timer.expires = jiffies + stage_time * HZ;
8058 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
8059 ipr_cmd->done = ipr_reset_ioa_job;
8060 add_timer(&ipr_cmd->timer);
8062 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
8064 return IPR_RC_JOB_RETURN;
8068 * ipr_reset_enable_ioa - Enable the IOA following a reset.
8069 * @ipr_cmd: ipr command struct
8071 * This function reinitializes some control blocks and
8072 * enables destructive diagnostics on the adapter.
8077 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
8079 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8080 volatile u32 int_reg;
8081 volatile u64 maskval;
8085 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
8086 ipr_init_ioa_mem(ioa_cfg);
8088 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8089 spin_lock(&ioa_cfg->hrrq[i]._lock);
8090 ioa_cfg->hrrq[i].allow_interrupts = 1;
8091 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8094 if (ioa_cfg->sis64) {
8095 /* Set the adapter to the correct endian mode. */
8096 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
8097 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
8100 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
8102 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
8103 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
8104 ioa_cfg->regs.clr_interrupt_mask_reg32);
8105 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8106 return IPR_RC_JOB_CONTINUE;
8109 /* Enable destructive diagnostics on IOA */
8110 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
8112 if (ioa_cfg->sis64) {
8113 maskval = IPR_PCII_IPL_STAGE_CHANGE;
8114 maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
8115 writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
8117 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
8119 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8121 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
8123 if (ioa_cfg->sis64) {
8124 ipr_cmd->job_step = ipr_reset_next_stage;
8125 return IPR_RC_JOB_CONTINUE;
8128 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
8129 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
8130 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
8131 ipr_cmd->done = ipr_reset_ioa_job;
8132 add_timer(&ipr_cmd->timer);
8133 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
8136 return IPR_RC_JOB_RETURN;
8140 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
8141 * @ipr_cmd: ipr command struct
8143 * This function is invoked when an adapter dump has run out
8144 * of processing time.
8147 * IPR_RC_JOB_CONTINUE
8149 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
8151 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8153 if (ioa_cfg->sdt_state == GET_DUMP)
8154 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8155 else if (ioa_cfg->sdt_state == READ_DUMP)
8156 ioa_cfg->sdt_state = ABORT_DUMP;
8158 ioa_cfg->dump_timeout = 1;
8159 ipr_cmd->job_step = ipr_reset_alert;
8161 return IPR_RC_JOB_CONTINUE;
8165 * ipr_unit_check_no_data - Log a unit check/no data error log
8166 * @ioa_cfg: ioa config struct
8168 * Logs an error indicating the adapter unit checked, but for some
8169 * reason, we were unable to fetch the unit check buffer.
8174 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
8176 ioa_cfg->errors_logged++;
8177 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
8181 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
8182 * @ioa_cfg: ioa config struct
8184 * Fetches the unit check buffer from the adapter by clocking the data
8185 * through the mailbox register.
8190 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
8192 unsigned long mailbox;
8193 struct ipr_hostrcb *hostrcb;
8194 struct ipr_uc_sdt sdt;
8198 mailbox = readl(ioa_cfg->ioa_mailbox);
8200 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
8201 ipr_unit_check_no_data(ioa_cfg);
8205 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
8206 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
8207 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
8209 if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
8210 ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
8211 (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
8212 ipr_unit_check_no_data(ioa_cfg);
8216 /* Find length of the first sdt entry (UC buffer) */
8217 if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
8218 length = be32_to_cpu(sdt.entry[0].end_token);
8220 length = (be32_to_cpu(sdt.entry[0].end_token) -
8221 be32_to_cpu(sdt.entry[0].start_token)) &
8222 IPR_FMT2_MBX_ADDR_MASK;
8224 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
8225 struct ipr_hostrcb, queue);
8226 list_del(&hostrcb->queue);
8227 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
8229 rc = ipr_get_ldump_data_section(ioa_cfg,
8230 be32_to_cpu(sdt.entry[0].start_token),
8231 (__be32 *)&hostrcb->hcam,
8232 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
8235 ipr_handle_log_data(ioa_cfg, hostrcb);
8236 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
8237 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
8238 ioa_cfg->sdt_state == GET_DUMP)
8239 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8241 ipr_unit_check_no_data(ioa_cfg);
8243 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
8247 * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
8248 * @ipr_cmd: ipr command struct
8250 * Description: This function will call to get the unit check buffer.
8255 static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
8257 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8260 ioa_cfg->ioa_unit_checked = 0;
8261 ipr_get_unit_check_buffer(ioa_cfg);
8262 ipr_cmd->job_step = ipr_reset_alert;
8263 ipr_reset_start_timer(ipr_cmd, 0);
8266 return IPR_RC_JOB_RETURN;
8270 * ipr_reset_restore_cfg_space - Restore PCI config space.
8271 * @ipr_cmd: ipr command struct
8273 * Description: This function restores the saved PCI config space of
8274 * the adapter, fails all outstanding ops back to the callers, and
8275 * fetches the dump/unit check if applicable to this reset.
8278 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8280 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
8282 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8286 ioa_cfg->pdev->state_saved = true;
8287 pci_restore_state(ioa_cfg->pdev);
8289 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
8290 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
8291 return IPR_RC_JOB_CONTINUE;
8294 ipr_fail_all_ops(ioa_cfg);
8296 if (ioa_cfg->sis64) {
8297 /* Set the adapter to the correct endian mode. */
8298 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
8299 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
8302 if (ioa_cfg->ioa_unit_checked) {
8303 if (ioa_cfg->sis64) {
8304 ipr_cmd->job_step = ipr_reset_get_unit_check_job;
8305 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
8306 return IPR_RC_JOB_RETURN;
8308 ioa_cfg->ioa_unit_checked = 0;
8309 ipr_get_unit_check_buffer(ioa_cfg);
8310 ipr_cmd->job_step = ipr_reset_alert;
8311 ipr_reset_start_timer(ipr_cmd, 0);
8312 return IPR_RC_JOB_RETURN;
8316 if (ioa_cfg->in_ioa_bringdown) {
8317 ipr_cmd->job_step = ipr_ioa_bringdown_done;
8319 ipr_cmd->job_step = ipr_reset_enable_ioa;
8321 if (GET_DUMP == ioa_cfg->sdt_state) {
8322 ioa_cfg->sdt_state = READ_DUMP;
8323 ioa_cfg->dump_timeout = 0;
8325 ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
8327 ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
8328 ipr_cmd->job_step = ipr_reset_wait_for_dump;
8329 schedule_work(&ioa_cfg->work_q);
8330 return IPR_RC_JOB_RETURN;
8335 return IPR_RC_JOB_CONTINUE;
8339 * ipr_reset_bist_done - BIST has completed on the adapter.
8340 * @ipr_cmd: ipr command struct
8342 * Description: Unblock config space and resume the reset process.
8345 * IPR_RC_JOB_CONTINUE
8347 static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
8349 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8352 if (ioa_cfg->cfg_locked)
8353 pci_cfg_access_unlock(ioa_cfg->pdev);
8354 ioa_cfg->cfg_locked = 0;
8355 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
8357 return IPR_RC_JOB_CONTINUE;
8361 * ipr_reset_start_bist - Run BIST on the adapter.
8362 * @ipr_cmd: ipr command struct
8364 * Description: This function runs BIST on the adapter, then delays 2 seconds.
8367 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8369 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
8371 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8372 int rc = PCIBIOS_SUCCESSFUL;
8375 if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
8376 writel(IPR_UPROCI_SIS64_START_BIST,
8377 ioa_cfg->regs.set_uproc_interrupt_reg32);
8379 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
8381 if (rc == PCIBIOS_SUCCESSFUL) {
8382 ipr_cmd->job_step = ipr_reset_bist_done;
8383 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
8384 rc = IPR_RC_JOB_RETURN;
8386 if (ioa_cfg->cfg_locked)
8387 pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
8388 ioa_cfg->cfg_locked = 0;
8389 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
8390 rc = IPR_RC_JOB_CONTINUE;
8398 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
8399 * @ipr_cmd: ipr command struct
8401 * Description: This clears PCI reset to the adapter and delays two seconds.
8406 static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
8409 ipr_cmd->job_step = ipr_reset_bist_done;
8410 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
8412 return IPR_RC_JOB_RETURN;
8416 * ipr_reset_reset_work - Pulse a PCIe fundamental reset
8417 * @work: work struct
8419 * Description: This pulses warm reset to a slot.
8422 static void ipr_reset_reset_work(struct work_struct *work)
8424 struct ipr_cmnd *ipr_cmd = container_of(work, struct ipr_cmnd, work);
8425 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8426 struct pci_dev *pdev = ioa_cfg->pdev;
8427 unsigned long lock_flags = 0;
8430 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
8431 msleep(jiffies_to_msecs(IPR_PCI_RESET_TIMEOUT));
8432 pci_set_pcie_reset_state(pdev, pcie_deassert_reset);
8434 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8435 if (ioa_cfg->reset_cmd == ipr_cmd)
8436 ipr_reset_ioa_job(ipr_cmd);
8437 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8442 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
8443 * @ipr_cmd: ipr command struct
8445 * Description: This asserts PCI reset to the adapter.
8450 static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
8452 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8455 INIT_WORK(&ipr_cmd->work, ipr_reset_reset_work);
8456 queue_work(ioa_cfg->reset_work_q, &ipr_cmd->work);
8457 ipr_cmd->job_step = ipr_reset_slot_reset_done;
8459 return IPR_RC_JOB_RETURN;
8463 * ipr_reset_block_config_access_wait - Wait for permission to block config access
8464 * @ipr_cmd: ipr command struct
8466 * Description: This attempts to block config access to the IOA.
8469 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8471 static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
8473 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8474 int rc = IPR_RC_JOB_CONTINUE;
8476 if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
8477 ioa_cfg->cfg_locked = 1;
8478 ipr_cmd->job_step = ioa_cfg->reset;
8480 if (ipr_cmd->u.time_left) {
8481 rc = IPR_RC_JOB_RETURN;
8482 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8483 ipr_reset_start_timer(ipr_cmd,
8484 IPR_CHECK_FOR_RESET_TIMEOUT);
8486 ipr_cmd->job_step = ioa_cfg->reset;
8487 dev_err(&ioa_cfg->pdev->dev,
8488 "Timed out waiting to lock config access. Resetting anyway.\n");
8496 * ipr_reset_block_config_access - Block config access to the IOA
8497 * @ipr_cmd: ipr command struct
8499 * Description: This attempts to block config access to the IOA
8502 * IPR_RC_JOB_CONTINUE
8504 static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
8506 ipr_cmd->ioa_cfg->cfg_locked = 0;
8507 ipr_cmd->job_step = ipr_reset_block_config_access_wait;
8508 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8509 return IPR_RC_JOB_CONTINUE;
8513 * ipr_reset_allowed - Query whether or not IOA can be reset
8514 * @ioa_cfg: ioa config struct
8517 * 0 if reset not allowed / non-zero if reset is allowed
8519 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
8521 volatile u32 temp_reg;
8523 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
8524 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
8528 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
8529 * @ipr_cmd: ipr command struct
8531 * Description: This function waits for adapter permission to run BIST,
8532 * then runs BIST. If the adapter does not give permission after a
8533 * reasonable time, we will reset the adapter anyway. The impact of
8534 * resetting the adapter without warning the adapter is the risk of
8535 * losing the persistent error log on the adapter. If the adapter is
8536 * reset while it is writing to the flash on the adapter, the flash
8537 * segment will have bad ECC and be zeroed.
8540 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8542 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
8544 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8545 int rc = IPR_RC_JOB_RETURN;
8547 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
8548 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8549 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8551 ipr_cmd->job_step = ipr_reset_block_config_access;
8552 rc = IPR_RC_JOB_CONTINUE;
8559 * ipr_reset_alert - Alert the adapter of a pending reset
8560 * @ipr_cmd: ipr command struct
8562 * Description: This function alerts the adapter that it will be reset.
8563 * If memory space is not currently enabled, proceed directly
8564 * to running BIST on the adapter. The timer must always be started
8565 * so we guarantee we do not run BIST from ipr_isr.
8570 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
8572 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8577 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
8579 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
8580 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
8581 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
8582 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
8584 ipr_cmd->job_step = ipr_reset_block_config_access;
8587 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8588 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8591 return IPR_RC_JOB_RETURN;
8595 * ipr_reset_quiesce_done - Complete IOA disconnect
8596 * @ipr_cmd: ipr command struct
8598 * Description: Freeze the adapter to complete quiesce processing
8601 * IPR_RC_JOB_CONTINUE
8603 static int ipr_reset_quiesce_done(struct ipr_cmnd *ipr_cmd)
8605 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8608 ipr_cmd->job_step = ipr_ioa_bringdown_done;
8609 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
8611 return IPR_RC_JOB_CONTINUE;
8615 * ipr_reset_cancel_hcam_done - Check for outstanding commands
8616 * @ipr_cmd: ipr command struct
8618 * Description: Ensure nothing is outstanding to the IOA and
8619 * proceed with IOA disconnect. Otherwise reset the IOA.
8622 * IPR_RC_JOB_RETURN / IPR_RC_JOB_CONTINUE
8624 static int ipr_reset_cancel_hcam_done(struct ipr_cmnd *ipr_cmd)
8626 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8627 struct ipr_cmnd *loop_cmd;
8628 struct ipr_hrr_queue *hrrq;
8629 int rc = IPR_RC_JOB_CONTINUE;
8633 ipr_cmd->job_step = ipr_reset_quiesce_done;
8635 for_each_hrrq(hrrq, ioa_cfg) {
8636 spin_lock(&hrrq->_lock);
8637 list_for_each_entry(loop_cmd, &hrrq->hrrq_pending_q, queue) {
8639 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8640 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
8641 rc = IPR_RC_JOB_RETURN;
8644 spin_unlock(&hrrq->_lock);
8655 * ipr_reset_cancel_hcam - Cancel outstanding HCAMs
8656 * @ipr_cmd: ipr command struct
8658 * Description: Cancel any oustanding HCAMs to the IOA.
8661 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8663 static int ipr_reset_cancel_hcam(struct ipr_cmnd *ipr_cmd)
8665 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8666 int rc = IPR_RC_JOB_CONTINUE;
8667 struct ipr_cmd_pkt *cmd_pkt;
8668 struct ipr_cmnd *hcam_cmd;
8669 struct ipr_hrr_queue *hrrq = &ioa_cfg->hrrq[IPR_INIT_HRRQ];
8672 ipr_cmd->job_step = ipr_reset_cancel_hcam_done;
8674 if (!hrrq->ioa_is_dead) {
8675 if (!list_empty(&ioa_cfg->hostrcb_pending_q)) {
8676 list_for_each_entry(hcam_cmd, &hrrq->hrrq_pending_q, queue) {
8677 if (hcam_cmd->ioarcb.cmd_pkt.cdb[0] != IPR_HOST_CONTROLLED_ASYNC)
8680 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8681 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8682 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
8683 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
8684 cmd_pkt->cdb[0] = IPR_CANCEL_REQUEST;
8685 cmd_pkt->cdb[1] = IPR_CANCEL_64BIT_IOARCB;
8686 cmd_pkt->cdb[10] = ((u64) hcam_cmd->dma_addr >> 56) & 0xff;
8687 cmd_pkt->cdb[11] = ((u64) hcam_cmd->dma_addr >> 48) & 0xff;
8688 cmd_pkt->cdb[12] = ((u64) hcam_cmd->dma_addr >> 40) & 0xff;
8689 cmd_pkt->cdb[13] = ((u64) hcam_cmd->dma_addr >> 32) & 0xff;
8690 cmd_pkt->cdb[2] = ((u64) hcam_cmd->dma_addr >> 24) & 0xff;
8691 cmd_pkt->cdb[3] = ((u64) hcam_cmd->dma_addr >> 16) & 0xff;
8692 cmd_pkt->cdb[4] = ((u64) hcam_cmd->dma_addr >> 8) & 0xff;
8693 cmd_pkt->cdb[5] = ((u64) hcam_cmd->dma_addr) & 0xff;
8695 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
8696 IPR_CANCEL_TIMEOUT);
8698 rc = IPR_RC_JOB_RETURN;
8699 ipr_cmd->job_step = ipr_reset_cancel_hcam;
8704 ipr_cmd->job_step = ipr_reset_alert;
8711 * ipr_reset_ucode_download_done - Microcode download completion
8712 * @ipr_cmd: ipr command struct
8714 * Description: This function unmaps the microcode download buffer.
8717 * IPR_RC_JOB_CONTINUE
8719 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
8721 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8722 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8724 dma_unmap_sg(&ioa_cfg->pdev->dev, sglist->scatterlist,
8725 sglist->num_sg, DMA_TO_DEVICE);
8727 ipr_cmd->job_step = ipr_reset_alert;
8728 return IPR_RC_JOB_CONTINUE;
8732 * ipr_reset_ucode_download - Download microcode to the adapter
8733 * @ipr_cmd: ipr command struct
8735 * Description: This function checks to see if it there is microcode
8736 * to download to the adapter. If there is, a download is performed.
8739 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8741 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
8743 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8744 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8747 ipr_cmd->job_step = ipr_reset_alert;
8750 return IPR_RC_JOB_CONTINUE;
8752 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8753 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
8754 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
8755 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
8756 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
8757 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
8758 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
8761 ipr_build_ucode_ioadl64(ipr_cmd, sglist);
8763 ipr_build_ucode_ioadl(ipr_cmd, sglist);
8764 ipr_cmd->job_step = ipr_reset_ucode_download_done;
8766 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
8767 IPR_WRITE_BUFFER_TIMEOUT);
8770 return IPR_RC_JOB_RETURN;
8774 * ipr_reset_shutdown_ioa - Shutdown the adapter
8775 * @ipr_cmd: ipr command struct
8777 * Description: This function issues an adapter shutdown of the
8778 * specified type to the specified adapter as part of the
8779 * adapter reset job.
8782 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8784 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
8786 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8787 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
8788 unsigned long timeout;
8789 int rc = IPR_RC_JOB_CONTINUE;
8792 if (shutdown_type == IPR_SHUTDOWN_QUIESCE)
8793 ipr_cmd->job_step = ipr_reset_cancel_hcam;
8794 else if (shutdown_type != IPR_SHUTDOWN_NONE &&
8795 !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
8796 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8797 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8798 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
8799 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
8801 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
8802 timeout = IPR_SHUTDOWN_TIMEOUT;
8803 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
8804 timeout = IPR_INTERNAL_TIMEOUT;
8805 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
8806 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
8808 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
8810 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
8812 rc = IPR_RC_JOB_RETURN;
8813 ipr_cmd->job_step = ipr_reset_ucode_download;
8815 ipr_cmd->job_step = ipr_reset_alert;
8822 * ipr_reset_ioa_job - Adapter reset job
8823 * @ipr_cmd: ipr command struct
8825 * Description: This function is the job router for the adapter reset job.
8830 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
8833 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8836 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
8838 if (ioa_cfg->reset_cmd != ipr_cmd) {
8840 * We are doing nested adapter resets and this is
8841 * not the current reset job.
8843 list_add_tail(&ipr_cmd->queue,
8844 &ipr_cmd->hrrq->hrrq_free_q);
8848 if (IPR_IOASC_SENSE_KEY(ioasc)) {
8849 rc = ipr_cmd->job_step_failed(ipr_cmd);
8850 if (rc == IPR_RC_JOB_RETURN)
8854 ipr_reinit_ipr_cmnd(ipr_cmd);
8855 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
8856 rc = ipr_cmd->job_step(ipr_cmd);
8857 } while (rc == IPR_RC_JOB_CONTINUE);
8861 * _ipr_initiate_ioa_reset - Initiate an adapter reset
8862 * @ioa_cfg: ioa config struct
8863 * @job_step: first job step of reset job
8864 * @shutdown_type: shutdown type
8866 * Description: This function will initiate the reset of the given adapter
8867 * starting at the selected job step.
8868 * If the caller needs to wait on the completion of the reset,
8869 * the caller must sleep on the reset_wait_q.
8874 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8875 int (*job_step) (struct ipr_cmnd *),
8876 enum ipr_shutdown_type shutdown_type)
8878 struct ipr_cmnd *ipr_cmd;
8881 ioa_cfg->in_reset_reload = 1;
8882 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8883 spin_lock(&ioa_cfg->hrrq[i]._lock);
8884 ioa_cfg->hrrq[i].allow_cmds = 0;
8885 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8888 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa)
8889 scsi_block_requests(ioa_cfg->host);
8891 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
8892 ioa_cfg->reset_cmd = ipr_cmd;
8893 ipr_cmd->job_step = job_step;
8894 ipr_cmd->u.shutdown_type = shutdown_type;
8896 ipr_reset_ioa_job(ipr_cmd);
8900 * ipr_initiate_ioa_reset - Initiate an adapter reset
8901 * @ioa_cfg: ioa config struct
8902 * @shutdown_type: shutdown type
8904 * Description: This function will initiate the reset of the given adapter.
8905 * If the caller needs to wait on the completion of the reset,
8906 * the caller must sleep on the reset_wait_q.
8911 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8912 enum ipr_shutdown_type shutdown_type)
8916 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
8919 if (ioa_cfg->in_reset_reload) {
8920 if (ioa_cfg->sdt_state == GET_DUMP)
8921 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8922 else if (ioa_cfg->sdt_state == READ_DUMP)
8923 ioa_cfg->sdt_state = ABORT_DUMP;
8926 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
8927 dev_err(&ioa_cfg->pdev->dev,
8928 "IOA taken offline - error recovery failed\n");
8930 ioa_cfg->reset_retries = 0;
8931 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8932 spin_lock(&ioa_cfg->hrrq[i]._lock);
8933 ioa_cfg->hrrq[i].ioa_is_dead = 1;
8934 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8938 if (ioa_cfg->in_ioa_bringdown) {
8939 ioa_cfg->reset_cmd = NULL;
8940 ioa_cfg->in_reset_reload = 0;
8941 ipr_fail_all_ops(ioa_cfg);
8942 wake_up_all(&ioa_cfg->reset_wait_q);
8944 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
8945 spin_unlock_irq(ioa_cfg->host->host_lock);
8946 scsi_unblock_requests(ioa_cfg->host);
8947 spin_lock_irq(ioa_cfg->host->host_lock);
8951 ioa_cfg->in_ioa_bringdown = 1;
8952 shutdown_type = IPR_SHUTDOWN_NONE;
8956 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
8961 * ipr_reset_freeze - Hold off all I/O activity
8962 * @ipr_cmd: ipr command struct
8964 * Description: If the PCI slot is frozen, hold off all I/O
8965 * activity; then, as soon as the slot is available again,
8966 * initiate an adapter reset.
8968 static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
8970 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8973 /* Disallow new interrupts, avoid loop */
8974 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8975 spin_lock(&ioa_cfg->hrrq[i]._lock);
8976 ioa_cfg->hrrq[i].allow_interrupts = 0;
8977 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8980 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
8981 ipr_cmd->done = ipr_reset_ioa_job;
8982 return IPR_RC_JOB_RETURN;
8986 * ipr_pci_mmio_enabled - Called when MMIO has been re-enabled
8987 * @pdev: PCI device struct
8989 * Description: This routine is called to tell us that the MMIO
8990 * access to the IOA has been restored
8992 static pci_ers_result_t ipr_pci_mmio_enabled(struct pci_dev *pdev)
8994 unsigned long flags = 0;
8995 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8997 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8998 if (!ioa_cfg->probe_done)
8999 pci_save_state(pdev);
9000 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
9001 return PCI_ERS_RESULT_NEED_RESET;
9005 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
9006 * @pdev: PCI device struct
9008 * Description: This routine is called to tell us that the PCI bus
9009 * is down. Can't do anything here, except put the device driver
9010 * into a holding pattern, waiting for the PCI bus to come back.
9012 static void ipr_pci_frozen(struct pci_dev *pdev)
9014 unsigned long flags = 0;
9015 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9017 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
9018 if (ioa_cfg->probe_done)
9019 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
9020 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
9024 * ipr_pci_slot_reset - Called when PCI slot has been reset.
9025 * @pdev: PCI device struct
9027 * Description: This routine is called by the pci error recovery
9028 * code after the PCI slot has been reset, just before we
9029 * should resume normal operations.
9031 static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
9033 unsigned long flags = 0;
9034 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9036 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
9037 if (ioa_cfg->probe_done) {
9038 if (ioa_cfg->needs_warm_reset)
9039 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
9041 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
9044 wake_up_all(&ioa_cfg->eeh_wait_q);
9045 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
9046 return PCI_ERS_RESULT_RECOVERED;
9050 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
9051 * @pdev: PCI device struct
9053 * Description: This routine is called when the PCI bus has
9054 * permanently failed.
9056 static void ipr_pci_perm_failure(struct pci_dev *pdev)
9058 unsigned long flags = 0;
9059 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9062 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
9063 if (ioa_cfg->probe_done) {
9064 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
9065 ioa_cfg->sdt_state = ABORT_DUMP;
9066 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES - 1;
9067 ioa_cfg->in_ioa_bringdown = 1;
9068 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9069 spin_lock(&ioa_cfg->hrrq[i]._lock);
9070 ioa_cfg->hrrq[i].allow_cmds = 0;
9071 spin_unlock(&ioa_cfg->hrrq[i]._lock);
9074 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
9076 wake_up_all(&ioa_cfg->eeh_wait_q);
9077 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
9081 * ipr_pci_error_detected - Called when a PCI error is detected.
9082 * @pdev: PCI device struct
9083 * @state: PCI channel state
9085 * Description: Called when a PCI error is detected.
9088 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
9090 static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
9091 pci_channel_state_t state)
9094 case pci_channel_io_frozen:
9095 ipr_pci_frozen(pdev);
9096 return PCI_ERS_RESULT_CAN_RECOVER;
9097 case pci_channel_io_perm_failure:
9098 ipr_pci_perm_failure(pdev);
9099 return PCI_ERS_RESULT_DISCONNECT;
9104 return PCI_ERS_RESULT_NEED_RESET;
9108 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
9109 * @ioa_cfg: ioa cfg struct
9111 * Description: This is the second phase of adapter intialization
9112 * This function takes care of initilizing the adapter to the point
9113 * where it can accept new commands.
9116 * 0 on success / -EIO on failure
9118 static int ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
9121 unsigned long host_lock_flags = 0;
9124 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9125 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
9126 ioa_cfg->probe_done = 1;
9127 if (ioa_cfg->needs_hard_reset) {
9128 ioa_cfg->needs_hard_reset = 0;
9129 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
9131 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
9133 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9140 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
9141 * @ioa_cfg: ioa config struct
9146 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
9150 if (ioa_cfg->ipr_cmnd_list) {
9151 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
9152 if (ioa_cfg->ipr_cmnd_list[i])
9153 dma_pool_free(ioa_cfg->ipr_cmd_pool,
9154 ioa_cfg->ipr_cmnd_list[i],
9155 ioa_cfg->ipr_cmnd_list_dma[i]);
9157 ioa_cfg->ipr_cmnd_list[i] = NULL;
9161 if (ioa_cfg->ipr_cmd_pool)
9162 dma_pool_destroy(ioa_cfg->ipr_cmd_pool);
9164 kfree(ioa_cfg->ipr_cmnd_list);
9165 kfree(ioa_cfg->ipr_cmnd_list_dma);
9166 ioa_cfg->ipr_cmnd_list = NULL;
9167 ioa_cfg->ipr_cmnd_list_dma = NULL;
9168 ioa_cfg->ipr_cmd_pool = NULL;
9172 * ipr_free_mem - Frees memory allocated for an adapter
9173 * @ioa_cfg: ioa cfg struct
9178 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
9182 kfree(ioa_cfg->res_entries);
9183 dma_free_coherent(&ioa_cfg->pdev->dev, sizeof(struct ipr_misc_cbs),
9184 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
9185 ipr_free_cmd_blks(ioa_cfg);
9187 for (i = 0; i < ioa_cfg->hrrq_num; i++)
9188 dma_free_coherent(&ioa_cfg->pdev->dev,
9189 sizeof(u32) * ioa_cfg->hrrq[i].size,
9190 ioa_cfg->hrrq[i].host_rrq,
9191 ioa_cfg->hrrq[i].host_rrq_dma);
9193 dma_free_coherent(&ioa_cfg->pdev->dev, ioa_cfg->cfg_table_size,
9194 ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
9196 for (i = 0; i < IPR_NUM_HCAMS; i++) {
9197 dma_free_coherent(&ioa_cfg->pdev->dev,
9198 sizeof(struct ipr_hostrcb),
9199 ioa_cfg->hostrcb[i],
9200 ioa_cfg->hostrcb_dma[i]);
9203 ipr_free_dump(ioa_cfg);
9204 kfree(ioa_cfg->trace);
9208 * ipr_free_irqs - Free all allocated IRQs for the adapter.
9209 * @ioa_cfg: ipr cfg struct
9211 * This function frees all allocated IRQs for the
9212 * specified adapter.
9217 static void ipr_free_irqs(struct ipr_ioa_cfg *ioa_cfg)
9219 struct pci_dev *pdev = ioa_cfg->pdev;
9221 if (ioa_cfg->intr_flag == IPR_USE_MSI ||
9222 ioa_cfg->intr_flag == IPR_USE_MSIX) {
9224 for (i = 0; i < ioa_cfg->nvectors; i++)
9225 free_irq(ioa_cfg->vectors_info[i].vec,
9228 free_irq(pdev->irq, &ioa_cfg->hrrq[0]);
9230 if (ioa_cfg->intr_flag == IPR_USE_MSI) {
9231 pci_disable_msi(pdev);
9232 ioa_cfg->intr_flag &= ~IPR_USE_MSI;
9233 } else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
9234 pci_disable_msix(pdev);
9235 ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
9240 * ipr_free_all_resources - Free all allocated resources for an adapter.
9241 * @ipr_cmd: ipr command struct
9243 * This function frees all allocated resources for the
9244 * specified adapter.
9249 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
9251 struct pci_dev *pdev = ioa_cfg->pdev;
9254 ipr_free_irqs(ioa_cfg);
9255 if (ioa_cfg->reset_work_q)
9256 destroy_workqueue(ioa_cfg->reset_work_q);
9257 iounmap(ioa_cfg->hdw_dma_regs);
9258 pci_release_regions(pdev);
9259 ipr_free_mem(ioa_cfg);
9260 scsi_host_put(ioa_cfg->host);
9261 pci_disable_device(pdev);
9266 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
9267 * @ioa_cfg: ioa config struct
9270 * 0 on success / -ENOMEM on allocation failure
9272 static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
9274 struct ipr_cmnd *ipr_cmd;
9275 struct ipr_ioarcb *ioarcb;
9276 dma_addr_t dma_addr;
9277 int i, entries_each_hrrq, hrrq_id = 0;
9279 ioa_cfg->ipr_cmd_pool = dma_pool_create(IPR_NAME, &ioa_cfg->pdev->dev,
9280 sizeof(struct ipr_cmnd), 512, 0);
9282 if (!ioa_cfg->ipr_cmd_pool)
9285 ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
9286 ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
9288 if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
9289 ipr_free_cmd_blks(ioa_cfg);
9293 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9294 if (ioa_cfg->hrrq_num > 1) {
9296 entries_each_hrrq = IPR_NUM_INTERNAL_CMD_BLKS;
9297 ioa_cfg->hrrq[i].min_cmd_id = 0;
9298 ioa_cfg->hrrq[i].max_cmd_id =
9299 (entries_each_hrrq - 1);
9302 IPR_NUM_BASE_CMD_BLKS/
9303 (ioa_cfg->hrrq_num - 1);
9304 ioa_cfg->hrrq[i].min_cmd_id =
9305 IPR_NUM_INTERNAL_CMD_BLKS +
9306 (i - 1) * entries_each_hrrq;
9307 ioa_cfg->hrrq[i].max_cmd_id =
9308 (IPR_NUM_INTERNAL_CMD_BLKS +
9309 i * entries_each_hrrq - 1);
9312 entries_each_hrrq = IPR_NUM_CMD_BLKS;
9313 ioa_cfg->hrrq[i].min_cmd_id = 0;
9314 ioa_cfg->hrrq[i].max_cmd_id = (entries_each_hrrq - 1);
9316 ioa_cfg->hrrq[i].size = entries_each_hrrq;
9319 BUG_ON(ioa_cfg->hrrq_num == 0);
9321 i = IPR_NUM_CMD_BLKS -
9322 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id - 1;
9324 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].size += i;
9325 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id += i;
9328 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
9329 ipr_cmd = dma_pool_alloc(ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
9332 ipr_free_cmd_blks(ioa_cfg);
9336 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
9337 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
9338 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
9340 ioarcb = &ipr_cmd->ioarcb;
9341 ipr_cmd->dma_addr = dma_addr;
9343 ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
9345 ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
9347 ioarcb->host_response_handle = cpu_to_be32(i << 2);
9348 if (ioa_cfg->sis64) {
9349 ioarcb->u.sis64_addr_data.data_ioadl_addr =
9350 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
9351 ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
9352 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
9354 ioarcb->write_ioadl_addr =
9355 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
9356 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
9357 ioarcb->ioasa_host_pci_addr =
9358 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
9360 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
9361 ipr_cmd->cmd_index = i;
9362 ipr_cmd->ioa_cfg = ioa_cfg;
9363 ipr_cmd->sense_buffer_dma = dma_addr +
9364 offsetof(struct ipr_cmnd, sense_buffer);
9366 ipr_cmd->ioarcb.cmd_pkt.hrrq_id = hrrq_id;
9367 ipr_cmd->hrrq = &ioa_cfg->hrrq[hrrq_id];
9368 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
9369 if (i >= ioa_cfg->hrrq[hrrq_id].max_cmd_id)
9377 * ipr_alloc_mem - Allocate memory for an adapter
9378 * @ioa_cfg: ioa config struct
9381 * 0 on success / non-zero for error
9383 static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
9385 struct pci_dev *pdev = ioa_cfg->pdev;
9386 int i, rc = -ENOMEM;
9389 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
9390 ioa_cfg->max_devs_supported, GFP_KERNEL);
9392 if (!ioa_cfg->res_entries)
9395 for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
9396 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
9397 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
9400 ioa_cfg->vpd_cbs = dma_alloc_coherent(&pdev->dev,
9401 sizeof(struct ipr_misc_cbs),
9402 &ioa_cfg->vpd_cbs_dma,
9405 if (!ioa_cfg->vpd_cbs)
9406 goto out_free_res_entries;
9408 if (ipr_alloc_cmd_blks(ioa_cfg))
9409 goto out_free_vpd_cbs;
9411 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9412 ioa_cfg->hrrq[i].host_rrq = dma_alloc_coherent(&pdev->dev,
9413 sizeof(u32) * ioa_cfg->hrrq[i].size,
9414 &ioa_cfg->hrrq[i].host_rrq_dma,
9417 if (!ioa_cfg->hrrq[i].host_rrq) {
9419 dma_free_coherent(&pdev->dev,
9420 sizeof(u32) * ioa_cfg->hrrq[i].size,
9421 ioa_cfg->hrrq[i].host_rrq,
9422 ioa_cfg->hrrq[i].host_rrq_dma);
9423 goto out_ipr_free_cmd_blocks;
9425 ioa_cfg->hrrq[i].ioa_cfg = ioa_cfg;
9428 ioa_cfg->u.cfg_table = dma_alloc_coherent(&pdev->dev,
9429 ioa_cfg->cfg_table_size,
9430 &ioa_cfg->cfg_table_dma,
9433 if (!ioa_cfg->u.cfg_table)
9434 goto out_free_host_rrq;
9436 for (i = 0; i < IPR_NUM_HCAMS; i++) {
9437 ioa_cfg->hostrcb[i] = dma_alloc_coherent(&pdev->dev,
9438 sizeof(struct ipr_hostrcb),
9439 &ioa_cfg->hostrcb_dma[i],
9442 if (!ioa_cfg->hostrcb[i])
9443 goto out_free_hostrcb_dma;
9445 ioa_cfg->hostrcb[i]->hostrcb_dma =
9446 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
9447 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
9448 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
9451 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
9452 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
9454 if (!ioa_cfg->trace)
9455 goto out_free_hostrcb_dma;
9462 out_free_hostrcb_dma:
9464 dma_free_coherent(&pdev->dev, sizeof(struct ipr_hostrcb),
9465 ioa_cfg->hostrcb[i],
9466 ioa_cfg->hostrcb_dma[i]);
9468 dma_free_coherent(&pdev->dev, ioa_cfg->cfg_table_size,
9469 ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
9471 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9472 dma_free_coherent(&pdev->dev,
9473 sizeof(u32) * ioa_cfg->hrrq[i].size,
9474 ioa_cfg->hrrq[i].host_rrq,
9475 ioa_cfg->hrrq[i].host_rrq_dma);
9477 out_ipr_free_cmd_blocks:
9478 ipr_free_cmd_blks(ioa_cfg);
9480 dma_free_coherent(&pdev->dev, sizeof(struct ipr_misc_cbs),
9481 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
9482 out_free_res_entries:
9483 kfree(ioa_cfg->res_entries);
9488 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
9489 * @ioa_cfg: ioa config struct
9494 static void ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
9498 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
9499 ioa_cfg->bus_attr[i].bus = i;
9500 ioa_cfg->bus_attr[i].qas_enabled = 0;
9501 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
9502 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
9503 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
9505 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
9510 * ipr_init_regs - Initialize IOA registers
9511 * @ioa_cfg: ioa config struct
9516 static void ipr_init_regs(struct ipr_ioa_cfg *ioa_cfg)
9518 const struct ipr_interrupt_offsets *p;
9519 struct ipr_interrupts *t;
9522 p = &ioa_cfg->chip_cfg->regs;
9524 base = ioa_cfg->hdw_dma_regs;
9526 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
9527 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
9528 t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
9529 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
9530 t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
9531 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
9532 t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
9533 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
9534 t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
9535 t->ioarrin_reg = base + p->ioarrin_reg;
9536 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
9537 t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
9538 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
9539 t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
9540 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
9541 t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
9543 if (ioa_cfg->sis64) {
9544 t->init_feedback_reg = base + p->init_feedback_reg;
9545 t->dump_addr_reg = base + p->dump_addr_reg;
9546 t->dump_data_reg = base + p->dump_data_reg;
9547 t->endian_swap_reg = base + p->endian_swap_reg;
9552 * ipr_init_ioa_cfg - Initialize IOA config struct
9553 * @ioa_cfg: ioa config struct
9554 * @host: scsi host struct
9555 * @pdev: PCI dev struct
9560 static void ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
9561 struct Scsi_Host *host, struct pci_dev *pdev)
9565 ioa_cfg->host = host;
9566 ioa_cfg->pdev = pdev;
9567 ioa_cfg->log_level = ipr_log_level;
9568 ioa_cfg->doorbell = IPR_DOORBELL;
9569 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
9570 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
9571 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
9572 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
9573 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
9574 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
9576 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
9577 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
9578 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
9579 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
9580 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
9581 init_waitqueue_head(&ioa_cfg->reset_wait_q);
9582 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9583 init_waitqueue_head(&ioa_cfg->eeh_wait_q);
9584 ioa_cfg->sdt_state = INACTIVE;
9586 ipr_initialize_bus_attr(ioa_cfg);
9587 ioa_cfg->max_devs_supported = ipr_max_devs;
9589 if (ioa_cfg->sis64) {
9590 host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
9591 host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
9592 if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
9593 ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
9594 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
9595 + ((sizeof(struct ipr_config_table_entry64)
9596 * ioa_cfg->max_devs_supported)));
9598 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
9599 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
9600 if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
9601 ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
9602 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
9603 + ((sizeof(struct ipr_config_table_entry)
9604 * ioa_cfg->max_devs_supported)));
9607 host->max_channel = IPR_VSET_BUS;
9608 host->unique_id = host->host_no;
9609 host->max_cmd_len = IPR_MAX_CDB_LEN;
9610 host->can_queue = ioa_cfg->max_cmds;
9611 pci_set_drvdata(pdev, ioa_cfg);
9613 for (i = 0; i < ARRAY_SIZE(ioa_cfg->hrrq); i++) {
9614 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_free_q);
9615 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_pending_q);
9616 spin_lock_init(&ioa_cfg->hrrq[i]._lock);
9618 ioa_cfg->hrrq[i].lock = ioa_cfg->host->host_lock;
9620 ioa_cfg->hrrq[i].lock = &ioa_cfg->hrrq[i]._lock;
9625 * ipr_get_chip_info - Find adapter chip information
9626 * @dev_id: PCI device id struct
9629 * ptr to chip information on success / NULL on failure
9631 static const struct ipr_chip_t *
9632 ipr_get_chip_info(const struct pci_device_id *dev_id)
9636 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
9637 if (ipr_chip[i].vendor == dev_id->vendor &&
9638 ipr_chip[i].device == dev_id->device)
9639 return &ipr_chip[i];
9644 * ipr_wait_for_pci_err_recovery - Wait for any PCI error recovery to complete
9646 * @ioa_cfg: ioa config struct
9651 static void ipr_wait_for_pci_err_recovery(struct ipr_ioa_cfg *ioa_cfg)
9653 struct pci_dev *pdev = ioa_cfg->pdev;
9655 if (pci_channel_offline(pdev)) {
9656 wait_event_timeout(ioa_cfg->eeh_wait_q,
9657 !pci_channel_offline(pdev),
9658 IPR_PCI_ERROR_RECOVERY_TIMEOUT);
9659 pci_restore_state(pdev);
9663 static int ipr_enable_msix(struct ipr_ioa_cfg *ioa_cfg)
9665 struct msix_entry entries[IPR_MAX_MSIX_VECTORS];
9668 for (i = 0; i < ARRAY_SIZE(entries); ++i)
9669 entries[i].entry = i;
9671 vectors = pci_enable_msix_range(ioa_cfg->pdev,
9672 entries, 1, ipr_number_of_msix);
9674 ipr_wait_for_pci_err_recovery(ioa_cfg);
9678 for (i = 0; i < vectors; i++)
9679 ioa_cfg->vectors_info[i].vec = entries[i].vector;
9680 ioa_cfg->nvectors = vectors;
9685 static int ipr_enable_msi(struct ipr_ioa_cfg *ioa_cfg)
9689 vectors = pci_enable_msi_range(ioa_cfg->pdev, 1, ipr_number_of_msix);
9691 ipr_wait_for_pci_err_recovery(ioa_cfg);
9695 for (i = 0; i < vectors; i++)
9696 ioa_cfg->vectors_info[i].vec = ioa_cfg->pdev->irq + i;
9697 ioa_cfg->nvectors = vectors;
9702 static void name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
9704 int vec_idx, n = sizeof(ioa_cfg->vectors_info[0].desc) - 1;
9706 for (vec_idx = 0; vec_idx < ioa_cfg->nvectors; vec_idx++) {
9707 snprintf(ioa_cfg->vectors_info[vec_idx].desc, n,
9708 "host%d-%d", ioa_cfg->host->host_no, vec_idx);
9709 ioa_cfg->vectors_info[vec_idx].
9710 desc[strlen(ioa_cfg->vectors_info[vec_idx].desc)] = 0;
9714 static int ipr_request_other_msi_irqs(struct ipr_ioa_cfg *ioa_cfg)
9718 for (i = 1; i < ioa_cfg->nvectors; i++) {
9719 rc = request_irq(ioa_cfg->vectors_info[i].vec,
9722 ioa_cfg->vectors_info[i].desc,
9726 free_irq(ioa_cfg->vectors_info[i].vec,
9735 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
9736 * @pdev: PCI device struct
9738 * Description: Simply set the msi_received flag to 1 indicating that
9739 * Message Signaled Interrupts are supported.
9742 * 0 on success / non-zero on failure
9744 static irqreturn_t ipr_test_intr(int irq, void *devp)
9746 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
9747 unsigned long lock_flags = 0;
9748 irqreturn_t rc = IRQ_HANDLED;
9750 dev_info(&ioa_cfg->pdev->dev, "Received IRQ : %d\n", irq);
9751 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9753 ioa_cfg->msi_received = 1;
9754 wake_up(&ioa_cfg->msi_wait_q);
9756 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9761 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
9762 * @pdev: PCI device struct
9764 * Description: The return value from pci_enable_msi_range() can not always be
9765 * trusted. This routine sets up and initiates a test interrupt to determine
9766 * if the interrupt is received via the ipr_test_intr() service routine.
9767 * If the tests fails, the driver will fall back to LSI.
9770 * 0 on success / non-zero on failure
9772 static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
9775 volatile u32 int_reg;
9776 unsigned long lock_flags = 0;
9780 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9781 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9782 ioa_cfg->msi_received = 0;
9783 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9784 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
9785 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
9786 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9788 if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9789 rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
9791 rc = request_irq(pdev->irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
9793 dev_err(&pdev->dev, "Can not assign irq %d\n", pdev->irq);
9795 } else if (ipr_debug)
9796 dev_info(&pdev->dev, "IRQ assigned: %d\n", pdev->irq);
9798 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
9799 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
9800 wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
9801 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9802 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9804 if (!ioa_cfg->msi_received) {
9805 /* MSI test failed */
9806 dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
9808 } else if (ipr_debug)
9809 dev_info(&pdev->dev, "MSI test succeeded.\n");
9811 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9813 if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9814 free_irq(ioa_cfg->vectors_info[0].vec, ioa_cfg);
9816 free_irq(pdev->irq, ioa_cfg);
9823 /* ipr_probe_ioa - Allocates memory and does first stage of initialization
9824 * @pdev: PCI device struct
9825 * @dev_id: PCI device id struct
9828 * 0 on success / non-zero on failure
9830 static int ipr_probe_ioa(struct pci_dev *pdev,
9831 const struct pci_device_id *dev_id)
9833 struct ipr_ioa_cfg *ioa_cfg;
9834 struct Scsi_Host *host;
9835 unsigned long ipr_regs_pci;
9836 void __iomem *ipr_regs;
9837 int rc = PCIBIOS_SUCCESSFUL;
9838 volatile u32 mask, uproc, interrupts;
9839 unsigned long lock_flags, driver_lock_flags;
9843 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
9844 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
9847 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
9852 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
9853 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
9854 ata_host_init(&ioa_cfg->ata_host, &pdev->dev, &ipr_sata_ops);
9856 ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
9858 if (!ioa_cfg->ipr_chip) {
9859 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
9860 dev_id->vendor, dev_id->device);
9861 goto out_scsi_host_put;
9864 /* set SIS 32 or SIS 64 */
9865 ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
9866 ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
9867 ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
9868 ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
9870 if (ipr_transop_timeout)
9871 ioa_cfg->transop_timeout = ipr_transop_timeout;
9872 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
9873 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
9875 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
9877 ioa_cfg->revid = pdev->revision;
9879 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
9881 ipr_regs_pci = pci_resource_start(pdev, 0);
9883 rc = pci_request_regions(pdev, IPR_NAME);
9886 "Couldn't register memory range of registers\n");
9887 goto out_scsi_host_put;
9890 rc = pci_enable_device(pdev);
9892 if (rc || pci_channel_offline(pdev)) {
9893 if (pci_channel_offline(pdev)) {
9894 ipr_wait_for_pci_err_recovery(ioa_cfg);
9895 rc = pci_enable_device(pdev);
9899 dev_err(&pdev->dev, "Cannot enable adapter\n");
9900 ipr_wait_for_pci_err_recovery(ioa_cfg);
9901 goto out_release_regions;
9905 ipr_regs = pci_ioremap_bar(pdev, 0);
9909 "Couldn't map memory range of registers\n");
9914 ioa_cfg->hdw_dma_regs = ipr_regs;
9915 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
9916 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
9918 ipr_init_regs(ioa_cfg);
9920 if (ioa_cfg->sis64) {
9921 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
9923 dev_dbg(&pdev->dev, "Failed to set 64 bit DMA mask\n");
9924 rc = dma_set_mask_and_coherent(&pdev->dev,
9928 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
9931 dev_err(&pdev->dev, "Failed to set DMA mask\n");
9935 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
9936 ioa_cfg->chip_cfg->cache_line_size);
9938 if (rc != PCIBIOS_SUCCESSFUL) {
9939 dev_err(&pdev->dev, "Write of cache line size failed\n");
9940 ipr_wait_for_pci_err_recovery(ioa_cfg);
9945 /* Issue MMIO read to ensure card is not in EEH */
9946 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg);
9947 ipr_wait_for_pci_err_recovery(ioa_cfg);
9949 if (ipr_number_of_msix > IPR_MAX_MSIX_VECTORS) {
9950 dev_err(&pdev->dev, "The max number of MSIX is %d\n",
9951 IPR_MAX_MSIX_VECTORS);
9952 ipr_number_of_msix = IPR_MAX_MSIX_VECTORS;
9955 if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
9956 ipr_enable_msix(ioa_cfg) == 0)
9957 ioa_cfg->intr_flag = IPR_USE_MSIX;
9958 else if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
9959 ipr_enable_msi(ioa_cfg) == 0)
9960 ioa_cfg->intr_flag = IPR_USE_MSI;
9962 ioa_cfg->intr_flag = IPR_USE_LSI;
9963 ioa_cfg->nvectors = 1;
9964 dev_info(&pdev->dev, "Cannot enable MSI.\n");
9967 pci_set_master(pdev);
9969 if (pci_channel_offline(pdev)) {
9970 ipr_wait_for_pci_err_recovery(ioa_cfg);
9971 pci_set_master(pdev);
9972 if (pci_channel_offline(pdev)) {
9974 goto out_msi_disable;
9978 if (ioa_cfg->intr_flag == IPR_USE_MSI ||
9979 ioa_cfg->intr_flag == IPR_USE_MSIX) {
9980 rc = ipr_test_msi(ioa_cfg, pdev);
9981 if (rc == -EOPNOTSUPP) {
9982 ipr_wait_for_pci_err_recovery(ioa_cfg);
9983 if (ioa_cfg->intr_flag == IPR_USE_MSI) {
9984 ioa_cfg->intr_flag &= ~IPR_USE_MSI;
9985 pci_disable_msi(pdev);
9986 } else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
9987 ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
9988 pci_disable_msix(pdev);
9991 ioa_cfg->intr_flag = IPR_USE_LSI;
9992 ioa_cfg->nvectors = 1;
9995 goto out_msi_disable;
9997 if (ioa_cfg->intr_flag == IPR_USE_MSI)
9998 dev_info(&pdev->dev,
9999 "Request for %d MSIs succeeded with starting IRQ: %d\n",
10000 ioa_cfg->nvectors, pdev->irq);
10001 else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
10002 dev_info(&pdev->dev,
10003 "Request for %d MSIXs succeeded.",
10004 ioa_cfg->nvectors);
10008 ioa_cfg->hrrq_num = min3(ioa_cfg->nvectors,
10009 (unsigned int)num_online_cpus(),
10010 (unsigned int)IPR_MAX_HRRQ_NUM);
10012 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
10013 goto out_msi_disable;
10015 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
10016 goto out_msi_disable;
10018 rc = ipr_alloc_mem(ioa_cfg);
10020 dev_err(&pdev->dev,
10021 "Couldn't allocate enough memory for device driver!\n");
10022 goto out_msi_disable;
10025 /* Save away PCI config space for use following IOA reset */
10026 rc = pci_save_state(pdev);
10028 if (rc != PCIBIOS_SUCCESSFUL) {
10029 dev_err(&pdev->dev, "Failed to save PCI config space\n");
10031 goto cleanup_nolog;
10035 * If HRRQ updated interrupt is not masked, or reset alert is set,
10036 * the card is in an unknown state and needs a hard reset
10038 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
10039 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
10040 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
10041 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
10042 ioa_cfg->needs_hard_reset = 1;
10043 if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
10044 ioa_cfg->needs_hard_reset = 1;
10045 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
10046 ioa_cfg->ioa_unit_checked = 1;
10048 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
10049 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
10050 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
10052 if (ioa_cfg->intr_flag == IPR_USE_MSI
10053 || ioa_cfg->intr_flag == IPR_USE_MSIX) {
10054 name_msi_vectors(ioa_cfg);
10055 rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_isr,
10057 ioa_cfg->vectors_info[0].desc,
10058 &ioa_cfg->hrrq[0]);
10060 rc = ipr_request_other_msi_irqs(ioa_cfg);
10062 rc = request_irq(pdev->irq, ipr_isr,
10064 IPR_NAME, &ioa_cfg->hrrq[0]);
10067 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
10069 goto cleanup_nolog;
10072 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
10073 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
10074 ioa_cfg->needs_warm_reset = 1;
10075 ioa_cfg->reset = ipr_reset_slot_reset;
10077 ioa_cfg->reset_work_q = alloc_ordered_workqueue("ipr_reset_%d",
10078 WQ_MEM_RECLAIM, host->host_no);
10080 if (!ioa_cfg->reset_work_q) {
10081 dev_err(&pdev->dev, "Couldn't register reset workqueue\n");
10085 ioa_cfg->reset = ipr_reset_start_bist;
10087 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
10088 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
10089 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
10096 ipr_free_irqs(ioa_cfg);
10098 ipr_free_mem(ioa_cfg);
10100 ipr_wait_for_pci_err_recovery(ioa_cfg);
10101 if (ioa_cfg->intr_flag == IPR_USE_MSI)
10102 pci_disable_msi(pdev);
10103 else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
10104 pci_disable_msix(pdev);
10108 pci_disable_device(pdev);
10109 out_release_regions:
10110 pci_release_regions(pdev);
10112 scsi_host_put(host);
10117 * ipr_initiate_ioa_bringdown - Bring down an adapter
10118 * @ioa_cfg: ioa config struct
10119 * @shutdown_type: shutdown type
10121 * Description: This function will initiate bringing down the adapter.
10122 * This consists of issuing an IOA shutdown to the adapter
10123 * to flush the cache, and running BIST.
10124 * If the caller needs to wait on the completion of the reset,
10125 * the caller must sleep on the reset_wait_q.
10130 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
10131 enum ipr_shutdown_type shutdown_type)
10134 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
10135 ioa_cfg->sdt_state = ABORT_DUMP;
10136 ioa_cfg->reset_retries = 0;
10137 ioa_cfg->in_ioa_bringdown = 1;
10138 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
10143 * __ipr_remove - Remove a single adapter
10144 * @pdev: pci device struct
10146 * Adapter hot plug remove entry point.
10151 static void __ipr_remove(struct pci_dev *pdev)
10153 unsigned long host_lock_flags = 0;
10154 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
10156 unsigned long driver_lock_flags;
10159 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
10160 while (ioa_cfg->in_reset_reload) {
10161 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
10162 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
10163 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
10166 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
10167 spin_lock(&ioa_cfg->hrrq[i]._lock);
10168 ioa_cfg->hrrq[i].removing_ioa = 1;
10169 spin_unlock(&ioa_cfg->hrrq[i]._lock);
10172 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
10174 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
10175 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
10176 flush_work(&ioa_cfg->work_q);
10177 if (ioa_cfg->reset_work_q)
10178 flush_workqueue(ioa_cfg->reset_work_q);
10179 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
10180 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
10182 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
10183 list_del(&ioa_cfg->queue);
10184 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
10186 if (ioa_cfg->sdt_state == ABORT_DUMP)
10187 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
10188 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
10190 ipr_free_all_resources(ioa_cfg);
10196 * ipr_remove - IOA hot plug remove entry point
10197 * @pdev: pci device struct
10199 * Adapter hot plug remove entry point.
10204 static void ipr_remove(struct pci_dev *pdev)
10206 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
10210 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
10212 ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
10214 scsi_remove_host(ioa_cfg->host);
10216 __ipr_remove(pdev);
10222 * ipr_probe - Adapter hot plug add entry point
10225 * 0 on success / non-zero on failure
10227 static int ipr_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
10229 struct ipr_ioa_cfg *ioa_cfg;
10232 rc = ipr_probe_ioa(pdev, dev_id);
10237 ioa_cfg = pci_get_drvdata(pdev);
10238 rc = ipr_probe_ioa_part2(ioa_cfg);
10241 __ipr_remove(pdev);
10245 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
10248 __ipr_remove(pdev);
10252 rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
10256 scsi_remove_host(ioa_cfg->host);
10257 __ipr_remove(pdev);
10261 rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
10265 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
10267 scsi_remove_host(ioa_cfg->host);
10268 __ipr_remove(pdev);
10272 scsi_scan_host(ioa_cfg->host);
10273 ioa_cfg->iopoll_weight = ioa_cfg->chip_cfg->iopoll_weight;
10275 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
10276 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
10277 blk_iopoll_init(&ioa_cfg->hrrq[i].iopoll,
10278 ioa_cfg->iopoll_weight, ipr_iopoll);
10279 blk_iopoll_enable(&ioa_cfg->hrrq[i].iopoll);
10283 schedule_work(&ioa_cfg->work_q);
10288 * ipr_shutdown - Shutdown handler.
10289 * @pdev: pci device struct
10291 * This function is invoked upon system shutdown/reboot. It will issue
10292 * an adapter shutdown to the adapter to flush the write cache.
10297 static void ipr_shutdown(struct pci_dev *pdev)
10299 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
10300 unsigned long lock_flags = 0;
10301 enum ipr_shutdown_type shutdown_type = IPR_SHUTDOWN_NORMAL;
10304 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
10305 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
10306 ioa_cfg->iopoll_weight = 0;
10307 for (i = 1; i < ioa_cfg->hrrq_num; i++)
10308 blk_iopoll_disable(&ioa_cfg->hrrq[i].iopoll);
10311 while (ioa_cfg->in_reset_reload) {
10312 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
10313 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
10314 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
10317 if (ipr_fast_reboot && system_state == SYSTEM_RESTART && ioa_cfg->sis64)
10318 shutdown_type = IPR_SHUTDOWN_QUIESCE;
10320 ipr_initiate_ioa_bringdown(ioa_cfg, shutdown_type);
10321 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
10322 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
10323 if (ipr_fast_reboot && system_state == SYSTEM_RESTART && ioa_cfg->sis64) {
10324 ipr_free_irqs(ioa_cfg);
10325 pci_disable_device(ioa_cfg->pdev);
10329 static struct pci_device_id ipr_pci_table[] = {
10330 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
10331 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
10332 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
10333 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
10334 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
10335 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
10336 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
10337 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
10338 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
10339 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
10340 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
10341 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
10342 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
10343 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
10344 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
10345 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
10346 IPR_USE_LONG_TRANSOP_TIMEOUT },
10347 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
10348 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
10349 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
10350 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
10351 IPR_USE_LONG_TRANSOP_TIMEOUT },
10352 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
10353 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
10354 IPR_USE_LONG_TRANSOP_TIMEOUT },
10355 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
10356 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
10357 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
10358 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
10359 IPR_USE_LONG_TRANSOP_TIMEOUT},
10360 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
10361 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
10362 IPR_USE_LONG_TRANSOP_TIMEOUT },
10363 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
10364 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
10365 IPR_USE_LONG_TRANSOP_TIMEOUT },
10366 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
10367 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
10368 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
10369 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
10370 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
10371 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
10372 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
10373 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
10374 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
10375 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
10376 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
10377 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
10378 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
10379 IPR_USE_LONG_TRANSOP_TIMEOUT },
10380 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
10381 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
10382 IPR_USE_LONG_TRANSOP_TIMEOUT },
10383 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10384 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
10385 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10386 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
10387 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10388 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
10389 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10390 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C0, 0, 0, 0 },
10391 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10392 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
10393 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10394 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
10395 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10396 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
10397 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10398 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
10399 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10400 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
10401 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10402 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
10403 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10404 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
10405 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10406 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D5, 0, 0, 0 },
10407 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10408 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D6, 0, 0, 0 },
10409 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10410 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D7, 0, 0, 0 },
10411 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10412 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D8, 0, 0, 0 },
10413 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10414 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D9, 0, 0, 0 },
10415 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10416 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57DA, 0, 0, 0 },
10417 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10418 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EB, 0, 0, 0 },
10419 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10420 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EC, 0, 0, 0 },
10421 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10422 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57ED, 0, 0, 0 },
10423 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10424 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EE, 0, 0, 0 },
10425 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10426 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EF, 0, 0, 0 },
10427 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10428 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57F0, 0, 0, 0 },
10429 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10430 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCA, 0, 0, 0 },
10431 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10432 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CD2, 0, 0, 0 },
10433 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10434 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCD, 0, 0, 0 },
10437 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
10439 static const struct pci_error_handlers ipr_err_handler = {
10440 .error_detected = ipr_pci_error_detected,
10441 .mmio_enabled = ipr_pci_mmio_enabled,
10442 .slot_reset = ipr_pci_slot_reset,
10445 static struct pci_driver ipr_driver = {
10447 .id_table = ipr_pci_table,
10448 .probe = ipr_probe,
10449 .remove = ipr_remove,
10450 .shutdown = ipr_shutdown,
10451 .err_handler = &ipr_err_handler,
10455 * ipr_halt_done - Shutdown prepare completion
10460 static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
10462 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
10466 * ipr_halt - Issue shutdown prepare to all adapters
10469 * NOTIFY_OK on success / NOTIFY_DONE on failure
10471 static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
10473 struct ipr_cmnd *ipr_cmd;
10474 struct ipr_ioa_cfg *ioa_cfg;
10475 unsigned long flags = 0, driver_lock_flags;
10477 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
10478 return NOTIFY_DONE;
10480 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
10482 list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
10483 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
10484 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds ||
10485 (ipr_fast_reboot && event == SYS_RESTART && ioa_cfg->sis64)) {
10486 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10490 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
10491 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
10492 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
10493 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
10494 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
10496 ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
10497 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10499 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
10504 static struct notifier_block ipr_notifier = {
10509 * ipr_init - Module entry point
10512 * 0 on success / negative value on failure
10514 static int __init ipr_init(void)
10516 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
10517 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
10519 register_reboot_notifier(&ipr_notifier);
10520 return pci_register_driver(&ipr_driver);
10524 * ipr_exit - Module unload
10526 * Module unload entry point.
10531 static void __exit ipr_exit(void)
10533 unregister_reboot_notifier(&ipr_notifier);
10534 pci_unregister_driver(&ipr_driver);
10537 module_init(ipr_init);
10538 module_exit(ipr_exit);