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/ioport.h>
63 #include <linux/delay.h>
64 #include <linux/pci.h>
65 #include <linux/wait.h>
66 #include <linux/spinlock.h>
67 #include <linux/sched.h>
68 #include <linux/interrupt.h>
69 #include <linux/blkdev.h>
70 #include <linux/firmware.h>
71 #include <linux/module.h>
72 #include <linux/moduleparam.h>
73 #include <linux/libata.h>
74 #include <linux/hdreg.h>
77 #include <asm/processor.h>
78 #include <scsi/scsi.h>
79 #include <scsi/scsi_host.h>
80 #include <scsi/scsi_tcq.h>
81 #include <scsi/scsi_eh.h>
82 #include <scsi/scsi_cmnd.h>
88 static LIST_HEAD(ipr_ioa_head
);
89 static unsigned int ipr_log_level
= IPR_DEFAULT_LOG_LEVEL
;
90 static unsigned int ipr_max_speed
= 1;
91 static int ipr_testmode
= 0;
92 static unsigned int ipr_fastfail
= 0;
93 static unsigned int ipr_transop_timeout
= 0;
94 static unsigned int ipr_enable_cache
= 1;
95 static unsigned int ipr_debug
= 0;
96 static unsigned int ipr_dual_ioa_raid
= 1;
97 static DEFINE_SPINLOCK(ipr_driver_lock
);
99 /* This table describes the differences between DMA controller chips */
100 static const struct ipr_chip_cfg_t ipr_chip_cfg
[] = {
101 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
103 .cache_line_size
= 0x20,
105 .set_interrupt_mask_reg
= 0x0022C,
106 .clr_interrupt_mask_reg
= 0x00230,
107 .sense_interrupt_mask_reg
= 0x0022C,
108 .clr_interrupt_reg
= 0x00228,
109 .sense_interrupt_reg
= 0x00224,
110 .ioarrin_reg
= 0x00404,
111 .sense_uproc_interrupt_reg
= 0x00214,
112 .set_uproc_interrupt_reg
= 0x00214,
113 .clr_uproc_interrupt_reg
= 0x00218
116 { /* Snipe and Scamp */
118 .cache_line_size
= 0x20,
120 .set_interrupt_mask_reg
= 0x00288,
121 .clr_interrupt_mask_reg
= 0x0028C,
122 .sense_interrupt_mask_reg
= 0x00288,
123 .clr_interrupt_reg
= 0x00284,
124 .sense_interrupt_reg
= 0x00280,
125 .ioarrin_reg
= 0x00504,
126 .sense_uproc_interrupt_reg
= 0x00290,
127 .set_uproc_interrupt_reg
= 0x00290,
128 .clr_uproc_interrupt_reg
= 0x00294
133 static const struct ipr_chip_t ipr_chip
[] = {
134 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
, IPR_USE_LSI
, &ipr_chip_cfg
[0] },
135 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
, IPR_USE_LSI
, &ipr_chip_cfg
[0] },
136 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
, IPR_USE_LSI
, &ipr_chip_cfg
[0] },
137 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
, IPR_USE_LSI
, &ipr_chip_cfg
[0] },
138 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
, IPR_USE_MSI
, &ipr_chip_cfg
[0] },
139 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_SNIPE
, IPR_USE_LSI
, &ipr_chip_cfg
[1] },
140 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
, IPR_USE_LSI
, &ipr_chip_cfg
[1] }
143 static int ipr_max_bus_speeds
[] = {
144 IPR_80MBs_SCSI_RATE
, IPR_U160_SCSI_RATE
, IPR_U320_SCSI_RATE
147 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
148 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
149 module_param_named(max_speed
, ipr_max_speed
, uint
, 0);
150 MODULE_PARM_DESC(max_speed
, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
151 module_param_named(log_level
, ipr_log_level
, uint
, 0);
152 MODULE_PARM_DESC(log_level
, "Set to 0 - 4 for increasing verbosity of device driver");
153 module_param_named(testmode
, ipr_testmode
, int, 0);
154 MODULE_PARM_DESC(testmode
, "DANGEROUS!!! Allows unsupported configurations");
155 module_param_named(fastfail
, ipr_fastfail
, int, S_IRUGO
| S_IWUSR
);
156 MODULE_PARM_DESC(fastfail
, "Reduce timeouts and retries");
157 module_param_named(transop_timeout
, ipr_transop_timeout
, int, 0);
158 MODULE_PARM_DESC(transop_timeout
, "Time in seconds to wait for adapter to come operational (default: 300)");
159 module_param_named(enable_cache
, ipr_enable_cache
, int, 0);
160 MODULE_PARM_DESC(enable_cache
, "Enable adapter's non-volatile write cache (default: 1)");
161 module_param_named(debug
, ipr_debug
, int, S_IRUGO
| S_IWUSR
);
162 MODULE_PARM_DESC(debug
, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
163 module_param_named(dual_ioa_raid
, ipr_dual_ioa_raid
, int, 0);
164 MODULE_PARM_DESC(dual_ioa_raid
, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
165 MODULE_LICENSE("GPL");
166 MODULE_VERSION(IPR_DRIVER_VERSION
);
168 /* A constant array of IOASCs/URCs/Error Messages */
170 struct ipr_error_table_t ipr_error_table
[] = {
171 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL
,
172 "8155: An unknown error was received"},
174 "Soft underlength error"},
176 "Command to be cancelled not found"},
178 "Qualified success"},
179 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL
,
180 "FFFE: Soft device bus error recovered by the IOA"},
181 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL
,
182 "4101: Soft device bus fabric error"},
183 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL
,
184 "FFF9: Device sector reassign successful"},
185 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL
,
186 "FFF7: Media error recovered by device rewrite procedures"},
187 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL
,
188 "7001: IOA sector reassignment successful"},
189 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL
,
190 "FFF9: Soft media error. Sector reassignment recommended"},
191 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL
,
192 "FFF7: Media error recovered by IOA rewrite procedures"},
193 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL
,
194 "FF3D: Soft PCI bus error recovered by the IOA"},
195 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL
,
196 "FFF6: Device hardware error recovered by the IOA"},
197 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL
,
198 "FFF6: Device hardware error recovered by the device"},
199 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL
,
200 "FF3D: Soft IOA error recovered by the IOA"},
201 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL
,
202 "FFFA: Undefined device response recovered by the IOA"},
203 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL
,
204 "FFF6: Device bus error, message or command phase"},
205 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL
,
206 "FFFE: Task Management Function failed"},
207 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL
,
208 "FFF6: Failure prediction threshold exceeded"},
209 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL
,
210 "8009: Impending cache battery pack failure"},
212 "34FF: Disk device format in progress"},
213 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL
,
214 "9070: IOA requested reset"},
216 "Synchronization required"},
218 "No ready, IOA shutdown"},
220 "Not ready, IOA has been shutdown"},
221 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL
,
222 "3020: Storage subsystem configuration error"},
224 "FFF5: Medium error, data unreadable, recommend reassign"},
226 "7000: Medium error, data unreadable, do not reassign"},
227 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL
,
228 "FFF3: Disk media format bad"},
229 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL
,
230 "3002: Addressed device failed to respond to selection"},
231 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL
,
232 "3100: Device bus error"},
233 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL
,
234 "3109: IOA timed out a device command"},
236 "3120: SCSI bus is not operational"},
237 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL
,
238 "4100: Hard device bus fabric error"},
239 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL
,
240 "9000: IOA reserved area data check"},
241 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL
,
242 "9001: IOA reserved area invalid data pattern"},
243 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL
,
244 "9002: IOA reserved area LRC error"},
245 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL
,
246 "102E: Out of alternate sectors for disk storage"},
247 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL
,
248 "FFF4: Data transfer underlength error"},
249 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL
,
250 "FFF4: Data transfer overlength error"},
251 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL
,
252 "3400: Logical unit failure"},
253 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL
,
254 "FFF4: Device microcode is corrupt"},
255 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL
,
256 "8150: PCI bus error"},
258 "Unsupported device bus message received"},
259 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL
,
260 "FFF4: Disk device problem"},
261 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL
,
262 "8150: Permanent IOA failure"},
263 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL
,
264 "3010: Disk device returned wrong response to IOA"},
265 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL
,
266 "8151: IOA microcode error"},
268 "Device bus status error"},
269 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL
,
270 "8157: IOA error requiring IOA reset to recover"},
272 "ATA device status error"},
274 "Message reject received from the device"},
275 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL
,
276 "8008: A permanent cache battery pack failure occurred"},
277 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL
,
278 "9090: Disk unit has been modified after the last known status"},
279 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL
,
280 "9081: IOA detected device error"},
281 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL
,
282 "9082: IOA detected device error"},
283 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL
,
284 "3110: Device bus error, message or command phase"},
285 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL
,
286 "3110: SAS Command / Task Management Function failed"},
287 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL
,
288 "9091: Incorrect hardware configuration change has been detected"},
289 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL
,
290 "9073: Invalid multi-adapter configuration"},
291 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL
,
292 "4010: Incorrect connection between cascaded expanders"},
293 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL
,
294 "4020: Connections exceed IOA design limits"},
295 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL
,
296 "4030: Incorrect multipath connection"},
297 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL
,
298 "4110: Unsupported enclosure function"},
299 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL
,
300 "FFF4: Command to logical unit failed"},
302 "Illegal request, invalid request type or request packet"},
304 "Illegal request, invalid resource handle"},
306 "Illegal request, commands not allowed to this device"},
308 "Illegal request, command not allowed to a secondary adapter"},
310 "Illegal request, invalid field in parameter list"},
312 "Illegal request, parameter not supported"},
314 "Illegal request, parameter value invalid"},
316 "Illegal request, command sequence error"},
318 "Illegal request, dual adapter support not enabled"},
319 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL
,
320 "9031: Array protection temporarily suspended, protection resuming"},
321 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL
,
322 "9040: Array protection temporarily suspended, protection resuming"},
323 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL
,
324 "3140: Device bus not ready to ready transition"},
325 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL
,
326 "FFFB: SCSI bus was reset"},
328 "FFFE: SCSI bus transition to single ended"},
330 "FFFE: SCSI bus transition to LVD"},
331 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL
,
332 "FFFB: SCSI bus was reset by another initiator"},
333 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL
,
334 "3029: A device replacement has occurred"},
335 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL
,
336 "9051: IOA cache data exists for a missing or failed device"},
337 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL
,
338 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
339 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL
,
340 "9025: Disk unit is not supported at its physical location"},
341 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL
,
342 "3020: IOA detected a SCSI bus configuration error"},
343 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL
,
344 "3150: SCSI bus configuration error"},
345 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL
,
346 "9074: Asymmetric advanced function disk configuration"},
347 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL
,
348 "4040: Incomplete multipath connection between IOA and enclosure"},
349 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL
,
350 "4041: Incomplete multipath connection between enclosure and device"},
351 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL
,
352 "9075: Incomplete multipath connection between IOA and remote IOA"},
353 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL
,
354 "9076: Configuration error, missing remote IOA"},
355 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL
,
356 "4050: Enclosure does not support a required multipath function"},
357 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL
,
358 "4070: Logically bad block written on device"},
359 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL
,
360 "9041: Array protection temporarily suspended"},
361 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL
,
362 "9042: Corrupt array parity detected on specified device"},
363 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL
,
364 "9030: Array no longer protected due to missing or failed disk unit"},
365 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL
,
366 "9071: Link operational transition"},
367 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL
,
368 "9072: Link not operational transition"},
369 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL
,
370 "9032: Array exposed but still protected"},
371 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL
+ 1,
372 "70DD: Device forced failed by disrupt device command"},
373 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL
,
374 "4061: Multipath redundancy level got better"},
375 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL
,
376 "4060: Multipath redundancy level got worse"},
378 "Failure due to other device"},
379 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL
,
380 "9008: IOA does not support functions expected by devices"},
381 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL
,
382 "9010: Cache data associated with attached devices cannot be found"},
383 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL
,
384 "9011: Cache data belongs to devices other than those attached"},
385 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL
,
386 "9020: Array missing 2 or more devices with only 1 device present"},
387 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL
,
388 "9021: Array missing 2 or more devices with 2 or more devices present"},
389 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL
,
390 "9022: Exposed array is missing a required device"},
391 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL
,
392 "9023: Array member(s) not at required physical locations"},
393 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL
,
394 "9024: Array not functional due to present hardware configuration"},
395 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL
,
396 "9026: Array not functional due to present hardware configuration"},
397 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL
,
398 "9027: Array is missing a device and parity is out of sync"},
399 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL
,
400 "9028: Maximum number of arrays already exist"},
401 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL
,
402 "9050: Required cache data cannot be located for a disk unit"},
403 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL
,
404 "9052: Cache data exists for a device that has been modified"},
405 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL
,
406 "9054: IOA resources not available due to previous problems"},
407 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL
,
408 "9092: Disk unit requires initialization before use"},
409 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL
,
410 "9029: Incorrect hardware configuration change has been detected"},
411 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL
,
412 "9060: One or more disk pairs are missing from an array"},
413 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL
,
414 "9061: One or more disks are missing from an array"},
415 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL
,
416 "9062: One or more disks are missing from an array"},
417 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL
,
418 "9063: Maximum number of functional arrays has been exceeded"},
420 "Aborted command, invalid descriptor"},
422 "Command terminated by host"}
425 static const struct ipr_ses_table_entry ipr_ses_table
[] = {
426 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
427 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
428 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
429 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
430 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
431 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
432 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
433 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
434 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
435 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
436 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
437 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
438 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
442 * Function Prototypes
444 static int ipr_reset_alert(struct ipr_cmnd
*);
445 static void ipr_process_ccn(struct ipr_cmnd
*);
446 static void ipr_process_error(struct ipr_cmnd
*);
447 static void ipr_reset_ioa_job(struct ipr_cmnd
*);
448 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg
*,
449 enum ipr_shutdown_type
);
451 #ifdef CONFIG_SCSI_IPR_TRACE
453 * ipr_trc_hook - Add a trace entry to the driver trace
454 * @ipr_cmd: ipr command struct
456 * @add_data: additional data
461 static void ipr_trc_hook(struct ipr_cmnd
*ipr_cmd
,
462 u8 type
, u32 add_data
)
464 struct ipr_trace_entry
*trace_entry
;
465 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
467 trace_entry
= &ioa_cfg
->trace
[ioa_cfg
->trace_index
++];
468 trace_entry
->time
= jiffies
;
469 trace_entry
->op_code
= ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0];
470 trace_entry
->type
= type
;
471 trace_entry
->ata_op_code
= ipr_cmd
->ioarcb
.add_data
.u
.regs
.command
;
472 trace_entry
->cmd_index
= ipr_cmd
->cmd_index
& 0xff;
473 trace_entry
->res_handle
= ipr_cmd
->ioarcb
.res_handle
;
474 trace_entry
->u
.add_data
= add_data
;
477 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
481 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
482 * @ipr_cmd: ipr command struct
487 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd
*ipr_cmd
)
489 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
490 struct ipr_ioasa
*ioasa
= &ipr_cmd
->ioasa
;
491 dma_addr_t dma_addr
= be32_to_cpu(ioarcb
->ioarcb_host_pci_addr
);
493 memset(&ioarcb
->cmd_pkt
, 0, sizeof(struct ipr_cmd_pkt
));
494 ioarcb
->write_data_transfer_length
= 0;
495 ioarcb
->read_data_transfer_length
= 0;
496 ioarcb
->write_ioadl_len
= 0;
497 ioarcb
->read_ioadl_len
= 0;
498 ioarcb
->write_ioadl_addr
=
499 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, ioadl
));
500 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
502 ioasa
->residual_data_len
= 0;
503 ioasa
->u
.gata
.status
= 0;
505 ipr_cmd
->scsi_cmd
= NULL
;
507 ipr_cmd
->sense_buffer
[0] = 0;
508 ipr_cmd
->dma_use_sg
= 0;
512 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
513 * @ipr_cmd: ipr command struct
518 static void ipr_init_ipr_cmnd(struct ipr_cmnd
*ipr_cmd
)
520 ipr_reinit_ipr_cmnd(ipr_cmd
);
521 ipr_cmd
->u
.scratch
= 0;
522 ipr_cmd
->sibling
= NULL
;
523 init_timer(&ipr_cmd
->timer
);
527 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
528 * @ioa_cfg: ioa config struct
531 * pointer to ipr command struct
534 struct ipr_cmnd
*ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg
*ioa_cfg
)
536 struct ipr_cmnd
*ipr_cmd
;
538 ipr_cmd
= list_entry(ioa_cfg
->free_q
.next
, struct ipr_cmnd
, queue
);
539 list_del(&ipr_cmd
->queue
);
540 ipr_init_ipr_cmnd(ipr_cmd
);
546 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
547 * @ioa_cfg: ioa config struct
548 * @clr_ints: interrupts to clear
550 * This function masks all interrupts on the adapter, then clears the
551 * interrupts specified in the mask
556 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg
*ioa_cfg
,
559 volatile u32 int_reg
;
561 /* Stop new interrupts */
562 ioa_cfg
->allow_interrupts
= 0;
564 /* Set interrupt mask to stop all new interrupts */
565 writel(~0, ioa_cfg
->regs
.set_interrupt_mask_reg
);
567 /* Clear any pending interrupts */
568 writel(clr_ints
, ioa_cfg
->regs
.clr_interrupt_reg
);
569 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
573 * ipr_save_pcix_cmd_reg - Save PCI-X command register
574 * @ioa_cfg: ioa config struct
577 * 0 on success / -EIO on failure
579 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg
*ioa_cfg
)
581 int pcix_cmd_reg
= pci_find_capability(ioa_cfg
->pdev
, PCI_CAP_ID_PCIX
);
583 if (pcix_cmd_reg
== 0)
586 if (pci_read_config_word(ioa_cfg
->pdev
, pcix_cmd_reg
+ PCI_X_CMD
,
587 &ioa_cfg
->saved_pcix_cmd_reg
) != PCIBIOS_SUCCESSFUL
) {
588 dev_err(&ioa_cfg
->pdev
->dev
, "Failed to save PCI-X command register\n");
592 ioa_cfg
->saved_pcix_cmd_reg
|= PCI_X_CMD_DPERR_E
| PCI_X_CMD_ERO
;
597 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
598 * @ioa_cfg: ioa config struct
601 * 0 on success / -EIO on failure
603 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg
*ioa_cfg
)
605 int pcix_cmd_reg
= pci_find_capability(ioa_cfg
->pdev
, PCI_CAP_ID_PCIX
);
608 if (pci_write_config_word(ioa_cfg
->pdev
, pcix_cmd_reg
+ PCI_X_CMD
,
609 ioa_cfg
->saved_pcix_cmd_reg
) != PCIBIOS_SUCCESSFUL
) {
610 dev_err(&ioa_cfg
->pdev
->dev
, "Failed to setup PCI-X command register\n");
619 * ipr_sata_eh_done - done function for aborted SATA commands
620 * @ipr_cmd: ipr command struct
622 * This function is invoked for ops generated to SATA
623 * devices which are being aborted.
628 static void ipr_sata_eh_done(struct ipr_cmnd
*ipr_cmd
)
630 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
631 struct ata_queued_cmd
*qc
= ipr_cmd
->qc
;
632 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
634 qc
->err_mask
|= AC_ERR_OTHER
;
635 sata_port
->ioasa
.status
|= ATA_BUSY
;
636 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
641 * ipr_scsi_eh_done - mid-layer done function for aborted ops
642 * @ipr_cmd: ipr command struct
644 * This function is invoked by the interrupt handler for
645 * ops generated by the SCSI mid-layer which are being aborted.
650 static void ipr_scsi_eh_done(struct ipr_cmnd
*ipr_cmd
)
652 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
653 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
655 scsi_cmd
->result
|= (DID_ERROR
<< 16);
657 scsi_dma_unmap(ipr_cmd
->scsi_cmd
);
658 scsi_cmd
->scsi_done(scsi_cmd
);
659 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
663 * ipr_fail_all_ops - Fails all outstanding ops.
664 * @ioa_cfg: ioa config struct
666 * This function fails all outstanding ops.
671 static void ipr_fail_all_ops(struct ipr_ioa_cfg
*ioa_cfg
)
673 struct ipr_cmnd
*ipr_cmd
, *temp
;
676 list_for_each_entry_safe(ipr_cmd
, temp
, &ioa_cfg
->pending_q
, queue
) {
677 list_del(&ipr_cmd
->queue
);
679 ipr_cmd
->ioasa
.ioasc
= cpu_to_be32(IPR_IOASC_IOA_WAS_RESET
);
680 ipr_cmd
->ioasa
.ilid
= cpu_to_be32(IPR_DRIVER_ILID
);
682 if (ipr_cmd
->scsi_cmd
)
683 ipr_cmd
->done
= ipr_scsi_eh_done
;
684 else if (ipr_cmd
->qc
)
685 ipr_cmd
->done
= ipr_sata_eh_done
;
687 ipr_trc_hook(ipr_cmd
, IPR_TRACE_FINISH
, IPR_IOASC_IOA_WAS_RESET
);
688 del_timer(&ipr_cmd
->timer
);
689 ipr_cmd
->done(ipr_cmd
);
696 * ipr_do_req - Send driver initiated requests.
697 * @ipr_cmd: ipr command struct
698 * @done: done function
699 * @timeout_func: timeout function
700 * @timeout: timeout value
702 * This function sends the specified command to the adapter with the
703 * timeout given. The done function is invoked on command completion.
708 static void ipr_do_req(struct ipr_cmnd
*ipr_cmd
,
709 void (*done
) (struct ipr_cmnd
*),
710 void (*timeout_func
) (struct ipr_cmnd
*), u32 timeout
)
712 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
714 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->pending_q
);
716 ipr_cmd
->done
= done
;
718 ipr_cmd
->timer
.data
= (unsigned long) ipr_cmd
;
719 ipr_cmd
->timer
.expires
= jiffies
+ timeout
;
720 ipr_cmd
->timer
.function
= (void (*)(unsigned long))timeout_func
;
722 add_timer(&ipr_cmd
->timer
);
724 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, 0);
727 writel(be32_to_cpu(ipr_cmd
->ioarcb
.ioarcb_host_pci_addr
),
728 ioa_cfg
->regs
.ioarrin_reg
);
732 * ipr_internal_cmd_done - Op done function for an internally generated op.
733 * @ipr_cmd: ipr command struct
735 * This function is the op done function for an internally generated,
736 * blocking op. It simply wakes the sleeping thread.
741 static void ipr_internal_cmd_done(struct ipr_cmnd
*ipr_cmd
)
743 if (ipr_cmd
->sibling
)
744 ipr_cmd
->sibling
= NULL
;
746 complete(&ipr_cmd
->completion
);
750 * ipr_send_blocking_cmd - Send command and sleep on its completion.
751 * @ipr_cmd: ipr command struct
752 * @timeout_func: function to invoke if command times out
758 static void ipr_send_blocking_cmd(struct ipr_cmnd
*ipr_cmd
,
759 void (*timeout_func
) (struct ipr_cmnd
*ipr_cmd
),
762 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
764 init_completion(&ipr_cmd
->completion
);
765 ipr_do_req(ipr_cmd
, ipr_internal_cmd_done
, timeout_func
, timeout
);
767 spin_unlock_irq(ioa_cfg
->host
->host_lock
);
768 wait_for_completion(&ipr_cmd
->completion
);
769 spin_lock_irq(ioa_cfg
->host
->host_lock
);
773 * ipr_send_hcam - Send an HCAM to the adapter.
774 * @ioa_cfg: ioa config struct
776 * @hostrcb: hostrcb struct
778 * This function will send a Host Controlled Async command to the adapter.
779 * If HCAMs are currently not allowed to be issued to the adapter, it will
780 * place the hostrcb on the free queue.
785 static void ipr_send_hcam(struct ipr_ioa_cfg
*ioa_cfg
, u8 type
,
786 struct ipr_hostrcb
*hostrcb
)
788 struct ipr_cmnd
*ipr_cmd
;
789 struct ipr_ioarcb
*ioarcb
;
791 if (ioa_cfg
->allow_cmds
) {
792 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
793 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->pending_q
);
794 list_add_tail(&hostrcb
->queue
, &ioa_cfg
->hostrcb_pending_q
);
796 ipr_cmd
->u
.hostrcb
= hostrcb
;
797 ioarcb
= &ipr_cmd
->ioarcb
;
799 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
800 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_HCAM
;
801 ioarcb
->cmd_pkt
.cdb
[0] = IPR_HOST_CONTROLLED_ASYNC
;
802 ioarcb
->cmd_pkt
.cdb
[1] = type
;
803 ioarcb
->cmd_pkt
.cdb
[7] = (sizeof(hostrcb
->hcam
) >> 8) & 0xff;
804 ioarcb
->cmd_pkt
.cdb
[8] = sizeof(hostrcb
->hcam
) & 0xff;
806 ioarcb
->read_data_transfer_length
= cpu_to_be32(sizeof(hostrcb
->hcam
));
807 ioarcb
->read_ioadl_len
= cpu_to_be32(sizeof(struct ipr_ioadl_desc
));
808 ipr_cmd
->ioadl
[0].flags_and_data_len
=
809 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST
| sizeof(hostrcb
->hcam
));
810 ipr_cmd
->ioadl
[0].address
= cpu_to_be32(hostrcb
->hostrcb_dma
);
812 if (type
== IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
)
813 ipr_cmd
->done
= ipr_process_ccn
;
815 ipr_cmd
->done
= ipr_process_error
;
817 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, IPR_IOA_RES_ADDR
);
820 writel(be32_to_cpu(ipr_cmd
->ioarcb
.ioarcb_host_pci_addr
),
821 ioa_cfg
->regs
.ioarrin_reg
);
823 list_add_tail(&hostrcb
->queue
, &ioa_cfg
->hostrcb_free_q
);
828 * ipr_init_res_entry - Initialize a resource entry struct.
829 * @res: resource entry struct
834 static void ipr_init_res_entry(struct ipr_resource_entry
*res
)
836 res
->needs_sync_complete
= 0;
839 res
->del_from_ml
= 0;
840 res
->resetting_device
= 0;
842 res
->sata_port
= NULL
;
846 * ipr_handle_config_change - Handle a config change from the adapter
847 * @ioa_cfg: ioa config struct
853 static void ipr_handle_config_change(struct ipr_ioa_cfg
*ioa_cfg
,
854 struct ipr_hostrcb
*hostrcb
)
856 struct ipr_resource_entry
*res
= NULL
;
857 struct ipr_config_table_entry
*cfgte
;
860 cfgte
= &hostrcb
->hcam
.u
.ccn
.cfgte
;
862 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
863 if (!memcmp(&res
->cfgte
.res_addr
, &cfgte
->res_addr
,
864 sizeof(cfgte
->res_addr
))) {
871 if (list_empty(&ioa_cfg
->free_res_q
)) {
872 ipr_send_hcam(ioa_cfg
,
873 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
,
878 res
= list_entry(ioa_cfg
->free_res_q
.next
,
879 struct ipr_resource_entry
, queue
);
881 list_del(&res
->queue
);
882 ipr_init_res_entry(res
);
883 list_add_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
886 memcpy(&res
->cfgte
, cfgte
, sizeof(struct ipr_config_table_entry
));
888 if (hostrcb
->hcam
.notify_type
== IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY
) {
890 res
->del_from_ml
= 1;
891 res
->cfgte
.res_handle
= IPR_INVALID_RES_HANDLE
;
892 if (ioa_cfg
->allow_ml_add_del
)
893 schedule_work(&ioa_cfg
->work_q
);
895 list_move_tail(&res
->queue
, &ioa_cfg
->free_res_q
);
896 } else if (!res
->sdev
) {
898 if (ioa_cfg
->allow_ml_add_del
)
899 schedule_work(&ioa_cfg
->work_q
);
902 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
, hostrcb
);
906 * ipr_process_ccn - Op done function for a CCN.
907 * @ipr_cmd: ipr command struct
909 * This function is the op done function for a configuration
910 * change notification host controlled async from the adapter.
915 static void ipr_process_ccn(struct ipr_cmnd
*ipr_cmd
)
917 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
918 struct ipr_hostrcb
*hostrcb
= ipr_cmd
->u
.hostrcb
;
919 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
921 list_del(&hostrcb
->queue
);
922 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
925 if (ioasc
!= IPR_IOASC_IOA_WAS_RESET
)
926 dev_err(&ioa_cfg
->pdev
->dev
,
927 "Host RCB failed with IOASC: 0x%08X\n", ioasc
);
929 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
, hostrcb
);
931 ipr_handle_config_change(ioa_cfg
, hostrcb
);
936 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
937 * @i: index into buffer
938 * @buf: string to modify
940 * This function will strip all trailing whitespace, pad the end
941 * of the string with a single space, and NULL terminate the string.
944 * new length of string
946 static int strip_and_pad_whitespace(int i
, char *buf
)
948 while (i
&& buf
[i
] == ' ')
956 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
957 * @prefix: string to print at start of printk
958 * @hostrcb: hostrcb pointer
959 * @vpd: vendor/product id/sn struct
964 static void ipr_log_vpd_compact(char *prefix
, struct ipr_hostrcb
*hostrcb
,
967 char buffer
[IPR_VENDOR_ID_LEN
+ IPR_PROD_ID_LEN
+ IPR_SERIAL_NUM_LEN
+ 3];
970 memcpy(buffer
, vpd
->vpids
.vendor_id
, IPR_VENDOR_ID_LEN
);
971 i
= strip_and_pad_whitespace(IPR_VENDOR_ID_LEN
- 1, buffer
);
973 memcpy(&buffer
[i
], vpd
->vpids
.product_id
, IPR_PROD_ID_LEN
);
974 i
= strip_and_pad_whitespace(i
+ IPR_PROD_ID_LEN
- 1, buffer
);
976 memcpy(&buffer
[i
], vpd
->sn
, IPR_SERIAL_NUM_LEN
);
977 buffer
[IPR_SERIAL_NUM_LEN
+ i
] = '\0';
979 ipr_hcam_err(hostrcb
, "%s VPID/SN: %s\n", prefix
, buffer
);
983 * ipr_log_vpd - Log the passed VPD to the error log.
984 * @vpd: vendor/product id/sn struct
989 static void ipr_log_vpd(struct ipr_vpd
*vpd
)
991 char buffer
[IPR_VENDOR_ID_LEN
+ IPR_PROD_ID_LEN
992 + IPR_SERIAL_NUM_LEN
];
994 memcpy(buffer
, vpd
->vpids
.vendor_id
, IPR_VENDOR_ID_LEN
);
995 memcpy(buffer
+ IPR_VENDOR_ID_LEN
, vpd
->vpids
.product_id
,
997 buffer
[IPR_VENDOR_ID_LEN
+ IPR_PROD_ID_LEN
] = '\0';
998 ipr_err("Vendor/Product ID: %s\n", buffer
);
1000 memcpy(buffer
, vpd
->sn
, IPR_SERIAL_NUM_LEN
);
1001 buffer
[IPR_SERIAL_NUM_LEN
] = '\0';
1002 ipr_err(" Serial Number: %s\n", buffer
);
1006 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1007 * @prefix: string to print at start of printk
1008 * @hostrcb: hostrcb pointer
1009 * @vpd: vendor/product id/sn/wwn struct
1014 static void ipr_log_ext_vpd_compact(char *prefix
, struct ipr_hostrcb
*hostrcb
,
1015 struct ipr_ext_vpd
*vpd
)
1017 ipr_log_vpd_compact(prefix
, hostrcb
, &vpd
->vpd
);
1018 ipr_hcam_err(hostrcb
, "%s WWN: %08X%08X\n", prefix
,
1019 be32_to_cpu(vpd
->wwid
[0]), be32_to_cpu(vpd
->wwid
[1]));
1023 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1024 * @vpd: vendor/product id/sn/wwn struct
1029 static void ipr_log_ext_vpd(struct ipr_ext_vpd
*vpd
)
1031 ipr_log_vpd(&vpd
->vpd
);
1032 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd
->wwid
[0]),
1033 be32_to_cpu(vpd
->wwid
[1]));
1037 * ipr_log_enhanced_cache_error - Log a cache error.
1038 * @ioa_cfg: ioa config struct
1039 * @hostrcb: hostrcb struct
1044 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg
*ioa_cfg
,
1045 struct ipr_hostrcb
*hostrcb
)
1047 struct ipr_hostrcb_type_12_error
*error
=
1048 &hostrcb
->hcam
.u
.error
.u
.type_12_error
;
1050 ipr_err("-----Current Configuration-----\n");
1051 ipr_err("Cache Directory Card Information:\n");
1052 ipr_log_ext_vpd(&error
->ioa_vpd
);
1053 ipr_err("Adapter Card Information:\n");
1054 ipr_log_ext_vpd(&error
->cfc_vpd
);
1056 ipr_err("-----Expected Configuration-----\n");
1057 ipr_err("Cache Directory Card Information:\n");
1058 ipr_log_ext_vpd(&error
->ioa_last_attached_to_cfc_vpd
);
1059 ipr_err("Adapter Card Information:\n");
1060 ipr_log_ext_vpd(&error
->cfc_last_attached_to_ioa_vpd
);
1062 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1063 be32_to_cpu(error
->ioa_data
[0]),
1064 be32_to_cpu(error
->ioa_data
[1]),
1065 be32_to_cpu(error
->ioa_data
[2]));
1069 * ipr_log_cache_error - Log a cache error.
1070 * @ioa_cfg: ioa config struct
1071 * @hostrcb: hostrcb struct
1076 static void ipr_log_cache_error(struct ipr_ioa_cfg
*ioa_cfg
,
1077 struct ipr_hostrcb
*hostrcb
)
1079 struct ipr_hostrcb_type_02_error
*error
=
1080 &hostrcb
->hcam
.u
.error
.u
.type_02_error
;
1082 ipr_err("-----Current Configuration-----\n");
1083 ipr_err("Cache Directory Card Information:\n");
1084 ipr_log_vpd(&error
->ioa_vpd
);
1085 ipr_err("Adapter Card Information:\n");
1086 ipr_log_vpd(&error
->cfc_vpd
);
1088 ipr_err("-----Expected Configuration-----\n");
1089 ipr_err("Cache Directory Card Information:\n");
1090 ipr_log_vpd(&error
->ioa_last_attached_to_cfc_vpd
);
1091 ipr_err("Adapter Card Information:\n");
1092 ipr_log_vpd(&error
->cfc_last_attached_to_ioa_vpd
);
1094 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1095 be32_to_cpu(error
->ioa_data
[0]),
1096 be32_to_cpu(error
->ioa_data
[1]),
1097 be32_to_cpu(error
->ioa_data
[2]));
1101 * ipr_log_enhanced_config_error - Log a configuration error.
1102 * @ioa_cfg: ioa config struct
1103 * @hostrcb: hostrcb struct
1108 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg
*ioa_cfg
,
1109 struct ipr_hostrcb
*hostrcb
)
1111 int errors_logged
, i
;
1112 struct ipr_hostrcb_device_data_entry_enhanced
*dev_entry
;
1113 struct ipr_hostrcb_type_13_error
*error
;
1115 error
= &hostrcb
->hcam
.u
.error
.u
.type_13_error
;
1116 errors_logged
= be32_to_cpu(error
->errors_logged
);
1118 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1119 be32_to_cpu(error
->errors_detected
), errors_logged
);
1121 dev_entry
= error
->dev
;
1123 for (i
= 0; i
< errors_logged
; i
++, dev_entry
++) {
1126 ipr_phys_res_err(ioa_cfg
, dev_entry
->dev_res_addr
, "Device %d", i
+ 1);
1127 ipr_log_ext_vpd(&dev_entry
->vpd
);
1129 ipr_err("-----New Device Information-----\n");
1130 ipr_log_ext_vpd(&dev_entry
->new_vpd
);
1132 ipr_err("Cache Directory Card Information:\n");
1133 ipr_log_ext_vpd(&dev_entry
->ioa_last_with_dev_vpd
);
1135 ipr_err("Adapter Card Information:\n");
1136 ipr_log_ext_vpd(&dev_entry
->cfc_last_with_dev_vpd
);
1141 * ipr_log_config_error - Log a configuration error.
1142 * @ioa_cfg: ioa config struct
1143 * @hostrcb: hostrcb struct
1148 static void ipr_log_config_error(struct ipr_ioa_cfg
*ioa_cfg
,
1149 struct ipr_hostrcb
*hostrcb
)
1151 int errors_logged
, i
;
1152 struct ipr_hostrcb_device_data_entry
*dev_entry
;
1153 struct ipr_hostrcb_type_03_error
*error
;
1155 error
= &hostrcb
->hcam
.u
.error
.u
.type_03_error
;
1156 errors_logged
= be32_to_cpu(error
->errors_logged
);
1158 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1159 be32_to_cpu(error
->errors_detected
), errors_logged
);
1161 dev_entry
= error
->dev
;
1163 for (i
= 0; i
< errors_logged
; i
++, dev_entry
++) {
1166 ipr_phys_res_err(ioa_cfg
, dev_entry
->dev_res_addr
, "Device %d", i
+ 1);
1167 ipr_log_vpd(&dev_entry
->vpd
);
1169 ipr_err("-----New Device Information-----\n");
1170 ipr_log_vpd(&dev_entry
->new_vpd
);
1172 ipr_err("Cache Directory Card Information:\n");
1173 ipr_log_vpd(&dev_entry
->ioa_last_with_dev_vpd
);
1175 ipr_err("Adapter Card Information:\n");
1176 ipr_log_vpd(&dev_entry
->cfc_last_with_dev_vpd
);
1178 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1179 be32_to_cpu(dev_entry
->ioa_data
[0]),
1180 be32_to_cpu(dev_entry
->ioa_data
[1]),
1181 be32_to_cpu(dev_entry
->ioa_data
[2]),
1182 be32_to_cpu(dev_entry
->ioa_data
[3]),
1183 be32_to_cpu(dev_entry
->ioa_data
[4]));
1188 * ipr_log_enhanced_array_error - Log an array configuration error.
1189 * @ioa_cfg: ioa config struct
1190 * @hostrcb: hostrcb struct
1195 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg
*ioa_cfg
,
1196 struct ipr_hostrcb
*hostrcb
)
1199 struct ipr_hostrcb_type_14_error
*error
;
1200 struct ipr_hostrcb_array_data_entry_enhanced
*array_entry
;
1201 const u8 zero_sn
[IPR_SERIAL_NUM_LEN
] = { [0 ... IPR_SERIAL_NUM_LEN
-1] = '0' };
1203 error
= &hostrcb
->hcam
.u
.error
.u
.type_14_error
;
1207 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1208 error
->protection_level
,
1209 ioa_cfg
->host
->host_no
,
1210 error
->last_func_vset_res_addr
.bus
,
1211 error
->last_func_vset_res_addr
.target
,
1212 error
->last_func_vset_res_addr
.lun
);
1216 array_entry
= error
->array_member
;
1217 num_entries
= min_t(u32
, be32_to_cpu(error
->num_entries
),
1218 sizeof(error
->array_member
));
1220 for (i
= 0; i
< num_entries
; i
++, array_entry
++) {
1221 if (!memcmp(array_entry
->vpd
.vpd
.sn
, zero_sn
, IPR_SERIAL_NUM_LEN
))
1224 if (be32_to_cpu(error
->exposed_mode_adn
) == i
)
1225 ipr_err("Exposed Array Member %d:\n", i
);
1227 ipr_err("Array Member %d:\n", i
);
1229 ipr_log_ext_vpd(&array_entry
->vpd
);
1230 ipr_phys_res_err(ioa_cfg
, array_entry
->dev_res_addr
, "Current Location");
1231 ipr_phys_res_err(ioa_cfg
, array_entry
->expected_dev_res_addr
,
1232 "Expected Location");
1239 * ipr_log_array_error - Log an array configuration error.
1240 * @ioa_cfg: ioa config struct
1241 * @hostrcb: hostrcb struct
1246 static void ipr_log_array_error(struct ipr_ioa_cfg
*ioa_cfg
,
1247 struct ipr_hostrcb
*hostrcb
)
1250 struct ipr_hostrcb_type_04_error
*error
;
1251 struct ipr_hostrcb_array_data_entry
*array_entry
;
1252 const u8 zero_sn
[IPR_SERIAL_NUM_LEN
] = { [0 ... IPR_SERIAL_NUM_LEN
-1] = '0' };
1254 error
= &hostrcb
->hcam
.u
.error
.u
.type_04_error
;
1258 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1259 error
->protection_level
,
1260 ioa_cfg
->host
->host_no
,
1261 error
->last_func_vset_res_addr
.bus
,
1262 error
->last_func_vset_res_addr
.target
,
1263 error
->last_func_vset_res_addr
.lun
);
1267 array_entry
= error
->array_member
;
1269 for (i
= 0; i
< 18; i
++) {
1270 if (!memcmp(array_entry
->vpd
.sn
, zero_sn
, IPR_SERIAL_NUM_LEN
))
1273 if (be32_to_cpu(error
->exposed_mode_adn
) == i
)
1274 ipr_err("Exposed Array Member %d:\n", i
);
1276 ipr_err("Array Member %d:\n", i
);
1278 ipr_log_vpd(&array_entry
->vpd
);
1280 ipr_phys_res_err(ioa_cfg
, array_entry
->dev_res_addr
, "Current Location");
1281 ipr_phys_res_err(ioa_cfg
, array_entry
->expected_dev_res_addr
,
1282 "Expected Location");
1287 array_entry
= error
->array_member2
;
1294 * ipr_log_hex_data - Log additional hex IOA error data.
1295 * @ioa_cfg: ioa config struct
1296 * @data: IOA error data
1302 static void ipr_log_hex_data(struct ipr_ioa_cfg
*ioa_cfg
, u32
*data
, int len
)
1309 if (ioa_cfg
->log_level
<= IPR_DEFAULT_LOG_LEVEL
)
1310 len
= min_t(int, len
, IPR_DEFAULT_MAX_ERROR_DUMP
);
1312 for (i
= 0; i
< len
/ 4; i
+= 4) {
1313 ipr_err("%08X: %08X %08X %08X %08X\n", i
*4,
1314 be32_to_cpu(data
[i
]),
1315 be32_to_cpu(data
[i
+1]),
1316 be32_to_cpu(data
[i
+2]),
1317 be32_to_cpu(data
[i
+3]));
1322 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1323 * @ioa_cfg: ioa config struct
1324 * @hostrcb: hostrcb struct
1329 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg
*ioa_cfg
,
1330 struct ipr_hostrcb
*hostrcb
)
1332 struct ipr_hostrcb_type_17_error
*error
;
1334 error
= &hostrcb
->hcam
.u
.error
.u
.type_17_error
;
1335 error
->failure_reason
[sizeof(error
->failure_reason
) - 1] = '\0';
1336 strim(error
->failure_reason
);
1338 ipr_hcam_err(hostrcb
, "%s [PRC: %08X]\n", error
->failure_reason
,
1339 be32_to_cpu(hostrcb
->hcam
.u
.error
.prc
));
1340 ipr_log_ext_vpd_compact("Remote IOA", hostrcb
, &error
->vpd
);
1341 ipr_log_hex_data(ioa_cfg
, error
->data
,
1342 be32_to_cpu(hostrcb
->hcam
.length
) -
1343 (offsetof(struct ipr_hostrcb_error
, u
) +
1344 offsetof(struct ipr_hostrcb_type_17_error
, data
)));
1348 * ipr_log_dual_ioa_error - Log a dual adapter error.
1349 * @ioa_cfg: ioa config struct
1350 * @hostrcb: hostrcb struct
1355 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg
*ioa_cfg
,
1356 struct ipr_hostrcb
*hostrcb
)
1358 struct ipr_hostrcb_type_07_error
*error
;
1360 error
= &hostrcb
->hcam
.u
.error
.u
.type_07_error
;
1361 error
->failure_reason
[sizeof(error
->failure_reason
) - 1] = '\0';
1362 strim(error
->failure_reason
);
1364 ipr_hcam_err(hostrcb
, "%s [PRC: %08X]\n", error
->failure_reason
,
1365 be32_to_cpu(hostrcb
->hcam
.u
.error
.prc
));
1366 ipr_log_vpd_compact("Remote IOA", hostrcb
, &error
->vpd
);
1367 ipr_log_hex_data(ioa_cfg
, error
->data
,
1368 be32_to_cpu(hostrcb
->hcam
.length
) -
1369 (offsetof(struct ipr_hostrcb_error
, u
) +
1370 offsetof(struct ipr_hostrcb_type_07_error
, data
)));
1373 static const struct {
1376 } path_active_desc
[] = {
1377 { IPR_PATH_NO_INFO
, "Path" },
1378 { IPR_PATH_ACTIVE
, "Active path" },
1379 { IPR_PATH_NOT_ACTIVE
, "Inactive path" }
1382 static const struct {
1385 } path_state_desc
[] = {
1386 { IPR_PATH_STATE_NO_INFO
, "has no path state information available" },
1387 { IPR_PATH_HEALTHY
, "is healthy" },
1388 { IPR_PATH_DEGRADED
, "is degraded" },
1389 { IPR_PATH_FAILED
, "is failed" }
1393 * ipr_log_fabric_path - Log a fabric path error
1394 * @hostrcb: hostrcb struct
1395 * @fabric: fabric descriptor
1400 static void ipr_log_fabric_path(struct ipr_hostrcb
*hostrcb
,
1401 struct ipr_hostrcb_fabric_desc
*fabric
)
1404 u8 path_state
= fabric
->path_state
;
1405 u8 active
= path_state
& IPR_PATH_ACTIVE_MASK
;
1406 u8 state
= path_state
& IPR_PATH_STATE_MASK
;
1408 for (i
= 0; i
< ARRAY_SIZE(path_active_desc
); i
++) {
1409 if (path_active_desc
[i
].active
!= active
)
1412 for (j
= 0; j
< ARRAY_SIZE(path_state_desc
); j
++) {
1413 if (path_state_desc
[j
].state
!= state
)
1416 if (fabric
->cascaded_expander
== 0xff && fabric
->phy
== 0xff) {
1417 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d\n",
1418 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
1420 } else if (fabric
->cascaded_expander
== 0xff) {
1421 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d, Phy=%d\n",
1422 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
1423 fabric
->ioa_port
, fabric
->phy
);
1424 } else if (fabric
->phy
== 0xff) {
1425 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d, Cascade=%d\n",
1426 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
1427 fabric
->ioa_port
, fabric
->cascaded_expander
);
1429 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1430 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
1431 fabric
->ioa_port
, fabric
->cascaded_expander
, fabric
->phy
);
1437 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state
,
1438 fabric
->ioa_port
, fabric
->cascaded_expander
, fabric
->phy
);
1441 static const struct {
1444 } path_type_desc
[] = {
1445 { IPR_PATH_CFG_IOA_PORT
, "IOA port" },
1446 { IPR_PATH_CFG_EXP_PORT
, "Expander port" },
1447 { IPR_PATH_CFG_DEVICE_PORT
, "Device port" },
1448 { IPR_PATH_CFG_DEVICE_LUN
, "Device LUN" }
1451 static const struct {
1454 } path_status_desc
[] = {
1455 { IPR_PATH_CFG_NO_PROB
, "Functional" },
1456 { IPR_PATH_CFG_DEGRADED
, "Degraded" },
1457 { IPR_PATH_CFG_FAILED
, "Failed" },
1458 { IPR_PATH_CFG_SUSPECT
, "Suspect" },
1459 { IPR_PATH_NOT_DETECTED
, "Missing" },
1460 { IPR_PATH_INCORRECT_CONN
, "Incorrectly connected" }
1463 static const char *link_rate
[] = {
1466 "phy reset problem",
1483 * ipr_log_path_elem - Log a fabric path element.
1484 * @hostrcb: hostrcb struct
1485 * @cfg: fabric path element struct
1490 static void ipr_log_path_elem(struct ipr_hostrcb
*hostrcb
,
1491 struct ipr_hostrcb_config_element
*cfg
)
1494 u8 type
= cfg
->type_status
& IPR_PATH_CFG_TYPE_MASK
;
1495 u8 status
= cfg
->type_status
& IPR_PATH_CFG_STATUS_MASK
;
1497 if (type
== IPR_PATH_CFG_NOT_EXIST
)
1500 for (i
= 0; i
< ARRAY_SIZE(path_type_desc
); i
++) {
1501 if (path_type_desc
[i
].type
!= type
)
1504 for (j
= 0; j
< ARRAY_SIZE(path_status_desc
); j
++) {
1505 if (path_status_desc
[j
].status
!= status
)
1508 if (type
== IPR_PATH_CFG_IOA_PORT
) {
1509 ipr_hcam_err(hostrcb
, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
1510 path_status_desc
[j
].desc
, path_type_desc
[i
].desc
,
1511 cfg
->phy
, link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
1512 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
1514 if (cfg
->cascaded_expander
== 0xff && cfg
->phy
== 0xff) {
1515 ipr_hcam_err(hostrcb
, "%s %s: Link rate=%s, WWN=%08X%08X\n",
1516 path_status_desc
[j
].desc
, path_type_desc
[i
].desc
,
1517 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
1518 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
1519 } else if (cfg
->cascaded_expander
== 0xff) {
1520 ipr_hcam_err(hostrcb
, "%s %s: Phy=%d, Link rate=%s, "
1521 "WWN=%08X%08X\n", path_status_desc
[j
].desc
,
1522 path_type_desc
[i
].desc
, cfg
->phy
,
1523 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
1524 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
1525 } else if (cfg
->phy
== 0xff) {
1526 ipr_hcam_err(hostrcb
, "%s %s: Cascade=%d, Link rate=%s, "
1527 "WWN=%08X%08X\n", path_status_desc
[j
].desc
,
1528 path_type_desc
[i
].desc
, cfg
->cascaded_expander
,
1529 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
1530 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
1532 ipr_hcam_err(hostrcb
, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
1533 "WWN=%08X%08X\n", path_status_desc
[j
].desc
,
1534 path_type_desc
[i
].desc
, cfg
->cascaded_expander
, cfg
->phy
,
1535 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
1536 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
1543 ipr_hcam_err(hostrcb
, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
1544 "WWN=%08X%08X\n", cfg
->type_status
, cfg
->cascaded_expander
, cfg
->phy
,
1545 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
1546 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
1550 * ipr_log_fabric_error - Log a fabric error.
1551 * @ioa_cfg: ioa config struct
1552 * @hostrcb: hostrcb struct
1557 static void ipr_log_fabric_error(struct ipr_ioa_cfg
*ioa_cfg
,
1558 struct ipr_hostrcb
*hostrcb
)
1560 struct ipr_hostrcb_type_20_error
*error
;
1561 struct ipr_hostrcb_fabric_desc
*fabric
;
1562 struct ipr_hostrcb_config_element
*cfg
;
1565 error
= &hostrcb
->hcam
.u
.error
.u
.type_20_error
;
1566 error
->failure_reason
[sizeof(error
->failure_reason
) - 1] = '\0';
1567 ipr_hcam_err(hostrcb
, "%s\n", error
->failure_reason
);
1569 add_len
= be32_to_cpu(hostrcb
->hcam
.length
) -
1570 (offsetof(struct ipr_hostrcb_error
, u
) +
1571 offsetof(struct ipr_hostrcb_type_20_error
, desc
));
1573 for (i
= 0, fabric
= error
->desc
; i
< error
->num_entries
; i
++) {
1574 ipr_log_fabric_path(hostrcb
, fabric
);
1575 for_each_fabric_cfg(fabric
, cfg
)
1576 ipr_log_path_elem(hostrcb
, cfg
);
1578 add_len
-= be16_to_cpu(fabric
->length
);
1579 fabric
= (struct ipr_hostrcb_fabric_desc
*)
1580 ((unsigned long)fabric
+ be16_to_cpu(fabric
->length
));
1583 ipr_log_hex_data(ioa_cfg
, (u32
*)fabric
, add_len
);
1587 * ipr_log_generic_error - Log an adapter error.
1588 * @ioa_cfg: ioa config struct
1589 * @hostrcb: hostrcb struct
1594 static void ipr_log_generic_error(struct ipr_ioa_cfg
*ioa_cfg
,
1595 struct ipr_hostrcb
*hostrcb
)
1597 ipr_log_hex_data(ioa_cfg
, hostrcb
->hcam
.u
.raw
.data
,
1598 be32_to_cpu(hostrcb
->hcam
.length
));
1602 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
1605 * This function will return the index of into the ipr_error_table
1606 * for the specified IOASC. If the IOASC is not in the table,
1607 * 0 will be returned, which points to the entry used for unknown errors.
1610 * index into the ipr_error_table
1612 static u32
ipr_get_error(u32 ioasc
)
1616 for (i
= 0; i
< ARRAY_SIZE(ipr_error_table
); i
++)
1617 if (ipr_error_table
[i
].ioasc
== (ioasc
& IPR_IOASC_IOASC_MASK
))
1624 * ipr_handle_log_data - Log an adapter error.
1625 * @ioa_cfg: ioa config struct
1626 * @hostrcb: hostrcb struct
1628 * This function logs an adapter error to the system.
1633 static void ipr_handle_log_data(struct ipr_ioa_cfg
*ioa_cfg
,
1634 struct ipr_hostrcb
*hostrcb
)
1639 if (hostrcb
->hcam
.notify_type
!= IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY
)
1642 if (hostrcb
->hcam
.notifications_lost
== IPR_HOST_RCB_NOTIFICATIONS_LOST
)
1643 dev_err(&ioa_cfg
->pdev
->dev
, "Error notifications lost\n");
1645 ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error
.failing_dev_ioasc
);
1647 if (ioasc
== IPR_IOASC_BUS_WAS_RESET
||
1648 ioasc
== IPR_IOASC_BUS_WAS_RESET_BY_OTHER
) {
1649 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
1650 scsi_report_bus_reset(ioa_cfg
->host
,
1651 hostrcb
->hcam
.u
.error
.failing_dev_res_addr
.bus
);
1654 error_index
= ipr_get_error(ioasc
);
1656 if (!ipr_error_table
[error_index
].log_hcam
)
1659 ipr_hcam_err(hostrcb
, "%s\n", ipr_error_table
[error_index
].error
);
1661 /* Set indication we have logged an error */
1662 ioa_cfg
->errors_logged
++;
1664 if (ioa_cfg
->log_level
< ipr_error_table
[error_index
].log_hcam
)
1666 if (be32_to_cpu(hostrcb
->hcam
.length
) > sizeof(hostrcb
->hcam
.u
.raw
))
1667 hostrcb
->hcam
.length
= cpu_to_be32(sizeof(hostrcb
->hcam
.u
.raw
));
1669 switch (hostrcb
->hcam
.overlay_id
) {
1670 case IPR_HOST_RCB_OVERLAY_ID_2
:
1671 ipr_log_cache_error(ioa_cfg
, hostrcb
);
1673 case IPR_HOST_RCB_OVERLAY_ID_3
:
1674 ipr_log_config_error(ioa_cfg
, hostrcb
);
1676 case IPR_HOST_RCB_OVERLAY_ID_4
:
1677 case IPR_HOST_RCB_OVERLAY_ID_6
:
1678 ipr_log_array_error(ioa_cfg
, hostrcb
);
1680 case IPR_HOST_RCB_OVERLAY_ID_7
:
1681 ipr_log_dual_ioa_error(ioa_cfg
, hostrcb
);
1683 case IPR_HOST_RCB_OVERLAY_ID_12
:
1684 ipr_log_enhanced_cache_error(ioa_cfg
, hostrcb
);
1686 case IPR_HOST_RCB_OVERLAY_ID_13
:
1687 ipr_log_enhanced_config_error(ioa_cfg
, hostrcb
);
1689 case IPR_HOST_RCB_OVERLAY_ID_14
:
1690 case IPR_HOST_RCB_OVERLAY_ID_16
:
1691 ipr_log_enhanced_array_error(ioa_cfg
, hostrcb
);
1693 case IPR_HOST_RCB_OVERLAY_ID_17
:
1694 ipr_log_enhanced_dual_ioa_error(ioa_cfg
, hostrcb
);
1696 case IPR_HOST_RCB_OVERLAY_ID_20
:
1697 ipr_log_fabric_error(ioa_cfg
, hostrcb
);
1699 case IPR_HOST_RCB_OVERLAY_ID_1
:
1700 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT
:
1702 ipr_log_generic_error(ioa_cfg
, hostrcb
);
1708 * ipr_process_error - Op done function for an adapter error log.
1709 * @ipr_cmd: ipr command struct
1711 * This function is the op done function for an error log host
1712 * controlled async from the adapter. It will log the error and
1713 * send the HCAM back to the adapter.
1718 static void ipr_process_error(struct ipr_cmnd
*ipr_cmd
)
1720 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
1721 struct ipr_hostrcb
*hostrcb
= ipr_cmd
->u
.hostrcb
;
1722 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
1723 u32 fd_ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error
.failing_dev_ioasc
);
1725 list_del(&hostrcb
->queue
);
1726 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
1729 ipr_handle_log_data(ioa_cfg
, hostrcb
);
1730 if (fd_ioasc
== IPR_IOASC_NR_IOA_RESET_REQUIRED
)
1731 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_ABBREV
);
1732 } else if (ioasc
!= IPR_IOASC_IOA_WAS_RESET
) {
1733 dev_err(&ioa_cfg
->pdev
->dev
,
1734 "Host RCB failed with IOASC: 0x%08X\n", ioasc
);
1737 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_LOG_DATA
, hostrcb
);
1741 * ipr_timeout - An internally generated op has timed out.
1742 * @ipr_cmd: ipr command struct
1744 * This function blocks host requests and initiates an
1750 static void ipr_timeout(struct ipr_cmnd
*ipr_cmd
)
1752 unsigned long lock_flags
= 0;
1753 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
1756 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
1758 ioa_cfg
->errors_logged
++;
1759 dev_err(&ioa_cfg
->pdev
->dev
,
1760 "Adapter being reset due to command timeout.\n");
1762 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
1763 ioa_cfg
->sdt_state
= GET_DUMP
;
1765 if (!ioa_cfg
->in_reset_reload
|| ioa_cfg
->reset_cmd
== ipr_cmd
)
1766 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
1768 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
1773 * ipr_oper_timeout - Adapter timed out transitioning to operational
1774 * @ipr_cmd: ipr command struct
1776 * This function blocks host requests and initiates an
1782 static void ipr_oper_timeout(struct ipr_cmnd
*ipr_cmd
)
1784 unsigned long lock_flags
= 0;
1785 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
1788 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
1790 ioa_cfg
->errors_logged
++;
1791 dev_err(&ioa_cfg
->pdev
->dev
,
1792 "Adapter timed out transitioning to operational.\n");
1794 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
1795 ioa_cfg
->sdt_state
= GET_DUMP
;
1797 if (!ioa_cfg
->in_reset_reload
|| ioa_cfg
->reset_cmd
== ipr_cmd
) {
1799 ioa_cfg
->reset_retries
+= IPR_NUM_RESET_RELOAD_RETRIES
;
1800 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
1803 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
1808 * ipr_reset_reload - Reset/Reload the IOA
1809 * @ioa_cfg: ioa config struct
1810 * @shutdown_type: shutdown type
1812 * This function resets the adapter and re-initializes it.
1813 * This function assumes that all new host commands have been stopped.
1817 static int ipr_reset_reload(struct ipr_ioa_cfg
*ioa_cfg
,
1818 enum ipr_shutdown_type shutdown_type
)
1820 if (!ioa_cfg
->in_reset_reload
)
1821 ipr_initiate_ioa_reset(ioa_cfg
, shutdown_type
);
1823 spin_unlock_irq(ioa_cfg
->host
->host_lock
);
1824 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
1825 spin_lock_irq(ioa_cfg
->host
->host_lock
);
1827 /* If we got hit with a host reset while we were already resetting
1828 the adapter for some reason, and the reset failed. */
1829 if (ioa_cfg
->ioa_is_dead
) {
1838 * ipr_find_ses_entry - Find matching SES in SES table
1839 * @res: resource entry struct of SES
1842 * pointer to SES table entry / NULL on failure
1844 static const struct ipr_ses_table_entry
*
1845 ipr_find_ses_entry(struct ipr_resource_entry
*res
)
1848 const struct ipr_ses_table_entry
*ste
= ipr_ses_table
;
1850 for (i
= 0; i
< ARRAY_SIZE(ipr_ses_table
); i
++, ste
++) {
1851 for (j
= 0, matches
= 0; j
< IPR_PROD_ID_LEN
; j
++) {
1852 if (ste
->compare_product_id_byte
[j
] == 'X') {
1853 if (res
->cfgte
.std_inq_data
.vpids
.product_id
[j
] == ste
->product_id
[j
])
1861 if (matches
== IPR_PROD_ID_LEN
)
1869 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
1870 * @ioa_cfg: ioa config struct
1872 * @bus_width: bus width
1875 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
1876 * For a 2-byte wide SCSI bus, the maximum transfer speed is
1877 * twice the maximum transfer rate (e.g. for a wide enabled bus,
1878 * max 160MHz = max 320MB/sec).
1880 static u32
ipr_get_max_scsi_speed(struct ipr_ioa_cfg
*ioa_cfg
, u8 bus
, u8 bus_width
)
1882 struct ipr_resource_entry
*res
;
1883 const struct ipr_ses_table_entry
*ste
;
1884 u32 max_xfer_rate
= IPR_MAX_SCSI_RATE(bus_width
);
1886 /* Loop through each config table entry in the config table buffer */
1887 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
1888 if (!(IPR_IS_SES_DEVICE(res
->cfgte
.std_inq_data
)))
1891 if (bus
!= res
->cfgte
.res_addr
.bus
)
1894 if (!(ste
= ipr_find_ses_entry(res
)))
1897 max_xfer_rate
= (ste
->max_bus_speed_limit
* 10) / (bus_width
/ 8);
1900 return max_xfer_rate
;
1904 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
1905 * @ioa_cfg: ioa config struct
1906 * @max_delay: max delay in micro-seconds to wait
1908 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
1911 * 0 on success / other on failure
1913 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg
*ioa_cfg
, int max_delay
)
1915 volatile u32 pcii_reg
;
1918 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
1919 while (delay
< max_delay
) {
1920 pcii_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
1922 if (pcii_reg
& IPR_PCII_IO_DEBUG_ACKNOWLEDGE
)
1925 /* udelay cannot be used if delay is more than a few milliseconds */
1926 if ((delay
/ 1000) > MAX_UDELAY_MS
)
1927 mdelay(delay
/ 1000);
1937 * ipr_get_ldump_data_section - Dump IOA memory
1938 * @ioa_cfg: ioa config struct
1939 * @start_addr: adapter address to dump
1940 * @dest: destination kernel buffer
1941 * @length_in_words: length to dump in 4 byte words
1944 * 0 on success / -EIO on failure
1946 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg
*ioa_cfg
,
1948 __be32
*dest
, u32 length_in_words
)
1950 volatile u32 temp_pcii_reg
;
1953 /* Write IOA interrupt reg starting LDUMP state */
1954 writel((IPR_UPROCI_RESET_ALERT
| IPR_UPROCI_IO_DEBUG_ALERT
),
1955 ioa_cfg
->regs
.set_uproc_interrupt_reg
);
1957 /* Wait for IO debug acknowledge */
1958 if (ipr_wait_iodbg_ack(ioa_cfg
,
1959 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC
)) {
1960 dev_err(&ioa_cfg
->pdev
->dev
,
1961 "IOA dump long data transfer timeout\n");
1965 /* Signal LDUMP interlocked - clear IO debug ack */
1966 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
,
1967 ioa_cfg
->regs
.clr_interrupt_reg
);
1969 /* Write Mailbox with starting address */
1970 writel(start_addr
, ioa_cfg
->ioa_mailbox
);
1972 /* Signal address valid - clear IOA Reset alert */
1973 writel(IPR_UPROCI_RESET_ALERT
,
1974 ioa_cfg
->regs
.clr_uproc_interrupt_reg
);
1976 for (i
= 0; i
< length_in_words
; i
++) {
1977 /* Wait for IO debug acknowledge */
1978 if (ipr_wait_iodbg_ack(ioa_cfg
,
1979 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC
)) {
1980 dev_err(&ioa_cfg
->pdev
->dev
,
1981 "IOA dump short data transfer timeout\n");
1985 /* Read data from mailbox and increment destination pointer */
1986 *dest
= cpu_to_be32(readl(ioa_cfg
->ioa_mailbox
));
1989 /* For all but the last word of data, signal data received */
1990 if (i
< (length_in_words
- 1)) {
1991 /* Signal dump data received - Clear IO debug Ack */
1992 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
,
1993 ioa_cfg
->regs
.clr_interrupt_reg
);
1997 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
1998 writel(IPR_UPROCI_RESET_ALERT
,
1999 ioa_cfg
->regs
.set_uproc_interrupt_reg
);
2001 writel(IPR_UPROCI_IO_DEBUG_ALERT
,
2002 ioa_cfg
->regs
.clr_uproc_interrupt_reg
);
2004 /* Signal dump data received - Clear IO debug Ack */
2005 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
,
2006 ioa_cfg
->regs
.clr_interrupt_reg
);
2008 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2009 while (delay
< IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC
) {
2011 readl(ioa_cfg
->regs
.sense_uproc_interrupt_reg
);
2013 if (!(temp_pcii_reg
& IPR_UPROCI_RESET_ALERT
))
2023 #ifdef CONFIG_SCSI_IPR_DUMP
2025 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2026 * @ioa_cfg: ioa config struct
2027 * @pci_address: adapter address
2028 * @length: length of data to copy
2030 * Copy data from PCI adapter to kernel buffer.
2031 * Note: length MUST be a 4 byte multiple
2033 * 0 on success / other on failure
2035 static int ipr_sdt_copy(struct ipr_ioa_cfg
*ioa_cfg
,
2036 unsigned long pci_address
, u32 length
)
2038 int bytes_copied
= 0;
2039 int cur_len
, rc
, rem_len
, rem_page_len
;
2041 unsigned long lock_flags
= 0;
2042 struct ipr_ioa_dump
*ioa_dump
= &ioa_cfg
->dump
->ioa_dump
;
2044 while (bytes_copied
< length
&&
2045 (ioa_dump
->hdr
.len
+ bytes_copied
) < IPR_MAX_IOA_DUMP_SIZE
) {
2046 if (ioa_dump
->page_offset
>= PAGE_SIZE
||
2047 ioa_dump
->page_offset
== 0) {
2048 page
= (__be32
*)__get_free_page(GFP_ATOMIC
);
2052 return bytes_copied
;
2055 ioa_dump
->page_offset
= 0;
2056 ioa_dump
->ioa_data
[ioa_dump
->next_page_index
] = page
;
2057 ioa_dump
->next_page_index
++;
2059 page
= ioa_dump
->ioa_data
[ioa_dump
->next_page_index
- 1];
2061 rem_len
= length
- bytes_copied
;
2062 rem_page_len
= PAGE_SIZE
- ioa_dump
->page_offset
;
2063 cur_len
= min(rem_len
, rem_page_len
);
2065 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2066 if (ioa_cfg
->sdt_state
== ABORT_DUMP
) {
2069 rc
= ipr_get_ldump_data_section(ioa_cfg
,
2070 pci_address
+ bytes_copied
,
2071 &page
[ioa_dump
->page_offset
/ 4],
2072 (cur_len
/ sizeof(u32
)));
2074 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2077 ioa_dump
->page_offset
+= cur_len
;
2078 bytes_copied
+= cur_len
;
2086 return bytes_copied
;
2090 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2091 * @hdr: dump entry header struct
2096 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header
*hdr
)
2098 hdr
->eye_catcher
= IPR_DUMP_EYE_CATCHER
;
2100 hdr
->offset
= sizeof(*hdr
);
2101 hdr
->status
= IPR_DUMP_STATUS_SUCCESS
;
2105 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2106 * @ioa_cfg: ioa config struct
2107 * @driver_dump: driver dump struct
2112 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg
*ioa_cfg
,
2113 struct ipr_driver_dump
*driver_dump
)
2115 struct ipr_inquiry_page3
*ucode_vpd
= &ioa_cfg
->vpd_cbs
->page3_data
;
2117 ipr_init_dump_entry_hdr(&driver_dump
->ioa_type_entry
.hdr
);
2118 driver_dump
->ioa_type_entry
.hdr
.len
=
2119 sizeof(struct ipr_dump_ioa_type_entry
) -
2120 sizeof(struct ipr_dump_entry_header
);
2121 driver_dump
->ioa_type_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_BINARY
;
2122 driver_dump
->ioa_type_entry
.hdr
.id
= IPR_DUMP_DRIVER_TYPE_ID
;
2123 driver_dump
->ioa_type_entry
.type
= ioa_cfg
->type
;
2124 driver_dump
->ioa_type_entry
.fw_version
= (ucode_vpd
->major_release
<< 24) |
2125 (ucode_vpd
->card_type
<< 16) | (ucode_vpd
->minor_release
[0] << 8) |
2126 ucode_vpd
->minor_release
[1];
2127 driver_dump
->hdr
.num_entries
++;
2131 * ipr_dump_version_data - Fill in the driver version in the dump.
2132 * @ioa_cfg: ioa config struct
2133 * @driver_dump: driver dump struct
2138 static void ipr_dump_version_data(struct ipr_ioa_cfg
*ioa_cfg
,
2139 struct ipr_driver_dump
*driver_dump
)
2141 ipr_init_dump_entry_hdr(&driver_dump
->version_entry
.hdr
);
2142 driver_dump
->version_entry
.hdr
.len
=
2143 sizeof(struct ipr_dump_version_entry
) -
2144 sizeof(struct ipr_dump_entry_header
);
2145 driver_dump
->version_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_ASCII
;
2146 driver_dump
->version_entry
.hdr
.id
= IPR_DUMP_DRIVER_VERSION_ID
;
2147 strcpy(driver_dump
->version_entry
.version
, IPR_DRIVER_VERSION
);
2148 driver_dump
->hdr
.num_entries
++;
2152 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2153 * @ioa_cfg: ioa config struct
2154 * @driver_dump: driver dump struct
2159 static void ipr_dump_trace_data(struct ipr_ioa_cfg
*ioa_cfg
,
2160 struct ipr_driver_dump
*driver_dump
)
2162 ipr_init_dump_entry_hdr(&driver_dump
->trace_entry
.hdr
);
2163 driver_dump
->trace_entry
.hdr
.len
=
2164 sizeof(struct ipr_dump_trace_entry
) -
2165 sizeof(struct ipr_dump_entry_header
);
2166 driver_dump
->trace_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_BINARY
;
2167 driver_dump
->trace_entry
.hdr
.id
= IPR_DUMP_TRACE_ID
;
2168 memcpy(driver_dump
->trace_entry
.trace
, ioa_cfg
->trace
, IPR_TRACE_SIZE
);
2169 driver_dump
->hdr
.num_entries
++;
2173 * ipr_dump_location_data - Fill in the IOA location in the dump.
2174 * @ioa_cfg: ioa config struct
2175 * @driver_dump: driver dump struct
2180 static void ipr_dump_location_data(struct ipr_ioa_cfg
*ioa_cfg
,
2181 struct ipr_driver_dump
*driver_dump
)
2183 ipr_init_dump_entry_hdr(&driver_dump
->location_entry
.hdr
);
2184 driver_dump
->location_entry
.hdr
.len
=
2185 sizeof(struct ipr_dump_location_entry
) -
2186 sizeof(struct ipr_dump_entry_header
);
2187 driver_dump
->location_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_ASCII
;
2188 driver_dump
->location_entry
.hdr
.id
= IPR_DUMP_LOCATION_ID
;
2189 strcpy(driver_dump
->location_entry
.location
, dev_name(&ioa_cfg
->pdev
->dev
));
2190 driver_dump
->hdr
.num_entries
++;
2194 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2195 * @ioa_cfg: ioa config struct
2196 * @dump: dump struct
2201 static void ipr_get_ioa_dump(struct ipr_ioa_cfg
*ioa_cfg
, struct ipr_dump
*dump
)
2203 unsigned long start_addr
, sdt_word
;
2204 unsigned long lock_flags
= 0;
2205 struct ipr_driver_dump
*driver_dump
= &dump
->driver_dump
;
2206 struct ipr_ioa_dump
*ioa_dump
= &dump
->ioa_dump
;
2207 u32 num_entries
, start_off
, end_off
;
2208 u32 bytes_to_copy
, bytes_copied
, rc
;
2209 struct ipr_sdt
*sdt
;
2214 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2216 if (ioa_cfg
->sdt_state
!= GET_DUMP
) {
2217 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2221 start_addr
= readl(ioa_cfg
->ioa_mailbox
);
2223 if (!ipr_sdt_is_fmt2(start_addr
)) {
2224 dev_err(&ioa_cfg
->pdev
->dev
,
2225 "Invalid dump table format: %lx\n", start_addr
);
2226 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2230 dev_err(&ioa_cfg
->pdev
->dev
, "Dump of IOA initiated\n");
2232 driver_dump
->hdr
.eye_catcher
= IPR_DUMP_EYE_CATCHER
;
2234 /* Initialize the overall dump header */
2235 driver_dump
->hdr
.len
= sizeof(struct ipr_driver_dump
);
2236 driver_dump
->hdr
.num_entries
= 1;
2237 driver_dump
->hdr
.first_entry_offset
= sizeof(struct ipr_dump_header
);
2238 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_SUCCESS
;
2239 driver_dump
->hdr
.os
= IPR_DUMP_OS_LINUX
;
2240 driver_dump
->hdr
.driver_name
= IPR_DUMP_DRIVER_NAME
;
2242 ipr_dump_version_data(ioa_cfg
, driver_dump
);
2243 ipr_dump_location_data(ioa_cfg
, driver_dump
);
2244 ipr_dump_ioa_type_data(ioa_cfg
, driver_dump
);
2245 ipr_dump_trace_data(ioa_cfg
, driver_dump
);
2247 /* Update dump_header */
2248 driver_dump
->hdr
.len
+= sizeof(struct ipr_dump_entry_header
);
2250 /* IOA Dump entry */
2251 ipr_init_dump_entry_hdr(&ioa_dump
->hdr
);
2252 ioa_dump
->format
= IPR_SDT_FMT2
;
2253 ioa_dump
->hdr
.len
= 0;
2254 ioa_dump
->hdr
.data_type
= IPR_DUMP_DATA_TYPE_BINARY
;
2255 ioa_dump
->hdr
.id
= IPR_DUMP_IOA_DUMP_ID
;
2257 /* First entries in sdt are actually a list of dump addresses and
2258 lengths to gather the real dump data. sdt represents the pointer
2259 to the ioa generated dump table. Dump data will be extracted based
2260 on entries in this table */
2261 sdt
= &ioa_dump
->sdt
;
2263 rc
= ipr_get_ldump_data_section(ioa_cfg
, start_addr
, (__be32
*)sdt
,
2264 sizeof(struct ipr_sdt
) / sizeof(__be32
));
2266 /* Smart Dump table is ready to use and the first entry is valid */
2267 if (rc
|| (be32_to_cpu(sdt
->hdr
.state
) != IPR_FMT2_SDT_READY_TO_USE
)) {
2268 dev_err(&ioa_cfg
->pdev
->dev
,
2269 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
2270 rc
, be32_to_cpu(sdt
->hdr
.state
));
2271 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_FAILED
;
2272 ioa_cfg
->sdt_state
= DUMP_OBTAINED
;
2273 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2277 num_entries
= be32_to_cpu(sdt
->hdr
.num_entries_used
);
2279 if (num_entries
> IPR_NUM_SDT_ENTRIES
)
2280 num_entries
= IPR_NUM_SDT_ENTRIES
;
2282 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2284 for (i
= 0; i
< num_entries
; i
++) {
2285 if (ioa_dump
->hdr
.len
> IPR_MAX_IOA_DUMP_SIZE
) {
2286 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_QUAL_SUCCESS
;
2290 if (sdt
->entry
[i
].flags
& IPR_SDT_VALID_ENTRY
) {
2291 sdt_word
= be32_to_cpu(sdt
->entry
[i
].bar_str_offset
);
2292 start_off
= sdt_word
& IPR_FMT2_MBX_ADDR_MASK
;
2293 end_off
= be32_to_cpu(sdt
->entry
[i
].end_offset
);
2295 if (ipr_sdt_is_fmt2(sdt_word
) && sdt_word
) {
2296 bytes_to_copy
= end_off
- start_off
;
2297 if (bytes_to_copy
> IPR_MAX_IOA_DUMP_SIZE
) {
2298 sdt
->entry
[i
].flags
&= ~IPR_SDT_VALID_ENTRY
;
2302 /* Copy data from adapter to driver buffers */
2303 bytes_copied
= ipr_sdt_copy(ioa_cfg
, sdt_word
,
2306 ioa_dump
->hdr
.len
+= bytes_copied
;
2308 if (bytes_copied
!= bytes_to_copy
) {
2309 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_QUAL_SUCCESS
;
2316 dev_err(&ioa_cfg
->pdev
->dev
, "Dump of IOA completed.\n");
2318 /* Update dump_header */
2319 driver_dump
->hdr
.len
+= ioa_dump
->hdr
.len
;
2321 ioa_cfg
->sdt_state
= DUMP_OBTAINED
;
2326 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
2330 * ipr_release_dump - Free adapter dump memory
2331 * @kref: kref struct
2336 static void ipr_release_dump(struct kref
*kref
)
2338 struct ipr_dump
*dump
= container_of(kref
,struct ipr_dump
,kref
);
2339 struct ipr_ioa_cfg
*ioa_cfg
= dump
->ioa_cfg
;
2340 unsigned long lock_flags
= 0;
2344 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2345 ioa_cfg
->dump
= NULL
;
2346 ioa_cfg
->sdt_state
= INACTIVE
;
2347 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2349 for (i
= 0; i
< dump
->ioa_dump
.next_page_index
; i
++)
2350 free_page((unsigned long) dump
->ioa_dump
.ioa_data
[i
]);
2357 * ipr_worker_thread - Worker thread
2358 * @work: ioa config struct
2360 * Called at task level from a work thread. This function takes care
2361 * of adding and removing device from the mid-layer as configuration
2362 * changes are detected by the adapter.
2367 static void ipr_worker_thread(struct work_struct
*work
)
2369 unsigned long lock_flags
;
2370 struct ipr_resource_entry
*res
;
2371 struct scsi_device
*sdev
;
2372 struct ipr_dump
*dump
;
2373 struct ipr_ioa_cfg
*ioa_cfg
=
2374 container_of(work
, struct ipr_ioa_cfg
, work_q
);
2375 u8 bus
, target
, lun
;
2379 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2381 if (ioa_cfg
->sdt_state
== GET_DUMP
) {
2382 dump
= ioa_cfg
->dump
;
2384 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2387 kref_get(&dump
->kref
);
2388 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2389 ipr_get_ioa_dump(ioa_cfg
, dump
);
2390 kref_put(&dump
->kref
, ipr_release_dump
);
2392 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2393 if (ioa_cfg
->sdt_state
== DUMP_OBTAINED
)
2394 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
2395 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2402 if (!ioa_cfg
->allow_cmds
|| !ioa_cfg
->allow_ml_add_del
) {
2403 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2407 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
2408 if (res
->del_from_ml
&& res
->sdev
) {
2411 if (!scsi_device_get(sdev
)) {
2412 list_move_tail(&res
->queue
, &ioa_cfg
->free_res_q
);
2413 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2414 scsi_remove_device(sdev
);
2415 scsi_device_put(sdev
);
2416 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2423 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
2424 if (res
->add_to_ml
) {
2425 bus
= res
->cfgte
.res_addr
.bus
;
2426 target
= res
->cfgte
.res_addr
.target
;
2427 lun
= res
->cfgte
.res_addr
.lun
;
2429 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2430 scsi_add_device(ioa_cfg
->host
, bus
, target
, lun
);
2431 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2436 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2437 kobject_uevent(&ioa_cfg
->host
->shost_dev
.kobj
, KOBJ_CHANGE
);
2441 #ifdef CONFIG_SCSI_IPR_TRACE
2443 * ipr_read_trace - Dump the adapter trace
2444 * @kobj: kobject struct
2445 * @bin_attr: bin_attribute struct
2448 * @count: buffer size
2451 * number of bytes printed to buffer
2453 static ssize_t
ipr_read_trace(struct kobject
*kobj
,
2454 struct bin_attribute
*bin_attr
,
2455 char *buf
, loff_t off
, size_t count
)
2457 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2458 struct Scsi_Host
*shost
= class_to_shost(dev
);
2459 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
2460 unsigned long lock_flags
= 0;
2463 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2464 ret
= memory_read_from_buffer(buf
, count
, &off
, ioa_cfg
->trace
,
2466 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2471 static struct bin_attribute ipr_trace_attr
= {
2477 .read
= ipr_read_trace
,
2481 static const struct {
2482 enum ipr_cache_state state
;
2484 } cache_state
[] = {
2485 { CACHE_NONE
, "none" },
2486 { CACHE_DISABLED
, "disabled" },
2487 { CACHE_ENABLED
, "enabled" }
2491 * ipr_show_write_caching - Show the write caching attribute
2492 * @dev: device struct
2496 * number of bytes printed to buffer
2498 static ssize_t
ipr_show_write_caching(struct device
*dev
,
2499 struct device_attribute
*attr
, char *buf
)
2501 struct Scsi_Host
*shost
= class_to_shost(dev
);
2502 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
2503 unsigned long lock_flags
= 0;
2506 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2507 for (i
= 0; i
< ARRAY_SIZE(cache_state
); i
++) {
2508 if (cache_state
[i
].state
== ioa_cfg
->cache_state
) {
2509 len
= snprintf(buf
, PAGE_SIZE
, "%s\n", cache_state
[i
].name
);
2513 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2519 * ipr_store_write_caching - Enable/disable adapter write cache
2520 * @dev: device struct
2522 * @count: buffer size
2524 * This function will enable/disable adapter write cache.
2527 * count on success / other on failure
2529 static ssize_t
ipr_store_write_caching(struct device
*dev
,
2530 struct device_attribute
*attr
,
2531 const char *buf
, size_t count
)
2533 struct Scsi_Host
*shost
= class_to_shost(dev
);
2534 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
2535 unsigned long lock_flags
= 0;
2536 enum ipr_cache_state new_state
= CACHE_INVALID
;
2539 if (!capable(CAP_SYS_ADMIN
))
2541 if (ioa_cfg
->cache_state
== CACHE_NONE
)
2544 for (i
= 0; i
< ARRAY_SIZE(cache_state
); i
++) {
2545 if (!strncmp(cache_state
[i
].name
, buf
, strlen(cache_state
[i
].name
))) {
2546 new_state
= cache_state
[i
].state
;
2551 if (new_state
!= CACHE_DISABLED
&& new_state
!= CACHE_ENABLED
)
2554 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2555 if (ioa_cfg
->cache_state
== new_state
) {
2556 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2560 ioa_cfg
->cache_state
= new_state
;
2561 dev_info(&ioa_cfg
->pdev
->dev
, "%s adapter write cache.\n",
2562 new_state
== CACHE_ENABLED
? "Enabling" : "Disabling");
2563 if (!ioa_cfg
->in_reset_reload
)
2564 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
2565 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2566 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
2571 static struct device_attribute ipr_ioa_cache_attr
= {
2573 .name
= "write_cache",
2574 .mode
= S_IRUGO
| S_IWUSR
,
2576 .show
= ipr_show_write_caching
,
2577 .store
= ipr_store_write_caching
2581 * ipr_show_fw_version - Show the firmware version
2582 * @dev: class device struct
2586 * number of bytes printed to buffer
2588 static ssize_t
ipr_show_fw_version(struct device
*dev
,
2589 struct device_attribute
*attr
, char *buf
)
2591 struct Scsi_Host
*shost
= class_to_shost(dev
);
2592 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
2593 struct ipr_inquiry_page3
*ucode_vpd
= &ioa_cfg
->vpd_cbs
->page3_data
;
2594 unsigned long lock_flags
= 0;
2597 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2598 len
= snprintf(buf
, PAGE_SIZE
, "%02X%02X%02X%02X\n",
2599 ucode_vpd
->major_release
, ucode_vpd
->card_type
,
2600 ucode_vpd
->minor_release
[0],
2601 ucode_vpd
->minor_release
[1]);
2602 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2606 static struct device_attribute ipr_fw_version_attr
= {
2608 .name
= "fw_version",
2611 .show
= ipr_show_fw_version
,
2615 * ipr_show_log_level - Show the adapter's error logging level
2616 * @dev: class device struct
2620 * number of bytes printed to buffer
2622 static ssize_t
ipr_show_log_level(struct device
*dev
,
2623 struct device_attribute
*attr
, char *buf
)
2625 struct Scsi_Host
*shost
= class_to_shost(dev
);
2626 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
2627 unsigned long lock_flags
= 0;
2630 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2631 len
= snprintf(buf
, PAGE_SIZE
, "%d\n", ioa_cfg
->log_level
);
2632 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2637 * ipr_store_log_level - Change the adapter's error logging level
2638 * @dev: class device struct
2642 * number of bytes printed to buffer
2644 static ssize_t
ipr_store_log_level(struct device
*dev
,
2645 struct device_attribute
*attr
,
2646 const char *buf
, size_t count
)
2648 struct Scsi_Host
*shost
= class_to_shost(dev
);
2649 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
2650 unsigned long lock_flags
= 0;
2652 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2653 ioa_cfg
->log_level
= simple_strtoul(buf
, NULL
, 10);
2654 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2658 static struct device_attribute ipr_log_level_attr
= {
2660 .name
= "log_level",
2661 .mode
= S_IRUGO
| S_IWUSR
,
2663 .show
= ipr_show_log_level
,
2664 .store
= ipr_store_log_level
2668 * ipr_store_diagnostics - IOA Diagnostics interface
2669 * @dev: device struct
2671 * @count: buffer size
2673 * This function will reset the adapter and wait a reasonable
2674 * amount of time for any errors that the adapter might log.
2677 * count on success / other on failure
2679 static ssize_t
ipr_store_diagnostics(struct device
*dev
,
2680 struct device_attribute
*attr
,
2681 const char *buf
, size_t count
)
2683 struct Scsi_Host
*shost
= class_to_shost(dev
);
2684 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
2685 unsigned long lock_flags
= 0;
2688 if (!capable(CAP_SYS_ADMIN
))
2691 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2692 while(ioa_cfg
->in_reset_reload
) {
2693 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2694 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
2695 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2698 ioa_cfg
->errors_logged
= 0;
2699 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
2701 if (ioa_cfg
->in_reset_reload
) {
2702 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2703 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
2705 /* Wait for a second for any errors to be logged */
2708 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2712 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2713 if (ioa_cfg
->in_reset_reload
|| ioa_cfg
->errors_logged
)
2715 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2720 static struct device_attribute ipr_diagnostics_attr
= {
2722 .name
= "run_diagnostics",
2725 .store
= ipr_store_diagnostics
2729 * ipr_show_adapter_state - Show the adapter's state
2730 * @class_dev: device struct
2734 * number of bytes printed to buffer
2736 static ssize_t
ipr_show_adapter_state(struct device
*dev
,
2737 struct device_attribute
*attr
, char *buf
)
2739 struct Scsi_Host
*shost
= class_to_shost(dev
);
2740 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
2741 unsigned long lock_flags
= 0;
2744 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2745 if (ioa_cfg
->ioa_is_dead
)
2746 len
= snprintf(buf
, PAGE_SIZE
, "offline\n");
2748 len
= snprintf(buf
, PAGE_SIZE
, "online\n");
2749 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2754 * ipr_store_adapter_state - Change adapter state
2755 * @dev: device struct
2757 * @count: buffer size
2759 * This function will change the adapter's state.
2762 * count on success / other on failure
2764 static ssize_t
ipr_store_adapter_state(struct device
*dev
,
2765 struct device_attribute
*attr
,
2766 const char *buf
, size_t count
)
2768 struct Scsi_Host
*shost
= class_to_shost(dev
);
2769 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
2770 unsigned long lock_flags
;
2773 if (!capable(CAP_SYS_ADMIN
))
2776 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2777 if (ioa_cfg
->ioa_is_dead
&& !strncmp(buf
, "online", 6)) {
2778 ioa_cfg
->ioa_is_dead
= 0;
2779 ioa_cfg
->reset_retries
= 0;
2780 ioa_cfg
->in_ioa_bringdown
= 0;
2781 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
2783 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2784 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
2789 static struct device_attribute ipr_ioa_state_attr
= {
2791 .name
= "online_state",
2792 .mode
= S_IRUGO
| S_IWUSR
,
2794 .show
= ipr_show_adapter_state
,
2795 .store
= ipr_store_adapter_state
2799 * ipr_store_reset_adapter - Reset the adapter
2800 * @dev: device struct
2802 * @count: buffer size
2804 * This function will reset the adapter.
2807 * count on success / other on failure
2809 static ssize_t
ipr_store_reset_adapter(struct device
*dev
,
2810 struct device_attribute
*attr
,
2811 const char *buf
, size_t count
)
2813 struct Scsi_Host
*shost
= class_to_shost(dev
);
2814 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
2815 unsigned long lock_flags
;
2818 if (!capable(CAP_SYS_ADMIN
))
2821 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2822 if (!ioa_cfg
->in_reset_reload
)
2823 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
2824 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2825 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
2830 static struct device_attribute ipr_ioa_reset_attr
= {
2832 .name
= "reset_host",
2835 .store
= ipr_store_reset_adapter
2839 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
2840 * @buf_len: buffer length
2842 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
2843 * list to use for microcode download
2846 * pointer to sglist / NULL on failure
2848 static struct ipr_sglist
*ipr_alloc_ucode_buffer(int buf_len
)
2850 int sg_size
, order
, bsize_elem
, num_elem
, i
, j
;
2851 struct ipr_sglist
*sglist
;
2852 struct scatterlist
*scatterlist
;
2855 /* Get the minimum size per scatter/gather element */
2856 sg_size
= buf_len
/ (IPR_MAX_SGLIST
- 1);
2858 /* Get the actual size per element */
2859 order
= get_order(sg_size
);
2861 /* Determine the actual number of bytes per element */
2862 bsize_elem
= PAGE_SIZE
* (1 << order
);
2864 /* Determine the actual number of sg entries needed */
2865 if (buf_len
% bsize_elem
)
2866 num_elem
= (buf_len
/ bsize_elem
) + 1;
2868 num_elem
= buf_len
/ bsize_elem
;
2870 /* Allocate a scatter/gather list for the DMA */
2871 sglist
= kzalloc(sizeof(struct ipr_sglist
) +
2872 (sizeof(struct scatterlist
) * (num_elem
- 1)),
2875 if (sglist
== NULL
) {
2880 scatterlist
= sglist
->scatterlist
;
2881 sg_init_table(scatterlist
, num_elem
);
2883 sglist
->order
= order
;
2884 sglist
->num_sg
= num_elem
;
2886 /* Allocate a bunch of sg elements */
2887 for (i
= 0; i
< num_elem
; i
++) {
2888 page
= alloc_pages(GFP_KERNEL
, order
);
2892 /* Free up what we already allocated */
2893 for (j
= i
- 1; j
>= 0; j
--)
2894 __free_pages(sg_page(&scatterlist
[j
]), order
);
2899 sg_set_page(&scatterlist
[i
], page
, 0, 0);
2906 * ipr_free_ucode_buffer - Frees a microcode download buffer
2907 * @p_dnld: scatter/gather list pointer
2909 * Free a DMA'able ucode download buffer previously allocated with
2910 * ipr_alloc_ucode_buffer
2915 static void ipr_free_ucode_buffer(struct ipr_sglist
*sglist
)
2919 for (i
= 0; i
< sglist
->num_sg
; i
++)
2920 __free_pages(sg_page(&sglist
->scatterlist
[i
]), sglist
->order
);
2926 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
2927 * @sglist: scatter/gather list pointer
2928 * @buffer: buffer pointer
2929 * @len: buffer length
2931 * Copy a microcode image from a user buffer into a buffer allocated by
2932 * ipr_alloc_ucode_buffer
2935 * 0 on success / other on failure
2937 static int ipr_copy_ucode_buffer(struct ipr_sglist
*sglist
,
2938 u8
*buffer
, u32 len
)
2940 int bsize_elem
, i
, result
= 0;
2941 struct scatterlist
*scatterlist
;
2944 /* Determine the actual number of bytes per element */
2945 bsize_elem
= PAGE_SIZE
* (1 << sglist
->order
);
2947 scatterlist
= sglist
->scatterlist
;
2949 for (i
= 0; i
< (len
/ bsize_elem
); i
++, buffer
+= bsize_elem
) {
2950 struct page
*page
= sg_page(&scatterlist
[i
]);
2953 memcpy(kaddr
, buffer
, bsize_elem
);
2956 scatterlist
[i
].length
= bsize_elem
;
2964 if (len
% bsize_elem
) {
2965 struct page
*page
= sg_page(&scatterlist
[i
]);
2968 memcpy(kaddr
, buffer
, len
% bsize_elem
);
2971 scatterlist
[i
].length
= len
% bsize_elem
;
2974 sglist
->buffer_len
= len
;
2979 * ipr_build_ucode_ioadl - Build a microcode download IOADL
2980 * @ipr_cmd: ipr command struct
2981 * @sglist: scatter/gather list
2983 * Builds a microcode download IOA data list (IOADL).
2986 static void ipr_build_ucode_ioadl(struct ipr_cmnd
*ipr_cmd
,
2987 struct ipr_sglist
*sglist
)
2989 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
2990 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->ioadl
;
2991 struct scatterlist
*scatterlist
= sglist
->scatterlist
;
2994 ipr_cmd
->dma_use_sg
= sglist
->num_dma_sg
;
2995 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
2996 ioarcb
->write_data_transfer_length
= cpu_to_be32(sglist
->buffer_len
);
2997 ioarcb
->write_ioadl_len
=
2998 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
3000 for (i
= 0; i
< ipr_cmd
->dma_use_sg
; i
++) {
3001 ioadl
[i
].flags_and_data_len
=
3002 cpu_to_be32(IPR_IOADL_FLAGS_WRITE
| sg_dma_len(&scatterlist
[i
]));
3004 cpu_to_be32(sg_dma_address(&scatterlist
[i
]));
3007 ioadl
[i
-1].flags_and_data_len
|=
3008 cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
3012 * ipr_update_ioa_ucode - Update IOA's microcode
3013 * @ioa_cfg: ioa config struct
3014 * @sglist: scatter/gather list
3016 * Initiate an adapter reset to update the IOA's microcode
3019 * 0 on success / -EIO on failure
3021 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg
*ioa_cfg
,
3022 struct ipr_sglist
*sglist
)
3024 unsigned long lock_flags
;
3026 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3027 while(ioa_cfg
->in_reset_reload
) {
3028 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3029 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3030 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3033 if (ioa_cfg
->ucode_sglist
) {
3034 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3035 dev_err(&ioa_cfg
->pdev
->dev
,
3036 "Microcode download already in progress\n");
3040 sglist
->num_dma_sg
= pci_map_sg(ioa_cfg
->pdev
, sglist
->scatterlist
,
3041 sglist
->num_sg
, DMA_TO_DEVICE
);
3043 if (!sglist
->num_dma_sg
) {
3044 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3045 dev_err(&ioa_cfg
->pdev
->dev
,
3046 "Failed to map microcode download buffer!\n");
3050 ioa_cfg
->ucode_sglist
= sglist
;
3051 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
3052 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3053 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3055 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3056 ioa_cfg
->ucode_sglist
= NULL
;
3057 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3062 * ipr_store_update_fw - Update the firmware on the adapter
3063 * @class_dev: device struct
3065 * @count: buffer size
3067 * This function will update the firmware on the adapter.
3070 * count on success / other on failure
3072 static ssize_t
ipr_store_update_fw(struct device
*dev
,
3073 struct device_attribute
*attr
,
3074 const char *buf
, size_t count
)
3076 struct Scsi_Host
*shost
= class_to_shost(dev
);
3077 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3078 struct ipr_ucode_image_header
*image_hdr
;
3079 const struct firmware
*fw_entry
;
3080 struct ipr_sglist
*sglist
;
3083 int len
, result
, dnld_size
;
3085 if (!capable(CAP_SYS_ADMIN
))
3088 len
= snprintf(fname
, 99, "%s", buf
);
3089 fname
[len
-1] = '\0';
3091 if(request_firmware(&fw_entry
, fname
, &ioa_cfg
->pdev
->dev
)) {
3092 dev_err(&ioa_cfg
->pdev
->dev
, "Firmware file %s not found\n", fname
);
3096 image_hdr
= (struct ipr_ucode_image_header
*)fw_entry
->data
;
3098 if (be32_to_cpu(image_hdr
->header_length
) > fw_entry
->size
||
3099 (ioa_cfg
->vpd_cbs
->page3_data
.card_type
&&
3100 ioa_cfg
->vpd_cbs
->page3_data
.card_type
!= image_hdr
->card_type
)) {
3101 dev_err(&ioa_cfg
->pdev
->dev
, "Invalid microcode buffer\n");
3102 release_firmware(fw_entry
);
3106 src
= (u8
*)image_hdr
+ be32_to_cpu(image_hdr
->header_length
);
3107 dnld_size
= fw_entry
->size
- be32_to_cpu(image_hdr
->header_length
);
3108 sglist
= ipr_alloc_ucode_buffer(dnld_size
);
3111 dev_err(&ioa_cfg
->pdev
->dev
, "Microcode buffer allocation failed\n");
3112 release_firmware(fw_entry
);
3116 result
= ipr_copy_ucode_buffer(sglist
, src
, dnld_size
);
3119 dev_err(&ioa_cfg
->pdev
->dev
,
3120 "Microcode buffer copy to DMA buffer failed\n");
3124 result
= ipr_update_ioa_ucode(ioa_cfg
, sglist
);
3129 ipr_free_ucode_buffer(sglist
);
3130 release_firmware(fw_entry
);
3134 static struct device_attribute ipr_update_fw_attr
= {
3136 .name
= "update_fw",
3139 .store
= ipr_store_update_fw
3142 static struct device_attribute
*ipr_ioa_attrs
[] = {
3143 &ipr_fw_version_attr
,
3144 &ipr_log_level_attr
,
3145 &ipr_diagnostics_attr
,
3146 &ipr_ioa_state_attr
,
3147 &ipr_ioa_reset_attr
,
3148 &ipr_update_fw_attr
,
3149 &ipr_ioa_cache_attr
,
3153 #ifdef CONFIG_SCSI_IPR_DUMP
3155 * ipr_read_dump - Dump the adapter
3156 * @kobj: kobject struct
3157 * @bin_attr: bin_attribute struct
3160 * @count: buffer size
3163 * number of bytes printed to buffer
3165 static ssize_t
ipr_read_dump(struct kobject
*kobj
,
3166 struct bin_attribute
*bin_attr
,
3167 char *buf
, loff_t off
, size_t count
)
3169 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
3170 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3171 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3172 struct ipr_dump
*dump
;
3173 unsigned long lock_flags
= 0;
3178 if (!capable(CAP_SYS_ADMIN
))
3181 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3182 dump
= ioa_cfg
->dump
;
3184 if (ioa_cfg
->sdt_state
!= DUMP_OBTAINED
|| !dump
) {
3185 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3188 kref_get(&dump
->kref
);
3189 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3191 if (off
> dump
->driver_dump
.hdr
.len
) {
3192 kref_put(&dump
->kref
, ipr_release_dump
);
3196 if (off
+ count
> dump
->driver_dump
.hdr
.len
) {
3197 count
= dump
->driver_dump
.hdr
.len
- off
;
3201 if (count
&& off
< sizeof(dump
->driver_dump
)) {
3202 if (off
+ count
> sizeof(dump
->driver_dump
))
3203 len
= sizeof(dump
->driver_dump
) - off
;
3206 src
= (u8
*)&dump
->driver_dump
+ off
;
3207 memcpy(buf
, src
, len
);
3213 off
-= sizeof(dump
->driver_dump
);
3215 if (count
&& off
< offsetof(struct ipr_ioa_dump
, ioa_data
)) {
3216 if (off
+ count
> offsetof(struct ipr_ioa_dump
, ioa_data
))
3217 len
= offsetof(struct ipr_ioa_dump
, ioa_data
) - off
;
3220 src
= (u8
*)&dump
->ioa_dump
+ off
;
3221 memcpy(buf
, src
, len
);
3227 off
-= offsetof(struct ipr_ioa_dump
, ioa_data
);
3230 if ((off
& PAGE_MASK
) != ((off
+ count
) & PAGE_MASK
))
3231 len
= PAGE_ALIGN(off
) - off
;
3234 src
= (u8
*)dump
->ioa_dump
.ioa_data
[(off
& PAGE_MASK
) >> PAGE_SHIFT
];
3235 src
+= off
& ~PAGE_MASK
;
3236 memcpy(buf
, src
, len
);
3242 kref_put(&dump
->kref
, ipr_release_dump
);
3247 * ipr_alloc_dump - Prepare for adapter dump
3248 * @ioa_cfg: ioa config struct
3251 * 0 on success / other on failure
3253 static int ipr_alloc_dump(struct ipr_ioa_cfg
*ioa_cfg
)
3255 struct ipr_dump
*dump
;
3256 unsigned long lock_flags
= 0;
3258 dump
= kzalloc(sizeof(struct ipr_dump
), GFP_KERNEL
);
3261 ipr_err("Dump memory allocation failed\n");
3265 kref_init(&dump
->kref
);
3266 dump
->ioa_cfg
= ioa_cfg
;
3268 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3270 if (INACTIVE
!= ioa_cfg
->sdt_state
) {
3271 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3276 ioa_cfg
->dump
= dump
;
3277 ioa_cfg
->sdt_state
= WAIT_FOR_DUMP
;
3278 if (ioa_cfg
->ioa_is_dead
&& !ioa_cfg
->dump_taken
) {
3279 ioa_cfg
->dump_taken
= 1;
3280 schedule_work(&ioa_cfg
->work_q
);
3282 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3288 * ipr_free_dump - Free adapter dump memory
3289 * @ioa_cfg: ioa config struct
3292 * 0 on success / other on failure
3294 static int ipr_free_dump(struct ipr_ioa_cfg
*ioa_cfg
)
3296 struct ipr_dump
*dump
;
3297 unsigned long lock_flags
= 0;
3301 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3302 dump
= ioa_cfg
->dump
;
3304 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3308 ioa_cfg
->dump
= NULL
;
3309 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3311 kref_put(&dump
->kref
, ipr_release_dump
);
3318 * ipr_write_dump - Setup dump state of adapter
3319 * @kobj: kobject struct
3320 * @bin_attr: bin_attribute struct
3323 * @count: buffer size
3326 * number of bytes printed to buffer
3328 static ssize_t
ipr_write_dump(struct kobject
*kobj
,
3329 struct bin_attribute
*bin_attr
,
3330 char *buf
, loff_t off
, size_t count
)
3332 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
3333 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3334 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3337 if (!capable(CAP_SYS_ADMIN
))
3341 rc
= ipr_alloc_dump(ioa_cfg
);
3342 else if (buf
[0] == '0')
3343 rc
= ipr_free_dump(ioa_cfg
);
3353 static struct bin_attribute ipr_dump_attr
= {
3356 .mode
= S_IRUSR
| S_IWUSR
,
3359 .read
= ipr_read_dump
,
3360 .write
= ipr_write_dump
3363 static int ipr_free_dump(struct ipr_ioa_cfg
*ioa_cfg
) { return 0; };
3367 * ipr_change_queue_depth - Change the device's queue depth
3368 * @sdev: scsi device struct
3369 * @qdepth: depth to set
3370 * @reason: calling context
3375 static int ipr_change_queue_depth(struct scsi_device
*sdev
, int qdepth
,
3378 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
3379 struct ipr_resource_entry
*res
;
3380 unsigned long lock_flags
= 0;
3382 if (reason
!= SCSI_QDEPTH_DEFAULT
)
3385 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3386 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
3388 if (res
&& ipr_is_gata(res
) && qdepth
> IPR_MAX_CMD_PER_ATA_LUN
)
3389 qdepth
= IPR_MAX_CMD_PER_ATA_LUN
;
3390 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3392 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
3393 return sdev
->queue_depth
;
3397 * ipr_change_queue_type - Change the device's queue type
3398 * @dsev: scsi device struct
3399 * @tag_type: type of tags to use
3402 * actual queue type set
3404 static int ipr_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
3406 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
3407 struct ipr_resource_entry
*res
;
3408 unsigned long lock_flags
= 0;
3410 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3411 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
3414 if (ipr_is_gscsi(res
) && sdev
->tagged_supported
) {
3416 * We don't bother quiescing the device here since the
3417 * adapter firmware does it for us.
3419 scsi_set_tag_type(sdev
, tag_type
);
3422 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
3424 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
3430 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3435 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
3436 * @dev: device struct
3440 * number of bytes printed to buffer
3442 static ssize_t
ipr_show_adapter_handle(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3444 struct scsi_device
*sdev
= to_scsi_device(dev
);
3445 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
3446 struct ipr_resource_entry
*res
;
3447 unsigned long lock_flags
= 0;
3448 ssize_t len
= -ENXIO
;
3450 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3451 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
3453 len
= snprintf(buf
, PAGE_SIZE
, "%08X\n", res
->cfgte
.res_handle
);
3454 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3458 static struct device_attribute ipr_adapter_handle_attr
= {
3460 .name
= "adapter_handle",
3463 .show
= ipr_show_adapter_handle
3466 static struct device_attribute
*ipr_dev_attrs
[] = {
3467 &ipr_adapter_handle_attr
,
3472 * ipr_biosparam - Return the HSC mapping
3473 * @sdev: scsi device struct
3474 * @block_device: block device pointer
3475 * @capacity: capacity of the device
3476 * @parm: Array containing returned HSC values.
3478 * This function generates the HSC parms that fdisk uses.
3479 * We want to make sure we return something that places partitions
3480 * on 4k boundaries for best performance with the IOA.
3485 static int ipr_biosparam(struct scsi_device
*sdev
,
3486 struct block_device
*block_device
,
3487 sector_t capacity
, int *parm
)
3495 cylinders
= capacity
;
3496 sector_div(cylinders
, (128 * 32));
3501 parm
[2] = cylinders
;
3507 * ipr_find_starget - Find target based on bus/target.
3508 * @starget: scsi target struct
3511 * resource entry pointer if found / NULL if not found
3513 static struct ipr_resource_entry
*ipr_find_starget(struct scsi_target
*starget
)
3515 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
3516 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) shost
->hostdata
;
3517 struct ipr_resource_entry
*res
;
3519 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
3520 if ((res
->cfgte
.res_addr
.bus
== starget
->channel
) &&
3521 (res
->cfgte
.res_addr
.target
== starget
->id
) &&
3522 (res
->cfgte
.res_addr
.lun
== 0)) {
3530 static struct ata_port_info sata_port_info
;
3533 * ipr_target_alloc - Prepare for commands to a SCSI target
3534 * @starget: scsi target struct
3536 * If the device is a SATA device, this function allocates an
3537 * ATA port with libata, else it does nothing.
3540 * 0 on success / non-0 on failure
3542 static int ipr_target_alloc(struct scsi_target
*starget
)
3544 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
3545 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) shost
->hostdata
;
3546 struct ipr_sata_port
*sata_port
;
3547 struct ata_port
*ap
;
3548 struct ipr_resource_entry
*res
;
3549 unsigned long lock_flags
;
3551 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3552 res
= ipr_find_starget(starget
);
3553 starget
->hostdata
= NULL
;
3555 if (res
&& ipr_is_gata(res
)) {
3556 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3557 sata_port
= kzalloc(sizeof(*sata_port
), GFP_KERNEL
);
3561 ap
= ata_sas_port_alloc(&ioa_cfg
->ata_host
, &sata_port_info
, shost
);
3563 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3564 sata_port
->ioa_cfg
= ioa_cfg
;
3566 sata_port
->res
= res
;
3568 res
->sata_port
= sata_port
;
3569 ap
->private_data
= sata_port
;
3570 starget
->hostdata
= sata_port
;
3576 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3582 * ipr_target_destroy - Destroy a SCSI target
3583 * @starget: scsi target struct
3585 * If the device was a SATA device, this function frees the libata
3586 * ATA port, else it does nothing.
3589 static void ipr_target_destroy(struct scsi_target
*starget
)
3591 struct ipr_sata_port
*sata_port
= starget
->hostdata
;
3594 starget
->hostdata
= NULL
;
3595 ata_sas_port_destroy(sata_port
->ap
);
3601 * ipr_find_sdev - Find device based on bus/target/lun.
3602 * @sdev: scsi device struct
3605 * resource entry pointer if found / NULL if not found
3607 static struct ipr_resource_entry
*ipr_find_sdev(struct scsi_device
*sdev
)
3609 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
3610 struct ipr_resource_entry
*res
;
3612 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
3613 if ((res
->cfgte
.res_addr
.bus
== sdev
->channel
) &&
3614 (res
->cfgte
.res_addr
.target
== sdev
->id
) &&
3615 (res
->cfgte
.res_addr
.lun
== sdev
->lun
))
3623 * ipr_slave_destroy - Unconfigure a SCSI device
3624 * @sdev: scsi device struct
3629 static void ipr_slave_destroy(struct scsi_device
*sdev
)
3631 struct ipr_resource_entry
*res
;
3632 struct ipr_ioa_cfg
*ioa_cfg
;
3633 unsigned long lock_flags
= 0;
3635 ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
3637 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3638 res
= (struct ipr_resource_entry
*) sdev
->hostdata
;
3641 ata_port_disable(res
->sata_port
->ap
);
3642 sdev
->hostdata
= NULL
;
3644 res
->sata_port
= NULL
;
3646 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3650 * ipr_slave_configure - Configure a SCSI device
3651 * @sdev: scsi device struct
3653 * This function configures the specified scsi device.
3658 static int ipr_slave_configure(struct scsi_device
*sdev
)
3660 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
3661 struct ipr_resource_entry
*res
;
3662 struct ata_port
*ap
= NULL
;
3663 unsigned long lock_flags
= 0;
3665 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3666 res
= sdev
->hostdata
;
3668 if (ipr_is_af_dasd_device(res
))
3669 sdev
->type
= TYPE_RAID
;
3670 if (ipr_is_af_dasd_device(res
) || ipr_is_ioa_resource(res
)) {
3671 sdev
->scsi_level
= 4;
3672 sdev
->no_uld_attach
= 1;
3674 if (ipr_is_vset_device(res
)) {
3675 blk_queue_rq_timeout(sdev
->request_queue
,
3676 IPR_VSET_RW_TIMEOUT
);
3677 blk_queue_max_sectors(sdev
->request_queue
, IPR_VSET_MAX_SECTORS
);
3679 if (ipr_is_vset_device(res
) || ipr_is_scsi_disk(res
))
3680 sdev
->allow_restart
= 1;
3681 if (ipr_is_gata(res
) && res
->sata_port
)
3682 ap
= res
->sata_port
->ap
;
3683 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3686 scsi_adjust_queue_depth(sdev
, 0, IPR_MAX_CMD_PER_ATA_LUN
);
3687 ata_sas_slave_configure(sdev
, ap
);
3689 scsi_adjust_queue_depth(sdev
, 0, sdev
->host
->cmd_per_lun
);
3692 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3697 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
3698 * @sdev: scsi device struct
3700 * This function initializes an ATA port so that future commands
3701 * sent through queuecommand will work.
3706 static int ipr_ata_slave_alloc(struct scsi_device
*sdev
)
3708 struct ipr_sata_port
*sata_port
= NULL
;
3712 if (sdev
->sdev_target
)
3713 sata_port
= sdev
->sdev_target
->hostdata
;
3715 rc
= ata_sas_port_init(sata_port
->ap
);
3717 ipr_slave_destroy(sdev
);
3724 * ipr_slave_alloc - Prepare for commands to a device.
3725 * @sdev: scsi device struct
3727 * This function saves a pointer to the resource entry
3728 * in the scsi device struct if the device exists. We
3729 * can then use this pointer in ipr_queuecommand when
3730 * handling new commands.
3733 * 0 on success / -ENXIO if device does not exist
3735 static int ipr_slave_alloc(struct scsi_device
*sdev
)
3737 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
3738 struct ipr_resource_entry
*res
;
3739 unsigned long lock_flags
;
3742 sdev
->hostdata
= NULL
;
3744 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3746 res
= ipr_find_sdev(sdev
);
3751 sdev
->hostdata
= res
;
3752 if (!ipr_is_naca_model(res
))
3753 res
->needs_sync_complete
= 1;
3755 if (ipr_is_gata(res
)) {
3756 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3757 return ipr_ata_slave_alloc(sdev
);
3761 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3767 * ipr_eh_host_reset - Reset the host adapter
3768 * @scsi_cmd: scsi command struct
3773 static int __ipr_eh_host_reset(struct scsi_cmnd
* scsi_cmd
)
3775 struct ipr_ioa_cfg
*ioa_cfg
;
3779 ioa_cfg
= (struct ipr_ioa_cfg
*) scsi_cmd
->device
->host
->hostdata
;
3781 dev_err(&ioa_cfg
->pdev
->dev
,
3782 "Adapter being reset as a result of error recovery.\n");
3784 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
3785 ioa_cfg
->sdt_state
= GET_DUMP
;
3787 rc
= ipr_reset_reload(ioa_cfg
, IPR_SHUTDOWN_ABBREV
);
3793 static int ipr_eh_host_reset(struct scsi_cmnd
* cmd
)
3797 spin_lock_irq(cmd
->device
->host
->host_lock
);
3798 rc
= __ipr_eh_host_reset(cmd
);
3799 spin_unlock_irq(cmd
->device
->host
->host_lock
);
3805 * ipr_device_reset - Reset the device
3806 * @ioa_cfg: ioa config struct
3807 * @res: resource entry struct
3809 * This function issues a device reset to the affected device.
3810 * If the device is a SCSI device, a LUN reset will be sent
3811 * to the device first. If that does not work, a target reset
3812 * will be sent. If the device is a SATA device, a PHY reset will
3816 * 0 on success / non-zero on failure
3818 static int ipr_device_reset(struct ipr_ioa_cfg
*ioa_cfg
,
3819 struct ipr_resource_entry
*res
)
3821 struct ipr_cmnd
*ipr_cmd
;
3822 struct ipr_ioarcb
*ioarcb
;
3823 struct ipr_cmd_pkt
*cmd_pkt
;
3824 struct ipr_ioarcb_ata_regs
*regs
;
3828 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
3829 ioarcb
= &ipr_cmd
->ioarcb
;
3830 cmd_pkt
= &ioarcb
->cmd_pkt
;
3831 regs
= &ioarcb
->add_data
.u
.regs
;
3833 ioarcb
->res_handle
= res
->cfgte
.res_handle
;
3834 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
3835 cmd_pkt
->cdb
[0] = IPR_RESET_DEVICE
;
3836 if (ipr_is_gata(res
)) {
3837 cmd_pkt
->cdb
[2] = IPR_ATA_PHY_RESET
;
3838 ioarcb
->add_cmd_parms_len
= cpu_to_be32(sizeof(regs
->flags
));
3839 regs
->flags
|= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION
;
3842 ipr_send_blocking_cmd(ipr_cmd
, ipr_timeout
, IPR_DEVICE_RESET_TIMEOUT
);
3843 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
3844 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
3845 if (ipr_is_gata(res
) && res
->sata_port
&& ioasc
!= IPR_IOASC_IOA_WAS_RESET
)
3846 memcpy(&res
->sata_port
->ioasa
, &ipr_cmd
->ioasa
.u
.gata
,
3847 sizeof(struct ipr_ioasa_gata
));
3850 return (IPR_IOASC_SENSE_KEY(ioasc
) ? -EIO
: 0);
3854 * ipr_sata_reset - Reset the SATA port
3855 * @link: SATA link to reset
3856 * @classes: class of the attached device
3858 * This function issues a SATA phy reset to the affected ATA link.
3861 * 0 on success / non-zero on failure
3863 static int ipr_sata_reset(struct ata_link
*link
, unsigned int *classes
,
3864 unsigned long deadline
)
3866 struct ipr_sata_port
*sata_port
= link
->ap
->private_data
;
3867 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
3868 struct ipr_resource_entry
*res
;
3869 unsigned long lock_flags
= 0;
3873 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3874 while(ioa_cfg
->in_reset_reload
) {
3875 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3876 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3877 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3880 res
= sata_port
->res
;
3882 rc
= ipr_device_reset(ioa_cfg
, res
);
3883 switch(res
->cfgte
.proto
) {
3884 case IPR_PROTO_SATA
:
3885 case IPR_PROTO_SAS_STP
:
3886 *classes
= ATA_DEV_ATA
;
3888 case IPR_PROTO_SATA_ATAPI
:
3889 case IPR_PROTO_SAS_STP_ATAPI
:
3890 *classes
= ATA_DEV_ATAPI
;
3893 *classes
= ATA_DEV_UNKNOWN
;
3898 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3904 * ipr_eh_dev_reset - Reset the device
3905 * @scsi_cmd: scsi command struct
3907 * This function issues a device reset to the affected device.
3908 * A LUN reset will be sent to the device first. If that does
3909 * not work, a target reset will be sent.
3914 static int __ipr_eh_dev_reset(struct scsi_cmnd
* scsi_cmd
)
3916 struct ipr_cmnd
*ipr_cmd
;
3917 struct ipr_ioa_cfg
*ioa_cfg
;
3918 struct ipr_resource_entry
*res
;
3919 struct ata_port
*ap
;
3923 ioa_cfg
= (struct ipr_ioa_cfg
*) scsi_cmd
->device
->host
->hostdata
;
3924 res
= scsi_cmd
->device
->hostdata
;
3930 * If we are currently going through reset/reload, return failed. This will force the
3931 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
3934 if (ioa_cfg
->in_reset_reload
)
3936 if (ioa_cfg
->ioa_is_dead
)
3939 list_for_each_entry(ipr_cmd
, &ioa_cfg
->pending_q
, queue
) {
3940 if (ipr_cmd
->ioarcb
.res_handle
== res
->cfgte
.res_handle
) {
3941 if (ipr_cmd
->scsi_cmd
)
3942 ipr_cmd
->done
= ipr_scsi_eh_done
;
3944 ipr_cmd
->done
= ipr_sata_eh_done
;
3945 if (ipr_cmd
->qc
&& !(ipr_cmd
->qc
->flags
& ATA_QCFLAG_FAILED
)) {
3946 ipr_cmd
->qc
->err_mask
|= AC_ERR_TIMEOUT
;
3947 ipr_cmd
->qc
->flags
|= ATA_QCFLAG_FAILED
;
3952 res
->resetting_device
= 1;
3953 scmd_printk(KERN_ERR
, scsi_cmd
, "Resetting device\n");
3955 if (ipr_is_gata(res
) && res
->sata_port
) {
3956 ap
= res
->sata_port
->ap
;
3957 spin_unlock_irq(scsi_cmd
->device
->host
->host_lock
);
3958 ata_std_error_handler(ap
);
3959 spin_lock_irq(scsi_cmd
->device
->host
->host_lock
);
3961 list_for_each_entry(ipr_cmd
, &ioa_cfg
->pending_q
, queue
) {
3962 if (ipr_cmd
->ioarcb
.res_handle
== res
->cfgte
.res_handle
) {
3968 rc
= ipr_device_reset(ioa_cfg
, res
);
3969 res
->resetting_device
= 0;
3972 return (rc
? FAILED
: SUCCESS
);
3975 static int ipr_eh_dev_reset(struct scsi_cmnd
* cmd
)
3979 spin_lock_irq(cmd
->device
->host
->host_lock
);
3980 rc
= __ipr_eh_dev_reset(cmd
);
3981 spin_unlock_irq(cmd
->device
->host
->host_lock
);
3987 * ipr_bus_reset_done - Op done function for bus reset.
3988 * @ipr_cmd: ipr command struct
3990 * This function is the op done function for a bus reset
3995 static void ipr_bus_reset_done(struct ipr_cmnd
*ipr_cmd
)
3997 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
3998 struct ipr_resource_entry
*res
;
4001 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
4002 if (!memcmp(&res
->cfgte
.res_handle
, &ipr_cmd
->ioarcb
.res_handle
,
4003 sizeof(res
->cfgte
.res_handle
))) {
4004 scsi_report_bus_reset(ioa_cfg
->host
, res
->cfgte
.res_addr
.bus
);
4010 * If abort has not completed, indicate the reset has, else call the
4011 * abort's done function to wake the sleeping eh thread
4013 if (ipr_cmd
->sibling
->sibling
)
4014 ipr_cmd
->sibling
->sibling
= NULL
;
4016 ipr_cmd
->sibling
->done(ipr_cmd
->sibling
);
4018 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
4023 * ipr_abort_timeout - An abort task has timed out
4024 * @ipr_cmd: ipr command struct
4026 * This function handles when an abort task times out. If this
4027 * happens we issue a bus reset since we have resources tied
4028 * up that must be freed before returning to the midlayer.
4033 static void ipr_abort_timeout(struct ipr_cmnd
*ipr_cmd
)
4035 struct ipr_cmnd
*reset_cmd
;
4036 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
4037 struct ipr_cmd_pkt
*cmd_pkt
;
4038 unsigned long lock_flags
= 0;
4041 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4042 if (ipr_cmd
->completion
.done
|| ioa_cfg
->in_reset_reload
) {
4043 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4047 sdev_printk(KERN_ERR
, ipr_cmd
->u
.sdev
, "Abort timed out. Resetting bus.\n");
4048 reset_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
4049 ipr_cmd
->sibling
= reset_cmd
;
4050 reset_cmd
->sibling
= ipr_cmd
;
4051 reset_cmd
->ioarcb
.res_handle
= ipr_cmd
->ioarcb
.res_handle
;
4052 cmd_pkt
= &reset_cmd
->ioarcb
.cmd_pkt
;
4053 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
4054 cmd_pkt
->cdb
[0] = IPR_RESET_DEVICE
;
4055 cmd_pkt
->cdb
[2] = IPR_RESET_TYPE_SELECT
| IPR_BUS_RESET
;
4057 ipr_do_req(reset_cmd
, ipr_bus_reset_done
, ipr_timeout
, IPR_DEVICE_RESET_TIMEOUT
);
4058 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4063 * ipr_cancel_op - Cancel specified op
4064 * @scsi_cmd: scsi command struct
4066 * This function cancels specified op.
4071 static int ipr_cancel_op(struct scsi_cmnd
* scsi_cmd
)
4073 struct ipr_cmnd
*ipr_cmd
;
4074 struct ipr_ioa_cfg
*ioa_cfg
;
4075 struct ipr_resource_entry
*res
;
4076 struct ipr_cmd_pkt
*cmd_pkt
;
4081 ioa_cfg
= (struct ipr_ioa_cfg
*)scsi_cmd
->device
->host
->hostdata
;
4082 res
= scsi_cmd
->device
->hostdata
;
4084 /* If we are currently going through reset/reload, return failed.
4085 * This will force the mid-layer to call ipr_eh_host_reset,
4086 * which will then go to sleep and wait for the reset to complete
4088 if (ioa_cfg
->in_reset_reload
|| ioa_cfg
->ioa_is_dead
)
4090 if (!res
|| !ipr_is_gscsi(res
))
4093 list_for_each_entry(ipr_cmd
, &ioa_cfg
->pending_q
, queue
) {
4094 if (ipr_cmd
->scsi_cmd
== scsi_cmd
) {
4095 ipr_cmd
->done
= ipr_scsi_eh_done
;
4104 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
4105 ipr_cmd
->ioarcb
.res_handle
= res
->cfgte
.res_handle
;
4106 cmd_pkt
= &ipr_cmd
->ioarcb
.cmd_pkt
;
4107 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
4108 cmd_pkt
->cdb
[0] = IPR_CANCEL_ALL_REQUESTS
;
4109 ipr_cmd
->u
.sdev
= scsi_cmd
->device
;
4111 scmd_printk(KERN_ERR
, scsi_cmd
, "Aborting command: %02X\n",
4113 ipr_send_blocking_cmd(ipr_cmd
, ipr_abort_timeout
, IPR_CANCEL_ALL_TIMEOUT
);
4114 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
4117 * If the abort task timed out and we sent a bus reset, we will get
4118 * one the following responses to the abort
4120 if (ioasc
== IPR_IOASC_BUS_WAS_RESET
|| ioasc
== IPR_IOASC_SYNC_REQUIRED
) {
4125 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
4126 if (!ipr_is_naca_model(res
))
4127 res
->needs_sync_complete
= 1;
4130 return (IPR_IOASC_SENSE_KEY(ioasc
) ? FAILED
: SUCCESS
);
4134 * ipr_eh_abort - Abort a single op
4135 * @scsi_cmd: scsi command struct
4140 static int ipr_eh_abort(struct scsi_cmnd
* scsi_cmd
)
4142 unsigned long flags
;
4147 spin_lock_irqsave(scsi_cmd
->device
->host
->host_lock
, flags
);
4148 rc
= ipr_cancel_op(scsi_cmd
);
4149 spin_unlock_irqrestore(scsi_cmd
->device
->host
->host_lock
, flags
);
4156 * ipr_handle_other_interrupt - Handle "other" interrupts
4157 * @ioa_cfg: ioa config struct
4158 * @int_reg: interrupt register
4161 * IRQ_NONE / IRQ_HANDLED
4163 static irqreturn_t
ipr_handle_other_interrupt(struct ipr_ioa_cfg
*ioa_cfg
,
4164 volatile u32 int_reg
)
4166 irqreturn_t rc
= IRQ_HANDLED
;
4168 if (int_reg
& IPR_PCII_IOA_TRANS_TO_OPER
) {
4169 /* Mask the interrupt */
4170 writel(IPR_PCII_IOA_TRANS_TO_OPER
, ioa_cfg
->regs
.set_interrupt_mask_reg
);
4172 /* Clear the interrupt */
4173 writel(IPR_PCII_IOA_TRANS_TO_OPER
, ioa_cfg
->regs
.clr_interrupt_reg
);
4174 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
4176 list_del(&ioa_cfg
->reset_cmd
->queue
);
4177 del_timer(&ioa_cfg
->reset_cmd
->timer
);
4178 ipr_reset_ioa_job(ioa_cfg
->reset_cmd
);
4180 if (int_reg
& IPR_PCII_IOA_UNIT_CHECKED
)
4181 ioa_cfg
->ioa_unit_checked
= 1;
4183 dev_err(&ioa_cfg
->pdev
->dev
,
4184 "Permanent IOA failure. 0x%08X\n", int_reg
);
4186 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
4187 ioa_cfg
->sdt_state
= GET_DUMP
;
4189 ipr_mask_and_clear_interrupts(ioa_cfg
, ~0);
4190 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
4197 * ipr_isr_eh - Interrupt service routine error handler
4198 * @ioa_cfg: ioa config struct
4199 * @msg: message to log
4204 static void ipr_isr_eh(struct ipr_ioa_cfg
*ioa_cfg
, char *msg
)
4206 ioa_cfg
->errors_logged
++;
4207 dev_err(&ioa_cfg
->pdev
->dev
, "%s\n", msg
);
4209 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
4210 ioa_cfg
->sdt_state
= GET_DUMP
;
4212 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
4216 * ipr_isr - Interrupt service routine
4218 * @devp: pointer to ioa config struct
4221 * IRQ_NONE / IRQ_HANDLED
4223 static irqreturn_t
ipr_isr(int irq
, void *devp
)
4225 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)devp
;
4226 unsigned long lock_flags
= 0;
4227 volatile u32 int_reg
, int_mask_reg
;
4231 struct ipr_cmnd
*ipr_cmd
;
4232 irqreturn_t rc
= IRQ_NONE
;
4234 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4236 /* If interrupts are disabled, ignore the interrupt */
4237 if (!ioa_cfg
->allow_interrupts
) {
4238 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4242 int_mask_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
4243 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
) & ~int_mask_reg
;
4245 /* If an interrupt on the adapter did not occur, ignore it */
4246 if (unlikely((int_reg
& IPR_PCII_OPER_INTERRUPTS
) == 0)) {
4247 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4254 while ((be32_to_cpu(*ioa_cfg
->hrrq_curr
) & IPR_HRRQ_TOGGLE_BIT
) ==
4255 ioa_cfg
->toggle_bit
) {
4257 cmd_index
= (be32_to_cpu(*ioa_cfg
->hrrq_curr
) &
4258 IPR_HRRQ_REQ_RESP_HANDLE_MASK
) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT
;
4260 if (unlikely(cmd_index
>= IPR_NUM_CMD_BLKS
)) {
4261 ipr_isr_eh(ioa_cfg
, "Invalid response handle from IOA");
4262 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4266 ipr_cmd
= ioa_cfg
->ipr_cmnd_list
[cmd_index
];
4268 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
4270 ipr_trc_hook(ipr_cmd
, IPR_TRACE_FINISH
, ioasc
);
4272 list_del(&ipr_cmd
->queue
);
4273 del_timer(&ipr_cmd
->timer
);
4274 ipr_cmd
->done(ipr_cmd
);
4278 if (ioa_cfg
->hrrq_curr
< ioa_cfg
->hrrq_end
) {
4279 ioa_cfg
->hrrq_curr
++;
4281 ioa_cfg
->hrrq_curr
= ioa_cfg
->hrrq_start
;
4282 ioa_cfg
->toggle_bit
^= 1u;
4286 if (ipr_cmd
!= NULL
) {
4287 /* Clear the PCI interrupt */
4289 writel(IPR_PCII_HRRQ_UPDATED
, ioa_cfg
->regs
.clr_interrupt_reg
);
4290 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
) & ~int_mask_reg
;
4291 } while (int_reg
& IPR_PCII_HRRQ_UPDATED
&&
4292 num_hrrq
++ < IPR_MAX_HRRQ_RETRIES
);
4294 if (int_reg
& IPR_PCII_HRRQ_UPDATED
) {
4295 ipr_isr_eh(ioa_cfg
, "Error clearing HRRQ");
4296 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4304 if (unlikely(rc
== IRQ_NONE
))
4305 rc
= ipr_handle_other_interrupt(ioa_cfg
, int_reg
);
4307 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4312 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
4313 * @ioa_cfg: ioa config struct
4314 * @ipr_cmd: ipr command struct
4317 * 0 on success / -1 on failure
4319 static int ipr_build_ioadl(struct ipr_ioa_cfg
*ioa_cfg
,
4320 struct ipr_cmnd
*ipr_cmd
)
4323 struct scatterlist
*sg
;
4325 u32 ioadl_flags
= 0;
4326 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
4327 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
4328 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->ioadl
;
4330 length
= scsi_bufflen(scsi_cmd
);
4334 nseg
= scsi_dma_map(scsi_cmd
);
4336 dev_err(&ioa_cfg
->pdev
->dev
, "pci_map_sg failed!\n");
4340 ipr_cmd
->dma_use_sg
= nseg
;
4342 if (scsi_cmd
->sc_data_direction
== DMA_TO_DEVICE
) {
4343 ioadl_flags
= IPR_IOADL_FLAGS_WRITE
;
4344 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
4345 ioarcb
->write_data_transfer_length
= cpu_to_be32(length
);
4346 ioarcb
->write_ioadl_len
=
4347 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
4348 } else if (scsi_cmd
->sc_data_direction
== DMA_FROM_DEVICE
) {
4349 ioadl_flags
= IPR_IOADL_FLAGS_READ
;
4350 ioarcb
->read_data_transfer_length
= cpu_to_be32(length
);
4351 ioarcb
->read_ioadl_len
=
4352 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
4355 if (ipr_cmd
->dma_use_sg
<= ARRAY_SIZE(ioarcb
->add_data
.u
.ioadl
)) {
4356 ioadl
= ioarcb
->add_data
.u
.ioadl
;
4357 ioarcb
->write_ioadl_addr
=
4358 cpu_to_be32(be32_to_cpu(ioarcb
->ioarcb_host_pci_addr
) +
4359 offsetof(struct ipr_ioarcb
, add_data
));
4360 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
4363 scsi_for_each_sg(scsi_cmd
, sg
, ipr_cmd
->dma_use_sg
, i
) {
4364 ioadl
[i
].flags_and_data_len
=
4365 cpu_to_be32(ioadl_flags
| sg_dma_len(sg
));
4366 ioadl
[i
].address
= cpu_to_be32(sg_dma_address(sg
));
4369 ioadl
[i
-1].flags_and_data_len
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
4374 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
4375 * @scsi_cmd: scsi command struct
4380 static u8
ipr_get_task_attributes(struct scsi_cmnd
*scsi_cmd
)
4383 u8 rc
= IPR_FLAGS_LO_UNTAGGED_TASK
;
4385 if (scsi_populate_tag_msg(scsi_cmd
, tag
)) {
4387 case MSG_SIMPLE_TAG
:
4388 rc
= IPR_FLAGS_LO_SIMPLE_TASK
;
4391 rc
= IPR_FLAGS_LO_HEAD_OF_Q_TASK
;
4393 case MSG_ORDERED_TAG
:
4394 rc
= IPR_FLAGS_LO_ORDERED_TASK
;
4403 * ipr_erp_done - Process completion of ERP for a device
4404 * @ipr_cmd: ipr command struct
4406 * This function copies the sense buffer into the scsi_cmd
4407 * struct and pushes the scsi_done function.
4412 static void ipr_erp_done(struct ipr_cmnd
*ipr_cmd
)
4414 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
4415 struct ipr_resource_entry
*res
= scsi_cmd
->device
->hostdata
;
4416 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
4417 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
4419 if (IPR_IOASC_SENSE_KEY(ioasc
) > 0) {
4420 scsi_cmd
->result
|= (DID_ERROR
<< 16);
4421 scmd_printk(KERN_ERR
, scsi_cmd
,
4422 "Request Sense failed with IOASC: 0x%08X\n", ioasc
);
4424 memcpy(scsi_cmd
->sense_buffer
, ipr_cmd
->sense_buffer
,
4425 SCSI_SENSE_BUFFERSIZE
);
4429 if (!ipr_is_naca_model(res
))
4430 res
->needs_sync_complete
= 1;
4433 scsi_dma_unmap(ipr_cmd
->scsi_cmd
);
4434 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
4435 scsi_cmd
->scsi_done(scsi_cmd
);
4439 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
4440 * @ipr_cmd: ipr command struct
4445 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd
*ipr_cmd
)
4447 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
4448 struct ipr_ioasa
*ioasa
= &ipr_cmd
->ioasa
;
4449 dma_addr_t dma_addr
= be32_to_cpu(ioarcb
->ioarcb_host_pci_addr
);
4451 memset(&ioarcb
->cmd_pkt
, 0, sizeof(struct ipr_cmd_pkt
));
4452 ioarcb
->write_data_transfer_length
= 0;
4453 ioarcb
->read_data_transfer_length
= 0;
4454 ioarcb
->write_ioadl_len
= 0;
4455 ioarcb
->read_ioadl_len
= 0;
4457 ioasa
->residual_data_len
= 0;
4458 ioarcb
->write_ioadl_addr
=
4459 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, ioadl
));
4460 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
4464 * ipr_erp_request_sense - Send request sense to a device
4465 * @ipr_cmd: ipr command struct
4467 * This function sends a request sense to a device as a result
4468 * of a check condition.
4473 static void ipr_erp_request_sense(struct ipr_cmnd
*ipr_cmd
)
4475 struct ipr_cmd_pkt
*cmd_pkt
= &ipr_cmd
->ioarcb
.cmd_pkt
;
4476 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
4478 if (IPR_IOASC_SENSE_KEY(ioasc
) > 0) {
4479 ipr_erp_done(ipr_cmd
);
4483 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd
);
4485 cmd_pkt
->request_type
= IPR_RQTYPE_SCSICDB
;
4486 cmd_pkt
->cdb
[0] = REQUEST_SENSE
;
4487 cmd_pkt
->cdb
[4] = SCSI_SENSE_BUFFERSIZE
;
4488 cmd_pkt
->flags_hi
|= IPR_FLAGS_HI_SYNC_OVERRIDE
;
4489 cmd_pkt
->flags_hi
|= IPR_FLAGS_HI_NO_ULEN_CHK
;
4490 cmd_pkt
->timeout
= cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT
/ HZ
);
4492 ipr_cmd
->ioadl
[0].flags_and_data_len
=
4493 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST
| SCSI_SENSE_BUFFERSIZE
);
4494 ipr_cmd
->ioadl
[0].address
=
4495 cpu_to_be32(ipr_cmd
->sense_buffer_dma
);
4497 ipr_cmd
->ioarcb
.read_ioadl_len
=
4498 cpu_to_be32(sizeof(struct ipr_ioadl_desc
));
4499 ipr_cmd
->ioarcb
.read_data_transfer_length
=
4500 cpu_to_be32(SCSI_SENSE_BUFFERSIZE
);
4502 ipr_do_req(ipr_cmd
, ipr_erp_done
, ipr_timeout
,
4503 IPR_REQUEST_SENSE_TIMEOUT
* 2);
4507 * ipr_erp_cancel_all - Send cancel all to a device
4508 * @ipr_cmd: ipr command struct
4510 * This function sends a cancel all to a device to clear the
4511 * queue. If we are running TCQ on the device, QERR is set to 1,
4512 * which means all outstanding ops have been dropped on the floor.
4513 * Cancel all will return them to us.
4518 static void ipr_erp_cancel_all(struct ipr_cmnd
*ipr_cmd
)
4520 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
4521 struct ipr_resource_entry
*res
= scsi_cmd
->device
->hostdata
;
4522 struct ipr_cmd_pkt
*cmd_pkt
;
4526 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd
);
4528 if (!scsi_get_tag_type(scsi_cmd
->device
)) {
4529 ipr_erp_request_sense(ipr_cmd
);
4533 cmd_pkt
= &ipr_cmd
->ioarcb
.cmd_pkt
;
4534 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
4535 cmd_pkt
->cdb
[0] = IPR_CANCEL_ALL_REQUESTS
;
4537 ipr_do_req(ipr_cmd
, ipr_erp_request_sense
, ipr_timeout
,
4538 IPR_CANCEL_ALL_TIMEOUT
);
4542 * ipr_dump_ioasa - Dump contents of IOASA
4543 * @ioa_cfg: ioa config struct
4544 * @ipr_cmd: ipr command struct
4545 * @res: resource entry struct
4547 * This function is invoked by the interrupt handler when ops
4548 * fail. It will log the IOASA if appropriate. Only called
4554 static void ipr_dump_ioasa(struct ipr_ioa_cfg
*ioa_cfg
,
4555 struct ipr_cmnd
*ipr_cmd
, struct ipr_resource_entry
*res
)
4559 u32 ioasc
, fd_ioasc
;
4560 struct ipr_ioasa
*ioasa
= &ipr_cmd
->ioasa
;
4561 __be32
*ioasa_data
= (__be32
*)ioasa
;
4564 ioasc
= be32_to_cpu(ioasa
->ioasc
) & IPR_IOASC_IOASC_MASK
;
4565 fd_ioasc
= be32_to_cpu(ioasa
->fd_ioasc
) & IPR_IOASC_IOASC_MASK
;
4570 if (ioa_cfg
->log_level
< IPR_DEFAULT_LOG_LEVEL
)
4573 if (ioasc
== IPR_IOASC_BUS_WAS_RESET
&& fd_ioasc
)
4574 error_index
= ipr_get_error(fd_ioasc
);
4576 error_index
= ipr_get_error(ioasc
);
4578 if (ioa_cfg
->log_level
< IPR_MAX_LOG_LEVEL
) {
4579 /* Don't log an error if the IOA already logged one */
4580 if (ioasa
->ilid
!= 0)
4583 if (!ipr_is_gscsi(res
))
4586 if (ipr_error_table
[error_index
].log_ioasa
== 0)
4590 ipr_res_err(ioa_cfg
, res
, "%s\n", ipr_error_table
[error_index
].error
);
4592 if (sizeof(struct ipr_ioasa
) < be16_to_cpu(ioasa
->ret_stat_len
))
4593 data_len
= sizeof(struct ipr_ioasa
);
4595 data_len
= be16_to_cpu(ioasa
->ret_stat_len
);
4597 ipr_err("IOASA Dump:\n");
4599 for (i
= 0; i
< data_len
/ 4; i
+= 4) {
4600 ipr_err("%08X: %08X %08X %08X %08X\n", i
*4,
4601 be32_to_cpu(ioasa_data
[i
]),
4602 be32_to_cpu(ioasa_data
[i
+1]),
4603 be32_to_cpu(ioasa_data
[i
+2]),
4604 be32_to_cpu(ioasa_data
[i
+3]));
4609 * ipr_gen_sense - Generate SCSI sense data from an IOASA
4611 * @sense_buf: sense data buffer
4616 static void ipr_gen_sense(struct ipr_cmnd
*ipr_cmd
)
4619 u8
*sense_buf
= ipr_cmd
->scsi_cmd
->sense_buffer
;
4620 struct ipr_resource_entry
*res
= ipr_cmd
->scsi_cmd
->device
->hostdata
;
4621 struct ipr_ioasa
*ioasa
= &ipr_cmd
->ioasa
;
4622 u32 ioasc
= be32_to_cpu(ioasa
->ioasc
);
4624 memset(sense_buf
, 0, SCSI_SENSE_BUFFERSIZE
);
4626 if (ioasc
>= IPR_FIRST_DRIVER_IOASC
)
4629 ipr_cmd
->scsi_cmd
->result
= SAM_STAT_CHECK_CONDITION
;
4631 if (ipr_is_vset_device(res
) &&
4632 ioasc
== IPR_IOASC_MED_DO_NOT_REALLOC
&&
4633 ioasa
->u
.vset
.failing_lba_hi
!= 0) {
4634 sense_buf
[0] = 0x72;
4635 sense_buf
[1] = IPR_IOASC_SENSE_KEY(ioasc
);
4636 sense_buf
[2] = IPR_IOASC_SENSE_CODE(ioasc
);
4637 sense_buf
[3] = IPR_IOASC_SENSE_QUAL(ioasc
);
4641 sense_buf
[9] = 0x0A;
4642 sense_buf
[10] = 0x80;
4644 failing_lba
= be32_to_cpu(ioasa
->u
.vset
.failing_lba_hi
);
4646 sense_buf
[12] = (failing_lba
& 0xff000000) >> 24;
4647 sense_buf
[13] = (failing_lba
& 0x00ff0000) >> 16;
4648 sense_buf
[14] = (failing_lba
& 0x0000ff00) >> 8;
4649 sense_buf
[15] = failing_lba
& 0x000000ff;
4651 failing_lba
= be32_to_cpu(ioasa
->u
.vset
.failing_lba_lo
);
4653 sense_buf
[16] = (failing_lba
& 0xff000000) >> 24;
4654 sense_buf
[17] = (failing_lba
& 0x00ff0000) >> 16;
4655 sense_buf
[18] = (failing_lba
& 0x0000ff00) >> 8;
4656 sense_buf
[19] = failing_lba
& 0x000000ff;
4658 sense_buf
[0] = 0x70;
4659 sense_buf
[2] = IPR_IOASC_SENSE_KEY(ioasc
);
4660 sense_buf
[12] = IPR_IOASC_SENSE_CODE(ioasc
);
4661 sense_buf
[13] = IPR_IOASC_SENSE_QUAL(ioasc
);
4663 /* Illegal request */
4664 if ((IPR_IOASC_SENSE_KEY(ioasc
) == 0x05) &&
4665 (be32_to_cpu(ioasa
->ioasc_specific
) & IPR_FIELD_POINTER_VALID
)) {
4666 sense_buf
[7] = 10; /* additional length */
4668 /* IOARCB was in error */
4669 if (IPR_IOASC_SENSE_CODE(ioasc
) == 0x24)
4670 sense_buf
[15] = 0xC0;
4671 else /* Parameter data was invalid */
4672 sense_buf
[15] = 0x80;
4675 ((IPR_FIELD_POINTER_MASK
&
4676 be32_to_cpu(ioasa
->ioasc_specific
)) >> 8) & 0xff;
4678 (IPR_FIELD_POINTER_MASK
&
4679 be32_to_cpu(ioasa
->ioasc_specific
)) & 0xff;
4681 if (ioasc
== IPR_IOASC_MED_DO_NOT_REALLOC
) {
4682 if (ipr_is_vset_device(res
))
4683 failing_lba
= be32_to_cpu(ioasa
->u
.vset
.failing_lba_lo
);
4685 failing_lba
= be32_to_cpu(ioasa
->u
.dasd
.failing_lba
);
4687 sense_buf
[0] |= 0x80; /* Or in the Valid bit */
4688 sense_buf
[3] = (failing_lba
& 0xff000000) >> 24;
4689 sense_buf
[4] = (failing_lba
& 0x00ff0000) >> 16;
4690 sense_buf
[5] = (failing_lba
& 0x0000ff00) >> 8;
4691 sense_buf
[6] = failing_lba
& 0x000000ff;
4694 sense_buf
[7] = 6; /* additional length */
4700 * ipr_get_autosense - Copy autosense data to sense buffer
4701 * @ipr_cmd: ipr command struct
4703 * This function copies the autosense buffer to the buffer
4704 * in the scsi_cmd, if there is autosense available.
4707 * 1 if autosense was available / 0 if not
4709 static int ipr_get_autosense(struct ipr_cmnd
*ipr_cmd
)
4711 struct ipr_ioasa
*ioasa
= &ipr_cmd
->ioasa
;
4713 if ((be32_to_cpu(ioasa
->ioasc_specific
) & IPR_AUTOSENSE_VALID
) == 0)
4716 memcpy(ipr_cmd
->scsi_cmd
->sense_buffer
, ioasa
->auto_sense
.data
,
4717 min_t(u16
, be16_to_cpu(ioasa
->auto_sense
.auto_sense_len
),
4718 SCSI_SENSE_BUFFERSIZE
));
4723 * ipr_erp_start - Process an error response for a SCSI op
4724 * @ioa_cfg: ioa config struct
4725 * @ipr_cmd: ipr command struct
4727 * This function determines whether or not to initiate ERP
4728 * on the affected device.
4733 static void ipr_erp_start(struct ipr_ioa_cfg
*ioa_cfg
,
4734 struct ipr_cmnd
*ipr_cmd
)
4736 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
4737 struct ipr_resource_entry
*res
= scsi_cmd
->device
->hostdata
;
4738 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
4739 u32 masked_ioasc
= ioasc
& IPR_IOASC_IOASC_MASK
;
4742 ipr_scsi_eh_done(ipr_cmd
);
4746 if (!ipr_is_gscsi(res
) && masked_ioasc
!= IPR_IOASC_HW_DEV_BUS_STATUS
)
4747 ipr_gen_sense(ipr_cmd
);
4749 ipr_dump_ioasa(ioa_cfg
, ipr_cmd
, res
);
4751 switch (masked_ioasc
) {
4752 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST
:
4753 if (ipr_is_naca_model(res
))
4754 scsi_cmd
->result
|= (DID_ABORT
<< 16);
4756 scsi_cmd
->result
|= (DID_IMM_RETRY
<< 16);
4758 case IPR_IOASC_IR_RESOURCE_HANDLE
:
4759 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA
:
4760 scsi_cmd
->result
|= (DID_NO_CONNECT
<< 16);
4762 case IPR_IOASC_HW_SEL_TIMEOUT
:
4763 scsi_cmd
->result
|= (DID_NO_CONNECT
<< 16);
4764 if (!ipr_is_naca_model(res
))
4765 res
->needs_sync_complete
= 1;
4767 case IPR_IOASC_SYNC_REQUIRED
:
4769 res
->needs_sync_complete
= 1;
4770 scsi_cmd
->result
|= (DID_IMM_RETRY
<< 16);
4772 case IPR_IOASC_MED_DO_NOT_REALLOC
: /* prevent retries */
4773 case IPR_IOASA_IR_DUAL_IOA_DISABLED
:
4774 scsi_cmd
->result
|= (DID_PASSTHROUGH
<< 16);
4776 case IPR_IOASC_BUS_WAS_RESET
:
4777 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER
:
4779 * Report the bus reset and ask for a retry. The device
4780 * will give CC/UA the next command.
4782 if (!res
->resetting_device
)
4783 scsi_report_bus_reset(ioa_cfg
->host
, scsi_cmd
->device
->channel
);
4784 scsi_cmd
->result
|= (DID_ERROR
<< 16);
4785 if (!ipr_is_naca_model(res
))
4786 res
->needs_sync_complete
= 1;
4788 case IPR_IOASC_HW_DEV_BUS_STATUS
:
4789 scsi_cmd
->result
|= IPR_IOASC_SENSE_STATUS(ioasc
);
4790 if (IPR_IOASC_SENSE_STATUS(ioasc
) == SAM_STAT_CHECK_CONDITION
) {
4791 if (!ipr_get_autosense(ipr_cmd
)) {
4792 if (!ipr_is_naca_model(res
)) {
4793 ipr_erp_cancel_all(ipr_cmd
);
4798 if (!ipr_is_naca_model(res
))
4799 res
->needs_sync_complete
= 1;
4801 case IPR_IOASC_NR_INIT_CMD_REQUIRED
:
4804 if (IPR_IOASC_SENSE_KEY(ioasc
) > RECOVERED_ERROR
)
4805 scsi_cmd
->result
|= (DID_ERROR
<< 16);
4806 if (!ipr_is_vset_device(res
) && !ipr_is_naca_model(res
))
4807 res
->needs_sync_complete
= 1;
4811 scsi_dma_unmap(ipr_cmd
->scsi_cmd
);
4812 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
4813 scsi_cmd
->scsi_done(scsi_cmd
);
4817 * ipr_scsi_done - mid-layer done function
4818 * @ipr_cmd: ipr command struct
4820 * This function is invoked by the interrupt handler for
4821 * ops generated by the SCSI mid-layer
4826 static void ipr_scsi_done(struct ipr_cmnd
*ipr_cmd
)
4828 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
4829 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
4830 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
4832 scsi_set_resid(scsi_cmd
, be32_to_cpu(ipr_cmd
->ioasa
.residual_data_len
));
4834 if (likely(IPR_IOASC_SENSE_KEY(ioasc
) == 0)) {
4835 scsi_dma_unmap(ipr_cmd
->scsi_cmd
);
4836 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
4837 scsi_cmd
->scsi_done(scsi_cmd
);
4839 ipr_erp_start(ioa_cfg
, ipr_cmd
);
4843 * ipr_queuecommand - Queue a mid-layer request
4844 * @scsi_cmd: scsi command struct
4845 * @done: done function
4847 * This function queues a request generated by the mid-layer.
4851 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
4852 * SCSI_MLQUEUE_HOST_BUSY if host is busy
4854 static int ipr_queuecommand(struct scsi_cmnd
*scsi_cmd
,
4855 void (*done
) (struct scsi_cmnd
*))
4857 struct ipr_ioa_cfg
*ioa_cfg
;
4858 struct ipr_resource_entry
*res
;
4859 struct ipr_ioarcb
*ioarcb
;
4860 struct ipr_cmnd
*ipr_cmd
;
4863 scsi_cmd
->scsi_done
= done
;
4864 ioa_cfg
= (struct ipr_ioa_cfg
*)scsi_cmd
->device
->host
->hostdata
;
4865 res
= scsi_cmd
->device
->hostdata
;
4866 scsi_cmd
->result
= (DID_OK
<< 16);
4869 * We are currently blocking all devices due to a host reset
4870 * We have told the host to stop giving us new requests, but
4871 * ERP ops don't count. FIXME
4873 if (unlikely(!ioa_cfg
->allow_cmds
&& !ioa_cfg
->ioa_is_dead
))
4874 return SCSI_MLQUEUE_HOST_BUSY
;
4877 * FIXME - Create scsi_set_host_offline interface
4878 * and the ioa_is_dead check can be removed
4880 if (unlikely(ioa_cfg
->ioa_is_dead
|| !res
)) {
4881 memset(scsi_cmd
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
4882 scsi_cmd
->result
= (DID_NO_CONNECT
<< 16);
4883 scsi_cmd
->scsi_done(scsi_cmd
);
4887 if (ipr_is_gata(res
) && res
->sata_port
)
4888 return ata_sas_queuecmd(scsi_cmd
, done
, res
->sata_port
->ap
);
4890 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
4891 ioarcb
= &ipr_cmd
->ioarcb
;
4892 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->pending_q
);
4894 memcpy(ioarcb
->cmd_pkt
.cdb
, scsi_cmd
->cmnd
, scsi_cmd
->cmd_len
);
4895 ipr_cmd
->scsi_cmd
= scsi_cmd
;
4896 ioarcb
->res_handle
= res
->cfgte
.res_handle
;
4897 ipr_cmd
->done
= ipr_scsi_done
;
4898 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, IPR_GET_PHYS_LOC(res
->cfgte
.res_addr
));
4900 if (ipr_is_gscsi(res
) || ipr_is_vset_device(res
)) {
4901 if (scsi_cmd
->underflow
== 0)
4902 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_ULEN_CHK
;
4904 if (res
->needs_sync_complete
) {
4905 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_SYNC_COMPLETE
;
4906 res
->needs_sync_complete
= 0;
4909 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_LINK_DESC
;
4910 ioarcb
->cmd_pkt
.flags_lo
|= IPR_FLAGS_LO_DELAY_AFTER_RST
;
4911 ioarcb
->cmd_pkt
.flags_lo
|= IPR_FLAGS_LO_ALIGNED_BFR
;
4912 ioarcb
->cmd_pkt
.flags_lo
|= ipr_get_task_attributes(scsi_cmd
);
4915 if (scsi_cmd
->cmnd
[0] >= 0xC0 &&
4916 (!ipr_is_gscsi(res
) || scsi_cmd
->cmnd
[0] == IPR_QUERY_RSRC_STATE
))
4917 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
4919 if (likely(rc
== 0))
4920 rc
= ipr_build_ioadl(ioa_cfg
, ipr_cmd
);
4922 if (likely(rc
== 0)) {
4924 writel(be32_to_cpu(ipr_cmd
->ioarcb
.ioarcb_host_pci_addr
),
4925 ioa_cfg
->regs
.ioarrin_reg
);
4927 list_move_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
4928 return SCSI_MLQUEUE_HOST_BUSY
;
4935 * ipr_ioctl - IOCTL handler
4936 * @sdev: scsi device struct
4941 * 0 on success / other on failure
4943 static int ipr_ioctl(struct scsi_device
*sdev
, int cmd
, void __user
*arg
)
4945 struct ipr_resource_entry
*res
;
4947 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
4948 if (res
&& ipr_is_gata(res
)) {
4949 if (cmd
== HDIO_GET_IDENTITY
)
4951 return ata_sas_scsi_ioctl(res
->sata_port
->ap
, sdev
, cmd
, arg
);
4958 * ipr_info - Get information about the card/driver
4959 * @scsi_host: scsi host struct
4962 * pointer to buffer with description string
4964 static const char * ipr_ioa_info(struct Scsi_Host
*host
)
4966 static char buffer
[512];
4967 struct ipr_ioa_cfg
*ioa_cfg
;
4968 unsigned long lock_flags
= 0;
4970 ioa_cfg
= (struct ipr_ioa_cfg
*) host
->hostdata
;
4972 spin_lock_irqsave(host
->host_lock
, lock_flags
);
4973 sprintf(buffer
, "IBM %X Storage Adapter", ioa_cfg
->type
);
4974 spin_unlock_irqrestore(host
->host_lock
, lock_flags
);
4979 static struct scsi_host_template driver_template
= {
4980 .module
= THIS_MODULE
,
4982 .info
= ipr_ioa_info
,
4984 .queuecommand
= ipr_queuecommand
,
4985 .eh_abort_handler
= ipr_eh_abort
,
4986 .eh_device_reset_handler
= ipr_eh_dev_reset
,
4987 .eh_host_reset_handler
= ipr_eh_host_reset
,
4988 .slave_alloc
= ipr_slave_alloc
,
4989 .slave_configure
= ipr_slave_configure
,
4990 .slave_destroy
= ipr_slave_destroy
,
4991 .target_alloc
= ipr_target_alloc
,
4992 .target_destroy
= ipr_target_destroy
,
4993 .change_queue_depth
= ipr_change_queue_depth
,
4994 .change_queue_type
= ipr_change_queue_type
,
4995 .bios_param
= ipr_biosparam
,
4996 .can_queue
= IPR_MAX_COMMANDS
,
4998 .sg_tablesize
= IPR_MAX_SGLIST
,
4999 .max_sectors
= IPR_IOA_MAX_SECTORS
,
5000 .cmd_per_lun
= IPR_MAX_CMD_PER_LUN
,
5001 .use_clustering
= ENABLE_CLUSTERING
,
5002 .shost_attrs
= ipr_ioa_attrs
,
5003 .sdev_attrs
= ipr_dev_attrs
,
5004 .proc_name
= IPR_NAME
5008 * ipr_ata_phy_reset - libata phy_reset handler
5009 * @ap: ata port to reset
5012 static void ipr_ata_phy_reset(struct ata_port
*ap
)
5014 unsigned long flags
;
5015 struct ipr_sata_port
*sata_port
= ap
->private_data
;
5016 struct ipr_resource_entry
*res
= sata_port
->res
;
5017 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
5021 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
5022 while(ioa_cfg
->in_reset_reload
) {
5023 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
5024 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
5025 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
5028 if (!ioa_cfg
->allow_cmds
)
5031 rc
= ipr_device_reset(ioa_cfg
, res
);
5034 ata_port_disable(ap
);
5038 switch(res
->cfgte
.proto
) {
5039 case IPR_PROTO_SATA
:
5040 case IPR_PROTO_SAS_STP
:
5041 ap
->link
.device
[0].class = ATA_DEV_ATA
;
5043 case IPR_PROTO_SATA_ATAPI
:
5044 case IPR_PROTO_SAS_STP_ATAPI
:
5045 ap
->link
.device
[0].class = ATA_DEV_ATAPI
;
5048 ap
->link
.device
[0].class = ATA_DEV_UNKNOWN
;
5049 ata_port_disable(ap
);
5054 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
5059 * ipr_ata_post_internal - Cleanup after an internal command
5060 * @qc: ATA queued command
5065 static void ipr_ata_post_internal(struct ata_queued_cmd
*qc
)
5067 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
5068 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
5069 struct ipr_cmnd
*ipr_cmd
;
5070 unsigned long flags
;
5072 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
5073 while(ioa_cfg
->in_reset_reload
) {
5074 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
5075 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
5076 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
5079 list_for_each_entry(ipr_cmd
, &ioa_cfg
->pending_q
, queue
) {
5080 if (ipr_cmd
->qc
== qc
) {
5081 ipr_device_reset(ioa_cfg
, sata_port
->res
);
5085 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
5089 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
5090 * @regs: destination
5091 * @tf: source ATA taskfile
5096 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs
*regs
,
5097 struct ata_taskfile
*tf
)
5099 regs
->feature
= tf
->feature
;
5100 regs
->nsect
= tf
->nsect
;
5101 regs
->lbal
= tf
->lbal
;
5102 regs
->lbam
= tf
->lbam
;
5103 regs
->lbah
= tf
->lbah
;
5104 regs
->device
= tf
->device
;
5105 regs
->command
= tf
->command
;
5106 regs
->hob_feature
= tf
->hob_feature
;
5107 regs
->hob_nsect
= tf
->hob_nsect
;
5108 regs
->hob_lbal
= tf
->hob_lbal
;
5109 regs
->hob_lbam
= tf
->hob_lbam
;
5110 regs
->hob_lbah
= tf
->hob_lbah
;
5111 regs
->ctl
= tf
->ctl
;
5115 * ipr_sata_done - done function for SATA commands
5116 * @ipr_cmd: ipr command struct
5118 * This function is invoked by the interrupt handler for
5119 * ops generated by the SCSI mid-layer to SATA devices
5124 static void ipr_sata_done(struct ipr_cmnd
*ipr_cmd
)
5126 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5127 struct ata_queued_cmd
*qc
= ipr_cmd
->qc
;
5128 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
5129 struct ipr_resource_entry
*res
= sata_port
->res
;
5130 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
5132 memcpy(&sata_port
->ioasa
, &ipr_cmd
->ioasa
.u
.gata
,
5133 sizeof(struct ipr_ioasa_gata
));
5134 ipr_dump_ioasa(ioa_cfg
, ipr_cmd
, res
);
5136 if (be32_to_cpu(ipr_cmd
->ioasa
.ioasc_specific
) & IPR_ATA_DEVICE_WAS_RESET
)
5137 scsi_report_device_reset(ioa_cfg
->host
, res
->cfgte
.res_addr
.bus
,
5138 res
->cfgte
.res_addr
.target
);
5140 if (IPR_IOASC_SENSE_KEY(ioasc
) > RECOVERED_ERROR
)
5141 qc
->err_mask
|= __ac_err_mask(ipr_cmd
->ioasa
.u
.gata
.status
);
5143 qc
->err_mask
|= ac_err_mask(ipr_cmd
->ioasa
.u
.gata
.status
);
5144 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
5145 ata_qc_complete(qc
);
5149 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
5150 * @ipr_cmd: ipr command struct
5151 * @qc: ATA queued command
5154 static void ipr_build_ata_ioadl(struct ipr_cmnd
*ipr_cmd
,
5155 struct ata_queued_cmd
*qc
)
5157 u32 ioadl_flags
= 0;
5158 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5159 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->ioadl
;
5160 struct ipr_ioadl_desc
*last_ioadl
= NULL
;
5161 int len
= qc
->nbytes
;
5162 struct scatterlist
*sg
;
5168 if (qc
->dma_dir
== DMA_TO_DEVICE
) {
5169 ioadl_flags
= IPR_IOADL_FLAGS_WRITE
;
5170 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
5171 ioarcb
->write_data_transfer_length
= cpu_to_be32(len
);
5172 ioarcb
->write_ioadl_len
=
5173 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
5174 } else if (qc
->dma_dir
== DMA_FROM_DEVICE
) {
5175 ioadl_flags
= IPR_IOADL_FLAGS_READ
;
5176 ioarcb
->read_data_transfer_length
= cpu_to_be32(len
);
5177 ioarcb
->read_ioadl_len
=
5178 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
5181 for_each_sg(qc
->sg
, sg
, qc
->n_elem
, si
) {
5182 ioadl
->flags_and_data_len
= cpu_to_be32(ioadl_flags
| sg_dma_len(sg
));
5183 ioadl
->address
= cpu_to_be32(sg_dma_address(sg
));
5189 if (likely(last_ioadl
))
5190 last_ioadl
->flags_and_data_len
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
5194 * ipr_qc_issue - Issue a SATA qc to a device
5195 * @qc: queued command
5200 static unsigned int ipr_qc_issue(struct ata_queued_cmd
*qc
)
5202 struct ata_port
*ap
= qc
->ap
;
5203 struct ipr_sata_port
*sata_port
= ap
->private_data
;
5204 struct ipr_resource_entry
*res
= sata_port
->res
;
5205 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
5206 struct ipr_cmnd
*ipr_cmd
;
5207 struct ipr_ioarcb
*ioarcb
;
5208 struct ipr_ioarcb_ata_regs
*regs
;
5210 if (unlikely(!ioa_cfg
->allow_cmds
|| ioa_cfg
->ioa_is_dead
))
5211 return AC_ERR_SYSTEM
;
5213 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
5214 ioarcb
= &ipr_cmd
->ioarcb
;
5215 regs
= &ioarcb
->add_data
.u
.regs
;
5217 memset(&ioarcb
->add_data
, 0, sizeof(ioarcb
->add_data
));
5218 ioarcb
->add_cmd_parms_len
= cpu_to_be32(sizeof(ioarcb
->add_data
.u
.regs
));
5220 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->pending_q
);
5222 ipr_cmd
->done
= ipr_sata_done
;
5223 ipr_cmd
->ioarcb
.res_handle
= res
->cfgte
.res_handle
;
5224 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_ATA_PASSTHRU
;
5225 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_LINK_DESC
;
5226 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_ULEN_CHK
;
5227 ipr_cmd
->dma_use_sg
= qc
->n_elem
;
5229 ipr_build_ata_ioadl(ipr_cmd
, qc
);
5230 regs
->flags
|= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION
;
5231 ipr_copy_sata_tf(regs
, &qc
->tf
);
5232 memcpy(ioarcb
->cmd_pkt
.cdb
, qc
->cdb
, IPR_MAX_CDB_LEN
);
5233 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, IPR_GET_PHYS_LOC(res
->cfgte
.res_addr
));
5235 switch (qc
->tf
.protocol
) {
5236 case ATA_PROT_NODATA
:
5241 regs
->flags
|= IPR_ATA_FLAG_XFER_TYPE_DMA
;
5244 case ATAPI_PROT_PIO
:
5245 case ATAPI_PROT_NODATA
:
5246 regs
->flags
|= IPR_ATA_FLAG_PACKET_CMD
;
5249 case ATAPI_PROT_DMA
:
5250 regs
->flags
|= IPR_ATA_FLAG_PACKET_CMD
;
5251 regs
->flags
|= IPR_ATA_FLAG_XFER_TYPE_DMA
;
5256 return AC_ERR_INVALID
;
5260 writel(be32_to_cpu(ioarcb
->ioarcb_host_pci_addr
),
5261 ioa_cfg
->regs
.ioarrin_reg
);
5266 * ipr_qc_fill_rtf - Read result TF
5267 * @qc: ATA queued command
5272 static bool ipr_qc_fill_rtf(struct ata_queued_cmd
*qc
)
5274 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
5275 struct ipr_ioasa_gata
*g
= &sata_port
->ioasa
;
5276 struct ata_taskfile
*tf
= &qc
->result_tf
;
5278 tf
->feature
= g
->error
;
5279 tf
->nsect
= g
->nsect
;
5283 tf
->device
= g
->device
;
5284 tf
->command
= g
->status
;
5285 tf
->hob_nsect
= g
->hob_nsect
;
5286 tf
->hob_lbal
= g
->hob_lbal
;
5287 tf
->hob_lbam
= g
->hob_lbam
;
5288 tf
->hob_lbah
= g
->hob_lbah
;
5289 tf
->ctl
= g
->alt_status
;
5294 static struct ata_port_operations ipr_sata_ops
= {
5295 .phy_reset
= ipr_ata_phy_reset
,
5296 .hardreset
= ipr_sata_reset
,
5297 .post_internal_cmd
= ipr_ata_post_internal
,
5298 .qc_prep
= ata_noop_qc_prep
,
5299 .qc_issue
= ipr_qc_issue
,
5300 .qc_fill_rtf
= ipr_qc_fill_rtf
,
5301 .port_start
= ata_sas_port_start
,
5302 .port_stop
= ata_sas_port_stop
5305 static struct ata_port_info sata_port_info
= {
5306 .flags
= ATA_FLAG_SATA
| ATA_FLAG_NO_LEGACY
| ATA_FLAG_SATA_RESET
|
5307 ATA_FLAG_MMIO
| ATA_FLAG_PIO_DMA
,
5308 .pio_mask
= 0x10, /* pio4 */
5310 .udma_mask
= 0x7f, /* udma0-6 */
5311 .port_ops
= &ipr_sata_ops
5314 #ifdef CONFIG_PPC_PSERIES
5315 static const u16 ipr_blocked_processors
[] = {
5327 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
5328 * @ioa_cfg: ioa cfg struct
5330 * Adapters that use Gemstone revision < 3.1 do not work reliably on
5331 * certain pSeries hardware. This function determines if the given
5332 * adapter is in one of these confgurations or not.
5335 * 1 if adapter is not supported / 0 if adapter is supported
5337 static int ipr_invalid_adapter(struct ipr_ioa_cfg
*ioa_cfg
)
5341 if ((ioa_cfg
->type
== 0x5702) && (ioa_cfg
->pdev
->revision
< 4)) {
5342 for (i
= 0; i
< ARRAY_SIZE(ipr_blocked_processors
); i
++){
5343 if (__is_processor(ipr_blocked_processors
[i
]))
5350 #define ipr_invalid_adapter(ioa_cfg) 0
5354 * ipr_ioa_bringdown_done - IOA bring down completion.
5355 * @ipr_cmd: ipr command struct
5357 * This function processes the completion of an adapter bring down.
5358 * It wakes any reset sleepers.
5363 static int ipr_ioa_bringdown_done(struct ipr_cmnd
*ipr_cmd
)
5365 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5368 ioa_cfg
->in_reset_reload
= 0;
5369 ioa_cfg
->reset_retries
= 0;
5370 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
5371 wake_up_all(&ioa_cfg
->reset_wait_q
);
5373 spin_unlock_irq(ioa_cfg
->host
->host_lock
);
5374 scsi_unblock_requests(ioa_cfg
->host
);
5375 spin_lock_irq(ioa_cfg
->host
->host_lock
);
5378 return IPR_RC_JOB_RETURN
;
5382 * ipr_ioa_reset_done - IOA reset completion.
5383 * @ipr_cmd: ipr command struct
5385 * This function processes the completion of an adapter reset.
5386 * It schedules any necessary mid-layer add/removes and
5387 * wakes any reset sleepers.
5392 static int ipr_ioa_reset_done(struct ipr_cmnd
*ipr_cmd
)
5394 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5395 struct ipr_resource_entry
*res
;
5396 struct ipr_hostrcb
*hostrcb
, *temp
;
5400 ioa_cfg
->in_reset_reload
= 0;
5401 ioa_cfg
->allow_cmds
= 1;
5402 ioa_cfg
->reset_cmd
= NULL
;
5403 ioa_cfg
->doorbell
|= IPR_RUNTIME_RESET
;
5405 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
5406 if (ioa_cfg
->allow_ml_add_del
&& (res
->add_to_ml
|| res
->del_from_ml
)) {
5411 schedule_work(&ioa_cfg
->work_q
);
5413 list_for_each_entry_safe(hostrcb
, temp
, &ioa_cfg
->hostrcb_free_q
, queue
) {
5414 list_del(&hostrcb
->queue
);
5415 if (i
++ < IPR_NUM_LOG_HCAMS
)
5416 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_LOG_DATA
, hostrcb
);
5418 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
, hostrcb
);
5421 scsi_report_bus_reset(ioa_cfg
->host
, IPR_VSET_BUS
);
5422 dev_info(&ioa_cfg
->pdev
->dev
, "IOA initialized.\n");
5424 ioa_cfg
->reset_retries
= 0;
5425 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
5426 wake_up_all(&ioa_cfg
->reset_wait_q
);
5428 spin_unlock(ioa_cfg
->host
->host_lock
);
5429 scsi_unblock_requests(ioa_cfg
->host
);
5430 spin_lock(ioa_cfg
->host
->host_lock
);
5432 if (!ioa_cfg
->allow_cmds
)
5433 scsi_block_requests(ioa_cfg
->host
);
5436 return IPR_RC_JOB_RETURN
;
5440 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
5441 * @supported_dev: supported device struct
5442 * @vpids: vendor product id struct
5447 static void ipr_set_sup_dev_dflt(struct ipr_supported_device
*supported_dev
,
5448 struct ipr_std_inq_vpids
*vpids
)
5450 memset(supported_dev
, 0, sizeof(struct ipr_supported_device
));
5451 memcpy(&supported_dev
->vpids
, vpids
, sizeof(struct ipr_std_inq_vpids
));
5452 supported_dev
->num_records
= 1;
5453 supported_dev
->data_length
=
5454 cpu_to_be16(sizeof(struct ipr_supported_device
));
5455 supported_dev
->reserved
= 0;
5459 * ipr_set_supported_devs - Send Set Supported Devices for a device
5460 * @ipr_cmd: ipr command struct
5462 * This function send a Set Supported Devices to the adapter
5465 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5467 static int ipr_set_supported_devs(struct ipr_cmnd
*ipr_cmd
)
5469 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5470 struct ipr_supported_device
*supp_dev
= &ioa_cfg
->vpd_cbs
->supp_dev
;
5471 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->ioadl
;
5472 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5473 struct ipr_resource_entry
*res
= ipr_cmd
->u
.res
;
5475 ipr_cmd
->job_step
= ipr_ioa_reset_done
;
5477 list_for_each_entry_continue(res
, &ioa_cfg
->used_res_q
, queue
) {
5478 if (!ipr_is_scsi_disk(res
))
5481 ipr_cmd
->u
.res
= res
;
5482 ipr_set_sup_dev_dflt(supp_dev
, &res
->cfgte
.std_inq_data
.vpids
);
5484 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
5485 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
5486 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
5488 ioarcb
->cmd_pkt
.cdb
[0] = IPR_SET_SUPPORTED_DEVICES
;
5489 ioarcb
->cmd_pkt
.cdb
[7] = (sizeof(struct ipr_supported_device
) >> 8) & 0xff;
5490 ioarcb
->cmd_pkt
.cdb
[8] = sizeof(struct ipr_supported_device
) & 0xff;
5492 ioadl
->flags_and_data_len
= cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST
|
5493 sizeof(struct ipr_supported_device
));
5494 ioadl
->address
= cpu_to_be32(ioa_cfg
->vpd_cbs_dma
+
5495 offsetof(struct ipr_misc_cbs
, supp_dev
));
5496 ioarcb
->write_ioadl_len
= cpu_to_be32(sizeof(struct ipr_ioadl_desc
));
5497 ioarcb
->write_data_transfer_length
=
5498 cpu_to_be32(sizeof(struct ipr_supported_device
));
5500 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
,
5501 IPR_SET_SUP_DEVICE_TIMEOUT
);
5503 ipr_cmd
->job_step
= ipr_set_supported_devs
;
5504 return IPR_RC_JOB_RETURN
;
5507 return IPR_RC_JOB_CONTINUE
;
5511 * ipr_setup_write_cache - Disable write cache if needed
5512 * @ipr_cmd: ipr command struct
5514 * This function sets up adapters write cache to desired setting
5517 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5519 static int ipr_setup_write_cache(struct ipr_cmnd
*ipr_cmd
)
5521 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5523 ipr_cmd
->job_step
= ipr_set_supported_devs
;
5524 ipr_cmd
->u
.res
= list_entry(ioa_cfg
->used_res_q
.next
,
5525 struct ipr_resource_entry
, queue
);
5527 if (ioa_cfg
->cache_state
!= CACHE_DISABLED
)
5528 return IPR_RC_JOB_CONTINUE
;
5530 ipr_cmd
->ioarcb
.res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
5531 ipr_cmd
->ioarcb
.cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
5532 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0] = IPR_IOA_SHUTDOWN
;
5533 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL
;
5535 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
5537 return IPR_RC_JOB_RETURN
;
5541 * ipr_get_mode_page - Locate specified mode page
5542 * @mode_pages: mode page buffer
5543 * @page_code: page code to find
5544 * @len: minimum required length for mode page
5547 * pointer to mode page / NULL on failure
5549 static void *ipr_get_mode_page(struct ipr_mode_pages
*mode_pages
,
5550 u32 page_code
, u32 len
)
5552 struct ipr_mode_page_hdr
*mode_hdr
;
5556 if (!mode_pages
|| (mode_pages
->hdr
.length
== 0))
5559 length
= (mode_pages
->hdr
.length
+ 1) - 4 - mode_pages
->hdr
.block_desc_len
;
5560 mode_hdr
= (struct ipr_mode_page_hdr
*)
5561 (mode_pages
->data
+ mode_pages
->hdr
.block_desc_len
);
5564 if (IPR_GET_MODE_PAGE_CODE(mode_hdr
) == page_code
) {
5565 if (mode_hdr
->page_length
>= (len
- sizeof(struct ipr_mode_page_hdr
)))
5569 page_length
= (sizeof(struct ipr_mode_page_hdr
) +
5570 mode_hdr
->page_length
);
5571 length
-= page_length
;
5572 mode_hdr
= (struct ipr_mode_page_hdr
*)
5573 ((unsigned long)mode_hdr
+ page_length
);
5580 * ipr_check_term_power - Check for term power errors
5581 * @ioa_cfg: ioa config struct
5582 * @mode_pages: IOAFP mode pages buffer
5584 * Check the IOAFP's mode page 28 for term power errors
5589 static void ipr_check_term_power(struct ipr_ioa_cfg
*ioa_cfg
,
5590 struct ipr_mode_pages
*mode_pages
)
5594 struct ipr_dev_bus_entry
*bus
;
5595 struct ipr_mode_page28
*mode_page
;
5597 mode_page
= ipr_get_mode_page(mode_pages
, 0x28,
5598 sizeof(struct ipr_mode_page28
));
5600 entry_length
= mode_page
->entry_length
;
5602 bus
= mode_page
->bus
;
5604 for (i
= 0; i
< mode_page
->num_entries
; i
++) {
5605 if (bus
->flags
& IPR_SCSI_ATTR_NO_TERM_PWR
) {
5606 dev_err(&ioa_cfg
->pdev
->dev
,
5607 "Term power is absent on scsi bus %d\n",
5611 bus
= (struct ipr_dev_bus_entry
*)((char *)bus
+ entry_length
);
5616 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
5617 * @ioa_cfg: ioa config struct
5619 * Looks through the config table checking for SES devices. If
5620 * the SES device is in the SES table indicating a maximum SCSI
5621 * bus speed, the speed is limited for the bus.
5626 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg
*ioa_cfg
)
5631 for (i
= 0; i
< IPR_MAX_NUM_BUSES
; i
++) {
5632 max_xfer_rate
= ipr_get_max_scsi_speed(ioa_cfg
, i
,
5633 ioa_cfg
->bus_attr
[i
].bus_width
);
5635 if (max_xfer_rate
< ioa_cfg
->bus_attr
[i
].max_xfer_rate
)
5636 ioa_cfg
->bus_attr
[i
].max_xfer_rate
= max_xfer_rate
;
5641 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
5642 * @ioa_cfg: ioa config struct
5643 * @mode_pages: mode page 28 buffer
5645 * Updates mode page 28 based on driver configuration
5650 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg
*ioa_cfg
,
5651 struct ipr_mode_pages
*mode_pages
)
5653 int i
, entry_length
;
5654 struct ipr_dev_bus_entry
*bus
;
5655 struct ipr_bus_attributes
*bus_attr
;
5656 struct ipr_mode_page28
*mode_page
;
5658 mode_page
= ipr_get_mode_page(mode_pages
, 0x28,
5659 sizeof(struct ipr_mode_page28
));
5661 entry_length
= mode_page
->entry_length
;
5663 /* Loop for each device bus entry */
5664 for (i
= 0, bus
= mode_page
->bus
;
5665 i
< mode_page
->num_entries
;
5666 i
++, bus
= (struct ipr_dev_bus_entry
*)((u8
*)bus
+ entry_length
)) {
5667 if (bus
->res_addr
.bus
> IPR_MAX_NUM_BUSES
) {
5668 dev_err(&ioa_cfg
->pdev
->dev
,
5669 "Invalid resource address reported: 0x%08X\n",
5670 IPR_GET_PHYS_LOC(bus
->res_addr
));
5674 bus_attr
= &ioa_cfg
->bus_attr
[i
];
5675 bus
->extended_reset_delay
= IPR_EXTENDED_RESET_DELAY
;
5676 bus
->bus_width
= bus_attr
->bus_width
;
5677 bus
->max_xfer_rate
= cpu_to_be32(bus_attr
->max_xfer_rate
);
5678 bus
->flags
&= ~IPR_SCSI_ATTR_QAS_MASK
;
5679 if (bus_attr
->qas_enabled
)
5680 bus
->flags
|= IPR_SCSI_ATTR_ENABLE_QAS
;
5682 bus
->flags
|= IPR_SCSI_ATTR_DISABLE_QAS
;
5687 * ipr_build_mode_select - Build a mode select command
5688 * @ipr_cmd: ipr command struct
5689 * @res_handle: resource handle to send command to
5690 * @parm: Byte 2 of Mode Sense command
5691 * @dma_addr: DMA buffer address
5692 * @xfer_len: data transfer length
5697 static void ipr_build_mode_select(struct ipr_cmnd
*ipr_cmd
,
5698 __be32 res_handle
, u8 parm
, u32 dma_addr
,
5701 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->ioadl
;
5702 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5704 ioarcb
->res_handle
= res_handle
;
5705 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
5706 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
5707 ioarcb
->cmd_pkt
.cdb
[0] = MODE_SELECT
;
5708 ioarcb
->cmd_pkt
.cdb
[1] = parm
;
5709 ioarcb
->cmd_pkt
.cdb
[4] = xfer_len
;
5711 ioadl
->flags_and_data_len
=
5712 cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST
| xfer_len
);
5713 ioadl
->address
= cpu_to_be32(dma_addr
);
5714 ioarcb
->write_ioadl_len
= cpu_to_be32(sizeof(struct ipr_ioadl_desc
));
5715 ioarcb
->write_data_transfer_length
= cpu_to_be32(xfer_len
);
5719 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
5720 * @ipr_cmd: ipr command struct
5722 * This function sets up the SCSI bus attributes and sends
5723 * a Mode Select for Page 28 to activate them.
5728 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd
*ipr_cmd
)
5730 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5731 struct ipr_mode_pages
*mode_pages
= &ioa_cfg
->vpd_cbs
->mode_pages
;
5735 ipr_scsi_bus_speed_limit(ioa_cfg
);
5736 ipr_check_term_power(ioa_cfg
, mode_pages
);
5737 ipr_modify_ioafp_mode_page_28(ioa_cfg
, mode_pages
);
5738 length
= mode_pages
->hdr
.length
+ 1;
5739 mode_pages
->hdr
.length
= 0;
5741 ipr_build_mode_select(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
), 0x11,
5742 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, mode_pages
),
5745 ipr_cmd
->job_step
= ipr_setup_write_cache
;
5746 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
5749 return IPR_RC_JOB_RETURN
;
5753 * ipr_build_mode_sense - Builds a mode sense command
5754 * @ipr_cmd: ipr command struct
5755 * @res: resource entry struct
5756 * @parm: Byte 2 of mode sense command
5757 * @dma_addr: DMA address of mode sense buffer
5758 * @xfer_len: Size of DMA buffer
5763 static void ipr_build_mode_sense(struct ipr_cmnd
*ipr_cmd
,
5765 u8 parm
, u32 dma_addr
, u8 xfer_len
)
5767 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->ioadl
;
5768 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5770 ioarcb
->res_handle
= res_handle
;
5771 ioarcb
->cmd_pkt
.cdb
[0] = MODE_SENSE
;
5772 ioarcb
->cmd_pkt
.cdb
[2] = parm
;
5773 ioarcb
->cmd_pkt
.cdb
[4] = xfer_len
;
5774 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
5776 ioadl
->flags_and_data_len
=
5777 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST
| xfer_len
);
5778 ioadl
->address
= cpu_to_be32(dma_addr
);
5779 ioarcb
->read_ioadl_len
= cpu_to_be32(sizeof(struct ipr_ioadl_desc
));
5780 ioarcb
->read_data_transfer_length
= cpu_to_be32(xfer_len
);
5784 * ipr_reset_cmd_failed - Handle failure of IOA reset command
5785 * @ipr_cmd: ipr command struct
5787 * This function handles the failure of an IOA bringup command.
5792 static int ipr_reset_cmd_failed(struct ipr_cmnd
*ipr_cmd
)
5794 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5795 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
5797 dev_err(&ioa_cfg
->pdev
->dev
,
5798 "0x%02X failed with IOASC: 0x%08X\n",
5799 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0], ioasc
);
5801 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
5802 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
5803 return IPR_RC_JOB_RETURN
;
5807 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
5808 * @ipr_cmd: ipr command struct
5810 * This function handles the failure of a Mode Sense to the IOAFP.
5811 * Some adapters do not handle all mode pages.
5814 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5816 static int ipr_reset_mode_sense_failed(struct ipr_cmnd
*ipr_cmd
)
5818 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
5820 if (ioasc
== IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT
) {
5821 ipr_cmd
->job_step
= ipr_setup_write_cache
;
5822 return IPR_RC_JOB_CONTINUE
;
5825 return ipr_reset_cmd_failed(ipr_cmd
);
5829 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
5830 * @ipr_cmd: ipr command struct
5832 * This function send a Page 28 mode sense to the IOA to
5833 * retrieve SCSI bus attributes.
5838 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd
*ipr_cmd
)
5840 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5843 ipr_build_mode_sense(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
),
5844 0x28, ioa_cfg
->vpd_cbs_dma
+
5845 offsetof(struct ipr_misc_cbs
, mode_pages
),
5846 sizeof(struct ipr_mode_pages
));
5848 ipr_cmd
->job_step
= ipr_ioafp_mode_select_page28
;
5849 ipr_cmd
->job_step_failed
= ipr_reset_mode_sense_failed
;
5851 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
5854 return IPR_RC_JOB_RETURN
;
5858 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
5859 * @ipr_cmd: ipr command struct
5861 * This function enables dual IOA RAID support if possible.
5866 static int ipr_ioafp_mode_select_page24(struct ipr_cmnd
*ipr_cmd
)
5868 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5869 struct ipr_mode_pages
*mode_pages
= &ioa_cfg
->vpd_cbs
->mode_pages
;
5870 struct ipr_mode_page24
*mode_page
;
5874 mode_page
= ipr_get_mode_page(mode_pages
, 0x24,
5875 sizeof(struct ipr_mode_page24
));
5878 mode_page
->flags
|= IPR_ENABLE_DUAL_IOA_AF
;
5880 length
= mode_pages
->hdr
.length
+ 1;
5881 mode_pages
->hdr
.length
= 0;
5883 ipr_build_mode_select(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
), 0x11,
5884 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, mode_pages
),
5887 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page28
;
5888 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
5891 return IPR_RC_JOB_RETURN
;
5895 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
5896 * @ipr_cmd: ipr command struct
5898 * This function handles the failure of a Mode Sense to the IOAFP.
5899 * Some adapters do not handle all mode pages.
5902 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5904 static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd
*ipr_cmd
)
5906 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
5908 if (ioasc
== IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT
) {
5909 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page28
;
5910 return IPR_RC_JOB_CONTINUE
;
5913 return ipr_reset_cmd_failed(ipr_cmd
);
5917 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
5918 * @ipr_cmd: ipr command struct
5920 * This function send a mode sense to the IOA to retrieve
5921 * the IOA Advanced Function Control mode page.
5926 static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd
*ipr_cmd
)
5928 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5931 ipr_build_mode_sense(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
),
5932 0x24, ioa_cfg
->vpd_cbs_dma
+
5933 offsetof(struct ipr_misc_cbs
, mode_pages
),
5934 sizeof(struct ipr_mode_pages
));
5936 ipr_cmd
->job_step
= ipr_ioafp_mode_select_page24
;
5937 ipr_cmd
->job_step_failed
= ipr_reset_mode_sense_page24_failed
;
5939 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
5942 return IPR_RC_JOB_RETURN
;
5946 * ipr_init_res_table - Initialize the resource table
5947 * @ipr_cmd: ipr command struct
5949 * This function looks through the existing resource table, comparing
5950 * it with the config table. This function will take care of old/new
5951 * devices and schedule adding/removing them from the mid-layer
5955 * IPR_RC_JOB_CONTINUE
5957 static int ipr_init_res_table(struct ipr_cmnd
*ipr_cmd
)
5959 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5960 struct ipr_resource_entry
*res
, *temp
;
5961 struct ipr_config_table_entry
*cfgte
;
5966 if (ioa_cfg
->cfg_table
->hdr
.flags
& IPR_UCODE_DOWNLOAD_REQ
)
5967 dev_err(&ioa_cfg
->pdev
->dev
, "Microcode download required\n");
5969 list_for_each_entry_safe(res
, temp
, &ioa_cfg
->used_res_q
, queue
)
5970 list_move_tail(&res
->queue
, &old_res
);
5972 for (i
= 0; i
< ioa_cfg
->cfg_table
->hdr
.num_entries
; i
++) {
5973 cfgte
= &ioa_cfg
->cfg_table
->dev
[i
];
5976 list_for_each_entry_safe(res
, temp
, &old_res
, queue
) {
5977 if (!memcmp(&res
->cfgte
.res_addr
,
5978 &cfgte
->res_addr
, sizeof(cfgte
->res_addr
))) {
5979 list_move_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
5986 if (list_empty(&ioa_cfg
->free_res_q
)) {
5987 dev_err(&ioa_cfg
->pdev
->dev
, "Too many devices attached\n");
5992 res
= list_entry(ioa_cfg
->free_res_q
.next
,
5993 struct ipr_resource_entry
, queue
);
5994 list_move_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
5995 ipr_init_res_entry(res
);
6000 memcpy(&res
->cfgte
, cfgte
, sizeof(struct ipr_config_table_entry
));
6003 list_for_each_entry_safe(res
, temp
, &old_res
, queue
) {
6005 res
->del_from_ml
= 1;
6006 res
->cfgte
.res_handle
= IPR_INVALID_RES_HANDLE
;
6007 list_move_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
6009 list_move_tail(&res
->queue
, &ioa_cfg
->free_res_q
);
6013 if (ioa_cfg
->dual_raid
&& ipr_dual_ioa_raid
)
6014 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page24
;
6016 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page28
;
6019 return IPR_RC_JOB_CONTINUE
;
6023 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
6024 * @ipr_cmd: ipr command struct
6026 * This function sends a Query IOA Configuration command
6027 * to the adapter to retrieve the IOA configuration table.
6032 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd
*ipr_cmd
)
6034 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6035 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
6036 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->ioadl
;
6037 struct ipr_inquiry_page3
*ucode_vpd
= &ioa_cfg
->vpd_cbs
->page3_data
;
6038 struct ipr_inquiry_cap
*cap
= &ioa_cfg
->vpd_cbs
->cap
;
6041 if (cap
->cap
& IPR_CAP_DUAL_IOA_RAID
)
6042 ioa_cfg
->dual_raid
= 1;
6043 dev_info(&ioa_cfg
->pdev
->dev
, "Adapter firmware version: %02X%02X%02X%02X\n",
6044 ucode_vpd
->major_release
, ucode_vpd
->card_type
,
6045 ucode_vpd
->minor_release
[0], ucode_vpd
->minor_release
[1]);
6046 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
6047 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
6049 ioarcb
->cmd_pkt
.cdb
[0] = IPR_QUERY_IOA_CONFIG
;
6050 ioarcb
->cmd_pkt
.cdb
[7] = (sizeof(struct ipr_config_table
) >> 8) & 0xff;
6051 ioarcb
->cmd_pkt
.cdb
[8] = sizeof(struct ipr_config_table
) & 0xff;
6053 ioarcb
->read_ioadl_len
= cpu_to_be32(sizeof(struct ipr_ioadl_desc
));
6054 ioarcb
->read_data_transfer_length
=
6055 cpu_to_be32(sizeof(struct ipr_config_table
));
6057 ioadl
->address
= cpu_to_be32(ioa_cfg
->cfg_table_dma
);
6058 ioadl
->flags_and_data_len
=
6059 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST
| sizeof(struct ipr_config_table
));
6061 ipr_cmd
->job_step
= ipr_init_res_table
;
6063 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
6066 return IPR_RC_JOB_RETURN
;
6070 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
6071 * @ipr_cmd: ipr command struct
6073 * This utility function sends an inquiry to the adapter.
6078 static void ipr_ioafp_inquiry(struct ipr_cmnd
*ipr_cmd
, u8 flags
, u8 page
,
6079 u32 dma_addr
, u8 xfer_len
)
6081 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
6082 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->ioadl
;
6085 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
6086 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
6088 ioarcb
->cmd_pkt
.cdb
[0] = INQUIRY
;
6089 ioarcb
->cmd_pkt
.cdb
[1] = flags
;
6090 ioarcb
->cmd_pkt
.cdb
[2] = page
;
6091 ioarcb
->cmd_pkt
.cdb
[4] = xfer_len
;
6093 ioarcb
->read_ioadl_len
= cpu_to_be32(sizeof(struct ipr_ioadl_desc
));
6094 ioarcb
->read_data_transfer_length
= cpu_to_be32(xfer_len
);
6096 ioadl
->address
= cpu_to_be32(dma_addr
);
6097 ioadl
->flags_and_data_len
=
6098 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST
| xfer_len
);
6100 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
6105 * ipr_inquiry_page_supported - Is the given inquiry page supported
6106 * @page0: inquiry page 0 buffer
6109 * This function determines if the specified inquiry page is supported.
6112 * 1 if page is supported / 0 if not
6114 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0
*page0
, u8 page
)
6118 for (i
= 0; i
< min_t(u8
, page0
->len
, IPR_INQUIRY_PAGE0_ENTRIES
); i
++)
6119 if (page0
->page
[i
] == page
)
6126 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
6127 * @ipr_cmd: ipr command struct
6129 * This function sends a Page 0xD0 inquiry to the adapter
6130 * to retrieve adapter capabilities.
6133 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6135 static int ipr_ioafp_cap_inquiry(struct ipr_cmnd
*ipr_cmd
)
6137 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6138 struct ipr_inquiry_page0
*page0
= &ioa_cfg
->vpd_cbs
->page0_data
;
6139 struct ipr_inquiry_cap
*cap
= &ioa_cfg
->vpd_cbs
->cap
;
6142 ipr_cmd
->job_step
= ipr_ioafp_query_ioa_cfg
;
6143 memset(cap
, 0, sizeof(*cap
));
6145 if (ipr_inquiry_page_supported(page0
, 0xD0)) {
6146 ipr_ioafp_inquiry(ipr_cmd
, 1, 0xD0,
6147 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, cap
),
6148 sizeof(struct ipr_inquiry_cap
));
6149 return IPR_RC_JOB_RETURN
;
6153 return IPR_RC_JOB_CONTINUE
;
6157 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
6158 * @ipr_cmd: ipr command struct
6160 * This function sends a Page 3 inquiry to the adapter
6161 * to retrieve software VPD information.
6164 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6166 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd
*ipr_cmd
)
6168 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6169 struct ipr_inquiry_page0
*page0
= &ioa_cfg
->vpd_cbs
->page0_data
;
6173 if (!ipr_inquiry_page_supported(page0
, 1))
6174 ioa_cfg
->cache_state
= CACHE_NONE
;
6176 ipr_cmd
->job_step
= ipr_ioafp_cap_inquiry
;
6178 ipr_ioafp_inquiry(ipr_cmd
, 1, 3,
6179 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, page3_data
),
6180 sizeof(struct ipr_inquiry_page3
));
6183 return IPR_RC_JOB_RETURN
;
6187 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
6188 * @ipr_cmd: ipr command struct
6190 * This function sends a Page 0 inquiry to the adapter
6191 * to retrieve supported inquiry pages.
6194 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6196 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd
*ipr_cmd
)
6198 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6203 /* Grab the type out of the VPD and store it away */
6204 memcpy(type
, ioa_cfg
->vpd_cbs
->ioa_vpd
.std_inq_data
.vpids
.product_id
, 4);
6206 ioa_cfg
->type
= simple_strtoul((char *)type
, NULL
, 16);
6208 ipr_cmd
->job_step
= ipr_ioafp_page3_inquiry
;
6210 ipr_ioafp_inquiry(ipr_cmd
, 1, 0,
6211 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, page0_data
),
6212 sizeof(struct ipr_inquiry_page0
));
6215 return IPR_RC_JOB_RETURN
;
6219 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
6220 * @ipr_cmd: ipr command struct
6222 * This function sends a standard inquiry to the adapter.
6227 static int ipr_ioafp_std_inquiry(struct ipr_cmnd
*ipr_cmd
)
6229 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6232 ipr_cmd
->job_step
= ipr_ioafp_page0_inquiry
;
6234 ipr_ioafp_inquiry(ipr_cmd
, 0, 0,
6235 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, ioa_vpd
),
6236 sizeof(struct ipr_ioa_vpd
));
6239 return IPR_RC_JOB_RETURN
;
6243 * ipr_ioafp_indentify_hrrq - Send Identify Host RRQ.
6244 * @ipr_cmd: ipr command struct
6246 * This function send an Identify Host Request Response Queue
6247 * command to establish the HRRQ with the adapter.
6252 static int ipr_ioafp_indentify_hrrq(struct ipr_cmnd
*ipr_cmd
)
6254 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6255 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
6258 dev_info(&ioa_cfg
->pdev
->dev
, "Starting IOA initialization sequence.\n");
6260 ioarcb
->cmd_pkt
.cdb
[0] = IPR_ID_HOST_RR_Q
;
6261 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
6263 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
6264 ioarcb
->cmd_pkt
.cdb
[2] =
6265 ((u32
) ioa_cfg
->host_rrq_dma
>> 24) & 0xff;
6266 ioarcb
->cmd_pkt
.cdb
[3] =
6267 ((u32
) ioa_cfg
->host_rrq_dma
>> 16) & 0xff;
6268 ioarcb
->cmd_pkt
.cdb
[4] =
6269 ((u32
) ioa_cfg
->host_rrq_dma
>> 8) & 0xff;
6270 ioarcb
->cmd_pkt
.cdb
[5] =
6271 ((u32
) ioa_cfg
->host_rrq_dma
) & 0xff;
6272 ioarcb
->cmd_pkt
.cdb
[7] =
6273 ((sizeof(u32
) * IPR_NUM_CMD_BLKS
) >> 8) & 0xff;
6274 ioarcb
->cmd_pkt
.cdb
[8] =
6275 (sizeof(u32
) * IPR_NUM_CMD_BLKS
) & 0xff;
6277 ipr_cmd
->job_step
= ipr_ioafp_std_inquiry
;
6279 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
6282 return IPR_RC_JOB_RETURN
;
6286 * ipr_reset_timer_done - Adapter reset timer function
6287 * @ipr_cmd: ipr command struct
6289 * Description: This function is used in adapter reset processing
6290 * for timing events. If the reset_cmd pointer in the IOA
6291 * config struct is not this adapter's we are doing nested
6292 * resets and fail_all_ops will take care of freeing the
6298 static void ipr_reset_timer_done(struct ipr_cmnd
*ipr_cmd
)
6300 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6301 unsigned long lock_flags
= 0;
6303 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
6305 if (ioa_cfg
->reset_cmd
== ipr_cmd
) {
6306 list_del(&ipr_cmd
->queue
);
6307 ipr_cmd
->done(ipr_cmd
);
6310 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
6314 * ipr_reset_start_timer - Start a timer for adapter reset job
6315 * @ipr_cmd: ipr command struct
6316 * @timeout: timeout value
6318 * Description: This function is used in adapter reset processing
6319 * for timing events. If the reset_cmd pointer in the IOA
6320 * config struct is not this adapter's we are doing nested
6321 * resets and fail_all_ops will take care of freeing the
6327 static void ipr_reset_start_timer(struct ipr_cmnd
*ipr_cmd
,
6328 unsigned long timeout
)
6330 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->ioa_cfg
->pending_q
);
6331 ipr_cmd
->done
= ipr_reset_ioa_job
;
6333 ipr_cmd
->timer
.data
= (unsigned long) ipr_cmd
;
6334 ipr_cmd
->timer
.expires
= jiffies
+ timeout
;
6335 ipr_cmd
->timer
.function
= (void (*)(unsigned long))ipr_reset_timer_done
;
6336 add_timer(&ipr_cmd
->timer
);
6340 * ipr_init_ioa_mem - Initialize ioa_cfg control block
6341 * @ioa_cfg: ioa cfg struct
6346 static void ipr_init_ioa_mem(struct ipr_ioa_cfg
*ioa_cfg
)
6348 memset(ioa_cfg
->host_rrq
, 0, sizeof(u32
) * IPR_NUM_CMD_BLKS
);
6350 /* Initialize Host RRQ pointers */
6351 ioa_cfg
->hrrq_start
= ioa_cfg
->host_rrq
;
6352 ioa_cfg
->hrrq_end
= &ioa_cfg
->host_rrq
[IPR_NUM_CMD_BLKS
- 1];
6353 ioa_cfg
->hrrq_curr
= ioa_cfg
->hrrq_start
;
6354 ioa_cfg
->toggle_bit
= 1;
6356 /* Zero out config table */
6357 memset(ioa_cfg
->cfg_table
, 0, sizeof(struct ipr_config_table
));
6361 * ipr_reset_enable_ioa - Enable the IOA following a reset.
6362 * @ipr_cmd: ipr command struct
6364 * This function reinitializes some control blocks and
6365 * enables destructive diagnostics on the adapter.
6370 static int ipr_reset_enable_ioa(struct ipr_cmnd
*ipr_cmd
)
6372 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6373 volatile u32 int_reg
;
6376 ipr_cmd
->job_step
= ipr_ioafp_indentify_hrrq
;
6377 ipr_init_ioa_mem(ioa_cfg
);
6379 ioa_cfg
->allow_interrupts
= 1;
6380 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
6382 if (int_reg
& IPR_PCII_IOA_TRANS_TO_OPER
) {
6383 writel((IPR_PCII_ERROR_INTERRUPTS
| IPR_PCII_HRRQ_UPDATED
),
6384 ioa_cfg
->regs
.clr_interrupt_mask_reg
);
6385 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
6386 return IPR_RC_JOB_CONTINUE
;
6389 /* Enable destructive diagnostics on IOA */
6390 writel(ioa_cfg
->doorbell
, ioa_cfg
->regs
.set_uproc_interrupt_reg
);
6392 writel(IPR_PCII_OPER_INTERRUPTS
, ioa_cfg
->regs
.clr_interrupt_mask_reg
);
6393 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
6395 dev_info(&ioa_cfg
->pdev
->dev
, "Initializing IOA.\n");
6397 ipr_cmd
->timer
.data
= (unsigned long) ipr_cmd
;
6398 ipr_cmd
->timer
.expires
= jiffies
+ (ioa_cfg
->transop_timeout
* HZ
);
6399 ipr_cmd
->timer
.function
= (void (*)(unsigned long))ipr_oper_timeout
;
6400 ipr_cmd
->done
= ipr_reset_ioa_job
;
6401 add_timer(&ipr_cmd
->timer
);
6402 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->pending_q
);
6405 return IPR_RC_JOB_RETURN
;
6409 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
6410 * @ipr_cmd: ipr command struct
6412 * This function is invoked when an adapter dump has run out
6413 * of processing time.
6416 * IPR_RC_JOB_CONTINUE
6418 static int ipr_reset_wait_for_dump(struct ipr_cmnd
*ipr_cmd
)
6420 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6422 if (ioa_cfg
->sdt_state
== GET_DUMP
)
6423 ioa_cfg
->sdt_state
= ABORT_DUMP
;
6425 ipr_cmd
->job_step
= ipr_reset_alert
;
6427 return IPR_RC_JOB_CONTINUE
;
6431 * ipr_unit_check_no_data - Log a unit check/no data error log
6432 * @ioa_cfg: ioa config struct
6434 * Logs an error indicating the adapter unit checked, but for some
6435 * reason, we were unable to fetch the unit check buffer.
6440 static void ipr_unit_check_no_data(struct ipr_ioa_cfg
*ioa_cfg
)
6442 ioa_cfg
->errors_logged
++;
6443 dev_err(&ioa_cfg
->pdev
->dev
, "IOA unit check with no data\n");
6447 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
6448 * @ioa_cfg: ioa config struct
6450 * Fetches the unit check buffer from the adapter by clocking the data
6451 * through the mailbox register.
6456 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg
*ioa_cfg
)
6458 unsigned long mailbox
;
6459 struct ipr_hostrcb
*hostrcb
;
6460 struct ipr_uc_sdt sdt
;
6464 mailbox
= readl(ioa_cfg
->ioa_mailbox
);
6466 if (!ipr_sdt_is_fmt2(mailbox
)) {
6467 ipr_unit_check_no_data(ioa_cfg
);
6471 memset(&sdt
, 0, sizeof(struct ipr_uc_sdt
));
6472 rc
= ipr_get_ldump_data_section(ioa_cfg
, mailbox
, (__be32
*) &sdt
,
6473 (sizeof(struct ipr_uc_sdt
)) / sizeof(__be32
));
6475 if (rc
|| (be32_to_cpu(sdt
.hdr
.state
) != IPR_FMT2_SDT_READY_TO_USE
) ||
6476 !(sdt
.entry
[0].flags
& IPR_SDT_VALID_ENTRY
)) {
6477 ipr_unit_check_no_data(ioa_cfg
);
6481 /* Find length of the first sdt entry (UC buffer) */
6482 length
= (be32_to_cpu(sdt
.entry
[0].end_offset
) -
6483 be32_to_cpu(sdt
.entry
[0].bar_str_offset
)) & IPR_FMT2_MBX_ADDR_MASK
;
6485 hostrcb
= list_entry(ioa_cfg
->hostrcb_free_q
.next
,
6486 struct ipr_hostrcb
, queue
);
6487 list_del(&hostrcb
->queue
);
6488 memset(&hostrcb
->hcam
, 0, sizeof(hostrcb
->hcam
));
6490 rc
= ipr_get_ldump_data_section(ioa_cfg
,
6491 be32_to_cpu(sdt
.entry
[0].bar_str_offset
),
6492 (__be32
*)&hostrcb
->hcam
,
6493 min(length
, (int)sizeof(hostrcb
->hcam
)) / sizeof(__be32
));
6496 ipr_handle_log_data(ioa_cfg
, hostrcb
);
6497 ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error
.failing_dev_ioasc
);
6498 if (ioasc
== IPR_IOASC_NR_IOA_RESET_REQUIRED
&&
6499 ioa_cfg
->sdt_state
== GET_DUMP
)
6500 ioa_cfg
->sdt_state
= WAIT_FOR_DUMP
;
6502 ipr_unit_check_no_data(ioa_cfg
);
6504 list_add_tail(&hostrcb
->queue
, &ioa_cfg
->hostrcb_free_q
);
6508 * ipr_reset_restore_cfg_space - Restore PCI config space.
6509 * @ipr_cmd: ipr command struct
6511 * Description: This function restores the saved PCI config space of
6512 * the adapter, fails all outstanding ops back to the callers, and
6513 * fetches the dump/unit check if applicable to this reset.
6516 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6518 static int ipr_reset_restore_cfg_space(struct ipr_cmnd
*ipr_cmd
)
6520 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6524 ioa_cfg
->pdev
->state_saved
= true;
6525 rc
= pci_restore_state(ioa_cfg
->pdev
);
6527 if (rc
!= PCIBIOS_SUCCESSFUL
) {
6528 ipr_cmd
->ioasa
.ioasc
= cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR
);
6529 return IPR_RC_JOB_CONTINUE
;
6532 if (ipr_set_pcix_cmd_reg(ioa_cfg
)) {
6533 ipr_cmd
->ioasa
.ioasc
= cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR
);
6534 return IPR_RC_JOB_CONTINUE
;
6537 ipr_fail_all_ops(ioa_cfg
);
6539 if (ioa_cfg
->ioa_unit_checked
) {
6540 ioa_cfg
->ioa_unit_checked
= 0;
6541 ipr_get_unit_check_buffer(ioa_cfg
);
6542 ipr_cmd
->job_step
= ipr_reset_alert
;
6543 ipr_reset_start_timer(ipr_cmd
, 0);
6544 return IPR_RC_JOB_RETURN
;
6547 if (ioa_cfg
->in_ioa_bringdown
) {
6548 ipr_cmd
->job_step
= ipr_ioa_bringdown_done
;
6550 ipr_cmd
->job_step
= ipr_reset_enable_ioa
;
6552 if (GET_DUMP
== ioa_cfg
->sdt_state
) {
6553 ipr_reset_start_timer(ipr_cmd
, IPR_DUMP_TIMEOUT
);
6554 ipr_cmd
->job_step
= ipr_reset_wait_for_dump
;
6555 schedule_work(&ioa_cfg
->work_q
);
6556 return IPR_RC_JOB_RETURN
;
6561 return IPR_RC_JOB_CONTINUE
;
6565 * ipr_reset_bist_done - BIST has completed on the adapter.
6566 * @ipr_cmd: ipr command struct
6568 * Description: Unblock config space and resume the reset process.
6571 * IPR_RC_JOB_CONTINUE
6573 static int ipr_reset_bist_done(struct ipr_cmnd
*ipr_cmd
)
6576 pci_unblock_user_cfg_access(ipr_cmd
->ioa_cfg
->pdev
);
6577 ipr_cmd
->job_step
= ipr_reset_restore_cfg_space
;
6579 return IPR_RC_JOB_CONTINUE
;
6583 * ipr_reset_start_bist - Run BIST on the adapter.
6584 * @ipr_cmd: ipr command struct
6586 * Description: This function runs BIST on the adapter, then delays 2 seconds.
6589 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6591 static int ipr_reset_start_bist(struct ipr_cmnd
*ipr_cmd
)
6593 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6597 pci_block_user_cfg_access(ioa_cfg
->pdev
);
6598 rc
= pci_write_config_byte(ioa_cfg
->pdev
, PCI_BIST
, PCI_BIST_START
);
6600 if (rc
!= PCIBIOS_SUCCESSFUL
) {
6601 pci_unblock_user_cfg_access(ipr_cmd
->ioa_cfg
->pdev
);
6602 ipr_cmd
->ioasa
.ioasc
= cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR
);
6603 rc
= IPR_RC_JOB_CONTINUE
;
6605 ipr_cmd
->job_step
= ipr_reset_bist_done
;
6606 ipr_reset_start_timer(ipr_cmd
, IPR_WAIT_FOR_BIST_TIMEOUT
);
6607 rc
= IPR_RC_JOB_RETURN
;
6615 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
6616 * @ipr_cmd: ipr command struct
6618 * Description: This clears PCI reset to the adapter and delays two seconds.
6623 static int ipr_reset_slot_reset_done(struct ipr_cmnd
*ipr_cmd
)
6626 pci_set_pcie_reset_state(ipr_cmd
->ioa_cfg
->pdev
, pcie_deassert_reset
);
6627 ipr_cmd
->job_step
= ipr_reset_bist_done
;
6628 ipr_reset_start_timer(ipr_cmd
, IPR_WAIT_FOR_BIST_TIMEOUT
);
6630 return IPR_RC_JOB_RETURN
;
6634 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
6635 * @ipr_cmd: ipr command struct
6637 * Description: This asserts PCI reset to the adapter.
6642 static int ipr_reset_slot_reset(struct ipr_cmnd
*ipr_cmd
)
6644 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6645 struct pci_dev
*pdev
= ioa_cfg
->pdev
;
6648 pci_block_user_cfg_access(pdev
);
6649 pci_set_pcie_reset_state(pdev
, pcie_warm_reset
);
6650 ipr_cmd
->job_step
= ipr_reset_slot_reset_done
;
6651 ipr_reset_start_timer(ipr_cmd
, IPR_PCI_RESET_TIMEOUT
);
6653 return IPR_RC_JOB_RETURN
;
6657 * ipr_reset_allowed - Query whether or not IOA can be reset
6658 * @ioa_cfg: ioa config struct
6661 * 0 if reset not allowed / non-zero if reset is allowed
6663 static int ipr_reset_allowed(struct ipr_ioa_cfg
*ioa_cfg
)
6665 volatile u32 temp_reg
;
6667 temp_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
6668 return ((temp_reg
& IPR_PCII_CRITICAL_OPERATION
) == 0);
6672 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
6673 * @ipr_cmd: ipr command struct
6675 * Description: This function waits for adapter permission to run BIST,
6676 * then runs BIST. If the adapter does not give permission after a
6677 * reasonable time, we will reset the adapter anyway. The impact of
6678 * resetting the adapter without warning the adapter is the risk of
6679 * losing the persistent error log on the adapter. If the adapter is
6680 * reset while it is writing to the flash on the adapter, the flash
6681 * segment will have bad ECC and be zeroed.
6684 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6686 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd
*ipr_cmd
)
6688 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6689 int rc
= IPR_RC_JOB_RETURN
;
6691 if (!ipr_reset_allowed(ioa_cfg
) && ipr_cmd
->u
.time_left
) {
6692 ipr_cmd
->u
.time_left
-= IPR_CHECK_FOR_RESET_TIMEOUT
;
6693 ipr_reset_start_timer(ipr_cmd
, IPR_CHECK_FOR_RESET_TIMEOUT
);
6695 ipr_cmd
->job_step
= ioa_cfg
->reset
;
6696 rc
= IPR_RC_JOB_CONTINUE
;
6703 * ipr_reset_alert_part2 - Alert the adapter of a pending reset
6704 * @ipr_cmd: ipr command struct
6706 * Description: This function alerts the adapter that it will be reset.
6707 * If memory space is not currently enabled, proceed directly
6708 * to running BIST on the adapter. The timer must always be started
6709 * so we guarantee we do not run BIST from ipr_isr.
6714 static int ipr_reset_alert(struct ipr_cmnd
*ipr_cmd
)
6716 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6721 rc
= pci_read_config_word(ioa_cfg
->pdev
, PCI_COMMAND
, &cmd_reg
);
6723 if ((rc
== PCIBIOS_SUCCESSFUL
) && (cmd_reg
& PCI_COMMAND_MEMORY
)) {
6724 ipr_mask_and_clear_interrupts(ioa_cfg
, ~0);
6725 writel(IPR_UPROCI_RESET_ALERT
, ioa_cfg
->regs
.set_uproc_interrupt_reg
);
6726 ipr_cmd
->job_step
= ipr_reset_wait_to_start_bist
;
6728 ipr_cmd
->job_step
= ioa_cfg
->reset
;
6731 ipr_cmd
->u
.time_left
= IPR_WAIT_FOR_RESET_TIMEOUT
;
6732 ipr_reset_start_timer(ipr_cmd
, IPR_CHECK_FOR_RESET_TIMEOUT
);
6735 return IPR_RC_JOB_RETURN
;
6739 * ipr_reset_ucode_download_done - Microcode download completion
6740 * @ipr_cmd: ipr command struct
6742 * Description: This function unmaps the microcode download buffer.
6745 * IPR_RC_JOB_CONTINUE
6747 static int ipr_reset_ucode_download_done(struct ipr_cmnd
*ipr_cmd
)
6749 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6750 struct ipr_sglist
*sglist
= ioa_cfg
->ucode_sglist
;
6752 pci_unmap_sg(ioa_cfg
->pdev
, sglist
->scatterlist
,
6753 sglist
->num_sg
, DMA_TO_DEVICE
);
6755 ipr_cmd
->job_step
= ipr_reset_alert
;
6756 return IPR_RC_JOB_CONTINUE
;
6760 * ipr_reset_ucode_download - Download microcode to the adapter
6761 * @ipr_cmd: ipr command struct
6763 * Description: This function checks to see if it there is microcode
6764 * to download to the adapter. If there is, a download is performed.
6767 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6769 static int ipr_reset_ucode_download(struct ipr_cmnd
*ipr_cmd
)
6771 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6772 struct ipr_sglist
*sglist
= ioa_cfg
->ucode_sglist
;
6775 ipr_cmd
->job_step
= ipr_reset_alert
;
6778 return IPR_RC_JOB_CONTINUE
;
6780 ipr_cmd
->ioarcb
.res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
6781 ipr_cmd
->ioarcb
.cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
6782 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0] = WRITE_BUFFER
;
6783 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE
;
6784 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[6] = (sglist
->buffer_len
& 0xff0000) >> 16;
6785 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[7] = (sglist
->buffer_len
& 0x00ff00) >> 8;
6786 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[8] = sglist
->buffer_len
& 0x0000ff;
6788 ipr_build_ucode_ioadl(ipr_cmd
, sglist
);
6789 ipr_cmd
->job_step
= ipr_reset_ucode_download_done
;
6791 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
,
6792 IPR_WRITE_BUFFER_TIMEOUT
);
6795 return IPR_RC_JOB_RETURN
;
6799 * ipr_reset_shutdown_ioa - Shutdown the adapter
6800 * @ipr_cmd: ipr command struct
6802 * Description: This function issues an adapter shutdown of the
6803 * specified type to the specified adapter as part of the
6804 * adapter reset job.
6807 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6809 static int ipr_reset_shutdown_ioa(struct ipr_cmnd
*ipr_cmd
)
6811 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6812 enum ipr_shutdown_type shutdown_type
= ipr_cmd
->u
.shutdown_type
;
6813 unsigned long timeout
;
6814 int rc
= IPR_RC_JOB_CONTINUE
;
6817 if (shutdown_type
!= IPR_SHUTDOWN_NONE
&& !ioa_cfg
->ioa_is_dead
) {
6818 ipr_cmd
->ioarcb
.res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
6819 ipr_cmd
->ioarcb
.cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
6820 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0] = IPR_IOA_SHUTDOWN
;
6821 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[1] = shutdown_type
;
6823 if (shutdown_type
== IPR_SHUTDOWN_NORMAL
)
6824 timeout
= IPR_SHUTDOWN_TIMEOUT
;
6825 else if (shutdown_type
== IPR_SHUTDOWN_PREPARE_FOR_NORMAL
)
6826 timeout
= IPR_INTERNAL_TIMEOUT
;
6827 else if (ioa_cfg
->dual_raid
&& ipr_dual_ioa_raid
)
6828 timeout
= IPR_DUAL_IOA_ABBR_SHUTDOWN_TO
;
6830 timeout
= IPR_ABBREV_SHUTDOWN_TIMEOUT
;
6832 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, timeout
);
6834 rc
= IPR_RC_JOB_RETURN
;
6835 ipr_cmd
->job_step
= ipr_reset_ucode_download
;
6837 ipr_cmd
->job_step
= ipr_reset_alert
;
6844 * ipr_reset_ioa_job - Adapter reset job
6845 * @ipr_cmd: ipr command struct
6847 * Description: This function is the job router for the adapter reset job.
6852 static void ipr_reset_ioa_job(struct ipr_cmnd
*ipr_cmd
)
6855 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6858 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
6860 if (ioa_cfg
->reset_cmd
!= ipr_cmd
) {
6862 * We are doing nested adapter resets and this is
6863 * not the current reset job.
6865 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
6869 if (IPR_IOASC_SENSE_KEY(ioasc
)) {
6870 rc
= ipr_cmd
->job_step_failed(ipr_cmd
);
6871 if (rc
== IPR_RC_JOB_RETURN
)
6875 ipr_reinit_ipr_cmnd(ipr_cmd
);
6876 ipr_cmd
->job_step_failed
= ipr_reset_cmd_failed
;
6877 rc
= ipr_cmd
->job_step(ipr_cmd
);
6878 } while(rc
== IPR_RC_JOB_CONTINUE
);
6882 * _ipr_initiate_ioa_reset - Initiate an adapter reset
6883 * @ioa_cfg: ioa config struct
6884 * @job_step: first job step of reset job
6885 * @shutdown_type: shutdown type
6887 * Description: This function will initiate the reset of the given adapter
6888 * starting at the selected job step.
6889 * If the caller needs to wait on the completion of the reset,
6890 * the caller must sleep on the reset_wait_q.
6895 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg
*ioa_cfg
,
6896 int (*job_step
) (struct ipr_cmnd
*),
6897 enum ipr_shutdown_type shutdown_type
)
6899 struct ipr_cmnd
*ipr_cmd
;
6901 ioa_cfg
->in_reset_reload
= 1;
6902 ioa_cfg
->allow_cmds
= 0;
6903 scsi_block_requests(ioa_cfg
->host
);
6905 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
6906 ioa_cfg
->reset_cmd
= ipr_cmd
;
6907 ipr_cmd
->job_step
= job_step
;
6908 ipr_cmd
->u
.shutdown_type
= shutdown_type
;
6910 ipr_reset_ioa_job(ipr_cmd
);
6914 * ipr_initiate_ioa_reset - Initiate an adapter reset
6915 * @ioa_cfg: ioa config struct
6916 * @shutdown_type: shutdown type
6918 * Description: This function will initiate the reset of the given adapter.
6919 * If the caller needs to wait on the completion of the reset,
6920 * the caller must sleep on the reset_wait_q.
6925 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg
*ioa_cfg
,
6926 enum ipr_shutdown_type shutdown_type
)
6928 if (ioa_cfg
->ioa_is_dead
)
6931 if (ioa_cfg
->in_reset_reload
&& ioa_cfg
->sdt_state
== GET_DUMP
)
6932 ioa_cfg
->sdt_state
= ABORT_DUMP
;
6934 if (ioa_cfg
->reset_retries
++ >= IPR_NUM_RESET_RELOAD_RETRIES
) {
6935 dev_err(&ioa_cfg
->pdev
->dev
,
6936 "IOA taken offline - error recovery failed\n");
6938 ioa_cfg
->reset_retries
= 0;
6939 ioa_cfg
->ioa_is_dead
= 1;
6941 if (ioa_cfg
->in_ioa_bringdown
) {
6942 ioa_cfg
->reset_cmd
= NULL
;
6943 ioa_cfg
->in_reset_reload
= 0;
6944 ipr_fail_all_ops(ioa_cfg
);
6945 wake_up_all(&ioa_cfg
->reset_wait_q
);
6947 spin_unlock_irq(ioa_cfg
->host
->host_lock
);
6948 scsi_unblock_requests(ioa_cfg
->host
);
6949 spin_lock_irq(ioa_cfg
->host
->host_lock
);
6952 ioa_cfg
->in_ioa_bringdown
= 1;
6953 shutdown_type
= IPR_SHUTDOWN_NONE
;
6957 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_shutdown_ioa
,
6962 * ipr_reset_freeze - Hold off all I/O activity
6963 * @ipr_cmd: ipr command struct
6965 * Description: If the PCI slot is frozen, hold off all I/O
6966 * activity; then, as soon as the slot is available again,
6967 * initiate an adapter reset.
6969 static int ipr_reset_freeze(struct ipr_cmnd
*ipr_cmd
)
6971 /* Disallow new interrupts, avoid loop */
6972 ipr_cmd
->ioa_cfg
->allow_interrupts
= 0;
6973 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->ioa_cfg
->pending_q
);
6974 ipr_cmd
->done
= ipr_reset_ioa_job
;
6975 return IPR_RC_JOB_RETURN
;
6979 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
6980 * @pdev: PCI device struct
6982 * Description: This routine is called to tell us that the PCI bus
6983 * is down. Can't do anything here, except put the device driver
6984 * into a holding pattern, waiting for the PCI bus to come back.
6986 static void ipr_pci_frozen(struct pci_dev
*pdev
)
6988 unsigned long flags
= 0;
6989 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
6991 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
6992 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_freeze
, IPR_SHUTDOWN_NONE
);
6993 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
6997 * ipr_pci_slot_reset - Called when PCI slot has been reset.
6998 * @pdev: PCI device struct
7000 * Description: This routine is called by the pci error recovery
7001 * code after the PCI slot has been reset, just before we
7002 * should resume normal operations.
7004 static pci_ers_result_t
ipr_pci_slot_reset(struct pci_dev
*pdev
)
7006 unsigned long flags
= 0;
7007 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
7009 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
7010 if (ioa_cfg
->needs_warm_reset
)
7011 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
7013 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_restore_cfg_space
,
7015 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
7016 return PCI_ERS_RESULT_RECOVERED
;
7020 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
7021 * @pdev: PCI device struct
7023 * Description: This routine is called when the PCI bus has
7024 * permanently failed.
7026 static void ipr_pci_perm_failure(struct pci_dev
*pdev
)
7028 unsigned long flags
= 0;
7029 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
7031 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
7032 if (ioa_cfg
->sdt_state
== WAIT_FOR_DUMP
)
7033 ioa_cfg
->sdt_state
= ABORT_DUMP
;
7034 ioa_cfg
->reset_retries
= IPR_NUM_RESET_RELOAD_RETRIES
;
7035 ioa_cfg
->in_ioa_bringdown
= 1;
7036 ioa_cfg
->allow_cmds
= 0;
7037 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
7038 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
7042 * ipr_pci_error_detected - Called when a PCI error is detected.
7043 * @pdev: PCI device struct
7044 * @state: PCI channel state
7046 * Description: Called when a PCI error is detected.
7049 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7051 static pci_ers_result_t
ipr_pci_error_detected(struct pci_dev
*pdev
,
7052 pci_channel_state_t state
)
7055 case pci_channel_io_frozen
:
7056 ipr_pci_frozen(pdev
);
7057 return PCI_ERS_RESULT_NEED_RESET
;
7058 case pci_channel_io_perm_failure
:
7059 ipr_pci_perm_failure(pdev
);
7060 return PCI_ERS_RESULT_DISCONNECT
;
7065 return PCI_ERS_RESULT_NEED_RESET
;
7069 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
7070 * @ioa_cfg: ioa cfg struct
7072 * Description: This is the second phase of adapter intialization
7073 * This function takes care of initilizing the adapter to the point
7074 * where it can accept new commands.
7077 * 0 on success / -EIO on failure
7079 static int __devinit
ipr_probe_ioa_part2(struct ipr_ioa_cfg
*ioa_cfg
)
7082 unsigned long host_lock_flags
= 0;
7085 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7086 dev_dbg(&ioa_cfg
->pdev
->dev
, "ioa_cfg adx: 0x%p\n", ioa_cfg
);
7087 if (ioa_cfg
->needs_hard_reset
) {
7088 ioa_cfg
->needs_hard_reset
= 0;
7089 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
7091 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_enable_ioa
,
7094 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7095 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
7096 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7098 if (ioa_cfg
->ioa_is_dead
) {
7100 } else if (ipr_invalid_adapter(ioa_cfg
)) {
7104 dev_err(&ioa_cfg
->pdev
->dev
,
7105 "Adapter not supported in this hardware configuration.\n");
7108 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7115 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
7116 * @ioa_cfg: ioa config struct
7121 static void ipr_free_cmd_blks(struct ipr_ioa_cfg
*ioa_cfg
)
7125 for (i
= 0; i
< IPR_NUM_CMD_BLKS
; i
++) {
7126 if (ioa_cfg
->ipr_cmnd_list
[i
])
7127 pci_pool_free(ioa_cfg
->ipr_cmd_pool
,
7128 ioa_cfg
->ipr_cmnd_list
[i
],
7129 ioa_cfg
->ipr_cmnd_list_dma
[i
]);
7131 ioa_cfg
->ipr_cmnd_list
[i
] = NULL
;
7134 if (ioa_cfg
->ipr_cmd_pool
)
7135 pci_pool_destroy (ioa_cfg
->ipr_cmd_pool
);
7137 ioa_cfg
->ipr_cmd_pool
= NULL
;
7141 * ipr_free_mem - Frees memory allocated for an adapter
7142 * @ioa_cfg: ioa cfg struct
7147 static void ipr_free_mem(struct ipr_ioa_cfg
*ioa_cfg
)
7151 kfree(ioa_cfg
->res_entries
);
7152 pci_free_consistent(ioa_cfg
->pdev
, sizeof(struct ipr_misc_cbs
),
7153 ioa_cfg
->vpd_cbs
, ioa_cfg
->vpd_cbs_dma
);
7154 ipr_free_cmd_blks(ioa_cfg
);
7155 pci_free_consistent(ioa_cfg
->pdev
, sizeof(u32
) * IPR_NUM_CMD_BLKS
,
7156 ioa_cfg
->host_rrq
, ioa_cfg
->host_rrq_dma
);
7157 pci_free_consistent(ioa_cfg
->pdev
, sizeof(struct ipr_config_table
),
7159 ioa_cfg
->cfg_table_dma
);
7161 for (i
= 0; i
< IPR_NUM_HCAMS
; i
++) {
7162 pci_free_consistent(ioa_cfg
->pdev
,
7163 sizeof(struct ipr_hostrcb
),
7164 ioa_cfg
->hostrcb
[i
],
7165 ioa_cfg
->hostrcb_dma
[i
]);
7168 ipr_free_dump(ioa_cfg
);
7169 kfree(ioa_cfg
->trace
);
7173 * ipr_free_all_resources - Free all allocated resources for an adapter.
7174 * @ipr_cmd: ipr command struct
7176 * This function frees all allocated resources for the
7177 * specified adapter.
7182 static void ipr_free_all_resources(struct ipr_ioa_cfg
*ioa_cfg
)
7184 struct pci_dev
*pdev
= ioa_cfg
->pdev
;
7187 free_irq(pdev
->irq
, ioa_cfg
);
7188 pci_disable_msi(pdev
);
7189 iounmap(ioa_cfg
->hdw_dma_regs
);
7190 pci_release_regions(pdev
);
7191 ipr_free_mem(ioa_cfg
);
7192 scsi_host_put(ioa_cfg
->host
);
7193 pci_disable_device(pdev
);
7198 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
7199 * @ioa_cfg: ioa config struct
7202 * 0 on success / -ENOMEM on allocation failure
7204 static int __devinit
ipr_alloc_cmd_blks(struct ipr_ioa_cfg
*ioa_cfg
)
7206 struct ipr_cmnd
*ipr_cmd
;
7207 struct ipr_ioarcb
*ioarcb
;
7208 dma_addr_t dma_addr
;
7211 ioa_cfg
->ipr_cmd_pool
= pci_pool_create (IPR_NAME
, ioa_cfg
->pdev
,
7212 sizeof(struct ipr_cmnd
), 8, 0);
7214 if (!ioa_cfg
->ipr_cmd_pool
)
7217 for (i
= 0; i
< IPR_NUM_CMD_BLKS
; i
++) {
7218 ipr_cmd
= pci_pool_alloc (ioa_cfg
->ipr_cmd_pool
, GFP_KERNEL
, &dma_addr
);
7221 ipr_free_cmd_blks(ioa_cfg
);
7225 memset(ipr_cmd
, 0, sizeof(*ipr_cmd
));
7226 ioa_cfg
->ipr_cmnd_list
[i
] = ipr_cmd
;
7227 ioa_cfg
->ipr_cmnd_list_dma
[i
] = dma_addr
;
7229 ioarcb
= &ipr_cmd
->ioarcb
;
7230 ioarcb
->ioarcb_host_pci_addr
= cpu_to_be32(dma_addr
);
7231 ioarcb
->host_response_handle
= cpu_to_be32(i
<< 2);
7232 ioarcb
->write_ioadl_addr
=
7233 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, ioadl
));
7234 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
7235 ioarcb
->ioasa_host_pci_addr
=
7236 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, ioasa
));
7237 ioarcb
->ioasa_len
= cpu_to_be16(sizeof(struct ipr_ioasa
));
7238 ipr_cmd
->cmd_index
= i
;
7239 ipr_cmd
->ioa_cfg
= ioa_cfg
;
7240 ipr_cmd
->sense_buffer_dma
= dma_addr
+
7241 offsetof(struct ipr_cmnd
, sense_buffer
);
7243 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
7250 * ipr_alloc_mem - Allocate memory for an adapter
7251 * @ioa_cfg: ioa config struct
7254 * 0 on success / non-zero for error
7256 static int __devinit
ipr_alloc_mem(struct ipr_ioa_cfg
*ioa_cfg
)
7258 struct pci_dev
*pdev
= ioa_cfg
->pdev
;
7259 int i
, rc
= -ENOMEM
;
7262 ioa_cfg
->res_entries
= kzalloc(sizeof(struct ipr_resource_entry
) *
7263 IPR_MAX_PHYSICAL_DEVS
, GFP_KERNEL
);
7265 if (!ioa_cfg
->res_entries
)
7268 for (i
= 0; i
< IPR_MAX_PHYSICAL_DEVS
; i
++)
7269 list_add_tail(&ioa_cfg
->res_entries
[i
].queue
, &ioa_cfg
->free_res_q
);
7271 ioa_cfg
->vpd_cbs
= pci_alloc_consistent(ioa_cfg
->pdev
,
7272 sizeof(struct ipr_misc_cbs
),
7273 &ioa_cfg
->vpd_cbs_dma
);
7275 if (!ioa_cfg
->vpd_cbs
)
7276 goto out_free_res_entries
;
7278 if (ipr_alloc_cmd_blks(ioa_cfg
))
7279 goto out_free_vpd_cbs
;
7281 ioa_cfg
->host_rrq
= pci_alloc_consistent(ioa_cfg
->pdev
,
7282 sizeof(u32
) * IPR_NUM_CMD_BLKS
,
7283 &ioa_cfg
->host_rrq_dma
);
7285 if (!ioa_cfg
->host_rrq
)
7286 goto out_ipr_free_cmd_blocks
;
7288 ioa_cfg
->cfg_table
= pci_alloc_consistent(ioa_cfg
->pdev
,
7289 sizeof(struct ipr_config_table
),
7290 &ioa_cfg
->cfg_table_dma
);
7292 if (!ioa_cfg
->cfg_table
)
7293 goto out_free_host_rrq
;
7295 for (i
= 0; i
< IPR_NUM_HCAMS
; i
++) {
7296 ioa_cfg
->hostrcb
[i
] = pci_alloc_consistent(ioa_cfg
->pdev
,
7297 sizeof(struct ipr_hostrcb
),
7298 &ioa_cfg
->hostrcb_dma
[i
]);
7300 if (!ioa_cfg
->hostrcb
[i
])
7301 goto out_free_hostrcb_dma
;
7303 ioa_cfg
->hostrcb
[i
]->hostrcb_dma
=
7304 ioa_cfg
->hostrcb_dma
[i
] + offsetof(struct ipr_hostrcb
, hcam
);
7305 ioa_cfg
->hostrcb
[i
]->ioa_cfg
= ioa_cfg
;
7306 list_add_tail(&ioa_cfg
->hostrcb
[i
]->queue
, &ioa_cfg
->hostrcb_free_q
);
7309 ioa_cfg
->trace
= kzalloc(sizeof(struct ipr_trace_entry
) *
7310 IPR_NUM_TRACE_ENTRIES
, GFP_KERNEL
);
7312 if (!ioa_cfg
->trace
)
7313 goto out_free_hostrcb_dma
;
7320 out_free_hostrcb_dma
:
7322 pci_free_consistent(pdev
, sizeof(struct ipr_hostrcb
),
7323 ioa_cfg
->hostrcb
[i
],
7324 ioa_cfg
->hostrcb_dma
[i
]);
7326 pci_free_consistent(pdev
, sizeof(struct ipr_config_table
),
7327 ioa_cfg
->cfg_table
, ioa_cfg
->cfg_table_dma
);
7329 pci_free_consistent(pdev
, sizeof(u32
) * IPR_NUM_CMD_BLKS
,
7330 ioa_cfg
->host_rrq
, ioa_cfg
->host_rrq_dma
);
7331 out_ipr_free_cmd_blocks
:
7332 ipr_free_cmd_blks(ioa_cfg
);
7334 pci_free_consistent(pdev
, sizeof(struct ipr_misc_cbs
),
7335 ioa_cfg
->vpd_cbs
, ioa_cfg
->vpd_cbs_dma
);
7336 out_free_res_entries
:
7337 kfree(ioa_cfg
->res_entries
);
7342 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
7343 * @ioa_cfg: ioa config struct
7348 static void __devinit
ipr_initialize_bus_attr(struct ipr_ioa_cfg
*ioa_cfg
)
7352 for (i
= 0; i
< IPR_MAX_NUM_BUSES
; i
++) {
7353 ioa_cfg
->bus_attr
[i
].bus
= i
;
7354 ioa_cfg
->bus_attr
[i
].qas_enabled
= 0;
7355 ioa_cfg
->bus_attr
[i
].bus_width
= IPR_DEFAULT_BUS_WIDTH
;
7356 if (ipr_max_speed
< ARRAY_SIZE(ipr_max_bus_speeds
))
7357 ioa_cfg
->bus_attr
[i
].max_xfer_rate
= ipr_max_bus_speeds
[ipr_max_speed
];
7359 ioa_cfg
->bus_attr
[i
].max_xfer_rate
= IPR_U160_SCSI_RATE
;
7364 * ipr_init_ioa_cfg - Initialize IOA config struct
7365 * @ioa_cfg: ioa config struct
7366 * @host: scsi host struct
7367 * @pdev: PCI dev struct
7372 static void __devinit
ipr_init_ioa_cfg(struct ipr_ioa_cfg
*ioa_cfg
,
7373 struct Scsi_Host
*host
, struct pci_dev
*pdev
)
7375 const struct ipr_interrupt_offsets
*p
;
7376 struct ipr_interrupts
*t
;
7379 ioa_cfg
->host
= host
;
7380 ioa_cfg
->pdev
= pdev
;
7381 ioa_cfg
->log_level
= ipr_log_level
;
7382 ioa_cfg
->doorbell
= IPR_DOORBELL
;
7383 sprintf(ioa_cfg
->eye_catcher
, IPR_EYECATCHER
);
7384 sprintf(ioa_cfg
->trace_start
, IPR_TRACE_START_LABEL
);
7385 sprintf(ioa_cfg
->ipr_free_label
, IPR_FREEQ_LABEL
);
7386 sprintf(ioa_cfg
->ipr_pending_label
, IPR_PENDQ_LABEL
);
7387 sprintf(ioa_cfg
->cfg_table_start
, IPR_CFG_TBL_START
);
7388 sprintf(ioa_cfg
->resource_table_label
, IPR_RES_TABLE_LABEL
);
7389 sprintf(ioa_cfg
->ipr_hcam_label
, IPR_HCAM_LABEL
);
7390 sprintf(ioa_cfg
->ipr_cmd_label
, IPR_CMD_LABEL
);
7392 INIT_LIST_HEAD(&ioa_cfg
->free_q
);
7393 INIT_LIST_HEAD(&ioa_cfg
->pending_q
);
7394 INIT_LIST_HEAD(&ioa_cfg
->hostrcb_free_q
);
7395 INIT_LIST_HEAD(&ioa_cfg
->hostrcb_pending_q
);
7396 INIT_LIST_HEAD(&ioa_cfg
->free_res_q
);
7397 INIT_LIST_HEAD(&ioa_cfg
->used_res_q
);
7398 INIT_WORK(&ioa_cfg
->work_q
, ipr_worker_thread
);
7399 init_waitqueue_head(&ioa_cfg
->reset_wait_q
);
7400 init_waitqueue_head(&ioa_cfg
->msi_wait_q
);
7401 ioa_cfg
->sdt_state
= INACTIVE
;
7402 if (ipr_enable_cache
)
7403 ioa_cfg
->cache_state
= CACHE_ENABLED
;
7405 ioa_cfg
->cache_state
= CACHE_DISABLED
;
7407 ipr_initialize_bus_attr(ioa_cfg
);
7409 host
->max_id
= IPR_MAX_NUM_TARGETS_PER_BUS
;
7410 host
->max_lun
= IPR_MAX_NUM_LUNS_PER_TARGET
;
7411 host
->max_channel
= IPR_MAX_BUS_TO_SCAN
;
7412 host
->unique_id
= host
->host_no
;
7413 host
->max_cmd_len
= IPR_MAX_CDB_LEN
;
7414 pci_set_drvdata(pdev
, ioa_cfg
);
7416 p
= &ioa_cfg
->chip_cfg
->regs
;
7418 base
= ioa_cfg
->hdw_dma_regs
;
7420 t
->set_interrupt_mask_reg
= base
+ p
->set_interrupt_mask_reg
;
7421 t
->clr_interrupt_mask_reg
= base
+ p
->clr_interrupt_mask_reg
;
7422 t
->sense_interrupt_mask_reg
= base
+ p
->sense_interrupt_mask_reg
;
7423 t
->clr_interrupt_reg
= base
+ p
->clr_interrupt_reg
;
7424 t
->sense_interrupt_reg
= base
+ p
->sense_interrupt_reg
;
7425 t
->ioarrin_reg
= base
+ p
->ioarrin_reg
;
7426 t
->sense_uproc_interrupt_reg
= base
+ p
->sense_uproc_interrupt_reg
;
7427 t
->set_uproc_interrupt_reg
= base
+ p
->set_uproc_interrupt_reg
;
7428 t
->clr_uproc_interrupt_reg
= base
+ p
->clr_uproc_interrupt_reg
;
7432 * ipr_get_chip_info - Find adapter chip information
7433 * @dev_id: PCI device id struct
7436 * ptr to chip information on success / NULL on failure
7438 static const struct ipr_chip_t
* __devinit
7439 ipr_get_chip_info(const struct pci_device_id
*dev_id
)
7443 for (i
= 0; i
< ARRAY_SIZE(ipr_chip
); i
++)
7444 if (ipr_chip
[i
].vendor
== dev_id
->vendor
&&
7445 ipr_chip
[i
].device
== dev_id
->device
)
7446 return &ipr_chip
[i
];
7451 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
7452 * @pdev: PCI device struct
7454 * Description: Simply set the msi_received flag to 1 indicating that
7455 * Message Signaled Interrupts are supported.
7458 * 0 on success / non-zero on failure
7460 static irqreturn_t __devinit
ipr_test_intr(int irq
, void *devp
)
7462 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)devp
;
7463 unsigned long lock_flags
= 0;
7464 irqreturn_t rc
= IRQ_HANDLED
;
7466 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
7468 ioa_cfg
->msi_received
= 1;
7469 wake_up(&ioa_cfg
->msi_wait_q
);
7471 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
7476 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
7477 * @pdev: PCI device struct
7479 * Description: The return value from pci_enable_msi() can not always be
7480 * trusted. This routine sets up and initiates a test interrupt to determine
7481 * if the interrupt is received via the ipr_test_intr() service routine.
7482 * If the tests fails, the driver will fall back to LSI.
7485 * 0 on success / non-zero on failure
7487 static int __devinit
ipr_test_msi(struct ipr_ioa_cfg
*ioa_cfg
,
7488 struct pci_dev
*pdev
)
7491 volatile u32 int_reg
;
7492 unsigned long lock_flags
= 0;
7496 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
7497 init_waitqueue_head(&ioa_cfg
->msi_wait_q
);
7498 ioa_cfg
->msi_received
= 0;
7499 ipr_mask_and_clear_interrupts(ioa_cfg
, ~IPR_PCII_IOA_TRANS_TO_OPER
);
7500 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
, ioa_cfg
->regs
.clr_interrupt_mask_reg
);
7501 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
7502 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
7504 rc
= request_irq(pdev
->irq
, ipr_test_intr
, 0, IPR_NAME
, ioa_cfg
);
7506 dev_err(&pdev
->dev
, "Can not assign irq %d\n", pdev
->irq
);
7508 } else if (ipr_debug
)
7509 dev_info(&pdev
->dev
, "IRQ assigned: %d\n", pdev
->irq
);
7511 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
, ioa_cfg
->regs
.sense_interrupt_reg
);
7512 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
7513 wait_event_timeout(ioa_cfg
->msi_wait_q
, ioa_cfg
->msi_received
, HZ
);
7514 ipr_mask_and_clear_interrupts(ioa_cfg
, ~IPR_PCII_IOA_TRANS_TO_OPER
);
7516 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
7517 if (!ioa_cfg
->msi_received
) {
7518 /* MSI test failed */
7519 dev_info(&pdev
->dev
, "MSI test failed. Falling back to LSI.\n");
7521 } else if (ipr_debug
)
7522 dev_info(&pdev
->dev
, "MSI test succeeded.\n");
7524 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
7526 free_irq(pdev
->irq
, ioa_cfg
);
7534 * ipr_probe_ioa - Allocates memory and does first stage of initialization
7535 * @pdev: PCI device struct
7536 * @dev_id: PCI device id struct
7539 * 0 on success / non-zero on failure
7541 static int __devinit
ipr_probe_ioa(struct pci_dev
*pdev
,
7542 const struct pci_device_id
*dev_id
)
7544 struct ipr_ioa_cfg
*ioa_cfg
;
7545 struct Scsi_Host
*host
;
7546 unsigned long ipr_regs_pci
;
7547 void __iomem
*ipr_regs
;
7548 int rc
= PCIBIOS_SUCCESSFUL
;
7549 volatile u32 mask
, uproc
, interrupts
;
7553 if ((rc
= pci_enable_device(pdev
))) {
7554 dev_err(&pdev
->dev
, "Cannot enable adapter\n");
7558 dev_info(&pdev
->dev
, "Found IOA with IRQ: %d\n", pdev
->irq
);
7560 host
= scsi_host_alloc(&driver_template
, sizeof(*ioa_cfg
));
7563 dev_err(&pdev
->dev
, "call to scsi_host_alloc failed!\n");
7568 ioa_cfg
= (struct ipr_ioa_cfg
*)host
->hostdata
;
7569 memset(ioa_cfg
, 0, sizeof(struct ipr_ioa_cfg
));
7570 ata_host_init(&ioa_cfg
->ata_host
, &pdev
->dev
,
7571 sata_port_info
.flags
, &ipr_sata_ops
);
7573 ioa_cfg
->ipr_chip
= ipr_get_chip_info(dev_id
);
7575 if (!ioa_cfg
->ipr_chip
) {
7576 dev_err(&pdev
->dev
, "Unknown adapter chipset 0x%04X 0x%04X\n",
7577 dev_id
->vendor
, dev_id
->device
);
7578 goto out_scsi_host_put
;
7581 ioa_cfg
->chip_cfg
= ioa_cfg
->ipr_chip
->cfg
;
7583 if (ipr_transop_timeout
)
7584 ioa_cfg
->transop_timeout
= ipr_transop_timeout
;
7585 else if (dev_id
->driver_data
& IPR_USE_LONG_TRANSOP_TIMEOUT
)
7586 ioa_cfg
->transop_timeout
= IPR_LONG_OPERATIONAL_TIMEOUT
;
7588 ioa_cfg
->transop_timeout
= IPR_OPERATIONAL_TIMEOUT
;
7590 ioa_cfg
->revid
= pdev
->revision
;
7592 ipr_regs_pci
= pci_resource_start(pdev
, 0);
7594 rc
= pci_request_regions(pdev
, IPR_NAME
);
7597 "Couldn't register memory range of registers\n");
7598 goto out_scsi_host_put
;
7601 ipr_regs
= pci_ioremap_bar(pdev
, 0);
7605 "Couldn't map memory range of registers\n");
7607 goto out_release_regions
;
7610 ioa_cfg
->hdw_dma_regs
= ipr_regs
;
7611 ioa_cfg
->hdw_dma_regs_pci
= ipr_regs_pci
;
7612 ioa_cfg
->ioa_mailbox
= ioa_cfg
->chip_cfg
->mailbox
+ ipr_regs
;
7614 ipr_init_ioa_cfg(ioa_cfg
, host
, pdev
);
7616 pci_set_master(pdev
);
7618 rc
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
7620 dev_err(&pdev
->dev
, "Failed to set PCI DMA mask\n");
7624 rc
= pci_write_config_byte(pdev
, PCI_CACHE_LINE_SIZE
,
7625 ioa_cfg
->chip_cfg
->cache_line_size
);
7627 if (rc
!= PCIBIOS_SUCCESSFUL
) {
7628 dev_err(&pdev
->dev
, "Write of cache line size failed\n");
7633 /* Enable MSI style interrupts if they are supported. */
7634 if (ioa_cfg
->ipr_chip
->intr_type
== IPR_USE_MSI
&& !pci_enable_msi(pdev
)) {
7635 rc
= ipr_test_msi(ioa_cfg
, pdev
);
7636 if (rc
== -EOPNOTSUPP
)
7637 pci_disable_msi(pdev
);
7639 goto out_msi_disable
;
7641 dev_info(&pdev
->dev
, "MSI enabled with IRQ: %d\n", pdev
->irq
);
7642 } else if (ipr_debug
)
7643 dev_info(&pdev
->dev
, "Cannot enable MSI.\n");
7645 /* Save away PCI config space for use following IOA reset */
7646 rc
= pci_save_state(pdev
);
7648 if (rc
!= PCIBIOS_SUCCESSFUL
) {
7649 dev_err(&pdev
->dev
, "Failed to save PCI config space\n");
7654 if ((rc
= ipr_save_pcix_cmd_reg(ioa_cfg
)))
7657 if ((rc
= ipr_set_pcix_cmd_reg(ioa_cfg
)))
7660 rc
= ipr_alloc_mem(ioa_cfg
);
7663 "Couldn't allocate enough memory for device driver!\n");
7668 * If HRRQ updated interrupt is not masked, or reset alert is set,
7669 * the card is in an unknown state and needs a hard reset
7671 mask
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
7672 interrupts
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
7673 uproc
= readl(ioa_cfg
->regs
.sense_uproc_interrupt_reg
);
7674 if ((mask
& IPR_PCII_HRRQ_UPDATED
) == 0 || (uproc
& IPR_UPROCI_RESET_ALERT
))
7675 ioa_cfg
->needs_hard_reset
= 1;
7676 if (interrupts
& IPR_PCII_ERROR_INTERRUPTS
)
7677 ioa_cfg
->needs_hard_reset
= 1;
7678 if (interrupts
& IPR_PCII_IOA_UNIT_CHECKED
)
7679 ioa_cfg
->ioa_unit_checked
= 1;
7681 ipr_mask_and_clear_interrupts(ioa_cfg
, ~IPR_PCII_IOA_TRANS_TO_OPER
);
7682 rc
= request_irq(pdev
->irq
, ipr_isr
,
7683 ioa_cfg
->msi_received
? 0 : IRQF_SHARED
,
7687 dev_err(&pdev
->dev
, "Couldn't register IRQ %d! rc=%d\n",
7692 if ((dev_id
->driver_data
& IPR_USE_PCI_WARM_RESET
) ||
7693 (dev_id
->device
== PCI_DEVICE_ID_IBM_OBSIDIAN_E
&& !ioa_cfg
->revid
)) {
7694 ioa_cfg
->needs_warm_reset
= 1;
7695 ioa_cfg
->reset
= ipr_reset_slot_reset
;
7697 ioa_cfg
->reset
= ipr_reset_start_bist
;
7699 spin_lock(&ipr_driver_lock
);
7700 list_add_tail(&ioa_cfg
->queue
, &ipr_ioa_head
);
7701 spin_unlock(&ipr_driver_lock
);
7708 ipr_free_mem(ioa_cfg
);
7712 pci_disable_msi(pdev
);
7713 out_release_regions
:
7714 pci_release_regions(pdev
);
7716 scsi_host_put(host
);
7718 pci_disable_device(pdev
);
7723 * ipr_scan_vsets - Scans for VSET devices
7724 * @ioa_cfg: ioa config struct
7726 * Description: Since the VSET resources do not follow SAM in that we can have
7727 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
7732 static void ipr_scan_vsets(struct ipr_ioa_cfg
*ioa_cfg
)
7736 for (target
= 0; target
< IPR_MAX_NUM_TARGETS_PER_BUS
; target
++)
7737 for (lun
= 0; lun
< IPR_MAX_NUM_VSET_LUNS_PER_TARGET
; lun
++ )
7738 scsi_add_device(ioa_cfg
->host
, IPR_VSET_BUS
, target
, lun
);
7742 * ipr_initiate_ioa_bringdown - Bring down an adapter
7743 * @ioa_cfg: ioa config struct
7744 * @shutdown_type: shutdown type
7746 * Description: This function will initiate bringing down the adapter.
7747 * This consists of issuing an IOA shutdown to the adapter
7748 * to flush the cache, and running BIST.
7749 * If the caller needs to wait on the completion of the reset,
7750 * the caller must sleep on the reset_wait_q.
7755 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg
*ioa_cfg
,
7756 enum ipr_shutdown_type shutdown_type
)
7759 if (ioa_cfg
->sdt_state
== WAIT_FOR_DUMP
)
7760 ioa_cfg
->sdt_state
= ABORT_DUMP
;
7761 ioa_cfg
->reset_retries
= 0;
7762 ioa_cfg
->in_ioa_bringdown
= 1;
7763 ipr_initiate_ioa_reset(ioa_cfg
, shutdown_type
);
7768 * __ipr_remove - Remove a single adapter
7769 * @pdev: pci device struct
7771 * Adapter hot plug remove entry point.
7776 static void __ipr_remove(struct pci_dev
*pdev
)
7778 unsigned long host_lock_flags
= 0;
7779 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
7782 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7783 while(ioa_cfg
->in_reset_reload
) {
7784 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7785 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
7786 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7789 ipr_initiate_ioa_bringdown(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
7791 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7792 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
7793 flush_scheduled_work();
7794 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7796 spin_lock(&ipr_driver_lock
);
7797 list_del(&ioa_cfg
->queue
);
7798 spin_unlock(&ipr_driver_lock
);
7800 if (ioa_cfg
->sdt_state
== ABORT_DUMP
)
7801 ioa_cfg
->sdt_state
= WAIT_FOR_DUMP
;
7802 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7804 ipr_free_all_resources(ioa_cfg
);
7810 * ipr_remove - IOA hot plug remove entry point
7811 * @pdev: pci device struct
7813 * Adapter hot plug remove entry point.
7818 static void __devexit
ipr_remove(struct pci_dev
*pdev
)
7820 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
7824 ipr_remove_trace_file(&ioa_cfg
->host
->shost_dev
.kobj
,
7826 ipr_remove_dump_file(&ioa_cfg
->host
->shost_dev
.kobj
,
7828 scsi_remove_host(ioa_cfg
->host
);
7836 * ipr_probe - Adapter hot plug add entry point
7839 * 0 on success / non-zero on failure
7841 static int __devinit
ipr_probe(struct pci_dev
*pdev
,
7842 const struct pci_device_id
*dev_id
)
7844 struct ipr_ioa_cfg
*ioa_cfg
;
7847 rc
= ipr_probe_ioa(pdev
, dev_id
);
7852 ioa_cfg
= pci_get_drvdata(pdev
);
7853 rc
= ipr_probe_ioa_part2(ioa_cfg
);
7860 rc
= scsi_add_host(ioa_cfg
->host
, &pdev
->dev
);
7867 rc
= ipr_create_trace_file(&ioa_cfg
->host
->shost_dev
.kobj
,
7871 scsi_remove_host(ioa_cfg
->host
);
7876 rc
= ipr_create_dump_file(&ioa_cfg
->host
->shost_dev
.kobj
,
7880 ipr_remove_trace_file(&ioa_cfg
->host
->shost_dev
.kobj
,
7882 scsi_remove_host(ioa_cfg
->host
);
7887 scsi_scan_host(ioa_cfg
->host
);
7888 ipr_scan_vsets(ioa_cfg
);
7889 scsi_add_device(ioa_cfg
->host
, IPR_IOA_BUS
, IPR_IOA_TARGET
, IPR_IOA_LUN
);
7890 ioa_cfg
->allow_ml_add_del
= 1;
7891 ioa_cfg
->host
->max_channel
= IPR_VSET_BUS
;
7892 schedule_work(&ioa_cfg
->work_q
);
7897 * ipr_shutdown - Shutdown handler.
7898 * @pdev: pci device struct
7900 * This function is invoked upon system shutdown/reboot. It will issue
7901 * an adapter shutdown to the adapter to flush the write cache.
7906 static void ipr_shutdown(struct pci_dev
*pdev
)
7908 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
7909 unsigned long lock_flags
= 0;
7911 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
7912 while(ioa_cfg
->in_reset_reload
) {
7913 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
7914 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
7915 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
7918 ipr_initiate_ioa_bringdown(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
7919 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
7920 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
7923 static struct pci_device_id ipr_pci_table
[] __devinitdata
= {
7924 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
7925 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_5702
, 0, 0, 0 },
7926 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
7927 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_5703
, 0, 0, 0 },
7928 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
7929 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_573D
, 0, 0, 0 },
7930 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
7931 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_573E
, 0, 0, 0 },
7932 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
7933 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571B
, 0, 0, 0 },
7934 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
7935 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572E
, 0, 0, 0 },
7936 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
7937 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571A
, 0, 0, 0 },
7938 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
7939 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_575B
, 0, 0,
7940 IPR_USE_LONG_TRANSOP_TIMEOUT
},
7941 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
,
7942 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572A
, 0, 0, 0 },
7943 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
,
7944 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572B
, 0, 0,
7945 IPR_USE_LONG_TRANSOP_TIMEOUT
},
7946 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
,
7947 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_575C
, 0, 0,
7948 IPR_USE_LONG_TRANSOP_TIMEOUT
},
7949 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
,
7950 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572A
, 0, 0, 0 },
7951 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
,
7952 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572B
, 0, 0,
7953 IPR_USE_LONG_TRANSOP_TIMEOUT
},
7954 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
,
7955 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_575C
, 0, 0,
7956 IPR_USE_LONG_TRANSOP_TIMEOUT
},
7957 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
,
7958 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_574E
, 0, 0,
7959 IPR_USE_LONG_TRANSOP_TIMEOUT
},
7960 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
,
7961 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_575D
, 0, 0,
7962 IPR_USE_LONG_TRANSOP_TIMEOUT
},
7963 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
,
7964 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B3
, 0, 0, 0 },
7965 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
,
7966 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B7
, 0, 0,
7967 IPR_USE_LONG_TRANSOP_TIMEOUT
| IPR_USE_PCI_WARM_RESET
},
7968 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_SNIPE
,
7969 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_2780
, 0, 0, 0 },
7970 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
,
7971 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571E
, 0, 0, 0 },
7972 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
,
7973 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571F
, 0, 0,
7974 IPR_USE_LONG_TRANSOP_TIMEOUT
},
7975 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
,
7976 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572F
, 0, 0,
7977 IPR_USE_LONG_TRANSOP_TIMEOUT
},
7978 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_SCAMP_E
,
7979 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_574D
, 0, 0,
7980 IPR_USE_LONG_TRANSOP_TIMEOUT
},
7983 MODULE_DEVICE_TABLE(pci
, ipr_pci_table
);
7985 static struct pci_error_handlers ipr_err_handler
= {
7986 .error_detected
= ipr_pci_error_detected
,
7987 .slot_reset
= ipr_pci_slot_reset
,
7990 static struct pci_driver ipr_driver
= {
7992 .id_table
= ipr_pci_table
,
7994 .remove
= __devexit_p(ipr_remove
),
7995 .shutdown
= ipr_shutdown
,
7996 .err_handler
= &ipr_err_handler
,
8000 * ipr_init - Module entry point
8003 * 0 on success / negative value on failure
8005 static int __init
ipr_init(void)
8007 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
8008 IPR_DRIVER_VERSION
, IPR_DRIVER_DATE
);
8010 return pci_register_driver(&ipr_driver
);
8014 * ipr_exit - Module unload
8016 * Module unload entry point.
8021 static void __exit
ipr_exit(void)
8023 pci_unregister_driver(&ipr_driver
);
8026 module_init(ipr_init
);
8027 module_exit(ipr_exit
);