2 * ipr.c -- driver for IBM Power Linux RAID adapters
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 DEFINE_SPINLOCK(ipr_driver_lock);
104 /* This table describes the differences between DMA controller chips */
105 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
106 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
109 .cache_line_size = 0x20,
113 .set_interrupt_mask_reg = 0x0022C,
114 .clr_interrupt_mask_reg = 0x00230,
115 .clr_interrupt_mask_reg32 = 0x00230,
116 .sense_interrupt_mask_reg = 0x0022C,
117 .sense_interrupt_mask_reg32 = 0x0022C,
118 .clr_interrupt_reg = 0x00228,
119 .clr_interrupt_reg32 = 0x00228,
120 .sense_interrupt_reg = 0x00224,
121 .sense_interrupt_reg32 = 0x00224,
122 .ioarrin_reg = 0x00404,
123 .sense_uproc_interrupt_reg = 0x00214,
124 .sense_uproc_interrupt_reg32 = 0x00214,
125 .set_uproc_interrupt_reg = 0x00214,
126 .set_uproc_interrupt_reg32 = 0x00214,
127 .clr_uproc_interrupt_reg = 0x00218,
128 .clr_uproc_interrupt_reg32 = 0x00218
131 { /* Snipe and Scamp */
134 .cache_line_size = 0x20,
138 .set_interrupt_mask_reg = 0x00288,
139 .clr_interrupt_mask_reg = 0x0028C,
140 .clr_interrupt_mask_reg32 = 0x0028C,
141 .sense_interrupt_mask_reg = 0x00288,
142 .sense_interrupt_mask_reg32 = 0x00288,
143 .clr_interrupt_reg = 0x00284,
144 .clr_interrupt_reg32 = 0x00284,
145 .sense_interrupt_reg = 0x00280,
146 .sense_interrupt_reg32 = 0x00280,
147 .ioarrin_reg = 0x00504,
148 .sense_uproc_interrupt_reg = 0x00290,
149 .sense_uproc_interrupt_reg32 = 0x00290,
150 .set_uproc_interrupt_reg = 0x00290,
151 .set_uproc_interrupt_reg32 = 0x00290,
152 .clr_uproc_interrupt_reg = 0x00294,
153 .clr_uproc_interrupt_reg32 = 0x00294
159 .cache_line_size = 0x20,
163 .set_interrupt_mask_reg = 0x00010,
164 .clr_interrupt_mask_reg = 0x00018,
165 .clr_interrupt_mask_reg32 = 0x0001C,
166 .sense_interrupt_mask_reg = 0x00010,
167 .sense_interrupt_mask_reg32 = 0x00014,
168 .clr_interrupt_reg = 0x00008,
169 .clr_interrupt_reg32 = 0x0000C,
170 .sense_interrupt_reg = 0x00000,
171 .sense_interrupt_reg32 = 0x00004,
172 .ioarrin_reg = 0x00070,
173 .sense_uproc_interrupt_reg = 0x00020,
174 .sense_uproc_interrupt_reg32 = 0x00024,
175 .set_uproc_interrupt_reg = 0x00020,
176 .set_uproc_interrupt_reg32 = 0x00024,
177 .clr_uproc_interrupt_reg = 0x00028,
178 .clr_uproc_interrupt_reg32 = 0x0002C,
179 .init_feedback_reg = 0x0005C,
180 .dump_addr_reg = 0x00064,
181 .dump_data_reg = 0x00068,
182 .endian_swap_reg = 0x00084
187 static const struct ipr_chip_t ipr_chip[] = {
188 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
189 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
190 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
191 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
192 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, IPR_USE_MSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
193 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
194 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
195 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
196 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
199 static int ipr_max_bus_speeds[] = {
200 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
204 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
205 module_param_named(max_speed, ipr_max_speed, uint, 0);
206 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
207 module_param_named(log_level, ipr_log_level, uint, 0);
208 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
209 module_param_named(testmode, ipr_testmode, int, 0);
210 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
211 module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
212 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
213 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
214 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
215 module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
216 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
217 module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
218 MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
219 module_param_named(max_devs, ipr_max_devs, int, 0);
220 MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
221 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
222 module_param_named(number_of_msix, ipr_number_of_msix, int, 0);
223 MODULE_PARM_DESC(number_of_msix, "Specify the number of MSIX interrupts to use on capable adapters (1 - 16). (default:2)");
224 MODULE_LICENSE("GPL");
225 MODULE_VERSION(IPR_DRIVER_VERSION);
227 /* A constant array of IOASCs/URCs/Error Messages */
229 struct ipr_error_table_t ipr_error_table[] = {
230 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
231 "8155: An unknown error was received"},
233 "Soft underlength error"},
235 "Command to be cancelled not found"},
237 "Qualified success"},
238 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
239 "FFFE: Soft device bus error recovered by the IOA"},
240 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
241 "4101: Soft device bus fabric error"},
242 {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
243 "FFFC: Logical block guard error recovered by the device"},
244 {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
245 "FFFC: Logical block reference tag error recovered by the device"},
246 {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
247 "4171: Recovered scatter list tag / sequence number error"},
248 {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
249 "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
250 {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
251 "4171: Recovered logical block sequence number error on IOA to Host transfer"},
252 {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
253 "FFFD: Recovered logical block reference tag error detected by the IOA"},
254 {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
255 "FFFD: Logical block guard error recovered by the IOA"},
256 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
257 "FFF9: Device sector reassign successful"},
258 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
259 "FFF7: Media error recovered by device rewrite procedures"},
260 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
261 "7001: IOA sector reassignment successful"},
262 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
263 "FFF9: Soft media error. Sector reassignment recommended"},
264 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
265 "FFF7: Media error recovered by IOA rewrite procedures"},
266 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
267 "FF3D: Soft PCI bus error recovered by the IOA"},
268 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
269 "FFF6: Device hardware error recovered by the IOA"},
270 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
271 "FFF6: Device hardware error recovered by the device"},
272 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
273 "FF3D: Soft IOA error recovered by the IOA"},
274 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
275 "FFFA: Undefined device response recovered by the IOA"},
276 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
277 "FFF6: Device bus error, message or command phase"},
278 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
279 "FFFE: Task Management Function failed"},
280 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
281 "FFF6: Failure prediction threshold exceeded"},
282 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
283 "8009: Impending cache battery pack failure"},
285 "Logical Unit in process of becoming ready"},
287 "Initializing command required"},
289 "34FF: Disk device format in progress"},
291 "Logical unit not accessible, target port in unavailable state"},
292 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
293 "9070: IOA requested reset"},
295 "Synchronization required"},
297 "IOA microcode download required"},
299 "Device bus connection is prohibited by host"},
301 "No ready, IOA shutdown"},
303 "Not ready, IOA has been shutdown"},
304 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
305 "3020: Storage subsystem configuration error"},
307 "FFF5: Medium error, data unreadable, recommend reassign"},
309 "7000: Medium error, data unreadable, do not reassign"},
310 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
311 "FFF3: Disk media format bad"},
312 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
313 "3002: Addressed device failed to respond to selection"},
314 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
315 "3100: Device bus error"},
316 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
317 "3109: IOA timed out a device command"},
319 "3120: SCSI bus is not operational"},
320 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
321 "4100: Hard device bus fabric error"},
322 {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
323 "310C: Logical block guard error detected by the device"},
324 {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
325 "310C: Logical block reference tag error detected by the device"},
326 {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
327 "4170: Scatter list tag / sequence number error"},
328 {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
329 "8150: Logical block CRC error on IOA to Host transfer"},
330 {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
331 "4170: Logical block sequence number error on IOA to Host transfer"},
332 {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
333 "310D: Logical block reference tag error detected by the IOA"},
334 {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
335 "310D: Logical block guard error detected by the IOA"},
336 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
337 "9000: IOA reserved area data check"},
338 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
339 "9001: IOA reserved area invalid data pattern"},
340 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
341 "9002: IOA reserved area LRC error"},
342 {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
343 "Hardware Error, IOA metadata access error"},
344 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
345 "102E: Out of alternate sectors for disk storage"},
346 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
347 "FFF4: Data transfer underlength error"},
348 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
349 "FFF4: Data transfer overlength error"},
350 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
351 "3400: Logical unit failure"},
352 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
353 "FFF4: Device microcode is corrupt"},
354 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
355 "8150: PCI bus error"},
357 "Unsupported device bus message received"},
358 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
359 "FFF4: Disk device problem"},
360 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
361 "8150: Permanent IOA failure"},
362 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
363 "3010: Disk device returned wrong response to IOA"},
364 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
365 "8151: IOA microcode error"},
367 "Device bus status error"},
368 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
369 "8157: IOA error requiring IOA reset to recover"},
371 "ATA device status error"},
373 "Message reject received from the device"},
374 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
375 "8008: A permanent cache battery pack failure occurred"},
376 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
377 "9090: Disk unit has been modified after the last known status"},
378 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
379 "9081: IOA detected device error"},
380 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
381 "9082: IOA detected device error"},
382 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
383 "3110: Device bus error, message or command phase"},
384 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
385 "3110: SAS Command / Task Management Function failed"},
386 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
387 "9091: Incorrect hardware configuration change has been detected"},
388 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
389 "9073: Invalid multi-adapter configuration"},
390 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
391 "4010: Incorrect connection between cascaded expanders"},
392 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
393 "4020: Connections exceed IOA design limits"},
394 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
395 "4030: Incorrect multipath connection"},
396 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
397 "4110: Unsupported enclosure function"},
398 {0x04679800, 0, IPR_DEFAULT_LOG_LEVEL,
399 "4120: SAS cable VPD cannot be read"},
400 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
401 "FFF4: Command to logical unit failed"},
403 "Illegal request, invalid request type or request packet"},
405 "Illegal request, invalid resource handle"},
407 "Illegal request, commands not allowed to this device"},
409 "Illegal request, command not allowed to a secondary adapter"},
411 "Illegal request, command not allowed to a non-optimized resource"},
413 "Illegal request, invalid field in parameter list"},
415 "Illegal request, parameter not supported"},
417 "Illegal request, parameter value invalid"},
419 "Illegal request, command sequence error"},
421 "Illegal request, dual adapter support not enabled"},
423 "Illegal request, another cable connector was physically disabled"},
425 "Illegal request, inconsistent group id/group count"},
426 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
427 "9031: Array protection temporarily suspended, protection resuming"},
428 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
429 "9040: Array protection temporarily suspended, protection resuming"},
430 {0x060B0100, 0, IPR_DEFAULT_LOG_LEVEL,
431 "4080: IOA exceeded maximum operating temperature"},
432 {0x060B8000, 0, IPR_DEFAULT_LOG_LEVEL,
433 "4085: Service required"},
434 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
435 "3140: Device bus not ready to ready transition"},
436 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
437 "FFFB: SCSI bus was reset"},
439 "FFFE: SCSI bus transition to single ended"},
441 "FFFE: SCSI bus transition to LVD"},
442 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
443 "FFFB: SCSI bus was reset by another initiator"},
444 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
445 "3029: A device replacement has occurred"},
446 {0x063F8300, 0, IPR_DEFAULT_LOG_LEVEL,
447 "4102: Device bus fabric performance degradation"},
448 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
449 "9051: IOA cache data exists for a missing or failed device"},
450 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
451 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
452 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
453 "9025: Disk unit is not supported at its physical location"},
454 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
455 "3020: IOA detected a SCSI bus configuration error"},
456 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
457 "3150: SCSI bus configuration error"},
458 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
459 "9074: Asymmetric advanced function disk configuration"},
460 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
461 "4040: Incomplete multipath connection between IOA and enclosure"},
462 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
463 "4041: Incomplete multipath connection between enclosure and device"},
464 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
465 "9075: Incomplete multipath connection between IOA and remote IOA"},
466 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
467 "9076: Configuration error, missing remote IOA"},
468 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
469 "4050: Enclosure does not support a required multipath function"},
470 {0x06679800, 0, IPR_DEFAULT_LOG_LEVEL,
471 "4121: Configuration error, required cable is missing"},
472 {0x06679900, 0, IPR_DEFAULT_LOG_LEVEL,
473 "4122: Cable is not plugged into the correct location on remote IOA"},
474 {0x06679A00, 0, IPR_DEFAULT_LOG_LEVEL,
475 "4123: Configuration error, invalid cable vital product data"},
476 {0x06679B00, 0, IPR_DEFAULT_LOG_LEVEL,
477 "4124: Configuration error, both cable ends are plugged into the same IOA"},
478 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
479 "4070: Logically bad block written on device"},
480 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
481 "9041: Array protection temporarily suspended"},
482 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
483 "9042: Corrupt array parity detected on specified device"},
484 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
485 "9030: Array no longer protected due to missing or failed disk unit"},
486 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
487 "9071: Link operational transition"},
488 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
489 "9072: Link not operational transition"},
490 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
491 "9032: Array exposed but still protected"},
492 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
493 "70DD: Device forced failed by disrupt device command"},
494 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
495 "4061: Multipath redundancy level got better"},
496 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
497 "4060: Multipath redundancy level got worse"},
499 "Failure due to other device"},
500 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
501 "9008: IOA does not support functions expected by devices"},
502 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
503 "9010: Cache data associated with attached devices cannot be found"},
504 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
505 "9011: Cache data belongs to devices other than those attached"},
506 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
507 "9020: Array missing 2 or more devices with only 1 device present"},
508 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
509 "9021: Array missing 2 or more devices with 2 or more devices present"},
510 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
511 "9022: Exposed array is missing a required device"},
512 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
513 "9023: Array member(s) not at required physical locations"},
514 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
515 "9024: Array not functional due to present hardware configuration"},
516 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
517 "9026: Array not functional due to present hardware configuration"},
518 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
519 "9027: Array is missing a device and parity is out of sync"},
520 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
521 "9028: Maximum number of arrays already exist"},
522 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
523 "9050: Required cache data cannot be located for a disk unit"},
524 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
525 "9052: Cache data exists for a device that has been modified"},
526 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
527 "9054: IOA resources not available due to previous problems"},
528 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
529 "9092: Disk unit requires initialization before use"},
530 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
531 "9029: Incorrect hardware configuration change has been detected"},
532 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
533 "9060: One or more disk pairs are missing from an array"},
534 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
535 "9061: One or more disks are missing from an array"},
536 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
537 "9062: One or more disks are missing from an array"},
538 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
539 "9063: Maximum number of functional arrays has been exceeded"},
541 "Data protect, other volume set problem"},
543 "Aborted command, invalid descriptor"},
545 "Target operating conditions have changed, dual adapter takeover"},
547 "Aborted command, medium removal prevented"},
549 "Command terminated by host"},
551 "Aborted command, command terminated by host"}
554 static const struct ipr_ses_table_entry ipr_ses_table[] = {
555 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
556 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
557 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
558 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
559 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
560 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
561 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
562 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
563 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
564 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
565 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
566 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
567 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
571 * Function Prototypes
573 static int ipr_reset_alert(struct ipr_cmnd *);
574 static void ipr_process_ccn(struct ipr_cmnd *);
575 static void ipr_process_error(struct ipr_cmnd *);
576 static void ipr_reset_ioa_job(struct ipr_cmnd *);
577 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
578 enum ipr_shutdown_type);
580 #ifdef CONFIG_SCSI_IPR_TRACE
582 * ipr_trc_hook - Add a trace entry to the driver trace
583 * @ipr_cmd: ipr command struct
585 * @add_data: additional data
590 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
591 u8 type, u32 add_data)
593 struct ipr_trace_entry *trace_entry;
594 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
596 trace_entry = &ioa_cfg->trace[atomic_add_return
597 (1, &ioa_cfg->trace_index)%IPR_NUM_TRACE_ENTRIES];
598 trace_entry->time = jiffies;
599 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
600 trace_entry->type = type;
601 if (ipr_cmd->ioa_cfg->sis64)
602 trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
604 trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
605 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
606 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
607 trace_entry->u.add_data = add_data;
611 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
615 * ipr_lock_and_done - Acquire lock and complete command
616 * @ipr_cmd: ipr command struct
621 static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
623 unsigned long lock_flags;
624 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
626 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
627 ipr_cmd->done(ipr_cmd);
628 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
632 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
633 * @ipr_cmd: ipr command struct
638 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
640 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
641 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
642 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
643 dma_addr_t dma_addr = ipr_cmd->dma_addr;
646 hrrq_id = ioarcb->cmd_pkt.hrrq_id;
647 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
648 ioarcb->cmd_pkt.hrrq_id = hrrq_id;
649 ioarcb->data_transfer_length = 0;
650 ioarcb->read_data_transfer_length = 0;
651 ioarcb->ioadl_len = 0;
652 ioarcb->read_ioadl_len = 0;
654 if (ipr_cmd->ioa_cfg->sis64) {
655 ioarcb->u.sis64_addr_data.data_ioadl_addr =
656 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
657 ioasa64->u.gata.status = 0;
659 ioarcb->write_ioadl_addr =
660 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
661 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
662 ioasa->u.gata.status = 0;
665 ioasa->hdr.ioasc = 0;
666 ioasa->hdr.residual_data_len = 0;
667 ipr_cmd->scsi_cmd = NULL;
669 ipr_cmd->sense_buffer[0] = 0;
670 ipr_cmd->dma_use_sg = 0;
674 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
675 * @ipr_cmd: ipr command struct
680 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
681 void (*fast_done) (struct ipr_cmnd *))
683 ipr_reinit_ipr_cmnd(ipr_cmd);
684 ipr_cmd->u.scratch = 0;
685 ipr_cmd->sibling = NULL;
686 ipr_cmd->eh_comp = NULL;
687 ipr_cmd->fast_done = fast_done;
688 init_timer(&ipr_cmd->timer);
692 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
693 * @ioa_cfg: ioa config struct
696 * pointer to ipr command struct
699 struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_hrr_queue *hrrq)
701 struct ipr_cmnd *ipr_cmd = NULL;
703 if (likely(!list_empty(&hrrq->hrrq_free_q))) {
704 ipr_cmd = list_entry(hrrq->hrrq_free_q.next,
705 struct ipr_cmnd, queue);
706 list_del(&ipr_cmd->queue);
714 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
715 * @ioa_cfg: ioa config struct
718 * pointer to ipr command struct
721 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
723 struct ipr_cmnd *ipr_cmd =
724 __ipr_get_free_ipr_cmnd(&ioa_cfg->hrrq[IPR_INIT_HRRQ]);
725 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
730 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
731 * @ioa_cfg: ioa config struct
732 * @clr_ints: interrupts to clear
734 * This function masks all interrupts on the adapter, then clears the
735 * interrupts specified in the mask
740 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
743 volatile u32 int_reg;
746 /* Stop new interrupts */
747 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
748 spin_lock(&ioa_cfg->hrrq[i]._lock);
749 ioa_cfg->hrrq[i].allow_interrupts = 0;
750 spin_unlock(&ioa_cfg->hrrq[i]._lock);
754 /* Set interrupt mask to stop all new interrupts */
756 writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
758 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
760 /* Clear any pending interrupts */
762 writel(~0, ioa_cfg->regs.clr_interrupt_reg);
763 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
764 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
768 * ipr_save_pcix_cmd_reg - Save PCI-X command register
769 * @ioa_cfg: ioa config struct
772 * 0 on success / -EIO on failure
774 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
776 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
778 if (pcix_cmd_reg == 0)
781 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
782 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
783 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
787 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
792 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
793 * @ioa_cfg: ioa config struct
796 * 0 on success / -EIO on failure
798 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
800 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
803 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
804 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
805 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
814 * ipr_sata_eh_done - done function for aborted SATA commands
815 * @ipr_cmd: ipr command struct
817 * This function is invoked for ops generated to SATA
818 * devices which are being aborted.
823 static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
825 struct ata_queued_cmd *qc = ipr_cmd->qc;
826 struct ipr_sata_port *sata_port = qc->ap->private_data;
828 qc->err_mask |= AC_ERR_OTHER;
829 sata_port->ioasa.status |= ATA_BUSY;
830 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
835 * ipr_scsi_eh_done - mid-layer done function for aborted ops
836 * @ipr_cmd: ipr command struct
838 * This function is invoked by the interrupt handler for
839 * ops generated by the SCSI mid-layer which are being aborted.
844 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
846 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
848 scsi_cmd->result |= (DID_ERROR << 16);
850 scsi_dma_unmap(ipr_cmd->scsi_cmd);
851 scsi_cmd->scsi_done(scsi_cmd);
852 if (ipr_cmd->eh_comp)
853 complete(ipr_cmd->eh_comp);
854 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
858 * ipr_fail_all_ops - Fails all outstanding ops.
859 * @ioa_cfg: ioa config struct
861 * This function fails all outstanding ops.
866 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
868 struct ipr_cmnd *ipr_cmd, *temp;
869 struct ipr_hrr_queue *hrrq;
872 for_each_hrrq(hrrq, ioa_cfg) {
873 spin_lock(&hrrq->_lock);
874 list_for_each_entry_safe(ipr_cmd,
875 temp, &hrrq->hrrq_pending_q, queue) {
876 list_del(&ipr_cmd->queue);
878 ipr_cmd->s.ioasa.hdr.ioasc =
879 cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
880 ipr_cmd->s.ioasa.hdr.ilid =
881 cpu_to_be32(IPR_DRIVER_ILID);
883 if (ipr_cmd->scsi_cmd)
884 ipr_cmd->done = ipr_scsi_eh_done;
885 else if (ipr_cmd->qc)
886 ipr_cmd->done = ipr_sata_eh_done;
888 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH,
889 IPR_IOASC_IOA_WAS_RESET);
890 del_timer(&ipr_cmd->timer);
891 ipr_cmd->done(ipr_cmd);
893 spin_unlock(&hrrq->_lock);
899 * ipr_send_command - Send driver initiated requests.
900 * @ipr_cmd: ipr command struct
902 * This function sends a command to the adapter using the correct write call.
903 * In the case of sis64, calculate the ioarcb size required. Then or in the
909 static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
911 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
912 dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
914 if (ioa_cfg->sis64) {
915 /* The default size is 256 bytes */
916 send_dma_addr |= 0x1;
918 /* If the number of ioadls * size of ioadl > 128 bytes,
919 then use a 512 byte ioarcb */
920 if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
921 send_dma_addr |= 0x4;
922 writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
924 writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
928 * ipr_do_req - Send driver initiated requests.
929 * @ipr_cmd: ipr command struct
930 * @done: done function
931 * @timeout_func: timeout function
932 * @timeout: timeout value
934 * This function sends the specified command to the adapter with the
935 * timeout given. The done function is invoked on command completion.
940 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
941 void (*done) (struct ipr_cmnd *),
942 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
944 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
946 ipr_cmd->done = done;
948 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
949 ipr_cmd->timer.expires = jiffies + timeout;
950 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
952 add_timer(&ipr_cmd->timer);
954 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
956 ipr_send_command(ipr_cmd);
960 * ipr_internal_cmd_done - Op done function for an internally generated op.
961 * @ipr_cmd: ipr command struct
963 * This function is the op done function for an internally generated,
964 * blocking op. It simply wakes the sleeping thread.
969 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
971 if (ipr_cmd->sibling)
972 ipr_cmd->sibling = NULL;
974 complete(&ipr_cmd->completion);
978 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
979 * @ipr_cmd: ipr command struct
980 * @dma_addr: dma address
981 * @len: transfer length
982 * @flags: ioadl flag value
984 * This function initializes an ioadl in the case where there is only a single
990 static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
993 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
994 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
996 ipr_cmd->dma_use_sg = 1;
998 if (ipr_cmd->ioa_cfg->sis64) {
999 ioadl64->flags = cpu_to_be32(flags);
1000 ioadl64->data_len = cpu_to_be32(len);
1001 ioadl64->address = cpu_to_be64(dma_addr);
1003 ipr_cmd->ioarcb.ioadl_len =
1004 cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
1005 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1007 ioadl->flags_and_data_len = cpu_to_be32(flags | len);
1008 ioadl->address = cpu_to_be32(dma_addr);
1010 if (flags == IPR_IOADL_FLAGS_READ_LAST) {
1011 ipr_cmd->ioarcb.read_ioadl_len =
1012 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1013 ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
1015 ipr_cmd->ioarcb.ioadl_len =
1016 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1017 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1023 * ipr_send_blocking_cmd - Send command and sleep on its completion.
1024 * @ipr_cmd: ipr command struct
1025 * @timeout_func: function to invoke if command times out
1031 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
1032 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
1035 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1037 init_completion(&ipr_cmd->completion);
1038 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
1040 spin_unlock_irq(ioa_cfg->host->host_lock);
1041 wait_for_completion(&ipr_cmd->completion);
1042 spin_lock_irq(ioa_cfg->host->host_lock);
1045 static int ipr_get_hrrq_index(struct ipr_ioa_cfg *ioa_cfg)
1047 if (ioa_cfg->hrrq_num == 1)
1050 return (atomic_add_return(1, &ioa_cfg->hrrq_index) % (ioa_cfg->hrrq_num - 1)) + 1;
1054 * ipr_send_hcam - Send an HCAM to the adapter.
1055 * @ioa_cfg: ioa config struct
1057 * @hostrcb: hostrcb struct
1059 * This function will send a Host Controlled Async command to the adapter.
1060 * If HCAMs are currently not allowed to be issued to the adapter, it will
1061 * place the hostrcb on the free queue.
1066 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
1067 struct ipr_hostrcb *hostrcb)
1069 struct ipr_cmnd *ipr_cmd;
1070 struct ipr_ioarcb *ioarcb;
1072 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
1073 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
1074 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
1075 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
1077 ipr_cmd->u.hostrcb = hostrcb;
1078 ioarcb = &ipr_cmd->ioarcb;
1080 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
1081 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
1082 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
1083 ioarcb->cmd_pkt.cdb[1] = type;
1084 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
1085 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
1087 ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
1088 sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
1090 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
1091 ipr_cmd->done = ipr_process_ccn;
1093 ipr_cmd->done = ipr_process_error;
1095 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
1097 ipr_send_command(ipr_cmd);
1099 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
1104 * ipr_update_ata_class - Update the ata class in the resource entry
1105 * @res: resource entry struct
1106 * @proto: cfgte device bus protocol value
1111 static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
1114 case IPR_PROTO_SATA:
1115 case IPR_PROTO_SAS_STP:
1116 res->ata_class = ATA_DEV_ATA;
1118 case IPR_PROTO_SATA_ATAPI:
1119 case IPR_PROTO_SAS_STP_ATAPI:
1120 res->ata_class = ATA_DEV_ATAPI;
1123 res->ata_class = ATA_DEV_UNKNOWN;
1129 * ipr_init_res_entry - Initialize a resource entry struct.
1130 * @res: resource entry struct
1131 * @cfgtew: config table entry wrapper struct
1136 static void ipr_init_res_entry(struct ipr_resource_entry *res,
1137 struct ipr_config_table_entry_wrapper *cfgtew)
1141 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1142 struct ipr_resource_entry *gscsi_res = NULL;
1144 res->needs_sync_complete = 0;
1147 res->del_from_ml = 0;
1148 res->resetting_device = 0;
1149 res->reset_occurred = 0;
1151 res->sata_port = NULL;
1153 if (ioa_cfg->sis64) {
1154 proto = cfgtew->u.cfgte64->proto;
1155 res->res_flags = cfgtew->u.cfgte64->res_flags;
1156 res->qmodel = IPR_QUEUEING_MODEL64(res);
1157 res->type = cfgtew->u.cfgte64->res_type;
1159 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1160 sizeof(res->res_path));
1163 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1164 sizeof(res->dev_lun.scsi_lun));
1165 res->lun = scsilun_to_int(&res->dev_lun);
1167 if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1168 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1169 if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1171 res->target = gscsi_res->target;
1176 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1177 ioa_cfg->max_devs_supported);
1178 set_bit(res->target, ioa_cfg->target_ids);
1180 } else if (res->type == IPR_RES_TYPE_IOAFP) {
1181 res->bus = IPR_IOAFP_VIRTUAL_BUS;
1183 } else if (res->type == IPR_RES_TYPE_ARRAY) {
1184 res->bus = IPR_ARRAY_VIRTUAL_BUS;
1185 res->target = find_first_zero_bit(ioa_cfg->array_ids,
1186 ioa_cfg->max_devs_supported);
1187 set_bit(res->target, ioa_cfg->array_ids);
1188 } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1189 res->bus = IPR_VSET_VIRTUAL_BUS;
1190 res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1191 ioa_cfg->max_devs_supported);
1192 set_bit(res->target, ioa_cfg->vset_ids);
1194 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1195 ioa_cfg->max_devs_supported);
1196 set_bit(res->target, ioa_cfg->target_ids);
1199 proto = cfgtew->u.cfgte->proto;
1200 res->qmodel = IPR_QUEUEING_MODEL(res);
1201 res->flags = cfgtew->u.cfgte->flags;
1202 if (res->flags & IPR_IS_IOA_RESOURCE)
1203 res->type = IPR_RES_TYPE_IOAFP;
1205 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1207 res->bus = cfgtew->u.cfgte->res_addr.bus;
1208 res->target = cfgtew->u.cfgte->res_addr.target;
1209 res->lun = cfgtew->u.cfgte->res_addr.lun;
1210 res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
1213 ipr_update_ata_class(res, proto);
1217 * ipr_is_same_device - Determine if two devices are the same.
1218 * @res: resource entry struct
1219 * @cfgtew: config table entry wrapper struct
1222 * 1 if the devices are the same / 0 otherwise
1224 static int ipr_is_same_device(struct ipr_resource_entry *res,
1225 struct ipr_config_table_entry_wrapper *cfgtew)
1227 if (res->ioa_cfg->sis64) {
1228 if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1229 sizeof(cfgtew->u.cfgte64->dev_id)) &&
1230 !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1231 sizeof(cfgtew->u.cfgte64->lun))) {
1235 if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1236 res->target == cfgtew->u.cfgte->res_addr.target &&
1237 res->lun == cfgtew->u.cfgte->res_addr.lun)
1245 * __ipr_format_res_path - Format the resource path for printing.
1246 * @res_path: resource path
1248 * @len: length of buffer provided
1253 static char *__ipr_format_res_path(u8 *res_path, char *buffer, int len)
1259 p += snprintf(p, buffer + len - p, "%02X", res_path[0]);
1260 for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
1261 p += snprintf(p, buffer + len - p, "-%02X", res_path[i]);
1267 * ipr_format_res_path - Format the resource path for printing.
1268 * @ioa_cfg: ioa config struct
1269 * @res_path: resource path
1271 * @len: length of buffer provided
1276 static char *ipr_format_res_path(struct ipr_ioa_cfg *ioa_cfg,
1277 u8 *res_path, char *buffer, int len)
1282 p += snprintf(p, buffer + len - p, "%d/", ioa_cfg->host->host_no);
1283 __ipr_format_res_path(res_path, p, len - (buffer - p));
1288 * ipr_update_res_entry - Update the resource entry.
1289 * @res: resource entry struct
1290 * @cfgtew: config table entry wrapper struct
1295 static void ipr_update_res_entry(struct ipr_resource_entry *res,
1296 struct ipr_config_table_entry_wrapper *cfgtew)
1298 char buffer[IPR_MAX_RES_PATH_LENGTH];
1302 if (res->ioa_cfg->sis64) {
1303 res->flags = cfgtew->u.cfgte64->flags;
1304 res->res_flags = cfgtew->u.cfgte64->res_flags;
1305 res->type = cfgtew->u.cfgte64->res_type;
1307 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1308 sizeof(struct ipr_std_inq_data));
1310 res->qmodel = IPR_QUEUEING_MODEL64(res);
1311 proto = cfgtew->u.cfgte64->proto;
1312 res->res_handle = cfgtew->u.cfgte64->res_handle;
1313 res->dev_id = cfgtew->u.cfgte64->dev_id;
1315 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1316 sizeof(res->dev_lun.scsi_lun));
1318 if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1319 sizeof(res->res_path))) {
1320 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1321 sizeof(res->res_path));
1325 if (res->sdev && new_path)
1326 sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
1327 ipr_format_res_path(res->ioa_cfg,
1328 res->res_path, buffer, sizeof(buffer)));
1330 res->flags = cfgtew->u.cfgte->flags;
1331 if (res->flags & IPR_IS_IOA_RESOURCE)
1332 res->type = IPR_RES_TYPE_IOAFP;
1334 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1336 memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1337 sizeof(struct ipr_std_inq_data));
1339 res->qmodel = IPR_QUEUEING_MODEL(res);
1340 proto = cfgtew->u.cfgte->proto;
1341 res->res_handle = cfgtew->u.cfgte->res_handle;
1344 ipr_update_ata_class(res, proto);
1348 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1350 * @res: resource entry struct
1351 * @cfgtew: config table entry wrapper struct
1356 static void ipr_clear_res_target(struct ipr_resource_entry *res)
1358 struct ipr_resource_entry *gscsi_res = NULL;
1359 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1361 if (!ioa_cfg->sis64)
1364 if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1365 clear_bit(res->target, ioa_cfg->array_ids);
1366 else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1367 clear_bit(res->target, ioa_cfg->vset_ids);
1368 else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1369 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1370 if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1372 clear_bit(res->target, ioa_cfg->target_ids);
1374 } else if (res->bus == 0)
1375 clear_bit(res->target, ioa_cfg->target_ids);
1379 * ipr_handle_config_change - Handle a config change from the adapter
1380 * @ioa_cfg: ioa config struct
1386 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
1387 struct ipr_hostrcb *hostrcb)
1389 struct ipr_resource_entry *res = NULL;
1390 struct ipr_config_table_entry_wrapper cfgtew;
1391 __be32 cc_res_handle;
1395 if (ioa_cfg->sis64) {
1396 cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1397 cc_res_handle = cfgtew.u.cfgte64->res_handle;
1399 cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1400 cc_res_handle = cfgtew.u.cfgte->res_handle;
1403 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1404 if (res->res_handle == cc_res_handle) {
1411 if (list_empty(&ioa_cfg->free_res_q)) {
1412 ipr_send_hcam(ioa_cfg,
1413 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1418 res = list_entry(ioa_cfg->free_res_q.next,
1419 struct ipr_resource_entry, queue);
1421 list_del(&res->queue);
1422 ipr_init_res_entry(res, &cfgtew);
1423 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1426 ipr_update_res_entry(res, &cfgtew);
1428 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1430 res->del_from_ml = 1;
1431 res->res_handle = IPR_INVALID_RES_HANDLE;
1432 schedule_work(&ioa_cfg->work_q);
1434 ipr_clear_res_target(res);
1435 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
1437 } else if (!res->sdev || res->del_from_ml) {
1439 schedule_work(&ioa_cfg->work_q);
1442 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1446 * ipr_process_ccn - Op done function for a CCN.
1447 * @ipr_cmd: ipr command struct
1449 * This function is the op done function for a configuration
1450 * change notification host controlled async from the adapter.
1455 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1457 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1458 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1459 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
1461 list_del(&hostrcb->queue);
1462 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
1465 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
1466 dev_err(&ioa_cfg->pdev->dev,
1467 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1469 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1471 ipr_handle_config_change(ioa_cfg, hostrcb);
1476 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1477 * @i: index into buffer
1478 * @buf: string to modify
1480 * This function will strip all trailing whitespace, pad the end
1481 * of the string with a single space, and NULL terminate the string.
1484 * new length of string
1486 static int strip_and_pad_whitespace(int i, char *buf)
1488 while (i && buf[i] == ' ')
1496 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1497 * @prefix: string to print at start of printk
1498 * @hostrcb: hostrcb pointer
1499 * @vpd: vendor/product id/sn struct
1504 static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1505 struct ipr_vpd *vpd)
1507 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
1510 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1511 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
1513 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
1514 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
1516 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1517 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1519 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1523 * ipr_log_vpd - Log the passed VPD to the error log.
1524 * @vpd: vendor/product id/sn struct
1529 static void ipr_log_vpd(struct ipr_vpd *vpd)
1531 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1532 + IPR_SERIAL_NUM_LEN];
1534 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1535 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
1537 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1538 ipr_err("Vendor/Product ID: %s\n", buffer);
1540 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
1541 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1542 ipr_err(" Serial Number: %s\n", buffer);
1546 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1547 * @prefix: string to print at start of printk
1548 * @hostrcb: hostrcb pointer
1549 * @vpd: vendor/product id/sn/wwn struct
1554 static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1555 struct ipr_ext_vpd *vpd)
1557 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1558 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1559 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1563 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1564 * @vpd: vendor/product id/sn/wwn struct
1569 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1571 ipr_log_vpd(&vpd->vpd);
1572 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1573 be32_to_cpu(vpd->wwid[1]));
1577 * ipr_log_enhanced_cache_error - Log a cache error.
1578 * @ioa_cfg: ioa config struct
1579 * @hostrcb: hostrcb struct
1584 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1585 struct ipr_hostrcb *hostrcb)
1587 struct ipr_hostrcb_type_12_error *error;
1590 error = &hostrcb->hcam.u.error64.u.type_12_error;
1592 error = &hostrcb->hcam.u.error.u.type_12_error;
1594 ipr_err("-----Current Configuration-----\n");
1595 ipr_err("Cache Directory Card Information:\n");
1596 ipr_log_ext_vpd(&error->ioa_vpd);
1597 ipr_err("Adapter Card Information:\n");
1598 ipr_log_ext_vpd(&error->cfc_vpd);
1600 ipr_err("-----Expected Configuration-----\n");
1601 ipr_err("Cache Directory Card Information:\n");
1602 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1603 ipr_err("Adapter Card Information:\n");
1604 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1606 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1607 be32_to_cpu(error->ioa_data[0]),
1608 be32_to_cpu(error->ioa_data[1]),
1609 be32_to_cpu(error->ioa_data[2]));
1613 * ipr_log_cache_error - Log a cache error.
1614 * @ioa_cfg: ioa config struct
1615 * @hostrcb: hostrcb struct
1620 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1621 struct ipr_hostrcb *hostrcb)
1623 struct ipr_hostrcb_type_02_error *error =
1624 &hostrcb->hcam.u.error.u.type_02_error;
1626 ipr_err("-----Current Configuration-----\n");
1627 ipr_err("Cache Directory Card Information:\n");
1628 ipr_log_vpd(&error->ioa_vpd);
1629 ipr_err("Adapter Card Information:\n");
1630 ipr_log_vpd(&error->cfc_vpd);
1632 ipr_err("-----Expected Configuration-----\n");
1633 ipr_err("Cache Directory Card Information:\n");
1634 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1635 ipr_err("Adapter Card Information:\n");
1636 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1638 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1639 be32_to_cpu(error->ioa_data[0]),
1640 be32_to_cpu(error->ioa_data[1]),
1641 be32_to_cpu(error->ioa_data[2]));
1645 * ipr_log_enhanced_config_error - Log a configuration error.
1646 * @ioa_cfg: ioa config struct
1647 * @hostrcb: hostrcb struct
1652 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1653 struct ipr_hostrcb *hostrcb)
1655 int errors_logged, i;
1656 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1657 struct ipr_hostrcb_type_13_error *error;
1659 error = &hostrcb->hcam.u.error.u.type_13_error;
1660 errors_logged = be32_to_cpu(error->errors_logged);
1662 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1663 be32_to_cpu(error->errors_detected), errors_logged);
1665 dev_entry = error->dev;
1667 for (i = 0; i < errors_logged; i++, dev_entry++) {
1670 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1671 ipr_log_ext_vpd(&dev_entry->vpd);
1673 ipr_err("-----New Device Information-----\n");
1674 ipr_log_ext_vpd(&dev_entry->new_vpd);
1676 ipr_err("Cache Directory Card Information:\n");
1677 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1679 ipr_err("Adapter Card Information:\n");
1680 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1685 * ipr_log_sis64_config_error - Log a device error.
1686 * @ioa_cfg: ioa config struct
1687 * @hostrcb: hostrcb struct
1692 static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
1693 struct ipr_hostrcb *hostrcb)
1695 int errors_logged, i;
1696 struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
1697 struct ipr_hostrcb_type_23_error *error;
1698 char buffer[IPR_MAX_RES_PATH_LENGTH];
1700 error = &hostrcb->hcam.u.error64.u.type_23_error;
1701 errors_logged = be32_to_cpu(error->errors_logged);
1703 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1704 be32_to_cpu(error->errors_detected), errors_logged);
1706 dev_entry = error->dev;
1708 for (i = 0; i < errors_logged; i++, dev_entry++) {
1711 ipr_err("Device %d : %s", i + 1,
1712 __ipr_format_res_path(dev_entry->res_path,
1713 buffer, sizeof(buffer)));
1714 ipr_log_ext_vpd(&dev_entry->vpd);
1716 ipr_err("-----New Device Information-----\n");
1717 ipr_log_ext_vpd(&dev_entry->new_vpd);
1719 ipr_err("Cache Directory Card Information:\n");
1720 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1722 ipr_err("Adapter Card Information:\n");
1723 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1728 * ipr_log_config_error - Log a configuration error.
1729 * @ioa_cfg: ioa config struct
1730 * @hostrcb: hostrcb struct
1735 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1736 struct ipr_hostrcb *hostrcb)
1738 int errors_logged, i;
1739 struct ipr_hostrcb_device_data_entry *dev_entry;
1740 struct ipr_hostrcb_type_03_error *error;
1742 error = &hostrcb->hcam.u.error.u.type_03_error;
1743 errors_logged = be32_to_cpu(error->errors_logged);
1745 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1746 be32_to_cpu(error->errors_detected), errors_logged);
1748 dev_entry = error->dev;
1750 for (i = 0; i < errors_logged; i++, dev_entry++) {
1753 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1754 ipr_log_vpd(&dev_entry->vpd);
1756 ipr_err("-----New Device Information-----\n");
1757 ipr_log_vpd(&dev_entry->new_vpd);
1759 ipr_err("Cache Directory Card Information:\n");
1760 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1762 ipr_err("Adapter Card Information:\n");
1763 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1765 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1766 be32_to_cpu(dev_entry->ioa_data[0]),
1767 be32_to_cpu(dev_entry->ioa_data[1]),
1768 be32_to_cpu(dev_entry->ioa_data[2]),
1769 be32_to_cpu(dev_entry->ioa_data[3]),
1770 be32_to_cpu(dev_entry->ioa_data[4]));
1775 * ipr_log_enhanced_array_error - Log an array configuration error.
1776 * @ioa_cfg: ioa config struct
1777 * @hostrcb: hostrcb struct
1782 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1783 struct ipr_hostrcb *hostrcb)
1786 struct ipr_hostrcb_type_14_error *error;
1787 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1788 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1790 error = &hostrcb->hcam.u.error.u.type_14_error;
1794 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1795 error->protection_level,
1796 ioa_cfg->host->host_no,
1797 error->last_func_vset_res_addr.bus,
1798 error->last_func_vset_res_addr.target,
1799 error->last_func_vset_res_addr.lun);
1803 array_entry = error->array_member;
1804 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1805 ARRAY_SIZE(error->array_member));
1807 for (i = 0; i < num_entries; i++, array_entry++) {
1808 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1811 if (be32_to_cpu(error->exposed_mode_adn) == i)
1812 ipr_err("Exposed Array Member %d:\n", i);
1814 ipr_err("Array Member %d:\n", i);
1816 ipr_log_ext_vpd(&array_entry->vpd);
1817 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1818 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1819 "Expected Location");
1826 * ipr_log_array_error - Log an array configuration error.
1827 * @ioa_cfg: ioa config struct
1828 * @hostrcb: hostrcb struct
1833 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1834 struct ipr_hostrcb *hostrcb)
1837 struct ipr_hostrcb_type_04_error *error;
1838 struct ipr_hostrcb_array_data_entry *array_entry;
1839 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1841 error = &hostrcb->hcam.u.error.u.type_04_error;
1845 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1846 error->protection_level,
1847 ioa_cfg->host->host_no,
1848 error->last_func_vset_res_addr.bus,
1849 error->last_func_vset_res_addr.target,
1850 error->last_func_vset_res_addr.lun);
1854 array_entry = error->array_member;
1856 for (i = 0; i < 18; i++) {
1857 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1860 if (be32_to_cpu(error->exposed_mode_adn) == i)
1861 ipr_err("Exposed Array Member %d:\n", i);
1863 ipr_err("Array Member %d:\n", i);
1865 ipr_log_vpd(&array_entry->vpd);
1867 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1868 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1869 "Expected Location");
1874 array_entry = error->array_member2;
1881 * ipr_log_hex_data - Log additional hex IOA error data.
1882 * @ioa_cfg: ioa config struct
1883 * @data: IOA error data
1889 static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
1896 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1897 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1899 for (i = 0; i < len / 4; i += 4) {
1900 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1901 be32_to_cpu(data[i]),
1902 be32_to_cpu(data[i+1]),
1903 be32_to_cpu(data[i+2]),
1904 be32_to_cpu(data[i+3]));
1909 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1910 * @ioa_cfg: ioa config struct
1911 * @hostrcb: hostrcb struct
1916 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1917 struct ipr_hostrcb *hostrcb)
1919 struct ipr_hostrcb_type_17_error *error;
1922 error = &hostrcb->hcam.u.error64.u.type_17_error;
1924 error = &hostrcb->hcam.u.error.u.type_17_error;
1926 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1927 strim(error->failure_reason);
1929 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1930 be32_to_cpu(hostrcb->hcam.u.error.prc));
1931 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1932 ipr_log_hex_data(ioa_cfg, error->data,
1933 be32_to_cpu(hostrcb->hcam.length) -
1934 (offsetof(struct ipr_hostrcb_error, u) +
1935 offsetof(struct ipr_hostrcb_type_17_error, data)));
1939 * ipr_log_dual_ioa_error - Log a dual adapter error.
1940 * @ioa_cfg: ioa config struct
1941 * @hostrcb: hostrcb struct
1946 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1947 struct ipr_hostrcb *hostrcb)
1949 struct ipr_hostrcb_type_07_error *error;
1951 error = &hostrcb->hcam.u.error.u.type_07_error;
1952 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1953 strim(error->failure_reason);
1955 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1956 be32_to_cpu(hostrcb->hcam.u.error.prc));
1957 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1958 ipr_log_hex_data(ioa_cfg, error->data,
1959 be32_to_cpu(hostrcb->hcam.length) -
1960 (offsetof(struct ipr_hostrcb_error, u) +
1961 offsetof(struct ipr_hostrcb_type_07_error, data)));
1964 static const struct {
1967 } path_active_desc[] = {
1968 { IPR_PATH_NO_INFO, "Path" },
1969 { IPR_PATH_ACTIVE, "Active path" },
1970 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1973 static const struct {
1976 } path_state_desc[] = {
1977 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1978 { IPR_PATH_HEALTHY, "is healthy" },
1979 { IPR_PATH_DEGRADED, "is degraded" },
1980 { IPR_PATH_FAILED, "is failed" }
1984 * ipr_log_fabric_path - Log a fabric path error
1985 * @hostrcb: hostrcb struct
1986 * @fabric: fabric descriptor
1991 static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1992 struct ipr_hostrcb_fabric_desc *fabric)
1995 u8 path_state = fabric->path_state;
1996 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1997 u8 state = path_state & IPR_PATH_STATE_MASK;
1999 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
2000 if (path_active_desc[i].active != active)
2003 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2004 if (path_state_desc[j].state != state)
2007 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
2008 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
2009 path_active_desc[i].desc, path_state_desc[j].desc,
2011 } else if (fabric->cascaded_expander == 0xff) {
2012 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
2013 path_active_desc[i].desc, path_state_desc[j].desc,
2014 fabric->ioa_port, fabric->phy);
2015 } else if (fabric->phy == 0xff) {
2016 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
2017 path_active_desc[i].desc, path_state_desc[j].desc,
2018 fabric->ioa_port, fabric->cascaded_expander);
2020 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
2021 path_active_desc[i].desc, path_state_desc[j].desc,
2022 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2028 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
2029 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2033 * ipr_log64_fabric_path - Log a fabric path error
2034 * @hostrcb: hostrcb struct
2035 * @fabric: fabric descriptor
2040 static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
2041 struct ipr_hostrcb64_fabric_desc *fabric)
2044 u8 path_state = fabric->path_state;
2045 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
2046 u8 state = path_state & IPR_PATH_STATE_MASK;
2047 char buffer[IPR_MAX_RES_PATH_LENGTH];
2049 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
2050 if (path_active_desc[i].active != active)
2053 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2054 if (path_state_desc[j].state != state)
2057 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
2058 path_active_desc[i].desc, path_state_desc[j].desc,
2059 ipr_format_res_path(hostrcb->ioa_cfg,
2061 buffer, sizeof(buffer)));
2066 ipr_err("Path state=%02X Resource Path=%s\n", path_state,
2067 ipr_format_res_path(hostrcb->ioa_cfg, fabric->res_path,
2068 buffer, sizeof(buffer)));
2071 static const struct {
2074 } path_type_desc[] = {
2075 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
2076 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
2077 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
2078 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
2081 static const struct {
2084 } path_status_desc[] = {
2085 { IPR_PATH_CFG_NO_PROB, "Functional" },
2086 { IPR_PATH_CFG_DEGRADED, "Degraded" },
2087 { IPR_PATH_CFG_FAILED, "Failed" },
2088 { IPR_PATH_CFG_SUSPECT, "Suspect" },
2089 { IPR_PATH_NOT_DETECTED, "Missing" },
2090 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
2093 static const char *link_rate[] = {
2096 "phy reset problem",
2113 * ipr_log_path_elem - Log a fabric path element.
2114 * @hostrcb: hostrcb struct
2115 * @cfg: fabric path element struct
2120 static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
2121 struct ipr_hostrcb_config_element *cfg)
2124 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2125 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2127 if (type == IPR_PATH_CFG_NOT_EXIST)
2130 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2131 if (path_type_desc[i].type != type)
2134 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2135 if (path_status_desc[j].status != status)
2138 if (type == IPR_PATH_CFG_IOA_PORT) {
2139 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
2140 path_status_desc[j].desc, path_type_desc[i].desc,
2141 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2142 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2144 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
2145 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2146 path_status_desc[j].desc, path_type_desc[i].desc,
2147 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2148 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2149 } else if (cfg->cascaded_expander == 0xff) {
2150 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
2151 "WWN=%08X%08X\n", path_status_desc[j].desc,
2152 path_type_desc[i].desc, cfg->phy,
2153 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2154 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2155 } else if (cfg->phy == 0xff) {
2156 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
2157 "WWN=%08X%08X\n", path_status_desc[j].desc,
2158 path_type_desc[i].desc, cfg->cascaded_expander,
2159 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2160 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2162 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2163 "WWN=%08X%08X\n", path_status_desc[j].desc,
2164 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
2165 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2166 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2173 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2174 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
2175 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2176 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2180 * ipr_log64_path_elem - Log a fabric path element.
2181 * @hostrcb: hostrcb struct
2182 * @cfg: fabric path element struct
2187 static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
2188 struct ipr_hostrcb64_config_element *cfg)
2191 u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
2192 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2193 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2194 char buffer[IPR_MAX_RES_PATH_LENGTH];
2196 if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
2199 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2200 if (path_type_desc[i].type != type)
2203 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2204 if (path_status_desc[j].status != status)
2207 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2208 path_status_desc[j].desc, path_type_desc[i].desc,
2209 ipr_format_res_path(hostrcb->ioa_cfg,
2210 cfg->res_path, buffer, sizeof(buffer)),
2211 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2212 be32_to_cpu(cfg->wwid[0]),
2213 be32_to_cpu(cfg->wwid[1]));
2217 ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
2218 "WWN=%08X%08X\n", cfg->type_status,
2219 ipr_format_res_path(hostrcb->ioa_cfg,
2220 cfg->res_path, buffer, sizeof(buffer)),
2221 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2222 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2226 * ipr_log_fabric_error - Log a fabric error.
2227 * @ioa_cfg: ioa config struct
2228 * @hostrcb: hostrcb struct
2233 static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2234 struct ipr_hostrcb *hostrcb)
2236 struct ipr_hostrcb_type_20_error *error;
2237 struct ipr_hostrcb_fabric_desc *fabric;
2238 struct ipr_hostrcb_config_element *cfg;
2241 error = &hostrcb->hcam.u.error.u.type_20_error;
2242 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2243 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2245 add_len = be32_to_cpu(hostrcb->hcam.length) -
2246 (offsetof(struct ipr_hostrcb_error, u) +
2247 offsetof(struct ipr_hostrcb_type_20_error, desc));
2249 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2250 ipr_log_fabric_path(hostrcb, fabric);
2251 for_each_fabric_cfg(fabric, cfg)
2252 ipr_log_path_elem(hostrcb, cfg);
2254 add_len -= be16_to_cpu(fabric->length);
2255 fabric = (struct ipr_hostrcb_fabric_desc *)
2256 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2259 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2263 * ipr_log_sis64_array_error - Log a sis64 array error.
2264 * @ioa_cfg: ioa config struct
2265 * @hostrcb: hostrcb struct
2270 static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
2271 struct ipr_hostrcb *hostrcb)
2274 struct ipr_hostrcb_type_24_error *error;
2275 struct ipr_hostrcb64_array_data_entry *array_entry;
2276 char buffer[IPR_MAX_RES_PATH_LENGTH];
2277 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
2279 error = &hostrcb->hcam.u.error64.u.type_24_error;
2283 ipr_err("RAID %s Array Configuration: %s\n",
2284 error->protection_level,
2285 ipr_format_res_path(ioa_cfg, error->last_res_path,
2286 buffer, sizeof(buffer)));
2290 array_entry = error->array_member;
2291 num_entries = min_t(u32, error->num_entries,
2292 ARRAY_SIZE(error->array_member));
2294 for (i = 0; i < num_entries; i++, array_entry++) {
2296 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
2299 if (error->exposed_mode_adn == i)
2300 ipr_err("Exposed Array Member %d:\n", i);
2302 ipr_err("Array Member %d:\n", i);
2304 ipr_err("Array Member %d:\n", i);
2305 ipr_log_ext_vpd(&array_entry->vpd);
2306 ipr_err("Current Location: %s\n",
2307 ipr_format_res_path(ioa_cfg, array_entry->res_path,
2308 buffer, sizeof(buffer)));
2309 ipr_err("Expected Location: %s\n",
2310 ipr_format_res_path(ioa_cfg,
2311 array_entry->expected_res_path,
2312 buffer, sizeof(buffer)));
2319 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2320 * @ioa_cfg: ioa config struct
2321 * @hostrcb: hostrcb struct
2326 static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2327 struct ipr_hostrcb *hostrcb)
2329 struct ipr_hostrcb_type_30_error *error;
2330 struct ipr_hostrcb64_fabric_desc *fabric;
2331 struct ipr_hostrcb64_config_element *cfg;
2334 error = &hostrcb->hcam.u.error64.u.type_30_error;
2336 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2337 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2339 add_len = be32_to_cpu(hostrcb->hcam.length) -
2340 (offsetof(struct ipr_hostrcb64_error, u) +
2341 offsetof(struct ipr_hostrcb_type_30_error, desc));
2343 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2344 ipr_log64_fabric_path(hostrcb, fabric);
2345 for_each_fabric_cfg(fabric, cfg)
2346 ipr_log64_path_elem(hostrcb, cfg);
2348 add_len -= be16_to_cpu(fabric->length);
2349 fabric = (struct ipr_hostrcb64_fabric_desc *)
2350 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2353 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2357 * ipr_log_generic_error - Log an adapter error.
2358 * @ioa_cfg: ioa config struct
2359 * @hostrcb: hostrcb struct
2364 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
2365 struct ipr_hostrcb *hostrcb)
2367 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
2368 be32_to_cpu(hostrcb->hcam.length));
2372 * ipr_log_sis64_device_error - Log a cache error.
2373 * @ioa_cfg: ioa config struct
2374 * @hostrcb: hostrcb struct
2379 static void ipr_log_sis64_device_error(struct ipr_ioa_cfg *ioa_cfg,
2380 struct ipr_hostrcb *hostrcb)
2382 struct ipr_hostrcb_type_21_error *error;
2383 char buffer[IPR_MAX_RES_PATH_LENGTH];
2385 error = &hostrcb->hcam.u.error64.u.type_21_error;
2387 ipr_err("-----Failing Device Information-----\n");
2388 ipr_err("World Wide Unique ID: %08X%08X%08X%08X\n",
2389 be32_to_cpu(error->wwn[0]), be32_to_cpu(error->wwn[1]),
2390 be32_to_cpu(error->wwn[2]), be32_to_cpu(error->wwn[3]));
2391 ipr_err("Device Resource Path: %s\n",
2392 __ipr_format_res_path(error->res_path,
2393 buffer, sizeof(buffer)));
2394 error->primary_problem_desc[sizeof(error->primary_problem_desc) - 1] = '\0';
2395 error->second_problem_desc[sizeof(error->second_problem_desc) - 1] = '\0';
2396 ipr_err("Primary Problem Description: %s\n", error->primary_problem_desc);
2397 ipr_err("Secondary Problem Description: %s\n", error->second_problem_desc);
2398 ipr_err("SCSI Sense Data:\n");
2399 ipr_log_hex_data(ioa_cfg, error->sense_data, sizeof(error->sense_data));
2400 ipr_err("SCSI Command Descriptor Block: \n");
2401 ipr_log_hex_data(ioa_cfg, error->cdb, sizeof(error->cdb));
2403 ipr_err("Additional IOA Data:\n");
2404 ipr_log_hex_data(ioa_cfg, error->ioa_data, be32_to_cpu(error->length_of_error));
2408 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2411 * This function will return the index of into the ipr_error_table
2412 * for the specified IOASC. If the IOASC is not in the table,
2413 * 0 will be returned, which points to the entry used for unknown errors.
2416 * index into the ipr_error_table
2418 static u32 ipr_get_error(u32 ioasc)
2422 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
2423 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
2430 * ipr_handle_log_data - Log an adapter error.
2431 * @ioa_cfg: ioa config struct
2432 * @hostrcb: hostrcb struct
2434 * This function logs an adapter error to the system.
2439 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
2440 struct ipr_hostrcb *hostrcb)
2444 struct ipr_hostrcb_type_21_error *error;
2446 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
2449 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
2450 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
2453 ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2455 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2457 if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
2458 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
2459 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2460 scsi_report_bus_reset(ioa_cfg->host,
2461 hostrcb->hcam.u.error.fd_res_addr.bus);
2464 error_index = ipr_get_error(ioasc);
2466 if (!ipr_error_table[error_index].log_hcam)
2469 if (ioasc == IPR_IOASC_HW_CMD_FAILED &&
2470 hostrcb->hcam.overlay_id == IPR_HOST_RCB_OVERLAY_ID_21) {
2471 error = &hostrcb->hcam.u.error64.u.type_21_error;
2473 if (((be32_to_cpu(error->sense_data[0]) & 0x0000ff00) >> 8) == ILLEGAL_REQUEST &&
2474 ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
2478 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
2480 /* Set indication we have logged an error */
2481 ioa_cfg->errors_logged++;
2483 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
2485 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
2486 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
2488 switch (hostrcb->hcam.overlay_id) {
2489 case IPR_HOST_RCB_OVERLAY_ID_2:
2490 ipr_log_cache_error(ioa_cfg, hostrcb);
2492 case IPR_HOST_RCB_OVERLAY_ID_3:
2493 ipr_log_config_error(ioa_cfg, hostrcb);
2495 case IPR_HOST_RCB_OVERLAY_ID_4:
2496 case IPR_HOST_RCB_OVERLAY_ID_6:
2497 ipr_log_array_error(ioa_cfg, hostrcb);
2499 case IPR_HOST_RCB_OVERLAY_ID_7:
2500 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
2502 case IPR_HOST_RCB_OVERLAY_ID_12:
2503 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
2505 case IPR_HOST_RCB_OVERLAY_ID_13:
2506 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
2508 case IPR_HOST_RCB_OVERLAY_ID_14:
2509 case IPR_HOST_RCB_OVERLAY_ID_16:
2510 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
2512 case IPR_HOST_RCB_OVERLAY_ID_17:
2513 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
2515 case IPR_HOST_RCB_OVERLAY_ID_20:
2516 ipr_log_fabric_error(ioa_cfg, hostrcb);
2518 case IPR_HOST_RCB_OVERLAY_ID_21:
2519 ipr_log_sis64_device_error(ioa_cfg, hostrcb);
2521 case IPR_HOST_RCB_OVERLAY_ID_23:
2522 ipr_log_sis64_config_error(ioa_cfg, hostrcb);
2524 case IPR_HOST_RCB_OVERLAY_ID_24:
2525 case IPR_HOST_RCB_OVERLAY_ID_26:
2526 ipr_log_sis64_array_error(ioa_cfg, hostrcb);
2528 case IPR_HOST_RCB_OVERLAY_ID_30:
2529 ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
2531 case IPR_HOST_RCB_OVERLAY_ID_1:
2532 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
2534 ipr_log_generic_error(ioa_cfg, hostrcb);
2540 * ipr_process_error - Op done function for an adapter error log.
2541 * @ipr_cmd: ipr command struct
2543 * This function is the op done function for an error log host
2544 * controlled async from the adapter. It will log the error and
2545 * send the HCAM back to the adapter.
2550 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2552 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2553 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
2554 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
2558 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2560 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2562 list_del(&hostrcb->queue);
2563 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
2566 ipr_handle_log_data(ioa_cfg, hostrcb);
2567 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
2568 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
2569 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
2570 dev_err(&ioa_cfg->pdev->dev,
2571 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
2574 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2578 * ipr_timeout - An internally generated op has timed out.
2579 * @ipr_cmd: ipr command struct
2581 * This function blocks host requests and initiates an
2587 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
2589 unsigned long lock_flags = 0;
2590 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2593 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2595 ioa_cfg->errors_logged++;
2596 dev_err(&ioa_cfg->pdev->dev,
2597 "Adapter being reset due to command timeout.\n");
2599 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2600 ioa_cfg->sdt_state = GET_DUMP;
2602 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
2603 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2605 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2610 * ipr_oper_timeout - Adapter timed out transitioning to operational
2611 * @ipr_cmd: ipr command struct
2613 * This function blocks host requests and initiates an
2619 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
2621 unsigned long lock_flags = 0;
2622 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2625 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2627 ioa_cfg->errors_logged++;
2628 dev_err(&ioa_cfg->pdev->dev,
2629 "Adapter timed out transitioning to operational.\n");
2631 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2632 ioa_cfg->sdt_state = GET_DUMP;
2634 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
2636 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
2637 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2640 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2645 * ipr_find_ses_entry - Find matching SES in SES table
2646 * @res: resource entry struct of SES
2649 * pointer to SES table entry / NULL on failure
2651 static const struct ipr_ses_table_entry *
2652 ipr_find_ses_entry(struct ipr_resource_entry *res)
2655 struct ipr_std_inq_vpids *vpids;
2656 const struct ipr_ses_table_entry *ste = ipr_ses_table;
2658 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
2659 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
2660 if (ste->compare_product_id_byte[j] == 'X') {
2661 vpids = &res->std_inq_data.vpids;
2662 if (vpids->product_id[j] == ste->product_id[j])
2670 if (matches == IPR_PROD_ID_LEN)
2678 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2679 * @ioa_cfg: ioa config struct
2681 * @bus_width: bus width
2684 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2685 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2686 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2687 * max 160MHz = max 320MB/sec).
2689 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
2691 struct ipr_resource_entry *res;
2692 const struct ipr_ses_table_entry *ste;
2693 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
2695 /* Loop through each config table entry in the config table buffer */
2696 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2697 if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
2700 if (bus != res->bus)
2703 if (!(ste = ipr_find_ses_entry(res)))
2706 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
2709 return max_xfer_rate;
2713 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2714 * @ioa_cfg: ioa config struct
2715 * @max_delay: max delay in micro-seconds to wait
2717 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2720 * 0 on success / other on failure
2722 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
2724 volatile u32 pcii_reg;
2727 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2728 while (delay < max_delay) {
2729 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
2731 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
2734 /* udelay cannot be used if delay is more than a few milliseconds */
2735 if ((delay / 1000) > MAX_UDELAY_MS)
2736 mdelay(delay / 1000);
2746 * ipr_get_sis64_dump_data_section - Dump IOA memory
2747 * @ioa_cfg: ioa config struct
2748 * @start_addr: adapter address to dump
2749 * @dest: destination kernel buffer
2750 * @length_in_words: length to dump in 4 byte words
2755 static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2757 __be32 *dest, u32 length_in_words)
2761 for (i = 0; i < length_in_words; i++) {
2762 writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
2763 *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
2771 * ipr_get_ldump_data_section - Dump IOA memory
2772 * @ioa_cfg: ioa config struct
2773 * @start_addr: adapter address to dump
2774 * @dest: destination kernel buffer
2775 * @length_in_words: length to dump in 4 byte words
2778 * 0 on success / -EIO on failure
2780 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2782 __be32 *dest, u32 length_in_words)
2784 volatile u32 temp_pcii_reg;
2788 return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
2789 dest, length_in_words);
2791 /* Write IOA interrupt reg starting LDUMP state */
2792 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
2793 ioa_cfg->regs.set_uproc_interrupt_reg32);
2795 /* Wait for IO debug acknowledge */
2796 if (ipr_wait_iodbg_ack(ioa_cfg,
2797 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
2798 dev_err(&ioa_cfg->pdev->dev,
2799 "IOA dump long data transfer timeout\n");
2803 /* Signal LDUMP interlocked - clear IO debug ack */
2804 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2805 ioa_cfg->regs.clr_interrupt_reg);
2807 /* Write Mailbox with starting address */
2808 writel(start_addr, ioa_cfg->ioa_mailbox);
2810 /* Signal address valid - clear IOA Reset alert */
2811 writel(IPR_UPROCI_RESET_ALERT,
2812 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2814 for (i = 0; i < length_in_words; i++) {
2815 /* Wait for IO debug acknowledge */
2816 if (ipr_wait_iodbg_ack(ioa_cfg,
2817 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2818 dev_err(&ioa_cfg->pdev->dev,
2819 "IOA dump short data transfer timeout\n");
2823 /* Read data from mailbox and increment destination pointer */
2824 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2827 /* For all but the last word of data, signal data received */
2828 if (i < (length_in_words - 1)) {
2829 /* Signal dump data received - Clear IO debug Ack */
2830 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2831 ioa_cfg->regs.clr_interrupt_reg);
2835 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2836 writel(IPR_UPROCI_RESET_ALERT,
2837 ioa_cfg->regs.set_uproc_interrupt_reg32);
2839 writel(IPR_UPROCI_IO_DEBUG_ALERT,
2840 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2842 /* Signal dump data received - Clear IO debug Ack */
2843 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2844 ioa_cfg->regs.clr_interrupt_reg);
2846 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2847 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2849 readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
2851 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2861 #ifdef CONFIG_SCSI_IPR_DUMP
2863 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2864 * @ioa_cfg: ioa config struct
2865 * @pci_address: adapter address
2866 * @length: length of data to copy
2868 * Copy data from PCI adapter to kernel buffer.
2869 * Note: length MUST be a 4 byte multiple
2871 * 0 on success / other on failure
2873 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2874 unsigned long pci_address, u32 length)
2876 int bytes_copied = 0;
2877 int cur_len, rc, rem_len, rem_page_len, max_dump_size;
2879 unsigned long lock_flags = 0;
2880 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2883 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2885 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2887 while (bytes_copied < length &&
2888 (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
2889 if (ioa_dump->page_offset >= PAGE_SIZE ||
2890 ioa_dump->page_offset == 0) {
2891 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2895 return bytes_copied;
2898 ioa_dump->page_offset = 0;
2899 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2900 ioa_dump->next_page_index++;
2902 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2904 rem_len = length - bytes_copied;
2905 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2906 cur_len = min(rem_len, rem_page_len);
2908 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2909 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2912 rc = ipr_get_ldump_data_section(ioa_cfg,
2913 pci_address + bytes_copied,
2914 &page[ioa_dump->page_offset / 4],
2915 (cur_len / sizeof(u32)));
2917 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2920 ioa_dump->page_offset += cur_len;
2921 bytes_copied += cur_len;
2929 return bytes_copied;
2933 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2934 * @hdr: dump entry header struct
2939 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2941 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2943 hdr->offset = sizeof(*hdr);
2944 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2948 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2949 * @ioa_cfg: ioa config struct
2950 * @driver_dump: driver dump struct
2955 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2956 struct ipr_driver_dump *driver_dump)
2958 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2960 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2961 driver_dump->ioa_type_entry.hdr.len =
2962 sizeof(struct ipr_dump_ioa_type_entry) -
2963 sizeof(struct ipr_dump_entry_header);
2964 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2965 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2966 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2967 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2968 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2969 ucode_vpd->minor_release[1];
2970 driver_dump->hdr.num_entries++;
2974 * ipr_dump_version_data - Fill in the driver version in the dump.
2975 * @ioa_cfg: ioa config struct
2976 * @driver_dump: driver dump struct
2981 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2982 struct ipr_driver_dump *driver_dump)
2984 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2985 driver_dump->version_entry.hdr.len =
2986 sizeof(struct ipr_dump_version_entry) -
2987 sizeof(struct ipr_dump_entry_header);
2988 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2989 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2990 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2991 driver_dump->hdr.num_entries++;
2995 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2996 * @ioa_cfg: ioa config struct
2997 * @driver_dump: driver dump struct
3002 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
3003 struct ipr_driver_dump *driver_dump)
3005 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
3006 driver_dump->trace_entry.hdr.len =
3007 sizeof(struct ipr_dump_trace_entry) -
3008 sizeof(struct ipr_dump_entry_header);
3009 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3010 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
3011 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
3012 driver_dump->hdr.num_entries++;
3016 * ipr_dump_location_data - Fill in the IOA location in the dump.
3017 * @ioa_cfg: ioa config struct
3018 * @driver_dump: driver dump struct
3023 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
3024 struct ipr_driver_dump *driver_dump)
3026 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
3027 driver_dump->location_entry.hdr.len =
3028 sizeof(struct ipr_dump_location_entry) -
3029 sizeof(struct ipr_dump_entry_header);
3030 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
3031 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
3032 strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
3033 driver_dump->hdr.num_entries++;
3037 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
3038 * @ioa_cfg: ioa config struct
3039 * @dump: dump struct
3044 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
3046 unsigned long start_addr, sdt_word;
3047 unsigned long lock_flags = 0;
3048 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
3049 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
3050 u32 num_entries, max_num_entries, start_off, end_off;
3051 u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
3052 struct ipr_sdt *sdt;
3058 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3060 if (ioa_cfg->sdt_state != READ_DUMP) {
3061 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3065 if (ioa_cfg->sis64) {
3066 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3067 ssleep(IPR_DUMP_DELAY_SECONDS);
3068 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3071 start_addr = readl(ioa_cfg->ioa_mailbox);
3073 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
3074 dev_err(&ioa_cfg->pdev->dev,
3075 "Invalid dump table format: %lx\n", start_addr);
3076 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3080 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
3082 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
3084 /* Initialize the overall dump header */
3085 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
3086 driver_dump->hdr.num_entries = 1;
3087 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
3088 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
3089 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
3090 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
3092 ipr_dump_version_data(ioa_cfg, driver_dump);
3093 ipr_dump_location_data(ioa_cfg, driver_dump);
3094 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
3095 ipr_dump_trace_data(ioa_cfg, driver_dump);
3097 /* Update dump_header */
3098 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
3100 /* IOA Dump entry */
3101 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
3102 ioa_dump->hdr.len = 0;
3103 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3104 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
3106 /* First entries in sdt are actually a list of dump addresses and
3107 lengths to gather the real dump data. sdt represents the pointer
3108 to the ioa generated dump table. Dump data will be extracted based
3109 on entries in this table */
3110 sdt = &ioa_dump->sdt;
3112 if (ioa_cfg->sis64) {
3113 max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
3114 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
3116 max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
3117 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
3120 bytes_to_copy = offsetof(struct ipr_sdt, entry) +
3121 (max_num_entries * sizeof(struct ipr_sdt_entry));
3122 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
3123 bytes_to_copy / sizeof(__be32));
3125 /* Smart Dump table is ready to use and the first entry is valid */
3126 if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
3127 (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
3128 dev_err(&ioa_cfg->pdev->dev,
3129 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
3130 rc, be32_to_cpu(sdt->hdr.state));
3131 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
3132 ioa_cfg->sdt_state = DUMP_OBTAINED;
3133 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3137 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
3139 if (num_entries > max_num_entries)
3140 num_entries = max_num_entries;
3142 /* Update dump length to the actual data to be copied */
3143 dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
3145 dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
3147 dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
3149 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3151 for (i = 0; i < num_entries; i++) {
3152 if (ioa_dump->hdr.len > max_dump_size) {
3153 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3157 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
3158 sdt_word = be32_to_cpu(sdt->entry[i].start_token);
3160 bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
3162 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
3163 end_off = be32_to_cpu(sdt->entry[i].end_token);
3165 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
3166 bytes_to_copy = end_off - start_off;
3171 if (bytes_to_copy > max_dump_size) {
3172 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
3176 /* Copy data from adapter to driver buffers */
3177 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
3180 ioa_dump->hdr.len += bytes_copied;
3182 if (bytes_copied != bytes_to_copy) {
3183 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3190 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
3192 /* Update dump_header */
3193 driver_dump->hdr.len += ioa_dump->hdr.len;
3195 ioa_cfg->sdt_state = DUMP_OBTAINED;
3200 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while (0)
3204 * ipr_release_dump - Free adapter dump memory
3205 * @kref: kref struct
3210 static void ipr_release_dump(struct kref *kref)
3212 struct ipr_dump *dump = container_of(kref, struct ipr_dump, kref);
3213 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
3214 unsigned long lock_flags = 0;
3218 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3219 ioa_cfg->dump = NULL;
3220 ioa_cfg->sdt_state = INACTIVE;
3221 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3223 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
3224 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
3226 vfree(dump->ioa_dump.ioa_data);
3232 * ipr_worker_thread - Worker thread
3233 * @work: ioa config struct
3235 * Called at task level from a work thread. This function takes care
3236 * of adding and removing device from the mid-layer as configuration
3237 * changes are detected by the adapter.
3242 static void ipr_worker_thread(struct work_struct *work)
3244 unsigned long lock_flags;
3245 struct ipr_resource_entry *res;
3246 struct scsi_device *sdev;
3247 struct ipr_dump *dump;
3248 struct ipr_ioa_cfg *ioa_cfg =
3249 container_of(work, struct ipr_ioa_cfg, work_q);
3250 u8 bus, target, lun;
3254 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3256 if (ioa_cfg->sdt_state == READ_DUMP) {
3257 dump = ioa_cfg->dump;
3259 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3262 kref_get(&dump->kref);
3263 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3264 ipr_get_ioa_dump(ioa_cfg, dump);
3265 kref_put(&dump->kref, ipr_release_dump);
3267 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3268 if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
3269 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3270 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3277 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
3278 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3282 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3283 if (res->del_from_ml && res->sdev) {
3286 if (!scsi_device_get(sdev)) {
3287 if (!res->add_to_ml)
3288 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
3290 res->del_from_ml = 0;
3291 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3292 scsi_remove_device(sdev);
3293 scsi_device_put(sdev);
3294 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3301 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3302 if (res->add_to_ml) {
3304 target = res->target;
3307 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3308 scsi_add_device(ioa_cfg->host, bus, target, lun);
3309 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3314 ioa_cfg->scan_done = 1;
3315 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3316 kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
3320 #ifdef CONFIG_SCSI_IPR_TRACE
3322 * ipr_read_trace - Dump the adapter trace
3323 * @filp: open sysfs file
3324 * @kobj: kobject struct
3325 * @bin_attr: bin_attribute struct
3328 * @count: buffer size
3331 * number of bytes printed to buffer
3333 static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
3334 struct bin_attribute *bin_attr,
3335 char *buf, loff_t off, size_t count)
3337 struct device *dev = container_of(kobj, struct device, kobj);
3338 struct Scsi_Host *shost = class_to_shost(dev);
3339 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3340 unsigned long lock_flags = 0;
3343 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3344 ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
3346 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3351 static struct bin_attribute ipr_trace_attr = {
3357 .read = ipr_read_trace,
3362 * ipr_show_fw_version - Show the firmware version
3363 * @dev: class device struct
3367 * number of bytes printed to buffer
3369 static ssize_t ipr_show_fw_version(struct device *dev,
3370 struct device_attribute *attr, char *buf)
3372 struct Scsi_Host *shost = class_to_shost(dev);
3373 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3374 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
3375 unsigned long lock_flags = 0;
3378 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3379 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
3380 ucode_vpd->major_release, ucode_vpd->card_type,
3381 ucode_vpd->minor_release[0],
3382 ucode_vpd->minor_release[1]);
3383 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3387 static struct device_attribute ipr_fw_version_attr = {
3389 .name = "fw_version",
3392 .show = ipr_show_fw_version,
3396 * ipr_show_log_level - Show the adapter's error logging level
3397 * @dev: class device struct
3401 * number of bytes printed to buffer
3403 static ssize_t ipr_show_log_level(struct device *dev,
3404 struct device_attribute *attr, char *buf)
3406 struct Scsi_Host *shost = class_to_shost(dev);
3407 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3408 unsigned long lock_flags = 0;
3411 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3412 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
3413 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3418 * ipr_store_log_level - Change the adapter's error logging level
3419 * @dev: class device struct
3423 * number of bytes printed to buffer
3425 static ssize_t ipr_store_log_level(struct device *dev,
3426 struct device_attribute *attr,
3427 const char *buf, size_t count)
3429 struct Scsi_Host *shost = class_to_shost(dev);
3430 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3431 unsigned long lock_flags = 0;
3433 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3434 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
3435 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3439 static struct device_attribute ipr_log_level_attr = {
3441 .name = "log_level",
3442 .mode = S_IRUGO | S_IWUSR,
3444 .show = ipr_show_log_level,
3445 .store = ipr_store_log_level
3449 * ipr_store_diagnostics - IOA Diagnostics interface
3450 * @dev: device struct
3452 * @count: buffer size
3454 * This function will reset the adapter and wait a reasonable
3455 * amount of time for any errors that the adapter might log.
3458 * count on success / other on failure
3460 static ssize_t ipr_store_diagnostics(struct device *dev,
3461 struct device_attribute *attr,
3462 const char *buf, size_t count)
3464 struct Scsi_Host *shost = class_to_shost(dev);
3465 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3466 unsigned long lock_flags = 0;
3469 if (!capable(CAP_SYS_ADMIN))
3472 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3473 while (ioa_cfg->in_reset_reload) {
3474 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3475 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3476 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3479 ioa_cfg->errors_logged = 0;
3480 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3482 if (ioa_cfg->in_reset_reload) {
3483 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3484 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3486 /* Wait for a second for any errors to be logged */
3489 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3493 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3494 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
3496 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3501 static struct device_attribute ipr_diagnostics_attr = {
3503 .name = "run_diagnostics",
3506 .store = ipr_store_diagnostics
3510 * ipr_show_adapter_state - Show the adapter's state
3511 * @class_dev: device struct
3515 * number of bytes printed to buffer
3517 static ssize_t ipr_show_adapter_state(struct device *dev,
3518 struct device_attribute *attr, char *buf)
3520 struct Scsi_Host *shost = class_to_shost(dev);
3521 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3522 unsigned long lock_flags = 0;
3525 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3526 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
3527 len = snprintf(buf, PAGE_SIZE, "offline\n");
3529 len = snprintf(buf, PAGE_SIZE, "online\n");
3530 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3535 * ipr_store_adapter_state - Change adapter state
3536 * @dev: device struct
3538 * @count: buffer size
3540 * This function will change the adapter's state.
3543 * count on success / other on failure
3545 static ssize_t ipr_store_adapter_state(struct device *dev,
3546 struct device_attribute *attr,
3547 const char *buf, size_t count)
3549 struct Scsi_Host *shost = class_to_shost(dev);
3550 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3551 unsigned long lock_flags;
3552 int result = count, i;
3554 if (!capable(CAP_SYS_ADMIN))
3557 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3558 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead &&
3559 !strncmp(buf, "online", 6)) {
3560 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
3561 spin_lock(&ioa_cfg->hrrq[i]._lock);
3562 ioa_cfg->hrrq[i].ioa_is_dead = 0;
3563 spin_unlock(&ioa_cfg->hrrq[i]._lock);
3566 ioa_cfg->reset_retries = 0;
3567 ioa_cfg->in_ioa_bringdown = 0;
3568 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3570 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3571 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3576 static struct device_attribute ipr_ioa_state_attr = {
3578 .name = "online_state",
3579 .mode = S_IRUGO | S_IWUSR,
3581 .show = ipr_show_adapter_state,
3582 .store = ipr_store_adapter_state
3586 * ipr_store_reset_adapter - Reset the adapter
3587 * @dev: device struct
3589 * @count: buffer size
3591 * This function will reset the adapter.
3594 * count on success / other on failure
3596 static ssize_t ipr_store_reset_adapter(struct device *dev,
3597 struct device_attribute *attr,
3598 const char *buf, size_t count)
3600 struct Scsi_Host *shost = class_to_shost(dev);
3601 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3602 unsigned long lock_flags;
3605 if (!capable(CAP_SYS_ADMIN))
3608 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3609 if (!ioa_cfg->in_reset_reload)
3610 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3611 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3612 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3617 static struct device_attribute ipr_ioa_reset_attr = {
3619 .name = "reset_host",
3622 .store = ipr_store_reset_adapter
3625 static int ipr_iopoll(struct blk_iopoll *iop, int budget);
3627 * ipr_show_iopoll_weight - Show ipr polling mode
3628 * @dev: class device struct
3632 * number of bytes printed to buffer
3634 static ssize_t ipr_show_iopoll_weight(struct device *dev,
3635 struct device_attribute *attr, char *buf)
3637 struct Scsi_Host *shost = class_to_shost(dev);
3638 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3639 unsigned long lock_flags = 0;
3642 spin_lock_irqsave(shost->host_lock, lock_flags);
3643 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->iopoll_weight);
3644 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3650 * ipr_store_iopoll_weight - Change the adapter's polling mode
3651 * @dev: class device struct
3655 * number of bytes printed to buffer
3657 static ssize_t ipr_store_iopoll_weight(struct device *dev,
3658 struct device_attribute *attr,
3659 const char *buf, size_t count)
3661 struct Scsi_Host *shost = class_to_shost(dev);
3662 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3663 unsigned long user_iopoll_weight;
3664 unsigned long lock_flags = 0;
3667 if (!ioa_cfg->sis64) {
3668 dev_info(&ioa_cfg->pdev->dev, "blk-iopoll not supported on this adapter\n");
3671 if (kstrtoul(buf, 10, &user_iopoll_weight))
3674 if (user_iopoll_weight > 256) {
3675 dev_info(&ioa_cfg->pdev->dev, "Invalid blk-iopoll weight. It must be less than 256\n");
3679 if (user_iopoll_weight == ioa_cfg->iopoll_weight) {
3680 dev_info(&ioa_cfg->pdev->dev, "Current blk-iopoll weight has the same weight\n");
3684 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
3685 for (i = 1; i < ioa_cfg->hrrq_num; i++)
3686 blk_iopoll_disable(&ioa_cfg->hrrq[i].iopoll);
3689 spin_lock_irqsave(shost->host_lock, lock_flags);
3690 ioa_cfg->iopoll_weight = user_iopoll_weight;
3691 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
3692 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
3693 blk_iopoll_init(&ioa_cfg->hrrq[i].iopoll,
3694 ioa_cfg->iopoll_weight, ipr_iopoll);
3695 blk_iopoll_enable(&ioa_cfg->hrrq[i].iopoll);
3698 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3703 static struct device_attribute ipr_iopoll_weight_attr = {
3705 .name = "iopoll_weight",
3706 .mode = S_IRUGO | S_IWUSR,
3708 .show = ipr_show_iopoll_weight,
3709 .store = ipr_store_iopoll_weight
3713 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3714 * @buf_len: buffer length
3716 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3717 * list to use for microcode download
3720 * pointer to sglist / NULL on failure
3722 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
3724 int sg_size, order, bsize_elem, num_elem, i, j;
3725 struct ipr_sglist *sglist;
3726 struct scatterlist *scatterlist;
3729 /* Get the minimum size per scatter/gather element */
3730 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
3732 /* Get the actual size per element */
3733 order = get_order(sg_size);
3735 /* Determine the actual number of bytes per element */
3736 bsize_elem = PAGE_SIZE * (1 << order);
3738 /* Determine the actual number of sg entries needed */
3739 if (buf_len % bsize_elem)
3740 num_elem = (buf_len / bsize_elem) + 1;
3742 num_elem = buf_len / bsize_elem;
3744 /* Allocate a scatter/gather list for the DMA */
3745 sglist = kzalloc(sizeof(struct ipr_sglist) +
3746 (sizeof(struct scatterlist) * (num_elem - 1)),
3749 if (sglist == NULL) {
3754 scatterlist = sglist->scatterlist;
3755 sg_init_table(scatterlist, num_elem);
3757 sglist->order = order;
3758 sglist->num_sg = num_elem;
3760 /* Allocate a bunch of sg elements */
3761 for (i = 0; i < num_elem; i++) {
3762 page = alloc_pages(GFP_KERNEL, order);
3766 /* Free up what we already allocated */
3767 for (j = i - 1; j >= 0; j--)
3768 __free_pages(sg_page(&scatterlist[j]), order);
3773 sg_set_page(&scatterlist[i], page, 0, 0);
3780 * ipr_free_ucode_buffer - Frees a microcode download buffer
3781 * @p_dnld: scatter/gather list pointer
3783 * Free a DMA'able ucode download buffer previously allocated with
3784 * ipr_alloc_ucode_buffer
3789 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
3793 for (i = 0; i < sglist->num_sg; i++)
3794 __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
3800 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3801 * @sglist: scatter/gather list pointer
3802 * @buffer: buffer pointer
3803 * @len: buffer length
3805 * Copy a microcode image from a user buffer into a buffer allocated by
3806 * ipr_alloc_ucode_buffer
3809 * 0 on success / other on failure
3811 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
3812 u8 *buffer, u32 len)
3814 int bsize_elem, i, result = 0;
3815 struct scatterlist *scatterlist;
3818 /* Determine the actual number of bytes per element */
3819 bsize_elem = PAGE_SIZE * (1 << sglist->order);
3821 scatterlist = sglist->scatterlist;
3823 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
3824 struct page *page = sg_page(&scatterlist[i]);
3827 memcpy(kaddr, buffer, bsize_elem);
3830 scatterlist[i].length = bsize_elem;
3838 if (len % bsize_elem) {
3839 struct page *page = sg_page(&scatterlist[i]);
3842 memcpy(kaddr, buffer, len % bsize_elem);
3845 scatterlist[i].length = len % bsize_elem;
3848 sglist->buffer_len = len;
3853 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3854 * @ipr_cmd: ipr command struct
3855 * @sglist: scatter/gather list
3857 * Builds a microcode download IOA data list (IOADL).
3860 static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
3861 struct ipr_sglist *sglist)
3863 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3864 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
3865 struct scatterlist *scatterlist = sglist->scatterlist;
3868 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3869 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3870 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3873 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
3874 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3875 ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
3876 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
3877 ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
3880 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3884 * ipr_build_ucode_ioadl - Build a microcode download IOADL
3885 * @ipr_cmd: ipr command struct
3886 * @sglist: scatter/gather list
3888 * Builds a microcode download IOA data list (IOADL).
3891 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
3892 struct ipr_sglist *sglist)
3894 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3895 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
3896 struct scatterlist *scatterlist = sglist->scatterlist;
3899 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3900 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3901 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3904 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3906 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3907 ioadl[i].flags_and_data_len =
3908 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
3910 cpu_to_be32(sg_dma_address(&scatterlist[i]));
3913 ioadl[i-1].flags_and_data_len |=
3914 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3918 * ipr_update_ioa_ucode - Update IOA's microcode
3919 * @ioa_cfg: ioa config struct
3920 * @sglist: scatter/gather list
3922 * Initiate an adapter reset to update the IOA's microcode
3925 * 0 on success / -EIO on failure
3927 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3928 struct ipr_sglist *sglist)
3930 unsigned long lock_flags;
3932 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3933 while (ioa_cfg->in_reset_reload) {
3934 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3935 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3936 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3939 if (ioa_cfg->ucode_sglist) {
3940 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3941 dev_err(&ioa_cfg->pdev->dev,
3942 "Microcode download already in progress\n");
3946 sglist->num_dma_sg = dma_map_sg(&ioa_cfg->pdev->dev,
3947 sglist->scatterlist, sglist->num_sg,
3950 if (!sglist->num_dma_sg) {
3951 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3952 dev_err(&ioa_cfg->pdev->dev,
3953 "Failed to map microcode download buffer!\n");
3957 ioa_cfg->ucode_sglist = sglist;
3958 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3959 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3960 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3962 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3963 ioa_cfg->ucode_sglist = NULL;
3964 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3969 * ipr_store_update_fw - Update the firmware on the adapter
3970 * @class_dev: device struct
3972 * @count: buffer size
3974 * This function will update the firmware on the adapter.
3977 * count on success / other on failure
3979 static ssize_t ipr_store_update_fw(struct device *dev,
3980 struct device_attribute *attr,
3981 const char *buf, size_t count)
3983 struct Scsi_Host *shost = class_to_shost(dev);
3984 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3985 struct ipr_ucode_image_header *image_hdr;
3986 const struct firmware *fw_entry;
3987 struct ipr_sglist *sglist;
3990 int len, result, dnld_size;
3992 if (!capable(CAP_SYS_ADMIN))
3995 len = snprintf(fname, 99, "%s", buf);
3996 fname[len-1] = '\0';
3998 if (request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3999 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
4003 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
4005 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
4006 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
4007 sglist = ipr_alloc_ucode_buffer(dnld_size);
4010 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
4011 release_firmware(fw_entry);
4015 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
4018 dev_err(&ioa_cfg->pdev->dev,
4019 "Microcode buffer copy to DMA buffer failed\n");
4023 ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
4025 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
4030 ipr_free_ucode_buffer(sglist);
4031 release_firmware(fw_entry);
4035 static struct device_attribute ipr_update_fw_attr = {
4037 .name = "update_fw",
4040 .store = ipr_store_update_fw
4044 * ipr_show_fw_type - Show the adapter's firmware type.
4045 * @dev: class device struct
4049 * number of bytes printed to buffer
4051 static ssize_t ipr_show_fw_type(struct device *dev,
4052 struct device_attribute *attr, char *buf)
4054 struct Scsi_Host *shost = class_to_shost(dev);
4055 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4056 unsigned long lock_flags = 0;
4059 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4060 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
4061 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4065 static struct device_attribute ipr_ioa_fw_type_attr = {
4070 .show = ipr_show_fw_type
4073 static struct device_attribute *ipr_ioa_attrs[] = {
4074 &ipr_fw_version_attr,
4075 &ipr_log_level_attr,
4076 &ipr_diagnostics_attr,
4077 &ipr_ioa_state_attr,
4078 &ipr_ioa_reset_attr,
4079 &ipr_update_fw_attr,
4080 &ipr_ioa_fw_type_attr,
4081 &ipr_iopoll_weight_attr,
4085 #ifdef CONFIG_SCSI_IPR_DUMP
4087 * ipr_read_dump - Dump the adapter
4088 * @filp: open sysfs file
4089 * @kobj: kobject struct
4090 * @bin_attr: bin_attribute struct
4093 * @count: buffer size
4096 * number of bytes printed to buffer
4098 static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
4099 struct bin_attribute *bin_attr,
4100 char *buf, loff_t off, size_t count)
4102 struct device *cdev = container_of(kobj, struct device, kobj);
4103 struct Scsi_Host *shost = class_to_shost(cdev);
4104 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4105 struct ipr_dump *dump;
4106 unsigned long lock_flags = 0;
4111 if (!capable(CAP_SYS_ADMIN))
4114 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4115 dump = ioa_cfg->dump;
4117 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
4118 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4121 kref_get(&dump->kref);
4122 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4124 if (off > dump->driver_dump.hdr.len) {
4125 kref_put(&dump->kref, ipr_release_dump);
4129 if (off + count > dump->driver_dump.hdr.len) {
4130 count = dump->driver_dump.hdr.len - off;
4134 if (count && off < sizeof(dump->driver_dump)) {
4135 if (off + count > sizeof(dump->driver_dump))
4136 len = sizeof(dump->driver_dump) - off;
4139 src = (u8 *)&dump->driver_dump + off;
4140 memcpy(buf, src, len);
4146 off -= sizeof(dump->driver_dump);
4149 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4150 (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
4151 sizeof(struct ipr_sdt_entry));
4153 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4154 (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
4156 if (count && off < sdt_end) {
4157 if (off + count > sdt_end)
4158 len = sdt_end - off;
4161 src = (u8 *)&dump->ioa_dump + off;
4162 memcpy(buf, src, len);
4171 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
4172 len = PAGE_ALIGN(off) - off;
4175 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
4176 src += off & ~PAGE_MASK;
4177 memcpy(buf, src, len);
4183 kref_put(&dump->kref, ipr_release_dump);
4188 * ipr_alloc_dump - Prepare for adapter dump
4189 * @ioa_cfg: ioa config struct
4192 * 0 on success / other on failure
4194 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
4196 struct ipr_dump *dump;
4198 unsigned long lock_flags = 0;
4200 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
4203 ipr_err("Dump memory allocation failed\n");
4208 ioa_data = vmalloc(IPR_FMT3_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
4210 ioa_data = vmalloc(IPR_FMT2_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
4213 ipr_err("Dump memory allocation failed\n");
4218 dump->ioa_dump.ioa_data = ioa_data;
4220 kref_init(&dump->kref);
4221 dump->ioa_cfg = ioa_cfg;
4223 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4225 if (INACTIVE != ioa_cfg->sdt_state) {
4226 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4227 vfree(dump->ioa_dump.ioa_data);
4232 ioa_cfg->dump = dump;
4233 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
4234 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead && !ioa_cfg->dump_taken) {
4235 ioa_cfg->dump_taken = 1;
4236 schedule_work(&ioa_cfg->work_q);
4238 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4244 * ipr_free_dump - Free adapter dump memory
4245 * @ioa_cfg: ioa config struct
4248 * 0 on success / other on failure
4250 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
4252 struct ipr_dump *dump;
4253 unsigned long lock_flags = 0;
4257 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4258 dump = ioa_cfg->dump;
4260 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4264 ioa_cfg->dump = NULL;
4265 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4267 kref_put(&dump->kref, ipr_release_dump);
4274 * ipr_write_dump - Setup dump state of adapter
4275 * @filp: open sysfs file
4276 * @kobj: kobject struct
4277 * @bin_attr: bin_attribute struct
4280 * @count: buffer size
4283 * number of bytes printed to buffer
4285 static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
4286 struct bin_attribute *bin_attr,
4287 char *buf, loff_t off, size_t count)
4289 struct device *cdev = container_of(kobj, struct device, kobj);
4290 struct Scsi_Host *shost = class_to_shost(cdev);
4291 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4294 if (!capable(CAP_SYS_ADMIN))
4298 rc = ipr_alloc_dump(ioa_cfg);
4299 else if (buf[0] == '0')
4300 rc = ipr_free_dump(ioa_cfg);
4310 static struct bin_attribute ipr_dump_attr = {
4313 .mode = S_IRUSR | S_IWUSR,
4316 .read = ipr_read_dump,
4317 .write = ipr_write_dump
4320 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
4324 * ipr_change_queue_depth - Change the device's queue depth
4325 * @sdev: scsi device struct
4326 * @qdepth: depth to set
4327 * @reason: calling context
4332 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
4334 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4335 struct ipr_resource_entry *res;
4336 unsigned long lock_flags = 0;
4338 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4339 res = (struct ipr_resource_entry *)sdev->hostdata;
4341 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
4342 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
4343 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4345 scsi_change_queue_depth(sdev, qdepth);
4346 return sdev->queue_depth;
4350 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4351 * @dev: device struct
4352 * @attr: device attribute structure
4356 * number of bytes printed to buffer
4358 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
4360 struct scsi_device *sdev = to_scsi_device(dev);
4361 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4362 struct ipr_resource_entry *res;
4363 unsigned long lock_flags = 0;
4364 ssize_t len = -ENXIO;
4366 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4367 res = (struct ipr_resource_entry *)sdev->hostdata;
4369 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
4370 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4374 static struct device_attribute ipr_adapter_handle_attr = {
4376 .name = "adapter_handle",
4379 .show = ipr_show_adapter_handle
4383 * ipr_show_resource_path - Show the resource path or the resource address for
4385 * @dev: device struct
4386 * @attr: device attribute structure
4390 * number of bytes printed to buffer
4392 static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
4394 struct scsi_device *sdev = to_scsi_device(dev);
4395 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4396 struct ipr_resource_entry *res;
4397 unsigned long lock_flags = 0;
4398 ssize_t len = -ENXIO;
4399 char buffer[IPR_MAX_RES_PATH_LENGTH];
4401 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4402 res = (struct ipr_resource_entry *)sdev->hostdata;
4403 if (res && ioa_cfg->sis64)
4404 len = snprintf(buf, PAGE_SIZE, "%s\n",
4405 __ipr_format_res_path(res->res_path, buffer,
4408 len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
4409 res->bus, res->target, res->lun);
4411 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4415 static struct device_attribute ipr_resource_path_attr = {
4417 .name = "resource_path",
4420 .show = ipr_show_resource_path
4424 * ipr_show_device_id - Show the device_id for this device.
4425 * @dev: device struct
4426 * @attr: device attribute structure
4430 * number of bytes printed to buffer
4432 static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
4434 struct scsi_device *sdev = to_scsi_device(dev);
4435 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4436 struct ipr_resource_entry *res;
4437 unsigned long lock_flags = 0;
4438 ssize_t len = -ENXIO;
4440 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4441 res = (struct ipr_resource_entry *)sdev->hostdata;
4442 if (res && ioa_cfg->sis64)
4443 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->dev_id);
4445 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
4447 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4451 static struct device_attribute ipr_device_id_attr = {
4453 .name = "device_id",
4456 .show = ipr_show_device_id
4460 * ipr_show_resource_type - Show the resource type for this device.
4461 * @dev: device struct
4462 * @attr: device attribute structure
4466 * number of bytes printed to buffer
4468 static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
4470 struct scsi_device *sdev = to_scsi_device(dev);
4471 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4472 struct ipr_resource_entry *res;
4473 unsigned long lock_flags = 0;
4474 ssize_t len = -ENXIO;
4476 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4477 res = (struct ipr_resource_entry *)sdev->hostdata;
4480 len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
4482 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4486 static struct device_attribute ipr_resource_type_attr = {
4488 .name = "resource_type",
4491 .show = ipr_show_resource_type
4494 static struct device_attribute *ipr_dev_attrs[] = {
4495 &ipr_adapter_handle_attr,
4496 &ipr_resource_path_attr,
4497 &ipr_device_id_attr,
4498 &ipr_resource_type_attr,
4503 * ipr_biosparam - Return the HSC mapping
4504 * @sdev: scsi device struct
4505 * @block_device: block device pointer
4506 * @capacity: capacity of the device
4507 * @parm: Array containing returned HSC values.
4509 * This function generates the HSC parms that fdisk uses.
4510 * We want to make sure we return something that places partitions
4511 * on 4k boundaries for best performance with the IOA.
4516 static int ipr_biosparam(struct scsi_device *sdev,
4517 struct block_device *block_device,
4518 sector_t capacity, int *parm)
4526 cylinders = capacity;
4527 sector_div(cylinders, (128 * 32));
4532 parm[2] = cylinders;
4538 * ipr_find_starget - Find target based on bus/target.
4539 * @starget: scsi target struct
4542 * resource entry pointer if found / NULL if not found
4544 static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
4546 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4547 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4548 struct ipr_resource_entry *res;
4550 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4551 if ((res->bus == starget->channel) &&
4552 (res->target == starget->id)) {
4560 static struct ata_port_info sata_port_info;
4563 * ipr_target_alloc - Prepare for commands to a SCSI target
4564 * @starget: scsi target struct
4566 * If the device is a SATA device, this function allocates an
4567 * ATA port with libata, else it does nothing.
4570 * 0 on success / non-0 on failure
4572 static int ipr_target_alloc(struct scsi_target *starget)
4574 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4575 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4576 struct ipr_sata_port *sata_port;
4577 struct ata_port *ap;
4578 struct ipr_resource_entry *res;
4579 unsigned long lock_flags;
4581 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4582 res = ipr_find_starget(starget);
4583 starget->hostdata = NULL;
4585 if (res && ipr_is_gata(res)) {
4586 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4587 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
4591 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
4593 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4594 sata_port->ioa_cfg = ioa_cfg;
4596 sata_port->res = res;
4598 res->sata_port = sata_port;
4599 ap->private_data = sata_port;
4600 starget->hostdata = sata_port;
4606 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4612 * ipr_target_destroy - Destroy a SCSI target
4613 * @starget: scsi target struct
4615 * If the device was a SATA device, this function frees the libata
4616 * ATA port, else it does nothing.
4619 static void ipr_target_destroy(struct scsi_target *starget)
4621 struct ipr_sata_port *sata_port = starget->hostdata;
4622 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4623 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4625 if (ioa_cfg->sis64) {
4626 if (!ipr_find_starget(starget)) {
4627 if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4628 clear_bit(starget->id, ioa_cfg->array_ids);
4629 else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4630 clear_bit(starget->id, ioa_cfg->vset_ids);
4631 else if (starget->channel == 0)
4632 clear_bit(starget->id, ioa_cfg->target_ids);
4637 starget->hostdata = NULL;
4638 ata_sas_port_destroy(sata_port->ap);
4644 * ipr_find_sdev - Find device based on bus/target/lun.
4645 * @sdev: scsi device struct
4648 * resource entry pointer if found / NULL if not found
4650 static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
4652 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4653 struct ipr_resource_entry *res;
4655 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4656 if ((res->bus == sdev->channel) &&
4657 (res->target == sdev->id) &&
4658 (res->lun == sdev->lun))
4666 * ipr_slave_destroy - Unconfigure a SCSI device
4667 * @sdev: scsi device struct
4672 static void ipr_slave_destroy(struct scsi_device *sdev)
4674 struct ipr_resource_entry *res;
4675 struct ipr_ioa_cfg *ioa_cfg;
4676 unsigned long lock_flags = 0;
4678 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4680 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4681 res = (struct ipr_resource_entry *) sdev->hostdata;
4684 res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
4685 sdev->hostdata = NULL;
4687 res->sata_port = NULL;
4689 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4693 * ipr_slave_configure - Configure a SCSI device
4694 * @sdev: scsi device struct
4696 * This function configures the specified scsi device.
4701 static int ipr_slave_configure(struct scsi_device *sdev)
4703 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4704 struct ipr_resource_entry *res;
4705 struct ata_port *ap = NULL;
4706 unsigned long lock_flags = 0;
4707 char buffer[IPR_MAX_RES_PATH_LENGTH];
4709 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4710 res = sdev->hostdata;
4712 if (ipr_is_af_dasd_device(res))
4713 sdev->type = TYPE_RAID;
4714 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
4715 sdev->scsi_level = 4;
4716 sdev->no_uld_attach = 1;
4718 if (ipr_is_vset_device(res)) {
4719 sdev->scsi_level = SCSI_SPC_3;
4720 blk_queue_rq_timeout(sdev->request_queue,
4721 IPR_VSET_RW_TIMEOUT);
4722 blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
4724 if (ipr_is_gata(res) && res->sata_port)
4725 ap = res->sata_port->ap;
4726 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4729 scsi_change_queue_depth(sdev, IPR_MAX_CMD_PER_ATA_LUN);
4730 ata_sas_slave_configure(sdev, ap);
4734 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
4735 ipr_format_res_path(ioa_cfg,
4736 res->res_path, buffer, sizeof(buffer)));
4739 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4744 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
4745 * @sdev: scsi device struct
4747 * This function initializes an ATA port so that future commands
4748 * sent through queuecommand will work.
4753 static int ipr_ata_slave_alloc(struct scsi_device *sdev)
4755 struct ipr_sata_port *sata_port = NULL;
4759 if (sdev->sdev_target)
4760 sata_port = sdev->sdev_target->hostdata;
4762 rc = ata_sas_port_init(sata_port->ap);
4764 rc = ata_sas_sync_probe(sata_port->ap);
4768 ipr_slave_destroy(sdev);
4775 * ipr_slave_alloc - Prepare for commands to a device.
4776 * @sdev: scsi device struct
4778 * This function saves a pointer to the resource entry
4779 * in the scsi device struct if the device exists. We
4780 * can then use this pointer in ipr_queuecommand when
4781 * handling new commands.
4784 * 0 on success / -ENXIO if device does not exist
4786 static int ipr_slave_alloc(struct scsi_device *sdev)
4788 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4789 struct ipr_resource_entry *res;
4790 unsigned long lock_flags;
4793 sdev->hostdata = NULL;
4795 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4797 res = ipr_find_sdev(sdev);
4802 sdev->hostdata = res;
4803 if (!ipr_is_naca_model(res))
4804 res->needs_sync_complete = 1;
4806 if (ipr_is_gata(res)) {
4807 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4808 return ipr_ata_slave_alloc(sdev);
4812 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4818 * ipr_match_lun - Match function for specified LUN
4819 * @ipr_cmd: ipr command struct
4820 * @device: device to match (sdev)
4823 * 1 if command matches sdev / 0 if command does not match sdev
4825 static int ipr_match_lun(struct ipr_cmnd *ipr_cmd, void *device)
4827 if (ipr_cmd->scsi_cmd && ipr_cmd->scsi_cmd->device == device)
4833 * ipr_wait_for_ops - Wait for matching commands to complete
4834 * @ipr_cmd: ipr command struct
4835 * @device: device to match (sdev)
4836 * @match: match function to use
4841 static int ipr_wait_for_ops(struct ipr_ioa_cfg *ioa_cfg, void *device,
4842 int (*match)(struct ipr_cmnd *, void *))
4844 struct ipr_cmnd *ipr_cmd;
4846 unsigned long flags;
4847 struct ipr_hrr_queue *hrrq;
4848 signed long timeout = IPR_ABORT_TASK_TIMEOUT;
4849 DECLARE_COMPLETION_ONSTACK(comp);
4855 for_each_hrrq(hrrq, ioa_cfg) {
4856 spin_lock_irqsave(hrrq->lock, flags);
4857 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
4858 if (match(ipr_cmd, device)) {
4859 ipr_cmd->eh_comp = ∁
4863 spin_unlock_irqrestore(hrrq->lock, flags);
4867 timeout = wait_for_completion_timeout(&comp, timeout);
4872 for_each_hrrq(hrrq, ioa_cfg) {
4873 spin_lock_irqsave(hrrq->lock, flags);
4874 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
4875 if (match(ipr_cmd, device)) {
4876 ipr_cmd->eh_comp = NULL;
4880 spin_unlock_irqrestore(hrrq->lock, flags);
4884 dev_err(&ioa_cfg->pdev->dev, "Timed out waiting for aborted commands\n");
4886 return wait ? FAILED : SUCCESS;
4895 static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
4897 struct ipr_ioa_cfg *ioa_cfg;
4898 unsigned long lock_flags = 0;
4902 ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
4903 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4905 if (!ioa_cfg->in_reset_reload && !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
4906 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
4907 dev_err(&ioa_cfg->pdev->dev,
4908 "Adapter being reset as a result of error recovery.\n");
4910 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4911 ioa_cfg->sdt_state = GET_DUMP;
4914 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4915 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4916 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4918 /* If we got hit with a host reset while we were already resetting
4919 the adapter for some reason, and the reset failed. */
4920 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
4925 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4931 * ipr_device_reset - Reset the device
4932 * @ioa_cfg: ioa config struct
4933 * @res: resource entry struct
4935 * This function issues a device reset to the affected device.
4936 * If the device is a SCSI device, a LUN reset will be sent
4937 * to the device first. If that does not work, a target reset
4938 * will be sent. If the device is a SATA device, a PHY reset will
4942 * 0 on success / non-zero on failure
4944 static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
4945 struct ipr_resource_entry *res)
4947 struct ipr_cmnd *ipr_cmd;
4948 struct ipr_ioarcb *ioarcb;
4949 struct ipr_cmd_pkt *cmd_pkt;
4950 struct ipr_ioarcb_ata_regs *regs;
4954 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4955 ioarcb = &ipr_cmd->ioarcb;
4956 cmd_pkt = &ioarcb->cmd_pkt;
4958 if (ipr_cmd->ioa_cfg->sis64) {
4959 regs = &ipr_cmd->i.ata_ioadl.regs;
4960 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
4962 regs = &ioarcb->u.add_data.u.regs;
4964 ioarcb->res_handle = res->res_handle;
4965 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4966 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
4967 if (ipr_is_gata(res)) {
4968 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
4969 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
4970 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
4973 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
4974 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
4975 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
4976 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) {
4977 if (ipr_cmd->ioa_cfg->sis64)
4978 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
4979 sizeof(struct ipr_ioasa_gata));
4981 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
4982 sizeof(struct ipr_ioasa_gata));
4986 return IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0;
4990 * ipr_sata_reset - Reset the SATA port
4991 * @link: SATA link to reset
4992 * @classes: class of the attached device
4994 * This function issues a SATA phy reset to the affected ATA link.
4997 * 0 on success / non-zero on failure
4999 static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
5000 unsigned long deadline)
5002 struct ipr_sata_port *sata_port = link->ap->private_data;
5003 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5004 struct ipr_resource_entry *res;
5005 unsigned long lock_flags = 0;
5009 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5010 while (ioa_cfg->in_reset_reload) {
5011 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5012 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
5013 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5016 res = sata_port->res;
5018 rc = ipr_device_reset(ioa_cfg, res);
5019 *classes = res->ata_class;
5022 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5028 * ipr_eh_dev_reset - Reset the device
5029 * @scsi_cmd: scsi command struct
5031 * This function issues a device reset to the affected device.
5032 * A LUN reset will be sent to the device first. If that does
5033 * not work, a target reset will be sent.
5038 static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
5040 struct ipr_cmnd *ipr_cmd;
5041 struct ipr_ioa_cfg *ioa_cfg;
5042 struct ipr_resource_entry *res;
5043 struct ata_port *ap;
5045 struct ipr_hrr_queue *hrrq;
5048 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
5049 res = scsi_cmd->device->hostdata;
5055 * If we are currently going through reset/reload, return failed. This will force the
5056 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
5059 if (ioa_cfg->in_reset_reload)
5061 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
5064 for_each_hrrq(hrrq, ioa_cfg) {
5065 spin_lock(&hrrq->_lock);
5066 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
5067 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
5068 if (ipr_cmd->scsi_cmd)
5069 ipr_cmd->done = ipr_scsi_eh_done;
5071 ipr_cmd->done = ipr_sata_eh_done;
5073 !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
5074 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
5075 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
5079 spin_unlock(&hrrq->_lock);
5081 res->resetting_device = 1;
5082 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
5084 if (ipr_is_gata(res) && res->sata_port) {
5085 ap = res->sata_port->ap;
5086 spin_unlock_irq(scsi_cmd->device->host->host_lock);
5087 ata_std_error_handler(ap);
5088 spin_lock_irq(scsi_cmd->device->host->host_lock);
5090 for_each_hrrq(hrrq, ioa_cfg) {
5091 spin_lock(&hrrq->_lock);
5092 list_for_each_entry(ipr_cmd,
5093 &hrrq->hrrq_pending_q, queue) {
5094 if (ipr_cmd->ioarcb.res_handle ==
5100 spin_unlock(&hrrq->_lock);
5103 rc = ipr_device_reset(ioa_cfg, res);
5104 res->resetting_device = 0;
5105 res->reset_occurred = 1;
5108 return rc ? FAILED : SUCCESS;
5111 static int ipr_eh_dev_reset(struct scsi_cmnd *cmd)
5114 struct ipr_ioa_cfg *ioa_cfg;
5116 ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
5118 spin_lock_irq(cmd->device->host->host_lock);
5119 rc = __ipr_eh_dev_reset(cmd);
5120 spin_unlock_irq(cmd->device->host->host_lock);
5123 rc = ipr_wait_for_ops(ioa_cfg, cmd->device, ipr_match_lun);
5129 * ipr_bus_reset_done - Op done function for bus reset.
5130 * @ipr_cmd: ipr command struct
5132 * This function is the op done function for a bus reset
5137 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
5139 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5140 struct ipr_resource_entry *res;
5143 if (!ioa_cfg->sis64)
5144 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
5145 if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
5146 scsi_report_bus_reset(ioa_cfg->host, res->bus);
5152 * If abort has not completed, indicate the reset has, else call the
5153 * abort's done function to wake the sleeping eh thread
5155 if (ipr_cmd->sibling->sibling)
5156 ipr_cmd->sibling->sibling = NULL;
5158 ipr_cmd->sibling->done(ipr_cmd->sibling);
5160 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5165 * ipr_abort_timeout - An abort task has timed out
5166 * @ipr_cmd: ipr command struct
5168 * This function handles when an abort task times out. If this
5169 * happens we issue a bus reset since we have resources tied
5170 * up that must be freed before returning to the midlayer.
5175 static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
5177 struct ipr_cmnd *reset_cmd;
5178 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5179 struct ipr_cmd_pkt *cmd_pkt;
5180 unsigned long lock_flags = 0;
5183 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5184 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
5185 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5189 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
5190 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5191 ipr_cmd->sibling = reset_cmd;
5192 reset_cmd->sibling = ipr_cmd;
5193 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
5194 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
5195 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5196 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
5197 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
5199 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
5200 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5205 * ipr_cancel_op - Cancel specified op
5206 * @scsi_cmd: scsi command struct
5208 * This function cancels specified op.
5213 static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
5215 struct ipr_cmnd *ipr_cmd;
5216 struct ipr_ioa_cfg *ioa_cfg;
5217 struct ipr_resource_entry *res;
5218 struct ipr_cmd_pkt *cmd_pkt;
5221 struct ipr_hrr_queue *hrrq;
5224 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
5225 res = scsi_cmd->device->hostdata;
5227 /* If we are currently going through reset/reload, return failed.
5228 * This will force the mid-layer to call ipr_eh_host_reset,
5229 * which will then go to sleep and wait for the reset to complete
5231 if (ioa_cfg->in_reset_reload ||
5232 ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
5238 * If we are aborting a timed out op, chances are that the timeout was caused
5239 * by a still not detected EEH error. In such cases, reading a register will
5240 * trigger the EEH recovery infrastructure.
5242 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5244 if (!ipr_is_gscsi(res))
5247 for_each_hrrq(hrrq, ioa_cfg) {
5248 spin_lock(&hrrq->_lock);
5249 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
5250 if (ipr_cmd->scsi_cmd == scsi_cmd) {
5251 ipr_cmd->done = ipr_scsi_eh_done;
5256 spin_unlock(&hrrq->_lock);
5262 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5263 ipr_cmd->ioarcb.res_handle = res->res_handle;
5264 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5265 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5266 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5267 ipr_cmd->u.sdev = scsi_cmd->device;
5269 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
5271 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
5272 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5275 * If the abort task timed out and we sent a bus reset, we will get
5276 * one the following responses to the abort
5278 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
5283 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5284 if (!ipr_is_naca_model(res))
5285 res->needs_sync_complete = 1;
5288 return IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS;
5292 * ipr_eh_abort - Abort a single op
5293 * @scsi_cmd: scsi command struct
5296 * 0 if scan in progress / 1 if scan is complete
5298 static int ipr_scan_finished(struct Scsi_Host *shost, unsigned long elapsed_time)
5300 unsigned long lock_flags;
5301 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
5304 spin_lock_irqsave(shost->host_lock, lock_flags);
5305 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead || ioa_cfg->scan_done)
5307 if ((elapsed_time/HZ) > (ioa_cfg->transop_timeout * 2))
5309 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5314 * ipr_eh_host_reset - Reset the host adapter
5315 * @scsi_cmd: scsi command struct
5320 static int ipr_eh_abort(struct scsi_cmnd *scsi_cmd)
5322 unsigned long flags;
5324 struct ipr_ioa_cfg *ioa_cfg;
5328 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
5330 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
5331 rc = ipr_cancel_op(scsi_cmd);
5332 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
5335 rc = ipr_wait_for_ops(ioa_cfg, scsi_cmd->device, ipr_match_lun);
5341 * ipr_handle_other_interrupt - Handle "other" interrupts
5342 * @ioa_cfg: ioa config struct
5343 * @int_reg: interrupt register
5346 * IRQ_NONE / IRQ_HANDLED
5348 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
5351 irqreturn_t rc = IRQ_HANDLED;
5354 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
5355 int_reg &= ~int_mask_reg;
5357 /* If an interrupt on the adapter did not occur, ignore it.
5358 * Or in the case of SIS 64, check for a stage change interrupt.
5360 if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
5361 if (ioa_cfg->sis64) {
5362 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
5363 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5364 if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
5366 /* clear stage change */
5367 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
5368 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5369 list_del(&ioa_cfg->reset_cmd->queue);
5370 del_timer(&ioa_cfg->reset_cmd->timer);
5371 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5379 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
5380 /* Mask the interrupt */
5381 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
5383 /* Clear the interrupt */
5384 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
5385 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5387 list_del(&ioa_cfg->reset_cmd->queue);
5388 del_timer(&ioa_cfg->reset_cmd->timer);
5389 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5390 } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
5391 if (ioa_cfg->clear_isr) {
5392 if (ipr_debug && printk_ratelimit())
5393 dev_err(&ioa_cfg->pdev->dev,
5394 "Spurious interrupt detected. 0x%08X\n", int_reg);
5395 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5396 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5400 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
5401 ioa_cfg->ioa_unit_checked = 1;
5402 else if (int_reg & IPR_PCII_NO_HOST_RRQ)
5403 dev_err(&ioa_cfg->pdev->dev,
5404 "No Host RRQ. 0x%08X\n", int_reg);
5406 dev_err(&ioa_cfg->pdev->dev,
5407 "Permanent IOA failure. 0x%08X\n", int_reg);
5409 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5410 ioa_cfg->sdt_state = GET_DUMP;
5412 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
5413 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5420 * ipr_isr_eh - Interrupt service routine error handler
5421 * @ioa_cfg: ioa config struct
5422 * @msg: message to log
5427 static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg, u16 number)
5429 ioa_cfg->errors_logged++;
5430 dev_err(&ioa_cfg->pdev->dev, "%s %d\n", msg, number);
5432 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5433 ioa_cfg->sdt_state = GET_DUMP;
5435 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5438 static int ipr_process_hrrq(struct ipr_hrr_queue *hrr_queue, int budget,
5439 struct list_head *doneq)
5443 struct ipr_cmnd *ipr_cmd;
5444 struct ipr_ioa_cfg *ioa_cfg = hrr_queue->ioa_cfg;
5447 /* If interrupts are disabled, ignore the interrupt */
5448 if (!hrr_queue->allow_interrupts)
5451 while ((be32_to_cpu(*hrr_queue->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5452 hrr_queue->toggle_bit) {
5454 cmd_index = (be32_to_cpu(*hrr_queue->hrrq_curr) &
5455 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >>
5456 IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
5458 if (unlikely(cmd_index > hrr_queue->max_cmd_id ||
5459 cmd_index < hrr_queue->min_cmd_id)) {
5461 "Invalid response handle from IOA: ",
5466 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
5467 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5469 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
5471 list_move_tail(&ipr_cmd->queue, doneq);
5473 if (hrr_queue->hrrq_curr < hrr_queue->hrrq_end) {
5474 hrr_queue->hrrq_curr++;
5476 hrr_queue->hrrq_curr = hrr_queue->hrrq_start;
5477 hrr_queue->toggle_bit ^= 1u;
5480 if (budget > 0 && num_hrrq >= budget)
5487 static int ipr_iopoll(struct blk_iopoll *iop, int budget)
5489 struct ipr_ioa_cfg *ioa_cfg;
5490 struct ipr_hrr_queue *hrrq;
5491 struct ipr_cmnd *ipr_cmd, *temp;
5492 unsigned long hrrq_flags;
5496 hrrq = container_of(iop, struct ipr_hrr_queue, iopoll);
5497 ioa_cfg = hrrq->ioa_cfg;
5499 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5500 completed_ops = ipr_process_hrrq(hrrq, budget, &doneq);
5502 if (completed_ops < budget)
5503 blk_iopoll_complete(iop);
5504 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5506 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5507 list_del(&ipr_cmd->queue);
5508 del_timer(&ipr_cmd->timer);
5509 ipr_cmd->fast_done(ipr_cmd);
5512 return completed_ops;
5516 * ipr_isr - Interrupt service routine
5518 * @devp: pointer to ioa config struct
5521 * IRQ_NONE / IRQ_HANDLED
5523 static irqreturn_t ipr_isr(int irq, void *devp)
5525 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
5526 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
5527 unsigned long hrrq_flags = 0;
5531 struct ipr_cmnd *ipr_cmd, *temp;
5532 irqreturn_t rc = IRQ_NONE;
5535 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5536 /* If interrupts are disabled, ignore the interrupt */
5537 if (!hrrq->allow_interrupts) {
5538 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5543 if (ipr_process_hrrq(hrrq, -1, &doneq)) {
5546 if (!ioa_cfg->clear_isr)
5549 /* Clear the PCI interrupt */
5552 writel(IPR_PCII_HRRQ_UPDATED,
5553 ioa_cfg->regs.clr_interrupt_reg32);
5554 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5555 } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
5556 num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
5558 } else if (rc == IRQ_NONE && irq_none == 0) {
5559 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5561 } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
5562 int_reg & IPR_PCII_HRRQ_UPDATED) {
5564 "Error clearing HRRQ: ", num_hrrq);
5571 if (unlikely(rc == IRQ_NONE))
5572 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
5574 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5575 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5576 list_del(&ipr_cmd->queue);
5577 del_timer(&ipr_cmd->timer);
5578 ipr_cmd->fast_done(ipr_cmd);
5584 * ipr_isr_mhrrq - Interrupt service routine
5586 * @devp: pointer to ioa config struct
5589 * IRQ_NONE / IRQ_HANDLED
5591 static irqreturn_t ipr_isr_mhrrq(int irq, void *devp)
5593 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
5594 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
5595 unsigned long hrrq_flags = 0;
5596 struct ipr_cmnd *ipr_cmd, *temp;
5597 irqreturn_t rc = IRQ_NONE;
5600 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5602 /* If interrupts are disabled, ignore the interrupt */
5603 if (!hrrq->allow_interrupts) {
5604 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5608 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
5609 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5611 if (!blk_iopoll_sched_prep(&hrrq->iopoll))
5612 blk_iopoll_sched(&hrrq->iopoll);
5613 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5617 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5620 if (ipr_process_hrrq(hrrq, -1, &doneq))
5624 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5626 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5627 list_del(&ipr_cmd->queue);
5628 del_timer(&ipr_cmd->timer);
5629 ipr_cmd->fast_done(ipr_cmd);
5635 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
5636 * @ioa_cfg: ioa config struct
5637 * @ipr_cmd: ipr command struct
5640 * 0 on success / -1 on failure
5642 static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
5643 struct ipr_cmnd *ipr_cmd)
5646 struct scatterlist *sg;
5648 u32 ioadl_flags = 0;
5649 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5650 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5651 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
5653 length = scsi_bufflen(scsi_cmd);
5657 nseg = scsi_dma_map(scsi_cmd);
5659 if (printk_ratelimit())
5660 dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
5664 ipr_cmd->dma_use_sg = nseg;
5666 ioarcb->data_transfer_length = cpu_to_be32(length);
5668 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
5670 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5671 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5672 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5673 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
5674 ioadl_flags = IPR_IOADL_FLAGS_READ;
5676 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5677 ioadl64[i].flags = cpu_to_be32(ioadl_flags);
5678 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
5679 ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
5682 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5687 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5688 * @ioa_cfg: ioa config struct
5689 * @ipr_cmd: ipr command struct
5692 * 0 on success / -1 on failure
5694 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5695 struct ipr_cmnd *ipr_cmd)
5698 struct scatterlist *sg;
5700 u32 ioadl_flags = 0;
5701 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5702 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5703 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
5705 length = scsi_bufflen(scsi_cmd);
5709 nseg = scsi_dma_map(scsi_cmd);
5711 dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
5715 ipr_cmd->dma_use_sg = nseg;
5717 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5718 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5719 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5720 ioarcb->data_transfer_length = cpu_to_be32(length);
5722 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5723 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
5724 ioadl_flags = IPR_IOADL_FLAGS_READ;
5725 ioarcb->read_data_transfer_length = cpu_to_be32(length);
5726 ioarcb->read_ioadl_len =
5727 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5730 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
5731 ioadl = ioarcb->u.add_data.u.ioadl;
5732 ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
5733 offsetof(struct ipr_ioarcb, u.add_data));
5734 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5737 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5738 ioadl[i].flags_and_data_len =
5739 cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5740 ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
5743 ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5748 * ipr_erp_done - Process completion of ERP for a device
5749 * @ipr_cmd: ipr command struct
5751 * This function copies the sense buffer into the scsi_cmd
5752 * struct and pushes the scsi_done function.
5757 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
5759 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5760 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5761 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5763 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5764 scsi_cmd->result |= (DID_ERROR << 16);
5765 scmd_printk(KERN_ERR, scsi_cmd,
5766 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
5768 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
5769 SCSI_SENSE_BUFFERSIZE);
5773 if (!ipr_is_naca_model(res))
5774 res->needs_sync_complete = 1;
5777 scsi_dma_unmap(ipr_cmd->scsi_cmd);
5778 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5779 scsi_cmd->scsi_done(scsi_cmd);
5783 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5784 * @ipr_cmd: ipr command struct
5789 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
5791 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5792 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5793 dma_addr_t dma_addr = ipr_cmd->dma_addr;
5795 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
5796 ioarcb->data_transfer_length = 0;
5797 ioarcb->read_data_transfer_length = 0;
5798 ioarcb->ioadl_len = 0;
5799 ioarcb->read_ioadl_len = 0;
5800 ioasa->hdr.ioasc = 0;
5801 ioasa->hdr.residual_data_len = 0;
5803 if (ipr_cmd->ioa_cfg->sis64)
5804 ioarcb->u.sis64_addr_data.data_ioadl_addr =
5805 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
5807 ioarcb->write_ioadl_addr =
5808 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
5809 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5814 * ipr_erp_request_sense - Send request sense to a device
5815 * @ipr_cmd: ipr command struct
5817 * This function sends a request sense to a device as a result
5818 * of a check condition.
5823 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
5825 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5826 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5828 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5829 ipr_erp_done(ipr_cmd);
5833 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5835 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
5836 cmd_pkt->cdb[0] = REQUEST_SENSE;
5837 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
5838 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
5839 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5840 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
5842 ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
5843 SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
5845 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
5846 IPR_REQUEST_SENSE_TIMEOUT * 2);
5850 * ipr_erp_cancel_all - Send cancel all to a device
5851 * @ipr_cmd: ipr command struct
5853 * This function sends a cancel all to a device to clear the
5854 * queue. If we are running TCQ on the device, QERR is set to 1,
5855 * which means all outstanding ops have been dropped on the floor.
5856 * Cancel all will return them to us.
5861 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
5863 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5864 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5865 struct ipr_cmd_pkt *cmd_pkt;
5869 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5871 if (!scsi_cmd->device->simple_tags) {
5872 ipr_erp_request_sense(ipr_cmd);
5876 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5877 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5878 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5880 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
5881 IPR_CANCEL_ALL_TIMEOUT);
5885 * ipr_dump_ioasa - Dump contents of IOASA
5886 * @ioa_cfg: ioa config struct
5887 * @ipr_cmd: ipr command struct
5888 * @res: resource entry struct
5890 * This function is invoked by the interrupt handler when ops
5891 * fail. It will log the IOASA if appropriate. Only called
5897 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
5898 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
5902 u32 ioasc, fd_ioasc;
5903 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5904 __be32 *ioasa_data = (__be32 *)ioasa;
5907 ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
5908 fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
5913 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
5916 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
5917 error_index = ipr_get_error(fd_ioasc);
5919 error_index = ipr_get_error(ioasc);
5921 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
5922 /* Don't log an error if the IOA already logged one */
5923 if (ioasa->hdr.ilid != 0)
5926 if (!ipr_is_gscsi(res))
5929 if (ipr_error_table[error_index].log_ioasa == 0)
5933 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
5935 data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
5936 if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
5937 data_len = sizeof(struct ipr_ioasa64);
5938 else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
5939 data_len = sizeof(struct ipr_ioasa);
5941 ipr_err("IOASA Dump:\n");
5943 for (i = 0; i < data_len / 4; i += 4) {
5944 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
5945 be32_to_cpu(ioasa_data[i]),
5946 be32_to_cpu(ioasa_data[i+1]),
5947 be32_to_cpu(ioasa_data[i+2]),
5948 be32_to_cpu(ioasa_data[i+3]));
5953 * ipr_gen_sense - Generate SCSI sense data from an IOASA
5955 * @sense_buf: sense data buffer
5960 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
5963 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
5964 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
5965 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5966 u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
5968 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
5970 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
5973 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
5975 if (ipr_is_vset_device(res) &&
5976 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
5977 ioasa->u.vset.failing_lba_hi != 0) {
5978 sense_buf[0] = 0x72;
5979 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
5980 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
5981 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
5985 sense_buf[9] = 0x0A;
5986 sense_buf[10] = 0x80;
5988 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
5990 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
5991 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
5992 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
5993 sense_buf[15] = failing_lba & 0x000000ff;
5995 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5997 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
5998 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
5999 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
6000 sense_buf[19] = failing_lba & 0x000000ff;
6002 sense_buf[0] = 0x70;
6003 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
6004 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
6005 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
6007 /* Illegal request */
6008 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
6009 (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
6010 sense_buf[7] = 10; /* additional length */
6012 /* IOARCB was in error */
6013 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
6014 sense_buf[15] = 0xC0;
6015 else /* Parameter data was invalid */
6016 sense_buf[15] = 0x80;
6019 ((IPR_FIELD_POINTER_MASK &
6020 be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
6022 (IPR_FIELD_POINTER_MASK &
6023 be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
6025 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
6026 if (ipr_is_vset_device(res))
6027 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
6029 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
6031 sense_buf[0] |= 0x80; /* Or in the Valid bit */
6032 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
6033 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
6034 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
6035 sense_buf[6] = failing_lba & 0x000000ff;
6038 sense_buf[7] = 6; /* additional length */
6044 * ipr_get_autosense - Copy autosense data to sense buffer
6045 * @ipr_cmd: ipr command struct
6047 * This function copies the autosense buffer to the buffer
6048 * in the scsi_cmd, if there is autosense available.
6051 * 1 if autosense was available / 0 if not
6053 static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
6055 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
6056 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
6058 if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
6061 if (ipr_cmd->ioa_cfg->sis64)
6062 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
6063 min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
6064 SCSI_SENSE_BUFFERSIZE));
6066 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
6067 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
6068 SCSI_SENSE_BUFFERSIZE));
6073 * ipr_erp_start - Process an error response for a SCSI op
6074 * @ioa_cfg: ioa config struct
6075 * @ipr_cmd: ipr command struct
6077 * This function determines whether or not to initiate ERP
6078 * on the affected device.
6083 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
6084 struct ipr_cmnd *ipr_cmd)
6086 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
6087 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
6088 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6089 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
6092 ipr_scsi_eh_done(ipr_cmd);
6096 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
6097 ipr_gen_sense(ipr_cmd);
6099 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6101 switch (masked_ioasc) {
6102 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
6103 if (ipr_is_naca_model(res))
6104 scsi_cmd->result |= (DID_ABORT << 16);
6106 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6108 case IPR_IOASC_IR_RESOURCE_HANDLE:
6109 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
6110 scsi_cmd->result |= (DID_NO_CONNECT << 16);
6112 case IPR_IOASC_HW_SEL_TIMEOUT:
6113 scsi_cmd->result |= (DID_NO_CONNECT << 16);
6114 if (!ipr_is_naca_model(res))
6115 res->needs_sync_complete = 1;
6117 case IPR_IOASC_SYNC_REQUIRED:
6119 res->needs_sync_complete = 1;
6120 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6122 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
6123 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
6124 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
6126 case IPR_IOASC_BUS_WAS_RESET:
6127 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
6129 * Report the bus reset and ask for a retry. The device
6130 * will give CC/UA the next command.
6132 if (!res->resetting_device)
6133 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
6134 scsi_cmd->result |= (DID_ERROR << 16);
6135 if (!ipr_is_naca_model(res))
6136 res->needs_sync_complete = 1;
6138 case IPR_IOASC_HW_DEV_BUS_STATUS:
6139 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
6140 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
6141 if (!ipr_get_autosense(ipr_cmd)) {
6142 if (!ipr_is_naca_model(res)) {
6143 ipr_erp_cancel_all(ipr_cmd);
6148 if (!ipr_is_naca_model(res))
6149 res->needs_sync_complete = 1;
6151 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
6154 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
6155 scsi_cmd->result |= (DID_ERROR << 16);
6156 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
6157 res->needs_sync_complete = 1;
6161 scsi_dma_unmap(ipr_cmd->scsi_cmd);
6162 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6163 scsi_cmd->scsi_done(scsi_cmd);
6167 * ipr_scsi_done - mid-layer done function
6168 * @ipr_cmd: ipr command struct
6170 * This function is invoked by the interrupt handler for
6171 * ops generated by the SCSI mid-layer
6176 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
6178 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6179 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
6180 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6181 unsigned long hrrq_flags;
6183 scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
6185 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
6186 scsi_dma_unmap(scsi_cmd);
6188 spin_lock_irqsave(ipr_cmd->hrrq->lock, hrrq_flags);
6189 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6190 scsi_cmd->scsi_done(scsi_cmd);
6191 spin_unlock_irqrestore(ipr_cmd->hrrq->lock, hrrq_flags);
6193 spin_lock_irqsave(ipr_cmd->hrrq->lock, hrrq_flags);
6194 ipr_erp_start(ioa_cfg, ipr_cmd);
6195 spin_unlock_irqrestore(ipr_cmd->hrrq->lock, hrrq_flags);
6200 * ipr_queuecommand - Queue a mid-layer request
6201 * @shost: scsi host struct
6202 * @scsi_cmd: scsi command struct
6204 * This function queues a request generated by the mid-layer.
6208 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
6209 * SCSI_MLQUEUE_HOST_BUSY if host is busy
6211 static int ipr_queuecommand(struct Scsi_Host *shost,
6212 struct scsi_cmnd *scsi_cmd)
6214 struct ipr_ioa_cfg *ioa_cfg;
6215 struct ipr_resource_entry *res;
6216 struct ipr_ioarcb *ioarcb;
6217 struct ipr_cmnd *ipr_cmd;
6218 unsigned long hrrq_flags, lock_flags;
6220 struct ipr_hrr_queue *hrrq;
6223 ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
6225 scsi_cmd->result = (DID_OK << 16);
6226 res = scsi_cmd->device->hostdata;
6228 if (ipr_is_gata(res) && res->sata_port) {
6229 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6230 rc = ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
6231 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6235 hrrq_id = ipr_get_hrrq_index(ioa_cfg);
6236 hrrq = &ioa_cfg->hrrq[hrrq_id];
6238 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6240 * We are currently blocking all devices due to a host reset
6241 * We have told the host to stop giving us new requests, but
6242 * ERP ops don't count. FIXME
6244 if (unlikely(!hrrq->allow_cmds && !hrrq->ioa_is_dead && !hrrq->removing_ioa)) {
6245 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6246 return SCSI_MLQUEUE_HOST_BUSY;
6250 * FIXME - Create scsi_set_host_offline interface
6251 * and the ioa_is_dead check can be removed
6253 if (unlikely(hrrq->ioa_is_dead || hrrq->removing_ioa || !res)) {
6254 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6258 ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
6259 if (ipr_cmd == NULL) {
6260 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6261 return SCSI_MLQUEUE_HOST_BUSY;
6263 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6265 ipr_init_ipr_cmnd(ipr_cmd, ipr_scsi_done);
6266 ioarcb = &ipr_cmd->ioarcb;
6268 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
6269 ipr_cmd->scsi_cmd = scsi_cmd;
6270 ipr_cmd->done = ipr_scsi_eh_done;
6272 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
6273 if (scsi_cmd->underflow == 0)
6274 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
6276 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6277 if (ipr_is_gscsi(res) && res->reset_occurred) {
6278 res->reset_occurred = 0;
6279 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
6281 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
6282 if (scsi_cmd->flags & SCMD_TAGGED)
6283 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_SIMPLE_TASK;
6285 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_UNTAGGED_TASK;
6288 if (scsi_cmd->cmnd[0] >= 0xC0 &&
6289 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE)) {
6290 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6294 rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
6296 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
6298 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6299 if (unlikely(rc || (!hrrq->allow_cmds && !hrrq->ioa_is_dead))) {
6300 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
6301 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6303 scsi_dma_unmap(scsi_cmd);
6304 return SCSI_MLQUEUE_HOST_BUSY;
6307 if (unlikely(hrrq->ioa_is_dead)) {
6308 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
6309 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6310 scsi_dma_unmap(scsi_cmd);
6314 ioarcb->res_handle = res->res_handle;
6315 if (res->needs_sync_complete) {
6316 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
6317 res->needs_sync_complete = 0;
6319 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_pending_q);
6320 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
6321 ipr_send_command(ipr_cmd);
6322 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6326 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6327 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
6328 scsi_cmd->result = (DID_NO_CONNECT << 16);
6329 scsi_cmd->scsi_done(scsi_cmd);
6330 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6335 * ipr_ioctl - IOCTL handler
6336 * @sdev: scsi device struct
6341 * 0 on success / other on failure
6343 static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
6345 struct ipr_resource_entry *res;
6347 res = (struct ipr_resource_entry *)sdev->hostdata;
6348 if (res && ipr_is_gata(res)) {
6349 if (cmd == HDIO_GET_IDENTITY)
6351 return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
6358 * ipr_info - Get information about the card/driver
6359 * @scsi_host: scsi host struct
6362 * pointer to buffer with description string
6364 static const char *ipr_ioa_info(struct Scsi_Host *host)
6366 static char buffer[512];
6367 struct ipr_ioa_cfg *ioa_cfg;
6368 unsigned long lock_flags = 0;
6370 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
6372 spin_lock_irqsave(host->host_lock, lock_flags);
6373 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
6374 spin_unlock_irqrestore(host->host_lock, lock_flags);
6379 static struct scsi_host_template driver_template = {
6380 .module = THIS_MODULE,
6382 .info = ipr_ioa_info,
6384 .queuecommand = ipr_queuecommand,
6385 .eh_abort_handler = ipr_eh_abort,
6386 .eh_device_reset_handler = ipr_eh_dev_reset,
6387 .eh_host_reset_handler = ipr_eh_host_reset,
6388 .slave_alloc = ipr_slave_alloc,
6389 .slave_configure = ipr_slave_configure,
6390 .slave_destroy = ipr_slave_destroy,
6391 .scan_finished = ipr_scan_finished,
6392 .target_alloc = ipr_target_alloc,
6393 .target_destroy = ipr_target_destroy,
6394 .change_queue_depth = ipr_change_queue_depth,
6395 .bios_param = ipr_biosparam,
6396 .can_queue = IPR_MAX_COMMANDS,
6398 .sg_tablesize = IPR_MAX_SGLIST,
6399 .max_sectors = IPR_IOA_MAX_SECTORS,
6400 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
6401 .use_clustering = ENABLE_CLUSTERING,
6402 .shost_attrs = ipr_ioa_attrs,
6403 .sdev_attrs = ipr_dev_attrs,
6404 .proc_name = IPR_NAME,
6410 * ipr_ata_phy_reset - libata phy_reset handler
6411 * @ap: ata port to reset
6414 static void ipr_ata_phy_reset(struct ata_port *ap)
6416 unsigned long flags;
6417 struct ipr_sata_port *sata_port = ap->private_data;
6418 struct ipr_resource_entry *res = sata_port->res;
6419 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6423 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6424 while (ioa_cfg->in_reset_reload) {
6425 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6426 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6427 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6430 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
6433 rc = ipr_device_reset(ioa_cfg, res);
6436 ap->link.device[0].class = ATA_DEV_NONE;
6440 ap->link.device[0].class = res->ata_class;
6441 if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
6442 ap->link.device[0].class = ATA_DEV_NONE;
6445 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6450 * ipr_ata_post_internal - Cleanup after an internal command
6451 * @qc: ATA queued command
6456 static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
6458 struct ipr_sata_port *sata_port = qc->ap->private_data;
6459 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6460 struct ipr_cmnd *ipr_cmd;
6461 struct ipr_hrr_queue *hrrq;
6462 unsigned long flags;
6464 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6465 while (ioa_cfg->in_reset_reload) {
6466 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6467 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6468 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6471 for_each_hrrq(hrrq, ioa_cfg) {
6472 spin_lock(&hrrq->_lock);
6473 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
6474 if (ipr_cmd->qc == qc) {
6475 ipr_device_reset(ioa_cfg, sata_port->res);
6479 spin_unlock(&hrrq->_lock);
6481 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6485 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
6486 * @regs: destination
6487 * @tf: source ATA taskfile
6492 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
6493 struct ata_taskfile *tf)
6495 regs->feature = tf->feature;
6496 regs->nsect = tf->nsect;
6497 regs->lbal = tf->lbal;
6498 regs->lbam = tf->lbam;
6499 regs->lbah = tf->lbah;
6500 regs->device = tf->device;
6501 regs->command = tf->command;
6502 regs->hob_feature = tf->hob_feature;
6503 regs->hob_nsect = tf->hob_nsect;
6504 regs->hob_lbal = tf->hob_lbal;
6505 regs->hob_lbam = tf->hob_lbam;
6506 regs->hob_lbah = tf->hob_lbah;
6507 regs->ctl = tf->ctl;
6511 * ipr_sata_done - done function for SATA commands
6512 * @ipr_cmd: ipr command struct
6514 * This function is invoked by the interrupt handler for
6515 * ops generated by the SCSI mid-layer to SATA devices
6520 static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
6522 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6523 struct ata_queued_cmd *qc = ipr_cmd->qc;
6524 struct ipr_sata_port *sata_port = qc->ap->private_data;
6525 struct ipr_resource_entry *res = sata_port->res;
6526 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6528 spin_lock(&ipr_cmd->hrrq->_lock);
6529 if (ipr_cmd->ioa_cfg->sis64)
6530 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
6531 sizeof(struct ipr_ioasa_gata));
6533 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
6534 sizeof(struct ipr_ioasa_gata));
6535 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6537 if (be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
6538 scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
6540 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
6541 qc->err_mask |= __ac_err_mask(sata_port->ioasa.status);
6543 qc->err_mask |= ac_err_mask(sata_port->ioasa.status);
6544 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6545 spin_unlock(&ipr_cmd->hrrq->_lock);
6546 ata_qc_complete(qc);
6550 * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
6551 * @ipr_cmd: ipr command struct
6552 * @qc: ATA queued command
6555 static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
6556 struct ata_queued_cmd *qc)
6558 u32 ioadl_flags = 0;
6559 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6560 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ata_ioadl.ioadl64;
6561 struct ipr_ioadl64_desc *last_ioadl64 = NULL;
6562 int len = qc->nbytes;
6563 struct scatterlist *sg;
6565 dma_addr_t dma_addr = ipr_cmd->dma_addr;
6570 if (qc->dma_dir == DMA_TO_DEVICE) {
6571 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6572 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6573 } else if (qc->dma_dir == DMA_FROM_DEVICE)
6574 ioadl_flags = IPR_IOADL_FLAGS_READ;
6576 ioarcb->data_transfer_length = cpu_to_be32(len);
6578 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
6579 ioarcb->u.sis64_addr_data.data_ioadl_addr =
6580 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl.ioadl64));
6582 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6583 ioadl64->flags = cpu_to_be32(ioadl_flags);
6584 ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
6585 ioadl64->address = cpu_to_be64(sg_dma_address(sg));
6587 last_ioadl64 = ioadl64;
6591 if (likely(last_ioadl64))
6592 last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6596 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
6597 * @ipr_cmd: ipr command struct
6598 * @qc: ATA queued command
6601 static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
6602 struct ata_queued_cmd *qc)
6604 u32 ioadl_flags = 0;
6605 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6606 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
6607 struct ipr_ioadl_desc *last_ioadl = NULL;
6608 int len = qc->nbytes;
6609 struct scatterlist *sg;
6615 if (qc->dma_dir == DMA_TO_DEVICE) {
6616 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6617 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6618 ioarcb->data_transfer_length = cpu_to_be32(len);
6620 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6621 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
6622 ioadl_flags = IPR_IOADL_FLAGS_READ;
6623 ioarcb->read_data_transfer_length = cpu_to_be32(len);
6624 ioarcb->read_ioadl_len =
6625 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6628 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6629 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
6630 ioadl->address = cpu_to_be32(sg_dma_address(sg));
6636 if (likely(last_ioadl))
6637 last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6641 * ipr_qc_defer - Get a free ipr_cmd
6642 * @qc: queued command
6647 static int ipr_qc_defer(struct ata_queued_cmd *qc)
6649 struct ata_port *ap = qc->ap;
6650 struct ipr_sata_port *sata_port = ap->private_data;
6651 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6652 struct ipr_cmnd *ipr_cmd;
6653 struct ipr_hrr_queue *hrrq;
6656 hrrq_id = ipr_get_hrrq_index(ioa_cfg);
6657 hrrq = &ioa_cfg->hrrq[hrrq_id];
6659 qc->lldd_task = NULL;
6660 spin_lock(&hrrq->_lock);
6661 if (unlikely(hrrq->ioa_is_dead)) {
6662 spin_unlock(&hrrq->_lock);
6666 if (unlikely(!hrrq->allow_cmds)) {
6667 spin_unlock(&hrrq->_lock);
6668 return ATA_DEFER_LINK;
6671 ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
6672 if (ipr_cmd == NULL) {
6673 spin_unlock(&hrrq->_lock);
6674 return ATA_DEFER_LINK;
6677 qc->lldd_task = ipr_cmd;
6678 spin_unlock(&hrrq->_lock);
6683 * ipr_qc_issue - Issue a SATA qc to a device
6684 * @qc: queued command
6689 static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
6691 struct ata_port *ap = qc->ap;
6692 struct ipr_sata_port *sata_port = ap->private_data;
6693 struct ipr_resource_entry *res = sata_port->res;
6694 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6695 struct ipr_cmnd *ipr_cmd;
6696 struct ipr_ioarcb *ioarcb;
6697 struct ipr_ioarcb_ata_regs *regs;
6699 if (qc->lldd_task == NULL)
6702 ipr_cmd = qc->lldd_task;
6703 if (ipr_cmd == NULL)
6704 return AC_ERR_SYSTEM;
6706 qc->lldd_task = NULL;
6707 spin_lock(&ipr_cmd->hrrq->_lock);
6708 if (unlikely(!ipr_cmd->hrrq->allow_cmds ||
6709 ipr_cmd->hrrq->ioa_is_dead)) {
6710 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6711 spin_unlock(&ipr_cmd->hrrq->_lock);
6712 return AC_ERR_SYSTEM;
6715 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
6716 ioarcb = &ipr_cmd->ioarcb;
6718 if (ioa_cfg->sis64) {
6719 regs = &ipr_cmd->i.ata_ioadl.regs;
6720 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
6722 regs = &ioarcb->u.add_data.u.regs;
6724 memset(regs, 0, sizeof(*regs));
6725 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
6727 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
6729 ipr_cmd->done = ipr_sata_done;
6730 ipr_cmd->ioarcb.res_handle = res->res_handle;
6731 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
6732 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6733 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
6734 ipr_cmd->dma_use_sg = qc->n_elem;
6737 ipr_build_ata_ioadl64(ipr_cmd, qc);
6739 ipr_build_ata_ioadl(ipr_cmd, qc);
6741 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
6742 ipr_copy_sata_tf(regs, &qc->tf);
6743 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
6744 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
6746 switch (qc->tf.protocol) {
6747 case ATA_PROT_NODATA:
6752 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6755 case ATAPI_PROT_PIO:
6756 case ATAPI_PROT_NODATA:
6757 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6760 case ATAPI_PROT_DMA:
6761 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6762 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6767 spin_unlock(&ipr_cmd->hrrq->_lock);
6768 return AC_ERR_INVALID;
6771 ipr_send_command(ipr_cmd);
6772 spin_unlock(&ipr_cmd->hrrq->_lock);
6778 * ipr_qc_fill_rtf - Read result TF
6779 * @qc: ATA queued command
6784 static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
6786 struct ipr_sata_port *sata_port = qc->ap->private_data;
6787 struct ipr_ioasa_gata *g = &sata_port->ioasa;
6788 struct ata_taskfile *tf = &qc->result_tf;
6790 tf->feature = g->error;
6791 tf->nsect = g->nsect;
6795 tf->device = g->device;
6796 tf->command = g->status;
6797 tf->hob_nsect = g->hob_nsect;
6798 tf->hob_lbal = g->hob_lbal;
6799 tf->hob_lbam = g->hob_lbam;
6800 tf->hob_lbah = g->hob_lbah;
6805 static struct ata_port_operations ipr_sata_ops = {
6806 .phy_reset = ipr_ata_phy_reset,
6807 .hardreset = ipr_sata_reset,
6808 .post_internal_cmd = ipr_ata_post_internal,
6809 .qc_prep = ata_noop_qc_prep,
6810 .qc_defer = ipr_qc_defer,
6811 .qc_issue = ipr_qc_issue,
6812 .qc_fill_rtf = ipr_qc_fill_rtf,
6813 .port_start = ata_sas_port_start,
6814 .port_stop = ata_sas_port_stop
6817 static struct ata_port_info sata_port_info = {
6818 .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA |
6820 .pio_mask = ATA_PIO4_ONLY,
6821 .mwdma_mask = ATA_MWDMA2,
6822 .udma_mask = ATA_UDMA6,
6823 .port_ops = &ipr_sata_ops
6826 #ifdef CONFIG_PPC_PSERIES
6827 static const u16 ipr_blocked_processors[] = {
6839 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
6840 * @ioa_cfg: ioa cfg struct
6842 * Adapters that use Gemstone revision < 3.1 do not work reliably on
6843 * certain pSeries hardware. This function determines if the given
6844 * adapter is in one of these confgurations or not.
6847 * 1 if adapter is not supported / 0 if adapter is supported
6849 static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
6853 if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
6854 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++) {
6855 if (pvr_version_is(ipr_blocked_processors[i]))
6862 #define ipr_invalid_adapter(ioa_cfg) 0
6866 * ipr_ioa_bringdown_done - IOA bring down completion.
6867 * @ipr_cmd: ipr command struct
6869 * This function processes the completion of an adapter bring down.
6870 * It wakes any reset sleepers.
6875 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
6877 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6881 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
6883 spin_unlock_irq(ioa_cfg->host->host_lock);
6884 scsi_unblock_requests(ioa_cfg->host);
6885 spin_lock_irq(ioa_cfg->host->host_lock);
6888 ioa_cfg->in_reset_reload = 0;
6889 ioa_cfg->reset_retries = 0;
6890 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
6891 spin_lock(&ioa_cfg->hrrq[i]._lock);
6892 ioa_cfg->hrrq[i].ioa_is_dead = 1;
6893 spin_unlock(&ioa_cfg->hrrq[i]._lock);
6897 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6898 wake_up_all(&ioa_cfg->reset_wait_q);
6901 return IPR_RC_JOB_RETURN;
6905 * ipr_ioa_reset_done - IOA reset completion.
6906 * @ipr_cmd: ipr command struct
6908 * This function processes the completion of an adapter reset.
6909 * It schedules any necessary mid-layer add/removes and
6910 * wakes any reset sleepers.
6915 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
6917 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6918 struct ipr_resource_entry *res;
6919 struct ipr_hostrcb *hostrcb, *temp;
6923 ioa_cfg->in_reset_reload = 0;
6924 for (j = 0; j < ioa_cfg->hrrq_num; j++) {
6925 spin_lock(&ioa_cfg->hrrq[j]._lock);
6926 ioa_cfg->hrrq[j].allow_cmds = 1;
6927 spin_unlock(&ioa_cfg->hrrq[j]._lock);
6930 ioa_cfg->reset_cmd = NULL;
6931 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
6933 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
6934 if (res->add_to_ml || res->del_from_ml) {
6939 schedule_work(&ioa_cfg->work_q);
6941 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
6942 list_del(&hostrcb->queue);
6943 if (i++ < IPR_NUM_LOG_HCAMS)
6944 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
6946 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
6949 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
6950 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
6952 ioa_cfg->reset_retries = 0;
6953 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6954 wake_up_all(&ioa_cfg->reset_wait_q);
6956 spin_unlock(ioa_cfg->host->host_lock);
6957 scsi_unblock_requests(ioa_cfg->host);
6958 spin_lock(ioa_cfg->host->host_lock);
6960 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
6961 scsi_block_requests(ioa_cfg->host);
6963 schedule_work(&ioa_cfg->work_q);
6965 return IPR_RC_JOB_RETURN;
6969 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
6970 * @supported_dev: supported device struct
6971 * @vpids: vendor product id struct
6976 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
6977 struct ipr_std_inq_vpids *vpids)
6979 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
6980 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
6981 supported_dev->num_records = 1;
6982 supported_dev->data_length =
6983 cpu_to_be16(sizeof(struct ipr_supported_device));
6984 supported_dev->reserved = 0;
6988 * ipr_set_supported_devs - Send Set Supported Devices for a device
6989 * @ipr_cmd: ipr command struct
6991 * This function sends a Set Supported Devices to the adapter
6994 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6996 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
6998 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6999 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
7000 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7001 struct ipr_resource_entry *res = ipr_cmd->u.res;
7003 ipr_cmd->job_step = ipr_ioa_reset_done;
7005 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
7006 if (!ipr_is_scsi_disk(res))
7009 ipr_cmd->u.res = res;
7010 ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
7012 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7013 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
7014 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7016 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
7017 ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
7018 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
7019 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
7021 ipr_init_ioadl(ipr_cmd,
7022 ioa_cfg->vpd_cbs_dma +
7023 offsetof(struct ipr_misc_cbs, supp_dev),
7024 sizeof(struct ipr_supported_device),
7025 IPR_IOADL_FLAGS_WRITE_LAST);
7027 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7028 IPR_SET_SUP_DEVICE_TIMEOUT);
7030 if (!ioa_cfg->sis64)
7031 ipr_cmd->job_step = ipr_set_supported_devs;
7033 return IPR_RC_JOB_RETURN;
7037 return IPR_RC_JOB_CONTINUE;
7041 * ipr_get_mode_page - Locate specified mode page
7042 * @mode_pages: mode page buffer
7043 * @page_code: page code to find
7044 * @len: minimum required length for mode page
7047 * pointer to mode page / NULL on failure
7049 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
7050 u32 page_code, u32 len)
7052 struct ipr_mode_page_hdr *mode_hdr;
7056 if (!mode_pages || (mode_pages->hdr.length == 0))
7059 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
7060 mode_hdr = (struct ipr_mode_page_hdr *)
7061 (mode_pages->data + mode_pages->hdr.block_desc_len);
7064 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
7065 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
7069 page_length = (sizeof(struct ipr_mode_page_hdr) +
7070 mode_hdr->page_length);
7071 length -= page_length;
7072 mode_hdr = (struct ipr_mode_page_hdr *)
7073 ((unsigned long)mode_hdr + page_length);
7080 * ipr_check_term_power - Check for term power errors
7081 * @ioa_cfg: ioa config struct
7082 * @mode_pages: IOAFP mode pages buffer
7084 * Check the IOAFP's mode page 28 for term power errors
7089 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
7090 struct ipr_mode_pages *mode_pages)
7094 struct ipr_dev_bus_entry *bus;
7095 struct ipr_mode_page28 *mode_page;
7097 mode_page = ipr_get_mode_page(mode_pages, 0x28,
7098 sizeof(struct ipr_mode_page28));
7100 entry_length = mode_page->entry_length;
7102 bus = mode_page->bus;
7104 for (i = 0; i < mode_page->num_entries; i++) {
7105 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
7106 dev_err(&ioa_cfg->pdev->dev,
7107 "Term power is absent on scsi bus %d\n",
7111 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
7116 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
7117 * @ioa_cfg: ioa config struct
7119 * Looks through the config table checking for SES devices. If
7120 * the SES device is in the SES table indicating a maximum SCSI
7121 * bus speed, the speed is limited for the bus.
7126 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
7131 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
7132 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
7133 ioa_cfg->bus_attr[i].bus_width);
7135 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
7136 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
7141 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
7142 * @ioa_cfg: ioa config struct
7143 * @mode_pages: mode page 28 buffer
7145 * Updates mode page 28 based on driver configuration
7150 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
7151 struct ipr_mode_pages *mode_pages)
7153 int i, entry_length;
7154 struct ipr_dev_bus_entry *bus;
7155 struct ipr_bus_attributes *bus_attr;
7156 struct ipr_mode_page28 *mode_page;
7158 mode_page = ipr_get_mode_page(mode_pages, 0x28,
7159 sizeof(struct ipr_mode_page28));
7161 entry_length = mode_page->entry_length;
7163 /* Loop for each device bus entry */
7164 for (i = 0, bus = mode_page->bus;
7165 i < mode_page->num_entries;
7166 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
7167 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
7168 dev_err(&ioa_cfg->pdev->dev,
7169 "Invalid resource address reported: 0x%08X\n",
7170 IPR_GET_PHYS_LOC(bus->res_addr));
7174 bus_attr = &ioa_cfg->bus_attr[i];
7175 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
7176 bus->bus_width = bus_attr->bus_width;
7177 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
7178 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
7179 if (bus_attr->qas_enabled)
7180 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
7182 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
7187 * ipr_build_mode_select - Build a mode select command
7188 * @ipr_cmd: ipr command struct
7189 * @res_handle: resource handle to send command to
7190 * @parm: Byte 2 of Mode Sense command
7191 * @dma_addr: DMA buffer address
7192 * @xfer_len: data transfer length
7197 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
7198 __be32 res_handle, u8 parm,
7199 dma_addr_t dma_addr, u8 xfer_len)
7201 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7203 ioarcb->res_handle = res_handle;
7204 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7205 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
7206 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
7207 ioarcb->cmd_pkt.cdb[1] = parm;
7208 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7210 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
7214 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
7215 * @ipr_cmd: ipr command struct
7217 * This function sets up the SCSI bus attributes and sends
7218 * a Mode Select for Page 28 to activate them.
7223 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
7225 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7226 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
7230 ipr_scsi_bus_speed_limit(ioa_cfg);
7231 ipr_check_term_power(ioa_cfg, mode_pages);
7232 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
7233 length = mode_pages->hdr.length + 1;
7234 mode_pages->hdr.length = 0;
7236 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
7237 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
7240 ipr_cmd->job_step = ipr_set_supported_devs;
7241 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
7242 struct ipr_resource_entry, queue);
7243 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7246 return IPR_RC_JOB_RETURN;
7250 * ipr_build_mode_sense - Builds a mode sense command
7251 * @ipr_cmd: ipr command struct
7252 * @res: resource entry struct
7253 * @parm: Byte 2 of mode sense command
7254 * @dma_addr: DMA address of mode sense buffer
7255 * @xfer_len: Size of DMA buffer
7260 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
7262 u8 parm, dma_addr_t dma_addr, u8 xfer_len)
7264 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7266 ioarcb->res_handle = res_handle;
7267 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
7268 ioarcb->cmd_pkt.cdb[2] = parm;
7269 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7270 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7272 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
7276 * ipr_reset_cmd_failed - Handle failure of IOA reset command
7277 * @ipr_cmd: ipr command struct
7279 * This function handles the failure of an IOA bringup command.
7284 static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
7286 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7287 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
7289 dev_err(&ioa_cfg->pdev->dev,
7290 "0x%02X failed with IOASC: 0x%08X\n",
7291 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
7293 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7294 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
7295 return IPR_RC_JOB_RETURN;
7299 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
7300 * @ipr_cmd: ipr command struct
7302 * This function handles the failure of a Mode Sense to the IOAFP.
7303 * Some adapters do not handle all mode pages.
7306 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7308 static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
7310 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7311 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
7313 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
7314 ipr_cmd->job_step = ipr_set_supported_devs;
7315 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
7316 struct ipr_resource_entry, queue);
7317 return IPR_RC_JOB_CONTINUE;
7320 return ipr_reset_cmd_failed(ipr_cmd);
7324 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
7325 * @ipr_cmd: ipr command struct
7327 * This function send a Page 28 mode sense to the IOA to
7328 * retrieve SCSI bus attributes.
7333 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
7335 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7338 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
7339 0x28, ioa_cfg->vpd_cbs_dma +
7340 offsetof(struct ipr_misc_cbs, mode_pages),
7341 sizeof(struct ipr_mode_pages));
7343 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
7344 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
7346 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7349 return IPR_RC_JOB_RETURN;
7353 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
7354 * @ipr_cmd: ipr command struct
7356 * This function enables dual IOA RAID support if possible.
7361 static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
7363 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7364 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
7365 struct ipr_mode_page24 *mode_page;
7369 mode_page = ipr_get_mode_page(mode_pages, 0x24,
7370 sizeof(struct ipr_mode_page24));
7373 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
7375 length = mode_pages->hdr.length + 1;
7376 mode_pages->hdr.length = 0;
7378 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
7379 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
7382 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7383 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7386 return IPR_RC_JOB_RETURN;
7390 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
7391 * @ipr_cmd: ipr command struct
7393 * This function handles the failure of a Mode Sense to the IOAFP.
7394 * Some adapters do not handle all mode pages.
7397 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7399 static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
7401 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
7403 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
7404 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7405 return IPR_RC_JOB_CONTINUE;
7408 return ipr_reset_cmd_failed(ipr_cmd);
7412 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
7413 * @ipr_cmd: ipr command struct
7415 * This function send a mode sense to the IOA to retrieve
7416 * the IOA Advanced Function Control mode page.
7421 static int ipr_ioafp_mode_sense_page24(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 0x24, 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_page24;
7432 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
7434 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7437 return IPR_RC_JOB_RETURN;
7441 * ipr_init_res_table - Initialize the resource table
7442 * @ipr_cmd: ipr command struct
7444 * This function looks through the existing resource table, comparing
7445 * it with the config table. This function will take care of old/new
7446 * devices and schedule adding/removing them from the mid-layer
7450 * IPR_RC_JOB_CONTINUE
7452 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
7454 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7455 struct ipr_resource_entry *res, *temp;
7456 struct ipr_config_table_entry_wrapper cfgtew;
7457 int entries, found, flag, i;
7462 flag = ioa_cfg->u.cfg_table64->hdr64.flags;
7464 flag = ioa_cfg->u.cfg_table->hdr.flags;
7466 if (flag & IPR_UCODE_DOWNLOAD_REQ)
7467 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
7469 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
7470 list_move_tail(&res->queue, &old_res);
7473 entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
7475 entries = ioa_cfg->u.cfg_table->hdr.num_entries;
7477 for (i = 0; i < entries; i++) {
7479 cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
7481 cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
7484 list_for_each_entry_safe(res, temp, &old_res, queue) {
7485 if (ipr_is_same_device(res, &cfgtew)) {
7486 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7493 if (list_empty(&ioa_cfg->free_res_q)) {
7494 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
7499 res = list_entry(ioa_cfg->free_res_q.next,
7500 struct ipr_resource_entry, queue);
7501 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7502 ipr_init_res_entry(res, &cfgtew);
7504 } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
7505 res->sdev->allow_restart = 1;
7508 ipr_update_res_entry(res, &cfgtew);
7511 list_for_each_entry_safe(res, temp, &old_res, queue) {
7513 res->del_from_ml = 1;
7514 res->res_handle = IPR_INVALID_RES_HANDLE;
7515 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7519 list_for_each_entry_safe(res, temp, &old_res, queue) {
7520 ipr_clear_res_target(res);
7521 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
7524 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
7525 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
7527 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7530 return IPR_RC_JOB_CONTINUE;
7534 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
7535 * @ipr_cmd: ipr command struct
7537 * This function sends a Query IOA Configuration command
7538 * to the adapter to retrieve the IOA configuration table.
7543 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
7545 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7546 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7547 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
7548 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7551 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
7552 ioa_cfg->dual_raid = 1;
7553 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
7554 ucode_vpd->major_release, ucode_vpd->card_type,
7555 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
7556 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7557 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7559 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
7560 ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
7561 ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
7562 ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
7564 ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
7565 IPR_IOADL_FLAGS_READ_LAST);
7567 ipr_cmd->job_step = ipr_init_res_table;
7569 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7572 return IPR_RC_JOB_RETURN;
7576 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
7577 * @ipr_cmd: ipr command struct
7579 * This utility function sends an inquiry to the adapter.
7584 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
7585 dma_addr_t dma_addr, u8 xfer_len)
7587 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7590 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7591 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7593 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
7594 ioarcb->cmd_pkt.cdb[1] = flags;
7595 ioarcb->cmd_pkt.cdb[2] = page;
7596 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7598 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
7600 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7605 * ipr_inquiry_page_supported - Is the given inquiry page supported
7606 * @page0: inquiry page 0 buffer
7609 * This function determines if the specified inquiry page is supported.
7612 * 1 if page is supported / 0 if not
7614 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
7618 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
7619 if (page0->page[i] == page)
7626 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
7627 * @ipr_cmd: ipr command struct
7629 * This function sends a Page 0xD0 inquiry to the adapter
7630 * to retrieve adapter capabilities.
7633 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7635 static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
7637 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7638 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
7639 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7642 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
7643 memset(cap, 0, sizeof(*cap));
7645 if (ipr_inquiry_page_supported(page0, 0xD0)) {
7646 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
7647 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
7648 sizeof(struct ipr_inquiry_cap));
7649 return IPR_RC_JOB_RETURN;
7653 return IPR_RC_JOB_CONTINUE;
7657 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
7658 * @ipr_cmd: ipr command struct
7660 * This function sends a Page 3 inquiry to the adapter
7661 * to retrieve software VPD information.
7664 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7666 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
7668 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7672 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
7674 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
7675 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
7676 sizeof(struct ipr_inquiry_page3));
7679 return IPR_RC_JOB_RETURN;
7683 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
7684 * @ipr_cmd: ipr command struct
7686 * This function sends a Page 0 inquiry to the adapter
7687 * to retrieve supported inquiry pages.
7690 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7692 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
7694 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7699 /* Grab the type out of the VPD and store it away */
7700 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
7702 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
7704 if (ipr_invalid_adapter(ioa_cfg)) {
7705 dev_err(&ioa_cfg->pdev->dev,
7706 "Adapter not supported in this hardware configuration.\n");
7708 if (!ipr_testmode) {
7709 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
7710 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7711 list_add_tail(&ipr_cmd->queue,
7712 &ioa_cfg->hrrq->hrrq_free_q);
7713 return IPR_RC_JOB_RETURN;
7717 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
7719 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
7720 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
7721 sizeof(struct ipr_inquiry_page0));
7724 return IPR_RC_JOB_RETURN;
7728 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
7729 * @ipr_cmd: ipr command struct
7731 * This function sends a standard inquiry to the adapter.
7736 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
7738 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7741 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
7743 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
7744 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
7745 sizeof(struct ipr_ioa_vpd));
7748 return IPR_RC_JOB_RETURN;
7752 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
7753 * @ipr_cmd: ipr command struct
7755 * This function send an Identify Host Request Response Queue
7756 * command to establish the HRRQ with the adapter.
7761 static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
7763 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7764 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7765 struct ipr_hrr_queue *hrrq;
7768 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
7769 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
7771 if (ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num) {
7772 hrrq = &ioa_cfg->hrrq[ioa_cfg->identify_hrrq_index];
7774 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
7775 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7777 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7779 ioarcb->cmd_pkt.cdb[1] = 0x1;
7781 if (ioa_cfg->nvectors == 1)
7782 ioarcb->cmd_pkt.cdb[1] &= ~IPR_ID_HRRQ_SELE_ENABLE;
7784 ioarcb->cmd_pkt.cdb[1] |= IPR_ID_HRRQ_SELE_ENABLE;
7786 ioarcb->cmd_pkt.cdb[2] =
7787 ((u64) hrrq->host_rrq_dma >> 24) & 0xff;
7788 ioarcb->cmd_pkt.cdb[3] =
7789 ((u64) hrrq->host_rrq_dma >> 16) & 0xff;
7790 ioarcb->cmd_pkt.cdb[4] =
7791 ((u64) hrrq->host_rrq_dma >> 8) & 0xff;
7792 ioarcb->cmd_pkt.cdb[5] =
7793 ((u64) hrrq->host_rrq_dma) & 0xff;
7794 ioarcb->cmd_pkt.cdb[7] =
7795 ((sizeof(u32) * hrrq->size) >> 8) & 0xff;
7796 ioarcb->cmd_pkt.cdb[8] =
7797 (sizeof(u32) * hrrq->size) & 0xff;
7799 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
7800 ioarcb->cmd_pkt.cdb[9] =
7801 ioa_cfg->identify_hrrq_index;
7803 if (ioa_cfg->sis64) {
7804 ioarcb->cmd_pkt.cdb[10] =
7805 ((u64) hrrq->host_rrq_dma >> 56) & 0xff;
7806 ioarcb->cmd_pkt.cdb[11] =
7807 ((u64) hrrq->host_rrq_dma >> 48) & 0xff;
7808 ioarcb->cmd_pkt.cdb[12] =
7809 ((u64) hrrq->host_rrq_dma >> 40) & 0xff;
7810 ioarcb->cmd_pkt.cdb[13] =
7811 ((u64) hrrq->host_rrq_dma >> 32) & 0xff;
7814 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
7815 ioarcb->cmd_pkt.cdb[14] =
7816 ioa_cfg->identify_hrrq_index;
7818 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7819 IPR_INTERNAL_TIMEOUT);
7821 if (++ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num)
7822 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7825 return IPR_RC_JOB_RETURN;
7829 return IPR_RC_JOB_CONTINUE;
7833 * ipr_reset_timer_done - Adapter reset timer function
7834 * @ipr_cmd: ipr command struct
7836 * Description: This function is used in adapter reset processing
7837 * for timing events. If the reset_cmd pointer in the IOA
7838 * config struct is not this adapter's we are doing nested
7839 * resets and fail_all_ops will take care of freeing the
7845 static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
7847 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7848 unsigned long lock_flags = 0;
7850 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7852 if (ioa_cfg->reset_cmd == ipr_cmd) {
7853 list_del(&ipr_cmd->queue);
7854 ipr_cmd->done(ipr_cmd);
7857 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7861 * ipr_reset_start_timer - Start a timer for adapter reset job
7862 * @ipr_cmd: ipr command struct
7863 * @timeout: timeout value
7865 * Description: This function is used in adapter reset processing
7866 * for timing events. If the reset_cmd pointer in the IOA
7867 * config struct is not this adapter's we are doing nested
7868 * resets and fail_all_ops will take care of freeing the
7874 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
7875 unsigned long timeout)
7879 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
7880 ipr_cmd->done = ipr_reset_ioa_job;
7882 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7883 ipr_cmd->timer.expires = jiffies + timeout;
7884 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
7885 add_timer(&ipr_cmd->timer);
7889 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7890 * @ioa_cfg: ioa cfg struct
7895 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
7897 struct ipr_hrr_queue *hrrq;
7899 for_each_hrrq(hrrq, ioa_cfg) {
7900 spin_lock(&hrrq->_lock);
7901 memset(hrrq->host_rrq, 0, sizeof(u32) * hrrq->size);
7903 /* Initialize Host RRQ pointers */
7904 hrrq->hrrq_start = hrrq->host_rrq;
7905 hrrq->hrrq_end = &hrrq->host_rrq[hrrq->size - 1];
7906 hrrq->hrrq_curr = hrrq->hrrq_start;
7907 hrrq->toggle_bit = 1;
7908 spin_unlock(&hrrq->_lock);
7912 ioa_cfg->identify_hrrq_index = 0;
7913 if (ioa_cfg->hrrq_num == 1)
7914 atomic_set(&ioa_cfg->hrrq_index, 0);
7916 atomic_set(&ioa_cfg->hrrq_index, 1);
7918 /* Zero out config table */
7919 memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
7923 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
7924 * @ipr_cmd: ipr command struct
7927 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7929 static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
7931 unsigned long stage, stage_time;
7933 volatile u32 int_reg;
7934 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7937 feedback = readl(ioa_cfg->regs.init_feedback_reg);
7938 stage = feedback & IPR_IPL_INIT_STAGE_MASK;
7939 stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
7941 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
7943 /* sanity check the stage_time value */
7944 if (stage_time == 0)
7945 stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
7946 else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
7947 stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
7948 else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
7949 stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
7951 if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
7952 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
7953 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7954 stage_time = ioa_cfg->transop_timeout;
7955 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7956 } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
7957 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
7958 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7959 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7960 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7961 maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
7962 writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
7963 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7964 return IPR_RC_JOB_CONTINUE;
7968 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7969 ipr_cmd->timer.expires = jiffies + stage_time * HZ;
7970 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7971 ipr_cmd->done = ipr_reset_ioa_job;
7972 add_timer(&ipr_cmd->timer);
7974 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
7976 return IPR_RC_JOB_RETURN;
7980 * ipr_reset_enable_ioa - Enable the IOA following a reset.
7981 * @ipr_cmd: ipr command struct
7983 * This function reinitializes some control blocks and
7984 * enables destructive diagnostics on the adapter.
7989 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
7991 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7992 volatile u32 int_reg;
7993 volatile u64 maskval;
7997 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7998 ipr_init_ioa_mem(ioa_cfg);
8000 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8001 spin_lock(&ioa_cfg->hrrq[i]._lock);
8002 ioa_cfg->hrrq[i].allow_interrupts = 1;
8003 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8006 if (ioa_cfg->sis64) {
8007 /* Set the adapter to the correct endian mode. */
8008 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
8009 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
8012 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
8014 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
8015 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
8016 ioa_cfg->regs.clr_interrupt_mask_reg32);
8017 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8018 return IPR_RC_JOB_CONTINUE;
8021 /* Enable destructive diagnostics on IOA */
8022 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
8024 if (ioa_cfg->sis64) {
8025 maskval = IPR_PCII_IPL_STAGE_CHANGE;
8026 maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
8027 writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
8029 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
8031 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8033 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
8035 if (ioa_cfg->sis64) {
8036 ipr_cmd->job_step = ipr_reset_next_stage;
8037 return IPR_RC_JOB_CONTINUE;
8040 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
8041 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
8042 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
8043 ipr_cmd->done = ipr_reset_ioa_job;
8044 add_timer(&ipr_cmd->timer);
8045 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
8048 return IPR_RC_JOB_RETURN;
8052 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
8053 * @ipr_cmd: ipr command struct
8055 * This function is invoked when an adapter dump has run out
8056 * of processing time.
8059 * IPR_RC_JOB_CONTINUE
8061 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
8063 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8065 if (ioa_cfg->sdt_state == GET_DUMP)
8066 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8067 else if (ioa_cfg->sdt_state == READ_DUMP)
8068 ioa_cfg->sdt_state = ABORT_DUMP;
8070 ioa_cfg->dump_timeout = 1;
8071 ipr_cmd->job_step = ipr_reset_alert;
8073 return IPR_RC_JOB_CONTINUE;
8077 * ipr_unit_check_no_data - Log a unit check/no data error log
8078 * @ioa_cfg: ioa config struct
8080 * Logs an error indicating the adapter unit checked, but for some
8081 * reason, we were unable to fetch the unit check buffer.
8086 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
8088 ioa_cfg->errors_logged++;
8089 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
8093 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
8094 * @ioa_cfg: ioa config struct
8096 * Fetches the unit check buffer from the adapter by clocking the data
8097 * through the mailbox register.
8102 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
8104 unsigned long mailbox;
8105 struct ipr_hostrcb *hostrcb;
8106 struct ipr_uc_sdt sdt;
8110 mailbox = readl(ioa_cfg->ioa_mailbox);
8112 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
8113 ipr_unit_check_no_data(ioa_cfg);
8117 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
8118 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
8119 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
8121 if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
8122 ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
8123 (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
8124 ipr_unit_check_no_data(ioa_cfg);
8128 /* Find length of the first sdt entry (UC buffer) */
8129 if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
8130 length = be32_to_cpu(sdt.entry[0].end_token);
8132 length = (be32_to_cpu(sdt.entry[0].end_token) -
8133 be32_to_cpu(sdt.entry[0].start_token)) &
8134 IPR_FMT2_MBX_ADDR_MASK;
8136 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
8137 struct ipr_hostrcb, queue);
8138 list_del(&hostrcb->queue);
8139 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
8141 rc = ipr_get_ldump_data_section(ioa_cfg,
8142 be32_to_cpu(sdt.entry[0].start_token),
8143 (__be32 *)&hostrcb->hcam,
8144 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
8147 ipr_handle_log_data(ioa_cfg, hostrcb);
8148 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
8149 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
8150 ioa_cfg->sdt_state == GET_DUMP)
8151 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8153 ipr_unit_check_no_data(ioa_cfg);
8155 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
8159 * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
8160 * @ipr_cmd: ipr command struct
8162 * Description: This function will call to get the unit check buffer.
8167 static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
8169 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8172 ioa_cfg->ioa_unit_checked = 0;
8173 ipr_get_unit_check_buffer(ioa_cfg);
8174 ipr_cmd->job_step = ipr_reset_alert;
8175 ipr_reset_start_timer(ipr_cmd, 0);
8178 return IPR_RC_JOB_RETURN;
8182 * ipr_reset_restore_cfg_space - Restore PCI config space.
8183 * @ipr_cmd: ipr command struct
8185 * Description: This function restores the saved PCI config space of
8186 * the adapter, fails all outstanding ops back to the callers, and
8187 * fetches the dump/unit check if applicable to this reset.
8190 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8192 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
8194 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8198 ioa_cfg->pdev->state_saved = true;
8199 pci_restore_state(ioa_cfg->pdev);
8201 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
8202 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
8203 return IPR_RC_JOB_CONTINUE;
8206 ipr_fail_all_ops(ioa_cfg);
8208 if (ioa_cfg->sis64) {
8209 /* Set the adapter to the correct endian mode. */
8210 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
8211 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
8214 if (ioa_cfg->ioa_unit_checked) {
8215 if (ioa_cfg->sis64) {
8216 ipr_cmd->job_step = ipr_reset_get_unit_check_job;
8217 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
8218 return IPR_RC_JOB_RETURN;
8220 ioa_cfg->ioa_unit_checked = 0;
8221 ipr_get_unit_check_buffer(ioa_cfg);
8222 ipr_cmd->job_step = ipr_reset_alert;
8223 ipr_reset_start_timer(ipr_cmd, 0);
8224 return IPR_RC_JOB_RETURN;
8228 if (ioa_cfg->in_ioa_bringdown) {
8229 ipr_cmd->job_step = ipr_ioa_bringdown_done;
8231 ipr_cmd->job_step = ipr_reset_enable_ioa;
8233 if (GET_DUMP == ioa_cfg->sdt_state) {
8234 ioa_cfg->sdt_state = READ_DUMP;
8235 ioa_cfg->dump_timeout = 0;
8237 ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
8239 ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
8240 ipr_cmd->job_step = ipr_reset_wait_for_dump;
8241 schedule_work(&ioa_cfg->work_q);
8242 return IPR_RC_JOB_RETURN;
8247 return IPR_RC_JOB_CONTINUE;
8251 * ipr_reset_bist_done - BIST has completed on the adapter.
8252 * @ipr_cmd: ipr command struct
8254 * Description: Unblock config space and resume the reset process.
8257 * IPR_RC_JOB_CONTINUE
8259 static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
8261 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8264 if (ioa_cfg->cfg_locked)
8265 pci_cfg_access_unlock(ioa_cfg->pdev);
8266 ioa_cfg->cfg_locked = 0;
8267 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
8269 return IPR_RC_JOB_CONTINUE;
8273 * ipr_reset_start_bist - Run BIST on the adapter.
8274 * @ipr_cmd: ipr command struct
8276 * Description: This function runs BIST on the adapter, then delays 2 seconds.
8279 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8281 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
8283 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8284 int rc = PCIBIOS_SUCCESSFUL;
8287 if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
8288 writel(IPR_UPROCI_SIS64_START_BIST,
8289 ioa_cfg->regs.set_uproc_interrupt_reg32);
8291 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
8293 if (rc == PCIBIOS_SUCCESSFUL) {
8294 ipr_cmd->job_step = ipr_reset_bist_done;
8295 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
8296 rc = IPR_RC_JOB_RETURN;
8298 if (ioa_cfg->cfg_locked)
8299 pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
8300 ioa_cfg->cfg_locked = 0;
8301 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
8302 rc = IPR_RC_JOB_CONTINUE;
8310 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
8311 * @ipr_cmd: ipr command struct
8313 * Description: This clears PCI reset to the adapter and delays two seconds.
8318 static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
8321 pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
8322 ipr_cmd->job_step = ipr_reset_bist_done;
8323 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
8325 return IPR_RC_JOB_RETURN;
8329 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
8330 * @ipr_cmd: ipr command struct
8332 * Description: This asserts PCI reset to the adapter.
8337 static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
8339 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8340 struct pci_dev *pdev = ioa_cfg->pdev;
8343 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
8344 ipr_cmd->job_step = ipr_reset_slot_reset_done;
8345 ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
8347 return IPR_RC_JOB_RETURN;
8351 * ipr_reset_block_config_access_wait - Wait for permission to block config access
8352 * @ipr_cmd: ipr command struct
8354 * Description: This attempts to block config access to the IOA.
8357 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8359 static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
8361 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8362 int rc = IPR_RC_JOB_CONTINUE;
8364 if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
8365 ioa_cfg->cfg_locked = 1;
8366 ipr_cmd->job_step = ioa_cfg->reset;
8368 if (ipr_cmd->u.time_left) {
8369 rc = IPR_RC_JOB_RETURN;
8370 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8371 ipr_reset_start_timer(ipr_cmd,
8372 IPR_CHECK_FOR_RESET_TIMEOUT);
8374 ipr_cmd->job_step = ioa_cfg->reset;
8375 dev_err(&ioa_cfg->pdev->dev,
8376 "Timed out waiting to lock config access. Resetting anyway.\n");
8384 * ipr_reset_block_config_access - Block config access to the IOA
8385 * @ipr_cmd: ipr command struct
8387 * Description: This attempts to block config access to the IOA
8390 * IPR_RC_JOB_CONTINUE
8392 static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
8394 ipr_cmd->ioa_cfg->cfg_locked = 0;
8395 ipr_cmd->job_step = ipr_reset_block_config_access_wait;
8396 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8397 return IPR_RC_JOB_CONTINUE;
8401 * ipr_reset_allowed - Query whether or not IOA can be reset
8402 * @ioa_cfg: ioa config struct
8405 * 0 if reset not allowed / non-zero if reset is allowed
8407 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
8409 volatile u32 temp_reg;
8411 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
8412 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
8416 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
8417 * @ipr_cmd: ipr command struct
8419 * Description: This function waits for adapter permission to run BIST,
8420 * then runs BIST. If the adapter does not give permission after a
8421 * reasonable time, we will reset the adapter anyway. The impact of
8422 * resetting the adapter without warning the adapter is the risk of
8423 * losing the persistent error log on the adapter. If the adapter is
8424 * reset while it is writing to the flash on the adapter, the flash
8425 * segment will have bad ECC and be zeroed.
8428 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8430 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
8432 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8433 int rc = IPR_RC_JOB_RETURN;
8435 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
8436 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8437 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8439 ipr_cmd->job_step = ipr_reset_block_config_access;
8440 rc = IPR_RC_JOB_CONTINUE;
8447 * ipr_reset_alert - Alert the adapter of a pending reset
8448 * @ipr_cmd: ipr command struct
8450 * Description: This function alerts the adapter that it will be reset.
8451 * If memory space is not currently enabled, proceed directly
8452 * to running BIST on the adapter. The timer must always be started
8453 * so we guarantee we do not run BIST from ipr_isr.
8458 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
8460 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8465 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
8467 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
8468 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
8469 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
8470 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
8472 ipr_cmd->job_step = ipr_reset_block_config_access;
8475 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8476 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8479 return IPR_RC_JOB_RETURN;
8483 * ipr_reset_ucode_download_done - Microcode download completion
8484 * @ipr_cmd: ipr command struct
8486 * Description: This function unmaps the microcode download buffer.
8489 * IPR_RC_JOB_CONTINUE
8491 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
8493 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8494 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8496 dma_unmap_sg(&ioa_cfg->pdev->dev, sglist->scatterlist,
8497 sglist->num_sg, DMA_TO_DEVICE);
8499 ipr_cmd->job_step = ipr_reset_alert;
8500 return IPR_RC_JOB_CONTINUE;
8504 * ipr_reset_ucode_download - Download microcode to the adapter
8505 * @ipr_cmd: ipr command struct
8507 * Description: This function checks to see if it there is microcode
8508 * to download to the adapter. If there is, a download is performed.
8511 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8513 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
8515 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8516 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8519 ipr_cmd->job_step = ipr_reset_alert;
8522 return IPR_RC_JOB_CONTINUE;
8524 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8525 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
8526 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
8527 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
8528 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
8529 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
8530 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
8533 ipr_build_ucode_ioadl64(ipr_cmd, sglist);
8535 ipr_build_ucode_ioadl(ipr_cmd, sglist);
8536 ipr_cmd->job_step = ipr_reset_ucode_download_done;
8538 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
8539 IPR_WRITE_BUFFER_TIMEOUT);
8542 return IPR_RC_JOB_RETURN;
8546 * ipr_reset_shutdown_ioa - Shutdown the adapter
8547 * @ipr_cmd: ipr command struct
8549 * Description: This function issues an adapter shutdown of the
8550 * specified type to the specified adapter as part of the
8551 * adapter reset job.
8554 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8556 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
8558 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8559 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
8560 unsigned long timeout;
8561 int rc = IPR_RC_JOB_CONTINUE;
8564 if (shutdown_type != IPR_SHUTDOWN_NONE &&
8565 !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
8566 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8567 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8568 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
8569 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
8571 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
8572 timeout = IPR_SHUTDOWN_TIMEOUT;
8573 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
8574 timeout = IPR_INTERNAL_TIMEOUT;
8575 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
8576 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
8578 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
8580 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
8582 rc = IPR_RC_JOB_RETURN;
8583 ipr_cmd->job_step = ipr_reset_ucode_download;
8585 ipr_cmd->job_step = ipr_reset_alert;
8592 * ipr_reset_ioa_job - Adapter reset job
8593 * @ipr_cmd: ipr command struct
8595 * Description: This function is the job router for the adapter reset job.
8600 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
8603 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8606 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
8608 if (ioa_cfg->reset_cmd != ipr_cmd) {
8610 * We are doing nested adapter resets and this is
8611 * not the current reset job.
8613 list_add_tail(&ipr_cmd->queue,
8614 &ipr_cmd->hrrq->hrrq_free_q);
8618 if (IPR_IOASC_SENSE_KEY(ioasc)) {
8619 rc = ipr_cmd->job_step_failed(ipr_cmd);
8620 if (rc == IPR_RC_JOB_RETURN)
8624 ipr_reinit_ipr_cmnd(ipr_cmd);
8625 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
8626 rc = ipr_cmd->job_step(ipr_cmd);
8627 } while (rc == IPR_RC_JOB_CONTINUE);
8631 * _ipr_initiate_ioa_reset - Initiate an adapter reset
8632 * @ioa_cfg: ioa config struct
8633 * @job_step: first job step of reset job
8634 * @shutdown_type: shutdown type
8636 * Description: This function will initiate the reset of the given adapter
8637 * starting at the selected job step.
8638 * If the caller needs to wait on the completion of the reset,
8639 * the caller must sleep on the reset_wait_q.
8644 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8645 int (*job_step) (struct ipr_cmnd *),
8646 enum ipr_shutdown_type shutdown_type)
8648 struct ipr_cmnd *ipr_cmd;
8651 ioa_cfg->in_reset_reload = 1;
8652 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8653 spin_lock(&ioa_cfg->hrrq[i]._lock);
8654 ioa_cfg->hrrq[i].allow_cmds = 0;
8655 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8658 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa)
8659 scsi_block_requests(ioa_cfg->host);
8661 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
8662 ioa_cfg->reset_cmd = ipr_cmd;
8663 ipr_cmd->job_step = job_step;
8664 ipr_cmd->u.shutdown_type = shutdown_type;
8666 ipr_reset_ioa_job(ipr_cmd);
8670 * ipr_initiate_ioa_reset - Initiate an adapter reset
8671 * @ioa_cfg: ioa config struct
8672 * @shutdown_type: shutdown type
8674 * Description: This function will initiate the reset of the given adapter.
8675 * If the caller needs to wait on the completion of the reset,
8676 * the caller must sleep on the reset_wait_q.
8681 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8682 enum ipr_shutdown_type shutdown_type)
8686 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
8689 if (ioa_cfg->in_reset_reload) {
8690 if (ioa_cfg->sdt_state == GET_DUMP)
8691 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8692 else if (ioa_cfg->sdt_state == READ_DUMP)
8693 ioa_cfg->sdt_state = ABORT_DUMP;
8696 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
8697 dev_err(&ioa_cfg->pdev->dev,
8698 "IOA taken offline - error recovery failed\n");
8700 ioa_cfg->reset_retries = 0;
8701 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8702 spin_lock(&ioa_cfg->hrrq[i]._lock);
8703 ioa_cfg->hrrq[i].ioa_is_dead = 1;
8704 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8708 if (ioa_cfg->in_ioa_bringdown) {
8709 ioa_cfg->reset_cmd = NULL;
8710 ioa_cfg->in_reset_reload = 0;
8711 ipr_fail_all_ops(ioa_cfg);
8712 wake_up_all(&ioa_cfg->reset_wait_q);
8714 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
8715 spin_unlock_irq(ioa_cfg->host->host_lock);
8716 scsi_unblock_requests(ioa_cfg->host);
8717 spin_lock_irq(ioa_cfg->host->host_lock);
8721 ioa_cfg->in_ioa_bringdown = 1;
8722 shutdown_type = IPR_SHUTDOWN_NONE;
8726 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
8731 * ipr_reset_freeze - Hold off all I/O activity
8732 * @ipr_cmd: ipr command struct
8734 * Description: If the PCI slot is frozen, hold off all I/O
8735 * activity; then, as soon as the slot is available again,
8736 * initiate an adapter reset.
8738 static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
8740 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8743 /* Disallow new interrupts, avoid loop */
8744 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8745 spin_lock(&ioa_cfg->hrrq[i]._lock);
8746 ioa_cfg->hrrq[i].allow_interrupts = 0;
8747 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8750 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
8751 ipr_cmd->done = ipr_reset_ioa_job;
8752 return IPR_RC_JOB_RETURN;
8756 * ipr_pci_mmio_enabled - Called when MMIO has been re-enabled
8757 * @pdev: PCI device struct
8759 * Description: This routine is called to tell us that the MMIO
8760 * access to the IOA has been restored
8762 static pci_ers_result_t ipr_pci_mmio_enabled(struct pci_dev *pdev)
8764 unsigned long flags = 0;
8765 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8767 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8768 if (!ioa_cfg->probe_done)
8769 pci_save_state(pdev);
8770 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8771 return PCI_ERS_RESULT_NEED_RESET;
8775 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
8776 * @pdev: PCI device struct
8778 * Description: This routine is called to tell us that the PCI bus
8779 * is down. Can't do anything here, except put the device driver
8780 * into a holding pattern, waiting for the PCI bus to come back.
8782 static void ipr_pci_frozen(struct pci_dev *pdev)
8784 unsigned long flags = 0;
8785 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8787 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8788 if (ioa_cfg->probe_done)
8789 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
8790 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8794 * ipr_pci_slot_reset - Called when PCI slot has been reset.
8795 * @pdev: PCI device struct
8797 * Description: This routine is called by the pci error recovery
8798 * code after the PCI slot has been reset, just before we
8799 * should resume normal operations.
8801 static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
8803 unsigned long flags = 0;
8804 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8806 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8807 if (ioa_cfg->probe_done) {
8808 if (ioa_cfg->needs_warm_reset)
8809 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8811 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
8814 wake_up_all(&ioa_cfg->eeh_wait_q);
8815 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8816 return PCI_ERS_RESULT_RECOVERED;
8820 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
8821 * @pdev: PCI device struct
8823 * Description: This routine is called when the PCI bus has
8824 * permanently failed.
8826 static void ipr_pci_perm_failure(struct pci_dev *pdev)
8828 unsigned long flags = 0;
8829 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8832 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8833 if (ioa_cfg->probe_done) {
8834 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
8835 ioa_cfg->sdt_state = ABORT_DUMP;
8836 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES - 1;
8837 ioa_cfg->in_ioa_bringdown = 1;
8838 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8839 spin_lock(&ioa_cfg->hrrq[i]._lock);
8840 ioa_cfg->hrrq[i].allow_cmds = 0;
8841 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8844 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8846 wake_up_all(&ioa_cfg->eeh_wait_q);
8847 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8851 * ipr_pci_error_detected - Called when a PCI error is detected.
8852 * @pdev: PCI device struct
8853 * @state: PCI channel state
8855 * Description: Called when a PCI error is detected.
8858 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8860 static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
8861 pci_channel_state_t state)
8864 case pci_channel_io_frozen:
8865 ipr_pci_frozen(pdev);
8866 return PCI_ERS_RESULT_CAN_RECOVER;
8867 case pci_channel_io_perm_failure:
8868 ipr_pci_perm_failure(pdev);
8869 return PCI_ERS_RESULT_DISCONNECT;
8874 return PCI_ERS_RESULT_NEED_RESET;
8878 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
8879 * @ioa_cfg: ioa cfg struct
8881 * Description: This is the second phase of adapter intialization
8882 * This function takes care of initilizing the adapter to the point
8883 * where it can accept new commands.
8886 * 0 on success / -EIO on failure
8888 static int ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
8891 unsigned long host_lock_flags = 0;
8894 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8895 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
8896 ioa_cfg->probe_done = 1;
8897 if (ioa_cfg->needs_hard_reset) {
8898 ioa_cfg->needs_hard_reset = 0;
8899 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8901 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
8903 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8910 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
8911 * @ioa_cfg: ioa config struct
8916 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8920 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8921 if (ioa_cfg->ipr_cmnd_list[i])
8922 dma_pool_free(ioa_cfg->ipr_cmd_pool,
8923 ioa_cfg->ipr_cmnd_list[i],
8924 ioa_cfg->ipr_cmnd_list_dma[i]);
8926 ioa_cfg->ipr_cmnd_list[i] = NULL;
8929 if (ioa_cfg->ipr_cmd_pool)
8930 dma_pool_destroy(ioa_cfg->ipr_cmd_pool);
8932 kfree(ioa_cfg->ipr_cmnd_list);
8933 kfree(ioa_cfg->ipr_cmnd_list_dma);
8934 ioa_cfg->ipr_cmnd_list = NULL;
8935 ioa_cfg->ipr_cmnd_list_dma = NULL;
8936 ioa_cfg->ipr_cmd_pool = NULL;
8940 * ipr_free_mem - Frees memory allocated for an adapter
8941 * @ioa_cfg: ioa cfg struct
8946 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
8950 kfree(ioa_cfg->res_entries);
8951 dma_free_coherent(&ioa_cfg->pdev->dev, sizeof(struct ipr_misc_cbs),
8952 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8953 ipr_free_cmd_blks(ioa_cfg);
8955 for (i = 0; i < ioa_cfg->hrrq_num; i++)
8956 dma_free_coherent(&ioa_cfg->pdev->dev,
8957 sizeof(u32) * ioa_cfg->hrrq[i].size,
8958 ioa_cfg->hrrq[i].host_rrq,
8959 ioa_cfg->hrrq[i].host_rrq_dma);
8961 dma_free_coherent(&ioa_cfg->pdev->dev, ioa_cfg->cfg_table_size,
8962 ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
8964 for (i = 0; i < IPR_NUM_HCAMS; i++) {
8965 dma_free_coherent(&ioa_cfg->pdev->dev,
8966 sizeof(struct ipr_hostrcb),
8967 ioa_cfg->hostrcb[i],
8968 ioa_cfg->hostrcb_dma[i]);
8971 ipr_free_dump(ioa_cfg);
8972 kfree(ioa_cfg->trace);
8976 * ipr_free_all_resources - Free all allocated resources for an adapter.
8977 * @ipr_cmd: ipr command struct
8979 * This function frees all allocated resources for the
8980 * specified adapter.
8985 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
8987 struct pci_dev *pdev = ioa_cfg->pdev;
8990 if (ioa_cfg->intr_flag == IPR_USE_MSI ||
8991 ioa_cfg->intr_flag == IPR_USE_MSIX) {
8993 for (i = 0; i < ioa_cfg->nvectors; i++)
8994 free_irq(ioa_cfg->vectors_info[i].vec,
8997 free_irq(pdev->irq, &ioa_cfg->hrrq[0]);
8999 if (ioa_cfg->intr_flag == IPR_USE_MSI) {
9000 pci_disable_msi(pdev);
9001 ioa_cfg->intr_flag &= ~IPR_USE_MSI;
9002 } else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
9003 pci_disable_msix(pdev);
9004 ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
9007 iounmap(ioa_cfg->hdw_dma_regs);
9008 pci_release_regions(pdev);
9009 ipr_free_mem(ioa_cfg);
9010 scsi_host_put(ioa_cfg->host);
9011 pci_disable_device(pdev);
9016 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
9017 * @ioa_cfg: ioa config struct
9020 * 0 on success / -ENOMEM on allocation failure
9022 static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
9024 struct ipr_cmnd *ipr_cmd;
9025 struct ipr_ioarcb *ioarcb;
9026 dma_addr_t dma_addr;
9027 int i, entries_each_hrrq, hrrq_id = 0;
9029 ioa_cfg->ipr_cmd_pool = dma_pool_create(IPR_NAME, &ioa_cfg->pdev->dev,
9030 sizeof(struct ipr_cmnd), 512, 0);
9032 if (!ioa_cfg->ipr_cmd_pool)
9035 ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
9036 ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
9038 if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
9039 ipr_free_cmd_blks(ioa_cfg);
9043 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9044 if (ioa_cfg->hrrq_num > 1) {
9046 entries_each_hrrq = IPR_NUM_INTERNAL_CMD_BLKS;
9047 ioa_cfg->hrrq[i].min_cmd_id = 0;
9048 ioa_cfg->hrrq[i].max_cmd_id =
9049 (entries_each_hrrq - 1);
9052 IPR_NUM_BASE_CMD_BLKS/
9053 (ioa_cfg->hrrq_num - 1);
9054 ioa_cfg->hrrq[i].min_cmd_id =
9055 IPR_NUM_INTERNAL_CMD_BLKS +
9056 (i - 1) * entries_each_hrrq;
9057 ioa_cfg->hrrq[i].max_cmd_id =
9058 (IPR_NUM_INTERNAL_CMD_BLKS +
9059 i * entries_each_hrrq - 1);
9062 entries_each_hrrq = IPR_NUM_CMD_BLKS;
9063 ioa_cfg->hrrq[i].min_cmd_id = 0;
9064 ioa_cfg->hrrq[i].max_cmd_id = (entries_each_hrrq - 1);
9066 ioa_cfg->hrrq[i].size = entries_each_hrrq;
9069 BUG_ON(ioa_cfg->hrrq_num == 0);
9071 i = IPR_NUM_CMD_BLKS -
9072 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id - 1;
9074 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].size += i;
9075 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id += i;
9078 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
9079 ipr_cmd = dma_pool_alloc(ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
9082 ipr_free_cmd_blks(ioa_cfg);
9086 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
9087 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
9088 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
9090 ioarcb = &ipr_cmd->ioarcb;
9091 ipr_cmd->dma_addr = dma_addr;
9093 ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
9095 ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
9097 ioarcb->host_response_handle = cpu_to_be32(i << 2);
9098 if (ioa_cfg->sis64) {
9099 ioarcb->u.sis64_addr_data.data_ioadl_addr =
9100 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
9101 ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
9102 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
9104 ioarcb->write_ioadl_addr =
9105 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
9106 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
9107 ioarcb->ioasa_host_pci_addr =
9108 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
9110 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
9111 ipr_cmd->cmd_index = i;
9112 ipr_cmd->ioa_cfg = ioa_cfg;
9113 ipr_cmd->sense_buffer_dma = dma_addr +
9114 offsetof(struct ipr_cmnd, sense_buffer);
9116 ipr_cmd->ioarcb.cmd_pkt.hrrq_id = hrrq_id;
9117 ipr_cmd->hrrq = &ioa_cfg->hrrq[hrrq_id];
9118 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
9119 if (i >= ioa_cfg->hrrq[hrrq_id].max_cmd_id)
9127 * ipr_alloc_mem - Allocate memory for an adapter
9128 * @ioa_cfg: ioa config struct
9131 * 0 on success / non-zero for error
9133 static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
9135 struct pci_dev *pdev = ioa_cfg->pdev;
9136 int i, rc = -ENOMEM;
9139 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
9140 ioa_cfg->max_devs_supported, GFP_KERNEL);
9142 if (!ioa_cfg->res_entries)
9145 for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
9146 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
9147 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
9150 ioa_cfg->vpd_cbs = dma_alloc_coherent(&pdev->dev,
9151 sizeof(struct ipr_misc_cbs),
9152 &ioa_cfg->vpd_cbs_dma,
9155 if (!ioa_cfg->vpd_cbs)
9156 goto out_free_res_entries;
9158 if (ipr_alloc_cmd_blks(ioa_cfg))
9159 goto out_free_vpd_cbs;
9161 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9162 ioa_cfg->hrrq[i].host_rrq = dma_alloc_coherent(&pdev->dev,
9163 sizeof(u32) * ioa_cfg->hrrq[i].size,
9164 &ioa_cfg->hrrq[i].host_rrq_dma,
9167 if (!ioa_cfg->hrrq[i].host_rrq) {
9169 dma_free_coherent(&pdev->dev,
9170 sizeof(u32) * ioa_cfg->hrrq[i].size,
9171 ioa_cfg->hrrq[i].host_rrq,
9172 ioa_cfg->hrrq[i].host_rrq_dma);
9173 goto out_ipr_free_cmd_blocks;
9175 ioa_cfg->hrrq[i].ioa_cfg = ioa_cfg;
9178 ioa_cfg->u.cfg_table = dma_alloc_coherent(&pdev->dev,
9179 ioa_cfg->cfg_table_size,
9180 &ioa_cfg->cfg_table_dma,
9183 if (!ioa_cfg->u.cfg_table)
9184 goto out_free_host_rrq;
9186 for (i = 0; i < IPR_NUM_HCAMS; i++) {
9187 ioa_cfg->hostrcb[i] = dma_alloc_coherent(&pdev->dev,
9188 sizeof(struct ipr_hostrcb),
9189 &ioa_cfg->hostrcb_dma[i],
9192 if (!ioa_cfg->hostrcb[i])
9193 goto out_free_hostrcb_dma;
9195 ioa_cfg->hostrcb[i]->hostrcb_dma =
9196 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
9197 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
9198 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
9201 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
9202 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
9204 if (!ioa_cfg->trace)
9205 goto out_free_hostrcb_dma;
9212 out_free_hostrcb_dma:
9214 dma_free_coherent(&pdev->dev, sizeof(struct ipr_hostrcb),
9215 ioa_cfg->hostrcb[i],
9216 ioa_cfg->hostrcb_dma[i]);
9218 dma_free_coherent(&pdev->dev, ioa_cfg->cfg_table_size,
9219 ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
9221 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9222 dma_free_coherent(&pdev->dev,
9223 sizeof(u32) * ioa_cfg->hrrq[i].size,
9224 ioa_cfg->hrrq[i].host_rrq,
9225 ioa_cfg->hrrq[i].host_rrq_dma);
9227 out_ipr_free_cmd_blocks:
9228 ipr_free_cmd_blks(ioa_cfg);
9230 dma_free_coherent(&pdev->dev, sizeof(struct ipr_misc_cbs),
9231 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
9232 out_free_res_entries:
9233 kfree(ioa_cfg->res_entries);
9238 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
9239 * @ioa_cfg: ioa config struct
9244 static void ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
9248 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
9249 ioa_cfg->bus_attr[i].bus = i;
9250 ioa_cfg->bus_attr[i].qas_enabled = 0;
9251 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
9252 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
9253 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
9255 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
9260 * ipr_init_regs - Initialize IOA registers
9261 * @ioa_cfg: ioa config struct
9266 static void ipr_init_regs(struct ipr_ioa_cfg *ioa_cfg)
9268 const struct ipr_interrupt_offsets *p;
9269 struct ipr_interrupts *t;
9272 p = &ioa_cfg->chip_cfg->regs;
9274 base = ioa_cfg->hdw_dma_regs;
9276 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
9277 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
9278 t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
9279 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
9280 t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
9281 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
9282 t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
9283 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
9284 t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
9285 t->ioarrin_reg = base + p->ioarrin_reg;
9286 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
9287 t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
9288 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
9289 t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
9290 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
9291 t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
9293 if (ioa_cfg->sis64) {
9294 t->init_feedback_reg = base + p->init_feedback_reg;
9295 t->dump_addr_reg = base + p->dump_addr_reg;
9296 t->dump_data_reg = base + p->dump_data_reg;
9297 t->endian_swap_reg = base + p->endian_swap_reg;
9302 * ipr_init_ioa_cfg - Initialize IOA config struct
9303 * @ioa_cfg: ioa config struct
9304 * @host: scsi host struct
9305 * @pdev: PCI dev struct
9310 static void ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
9311 struct Scsi_Host *host, struct pci_dev *pdev)
9315 ioa_cfg->host = host;
9316 ioa_cfg->pdev = pdev;
9317 ioa_cfg->log_level = ipr_log_level;
9318 ioa_cfg->doorbell = IPR_DOORBELL;
9319 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
9320 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
9321 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
9322 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
9323 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
9324 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
9326 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
9327 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
9328 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
9329 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
9330 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
9331 init_waitqueue_head(&ioa_cfg->reset_wait_q);
9332 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9333 init_waitqueue_head(&ioa_cfg->eeh_wait_q);
9334 ioa_cfg->sdt_state = INACTIVE;
9336 ipr_initialize_bus_attr(ioa_cfg);
9337 ioa_cfg->max_devs_supported = ipr_max_devs;
9339 if (ioa_cfg->sis64) {
9340 host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
9341 host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
9342 if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
9343 ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
9344 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
9345 + ((sizeof(struct ipr_config_table_entry64)
9346 * ioa_cfg->max_devs_supported)));
9348 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
9349 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
9350 if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
9351 ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
9352 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
9353 + ((sizeof(struct ipr_config_table_entry)
9354 * ioa_cfg->max_devs_supported)));
9357 host->max_channel = IPR_VSET_BUS;
9358 host->unique_id = host->host_no;
9359 host->max_cmd_len = IPR_MAX_CDB_LEN;
9360 host->can_queue = ioa_cfg->max_cmds;
9361 pci_set_drvdata(pdev, ioa_cfg);
9363 for (i = 0; i < ARRAY_SIZE(ioa_cfg->hrrq); i++) {
9364 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_free_q);
9365 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_pending_q);
9366 spin_lock_init(&ioa_cfg->hrrq[i]._lock);
9368 ioa_cfg->hrrq[i].lock = ioa_cfg->host->host_lock;
9370 ioa_cfg->hrrq[i].lock = &ioa_cfg->hrrq[i]._lock;
9375 * ipr_get_chip_info - Find adapter chip information
9376 * @dev_id: PCI device id struct
9379 * ptr to chip information on success / NULL on failure
9381 static const struct ipr_chip_t *
9382 ipr_get_chip_info(const struct pci_device_id *dev_id)
9386 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
9387 if (ipr_chip[i].vendor == dev_id->vendor &&
9388 ipr_chip[i].device == dev_id->device)
9389 return &ipr_chip[i];
9394 * ipr_wait_for_pci_err_recovery - Wait for any PCI error recovery to complete
9396 * @ioa_cfg: ioa config struct
9401 static void ipr_wait_for_pci_err_recovery(struct ipr_ioa_cfg *ioa_cfg)
9403 struct pci_dev *pdev = ioa_cfg->pdev;
9405 if (pci_channel_offline(pdev)) {
9406 wait_event_timeout(ioa_cfg->eeh_wait_q,
9407 !pci_channel_offline(pdev),
9408 IPR_PCI_ERROR_RECOVERY_TIMEOUT);
9409 pci_restore_state(pdev);
9413 static int ipr_enable_msix(struct ipr_ioa_cfg *ioa_cfg)
9415 struct msix_entry entries[IPR_MAX_MSIX_VECTORS];
9418 for (i = 0; i < ARRAY_SIZE(entries); ++i)
9419 entries[i].entry = i;
9421 vectors = pci_enable_msix_range(ioa_cfg->pdev,
9422 entries, 1, ipr_number_of_msix);
9424 ipr_wait_for_pci_err_recovery(ioa_cfg);
9428 for (i = 0; i < vectors; i++)
9429 ioa_cfg->vectors_info[i].vec = entries[i].vector;
9430 ioa_cfg->nvectors = vectors;
9435 static int ipr_enable_msi(struct ipr_ioa_cfg *ioa_cfg)
9439 vectors = pci_enable_msi_range(ioa_cfg->pdev, 1, ipr_number_of_msix);
9441 ipr_wait_for_pci_err_recovery(ioa_cfg);
9445 for (i = 0; i < vectors; i++)
9446 ioa_cfg->vectors_info[i].vec = ioa_cfg->pdev->irq + i;
9447 ioa_cfg->nvectors = vectors;
9452 static void name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
9454 int vec_idx, n = sizeof(ioa_cfg->vectors_info[0].desc) - 1;
9456 for (vec_idx = 0; vec_idx < ioa_cfg->nvectors; vec_idx++) {
9457 snprintf(ioa_cfg->vectors_info[vec_idx].desc, n,
9458 "host%d-%d", ioa_cfg->host->host_no, vec_idx);
9459 ioa_cfg->vectors_info[vec_idx].
9460 desc[strlen(ioa_cfg->vectors_info[vec_idx].desc)] = 0;
9464 static int ipr_request_other_msi_irqs(struct ipr_ioa_cfg *ioa_cfg)
9468 for (i = 1; i < ioa_cfg->nvectors; i++) {
9469 rc = request_irq(ioa_cfg->vectors_info[i].vec,
9472 ioa_cfg->vectors_info[i].desc,
9476 free_irq(ioa_cfg->vectors_info[i].vec,
9485 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
9486 * @pdev: PCI device struct
9488 * Description: Simply set the msi_received flag to 1 indicating that
9489 * Message Signaled Interrupts are supported.
9492 * 0 on success / non-zero on failure
9494 static irqreturn_t ipr_test_intr(int irq, void *devp)
9496 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
9497 unsigned long lock_flags = 0;
9498 irqreturn_t rc = IRQ_HANDLED;
9500 dev_info(&ioa_cfg->pdev->dev, "Received IRQ : %d\n", irq);
9501 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9503 ioa_cfg->msi_received = 1;
9504 wake_up(&ioa_cfg->msi_wait_q);
9506 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9511 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
9512 * @pdev: PCI device struct
9514 * Description: The return value from pci_enable_msi_range() can not always be
9515 * trusted. This routine sets up and initiates a test interrupt to determine
9516 * if the interrupt is received via the ipr_test_intr() service routine.
9517 * If the tests fails, the driver will fall back to LSI.
9520 * 0 on success / non-zero on failure
9522 static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
9525 volatile u32 int_reg;
9526 unsigned long lock_flags = 0;
9530 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9531 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9532 ioa_cfg->msi_received = 0;
9533 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9534 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
9535 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
9536 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9538 if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9539 rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
9541 rc = request_irq(pdev->irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
9543 dev_err(&pdev->dev, "Can not assign irq %d\n", pdev->irq);
9545 } else if (ipr_debug)
9546 dev_info(&pdev->dev, "IRQ assigned: %d\n", pdev->irq);
9548 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
9549 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
9550 wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
9551 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9552 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9554 if (!ioa_cfg->msi_received) {
9555 /* MSI test failed */
9556 dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
9558 } else if (ipr_debug)
9559 dev_info(&pdev->dev, "MSI test succeeded.\n");
9561 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9563 if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9564 free_irq(ioa_cfg->vectors_info[0].vec, ioa_cfg);
9566 free_irq(pdev->irq, ioa_cfg);
9573 /* ipr_probe_ioa - Allocates memory and does first stage of initialization
9574 * @pdev: PCI device struct
9575 * @dev_id: PCI device id struct
9578 * 0 on success / non-zero on failure
9580 static int ipr_probe_ioa(struct pci_dev *pdev,
9581 const struct pci_device_id *dev_id)
9583 struct ipr_ioa_cfg *ioa_cfg;
9584 struct Scsi_Host *host;
9585 unsigned long ipr_regs_pci;
9586 void __iomem *ipr_regs;
9587 int rc = PCIBIOS_SUCCESSFUL;
9588 volatile u32 mask, uproc, interrupts;
9589 unsigned long lock_flags, driver_lock_flags;
9593 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
9594 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
9597 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
9602 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
9603 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
9604 ata_host_init(&ioa_cfg->ata_host, &pdev->dev, &ipr_sata_ops);
9606 ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
9608 if (!ioa_cfg->ipr_chip) {
9609 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
9610 dev_id->vendor, dev_id->device);
9611 goto out_scsi_host_put;
9614 /* set SIS 32 or SIS 64 */
9615 ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
9616 ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
9617 ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
9618 ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
9620 if (ipr_transop_timeout)
9621 ioa_cfg->transop_timeout = ipr_transop_timeout;
9622 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
9623 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
9625 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
9627 ioa_cfg->revid = pdev->revision;
9629 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
9631 ipr_regs_pci = pci_resource_start(pdev, 0);
9633 rc = pci_request_regions(pdev, IPR_NAME);
9636 "Couldn't register memory range of registers\n");
9637 goto out_scsi_host_put;
9640 rc = pci_enable_device(pdev);
9642 if (rc || pci_channel_offline(pdev)) {
9643 if (pci_channel_offline(pdev)) {
9644 ipr_wait_for_pci_err_recovery(ioa_cfg);
9645 rc = pci_enable_device(pdev);
9649 dev_err(&pdev->dev, "Cannot enable adapter\n");
9650 ipr_wait_for_pci_err_recovery(ioa_cfg);
9651 goto out_release_regions;
9655 ipr_regs = pci_ioremap_bar(pdev, 0);
9659 "Couldn't map memory range of registers\n");
9664 ioa_cfg->hdw_dma_regs = ipr_regs;
9665 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
9666 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
9668 ipr_init_regs(ioa_cfg);
9670 if (ioa_cfg->sis64) {
9671 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
9673 dev_dbg(&pdev->dev, "Failed to set 64 bit DMA mask\n");
9674 rc = dma_set_mask_and_coherent(&pdev->dev,
9678 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
9681 dev_err(&pdev->dev, "Failed to set DMA mask\n");
9685 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
9686 ioa_cfg->chip_cfg->cache_line_size);
9688 if (rc != PCIBIOS_SUCCESSFUL) {
9689 dev_err(&pdev->dev, "Write of cache line size failed\n");
9690 ipr_wait_for_pci_err_recovery(ioa_cfg);
9695 /* Issue MMIO read to ensure card is not in EEH */
9696 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg);
9697 ipr_wait_for_pci_err_recovery(ioa_cfg);
9699 if (ipr_number_of_msix > IPR_MAX_MSIX_VECTORS) {
9700 dev_err(&pdev->dev, "The max number of MSIX is %d\n",
9701 IPR_MAX_MSIX_VECTORS);
9702 ipr_number_of_msix = IPR_MAX_MSIX_VECTORS;
9705 if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
9706 ipr_enable_msix(ioa_cfg) == 0)
9707 ioa_cfg->intr_flag = IPR_USE_MSIX;
9708 else if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
9709 ipr_enable_msi(ioa_cfg) == 0)
9710 ioa_cfg->intr_flag = IPR_USE_MSI;
9712 ioa_cfg->intr_flag = IPR_USE_LSI;
9713 ioa_cfg->nvectors = 1;
9714 dev_info(&pdev->dev, "Cannot enable MSI.\n");
9717 pci_set_master(pdev);
9719 if (pci_channel_offline(pdev)) {
9720 ipr_wait_for_pci_err_recovery(ioa_cfg);
9721 pci_set_master(pdev);
9722 if (pci_channel_offline(pdev)) {
9724 goto out_msi_disable;
9728 if (ioa_cfg->intr_flag == IPR_USE_MSI ||
9729 ioa_cfg->intr_flag == IPR_USE_MSIX) {
9730 rc = ipr_test_msi(ioa_cfg, pdev);
9731 if (rc == -EOPNOTSUPP) {
9732 ipr_wait_for_pci_err_recovery(ioa_cfg);
9733 if (ioa_cfg->intr_flag == IPR_USE_MSI) {
9734 ioa_cfg->intr_flag &= ~IPR_USE_MSI;
9735 pci_disable_msi(pdev);
9736 } else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
9737 ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
9738 pci_disable_msix(pdev);
9741 ioa_cfg->intr_flag = IPR_USE_LSI;
9742 ioa_cfg->nvectors = 1;
9745 goto out_msi_disable;
9747 if (ioa_cfg->intr_flag == IPR_USE_MSI)
9748 dev_info(&pdev->dev,
9749 "Request for %d MSIs succeeded with starting IRQ: %d\n",
9750 ioa_cfg->nvectors, pdev->irq);
9751 else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9752 dev_info(&pdev->dev,
9753 "Request for %d MSIXs succeeded.",
9758 ioa_cfg->hrrq_num = min3(ioa_cfg->nvectors,
9759 (unsigned int)num_online_cpus(),
9760 (unsigned int)IPR_MAX_HRRQ_NUM);
9762 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
9763 goto out_msi_disable;
9765 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
9766 goto out_msi_disable;
9768 rc = ipr_alloc_mem(ioa_cfg);
9771 "Couldn't allocate enough memory for device driver!\n");
9772 goto out_msi_disable;
9775 /* Save away PCI config space for use following IOA reset */
9776 rc = pci_save_state(pdev);
9778 if (rc != PCIBIOS_SUCCESSFUL) {
9779 dev_err(&pdev->dev, "Failed to save PCI config space\n");
9785 * If HRRQ updated interrupt is not masked, or reset alert is set,
9786 * the card is in an unknown state and needs a hard reset
9788 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
9789 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
9790 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
9791 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
9792 ioa_cfg->needs_hard_reset = 1;
9793 if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
9794 ioa_cfg->needs_hard_reset = 1;
9795 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
9796 ioa_cfg->ioa_unit_checked = 1;
9798 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9799 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9800 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9802 if (ioa_cfg->intr_flag == IPR_USE_MSI
9803 || ioa_cfg->intr_flag == IPR_USE_MSIX) {
9804 name_msi_vectors(ioa_cfg);
9805 rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_isr,
9807 ioa_cfg->vectors_info[0].desc,
9810 rc = ipr_request_other_msi_irqs(ioa_cfg);
9812 rc = request_irq(pdev->irq, ipr_isr,
9814 IPR_NAME, &ioa_cfg->hrrq[0]);
9817 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
9822 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
9823 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
9824 ioa_cfg->needs_warm_reset = 1;
9825 ioa_cfg->reset = ipr_reset_slot_reset;
9827 ioa_cfg->reset = ipr_reset_start_bist;
9829 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
9830 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
9831 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
9838 ipr_free_mem(ioa_cfg);
9840 ipr_wait_for_pci_err_recovery(ioa_cfg);
9841 if (ioa_cfg->intr_flag == IPR_USE_MSI)
9842 pci_disable_msi(pdev);
9843 else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9844 pci_disable_msix(pdev);
9848 pci_disable_device(pdev);
9849 out_release_regions:
9850 pci_release_regions(pdev);
9852 scsi_host_put(host);
9857 * ipr_initiate_ioa_bringdown - Bring down an adapter
9858 * @ioa_cfg: ioa config struct
9859 * @shutdown_type: shutdown type
9861 * Description: This function will initiate bringing down the adapter.
9862 * This consists of issuing an IOA shutdown to the adapter
9863 * to flush the cache, and running BIST.
9864 * If the caller needs to wait on the completion of the reset,
9865 * the caller must sleep on the reset_wait_q.
9870 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
9871 enum ipr_shutdown_type shutdown_type)
9874 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
9875 ioa_cfg->sdt_state = ABORT_DUMP;
9876 ioa_cfg->reset_retries = 0;
9877 ioa_cfg->in_ioa_bringdown = 1;
9878 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
9883 * __ipr_remove - Remove a single adapter
9884 * @pdev: pci device struct
9886 * Adapter hot plug remove entry point.
9891 static void __ipr_remove(struct pci_dev *pdev)
9893 unsigned long host_lock_flags = 0;
9894 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9896 unsigned long driver_lock_flags;
9899 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9900 while (ioa_cfg->in_reset_reload) {
9901 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9902 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9903 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9906 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9907 spin_lock(&ioa_cfg->hrrq[i]._lock);
9908 ioa_cfg->hrrq[i].removing_ioa = 1;
9909 spin_unlock(&ioa_cfg->hrrq[i]._lock);
9912 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9914 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9915 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9916 flush_work(&ioa_cfg->work_q);
9917 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
9918 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9920 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
9921 list_del(&ioa_cfg->queue);
9922 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
9924 if (ioa_cfg->sdt_state == ABORT_DUMP)
9925 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
9926 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9928 ipr_free_all_resources(ioa_cfg);
9934 * ipr_remove - IOA hot plug remove entry point
9935 * @pdev: pci device struct
9937 * Adapter hot plug remove entry point.
9942 static void ipr_remove(struct pci_dev *pdev)
9944 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9948 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
9950 ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
9952 scsi_remove_host(ioa_cfg->host);
9960 * ipr_probe - Adapter hot plug add entry point
9963 * 0 on success / non-zero on failure
9965 static int ipr_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
9967 struct ipr_ioa_cfg *ioa_cfg;
9970 rc = ipr_probe_ioa(pdev, dev_id);
9975 ioa_cfg = pci_get_drvdata(pdev);
9976 rc = ipr_probe_ioa_part2(ioa_cfg);
9983 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
9990 rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
9994 scsi_remove_host(ioa_cfg->host);
9999 rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
10003 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
10005 scsi_remove_host(ioa_cfg->host);
10006 __ipr_remove(pdev);
10010 scsi_scan_host(ioa_cfg->host);
10011 ioa_cfg->iopoll_weight = ioa_cfg->chip_cfg->iopoll_weight;
10013 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
10014 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
10015 blk_iopoll_init(&ioa_cfg->hrrq[i].iopoll,
10016 ioa_cfg->iopoll_weight, ipr_iopoll);
10017 blk_iopoll_enable(&ioa_cfg->hrrq[i].iopoll);
10021 schedule_work(&ioa_cfg->work_q);
10026 * ipr_shutdown - Shutdown handler.
10027 * @pdev: pci device struct
10029 * This function is invoked upon system shutdown/reboot. It will issue
10030 * an adapter shutdown to the adapter to flush the write cache.
10035 static void ipr_shutdown(struct pci_dev *pdev)
10037 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
10038 unsigned long lock_flags = 0;
10041 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
10042 if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
10043 ioa_cfg->iopoll_weight = 0;
10044 for (i = 1; i < ioa_cfg->hrrq_num; i++)
10045 blk_iopoll_disable(&ioa_cfg->hrrq[i].iopoll);
10048 while (ioa_cfg->in_reset_reload) {
10049 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
10050 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
10051 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
10054 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
10055 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
10056 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
10059 static struct pci_device_id ipr_pci_table[] = {
10060 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
10061 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
10062 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
10063 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
10064 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
10065 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
10066 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
10067 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
10068 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
10069 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
10070 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
10071 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
10072 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
10073 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
10074 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
10075 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
10076 IPR_USE_LONG_TRANSOP_TIMEOUT },
10077 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
10078 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
10079 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
10080 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
10081 IPR_USE_LONG_TRANSOP_TIMEOUT },
10082 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
10083 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
10084 IPR_USE_LONG_TRANSOP_TIMEOUT },
10085 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
10086 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
10087 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
10088 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
10089 IPR_USE_LONG_TRANSOP_TIMEOUT},
10090 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
10091 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
10092 IPR_USE_LONG_TRANSOP_TIMEOUT },
10093 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
10094 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
10095 IPR_USE_LONG_TRANSOP_TIMEOUT },
10096 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
10097 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
10098 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
10099 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
10100 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
10101 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
10102 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
10103 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
10104 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
10105 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
10106 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
10107 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
10108 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
10109 IPR_USE_LONG_TRANSOP_TIMEOUT },
10110 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
10111 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
10112 IPR_USE_LONG_TRANSOP_TIMEOUT },
10113 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10114 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
10115 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10116 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
10117 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10118 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
10119 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10120 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C0, 0, 0, 0 },
10121 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10122 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
10123 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
10124 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
10125 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10126 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
10127 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10128 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
10129 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10130 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
10131 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10132 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
10133 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10134 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
10135 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10136 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D5, 0, 0, 0 },
10137 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10138 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D6, 0, 0, 0 },
10139 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10140 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D7, 0, 0, 0 },
10141 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10142 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D8, 0, 0, 0 },
10143 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10144 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D9, 0, 0, 0 },
10145 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10146 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57DA, 0, 0, 0 },
10147 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10148 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EB, 0, 0, 0 },
10149 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10150 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EC, 0, 0, 0 },
10151 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10152 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57ED, 0, 0, 0 },
10153 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10154 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EE, 0, 0, 0 },
10155 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10156 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EF, 0, 0, 0 },
10157 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10158 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57F0, 0, 0, 0 },
10159 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10160 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCA, 0, 0, 0 },
10161 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10162 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CD2, 0, 0, 0 },
10163 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10164 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCD, 0, 0, 0 },
10167 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
10169 static const struct pci_error_handlers ipr_err_handler = {
10170 .error_detected = ipr_pci_error_detected,
10171 .mmio_enabled = ipr_pci_mmio_enabled,
10172 .slot_reset = ipr_pci_slot_reset,
10175 static struct pci_driver ipr_driver = {
10177 .id_table = ipr_pci_table,
10178 .probe = ipr_probe,
10179 .remove = ipr_remove,
10180 .shutdown = ipr_shutdown,
10181 .err_handler = &ipr_err_handler,
10185 * ipr_halt_done - Shutdown prepare completion
10190 static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
10192 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
10196 * ipr_halt - Issue shutdown prepare to all adapters
10199 * NOTIFY_OK on success / NOTIFY_DONE on failure
10201 static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
10203 struct ipr_cmnd *ipr_cmd;
10204 struct ipr_ioa_cfg *ioa_cfg;
10205 unsigned long flags = 0, driver_lock_flags;
10207 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
10208 return NOTIFY_DONE;
10210 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
10212 list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
10213 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
10214 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
10215 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10219 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
10220 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
10221 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
10222 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
10223 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
10225 ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
10226 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10228 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
10233 static struct notifier_block ipr_notifier = {
10238 * ipr_init - Module entry point
10241 * 0 on success / negative value on failure
10243 static int __init ipr_init(void)
10245 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
10246 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
10248 register_reboot_notifier(&ipr_notifier);
10249 return pci_register_driver(&ipr_driver);
10253 * ipr_exit - Module unload
10255 * Module unload entry point.
10260 static void __exit ipr_exit(void)
10262 unregister_reboot_notifier(&ipr_notifier);
10263 pci_unregister_driver(&ipr_driver);
10266 module_init(ipr_init);
10267 module_exit(ipr_exit);