2 * ipr.c -- driver for IBM Power Linux RAID adapters
4 * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
6 * Copyright (C) 2003, 2004 IBM Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * This driver is used to control the following SCSI adapters:
29 * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
31 * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
32 * PCI-X Dual Channel Ultra 320 SCSI Adapter
33 * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
34 * Embedded SCSI adapter on p615 and p655 systems
36 * Supported Hardware Features:
37 * - Ultra 320 SCSI controller
38 * - PCI-X host interface
39 * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
40 * - Non-Volatile Write Cache
41 * - Supports attachment of non-RAID disks, tape, and optical devices
42 * - RAID Levels 0, 5, 10
44 * - Background Parity Checking
45 * - Background Data Scrubbing
46 * - Ability to increase the capacity of an existing RAID 5 disk array
50 * - Tagged command queuing
51 * - Adapter microcode download
53 * - SCSI device hot plug
58 #include <linux/init.h>
59 #include <linux/types.h>
60 #include <linux/errno.h>
61 #include <linux/kernel.h>
62 #include <linux/slab.h>
63 #include <linux/vmalloc.h>
64 #include <linux/ioport.h>
65 #include <linux/delay.h>
66 #include <linux/pci.h>
67 #include <linux/wait.h>
68 #include <linux/spinlock.h>
69 #include <linux/sched.h>
70 #include <linux/interrupt.h>
71 #include <linux/blkdev.h>
72 #include <linux/firmware.h>
73 #include <linux/module.h>
74 #include <linux/moduleparam.h>
75 #include <linux/libata.h>
76 #include <linux/hdreg.h>
77 #include <linux/reboot.h>
78 #include <linux/stringify.h>
81 #include <asm/processor.h>
82 #include <scsi/scsi.h>
83 #include <scsi/scsi_host.h>
84 #include <scsi/scsi_tcq.h>
85 #include <scsi/scsi_eh.h>
86 #include <scsi/scsi_cmnd.h>
92 static LIST_HEAD(ipr_ioa_head);
93 static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
94 static unsigned int ipr_max_speed = 1;
95 static int ipr_testmode = 0;
96 static unsigned int ipr_fastfail = 0;
97 static unsigned int ipr_transop_timeout = 0;
98 static unsigned int ipr_debug = 0;
99 static unsigned int ipr_max_devs = IPR_DEFAULT_SIS64_DEVS;
100 static unsigned int ipr_dual_ioa_raid = 1;
101 static DEFINE_SPINLOCK(ipr_driver_lock);
103 /* This table describes the differences between DMA controller chips */
104 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
105 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
108 .cache_line_size = 0x20,
111 .set_interrupt_mask_reg = 0x0022C,
112 .clr_interrupt_mask_reg = 0x00230,
113 .clr_interrupt_mask_reg32 = 0x00230,
114 .sense_interrupt_mask_reg = 0x0022C,
115 .sense_interrupt_mask_reg32 = 0x0022C,
116 .clr_interrupt_reg = 0x00228,
117 .clr_interrupt_reg32 = 0x00228,
118 .sense_interrupt_reg = 0x00224,
119 .sense_interrupt_reg32 = 0x00224,
120 .ioarrin_reg = 0x00404,
121 .sense_uproc_interrupt_reg = 0x00214,
122 .sense_uproc_interrupt_reg32 = 0x00214,
123 .set_uproc_interrupt_reg = 0x00214,
124 .set_uproc_interrupt_reg32 = 0x00214,
125 .clr_uproc_interrupt_reg = 0x00218,
126 .clr_uproc_interrupt_reg32 = 0x00218
129 { /* Snipe and Scamp */
132 .cache_line_size = 0x20,
135 .set_interrupt_mask_reg = 0x00288,
136 .clr_interrupt_mask_reg = 0x0028C,
137 .clr_interrupt_mask_reg32 = 0x0028C,
138 .sense_interrupt_mask_reg = 0x00288,
139 .sense_interrupt_mask_reg32 = 0x00288,
140 .clr_interrupt_reg = 0x00284,
141 .clr_interrupt_reg32 = 0x00284,
142 .sense_interrupt_reg = 0x00280,
143 .sense_interrupt_reg32 = 0x00280,
144 .ioarrin_reg = 0x00504,
145 .sense_uproc_interrupt_reg = 0x00290,
146 .sense_uproc_interrupt_reg32 = 0x00290,
147 .set_uproc_interrupt_reg = 0x00290,
148 .set_uproc_interrupt_reg32 = 0x00290,
149 .clr_uproc_interrupt_reg = 0x00294,
150 .clr_uproc_interrupt_reg32 = 0x00294
156 .cache_line_size = 0x20,
159 .set_interrupt_mask_reg = 0x00010,
160 .clr_interrupt_mask_reg = 0x00018,
161 .clr_interrupt_mask_reg32 = 0x0001C,
162 .sense_interrupt_mask_reg = 0x00010,
163 .sense_interrupt_mask_reg32 = 0x00014,
164 .clr_interrupt_reg = 0x00008,
165 .clr_interrupt_reg32 = 0x0000C,
166 .sense_interrupt_reg = 0x00000,
167 .sense_interrupt_reg32 = 0x00004,
168 .ioarrin_reg = 0x00070,
169 .sense_uproc_interrupt_reg = 0x00020,
170 .sense_uproc_interrupt_reg32 = 0x00024,
171 .set_uproc_interrupt_reg = 0x00020,
172 .set_uproc_interrupt_reg32 = 0x00024,
173 .clr_uproc_interrupt_reg = 0x00028,
174 .clr_uproc_interrupt_reg32 = 0x0002C,
175 .init_feedback_reg = 0x0005C,
176 .dump_addr_reg = 0x00064,
177 .dump_data_reg = 0x00068,
178 .endian_swap_reg = 0x00084
183 static const struct ipr_chip_t ipr_chip[] = {
184 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
185 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
186 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
187 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
188 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, IPR_USE_MSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
189 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
190 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
191 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
192 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
195 static int ipr_max_bus_speeds [] = {
196 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
199 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
200 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
201 module_param_named(max_speed, ipr_max_speed, uint, 0);
202 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
203 module_param_named(log_level, ipr_log_level, uint, 0);
204 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
205 module_param_named(testmode, ipr_testmode, int, 0);
206 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
207 module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
208 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
209 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
210 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
211 module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
212 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
213 module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
214 MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
215 module_param_named(max_devs, ipr_max_devs, int, 0);
216 MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
217 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
218 MODULE_LICENSE("GPL");
219 MODULE_VERSION(IPR_DRIVER_VERSION);
221 /* A constant array of IOASCs/URCs/Error Messages */
223 struct ipr_error_table_t ipr_error_table[] = {
224 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
225 "8155: An unknown error was received"},
227 "Soft underlength error"},
229 "Command to be cancelled not found"},
231 "Qualified success"},
232 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
233 "FFFE: Soft device bus error recovered by the IOA"},
234 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
235 "4101: Soft device bus fabric error"},
236 {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
237 "FFFC: Logical block guard error recovered by the device"},
238 {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
239 "FFFC: Logical block reference tag error recovered by the device"},
240 {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
241 "4171: Recovered scatter list tag / sequence number error"},
242 {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
243 "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
244 {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
245 "4171: Recovered logical block sequence number error on IOA to Host transfer"},
246 {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
247 "FFFD: Recovered logical block reference tag error detected by the IOA"},
248 {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
249 "FFFD: Logical block guard error recovered by the IOA"},
250 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
251 "FFF9: Device sector reassign successful"},
252 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
253 "FFF7: Media error recovered by device rewrite procedures"},
254 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
255 "7001: IOA sector reassignment successful"},
256 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
257 "FFF9: Soft media error. Sector reassignment recommended"},
258 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
259 "FFF7: Media error recovered by IOA rewrite procedures"},
260 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
261 "FF3D: Soft PCI bus error recovered by the IOA"},
262 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
263 "FFF6: Device hardware error recovered by the IOA"},
264 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
265 "FFF6: Device hardware error recovered by the device"},
266 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
267 "FF3D: Soft IOA error recovered by the IOA"},
268 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
269 "FFFA: Undefined device response recovered by the IOA"},
270 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
271 "FFF6: Device bus error, message or command phase"},
272 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
273 "FFFE: Task Management Function failed"},
274 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
275 "FFF6: Failure prediction threshold exceeded"},
276 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
277 "8009: Impending cache battery pack failure"},
279 "34FF: Disk device format in progress"},
280 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
281 "9070: IOA requested reset"},
283 "Synchronization required"},
285 "No ready, IOA shutdown"},
287 "Not ready, IOA has been shutdown"},
288 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
289 "3020: Storage subsystem configuration error"},
291 "FFF5: Medium error, data unreadable, recommend reassign"},
293 "7000: Medium error, data unreadable, do not reassign"},
294 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
295 "FFF3: Disk media format bad"},
296 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
297 "3002: Addressed device failed to respond to selection"},
298 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
299 "3100: Device bus error"},
300 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
301 "3109: IOA timed out a device command"},
303 "3120: SCSI bus is not operational"},
304 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
305 "4100: Hard device bus fabric error"},
306 {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
307 "310C: Logical block guard error detected by the device"},
308 {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
309 "310C: Logical block reference tag error detected by the device"},
310 {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
311 "4170: Scatter list tag / sequence number error"},
312 {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
313 "8150: Logical block CRC error on IOA to Host transfer"},
314 {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
315 "4170: Logical block sequence number error on IOA to Host transfer"},
316 {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
317 "310D: Logical block reference tag error detected by the IOA"},
318 {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
319 "310D: Logical block guard error detected by the IOA"},
320 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
321 "9000: IOA reserved area data check"},
322 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
323 "9001: IOA reserved area invalid data pattern"},
324 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
325 "9002: IOA reserved area LRC error"},
326 {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
327 "Hardware Error, IOA metadata access error"},
328 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
329 "102E: Out of alternate sectors for disk storage"},
330 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
331 "FFF4: Data transfer underlength error"},
332 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
333 "FFF4: Data transfer overlength error"},
334 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
335 "3400: Logical unit failure"},
336 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
337 "FFF4: Device microcode is corrupt"},
338 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
339 "8150: PCI bus error"},
341 "Unsupported device bus message received"},
342 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
343 "FFF4: Disk device problem"},
344 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
345 "8150: Permanent IOA failure"},
346 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
347 "3010: Disk device returned wrong response to IOA"},
348 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
349 "8151: IOA microcode error"},
351 "Device bus status error"},
352 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
353 "8157: IOA error requiring IOA reset to recover"},
355 "ATA device status error"},
357 "Message reject received from the device"},
358 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
359 "8008: A permanent cache battery pack failure occurred"},
360 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
361 "9090: Disk unit has been modified after the last known status"},
362 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
363 "9081: IOA detected device error"},
364 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
365 "9082: IOA detected device error"},
366 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
367 "3110: Device bus error, message or command phase"},
368 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
369 "3110: SAS Command / Task Management Function failed"},
370 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
371 "9091: Incorrect hardware configuration change has been detected"},
372 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
373 "9073: Invalid multi-adapter configuration"},
374 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
375 "4010: Incorrect connection between cascaded expanders"},
376 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
377 "4020: Connections exceed IOA design limits"},
378 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
379 "4030: Incorrect multipath connection"},
380 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
381 "4110: Unsupported enclosure function"},
382 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
383 "FFF4: Command to logical unit failed"},
385 "Illegal request, invalid request type or request packet"},
387 "Illegal request, invalid resource handle"},
389 "Illegal request, commands not allowed to this device"},
391 "Illegal request, command not allowed to a secondary adapter"},
393 "Illegal request, command not allowed to a non-optimized resource"},
395 "Illegal request, invalid field in parameter list"},
397 "Illegal request, parameter not supported"},
399 "Illegal request, parameter value invalid"},
401 "Illegal request, command sequence error"},
403 "Illegal request, dual adapter support not enabled"},
404 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
405 "9031: Array protection temporarily suspended, protection resuming"},
406 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
407 "9040: Array protection temporarily suspended, protection resuming"},
408 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
409 "3140: Device bus not ready to ready transition"},
410 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
411 "FFFB: SCSI bus was reset"},
413 "FFFE: SCSI bus transition to single ended"},
415 "FFFE: SCSI bus transition to LVD"},
416 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
417 "FFFB: SCSI bus was reset by another initiator"},
418 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
419 "3029: A device replacement has occurred"},
420 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
421 "9051: IOA cache data exists for a missing or failed device"},
422 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
423 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
424 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
425 "9025: Disk unit is not supported at its physical location"},
426 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
427 "3020: IOA detected a SCSI bus configuration error"},
428 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
429 "3150: SCSI bus configuration error"},
430 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
431 "9074: Asymmetric advanced function disk configuration"},
432 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
433 "4040: Incomplete multipath connection between IOA and enclosure"},
434 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
435 "4041: Incomplete multipath connection between enclosure and device"},
436 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
437 "9075: Incomplete multipath connection between IOA and remote IOA"},
438 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
439 "9076: Configuration error, missing remote IOA"},
440 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
441 "4050: Enclosure does not support a required multipath function"},
442 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
443 "4070: Logically bad block written on device"},
444 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
445 "9041: Array protection temporarily suspended"},
446 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
447 "9042: Corrupt array parity detected on specified device"},
448 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
449 "9030: Array no longer protected due to missing or failed disk unit"},
450 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
451 "9071: Link operational transition"},
452 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
453 "9072: Link not operational transition"},
454 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
455 "9032: Array exposed but still protected"},
456 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
457 "70DD: Device forced failed by disrupt device command"},
458 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
459 "4061: Multipath redundancy level got better"},
460 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
461 "4060: Multipath redundancy level got worse"},
463 "Failure due to other device"},
464 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
465 "9008: IOA does not support functions expected by devices"},
466 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
467 "9010: Cache data associated with attached devices cannot be found"},
468 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
469 "9011: Cache data belongs to devices other than those attached"},
470 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
471 "9020: Array missing 2 or more devices with only 1 device present"},
472 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
473 "9021: Array missing 2 or more devices with 2 or more devices present"},
474 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
475 "9022: Exposed array is missing a required device"},
476 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
477 "9023: Array member(s) not at required physical locations"},
478 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
479 "9024: Array not functional due to present hardware configuration"},
480 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
481 "9026: Array not functional due to present hardware configuration"},
482 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
483 "9027: Array is missing a device and parity is out of sync"},
484 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
485 "9028: Maximum number of arrays already exist"},
486 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
487 "9050: Required cache data cannot be located for a disk unit"},
488 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
489 "9052: Cache data exists for a device that has been modified"},
490 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
491 "9054: IOA resources not available due to previous problems"},
492 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
493 "9092: Disk unit requires initialization before use"},
494 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
495 "9029: Incorrect hardware configuration change has been detected"},
496 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
497 "9060: One or more disk pairs are missing from an array"},
498 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
499 "9061: One or more disks are missing from an array"},
500 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
501 "9062: One or more disks are missing from an array"},
502 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
503 "9063: Maximum number of functional arrays has been exceeded"},
505 "Aborted command, invalid descriptor"},
507 "Command terminated by host"}
510 static const struct ipr_ses_table_entry ipr_ses_table[] = {
511 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
512 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
513 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
514 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
515 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
516 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
517 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
518 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
519 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
520 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
521 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
522 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
523 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
527 * Function Prototypes
529 static int ipr_reset_alert(struct ipr_cmnd *);
530 static void ipr_process_ccn(struct ipr_cmnd *);
531 static void ipr_process_error(struct ipr_cmnd *);
532 static void ipr_reset_ioa_job(struct ipr_cmnd *);
533 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
534 enum ipr_shutdown_type);
536 #ifdef CONFIG_SCSI_IPR_TRACE
538 * ipr_trc_hook - Add a trace entry to the driver trace
539 * @ipr_cmd: ipr command struct
541 * @add_data: additional data
546 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
547 u8 type, u32 add_data)
549 struct ipr_trace_entry *trace_entry;
550 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
552 trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
553 trace_entry->time = jiffies;
554 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
555 trace_entry->type = type;
556 if (ipr_cmd->ioa_cfg->sis64)
557 trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
559 trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
560 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
561 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
562 trace_entry->u.add_data = add_data;
565 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
569 * ipr_lock_and_done - Acquire lock and complete command
570 * @ipr_cmd: ipr command struct
575 static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
577 unsigned long lock_flags;
578 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
580 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
581 ipr_cmd->done(ipr_cmd);
582 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
586 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
587 * @ipr_cmd: ipr command struct
592 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
594 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
595 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
596 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
597 dma_addr_t dma_addr = ipr_cmd->dma_addr;
599 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
600 ioarcb->data_transfer_length = 0;
601 ioarcb->read_data_transfer_length = 0;
602 ioarcb->ioadl_len = 0;
603 ioarcb->read_ioadl_len = 0;
605 if (ipr_cmd->ioa_cfg->sis64) {
606 ioarcb->u.sis64_addr_data.data_ioadl_addr =
607 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
608 ioasa64->u.gata.status = 0;
610 ioarcb->write_ioadl_addr =
611 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
612 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
613 ioasa->u.gata.status = 0;
616 ioasa->hdr.ioasc = 0;
617 ioasa->hdr.residual_data_len = 0;
618 ipr_cmd->scsi_cmd = NULL;
620 ipr_cmd->sense_buffer[0] = 0;
621 ipr_cmd->dma_use_sg = 0;
625 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
626 * @ipr_cmd: ipr command struct
631 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
632 void (*fast_done) (struct ipr_cmnd *))
634 ipr_reinit_ipr_cmnd(ipr_cmd);
635 ipr_cmd->u.scratch = 0;
636 ipr_cmd->sibling = NULL;
637 ipr_cmd->fast_done = fast_done;
638 init_timer(&ipr_cmd->timer);
642 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
643 * @ioa_cfg: ioa config struct
646 * pointer to ipr command struct
649 struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
651 struct ipr_cmnd *ipr_cmd;
653 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
654 list_del(&ipr_cmd->queue);
660 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
661 * @ioa_cfg: ioa config struct
664 * pointer to ipr command struct
667 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
669 struct ipr_cmnd *ipr_cmd = __ipr_get_free_ipr_cmnd(ioa_cfg);
670 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
675 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
676 * @ioa_cfg: ioa config struct
677 * @clr_ints: interrupts to clear
679 * This function masks all interrupts on the adapter, then clears the
680 * interrupts specified in the mask
685 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
688 volatile u32 int_reg;
690 /* Stop new interrupts */
691 ioa_cfg->allow_interrupts = 0;
693 /* Set interrupt mask to stop all new interrupts */
695 writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
697 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
699 /* Clear any pending interrupts */
701 writel(~0, ioa_cfg->regs.clr_interrupt_reg);
702 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
703 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
707 * ipr_save_pcix_cmd_reg - Save PCI-X command register
708 * @ioa_cfg: ioa config struct
711 * 0 on success / -EIO on failure
713 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
715 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
717 if (pcix_cmd_reg == 0)
720 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
721 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
722 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
726 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
731 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
732 * @ioa_cfg: ioa config struct
735 * 0 on success / -EIO on failure
737 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
739 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
742 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
743 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
744 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
753 * ipr_sata_eh_done - done function for aborted SATA commands
754 * @ipr_cmd: ipr command struct
756 * This function is invoked for ops generated to SATA
757 * devices which are being aborted.
762 static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
764 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
765 struct ata_queued_cmd *qc = ipr_cmd->qc;
766 struct ipr_sata_port *sata_port = qc->ap->private_data;
768 qc->err_mask |= AC_ERR_OTHER;
769 sata_port->ioasa.status |= ATA_BUSY;
770 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
775 * ipr_scsi_eh_done - mid-layer done function for aborted ops
776 * @ipr_cmd: ipr command struct
778 * This function is invoked by the interrupt handler for
779 * ops generated by the SCSI mid-layer which are being aborted.
784 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
786 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
787 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
789 scsi_cmd->result |= (DID_ERROR << 16);
791 scsi_dma_unmap(ipr_cmd->scsi_cmd);
792 scsi_cmd->scsi_done(scsi_cmd);
793 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
797 * ipr_fail_all_ops - Fails all outstanding ops.
798 * @ioa_cfg: ioa config struct
800 * This function fails all outstanding ops.
805 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
807 struct ipr_cmnd *ipr_cmd, *temp;
810 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
811 list_del(&ipr_cmd->queue);
813 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
814 ipr_cmd->s.ioasa.hdr.ilid = cpu_to_be32(IPR_DRIVER_ILID);
816 if (ipr_cmd->scsi_cmd)
817 ipr_cmd->done = ipr_scsi_eh_done;
818 else if (ipr_cmd->qc)
819 ipr_cmd->done = ipr_sata_eh_done;
821 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
822 del_timer(&ipr_cmd->timer);
823 ipr_cmd->done(ipr_cmd);
830 * ipr_send_command - Send driver initiated requests.
831 * @ipr_cmd: ipr command struct
833 * This function sends a command to the adapter using the correct write call.
834 * In the case of sis64, calculate the ioarcb size required. Then or in the
840 static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
842 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
843 dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
845 if (ioa_cfg->sis64) {
846 /* The default size is 256 bytes */
847 send_dma_addr |= 0x1;
849 /* If the number of ioadls * size of ioadl > 128 bytes,
850 then use a 512 byte ioarcb */
851 if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
852 send_dma_addr |= 0x4;
853 writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
855 writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
859 * ipr_do_req - Send driver initiated requests.
860 * @ipr_cmd: ipr command struct
861 * @done: done function
862 * @timeout_func: timeout function
863 * @timeout: timeout value
865 * This function sends the specified command to the adapter with the
866 * timeout given. The done function is invoked on command completion.
871 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
872 void (*done) (struct ipr_cmnd *),
873 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
875 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
877 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
879 ipr_cmd->done = done;
881 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
882 ipr_cmd->timer.expires = jiffies + timeout;
883 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
885 add_timer(&ipr_cmd->timer);
887 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
889 ipr_send_command(ipr_cmd);
893 * ipr_internal_cmd_done - Op done function for an internally generated op.
894 * @ipr_cmd: ipr command struct
896 * This function is the op done function for an internally generated,
897 * blocking op. It simply wakes the sleeping thread.
902 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
904 if (ipr_cmd->sibling)
905 ipr_cmd->sibling = NULL;
907 complete(&ipr_cmd->completion);
911 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
912 * @ipr_cmd: ipr command struct
913 * @dma_addr: dma address
914 * @len: transfer length
915 * @flags: ioadl flag value
917 * This function initializes an ioadl in the case where there is only a single
923 static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
926 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
927 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
929 ipr_cmd->dma_use_sg = 1;
931 if (ipr_cmd->ioa_cfg->sis64) {
932 ioadl64->flags = cpu_to_be32(flags);
933 ioadl64->data_len = cpu_to_be32(len);
934 ioadl64->address = cpu_to_be64(dma_addr);
936 ipr_cmd->ioarcb.ioadl_len =
937 cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
938 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
940 ioadl->flags_and_data_len = cpu_to_be32(flags | len);
941 ioadl->address = cpu_to_be32(dma_addr);
943 if (flags == IPR_IOADL_FLAGS_READ_LAST) {
944 ipr_cmd->ioarcb.read_ioadl_len =
945 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
946 ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
948 ipr_cmd->ioarcb.ioadl_len =
949 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
950 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
956 * ipr_send_blocking_cmd - Send command and sleep on its completion.
957 * @ipr_cmd: ipr command struct
958 * @timeout_func: function to invoke if command times out
964 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
965 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
968 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
970 init_completion(&ipr_cmd->completion);
971 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
973 spin_unlock_irq(ioa_cfg->host->host_lock);
974 wait_for_completion(&ipr_cmd->completion);
975 spin_lock_irq(ioa_cfg->host->host_lock);
979 * ipr_send_hcam - Send an HCAM to the adapter.
980 * @ioa_cfg: ioa config struct
982 * @hostrcb: hostrcb struct
984 * This function will send a Host Controlled Async command to the adapter.
985 * If HCAMs are currently not allowed to be issued to the adapter, it will
986 * place the hostrcb on the free queue.
991 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
992 struct ipr_hostrcb *hostrcb)
994 struct ipr_cmnd *ipr_cmd;
995 struct ipr_ioarcb *ioarcb;
997 if (ioa_cfg->allow_cmds) {
998 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
999 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
1000 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
1002 ipr_cmd->u.hostrcb = hostrcb;
1003 ioarcb = &ipr_cmd->ioarcb;
1005 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
1006 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
1007 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
1008 ioarcb->cmd_pkt.cdb[1] = type;
1009 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
1010 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
1012 ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
1013 sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
1015 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
1016 ipr_cmd->done = ipr_process_ccn;
1018 ipr_cmd->done = ipr_process_error;
1020 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
1022 ipr_send_command(ipr_cmd);
1024 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
1029 * ipr_update_ata_class - Update the ata class in the resource entry
1030 * @res: resource entry struct
1031 * @proto: cfgte device bus protocol value
1036 static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
1039 case IPR_PROTO_SATA:
1040 case IPR_PROTO_SAS_STP:
1041 res->ata_class = ATA_DEV_ATA;
1043 case IPR_PROTO_SATA_ATAPI:
1044 case IPR_PROTO_SAS_STP_ATAPI:
1045 res->ata_class = ATA_DEV_ATAPI;
1048 res->ata_class = ATA_DEV_UNKNOWN;
1054 * ipr_init_res_entry - Initialize a resource entry struct.
1055 * @res: resource entry struct
1056 * @cfgtew: config table entry wrapper struct
1061 static void ipr_init_res_entry(struct ipr_resource_entry *res,
1062 struct ipr_config_table_entry_wrapper *cfgtew)
1066 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1067 struct ipr_resource_entry *gscsi_res = NULL;
1069 res->needs_sync_complete = 0;
1072 res->del_from_ml = 0;
1073 res->resetting_device = 0;
1075 res->sata_port = NULL;
1077 if (ioa_cfg->sis64) {
1078 proto = cfgtew->u.cfgte64->proto;
1079 res->res_flags = cfgtew->u.cfgte64->res_flags;
1080 res->qmodel = IPR_QUEUEING_MODEL64(res);
1081 res->type = cfgtew->u.cfgte64->res_type;
1083 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1084 sizeof(res->res_path));
1087 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1088 sizeof(res->dev_lun.scsi_lun));
1089 res->lun = scsilun_to_int(&res->dev_lun);
1091 if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1092 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1093 if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1095 res->target = gscsi_res->target;
1100 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1101 ioa_cfg->max_devs_supported);
1102 set_bit(res->target, ioa_cfg->target_ids);
1104 } else if (res->type == IPR_RES_TYPE_IOAFP) {
1105 res->bus = IPR_IOAFP_VIRTUAL_BUS;
1107 } else if (res->type == IPR_RES_TYPE_ARRAY) {
1108 res->bus = IPR_ARRAY_VIRTUAL_BUS;
1109 res->target = find_first_zero_bit(ioa_cfg->array_ids,
1110 ioa_cfg->max_devs_supported);
1111 set_bit(res->target, ioa_cfg->array_ids);
1112 } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1113 res->bus = IPR_VSET_VIRTUAL_BUS;
1114 res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1115 ioa_cfg->max_devs_supported);
1116 set_bit(res->target, ioa_cfg->vset_ids);
1118 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1119 ioa_cfg->max_devs_supported);
1120 set_bit(res->target, ioa_cfg->target_ids);
1123 proto = cfgtew->u.cfgte->proto;
1124 res->qmodel = IPR_QUEUEING_MODEL(res);
1125 res->flags = cfgtew->u.cfgte->flags;
1126 if (res->flags & IPR_IS_IOA_RESOURCE)
1127 res->type = IPR_RES_TYPE_IOAFP;
1129 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1131 res->bus = cfgtew->u.cfgte->res_addr.bus;
1132 res->target = cfgtew->u.cfgte->res_addr.target;
1133 res->lun = cfgtew->u.cfgte->res_addr.lun;
1134 res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
1137 ipr_update_ata_class(res, proto);
1141 * ipr_is_same_device - Determine if two devices are the same.
1142 * @res: resource entry struct
1143 * @cfgtew: config table entry wrapper struct
1146 * 1 if the devices are the same / 0 otherwise
1148 static int ipr_is_same_device(struct ipr_resource_entry *res,
1149 struct ipr_config_table_entry_wrapper *cfgtew)
1151 if (res->ioa_cfg->sis64) {
1152 if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1153 sizeof(cfgtew->u.cfgte64->dev_id)) &&
1154 !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1155 sizeof(cfgtew->u.cfgte64->lun))) {
1159 if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1160 res->target == cfgtew->u.cfgte->res_addr.target &&
1161 res->lun == cfgtew->u.cfgte->res_addr.lun)
1169 * ipr_format_res_path - Format the resource path for printing.
1170 * @res_path: resource path
1176 static char *ipr_format_res_path(u8 *res_path, char *buffer, int len)
1182 p += snprintf(p, buffer + len - p, "%02X", res_path[0]);
1183 for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
1184 p += snprintf(p, buffer + len - p, "-%02X", res_path[i]);
1190 * ipr_update_res_entry - Update the resource entry.
1191 * @res: resource entry struct
1192 * @cfgtew: config table entry wrapper struct
1197 static void ipr_update_res_entry(struct ipr_resource_entry *res,
1198 struct ipr_config_table_entry_wrapper *cfgtew)
1200 char buffer[IPR_MAX_RES_PATH_LENGTH];
1204 if (res->ioa_cfg->sis64) {
1205 res->flags = cfgtew->u.cfgte64->flags;
1206 res->res_flags = cfgtew->u.cfgte64->res_flags;
1207 res->type = cfgtew->u.cfgte64->res_type;
1209 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1210 sizeof(struct ipr_std_inq_data));
1212 res->qmodel = IPR_QUEUEING_MODEL64(res);
1213 proto = cfgtew->u.cfgte64->proto;
1214 res->res_handle = cfgtew->u.cfgte64->res_handle;
1215 res->dev_id = cfgtew->u.cfgte64->dev_id;
1217 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1218 sizeof(res->dev_lun.scsi_lun));
1220 if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1221 sizeof(res->res_path))) {
1222 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1223 sizeof(res->res_path));
1227 if (res->sdev && new_path)
1228 sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
1229 ipr_format_res_path(res->res_path, buffer,
1232 res->flags = cfgtew->u.cfgte->flags;
1233 if (res->flags & IPR_IS_IOA_RESOURCE)
1234 res->type = IPR_RES_TYPE_IOAFP;
1236 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1238 memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1239 sizeof(struct ipr_std_inq_data));
1241 res->qmodel = IPR_QUEUEING_MODEL(res);
1242 proto = cfgtew->u.cfgte->proto;
1243 res->res_handle = cfgtew->u.cfgte->res_handle;
1246 ipr_update_ata_class(res, proto);
1250 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1252 * @res: resource entry struct
1253 * @cfgtew: config table entry wrapper struct
1258 static void ipr_clear_res_target(struct ipr_resource_entry *res)
1260 struct ipr_resource_entry *gscsi_res = NULL;
1261 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1263 if (!ioa_cfg->sis64)
1266 if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1267 clear_bit(res->target, ioa_cfg->array_ids);
1268 else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1269 clear_bit(res->target, ioa_cfg->vset_ids);
1270 else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1271 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1272 if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1274 clear_bit(res->target, ioa_cfg->target_ids);
1276 } else if (res->bus == 0)
1277 clear_bit(res->target, ioa_cfg->target_ids);
1281 * ipr_handle_config_change - Handle a config change from the adapter
1282 * @ioa_cfg: ioa config struct
1288 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
1289 struct ipr_hostrcb *hostrcb)
1291 struct ipr_resource_entry *res = NULL;
1292 struct ipr_config_table_entry_wrapper cfgtew;
1293 __be32 cc_res_handle;
1297 if (ioa_cfg->sis64) {
1298 cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1299 cc_res_handle = cfgtew.u.cfgte64->res_handle;
1301 cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1302 cc_res_handle = cfgtew.u.cfgte->res_handle;
1305 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1306 if (res->res_handle == cc_res_handle) {
1313 if (list_empty(&ioa_cfg->free_res_q)) {
1314 ipr_send_hcam(ioa_cfg,
1315 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1320 res = list_entry(ioa_cfg->free_res_q.next,
1321 struct ipr_resource_entry, queue);
1323 list_del(&res->queue);
1324 ipr_init_res_entry(res, &cfgtew);
1325 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1328 ipr_update_res_entry(res, &cfgtew);
1330 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1332 res->del_from_ml = 1;
1333 res->res_handle = IPR_INVALID_RES_HANDLE;
1334 if (ioa_cfg->allow_ml_add_del)
1335 schedule_work(&ioa_cfg->work_q);
1337 ipr_clear_res_target(res);
1338 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
1340 } else if (!res->sdev || res->del_from_ml) {
1342 if (ioa_cfg->allow_ml_add_del)
1343 schedule_work(&ioa_cfg->work_q);
1346 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1350 * ipr_process_ccn - Op done function for a CCN.
1351 * @ipr_cmd: ipr command struct
1353 * This function is the op done function for a configuration
1354 * change notification host controlled async from the adapter.
1359 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1361 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1362 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1363 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
1365 list_del(&hostrcb->queue);
1366 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1369 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
1370 dev_err(&ioa_cfg->pdev->dev,
1371 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1373 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1375 ipr_handle_config_change(ioa_cfg, hostrcb);
1380 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1381 * @i: index into buffer
1382 * @buf: string to modify
1384 * This function will strip all trailing whitespace, pad the end
1385 * of the string with a single space, and NULL terminate the string.
1388 * new length of string
1390 static int strip_and_pad_whitespace(int i, char *buf)
1392 while (i && buf[i] == ' ')
1400 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1401 * @prefix: string to print at start of printk
1402 * @hostrcb: hostrcb pointer
1403 * @vpd: vendor/product id/sn struct
1408 static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1409 struct ipr_vpd *vpd)
1411 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
1414 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1415 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
1417 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
1418 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
1420 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1421 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1423 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1427 * ipr_log_vpd - Log the passed VPD to the error log.
1428 * @vpd: vendor/product id/sn struct
1433 static void ipr_log_vpd(struct ipr_vpd *vpd)
1435 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1436 + IPR_SERIAL_NUM_LEN];
1438 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1439 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
1441 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1442 ipr_err("Vendor/Product ID: %s\n", buffer);
1444 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
1445 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1446 ipr_err(" Serial Number: %s\n", buffer);
1450 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1451 * @prefix: string to print at start of printk
1452 * @hostrcb: hostrcb pointer
1453 * @vpd: vendor/product id/sn/wwn struct
1458 static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1459 struct ipr_ext_vpd *vpd)
1461 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1462 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1463 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1467 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1468 * @vpd: vendor/product id/sn/wwn struct
1473 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1475 ipr_log_vpd(&vpd->vpd);
1476 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1477 be32_to_cpu(vpd->wwid[1]));
1481 * ipr_log_enhanced_cache_error - Log a cache error.
1482 * @ioa_cfg: ioa config struct
1483 * @hostrcb: hostrcb struct
1488 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1489 struct ipr_hostrcb *hostrcb)
1491 struct ipr_hostrcb_type_12_error *error;
1494 error = &hostrcb->hcam.u.error64.u.type_12_error;
1496 error = &hostrcb->hcam.u.error.u.type_12_error;
1498 ipr_err("-----Current Configuration-----\n");
1499 ipr_err("Cache Directory Card Information:\n");
1500 ipr_log_ext_vpd(&error->ioa_vpd);
1501 ipr_err("Adapter Card Information:\n");
1502 ipr_log_ext_vpd(&error->cfc_vpd);
1504 ipr_err("-----Expected Configuration-----\n");
1505 ipr_err("Cache Directory Card Information:\n");
1506 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1507 ipr_err("Adapter Card Information:\n");
1508 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1510 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1511 be32_to_cpu(error->ioa_data[0]),
1512 be32_to_cpu(error->ioa_data[1]),
1513 be32_to_cpu(error->ioa_data[2]));
1517 * ipr_log_cache_error - Log a cache error.
1518 * @ioa_cfg: ioa config struct
1519 * @hostrcb: hostrcb struct
1524 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1525 struct ipr_hostrcb *hostrcb)
1527 struct ipr_hostrcb_type_02_error *error =
1528 &hostrcb->hcam.u.error.u.type_02_error;
1530 ipr_err("-----Current Configuration-----\n");
1531 ipr_err("Cache Directory Card Information:\n");
1532 ipr_log_vpd(&error->ioa_vpd);
1533 ipr_err("Adapter Card Information:\n");
1534 ipr_log_vpd(&error->cfc_vpd);
1536 ipr_err("-----Expected Configuration-----\n");
1537 ipr_err("Cache Directory Card Information:\n");
1538 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1539 ipr_err("Adapter Card Information:\n");
1540 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1542 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1543 be32_to_cpu(error->ioa_data[0]),
1544 be32_to_cpu(error->ioa_data[1]),
1545 be32_to_cpu(error->ioa_data[2]));
1549 * ipr_log_enhanced_config_error - Log a configuration error.
1550 * @ioa_cfg: ioa config struct
1551 * @hostrcb: hostrcb struct
1556 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1557 struct ipr_hostrcb *hostrcb)
1559 int errors_logged, i;
1560 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1561 struct ipr_hostrcb_type_13_error *error;
1563 error = &hostrcb->hcam.u.error.u.type_13_error;
1564 errors_logged = be32_to_cpu(error->errors_logged);
1566 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1567 be32_to_cpu(error->errors_detected), errors_logged);
1569 dev_entry = error->dev;
1571 for (i = 0; i < errors_logged; i++, dev_entry++) {
1574 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1575 ipr_log_ext_vpd(&dev_entry->vpd);
1577 ipr_err("-----New Device Information-----\n");
1578 ipr_log_ext_vpd(&dev_entry->new_vpd);
1580 ipr_err("Cache Directory Card Information:\n");
1581 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1583 ipr_err("Adapter Card Information:\n");
1584 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1589 * ipr_log_sis64_config_error - Log a device error.
1590 * @ioa_cfg: ioa config struct
1591 * @hostrcb: hostrcb struct
1596 static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
1597 struct ipr_hostrcb *hostrcb)
1599 int errors_logged, i;
1600 struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
1601 struct ipr_hostrcb_type_23_error *error;
1602 char buffer[IPR_MAX_RES_PATH_LENGTH];
1604 error = &hostrcb->hcam.u.error64.u.type_23_error;
1605 errors_logged = be32_to_cpu(error->errors_logged);
1607 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1608 be32_to_cpu(error->errors_detected), errors_logged);
1610 dev_entry = error->dev;
1612 for (i = 0; i < errors_logged; i++, dev_entry++) {
1615 ipr_err("Device %d : %s", i + 1,
1616 ipr_format_res_path(dev_entry->res_path, buffer,
1618 ipr_log_ext_vpd(&dev_entry->vpd);
1620 ipr_err("-----New Device Information-----\n");
1621 ipr_log_ext_vpd(&dev_entry->new_vpd);
1623 ipr_err("Cache Directory Card Information:\n");
1624 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1626 ipr_err("Adapter Card Information:\n");
1627 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1632 * ipr_log_config_error - Log a configuration error.
1633 * @ioa_cfg: ioa config struct
1634 * @hostrcb: hostrcb struct
1639 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1640 struct ipr_hostrcb *hostrcb)
1642 int errors_logged, i;
1643 struct ipr_hostrcb_device_data_entry *dev_entry;
1644 struct ipr_hostrcb_type_03_error *error;
1646 error = &hostrcb->hcam.u.error.u.type_03_error;
1647 errors_logged = be32_to_cpu(error->errors_logged);
1649 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1650 be32_to_cpu(error->errors_detected), errors_logged);
1652 dev_entry = error->dev;
1654 for (i = 0; i < errors_logged; i++, dev_entry++) {
1657 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1658 ipr_log_vpd(&dev_entry->vpd);
1660 ipr_err("-----New Device Information-----\n");
1661 ipr_log_vpd(&dev_entry->new_vpd);
1663 ipr_err("Cache Directory Card Information:\n");
1664 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1666 ipr_err("Adapter Card Information:\n");
1667 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1669 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1670 be32_to_cpu(dev_entry->ioa_data[0]),
1671 be32_to_cpu(dev_entry->ioa_data[1]),
1672 be32_to_cpu(dev_entry->ioa_data[2]),
1673 be32_to_cpu(dev_entry->ioa_data[3]),
1674 be32_to_cpu(dev_entry->ioa_data[4]));
1679 * ipr_log_enhanced_array_error - Log an array configuration error.
1680 * @ioa_cfg: ioa config struct
1681 * @hostrcb: hostrcb struct
1686 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1687 struct ipr_hostrcb *hostrcb)
1690 struct ipr_hostrcb_type_14_error *error;
1691 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1692 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1694 error = &hostrcb->hcam.u.error.u.type_14_error;
1698 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1699 error->protection_level,
1700 ioa_cfg->host->host_no,
1701 error->last_func_vset_res_addr.bus,
1702 error->last_func_vset_res_addr.target,
1703 error->last_func_vset_res_addr.lun);
1707 array_entry = error->array_member;
1708 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1709 ARRAY_SIZE(error->array_member));
1711 for (i = 0; i < num_entries; i++, array_entry++) {
1712 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1715 if (be32_to_cpu(error->exposed_mode_adn) == i)
1716 ipr_err("Exposed Array Member %d:\n", i);
1718 ipr_err("Array Member %d:\n", i);
1720 ipr_log_ext_vpd(&array_entry->vpd);
1721 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1722 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1723 "Expected Location");
1730 * ipr_log_array_error - Log an array configuration error.
1731 * @ioa_cfg: ioa config struct
1732 * @hostrcb: hostrcb struct
1737 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1738 struct ipr_hostrcb *hostrcb)
1741 struct ipr_hostrcb_type_04_error *error;
1742 struct ipr_hostrcb_array_data_entry *array_entry;
1743 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1745 error = &hostrcb->hcam.u.error.u.type_04_error;
1749 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1750 error->protection_level,
1751 ioa_cfg->host->host_no,
1752 error->last_func_vset_res_addr.bus,
1753 error->last_func_vset_res_addr.target,
1754 error->last_func_vset_res_addr.lun);
1758 array_entry = error->array_member;
1760 for (i = 0; i < 18; i++) {
1761 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1764 if (be32_to_cpu(error->exposed_mode_adn) == i)
1765 ipr_err("Exposed Array Member %d:\n", i);
1767 ipr_err("Array Member %d:\n", i);
1769 ipr_log_vpd(&array_entry->vpd);
1771 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1772 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1773 "Expected Location");
1778 array_entry = error->array_member2;
1785 * ipr_log_hex_data - Log additional hex IOA error data.
1786 * @ioa_cfg: ioa config struct
1787 * @data: IOA error data
1793 static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
1800 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1801 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1803 for (i = 0; i < len / 4; i += 4) {
1804 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1805 be32_to_cpu(data[i]),
1806 be32_to_cpu(data[i+1]),
1807 be32_to_cpu(data[i+2]),
1808 be32_to_cpu(data[i+3]));
1813 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1814 * @ioa_cfg: ioa config struct
1815 * @hostrcb: hostrcb struct
1820 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1821 struct ipr_hostrcb *hostrcb)
1823 struct ipr_hostrcb_type_17_error *error;
1826 error = &hostrcb->hcam.u.error64.u.type_17_error;
1828 error = &hostrcb->hcam.u.error.u.type_17_error;
1830 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1831 strim(error->failure_reason);
1833 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1834 be32_to_cpu(hostrcb->hcam.u.error.prc));
1835 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1836 ipr_log_hex_data(ioa_cfg, error->data,
1837 be32_to_cpu(hostrcb->hcam.length) -
1838 (offsetof(struct ipr_hostrcb_error, u) +
1839 offsetof(struct ipr_hostrcb_type_17_error, data)));
1843 * ipr_log_dual_ioa_error - Log a dual adapter error.
1844 * @ioa_cfg: ioa config struct
1845 * @hostrcb: hostrcb struct
1850 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1851 struct ipr_hostrcb *hostrcb)
1853 struct ipr_hostrcb_type_07_error *error;
1855 error = &hostrcb->hcam.u.error.u.type_07_error;
1856 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1857 strim(error->failure_reason);
1859 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1860 be32_to_cpu(hostrcb->hcam.u.error.prc));
1861 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1862 ipr_log_hex_data(ioa_cfg, error->data,
1863 be32_to_cpu(hostrcb->hcam.length) -
1864 (offsetof(struct ipr_hostrcb_error, u) +
1865 offsetof(struct ipr_hostrcb_type_07_error, data)));
1868 static const struct {
1871 } path_active_desc[] = {
1872 { IPR_PATH_NO_INFO, "Path" },
1873 { IPR_PATH_ACTIVE, "Active path" },
1874 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1877 static const struct {
1880 } path_state_desc[] = {
1881 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1882 { IPR_PATH_HEALTHY, "is healthy" },
1883 { IPR_PATH_DEGRADED, "is degraded" },
1884 { IPR_PATH_FAILED, "is failed" }
1888 * ipr_log_fabric_path - Log a fabric path error
1889 * @hostrcb: hostrcb struct
1890 * @fabric: fabric descriptor
1895 static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1896 struct ipr_hostrcb_fabric_desc *fabric)
1899 u8 path_state = fabric->path_state;
1900 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1901 u8 state = path_state & IPR_PATH_STATE_MASK;
1903 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1904 if (path_active_desc[i].active != active)
1907 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1908 if (path_state_desc[j].state != state)
1911 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
1912 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
1913 path_active_desc[i].desc, path_state_desc[j].desc,
1915 } else if (fabric->cascaded_expander == 0xff) {
1916 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
1917 path_active_desc[i].desc, path_state_desc[j].desc,
1918 fabric->ioa_port, fabric->phy);
1919 } else if (fabric->phy == 0xff) {
1920 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
1921 path_active_desc[i].desc, path_state_desc[j].desc,
1922 fabric->ioa_port, fabric->cascaded_expander);
1924 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1925 path_active_desc[i].desc, path_state_desc[j].desc,
1926 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1932 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
1933 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1937 * ipr_log64_fabric_path - Log a fabric path error
1938 * @hostrcb: hostrcb struct
1939 * @fabric: fabric descriptor
1944 static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
1945 struct ipr_hostrcb64_fabric_desc *fabric)
1948 u8 path_state = fabric->path_state;
1949 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1950 u8 state = path_state & IPR_PATH_STATE_MASK;
1951 char buffer[IPR_MAX_RES_PATH_LENGTH];
1953 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1954 if (path_active_desc[i].active != active)
1957 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1958 if (path_state_desc[j].state != state)
1961 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
1962 path_active_desc[i].desc, path_state_desc[j].desc,
1963 ipr_format_res_path(fabric->res_path, buffer,
1969 ipr_err("Path state=%02X Resource Path=%s\n", path_state,
1970 ipr_format_res_path(fabric->res_path, buffer, sizeof(buffer)));
1973 static const struct {
1976 } path_type_desc[] = {
1977 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
1978 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
1979 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
1980 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
1983 static const struct {
1986 } path_status_desc[] = {
1987 { IPR_PATH_CFG_NO_PROB, "Functional" },
1988 { IPR_PATH_CFG_DEGRADED, "Degraded" },
1989 { IPR_PATH_CFG_FAILED, "Failed" },
1990 { IPR_PATH_CFG_SUSPECT, "Suspect" },
1991 { IPR_PATH_NOT_DETECTED, "Missing" },
1992 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
1995 static const char *link_rate[] = {
1998 "phy reset problem",
2015 * ipr_log_path_elem - Log a fabric path element.
2016 * @hostrcb: hostrcb struct
2017 * @cfg: fabric path element struct
2022 static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
2023 struct ipr_hostrcb_config_element *cfg)
2026 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2027 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2029 if (type == IPR_PATH_CFG_NOT_EXIST)
2032 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2033 if (path_type_desc[i].type != type)
2036 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2037 if (path_status_desc[j].status != status)
2040 if (type == IPR_PATH_CFG_IOA_PORT) {
2041 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
2042 path_status_desc[j].desc, path_type_desc[i].desc,
2043 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2044 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2046 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
2047 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2048 path_status_desc[j].desc, path_type_desc[i].desc,
2049 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2050 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2051 } else if (cfg->cascaded_expander == 0xff) {
2052 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
2053 "WWN=%08X%08X\n", path_status_desc[j].desc,
2054 path_type_desc[i].desc, cfg->phy,
2055 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2056 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2057 } else if (cfg->phy == 0xff) {
2058 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
2059 "WWN=%08X%08X\n", path_status_desc[j].desc,
2060 path_type_desc[i].desc, cfg->cascaded_expander,
2061 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2062 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2064 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2065 "WWN=%08X%08X\n", path_status_desc[j].desc,
2066 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
2067 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2068 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2075 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2076 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
2077 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2078 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2082 * ipr_log64_path_elem - Log a fabric path element.
2083 * @hostrcb: hostrcb struct
2084 * @cfg: fabric path element struct
2089 static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
2090 struct ipr_hostrcb64_config_element *cfg)
2093 u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
2094 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2095 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2096 char buffer[IPR_MAX_RES_PATH_LENGTH];
2098 if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
2101 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2102 if (path_type_desc[i].type != type)
2105 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2106 if (path_status_desc[j].status != status)
2109 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2110 path_status_desc[j].desc, path_type_desc[i].desc,
2111 ipr_format_res_path(cfg->res_path, buffer,
2113 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2114 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2118 ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
2119 "WWN=%08X%08X\n", cfg->type_status,
2120 ipr_format_res_path(cfg->res_path, buffer, sizeof(buffer)),
2121 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2122 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2126 * ipr_log_fabric_error - Log a fabric error.
2127 * @ioa_cfg: ioa config struct
2128 * @hostrcb: hostrcb struct
2133 static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2134 struct ipr_hostrcb *hostrcb)
2136 struct ipr_hostrcb_type_20_error *error;
2137 struct ipr_hostrcb_fabric_desc *fabric;
2138 struct ipr_hostrcb_config_element *cfg;
2141 error = &hostrcb->hcam.u.error.u.type_20_error;
2142 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2143 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2145 add_len = be32_to_cpu(hostrcb->hcam.length) -
2146 (offsetof(struct ipr_hostrcb_error, u) +
2147 offsetof(struct ipr_hostrcb_type_20_error, desc));
2149 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2150 ipr_log_fabric_path(hostrcb, fabric);
2151 for_each_fabric_cfg(fabric, cfg)
2152 ipr_log_path_elem(hostrcb, cfg);
2154 add_len -= be16_to_cpu(fabric->length);
2155 fabric = (struct ipr_hostrcb_fabric_desc *)
2156 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2159 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2163 * ipr_log_sis64_array_error - Log a sis64 array error.
2164 * @ioa_cfg: ioa config struct
2165 * @hostrcb: hostrcb struct
2170 static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
2171 struct ipr_hostrcb *hostrcb)
2174 struct ipr_hostrcb_type_24_error *error;
2175 struct ipr_hostrcb64_array_data_entry *array_entry;
2176 char buffer[IPR_MAX_RES_PATH_LENGTH];
2177 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
2179 error = &hostrcb->hcam.u.error64.u.type_24_error;
2183 ipr_err("RAID %s Array Configuration: %s\n",
2184 error->protection_level,
2185 ipr_format_res_path(error->last_res_path, buffer, sizeof(buffer)));
2189 array_entry = error->array_member;
2190 num_entries = min_t(u32, error->num_entries,
2191 ARRAY_SIZE(error->array_member));
2193 for (i = 0; i < num_entries; i++, array_entry++) {
2195 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
2198 if (error->exposed_mode_adn == i)
2199 ipr_err("Exposed Array Member %d:\n", i);
2201 ipr_err("Array Member %d:\n", i);
2203 ipr_err("Array Member %d:\n", i);
2204 ipr_log_ext_vpd(&array_entry->vpd);
2205 ipr_err("Current Location: %s\n",
2206 ipr_format_res_path(array_entry->res_path, buffer,
2208 ipr_err("Expected Location: %s\n",
2209 ipr_format_res_path(array_entry->expected_res_path,
2210 buffer, sizeof(buffer)));
2217 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2218 * @ioa_cfg: ioa config struct
2219 * @hostrcb: hostrcb struct
2224 static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2225 struct ipr_hostrcb *hostrcb)
2227 struct ipr_hostrcb_type_30_error *error;
2228 struct ipr_hostrcb64_fabric_desc *fabric;
2229 struct ipr_hostrcb64_config_element *cfg;
2232 error = &hostrcb->hcam.u.error64.u.type_30_error;
2234 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2235 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2237 add_len = be32_to_cpu(hostrcb->hcam.length) -
2238 (offsetof(struct ipr_hostrcb64_error, u) +
2239 offsetof(struct ipr_hostrcb_type_30_error, desc));
2241 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2242 ipr_log64_fabric_path(hostrcb, fabric);
2243 for_each_fabric_cfg(fabric, cfg)
2244 ipr_log64_path_elem(hostrcb, cfg);
2246 add_len -= be16_to_cpu(fabric->length);
2247 fabric = (struct ipr_hostrcb64_fabric_desc *)
2248 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2251 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2255 * ipr_log_generic_error - Log an adapter error.
2256 * @ioa_cfg: ioa config struct
2257 * @hostrcb: hostrcb struct
2262 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
2263 struct ipr_hostrcb *hostrcb)
2265 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
2266 be32_to_cpu(hostrcb->hcam.length));
2270 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2273 * This function will return the index of into the ipr_error_table
2274 * for the specified IOASC. If the IOASC is not in the table,
2275 * 0 will be returned, which points to the entry used for unknown errors.
2278 * index into the ipr_error_table
2280 static u32 ipr_get_error(u32 ioasc)
2284 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
2285 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
2292 * ipr_handle_log_data - Log an adapter error.
2293 * @ioa_cfg: ioa config struct
2294 * @hostrcb: hostrcb struct
2296 * This function logs an adapter error to the system.
2301 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
2302 struct ipr_hostrcb *hostrcb)
2307 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
2310 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
2311 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
2314 ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2316 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2318 if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
2319 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
2320 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2321 scsi_report_bus_reset(ioa_cfg->host,
2322 hostrcb->hcam.u.error.fd_res_addr.bus);
2325 error_index = ipr_get_error(ioasc);
2327 if (!ipr_error_table[error_index].log_hcam)
2330 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
2332 /* Set indication we have logged an error */
2333 ioa_cfg->errors_logged++;
2335 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
2337 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
2338 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
2340 switch (hostrcb->hcam.overlay_id) {
2341 case IPR_HOST_RCB_OVERLAY_ID_2:
2342 ipr_log_cache_error(ioa_cfg, hostrcb);
2344 case IPR_HOST_RCB_OVERLAY_ID_3:
2345 ipr_log_config_error(ioa_cfg, hostrcb);
2347 case IPR_HOST_RCB_OVERLAY_ID_4:
2348 case IPR_HOST_RCB_OVERLAY_ID_6:
2349 ipr_log_array_error(ioa_cfg, hostrcb);
2351 case IPR_HOST_RCB_OVERLAY_ID_7:
2352 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
2354 case IPR_HOST_RCB_OVERLAY_ID_12:
2355 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
2357 case IPR_HOST_RCB_OVERLAY_ID_13:
2358 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
2360 case IPR_HOST_RCB_OVERLAY_ID_14:
2361 case IPR_HOST_RCB_OVERLAY_ID_16:
2362 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
2364 case IPR_HOST_RCB_OVERLAY_ID_17:
2365 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
2367 case IPR_HOST_RCB_OVERLAY_ID_20:
2368 ipr_log_fabric_error(ioa_cfg, hostrcb);
2370 case IPR_HOST_RCB_OVERLAY_ID_23:
2371 ipr_log_sis64_config_error(ioa_cfg, hostrcb);
2373 case IPR_HOST_RCB_OVERLAY_ID_24:
2374 case IPR_HOST_RCB_OVERLAY_ID_26:
2375 ipr_log_sis64_array_error(ioa_cfg, hostrcb);
2377 case IPR_HOST_RCB_OVERLAY_ID_30:
2378 ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
2380 case IPR_HOST_RCB_OVERLAY_ID_1:
2381 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
2383 ipr_log_generic_error(ioa_cfg, hostrcb);
2389 * ipr_process_error - Op done function for an adapter error log.
2390 * @ipr_cmd: ipr command struct
2392 * This function is the op done function for an error log host
2393 * controlled async from the adapter. It will log the error and
2394 * send the HCAM back to the adapter.
2399 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2401 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2402 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
2403 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
2407 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2409 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2411 list_del(&hostrcb->queue);
2412 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
2415 ipr_handle_log_data(ioa_cfg, hostrcb);
2416 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
2417 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
2418 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
2419 dev_err(&ioa_cfg->pdev->dev,
2420 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
2423 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2427 * ipr_timeout - An internally generated op has timed out.
2428 * @ipr_cmd: ipr command struct
2430 * This function blocks host requests and initiates an
2436 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
2438 unsigned long lock_flags = 0;
2439 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2442 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2444 ioa_cfg->errors_logged++;
2445 dev_err(&ioa_cfg->pdev->dev,
2446 "Adapter being reset due to command timeout.\n");
2448 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2449 ioa_cfg->sdt_state = GET_DUMP;
2451 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
2452 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2454 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2459 * ipr_oper_timeout - Adapter timed out transitioning to operational
2460 * @ipr_cmd: ipr command struct
2462 * This function blocks host requests and initiates an
2468 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
2470 unsigned long lock_flags = 0;
2471 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2474 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2476 ioa_cfg->errors_logged++;
2477 dev_err(&ioa_cfg->pdev->dev,
2478 "Adapter timed out transitioning to operational.\n");
2480 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2481 ioa_cfg->sdt_state = GET_DUMP;
2483 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
2485 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
2486 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2489 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2494 * ipr_reset_reload - Reset/Reload the IOA
2495 * @ioa_cfg: ioa config struct
2496 * @shutdown_type: shutdown type
2498 * This function resets the adapter and re-initializes it.
2499 * This function assumes that all new host commands have been stopped.
2503 static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
2504 enum ipr_shutdown_type shutdown_type)
2506 if (!ioa_cfg->in_reset_reload)
2507 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
2509 spin_unlock_irq(ioa_cfg->host->host_lock);
2510 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2511 spin_lock_irq(ioa_cfg->host->host_lock);
2513 /* If we got hit with a host reset while we were already resetting
2514 the adapter for some reason, and the reset failed. */
2515 if (ioa_cfg->ioa_is_dead) {
2524 * ipr_find_ses_entry - Find matching SES in SES table
2525 * @res: resource entry struct of SES
2528 * pointer to SES table entry / NULL on failure
2530 static const struct ipr_ses_table_entry *
2531 ipr_find_ses_entry(struct ipr_resource_entry *res)
2534 struct ipr_std_inq_vpids *vpids;
2535 const struct ipr_ses_table_entry *ste = ipr_ses_table;
2537 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
2538 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
2539 if (ste->compare_product_id_byte[j] == 'X') {
2540 vpids = &res->std_inq_data.vpids;
2541 if (vpids->product_id[j] == ste->product_id[j])
2549 if (matches == IPR_PROD_ID_LEN)
2557 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2558 * @ioa_cfg: ioa config struct
2560 * @bus_width: bus width
2563 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2564 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2565 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2566 * max 160MHz = max 320MB/sec).
2568 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
2570 struct ipr_resource_entry *res;
2571 const struct ipr_ses_table_entry *ste;
2572 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
2574 /* Loop through each config table entry in the config table buffer */
2575 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2576 if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
2579 if (bus != res->bus)
2582 if (!(ste = ipr_find_ses_entry(res)))
2585 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
2588 return max_xfer_rate;
2592 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2593 * @ioa_cfg: ioa config struct
2594 * @max_delay: max delay in micro-seconds to wait
2596 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2599 * 0 on success / other on failure
2601 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
2603 volatile u32 pcii_reg;
2606 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2607 while (delay < max_delay) {
2608 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
2610 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
2613 /* udelay cannot be used if delay is more than a few milliseconds */
2614 if ((delay / 1000) > MAX_UDELAY_MS)
2615 mdelay(delay / 1000);
2625 * ipr_get_sis64_dump_data_section - Dump IOA memory
2626 * @ioa_cfg: ioa config struct
2627 * @start_addr: adapter address to dump
2628 * @dest: destination kernel buffer
2629 * @length_in_words: length to dump in 4 byte words
2634 static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2636 __be32 *dest, u32 length_in_words)
2640 for (i = 0; i < length_in_words; i++) {
2641 writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
2642 *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
2650 * ipr_get_ldump_data_section - Dump IOA memory
2651 * @ioa_cfg: ioa config struct
2652 * @start_addr: adapter address to dump
2653 * @dest: destination kernel buffer
2654 * @length_in_words: length to dump in 4 byte words
2657 * 0 on success / -EIO on failure
2659 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2661 __be32 *dest, u32 length_in_words)
2663 volatile u32 temp_pcii_reg;
2667 return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
2668 dest, length_in_words);
2670 /* Write IOA interrupt reg starting LDUMP state */
2671 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
2672 ioa_cfg->regs.set_uproc_interrupt_reg32);
2674 /* Wait for IO debug acknowledge */
2675 if (ipr_wait_iodbg_ack(ioa_cfg,
2676 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
2677 dev_err(&ioa_cfg->pdev->dev,
2678 "IOA dump long data transfer timeout\n");
2682 /* Signal LDUMP interlocked - clear IO debug ack */
2683 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2684 ioa_cfg->regs.clr_interrupt_reg);
2686 /* Write Mailbox with starting address */
2687 writel(start_addr, ioa_cfg->ioa_mailbox);
2689 /* Signal address valid - clear IOA Reset alert */
2690 writel(IPR_UPROCI_RESET_ALERT,
2691 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2693 for (i = 0; i < length_in_words; i++) {
2694 /* Wait for IO debug acknowledge */
2695 if (ipr_wait_iodbg_ack(ioa_cfg,
2696 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2697 dev_err(&ioa_cfg->pdev->dev,
2698 "IOA dump short data transfer timeout\n");
2702 /* Read data from mailbox and increment destination pointer */
2703 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2706 /* For all but the last word of data, signal data received */
2707 if (i < (length_in_words - 1)) {
2708 /* Signal dump data received - Clear IO debug Ack */
2709 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2710 ioa_cfg->regs.clr_interrupt_reg);
2714 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2715 writel(IPR_UPROCI_RESET_ALERT,
2716 ioa_cfg->regs.set_uproc_interrupt_reg32);
2718 writel(IPR_UPROCI_IO_DEBUG_ALERT,
2719 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2721 /* Signal dump data received - Clear IO debug Ack */
2722 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2723 ioa_cfg->regs.clr_interrupt_reg);
2725 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2726 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2728 readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
2730 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2740 #ifdef CONFIG_SCSI_IPR_DUMP
2742 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2743 * @ioa_cfg: ioa config struct
2744 * @pci_address: adapter address
2745 * @length: length of data to copy
2747 * Copy data from PCI adapter to kernel buffer.
2748 * Note: length MUST be a 4 byte multiple
2750 * 0 on success / other on failure
2752 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2753 unsigned long pci_address, u32 length)
2755 int bytes_copied = 0;
2756 int cur_len, rc, rem_len, rem_page_len, max_dump_size;
2758 unsigned long lock_flags = 0;
2759 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2762 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2764 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2766 while (bytes_copied < length &&
2767 (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
2768 if (ioa_dump->page_offset >= PAGE_SIZE ||
2769 ioa_dump->page_offset == 0) {
2770 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2774 return bytes_copied;
2777 ioa_dump->page_offset = 0;
2778 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2779 ioa_dump->next_page_index++;
2781 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2783 rem_len = length - bytes_copied;
2784 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2785 cur_len = min(rem_len, rem_page_len);
2787 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2788 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2791 rc = ipr_get_ldump_data_section(ioa_cfg,
2792 pci_address + bytes_copied,
2793 &page[ioa_dump->page_offset / 4],
2794 (cur_len / sizeof(u32)));
2796 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2799 ioa_dump->page_offset += cur_len;
2800 bytes_copied += cur_len;
2808 return bytes_copied;
2812 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2813 * @hdr: dump entry header struct
2818 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2820 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2822 hdr->offset = sizeof(*hdr);
2823 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2827 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2828 * @ioa_cfg: ioa config struct
2829 * @driver_dump: driver dump struct
2834 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2835 struct ipr_driver_dump *driver_dump)
2837 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2839 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2840 driver_dump->ioa_type_entry.hdr.len =
2841 sizeof(struct ipr_dump_ioa_type_entry) -
2842 sizeof(struct ipr_dump_entry_header);
2843 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2844 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2845 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2846 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2847 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2848 ucode_vpd->minor_release[1];
2849 driver_dump->hdr.num_entries++;
2853 * ipr_dump_version_data - Fill in the driver version in the dump.
2854 * @ioa_cfg: ioa config struct
2855 * @driver_dump: driver dump struct
2860 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2861 struct ipr_driver_dump *driver_dump)
2863 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2864 driver_dump->version_entry.hdr.len =
2865 sizeof(struct ipr_dump_version_entry) -
2866 sizeof(struct ipr_dump_entry_header);
2867 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2868 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2869 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2870 driver_dump->hdr.num_entries++;
2874 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2875 * @ioa_cfg: ioa config struct
2876 * @driver_dump: driver dump struct
2881 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
2882 struct ipr_driver_dump *driver_dump)
2884 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
2885 driver_dump->trace_entry.hdr.len =
2886 sizeof(struct ipr_dump_trace_entry) -
2887 sizeof(struct ipr_dump_entry_header);
2888 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2889 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
2890 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
2891 driver_dump->hdr.num_entries++;
2895 * ipr_dump_location_data - Fill in the IOA location in the dump.
2896 * @ioa_cfg: ioa config struct
2897 * @driver_dump: driver dump struct
2902 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
2903 struct ipr_driver_dump *driver_dump)
2905 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
2906 driver_dump->location_entry.hdr.len =
2907 sizeof(struct ipr_dump_location_entry) -
2908 sizeof(struct ipr_dump_entry_header);
2909 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2910 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
2911 strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
2912 driver_dump->hdr.num_entries++;
2916 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2917 * @ioa_cfg: ioa config struct
2918 * @dump: dump struct
2923 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
2925 unsigned long start_addr, sdt_word;
2926 unsigned long lock_flags = 0;
2927 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
2928 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
2929 u32 num_entries, max_num_entries, start_off, end_off;
2930 u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
2931 struct ipr_sdt *sdt;
2937 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2939 if (ioa_cfg->sdt_state != READ_DUMP) {
2940 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2944 if (ioa_cfg->sis64) {
2945 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2946 ssleep(IPR_DUMP_DELAY_SECONDS);
2947 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2950 start_addr = readl(ioa_cfg->ioa_mailbox);
2952 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
2953 dev_err(&ioa_cfg->pdev->dev,
2954 "Invalid dump table format: %lx\n", start_addr);
2955 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2959 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
2961 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
2963 /* Initialize the overall dump header */
2964 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
2965 driver_dump->hdr.num_entries = 1;
2966 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
2967 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
2968 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
2969 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
2971 ipr_dump_version_data(ioa_cfg, driver_dump);
2972 ipr_dump_location_data(ioa_cfg, driver_dump);
2973 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
2974 ipr_dump_trace_data(ioa_cfg, driver_dump);
2976 /* Update dump_header */
2977 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
2979 /* IOA Dump entry */
2980 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
2981 ioa_dump->hdr.len = 0;
2982 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2983 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
2985 /* First entries in sdt are actually a list of dump addresses and
2986 lengths to gather the real dump data. sdt represents the pointer
2987 to the ioa generated dump table. Dump data will be extracted based
2988 on entries in this table */
2989 sdt = &ioa_dump->sdt;
2991 if (ioa_cfg->sis64) {
2992 max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
2993 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2995 max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
2996 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2999 bytes_to_copy = offsetof(struct ipr_sdt, entry) +
3000 (max_num_entries * sizeof(struct ipr_sdt_entry));
3001 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
3002 bytes_to_copy / sizeof(__be32));
3004 /* Smart Dump table is ready to use and the first entry is valid */
3005 if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
3006 (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
3007 dev_err(&ioa_cfg->pdev->dev,
3008 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
3009 rc, be32_to_cpu(sdt->hdr.state));
3010 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
3011 ioa_cfg->sdt_state = DUMP_OBTAINED;
3012 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3016 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
3018 if (num_entries > max_num_entries)
3019 num_entries = max_num_entries;
3021 /* Update dump length to the actual data to be copied */
3022 dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
3024 dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
3026 dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
3028 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3030 for (i = 0; i < num_entries; i++) {
3031 if (ioa_dump->hdr.len > max_dump_size) {
3032 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3036 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
3037 sdt_word = be32_to_cpu(sdt->entry[i].start_token);
3039 bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
3041 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
3042 end_off = be32_to_cpu(sdt->entry[i].end_token);
3044 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
3045 bytes_to_copy = end_off - start_off;
3050 if (bytes_to_copy > max_dump_size) {
3051 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
3055 /* Copy data from adapter to driver buffers */
3056 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
3059 ioa_dump->hdr.len += bytes_copied;
3061 if (bytes_copied != bytes_to_copy) {
3062 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3069 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
3071 /* Update dump_header */
3072 driver_dump->hdr.len += ioa_dump->hdr.len;
3074 ioa_cfg->sdt_state = DUMP_OBTAINED;
3079 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
3083 * ipr_release_dump - Free adapter dump memory
3084 * @kref: kref struct
3089 static void ipr_release_dump(struct kref *kref)
3091 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
3092 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
3093 unsigned long lock_flags = 0;
3097 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3098 ioa_cfg->dump = NULL;
3099 ioa_cfg->sdt_state = INACTIVE;
3100 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3102 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
3103 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
3105 vfree(dump->ioa_dump.ioa_data);
3111 * ipr_worker_thread - Worker thread
3112 * @work: ioa config struct
3114 * Called at task level from a work thread. This function takes care
3115 * of adding and removing device from the mid-layer as configuration
3116 * changes are detected by the adapter.
3121 static void ipr_worker_thread(struct work_struct *work)
3123 unsigned long lock_flags;
3124 struct ipr_resource_entry *res;
3125 struct scsi_device *sdev;
3126 struct ipr_dump *dump;
3127 struct ipr_ioa_cfg *ioa_cfg =
3128 container_of(work, struct ipr_ioa_cfg, work_q);
3129 u8 bus, target, lun;
3133 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3135 if (ioa_cfg->sdt_state == READ_DUMP) {
3136 dump = ioa_cfg->dump;
3138 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3141 kref_get(&dump->kref);
3142 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3143 ipr_get_ioa_dump(ioa_cfg, dump);
3144 kref_put(&dump->kref, ipr_release_dump);
3146 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3147 if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
3148 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3149 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3156 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
3157 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3161 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3162 if (res->del_from_ml && res->sdev) {
3165 if (!scsi_device_get(sdev)) {
3166 if (!res->add_to_ml)
3167 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
3169 res->del_from_ml = 0;
3170 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3171 scsi_remove_device(sdev);
3172 scsi_device_put(sdev);
3173 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3180 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3181 if (res->add_to_ml) {
3183 target = res->target;
3186 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3187 scsi_add_device(ioa_cfg->host, bus, target, lun);
3188 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3193 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3194 kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
3198 #ifdef CONFIG_SCSI_IPR_TRACE
3200 * ipr_read_trace - Dump the adapter trace
3201 * @filp: open sysfs file
3202 * @kobj: kobject struct
3203 * @bin_attr: bin_attribute struct
3206 * @count: buffer size
3209 * number of bytes printed to buffer
3211 static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
3212 struct bin_attribute *bin_attr,
3213 char *buf, loff_t off, size_t count)
3215 struct device *dev = container_of(kobj, struct device, kobj);
3216 struct Scsi_Host *shost = class_to_shost(dev);
3217 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3218 unsigned long lock_flags = 0;
3221 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3222 ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
3224 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3229 static struct bin_attribute ipr_trace_attr = {
3235 .read = ipr_read_trace,
3240 * ipr_show_fw_version - Show the firmware version
3241 * @dev: class device struct
3245 * number of bytes printed to buffer
3247 static ssize_t ipr_show_fw_version(struct device *dev,
3248 struct device_attribute *attr, char *buf)
3250 struct Scsi_Host *shost = class_to_shost(dev);
3251 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3252 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
3253 unsigned long lock_flags = 0;
3256 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3257 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
3258 ucode_vpd->major_release, ucode_vpd->card_type,
3259 ucode_vpd->minor_release[0],
3260 ucode_vpd->minor_release[1]);
3261 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3265 static struct device_attribute ipr_fw_version_attr = {
3267 .name = "fw_version",
3270 .show = ipr_show_fw_version,
3274 * ipr_show_log_level - Show the adapter's error logging level
3275 * @dev: class device struct
3279 * number of bytes printed to buffer
3281 static ssize_t ipr_show_log_level(struct device *dev,
3282 struct device_attribute *attr, char *buf)
3284 struct Scsi_Host *shost = class_to_shost(dev);
3285 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3286 unsigned long lock_flags = 0;
3289 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3290 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
3291 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3296 * ipr_store_log_level - Change the adapter's error logging level
3297 * @dev: class device struct
3301 * number of bytes printed to buffer
3303 static ssize_t ipr_store_log_level(struct device *dev,
3304 struct device_attribute *attr,
3305 const char *buf, size_t count)
3307 struct Scsi_Host *shost = class_to_shost(dev);
3308 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3309 unsigned long lock_flags = 0;
3311 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3312 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
3313 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3317 static struct device_attribute ipr_log_level_attr = {
3319 .name = "log_level",
3320 .mode = S_IRUGO | S_IWUSR,
3322 .show = ipr_show_log_level,
3323 .store = ipr_store_log_level
3327 * ipr_store_diagnostics - IOA Diagnostics interface
3328 * @dev: device struct
3330 * @count: buffer size
3332 * This function will reset the adapter and wait a reasonable
3333 * amount of time for any errors that the adapter might log.
3336 * count on success / other on failure
3338 static ssize_t ipr_store_diagnostics(struct device *dev,
3339 struct device_attribute *attr,
3340 const char *buf, size_t count)
3342 struct Scsi_Host *shost = class_to_shost(dev);
3343 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3344 unsigned long lock_flags = 0;
3347 if (!capable(CAP_SYS_ADMIN))
3350 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3351 while(ioa_cfg->in_reset_reload) {
3352 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3353 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3354 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3357 ioa_cfg->errors_logged = 0;
3358 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3360 if (ioa_cfg->in_reset_reload) {
3361 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3362 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3364 /* Wait for a second for any errors to be logged */
3367 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3371 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3372 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
3374 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3379 static struct device_attribute ipr_diagnostics_attr = {
3381 .name = "run_diagnostics",
3384 .store = ipr_store_diagnostics
3388 * ipr_show_adapter_state - Show the adapter's state
3389 * @class_dev: device struct
3393 * number of bytes printed to buffer
3395 static ssize_t ipr_show_adapter_state(struct device *dev,
3396 struct device_attribute *attr, char *buf)
3398 struct Scsi_Host *shost = class_to_shost(dev);
3399 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3400 unsigned long lock_flags = 0;
3403 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3404 if (ioa_cfg->ioa_is_dead)
3405 len = snprintf(buf, PAGE_SIZE, "offline\n");
3407 len = snprintf(buf, PAGE_SIZE, "online\n");
3408 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3413 * ipr_store_adapter_state - Change adapter state
3414 * @dev: device struct
3416 * @count: buffer size
3418 * This function will change the adapter's state.
3421 * count on success / other on failure
3423 static ssize_t ipr_store_adapter_state(struct device *dev,
3424 struct device_attribute *attr,
3425 const char *buf, size_t count)
3427 struct Scsi_Host *shost = class_to_shost(dev);
3428 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3429 unsigned long lock_flags;
3432 if (!capable(CAP_SYS_ADMIN))
3435 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3436 if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
3437 ioa_cfg->ioa_is_dead = 0;
3438 ioa_cfg->reset_retries = 0;
3439 ioa_cfg->in_ioa_bringdown = 0;
3440 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3442 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3443 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3448 static struct device_attribute ipr_ioa_state_attr = {
3450 .name = "online_state",
3451 .mode = S_IRUGO | S_IWUSR,
3453 .show = ipr_show_adapter_state,
3454 .store = ipr_store_adapter_state
3458 * ipr_store_reset_adapter - Reset the adapter
3459 * @dev: device struct
3461 * @count: buffer size
3463 * This function will reset the adapter.
3466 * count on success / other on failure
3468 static ssize_t ipr_store_reset_adapter(struct device *dev,
3469 struct device_attribute *attr,
3470 const char *buf, size_t count)
3472 struct Scsi_Host *shost = class_to_shost(dev);
3473 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3474 unsigned long lock_flags;
3477 if (!capable(CAP_SYS_ADMIN))
3480 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3481 if (!ioa_cfg->in_reset_reload)
3482 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3483 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3484 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3489 static struct device_attribute ipr_ioa_reset_attr = {
3491 .name = "reset_host",
3494 .store = ipr_store_reset_adapter
3498 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3499 * @buf_len: buffer length
3501 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3502 * list to use for microcode download
3505 * pointer to sglist / NULL on failure
3507 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
3509 int sg_size, order, bsize_elem, num_elem, i, j;
3510 struct ipr_sglist *sglist;
3511 struct scatterlist *scatterlist;
3514 /* Get the minimum size per scatter/gather element */
3515 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
3517 /* Get the actual size per element */
3518 order = get_order(sg_size);
3520 /* Determine the actual number of bytes per element */
3521 bsize_elem = PAGE_SIZE * (1 << order);
3523 /* Determine the actual number of sg entries needed */
3524 if (buf_len % bsize_elem)
3525 num_elem = (buf_len / bsize_elem) + 1;
3527 num_elem = buf_len / bsize_elem;
3529 /* Allocate a scatter/gather list for the DMA */
3530 sglist = kzalloc(sizeof(struct ipr_sglist) +
3531 (sizeof(struct scatterlist) * (num_elem - 1)),
3534 if (sglist == NULL) {
3539 scatterlist = sglist->scatterlist;
3540 sg_init_table(scatterlist, num_elem);
3542 sglist->order = order;
3543 sglist->num_sg = num_elem;
3545 /* Allocate a bunch of sg elements */
3546 for (i = 0; i < num_elem; i++) {
3547 page = alloc_pages(GFP_KERNEL, order);
3551 /* Free up what we already allocated */
3552 for (j = i - 1; j >= 0; j--)
3553 __free_pages(sg_page(&scatterlist[j]), order);
3558 sg_set_page(&scatterlist[i], page, 0, 0);
3565 * ipr_free_ucode_buffer - Frees a microcode download buffer
3566 * @p_dnld: scatter/gather list pointer
3568 * Free a DMA'able ucode download buffer previously allocated with
3569 * ipr_alloc_ucode_buffer
3574 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
3578 for (i = 0; i < sglist->num_sg; i++)
3579 __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
3585 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3586 * @sglist: scatter/gather list pointer
3587 * @buffer: buffer pointer
3588 * @len: buffer length
3590 * Copy a microcode image from a user buffer into a buffer allocated by
3591 * ipr_alloc_ucode_buffer
3594 * 0 on success / other on failure
3596 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
3597 u8 *buffer, u32 len)
3599 int bsize_elem, i, result = 0;
3600 struct scatterlist *scatterlist;
3603 /* Determine the actual number of bytes per element */
3604 bsize_elem = PAGE_SIZE * (1 << sglist->order);
3606 scatterlist = sglist->scatterlist;
3608 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
3609 struct page *page = sg_page(&scatterlist[i]);
3612 memcpy(kaddr, buffer, bsize_elem);
3615 scatterlist[i].length = bsize_elem;
3623 if (len % bsize_elem) {
3624 struct page *page = sg_page(&scatterlist[i]);
3627 memcpy(kaddr, buffer, len % bsize_elem);
3630 scatterlist[i].length = len % bsize_elem;
3633 sglist->buffer_len = len;
3638 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3639 * @ipr_cmd: ipr command struct
3640 * @sglist: scatter/gather list
3642 * Builds a microcode download IOA data list (IOADL).
3645 static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
3646 struct ipr_sglist *sglist)
3648 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3649 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
3650 struct scatterlist *scatterlist = sglist->scatterlist;
3653 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3654 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3655 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3658 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
3659 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3660 ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
3661 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
3662 ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
3665 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3669 * ipr_build_ucode_ioadl - Build a microcode download IOADL
3670 * @ipr_cmd: ipr command struct
3671 * @sglist: scatter/gather list
3673 * Builds a microcode download IOA data list (IOADL).
3676 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
3677 struct ipr_sglist *sglist)
3679 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3680 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
3681 struct scatterlist *scatterlist = sglist->scatterlist;
3684 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3685 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3686 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3689 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3691 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3692 ioadl[i].flags_and_data_len =
3693 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
3695 cpu_to_be32(sg_dma_address(&scatterlist[i]));
3698 ioadl[i-1].flags_and_data_len |=
3699 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3703 * ipr_update_ioa_ucode - Update IOA's microcode
3704 * @ioa_cfg: ioa config struct
3705 * @sglist: scatter/gather list
3707 * Initiate an adapter reset to update the IOA's microcode
3710 * 0 on success / -EIO on failure
3712 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3713 struct ipr_sglist *sglist)
3715 unsigned long lock_flags;
3717 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3718 while(ioa_cfg->in_reset_reload) {
3719 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3720 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3721 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3724 if (ioa_cfg->ucode_sglist) {
3725 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3726 dev_err(&ioa_cfg->pdev->dev,
3727 "Microcode download already in progress\n");
3731 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
3732 sglist->num_sg, DMA_TO_DEVICE);
3734 if (!sglist->num_dma_sg) {
3735 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3736 dev_err(&ioa_cfg->pdev->dev,
3737 "Failed to map microcode download buffer!\n");
3741 ioa_cfg->ucode_sglist = sglist;
3742 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3743 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3744 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3746 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3747 ioa_cfg->ucode_sglist = NULL;
3748 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3753 * ipr_store_update_fw - Update the firmware on the adapter
3754 * @class_dev: device struct
3756 * @count: buffer size
3758 * This function will update the firmware on the adapter.
3761 * count on success / other on failure
3763 static ssize_t ipr_store_update_fw(struct device *dev,
3764 struct device_attribute *attr,
3765 const char *buf, size_t count)
3767 struct Scsi_Host *shost = class_to_shost(dev);
3768 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3769 struct ipr_ucode_image_header *image_hdr;
3770 const struct firmware *fw_entry;
3771 struct ipr_sglist *sglist;
3774 int len, result, dnld_size;
3776 if (!capable(CAP_SYS_ADMIN))
3779 len = snprintf(fname, 99, "%s", buf);
3780 fname[len-1] = '\0';
3782 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3783 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3787 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
3789 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
3790 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
3791 sglist = ipr_alloc_ucode_buffer(dnld_size);
3794 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
3795 release_firmware(fw_entry);
3799 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
3802 dev_err(&ioa_cfg->pdev->dev,
3803 "Microcode buffer copy to DMA buffer failed\n");
3807 ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
3809 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
3814 ipr_free_ucode_buffer(sglist);
3815 release_firmware(fw_entry);
3819 static struct device_attribute ipr_update_fw_attr = {
3821 .name = "update_fw",
3824 .store = ipr_store_update_fw
3828 * ipr_show_fw_type - Show the adapter's firmware type.
3829 * @dev: class device struct
3833 * number of bytes printed to buffer
3835 static ssize_t ipr_show_fw_type(struct device *dev,
3836 struct device_attribute *attr, char *buf)
3838 struct Scsi_Host *shost = class_to_shost(dev);
3839 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3840 unsigned long lock_flags = 0;
3843 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3844 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
3845 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3849 static struct device_attribute ipr_ioa_fw_type_attr = {
3854 .show = ipr_show_fw_type
3857 static struct device_attribute *ipr_ioa_attrs[] = {
3858 &ipr_fw_version_attr,
3859 &ipr_log_level_attr,
3860 &ipr_diagnostics_attr,
3861 &ipr_ioa_state_attr,
3862 &ipr_ioa_reset_attr,
3863 &ipr_update_fw_attr,
3864 &ipr_ioa_fw_type_attr,
3868 #ifdef CONFIG_SCSI_IPR_DUMP
3870 * ipr_read_dump - Dump the adapter
3871 * @filp: open sysfs file
3872 * @kobj: kobject struct
3873 * @bin_attr: bin_attribute struct
3876 * @count: buffer size
3879 * number of bytes printed to buffer
3881 static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
3882 struct bin_attribute *bin_attr,
3883 char *buf, loff_t off, size_t count)
3885 struct device *cdev = container_of(kobj, struct device, kobj);
3886 struct Scsi_Host *shost = class_to_shost(cdev);
3887 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3888 struct ipr_dump *dump;
3889 unsigned long lock_flags = 0;
3894 if (!capable(CAP_SYS_ADMIN))
3897 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3898 dump = ioa_cfg->dump;
3900 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
3901 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3904 kref_get(&dump->kref);
3905 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3907 if (off > dump->driver_dump.hdr.len) {
3908 kref_put(&dump->kref, ipr_release_dump);
3912 if (off + count > dump->driver_dump.hdr.len) {
3913 count = dump->driver_dump.hdr.len - off;
3917 if (count && off < sizeof(dump->driver_dump)) {
3918 if (off + count > sizeof(dump->driver_dump))
3919 len = sizeof(dump->driver_dump) - off;
3922 src = (u8 *)&dump->driver_dump + off;
3923 memcpy(buf, src, len);
3929 off -= sizeof(dump->driver_dump);
3932 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
3933 (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
3934 sizeof(struct ipr_sdt_entry));
3936 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
3937 (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
3939 if (count && off < sdt_end) {
3940 if (off + count > sdt_end)
3941 len = sdt_end - off;
3944 src = (u8 *)&dump->ioa_dump + off;
3945 memcpy(buf, src, len);
3954 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
3955 len = PAGE_ALIGN(off) - off;
3958 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
3959 src += off & ~PAGE_MASK;
3960 memcpy(buf, src, len);
3966 kref_put(&dump->kref, ipr_release_dump);
3971 * ipr_alloc_dump - Prepare for adapter dump
3972 * @ioa_cfg: ioa config struct
3975 * 0 on success / other on failure
3977 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
3979 struct ipr_dump *dump;
3981 unsigned long lock_flags = 0;
3983 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
3986 ipr_err("Dump memory allocation failed\n");
3991 ioa_data = vmalloc(IPR_FMT3_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
3993 ioa_data = vmalloc(IPR_FMT2_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
3996 ipr_err("Dump memory allocation failed\n");
4001 dump->ioa_dump.ioa_data = ioa_data;
4003 kref_init(&dump->kref);
4004 dump->ioa_cfg = ioa_cfg;
4006 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4008 if (INACTIVE != ioa_cfg->sdt_state) {
4009 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4010 vfree(dump->ioa_dump.ioa_data);
4015 ioa_cfg->dump = dump;
4016 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
4017 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
4018 ioa_cfg->dump_taken = 1;
4019 schedule_work(&ioa_cfg->work_q);
4021 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4027 * ipr_free_dump - Free adapter dump memory
4028 * @ioa_cfg: ioa config struct
4031 * 0 on success / other on failure
4033 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
4035 struct ipr_dump *dump;
4036 unsigned long lock_flags = 0;
4040 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4041 dump = ioa_cfg->dump;
4043 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4047 ioa_cfg->dump = NULL;
4048 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4050 kref_put(&dump->kref, ipr_release_dump);
4057 * ipr_write_dump - Setup dump state of adapter
4058 * @filp: open sysfs file
4059 * @kobj: kobject struct
4060 * @bin_attr: bin_attribute struct
4063 * @count: buffer size
4066 * number of bytes printed to buffer
4068 static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
4069 struct bin_attribute *bin_attr,
4070 char *buf, loff_t off, size_t count)
4072 struct device *cdev = container_of(kobj, struct device, kobj);
4073 struct Scsi_Host *shost = class_to_shost(cdev);
4074 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4077 if (!capable(CAP_SYS_ADMIN))
4081 rc = ipr_alloc_dump(ioa_cfg);
4082 else if (buf[0] == '0')
4083 rc = ipr_free_dump(ioa_cfg);
4093 static struct bin_attribute ipr_dump_attr = {
4096 .mode = S_IRUSR | S_IWUSR,
4099 .read = ipr_read_dump,
4100 .write = ipr_write_dump
4103 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
4107 * ipr_change_queue_depth - Change the device's queue depth
4108 * @sdev: scsi device struct
4109 * @qdepth: depth to set
4110 * @reason: calling context
4115 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth,
4118 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4119 struct ipr_resource_entry *res;
4120 unsigned long lock_flags = 0;
4122 if (reason != SCSI_QDEPTH_DEFAULT)
4125 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4126 res = (struct ipr_resource_entry *)sdev->hostdata;
4128 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
4129 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
4130 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4132 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
4133 return sdev->queue_depth;
4137 * ipr_change_queue_type - Change the device's queue type
4138 * @dsev: scsi device struct
4139 * @tag_type: type of tags to use
4142 * actual queue type set
4144 static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
4146 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4147 struct ipr_resource_entry *res;
4148 unsigned long lock_flags = 0;
4150 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4151 res = (struct ipr_resource_entry *)sdev->hostdata;
4154 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
4156 * We don't bother quiescing the device here since the
4157 * adapter firmware does it for us.
4159 scsi_set_tag_type(sdev, tag_type);
4162 scsi_activate_tcq(sdev, sdev->queue_depth);
4164 scsi_deactivate_tcq(sdev, sdev->queue_depth);
4170 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4175 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4176 * @dev: device struct
4177 * @attr: device attribute structure
4181 * number of bytes printed to buffer
4183 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
4185 struct scsi_device *sdev = to_scsi_device(dev);
4186 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4187 struct ipr_resource_entry *res;
4188 unsigned long lock_flags = 0;
4189 ssize_t len = -ENXIO;
4191 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4192 res = (struct ipr_resource_entry *)sdev->hostdata;
4194 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
4195 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4199 static struct device_attribute ipr_adapter_handle_attr = {
4201 .name = "adapter_handle",
4204 .show = ipr_show_adapter_handle
4208 * ipr_show_resource_path - Show the resource path or the resource address for
4210 * @dev: device struct
4211 * @attr: device attribute structure
4215 * number of bytes printed to buffer
4217 static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
4219 struct scsi_device *sdev = to_scsi_device(dev);
4220 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4221 struct ipr_resource_entry *res;
4222 unsigned long lock_flags = 0;
4223 ssize_t len = -ENXIO;
4224 char buffer[IPR_MAX_RES_PATH_LENGTH];
4226 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4227 res = (struct ipr_resource_entry *)sdev->hostdata;
4228 if (res && ioa_cfg->sis64)
4229 len = snprintf(buf, PAGE_SIZE, "%s\n",
4230 ipr_format_res_path(res->res_path, buffer,
4233 len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
4234 res->bus, res->target, res->lun);
4236 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4240 static struct device_attribute ipr_resource_path_attr = {
4242 .name = "resource_path",
4245 .show = ipr_show_resource_path
4249 * ipr_show_device_id - Show the device_id for this device.
4250 * @dev: device struct
4251 * @attr: device attribute structure
4255 * number of bytes printed to buffer
4257 static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
4259 struct scsi_device *sdev = to_scsi_device(dev);
4260 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4261 struct ipr_resource_entry *res;
4262 unsigned long lock_flags = 0;
4263 ssize_t len = -ENXIO;
4265 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4266 res = (struct ipr_resource_entry *)sdev->hostdata;
4267 if (res && ioa_cfg->sis64)
4268 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->dev_id);
4270 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
4272 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4276 static struct device_attribute ipr_device_id_attr = {
4278 .name = "device_id",
4281 .show = ipr_show_device_id
4285 * ipr_show_resource_type - Show the resource type for this device.
4286 * @dev: device struct
4287 * @attr: device attribute structure
4291 * number of bytes printed to buffer
4293 static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
4295 struct scsi_device *sdev = to_scsi_device(dev);
4296 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4297 struct ipr_resource_entry *res;
4298 unsigned long lock_flags = 0;
4299 ssize_t len = -ENXIO;
4301 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4302 res = (struct ipr_resource_entry *)sdev->hostdata;
4305 len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
4307 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4311 static struct device_attribute ipr_resource_type_attr = {
4313 .name = "resource_type",
4316 .show = ipr_show_resource_type
4319 static struct device_attribute *ipr_dev_attrs[] = {
4320 &ipr_adapter_handle_attr,
4321 &ipr_resource_path_attr,
4322 &ipr_device_id_attr,
4323 &ipr_resource_type_attr,
4328 * ipr_biosparam - Return the HSC mapping
4329 * @sdev: scsi device struct
4330 * @block_device: block device pointer
4331 * @capacity: capacity of the device
4332 * @parm: Array containing returned HSC values.
4334 * This function generates the HSC parms that fdisk uses.
4335 * We want to make sure we return something that places partitions
4336 * on 4k boundaries for best performance with the IOA.
4341 static int ipr_biosparam(struct scsi_device *sdev,
4342 struct block_device *block_device,
4343 sector_t capacity, int *parm)
4351 cylinders = capacity;
4352 sector_div(cylinders, (128 * 32));
4357 parm[2] = cylinders;
4363 * ipr_find_starget - Find target based on bus/target.
4364 * @starget: scsi target struct
4367 * resource entry pointer if found / NULL if not found
4369 static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
4371 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4372 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4373 struct ipr_resource_entry *res;
4375 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4376 if ((res->bus == starget->channel) &&
4377 (res->target == starget->id)) {
4385 static struct ata_port_info sata_port_info;
4388 * ipr_target_alloc - Prepare for commands to a SCSI target
4389 * @starget: scsi target struct
4391 * If the device is a SATA device, this function allocates an
4392 * ATA port with libata, else it does nothing.
4395 * 0 on success / non-0 on failure
4397 static int ipr_target_alloc(struct scsi_target *starget)
4399 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4400 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4401 struct ipr_sata_port *sata_port;
4402 struct ata_port *ap;
4403 struct ipr_resource_entry *res;
4404 unsigned long lock_flags;
4406 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4407 res = ipr_find_starget(starget);
4408 starget->hostdata = NULL;
4410 if (res && ipr_is_gata(res)) {
4411 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4412 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
4416 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
4418 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4419 sata_port->ioa_cfg = ioa_cfg;
4421 sata_port->res = res;
4423 res->sata_port = sata_port;
4424 ap->private_data = sata_port;
4425 starget->hostdata = sata_port;
4431 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4437 * ipr_target_destroy - Destroy a SCSI target
4438 * @starget: scsi target struct
4440 * If the device was a SATA device, this function frees the libata
4441 * ATA port, else it does nothing.
4444 static void ipr_target_destroy(struct scsi_target *starget)
4446 struct ipr_sata_port *sata_port = starget->hostdata;
4447 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4448 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4450 if (ioa_cfg->sis64) {
4451 if (!ipr_find_starget(starget)) {
4452 if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4453 clear_bit(starget->id, ioa_cfg->array_ids);
4454 else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4455 clear_bit(starget->id, ioa_cfg->vset_ids);
4456 else if (starget->channel == 0)
4457 clear_bit(starget->id, ioa_cfg->target_ids);
4462 starget->hostdata = NULL;
4463 ata_sas_port_destroy(sata_port->ap);
4469 * ipr_find_sdev - Find device based on bus/target/lun.
4470 * @sdev: scsi device struct
4473 * resource entry pointer if found / NULL if not found
4475 static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
4477 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4478 struct ipr_resource_entry *res;
4480 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4481 if ((res->bus == sdev->channel) &&
4482 (res->target == sdev->id) &&
4483 (res->lun == sdev->lun))
4491 * ipr_slave_destroy - Unconfigure a SCSI device
4492 * @sdev: scsi device struct
4497 static void ipr_slave_destroy(struct scsi_device *sdev)
4499 struct ipr_resource_entry *res;
4500 struct ipr_ioa_cfg *ioa_cfg;
4501 unsigned long lock_flags = 0;
4503 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4505 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4506 res = (struct ipr_resource_entry *) sdev->hostdata;
4509 res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
4510 sdev->hostdata = NULL;
4512 res->sata_port = NULL;
4514 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4518 * ipr_slave_configure - Configure a SCSI device
4519 * @sdev: scsi device struct
4521 * This function configures the specified scsi device.
4526 static int ipr_slave_configure(struct scsi_device *sdev)
4528 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4529 struct ipr_resource_entry *res;
4530 struct ata_port *ap = NULL;
4531 unsigned long lock_flags = 0;
4532 char buffer[IPR_MAX_RES_PATH_LENGTH];
4534 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4535 res = sdev->hostdata;
4537 if (ipr_is_af_dasd_device(res))
4538 sdev->type = TYPE_RAID;
4539 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
4540 sdev->scsi_level = 4;
4541 sdev->no_uld_attach = 1;
4543 if (ipr_is_vset_device(res)) {
4544 blk_queue_rq_timeout(sdev->request_queue,
4545 IPR_VSET_RW_TIMEOUT);
4546 blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
4548 if (ipr_is_gata(res) && res->sata_port)
4549 ap = res->sata_port->ap;
4550 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4553 scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
4554 ata_sas_slave_configure(sdev, ap);
4556 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
4558 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
4559 ipr_format_res_path(res->res_path, buffer,
4563 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4568 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
4569 * @sdev: scsi device struct
4571 * This function initializes an ATA port so that future commands
4572 * sent through queuecommand will work.
4577 static int ipr_ata_slave_alloc(struct scsi_device *sdev)
4579 struct ipr_sata_port *sata_port = NULL;
4583 if (sdev->sdev_target)
4584 sata_port = sdev->sdev_target->hostdata;
4586 rc = ata_sas_port_init(sata_port->ap);
4588 rc = ata_sas_sync_probe(sata_port->ap);
4592 ipr_slave_destroy(sdev);
4599 * ipr_slave_alloc - Prepare for commands to a device.
4600 * @sdev: scsi device struct
4602 * This function saves a pointer to the resource entry
4603 * in the scsi device struct if the device exists. We
4604 * can then use this pointer in ipr_queuecommand when
4605 * handling new commands.
4608 * 0 on success / -ENXIO if device does not exist
4610 static int ipr_slave_alloc(struct scsi_device *sdev)
4612 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4613 struct ipr_resource_entry *res;
4614 unsigned long lock_flags;
4617 sdev->hostdata = NULL;
4619 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4621 res = ipr_find_sdev(sdev);
4626 sdev->hostdata = res;
4627 if (!ipr_is_naca_model(res))
4628 res->needs_sync_complete = 1;
4630 if (ipr_is_gata(res)) {
4631 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4632 return ipr_ata_slave_alloc(sdev);
4636 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4642 * ipr_eh_host_reset - Reset the host adapter
4643 * @scsi_cmd: scsi command struct
4648 static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
4650 struct ipr_ioa_cfg *ioa_cfg;
4654 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
4656 if (!ioa_cfg->in_reset_reload) {
4657 dev_err(&ioa_cfg->pdev->dev,
4658 "Adapter being reset as a result of error recovery.\n");
4660 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4661 ioa_cfg->sdt_state = GET_DUMP;
4664 rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
4670 static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
4674 spin_lock_irq(cmd->device->host->host_lock);
4675 rc = __ipr_eh_host_reset(cmd);
4676 spin_unlock_irq(cmd->device->host->host_lock);
4682 * ipr_device_reset - Reset the device
4683 * @ioa_cfg: ioa config struct
4684 * @res: resource entry struct
4686 * This function issues a device reset to the affected device.
4687 * If the device is a SCSI device, a LUN reset will be sent
4688 * to the device first. If that does not work, a target reset
4689 * will be sent. If the device is a SATA device, a PHY reset will
4693 * 0 on success / non-zero on failure
4695 static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
4696 struct ipr_resource_entry *res)
4698 struct ipr_cmnd *ipr_cmd;
4699 struct ipr_ioarcb *ioarcb;
4700 struct ipr_cmd_pkt *cmd_pkt;
4701 struct ipr_ioarcb_ata_regs *regs;
4705 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4706 ioarcb = &ipr_cmd->ioarcb;
4707 cmd_pkt = &ioarcb->cmd_pkt;
4709 if (ipr_cmd->ioa_cfg->sis64) {
4710 regs = &ipr_cmd->i.ata_ioadl.regs;
4711 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
4713 regs = &ioarcb->u.add_data.u.regs;
4715 ioarcb->res_handle = res->res_handle;
4716 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4717 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
4718 if (ipr_is_gata(res)) {
4719 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
4720 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
4721 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
4724 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
4725 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
4726 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4727 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) {
4728 if (ipr_cmd->ioa_cfg->sis64)
4729 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
4730 sizeof(struct ipr_ioasa_gata));
4732 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
4733 sizeof(struct ipr_ioasa_gata));
4737 return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0);
4741 * ipr_sata_reset - Reset the SATA port
4742 * @link: SATA link to reset
4743 * @classes: class of the attached device
4745 * This function issues a SATA phy reset to the affected ATA link.
4748 * 0 on success / non-zero on failure
4750 static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
4751 unsigned long deadline)
4753 struct ipr_sata_port *sata_port = link->ap->private_data;
4754 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4755 struct ipr_resource_entry *res;
4756 unsigned long lock_flags = 0;
4760 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4761 while(ioa_cfg->in_reset_reload) {
4762 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4763 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4764 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4767 res = sata_port->res;
4769 rc = ipr_device_reset(ioa_cfg, res);
4770 *classes = res->ata_class;
4773 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4779 * ipr_eh_dev_reset - Reset the device
4780 * @scsi_cmd: scsi command struct
4782 * This function issues a device reset to the affected device.
4783 * A LUN reset will be sent to the device first. If that does
4784 * not work, a target reset will be sent.
4789 static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
4791 struct ipr_cmnd *ipr_cmd;
4792 struct ipr_ioa_cfg *ioa_cfg;
4793 struct ipr_resource_entry *res;
4794 struct ata_port *ap;
4798 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
4799 res = scsi_cmd->device->hostdata;
4805 * If we are currently going through reset/reload, return failed. This will force the
4806 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
4809 if (ioa_cfg->in_reset_reload)
4811 if (ioa_cfg->ioa_is_dead)
4814 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4815 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
4816 if (ipr_cmd->scsi_cmd)
4817 ipr_cmd->done = ipr_scsi_eh_done;
4819 ipr_cmd->done = ipr_sata_eh_done;
4820 if (ipr_cmd->qc && !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
4821 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
4822 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
4827 res->resetting_device = 1;
4828 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
4830 if (ipr_is_gata(res) && res->sata_port) {
4831 ap = res->sata_port->ap;
4832 spin_unlock_irq(scsi_cmd->device->host->host_lock);
4833 ata_std_error_handler(ap);
4834 spin_lock_irq(scsi_cmd->device->host->host_lock);
4836 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4837 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
4843 rc = ipr_device_reset(ioa_cfg, res);
4844 res->resetting_device = 0;
4847 return (rc ? FAILED : SUCCESS);
4850 static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
4854 spin_lock_irq(cmd->device->host->host_lock);
4855 rc = __ipr_eh_dev_reset(cmd);
4856 spin_unlock_irq(cmd->device->host->host_lock);
4862 * ipr_bus_reset_done - Op done function for bus reset.
4863 * @ipr_cmd: ipr command struct
4865 * This function is the op done function for a bus reset
4870 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
4872 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4873 struct ipr_resource_entry *res;
4876 if (!ioa_cfg->sis64)
4877 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4878 if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
4879 scsi_report_bus_reset(ioa_cfg->host, res->bus);
4885 * If abort has not completed, indicate the reset has, else call the
4886 * abort's done function to wake the sleeping eh thread
4888 if (ipr_cmd->sibling->sibling)
4889 ipr_cmd->sibling->sibling = NULL;
4891 ipr_cmd->sibling->done(ipr_cmd->sibling);
4893 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4898 * ipr_abort_timeout - An abort task has timed out
4899 * @ipr_cmd: ipr command struct
4901 * This function handles when an abort task times out. If this
4902 * happens we issue a bus reset since we have resources tied
4903 * up that must be freed before returning to the midlayer.
4908 static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
4910 struct ipr_cmnd *reset_cmd;
4911 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4912 struct ipr_cmd_pkt *cmd_pkt;
4913 unsigned long lock_flags = 0;
4916 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4917 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
4918 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4922 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
4923 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4924 ipr_cmd->sibling = reset_cmd;
4925 reset_cmd->sibling = ipr_cmd;
4926 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
4927 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
4928 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4929 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
4930 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
4932 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
4933 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4938 * ipr_cancel_op - Cancel specified op
4939 * @scsi_cmd: scsi command struct
4941 * This function cancels specified op.
4946 static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
4948 struct ipr_cmnd *ipr_cmd;
4949 struct ipr_ioa_cfg *ioa_cfg;
4950 struct ipr_resource_entry *res;
4951 struct ipr_cmd_pkt *cmd_pkt;
4956 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4957 res = scsi_cmd->device->hostdata;
4959 /* If we are currently going through reset/reload, return failed.
4960 * This will force the mid-layer to call ipr_eh_host_reset,
4961 * which will then go to sleep and wait for the reset to complete
4963 if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
4969 * If we are aborting a timed out op, chances are that the timeout was caused
4970 * by a still not detected EEH error. In such cases, reading a register will
4971 * trigger the EEH recovery infrastructure.
4973 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
4975 if (!ipr_is_gscsi(res))
4978 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4979 if (ipr_cmd->scsi_cmd == scsi_cmd) {
4980 ipr_cmd->done = ipr_scsi_eh_done;
4989 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4990 ipr_cmd->ioarcb.res_handle = res->res_handle;
4991 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4992 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4993 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
4994 ipr_cmd->u.sdev = scsi_cmd->device;
4996 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
4998 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
4999 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5002 * If the abort task timed out and we sent a bus reset, we will get
5003 * one the following responses to the abort
5005 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
5010 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5011 if (!ipr_is_naca_model(res))
5012 res->needs_sync_complete = 1;
5015 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
5019 * ipr_eh_abort - Abort a single op
5020 * @scsi_cmd: scsi command struct
5025 static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
5027 unsigned long flags;
5032 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
5033 rc = ipr_cancel_op(scsi_cmd);
5034 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
5041 * ipr_handle_other_interrupt - Handle "other" interrupts
5042 * @ioa_cfg: ioa config struct
5043 * @int_reg: interrupt register
5046 * IRQ_NONE / IRQ_HANDLED
5048 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
5051 irqreturn_t rc = IRQ_HANDLED;
5054 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
5055 int_reg &= ~int_mask_reg;
5057 /* If an interrupt on the adapter did not occur, ignore it.
5058 * Or in the case of SIS 64, check for a stage change interrupt.
5060 if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
5061 if (ioa_cfg->sis64) {
5062 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
5063 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5064 if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
5066 /* clear stage change */
5067 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
5068 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5069 list_del(&ioa_cfg->reset_cmd->queue);
5070 del_timer(&ioa_cfg->reset_cmd->timer);
5071 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5079 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
5080 /* Mask the interrupt */
5081 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
5083 /* Clear the interrupt */
5084 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
5085 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5087 list_del(&ioa_cfg->reset_cmd->queue);
5088 del_timer(&ioa_cfg->reset_cmd->timer);
5089 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5090 } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
5091 if (ioa_cfg->clear_isr) {
5092 if (ipr_debug && printk_ratelimit())
5093 dev_err(&ioa_cfg->pdev->dev,
5094 "Spurious interrupt detected. 0x%08X\n", int_reg);
5095 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5096 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5100 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
5101 ioa_cfg->ioa_unit_checked = 1;
5103 dev_err(&ioa_cfg->pdev->dev,
5104 "Permanent IOA failure. 0x%08X\n", int_reg);
5106 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5107 ioa_cfg->sdt_state = GET_DUMP;
5109 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
5110 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5117 * ipr_isr_eh - Interrupt service routine error handler
5118 * @ioa_cfg: ioa config struct
5119 * @msg: message to log
5124 static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg)
5126 ioa_cfg->errors_logged++;
5127 dev_err(&ioa_cfg->pdev->dev, "%s\n", msg);
5129 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5130 ioa_cfg->sdt_state = GET_DUMP;
5132 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5136 * ipr_isr - Interrupt service routine
5138 * @devp: pointer to ioa config struct
5141 * IRQ_NONE / IRQ_HANDLED
5143 static irqreturn_t ipr_isr(int irq, void *devp)
5145 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
5146 unsigned long lock_flags = 0;
5152 struct ipr_cmnd *ipr_cmd, *temp;
5153 irqreturn_t rc = IRQ_NONE;
5156 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5158 /* If interrupts are disabled, ignore the interrupt */
5159 if (!ioa_cfg->allow_interrupts) {
5160 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5167 while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5168 ioa_cfg->toggle_bit) {
5170 cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
5171 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
5173 if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
5174 ipr_isr_eh(ioa_cfg, "Invalid response handle from IOA");
5179 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
5181 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5183 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
5185 list_move_tail(&ipr_cmd->queue, &doneq);
5189 if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
5190 ioa_cfg->hrrq_curr++;
5192 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
5193 ioa_cfg->toggle_bit ^= 1u;
5197 if (ipr_cmd && !ioa_cfg->clear_isr)
5200 if (ipr_cmd != NULL) {
5201 /* Clear the PCI interrupt */
5204 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5205 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5206 } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
5207 num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
5209 } else if (rc == IRQ_NONE && irq_none == 0) {
5210 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5212 } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
5213 int_reg & IPR_PCII_HRRQ_UPDATED) {
5214 ipr_isr_eh(ioa_cfg, "Error clearing HRRQ");
5221 if (unlikely(rc == IRQ_NONE))
5222 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
5225 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5226 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5227 list_del(&ipr_cmd->queue);
5228 del_timer(&ipr_cmd->timer);
5229 ipr_cmd->fast_done(ipr_cmd);
5236 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
5237 * @ioa_cfg: ioa config struct
5238 * @ipr_cmd: ipr command struct
5241 * 0 on success / -1 on failure
5243 static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
5244 struct ipr_cmnd *ipr_cmd)
5247 struct scatterlist *sg;
5249 u32 ioadl_flags = 0;
5250 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5251 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5252 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
5254 length = scsi_bufflen(scsi_cmd);
5258 nseg = scsi_dma_map(scsi_cmd);
5260 if (printk_ratelimit())
5261 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
5265 ipr_cmd->dma_use_sg = nseg;
5267 ioarcb->data_transfer_length = cpu_to_be32(length);
5269 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
5271 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5272 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5273 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5274 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
5275 ioadl_flags = IPR_IOADL_FLAGS_READ;
5277 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5278 ioadl64[i].flags = cpu_to_be32(ioadl_flags);
5279 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
5280 ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
5283 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5288 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5289 * @ioa_cfg: ioa config struct
5290 * @ipr_cmd: ipr command struct
5293 * 0 on success / -1 on failure
5295 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5296 struct ipr_cmnd *ipr_cmd)
5299 struct scatterlist *sg;
5301 u32 ioadl_flags = 0;
5302 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5303 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5304 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
5306 length = scsi_bufflen(scsi_cmd);
5310 nseg = scsi_dma_map(scsi_cmd);
5312 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
5316 ipr_cmd->dma_use_sg = nseg;
5318 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5319 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5320 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5321 ioarcb->data_transfer_length = cpu_to_be32(length);
5323 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5324 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
5325 ioadl_flags = IPR_IOADL_FLAGS_READ;
5326 ioarcb->read_data_transfer_length = cpu_to_be32(length);
5327 ioarcb->read_ioadl_len =
5328 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5331 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
5332 ioadl = ioarcb->u.add_data.u.ioadl;
5333 ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
5334 offsetof(struct ipr_ioarcb, u.add_data));
5335 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5338 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5339 ioadl[i].flags_and_data_len =
5340 cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5341 ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
5344 ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5349 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
5350 * @scsi_cmd: scsi command struct
5355 static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
5358 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
5360 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
5362 case MSG_SIMPLE_TAG:
5363 rc = IPR_FLAGS_LO_SIMPLE_TASK;
5366 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
5368 case MSG_ORDERED_TAG:
5369 rc = IPR_FLAGS_LO_ORDERED_TASK;
5378 * ipr_erp_done - Process completion of ERP for a device
5379 * @ipr_cmd: ipr command struct
5381 * This function copies the sense buffer into the scsi_cmd
5382 * struct and pushes the scsi_done function.
5387 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
5389 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5390 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5391 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5392 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5394 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5395 scsi_cmd->result |= (DID_ERROR << 16);
5396 scmd_printk(KERN_ERR, scsi_cmd,
5397 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
5399 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
5400 SCSI_SENSE_BUFFERSIZE);
5404 if (!ipr_is_naca_model(res))
5405 res->needs_sync_complete = 1;
5408 scsi_dma_unmap(ipr_cmd->scsi_cmd);
5409 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5410 scsi_cmd->scsi_done(scsi_cmd);
5414 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5415 * @ipr_cmd: ipr command struct
5420 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
5422 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5423 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5424 dma_addr_t dma_addr = ipr_cmd->dma_addr;
5426 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
5427 ioarcb->data_transfer_length = 0;
5428 ioarcb->read_data_transfer_length = 0;
5429 ioarcb->ioadl_len = 0;
5430 ioarcb->read_ioadl_len = 0;
5431 ioasa->hdr.ioasc = 0;
5432 ioasa->hdr.residual_data_len = 0;
5434 if (ipr_cmd->ioa_cfg->sis64)
5435 ioarcb->u.sis64_addr_data.data_ioadl_addr =
5436 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
5438 ioarcb->write_ioadl_addr =
5439 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
5440 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5445 * ipr_erp_request_sense - Send request sense to a device
5446 * @ipr_cmd: ipr command struct
5448 * This function sends a request sense to a device as a result
5449 * of a check condition.
5454 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
5456 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5457 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5459 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5460 ipr_erp_done(ipr_cmd);
5464 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5466 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
5467 cmd_pkt->cdb[0] = REQUEST_SENSE;
5468 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
5469 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
5470 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5471 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
5473 ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
5474 SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
5476 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
5477 IPR_REQUEST_SENSE_TIMEOUT * 2);
5481 * ipr_erp_cancel_all - Send cancel all to a device
5482 * @ipr_cmd: ipr command struct
5484 * This function sends a cancel all to a device to clear the
5485 * queue. If we are running TCQ on the device, QERR is set to 1,
5486 * which means all outstanding ops have been dropped on the floor.
5487 * Cancel all will return them to us.
5492 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
5494 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5495 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5496 struct ipr_cmd_pkt *cmd_pkt;
5500 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5502 if (!scsi_get_tag_type(scsi_cmd->device)) {
5503 ipr_erp_request_sense(ipr_cmd);
5507 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5508 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5509 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5511 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
5512 IPR_CANCEL_ALL_TIMEOUT);
5516 * ipr_dump_ioasa - Dump contents of IOASA
5517 * @ioa_cfg: ioa config struct
5518 * @ipr_cmd: ipr command struct
5519 * @res: resource entry struct
5521 * This function is invoked by the interrupt handler when ops
5522 * fail. It will log the IOASA if appropriate. Only called
5528 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
5529 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
5533 u32 ioasc, fd_ioasc;
5534 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5535 __be32 *ioasa_data = (__be32 *)ioasa;
5538 ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
5539 fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
5544 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
5547 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
5548 error_index = ipr_get_error(fd_ioasc);
5550 error_index = ipr_get_error(ioasc);
5552 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
5553 /* Don't log an error if the IOA already logged one */
5554 if (ioasa->hdr.ilid != 0)
5557 if (!ipr_is_gscsi(res))
5560 if (ipr_error_table[error_index].log_ioasa == 0)
5564 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
5566 data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
5567 if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
5568 data_len = sizeof(struct ipr_ioasa64);
5569 else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
5570 data_len = sizeof(struct ipr_ioasa);
5572 ipr_err("IOASA Dump:\n");
5574 for (i = 0; i < data_len / 4; i += 4) {
5575 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
5576 be32_to_cpu(ioasa_data[i]),
5577 be32_to_cpu(ioasa_data[i+1]),
5578 be32_to_cpu(ioasa_data[i+2]),
5579 be32_to_cpu(ioasa_data[i+3]));
5584 * ipr_gen_sense - Generate SCSI sense data from an IOASA
5586 * @sense_buf: sense data buffer
5591 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
5594 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
5595 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
5596 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5597 u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
5599 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
5601 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
5604 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
5606 if (ipr_is_vset_device(res) &&
5607 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
5608 ioasa->u.vset.failing_lba_hi != 0) {
5609 sense_buf[0] = 0x72;
5610 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
5611 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
5612 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
5616 sense_buf[9] = 0x0A;
5617 sense_buf[10] = 0x80;
5619 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
5621 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
5622 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
5623 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
5624 sense_buf[15] = failing_lba & 0x000000ff;
5626 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5628 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
5629 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
5630 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
5631 sense_buf[19] = failing_lba & 0x000000ff;
5633 sense_buf[0] = 0x70;
5634 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
5635 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
5636 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
5638 /* Illegal request */
5639 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
5640 (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
5641 sense_buf[7] = 10; /* additional length */
5643 /* IOARCB was in error */
5644 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
5645 sense_buf[15] = 0xC0;
5646 else /* Parameter data was invalid */
5647 sense_buf[15] = 0x80;
5650 ((IPR_FIELD_POINTER_MASK &
5651 be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
5653 (IPR_FIELD_POINTER_MASK &
5654 be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
5656 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
5657 if (ipr_is_vset_device(res))
5658 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5660 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
5662 sense_buf[0] |= 0x80; /* Or in the Valid bit */
5663 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
5664 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
5665 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
5666 sense_buf[6] = failing_lba & 0x000000ff;
5669 sense_buf[7] = 6; /* additional length */
5675 * ipr_get_autosense - Copy autosense data to sense buffer
5676 * @ipr_cmd: ipr command struct
5678 * This function copies the autosense buffer to the buffer
5679 * in the scsi_cmd, if there is autosense available.
5682 * 1 if autosense was available / 0 if not
5684 static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
5686 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5687 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
5689 if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
5692 if (ipr_cmd->ioa_cfg->sis64)
5693 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
5694 min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
5695 SCSI_SENSE_BUFFERSIZE));
5697 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
5698 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
5699 SCSI_SENSE_BUFFERSIZE));
5704 * ipr_erp_start - Process an error response for a SCSI op
5705 * @ioa_cfg: ioa config struct
5706 * @ipr_cmd: ipr command struct
5708 * This function determines whether or not to initiate ERP
5709 * on the affected device.
5714 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
5715 struct ipr_cmnd *ipr_cmd)
5717 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5718 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5719 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5720 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
5723 ipr_scsi_eh_done(ipr_cmd);
5727 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
5728 ipr_gen_sense(ipr_cmd);
5730 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
5732 switch (masked_ioasc) {
5733 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
5734 if (ipr_is_naca_model(res))
5735 scsi_cmd->result |= (DID_ABORT << 16);
5737 scsi_cmd->result |= (DID_IMM_RETRY << 16);
5739 case IPR_IOASC_IR_RESOURCE_HANDLE:
5740 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
5741 scsi_cmd->result |= (DID_NO_CONNECT << 16);
5743 case IPR_IOASC_HW_SEL_TIMEOUT:
5744 scsi_cmd->result |= (DID_NO_CONNECT << 16);
5745 if (!ipr_is_naca_model(res))
5746 res->needs_sync_complete = 1;
5748 case IPR_IOASC_SYNC_REQUIRED:
5750 res->needs_sync_complete = 1;
5751 scsi_cmd->result |= (DID_IMM_RETRY << 16);
5753 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
5754 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
5755 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
5757 case IPR_IOASC_BUS_WAS_RESET:
5758 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
5760 * Report the bus reset and ask for a retry. The device
5761 * will give CC/UA the next command.
5763 if (!res->resetting_device)
5764 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
5765 scsi_cmd->result |= (DID_ERROR << 16);
5766 if (!ipr_is_naca_model(res))
5767 res->needs_sync_complete = 1;
5769 case IPR_IOASC_HW_DEV_BUS_STATUS:
5770 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
5771 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
5772 if (!ipr_get_autosense(ipr_cmd)) {
5773 if (!ipr_is_naca_model(res)) {
5774 ipr_erp_cancel_all(ipr_cmd);
5779 if (!ipr_is_naca_model(res))
5780 res->needs_sync_complete = 1;
5782 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
5785 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
5786 scsi_cmd->result |= (DID_ERROR << 16);
5787 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
5788 res->needs_sync_complete = 1;
5792 scsi_dma_unmap(ipr_cmd->scsi_cmd);
5793 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5794 scsi_cmd->scsi_done(scsi_cmd);
5798 * ipr_scsi_done - mid-layer done function
5799 * @ipr_cmd: ipr command struct
5801 * This function is invoked by the interrupt handler for
5802 * ops generated by the SCSI mid-layer
5807 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
5809 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5810 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5811 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5812 unsigned long lock_flags;
5814 scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
5816 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
5817 scsi_dma_unmap(scsi_cmd);
5819 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5820 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5821 scsi_cmd->scsi_done(scsi_cmd);
5822 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5824 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5825 ipr_erp_start(ioa_cfg, ipr_cmd);
5826 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5831 * ipr_queuecommand - Queue a mid-layer request
5832 * @shost: scsi host struct
5833 * @scsi_cmd: scsi command struct
5835 * This function queues a request generated by the mid-layer.
5839 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
5840 * SCSI_MLQUEUE_HOST_BUSY if host is busy
5842 static int ipr_queuecommand(struct Scsi_Host *shost,
5843 struct scsi_cmnd *scsi_cmd)
5845 struct ipr_ioa_cfg *ioa_cfg;
5846 struct ipr_resource_entry *res;
5847 struct ipr_ioarcb *ioarcb;
5848 struct ipr_cmnd *ipr_cmd;
5849 unsigned long lock_flags;
5852 ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
5854 spin_lock_irqsave(shost->host_lock, lock_flags);
5855 scsi_cmd->result = (DID_OK << 16);
5856 res = scsi_cmd->device->hostdata;
5859 * We are currently blocking all devices due to a host reset
5860 * We have told the host to stop giving us new requests, but
5861 * ERP ops don't count. FIXME
5863 if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead)) {
5864 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5865 return SCSI_MLQUEUE_HOST_BUSY;
5869 * FIXME - Create scsi_set_host_offline interface
5870 * and the ioa_is_dead check can be removed
5872 if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
5873 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5877 if (ipr_is_gata(res) && res->sata_port)
5878 return ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
5880 ipr_cmd = __ipr_get_free_ipr_cmnd(ioa_cfg);
5881 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5883 ipr_init_ipr_cmnd(ipr_cmd, ipr_scsi_done);
5884 ioarcb = &ipr_cmd->ioarcb;
5886 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
5887 ipr_cmd->scsi_cmd = scsi_cmd;
5888 ipr_cmd->done = ipr_scsi_eh_done;
5890 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
5891 if (scsi_cmd->underflow == 0)
5892 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5894 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
5895 if (ipr_is_gscsi(res))
5896 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
5897 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
5898 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
5901 if (scsi_cmd->cmnd[0] >= 0xC0 &&
5902 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
5903 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5905 if (likely(rc == 0)) {
5907 rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
5909 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
5912 spin_lock_irqsave(shost->host_lock, lock_flags);
5913 if (unlikely(rc || (!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))) {
5914 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5915 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5917 scsi_dma_unmap(scsi_cmd);
5918 return SCSI_MLQUEUE_HOST_BUSY;
5921 if (unlikely(ioa_cfg->ioa_is_dead)) {
5922 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5923 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5924 scsi_dma_unmap(scsi_cmd);
5928 ioarcb->res_handle = res->res_handle;
5929 if (res->needs_sync_complete) {
5930 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
5931 res->needs_sync_complete = 0;
5933 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
5934 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
5935 ipr_send_command(ipr_cmd);
5936 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5940 spin_lock_irqsave(shost->host_lock, lock_flags);
5941 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
5942 scsi_cmd->result = (DID_NO_CONNECT << 16);
5943 scsi_cmd->scsi_done(scsi_cmd);
5944 spin_unlock_irqrestore(shost->host_lock, lock_flags);
5949 * ipr_ioctl - IOCTL handler
5950 * @sdev: scsi device struct
5955 * 0 on success / other on failure
5957 static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
5959 struct ipr_resource_entry *res;
5961 res = (struct ipr_resource_entry *)sdev->hostdata;
5962 if (res && ipr_is_gata(res)) {
5963 if (cmd == HDIO_GET_IDENTITY)
5965 return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
5972 * ipr_info - Get information about the card/driver
5973 * @scsi_host: scsi host struct
5976 * pointer to buffer with description string
5978 static const char * ipr_ioa_info(struct Scsi_Host *host)
5980 static char buffer[512];
5981 struct ipr_ioa_cfg *ioa_cfg;
5982 unsigned long lock_flags = 0;
5984 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
5986 spin_lock_irqsave(host->host_lock, lock_flags);
5987 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
5988 spin_unlock_irqrestore(host->host_lock, lock_flags);
5993 static struct scsi_host_template driver_template = {
5994 .module = THIS_MODULE,
5996 .info = ipr_ioa_info,
5998 .queuecommand = ipr_queuecommand,
5999 .eh_abort_handler = ipr_eh_abort,
6000 .eh_device_reset_handler = ipr_eh_dev_reset,
6001 .eh_host_reset_handler = ipr_eh_host_reset,
6002 .slave_alloc = ipr_slave_alloc,
6003 .slave_configure = ipr_slave_configure,
6004 .slave_destroy = ipr_slave_destroy,
6005 .target_alloc = ipr_target_alloc,
6006 .target_destroy = ipr_target_destroy,
6007 .change_queue_depth = ipr_change_queue_depth,
6008 .change_queue_type = ipr_change_queue_type,
6009 .bios_param = ipr_biosparam,
6010 .can_queue = IPR_MAX_COMMANDS,
6012 .sg_tablesize = IPR_MAX_SGLIST,
6013 .max_sectors = IPR_IOA_MAX_SECTORS,
6014 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
6015 .use_clustering = ENABLE_CLUSTERING,
6016 .shost_attrs = ipr_ioa_attrs,
6017 .sdev_attrs = ipr_dev_attrs,
6018 .proc_name = IPR_NAME
6022 * ipr_ata_phy_reset - libata phy_reset handler
6023 * @ap: ata port to reset
6026 static void ipr_ata_phy_reset(struct ata_port *ap)
6028 unsigned long flags;
6029 struct ipr_sata_port *sata_port = ap->private_data;
6030 struct ipr_resource_entry *res = sata_port->res;
6031 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6035 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6036 while(ioa_cfg->in_reset_reload) {
6037 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6038 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6039 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6042 if (!ioa_cfg->allow_cmds)
6045 rc = ipr_device_reset(ioa_cfg, res);
6048 ap->link.device[0].class = ATA_DEV_NONE;
6052 ap->link.device[0].class = res->ata_class;
6053 if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
6054 ap->link.device[0].class = ATA_DEV_NONE;
6057 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6062 * ipr_ata_post_internal - Cleanup after an internal command
6063 * @qc: ATA queued command
6068 static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
6070 struct ipr_sata_port *sata_port = qc->ap->private_data;
6071 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6072 struct ipr_cmnd *ipr_cmd;
6073 unsigned long flags;
6075 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6076 while(ioa_cfg->in_reset_reload) {
6077 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6078 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6079 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6082 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
6083 if (ipr_cmd->qc == qc) {
6084 ipr_device_reset(ioa_cfg, sata_port->res);
6088 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6092 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
6093 * @regs: destination
6094 * @tf: source ATA taskfile
6099 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
6100 struct ata_taskfile *tf)
6102 regs->feature = tf->feature;
6103 regs->nsect = tf->nsect;
6104 regs->lbal = tf->lbal;
6105 regs->lbam = tf->lbam;
6106 regs->lbah = tf->lbah;
6107 regs->device = tf->device;
6108 regs->command = tf->command;
6109 regs->hob_feature = tf->hob_feature;
6110 regs->hob_nsect = tf->hob_nsect;
6111 regs->hob_lbal = tf->hob_lbal;
6112 regs->hob_lbam = tf->hob_lbam;
6113 regs->hob_lbah = tf->hob_lbah;
6114 regs->ctl = tf->ctl;
6118 * ipr_sata_done - done function for SATA commands
6119 * @ipr_cmd: ipr command struct
6121 * This function is invoked by the interrupt handler for
6122 * ops generated by the SCSI mid-layer to SATA devices
6127 static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
6129 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6130 struct ata_queued_cmd *qc = ipr_cmd->qc;
6131 struct ipr_sata_port *sata_port = qc->ap->private_data;
6132 struct ipr_resource_entry *res = sata_port->res;
6133 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6135 if (ipr_cmd->ioa_cfg->sis64)
6136 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
6137 sizeof(struct ipr_ioasa_gata));
6139 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
6140 sizeof(struct ipr_ioasa_gata));
6141 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6143 if (be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
6144 scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
6146 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
6147 qc->err_mask |= __ac_err_mask(sata_port->ioasa.status);
6149 qc->err_mask |= ac_err_mask(sata_port->ioasa.status);
6150 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6151 ata_qc_complete(qc);
6155 * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
6156 * @ipr_cmd: ipr command struct
6157 * @qc: ATA queued command
6160 static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
6161 struct ata_queued_cmd *qc)
6163 u32 ioadl_flags = 0;
6164 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6165 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
6166 struct ipr_ioadl64_desc *last_ioadl64 = NULL;
6167 int len = qc->nbytes;
6168 struct scatterlist *sg;
6170 dma_addr_t dma_addr = ipr_cmd->dma_addr;
6175 if (qc->dma_dir == DMA_TO_DEVICE) {
6176 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6177 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6178 } else if (qc->dma_dir == DMA_FROM_DEVICE)
6179 ioadl_flags = IPR_IOADL_FLAGS_READ;
6181 ioarcb->data_transfer_length = cpu_to_be32(len);
6183 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
6184 ioarcb->u.sis64_addr_data.data_ioadl_addr =
6185 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl));
6187 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6188 ioadl64->flags = cpu_to_be32(ioadl_flags);
6189 ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
6190 ioadl64->address = cpu_to_be64(sg_dma_address(sg));
6192 last_ioadl64 = ioadl64;
6196 if (likely(last_ioadl64))
6197 last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6201 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
6202 * @ipr_cmd: ipr command struct
6203 * @qc: ATA queued command
6206 static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
6207 struct ata_queued_cmd *qc)
6209 u32 ioadl_flags = 0;
6210 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6211 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
6212 struct ipr_ioadl_desc *last_ioadl = NULL;
6213 int len = qc->nbytes;
6214 struct scatterlist *sg;
6220 if (qc->dma_dir == DMA_TO_DEVICE) {
6221 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6222 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6223 ioarcb->data_transfer_length = cpu_to_be32(len);
6225 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6226 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
6227 ioadl_flags = IPR_IOADL_FLAGS_READ;
6228 ioarcb->read_data_transfer_length = cpu_to_be32(len);
6229 ioarcb->read_ioadl_len =
6230 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6233 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6234 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
6235 ioadl->address = cpu_to_be32(sg_dma_address(sg));
6241 if (likely(last_ioadl))
6242 last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6246 * ipr_qc_issue - Issue a SATA qc to a device
6247 * @qc: queued command
6252 static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
6254 struct ata_port *ap = qc->ap;
6255 struct ipr_sata_port *sata_port = ap->private_data;
6256 struct ipr_resource_entry *res = sata_port->res;
6257 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6258 struct ipr_cmnd *ipr_cmd;
6259 struct ipr_ioarcb *ioarcb;
6260 struct ipr_ioarcb_ata_regs *regs;
6262 if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead))
6263 return AC_ERR_SYSTEM;
6265 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
6266 ioarcb = &ipr_cmd->ioarcb;
6268 if (ioa_cfg->sis64) {
6269 regs = &ipr_cmd->i.ata_ioadl.regs;
6270 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
6272 regs = &ioarcb->u.add_data.u.regs;
6274 memset(regs, 0, sizeof(*regs));
6275 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
6277 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
6279 ipr_cmd->done = ipr_sata_done;
6280 ipr_cmd->ioarcb.res_handle = res->res_handle;
6281 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
6282 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6283 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
6284 ipr_cmd->dma_use_sg = qc->n_elem;
6287 ipr_build_ata_ioadl64(ipr_cmd, qc);
6289 ipr_build_ata_ioadl(ipr_cmd, qc);
6291 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
6292 ipr_copy_sata_tf(regs, &qc->tf);
6293 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
6294 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
6296 switch (qc->tf.protocol) {
6297 case ATA_PROT_NODATA:
6302 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6305 case ATAPI_PROT_PIO:
6306 case ATAPI_PROT_NODATA:
6307 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6310 case ATAPI_PROT_DMA:
6311 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6312 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6317 return AC_ERR_INVALID;
6320 ipr_send_command(ipr_cmd);
6326 * ipr_qc_fill_rtf - Read result TF
6327 * @qc: ATA queued command
6332 static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
6334 struct ipr_sata_port *sata_port = qc->ap->private_data;
6335 struct ipr_ioasa_gata *g = &sata_port->ioasa;
6336 struct ata_taskfile *tf = &qc->result_tf;
6338 tf->feature = g->error;
6339 tf->nsect = g->nsect;
6343 tf->device = g->device;
6344 tf->command = g->status;
6345 tf->hob_nsect = g->hob_nsect;
6346 tf->hob_lbal = g->hob_lbal;
6347 tf->hob_lbam = g->hob_lbam;
6348 tf->hob_lbah = g->hob_lbah;
6349 tf->ctl = g->alt_status;
6354 static struct ata_port_operations ipr_sata_ops = {
6355 .phy_reset = ipr_ata_phy_reset,
6356 .hardreset = ipr_sata_reset,
6357 .post_internal_cmd = ipr_ata_post_internal,
6358 .qc_prep = ata_noop_qc_prep,
6359 .qc_issue = ipr_qc_issue,
6360 .qc_fill_rtf = ipr_qc_fill_rtf,
6361 .port_start = ata_sas_port_start,
6362 .port_stop = ata_sas_port_stop
6365 static struct ata_port_info sata_port_info = {
6366 .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA,
6367 .pio_mask = ATA_PIO4_ONLY,
6368 .mwdma_mask = ATA_MWDMA2,
6369 .udma_mask = ATA_UDMA6,
6370 .port_ops = &ipr_sata_ops
6373 #ifdef CONFIG_PPC_PSERIES
6374 static const u16 ipr_blocked_processors[] = {
6386 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
6387 * @ioa_cfg: ioa cfg struct
6389 * Adapters that use Gemstone revision < 3.1 do not work reliably on
6390 * certain pSeries hardware. This function determines if the given
6391 * adapter is in one of these confgurations or not.
6394 * 1 if adapter is not supported / 0 if adapter is supported
6396 static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
6400 if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
6401 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
6402 if (__is_processor(ipr_blocked_processors[i]))
6409 #define ipr_invalid_adapter(ioa_cfg) 0
6413 * ipr_ioa_bringdown_done - IOA bring down completion.
6414 * @ipr_cmd: ipr command struct
6416 * This function processes the completion of an adapter bring down.
6417 * It wakes any reset sleepers.
6422 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
6424 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6427 ioa_cfg->in_reset_reload = 0;
6428 ioa_cfg->reset_retries = 0;
6429 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6430 wake_up_all(&ioa_cfg->reset_wait_q);
6432 spin_unlock_irq(ioa_cfg->host->host_lock);
6433 scsi_unblock_requests(ioa_cfg->host);
6434 spin_lock_irq(ioa_cfg->host->host_lock);
6437 return IPR_RC_JOB_RETURN;
6441 * ipr_ioa_reset_done - IOA reset completion.
6442 * @ipr_cmd: ipr command struct
6444 * This function processes the completion of an adapter reset.
6445 * It schedules any necessary mid-layer add/removes and
6446 * wakes any reset sleepers.
6451 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
6453 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6454 struct ipr_resource_entry *res;
6455 struct ipr_hostrcb *hostrcb, *temp;
6459 ioa_cfg->in_reset_reload = 0;
6460 ioa_cfg->allow_cmds = 1;
6461 ioa_cfg->reset_cmd = NULL;
6462 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
6464 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
6465 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
6470 schedule_work(&ioa_cfg->work_q);
6472 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
6473 list_del(&hostrcb->queue);
6474 if (i++ < IPR_NUM_LOG_HCAMS)
6475 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
6477 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
6480 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
6481 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
6483 ioa_cfg->reset_retries = 0;
6484 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6485 wake_up_all(&ioa_cfg->reset_wait_q);
6487 spin_unlock(ioa_cfg->host->host_lock);
6488 scsi_unblock_requests(ioa_cfg->host);
6489 spin_lock(ioa_cfg->host->host_lock);
6491 if (!ioa_cfg->allow_cmds)
6492 scsi_block_requests(ioa_cfg->host);
6495 return IPR_RC_JOB_RETURN;
6499 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
6500 * @supported_dev: supported device struct
6501 * @vpids: vendor product id struct
6506 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
6507 struct ipr_std_inq_vpids *vpids)
6509 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
6510 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
6511 supported_dev->num_records = 1;
6512 supported_dev->data_length =
6513 cpu_to_be16(sizeof(struct ipr_supported_device));
6514 supported_dev->reserved = 0;
6518 * ipr_set_supported_devs - Send Set Supported Devices for a device
6519 * @ipr_cmd: ipr command struct
6521 * This function sends a Set Supported Devices to the adapter
6524 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6526 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
6528 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6529 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
6530 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6531 struct ipr_resource_entry *res = ipr_cmd->u.res;
6533 ipr_cmd->job_step = ipr_ioa_reset_done;
6535 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
6536 if (!ipr_is_scsi_disk(res))
6539 ipr_cmd->u.res = res;
6540 ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
6542 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6543 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6544 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6546 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
6547 ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
6548 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
6549 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
6551 ipr_init_ioadl(ipr_cmd,
6552 ioa_cfg->vpd_cbs_dma +
6553 offsetof(struct ipr_misc_cbs, supp_dev),
6554 sizeof(struct ipr_supported_device),
6555 IPR_IOADL_FLAGS_WRITE_LAST);
6557 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
6558 IPR_SET_SUP_DEVICE_TIMEOUT);
6560 if (!ioa_cfg->sis64)
6561 ipr_cmd->job_step = ipr_set_supported_devs;
6562 return IPR_RC_JOB_RETURN;
6565 return IPR_RC_JOB_CONTINUE;
6569 * ipr_get_mode_page - Locate specified mode page
6570 * @mode_pages: mode page buffer
6571 * @page_code: page code to find
6572 * @len: minimum required length for mode page
6575 * pointer to mode page / NULL on failure
6577 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
6578 u32 page_code, u32 len)
6580 struct ipr_mode_page_hdr *mode_hdr;
6584 if (!mode_pages || (mode_pages->hdr.length == 0))
6587 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
6588 mode_hdr = (struct ipr_mode_page_hdr *)
6589 (mode_pages->data + mode_pages->hdr.block_desc_len);
6592 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
6593 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
6597 page_length = (sizeof(struct ipr_mode_page_hdr) +
6598 mode_hdr->page_length);
6599 length -= page_length;
6600 mode_hdr = (struct ipr_mode_page_hdr *)
6601 ((unsigned long)mode_hdr + page_length);
6608 * ipr_check_term_power - Check for term power errors
6609 * @ioa_cfg: ioa config struct
6610 * @mode_pages: IOAFP mode pages buffer
6612 * Check the IOAFP's mode page 28 for term power errors
6617 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
6618 struct ipr_mode_pages *mode_pages)
6622 struct ipr_dev_bus_entry *bus;
6623 struct ipr_mode_page28 *mode_page;
6625 mode_page = ipr_get_mode_page(mode_pages, 0x28,
6626 sizeof(struct ipr_mode_page28));
6628 entry_length = mode_page->entry_length;
6630 bus = mode_page->bus;
6632 for (i = 0; i < mode_page->num_entries; i++) {
6633 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
6634 dev_err(&ioa_cfg->pdev->dev,
6635 "Term power is absent on scsi bus %d\n",
6639 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
6644 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
6645 * @ioa_cfg: ioa config struct
6647 * Looks through the config table checking for SES devices. If
6648 * the SES device is in the SES table indicating a maximum SCSI
6649 * bus speed, the speed is limited for the bus.
6654 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
6659 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
6660 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
6661 ioa_cfg->bus_attr[i].bus_width);
6663 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
6664 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
6669 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
6670 * @ioa_cfg: ioa config struct
6671 * @mode_pages: mode page 28 buffer
6673 * Updates mode page 28 based on driver configuration
6678 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
6679 struct ipr_mode_pages *mode_pages)
6681 int i, entry_length;
6682 struct ipr_dev_bus_entry *bus;
6683 struct ipr_bus_attributes *bus_attr;
6684 struct ipr_mode_page28 *mode_page;
6686 mode_page = ipr_get_mode_page(mode_pages, 0x28,
6687 sizeof(struct ipr_mode_page28));
6689 entry_length = mode_page->entry_length;
6691 /* Loop for each device bus entry */
6692 for (i = 0, bus = mode_page->bus;
6693 i < mode_page->num_entries;
6694 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
6695 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
6696 dev_err(&ioa_cfg->pdev->dev,
6697 "Invalid resource address reported: 0x%08X\n",
6698 IPR_GET_PHYS_LOC(bus->res_addr));
6702 bus_attr = &ioa_cfg->bus_attr[i];
6703 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
6704 bus->bus_width = bus_attr->bus_width;
6705 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
6706 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
6707 if (bus_attr->qas_enabled)
6708 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
6710 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
6715 * ipr_build_mode_select - Build a mode select command
6716 * @ipr_cmd: ipr command struct
6717 * @res_handle: resource handle to send command to
6718 * @parm: Byte 2 of Mode Sense command
6719 * @dma_addr: DMA buffer address
6720 * @xfer_len: data transfer length
6725 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
6726 __be32 res_handle, u8 parm,
6727 dma_addr_t dma_addr, u8 xfer_len)
6729 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6731 ioarcb->res_handle = res_handle;
6732 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6733 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6734 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
6735 ioarcb->cmd_pkt.cdb[1] = parm;
6736 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6738 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
6742 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
6743 * @ipr_cmd: ipr command struct
6745 * This function sets up the SCSI bus attributes and sends
6746 * a Mode Select for Page 28 to activate them.
6751 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
6753 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6754 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
6758 ipr_scsi_bus_speed_limit(ioa_cfg);
6759 ipr_check_term_power(ioa_cfg, mode_pages);
6760 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
6761 length = mode_pages->hdr.length + 1;
6762 mode_pages->hdr.length = 0;
6764 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
6765 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
6768 ipr_cmd->job_step = ipr_set_supported_devs;
6769 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
6770 struct ipr_resource_entry, queue);
6771 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6774 return IPR_RC_JOB_RETURN;
6778 * ipr_build_mode_sense - Builds a mode sense command
6779 * @ipr_cmd: ipr command struct
6780 * @res: resource entry struct
6781 * @parm: Byte 2 of mode sense command
6782 * @dma_addr: DMA address of mode sense buffer
6783 * @xfer_len: Size of DMA buffer
6788 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
6790 u8 parm, dma_addr_t dma_addr, u8 xfer_len)
6792 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6794 ioarcb->res_handle = res_handle;
6795 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
6796 ioarcb->cmd_pkt.cdb[2] = parm;
6797 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6798 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6800 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
6804 * ipr_reset_cmd_failed - Handle failure of IOA reset command
6805 * @ipr_cmd: ipr command struct
6807 * This function handles the failure of an IOA bringup command.
6812 static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
6814 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6815 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6817 dev_err(&ioa_cfg->pdev->dev,
6818 "0x%02X failed with IOASC: 0x%08X\n",
6819 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
6821 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
6822 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6823 return IPR_RC_JOB_RETURN;
6827 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
6828 * @ipr_cmd: ipr command struct
6830 * This function handles the failure of a Mode Sense to the IOAFP.
6831 * Some adapters do not handle all mode pages.
6834 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6836 static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
6838 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6839 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6841 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
6842 ipr_cmd->job_step = ipr_set_supported_devs;
6843 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
6844 struct ipr_resource_entry, queue);
6845 return IPR_RC_JOB_CONTINUE;
6848 return ipr_reset_cmd_failed(ipr_cmd);
6852 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
6853 * @ipr_cmd: ipr command struct
6855 * This function send a Page 28 mode sense to the IOA to
6856 * retrieve SCSI bus attributes.
6861 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
6863 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6866 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
6867 0x28, ioa_cfg->vpd_cbs_dma +
6868 offsetof(struct ipr_misc_cbs, mode_pages),
6869 sizeof(struct ipr_mode_pages));
6871 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
6872 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
6874 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6877 return IPR_RC_JOB_RETURN;
6881 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
6882 * @ipr_cmd: ipr command struct
6884 * This function enables dual IOA RAID support if possible.
6889 static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
6891 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6892 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
6893 struct ipr_mode_page24 *mode_page;
6897 mode_page = ipr_get_mode_page(mode_pages, 0x24,
6898 sizeof(struct ipr_mode_page24));
6901 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
6903 length = mode_pages->hdr.length + 1;
6904 mode_pages->hdr.length = 0;
6906 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
6907 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
6910 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6911 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6914 return IPR_RC_JOB_RETURN;
6918 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
6919 * @ipr_cmd: ipr command struct
6921 * This function handles the failure of a Mode Sense to the IOAFP.
6922 * Some adapters do not handle all mode pages.
6925 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6927 static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
6929 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6931 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
6932 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6933 return IPR_RC_JOB_CONTINUE;
6936 return ipr_reset_cmd_failed(ipr_cmd);
6940 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
6941 * @ipr_cmd: ipr command struct
6943 * This function send a mode sense to the IOA to retrieve
6944 * the IOA Advanced Function Control mode page.
6949 static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
6951 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6954 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
6955 0x24, ioa_cfg->vpd_cbs_dma +
6956 offsetof(struct ipr_misc_cbs, mode_pages),
6957 sizeof(struct ipr_mode_pages));
6959 ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
6960 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
6962 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6965 return IPR_RC_JOB_RETURN;
6969 * ipr_init_res_table - Initialize the resource table
6970 * @ipr_cmd: ipr command struct
6972 * This function looks through the existing resource table, comparing
6973 * it with the config table. This function will take care of old/new
6974 * devices and schedule adding/removing them from the mid-layer
6978 * IPR_RC_JOB_CONTINUE
6980 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
6982 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6983 struct ipr_resource_entry *res, *temp;
6984 struct ipr_config_table_entry_wrapper cfgtew;
6985 int entries, found, flag, i;
6990 flag = ioa_cfg->u.cfg_table64->hdr64.flags;
6992 flag = ioa_cfg->u.cfg_table->hdr.flags;
6994 if (flag & IPR_UCODE_DOWNLOAD_REQ)
6995 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
6997 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
6998 list_move_tail(&res->queue, &old_res);
7001 entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
7003 entries = ioa_cfg->u.cfg_table->hdr.num_entries;
7005 for (i = 0; i < entries; i++) {
7007 cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
7009 cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
7012 list_for_each_entry_safe(res, temp, &old_res, queue) {
7013 if (ipr_is_same_device(res, &cfgtew)) {
7014 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7021 if (list_empty(&ioa_cfg->free_res_q)) {
7022 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
7027 res = list_entry(ioa_cfg->free_res_q.next,
7028 struct ipr_resource_entry, queue);
7029 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7030 ipr_init_res_entry(res, &cfgtew);
7032 } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
7033 res->sdev->allow_restart = 1;
7036 ipr_update_res_entry(res, &cfgtew);
7039 list_for_each_entry_safe(res, temp, &old_res, queue) {
7041 res->del_from_ml = 1;
7042 res->res_handle = IPR_INVALID_RES_HANDLE;
7043 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7047 list_for_each_entry_safe(res, temp, &old_res, queue) {
7048 ipr_clear_res_target(res);
7049 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
7052 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
7053 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
7055 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7058 return IPR_RC_JOB_CONTINUE;
7062 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
7063 * @ipr_cmd: ipr command struct
7065 * This function sends a Query IOA Configuration command
7066 * to the adapter to retrieve the IOA configuration table.
7071 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
7073 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7074 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7075 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
7076 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7079 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
7080 ioa_cfg->dual_raid = 1;
7081 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
7082 ucode_vpd->major_release, ucode_vpd->card_type,
7083 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
7084 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7085 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7087 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
7088 ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
7089 ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
7090 ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
7092 ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
7093 IPR_IOADL_FLAGS_READ_LAST);
7095 ipr_cmd->job_step = ipr_init_res_table;
7097 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7100 return IPR_RC_JOB_RETURN;
7104 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
7105 * @ipr_cmd: ipr command struct
7107 * This utility function sends an inquiry to the adapter.
7112 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
7113 dma_addr_t dma_addr, u8 xfer_len)
7115 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7118 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7119 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7121 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
7122 ioarcb->cmd_pkt.cdb[1] = flags;
7123 ioarcb->cmd_pkt.cdb[2] = page;
7124 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7126 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
7128 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7133 * ipr_inquiry_page_supported - Is the given inquiry page supported
7134 * @page0: inquiry page 0 buffer
7137 * This function determines if the specified inquiry page is supported.
7140 * 1 if page is supported / 0 if not
7142 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
7146 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
7147 if (page0->page[i] == page)
7154 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
7155 * @ipr_cmd: ipr command struct
7157 * This function sends a Page 0xD0 inquiry to the adapter
7158 * to retrieve adapter capabilities.
7161 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7163 static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
7165 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7166 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
7167 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7170 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
7171 memset(cap, 0, sizeof(*cap));
7173 if (ipr_inquiry_page_supported(page0, 0xD0)) {
7174 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
7175 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
7176 sizeof(struct ipr_inquiry_cap));
7177 return IPR_RC_JOB_RETURN;
7181 return IPR_RC_JOB_CONTINUE;
7185 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
7186 * @ipr_cmd: ipr command struct
7188 * This function sends a Page 3 inquiry to the adapter
7189 * to retrieve software VPD information.
7192 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7194 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
7196 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7200 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
7202 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
7203 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
7204 sizeof(struct ipr_inquiry_page3));
7207 return IPR_RC_JOB_RETURN;
7211 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
7212 * @ipr_cmd: ipr command struct
7214 * This function sends a Page 0 inquiry to the adapter
7215 * to retrieve supported inquiry pages.
7218 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7220 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
7222 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7227 /* Grab the type out of the VPD and store it away */
7228 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
7230 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
7232 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
7234 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
7235 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
7236 sizeof(struct ipr_inquiry_page0));
7239 return IPR_RC_JOB_RETURN;
7243 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
7244 * @ipr_cmd: ipr command struct
7246 * This function sends a standard inquiry to the adapter.
7251 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
7253 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7256 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
7258 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
7259 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
7260 sizeof(struct ipr_ioa_vpd));
7263 return IPR_RC_JOB_RETURN;
7267 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
7268 * @ipr_cmd: ipr command struct
7270 * This function send an Identify Host Request Response Queue
7271 * command to establish the HRRQ with the adapter.
7276 static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
7278 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7279 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7282 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
7284 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
7285 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7287 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7289 ioarcb->cmd_pkt.cdb[1] = 0x1;
7290 ioarcb->cmd_pkt.cdb[2] =
7291 ((u64) ioa_cfg->host_rrq_dma >> 24) & 0xff;
7292 ioarcb->cmd_pkt.cdb[3] =
7293 ((u64) ioa_cfg->host_rrq_dma >> 16) & 0xff;
7294 ioarcb->cmd_pkt.cdb[4] =
7295 ((u64) ioa_cfg->host_rrq_dma >> 8) & 0xff;
7296 ioarcb->cmd_pkt.cdb[5] =
7297 ((u64) ioa_cfg->host_rrq_dma) & 0xff;
7298 ioarcb->cmd_pkt.cdb[7] =
7299 ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
7300 ioarcb->cmd_pkt.cdb[8] =
7301 (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
7303 if (ioa_cfg->sis64) {
7304 ioarcb->cmd_pkt.cdb[10] =
7305 ((u64) ioa_cfg->host_rrq_dma >> 56) & 0xff;
7306 ioarcb->cmd_pkt.cdb[11] =
7307 ((u64) ioa_cfg->host_rrq_dma >> 48) & 0xff;
7308 ioarcb->cmd_pkt.cdb[12] =
7309 ((u64) ioa_cfg->host_rrq_dma >> 40) & 0xff;
7310 ioarcb->cmd_pkt.cdb[13] =
7311 ((u64) ioa_cfg->host_rrq_dma >> 32) & 0xff;
7314 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
7316 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7319 return IPR_RC_JOB_RETURN;
7323 * ipr_reset_timer_done - Adapter reset timer function
7324 * @ipr_cmd: ipr command struct
7326 * Description: This function is used in adapter reset processing
7327 * for timing events. If the reset_cmd pointer in the IOA
7328 * config struct is not this adapter's we are doing nested
7329 * resets and fail_all_ops will take care of freeing the
7335 static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
7337 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7338 unsigned long lock_flags = 0;
7340 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7342 if (ioa_cfg->reset_cmd == ipr_cmd) {
7343 list_del(&ipr_cmd->queue);
7344 ipr_cmd->done(ipr_cmd);
7347 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7351 * ipr_reset_start_timer - Start a timer for adapter reset job
7352 * @ipr_cmd: ipr command struct
7353 * @timeout: timeout value
7355 * Description: This function is used in adapter reset processing
7356 * for timing events. If the reset_cmd pointer in the IOA
7357 * config struct is not this adapter's we are doing nested
7358 * resets and fail_all_ops will take care of freeing the
7364 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
7365 unsigned long timeout)
7367 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
7368 ipr_cmd->done = ipr_reset_ioa_job;
7370 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7371 ipr_cmd->timer.expires = jiffies + timeout;
7372 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
7373 add_timer(&ipr_cmd->timer);
7377 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7378 * @ioa_cfg: ioa cfg struct
7383 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
7385 memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
7387 /* Initialize Host RRQ pointers */
7388 ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
7389 ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
7390 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
7391 ioa_cfg->toggle_bit = 1;
7393 /* Zero out config table */
7394 memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
7398 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
7399 * @ipr_cmd: ipr command struct
7402 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7404 static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
7406 unsigned long stage, stage_time;
7408 volatile u32 int_reg;
7409 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7412 feedback = readl(ioa_cfg->regs.init_feedback_reg);
7413 stage = feedback & IPR_IPL_INIT_STAGE_MASK;
7414 stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
7416 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
7418 /* sanity check the stage_time value */
7419 if (stage_time == 0)
7420 stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
7421 else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
7422 stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
7423 else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
7424 stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
7426 if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
7427 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
7428 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7429 stage_time = ioa_cfg->transop_timeout;
7430 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7431 } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
7432 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
7433 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7434 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7435 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7436 maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
7437 writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
7438 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7439 return IPR_RC_JOB_CONTINUE;
7443 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7444 ipr_cmd->timer.expires = jiffies + stage_time * HZ;
7445 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7446 ipr_cmd->done = ipr_reset_ioa_job;
7447 add_timer(&ipr_cmd->timer);
7448 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
7450 return IPR_RC_JOB_RETURN;
7454 * ipr_reset_enable_ioa - Enable the IOA following a reset.
7455 * @ipr_cmd: ipr command struct
7457 * This function reinitializes some control blocks and
7458 * enables destructive diagnostics on the adapter.
7463 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
7465 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7466 volatile u32 int_reg;
7467 volatile u64 maskval;
7470 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7471 ipr_init_ioa_mem(ioa_cfg);
7473 ioa_cfg->allow_interrupts = 1;
7474 if (ioa_cfg->sis64) {
7475 /* Set the adapter to the correct endian mode. */
7476 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
7477 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
7480 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
7482 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7483 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
7484 ioa_cfg->regs.clr_interrupt_mask_reg32);
7485 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7486 return IPR_RC_JOB_CONTINUE;
7489 /* Enable destructive diagnostics on IOA */
7490 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
7492 if (ioa_cfg->sis64) {
7493 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7494 maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
7495 writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
7497 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
7499 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7501 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
7503 if (ioa_cfg->sis64) {
7504 ipr_cmd->job_step = ipr_reset_next_stage;
7505 return IPR_RC_JOB_CONTINUE;
7508 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7509 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
7510 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7511 ipr_cmd->done = ipr_reset_ioa_job;
7512 add_timer(&ipr_cmd->timer);
7513 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
7516 return IPR_RC_JOB_RETURN;
7520 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
7521 * @ipr_cmd: ipr command struct
7523 * This function is invoked when an adapter dump has run out
7524 * of processing time.
7527 * IPR_RC_JOB_CONTINUE
7529 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
7531 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7533 if (ioa_cfg->sdt_state == GET_DUMP)
7534 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7535 else if (ioa_cfg->sdt_state == READ_DUMP)
7536 ioa_cfg->sdt_state = ABORT_DUMP;
7538 ioa_cfg->dump_timeout = 1;
7539 ipr_cmd->job_step = ipr_reset_alert;
7541 return IPR_RC_JOB_CONTINUE;
7545 * ipr_unit_check_no_data - Log a unit check/no data error log
7546 * @ioa_cfg: ioa config struct
7548 * Logs an error indicating the adapter unit checked, but for some
7549 * reason, we were unable to fetch the unit check buffer.
7554 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
7556 ioa_cfg->errors_logged++;
7557 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
7561 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
7562 * @ioa_cfg: ioa config struct
7564 * Fetches the unit check buffer from the adapter by clocking the data
7565 * through the mailbox register.
7570 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
7572 unsigned long mailbox;
7573 struct ipr_hostrcb *hostrcb;
7574 struct ipr_uc_sdt sdt;
7578 mailbox = readl(ioa_cfg->ioa_mailbox);
7580 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
7581 ipr_unit_check_no_data(ioa_cfg);
7585 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
7586 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
7587 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
7589 if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
7590 ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
7591 (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
7592 ipr_unit_check_no_data(ioa_cfg);
7596 /* Find length of the first sdt entry (UC buffer) */
7597 if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
7598 length = be32_to_cpu(sdt.entry[0].end_token);
7600 length = (be32_to_cpu(sdt.entry[0].end_token) -
7601 be32_to_cpu(sdt.entry[0].start_token)) &
7602 IPR_FMT2_MBX_ADDR_MASK;
7604 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
7605 struct ipr_hostrcb, queue);
7606 list_del(&hostrcb->queue);
7607 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
7609 rc = ipr_get_ldump_data_section(ioa_cfg,
7610 be32_to_cpu(sdt.entry[0].start_token),
7611 (__be32 *)&hostrcb->hcam,
7612 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
7615 ipr_handle_log_data(ioa_cfg, hostrcb);
7616 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
7617 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
7618 ioa_cfg->sdt_state == GET_DUMP)
7619 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7621 ipr_unit_check_no_data(ioa_cfg);
7623 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
7627 * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
7628 * @ipr_cmd: ipr command struct
7630 * Description: This function will call to get the unit check buffer.
7635 static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
7637 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7640 ioa_cfg->ioa_unit_checked = 0;
7641 ipr_get_unit_check_buffer(ioa_cfg);
7642 ipr_cmd->job_step = ipr_reset_alert;
7643 ipr_reset_start_timer(ipr_cmd, 0);
7646 return IPR_RC_JOB_RETURN;
7650 * ipr_reset_restore_cfg_space - Restore PCI config space.
7651 * @ipr_cmd: ipr command struct
7653 * Description: This function restores the saved PCI config space of
7654 * the adapter, fails all outstanding ops back to the callers, and
7655 * fetches the dump/unit check if applicable to this reset.
7658 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7660 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
7662 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7666 ioa_cfg->pdev->state_saved = true;
7667 pci_restore_state(ioa_cfg->pdev);
7669 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
7670 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
7671 return IPR_RC_JOB_CONTINUE;
7674 ipr_fail_all_ops(ioa_cfg);
7676 if (ioa_cfg->sis64) {
7677 /* Set the adapter to the correct endian mode. */
7678 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
7679 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
7682 if (ioa_cfg->ioa_unit_checked) {
7683 if (ioa_cfg->sis64) {
7684 ipr_cmd->job_step = ipr_reset_get_unit_check_job;
7685 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
7686 return IPR_RC_JOB_RETURN;
7688 ioa_cfg->ioa_unit_checked = 0;
7689 ipr_get_unit_check_buffer(ioa_cfg);
7690 ipr_cmd->job_step = ipr_reset_alert;
7691 ipr_reset_start_timer(ipr_cmd, 0);
7692 return IPR_RC_JOB_RETURN;
7696 if (ioa_cfg->in_ioa_bringdown) {
7697 ipr_cmd->job_step = ipr_ioa_bringdown_done;
7699 ipr_cmd->job_step = ipr_reset_enable_ioa;
7701 if (GET_DUMP == ioa_cfg->sdt_state) {
7702 ioa_cfg->sdt_state = READ_DUMP;
7703 ioa_cfg->dump_timeout = 0;
7705 ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
7707 ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
7708 ipr_cmd->job_step = ipr_reset_wait_for_dump;
7709 schedule_work(&ioa_cfg->work_q);
7710 return IPR_RC_JOB_RETURN;
7715 return IPR_RC_JOB_CONTINUE;
7719 * ipr_reset_bist_done - BIST has completed on the adapter.
7720 * @ipr_cmd: ipr command struct
7722 * Description: Unblock config space and resume the reset process.
7725 * IPR_RC_JOB_CONTINUE
7727 static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
7729 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7732 if (ioa_cfg->cfg_locked)
7733 pci_cfg_access_unlock(ioa_cfg->pdev);
7734 ioa_cfg->cfg_locked = 0;
7735 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
7737 return IPR_RC_JOB_CONTINUE;
7741 * ipr_reset_start_bist - Run BIST on the adapter.
7742 * @ipr_cmd: ipr command struct
7744 * Description: This function runs BIST on the adapter, then delays 2 seconds.
7747 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7749 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
7751 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7752 int rc = PCIBIOS_SUCCESSFUL;
7755 if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
7756 writel(IPR_UPROCI_SIS64_START_BIST,
7757 ioa_cfg->regs.set_uproc_interrupt_reg32);
7759 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
7761 if (rc == PCIBIOS_SUCCESSFUL) {
7762 ipr_cmd->job_step = ipr_reset_bist_done;
7763 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
7764 rc = IPR_RC_JOB_RETURN;
7766 if (ioa_cfg->cfg_locked)
7767 pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
7768 ioa_cfg->cfg_locked = 0;
7769 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
7770 rc = IPR_RC_JOB_CONTINUE;
7778 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
7779 * @ipr_cmd: ipr command struct
7781 * Description: This clears PCI reset to the adapter and delays two seconds.
7786 static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
7789 pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
7790 ipr_cmd->job_step = ipr_reset_bist_done;
7791 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
7793 return IPR_RC_JOB_RETURN;
7797 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
7798 * @ipr_cmd: ipr command struct
7800 * Description: This asserts PCI reset to the adapter.
7805 static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
7807 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7808 struct pci_dev *pdev = ioa_cfg->pdev;
7811 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
7812 ipr_cmd->job_step = ipr_reset_slot_reset_done;
7813 ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
7815 return IPR_RC_JOB_RETURN;
7819 * ipr_reset_block_config_access_wait - Wait for permission to block config access
7820 * @ipr_cmd: ipr command struct
7822 * Description: This attempts to block config access to the IOA.
7825 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7827 static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
7829 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7830 int rc = IPR_RC_JOB_CONTINUE;
7832 if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
7833 ioa_cfg->cfg_locked = 1;
7834 ipr_cmd->job_step = ioa_cfg->reset;
7836 if (ipr_cmd->u.time_left) {
7837 rc = IPR_RC_JOB_RETURN;
7838 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
7839 ipr_reset_start_timer(ipr_cmd,
7840 IPR_CHECK_FOR_RESET_TIMEOUT);
7842 ipr_cmd->job_step = ioa_cfg->reset;
7843 dev_err(&ioa_cfg->pdev->dev,
7844 "Timed out waiting to lock config access. Resetting anyway.\n");
7852 * ipr_reset_block_config_access - Block config access to the IOA
7853 * @ipr_cmd: ipr command struct
7855 * Description: This attempts to block config access to the IOA
7858 * IPR_RC_JOB_CONTINUE
7860 static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
7862 ipr_cmd->ioa_cfg->cfg_locked = 0;
7863 ipr_cmd->job_step = ipr_reset_block_config_access_wait;
7864 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
7865 return IPR_RC_JOB_CONTINUE;
7869 * ipr_reset_allowed - Query whether or not IOA can be reset
7870 * @ioa_cfg: ioa config struct
7873 * 0 if reset not allowed / non-zero if reset is allowed
7875 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
7877 volatile u32 temp_reg;
7879 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
7880 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
7884 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
7885 * @ipr_cmd: ipr command struct
7887 * Description: This function waits for adapter permission to run BIST,
7888 * then runs BIST. If the adapter does not give permission after a
7889 * reasonable time, we will reset the adapter anyway. The impact of
7890 * resetting the adapter without warning the adapter is the risk of
7891 * losing the persistent error log on the adapter. If the adapter is
7892 * reset while it is writing to the flash on the adapter, the flash
7893 * segment will have bad ECC and be zeroed.
7896 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7898 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
7900 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7901 int rc = IPR_RC_JOB_RETURN;
7903 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
7904 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
7905 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
7907 ipr_cmd->job_step = ipr_reset_block_config_access;
7908 rc = IPR_RC_JOB_CONTINUE;
7915 * ipr_reset_alert - Alert the adapter of a pending reset
7916 * @ipr_cmd: ipr command struct
7918 * Description: This function alerts the adapter that it will be reset.
7919 * If memory space is not currently enabled, proceed directly
7920 * to running BIST on the adapter. The timer must always be started
7921 * so we guarantee we do not run BIST from ipr_isr.
7926 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
7928 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7933 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
7935 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
7936 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
7937 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
7938 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
7940 ipr_cmd->job_step = ipr_reset_block_config_access;
7943 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
7944 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
7947 return IPR_RC_JOB_RETURN;
7951 * ipr_reset_ucode_download_done - Microcode download completion
7952 * @ipr_cmd: ipr command struct
7954 * Description: This function unmaps the microcode download buffer.
7957 * IPR_RC_JOB_CONTINUE
7959 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
7961 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7962 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
7964 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
7965 sglist->num_sg, DMA_TO_DEVICE);
7967 ipr_cmd->job_step = ipr_reset_alert;
7968 return IPR_RC_JOB_CONTINUE;
7972 * ipr_reset_ucode_download - Download microcode to the adapter
7973 * @ipr_cmd: ipr command struct
7975 * Description: This function checks to see if it there is microcode
7976 * to download to the adapter. If there is, a download is performed.
7979 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7981 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
7983 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7984 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
7987 ipr_cmd->job_step = ipr_reset_alert;
7990 return IPR_RC_JOB_CONTINUE;
7992 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7993 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7994 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
7995 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
7996 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
7997 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
7998 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
8001 ipr_build_ucode_ioadl64(ipr_cmd, sglist);
8003 ipr_build_ucode_ioadl(ipr_cmd, sglist);
8004 ipr_cmd->job_step = ipr_reset_ucode_download_done;
8006 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
8007 IPR_WRITE_BUFFER_TIMEOUT);
8010 return IPR_RC_JOB_RETURN;
8014 * ipr_reset_shutdown_ioa - Shutdown the adapter
8015 * @ipr_cmd: ipr command struct
8017 * Description: This function issues an adapter shutdown of the
8018 * specified type to the specified adapter as part of the
8019 * adapter reset job.
8022 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8024 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
8026 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8027 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
8028 unsigned long timeout;
8029 int rc = IPR_RC_JOB_CONTINUE;
8032 if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
8033 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8034 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8035 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
8036 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
8038 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
8039 timeout = IPR_SHUTDOWN_TIMEOUT;
8040 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
8041 timeout = IPR_INTERNAL_TIMEOUT;
8042 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
8043 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
8045 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
8047 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
8049 rc = IPR_RC_JOB_RETURN;
8050 ipr_cmd->job_step = ipr_reset_ucode_download;
8052 ipr_cmd->job_step = ipr_reset_alert;
8059 * ipr_reset_ioa_job - Adapter reset job
8060 * @ipr_cmd: ipr command struct
8062 * Description: This function is the job router for the adapter reset job.
8067 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
8070 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8073 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
8075 if (ioa_cfg->reset_cmd != ipr_cmd) {
8077 * We are doing nested adapter resets and this is
8078 * not the current reset job.
8080 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
8084 if (IPR_IOASC_SENSE_KEY(ioasc)) {
8085 rc = ipr_cmd->job_step_failed(ipr_cmd);
8086 if (rc == IPR_RC_JOB_RETURN)
8090 ipr_reinit_ipr_cmnd(ipr_cmd);
8091 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
8092 rc = ipr_cmd->job_step(ipr_cmd);
8093 } while(rc == IPR_RC_JOB_CONTINUE);
8097 * _ipr_initiate_ioa_reset - Initiate an adapter reset
8098 * @ioa_cfg: ioa config struct
8099 * @job_step: first job step of reset job
8100 * @shutdown_type: shutdown type
8102 * Description: This function will initiate the reset of the given adapter
8103 * starting at the selected job step.
8104 * If the caller needs to wait on the completion of the reset,
8105 * the caller must sleep on the reset_wait_q.
8110 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8111 int (*job_step) (struct ipr_cmnd *),
8112 enum ipr_shutdown_type shutdown_type)
8114 struct ipr_cmnd *ipr_cmd;
8116 ioa_cfg->in_reset_reload = 1;
8117 ioa_cfg->allow_cmds = 0;
8118 scsi_block_requests(ioa_cfg->host);
8120 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
8121 ioa_cfg->reset_cmd = ipr_cmd;
8122 ipr_cmd->job_step = job_step;
8123 ipr_cmd->u.shutdown_type = shutdown_type;
8125 ipr_reset_ioa_job(ipr_cmd);
8129 * ipr_initiate_ioa_reset - Initiate an adapter reset
8130 * @ioa_cfg: ioa config struct
8131 * @shutdown_type: shutdown type
8133 * Description: This function will initiate the reset of the given adapter.
8134 * If the caller needs to wait on the completion of the reset,
8135 * the caller must sleep on the reset_wait_q.
8140 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8141 enum ipr_shutdown_type shutdown_type)
8143 if (ioa_cfg->ioa_is_dead)
8146 if (ioa_cfg->in_reset_reload) {
8147 if (ioa_cfg->sdt_state == GET_DUMP)
8148 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8149 else if (ioa_cfg->sdt_state == READ_DUMP)
8150 ioa_cfg->sdt_state = ABORT_DUMP;
8153 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
8154 dev_err(&ioa_cfg->pdev->dev,
8155 "IOA taken offline - error recovery failed\n");
8157 ioa_cfg->reset_retries = 0;
8158 ioa_cfg->ioa_is_dead = 1;
8160 if (ioa_cfg->in_ioa_bringdown) {
8161 ioa_cfg->reset_cmd = NULL;
8162 ioa_cfg->in_reset_reload = 0;
8163 ipr_fail_all_ops(ioa_cfg);
8164 wake_up_all(&ioa_cfg->reset_wait_q);
8166 spin_unlock_irq(ioa_cfg->host->host_lock);
8167 scsi_unblock_requests(ioa_cfg->host);
8168 spin_lock_irq(ioa_cfg->host->host_lock);
8171 ioa_cfg->in_ioa_bringdown = 1;
8172 shutdown_type = IPR_SHUTDOWN_NONE;
8176 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
8181 * ipr_reset_freeze - Hold off all I/O activity
8182 * @ipr_cmd: ipr command struct
8184 * Description: If the PCI slot is frozen, hold off all I/O
8185 * activity; then, as soon as the slot is available again,
8186 * initiate an adapter reset.
8188 static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
8190 /* Disallow new interrupts, avoid loop */
8191 ipr_cmd->ioa_cfg->allow_interrupts = 0;
8192 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
8193 ipr_cmd->done = ipr_reset_ioa_job;
8194 return IPR_RC_JOB_RETURN;
8198 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
8199 * @pdev: PCI device struct
8201 * Description: This routine is called to tell us that the PCI bus
8202 * is down. Can't do anything here, except put the device driver
8203 * into a holding pattern, waiting for the PCI bus to come back.
8205 static void ipr_pci_frozen(struct pci_dev *pdev)
8207 unsigned long flags = 0;
8208 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8210 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8211 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
8212 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8216 * ipr_pci_slot_reset - Called when PCI slot has been reset.
8217 * @pdev: PCI device struct
8219 * Description: This routine is called by the pci error recovery
8220 * code after the PCI slot has been reset, just before we
8221 * should resume normal operations.
8223 static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
8225 unsigned long flags = 0;
8226 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8228 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8229 if (ioa_cfg->needs_warm_reset)
8230 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8232 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
8234 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8235 return PCI_ERS_RESULT_RECOVERED;
8239 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
8240 * @pdev: PCI device struct
8242 * Description: This routine is called when the PCI bus has
8243 * permanently failed.
8245 static void ipr_pci_perm_failure(struct pci_dev *pdev)
8247 unsigned long flags = 0;
8248 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8250 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8251 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
8252 ioa_cfg->sdt_state = ABORT_DUMP;
8253 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES;
8254 ioa_cfg->in_ioa_bringdown = 1;
8255 ioa_cfg->allow_cmds = 0;
8256 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8257 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8261 * ipr_pci_error_detected - Called when a PCI error is detected.
8262 * @pdev: PCI device struct
8263 * @state: PCI channel state
8265 * Description: Called when a PCI error is detected.
8268 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8270 static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
8271 pci_channel_state_t state)
8274 case pci_channel_io_frozen:
8275 ipr_pci_frozen(pdev);
8276 return PCI_ERS_RESULT_NEED_RESET;
8277 case pci_channel_io_perm_failure:
8278 ipr_pci_perm_failure(pdev);
8279 return PCI_ERS_RESULT_DISCONNECT;
8284 return PCI_ERS_RESULT_NEED_RESET;
8288 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
8289 * @ioa_cfg: ioa cfg struct
8291 * Description: This is the second phase of adapter intialization
8292 * This function takes care of initilizing the adapter to the point
8293 * where it can accept new commands.
8296 * 0 on success / -EIO on failure
8298 static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
8301 unsigned long host_lock_flags = 0;
8304 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8305 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
8306 if (ioa_cfg->needs_hard_reset) {
8307 ioa_cfg->needs_hard_reset = 0;
8308 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8310 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
8313 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8314 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
8315 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8317 if (ioa_cfg->ioa_is_dead) {
8319 } else if (ipr_invalid_adapter(ioa_cfg)) {
8323 dev_err(&ioa_cfg->pdev->dev,
8324 "Adapter not supported in this hardware configuration.\n");
8327 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8334 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
8335 * @ioa_cfg: ioa config struct
8340 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8344 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8345 if (ioa_cfg->ipr_cmnd_list[i])
8346 pci_pool_free(ioa_cfg->ipr_cmd_pool,
8347 ioa_cfg->ipr_cmnd_list[i],
8348 ioa_cfg->ipr_cmnd_list_dma[i]);
8350 ioa_cfg->ipr_cmnd_list[i] = NULL;
8353 if (ioa_cfg->ipr_cmd_pool)
8354 pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
8356 kfree(ioa_cfg->ipr_cmnd_list);
8357 kfree(ioa_cfg->ipr_cmnd_list_dma);
8358 ioa_cfg->ipr_cmnd_list = NULL;
8359 ioa_cfg->ipr_cmnd_list_dma = NULL;
8360 ioa_cfg->ipr_cmd_pool = NULL;
8364 * ipr_free_mem - Frees memory allocated for an adapter
8365 * @ioa_cfg: ioa cfg struct
8370 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
8374 kfree(ioa_cfg->res_entries);
8375 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
8376 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8377 ipr_free_cmd_blks(ioa_cfg);
8378 pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
8379 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
8380 pci_free_consistent(ioa_cfg->pdev, ioa_cfg->cfg_table_size,
8381 ioa_cfg->u.cfg_table,
8382 ioa_cfg->cfg_table_dma);
8384 for (i = 0; i < IPR_NUM_HCAMS; i++) {
8385 pci_free_consistent(ioa_cfg->pdev,
8386 sizeof(struct ipr_hostrcb),
8387 ioa_cfg->hostrcb[i],
8388 ioa_cfg->hostrcb_dma[i]);
8391 ipr_free_dump(ioa_cfg);
8392 kfree(ioa_cfg->trace);
8396 * ipr_free_all_resources - Free all allocated resources for an adapter.
8397 * @ipr_cmd: ipr command struct
8399 * This function frees all allocated resources for the
8400 * specified adapter.
8405 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
8407 struct pci_dev *pdev = ioa_cfg->pdev;
8410 free_irq(pdev->irq, ioa_cfg);
8411 pci_disable_msi(pdev);
8412 iounmap(ioa_cfg->hdw_dma_regs);
8413 pci_release_regions(pdev);
8414 ipr_free_mem(ioa_cfg);
8415 scsi_host_put(ioa_cfg->host);
8416 pci_disable_device(pdev);
8421 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
8422 * @ioa_cfg: ioa config struct
8425 * 0 on success / -ENOMEM on allocation failure
8427 static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8429 struct ipr_cmnd *ipr_cmd;
8430 struct ipr_ioarcb *ioarcb;
8431 dma_addr_t dma_addr;
8434 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
8435 sizeof(struct ipr_cmnd), 512, 0);
8437 if (!ioa_cfg->ipr_cmd_pool)
8440 ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
8441 ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
8443 if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
8444 ipr_free_cmd_blks(ioa_cfg);
8448 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8449 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
8452 ipr_free_cmd_blks(ioa_cfg);
8456 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
8457 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
8458 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
8460 ioarcb = &ipr_cmd->ioarcb;
8461 ipr_cmd->dma_addr = dma_addr;
8463 ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
8465 ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
8467 ioarcb->host_response_handle = cpu_to_be32(i << 2);
8468 if (ioa_cfg->sis64) {
8469 ioarcb->u.sis64_addr_data.data_ioadl_addr =
8470 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
8471 ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
8472 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
8474 ioarcb->write_ioadl_addr =
8475 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
8476 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
8477 ioarcb->ioasa_host_pci_addr =
8478 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
8480 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
8481 ipr_cmd->cmd_index = i;
8482 ipr_cmd->ioa_cfg = ioa_cfg;
8483 ipr_cmd->sense_buffer_dma = dma_addr +
8484 offsetof(struct ipr_cmnd, sense_buffer);
8486 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
8493 * ipr_alloc_mem - Allocate memory for an adapter
8494 * @ioa_cfg: ioa config struct
8497 * 0 on success / non-zero for error
8499 static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
8501 struct pci_dev *pdev = ioa_cfg->pdev;
8502 int i, rc = -ENOMEM;
8505 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
8506 ioa_cfg->max_devs_supported, GFP_KERNEL);
8508 if (!ioa_cfg->res_entries)
8511 if (ioa_cfg->sis64) {
8512 ioa_cfg->target_ids = kzalloc(sizeof(unsigned long) *
8513 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8514 ioa_cfg->array_ids = kzalloc(sizeof(unsigned long) *
8515 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8516 ioa_cfg->vset_ids = kzalloc(sizeof(unsigned long) *
8517 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8520 for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
8521 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
8522 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
8525 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
8526 sizeof(struct ipr_misc_cbs),
8527 &ioa_cfg->vpd_cbs_dma);
8529 if (!ioa_cfg->vpd_cbs)
8530 goto out_free_res_entries;
8532 if (ipr_alloc_cmd_blks(ioa_cfg))
8533 goto out_free_vpd_cbs;
8535 ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
8536 sizeof(u32) * IPR_NUM_CMD_BLKS,
8537 &ioa_cfg->host_rrq_dma);
8539 if (!ioa_cfg->host_rrq)
8540 goto out_ipr_free_cmd_blocks;
8542 ioa_cfg->u.cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
8543 ioa_cfg->cfg_table_size,
8544 &ioa_cfg->cfg_table_dma);
8546 if (!ioa_cfg->u.cfg_table)
8547 goto out_free_host_rrq;
8549 for (i = 0; i < IPR_NUM_HCAMS; i++) {
8550 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
8551 sizeof(struct ipr_hostrcb),
8552 &ioa_cfg->hostrcb_dma[i]);
8554 if (!ioa_cfg->hostrcb[i])
8555 goto out_free_hostrcb_dma;
8557 ioa_cfg->hostrcb[i]->hostrcb_dma =
8558 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
8559 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
8560 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
8563 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
8564 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
8566 if (!ioa_cfg->trace)
8567 goto out_free_hostrcb_dma;
8574 out_free_hostrcb_dma:
8576 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
8577 ioa_cfg->hostrcb[i],
8578 ioa_cfg->hostrcb_dma[i]);
8580 pci_free_consistent(pdev, ioa_cfg->cfg_table_size,
8581 ioa_cfg->u.cfg_table,
8582 ioa_cfg->cfg_table_dma);
8584 pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
8585 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
8586 out_ipr_free_cmd_blocks:
8587 ipr_free_cmd_blks(ioa_cfg);
8589 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
8590 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8591 out_free_res_entries:
8592 kfree(ioa_cfg->res_entries);
8597 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
8598 * @ioa_cfg: ioa config struct
8603 static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
8607 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
8608 ioa_cfg->bus_attr[i].bus = i;
8609 ioa_cfg->bus_attr[i].qas_enabled = 0;
8610 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
8611 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
8612 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
8614 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
8619 * ipr_init_ioa_cfg - Initialize IOA config struct
8620 * @ioa_cfg: ioa config struct
8621 * @host: scsi host struct
8622 * @pdev: PCI dev struct
8627 static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
8628 struct Scsi_Host *host, struct pci_dev *pdev)
8630 const struct ipr_interrupt_offsets *p;
8631 struct ipr_interrupts *t;
8634 ioa_cfg->host = host;
8635 ioa_cfg->pdev = pdev;
8636 ioa_cfg->log_level = ipr_log_level;
8637 ioa_cfg->doorbell = IPR_DOORBELL;
8638 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
8639 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
8640 sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
8641 sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
8642 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
8643 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
8644 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
8645 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
8647 INIT_LIST_HEAD(&ioa_cfg->free_q);
8648 INIT_LIST_HEAD(&ioa_cfg->pending_q);
8649 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
8650 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
8651 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
8652 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
8653 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
8654 init_waitqueue_head(&ioa_cfg->reset_wait_q);
8655 init_waitqueue_head(&ioa_cfg->msi_wait_q);
8656 ioa_cfg->sdt_state = INACTIVE;
8658 ipr_initialize_bus_attr(ioa_cfg);
8659 ioa_cfg->max_devs_supported = ipr_max_devs;
8661 if (ioa_cfg->sis64) {
8662 host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
8663 host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
8664 if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
8665 ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
8667 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
8668 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
8669 if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
8670 ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
8672 host->max_channel = IPR_MAX_BUS_TO_SCAN;
8673 host->unique_id = host->host_no;
8674 host->max_cmd_len = IPR_MAX_CDB_LEN;
8675 host->can_queue = ioa_cfg->max_cmds;
8676 pci_set_drvdata(pdev, ioa_cfg);
8678 p = &ioa_cfg->chip_cfg->regs;
8680 base = ioa_cfg->hdw_dma_regs;
8682 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
8683 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
8684 t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
8685 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
8686 t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
8687 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
8688 t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
8689 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
8690 t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
8691 t->ioarrin_reg = base + p->ioarrin_reg;
8692 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
8693 t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
8694 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
8695 t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
8696 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
8697 t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
8699 if (ioa_cfg->sis64) {
8700 t->init_feedback_reg = base + p->init_feedback_reg;
8701 t->dump_addr_reg = base + p->dump_addr_reg;
8702 t->dump_data_reg = base + p->dump_data_reg;
8703 t->endian_swap_reg = base + p->endian_swap_reg;
8708 * ipr_get_chip_info - Find adapter chip information
8709 * @dev_id: PCI device id struct
8712 * ptr to chip information on success / NULL on failure
8714 static const struct ipr_chip_t * __devinit
8715 ipr_get_chip_info(const struct pci_device_id *dev_id)
8719 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
8720 if (ipr_chip[i].vendor == dev_id->vendor &&
8721 ipr_chip[i].device == dev_id->device)
8722 return &ipr_chip[i];
8727 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
8728 * @pdev: PCI device struct
8730 * Description: Simply set the msi_received flag to 1 indicating that
8731 * Message Signaled Interrupts are supported.
8734 * 0 on success / non-zero on failure
8736 static irqreturn_t __devinit ipr_test_intr(int irq, void *devp)
8738 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
8739 unsigned long lock_flags = 0;
8740 irqreturn_t rc = IRQ_HANDLED;
8742 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8744 ioa_cfg->msi_received = 1;
8745 wake_up(&ioa_cfg->msi_wait_q);
8747 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8752 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
8753 * @pdev: PCI device struct
8755 * Description: The return value from pci_enable_msi() can not always be
8756 * trusted. This routine sets up and initiates a test interrupt to determine
8757 * if the interrupt is received via the ipr_test_intr() service routine.
8758 * If the tests fails, the driver will fall back to LSI.
8761 * 0 on success / non-zero on failure
8763 static int __devinit ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg,
8764 struct pci_dev *pdev)
8767 volatile u32 int_reg;
8768 unsigned long lock_flags = 0;
8772 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8773 init_waitqueue_head(&ioa_cfg->msi_wait_q);
8774 ioa_cfg->msi_received = 0;
8775 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
8776 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
8777 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8778 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8780 rc = request_irq(pdev->irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
8782 dev_err(&pdev->dev, "Can not assign irq %d\n", pdev->irq);
8784 } else if (ipr_debug)
8785 dev_info(&pdev->dev, "IRQ assigned: %d\n", pdev->irq);
8787 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
8788 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
8789 wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
8790 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
8792 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8793 if (!ioa_cfg->msi_received) {
8794 /* MSI test failed */
8795 dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
8797 } else if (ipr_debug)
8798 dev_info(&pdev->dev, "MSI test succeeded.\n");
8800 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8802 free_irq(pdev->irq, ioa_cfg);
8810 * ipr_probe_ioa - Allocates memory and does first stage of initialization
8811 * @pdev: PCI device struct
8812 * @dev_id: PCI device id struct
8815 * 0 on success / non-zero on failure
8817 static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
8818 const struct pci_device_id *dev_id)
8820 struct ipr_ioa_cfg *ioa_cfg;
8821 struct Scsi_Host *host;
8822 unsigned long ipr_regs_pci;
8823 void __iomem *ipr_regs;
8824 int rc = PCIBIOS_SUCCESSFUL;
8825 volatile u32 mask, uproc, interrupts;
8829 if ((rc = pci_enable_device(pdev))) {
8830 dev_err(&pdev->dev, "Cannot enable adapter\n");
8834 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
8836 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
8839 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
8844 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
8845 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
8846 ata_host_init(&ioa_cfg->ata_host, &pdev->dev, &ipr_sata_ops);
8848 ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
8850 if (!ioa_cfg->ipr_chip) {
8851 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
8852 dev_id->vendor, dev_id->device);
8853 goto out_scsi_host_put;
8856 /* set SIS 32 or SIS 64 */
8857 ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
8858 ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
8859 ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
8860 ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
8862 if (ipr_transop_timeout)
8863 ioa_cfg->transop_timeout = ipr_transop_timeout;
8864 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
8865 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
8867 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
8869 ioa_cfg->revid = pdev->revision;
8871 ipr_regs_pci = pci_resource_start(pdev, 0);
8873 rc = pci_request_regions(pdev, IPR_NAME);
8876 "Couldn't register memory range of registers\n");
8877 goto out_scsi_host_put;
8880 ipr_regs = pci_ioremap_bar(pdev, 0);
8884 "Couldn't map memory range of registers\n");
8886 goto out_release_regions;
8889 ioa_cfg->hdw_dma_regs = ipr_regs;
8890 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
8891 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
8893 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
8895 pci_set_master(pdev);
8897 if (ioa_cfg->sis64) {
8898 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
8900 dev_dbg(&pdev->dev, "Failed to set 64 bit PCI DMA mask\n");
8901 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
8905 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
8908 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
8912 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
8913 ioa_cfg->chip_cfg->cache_line_size);
8915 if (rc != PCIBIOS_SUCCESSFUL) {
8916 dev_err(&pdev->dev, "Write of cache line size failed\n");
8921 /* Enable MSI style interrupts if they are supported. */
8922 if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI && !pci_enable_msi(pdev)) {
8923 rc = ipr_test_msi(ioa_cfg, pdev);
8924 if (rc == -EOPNOTSUPP)
8925 pci_disable_msi(pdev);
8927 goto out_msi_disable;
8929 dev_info(&pdev->dev, "MSI enabled with IRQ: %d\n", pdev->irq);
8930 } else if (ipr_debug)
8931 dev_info(&pdev->dev, "Cannot enable MSI.\n");
8933 /* Save away PCI config space for use following IOA reset */
8934 rc = pci_save_state(pdev);
8936 if (rc != PCIBIOS_SUCCESSFUL) {
8937 dev_err(&pdev->dev, "Failed to save PCI config space\n");
8939 goto out_msi_disable;
8942 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
8943 goto out_msi_disable;
8945 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
8946 goto out_msi_disable;
8949 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
8950 + ((sizeof(struct ipr_config_table_entry64)
8951 * ioa_cfg->max_devs_supported)));
8953 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
8954 + ((sizeof(struct ipr_config_table_entry)
8955 * ioa_cfg->max_devs_supported)));
8957 rc = ipr_alloc_mem(ioa_cfg);
8960 "Couldn't allocate enough memory for device driver!\n");
8961 goto out_msi_disable;
8965 * If HRRQ updated interrupt is not masked, or reset alert is set,
8966 * the card is in an unknown state and needs a hard reset
8968 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
8969 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
8970 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
8971 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
8972 ioa_cfg->needs_hard_reset = 1;
8973 if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
8974 ioa_cfg->needs_hard_reset = 1;
8975 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
8976 ioa_cfg->ioa_unit_checked = 1;
8978 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
8979 rc = request_irq(pdev->irq, ipr_isr,
8980 ioa_cfg->msi_received ? 0 : IRQF_SHARED,
8984 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
8989 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
8990 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
8991 ioa_cfg->needs_warm_reset = 1;
8992 ioa_cfg->reset = ipr_reset_slot_reset;
8994 ioa_cfg->reset = ipr_reset_start_bist;
8996 spin_lock(&ipr_driver_lock);
8997 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
8998 spin_unlock(&ipr_driver_lock);
9005 ipr_free_mem(ioa_cfg);
9007 pci_disable_msi(pdev);
9010 out_release_regions:
9011 pci_release_regions(pdev);
9013 scsi_host_put(host);
9015 pci_disable_device(pdev);
9020 * ipr_scan_vsets - Scans for VSET devices
9021 * @ioa_cfg: ioa config struct
9023 * Description: Since the VSET resources do not follow SAM in that we can have
9024 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
9029 static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
9033 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
9034 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
9035 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
9039 * ipr_initiate_ioa_bringdown - Bring down an adapter
9040 * @ioa_cfg: ioa config struct
9041 * @shutdown_type: shutdown type
9043 * Description: This function will initiate bringing down the adapter.
9044 * This consists of issuing an IOA shutdown to the adapter
9045 * to flush the cache, and running BIST.
9046 * If the caller needs to wait on the completion of the reset,
9047 * the caller must sleep on the reset_wait_q.
9052 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
9053 enum ipr_shutdown_type shutdown_type)
9056 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
9057 ioa_cfg->sdt_state = ABORT_DUMP;
9058 ioa_cfg->reset_retries = 0;
9059 ioa_cfg->in_ioa_bringdown = 1;
9060 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
9065 * __ipr_remove - Remove a single adapter
9066 * @pdev: pci device struct
9068 * Adapter hot plug remove entry point.
9073 static void __ipr_remove(struct pci_dev *pdev)
9075 unsigned long host_lock_flags = 0;
9076 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9079 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9080 while(ioa_cfg->in_reset_reload) {
9081 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9082 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9083 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9086 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9088 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9089 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9090 flush_work_sync(&ioa_cfg->work_q);
9091 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9093 spin_lock(&ipr_driver_lock);
9094 list_del(&ioa_cfg->queue);
9095 spin_unlock(&ipr_driver_lock);
9097 if (ioa_cfg->sdt_state == ABORT_DUMP)
9098 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
9099 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9101 ipr_free_all_resources(ioa_cfg);
9107 * ipr_remove - IOA hot plug remove entry point
9108 * @pdev: pci device struct
9110 * Adapter hot plug remove entry point.
9115 static void __devexit ipr_remove(struct pci_dev *pdev)
9117 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9121 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
9123 ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
9125 scsi_remove_host(ioa_cfg->host);
9133 * ipr_probe - Adapter hot plug add entry point
9136 * 0 on success / non-zero on failure
9138 static int __devinit ipr_probe(struct pci_dev *pdev,
9139 const struct pci_device_id *dev_id)
9141 struct ipr_ioa_cfg *ioa_cfg;
9144 rc = ipr_probe_ioa(pdev, dev_id);
9149 ioa_cfg = pci_get_drvdata(pdev);
9150 rc = ipr_probe_ioa_part2(ioa_cfg);
9157 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
9164 rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
9168 scsi_remove_host(ioa_cfg->host);
9173 rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
9177 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
9179 scsi_remove_host(ioa_cfg->host);
9184 scsi_scan_host(ioa_cfg->host);
9185 ipr_scan_vsets(ioa_cfg);
9186 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
9187 ioa_cfg->allow_ml_add_del = 1;
9188 ioa_cfg->host->max_channel = IPR_VSET_BUS;
9189 schedule_work(&ioa_cfg->work_q);
9194 * ipr_shutdown - Shutdown handler.
9195 * @pdev: pci device struct
9197 * This function is invoked upon system shutdown/reboot. It will issue
9198 * an adapter shutdown to the adapter to flush the write cache.
9203 static void ipr_shutdown(struct pci_dev *pdev)
9205 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9206 unsigned long lock_flags = 0;
9208 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9209 while(ioa_cfg->in_reset_reload) {
9210 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9211 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9212 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9215 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9216 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9217 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9220 static struct pci_device_id ipr_pci_table[] __devinitdata = {
9221 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9222 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
9223 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9224 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
9225 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9226 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
9227 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9228 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
9229 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9230 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
9231 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9232 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
9233 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9234 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
9235 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9236 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
9237 IPR_USE_LONG_TRANSOP_TIMEOUT },
9238 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
9239 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
9240 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
9241 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
9242 IPR_USE_LONG_TRANSOP_TIMEOUT },
9243 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
9244 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
9245 IPR_USE_LONG_TRANSOP_TIMEOUT },
9246 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
9247 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
9248 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
9249 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
9250 IPR_USE_LONG_TRANSOP_TIMEOUT},
9251 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
9252 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
9253 IPR_USE_LONG_TRANSOP_TIMEOUT },
9254 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9255 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
9256 IPR_USE_LONG_TRANSOP_TIMEOUT },
9257 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9258 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
9259 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9260 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
9261 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9262 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
9263 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
9264 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
9265 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
9266 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
9267 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
9268 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
9269 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
9270 IPR_USE_LONG_TRANSOP_TIMEOUT },
9271 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
9272 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
9273 IPR_USE_LONG_TRANSOP_TIMEOUT },
9274 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9275 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
9276 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9277 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
9278 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9279 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
9280 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9281 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
9282 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9283 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
9284 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9285 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
9286 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9287 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
9288 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9289 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
9290 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9291 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
9292 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9293 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
9296 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
9298 static struct pci_error_handlers ipr_err_handler = {
9299 .error_detected = ipr_pci_error_detected,
9300 .slot_reset = ipr_pci_slot_reset,
9303 static struct pci_driver ipr_driver = {
9305 .id_table = ipr_pci_table,
9307 .remove = __devexit_p(ipr_remove),
9308 .shutdown = ipr_shutdown,
9309 .err_handler = &ipr_err_handler,
9313 * ipr_halt_done - Shutdown prepare completion
9318 static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
9320 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
9322 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
9326 * ipr_halt - Issue shutdown prepare to all adapters
9329 * NOTIFY_OK on success / NOTIFY_DONE on failure
9331 static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
9333 struct ipr_cmnd *ipr_cmd;
9334 struct ipr_ioa_cfg *ioa_cfg;
9335 unsigned long flags = 0;
9337 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
9340 spin_lock(&ipr_driver_lock);
9342 list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
9343 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
9344 if (!ioa_cfg->allow_cmds) {
9345 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
9349 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
9350 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
9351 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
9352 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
9353 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
9355 ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
9356 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
9358 spin_unlock(&ipr_driver_lock);
9363 static struct notifier_block ipr_notifier = {
9368 * ipr_init - Module entry point
9371 * 0 on success / negative value on failure
9373 static int __init ipr_init(void)
9375 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
9376 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
9378 register_reboot_notifier(&ipr_notifier);
9379 return pci_register_driver(&ipr_driver);
9383 * ipr_exit - Module unload
9385 * Module unload entry point.
9390 static void __exit ipr_exit(void)
9392 unregister_reboot_notifier(&ipr_notifier);
9393 pci_unregister_driver(&ipr_driver);
9396 module_init(ipr_init);
9397 module_exit(ipr_exit);