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>
76 #include <asm/processor.h>
77 #include <scsi/scsi.h>
78 #include <scsi/scsi_host.h>
79 #include <scsi/scsi_tcq.h>
80 #include <scsi/scsi_eh.h>
81 #include <scsi/scsi_cmnd.h>
87 static struct list_head ipr_ioa_head = LIST_HEAD_INIT(ipr_ioa_head);
88 static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
89 static unsigned int ipr_max_speed = 1;
90 static int ipr_testmode = 0;
91 static unsigned int ipr_fastfail = 0;
92 static unsigned int ipr_transop_timeout = 0;
93 static unsigned int ipr_enable_cache = 1;
94 static unsigned int ipr_debug = 0;
95 static unsigned int ipr_dual_ioa_raid = 1;
96 static DEFINE_SPINLOCK(ipr_driver_lock);
98 /* This table describes the differences between DMA controller chips */
99 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
100 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
102 .cache_line_size = 0x20,
104 .set_interrupt_mask_reg = 0x0022C,
105 .clr_interrupt_mask_reg = 0x00230,
106 .sense_interrupt_mask_reg = 0x0022C,
107 .clr_interrupt_reg = 0x00228,
108 .sense_interrupt_reg = 0x00224,
109 .ioarrin_reg = 0x00404,
110 .sense_uproc_interrupt_reg = 0x00214,
111 .set_uproc_interrupt_reg = 0x00214,
112 .clr_uproc_interrupt_reg = 0x00218
115 { /* Snipe and Scamp */
117 .cache_line_size = 0x20,
119 .set_interrupt_mask_reg = 0x00288,
120 .clr_interrupt_mask_reg = 0x0028C,
121 .sense_interrupt_mask_reg = 0x00288,
122 .clr_interrupt_reg = 0x00284,
123 .sense_interrupt_reg = 0x00280,
124 .ioarrin_reg = 0x00504,
125 .sense_uproc_interrupt_reg = 0x00290,
126 .set_uproc_interrupt_reg = 0x00290,
127 .clr_uproc_interrupt_reg = 0x00294
132 static const struct ipr_chip_t ipr_chip[] = {
133 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, &ipr_chip_cfg[0] },
134 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, &ipr_chip_cfg[0] },
135 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, &ipr_chip_cfg[0] },
136 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, &ipr_chip_cfg[0] },
137 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, &ipr_chip_cfg[0] },
138 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, &ipr_chip_cfg[1] },
139 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, &ipr_chip_cfg[1] }
142 static int ipr_max_bus_speeds [] = {
143 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
146 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
147 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
148 module_param_named(max_speed, ipr_max_speed, uint, 0);
149 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
150 module_param_named(log_level, ipr_log_level, uint, 0);
151 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
152 module_param_named(testmode, ipr_testmode, int, 0);
153 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
154 module_param_named(fastfail, ipr_fastfail, int, 0);
155 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
156 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
157 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
158 module_param_named(enable_cache, ipr_enable_cache, int, 0);
159 MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)");
160 module_param_named(debug, ipr_debug, int, 0);
161 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
162 module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
163 MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
164 MODULE_LICENSE("GPL");
165 MODULE_VERSION(IPR_DRIVER_VERSION);
167 /* A constant array of IOASCs/URCs/Error Messages */
169 struct ipr_error_table_t ipr_error_table[] = {
170 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
171 "8155: An unknown error was received"},
173 "Soft underlength error"},
175 "Command to be cancelled not found"},
177 "Qualified success"},
178 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
179 "FFFE: Soft device bus error recovered by the IOA"},
180 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
181 "4101: Soft device bus fabric error"},
182 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
183 "FFF9: Device sector reassign successful"},
184 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
185 "FFF7: Media error recovered by device rewrite procedures"},
186 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
187 "7001: IOA sector reassignment successful"},
188 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
189 "FFF9: Soft media error. Sector reassignment recommended"},
190 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
191 "FFF7: Media error recovered by IOA rewrite procedures"},
192 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
193 "FF3D: Soft PCI bus error recovered by the IOA"},
194 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
195 "FFF6: Device hardware error recovered by the IOA"},
196 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
197 "FFF6: Device hardware error recovered by the device"},
198 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
199 "FF3D: Soft IOA error recovered by the IOA"},
200 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
201 "FFFA: Undefined device response recovered by the IOA"},
202 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
203 "FFF6: Device bus error, message or command phase"},
204 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
205 "FFFE: Task Management Function failed"},
206 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
207 "FFF6: Failure prediction threshold exceeded"},
208 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
209 "8009: Impending cache battery pack failure"},
211 "34FF: Disk device format in progress"},
212 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
213 "9070: IOA requested reset"},
215 "Synchronization required"},
217 "No ready, IOA shutdown"},
219 "Not ready, IOA has been shutdown"},
220 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
221 "3020: Storage subsystem configuration error"},
223 "FFF5: Medium error, data unreadable, recommend reassign"},
225 "7000: Medium error, data unreadable, do not reassign"},
226 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
227 "FFF3: Disk media format bad"},
228 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
229 "3002: Addressed device failed to respond to selection"},
230 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
231 "3100: Device bus error"},
232 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
233 "3109: IOA timed out a device command"},
235 "3120: SCSI bus is not operational"},
236 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
237 "4100: Hard device bus fabric error"},
238 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
239 "9000: IOA reserved area data check"},
240 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
241 "9001: IOA reserved area invalid data pattern"},
242 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
243 "9002: IOA reserved area LRC error"},
244 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
245 "102E: Out of alternate sectors for disk storage"},
246 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
247 "FFF4: Data transfer underlength error"},
248 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
249 "FFF4: Data transfer overlength error"},
250 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
251 "3400: Logical unit failure"},
252 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
253 "FFF4: Device microcode is corrupt"},
254 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
255 "8150: PCI bus error"},
257 "Unsupported device bus message received"},
258 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
259 "FFF4: Disk device problem"},
260 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
261 "8150: Permanent IOA failure"},
262 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
263 "3010: Disk device returned wrong response to IOA"},
264 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
265 "8151: IOA microcode error"},
267 "Device bus status error"},
268 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
269 "8157: IOA error requiring IOA reset to recover"},
271 "ATA device status error"},
273 "Message reject received from the device"},
274 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
275 "8008: A permanent cache battery pack failure occurred"},
276 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
277 "9090: Disk unit has been modified after the last known status"},
278 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
279 "9081: IOA detected device error"},
280 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
281 "9082: IOA detected device error"},
282 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
283 "3110: Device bus error, message or command phase"},
284 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
285 "3110: SAS Command / Task Management Function failed"},
286 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
287 "9091: Incorrect hardware configuration change has been detected"},
288 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
289 "9073: Invalid multi-adapter configuration"},
290 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
291 "4010: Incorrect connection between cascaded expanders"},
292 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
293 "4020: Connections exceed IOA design limits"},
294 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
295 "4030: Incorrect multipath connection"},
296 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
297 "4110: Unsupported enclosure function"},
298 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
299 "FFF4: Command to logical unit failed"},
301 "Illegal request, invalid request type or request packet"},
303 "Illegal request, invalid resource handle"},
305 "Illegal request, commands not allowed to this device"},
307 "Illegal request, command not allowed to a secondary adapter"},
309 "Illegal request, invalid field in parameter list"},
311 "Illegal request, parameter not supported"},
313 "Illegal request, parameter value invalid"},
315 "Illegal request, command sequence error"},
317 "Illegal request, dual adapter support not enabled"},
318 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
319 "9031: Array protection temporarily suspended, protection resuming"},
320 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
321 "9040: Array protection temporarily suspended, protection resuming"},
322 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
323 "3140: Device bus not ready to ready transition"},
324 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
325 "FFFB: SCSI bus was reset"},
327 "FFFE: SCSI bus transition to single ended"},
329 "FFFE: SCSI bus transition to LVD"},
330 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
331 "FFFB: SCSI bus was reset by another initiator"},
332 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
333 "3029: A device replacement has occurred"},
334 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
335 "9051: IOA cache data exists for a missing or failed device"},
336 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
337 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
338 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
339 "9025: Disk unit is not supported at its physical location"},
340 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
341 "3020: IOA detected a SCSI bus configuration error"},
342 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
343 "3150: SCSI bus configuration error"},
344 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
345 "9074: Asymmetric advanced function disk configuration"},
346 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
347 "4040: Incomplete multipath connection between IOA and enclosure"},
348 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
349 "4041: Incomplete multipath connection between enclosure and device"},
350 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
351 "9075: Incomplete multipath connection between IOA and remote IOA"},
352 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
353 "9076: Configuration error, missing remote IOA"},
354 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
355 "4050: Enclosure does not support a required multipath function"},
356 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
357 "9041: Array protection temporarily suspended"},
358 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
359 "9042: Corrupt array parity detected on specified device"},
360 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
361 "9030: Array no longer protected due to missing or failed disk unit"},
362 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
363 "9071: Link operational transition"},
364 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
365 "9072: Link not operational transition"},
366 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
367 "9032: Array exposed but still protected"},
368 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
369 "70DD: Device forced failed by disrupt device command"},
370 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
371 "4061: Multipath redundancy level got better"},
372 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
373 "4060: Multipath redundancy level got worse"},
375 "Failure due to other device"},
376 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
377 "9008: IOA does not support functions expected by devices"},
378 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
379 "9010: Cache data associated with attached devices cannot be found"},
380 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
381 "9011: Cache data belongs to devices other than those attached"},
382 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
383 "9020: Array missing 2 or more devices with only 1 device present"},
384 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
385 "9021: Array missing 2 or more devices with 2 or more devices present"},
386 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
387 "9022: Exposed array is missing a required device"},
388 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
389 "9023: Array member(s) not at required physical locations"},
390 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
391 "9024: Array not functional due to present hardware configuration"},
392 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
393 "9026: Array not functional due to present hardware configuration"},
394 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
395 "9027: Array is missing a device and parity is out of sync"},
396 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
397 "9028: Maximum number of arrays already exist"},
398 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
399 "9050: Required cache data cannot be located for a disk unit"},
400 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
401 "9052: Cache data exists for a device that has been modified"},
402 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
403 "9054: IOA resources not available due to previous problems"},
404 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
405 "9092: Disk unit requires initialization before use"},
406 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
407 "9029: Incorrect hardware configuration change has been detected"},
408 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
409 "9060: One or more disk pairs are missing from an array"},
410 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
411 "9061: One or more disks are missing from an array"},
412 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
413 "9062: One or more disks are missing from an array"},
414 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
415 "9063: Maximum number of functional arrays has been exceeded"},
417 "Aborted command, invalid descriptor"},
419 "Command terminated by host"}
422 static const struct ipr_ses_table_entry ipr_ses_table[] = {
423 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
424 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
425 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
426 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
427 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
428 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
429 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
430 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
431 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
432 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
433 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
434 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
435 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
439 * Function Prototypes
441 static int ipr_reset_alert(struct ipr_cmnd *);
442 static void ipr_process_ccn(struct ipr_cmnd *);
443 static void ipr_process_error(struct ipr_cmnd *);
444 static void ipr_reset_ioa_job(struct ipr_cmnd *);
445 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
446 enum ipr_shutdown_type);
448 #ifdef CONFIG_SCSI_IPR_TRACE
450 * ipr_trc_hook - Add a trace entry to the driver trace
451 * @ipr_cmd: ipr command struct
453 * @add_data: additional data
458 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
459 u8 type, u32 add_data)
461 struct ipr_trace_entry *trace_entry;
462 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
464 trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
465 trace_entry->time = jiffies;
466 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
467 trace_entry->type = type;
468 trace_entry->ata_op_code = ipr_cmd->ioarcb.add_data.u.regs.command;
469 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
470 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
471 trace_entry->u.add_data = add_data;
474 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
478 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
479 * @ipr_cmd: ipr command struct
484 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
486 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
487 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
488 dma_addr_t dma_addr = be32_to_cpu(ioarcb->ioarcb_host_pci_addr);
490 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
491 ioarcb->write_data_transfer_length = 0;
492 ioarcb->read_data_transfer_length = 0;
493 ioarcb->write_ioadl_len = 0;
494 ioarcb->read_ioadl_len = 0;
495 ioarcb->write_ioadl_addr =
496 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
497 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
499 ioasa->residual_data_len = 0;
500 ioasa->u.gata.status = 0;
502 ipr_cmd->scsi_cmd = NULL;
504 ipr_cmd->sense_buffer[0] = 0;
505 ipr_cmd->dma_use_sg = 0;
509 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
510 * @ipr_cmd: ipr command struct
515 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
517 ipr_reinit_ipr_cmnd(ipr_cmd);
518 ipr_cmd->u.scratch = 0;
519 ipr_cmd->sibling = NULL;
520 init_timer(&ipr_cmd->timer);
524 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
525 * @ioa_cfg: ioa config struct
528 * pointer to ipr command struct
531 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
533 struct ipr_cmnd *ipr_cmd;
535 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
536 list_del(&ipr_cmd->queue);
537 ipr_init_ipr_cmnd(ipr_cmd);
543 * ipr_unmap_sglist - Unmap scatterlist if mapped
544 * @ioa_cfg: ioa config struct
545 * @ipr_cmd: ipr command struct
550 static void ipr_unmap_sglist(struct ipr_ioa_cfg *ioa_cfg,
551 struct ipr_cmnd *ipr_cmd)
553 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
555 if (ipr_cmd->dma_use_sg) {
556 if (scsi_cmd->use_sg > 0) {
557 pci_unmap_sg(ioa_cfg->pdev, scsi_cmd->request_buffer,
559 scsi_cmd->sc_data_direction);
561 pci_unmap_single(ioa_cfg->pdev, ipr_cmd->dma_handle,
562 scsi_cmd->request_bufflen,
563 scsi_cmd->sc_data_direction);
569 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
570 * @ioa_cfg: ioa config struct
571 * @clr_ints: interrupts to clear
573 * This function masks all interrupts on the adapter, then clears the
574 * interrupts specified in the mask
579 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
582 volatile u32 int_reg;
584 /* Stop new interrupts */
585 ioa_cfg->allow_interrupts = 0;
587 /* Set interrupt mask to stop all new interrupts */
588 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
590 /* Clear any pending interrupts */
591 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
592 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
596 * ipr_save_pcix_cmd_reg - Save PCI-X command register
597 * @ioa_cfg: ioa config struct
600 * 0 on success / -EIO on failure
602 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
604 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
606 if (pcix_cmd_reg == 0)
609 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
610 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
611 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
615 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
620 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
621 * @ioa_cfg: ioa config struct
624 * 0 on success / -EIO on failure
626 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
628 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
631 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
632 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
633 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
642 * ipr_sata_eh_done - done function for aborted SATA commands
643 * @ipr_cmd: ipr command struct
645 * This function is invoked for ops generated to SATA
646 * devices which are being aborted.
651 static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
653 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
654 struct ata_queued_cmd *qc = ipr_cmd->qc;
655 struct ipr_sata_port *sata_port = qc->ap->private_data;
657 qc->err_mask |= AC_ERR_OTHER;
658 sata_port->ioasa.status |= ATA_BUSY;
659 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
664 * ipr_scsi_eh_done - mid-layer done function for aborted ops
665 * @ipr_cmd: ipr command struct
667 * This function is invoked by the interrupt handler for
668 * ops generated by the SCSI mid-layer which are being aborted.
673 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
675 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
676 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
678 scsi_cmd->result |= (DID_ERROR << 16);
680 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
681 scsi_cmd->scsi_done(scsi_cmd);
682 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
686 * ipr_fail_all_ops - Fails all outstanding ops.
687 * @ioa_cfg: ioa config struct
689 * This function fails all outstanding ops.
694 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
696 struct ipr_cmnd *ipr_cmd, *temp;
699 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
700 list_del(&ipr_cmd->queue);
702 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
703 ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
705 if (ipr_cmd->scsi_cmd)
706 ipr_cmd->done = ipr_scsi_eh_done;
707 else if (ipr_cmd->qc)
708 ipr_cmd->done = ipr_sata_eh_done;
710 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
711 del_timer(&ipr_cmd->timer);
712 ipr_cmd->done(ipr_cmd);
719 * ipr_do_req - Send driver initiated requests.
720 * @ipr_cmd: ipr command struct
721 * @done: done function
722 * @timeout_func: timeout function
723 * @timeout: timeout value
725 * This function sends the specified command to the adapter with the
726 * timeout given. The done function is invoked on command completion.
731 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
732 void (*done) (struct ipr_cmnd *),
733 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
735 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
737 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
739 ipr_cmd->done = done;
741 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
742 ipr_cmd->timer.expires = jiffies + timeout;
743 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
745 add_timer(&ipr_cmd->timer);
747 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
750 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
751 ioa_cfg->regs.ioarrin_reg);
755 * ipr_internal_cmd_done - Op done function for an internally generated op.
756 * @ipr_cmd: ipr command struct
758 * This function is the op done function for an internally generated,
759 * blocking op. It simply wakes the sleeping thread.
764 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
766 if (ipr_cmd->sibling)
767 ipr_cmd->sibling = NULL;
769 complete(&ipr_cmd->completion);
773 * ipr_send_blocking_cmd - Send command and sleep on its completion.
774 * @ipr_cmd: ipr command struct
775 * @timeout_func: function to invoke if command times out
781 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
782 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
785 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
787 init_completion(&ipr_cmd->completion);
788 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
790 spin_unlock_irq(ioa_cfg->host->host_lock);
791 wait_for_completion(&ipr_cmd->completion);
792 spin_lock_irq(ioa_cfg->host->host_lock);
796 * ipr_send_hcam - Send an HCAM to the adapter.
797 * @ioa_cfg: ioa config struct
799 * @hostrcb: hostrcb struct
801 * This function will send a Host Controlled Async command to the adapter.
802 * If HCAMs are currently not allowed to be issued to the adapter, it will
803 * place the hostrcb on the free queue.
808 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
809 struct ipr_hostrcb *hostrcb)
811 struct ipr_cmnd *ipr_cmd;
812 struct ipr_ioarcb *ioarcb;
814 if (ioa_cfg->allow_cmds) {
815 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
816 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
817 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
819 ipr_cmd->u.hostrcb = hostrcb;
820 ioarcb = &ipr_cmd->ioarcb;
822 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
823 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
824 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
825 ioarcb->cmd_pkt.cdb[1] = type;
826 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
827 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
829 ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
830 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
831 ipr_cmd->ioadl[0].flags_and_data_len =
832 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
833 ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
835 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
836 ipr_cmd->done = ipr_process_ccn;
838 ipr_cmd->done = ipr_process_error;
840 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
843 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
844 ioa_cfg->regs.ioarrin_reg);
846 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
851 * ipr_init_res_entry - Initialize a resource entry struct.
852 * @res: resource entry struct
857 static void ipr_init_res_entry(struct ipr_resource_entry *res)
859 res->needs_sync_complete = 0;
862 res->del_from_ml = 0;
863 res->resetting_device = 0;
865 res->sata_port = NULL;
869 * ipr_handle_config_change - Handle a config change from the adapter
870 * @ioa_cfg: ioa config struct
876 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
877 struct ipr_hostrcb *hostrcb)
879 struct ipr_resource_entry *res = NULL;
880 struct ipr_config_table_entry *cfgte;
883 cfgte = &hostrcb->hcam.u.ccn.cfgte;
885 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
886 if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
887 sizeof(cfgte->res_addr))) {
894 if (list_empty(&ioa_cfg->free_res_q)) {
895 ipr_send_hcam(ioa_cfg,
896 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
901 res = list_entry(ioa_cfg->free_res_q.next,
902 struct ipr_resource_entry, queue);
904 list_del(&res->queue);
905 ipr_init_res_entry(res);
906 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
909 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
911 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
913 res->del_from_ml = 1;
914 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
915 if (ioa_cfg->allow_ml_add_del)
916 schedule_work(&ioa_cfg->work_q);
918 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
919 } else if (!res->sdev) {
921 if (ioa_cfg->allow_ml_add_del)
922 schedule_work(&ioa_cfg->work_q);
925 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
929 * ipr_process_ccn - Op done function for a CCN.
930 * @ipr_cmd: ipr command struct
932 * This function is the op done function for a configuration
933 * change notification host controlled async from the adapter.
938 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
940 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
941 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
942 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
944 list_del(&hostrcb->queue);
945 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
948 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
949 dev_err(&ioa_cfg->pdev->dev,
950 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
952 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
954 ipr_handle_config_change(ioa_cfg, hostrcb);
959 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
960 * @i: index into buffer
961 * @buf: string to modify
963 * This function will strip all trailing whitespace, pad the end
964 * of the string with a single space, and NULL terminate the string.
967 * new length of string
969 static int strip_and_pad_whitespace(int i, char *buf)
971 while (i && buf[i] == ' ')
979 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
980 * @prefix: string to print at start of printk
981 * @hostrcb: hostrcb pointer
982 * @vpd: vendor/product id/sn struct
987 static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
990 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
993 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
994 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
996 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
997 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
999 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1000 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1002 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1006 * ipr_log_vpd - Log the passed VPD to the error log.
1007 * @vpd: vendor/product id/sn struct
1012 static void ipr_log_vpd(struct ipr_vpd *vpd)
1014 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1015 + IPR_SERIAL_NUM_LEN];
1017 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1018 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
1020 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1021 ipr_err("Vendor/Product ID: %s\n", buffer);
1023 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
1024 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1025 ipr_err(" Serial Number: %s\n", buffer);
1029 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1030 * @prefix: string to print at start of printk
1031 * @hostrcb: hostrcb pointer
1032 * @vpd: vendor/product id/sn/wwn struct
1037 static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1038 struct ipr_ext_vpd *vpd)
1040 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1041 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1042 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1046 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1047 * @vpd: vendor/product id/sn/wwn struct
1052 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1054 ipr_log_vpd(&vpd->vpd);
1055 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1056 be32_to_cpu(vpd->wwid[1]));
1060 * ipr_log_enhanced_cache_error - Log a cache error.
1061 * @ioa_cfg: ioa config struct
1062 * @hostrcb: hostrcb struct
1067 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1068 struct ipr_hostrcb *hostrcb)
1070 struct ipr_hostrcb_type_12_error *error =
1071 &hostrcb->hcam.u.error.u.type_12_error;
1073 ipr_err("-----Current Configuration-----\n");
1074 ipr_err("Cache Directory Card Information:\n");
1075 ipr_log_ext_vpd(&error->ioa_vpd);
1076 ipr_err("Adapter Card Information:\n");
1077 ipr_log_ext_vpd(&error->cfc_vpd);
1079 ipr_err("-----Expected Configuration-----\n");
1080 ipr_err("Cache Directory Card Information:\n");
1081 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1082 ipr_err("Adapter Card Information:\n");
1083 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1085 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1086 be32_to_cpu(error->ioa_data[0]),
1087 be32_to_cpu(error->ioa_data[1]),
1088 be32_to_cpu(error->ioa_data[2]));
1092 * ipr_log_cache_error - Log a cache error.
1093 * @ioa_cfg: ioa config struct
1094 * @hostrcb: hostrcb struct
1099 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1100 struct ipr_hostrcb *hostrcb)
1102 struct ipr_hostrcb_type_02_error *error =
1103 &hostrcb->hcam.u.error.u.type_02_error;
1105 ipr_err("-----Current Configuration-----\n");
1106 ipr_err("Cache Directory Card Information:\n");
1107 ipr_log_vpd(&error->ioa_vpd);
1108 ipr_err("Adapter Card Information:\n");
1109 ipr_log_vpd(&error->cfc_vpd);
1111 ipr_err("-----Expected Configuration-----\n");
1112 ipr_err("Cache Directory Card Information:\n");
1113 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1114 ipr_err("Adapter Card Information:\n");
1115 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1117 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1118 be32_to_cpu(error->ioa_data[0]),
1119 be32_to_cpu(error->ioa_data[1]),
1120 be32_to_cpu(error->ioa_data[2]));
1124 * ipr_log_enhanced_config_error - Log a configuration error.
1125 * @ioa_cfg: ioa config struct
1126 * @hostrcb: hostrcb struct
1131 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1132 struct ipr_hostrcb *hostrcb)
1134 int errors_logged, i;
1135 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1136 struct ipr_hostrcb_type_13_error *error;
1138 error = &hostrcb->hcam.u.error.u.type_13_error;
1139 errors_logged = be32_to_cpu(error->errors_logged);
1141 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1142 be32_to_cpu(error->errors_detected), errors_logged);
1144 dev_entry = error->dev;
1146 for (i = 0; i < errors_logged; i++, dev_entry++) {
1149 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1150 ipr_log_ext_vpd(&dev_entry->vpd);
1152 ipr_err("-----New Device Information-----\n");
1153 ipr_log_ext_vpd(&dev_entry->new_vpd);
1155 ipr_err("Cache Directory Card Information:\n");
1156 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1158 ipr_err("Adapter Card Information:\n");
1159 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1164 * ipr_log_config_error - Log a configuration error.
1165 * @ioa_cfg: ioa config struct
1166 * @hostrcb: hostrcb struct
1171 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1172 struct ipr_hostrcb *hostrcb)
1174 int errors_logged, i;
1175 struct ipr_hostrcb_device_data_entry *dev_entry;
1176 struct ipr_hostrcb_type_03_error *error;
1178 error = &hostrcb->hcam.u.error.u.type_03_error;
1179 errors_logged = be32_to_cpu(error->errors_logged);
1181 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1182 be32_to_cpu(error->errors_detected), errors_logged);
1184 dev_entry = error->dev;
1186 for (i = 0; i < errors_logged; i++, dev_entry++) {
1189 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1190 ipr_log_vpd(&dev_entry->vpd);
1192 ipr_err("-----New Device Information-----\n");
1193 ipr_log_vpd(&dev_entry->new_vpd);
1195 ipr_err("Cache Directory Card Information:\n");
1196 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1198 ipr_err("Adapter Card Information:\n");
1199 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1201 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1202 be32_to_cpu(dev_entry->ioa_data[0]),
1203 be32_to_cpu(dev_entry->ioa_data[1]),
1204 be32_to_cpu(dev_entry->ioa_data[2]),
1205 be32_to_cpu(dev_entry->ioa_data[3]),
1206 be32_to_cpu(dev_entry->ioa_data[4]));
1211 * ipr_log_enhanced_array_error - Log an array configuration error.
1212 * @ioa_cfg: ioa config struct
1213 * @hostrcb: hostrcb struct
1218 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1219 struct ipr_hostrcb *hostrcb)
1222 struct ipr_hostrcb_type_14_error *error;
1223 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1224 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1226 error = &hostrcb->hcam.u.error.u.type_14_error;
1230 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1231 error->protection_level,
1232 ioa_cfg->host->host_no,
1233 error->last_func_vset_res_addr.bus,
1234 error->last_func_vset_res_addr.target,
1235 error->last_func_vset_res_addr.lun);
1239 array_entry = error->array_member;
1240 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1241 sizeof(error->array_member));
1243 for (i = 0; i < num_entries; i++, array_entry++) {
1244 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1247 if (be32_to_cpu(error->exposed_mode_adn) == i)
1248 ipr_err("Exposed Array Member %d:\n", i);
1250 ipr_err("Array Member %d:\n", i);
1252 ipr_log_ext_vpd(&array_entry->vpd);
1253 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1254 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1255 "Expected Location");
1262 * ipr_log_array_error - Log an array configuration error.
1263 * @ioa_cfg: ioa config struct
1264 * @hostrcb: hostrcb struct
1269 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1270 struct ipr_hostrcb *hostrcb)
1273 struct ipr_hostrcb_type_04_error *error;
1274 struct ipr_hostrcb_array_data_entry *array_entry;
1275 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1277 error = &hostrcb->hcam.u.error.u.type_04_error;
1281 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1282 error->protection_level,
1283 ioa_cfg->host->host_no,
1284 error->last_func_vset_res_addr.bus,
1285 error->last_func_vset_res_addr.target,
1286 error->last_func_vset_res_addr.lun);
1290 array_entry = error->array_member;
1292 for (i = 0; i < 18; i++) {
1293 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1296 if (be32_to_cpu(error->exposed_mode_adn) == i)
1297 ipr_err("Exposed Array Member %d:\n", i);
1299 ipr_err("Array Member %d:\n", i);
1301 ipr_log_vpd(&array_entry->vpd);
1303 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1304 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1305 "Expected Location");
1310 array_entry = error->array_member2;
1317 * ipr_log_hex_data - Log additional hex IOA error data.
1318 * @ioa_cfg: ioa config struct
1319 * @data: IOA error data
1325 static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
1332 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1333 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1335 for (i = 0; i < len / 4; i += 4) {
1336 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1337 be32_to_cpu(data[i]),
1338 be32_to_cpu(data[i+1]),
1339 be32_to_cpu(data[i+2]),
1340 be32_to_cpu(data[i+3]));
1345 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1346 * @ioa_cfg: ioa config struct
1347 * @hostrcb: hostrcb struct
1352 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1353 struct ipr_hostrcb *hostrcb)
1355 struct ipr_hostrcb_type_17_error *error;
1357 error = &hostrcb->hcam.u.error.u.type_17_error;
1358 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1359 strstrip(error->failure_reason);
1361 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1362 be32_to_cpu(hostrcb->hcam.u.error.prc));
1363 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1364 ipr_log_hex_data(ioa_cfg, error->data,
1365 be32_to_cpu(hostrcb->hcam.length) -
1366 (offsetof(struct ipr_hostrcb_error, u) +
1367 offsetof(struct ipr_hostrcb_type_17_error, data)));
1371 * ipr_log_dual_ioa_error - Log a dual adapter error.
1372 * @ioa_cfg: ioa config struct
1373 * @hostrcb: hostrcb struct
1378 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1379 struct ipr_hostrcb *hostrcb)
1381 struct ipr_hostrcb_type_07_error *error;
1383 error = &hostrcb->hcam.u.error.u.type_07_error;
1384 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1385 strstrip(error->failure_reason);
1387 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1388 be32_to_cpu(hostrcb->hcam.u.error.prc));
1389 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1390 ipr_log_hex_data(ioa_cfg, error->data,
1391 be32_to_cpu(hostrcb->hcam.length) -
1392 (offsetof(struct ipr_hostrcb_error, u) +
1393 offsetof(struct ipr_hostrcb_type_07_error, data)));
1396 static const struct {
1399 } path_active_desc[] = {
1400 { IPR_PATH_NO_INFO, "Path" },
1401 { IPR_PATH_ACTIVE, "Active path" },
1402 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1405 static const struct {
1408 } path_state_desc[] = {
1409 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1410 { IPR_PATH_HEALTHY, "is healthy" },
1411 { IPR_PATH_DEGRADED, "is degraded" },
1412 { IPR_PATH_FAILED, "is failed" }
1416 * ipr_log_fabric_path - Log a fabric path error
1417 * @hostrcb: hostrcb struct
1418 * @fabric: fabric descriptor
1423 static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1424 struct ipr_hostrcb_fabric_desc *fabric)
1427 u8 path_state = fabric->path_state;
1428 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1429 u8 state = path_state & IPR_PATH_STATE_MASK;
1431 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1432 if (path_active_desc[i].active != active)
1435 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1436 if (path_state_desc[j].state != state)
1439 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
1440 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
1441 path_active_desc[i].desc, path_state_desc[j].desc,
1443 } else if (fabric->cascaded_expander == 0xff) {
1444 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
1445 path_active_desc[i].desc, path_state_desc[j].desc,
1446 fabric->ioa_port, fabric->phy);
1447 } else if (fabric->phy == 0xff) {
1448 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
1449 path_active_desc[i].desc, path_state_desc[j].desc,
1450 fabric->ioa_port, fabric->cascaded_expander);
1452 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1453 path_active_desc[i].desc, path_state_desc[j].desc,
1454 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1460 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
1461 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1464 static const struct {
1467 } path_type_desc[] = {
1468 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
1469 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
1470 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
1471 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
1474 static const struct {
1477 } path_status_desc[] = {
1478 { IPR_PATH_CFG_NO_PROB, "Functional" },
1479 { IPR_PATH_CFG_DEGRADED, "Degraded" },
1480 { IPR_PATH_CFG_FAILED, "Failed" },
1481 { IPR_PATH_CFG_SUSPECT, "Suspect" },
1482 { IPR_PATH_NOT_DETECTED, "Missing" },
1483 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
1486 static const char *link_rate[] = {
1489 "phy reset problem",
1506 * ipr_log_path_elem - Log a fabric path element.
1507 * @hostrcb: hostrcb struct
1508 * @cfg: fabric path element struct
1513 static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
1514 struct ipr_hostrcb_config_element *cfg)
1517 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
1518 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
1520 if (type == IPR_PATH_CFG_NOT_EXIST)
1523 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
1524 if (path_type_desc[i].type != type)
1527 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
1528 if (path_status_desc[j].status != status)
1531 if (type == IPR_PATH_CFG_IOA_PORT) {
1532 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
1533 path_status_desc[j].desc, path_type_desc[i].desc,
1534 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1535 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1537 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
1538 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
1539 path_status_desc[j].desc, path_type_desc[i].desc,
1540 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1541 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1542 } else if (cfg->cascaded_expander == 0xff) {
1543 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
1544 "WWN=%08X%08X\n", path_status_desc[j].desc,
1545 path_type_desc[i].desc, cfg->phy,
1546 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1547 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1548 } else if (cfg->phy == 0xff) {
1549 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
1550 "WWN=%08X%08X\n", path_status_desc[j].desc,
1551 path_type_desc[i].desc, cfg->cascaded_expander,
1552 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1553 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1555 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
1556 "WWN=%08X%08X\n", path_status_desc[j].desc,
1557 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
1558 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1559 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1566 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
1567 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
1568 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1569 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1573 * ipr_log_fabric_error - Log a fabric error.
1574 * @ioa_cfg: ioa config struct
1575 * @hostrcb: hostrcb struct
1580 static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
1581 struct ipr_hostrcb *hostrcb)
1583 struct ipr_hostrcb_type_20_error *error;
1584 struct ipr_hostrcb_fabric_desc *fabric;
1585 struct ipr_hostrcb_config_element *cfg;
1588 error = &hostrcb->hcam.u.error.u.type_20_error;
1589 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1590 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
1592 add_len = be32_to_cpu(hostrcb->hcam.length) -
1593 (offsetof(struct ipr_hostrcb_error, u) +
1594 offsetof(struct ipr_hostrcb_type_20_error, desc));
1596 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
1597 ipr_log_fabric_path(hostrcb, fabric);
1598 for_each_fabric_cfg(fabric, cfg)
1599 ipr_log_path_elem(hostrcb, cfg);
1601 add_len -= be16_to_cpu(fabric->length);
1602 fabric = (struct ipr_hostrcb_fabric_desc *)
1603 ((unsigned long)fabric + be16_to_cpu(fabric->length));
1606 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
1610 * ipr_log_generic_error - Log an adapter error.
1611 * @ioa_cfg: ioa config struct
1612 * @hostrcb: hostrcb struct
1617 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
1618 struct ipr_hostrcb *hostrcb)
1620 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
1621 be32_to_cpu(hostrcb->hcam.length));
1625 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
1628 * This function will return the index of into the ipr_error_table
1629 * for the specified IOASC. If the IOASC is not in the table,
1630 * 0 will be returned, which points to the entry used for unknown errors.
1633 * index into the ipr_error_table
1635 static u32 ipr_get_error(u32 ioasc)
1639 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
1640 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
1647 * ipr_handle_log_data - Log an adapter error.
1648 * @ioa_cfg: ioa config struct
1649 * @hostrcb: hostrcb struct
1651 * This function logs an adapter error to the system.
1656 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
1657 struct ipr_hostrcb *hostrcb)
1662 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
1665 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
1666 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
1668 ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1670 if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
1671 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
1672 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
1673 scsi_report_bus_reset(ioa_cfg->host,
1674 hostrcb->hcam.u.error.failing_dev_res_addr.bus);
1677 error_index = ipr_get_error(ioasc);
1679 if (!ipr_error_table[error_index].log_hcam)
1682 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
1684 /* Set indication we have logged an error */
1685 ioa_cfg->errors_logged++;
1687 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
1689 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
1690 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
1692 switch (hostrcb->hcam.overlay_id) {
1693 case IPR_HOST_RCB_OVERLAY_ID_2:
1694 ipr_log_cache_error(ioa_cfg, hostrcb);
1696 case IPR_HOST_RCB_OVERLAY_ID_3:
1697 ipr_log_config_error(ioa_cfg, hostrcb);
1699 case IPR_HOST_RCB_OVERLAY_ID_4:
1700 case IPR_HOST_RCB_OVERLAY_ID_6:
1701 ipr_log_array_error(ioa_cfg, hostrcb);
1703 case IPR_HOST_RCB_OVERLAY_ID_7:
1704 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
1706 case IPR_HOST_RCB_OVERLAY_ID_12:
1707 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
1709 case IPR_HOST_RCB_OVERLAY_ID_13:
1710 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
1712 case IPR_HOST_RCB_OVERLAY_ID_14:
1713 case IPR_HOST_RCB_OVERLAY_ID_16:
1714 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
1716 case IPR_HOST_RCB_OVERLAY_ID_17:
1717 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
1719 case IPR_HOST_RCB_OVERLAY_ID_20:
1720 ipr_log_fabric_error(ioa_cfg, hostrcb);
1722 case IPR_HOST_RCB_OVERLAY_ID_1:
1723 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
1725 ipr_log_generic_error(ioa_cfg, hostrcb);
1731 * ipr_process_error - Op done function for an adapter error log.
1732 * @ipr_cmd: ipr command struct
1734 * This function is the op done function for an error log host
1735 * controlled async from the adapter. It will log the error and
1736 * send the HCAM back to the adapter.
1741 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
1743 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1744 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1745 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
1746 u32 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1748 list_del(&hostrcb->queue);
1749 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1752 ipr_handle_log_data(ioa_cfg, hostrcb);
1753 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
1754 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
1755 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
1756 dev_err(&ioa_cfg->pdev->dev,
1757 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1760 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
1764 * ipr_timeout - An internally generated op has timed out.
1765 * @ipr_cmd: ipr command struct
1767 * This function blocks host requests and initiates an
1773 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
1775 unsigned long lock_flags = 0;
1776 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1779 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1781 ioa_cfg->errors_logged++;
1782 dev_err(&ioa_cfg->pdev->dev,
1783 "Adapter being reset due to command timeout.\n");
1785 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1786 ioa_cfg->sdt_state = GET_DUMP;
1788 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
1789 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1791 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1796 * ipr_oper_timeout - Adapter timed out transitioning to operational
1797 * @ipr_cmd: ipr command struct
1799 * This function blocks host requests and initiates an
1805 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
1807 unsigned long lock_flags = 0;
1808 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1811 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1813 ioa_cfg->errors_logged++;
1814 dev_err(&ioa_cfg->pdev->dev,
1815 "Adapter timed out transitioning to operational.\n");
1817 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1818 ioa_cfg->sdt_state = GET_DUMP;
1820 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
1822 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
1823 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1826 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1831 * ipr_reset_reload - Reset/Reload the IOA
1832 * @ioa_cfg: ioa config struct
1833 * @shutdown_type: shutdown type
1835 * This function resets the adapter and re-initializes it.
1836 * This function assumes that all new host commands have been stopped.
1840 static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
1841 enum ipr_shutdown_type shutdown_type)
1843 if (!ioa_cfg->in_reset_reload)
1844 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
1846 spin_unlock_irq(ioa_cfg->host->host_lock);
1847 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
1848 spin_lock_irq(ioa_cfg->host->host_lock);
1850 /* If we got hit with a host reset while we were already resetting
1851 the adapter for some reason, and the reset failed. */
1852 if (ioa_cfg->ioa_is_dead) {
1861 * ipr_find_ses_entry - Find matching SES in SES table
1862 * @res: resource entry struct of SES
1865 * pointer to SES table entry / NULL on failure
1867 static const struct ipr_ses_table_entry *
1868 ipr_find_ses_entry(struct ipr_resource_entry *res)
1871 const struct ipr_ses_table_entry *ste = ipr_ses_table;
1873 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
1874 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
1875 if (ste->compare_product_id_byte[j] == 'X') {
1876 if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
1884 if (matches == IPR_PROD_ID_LEN)
1892 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
1893 * @ioa_cfg: ioa config struct
1895 * @bus_width: bus width
1898 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
1899 * For a 2-byte wide SCSI bus, the maximum transfer speed is
1900 * twice the maximum transfer rate (e.g. for a wide enabled bus,
1901 * max 160MHz = max 320MB/sec).
1903 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
1905 struct ipr_resource_entry *res;
1906 const struct ipr_ses_table_entry *ste;
1907 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
1909 /* Loop through each config table entry in the config table buffer */
1910 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1911 if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
1914 if (bus != res->cfgte.res_addr.bus)
1917 if (!(ste = ipr_find_ses_entry(res)))
1920 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
1923 return max_xfer_rate;
1927 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
1928 * @ioa_cfg: ioa config struct
1929 * @max_delay: max delay in micro-seconds to wait
1931 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
1934 * 0 on success / other on failure
1936 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
1938 volatile u32 pcii_reg;
1941 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
1942 while (delay < max_delay) {
1943 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
1945 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
1948 /* udelay cannot be used if delay is more than a few milliseconds */
1949 if ((delay / 1000) > MAX_UDELAY_MS)
1950 mdelay(delay / 1000);
1960 * ipr_get_ldump_data_section - Dump IOA memory
1961 * @ioa_cfg: ioa config struct
1962 * @start_addr: adapter address to dump
1963 * @dest: destination kernel buffer
1964 * @length_in_words: length to dump in 4 byte words
1967 * 0 on success / -EIO on failure
1969 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
1971 __be32 *dest, u32 length_in_words)
1973 volatile u32 temp_pcii_reg;
1976 /* Write IOA interrupt reg starting LDUMP state */
1977 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
1978 ioa_cfg->regs.set_uproc_interrupt_reg);
1980 /* Wait for IO debug acknowledge */
1981 if (ipr_wait_iodbg_ack(ioa_cfg,
1982 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
1983 dev_err(&ioa_cfg->pdev->dev,
1984 "IOA dump long data transfer timeout\n");
1988 /* Signal LDUMP interlocked - clear IO debug ack */
1989 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1990 ioa_cfg->regs.clr_interrupt_reg);
1992 /* Write Mailbox with starting address */
1993 writel(start_addr, ioa_cfg->ioa_mailbox);
1995 /* Signal address valid - clear IOA Reset alert */
1996 writel(IPR_UPROCI_RESET_ALERT,
1997 ioa_cfg->regs.clr_uproc_interrupt_reg);
1999 for (i = 0; i < length_in_words; i++) {
2000 /* Wait for IO debug acknowledge */
2001 if (ipr_wait_iodbg_ack(ioa_cfg,
2002 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2003 dev_err(&ioa_cfg->pdev->dev,
2004 "IOA dump short data transfer timeout\n");
2008 /* Read data from mailbox and increment destination pointer */
2009 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2012 /* For all but the last word of data, signal data received */
2013 if (i < (length_in_words - 1)) {
2014 /* Signal dump data received - Clear IO debug Ack */
2015 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2016 ioa_cfg->regs.clr_interrupt_reg);
2020 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2021 writel(IPR_UPROCI_RESET_ALERT,
2022 ioa_cfg->regs.set_uproc_interrupt_reg);
2024 writel(IPR_UPROCI_IO_DEBUG_ALERT,
2025 ioa_cfg->regs.clr_uproc_interrupt_reg);
2027 /* Signal dump data received - Clear IO debug Ack */
2028 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2029 ioa_cfg->regs.clr_interrupt_reg);
2031 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2032 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2034 readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
2036 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2046 #ifdef CONFIG_SCSI_IPR_DUMP
2048 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2049 * @ioa_cfg: ioa config struct
2050 * @pci_address: adapter address
2051 * @length: length of data to copy
2053 * Copy data from PCI adapter to kernel buffer.
2054 * Note: length MUST be a 4 byte multiple
2056 * 0 on success / other on failure
2058 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2059 unsigned long pci_address, u32 length)
2061 int bytes_copied = 0;
2062 int cur_len, rc, rem_len, rem_page_len;
2064 unsigned long lock_flags = 0;
2065 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2067 while (bytes_copied < length &&
2068 (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
2069 if (ioa_dump->page_offset >= PAGE_SIZE ||
2070 ioa_dump->page_offset == 0) {
2071 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2075 return bytes_copied;
2078 ioa_dump->page_offset = 0;
2079 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2080 ioa_dump->next_page_index++;
2082 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2084 rem_len = length - bytes_copied;
2085 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2086 cur_len = min(rem_len, rem_page_len);
2088 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2089 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2092 rc = ipr_get_ldump_data_section(ioa_cfg,
2093 pci_address + bytes_copied,
2094 &page[ioa_dump->page_offset / 4],
2095 (cur_len / sizeof(u32)));
2097 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2100 ioa_dump->page_offset += cur_len;
2101 bytes_copied += cur_len;
2109 return bytes_copied;
2113 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2114 * @hdr: dump entry header struct
2119 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2121 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2123 hdr->offset = sizeof(*hdr);
2124 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2128 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2129 * @ioa_cfg: ioa config struct
2130 * @driver_dump: driver dump struct
2135 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2136 struct ipr_driver_dump *driver_dump)
2138 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2140 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2141 driver_dump->ioa_type_entry.hdr.len =
2142 sizeof(struct ipr_dump_ioa_type_entry) -
2143 sizeof(struct ipr_dump_entry_header);
2144 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2145 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2146 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2147 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2148 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2149 ucode_vpd->minor_release[1];
2150 driver_dump->hdr.num_entries++;
2154 * ipr_dump_version_data - Fill in the driver version in the dump.
2155 * @ioa_cfg: ioa config struct
2156 * @driver_dump: driver dump struct
2161 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2162 struct ipr_driver_dump *driver_dump)
2164 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2165 driver_dump->version_entry.hdr.len =
2166 sizeof(struct ipr_dump_version_entry) -
2167 sizeof(struct ipr_dump_entry_header);
2168 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2169 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2170 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2171 driver_dump->hdr.num_entries++;
2175 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2176 * @ioa_cfg: ioa config struct
2177 * @driver_dump: driver dump struct
2182 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
2183 struct ipr_driver_dump *driver_dump)
2185 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
2186 driver_dump->trace_entry.hdr.len =
2187 sizeof(struct ipr_dump_trace_entry) -
2188 sizeof(struct ipr_dump_entry_header);
2189 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2190 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
2191 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
2192 driver_dump->hdr.num_entries++;
2196 * ipr_dump_location_data - Fill in the IOA location in the dump.
2197 * @ioa_cfg: ioa config struct
2198 * @driver_dump: driver dump struct
2203 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
2204 struct ipr_driver_dump *driver_dump)
2206 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
2207 driver_dump->location_entry.hdr.len =
2208 sizeof(struct ipr_dump_location_entry) -
2209 sizeof(struct ipr_dump_entry_header);
2210 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2211 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
2212 strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
2213 driver_dump->hdr.num_entries++;
2217 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2218 * @ioa_cfg: ioa config struct
2219 * @dump: dump struct
2224 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
2226 unsigned long start_addr, sdt_word;
2227 unsigned long lock_flags = 0;
2228 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
2229 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
2230 u32 num_entries, start_off, end_off;
2231 u32 bytes_to_copy, bytes_copied, rc;
2232 struct ipr_sdt *sdt;
2237 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2239 if (ioa_cfg->sdt_state != GET_DUMP) {
2240 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2244 start_addr = readl(ioa_cfg->ioa_mailbox);
2246 if (!ipr_sdt_is_fmt2(start_addr)) {
2247 dev_err(&ioa_cfg->pdev->dev,
2248 "Invalid dump table format: %lx\n", start_addr);
2249 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2253 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
2255 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
2257 /* Initialize the overall dump header */
2258 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
2259 driver_dump->hdr.num_entries = 1;
2260 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
2261 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
2262 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
2263 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
2265 ipr_dump_version_data(ioa_cfg, driver_dump);
2266 ipr_dump_location_data(ioa_cfg, driver_dump);
2267 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
2268 ipr_dump_trace_data(ioa_cfg, driver_dump);
2270 /* Update dump_header */
2271 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
2273 /* IOA Dump entry */
2274 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
2275 ioa_dump->format = IPR_SDT_FMT2;
2276 ioa_dump->hdr.len = 0;
2277 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2278 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
2280 /* First entries in sdt are actually a list of dump addresses and
2281 lengths to gather the real dump data. sdt represents the pointer
2282 to the ioa generated dump table. Dump data will be extracted based
2283 on entries in this table */
2284 sdt = &ioa_dump->sdt;
2286 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
2287 sizeof(struct ipr_sdt) / sizeof(__be32));
2289 /* Smart Dump table is ready to use and the first entry is valid */
2290 if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
2291 dev_err(&ioa_cfg->pdev->dev,
2292 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
2293 rc, be32_to_cpu(sdt->hdr.state));
2294 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
2295 ioa_cfg->sdt_state = DUMP_OBTAINED;
2296 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2300 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
2302 if (num_entries > IPR_NUM_SDT_ENTRIES)
2303 num_entries = IPR_NUM_SDT_ENTRIES;
2305 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2307 for (i = 0; i < num_entries; i++) {
2308 if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
2309 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2313 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
2314 sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
2315 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
2316 end_off = be32_to_cpu(sdt->entry[i].end_offset);
2318 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
2319 bytes_to_copy = end_off - start_off;
2320 if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
2321 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
2325 /* Copy data from adapter to driver buffers */
2326 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
2329 ioa_dump->hdr.len += bytes_copied;
2331 if (bytes_copied != bytes_to_copy) {
2332 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2339 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
2341 /* Update dump_header */
2342 driver_dump->hdr.len += ioa_dump->hdr.len;
2344 ioa_cfg->sdt_state = DUMP_OBTAINED;
2349 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
2353 * ipr_release_dump - Free adapter dump memory
2354 * @kref: kref struct
2359 static void ipr_release_dump(struct kref *kref)
2361 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
2362 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
2363 unsigned long lock_flags = 0;
2367 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2368 ioa_cfg->dump = NULL;
2369 ioa_cfg->sdt_state = INACTIVE;
2370 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2372 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
2373 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
2380 * ipr_worker_thread - Worker thread
2381 * @work: ioa config struct
2383 * Called at task level from a work thread. This function takes care
2384 * of adding and removing device from the mid-layer as configuration
2385 * changes are detected by the adapter.
2390 static void ipr_worker_thread(struct work_struct *work)
2392 unsigned long lock_flags;
2393 struct ipr_resource_entry *res;
2394 struct scsi_device *sdev;
2395 struct ipr_dump *dump;
2396 struct ipr_ioa_cfg *ioa_cfg =
2397 container_of(work, struct ipr_ioa_cfg, work_q);
2398 u8 bus, target, lun;
2402 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2404 if (ioa_cfg->sdt_state == GET_DUMP) {
2405 dump = ioa_cfg->dump;
2407 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2410 kref_get(&dump->kref);
2411 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2412 ipr_get_ioa_dump(ioa_cfg, dump);
2413 kref_put(&dump->kref, ipr_release_dump);
2415 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2416 if (ioa_cfg->sdt_state == DUMP_OBTAINED)
2417 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2418 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2425 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
2426 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2430 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2431 if (res->del_from_ml && res->sdev) {
2434 if (!scsi_device_get(sdev)) {
2435 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
2436 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2437 scsi_remove_device(sdev);
2438 scsi_device_put(sdev);
2439 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2446 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2447 if (res->add_to_ml) {
2448 bus = res->cfgte.res_addr.bus;
2449 target = res->cfgte.res_addr.target;
2450 lun = res->cfgte.res_addr.lun;
2452 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2453 scsi_add_device(ioa_cfg->host, bus, target, lun);
2454 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2459 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2460 kobject_uevent(&ioa_cfg->host->shost_classdev.kobj, KOBJ_CHANGE);
2464 #ifdef CONFIG_SCSI_IPR_TRACE
2466 * ipr_read_trace - Dump the adapter trace
2467 * @kobj: kobject struct
2470 * @count: buffer size
2473 * number of bytes printed to buffer
2475 static ssize_t ipr_read_trace(struct kobject *kobj, char *buf,
2476 loff_t off, size_t count)
2478 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2479 struct Scsi_Host *shost = class_to_shost(cdev);
2480 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2481 unsigned long lock_flags = 0;
2482 int size = IPR_TRACE_SIZE;
2483 char *src = (char *)ioa_cfg->trace;
2487 if (off + count > size) {
2492 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2493 memcpy(buf, &src[off], count);
2494 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2498 static struct bin_attribute ipr_trace_attr = {
2504 .read = ipr_read_trace,
2508 static const struct {
2509 enum ipr_cache_state state;
2511 } cache_state [] = {
2512 { CACHE_NONE, "none" },
2513 { CACHE_DISABLED, "disabled" },
2514 { CACHE_ENABLED, "enabled" }
2518 * ipr_show_write_caching - Show the write caching attribute
2519 * @class_dev: class device struct
2523 * number of bytes printed to buffer
2525 static ssize_t ipr_show_write_caching(struct class_device *class_dev, char *buf)
2527 struct Scsi_Host *shost = class_to_shost(class_dev);
2528 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2529 unsigned long lock_flags = 0;
2532 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2533 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2534 if (cache_state[i].state == ioa_cfg->cache_state) {
2535 len = snprintf(buf, PAGE_SIZE, "%s\n", cache_state[i].name);
2539 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2545 * ipr_store_write_caching - Enable/disable adapter write cache
2546 * @class_dev: class_device struct
2548 * @count: buffer size
2550 * This function will enable/disable adapter write cache.
2553 * count on success / other on failure
2555 static ssize_t ipr_store_write_caching(struct class_device *class_dev,
2556 const char *buf, size_t count)
2558 struct Scsi_Host *shost = class_to_shost(class_dev);
2559 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2560 unsigned long lock_flags = 0;
2561 enum ipr_cache_state new_state = CACHE_INVALID;
2564 if (!capable(CAP_SYS_ADMIN))
2566 if (ioa_cfg->cache_state == CACHE_NONE)
2569 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2570 if (!strncmp(cache_state[i].name, buf, strlen(cache_state[i].name))) {
2571 new_state = cache_state[i].state;
2576 if (new_state != CACHE_DISABLED && new_state != CACHE_ENABLED)
2579 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2580 if (ioa_cfg->cache_state == new_state) {
2581 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2585 ioa_cfg->cache_state = new_state;
2586 dev_info(&ioa_cfg->pdev->dev, "%s adapter write cache.\n",
2587 new_state == CACHE_ENABLED ? "Enabling" : "Disabling");
2588 if (!ioa_cfg->in_reset_reload)
2589 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2590 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2591 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2596 static struct class_device_attribute ipr_ioa_cache_attr = {
2598 .name = "write_cache",
2599 .mode = S_IRUGO | S_IWUSR,
2601 .show = ipr_show_write_caching,
2602 .store = ipr_store_write_caching
2606 * ipr_show_fw_version - Show the firmware version
2607 * @class_dev: class device struct
2611 * number of bytes printed to buffer
2613 static ssize_t ipr_show_fw_version(struct class_device *class_dev, char *buf)
2615 struct Scsi_Host *shost = class_to_shost(class_dev);
2616 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2617 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2618 unsigned long lock_flags = 0;
2621 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2622 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
2623 ucode_vpd->major_release, ucode_vpd->card_type,
2624 ucode_vpd->minor_release[0],
2625 ucode_vpd->minor_release[1]);
2626 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2630 static struct class_device_attribute ipr_fw_version_attr = {
2632 .name = "fw_version",
2635 .show = ipr_show_fw_version,
2639 * ipr_show_log_level - Show the adapter's error logging level
2640 * @class_dev: class device struct
2644 * number of bytes printed to buffer
2646 static ssize_t ipr_show_log_level(struct class_device *class_dev, char *buf)
2648 struct Scsi_Host *shost = class_to_shost(class_dev);
2649 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2650 unsigned long lock_flags = 0;
2653 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2654 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
2655 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2660 * ipr_store_log_level - Change the adapter's error logging level
2661 * @class_dev: class device struct
2665 * number of bytes printed to buffer
2667 static ssize_t ipr_store_log_level(struct class_device *class_dev,
2668 const char *buf, size_t count)
2670 struct Scsi_Host *shost = class_to_shost(class_dev);
2671 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2672 unsigned long lock_flags = 0;
2674 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2675 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
2676 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2680 static struct class_device_attribute ipr_log_level_attr = {
2682 .name = "log_level",
2683 .mode = S_IRUGO | S_IWUSR,
2685 .show = ipr_show_log_level,
2686 .store = ipr_store_log_level
2690 * ipr_store_diagnostics - IOA Diagnostics interface
2691 * @class_dev: class_device struct
2693 * @count: buffer size
2695 * This function will reset the adapter and wait a reasonable
2696 * amount of time for any errors that the adapter might log.
2699 * count on success / other on failure
2701 static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
2702 const char *buf, size_t count)
2704 struct Scsi_Host *shost = class_to_shost(class_dev);
2705 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2706 unsigned long lock_flags = 0;
2709 if (!capable(CAP_SYS_ADMIN))
2712 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2713 while(ioa_cfg->in_reset_reload) {
2714 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2715 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2716 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2719 ioa_cfg->errors_logged = 0;
2720 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2722 if (ioa_cfg->in_reset_reload) {
2723 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2724 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2726 /* Wait for a second for any errors to be logged */
2729 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2733 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2734 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
2736 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2741 static struct class_device_attribute ipr_diagnostics_attr = {
2743 .name = "run_diagnostics",
2746 .store = ipr_store_diagnostics
2750 * ipr_show_adapter_state - Show the adapter's state
2751 * @class_dev: class device struct
2755 * number of bytes printed to buffer
2757 static ssize_t ipr_show_adapter_state(struct class_device *class_dev, char *buf)
2759 struct Scsi_Host *shost = class_to_shost(class_dev);
2760 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2761 unsigned long lock_flags = 0;
2764 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2765 if (ioa_cfg->ioa_is_dead)
2766 len = snprintf(buf, PAGE_SIZE, "offline\n");
2768 len = snprintf(buf, PAGE_SIZE, "online\n");
2769 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2774 * ipr_store_adapter_state - Change adapter state
2775 * @class_dev: class_device struct
2777 * @count: buffer size
2779 * This function will change the adapter's state.
2782 * count on success / other on failure
2784 static ssize_t ipr_store_adapter_state(struct class_device *class_dev,
2785 const char *buf, size_t count)
2787 struct Scsi_Host *shost = class_to_shost(class_dev);
2788 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2789 unsigned long lock_flags;
2792 if (!capable(CAP_SYS_ADMIN))
2795 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2796 if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
2797 ioa_cfg->ioa_is_dead = 0;
2798 ioa_cfg->reset_retries = 0;
2799 ioa_cfg->in_ioa_bringdown = 0;
2800 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2802 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2803 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2808 static struct class_device_attribute ipr_ioa_state_attr = {
2811 .mode = S_IRUGO | S_IWUSR,
2813 .show = ipr_show_adapter_state,
2814 .store = ipr_store_adapter_state
2818 * ipr_store_reset_adapter - Reset the adapter
2819 * @class_dev: class_device struct
2821 * @count: buffer size
2823 * This function will reset the adapter.
2826 * count on success / other on failure
2828 static ssize_t ipr_store_reset_adapter(struct class_device *class_dev,
2829 const char *buf, size_t count)
2831 struct Scsi_Host *shost = class_to_shost(class_dev);
2832 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2833 unsigned long lock_flags;
2836 if (!capable(CAP_SYS_ADMIN))
2839 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2840 if (!ioa_cfg->in_reset_reload)
2841 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2842 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2843 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2848 static struct class_device_attribute ipr_ioa_reset_attr = {
2850 .name = "reset_host",
2853 .store = ipr_store_reset_adapter
2857 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
2858 * @buf_len: buffer length
2860 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
2861 * list to use for microcode download
2864 * pointer to sglist / NULL on failure
2866 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
2868 int sg_size, order, bsize_elem, num_elem, i, j;
2869 struct ipr_sglist *sglist;
2870 struct scatterlist *scatterlist;
2873 /* Get the minimum size per scatter/gather element */
2874 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
2876 /* Get the actual size per element */
2877 order = get_order(sg_size);
2879 /* Determine the actual number of bytes per element */
2880 bsize_elem = PAGE_SIZE * (1 << order);
2882 /* Determine the actual number of sg entries needed */
2883 if (buf_len % bsize_elem)
2884 num_elem = (buf_len / bsize_elem) + 1;
2886 num_elem = buf_len / bsize_elem;
2888 /* Allocate a scatter/gather list for the DMA */
2889 sglist = kzalloc(sizeof(struct ipr_sglist) +
2890 (sizeof(struct scatterlist) * (num_elem - 1)),
2893 if (sglist == NULL) {
2898 scatterlist = sglist->scatterlist;
2900 sglist->order = order;
2901 sglist->num_sg = num_elem;
2903 /* Allocate a bunch of sg elements */
2904 for (i = 0; i < num_elem; i++) {
2905 page = alloc_pages(GFP_KERNEL, order);
2909 /* Free up what we already allocated */
2910 for (j = i - 1; j >= 0; j--)
2911 __free_pages(scatterlist[j].page, order);
2916 scatterlist[i].page = page;
2923 * ipr_free_ucode_buffer - Frees a microcode download buffer
2924 * @p_dnld: scatter/gather list pointer
2926 * Free a DMA'able ucode download buffer previously allocated with
2927 * ipr_alloc_ucode_buffer
2932 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
2936 for (i = 0; i < sglist->num_sg; i++)
2937 __free_pages(sglist->scatterlist[i].page, sglist->order);
2943 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
2944 * @sglist: scatter/gather list pointer
2945 * @buffer: buffer pointer
2946 * @len: buffer length
2948 * Copy a microcode image from a user buffer into a buffer allocated by
2949 * ipr_alloc_ucode_buffer
2952 * 0 on success / other on failure
2954 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
2955 u8 *buffer, u32 len)
2957 int bsize_elem, i, result = 0;
2958 struct scatterlist *scatterlist;
2961 /* Determine the actual number of bytes per element */
2962 bsize_elem = PAGE_SIZE * (1 << sglist->order);
2964 scatterlist = sglist->scatterlist;
2966 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
2967 kaddr = kmap(scatterlist[i].page);
2968 memcpy(kaddr, buffer, bsize_elem);
2969 kunmap(scatterlist[i].page);
2971 scatterlist[i].length = bsize_elem;
2979 if (len % bsize_elem) {
2980 kaddr = kmap(scatterlist[i].page);
2981 memcpy(kaddr, buffer, len % bsize_elem);
2982 kunmap(scatterlist[i].page);
2984 scatterlist[i].length = len % bsize_elem;
2987 sglist->buffer_len = len;
2992 * ipr_build_ucode_ioadl - Build a microcode download IOADL
2993 * @ipr_cmd: ipr command struct
2994 * @sglist: scatter/gather list
2996 * Builds a microcode download IOA data list (IOADL).
2999 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
3000 struct ipr_sglist *sglist)
3002 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3003 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
3004 struct scatterlist *scatterlist = sglist->scatterlist;
3007 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3008 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3009 ioarcb->write_data_transfer_length = cpu_to_be32(sglist->buffer_len);
3010 ioarcb->write_ioadl_len =
3011 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3013 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3014 ioadl[i].flags_and_data_len =
3015 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
3017 cpu_to_be32(sg_dma_address(&scatterlist[i]));
3020 ioadl[i-1].flags_and_data_len |=
3021 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3025 * ipr_update_ioa_ucode - Update IOA's microcode
3026 * @ioa_cfg: ioa config struct
3027 * @sglist: scatter/gather list
3029 * Initiate an adapter reset to update the IOA's microcode
3032 * 0 on success / -EIO on failure
3034 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3035 struct ipr_sglist *sglist)
3037 unsigned long lock_flags;
3039 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3040 while(ioa_cfg->in_reset_reload) {
3041 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3042 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3043 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3046 if (ioa_cfg->ucode_sglist) {
3047 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3048 dev_err(&ioa_cfg->pdev->dev,
3049 "Microcode download already in progress\n");
3053 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
3054 sglist->num_sg, DMA_TO_DEVICE);
3056 if (!sglist->num_dma_sg) {
3057 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3058 dev_err(&ioa_cfg->pdev->dev,
3059 "Failed to map microcode download buffer!\n");
3063 ioa_cfg->ucode_sglist = sglist;
3064 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3065 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3066 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3068 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3069 ioa_cfg->ucode_sglist = NULL;
3070 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3075 * ipr_store_update_fw - Update the firmware on the adapter
3076 * @class_dev: class_device struct
3078 * @count: buffer size
3080 * This function will update the firmware on the adapter.
3083 * count on success / other on failure
3085 static ssize_t ipr_store_update_fw(struct class_device *class_dev,
3086 const char *buf, size_t count)
3088 struct Scsi_Host *shost = class_to_shost(class_dev);
3089 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3090 struct ipr_ucode_image_header *image_hdr;
3091 const struct firmware *fw_entry;
3092 struct ipr_sglist *sglist;
3095 int len, result, dnld_size;
3097 if (!capable(CAP_SYS_ADMIN))
3100 len = snprintf(fname, 99, "%s", buf);
3101 fname[len-1] = '\0';
3103 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3104 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3108 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
3110 if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
3111 (ioa_cfg->vpd_cbs->page3_data.card_type &&
3112 ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
3113 dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
3114 release_firmware(fw_entry);
3118 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
3119 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
3120 sglist = ipr_alloc_ucode_buffer(dnld_size);
3123 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
3124 release_firmware(fw_entry);
3128 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
3131 dev_err(&ioa_cfg->pdev->dev,
3132 "Microcode buffer copy to DMA buffer failed\n");
3136 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
3141 ipr_free_ucode_buffer(sglist);
3142 release_firmware(fw_entry);
3146 static struct class_device_attribute ipr_update_fw_attr = {
3148 .name = "update_fw",
3151 .store = ipr_store_update_fw
3154 static struct class_device_attribute *ipr_ioa_attrs[] = {
3155 &ipr_fw_version_attr,
3156 &ipr_log_level_attr,
3157 &ipr_diagnostics_attr,
3158 &ipr_ioa_state_attr,
3159 &ipr_ioa_reset_attr,
3160 &ipr_update_fw_attr,
3161 &ipr_ioa_cache_attr,
3165 #ifdef CONFIG_SCSI_IPR_DUMP
3167 * ipr_read_dump - Dump the adapter
3168 * @kobj: kobject struct
3171 * @count: buffer size
3174 * number of bytes printed to buffer
3176 static ssize_t ipr_read_dump(struct kobject *kobj, char *buf,
3177 loff_t off, size_t count)
3179 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3180 struct Scsi_Host *shost = class_to_shost(cdev);
3181 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3182 struct ipr_dump *dump;
3183 unsigned long lock_flags = 0;
3188 if (!capable(CAP_SYS_ADMIN))
3191 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3192 dump = ioa_cfg->dump;
3194 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
3195 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3198 kref_get(&dump->kref);
3199 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3201 if (off > dump->driver_dump.hdr.len) {
3202 kref_put(&dump->kref, ipr_release_dump);
3206 if (off + count > dump->driver_dump.hdr.len) {
3207 count = dump->driver_dump.hdr.len - off;
3211 if (count && off < sizeof(dump->driver_dump)) {
3212 if (off + count > sizeof(dump->driver_dump))
3213 len = sizeof(dump->driver_dump) - off;
3216 src = (u8 *)&dump->driver_dump + off;
3217 memcpy(buf, src, len);
3223 off -= sizeof(dump->driver_dump);
3225 if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
3226 if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
3227 len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
3230 src = (u8 *)&dump->ioa_dump + off;
3231 memcpy(buf, src, len);
3237 off -= offsetof(struct ipr_ioa_dump, ioa_data);
3240 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
3241 len = PAGE_ALIGN(off) - off;
3244 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
3245 src += off & ~PAGE_MASK;
3246 memcpy(buf, src, len);
3252 kref_put(&dump->kref, ipr_release_dump);
3257 * ipr_alloc_dump - Prepare for adapter dump
3258 * @ioa_cfg: ioa config struct
3261 * 0 on success / other on failure
3263 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
3265 struct ipr_dump *dump;
3266 unsigned long lock_flags = 0;
3268 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
3271 ipr_err("Dump memory allocation failed\n");
3275 kref_init(&dump->kref);
3276 dump->ioa_cfg = ioa_cfg;
3278 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3280 if (INACTIVE != ioa_cfg->sdt_state) {
3281 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3286 ioa_cfg->dump = dump;
3287 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
3288 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
3289 ioa_cfg->dump_taken = 1;
3290 schedule_work(&ioa_cfg->work_q);
3292 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3298 * ipr_free_dump - Free adapter dump memory
3299 * @ioa_cfg: ioa config struct
3302 * 0 on success / other on failure
3304 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
3306 struct ipr_dump *dump;
3307 unsigned long lock_flags = 0;
3311 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3312 dump = ioa_cfg->dump;
3314 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3318 ioa_cfg->dump = NULL;
3319 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3321 kref_put(&dump->kref, ipr_release_dump);
3328 * ipr_write_dump - Setup dump state of adapter
3329 * @kobj: kobject struct
3332 * @count: buffer size
3335 * number of bytes printed to buffer
3337 static ssize_t ipr_write_dump(struct kobject *kobj, char *buf,
3338 loff_t off, size_t count)
3340 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3341 struct Scsi_Host *shost = class_to_shost(cdev);
3342 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3345 if (!capable(CAP_SYS_ADMIN))
3349 rc = ipr_alloc_dump(ioa_cfg);
3350 else if (buf[0] == '0')
3351 rc = ipr_free_dump(ioa_cfg);
3361 static struct bin_attribute ipr_dump_attr = {
3364 .mode = S_IRUSR | S_IWUSR,
3367 .read = ipr_read_dump,
3368 .write = ipr_write_dump
3371 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
3375 * ipr_change_queue_depth - Change the device's queue depth
3376 * @sdev: scsi device struct
3377 * @qdepth: depth to set
3382 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
3384 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3385 struct ipr_resource_entry *res;
3386 unsigned long lock_flags = 0;
3388 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3389 res = (struct ipr_resource_entry *)sdev->hostdata;
3391 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
3392 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
3393 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3395 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
3396 return sdev->queue_depth;
3400 * ipr_change_queue_type - Change the device's queue type
3401 * @dsev: scsi device struct
3402 * @tag_type: type of tags to use
3405 * actual queue type set
3407 static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
3409 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3410 struct ipr_resource_entry *res;
3411 unsigned long lock_flags = 0;
3413 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3414 res = (struct ipr_resource_entry *)sdev->hostdata;
3417 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
3419 * We don't bother quiescing the device here since the
3420 * adapter firmware does it for us.
3422 scsi_set_tag_type(sdev, tag_type);
3425 scsi_activate_tcq(sdev, sdev->queue_depth);
3427 scsi_deactivate_tcq(sdev, sdev->queue_depth);
3433 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3438 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
3439 * @dev: device struct
3443 * number of bytes printed to buffer
3445 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
3447 struct scsi_device *sdev = to_scsi_device(dev);
3448 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3449 struct ipr_resource_entry *res;
3450 unsigned long lock_flags = 0;
3451 ssize_t len = -ENXIO;
3453 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3454 res = (struct ipr_resource_entry *)sdev->hostdata;
3456 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->cfgte.res_handle);
3457 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3461 static struct device_attribute ipr_adapter_handle_attr = {
3463 .name = "adapter_handle",
3466 .show = ipr_show_adapter_handle
3469 static struct device_attribute *ipr_dev_attrs[] = {
3470 &ipr_adapter_handle_attr,
3475 * ipr_biosparam - Return the HSC mapping
3476 * @sdev: scsi device struct
3477 * @block_device: block device pointer
3478 * @capacity: capacity of the device
3479 * @parm: Array containing returned HSC values.
3481 * This function generates the HSC parms that fdisk uses.
3482 * We want to make sure we return something that places partitions
3483 * on 4k boundaries for best performance with the IOA.
3488 static int ipr_biosparam(struct scsi_device *sdev,
3489 struct block_device *block_device,
3490 sector_t capacity, int *parm)
3498 cylinders = capacity;
3499 sector_div(cylinders, (128 * 32));
3504 parm[2] = cylinders;
3510 * ipr_find_starget - Find target based on bus/target.
3511 * @starget: scsi target struct
3514 * resource entry pointer if found / NULL if not found
3516 static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
3518 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
3519 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
3520 struct ipr_resource_entry *res;
3522 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3523 if ((res->cfgte.res_addr.bus == starget->channel) &&
3524 (res->cfgte.res_addr.target == starget->id) &&
3525 (res->cfgte.res_addr.lun == 0)) {
3533 static struct ata_port_info sata_port_info;
3536 * ipr_target_alloc - Prepare for commands to a SCSI target
3537 * @starget: scsi target struct
3539 * If the device is a SATA device, this function allocates an
3540 * ATA port with libata, else it does nothing.
3543 * 0 on success / non-0 on failure
3545 static int ipr_target_alloc(struct scsi_target *starget)
3547 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
3548 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
3549 struct ipr_sata_port *sata_port;
3550 struct ata_port *ap;
3551 struct ipr_resource_entry *res;
3552 unsigned long lock_flags;
3554 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3555 res = ipr_find_starget(starget);
3556 starget->hostdata = NULL;
3558 if (res && ipr_is_gata(res)) {
3559 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3560 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
3564 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
3566 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3567 sata_port->ioa_cfg = ioa_cfg;
3569 sata_port->res = res;
3571 res->sata_port = sata_port;
3572 ap->private_data = sata_port;
3573 starget->hostdata = sata_port;
3579 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3585 * ipr_target_destroy - Destroy a SCSI target
3586 * @starget: scsi target struct
3588 * If the device was a SATA device, this function frees the libata
3589 * ATA port, else it does nothing.
3592 static void ipr_target_destroy(struct scsi_target *starget)
3594 struct ipr_sata_port *sata_port = starget->hostdata;
3597 starget->hostdata = NULL;
3598 ata_sas_port_destroy(sata_port->ap);
3604 * ipr_find_sdev - Find device based on bus/target/lun.
3605 * @sdev: scsi device struct
3608 * resource entry pointer if found / NULL if not found
3610 static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
3612 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3613 struct ipr_resource_entry *res;
3615 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3616 if ((res->cfgte.res_addr.bus == sdev->channel) &&
3617 (res->cfgte.res_addr.target == sdev->id) &&
3618 (res->cfgte.res_addr.lun == sdev->lun))
3626 * ipr_slave_destroy - Unconfigure a SCSI device
3627 * @sdev: scsi device struct
3632 static void ipr_slave_destroy(struct scsi_device *sdev)
3634 struct ipr_resource_entry *res;
3635 struct ipr_ioa_cfg *ioa_cfg;
3636 unsigned long lock_flags = 0;
3638 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3640 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3641 res = (struct ipr_resource_entry *) sdev->hostdata;
3644 ata_port_disable(res->sata_port->ap);
3645 sdev->hostdata = NULL;
3647 res->sata_port = NULL;
3649 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3653 * ipr_slave_configure - Configure a SCSI device
3654 * @sdev: scsi device struct
3656 * This function configures the specified scsi device.
3661 static int ipr_slave_configure(struct scsi_device *sdev)
3663 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3664 struct ipr_resource_entry *res;
3665 unsigned long lock_flags = 0;
3667 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3668 res = sdev->hostdata;
3670 if (ipr_is_af_dasd_device(res))
3671 sdev->type = TYPE_RAID;
3672 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
3673 sdev->scsi_level = 4;
3674 sdev->no_uld_attach = 1;
3676 if (ipr_is_vset_device(res)) {
3677 sdev->timeout = IPR_VSET_RW_TIMEOUT;
3678 blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
3680 if (ipr_is_vset_device(res) || ipr_is_scsi_disk(res))
3681 sdev->allow_restart = 1;
3682 if (ipr_is_gata(res) && res->sata_port) {
3683 scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
3684 ata_sas_slave_configure(sdev, res->sata_port->ap);
3686 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
3689 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3694 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
3695 * @sdev: scsi device struct
3697 * This function initializes an ATA port so that future commands
3698 * sent through queuecommand will work.
3703 static int ipr_ata_slave_alloc(struct scsi_device *sdev)
3705 struct ipr_sata_port *sata_port = NULL;
3709 if (sdev->sdev_target)
3710 sata_port = sdev->sdev_target->hostdata;
3712 rc = ata_sas_port_init(sata_port->ap);
3714 ipr_slave_destroy(sdev);
3721 * ipr_slave_alloc - Prepare for commands to a device.
3722 * @sdev: scsi device struct
3724 * This function saves a pointer to the resource entry
3725 * in the scsi device struct if the device exists. We
3726 * can then use this pointer in ipr_queuecommand when
3727 * handling new commands.
3730 * 0 on success / -ENXIO if device does not exist
3732 static int ipr_slave_alloc(struct scsi_device *sdev)
3734 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3735 struct ipr_resource_entry *res;
3736 unsigned long lock_flags;
3739 sdev->hostdata = NULL;
3741 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3743 res = ipr_find_sdev(sdev);
3748 sdev->hostdata = res;
3749 if (!ipr_is_naca_model(res))
3750 res->needs_sync_complete = 1;
3752 if (ipr_is_gata(res)) {
3753 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3754 return ipr_ata_slave_alloc(sdev);
3758 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3764 * ipr_eh_host_reset - Reset the host adapter
3765 * @scsi_cmd: scsi command struct
3770 static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
3772 struct ipr_ioa_cfg *ioa_cfg;
3776 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
3778 dev_err(&ioa_cfg->pdev->dev,
3779 "Adapter being reset as a result of error recovery.\n");
3781 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
3782 ioa_cfg->sdt_state = GET_DUMP;
3784 rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
3790 static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
3794 spin_lock_irq(cmd->device->host->host_lock);
3795 rc = __ipr_eh_host_reset(cmd);
3796 spin_unlock_irq(cmd->device->host->host_lock);
3802 * ipr_device_reset - Reset the device
3803 * @ioa_cfg: ioa config struct
3804 * @res: resource entry struct
3806 * This function issues a device reset to the affected device.
3807 * If the device is a SCSI device, a LUN reset will be sent
3808 * to the device first. If that does not work, a target reset
3809 * will be sent. If the device is a SATA device, a PHY reset will
3813 * 0 on success / non-zero on failure
3815 static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
3816 struct ipr_resource_entry *res)
3818 struct ipr_cmnd *ipr_cmd;
3819 struct ipr_ioarcb *ioarcb;
3820 struct ipr_cmd_pkt *cmd_pkt;
3821 struct ipr_ioarcb_ata_regs *regs;
3825 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3826 ioarcb = &ipr_cmd->ioarcb;
3827 cmd_pkt = &ioarcb->cmd_pkt;
3828 regs = &ioarcb->add_data.u.regs;
3830 ioarcb->res_handle = res->cfgte.res_handle;
3831 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3832 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3833 if (ipr_is_gata(res)) {
3834 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
3835 ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(regs->flags));
3836 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
3839 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3840 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3841 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3842 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET)
3843 memcpy(&res->sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
3844 sizeof(struct ipr_ioasa_gata));
3847 return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0);
3851 * ipr_sata_reset - Reset the SATA port
3852 * @ap: SATA port to reset
3853 * @classes: class of the attached device
3855 * This function issues a SATA phy reset to the affected ATA port.
3858 * 0 on success / non-zero on failure
3860 static int ipr_sata_reset(struct ata_port *ap, unsigned int *classes,
3861 unsigned long deadline)
3863 struct ipr_sata_port *sata_port = ap->private_data;
3864 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
3865 struct ipr_resource_entry *res;
3866 unsigned long lock_flags = 0;
3870 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3871 while(ioa_cfg->in_reset_reload) {
3872 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3873 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3874 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3877 res = sata_port->res;
3879 rc = ipr_device_reset(ioa_cfg, res);
3880 switch(res->cfgte.proto) {
3881 case IPR_PROTO_SATA:
3882 case IPR_PROTO_SAS_STP:
3883 *classes = ATA_DEV_ATA;
3885 case IPR_PROTO_SATA_ATAPI:
3886 case IPR_PROTO_SAS_STP_ATAPI:
3887 *classes = ATA_DEV_ATAPI;
3890 *classes = ATA_DEV_UNKNOWN;
3895 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3901 * ipr_eh_dev_reset - Reset the device
3902 * @scsi_cmd: scsi command struct
3904 * This function issues a device reset to the affected device.
3905 * A LUN reset will be sent to the device first. If that does
3906 * not work, a target reset will be sent.
3911 static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
3913 struct ipr_cmnd *ipr_cmd;
3914 struct ipr_ioa_cfg *ioa_cfg;
3915 struct ipr_resource_entry *res;
3916 struct ata_port *ap;
3920 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
3921 res = scsi_cmd->device->hostdata;
3927 * If we are currently going through reset/reload, return failed. This will force the
3928 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
3931 if (ioa_cfg->in_reset_reload)
3933 if (ioa_cfg->ioa_is_dead)
3936 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
3937 if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
3938 if (ipr_cmd->scsi_cmd)
3939 ipr_cmd->done = ipr_scsi_eh_done;
3941 ipr_cmd->done = ipr_sata_eh_done;
3942 if (ipr_cmd->qc && !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
3943 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
3944 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
3949 res->resetting_device = 1;
3950 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
3952 if (ipr_is_gata(res) && res->sata_port) {
3953 ap = res->sata_port->ap;
3954 spin_unlock_irq(scsi_cmd->device->host->host_lock);
3955 ata_do_eh(ap, NULL, NULL, ipr_sata_reset, NULL);
3956 spin_lock_irq(scsi_cmd->device->host->host_lock);
3958 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
3959 if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
3965 rc = ipr_device_reset(ioa_cfg, res);
3966 res->resetting_device = 0;
3969 return (rc ? FAILED : SUCCESS);
3972 static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
3976 spin_lock_irq(cmd->device->host->host_lock);
3977 rc = __ipr_eh_dev_reset(cmd);
3978 spin_unlock_irq(cmd->device->host->host_lock);
3984 * ipr_bus_reset_done - Op done function for bus reset.
3985 * @ipr_cmd: ipr command struct
3987 * This function is the op done function for a bus reset
3992 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
3994 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3995 struct ipr_resource_entry *res;
3998 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3999 if (!memcmp(&res->cfgte.res_handle, &ipr_cmd->ioarcb.res_handle,
4000 sizeof(res->cfgte.res_handle))) {
4001 scsi_report_bus_reset(ioa_cfg->host, res->cfgte.res_addr.bus);
4007 * If abort has not completed, indicate the reset has, else call the
4008 * abort's done function to wake the sleeping eh thread
4010 if (ipr_cmd->sibling->sibling)
4011 ipr_cmd->sibling->sibling = NULL;
4013 ipr_cmd->sibling->done(ipr_cmd->sibling);
4015 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4020 * ipr_abort_timeout - An abort task has timed out
4021 * @ipr_cmd: ipr command struct
4023 * This function handles when an abort task times out. If this
4024 * happens we issue a bus reset since we have resources tied
4025 * up that must be freed before returning to the midlayer.
4030 static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
4032 struct ipr_cmnd *reset_cmd;
4033 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4034 struct ipr_cmd_pkt *cmd_pkt;
4035 unsigned long lock_flags = 0;
4038 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4039 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
4040 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4044 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
4045 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4046 ipr_cmd->sibling = reset_cmd;
4047 reset_cmd->sibling = ipr_cmd;
4048 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
4049 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
4050 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4051 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
4052 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
4054 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
4055 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4060 * ipr_cancel_op - Cancel specified op
4061 * @scsi_cmd: scsi command struct
4063 * This function cancels specified op.
4068 static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
4070 struct ipr_cmnd *ipr_cmd;
4071 struct ipr_ioa_cfg *ioa_cfg;
4072 struct ipr_resource_entry *res;
4073 struct ipr_cmd_pkt *cmd_pkt;
4078 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4079 res = scsi_cmd->device->hostdata;
4081 /* If we are currently going through reset/reload, return failed.
4082 * This will force the mid-layer to call ipr_eh_host_reset,
4083 * which will then go to sleep and wait for the reset to complete
4085 if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
4087 if (!res || !ipr_is_gscsi(res))
4090 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4091 if (ipr_cmd->scsi_cmd == scsi_cmd) {
4092 ipr_cmd->done = ipr_scsi_eh_done;
4101 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4102 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
4103 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4104 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4105 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
4106 ipr_cmd->u.sdev = scsi_cmd->device;
4108 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
4110 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
4111 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4114 * If the abort task timed out and we sent a bus reset, we will get
4115 * one the following responses to the abort
4117 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
4122 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4123 if (!ipr_is_naca_model(res))
4124 res->needs_sync_complete = 1;
4127 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
4131 * ipr_eh_abort - Abort a single op
4132 * @scsi_cmd: scsi command struct
4137 static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
4139 unsigned long flags;
4144 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
4145 rc = ipr_cancel_op(scsi_cmd);
4146 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
4153 * ipr_handle_other_interrupt - Handle "other" interrupts
4154 * @ioa_cfg: ioa config struct
4155 * @int_reg: interrupt register
4158 * IRQ_NONE / IRQ_HANDLED
4160 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
4161 volatile u32 int_reg)
4163 irqreturn_t rc = IRQ_HANDLED;
4165 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
4166 /* Mask the interrupt */
4167 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
4169 /* Clear the interrupt */
4170 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
4171 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
4173 list_del(&ioa_cfg->reset_cmd->queue);
4174 del_timer(&ioa_cfg->reset_cmd->timer);
4175 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
4177 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
4178 ioa_cfg->ioa_unit_checked = 1;
4180 dev_err(&ioa_cfg->pdev->dev,
4181 "Permanent IOA failure. 0x%08X\n", int_reg);
4183 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4184 ioa_cfg->sdt_state = GET_DUMP;
4186 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
4187 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
4194 * ipr_isr - Interrupt service routine
4196 * @devp: pointer to ioa config struct
4199 * IRQ_NONE / IRQ_HANDLED
4201 static irqreturn_t ipr_isr(int irq, void *devp)
4203 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
4204 unsigned long lock_flags = 0;
4205 volatile u32 int_reg, int_mask_reg;
4208 struct ipr_cmnd *ipr_cmd;
4209 irqreturn_t rc = IRQ_NONE;
4211 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4213 /* If interrupts are disabled, ignore the interrupt */
4214 if (!ioa_cfg->allow_interrupts) {
4215 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4219 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
4220 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
4222 /* If an interrupt on the adapter did not occur, ignore it */
4223 if (unlikely((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0)) {
4224 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4231 while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
4232 ioa_cfg->toggle_bit) {
4234 cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
4235 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
4237 if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
4238 ioa_cfg->errors_logged++;
4239 dev_err(&ioa_cfg->pdev->dev, "Invalid response handle from IOA\n");
4241 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4242 ioa_cfg->sdt_state = GET_DUMP;
4244 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
4245 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4249 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
4251 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4253 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
4255 list_del(&ipr_cmd->queue);
4256 del_timer(&ipr_cmd->timer);
4257 ipr_cmd->done(ipr_cmd);
4261 if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
4262 ioa_cfg->hrrq_curr++;
4264 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
4265 ioa_cfg->toggle_bit ^= 1u;
4269 if (ipr_cmd != NULL) {
4270 /* Clear the PCI interrupt */
4271 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg);
4272 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
4277 if (unlikely(rc == IRQ_NONE))
4278 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
4280 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4285 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
4286 * @ioa_cfg: ioa config struct
4287 * @ipr_cmd: ipr command struct
4290 * 0 on success / -1 on failure
4292 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
4293 struct ipr_cmnd *ipr_cmd)
4296 struct scatterlist *sglist;
4298 u32 ioadl_flags = 0;
4299 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4300 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4301 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4303 length = scsi_cmd->request_bufflen;
4308 if (scsi_cmd->use_sg) {
4309 ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev,
4310 scsi_cmd->request_buffer,
4312 scsi_cmd->sc_data_direction);
4314 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
4315 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
4316 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4317 ioarcb->write_data_transfer_length = cpu_to_be32(length);
4318 ioarcb->write_ioadl_len =
4319 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
4320 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
4321 ioadl_flags = IPR_IOADL_FLAGS_READ;
4322 ioarcb->read_data_transfer_length = cpu_to_be32(length);
4323 ioarcb->read_ioadl_len =
4324 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
4327 sglist = scsi_cmd->request_buffer;
4329 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->add_data.u.ioadl)) {
4330 ioadl = ioarcb->add_data.u.ioadl;
4331 ioarcb->write_ioadl_addr =
4332 cpu_to_be32(be32_to_cpu(ioarcb->ioarcb_host_pci_addr) +
4333 offsetof(struct ipr_ioarcb, add_data));
4334 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
4337 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
4338 ioadl[i].flags_and_data_len =
4339 cpu_to_be32(ioadl_flags | sg_dma_len(&sglist[i]));
4341 cpu_to_be32(sg_dma_address(&sglist[i]));
4344 if (likely(ipr_cmd->dma_use_sg)) {
4345 ioadl[i-1].flags_and_data_len |=
4346 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
4349 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
4351 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
4352 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
4353 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4354 ioarcb->write_data_transfer_length = cpu_to_be32(length);
4355 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4356 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
4357 ioadl_flags = IPR_IOADL_FLAGS_READ;
4358 ioarcb->read_data_transfer_length = cpu_to_be32(length);
4359 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4362 ipr_cmd->dma_handle = pci_map_single(ioa_cfg->pdev,
4363 scsi_cmd->request_buffer, length,
4364 scsi_cmd->sc_data_direction);
4366 if (likely(!pci_dma_mapping_error(ipr_cmd->dma_handle))) {
4367 ioadl = ioarcb->add_data.u.ioadl;
4368 ioarcb->write_ioadl_addr =
4369 cpu_to_be32(be32_to_cpu(ioarcb->ioarcb_host_pci_addr) +
4370 offsetof(struct ipr_ioarcb, add_data));
4371 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
4372 ipr_cmd->dma_use_sg = 1;
4373 ioadl[0].flags_and_data_len =
4374 cpu_to_be32(ioadl_flags | length | IPR_IOADL_FLAGS_LAST);
4375 ioadl[0].address = cpu_to_be32(ipr_cmd->dma_handle);
4378 dev_err(&ioa_cfg->pdev->dev, "pci_map_single failed!\n");
4385 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
4386 * @scsi_cmd: scsi command struct
4391 static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
4394 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
4396 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
4398 case MSG_SIMPLE_TAG:
4399 rc = IPR_FLAGS_LO_SIMPLE_TASK;
4402 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
4404 case MSG_ORDERED_TAG:
4405 rc = IPR_FLAGS_LO_ORDERED_TASK;
4414 * ipr_erp_done - Process completion of ERP for a device
4415 * @ipr_cmd: ipr command struct
4417 * This function copies the sense buffer into the scsi_cmd
4418 * struct and pushes the scsi_done function.
4423 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
4425 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4426 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4427 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4428 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4430 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
4431 scsi_cmd->result |= (DID_ERROR << 16);
4432 scmd_printk(KERN_ERR, scsi_cmd,
4433 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
4435 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
4436 SCSI_SENSE_BUFFERSIZE);
4440 if (!ipr_is_naca_model(res))
4441 res->needs_sync_complete = 1;
4444 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4445 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4446 scsi_cmd->scsi_done(scsi_cmd);
4450 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
4451 * @ipr_cmd: ipr command struct
4456 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
4458 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4459 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4460 dma_addr_t dma_addr = be32_to_cpu(ioarcb->ioarcb_host_pci_addr);
4462 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
4463 ioarcb->write_data_transfer_length = 0;
4464 ioarcb->read_data_transfer_length = 0;
4465 ioarcb->write_ioadl_len = 0;
4466 ioarcb->read_ioadl_len = 0;
4468 ioasa->residual_data_len = 0;
4469 ioarcb->write_ioadl_addr =
4470 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
4471 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
4475 * ipr_erp_request_sense - Send request sense to a device
4476 * @ipr_cmd: ipr command struct
4478 * This function sends a request sense to a device as a result
4479 * of a check condition.
4484 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
4486 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4487 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4489 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
4490 ipr_erp_done(ipr_cmd);
4494 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
4496 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
4497 cmd_pkt->cdb[0] = REQUEST_SENSE;
4498 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
4499 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
4500 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
4501 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
4503 ipr_cmd->ioadl[0].flags_and_data_len =
4504 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | SCSI_SENSE_BUFFERSIZE);
4505 ipr_cmd->ioadl[0].address =
4506 cpu_to_be32(ipr_cmd->sense_buffer_dma);
4508 ipr_cmd->ioarcb.read_ioadl_len =
4509 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4510 ipr_cmd->ioarcb.read_data_transfer_length =
4511 cpu_to_be32(SCSI_SENSE_BUFFERSIZE);
4513 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
4514 IPR_REQUEST_SENSE_TIMEOUT * 2);
4518 * ipr_erp_cancel_all - Send cancel all to a device
4519 * @ipr_cmd: ipr command struct
4521 * This function sends a cancel all to a device to clear the
4522 * queue. If we are running TCQ on the device, QERR is set to 1,
4523 * which means all outstanding ops have been dropped on the floor.
4524 * Cancel all will return them to us.
4529 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
4531 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4532 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4533 struct ipr_cmd_pkt *cmd_pkt;
4537 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
4539 if (!scsi_get_tag_type(scsi_cmd->device)) {
4540 ipr_erp_request_sense(ipr_cmd);
4544 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4545 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4546 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
4548 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
4549 IPR_CANCEL_ALL_TIMEOUT);
4553 * ipr_dump_ioasa - Dump contents of IOASA
4554 * @ioa_cfg: ioa config struct
4555 * @ipr_cmd: ipr command struct
4556 * @res: resource entry struct
4558 * This function is invoked by the interrupt handler when ops
4559 * fail. It will log the IOASA if appropriate. Only called
4565 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
4566 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
4570 u32 ioasc, fd_ioasc;
4571 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4572 __be32 *ioasa_data = (__be32 *)ioasa;
4575 ioasc = be32_to_cpu(ioasa->ioasc) & IPR_IOASC_IOASC_MASK;
4576 fd_ioasc = be32_to_cpu(ioasa->fd_ioasc) & IPR_IOASC_IOASC_MASK;
4581 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
4584 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
4585 error_index = ipr_get_error(fd_ioasc);
4587 error_index = ipr_get_error(ioasc);
4589 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
4590 /* Don't log an error if the IOA already logged one */
4591 if (ioasa->ilid != 0)
4594 if (!ipr_is_gscsi(res))
4597 if (ipr_error_table[error_index].log_ioasa == 0)
4601 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
4603 if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
4604 data_len = sizeof(struct ipr_ioasa);
4606 data_len = be16_to_cpu(ioasa->ret_stat_len);
4608 ipr_err("IOASA Dump:\n");
4610 for (i = 0; i < data_len / 4; i += 4) {
4611 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
4612 be32_to_cpu(ioasa_data[i]),
4613 be32_to_cpu(ioasa_data[i+1]),
4614 be32_to_cpu(ioasa_data[i+2]),
4615 be32_to_cpu(ioasa_data[i+3]));
4620 * ipr_gen_sense - Generate SCSI sense data from an IOASA
4622 * @sense_buf: sense data buffer
4627 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
4630 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
4631 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
4632 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4633 u32 ioasc = be32_to_cpu(ioasa->ioasc);
4635 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
4637 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
4640 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
4642 if (ipr_is_vset_device(res) &&
4643 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
4644 ioasa->u.vset.failing_lba_hi != 0) {
4645 sense_buf[0] = 0x72;
4646 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
4647 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
4648 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
4652 sense_buf[9] = 0x0A;
4653 sense_buf[10] = 0x80;
4655 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
4657 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
4658 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
4659 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
4660 sense_buf[15] = failing_lba & 0x000000ff;
4662 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
4664 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
4665 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
4666 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
4667 sense_buf[19] = failing_lba & 0x000000ff;
4669 sense_buf[0] = 0x70;
4670 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
4671 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
4672 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
4674 /* Illegal request */
4675 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
4676 (be32_to_cpu(ioasa->ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
4677 sense_buf[7] = 10; /* additional length */
4679 /* IOARCB was in error */
4680 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
4681 sense_buf[15] = 0xC0;
4682 else /* Parameter data was invalid */
4683 sense_buf[15] = 0x80;
4686 ((IPR_FIELD_POINTER_MASK &
4687 be32_to_cpu(ioasa->ioasc_specific)) >> 8) & 0xff;
4689 (IPR_FIELD_POINTER_MASK &
4690 be32_to_cpu(ioasa->ioasc_specific)) & 0xff;
4692 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
4693 if (ipr_is_vset_device(res))
4694 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
4696 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
4698 sense_buf[0] |= 0x80; /* Or in the Valid bit */
4699 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
4700 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
4701 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
4702 sense_buf[6] = failing_lba & 0x000000ff;
4705 sense_buf[7] = 6; /* additional length */
4711 * ipr_get_autosense - Copy autosense data to sense buffer
4712 * @ipr_cmd: ipr command struct
4714 * This function copies the autosense buffer to the buffer
4715 * in the scsi_cmd, if there is autosense available.
4718 * 1 if autosense was available / 0 if not
4720 static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
4722 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4724 if ((be32_to_cpu(ioasa->ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
4727 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
4728 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
4729 SCSI_SENSE_BUFFERSIZE));
4734 * ipr_erp_start - Process an error response for a SCSI op
4735 * @ioa_cfg: ioa config struct
4736 * @ipr_cmd: ipr command struct
4738 * This function determines whether or not to initiate ERP
4739 * on the affected device.
4744 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
4745 struct ipr_cmnd *ipr_cmd)
4747 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4748 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4749 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4750 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
4753 ipr_scsi_eh_done(ipr_cmd);
4757 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
4758 ipr_gen_sense(ipr_cmd);
4760 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
4762 switch (masked_ioasc) {
4763 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
4764 if (ipr_is_naca_model(res))
4765 scsi_cmd->result |= (DID_ABORT << 16);
4767 scsi_cmd->result |= (DID_IMM_RETRY << 16);
4769 case IPR_IOASC_IR_RESOURCE_HANDLE:
4770 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
4771 scsi_cmd->result |= (DID_NO_CONNECT << 16);
4773 case IPR_IOASC_HW_SEL_TIMEOUT:
4774 scsi_cmd->result |= (DID_NO_CONNECT << 16);
4775 if (!ipr_is_naca_model(res))
4776 res->needs_sync_complete = 1;
4778 case IPR_IOASC_SYNC_REQUIRED:
4780 res->needs_sync_complete = 1;
4781 scsi_cmd->result |= (DID_IMM_RETRY << 16);
4783 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
4784 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
4785 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
4787 case IPR_IOASC_BUS_WAS_RESET:
4788 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
4790 * Report the bus reset and ask for a retry. The device
4791 * will give CC/UA the next command.
4793 if (!res->resetting_device)
4794 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
4795 scsi_cmd->result |= (DID_ERROR << 16);
4796 if (!ipr_is_naca_model(res))
4797 res->needs_sync_complete = 1;
4799 case IPR_IOASC_HW_DEV_BUS_STATUS:
4800 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
4801 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
4802 if (!ipr_get_autosense(ipr_cmd)) {
4803 if (!ipr_is_naca_model(res)) {
4804 ipr_erp_cancel_all(ipr_cmd);
4809 if (!ipr_is_naca_model(res))
4810 res->needs_sync_complete = 1;
4812 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
4815 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
4816 scsi_cmd->result |= (DID_ERROR << 16);
4817 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
4818 res->needs_sync_complete = 1;
4822 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4823 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4824 scsi_cmd->scsi_done(scsi_cmd);
4828 * ipr_scsi_done - mid-layer done function
4829 * @ipr_cmd: ipr command struct
4831 * This function is invoked by the interrupt handler for
4832 * ops generated by the SCSI mid-layer
4837 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
4839 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4840 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4841 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4843 scsi_cmd->resid = be32_to_cpu(ipr_cmd->ioasa.residual_data_len);
4845 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
4846 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4847 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4848 scsi_cmd->scsi_done(scsi_cmd);
4850 ipr_erp_start(ioa_cfg, ipr_cmd);
4854 * ipr_queuecommand - Queue a mid-layer request
4855 * @scsi_cmd: scsi command struct
4856 * @done: done function
4858 * This function queues a request generated by the mid-layer.
4862 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
4863 * SCSI_MLQUEUE_HOST_BUSY if host is busy
4865 static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
4866 void (*done) (struct scsi_cmnd *))
4868 struct ipr_ioa_cfg *ioa_cfg;
4869 struct ipr_resource_entry *res;
4870 struct ipr_ioarcb *ioarcb;
4871 struct ipr_cmnd *ipr_cmd;
4874 scsi_cmd->scsi_done = done;
4875 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4876 res = scsi_cmd->device->hostdata;
4877 scsi_cmd->result = (DID_OK << 16);
4880 * We are currently blocking all devices due to a host reset
4881 * We have told the host to stop giving us new requests, but
4882 * ERP ops don't count. FIXME
4884 if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))
4885 return SCSI_MLQUEUE_HOST_BUSY;
4888 * FIXME - Create scsi_set_host_offline interface
4889 * and the ioa_is_dead check can be removed
4891 if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
4892 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
4893 scsi_cmd->result = (DID_NO_CONNECT << 16);
4894 scsi_cmd->scsi_done(scsi_cmd);
4898 if (ipr_is_gata(res) && res->sata_port)
4899 return ata_sas_queuecmd(scsi_cmd, done, res->sata_port->ap);
4901 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4902 ioarcb = &ipr_cmd->ioarcb;
4903 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
4905 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
4906 ipr_cmd->scsi_cmd = scsi_cmd;
4907 ioarcb->res_handle = res->cfgte.res_handle;
4908 ipr_cmd->done = ipr_scsi_done;
4909 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
4911 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
4912 if (scsi_cmd->underflow == 0)
4913 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
4915 if (res->needs_sync_complete) {
4916 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
4917 res->needs_sync_complete = 0;
4920 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
4921 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
4922 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
4923 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
4926 if (scsi_cmd->cmnd[0] >= 0xC0 &&
4927 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
4928 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4930 if (likely(rc == 0))
4931 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
4933 if (likely(rc == 0)) {
4935 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
4936 ioa_cfg->regs.ioarrin_reg);
4938 list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4939 return SCSI_MLQUEUE_HOST_BUSY;
4946 * ipr_ioctl - IOCTL handler
4947 * @sdev: scsi device struct
4952 * 0 on success / other on failure
4954 static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
4956 struct ipr_resource_entry *res;
4958 res = (struct ipr_resource_entry *)sdev->hostdata;
4959 if (res && ipr_is_gata(res))
4960 return ata_scsi_ioctl(sdev, cmd, arg);
4966 * ipr_info - Get information about the card/driver
4967 * @scsi_host: scsi host struct
4970 * pointer to buffer with description string
4972 static const char * ipr_ioa_info(struct Scsi_Host *host)
4974 static char buffer[512];
4975 struct ipr_ioa_cfg *ioa_cfg;
4976 unsigned long lock_flags = 0;
4978 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
4980 spin_lock_irqsave(host->host_lock, lock_flags);
4981 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
4982 spin_unlock_irqrestore(host->host_lock, lock_flags);
4987 static struct scsi_host_template driver_template = {
4988 .module = THIS_MODULE,
4990 .info = ipr_ioa_info,
4992 .queuecommand = ipr_queuecommand,
4993 .eh_abort_handler = ipr_eh_abort,
4994 .eh_device_reset_handler = ipr_eh_dev_reset,
4995 .eh_host_reset_handler = ipr_eh_host_reset,
4996 .slave_alloc = ipr_slave_alloc,
4997 .slave_configure = ipr_slave_configure,
4998 .slave_destroy = ipr_slave_destroy,
4999 .target_alloc = ipr_target_alloc,
5000 .target_destroy = ipr_target_destroy,
5001 .change_queue_depth = ipr_change_queue_depth,
5002 .change_queue_type = ipr_change_queue_type,
5003 .bios_param = ipr_biosparam,
5004 .can_queue = IPR_MAX_COMMANDS,
5006 .sg_tablesize = IPR_MAX_SGLIST,
5007 .max_sectors = IPR_IOA_MAX_SECTORS,
5008 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
5009 .use_clustering = ENABLE_CLUSTERING,
5010 .shost_attrs = ipr_ioa_attrs,
5011 .sdev_attrs = ipr_dev_attrs,
5012 .proc_name = IPR_NAME
5016 * ipr_ata_phy_reset - libata phy_reset handler
5017 * @ap: ata port to reset
5020 static void ipr_ata_phy_reset(struct ata_port *ap)
5022 unsigned long flags;
5023 struct ipr_sata_port *sata_port = ap->private_data;
5024 struct ipr_resource_entry *res = sata_port->res;
5025 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5029 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
5030 while(ioa_cfg->in_reset_reload) {
5031 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
5032 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
5033 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
5036 if (!ioa_cfg->allow_cmds)
5039 rc = ipr_device_reset(ioa_cfg, res);
5042 ap->ops->port_disable(ap);
5046 switch(res->cfgte.proto) {
5047 case IPR_PROTO_SATA:
5048 case IPR_PROTO_SAS_STP:
5049 ap->device[0].class = ATA_DEV_ATA;
5051 case IPR_PROTO_SATA_ATAPI:
5052 case IPR_PROTO_SAS_STP_ATAPI:
5053 ap->device[0].class = ATA_DEV_ATAPI;
5056 ap->device[0].class = ATA_DEV_UNKNOWN;
5057 ap->ops->port_disable(ap);
5062 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
5067 * ipr_ata_post_internal - Cleanup after an internal command
5068 * @qc: ATA queued command
5073 static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
5075 struct ipr_sata_port *sata_port = qc->ap->private_data;
5076 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5077 struct ipr_cmnd *ipr_cmd;
5078 unsigned long flags;
5080 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
5081 while(ioa_cfg->in_reset_reload) {
5082 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
5083 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
5084 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
5087 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
5088 if (ipr_cmd->qc == qc) {
5089 ipr_device_reset(ioa_cfg, sata_port->res);
5093 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
5097 * ipr_tf_read - Read the current ATA taskfile for the ATA port
5099 * @tf: destination ATA taskfile
5104 static void ipr_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
5106 struct ipr_sata_port *sata_port = ap->private_data;
5107 struct ipr_ioasa_gata *g = &sata_port->ioasa;
5109 tf->feature = g->error;
5110 tf->nsect = g->nsect;
5114 tf->device = g->device;
5115 tf->command = g->status;
5116 tf->hob_nsect = g->hob_nsect;
5117 tf->hob_lbal = g->hob_lbal;
5118 tf->hob_lbam = g->hob_lbam;
5119 tf->hob_lbah = g->hob_lbah;
5120 tf->ctl = g->alt_status;
5124 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
5125 * @regs: destination
5126 * @tf: source ATA taskfile
5131 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
5132 struct ata_taskfile *tf)
5134 regs->feature = tf->feature;
5135 regs->nsect = tf->nsect;
5136 regs->lbal = tf->lbal;
5137 regs->lbam = tf->lbam;
5138 regs->lbah = tf->lbah;
5139 regs->device = tf->device;
5140 regs->command = tf->command;
5141 regs->hob_feature = tf->hob_feature;
5142 regs->hob_nsect = tf->hob_nsect;
5143 regs->hob_lbal = tf->hob_lbal;
5144 regs->hob_lbam = tf->hob_lbam;
5145 regs->hob_lbah = tf->hob_lbah;
5146 regs->ctl = tf->ctl;
5150 * ipr_sata_done - done function for SATA commands
5151 * @ipr_cmd: ipr command struct
5153 * This function is invoked by the interrupt handler for
5154 * ops generated by the SCSI mid-layer to SATA devices
5159 static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
5161 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5162 struct ata_queued_cmd *qc = ipr_cmd->qc;
5163 struct ipr_sata_port *sata_port = qc->ap->private_data;
5164 struct ipr_resource_entry *res = sata_port->res;
5165 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5167 memcpy(&sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
5168 sizeof(struct ipr_ioasa_gata));
5169 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
5171 if (be32_to_cpu(ipr_cmd->ioasa.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
5172 scsi_report_device_reset(ioa_cfg->host, res->cfgte.res_addr.bus,
5173 res->cfgte.res_addr.target);
5175 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
5176 qc->err_mask |= __ac_err_mask(ipr_cmd->ioasa.u.gata.status);
5178 qc->err_mask |= ac_err_mask(ipr_cmd->ioasa.u.gata.status);
5179 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5180 ata_qc_complete(qc);
5184 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
5185 * @ipr_cmd: ipr command struct
5186 * @qc: ATA queued command
5189 static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
5190 struct ata_queued_cmd *qc)
5192 u32 ioadl_flags = 0;
5193 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5194 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5195 int len = qc->nbytes + qc->pad_len;
5196 struct scatterlist *sg;
5201 if (qc->dma_dir == DMA_TO_DEVICE) {
5202 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5203 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5204 ioarcb->write_data_transfer_length = cpu_to_be32(len);
5205 ioarcb->write_ioadl_len =
5206 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5207 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
5208 ioadl_flags = IPR_IOADL_FLAGS_READ;
5209 ioarcb->read_data_transfer_length = cpu_to_be32(len);
5210 ioarcb->read_ioadl_len =
5211 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5214 ata_for_each_sg(sg, qc) {
5215 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5216 ioadl->address = cpu_to_be32(sg_dma_address(sg));
5217 if (ata_sg_is_last(sg, qc))
5218 ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5225 * ipr_qc_issue - Issue a SATA qc to a device
5226 * @qc: queued command
5231 static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
5233 struct ata_port *ap = qc->ap;
5234 struct ipr_sata_port *sata_port = ap->private_data;
5235 struct ipr_resource_entry *res = sata_port->res;
5236 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5237 struct ipr_cmnd *ipr_cmd;
5238 struct ipr_ioarcb *ioarcb;
5239 struct ipr_ioarcb_ata_regs *regs;
5241 if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead))
5242 return AC_ERR_SYSTEM;
5244 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5245 ioarcb = &ipr_cmd->ioarcb;
5246 regs = &ioarcb->add_data.u.regs;
5248 memset(&ioarcb->add_data, 0, sizeof(ioarcb->add_data));
5249 ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(ioarcb->add_data.u.regs));
5251 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
5253 ipr_cmd->done = ipr_sata_done;
5254 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
5255 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
5256 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
5257 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5258 ipr_cmd->dma_use_sg = qc->pad_len ? qc->n_elem + 1 : qc->n_elem;
5260 ipr_build_ata_ioadl(ipr_cmd, qc);
5261 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
5262 ipr_copy_sata_tf(regs, &qc->tf);
5263 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
5264 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
5266 switch (qc->tf.protocol) {
5267 case ATA_PROT_NODATA:
5272 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
5275 case ATA_PROT_ATAPI:
5276 case ATA_PROT_ATAPI_NODATA:
5277 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
5280 case ATA_PROT_ATAPI_DMA:
5281 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
5282 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
5287 return AC_ERR_INVALID;
5291 writel(be32_to_cpu(ioarcb->ioarcb_host_pci_addr),
5292 ioa_cfg->regs.ioarrin_reg);
5297 * ipr_ata_check_status - Return last ATA status
5303 static u8 ipr_ata_check_status(struct ata_port *ap)
5305 struct ipr_sata_port *sata_port = ap->private_data;
5306 return sata_port->ioasa.status;
5310 * ipr_ata_check_altstatus - Return last ATA altstatus
5316 static u8 ipr_ata_check_altstatus(struct ata_port *ap)
5318 struct ipr_sata_port *sata_port = ap->private_data;
5319 return sata_port->ioasa.alt_status;
5322 static struct ata_port_operations ipr_sata_ops = {
5323 .port_disable = ata_port_disable,
5324 .check_status = ipr_ata_check_status,
5325 .check_altstatus = ipr_ata_check_altstatus,
5326 .dev_select = ata_noop_dev_select,
5327 .phy_reset = ipr_ata_phy_reset,
5328 .post_internal_cmd = ipr_ata_post_internal,
5329 .tf_read = ipr_tf_read,
5330 .qc_prep = ata_noop_qc_prep,
5331 .qc_issue = ipr_qc_issue,
5332 .port_start = ata_sas_port_start,
5333 .port_stop = ata_sas_port_stop
5336 static struct ata_port_info sata_port_info = {
5337 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | ATA_FLAG_SATA_RESET |
5338 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
5339 .pio_mask = 0x10, /* pio4 */
5341 .udma_mask = 0x7f, /* udma0-6 */
5342 .port_ops = &ipr_sata_ops
5345 #ifdef CONFIG_PPC_PSERIES
5346 static const u16 ipr_blocked_processors[] = {
5358 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
5359 * @ioa_cfg: ioa cfg struct
5361 * Adapters that use Gemstone revision < 3.1 do not work reliably on
5362 * certain pSeries hardware. This function determines if the given
5363 * adapter is in one of these confgurations or not.
5366 * 1 if adapter is not supported / 0 if adapter is supported
5368 static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
5373 if (ioa_cfg->type == 0x5702) {
5374 if (pci_read_config_byte(ioa_cfg->pdev, PCI_REVISION_ID,
5375 &rev_id) == PCIBIOS_SUCCESSFUL) {
5377 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
5378 if (__is_processor(ipr_blocked_processors[i]))
5387 #define ipr_invalid_adapter(ioa_cfg) 0
5391 * ipr_ioa_bringdown_done - IOA bring down completion.
5392 * @ipr_cmd: ipr command struct
5394 * This function processes the completion of an adapter bring down.
5395 * It wakes any reset sleepers.
5400 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
5402 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5405 ioa_cfg->in_reset_reload = 0;
5406 ioa_cfg->reset_retries = 0;
5407 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5408 wake_up_all(&ioa_cfg->reset_wait_q);
5410 spin_unlock_irq(ioa_cfg->host->host_lock);
5411 scsi_unblock_requests(ioa_cfg->host);
5412 spin_lock_irq(ioa_cfg->host->host_lock);
5415 return IPR_RC_JOB_RETURN;
5419 * ipr_ioa_reset_done - IOA reset completion.
5420 * @ipr_cmd: ipr command struct
5422 * This function processes the completion of an adapter reset.
5423 * It schedules any necessary mid-layer add/removes and
5424 * wakes any reset sleepers.
5429 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
5431 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5432 struct ipr_resource_entry *res;
5433 struct ipr_hostrcb *hostrcb, *temp;
5437 ioa_cfg->in_reset_reload = 0;
5438 ioa_cfg->allow_cmds = 1;
5439 ioa_cfg->reset_cmd = NULL;
5440 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
5442 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
5443 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
5448 schedule_work(&ioa_cfg->work_q);
5450 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
5451 list_del(&hostrcb->queue);
5452 if (i++ < IPR_NUM_LOG_HCAMS)
5453 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
5455 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
5458 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
5459 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
5461 ioa_cfg->reset_retries = 0;
5462 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5463 wake_up_all(&ioa_cfg->reset_wait_q);
5465 spin_unlock_irq(ioa_cfg->host->host_lock);
5466 scsi_unblock_requests(ioa_cfg->host);
5467 spin_lock_irq(ioa_cfg->host->host_lock);
5469 if (!ioa_cfg->allow_cmds)
5470 scsi_block_requests(ioa_cfg->host);
5473 return IPR_RC_JOB_RETURN;
5477 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
5478 * @supported_dev: supported device struct
5479 * @vpids: vendor product id struct
5484 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
5485 struct ipr_std_inq_vpids *vpids)
5487 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
5488 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
5489 supported_dev->num_records = 1;
5490 supported_dev->data_length =
5491 cpu_to_be16(sizeof(struct ipr_supported_device));
5492 supported_dev->reserved = 0;
5496 * ipr_set_supported_devs - Send Set Supported Devices for a device
5497 * @ipr_cmd: ipr command struct
5499 * This function send a Set Supported Devices to the adapter
5502 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5504 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
5506 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5507 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
5508 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5509 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5510 struct ipr_resource_entry *res = ipr_cmd->u.res;
5512 ipr_cmd->job_step = ipr_ioa_reset_done;
5514 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
5515 if (!ipr_is_scsi_disk(res))
5518 ipr_cmd->u.res = res;
5519 ipr_set_sup_dev_dflt(supp_dev, &res->cfgte.std_inq_data.vpids);
5521 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5522 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5523 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5525 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
5526 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
5527 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
5529 ioadl->flags_and_data_len = cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST |
5530 sizeof(struct ipr_supported_device));
5531 ioadl->address = cpu_to_be32(ioa_cfg->vpd_cbs_dma +
5532 offsetof(struct ipr_misc_cbs, supp_dev));
5533 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5534 ioarcb->write_data_transfer_length =
5535 cpu_to_be32(sizeof(struct ipr_supported_device));
5537 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
5538 IPR_SET_SUP_DEVICE_TIMEOUT);
5540 ipr_cmd->job_step = ipr_set_supported_devs;
5541 return IPR_RC_JOB_RETURN;
5544 return IPR_RC_JOB_CONTINUE;
5548 * ipr_setup_write_cache - Disable write cache if needed
5549 * @ipr_cmd: ipr command struct
5551 * This function sets up adapters write cache to desired setting
5554 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5556 static int ipr_setup_write_cache(struct ipr_cmnd *ipr_cmd)
5558 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5560 ipr_cmd->job_step = ipr_set_supported_devs;
5561 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
5562 struct ipr_resource_entry, queue);
5564 if (ioa_cfg->cache_state != CACHE_DISABLED)
5565 return IPR_RC_JOB_CONTINUE;
5567 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5568 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5569 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
5570 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
5572 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5574 return IPR_RC_JOB_RETURN;
5578 * ipr_get_mode_page - Locate specified mode page
5579 * @mode_pages: mode page buffer
5580 * @page_code: page code to find
5581 * @len: minimum required length for mode page
5584 * pointer to mode page / NULL on failure
5586 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
5587 u32 page_code, u32 len)
5589 struct ipr_mode_page_hdr *mode_hdr;
5593 if (!mode_pages || (mode_pages->hdr.length == 0))
5596 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
5597 mode_hdr = (struct ipr_mode_page_hdr *)
5598 (mode_pages->data + mode_pages->hdr.block_desc_len);
5601 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
5602 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
5606 page_length = (sizeof(struct ipr_mode_page_hdr) +
5607 mode_hdr->page_length);
5608 length -= page_length;
5609 mode_hdr = (struct ipr_mode_page_hdr *)
5610 ((unsigned long)mode_hdr + page_length);
5617 * ipr_check_term_power - Check for term power errors
5618 * @ioa_cfg: ioa config struct
5619 * @mode_pages: IOAFP mode pages buffer
5621 * Check the IOAFP's mode page 28 for term power errors
5626 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
5627 struct ipr_mode_pages *mode_pages)
5631 struct ipr_dev_bus_entry *bus;
5632 struct ipr_mode_page28 *mode_page;
5634 mode_page = ipr_get_mode_page(mode_pages, 0x28,
5635 sizeof(struct ipr_mode_page28));
5637 entry_length = mode_page->entry_length;
5639 bus = mode_page->bus;
5641 for (i = 0; i < mode_page->num_entries; i++) {
5642 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
5643 dev_err(&ioa_cfg->pdev->dev,
5644 "Term power is absent on scsi bus %d\n",
5648 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
5653 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
5654 * @ioa_cfg: ioa config struct
5656 * Looks through the config table checking for SES devices. If
5657 * the SES device is in the SES table indicating a maximum SCSI
5658 * bus speed, the speed is limited for the bus.
5663 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
5668 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
5669 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
5670 ioa_cfg->bus_attr[i].bus_width);
5672 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
5673 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
5678 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
5679 * @ioa_cfg: ioa config struct
5680 * @mode_pages: mode page 28 buffer
5682 * Updates mode page 28 based on driver configuration
5687 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
5688 struct ipr_mode_pages *mode_pages)
5690 int i, entry_length;
5691 struct ipr_dev_bus_entry *bus;
5692 struct ipr_bus_attributes *bus_attr;
5693 struct ipr_mode_page28 *mode_page;
5695 mode_page = ipr_get_mode_page(mode_pages, 0x28,
5696 sizeof(struct ipr_mode_page28));
5698 entry_length = mode_page->entry_length;
5700 /* Loop for each device bus entry */
5701 for (i = 0, bus = mode_page->bus;
5702 i < mode_page->num_entries;
5703 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
5704 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
5705 dev_err(&ioa_cfg->pdev->dev,
5706 "Invalid resource address reported: 0x%08X\n",
5707 IPR_GET_PHYS_LOC(bus->res_addr));
5711 bus_attr = &ioa_cfg->bus_attr[i];
5712 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
5713 bus->bus_width = bus_attr->bus_width;
5714 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
5715 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
5716 if (bus_attr->qas_enabled)
5717 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
5719 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
5724 * ipr_build_mode_select - Build a mode select command
5725 * @ipr_cmd: ipr command struct
5726 * @res_handle: resource handle to send command to
5727 * @parm: Byte 2 of Mode Sense command
5728 * @dma_addr: DMA buffer address
5729 * @xfer_len: data transfer length
5734 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
5735 __be32 res_handle, u8 parm, u32 dma_addr,
5738 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5739 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5741 ioarcb->res_handle = res_handle;
5742 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5743 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5744 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
5745 ioarcb->cmd_pkt.cdb[1] = parm;
5746 ioarcb->cmd_pkt.cdb[4] = xfer_len;
5748 ioadl->flags_and_data_len =
5749 cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST | xfer_len);
5750 ioadl->address = cpu_to_be32(dma_addr);
5751 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5752 ioarcb->write_data_transfer_length = cpu_to_be32(xfer_len);
5756 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
5757 * @ipr_cmd: ipr command struct
5759 * This function sets up the SCSI bus attributes and sends
5760 * a Mode Select for Page 28 to activate them.
5765 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
5767 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5768 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
5772 ipr_scsi_bus_speed_limit(ioa_cfg);
5773 ipr_check_term_power(ioa_cfg, mode_pages);
5774 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
5775 length = mode_pages->hdr.length + 1;
5776 mode_pages->hdr.length = 0;
5778 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
5779 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
5782 ipr_cmd->job_step = ipr_setup_write_cache;
5783 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5786 return IPR_RC_JOB_RETURN;
5790 * ipr_build_mode_sense - Builds a mode sense command
5791 * @ipr_cmd: ipr command struct
5792 * @res: resource entry struct
5793 * @parm: Byte 2 of mode sense command
5794 * @dma_addr: DMA address of mode sense buffer
5795 * @xfer_len: Size of DMA buffer
5800 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
5802 u8 parm, u32 dma_addr, u8 xfer_len)
5804 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5805 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5807 ioarcb->res_handle = res_handle;
5808 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
5809 ioarcb->cmd_pkt.cdb[2] = parm;
5810 ioarcb->cmd_pkt.cdb[4] = xfer_len;
5811 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5813 ioadl->flags_and_data_len =
5814 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
5815 ioadl->address = cpu_to_be32(dma_addr);
5816 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5817 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
5821 * ipr_reset_cmd_failed - Handle failure of IOA reset command
5822 * @ipr_cmd: ipr command struct
5824 * This function handles the failure of an IOA bringup command.
5829 static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
5831 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5832 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5834 dev_err(&ioa_cfg->pdev->dev,
5835 "0x%02X failed with IOASC: 0x%08X\n",
5836 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
5838 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5839 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5840 return IPR_RC_JOB_RETURN;
5844 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
5845 * @ipr_cmd: ipr command struct
5847 * This function handles the failure of a Mode Sense to the IOAFP.
5848 * Some adapters do not handle all mode pages.
5851 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5853 static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
5855 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5857 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
5858 ipr_cmd->job_step = ipr_setup_write_cache;
5859 return IPR_RC_JOB_CONTINUE;
5862 return ipr_reset_cmd_failed(ipr_cmd);
5866 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
5867 * @ipr_cmd: ipr command struct
5869 * This function send a Page 28 mode sense to the IOA to
5870 * retrieve SCSI bus attributes.
5875 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
5877 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5880 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
5881 0x28, ioa_cfg->vpd_cbs_dma +
5882 offsetof(struct ipr_misc_cbs, mode_pages),
5883 sizeof(struct ipr_mode_pages));
5885 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
5886 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
5888 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5891 return IPR_RC_JOB_RETURN;
5895 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
5896 * @ipr_cmd: ipr command struct
5898 * This function enables dual IOA RAID support if possible.
5903 static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
5905 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5906 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
5907 struct ipr_mode_page24 *mode_page;
5911 mode_page = ipr_get_mode_page(mode_pages, 0x24,
5912 sizeof(struct ipr_mode_page24));
5915 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
5917 length = mode_pages->hdr.length + 1;
5918 mode_pages->hdr.length = 0;
5920 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
5921 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
5924 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
5925 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5928 return IPR_RC_JOB_RETURN;
5932 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
5933 * @ipr_cmd: ipr command struct
5935 * This function handles the failure of a Mode Sense to the IOAFP.
5936 * Some adapters do not handle all mode pages.
5939 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5941 static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
5943 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5945 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
5946 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
5947 return IPR_RC_JOB_CONTINUE;
5950 return ipr_reset_cmd_failed(ipr_cmd);
5954 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
5955 * @ipr_cmd: ipr command struct
5957 * This function send a mode sense to the IOA to retrieve
5958 * the IOA Advanced Function Control mode page.
5963 static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
5965 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5968 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
5969 0x24, ioa_cfg->vpd_cbs_dma +
5970 offsetof(struct ipr_misc_cbs, mode_pages),
5971 sizeof(struct ipr_mode_pages));
5973 ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
5974 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
5976 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5979 return IPR_RC_JOB_RETURN;
5983 * ipr_init_res_table - Initialize the resource table
5984 * @ipr_cmd: ipr command struct
5986 * This function looks through the existing resource table, comparing
5987 * it with the config table. This function will take care of old/new
5988 * devices and schedule adding/removing them from the mid-layer
5992 * IPR_RC_JOB_CONTINUE
5994 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
5996 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5997 struct ipr_resource_entry *res, *temp;
5998 struct ipr_config_table_entry *cfgte;
6003 if (ioa_cfg->cfg_table->hdr.flags & IPR_UCODE_DOWNLOAD_REQ)
6004 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
6006 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
6007 list_move_tail(&res->queue, &old_res);
6009 for (i = 0; i < ioa_cfg->cfg_table->hdr.num_entries; i++) {
6010 cfgte = &ioa_cfg->cfg_table->dev[i];
6013 list_for_each_entry_safe(res, temp, &old_res, queue) {
6014 if (!memcmp(&res->cfgte.res_addr,
6015 &cfgte->res_addr, sizeof(cfgte->res_addr))) {
6016 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
6023 if (list_empty(&ioa_cfg->free_res_q)) {
6024 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
6029 res = list_entry(ioa_cfg->free_res_q.next,
6030 struct ipr_resource_entry, queue);
6031 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
6032 ipr_init_res_entry(res);
6037 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
6040 list_for_each_entry_safe(res, temp, &old_res, queue) {
6042 res->del_from_ml = 1;
6043 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
6044 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
6046 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
6050 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
6051 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
6053 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6056 return IPR_RC_JOB_CONTINUE;
6060 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
6061 * @ipr_cmd: ipr command struct
6063 * This function sends a Query IOA Configuration command
6064 * to the adapter to retrieve the IOA configuration table.
6069 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
6071 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6072 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6073 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
6074 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
6075 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
6078 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
6079 ioa_cfg->dual_raid = 1;
6080 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
6081 ucode_vpd->major_release, ucode_vpd->card_type,
6082 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
6083 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6084 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6086 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
6087 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_config_table) >> 8) & 0xff;
6088 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_config_table) & 0xff;
6090 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
6091 ioarcb->read_data_transfer_length =
6092 cpu_to_be32(sizeof(struct ipr_config_table));
6094 ioadl->address = cpu_to_be32(ioa_cfg->cfg_table_dma);
6095 ioadl->flags_and_data_len =
6096 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(struct ipr_config_table));
6098 ipr_cmd->job_step = ipr_init_res_table;
6100 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6103 return IPR_RC_JOB_RETURN;
6107 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
6108 * @ipr_cmd: ipr command struct
6110 * This utility function sends an inquiry to the adapter.
6115 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
6116 u32 dma_addr, u8 xfer_len)
6118 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6119 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
6122 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6123 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6125 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
6126 ioarcb->cmd_pkt.cdb[1] = flags;
6127 ioarcb->cmd_pkt.cdb[2] = page;
6128 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6130 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
6131 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
6133 ioadl->address = cpu_to_be32(dma_addr);
6134 ioadl->flags_and_data_len =
6135 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
6137 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6142 * ipr_inquiry_page_supported - Is the given inquiry page supported
6143 * @page0: inquiry page 0 buffer
6146 * This function determines if the specified inquiry page is supported.
6149 * 1 if page is supported / 0 if not
6151 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
6155 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
6156 if (page0->page[i] == page)
6163 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
6164 * @ipr_cmd: ipr command struct
6166 * This function sends a Page 0xD0 inquiry to the adapter
6167 * to retrieve adapter capabilities.
6170 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6172 static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
6174 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6175 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
6176 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
6179 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
6180 memset(cap, 0, sizeof(*cap));
6182 if (ipr_inquiry_page_supported(page0, 0xD0)) {
6183 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
6184 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
6185 sizeof(struct ipr_inquiry_cap));
6186 return IPR_RC_JOB_RETURN;
6190 return IPR_RC_JOB_CONTINUE;
6194 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
6195 * @ipr_cmd: ipr command struct
6197 * This function sends a Page 3 inquiry to the adapter
6198 * to retrieve software VPD information.
6201 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6203 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
6205 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6206 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
6210 if (!ipr_inquiry_page_supported(page0, 1))
6211 ioa_cfg->cache_state = CACHE_NONE;
6213 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
6215 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
6216 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
6217 sizeof(struct ipr_inquiry_page3));
6220 return IPR_RC_JOB_RETURN;
6224 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
6225 * @ipr_cmd: ipr command struct
6227 * This function sends a Page 0 inquiry to the adapter
6228 * to retrieve supported inquiry pages.
6231 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6233 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
6235 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6240 /* Grab the type out of the VPD and store it away */
6241 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
6243 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
6245 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
6247 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
6248 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
6249 sizeof(struct ipr_inquiry_page0));
6252 return IPR_RC_JOB_RETURN;
6256 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
6257 * @ipr_cmd: ipr command struct
6259 * This function sends a standard inquiry to the adapter.
6264 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
6266 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6269 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
6271 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
6272 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
6273 sizeof(struct ipr_ioa_vpd));
6276 return IPR_RC_JOB_RETURN;
6280 * ipr_ioafp_indentify_hrrq - Send Identify Host RRQ.
6281 * @ipr_cmd: ipr command struct
6283 * This function send an Identify Host Request Response Queue
6284 * command to establish the HRRQ with the adapter.
6289 static int ipr_ioafp_indentify_hrrq(struct ipr_cmnd *ipr_cmd)
6291 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6292 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6295 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
6297 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
6298 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6300 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6301 ioarcb->cmd_pkt.cdb[2] =
6302 ((u32) ioa_cfg->host_rrq_dma >> 24) & 0xff;
6303 ioarcb->cmd_pkt.cdb[3] =
6304 ((u32) ioa_cfg->host_rrq_dma >> 16) & 0xff;
6305 ioarcb->cmd_pkt.cdb[4] =
6306 ((u32) ioa_cfg->host_rrq_dma >> 8) & 0xff;
6307 ioarcb->cmd_pkt.cdb[5] =
6308 ((u32) ioa_cfg->host_rrq_dma) & 0xff;
6309 ioarcb->cmd_pkt.cdb[7] =
6310 ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
6311 ioarcb->cmd_pkt.cdb[8] =
6312 (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
6314 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
6316 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6319 return IPR_RC_JOB_RETURN;
6323 * ipr_reset_timer_done - Adapter reset timer function
6324 * @ipr_cmd: ipr command struct
6326 * Description: This function is used in adapter reset processing
6327 * for timing events. If the reset_cmd pointer in the IOA
6328 * config struct is not this adapter's we are doing nested
6329 * resets and fail_all_ops will take care of freeing the
6335 static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
6337 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6338 unsigned long lock_flags = 0;
6340 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6342 if (ioa_cfg->reset_cmd == ipr_cmd) {
6343 list_del(&ipr_cmd->queue);
6344 ipr_cmd->done(ipr_cmd);
6347 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6351 * ipr_reset_start_timer - Start a timer for adapter reset job
6352 * @ipr_cmd: ipr command struct
6353 * @timeout: timeout value
6355 * Description: This function is used in adapter reset processing
6356 * for timing events. If the reset_cmd pointer in the IOA
6357 * config struct is not this adapter's we are doing nested
6358 * resets and fail_all_ops will take care of freeing the
6364 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
6365 unsigned long timeout)
6367 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
6368 ipr_cmd->done = ipr_reset_ioa_job;
6370 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
6371 ipr_cmd->timer.expires = jiffies + timeout;
6372 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
6373 add_timer(&ipr_cmd->timer);
6377 * ipr_init_ioa_mem - Initialize ioa_cfg control block
6378 * @ioa_cfg: ioa cfg struct
6383 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
6385 memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
6387 /* Initialize Host RRQ pointers */
6388 ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
6389 ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
6390 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
6391 ioa_cfg->toggle_bit = 1;
6393 /* Zero out config table */
6394 memset(ioa_cfg->cfg_table, 0, sizeof(struct ipr_config_table));
6398 * ipr_reset_enable_ioa - Enable the IOA following a reset.
6399 * @ipr_cmd: ipr command struct
6401 * This function reinitializes some control blocks and
6402 * enables destructive diagnostics on the adapter.
6407 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
6409 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6410 volatile u32 int_reg;
6413 ipr_cmd->job_step = ipr_ioafp_indentify_hrrq;
6414 ipr_init_ioa_mem(ioa_cfg);
6416 ioa_cfg->allow_interrupts = 1;
6417 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
6419 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
6420 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
6421 ioa_cfg->regs.clr_interrupt_mask_reg);
6422 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
6423 return IPR_RC_JOB_CONTINUE;
6426 /* Enable destructive diagnostics on IOA */
6427 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg);
6429 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg);
6430 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
6432 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
6434 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
6435 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
6436 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
6437 ipr_cmd->done = ipr_reset_ioa_job;
6438 add_timer(&ipr_cmd->timer);
6439 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
6442 return IPR_RC_JOB_RETURN;
6446 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
6447 * @ipr_cmd: ipr command struct
6449 * This function is invoked when an adapter dump has run out
6450 * of processing time.
6453 * IPR_RC_JOB_CONTINUE
6455 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
6457 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6459 if (ioa_cfg->sdt_state == GET_DUMP)
6460 ioa_cfg->sdt_state = ABORT_DUMP;
6462 ipr_cmd->job_step = ipr_reset_alert;
6464 return IPR_RC_JOB_CONTINUE;
6468 * ipr_unit_check_no_data - Log a unit check/no data error log
6469 * @ioa_cfg: ioa config struct
6471 * Logs an error indicating the adapter unit checked, but for some
6472 * reason, we were unable to fetch the unit check buffer.
6477 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
6479 ioa_cfg->errors_logged++;
6480 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
6484 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
6485 * @ioa_cfg: ioa config struct
6487 * Fetches the unit check buffer from the adapter by clocking the data
6488 * through the mailbox register.
6493 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
6495 unsigned long mailbox;
6496 struct ipr_hostrcb *hostrcb;
6497 struct ipr_uc_sdt sdt;
6501 mailbox = readl(ioa_cfg->ioa_mailbox);
6503 if (!ipr_sdt_is_fmt2(mailbox)) {
6504 ipr_unit_check_no_data(ioa_cfg);
6508 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
6509 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
6510 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
6512 if (rc || (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE) ||
6513 !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY)) {
6514 ipr_unit_check_no_data(ioa_cfg);
6518 /* Find length of the first sdt entry (UC buffer) */
6519 length = (be32_to_cpu(sdt.entry[0].end_offset) -
6520 be32_to_cpu(sdt.entry[0].bar_str_offset)) & IPR_FMT2_MBX_ADDR_MASK;
6522 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
6523 struct ipr_hostrcb, queue);
6524 list_del(&hostrcb->queue);
6525 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
6527 rc = ipr_get_ldump_data_section(ioa_cfg,
6528 be32_to_cpu(sdt.entry[0].bar_str_offset),
6529 (__be32 *)&hostrcb->hcam,
6530 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
6533 ipr_handle_log_data(ioa_cfg, hostrcb);
6534 ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
6535 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
6536 ioa_cfg->sdt_state == GET_DUMP)
6537 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
6539 ipr_unit_check_no_data(ioa_cfg);
6541 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
6545 * ipr_reset_restore_cfg_space - Restore PCI config space.
6546 * @ipr_cmd: ipr command struct
6548 * Description: This function restores the saved PCI config space of
6549 * the adapter, fails all outstanding ops back to the callers, and
6550 * fetches the dump/unit check if applicable to this reset.
6553 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6555 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
6557 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6561 rc = pci_restore_state(ioa_cfg->pdev);
6563 if (rc != PCIBIOS_SUCCESSFUL) {
6564 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6565 return IPR_RC_JOB_CONTINUE;
6568 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
6569 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6570 return IPR_RC_JOB_CONTINUE;
6573 ipr_fail_all_ops(ioa_cfg);
6575 if (ioa_cfg->ioa_unit_checked) {
6576 ioa_cfg->ioa_unit_checked = 0;
6577 ipr_get_unit_check_buffer(ioa_cfg);
6578 ipr_cmd->job_step = ipr_reset_alert;
6579 ipr_reset_start_timer(ipr_cmd, 0);
6580 return IPR_RC_JOB_RETURN;
6583 if (ioa_cfg->in_ioa_bringdown) {
6584 ipr_cmd->job_step = ipr_ioa_bringdown_done;
6586 ipr_cmd->job_step = ipr_reset_enable_ioa;
6588 if (GET_DUMP == ioa_cfg->sdt_state) {
6589 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_TIMEOUT);
6590 ipr_cmd->job_step = ipr_reset_wait_for_dump;
6591 schedule_work(&ioa_cfg->work_q);
6592 return IPR_RC_JOB_RETURN;
6597 return IPR_RC_JOB_CONTINUE;
6601 * ipr_reset_bist_done - BIST has completed on the adapter.
6602 * @ipr_cmd: ipr command struct
6604 * Description: Unblock config space and resume the reset process.
6607 * IPR_RC_JOB_CONTINUE
6609 static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
6612 pci_unblock_user_cfg_access(ipr_cmd->ioa_cfg->pdev);
6613 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
6615 return IPR_RC_JOB_CONTINUE;
6619 * ipr_reset_start_bist - Run BIST on the adapter.
6620 * @ipr_cmd: ipr command struct
6622 * Description: This function runs BIST on the adapter, then delays 2 seconds.
6625 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6627 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
6629 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6633 pci_block_user_cfg_access(ioa_cfg->pdev);
6634 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
6636 if (rc != PCIBIOS_SUCCESSFUL) {
6637 pci_unblock_user_cfg_access(ipr_cmd->ioa_cfg->pdev);
6638 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6639 rc = IPR_RC_JOB_CONTINUE;
6641 ipr_cmd->job_step = ipr_reset_bist_done;
6642 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
6643 rc = IPR_RC_JOB_RETURN;
6651 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
6652 * @ipr_cmd: ipr command struct
6654 * Description: This clears PCI reset to the adapter and delays two seconds.
6659 static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
6662 pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
6663 ipr_cmd->job_step = ipr_reset_bist_done;
6664 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
6666 return IPR_RC_JOB_RETURN;
6670 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
6671 * @ipr_cmd: ipr command struct
6673 * Description: This asserts PCI reset to the adapter.
6678 static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
6680 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6681 struct pci_dev *pdev = ioa_cfg->pdev;
6684 pci_block_user_cfg_access(pdev);
6685 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
6686 ipr_cmd->job_step = ipr_reset_slot_reset_done;
6687 ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
6689 return IPR_RC_JOB_RETURN;
6693 * ipr_reset_allowed - Query whether or not IOA can be reset
6694 * @ioa_cfg: ioa config struct
6697 * 0 if reset not allowed / non-zero if reset is allowed
6699 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
6701 volatile u32 temp_reg;
6703 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
6704 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
6708 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
6709 * @ipr_cmd: ipr command struct
6711 * Description: This function waits for adapter permission to run BIST,
6712 * then runs BIST. If the adapter does not give permission after a
6713 * reasonable time, we will reset the adapter anyway. The impact of
6714 * resetting the adapter without warning the adapter is the risk of
6715 * losing the persistent error log on the adapter. If the adapter is
6716 * reset while it is writing to the flash on the adapter, the flash
6717 * segment will have bad ECC and be zeroed.
6720 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6722 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
6724 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6725 int rc = IPR_RC_JOB_RETURN;
6727 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
6728 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
6729 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
6731 ipr_cmd->job_step = ioa_cfg->reset;
6732 rc = IPR_RC_JOB_CONTINUE;
6739 * ipr_reset_alert_part2 - Alert the adapter of a pending reset
6740 * @ipr_cmd: ipr command struct
6742 * Description: This function alerts the adapter that it will be reset.
6743 * If memory space is not currently enabled, proceed directly
6744 * to running BIST on the adapter. The timer must always be started
6745 * so we guarantee we do not run BIST from ipr_isr.
6750 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
6752 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6757 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
6759 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
6760 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
6761 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg);
6762 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
6764 ipr_cmd->job_step = ioa_cfg->reset;
6767 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
6768 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
6771 return IPR_RC_JOB_RETURN;
6775 * ipr_reset_ucode_download_done - Microcode download completion
6776 * @ipr_cmd: ipr command struct
6778 * Description: This function unmaps the microcode download buffer.
6781 * IPR_RC_JOB_CONTINUE
6783 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
6785 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6786 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
6788 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
6789 sglist->num_sg, DMA_TO_DEVICE);
6791 ipr_cmd->job_step = ipr_reset_alert;
6792 return IPR_RC_JOB_CONTINUE;
6796 * ipr_reset_ucode_download - Download microcode to the adapter
6797 * @ipr_cmd: ipr command struct
6799 * Description: This function checks to see if it there is microcode
6800 * to download to the adapter. If there is, a download is performed.
6803 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6805 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
6807 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6808 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
6811 ipr_cmd->job_step = ipr_reset_alert;
6814 return IPR_RC_JOB_CONTINUE;
6816 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6817 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6818 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
6819 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
6820 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
6821 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
6822 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
6824 ipr_build_ucode_ioadl(ipr_cmd, sglist);
6825 ipr_cmd->job_step = ipr_reset_ucode_download_done;
6827 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
6828 IPR_WRITE_BUFFER_TIMEOUT);
6831 return IPR_RC_JOB_RETURN;
6835 * ipr_reset_shutdown_ioa - Shutdown the adapter
6836 * @ipr_cmd: ipr command struct
6838 * Description: This function issues an adapter shutdown of the
6839 * specified type to the specified adapter as part of the
6840 * adapter reset job.
6843 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6845 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
6847 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6848 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
6849 unsigned long timeout;
6850 int rc = IPR_RC_JOB_CONTINUE;
6853 if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
6854 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6855 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6856 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
6857 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
6859 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
6860 timeout = IPR_SHUTDOWN_TIMEOUT;
6861 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
6862 timeout = IPR_INTERNAL_TIMEOUT;
6863 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
6864 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
6866 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
6868 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
6870 rc = IPR_RC_JOB_RETURN;
6871 ipr_cmd->job_step = ipr_reset_ucode_download;
6873 ipr_cmd->job_step = ipr_reset_alert;
6880 * ipr_reset_ioa_job - Adapter reset job
6881 * @ipr_cmd: ipr command struct
6883 * Description: This function is the job router for the adapter reset job.
6888 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
6891 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6894 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
6896 if (ioa_cfg->reset_cmd != ipr_cmd) {
6898 * We are doing nested adapter resets and this is
6899 * not the current reset job.
6901 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6905 if (IPR_IOASC_SENSE_KEY(ioasc)) {
6906 rc = ipr_cmd->job_step_failed(ipr_cmd);
6907 if (rc == IPR_RC_JOB_RETURN)
6911 ipr_reinit_ipr_cmnd(ipr_cmd);
6912 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
6913 rc = ipr_cmd->job_step(ipr_cmd);
6914 } while(rc == IPR_RC_JOB_CONTINUE);
6918 * _ipr_initiate_ioa_reset - Initiate an adapter reset
6919 * @ioa_cfg: ioa config struct
6920 * @job_step: first job step of reset job
6921 * @shutdown_type: shutdown type
6923 * Description: This function will initiate the reset of the given adapter
6924 * starting at the selected job step.
6925 * If the caller needs to wait on the completion of the reset,
6926 * the caller must sleep on the reset_wait_q.
6931 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
6932 int (*job_step) (struct ipr_cmnd *),
6933 enum ipr_shutdown_type shutdown_type)
6935 struct ipr_cmnd *ipr_cmd;
6937 ioa_cfg->in_reset_reload = 1;
6938 ioa_cfg->allow_cmds = 0;
6939 scsi_block_requests(ioa_cfg->host);
6941 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
6942 ioa_cfg->reset_cmd = ipr_cmd;
6943 ipr_cmd->job_step = job_step;
6944 ipr_cmd->u.shutdown_type = shutdown_type;
6946 ipr_reset_ioa_job(ipr_cmd);
6950 * ipr_initiate_ioa_reset - Initiate an adapter reset
6951 * @ioa_cfg: ioa config struct
6952 * @shutdown_type: shutdown type
6954 * Description: This function will initiate the reset of the given adapter.
6955 * If the caller needs to wait on the completion of the reset,
6956 * the caller must sleep on the reset_wait_q.
6961 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
6962 enum ipr_shutdown_type shutdown_type)
6964 if (ioa_cfg->ioa_is_dead)
6967 if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
6968 ioa_cfg->sdt_state = ABORT_DUMP;
6970 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
6971 dev_err(&ioa_cfg->pdev->dev,
6972 "IOA taken offline - error recovery failed\n");
6974 ioa_cfg->reset_retries = 0;
6975 ioa_cfg->ioa_is_dead = 1;
6977 if (ioa_cfg->in_ioa_bringdown) {
6978 ioa_cfg->reset_cmd = NULL;
6979 ioa_cfg->in_reset_reload = 0;
6980 ipr_fail_all_ops(ioa_cfg);
6981 wake_up_all(&ioa_cfg->reset_wait_q);
6983 spin_unlock_irq(ioa_cfg->host->host_lock);
6984 scsi_unblock_requests(ioa_cfg->host);
6985 spin_lock_irq(ioa_cfg->host->host_lock);
6988 ioa_cfg->in_ioa_bringdown = 1;
6989 shutdown_type = IPR_SHUTDOWN_NONE;
6993 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
6998 * ipr_reset_freeze - Hold off all I/O activity
6999 * @ipr_cmd: ipr command struct
7001 * Description: If the PCI slot is frozen, hold off all I/O
7002 * activity; then, as soon as the slot is available again,
7003 * initiate an adapter reset.
7005 static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
7007 /* Disallow new interrupts, avoid loop */
7008 ipr_cmd->ioa_cfg->allow_interrupts = 0;
7009 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
7010 ipr_cmd->done = ipr_reset_ioa_job;
7011 return IPR_RC_JOB_RETURN;
7015 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
7016 * @pdev: PCI device struct
7018 * Description: This routine is called to tell us that the PCI bus
7019 * is down. Can't do anything here, except put the device driver
7020 * into a holding pattern, waiting for the PCI bus to come back.
7022 static void ipr_pci_frozen(struct pci_dev *pdev)
7024 unsigned long flags = 0;
7025 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7027 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
7028 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
7029 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
7033 * ipr_pci_slot_reset - Called when PCI slot has been reset.
7034 * @pdev: PCI device struct
7036 * Description: This routine is called by the pci error recovery
7037 * code after the PCI slot has been reset, just before we
7038 * should resume normal operations.
7040 static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
7042 unsigned long flags = 0;
7043 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7045 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
7046 if (ioa_cfg->needs_warm_reset)
7047 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7049 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
7051 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
7052 return PCI_ERS_RESULT_RECOVERED;
7056 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
7057 * @pdev: PCI device struct
7059 * Description: This routine is called when the PCI bus has
7060 * permanently failed.
7062 static void ipr_pci_perm_failure(struct pci_dev *pdev)
7064 unsigned long flags = 0;
7065 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7067 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
7068 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
7069 ioa_cfg->sdt_state = ABORT_DUMP;
7070 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES;
7071 ioa_cfg->in_ioa_bringdown = 1;
7072 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7073 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
7077 * ipr_pci_error_detected - Called when a PCI error is detected.
7078 * @pdev: PCI device struct
7079 * @state: PCI channel state
7081 * Description: Called when a PCI error is detected.
7084 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7086 static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
7087 pci_channel_state_t state)
7090 case pci_channel_io_frozen:
7091 ipr_pci_frozen(pdev);
7092 return PCI_ERS_RESULT_NEED_RESET;
7093 case pci_channel_io_perm_failure:
7094 ipr_pci_perm_failure(pdev);
7095 return PCI_ERS_RESULT_DISCONNECT;
7100 return PCI_ERS_RESULT_NEED_RESET;
7104 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
7105 * @ioa_cfg: ioa cfg struct
7107 * Description: This is the second phase of adapter intialization
7108 * This function takes care of initilizing the adapter to the point
7109 * where it can accept new commands.
7112 * 0 on sucess / -EIO on failure
7114 static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
7117 unsigned long host_lock_flags = 0;
7120 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7121 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
7122 if (ioa_cfg->needs_hard_reset) {
7123 ioa_cfg->needs_hard_reset = 0;
7124 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7126 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
7129 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7130 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7131 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7133 if (ioa_cfg->ioa_is_dead) {
7135 } else if (ipr_invalid_adapter(ioa_cfg)) {
7139 dev_err(&ioa_cfg->pdev->dev,
7140 "Adapter not supported in this hardware configuration.\n");
7143 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7150 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
7151 * @ioa_cfg: ioa config struct
7156 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
7160 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
7161 if (ioa_cfg->ipr_cmnd_list[i])
7162 pci_pool_free(ioa_cfg->ipr_cmd_pool,
7163 ioa_cfg->ipr_cmnd_list[i],
7164 ioa_cfg->ipr_cmnd_list_dma[i]);
7166 ioa_cfg->ipr_cmnd_list[i] = NULL;
7169 if (ioa_cfg->ipr_cmd_pool)
7170 pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
7172 ioa_cfg->ipr_cmd_pool = NULL;
7176 * ipr_free_mem - Frees memory allocated for an adapter
7177 * @ioa_cfg: ioa cfg struct
7182 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
7186 kfree(ioa_cfg->res_entries);
7187 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
7188 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
7189 ipr_free_cmd_blks(ioa_cfg);
7190 pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
7191 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
7192 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_config_table),
7194 ioa_cfg->cfg_table_dma);
7196 for (i = 0; i < IPR_NUM_HCAMS; i++) {
7197 pci_free_consistent(ioa_cfg->pdev,
7198 sizeof(struct ipr_hostrcb),
7199 ioa_cfg->hostrcb[i],
7200 ioa_cfg->hostrcb_dma[i]);
7203 ipr_free_dump(ioa_cfg);
7204 kfree(ioa_cfg->trace);
7208 * ipr_free_all_resources - Free all allocated resources for an adapter.
7209 * @ipr_cmd: ipr command struct
7211 * This function frees all allocated resources for the
7212 * specified adapter.
7217 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
7219 struct pci_dev *pdev = ioa_cfg->pdev;
7222 free_irq(pdev->irq, ioa_cfg);
7223 iounmap(ioa_cfg->hdw_dma_regs);
7224 pci_release_regions(pdev);
7225 ipr_free_mem(ioa_cfg);
7226 scsi_host_put(ioa_cfg->host);
7227 pci_disable_device(pdev);
7232 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
7233 * @ioa_cfg: ioa config struct
7236 * 0 on success / -ENOMEM on allocation failure
7238 static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
7240 struct ipr_cmnd *ipr_cmd;
7241 struct ipr_ioarcb *ioarcb;
7242 dma_addr_t dma_addr;
7245 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
7246 sizeof(struct ipr_cmnd), 8, 0);
7248 if (!ioa_cfg->ipr_cmd_pool)
7251 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
7252 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
7255 ipr_free_cmd_blks(ioa_cfg);
7259 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
7260 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
7261 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
7263 ioarcb = &ipr_cmd->ioarcb;
7264 ioarcb->ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
7265 ioarcb->host_response_handle = cpu_to_be32(i << 2);
7266 ioarcb->write_ioadl_addr =
7267 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
7268 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
7269 ioarcb->ioasa_host_pci_addr =
7270 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioasa));
7271 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
7272 ipr_cmd->cmd_index = i;
7273 ipr_cmd->ioa_cfg = ioa_cfg;
7274 ipr_cmd->sense_buffer_dma = dma_addr +
7275 offsetof(struct ipr_cmnd, sense_buffer);
7277 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
7284 * ipr_alloc_mem - Allocate memory for an adapter
7285 * @ioa_cfg: ioa config struct
7288 * 0 on success / non-zero for error
7290 static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
7292 struct pci_dev *pdev = ioa_cfg->pdev;
7293 int i, rc = -ENOMEM;
7296 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
7297 IPR_MAX_PHYSICAL_DEVS, GFP_KERNEL);
7299 if (!ioa_cfg->res_entries)
7302 for (i = 0; i < IPR_MAX_PHYSICAL_DEVS; i++)
7303 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
7305 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
7306 sizeof(struct ipr_misc_cbs),
7307 &ioa_cfg->vpd_cbs_dma);
7309 if (!ioa_cfg->vpd_cbs)
7310 goto out_free_res_entries;
7312 if (ipr_alloc_cmd_blks(ioa_cfg))
7313 goto out_free_vpd_cbs;
7315 ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
7316 sizeof(u32) * IPR_NUM_CMD_BLKS,
7317 &ioa_cfg->host_rrq_dma);
7319 if (!ioa_cfg->host_rrq)
7320 goto out_ipr_free_cmd_blocks;
7322 ioa_cfg->cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
7323 sizeof(struct ipr_config_table),
7324 &ioa_cfg->cfg_table_dma);
7326 if (!ioa_cfg->cfg_table)
7327 goto out_free_host_rrq;
7329 for (i = 0; i < IPR_NUM_HCAMS; i++) {
7330 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
7331 sizeof(struct ipr_hostrcb),
7332 &ioa_cfg->hostrcb_dma[i]);
7334 if (!ioa_cfg->hostrcb[i])
7335 goto out_free_hostrcb_dma;
7337 ioa_cfg->hostrcb[i]->hostrcb_dma =
7338 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
7339 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
7340 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
7343 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
7344 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
7346 if (!ioa_cfg->trace)
7347 goto out_free_hostrcb_dma;
7354 out_free_hostrcb_dma:
7356 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
7357 ioa_cfg->hostrcb[i],
7358 ioa_cfg->hostrcb_dma[i]);
7360 pci_free_consistent(pdev, sizeof(struct ipr_config_table),
7361 ioa_cfg->cfg_table, ioa_cfg->cfg_table_dma);
7363 pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
7364 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
7365 out_ipr_free_cmd_blocks:
7366 ipr_free_cmd_blks(ioa_cfg);
7368 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
7369 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
7370 out_free_res_entries:
7371 kfree(ioa_cfg->res_entries);
7376 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
7377 * @ioa_cfg: ioa config struct
7382 static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
7386 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
7387 ioa_cfg->bus_attr[i].bus = i;
7388 ioa_cfg->bus_attr[i].qas_enabled = 0;
7389 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
7390 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
7391 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
7393 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
7398 * ipr_init_ioa_cfg - Initialize IOA config struct
7399 * @ioa_cfg: ioa config struct
7400 * @host: scsi host struct
7401 * @pdev: PCI dev struct
7406 static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
7407 struct Scsi_Host *host, struct pci_dev *pdev)
7409 const struct ipr_interrupt_offsets *p;
7410 struct ipr_interrupts *t;
7413 ioa_cfg->host = host;
7414 ioa_cfg->pdev = pdev;
7415 ioa_cfg->log_level = ipr_log_level;
7416 ioa_cfg->doorbell = IPR_DOORBELL;
7417 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
7418 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
7419 sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
7420 sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
7421 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
7422 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
7423 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
7424 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
7426 INIT_LIST_HEAD(&ioa_cfg->free_q);
7427 INIT_LIST_HEAD(&ioa_cfg->pending_q);
7428 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
7429 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
7430 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
7431 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
7432 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
7433 init_waitqueue_head(&ioa_cfg->reset_wait_q);
7434 ioa_cfg->sdt_state = INACTIVE;
7435 if (ipr_enable_cache)
7436 ioa_cfg->cache_state = CACHE_ENABLED;
7438 ioa_cfg->cache_state = CACHE_DISABLED;
7440 ipr_initialize_bus_attr(ioa_cfg);
7442 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
7443 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
7444 host->max_channel = IPR_MAX_BUS_TO_SCAN;
7445 host->unique_id = host->host_no;
7446 host->max_cmd_len = IPR_MAX_CDB_LEN;
7447 pci_set_drvdata(pdev, ioa_cfg);
7449 p = &ioa_cfg->chip_cfg->regs;
7451 base = ioa_cfg->hdw_dma_regs;
7453 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
7454 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
7455 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
7456 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
7457 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
7458 t->ioarrin_reg = base + p->ioarrin_reg;
7459 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
7460 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
7461 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
7465 * ipr_get_chip_cfg - Find adapter chip configuration
7466 * @dev_id: PCI device id struct
7469 * ptr to chip config on success / NULL on failure
7471 static const struct ipr_chip_cfg_t * __devinit
7472 ipr_get_chip_cfg(const struct pci_device_id *dev_id)
7476 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
7477 if (ipr_chip[i].vendor == dev_id->vendor &&
7478 ipr_chip[i].device == dev_id->device)
7479 return ipr_chip[i].cfg;
7484 * ipr_probe_ioa - Allocates memory and does first stage of initialization
7485 * @pdev: PCI device struct
7486 * @dev_id: PCI device id struct
7489 * 0 on success / non-zero on failure
7491 static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
7492 const struct pci_device_id *dev_id)
7494 struct ipr_ioa_cfg *ioa_cfg;
7495 struct Scsi_Host *host;
7496 unsigned long ipr_regs_pci;
7497 void __iomem *ipr_regs;
7498 int rc = PCIBIOS_SUCCESSFUL;
7499 volatile u32 mask, uproc, interrupts;
7503 if ((rc = pci_enable_device(pdev))) {
7504 dev_err(&pdev->dev, "Cannot enable adapter\n");
7508 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
7510 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
7513 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
7518 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
7519 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
7520 ata_host_init(&ioa_cfg->ata_host, &pdev->dev,
7521 sata_port_info.flags, &ipr_sata_ops);
7523 ioa_cfg->chip_cfg = ipr_get_chip_cfg(dev_id);
7525 if (!ioa_cfg->chip_cfg) {
7526 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
7527 dev_id->vendor, dev_id->device);
7528 goto out_scsi_host_put;
7531 if (ipr_transop_timeout)
7532 ioa_cfg->transop_timeout = ipr_transop_timeout;
7533 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
7534 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
7536 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
7538 rc = pci_read_config_byte(pdev, PCI_REVISION_ID, &ioa_cfg->revid);
7540 if (rc != PCIBIOS_SUCCESSFUL) {
7541 dev_err(&pdev->dev, "Failed to read PCI revision ID\n");
7543 goto out_scsi_host_put;
7546 ipr_regs_pci = pci_resource_start(pdev, 0);
7548 rc = pci_request_regions(pdev, IPR_NAME);
7551 "Couldn't register memory range of registers\n");
7552 goto out_scsi_host_put;
7555 ipr_regs = ioremap(ipr_regs_pci, pci_resource_len(pdev, 0));
7559 "Couldn't map memory range of registers\n");
7561 goto out_release_regions;
7564 ioa_cfg->hdw_dma_regs = ipr_regs;
7565 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
7566 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
7568 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
7570 pci_set_master(pdev);
7572 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
7574 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
7578 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
7579 ioa_cfg->chip_cfg->cache_line_size);
7581 if (rc != PCIBIOS_SUCCESSFUL) {
7582 dev_err(&pdev->dev, "Write of cache line size failed\n");
7587 /* Save away PCI config space for use following IOA reset */
7588 rc = pci_save_state(pdev);
7590 if (rc != PCIBIOS_SUCCESSFUL) {
7591 dev_err(&pdev->dev, "Failed to save PCI config space\n");
7596 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
7599 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
7602 rc = ipr_alloc_mem(ioa_cfg);
7605 "Couldn't allocate enough memory for device driver!\n");
7610 * If HRRQ updated interrupt is not masked, or reset alert is set,
7611 * the card is in an unknown state and needs a hard reset
7613 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7614 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg);
7615 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
7616 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
7617 ioa_cfg->needs_hard_reset = 1;
7618 if (interrupts & IPR_PCII_ERROR_INTERRUPTS)
7619 ioa_cfg->needs_hard_reset = 1;
7620 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
7621 ioa_cfg->ioa_unit_checked = 1;
7623 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
7624 rc = request_irq(pdev->irq, ipr_isr, IRQF_SHARED, IPR_NAME, ioa_cfg);
7627 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
7632 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
7633 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
7634 ioa_cfg->needs_warm_reset = 1;
7635 ioa_cfg->reset = ipr_reset_slot_reset;
7637 ioa_cfg->reset = ipr_reset_start_bist;
7639 spin_lock(&ipr_driver_lock);
7640 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
7641 spin_unlock(&ipr_driver_lock);
7648 ipr_free_mem(ioa_cfg);
7651 out_release_regions:
7652 pci_release_regions(pdev);
7654 scsi_host_put(host);
7656 pci_disable_device(pdev);
7661 * ipr_scan_vsets - Scans for VSET devices
7662 * @ioa_cfg: ioa config struct
7664 * Description: Since the VSET resources do not follow SAM in that we can have
7665 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
7670 static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
7674 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
7675 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
7676 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
7680 * ipr_initiate_ioa_bringdown - Bring down an adapter
7681 * @ioa_cfg: ioa config struct
7682 * @shutdown_type: shutdown type
7684 * Description: This function will initiate bringing down the adapter.
7685 * This consists of issuing an IOA shutdown to the adapter
7686 * to flush the cache, and running BIST.
7687 * If the caller needs to wait on the completion of the reset,
7688 * the caller must sleep on the reset_wait_q.
7693 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
7694 enum ipr_shutdown_type shutdown_type)
7697 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
7698 ioa_cfg->sdt_state = ABORT_DUMP;
7699 ioa_cfg->reset_retries = 0;
7700 ioa_cfg->in_ioa_bringdown = 1;
7701 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
7706 * __ipr_remove - Remove a single adapter
7707 * @pdev: pci device struct
7709 * Adapter hot plug remove entry point.
7714 static void __ipr_remove(struct pci_dev *pdev)
7716 unsigned long host_lock_flags = 0;
7717 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7720 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7721 while(ioa_cfg->in_reset_reload) {
7722 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7723 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7724 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7727 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
7729 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7730 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7731 flush_scheduled_work();
7732 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7734 spin_lock(&ipr_driver_lock);
7735 list_del(&ioa_cfg->queue);
7736 spin_unlock(&ipr_driver_lock);
7738 if (ioa_cfg->sdt_state == ABORT_DUMP)
7739 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7740 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7742 ipr_free_all_resources(ioa_cfg);
7748 * ipr_remove - IOA hot plug remove entry point
7749 * @pdev: pci device struct
7751 * Adapter hot plug remove entry point.
7756 static void ipr_remove(struct pci_dev *pdev)
7758 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7762 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7764 ipr_remove_dump_file(&ioa_cfg->host->shost_classdev.kobj,
7766 scsi_remove_host(ioa_cfg->host);
7774 * ipr_probe - Adapter hot plug add entry point
7777 * 0 on success / non-zero on failure
7779 static int __devinit ipr_probe(struct pci_dev *pdev,
7780 const struct pci_device_id *dev_id)
7782 struct ipr_ioa_cfg *ioa_cfg;
7785 rc = ipr_probe_ioa(pdev, dev_id);
7790 ioa_cfg = pci_get_drvdata(pdev);
7791 rc = ipr_probe_ioa_part2(ioa_cfg);
7798 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
7805 rc = ipr_create_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7809 scsi_remove_host(ioa_cfg->host);
7814 rc = ipr_create_dump_file(&ioa_cfg->host->shost_classdev.kobj,
7818 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7820 scsi_remove_host(ioa_cfg->host);
7825 scsi_scan_host(ioa_cfg->host);
7826 ipr_scan_vsets(ioa_cfg);
7827 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
7828 ioa_cfg->allow_ml_add_del = 1;
7829 ioa_cfg->host->max_channel = IPR_VSET_BUS;
7830 schedule_work(&ioa_cfg->work_q);
7835 * ipr_shutdown - Shutdown handler.
7836 * @pdev: pci device struct
7838 * This function is invoked upon system shutdown/reboot. It will issue
7839 * an adapter shutdown to the adapter to flush the write cache.
7844 static void ipr_shutdown(struct pci_dev *pdev)
7846 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7847 unsigned long lock_flags = 0;
7849 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7850 while(ioa_cfg->in_reset_reload) {
7851 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7852 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7853 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7856 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
7857 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7858 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7861 static struct pci_device_id ipr_pci_table[] __devinitdata = {
7862 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7863 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
7864 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7865 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
7866 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7867 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
7868 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7869 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
7870 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7871 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
7872 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7873 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
7874 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7875 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
7876 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7877 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
7878 IPR_USE_LONG_TRANSOP_TIMEOUT },
7879 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7880 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
7881 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7882 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
7883 IPR_USE_LONG_TRANSOP_TIMEOUT },
7884 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7885 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
7886 IPR_USE_LONG_TRANSOP_TIMEOUT },
7887 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7888 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
7889 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7890 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
7891 IPR_USE_LONG_TRANSOP_TIMEOUT},
7892 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7893 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
7894 IPR_USE_LONG_TRANSOP_TIMEOUT },
7895 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7896 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
7897 IPR_USE_LONG_TRANSOP_TIMEOUT },
7898 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7899 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575D, 0, 0,
7900 IPR_USE_LONG_TRANSOP_TIMEOUT },
7901 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7902 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
7903 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7904 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
7905 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
7906 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
7907 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
7908 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7909 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
7910 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7911 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
7912 IPR_USE_LONG_TRANSOP_TIMEOUT },
7913 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7914 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
7915 IPR_USE_LONG_TRANSOP_TIMEOUT },
7916 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SCAMP_E,
7917 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0,
7918 IPR_USE_LONG_TRANSOP_TIMEOUT },
7921 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
7923 static struct pci_error_handlers ipr_err_handler = {
7924 .error_detected = ipr_pci_error_detected,
7925 .slot_reset = ipr_pci_slot_reset,
7928 static struct pci_driver ipr_driver = {
7930 .id_table = ipr_pci_table,
7932 .remove = ipr_remove,
7933 .shutdown = ipr_shutdown,
7934 .err_handler = &ipr_err_handler,
7935 .dynids.use_driver_data = 1
7939 * ipr_init - Module entry point
7942 * 0 on success / negative value on failure
7944 static int __init ipr_init(void)
7946 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
7947 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
7949 return pci_register_driver(&ipr_driver);
7953 * ipr_exit - Module unload
7955 * Module unload entry point.
7960 static void __exit ipr_exit(void)
7962 pci_unregister_driver(&ipr_driver);
7965 module_init(ipr_init);
7966 module_exit(ipr_exit);