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 DEFINE_SPINLOCK(ipr_driver_lock);
97 /* This table describes the differences between DMA controller chips */
98 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
99 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
101 .cache_line_size = 0x20,
103 .set_interrupt_mask_reg = 0x0022C,
104 .clr_interrupt_mask_reg = 0x00230,
105 .sense_interrupt_mask_reg = 0x0022C,
106 .clr_interrupt_reg = 0x00228,
107 .sense_interrupt_reg = 0x00224,
108 .ioarrin_reg = 0x00404,
109 .sense_uproc_interrupt_reg = 0x00214,
110 .set_uproc_interrupt_reg = 0x00214,
111 .clr_uproc_interrupt_reg = 0x00218
114 { /* Snipe and Scamp */
116 .cache_line_size = 0x20,
118 .set_interrupt_mask_reg = 0x00288,
119 .clr_interrupt_mask_reg = 0x0028C,
120 .sense_interrupt_mask_reg = 0x00288,
121 .clr_interrupt_reg = 0x00284,
122 .sense_interrupt_reg = 0x00280,
123 .ioarrin_reg = 0x00504,
124 .sense_uproc_interrupt_reg = 0x00290,
125 .set_uproc_interrupt_reg = 0x00290,
126 .clr_uproc_interrupt_reg = 0x00294
131 static const struct ipr_chip_t ipr_chip[] = {
132 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, &ipr_chip_cfg[0] },
133 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, &ipr_chip_cfg[0] },
134 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, &ipr_chip_cfg[0] },
135 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, &ipr_chip_cfg[0] },
136 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, &ipr_chip_cfg[0] },
137 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, &ipr_chip_cfg[1] },
138 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, &ipr_chip_cfg[1] }
141 static int ipr_max_bus_speeds [] = {
142 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
145 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
146 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
147 module_param_named(max_speed, ipr_max_speed, uint, 0);
148 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
149 module_param_named(log_level, ipr_log_level, uint, 0);
150 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
151 module_param_named(testmode, ipr_testmode, int, 0);
152 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
153 module_param_named(fastfail, ipr_fastfail, int, 0);
154 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
155 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
156 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
157 module_param_named(enable_cache, ipr_enable_cache, int, 0);
158 MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)");
159 module_param_named(debug, ipr_debug, int, 0);
160 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
161 MODULE_LICENSE("GPL");
162 MODULE_VERSION(IPR_DRIVER_VERSION);
164 /* A constant array of IOASCs/URCs/Error Messages */
166 struct ipr_error_table_t ipr_error_table[] = {
167 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
168 "8155: An unknown error was received"},
170 "Soft underlength error"},
172 "Command to be cancelled not found"},
174 "Qualified success"},
175 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
176 "FFFE: Soft device bus error recovered by the IOA"},
177 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
178 "4101: Soft device bus fabric error"},
179 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
180 "FFF9: Device sector reassign successful"},
181 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
182 "FFF7: Media error recovered by device rewrite procedures"},
183 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
184 "7001: IOA sector reassignment successful"},
185 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
186 "FFF9: Soft media error. Sector reassignment recommended"},
187 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
188 "FFF7: Media error recovered by IOA rewrite procedures"},
189 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
190 "FF3D: Soft PCI bus error recovered by the IOA"},
191 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
192 "FFF6: Device hardware error recovered by the IOA"},
193 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
194 "FFF6: Device hardware error recovered by the device"},
195 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
196 "FF3D: Soft IOA error recovered by the IOA"},
197 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
198 "FFFA: Undefined device response recovered by the IOA"},
199 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
200 "FFF6: Device bus error, message or command phase"},
201 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
202 "FFFE: Task Management Function failed"},
203 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
204 "FFF6: Failure prediction threshold exceeded"},
205 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
206 "8009: Impending cache battery pack failure"},
208 "34FF: Disk device format in progress"},
209 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
210 "9070: IOA requested reset"},
212 "Synchronization required"},
214 "No ready, IOA shutdown"},
216 "Not ready, IOA has been shutdown"},
217 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
218 "3020: Storage subsystem configuration error"},
220 "FFF5: Medium error, data unreadable, recommend reassign"},
222 "7000: Medium error, data unreadable, do not reassign"},
223 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
224 "FFF3: Disk media format bad"},
225 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
226 "3002: Addressed device failed to respond to selection"},
227 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
228 "3100: Device bus error"},
229 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
230 "3109: IOA timed out a device command"},
232 "3120: SCSI bus is not operational"},
233 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
234 "4100: Hard device bus fabric error"},
235 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
236 "9000: IOA reserved area data check"},
237 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
238 "9001: IOA reserved area invalid data pattern"},
239 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
240 "9002: IOA reserved area LRC error"},
241 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
242 "102E: Out of alternate sectors for disk storage"},
243 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
244 "FFF4: Data transfer underlength error"},
245 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
246 "FFF4: Data transfer overlength error"},
247 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
248 "3400: Logical unit failure"},
249 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
250 "FFF4: Device microcode is corrupt"},
251 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
252 "8150: PCI bus error"},
254 "Unsupported device bus message received"},
255 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
256 "FFF4: Disk device problem"},
257 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
258 "8150: Permanent IOA failure"},
259 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
260 "3010: Disk device returned wrong response to IOA"},
261 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
262 "8151: IOA microcode error"},
264 "Device bus status error"},
265 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
266 "8157: IOA error requiring IOA reset to recover"},
268 "ATA device status error"},
270 "Message reject received from the device"},
271 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
272 "8008: A permanent cache battery pack failure occurred"},
273 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
274 "9090: Disk unit has been modified after the last known status"},
275 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
276 "9081: IOA detected device error"},
277 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
278 "9082: IOA detected device error"},
279 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
280 "3110: Device bus error, message or command phase"},
281 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
282 "3110: SAS Command / Task Management Function failed"},
283 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
284 "9091: Incorrect hardware configuration change has been detected"},
285 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
286 "9073: Invalid multi-adapter configuration"},
287 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
288 "4010: Incorrect connection between cascaded expanders"},
289 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
290 "4020: Connections exceed IOA design limits"},
291 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
292 "4030: Incorrect multipath connection"},
293 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
294 "4110: Unsupported enclosure function"},
295 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
296 "FFF4: Command to logical unit failed"},
298 "Illegal request, invalid request type or request packet"},
300 "Illegal request, invalid resource handle"},
302 "Illegal request, commands not allowed to this device"},
304 "Illegal request, command not allowed to a secondary adapter"},
306 "Illegal request, invalid field in parameter list"},
308 "Illegal request, parameter not supported"},
310 "Illegal request, parameter value invalid"},
312 "Illegal request, command sequence error"},
314 "Illegal request, dual adapter support not enabled"},
315 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
316 "9031: Array protection temporarily suspended, protection resuming"},
317 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
318 "9040: Array protection temporarily suspended, protection resuming"},
319 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
320 "3140: Device bus not ready to ready transition"},
321 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
322 "FFFB: SCSI bus was reset"},
324 "FFFE: SCSI bus transition to single ended"},
326 "FFFE: SCSI bus transition to LVD"},
327 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
328 "FFFB: SCSI bus was reset by another initiator"},
329 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
330 "3029: A device replacement has occurred"},
331 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
332 "9051: IOA cache data exists for a missing or failed device"},
333 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
334 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
335 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
336 "9025: Disk unit is not supported at its physical location"},
337 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
338 "3020: IOA detected a SCSI bus configuration error"},
339 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
340 "3150: SCSI bus configuration error"},
341 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
342 "9074: Asymmetric advanced function disk configuration"},
343 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
344 "4040: Incomplete multipath connection between IOA and enclosure"},
345 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
346 "4041: Incomplete multipath connection between enclosure and device"},
347 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
348 "9075: Incomplete multipath connection between IOA and remote IOA"},
349 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
350 "9076: Configuration error, missing remote IOA"},
351 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
352 "4050: Enclosure does not support a required multipath function"},
353 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
354 "9041: Array protection temporarily suspended"},
355 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
356 "9042: Corrupt array parity detected on specified device"},
357 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
358 "9030: Array no longer protected due to missing or failed disk unit"},
359 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
360 "9071: Link operational transition"},
361 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
362 "9072: Link not operational transition"},
363 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
364 "9032: Array exposed but still protected"},
365 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
366 "70DD: Device forced failed by disrupt device command"},
367 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
368 "4061: Multipath redundancy level got better"},
369 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
370 "4060: Multipath redundancy level got worse"},
372 "Failure due to other device"},
373 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
374 "9008: IOA does not support functions expected by devices"},
375 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
376 "9010: Cache data associated with attached devices cannot be found"},
377 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
378 "9011: Cache data belongs to devices other than those attached"},
379 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
380 "9020: Array missing 2 or more devices with only 1 device present"},
381 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
382 "9021: Array missing 2 or more devices with 2 or more devices present"},
383 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
384 "9022: Exposed array is missing a required device"},
385 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
386 "9023: Array member(s) not at required physical locations"},
387 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
388 "9024: Array not functional due to present hardware configuration"},
389 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
390 "9026: Array not functional due to present hardware configuration"},
391 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
392 "9027: Array is missing a device and parity is out of sync"},
393 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
394 "9028: Maximum number of arrays already exist"},
395 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
396 "9050: Required cache data cannot be located for a disk unit"},
397 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
398 "9052: Cache data exists for a device that has been modified"},
399 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
400 "9054: IOA resources not available due to previous problems"},
401 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
402 "9092: Disk unit requires initialization before use"},
403 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
404 "9029: Incorrect hardware configuration change has been detected"},
405 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
406 "9060: One or more disk pairs are missing from an array"},
407 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
408 "9061: One or more disks are missing from an array"},
409 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
410 "9062: One or more disks are missing from an array"},
411 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
412 "9063: Maximum number of functional arrays has been exceeded"},
414 "Aborted command, invalid descriptor"},
416 "Command terminated by host"}
419 static const struct ipr_ses_table_entry ipr_ses_table[] = {
420 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
421 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
422 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
423 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
424 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
425 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
426 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
427 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
428 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
429 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
430 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
431 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
432 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
436 * Function Prototypes
438 static int ipr_reset_alert(struct ipr_cmnd *);
439 static void ipr_process_ccn(struct ipr_cmnd *);
440 static void ipr_process_error(struct ipr_cmnd *);
441 static void ipr_reset_ioa_job(struct ipr_cmnd *);
442 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
443 enum ipr_shutdown_type);
445 #ifdef CONFIG_SCSI_IPR_TRACE
447 * ipr_trc_hook - Add a trace entry to the driver trace
448 * @ipr_cmd: ipr command struct
450 * @add_data: additional data
455 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
456 u8 type, u32 add_data)
458 struct ipr_trace_entry *trace_entry;
459 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
461 trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
462 trace_entry->time = jiffies;
463 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
464 trace_entry->type = type;
465 trace_entry->ata_op_code = ipr_cmd->ioarcb.add_data.u.regs.command;
466 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
467 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
468 trace_entry->u.add_data = add_data;
471 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
475 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
476 * @ipr_cmd: ipr command struct
481 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
483 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
484 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
485 dma_addr_t dma_addr = be32_to_cpu(ioarcb->ioarcb_host_pci_addr);
487 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
488 ioarcb->write_data_transfer_length = 0;
489 ioarcb->read_data_transfer_length = 0;
490 ioarcb->write_ioadl_len = 0;
491 ioarcb->read_ioadl_len = 0;
492 ioarcb->write_ioadl_addr =
493 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
494 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
496 ioasa->residual_data_len = 0;
497 ioasa->u.gata.status = 0;
499 ipr_cmd->scsi_cmd = NULL;
501 ipr_cmd->sense_buffer[0] = 0;
502 ipr_cmd->dma_use_sg = 0;
506 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
507 * @ipr_cmd: ipr command struct
512 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
514 ipr_reinit_ipr_cmnd(ipr_cmd);
515 ipr_cmd->u.scratch = 0;
516 ipr_cmd->sibling = NULL;
517 init_timer(&ipr_cmd->timer);
521 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
522 * @ioa_cfg: ioa config struct
525 * pointer to ipr command struct
528 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
530 struct ipr_cmnd *ipr_cmd;
532 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
533 list_del(&ipr_cmd->queue);
534 ipr_init_ipr_cmnd(ipr_cmd);
540 * ipr_unmap_sglist - Unmap scatterlist if mapped
541 * @ioa_cfg: ioa config struct
542 * @ipr_cmd: ipr command struct
547 static void ipr_unmap_sglist(struct ipr_ioa_cfg *ioa_cfg,
548 struct ipr_cmnd *ipr_cmd)
550 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
552 if (ipr_cmd->dma_use_sg) {
553 if (scsi_cmd->use_sg > 0) {
554 pci_unmap_sg(ioa_cfg->pdev, scsi_cmd->request_buffer,
556 scsi_cmd->sc_data_direction);
558 pci_unmap_single(ioa_cfg->pdev, ipr_cmd->dma_handle,
559 scsi_cmd->request_bufflen,
560 scsi_cmd->sc_data_direction);
566 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
567 * @ioa_cfg: ioa config struct
568 * @clr_ints: interrupts to clear
570 * This function masks all interrupts on the adapter, then clears the
571 * interrupts specified in the mask
576 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
579 volatile u32 int_reg;
581 /* Stop new interrupts */
582 ioa_cfg->allow_interrupts = 0;
584 /* Set interrupt mask to stop all new interrupts */
585 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
587 /* Clear any pending interrupts */
588 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
589 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
593 * ipr_save_pcix_cmd_reg - Save PCI-X command register
594 * @ioa_cfg: ioa config struct
597 * 0 on success / -EIO on failure
599 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
601 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
603 if (pcix_cmd_reg == 0)
606 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
607 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
608 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
612 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
617 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
618 * @ioa_cfg: ioa config struct
621 * 0 on success / -EIO on failure
623 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
625 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
628 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
629 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
630 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
639 * ipr_sata_eh_done - done function for aborted SATA commands
640 * @ipr_cmd: ipr command struct
642 * This function is invoked for ops generated to SATA
643 * devices which are being aborted.
648 static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
650 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
651 struct ata_queued_cmd *qc = ipr_cmd->qc;
652 struct ipr_sata_port *sata_port = qc->ap->private_data;
654 qc->err_mask |= AC_ERR_OTHER;
655 sata_port->ioasa.status |= ATA_BUSY;
656 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
661 * ipr_scsi_eh_done - mid-layer done function for aborted ops
662 * @ipr_cmd: ipr command struct
664 * This function is invoked by the interrupt handler for
665 * ops generated by the SCSI mid-layer which are being aborted.
670 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
672 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
673 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
675 scsi_cmd->result |= (DID_ERROR << 16);
677 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
678 scsi_cmd->scsi_done(scsi_cmd);
679 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
683 * ipr_fail_all_ops - Fails all outstanding ops.
684 * @ioa_cfg: ioa config struct
686 * This function fails all outstanding ops.
691 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
693 struct ipr_cmnd *ipr_cmd, *temp;
696 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
697 list_del(&ipr_cmd->queue);
699 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
700 ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
702 if (ipr_cmd->scsi_cmd)
703 ipr_cmd->done = ipr_scsi_eh_done;
704 else if (ipr_cmd->qc)
705 ipr_cmd->done = ipr_sata_eh_done;
707 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
708 del_timer(&ipr_cmd->timer);
709 ipr_cmd->done(ipr_cmd);
716 * ipr_do_req - Send driver initiated requests.
717 * @ipr_cmd: ipr command struct
718 * @done: done function
719 * @timeout_func: timeout function
720 * @timeout: timeout value
722 * This function sends the specified command to the adapter with the
723 * timeout given. The done function is invoked on command completion.
728 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
729 void (*done) (struct ipr_cmnd *),
730 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
732 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
734 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
736 ipr_cmd->done = done;
738 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
739 ipr_cmd->timer.expires = jiffies + timeout;
740 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
742 add_timer(&ipr_cmd->timer);
744 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
747 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
748 ioa_cfg->regs.ioarrin_reg);
752 * ipr_internal_cmd_done - Op done function for an internally generated op.
753 * @ipr_cmd: ipr command struct
755 * This function is the op done function for an internally generated,
756 * blocking op. It simply wakes the sleeping thread.
761 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
763 if (ipr_cmd->sibling)
764 ipr_cmd->sibling = NULL;
766 complete(&ipr_cmd->completion);
770 * ipr_send_blocking_cmd - Send command and sleep on its completion.
771 * @ipr_cmd: ipr command struct
772 * @timeout_func: function to invoke if command times out
778 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
779 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
782 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
784 init_completion(&ipr_cmd->completion);
785 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
787 spin_unlock_irq(ioa_cfg->host->host_lock);
788 wait_for_completion(&ipr_cmd->completion);
789 spin_lock_irq(ioa_cfg->host->host_lock);
793 * ipr_send_hcam - Send an HCAM to the adapter.
794 * @ioa_cfg: ioa config struct
796 * @hostrcb: hostrcb struct
798 * This function will send a Host Controlled Async command to the adapter.
799 * If HCAMs are currently not allowed to be issued to the adapter, it will
800 * place the hostrcb on the free queue.
805 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
806 struct ipr_hostrcb *hostrcb)
808 struct ipr_cmnd *ipr_cmd;
809 struct ipr_ioarcb *ioarcb;
811 if (ioa_cfg->allow_cmds) {
812 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
813 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
814 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
816 ipr_cmd->u.hostrcb = hostrcb;
817 ioarcb = &ipr_cmd->ioarcb;
819 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
820 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
821 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
822 ioarcb->cmd_pkt.cdb[1] = type;
823 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
824 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
826 ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
827 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
828 ipr_cmd->ioadl[0].flags_and_data_len =
829 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
830 ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
832 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
833 ipr_cmd->done = ipr_process_ccn;
835 ipr_cmd->done = ipr_process_error;
837 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
840 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
841 ioa_cfg->regs.ioarrin_reg);
843 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
848 * ipr_init_res_entry - Initialize a resource entry struct.
849 * @res: resource entry struct
854 static void ipr_init_res_entry(struct ipr_resource_entry *res)
856 res->needs_sync_complete = 0;
859 res->del_from_ml = 0;
860 res->resetting_device = 0;
862 res->sata_port = NULL;
866 * ipr_handle_config_change - Handle a config change from the adapter
867 * @ioa_cfg: ioa config struct
873 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
874 struct ipr_hostrcb *hostrcb)
876 struct ipr_resource_entry *res = NULL;
877 struct ipr_config_table_entry *cfgte;
880 cfgte = &hostrcb->hcam.u.ccn.cfgte;
882 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
883 if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
884 sizeof(cfgte->res_addr))) {
891 if (list_empty(&ioa_cfg->free_res_q)) {
892 ipr_send_hcam(ioa_cfg,
893 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
898 res = list_entry(ioa_cfg->free_res_q.next,
899 struct ipr_resource_entry, queue);
901 list_del(&res->queue);
902 ipr_init_res_entry(res);
903 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
906 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
908 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
910 res->del_from_ml = 1;
911 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
912 if (ioa_cfg->allow_ml_add_del)
913 schedule_work(&ioa_cfg->work_q);
915 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
916 } else if (!res->sdev) {
918 if (ioa_cfg->allow_ml_add_del)
919 schedule_work(&ioa_cfg->work_q);
922 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
926 * ipr_process_ccn - Op done function for a CCN.
927 * @ipr_cmd: ipr command struct
929 * This function is the op done function for a configuration
930 * change notification host controlled async from the adapter.
935 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
937 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
938 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
939 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
941 list_del(&hostrcb->queue);
942 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
945 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
946 dev_err(&ioa_cfg->pdev->dev,
947 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
949 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
951 ipr_handle_config_change(ioa_cfg, hostrcb);
956 * ipr_log_vpd - Log the passed VPD to the error log.
957 * @vpd: vendor/product id/sn struct
962 static void ipr_log_vpd(struct ipr_vpd *vpd)
964 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
965 + IPR_SERIAL_NUM_LEN];
967 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
968 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
970 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
971 ipr_err("Vendor/Product ID: %s\n", buffer);
973 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
974 buffer[IPR_SERIAL_NUM_LEN] = '\0';
975 ipr_err(" Serial Number: %s\n", buffer);
979 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
980 * @vpd: vendor/product id/sn/wwn struct
985 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
987 ipr_log_vpd(&vpd->vpd);
988 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
989 be32_to_cpu(vpd->wwid[1]));
993 * ipr_log_enhanced_cache_error - Log a cache error.
994 * @ioa_cfg: ioa config struct
995 * @hostrcb: hostrcb struct
1000 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1001 struct ipr_hostrcb *hostrcb)
1003 struct ipr_hostrcb_type_12_error *error =
1004 &hostrcb->hcam.u.error.u.type_12_error;
1006 ipr_err("-----Current Configuration-----\n");
1007 ipr_err("Cache Directory Card Information:\n");
1008 ipr_log_ext_vpd(&error->ioa_vpd);
1009 ipr_err("Adapter Card Information:\n");
1010 ipr_log_ext_vpd(&error->cfc_vpd);
1012 ipr_err("-----Expected Configuration-----\n");
1013 ipr_err("Cache Directory Card Information:\n");
1014 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1015 ipr_err("Adapter Card Information:\n");
1016 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1018 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1019 be32_to_cpu(error->ioa_data[0]),
1020 be32_to_cpu(error->ioa_data[1]),
1021 be32_to_cpu(error->ioa_data[2]));
1025 * ipr_log_cache_error - Log a cache error.
1026 * @ioa_cfg: ioa config struct
1027 * @hostrcb: hostrcb struct
1032 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1033 struct ipr_hostrcb *hostrcb)
1035 struct ipr_hostrcb_type_02_error *error =
1036 &hostrcb->hcam.u.error.u.type_02_error;
1038 ipr_err("-----Current Configuration-----\n");
1039 ipr_err("Cache Directory Card Information:\n");
1040 ipr_log_vpd(&error->ioa_vpd);
1041 ipr_err("Adapter Card Information:\n");
1042 ipr_log_vpd(&error->cfc_vpd);
1044 ipr_err("-----Expected Configuration-----\n");
1045 ipr_err("Cache Directory Card Information:\n");
1046 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1047 ipr_err("Adapter Card Information:\n");
1048 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1050 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1051 be32_to_cpu(error->ioa_data[0]),
1052 be32_to_cpu(error->ioa_data[1]),
1053 be32_to_cpu(error->ioa_data[2]));
1057 * ipr_log_enhanced_config_error - Log a configuration error.
1058 * @ioa_cfg: ioa config struct
1059 * @hostrcb: hostrcb struct
1064 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1065 struct ipr_hostrcb *hostrcb)
1067 int errors_logged, i;
1068 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1069 struct ipr_hostrcb_type_13_error *error;
1071 error = &hostrcb->hcam.u.error.u.type_13_error;
1072 errors_logged = be32_to_cpu(error->errors_logged);
1074 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1075 be32_to_cpu(error->errors_detected), errors_logged);
1077 dev_entry = error->dev;
1079 for (i = 0; i < errors_logged; i++, dev_entry++) {
1082 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1083 ipr_log_ext_vpd(&dev_entry->vpd);
1085 ipr_err("-----New Device Information-----\n");
1086 ipr_log_ext_vpd(&dev_entry->new_vpd);
1088 ipr_err("Cache Directory Card Information:\n");
1089 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1091 ipr_err("Adapter Card Information:\n");
1092 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1097 * ipr_log_config_error - Log a configuration error.
1098 * @ioa_cfg: ioa config struct
1099 * @hostrcb: hostrcb struct
1104 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1105 struct ipr_hostrcb *hostrcb)
1107 int errors_logged, i;
1108 struct ipr_hostrcb_device_data_entry *dev_entry;
1109 struct ipr_hostrcb_type_03_error *error;
1111 error = &hostrcb->hcam.u.error.u.type_03_error;
1112 errors_logged = be32_to_cpu(error->errors_logged);
1114 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1115 be32_to_cpu(error->errors_detected), errors_logged);
1117 dev_entry = error->dev;
1119 for (i = 0; i < errors_logged; i++, dev_entry++) {
1122 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1123 ipr_log_vpd(&dev_entry->vpd);
1125 ipr_err("-----New Device Information-----\n");
1126 ipr_log_vpd(&dev_entry->new_vpd);
1128 ipr_err("Cache Directory Card Information:\n");
1129 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1131 ipr_err("Adapter Card Information:\n");
1132 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1134 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1135 be32_to_cpu(dev_entry->ioa_data[0]),
1136 be32_to_cpu(dev_entry->ioa_data[1]),
1137 be32_to_cpu(dev_entry->ioa_data[2]),
1138 be32_to_cpu(dev_entry->ioa_data[3]),
1139 be32_to_cpu(dev_entry->ioa_data[4]));
1144 * ipr_log_enhanced_array_error - Log an array configuration error.
1145 * @ioa_cfg: ioa config struct
1146 * @hostrcb: hostrcb struct
1151 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1152 struct ipr_hostrcb *hostrcb)
1155 struct ipr_hostrcb_type_14_error *error;
1156 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1157 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1159 error = &hostrcb->hcam.u.error.u.type_14_error;
1163 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1164 error->protection_level,
1165 ioa_cfg->host->host_no,
1166 error->last_func_vset_res_addr.bus,
1167 error->last_func_vset_res_addr.target,
1168 error->last_func_vset_res_addr.lun);
1172 array_entry = error->array_member;
1173 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1174 sizeof(error->array_member));
1176 for (i = 0; i < num_entries; i++, array_entry++) {
1177 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1180 if (be32_to_cpu(error->exposed_mode_adn) == i)
1181 ipr_err("Exposed Array Member %d:\n", i);
1183 ipr_err("Array Member %d:\n", i);
1185 ipr_log_ext_vpd(&array_entry->vpd);
1186 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1187 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1188 "Expected Location");
1195 * ipr_log_array_error - Log an array configuration error.
1196 * @ioa_cfg: ioa config struct
1197 * @hostrcb: hostrcb struct
1202 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1203 struct ipr_hostrcb *hostrcb)
1206 struct ipr_hostrcb_type_04_error *error;
1207 struct ipr_hostrcb_array_data_entry *array_entry;
1208 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1210 error = &hostrcb->hcam.u.error.u.type_04_error;
1214 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1215 error->protection_level,
1216 ioa_cfg->host->host_no,
1217 error->last_func_vset_res_addr.bus,
1218 error->last_func_vset_res_addr.target,
1219 error->last_func_vset_res_addr.lun);
1223 array_entry = error->array_member;
1225 for (i = 0; i < 18; i++) {
1226 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1229 if (be32_to_cpu(error->exposed_mode_adn) == i)
1230 ipr_err("Exposed Array Member %d:\n", i);
1232 ipr_err("Array Member %d:\n", i);
1234 ipr_log_vpd(&array_entry->vpd);
1236 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1237 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1238 "Expected Location");
1243 array_entry = error->array_member2;
1250 * ipr_log_hex_data - Log additional hex IOA error data.
1251 * @ioa_cfg: ioa config struct
1252 * @data: IOA error data
1258 static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
1265 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1266 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1268 for (i = 0; i < len / 4; i += 4) {
1269 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1270 be32_to_cpu(data[i]),
1271 be32_to_cpu(data[i+1]),
1272 be32_to_cpu(data[i+2]),
1273 be32_to_cpu(data[i+3]));
1278 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1279 * @ioa_cfg: ioa config struct
1280 * @hostrcb: hostrcb struct
1285 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1286 struct ipr_hostrcb *hostrcb)
1288 struct ipr_hostrcb_type_17_error *error;
1290 error = &hostrcb->hcam.u.error.u.type_17_error;
1291 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1293 ipr_err("%s\n", error->failure_reason);
1294 ipr_err("Remote Adapter VPD:\n");
1295 ipr_log_ext_vpd(&error->vpd);
1296 ipr_log_hex_data(ioa_cfg, error->data,
1297 be32_to_cpu(hostrcb->hcam.length) -
1298 (offsetof(struct ipr_hostrcb_error, u) +
1299 offsetof(struct ipr_hostrcb_type_17_error, data)));
1303 * ipr_log_dual_ioa_error - Log a dual adapter error.
1304 * @ioa_cfg: ioa config struct
1305 * @hostrcb: hostrcb struct
1310 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1311 struct ipr_hostrcb *hostrcb)
1313 struct ipr_hostrcb_type_07_error *error;
1315 error = &hostrcb->hcam.u.error.u.type_07_error;
1316 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1318 ipr_err("%s\n", error->failure_reason);
1319 ipr_err("Remote Adapter VPD:\n");
1320 ipr_log_vpd(&error->vpd);
1321 ipr_log_hex_data(ioa_cfg, error->data,
1322 be32_to_cpu(hostrcb->hcam.length) -
1323 (offsetof(struct ipr_hostrcb_error, u) +
1324 offsetof(struct ipr_hostrcb_type_07_error, data)));
1327 static const struct {
1330 } path_active_desc[] = {
1331 { IPR_PATH_NO_INFO, "Path" },
1332 { IPR_PATH_ACTIVE, "Active path" },
1333 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1336 static const struct {
1339 } path_state_desc[] = {
1340 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1341 { IPR_PATH_HEALTHY, "is healthy" },
1342 { IPR_PATH_DEGRADED, "is degraded" },
1343 { IPR_PATH_FAILED, "is failed" }
1347 * ipr_log_fabric_path - Log a fabric path error
1348 * @hostrcb: hostrcb struct
1349 * @fabric: fabric descriptor
1354 static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1355 struct ipr_hostrcb_fabric_desc *fabric)
1358 u8 path_state = fabric->path_state;
1359 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1360 u8 state = path_state & IPR_PATH_STATE_MASK;
1362 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1363 if (path_active_desc[i].active != active)
1366 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1367 if (path_state_desc[j].state != state)
1370 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
1371 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
1372 path_active_desc[i].desc, path_state_desc[j].desc,
1374 } else if (fabric->cascaded_expander == 0xff) {
1375 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
1376 path_active_desc[i].desc, path_state_desc[j].desc,
1377 fabric->ioa_port, fabric->phy);
1378 } else if (fabric->phy == 0xff) {
1379 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
1380 path_active_desc[i].desc, path_state_desc[j].desc,
1381 fabric->ioa_port, fabric->cascaded_expander);
1383 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1384 path_active_desc[i].desc, path_state_desc[j].desc,
1385 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1391 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
1392 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1395 static const struct {
1398 } path_type_desc[] = {
1399 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
1400 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
1401 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
1402 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
1405 static const struct {
1408 } path_status_desc[] = {
1409 { IPR_PATH_CFG_NO_PROB, "Functional" },
1410 { IPR_PATH_CFG_DEGRADED, "Degraded" },
1411 { IPR_PATH_CFG_FAILED, "Failed" },
1412 { IPR_PATH_CFG_SUSPECT, "Suspect" },
1413 { IPR_PATH_NOT_DETECTED, "Missing" },
1414 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
1417 static const char *link_rate[] = {
1420 "phy reset problem",
1437 * ipr_log_path_elem - Log a fabric path element.
1438 * @hostrcb: hostrcb struct
1439 * @cfg: fabric path element struct
1444 static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
1445 struct ipr_hostrcb_config_element *cfg)
1448 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
1449 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
1451 if (type == IPR_PATH_CFG_NOT_EXIST)
1454 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
1455 if (path_type_desc[i].type != type)
1458 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
1459 if (path_status_desc[j].status != status)
1462 if (type == IPR_PATH_CFG_IOA_PORT) {
1463 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
1464 path_status_desc[j].desc, path_type_desc[i].desc,
1465 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1466 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1468 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
1469 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
1470 path_status_desc[j].desc, path_type_desc[i].desc,
1471 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1472 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1473 } else if (cfg->cascaded_expander == 0xff) {
1474 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
1475 "WWN=%08X%08X\n", path_status_desc[j].desc,
1476 path_type_desc[i].desc, cfg->phy,
1477 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1478 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1479 } else if (cfg->phy == 0xff) {
1480 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
1481 "WWN=%08X%08X\n", path_status_desc[j].desc,
1482 path_type_desc[i].desc, cfg->cascaded_expander,
1483 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1484 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1486 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
1487 "WWN=%08X%08X\n", path_status_desc[j].desc,
1488 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
1489 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1490 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1497 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
1498 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
1499 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1500 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1504 * ipr_log_fabric_error - Log a fabric error.
1505 * @ioa_cfg: ioa config struct
1506 * @hostrcb: hostrcb struct
1511 static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
1512 struct ipr_hostrcb *hostrcb)
1514 struct ipr_hostrcb_type_20_error *error;
1515 struct ipr_hostrcb_fabric_desc *fabric;
1516 struct ipr_hostrcb_config_element *cfg;
1519 error = &hostrcb->hcam.u.error.u.type_20_error;
1520 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1521 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
1523 add_len = be32_to_cpu(hostrcb->hcam.length) -
1524 (offsetof(struct ipr_hostrcb_error, u) +
1525 offsetof(struct ipr_hostrcb_type_20_error, desc));
1527 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
1528 ipr_log_fabric_path(hostrcb, fabric);
1529 for_each_fabric_cfg(fabric, cfg)
1530 ipr_log_path_elem(hostrcb, cfg);
1532 add_len -= be16_to_cpu(fabric->length);
1533 fabric = (struct ipr_hostrcb_fabric_desc *)
1534 ((unsigned long)fabric + be16_to_cpu(fabric->length));
1537 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
1541 * ipr_log_generic_error - Log an adapter error.
1542 * @ioa_cfg: ioa config struct
1543 * @hostrcb: hostrcb struct
1548 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
1549 struct ipr_hostrcb *hostrcb)
1551 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
1552 be32_to_cpu(hostrcb->hcam.length));
1556 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
1559 * This function will return the index of into the ipr_error_table
1560 * for the specified IOASC. If the IOASC is not in the table,
1561 * 0 will be returned, which points to the entry used for unknown errors.
1564 * index into the ipr_error_table
1566 static u32 ipr_get_error(u32 ioasc)
1570 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
1571 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
1578 * ipr_handle_log_data - Log an adapter error.
1579 * @ioa_cfg: ioa config struct
1580 * @hostrcb: hostrcb struct
1582 * This function logs an adapter error to the system.
1587 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
1588 struct ipr_hostrcb *hostrcb)
1593 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
1596 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
1597 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
1599 ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1601 if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
1602 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
1603 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
1604 scsi_report_bus_reset(ioa_cfg->host,
1605 hostrcb->hcam.u.error.failing_dev_res_addr.bus);
1608 error_index = ipr_get_error(ioasc);
1610 if (!ipr_error_table[error_index].log_hcam)
1613 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
1615 /* Set indication we have logged an error */
1616 ioa_cfg->errors_logged++;
1618 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
1620 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
1621 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
1623 switch (hostrcb->hcam.overlay_id) {
1624 case IPR_HOST_RCB_OVERLAY_ID_2:
1625 ipr_log_cache_error(ioa_cfg, hostrcb);
1627 case IPR_HOST_RCB_OVERLAY_ID_3:
1628 ipr_log_config_error(ioa_cfg, hostrcb);
1630 case IPR_HOST_RCB_OVERLAY_ID_4:
1631 case IPR_HOST_RCB_OVERLAY_ID_6:
1632 ipr_log_array_error(ioa_cfg, hostrcb);
1634 case IPR_HOST_RCB_OVERLAY_ID_7:
1635 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
1637 case IPR_HOST_RCB_OVERLAY_ID_12:
1638 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
1640 case IPR_HOST_RCB_OVERLAY_ID_13:
1641 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
1643 case IPR_HOST_RCB_OVERLAY_ID_14:
1644 case IPR_HOST_RCB_OVERLAY_ID_16:
1645 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
1647 case IPR_HOST_RCB_OVERLAY_ID_17:
1648 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
1650 case IPR_HOST_RCB_OVERLAY_ID_20:
1651 ipr_log_fabric_error(ioa_cfg, hostrcb);
1653 case IPR_HOST_RCB_OVERLAY_ID_1:
1654 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
1656 ipr_log_generic_error(ioa_cfg, hostrcb);
1662 * ipr_process_error - Op done function for an adapter error log.
1663 * @ipr_cmd: ipr command struct
1665 * This function is the op done function for an error log host
1666 * controlled async from the adapter. It will log the error and
1667 * send the HCAM back to the adapter.
1672 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
1674 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1675 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1676 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
1677 u32 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1679 list_del(&hostrcb->queue);
1680 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1683 ipr_handle_log_data(ioa_cfg, hostrcb);
1684 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
1685 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
1686 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
1687 dev_err(&ioa_cfg->pdev->dev,
1688 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1691 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
1695 * ipr_timeout - An internally generated op has timed out.
1696 * @ipr_cmd: ipr command struct
1698 * This function blocks host requests and initiates an
1704 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
1706 unsigned long lock_flags = 0;
1707 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1710 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1712 ioa_cfg->errors_logged++;
1713 dev_err(&ioa_cfg->pdev->dev,
1714 "Adapter being reset due to command timeout.\n");
1716 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1717 ioa_cfg->sdt_state = GET_DUMP;
1719 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
1720 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1722 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1727 * ipr_oper_timeout - Adapter timed out transitioning to operational
1728 * @ipr_cmd: ipr command struct
1730 * This function blocks host requests and initiates an
1736 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
1738 unsigned long lock_flags = 0;
1739 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1742 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1744 ioa_cfg->errors_logged++;
1745 dev_err(&ioa_cfg->pdev->dev,
1746 "Adapter timed out transitioning to operational.\n");
1748 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1749 ioa_cfg->sdt_state = GET_DUMP;
1751 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
1753 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
1754 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1757 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1762 * ipr_reset_reload - Reset/Reload the IOA
1763 * @ioa_cfg: ioa config struct
1764 * @shutdown_type: shutdown type
1766 * This function resets the adapter and re-initializes it.
1767 * This function assumes that all new host commands have been stopped.
1771 static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
1772 enum ipr_shutdown_type shutdown_type)
1774 if (!ioa_cfg->in_reset_reload)
1775 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
1777 spin_unlock_irq(ioa_cfg->host->host_lock);
1778 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
1779 spin_lock_irq(ioa_cfg->host->host_lock);
1781 /* If we got hit with a host reset while we were already resetting
1782 the adapter for some reason, and the reset failed. */
1783 if (ioa_cfg->ioa_is_dead) {
1792 * ipr_find_ses_entry - Find matching SES in SES table
1793 * @res: resource entry struct of SES
1796 * pointer to SES table entry / NULL on failure
1798 static const struct ipr_ses_table_entry *
1799 ipr_find_ses_entry(struct ipr_resource_entry *res)
1802 const struct ipr_ses_table_entry *ste = ipr_ses_table;
1804 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
1805 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
1806 if (ste->compare_product_id_byte[j] == 'X') {
1807 if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
1815 if (matches == IPR_PROD_ID_LEN)
1823 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
1824 * @ioa_cfg: ioa config struct
1826 * @bus_width: bus width
1829 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
1830 * For a 2-byte wide SCSI bus, the maximum transfer speed is
1831 * twice the maximum transfer rate (e.g. for a wide enabled bus,
1832 * max 160MHz = max 320MB/sec).
1834 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
1836 struct ipr_resource_entry *res;
1837 const struct ipr_ses_table_entry *ste;
1838 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
1840 /* Loop through each config table entry in the config table buffer */
1841 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1842 if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
1845 if (bus != res->cfgte.res_addr.bus)
1848 if (!(ste = ipr_find_ses_entry(res)))
1851 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
1854 return max_xfer_rate;
1858 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
1859 * @ioa_cfg: ioa config struct
1860 * @max_delay: max delay in micro-seconds to wait
1862 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
1865 * 0 on success / other on failure
1867 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
1869 volatile u32 pcii_reg;
1872 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
1873 while (delay < max_delay) {
1874 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
1876 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
1879 /* udelay cannot be used if delay is more than a few milliseconds */
1880 if ((delay / 1000) > MAX_UDELAY_MS)
1881 mdelay(delay / 1000);
1891 * ipr_get_ldump_data_section - Dump IOA memory
1892 * @ioa_cfg: ioa config struct
1893 * @start_addr: adapter address to dump
1894 * @dest: destination kernel buffer
1895 * @length_in_words: length to dump in 4 byte words
1898 * 0 on success / -EIO on failure
1900 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
1902 __be32 *dest, u32 length_in_words)
1904 volatile u32 temp_pcii_reg;
1907 /* Write IOA interrupt reg starting LDUMP state */
1908 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
1909 ioa_cfg->regs.set_uproc_interrupt_reg);
1911 /* Wait for IO debug acknowledge */
1912 if (ipr_wait_iodbg_ack(ioa_cfg,
1913 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
1914 dev_err(&ioa_cfg->pdev->dev,
1915 "IOA dump long data transfer timeout\n");
1919 /* Signal LDUMP interlocked - clear IO debug ack */
1920 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1921 ioa_cfg->regs.clr_interrupt_reg);
1923 /* Write Mailbox with starting address */
1924 writel(start_addr, ioa_cfg->ioa_mailbox);
1926 /* Signal address valid - clear IOA Reset alert */
1927 writel(IPR_UPROCI_RESET_ALERT,
1928 ioa_cfg->regs.clr_uproc_interrupt_reg);
1930 for (i = 0; i < length_in_words; i++) {
1931 /* Wait for IO debug acknowledge */
1932 if (ipr_wait_iodbg_ack(ioa_cfg,
1933 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
1934 dev_err(&ioa_cfg->pdev->dev,
1935 "IOA dump short data transfer timeout\n");
1939 /* Read data from mailbox and increment destination pointer */
1940 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
1943 /* For all but the last word of data, signal data received */
1944 if (i < (length_in_words - 1)) {
1945 /* Signal dump data received - Clear IO debug Ack */
1946 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1947 ioa_cfg->regs.clr_interrupt_reg);
1951 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
1952 writel(IPR_UPROCI_RESET_ALERT,
1953 ioa_cfg->regs.set_uproc_interrupt_reg);
1955 writel(IPR_UPROCI_IO_DEBUG_ALERT,
1956 ioa_cfg->regs.clr_uproc_interrupt_reg);
1958 /* Signal dump data received - Clear IO debug Ack */
1959 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1960 ioa_cfg->regs.clr_interrupt_reg);
1962 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
1963 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
1965 readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
1967 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
1977 #ifdef CONFIG_SCSI_IPR_DUMP
1979 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
1980 * @ioa_cfg: ioa config struct
1981 * @pci_address: adapter address
1982 * @length: length of data to copy
1984 * Copy data from PCI adapter to kernel buffer.
1985 * Note: length MUST be a 4 byte multiple
1987 * 0 on success / other on failure
1989 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
1990 unsigned long pci_address, u32 length)
1992 int bytes_copied = 0;
1993 int cur_len, rc, rem_len, rem_page_len;
1995 unsigned long lock_flags = 0;
1996 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
1998 while (bytes_copied < length &&
1999 (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
2000 if (ioa_dump->page_offset >= PAGE_SIZE ||
2001 ioa_dump->page_offset == 0) {
2002 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2006 return bytes_copied;
2009 ioa_dump->page_offset = 0;
2010 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2011 ioa_dump->next_page_index++;
2013 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2015 rem_len = length - bytes_copied;
2016 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2017 cur_len = min(rem_len, rem_page_len);
2019 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2020 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2023 rc = ipr_get_ldump_data_section(ioa_cfg,
2024 pci_address + bytes_copied,
2025 &page[ioa_dump->page_offset / 4],
2026 (cur_len / sizeof(u32)));
2028 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2031 ioa_dump->page_offset += cur_len;
2032 bytes_copied += cur_len;
2040 return bytes_copied;
2044 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2045 * @hdr: dump entry header struct
2050 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2052 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2054 hdr->offset = sizeof(*hdr);
2055 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2059 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2060 * @ioa_cfg: ioa config struct
2061 * @driver_dump: driver dump struct
2066 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2067 struct ipr_driver_dump *driver_dump)
2069 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2071 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2072 driver_dump->ioa_type_entry.hdr.len =
2073 sizeof(struct ipr_dump_ioa_type_entry) -
2074 sizeof(struct ipr_dump_entry_header);
2075 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2076 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2077 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2078 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2079 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2080 ucode_vpd->minor_release[1];
2081 driver_dump->hdr.num_entries++;
2085 * ipr_dump_version_data - Fill in the driver version in the dump.
2086 * @ioa_cfg: ioa config struct
2087 * @driver_dump: driver dump struct
2092 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2093 struct ipr_driver_dump *driver_dump)
2095 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2096 driver_dump->version_entry.hdr.len =
2097 sizeof(struct ipr_dump_version_entry) -
2098 sizeof(struct ipr_dump_entry_header);
2099 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2100 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2101 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2102 driver_dump->hdr.num_entries++;
2106 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2107 * @ioa_cfg: ioa config struct
2108 * @driver_dump: driver dump struct
2113 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
2114 struct ipr_driver_dump *driver_dump)
2116 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
2117 driver_dump->trace_entry.hdr.len =
2118 sizeof(struct ipr_dump_trace_entry) -
2119 sizeof(struct ipr_dump_entry_header);
2120 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2121 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
2122 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
2123 driver_dump->hdr.num_entries++;
2127 * ipr_dump_location_data - Fill in the IOA location in the dump.
2128 * @ioa_cfg: ioa config struct
2129 * @driver_dump: driver dump struct
2134 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
2135 struct ipr_driver_dump *driver_dump)
2137 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
2138 driver_dump->location_entry.hdr.len =
2139 sizeof(struct ipr_dump_location_entry) -
2140 sizeof(struct ipr_dump_entry_header);
2141 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2142 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
2143 strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
2144 driver_dump->hdr.num_entries++;
2148 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2149 * @ioa_cfg: ioa config struct
2150 * @dump: dump struct
2155 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
2157 unsigned long start_addr, sdt_word;
2158 unsigned long lock_flags = 0;
2159 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
2160 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
2161 u32 num_entries, start_off, end_off;
2162 u32 bytes_to_copy, bytes_copied, rc;
2163 struct ipr_sdt *sdt;
2168 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2170 if (ioa_cfg->sdt_state != GET_DUMP) {
2171 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2175 start_addr = readl(ioa_cfg->ioa_mailbox);
2177 if (!ipr_sdt_is_fmt2(start_addr)) {
2178 dev_err(&ioa_cfg->pdev->dev,
2179 "Invalid dump table format: %lx\n", start_addr);
2180 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2184 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
2186 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
2188 /* Initialize the overall dump header */
2189 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
2190 driver_dump->hdr.num_entries = 1;
2191 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
2192 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
2193 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
2194 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
2196 ipr_dump_version_data(ioa_cfg, driver_dump);
2197 ipr_dump_location_data(ioa_cfg, driver_dump);
2198 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
2199 ipr_dump_trace_data(ioa_cfg, driver_dump);
2201 /* Update dump_header */
2202 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
2204 /* IOA Dump entry */
2205 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
2206 ioa_dump->format = IPR_SDT_FMT2;
2207 ioa_dump->hdr.len = 0;
2208 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2209 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
2211 /* First entries in sdt are actually a list of dump addresses and
2212 lengths to gather the real dump data. sdt represents the pointer
2213 to the ioa generated dump table. Dump data will be extracted based
2214 on entries in this table */
2215 sdt = &ioa_dump->sdt;
2217 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
2218 sizeof(struct ipr_sdt) / sizeof(__be32));
2220 /* Smart Dump table is ready to use and the first entry is valid */
2221 if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
2222 dev_err(&ioa_cfg->pdev->dev,
2223 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
2224 rc, be32_to_cpu(sdt->hdr.state));
2225 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
2226 ioa_cfg->sdt_state = DUMP_OBTAINED;
2227 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2231 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
2233 if (num_entries > IPR_NUM_SDT_ENTRIES)
2234 num_entries = IPR_NUM_SDT_ENTRIES;
2236 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2238 for (i = 0; i < num_entries; i++) {
2239 if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
2240 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2244 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
2245 sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
2246 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
2247 end_off = be32_to_cpu(sdt->entry[i].end_offset);
2249 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
2250 bytes_to_copy = end_off - start_off;
2251 if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
2252 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
2256 /* Copy data from adapter to driver buffers */
2257 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
2260 ioa_dump->hdr.len += bytes_copied;
2262 if (bytes_copied != bytes_to_copy) {
2263 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2270 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
2272 /* Update dump_header */
2273 driver_dump->hdr.len += ioa_dump->hdr.len;
2275 ioa_cfg->sdt_state = DUMP_OBTAINED;
2280 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
2284 * ipr_release_dump - Free adapter dump memory
2285 * @kref: kref struct
2290 static void ipr_release_dump(struct kref *kref)
2292 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
2293 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
2294 unsigned long lock_flags = 0;
2298 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2299 ioa_cfg->dump = NULL;
2300 ioa_cfg->sdt_state = INACTIVE;
2301 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2303 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
2304 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
2311 * ipr_worker_thread - Worker thread
2312 * @work: ioa config struct
2314 * Called at task level from a work thread. This function takes care
2315 * of adding and removing device from the mid-layer as configuration
2316 * changes are detected by the adapter.
2321 static void ipr_worker_thread(struct work_struct *work)
2323 unsigned long lock_flags;
2324 struct ipr_resource_entry *res;
2325 struct scsi_device *sdev;
2326 struct ipr_dump *dump;
2327 struct ipr_ioa_cfg *ioa_cfg =
2328 container_of(work, struct ipr_ioa_cfg, work_q);
2329 u8 bus, target, lun;
2333 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2335 if (ioa_cfg->sdt_state == GET_DUMP) {
2336 dump = ioa_cfg->dump;
2338 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2341 kref_get(&dump->kref);
2342 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2343 ipr_get_ioa_dump(ioa_cfg, dump);
2344 kref_put(&dump->kref, ipr_release_dump);
2346 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2347 if (ioa_cfg->sdt_state == DUMP_OBTAINED)
2348 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2349 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2356 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
2357 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2361 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2362 if (res->del_from_ml && res->sdev) {
2365 if (!scsi_device_get(sdev)) {
2366 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
2367 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2368 scsi_remove_device(sdev);
2369 scsi_device_put(sdev);
2370 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2377 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2378 if (res->add_to_ml) {
2379 bus = res->cfgte.res_addr.bus;
2380 target = res->cfgte.res_addr.target;
2381 lun = res->cfgte.res_addr.lun;
2383 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2384 scsi_add_device(ioa_cfg->host, bus, target, lun);
2385 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2390 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2391 kobject_uevent(&ioa_cfg->host->shost_classdev.kobj, KOBJ_CHANGE);
2395 #ifdef CONFIG_SCSI_IPR_TRACE
2397 * ipr_read_trace - Dump the adapter trace
2398 * @kobj: kobject struct
2401 * @count: buffer size
2404 * number of bytes printed to buffer
2406 static ssize_t ipr_read_trace(struct kobject *kobj, char *buf,
2407 loff_t off, size_t count)
2409 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2410 struct Scsi_Host *shost = class_to_shost(cdev);
2411 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2412 unsigned long lock_flags = 0;
2413 int size = IPR_TRACE_SIZE;
2414 char *src = (char *)ioa_cfg->trace;
2418 if (off + count > size) {
2423 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2424 memcpy(buf, &src[off], count);
2425 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2429 static struct bin_attribute ipr_trace_attr = {
2435 .read = ipr_read_trace,
2439 static const struct {
2440 enum ipr_cache_state state;
2442 } cache_state [] = {
2443 { CACHE_NONE, "none" },
2444 { CACHE_DISABLED, "disabled" },
2445 { CACHE_ENABLED, "enabled" }
2449 * ipr_show_write_caching - Show the write caching attribute
2450 * @class_dev: class device struct
2454 * number of bytes printed to buffer
2456 static ssize_t ipr_show_write_caching(struct class_device *class_dev, char *buf)
2458 struct Scsi_Host *shost = class_to_shost(class_dev);
2459 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2460 unsigned long lock_flags = 0;
2463 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2464 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2465 if (cache_state[i].state == ioa_cfg->cache_state) {
2466 len = snprintf(buf, PAGE_SIZE, "%s\n", cache_state[i].name);
2470 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2476 * ipr_store_write_caching - Enable/disable adapter write cache
2477 * @class_dev: class_device struct
2479 * @count: buffer size
2481 * This function will enable/disable adapter write cache.
2484 * count on success / other on failure
2486 static ssize_t ipr_store_write_caching(struct class_device *class_dev,
2487 const char *buf, size_t count)
2489 struct Scsi_Host *shost = class_to_shost(class_dev);
2490 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2491 unsigned long lock_flags = 0;
2492 enum ipr_cache_state new_state = CACHE_INVALID;
2495 if (!capable(CAP_SYS_ADMIN))
2497 if (ioa_cfg->cache_state == CACHE_NONE)
2500 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2501 if (!strncmp(cache_state[i].name, buf, strlen(cache_state[i].name))) {
2502 new_state = cache_state[i].state;
2507 if (new_state != CACHE_DISABLED && new_state != CACHE_ENABLED)
2510 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2511 if (ioa_cfg->cache_state == new_state) {
2512 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2516 ioa_cfg->cache_state = new_state;
2517 dev_info(&ioa_cfg->pdev->dev, "%s adapter write cache.\n",
2518 new_state == CACHE_ENABLED ? "Enabling" : "Disabling");
2519 if (!ioa_cfg->in_reset_reload)
2520 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2521 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2522 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2527 static struct class_device_attribute ipr_ioa_cache_attr = {
2529 .name = "write_cache",
2530 .mode = S_IRUGO | S_IWUSR,
2532 .show = ipr_show_write_caching,
2533 .store = ipr_store_write_caching
2537 * ipr_show_fw_version - Show the firmware version
2538 * @class_dev: class device struct
2542 * number of bytes printed to buffer
2544 static ssize_t ipr_show_fw_version(struct class_device *class_dev, char *buf)
2546 struct Scsi_Host *shost = class_to_shost(class_dev);
2547 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2548 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2549 unsigned long lock_flags = 0;
2552 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2553 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
2554 ucode_vpd->major_release, ucode_vpd->card_type,
2555 ucode_vpd->minor_release[0],
2556 ucode_vpd->minor_release[1]);
2557 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2561 static struct class_device_attribute ipr_fw_version_attr = {
2563 .name = "fw_version",
2566 .show = ipr_show_fw_version,
2570 * ipr_show_log_level - Show the adapter's error logging level
2571 * @class_dev: class device struct
2575 * number of bytes printed to buffer
2577 static ssize_t ipr_show_log_level(struct class_device *class_dev, char *buf)
2579 struct Scsi_Host *shost = class_to_shost(class_dev);
2580 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2581 unsigned long lock_flags = 0;
2584 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2585 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
2586 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2591 * ipr_store_log_level - Change the adapter's error logging level
2592 * @class_dev: class device struct
2596 * number of bytes printed to buffer
2598 static ssize_t ipr_store_log_level(struct class_device *class_dev,
2599 const char *buf, size_t count)
2601 struct Scsi_Host *shost = class_to_shost(class_dev);
2602 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2603 unsigned long lock_flags = 0;
2605 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2606 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
2607 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2611 static struct class_device_attribute ipr_log_level_attr = {
2613 .name = "log_level",
2614 .mode = S_IRUGO | S_IWUSR,
2616 .show = ipr_show_log_level,
2617 .store = ipr_store_log_level
2621 * ipr_store_diagnostics - IOA Diagnostics interface
2622 * @class_dev: class_device struct
2624 * @count: buffer size
2626 * This function will reset the adapter and wait a reasonable
2627 * amount of time for any errors that the adapter might log.
2630 * count on success / other on failure
2632 static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
2633 const char *buf, size_t count)
2635 struct Scsi_Host *shost = class_to_shost(class_dev);
2636 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2637 unsigned long lock_flags = 0;
2640 if (!capable(CAP_SYS_ADMIN))
2643 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2644 while(ioa_cfg->in_reset_reload) {
2645 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2646 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2647 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2650 ioa_cfg->errors_logged = 0;
2651 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2653 if (ioa_cfg->in_reset_reload) {
2654 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2655 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2657 /* Wait for a second for any errors to be logged */
2660 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2664 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2665 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
2667 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2672 static struct class_device_attribute ipr_diagnostics_attr = {
2674 .name = "run_diagnostics",
2677 .store = ipr_store_diagnostics
2681 * ipr_show_adapter_state - Show the adapter's state
2682 * @class_dev: class device struct
2686 * number of bytes printed to buffer
2688 static ssize_t ipr_show_adapter_state(struct class_device *class_dev, char *buf)
2690 struct Scsi_Host *shost = class_to_shost(class_dev);
2691 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2692 unsigned long lock_flags = 0;
2695 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2696 if (ioa_cfg->ioa_is_dead)
2697 len = snprintf(buf, PAGE_SIZE, "offline\n");
2699 len = snprintf(buf, PAGE_SIZE, "online\n");
2700 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2705 * ipr_store_adapter_state - Change adapter state
2706 * @class_dev: class_device struct
2708 * @count: buffer size
2710 * This function will change the adapter's state.
2713 * count on success / other on failure
2715 static ssize_t ipr_store_adapter_state(struct class_device *class_dev,
2716 const char *buf, size_t count)
2718 struct Scsi_Host *shost = class_to_shost(class_dev);
2719 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2720 unsigned long lock_flags;
2723 if (!capable(CAP_SYS_ADMIN))
2726 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2727 if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
2728 ioa_cfg->ioa_is_dead = 0;
2729 ioa_cfg->reset_retries = 0;
2730 ioa_cfg->in_ioa_bringdown = 0;
2731 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2733 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2734 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2739 static struct class_device_attribute ipr_ioa_state_attr = {
2742 .mode = S_IRUGO | S_IWUSR,
2744 .show = ipr_show_adapter_state,
2745 .store = ipr_store_adapter_state
2749 * ipr_store_reset_adapter - Reset the adapter
2750 * @class_dev: class_device struct
2752 * @count: buffer size
2754 * This function will reset the adapter.
2757 * count on success / other on failure
2759 static ssize_t ipr_store_reset_adapter(struct class_device *class_dev,
2760 const char *buf, size_t count)
2762 struct Scsi_Host *shost = class_to_shost(class_dev);
2763 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2764 unsigned long lock_flags;
2767 if (!capable(CAP_SYS_ADMIN))
2770 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2771 if (!ioa_cfg->in_reset_reload)
2772 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2773 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2774 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2779 static struct class_device_attribute ipr_ioa_reset_attr = {
2781 .name = "reset_host",
2784 .store = ipr_store_reset_adapter
2788 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
2789 * @buf_len: buffer length
2791 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
2792 * list to use for microcode download
2795 * pointer to sglist / NULL on failure
2797 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
2799 int sg_size, order, bsize_elem, num_elem, i, j;
2800 struct ipr_sglist *sglist;
2801 struct scatterlist *scatterlist;
2804 /* Get the minimum size per scatter/gather element */
2805 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
2807 /* Get the actual size per element */
2808 order = get_order(sg_size);
2810 /* Determine the actual number of bytes per element */
2811 bsize_elem = PAGE_SIZE * (1 << order);
2813 /* Determine the actual number of sg entries needed */
2814 if (buf_len % bsize_elem)
2815 num_elem = (buf_len / bsize_elem) + 1;
2817 num_elem = buf_len / bsize_elem;
2819 /* Allocate a scatter/gather list for the DMA */
2820 sglist = kzalloc(sizeof(struct ipr_sglist) +
2821 (sizeof(struct scatterlist) * (num_elem - 1)),
2824 if (sglist == NULL) {
2829 scatterlist = sglist->scatterlist;
2831 sglist->order = order;
2832 sglist->num_sg = num_elem;
2834 /* Allocate a bunch of sg elements */
2835 for (i = 0; i < num_elem; i++) {
2836 page = alloc_pages(GFP_KERNEL, order);
2840 /* Free up what we already allocated */
2841 for (j = i - 1; j >= 0; j--)
2842 __free_pages(scatterlist[j].page, order);
2847 scatterlist[i].page = page;
2854 * ipr_free_ucode_buffer - Frees a microcode download buffer
2855 * @p_dnld: scatter/gather list pointer
2857 * Free a DMA'able ucode download buffer previously allocated with
2858 * ipr_alloc_ucode_buffer
2863 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
2867 for (i = 0; i < sglist->num_sg; i++)
2868 __free_pages(sglist->scatterlist[i].page, sglist->order);
2874 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
2875 * @sglist: scatter/gather list pointer
2876 * @buffer: buffer pointer
2877 * @len: buffer length
2879 * Copy a microcode image from a user buffer into a buffer allocated by
2880 * ipr_alloc_ucode_buffer
2883 * 0 on success / other on failure
2885 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
2886 u8 *buffer, u32 len)
2888 int bsize_elem, i, result = 0;
2889 struct scatterlist *scatterlist;
2892 /* Determine the actual number of bytes per element */
2893 bsize_elem = PAGE_SIZE * (1 << sglist->order);
2895 scatterlist = sglist->scatterlist;
2897 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
2898 kaddr = kmap(scatterlist[i].page);
2899 memcpy(kaddr, buffer, bsize_elem);
2900 kunmap(scatterlist[i].page);
2902 scatterlist[i].length = bsize_elem;
2910 if (len % bsize_elem) {
2911 kaddr = kmap(scatterlist[i].page);
2912 memcpy(kaddr, buffer, len % bsize_elem);
2913 kunmap(scatterlist[i].page);
2915 scatterlist[i].length = len % bsize_elem;
2918 sglist->buffer_len = len;
2923 * ipr_build_ucode_ioadl - Build a microcode download IOADL
2924 * @ipr_cmd: ipr command struct
2925 * @sglist: scatter/gather list
2927 * Builds a microcode download IOA data list (IOADL).
2930 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
2931 struct ipr_sglist *sglist)
2933 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
2934 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
2935 struct scatterlist *scatterlist = sglist->scatterlist;
2938 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
2939 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
2940 ioarcb->write_data_transfer_length = cpu_to_be32(sglist->buffer_len);
2941 ioarcb->write_ioadl_len =
2942 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
2944 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
2945 ioadl[i].flags_and_data_len =
2946 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
2948 cpu_to_be32(sg_dma_address(&scatterlist[i]));
2951 ioadl[i-1].flags_and_data_len |=
2952 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
2956 * ipr_update_ioa_ucode - Update IOA's microcode
2957 * @ioa_cfg: ioa config struct
2958 * @sglist: scatter/gather list
2960 * Initiate an adapter reset to update the IOA's microcode
2963 * 0 on success / -EIO on failure
2965 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
2966 struct ipr_sglist *sglist)
2968 unsigned long lock_flags;
2970 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2971 while(ioa_cfg->in_reset_reload) {
2972 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2973 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2974 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2977 if (ioa_cfg->ucode_sglist) {
2978 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2979 dev_err(&ioa_cfg->pdev->dev,
2980 "Microcode download already in progress\n");
2984 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
2985 sglist->num_sg, DMA_TO_DEVICE);
2987 if (!sglist->num_dma_sg) {
2988 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2989 dev_err(&ioa_cfg->pdev->dev,
2990 "Failed to map microcode download buffer!\n");
2994 ioa_cfg->ucode_sglist = sglist;
2995 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2996 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2997 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2999 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3000 ioa_cfg->ucode_sglist = NULL;
3001 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3006 * ipr_store_update_fw - Update the firmware on the adapter
3007 * @class_dev: class_device struct
3009 * @count: buffer size
3011 * This function will update the firmware on the adapter.
3014 * count on success / other on failure
3016 static ssize_t ipr_store_update_fw(struct class_device *class_dev,
3017 const char *buf, size_t count)
3019 struct Scsi_Host *shost = class_to_shost(class_dev);
3020 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3021 struct ipr_ucode_image_header *image_hdr;
3022 const struct firmware *fw_entry;
3023 struct ipr_sglist *sglist;
3026 int len, result, dnld_size;
3028 if (!capable(CAP_SYS_ADMIN))
3031 len = snprintf(fname, 99, "%s", buf);
3032 fname[len-1] = '\0';
3034 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3035 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3039 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
3041 if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
3042 (ioa_cfg->vpd_cbs->page3_data.card_type &&
3043 ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
3044 dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
3045 release_firmware(fw_entry);
3049 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
3050 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
3051 sglist = ipr_alloc_ucode_buffer(dnld_size);
3054 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
3055 release_firmware(fw_entry);
3059 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
3062 dev_err(&ioa_cfg->pdev->dev,
3063 "Microcode buffer copy to DMA buffer failed\n");
3067 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
3072 ipr_free_ucode_buffer(sglist);
3073 release_firmware(fw_entry);
3077 static struct class_device_attribute ipr_update_fw_attr = {
3079 .name = "update_fw",
3082 .store = ipr_store_update_fw
3085 static struct class_device_attribute *ipr_ioa_attrs[] = {
3086 &ipr_fw_version_attr,
3087 &ipr_log_level_attr,
3088 &ipr_diagnostics_attr,
3089 &ipr_ioa_state_attr,
3090 &ipr_ioa_reset_attr,
3091 &ipr_update_fw_attr,
3092 &ipr_ioa_cache_attr,
3096 #ifdef CONFIG_SCSI_IPR_DUMP
3098 * ipr_read_dump - Dump the adapter
3099 * @kobj: kobject struct
3102 * @count: buffer size
3105 * number of bytes printed to buffer
3107 static ssize_t ipr_read_dump(struct kobject *kobj, char *buf,
3108 loff_t off, size_t count)
3110 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3111 struct Scsi_Host *shost = class_to_shost(cdev);
3112 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3113 struct ipr_dump *dump;
3114 unsigned long lock_flags = 0;
3119 if (!capable(CAP_SYS_ADMIN))
3122 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3123 dump = ioa_cfg->dump;
3125 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
3126 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3129 kref_get(&dump->kref);
3130 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3132 if (off > dump->driver_dump.hdr.len) {
3133 kref_put(&dump->kref, ipr_release_dump);
3137 if (off + count > dump->driver_dump.hdr.len) {
3138 count = dump->driver_dump.hdr.len - off;
3142 if (count && off < sizeof(dump->driver_dump)) {
3143 if (off + count > sizeof(dump->driver_dump))
3144 len = sizeof(dump->driver_dump) - off;
3147 src = (u8 *)&dump->driver_dump + off;
3148 memcpy(buf, src, len);
3154 off -= sizeof(dump->driver_dump);
3156 if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
3157 if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
3158 len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
3161 src = (u8 *)&dump->ioa_dump + off;
3162 memcpy(buf, src, len);
3168 off -= offsetof(struct ipr_ioa_dump, ioa_data);
3171 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
3172 len = PAGE_ALIGN(off) - off;
3175 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
3176 src += off & ~PAGE_MASK;
3177 memcpy(buf, src, len);
3183 kref_put(&dump->kref, ipr_release_dump);
3188 * ipr_alloc_dump - Prepare for adapter dump
3189 * @ioa_cfg: ioa config struct
3192 * 0 on success / other on failure
3194 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
3196 struct ipr_dump *dump;
3197 unsigned long lock_flags = 0;
3199 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
3202 ipr_err("Dump memory allocation failed\n");
3206 kref_init(&dump->kref);
3207 dump->ioa_cfg = ioa_cfg;
3209 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3211 if (INACTIVE != ioa_cfg->sdt_state) {
3212 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3217 ioa_cfg->dump = dump;
3218 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
3219 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
3220 ioa_cfg->dump_taken = 1;
3221 schedule_work(&ioa_cfg->work_q);
3223 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3229 * ipr_free_dump - Free adapter dump memory
3230 * @ioa_cfg: ioa config struct
3233 * 0 on success / other on failure
3235 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
3237 struct ipr_dump *dump;
3238 unsigned long lock_flags = 0;
3242 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3243 dump = ioa_cfg->dump;
3245 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3249 ioa_cfg->dump = NULL;
3250 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3252 kref_put(&dump->kref, ipr_release_dump);
3259 * ipr_write_dump - Setup dump state of adapter
3260 * @kobj: kobject struct
3263 * @count: buffer size
3266 * number of bytes printed to buffer
3268 static ssize_t ipr_write_dump(struct kobject *kobj, char *buf,
3269 loff_t off, size_t count)
3271 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3272 struct Scsi_Host *shost = class_to_shost(cdev);
3273 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3276 if (!capable(CAP_SYS_ADMIN))
3280 rc = ipr_alloc_dump(ioa_cfg);
3281 else if (buf[0] == '0')
3282 rc = ipr_free_dump(ioa_cfg);
3292 static struct bin_attribute ipr_dump_attr = {
3295 .mode = S_IRUSR | S_IWUSR,
3298 .read = ipr_read_dump,
3299 .write = ipr_write_dump
3302 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
3306 * ipr_change_queue_depth - Change the device's queue depth
3307 * @sdev: scsi device struct
3308 * @qdepth: depth to set
3313 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
3315 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3316 struct ipr_resource_entry *res;
3317 unsigned long lock_flags = 0;
3319 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3320 res = (struct ipr_resource_entry *)sdev->hostdata;
3322 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
3323 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
3324 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3326 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
3327 return sdev->queue_depth;
3331 * ipr_change_queue_type - Change the device's queue type
3332 * @dsev: scsi device struct
3333 * @tag_type: type of tags to use
3336 * actual queue type set
3338 static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
3340 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3341 struct ipr_resource_entry *res;
3342 unsigned long lock_flags = 0;
3344 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3345 res = (struct ipr_resource_entry *)sdev->hostdata;
3348 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
3350 * We don't bother quiescing the device here since the
3351 * adapter firmware does it for us.
3353 scsi_set_tag_type(sdev, tag_type);
3356 scsi_activate_tcq(sdev, sdev->queue_depth);
3358 scsi_deactivate_tcq(sdev, sdev->queue_depth);
3364 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3369 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
3370 * @dev: device struct
3374 * number of bytes printed to buffer
3376 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
3378 struct scsi_device *sdev = to_scsi_device(dev);
3379 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3380 struct ipr_resource_entry *res;
3381 unsigned long lock_flags = 0;
3382 ssize_t len = -ENXIO;
3384 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3385 res = (struct ipr_resource_entry *)sdev->hostdata;
3387 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->cfgte.res_handle);
3388 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3392 static struct device_attribute ipr_adapter_handle_attr = {
3394 .name = "adapter_handle",
3397 .show = ipr_show_adapter_handle
3400 static struct device_attribute *ipr_dev_attrs[] = {
3401 &ipr_adapter_handle_attr,
3406 * ipr_biosparam - Return the HSC mapping
3407 * @sdev: scsi device struct
3408 * @block_device: block device pointer
3409 * @capacity: capacity of the device
3410 * @parm: Array containing returned HSC values.
3412 * This function generates the HSC parms that fdisk uses.
3413 * We want to make sure we return something that places partitions
3414 * on 4k boundaries for best performance with the IOA.
3419 static int ipr_biosparam(struct scsi_device *sdev,
3420 struct block_device *block_device,
3421 sector_t capacity, int *parm)
3429 cylinders = capacity;
3430 sector_div(cylinders, (128 * 32));
3435 parm[2] = cylinders;
3441 * ipr_find_starget - Find target based on bus/target.
3442 * @starget: scsi target struct
3445 * resource entry pointer if found / NULL if not found
3447 static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
3449 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
3450 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
3451 struct ipr_resource_entry *res;
3453 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3454 if ((res->cfgte.res_addr.bus == starget->channel) &&
3455 (res->cfgte.res_addr.target == starget->id) &&
3456 (res->cfgte.res_addr.lun == 0)) {
3464 static struct ata_port_info sata_port_info;
3467 * ipr_target_alloc - Prepare for commands to a SCSI target
3468 * @starget: scsi target struct
3470 * If the device is a SATA device, this function allocates an
3471 * ATA port with libata, else it does nothing.
3474 * 0 on success / non-0 on failure
3476 static int ipr_target_alloc(struct scsi_target *starget)
3478 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
3479 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
3480 struct ipr_sata_port *sata_port;
3481 struct ata_port *ap;
3482 struct ipr_resource_entry *res;
3483 unsigned long lock_flags;
3485 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3486 res = ipr_find_starget(starget);
3487 starget->hostdata = NULL;
3489 if (res && ipr_is_gata(res)) {
3490 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3491 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
3495 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
3497 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3498 sata_port->ioa_cfg = ioa_cfg;
3500 sata_port->res = res;
3502 res->sata_port = sata_port;
3503 ap->private_data = sata_port;
3504 starget->hostdata = sata_port;
3510 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3516 * ipr_target_destroy - Destroy a SCSI target
3517 * @starget: scsi target struct
3519 * If the device was a SATA device, this function frees the libata
3520 * ATA port, else it does nothing.
3523 static void ipr_target_destroy(struct scsi_target *starget)
3525 struct ipr_sata_port *sata_port = starget->hostdata;
3528 starget->hostdata = NULL;
3529 ata_sas_port_destroy(sata_port->ap);
3535 * ipr_find_sdev - Find device based on bus/target/lun.
3536 * @sdev: scsi device struct
3539 * resource entry pointer if found / NULL if not found
3541 static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
3543 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3544 struct ipr_resource_entry *res;
3546 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3547 if ((res->cfgte.res_addr.bus == sdev->channel) &&
3548 (res->cfgte.res_addr.target == sdev->id) &&
3549 (res->cfgte.res_addr.lun == sdev->lun))
3557 * ipr_slave_destroy - Unconfigure a SCSI device
3558 * @sdev: scsi device struct
3563 static void ipr_slave_destroy(struct scsi_device *sdev)
3565 struct ipr_resource_entry *res;
3566 struct ipr_ioa_cfg *ioa_cfg;
3567 unsigned long lock_flags = 0;
3569 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3571 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3572 res = (struct ipr_resource_entry *) sdev->hostdata;
3575 ata_port_disable(res->sata_port->ap);
3576 sdev->hostdata = NULL;
3578 res->sata_port = NULL;
3580 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3584 * ipr_slave_configure - Configure a SCSI device
3585 * @sdev: scsi device struct
3587 * This function configures the specified scsi device.
3592 static int ipr_slave_configure(struct scsi_device *sdev)
3594 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3595 struct ipr_resource_entry *res;
3596 unsigned long lock_flags = 0;
3598 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3599 res = sdev->hostdata;
3601 if (ipr_is_af_dasd_device(res))
3602 sdev->type = TYPE_RAID;
3603 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
3604 sdev->scsi_level = 4;
3605 sdev->no_uld_attach = 1;
3607 if (ipr_is_vset_device(res)) {
3608 sdev->timeout = IPR_VSET_RW_TIMEOUT;
3609 blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
3611 if (ipr_is_vset_device(res) || ipr_is_scsi_disk(res))
3612 sdev->allow_restart = 1;
3613 if (ipr_is_gata(res) && res->sata_port) {
3614 scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
3615 ata_sas_slave_configure(sdev, res->sata_port->ap);
3617 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
3620 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3625 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
3626 * @sdev: scsi device struct
3628 * This function initializes an ATA port so that future commands
3629 * sent through queuecommand will work.
3634 static int ipr_ata_slave_alloc(struct scsi_device *sdev)
3636 struct ipr_sata_port *sata_port = NULL;
3640 if (sdev->sdev_target)
3641 sata_port = sdev->sdev_target->hostdata;
3643 rc = ata_sas_port_init(sata_port->ap);
3645 ipr_slave_destroy(sdev);
3652 * ipr_slave_alloc - Prepare for commands to a device.
3653 * @sdev: scsi device struct
3655 * This function saves a pointer to the resource entry
3656 * in the scsi device struct if the device exists. We
3657 * can then use this pointer in ipr_queuecommand when
3658 * handling new commands.
3661 * 0 on success / -ENXIO if device does not exist
3663 static int ipr_slave_alloc(struct scsi_device *sdev)
3665 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3666 struct ipr_resource_entry *res;
3667 unsigned long lock_flags;
3670 sdev->hostdata = NULL;
3672 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3674 res = ipr_find_sdev(sdev);
3679 sdev->hostdata = res;
3680 if (!ipr_is_naca_model(res))
3681 res->needs_sync_complete = 1;
3683 if (ipr_is_gata(res)) {
3684 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3685 return ipr_ata_slave_alloc(sdev);
3689 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3695 * ipr_eh_host_reset - Reset the host adapter
3696 * @scsi_cmd: scsi command struct
3701 static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
3703 struct ipr_ioa_cfg *ioa_cfg;
3707 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
3709 dev_err(&ioa_cfg->pdev->dev,
3710 "Adapter being reset as a result of error recovery.\n");
3712 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
3713 ioa_cfg->sdt_state = GET_DUMP;
3715 rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
3721 static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
3725 spin_lock_irq(cmd->device->host->host_lock);
3726 rc = __ipr_eh_host_reset(cmd);
3727 spin_unlock_irq(cmd->device->host->host_lock);
3733 * ipr_device_reset - Reset the device
3734 * @ioa_cfg: ioa config struct
3735 * @res: resource entry struct
3737 * This function issues a device reset to the affected device.
3738 * If the device is a SCSI device, a LUN reset will be sent
3739 * to the device first. If that does not work, a target reset
3740 * will be sent. If the device is a SATA device, a PHY reset will
3744 * 0 on success / non-zero on failure
3746 static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
3747 struct ipr_resource_entry *res)
3749 struct ipr_cmnd *ipr_cmd;
3750 struct ipr_ioarcb *ioarcb;
3751 struct ipr_cmd_pkt *cmd_pkt;
3752 struct ipr_ioarcb_ata_regs *regs;
3756 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3757 ioarcb = &ipr_cmd->ioarcb;
3758 cmd_pkt = &ioarcb->cmd_pkt;
3759 regs = &ioarcb->add_data.u.regs;
3761 ioarcb->res_handle = res->cfgte.res_handle;
3762 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3763 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3764 if (ipr_is_gata(res)) {
3765 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
3766 ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(regs->flags));
3767 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
3770 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3771 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3772 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3773 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET)
3774 memcpy(&res->sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
3775 sizeof(struct ipr_ioasa_gata));
3778 return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0);
3782 * ipr_sata_reset - Reset the SATA port
3783 * @ap: SATA port to reset
3784 * @classes: class of the attached device
3786 * This function issues a SATA phy reset to the affected ATA port.
3789 * 0 on success / non-zero on failure
3791 static int ipr_sata_reset(struct ata_port *ap, unsigned int *classes,
3792 unsigned long deadline)
3794 struct ipr_sata_port *sata_port = ap->private_data;
3795 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
3796 struct ipr_resource_entry *res;
3797 unsigned long lock_flags = 0;
3801 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3802 while(ioa_cfg->in_reset_reload) {
3803 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3804 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3805 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3808 res = sata_port->res;
3810 rc = ipr_device_reset(ioa_cfg, res);
3811 switch(res->cfgte.proto) {
3812 case IPR_PROTO_SATA:
3813 case IPR_PROTO_SAS_STP:
3814 *classes = ATA_DEV_ATA;
3816 case IPR_PROTO_SATA_ATAPI:
3817 case IPR_PROTO_SAS_STP_ATAPI:
3818 *classes = ATA_DEV_ATAPI;
3821 *classes = ATA_DEV_UNKNOWN;
3826 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3832 * ipr_eh_dev_reset - Reset the device
3833 * @scsi_cmd: scsi command struct
3835 * This function issues a device reset to the affected device.
3836 * A LUN reset will be sent to the device first. If that does
3837 * not work, a target reset will be sent.
3842 static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
3844 struct ipr_cmnd *ipr_cmd;
3845 struct ipr_ioa_cfg *ioa_cfg;
3846 struct ipr_resource_entry *res;
3847 struct ata_port *ap;
3851 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
3852 res = scsi_cmd->device->hostdata;
3858 * If we are currently going through reset/reload, return failed. This will force the
3859 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
3862 if (ioa_cfg->in_reset_reload)
3864 if (ioa_cfg->ioa_is_dead)
3867 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
3868 if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
3869 if (ipr_cmd->scsi_cmd)
3870 ipr_cmd->done = ipr_scsi_eh_done;
3872 ipr_cmd->done = ipr_sata_eh_done;
3873 if (ipr_cmd->qc && !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
3874 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
3875 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
3880 res->resetting_device = 1;
3881 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
3883 if (ipr_is_gata(res) && res->sata_port) {
3884 ap = res->sata_port->ap;
3885 spin_unlock_irq(scsi_cmd->device->host->host_lock);
3886 ata_do_eh(ap, NULL, NULL, ipr_sata_reset, NULL);
3887 spin_lock_irq(scsi_cmd->device->host->host_lock);
3889 rc = ipr_device_reset(ioa_cfg, res);
3890 res->resetting_device = 0;
3893 return (rc ? FAILED : SUCCESS);
3896 static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
3900 spin_lock_irq(cmd->device->host->host_lock);
3901 rc = __ipr_eh_dev_reset(cmd);
3902 spin_unlock_irq(cmd->device->host->host_lock);
3908 * ipr_bus_reset_done - Op done function for bus reset.
3909 * @ipr_cmd: ipr command struct
3911 * This function is the op done function for a bus reset
3916 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
3918 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3919 struct ipr_resource_entry *res;
3922 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3923 if (!memcmp(&res->cfgte.res_handle, &ipr_cmd->ioarcb.res_handle,
3924 sizeof(res->cfgte.res_handle))) {
3925 scsi_report_bus_reset(ioa_cfg->host, res->cfgte.res_addr.bus);
3931 * If abort has not completed, indicate the reset has, else call the
3932 * abort's done function to wake the sleeping eh thread
3934 if (ipr_cmd->sibling->sibling)
3935 ipr_cmd->sibling->sibling = NULL;
3937 ipr_cmd->sibling->done(ipr_cmd->sibling);
3939 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3944 * ipr_abort_timeout - An abort task has timed out
3945 * @ipr_cmd: ipr command struct
3947 * This function handles when an abort task times out. If this
3948 * happens we issue a bus reset since we have resources tied
3949 * up that must be freed before returning to the midlayer.
3954 static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
3956 struct ipr_cmnd *reset_cmd;
3957 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3958 struct ipr_cmd_pkt *cmd_pkt;
3959 unsigned long lock_flags = 0;
3962 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3963 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
3964 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3968 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
3969 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3970 ipr_cmd->sibling = reset_cmd;
3971 reset_cmd->sibling = ipr_cmd;
3972 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
3973 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
3974 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3975 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3976 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
3978 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3979 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3984 * ipr_cancel_op - Cancel specified op
3985 * @scsi_cmd: scsi command struct
3987 * This function cancels specified op.
3992 static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
3994 struct ipr_cmnd *ipr_cmd;
3995 struct ipr_ioa_cfg *ioa_cfg;
3996 struct ipr_resource_entry *res;
3997 struct ipr_cmd_pkt *cmd_pkt;
4002 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4003 res = scsi_cmd->device->hostdata;
4005 /* If we are currently going through reset/reload, return failed.
4006 * This will force the mid-layer to call ipr_eh_host_reset,
4007 * which will then go to sleep and wait for the reset to complete
4009 if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
4011 if (!res || !ipr_is_gscsi(res))
4014 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4015 if (ipr_cmd->scsi_cmd == scsi_cmd) {
4016 ipr_cmd->done = ipr_scsi_eh_done;
4025 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4026 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
4027 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4028 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4029 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
4030 ipr_cmd->u.sdev = scsi_cmd->device;
4032 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
4034 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
4035 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4038 * If the abort task timed out and we sent a bus reset, we will get
4039 * one the following responses to the abort
4041 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
4046 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4047 if (!ipr_is_naca_model(res))
4048 res->needs_sync_complete = 1;
4051 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
4055 * ipr_eh_abort - Abort a single op
4056 * @scsi_cmd: scsi command struct
4061 static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
4063 unsigned long flags;
4068 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
4069 rc = ipr_cancel_op(scsi_cmd);
4070 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
4077 * ipr_handle_other_interrupt - Handle "other" interrupts
4078 * @ioa_cfg: ioa config struct
4079 * @int_reg: interrupt register
4082 * IRQ_NONE / IRQ_HANDLED
4084 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
4085 volatile u32 int_reg)
4087 irqreturn_t rc = IRQ_HANDLED;
4089 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
4090 /* Mask the interrupt */
4091 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
4093 /* Clear the interrupt */
4094 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
4095 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
4097 list_del(&ioa_cfg->reset_cmd->queue);
4098 del_timer(&ioa_cfg->reset_cmd->timer);
4099 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
4101 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
4102 ioa_cfg->ioa_unit_checked = 1;
4104 dev_err(&ioa_cfg->pdev->dev,
4105 "Permanent IOA failure. 0x%08X\n", int_reg);
4107 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4108 ioa_cfg->sdt_state = GET_DUMP;
4110 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
4111 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
4118 * ipr_isr - Interrupt service routine
4120 * @devp: pointer to ioa config struct
4123 * IRQ_NONE / IRQ_HANDLED
4125 static irqreturn_t ipr_isr(int irq, void *devp)
4127 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
4128 unsigned long lock_flags = 0;
4129 volatile u32 int_reg, int_mask_reg;
4132 struct ipr_cmnd *ipr_cmd;
4133 irqreturn_t rc = IRQ_NONE;
4135 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4137 /* If interrupts are disabled, ignore the interrupt */
4138 if (!ioa_cfg->allow_interrupts) {
4139 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4143 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
4144 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
4146 /* If an interrupt on the adapter did not occur, ignore it */
4147 if (unlikely((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0)) {
4148 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4155 while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
4156 ioa_cfg->toggle_bit) {
4158 cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
4159 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
4161 if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
4162 ioa_cfg->errors_logged++;
4163 dev_err(&ioa_cfg->pdev->dev, "Invalid response handle from IOA\n");
4165 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4166 ioa_cfg->sdt_state = GET_DUMP;
4168 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
4169 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4173 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
4175 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4177 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
4179 list_del(&ipr_cmd->queue);
4180 del_timer(&ipr_cmd->timer);
4181 ipr_cmd->done(ipr_cmd);
4185 if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
4186 ioa_cfg->hrrq_curr++;
4188 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
4189 ioa_cfg->toggle_bit ^= 1u;
4193 if (ipr_cmd != NULL) {
4194 /* Clear the PCI interrupt */
4195 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg);
4196 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
4201 if (unlikely(rc == IRQ_NONE))
4202 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
4204 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4209 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
4210 * @ioa_cfg: ioa config struct
4211 * @ipr_cmd: ipr command struct
4214 * 0 on success / -1 on failure
4216 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
4217 struct ipr_cmnd *ipr_cmd)
4220 struct scatterlist *sglist;
4222 u32 ioadl_flags = 0;
4223 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4224 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4225 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4227 length = scsi_cmd->request_bufflen;
4232 if (scsi_cmd->use_sg) {
4233 ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev,
4234 scsi_cmd->request_buffer,
4236 scsi_cmd->sc_data_direction);
4238 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
4239 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
4240 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4241 ioarcb->write_data_transfer_length = cpu_to_be32(length);
4242 ioarcb->write_ioadl_len =
4243 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
4244 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
4245 ioadl_flags = IPR_IOADL_FLAGS_READ;
4246 ioarcb->read_data_transfer_length = cpu_to_be32(length);
4247 ioarcb->read_ioadl_len =
4248 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
4251 sglist = scsi_cmd->request_buffer;
4253 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->add_data.u.ioadl)) {
4254 ioadl = ioarcb->add_data.u.ioadl;
4255 ioarcb->write_ioadl_addr =
4256 cpu_to_be32(be32_to_cpu(ioarcb->ioarcb_host_pci_addr) +
4257 offsetof(struct ipr_ioarcb, add_data));
4258 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
4261 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
4262 ioadl[i].flags_and_data_len =
4263 cpu_to_be32(ioadl_flags | sg_dma_len(&sglist[i]));
4265 cpu_to_be32(sg_dma_address(&sglist[i]));
4268 if (likely(ipr_cmd->dma_use_sg)) {
4269 ioadl[i-1].flags_and_data_len |=
4270 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
4273 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
4275 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
4276 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
4277 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4278 ioarcb->write_data_transfer_length = cpu_to_be32(length);
4279 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4280 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
4281 ioadl_flags = IPR_IOADL_FLAGS_READ;
4282 ioarcb->read_data_transfer_length = cpu_to_be32(length);
4283 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4286 ipr_cmd->dma_handle = pci_map_single(ioa_cfg->pdev,
4287 scsi_cmd->request_buffer, length,
4288 scsi_cmd->sc_data_direction);
4290 if (likely(!pci_dma_mapping_error(ipr_cmd->dma_handle))) {
4291 ioadl = ioarcb->add_data.u.ioadl;
4292 ioarcb->write_ioadl_addr =
4293 cpu_to_be32(be32_to_cpu(ioarcb->ioarcb_host_pci_addr) +
4294 offsetof(struct ipr_ioarcb, add_data));
4295 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
4296 ipr_cmd->dma_use_sg = 1;
4297 ioadl[0].flags_and_data_len =
4298 cpu_to_be32(ioadl_flags | length | IPR_IOADL_FLAGS_LAST);
4299 ioadl[0].address = cpu_to_be32(ipr_cmd->dma_handle);
4302 dev_err(&ioa_cfg->pdev->dev, "pci_map_single failed!\n");
4309 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
4310 * @scsi_cmd: scsi command struct
4315 static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
4318 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
4320 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
4322 case MSG_SIMPLE_TAG:
4323 rc = IPR_FLAGS_LO_SIMPLE_TASK;
4326 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
4328 case MSG_ORDERED_TAG:
4329 rc = IPR_FLAGS_LO_ORDERED_TASK;
4338 * ipr_erp_done - Process completion of ERP for a device
4339 * @ipr_cmd: ipr command struct
4341 * This function copies the sense buffer into the scsi_cmd
4342 * struct and pushes the scsi_done function.
4347 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
4349 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4350 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4351 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4352 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4354 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
4355 scsi_cmd->result |= (DID_ERROR << 16);
4356 scmd_printk(KERN_ERR, scsi_cmd,
4357 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
4359 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
4360 SCSI_SENSE_BUFFERSIZE);
4364 if (!ipr_is_naca_model(res))
4365 res->needs_sync_complete = 1;
4368 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4369 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4370 scsi_cmd->scsi_done(scsi_cmd);
4374 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
4375 * @ipr_cmd: ipr command struct
4380 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
4382 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4383 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4384 dma_addr_t dma_addr = be32_to_cpu(ioarcb->ioarcb_host_pci_addr);
4386 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
4387 ioarcb->write_data_transfer_length = 0;
4388 ioarcb->read_data_transfer_length = 0;
4389 ioarcb->write_ioadl_len = 0;
4390 ioarcb->read_ioadl_len = 0;
4392 ioasa->residual_data_len = 0;
4393 ioarcb->write_ioadl_addr =
4394 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
4395 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
4399 * ipr_erp_request_sense - Send request sense to a device
4400 * @ipr_cmd: ipr command struct
4402 * This function sends a request sense to a device as a result
4403 * of a check condition.
4408 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
4410 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4411 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4413 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
4414 ipr_erp_done(ipr_cmd);
4418 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
4420 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
4421 cmd_pkt->cdb[0] = REQUEST_SENSE;
4422 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
4423 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
4424 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
4425 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
4427 ipr_cmd->ioadl[0].flags_and_data_len =
4428 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | SCSI_SENSE_BUFFERSIZE);
4429 ipr_cmd->ioadl[0].address =
4430 cpu_to_be32(ipr_cmd->sense_buffer_dma);
4432 ipr_cmd->ioarcb.read_ioadl_len =
4433 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4434 ipr_cmd->ioarcb.read_data_transfer_length =
4435 cpu_to_be32(SCSI_SENSE_BUFFERSIZE);
4437 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
4438 IPR_REQUEST_SENSE_TIMEOUT * 2);
4442 * ipr_erp_cancel_all - Send cancel all to a device
4443 * @ipr_cmd: ipr command struct
4445 * This function sends a cancel all to a device to clear the
4446 * queue. If we are running TCQ on the device, QERR is set to 1,
4447 * which means all outstanding ops have been dropped on the floor.
4448 * Cancel all will return them to us.
4453 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
4455 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4456 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4457 struct ipr_cmd_pkt *cmd_pkt;
4461 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
4463 if (!scsi_get_tag_type(scsi_cmd->device)) {
4464 ipr_erp_request_sense(ipr_cmd);
4468 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4469 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4470 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
4472 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
4473 IPR_CANCEL_ALL_TIMEOUT);
4477 * ipr_dump_ioasa - Dump contents of IOASA
4478 * @ioa_cfg: ioa config struct
4479 * @ipr_cmd: ipr command struct
4480 * @res: resource entry struct
4482 * This function is invoked by the interrupt handler when ops
4483 * fail. It will log the IOASA if appropriate. Only called
4489 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
4490 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
4494 u32 ioasc, fd_ioasc;
4495 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4496 __be32 *ioasa_data = (__be32 *)ioasa;
4499 ioasc = be32_to_cpu(ioasa->ioasc) & IPR_IOASC_IOASC_MASK;
4500 fd_ioasc = be32_to_cpu(ioasa->fd_ioasc) & IPR_IOASC_IOASC_MASK;
4505 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
4508 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
4509 error_index = ipr_get_error(fd_ioasc);
4511 error_index = ipr_get_error(ioasc);
4513 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
4514 /* Don't log an error if the IOA already logged one */
4515 if (ioasa->ilid != 0)
4518 if (!ipr_is_gscsi(res))
4521 if (ipr_error_table[error_index].log_ioasa == 0)
4525 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
4527 if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
4528 data_len = sizeof(struct ipr_ioasa);
4530 data_len = be16_to_cpu(ioasa->ret_stat_len);
4532 ipr_err("IOASA Dump:\n");
4534 for (i = 0; i < data_len / 4; i += 4) {
4535 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
4536 be32_to_cpu(ioasa_data[i]),
4537 be32_to_cpu(ioasa_data[i+1]),
4538 be32_to_cpu(ioasa_data[i+2]),
4539 be32_to_cpu(ioasa_data[i+3]));
4544 * ipr_gen_sense - Generate SCSI sense data from an IOASA
4546 * @sense_buf: sense data buffer
4551 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
4554 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
4555 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
4556 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4557 u32 ioasc = be32_to_cpu(ioasa->ioasc);
4559 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
4561 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
4564 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
4566 if (ipr_is_vset_device(res) &&
4567 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
4568 ioasa->u.vset.failing_lba_hi != 0) {
4569 sense_buf[0] = 0x72;
4570 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
4571 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
4572 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
4576 sense_buf[9] = 0x0A;
4577 sense_buf[10] = 0x80;
4579 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
4581 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
4582 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
4583 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
4584 sense_buf[15] = failing_lba & 0x000000ff;
4586 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
4588 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
4589 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
4590 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
4591 sense_buf[19] = failing_lba & 0x000000ff;
4593 sense_buf[0] = 0x70;
4594 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
4595 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
4596 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
4598 /* Illegal request */
4599 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
4600 (be32_to_cpu(ioasa->ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
4601 sense_buf[7] = 10; /* additional length */
4603 /* IOARCB was in error */
4604 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
4605 sense_buf[15] = 0xC0;
4606 else /* Parameter data was invalid */
4607 sense_buf[15] = 0x80;
4610 ((IPR_FIELD_POINTER_MASK &
4611 be32_to_cpu(ioasa->ioasc_specific)) >> 8) & 0xff;
4613 (IPR_FIELD_POINTER_MASK &
4614 be32_to_cpu(ioasa->ioasc_specific)) & 0xff;
4616 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
4617 if (ipr_is_vset_device(res))
4618 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
4620 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
4622 sense_buf[0] |= 0x80; /* Or in the Valid bit */
4623 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
4624 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
4625 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
4626 sense_buf[6] = failing_lba & 0x000000ff;
4629 sense_buf[7] = 6; /* additional length */
4635 * ipr_get_autosense - Copy autosense data to sense buffer
4636 * @ipr_cmd: ipr command struct
4638 * This function copies the autosense buffer to the buffer
4639 * in the scsi_cmd, if there is autosense available.
4642 * 1 if autosense was available / 0 if not
4644 static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
4646 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4648 if ((be32_to_cpu(ioasa->ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
4651 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
4652 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
4653 SCSI_SENSE_BUFFERSIZE));
4658 * ipr_erp_start - Process an error response for a SCSI op
4659 * @ioa_cfg: ioa config struct
4660 * @ipr_cmd: ipr command struct
4662 * This function determines whether or not to initiate ERP
4663 * on the affected device.
4668 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
4669 struct ipr_cmnd *ipr_cmd)
4671 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4672 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4673 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4674 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
4677 ipr_scsi_eh_done(ipr_cmd);
4681 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
4682 ipr_gen_sense(ipr_cmd);
4684 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
4686 switch (masked_ioasc) {
4687 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
4688 if (ipr_is_naca_model(res))
4689 scsi_cmd->result |= (DID_ABORT << 16);
4691 scsi_cmd->result |= (DID_IMM_RETRY << 16);
4693 case IPR_IOASC_IR_RESOURCE_HANDLE:
4694 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
4695 scsi_cmd->result |= (DID_NO_CONNECT << 16);
4697 case IPR_IOASC_HW_SEL_TIMEOUT:
4698 scsi_cmd->result |= (DID_NO_CONNECT << 16);
4699 if (!ipr_is_naca_model(res))
4700 res->needs_sync_complete = 1;
4702 case IPR_IOASC_SYNC_REQUIRED:
4704 res->needs_sync_complete = 1;
4705 scsi_cmd->result |= (DID_IMM_RETRY << 16);
4707 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
4708 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
4709 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
4711 case IPR_IOASC_BUS_WAS_RESET:
4712 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
4714 * Report the bus reset and ask for a retry. The device
4715 * will give CC/UA the next command.
4717 if (!res->resetting_device)
4718 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
4719 scsi_cmd->result |= (DID_ERROR << 16);
4720 if (!ipr_is_naca_model(res))
4721 res->needs_sync_complete = 1;
4723 case IPR_IOASC_HW_DEV_BUS_STATUS:
4724 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
4725 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
4726 if (!ipr_get_autosense(ipr_cmd)) {
4727 if (!ipr_is_naca_model(res)) {
4728 ipr_erp_cancel_all(ipr_cmd);
4733 if (!ipr_is_naca_model(res))
4734 res->needs_sync_complete = 1;
4736 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
4739 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
4740 scsi_cmd->result |= (DID_ERROR << 16);
4741 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
4742 res->needs_sync_complete = 1;
4746 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4747 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4748 scsi_cmd->scsi_done(scsi_cmd);
4752 * ipr_scsi_done - mid-layer done function
4753 * @ipr_cmd: ipr command struct
4755 * This function is invoked by the interrupt handler for
4756 * ops generated by the SCSI mid-layer
4761 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
4763 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4764 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4765 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4767 scsi_cmd->resid = be32_to_cpu(ipr_cmd->ioasa.residual_data_len);
4769 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
4770 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4771 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4772 scsi_cmd->scsi_done(scsi_cmd);
4774 ipr_erp_start(ioa_cfg, ipr_cmd);
4778 * ipr_queuecommand - Queue a mid-layer request
4779 * @scsi_cmd: scsi command struct
4780 * @done: done function
4782 * This function queues a request generated by the mid-layer.
4786 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
4787 * SCSI_MLQUEUE_HOST_BUSY if host is busy
4789 static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
4790 void (*done) (struct scsi_cmnd *))
4792 struct ipr_ioa_cfg *ioa_cfg;
4793 struct ipr_resource_entry *res;
4794 struct ipr_ioarcb *ioarcb;
4795 struct ipr_cmnd *ipr_cmd;
4798 scsi_cmd->scsi_done = done;
4799 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4800 res = scsi_cmd->device->hostdata;
4801 scsi_cmd->result = (DID_OK << 16);
4804 * We are currently blocking all devices due to a host reset
4805 * We have told the host to stop giving us new requests, but
4806 * ERP ops don't count. FIXME
4808 if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))
4809 return SCSI_MLQUEUE_HOST_BUSY;
4812 * FIXME - Create scsi_set_host_offline interface
4813 * and the ioa_is_dead check can be removed
4815 if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
4816 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
4817 scsi_cmd->result = (DID_NO_CONNECT << 16);
4818 scsi_cmd->scsi_done(scsi_cmd);
4822 if (ipr_is_gata(res) && res->sata_port)
4823 return ata_sas_queuecmd(scsi_cmd, done, res->sata_port->ap);
4825 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4826 ioarcb = &ipr_cmd->ioarcb;
4827 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
4829 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
4830 ipr_cmd->scsi_cmd = scsi_cmd;
4831 ioarcb->res_handle = res->cfgte.res_handle;
4832 ipr_cmd->done = ipr_scsi_done;
4833 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
4835 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
4836 if (scsi_cmd->underflow == 0)
4837 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
4839 if (res->needs_sync_complete) {
4840 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
4841 res->needs_sync_complete = 0;
4844 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
4845 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
4846 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
4847 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
4850 if (scsi_cmd->cmnd[0] >= 0xC0 &&
4851 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
4852 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4854 if (likely(rc == 0))
4855 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
4857 if (likely(rc == 0)) {
4859 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
4860 ioa_cfg->regs.ioarrin_reg);
4862 list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4863 return SCSI_MLQUEUE_HOST_BUSY;
4870 * ipr_ioctl - IOCTL handler
4871 * @sdev: scsi device struct
4876 * 0 on success / other on failure
4878 static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
4880 struct ipr_resource_entry *res;
4882 res = (struct ipr_resource_entry *)sdev->hostdata;
4883 if (res && ipr_is_gata(res))
4884 return ata_scsi_ioctl(sdev, cmd, arg);
4890 * ipr_info - Get information about the card/driver
4891 * @scsi_host: scsi host struct
4894 * pointer to buffer with description string
4896 static const char * ipr_ioa_info(struct Scsi_Host *host)
4898 static char buffer[512];
4899 struct ipr_ioa_cfg *ioa_cfg;
4900 unsigned long lock_flags = 0;
4902 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
4904 spin_lock_irqsave(host->host_lock, lock_flags);
4905 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
4906 spin_unlock_irqrestore(host->host_lock, lock_flags);
4911 static struct scsi_host_template driver_template = {
4912 .module = THIS_MODULE,
4914 .info = ipr_ioa_info,
4916 .queuecommand = ipr_queuecommand,
4917 .eh_abort_handler = ipr_eh_abort,
4918 .eh_device_reset_handler = ipr_eh_dev_reset,
4919 .eh_host_reset_handler = ipr_eh_host_reset,
4920 .slave_alloc = ipr_slave_alloc,
4921 .slave_configure = ipr_slave_configure,
4922 .slave_destroy = ipr_slave_destroy,
4923 .target_alloc = ipr_target_alloc,
4924 .target_destroy = ipr_target_destroy,
4925 .change_queue_depth = ipr_change_queue_depth,
4926 .change_queue_type = ipr_change_queue_type,
4927 .bios_param = ipr_biosparam,
4928 .can_queue = IPR_MAX_COMMANDS,
4930 .sg_tablesize = IPR_MAX_SGLIST,
4931 .max_sectors = IPR_IOA_MAX_SECTORS,
4932 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
4933 .use_clustering = ENABLE_CLUSTERING,
4934 .shost_attrs = ipr_ioa_attrs,
4935 .sdev_attrs = ipr_dev_attrs,
4936 .proc_name = IPR_NAME
4940 * ipr_ata_phy_reset - libata phy_reset handler
4941 * @ap: ata port to reset
4944 static void ipr_ata_phy_reset(struct ata_port *ap)
4946 unsigned long flags;
4947 struct ipr_sata_port *sata_port = ap->private_data;
4948 struct ipr_resource_entry *res = sata_port->res;
4949 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4953 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
4954 while(ioa_cfg->in_reset_reload) {
4955 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
4956 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4957 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
4960 if (!ioa_cfg->allow_cmds)
4963 rc = ipr_device_reset(ioa_cfg, res);
4966 ap->ops->port_disable(ap);
4970 switch(res->cfgte.proto) {
4971 case IPR_PROTO_SATA:
4972 case IPR_PROTO_SAS_STP:
4973 ap->device[0].class = ATA_DEV_ATA;
4975 case IPR_PROTO_SATA_ATAPI:
4976 case IPR_PROTO_SAS_STP_ATAPI:
4977 ap->device[0].class = ATA_DEV_ATAPI;
4980 ap->device[0].class = ATA_DEV_UNKNOWN;
4981 ap->ops->port_disable(ap);
4986 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
4991 * ipr_ata_post_internal - Cleanup after an internal command
4992 * @qc: ATA queued command
4997 static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
4999 struct ipr_sata_port *sata_port = qc->ap->private_data;
5000 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5001 struct ipr_cmnd *ipr_cmd;
5002 unsigned long flags;
5004 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
5005 while(ioa_cfg->in_reset_reload) {
5006 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
5007 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
5008 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
5011 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
5012 if (ipr_cmd->qc == qc) {
5013 ipr_device_reset(ioa_cfg, sata_port->res);
5017 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
5021 * ipr_tf_read - Read the current ATA taskfile for the ATA port
5023 * @tf: destination ATA taskfile
5028 static void ipr_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
5030 struct ipr_sata_port *sata_port = ap->private_data;
5031 struct ipr_ioasa_gata *g = &sata_port->ioasa;
5033 tf->feature = g->error;
5034 tf->nsect = g->nsect;
5038 tf->device = g->device;
5039 tf->command = g->status;
5040 tf->hob_nsect = g->hob_nsect;
5041 tf->hob_lbal = g->hob_lbal;
5042 tf->hob_lbam = g->hob_lbam;
5043 tf->hob_lbah = g->hob_lbah;
5044 tf->ctl = g->alt_status;
5048 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
5049 * @regs: destination
5050 * @tf: source ATA taskfile
5055 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
5056 struct ata_taskfile *tf)
5058 regs->feature = tf->feature;
5059 regs->nsect = tf->nsect;
5060 regs->lbal = tf->lbal;
5061 regs->lbam = tf->lbam;
5062 regs->lbah = tf->lbah;
5063 regs->device = tf->device;
5064 regs->command = tf->command;
5065 regs->hob_feature = tf->hob_feature;
5066 regs->hob_nsect = tf->hob_nsect;
5067 regs->hob_lbal = tf->hob_lbal;
5068 regs->hob_lbam = tf->hob_lbam;
5069 regs->hob_lbah = tf->hob_lbah;
5070 regs->ctl = tf->ctl;
5074 * ipr_sata_done - done function for SATA commands
5075 * @ipr_cmd: ipr command struct
5077 * This function is invoked by the interrupt handler for
5078 * ops generated by the SCSI mid-layer to SATA devices
5083 static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
5085 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5086 struct ata_queued_cmd *qc = ipr_cmd->qc;
5087 struct ipr_sata_port *sata_port = qc->ap->private_data;
5088 struct ipr_resource_entry *res = sata_port->res;
5089 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5091 memcpy(&sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
5092 sizeof(struct ipr_ioasa_gata));
5093 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
5095 if (be32_to_cpu(ipr_cmd->ioasa.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
5096 scsi_report_device_reset(ioa_cfg->host, res->cfgte.res_addr.bus,
5097 res->cfgte.res_addr.target);
5099 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
5100 qc->err_mask |= __ac_err_mask(ipr_cmd->ioasa.u.gata.status);
5102 qc->err_mask |= ac_err_mask(ipr_cmd->ioasa.u.gata.status);
5103 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5104 ata_qc_complete(qc);
5108 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
5109 * @ipr_cmd: ipr command struct
5110 * @qc: ATA queued command
5113 static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
5114 struct ata_queued_cmd *qc)
5116 u32 ioadl_flags = 0;
5117 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5118 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5119 int len = qc->nbytes + qc->pad_len;
5120 struct scatterlist *sg;
5125 if (qc->dma_dir == DMA_TO_DEVICE) {
5126 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5127 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5128 ioarcb->write_data_transfer_length = cpu_to_be32(len);
5129 ioarcb->write_ioadl_len =
5130 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5131 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
5132 ioadl_flags = IPR_IOADL_FLAGS_READ;
5133 ioarcb->read_data_transfer_length = cpu_to_be32(len);
5134 ioarcb->read_ioadl_len =
5135 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5138 ata_for_each_sg(sg, qc) {
5139 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5140 ioadl->address = cpu_to_be32(sg_dma_address(sg));
5141 if (ata_sg_is_last(sg, qc))
5142 ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5149 * ipr_qc_issue - Issue a SATA qc to a device
5150 * @qc: queued command
5155 static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
5157 struct ata_port *ap = qc->ap;
5158 struct ipr_sata_port *sata_port = ap->private_data;
5159 struct ipr_resource_entry *res = sata_port->res;
5160 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5161 struct ipr_cmnd *ipr_cmd;
5162 struct ipr_ioarcb *ioarcb;
5163 struct ipr_ioarcb_ata_regs *regs;
5165 if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead))
5166 return AC_ERR_SYSTEM;
5168 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5169 ioarcb = &ipr_cmd->ioarcb;
5170 regs = &ioarcb->add_data.u.regs;
5172 memset(&ioarcb->add_data, 0, sizeof(ioarcb->add_data));
5173 ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(ioarcb->add_data.u.regs));
5175 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
5177 ipr_cmd->done = ipr_sata_done;
5178 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
5179 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
5180 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
5181 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5182 ipr_cmd->dma_use_sg = qc->pad_len ? qc->n_elem + 1 : qc->n_elem;
5184 ipr_build_ata_ioadl(ipr_cmd, qc);
5185 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
5186 ipr_copy_sata_tf(regs, &qc->tf);
5187 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
5188 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
5190 switch (qc->tf.protocol) {
5191 case ATA_PROT_NODATA:
5196 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
5199 case ATA_PROT_ATAPI:
5200 case ATA_PROT_ATAPI_NODATA:
5201 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
5204 case ATA_PROT_ATAPI_DMA:
5205 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
5206 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
5211 return AC_ERR_INVALID;
5215 writel(be32_to_cpu(ioarcb->ioarcb_host_pci_addr),
5216 ioa_cfg->regs.ioarrin_reg);
5221 * ipr_ata_check_status - Return last ATA status
5227 static u8 ipr_ata_check_status(struct ata_port *ap)
5229 struct ipr_sata_port *sata_port = ap->private_data;
5230 return sata_port->ioasa.status;
5234 * ipr_ata_check_altstatus - Return last ATA altstatus
5240 static u8 ipr_ata_check_altstatus(struct ata_port *ap)
5242 struct ipr_sata_port *sata_port = ap->private_data;
5243 return sata_port->ioasa.alt_status;
5246 static struct ata_port_operations ipr_sata_ops = {
5247 .port_disable = ata_port_disable,
5248 .check_status = ipr_ata_check_status,
5249 .check_altstatus = ipr_ata_check_altstatus,
5250 .dev_select = ata_noop_dev_select,
5251 .phy_reset = ipr_ata_phy_reset,
5252 .post_internal_cmd = ipr_ata_post_internal,
5253 .tf_read = ipr_tf_read,
5254 .qc_prep = ata_noop_qc_prep,
5255 .qc_issue = ipr_qc_issue,
5256 .port_start = ata_sas_port_start,
5257 .port_stop = ata_sas_port_stop
5260 static struct ata_port_info sata_port_info = {
5261 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | ATA_FLAG_SATA_RESET |
5262 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
5263 .pio_mask = 0x10, /* pio4 */
5265 .udma_mask = 0x7f, /* udma0-6 */
5266 .port_ops = &ipr_sata_ops
5269 #ifdef CONFIG_PPC_PSERIES
5270 static const u16 ipr_blocked_processors[] = {
5282 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
5283 * @ioa_cfg: ioa cfg struct
5285 * Adapters that use Gemstone revision < 3.1 do not work reliably on
5286 * certain pSeries hardware. This function determines if the given
5287 * adapter is in one of these confgurations or not.
5290 * 1 if adapter is not supported / 0 if adapter is supported
5292 static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
5297 if (ioa_cfg->type == 0x5702) {
5298 if (pci_read_config_byte(ioa_cfg->pdev, PCI_REVISION_ID,
5299 &rev_id) == PCIBIOS_SUCCESSFUL) {
5301 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
5302 if (__is_processor(ipr_blocked_processors[i]))
5311 #define ipr_invalid_adapter(ioa_cfg) 0
5315 * ipr_ioa_bringdown_done - IOA bring down completion.
5316 * @ipr_cmd: ipr command struct
5318 * This function processes the completion of an adapter bring down.
5319 * It wakes any reset sleepers.
5324 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
5326 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5329 ioa_cfg->in_reset_reload = 0;
5330 ioa_cfg->reset_retries = 0;
5331 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5332 wake_up_all(&ioa_cfg->reset_wait_q);
5334 spin_unlock_irq(ioa_cfg->host->host_lock);
5335 scsi_unblock_requests(ioa_cfg->host);
5336 spin_lock_irq(ioa_cfg->host->host_lock);
5339 return IPR_RC_JOB_RETURN;
5343 * ipr_ioa_reset_done - IOA reset completion.
5344 * @ipr_cmd: ipr command struct
5346 * This function processes the completion of an adapter reset.
5347 * It schedules any necessary mid-layer add/removes and
5348 * wakes any reset sleepers.
5353 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
5355 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5356 struct ipr_resource_entry *res;
5357 struct ipr_hostrcb *hostrcb, *temp;
5361 ioa_cfg->in_reset_reload = 0;
5362 ioa_cfg->allow_cmds = 1;
5363 ioa_cfg->reset_cmd = NULL;
5364 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
5366 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
5367 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
5372 schedule_work(&ioa_cfg->work_q);
5374 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
5375 list_del(&hostrcb->queue);
5376 if (i++ < IPR_NUM_LOG_HCAMS)
5377 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
5379 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
5382 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
5383 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
5385 ioa_cfg->reset_retries = 0;
5386 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5387 wake_up_all(&ioa_cfg->reset_wait_q);
5389 spin_unlock_irq(ioa_cfg->host->host_lock);
5390 scsi_unblock_requests(ioa_cfg->host);
5391 spin_lock_irq(ioa_cfg->host->host_lock);
5393 if (!ioa_cfg->allow_cmds)
5394 scsi_block_requests(ioa_cfg->host);
5397 return IPR_RC_JOB_RETURN;
5401 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
5402 * @supported_dev: supported device struct
5403 * @vpids: vendor product id struct
5408 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
5409 struct ipr_std_inq_vpids *vpids)
5411 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
5412 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
5413 supported_dev->num_records = 1;
5414 supported_dev->data_length =
5415 cpu_to_be16(sizeof(struct ipr_supported_device));
5416 supported_dev->reserved = 0;
5420 * ipr_set_supported_devs - Send Set Supported Devices for a device
5421 * @ipr_cmd: ipr command struct
5423 * This function send a Set Supported Devices to the adapter
5426 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5428 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
5430 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5431 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
5432 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5433 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5434 struct ipr_resource_entry *res = ipr_cmd->u.res;
5436 ipr_cmd->job_step = ipr_ioa_reset_done;
5438 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
5439 if (!ipr_is_scsi_disk(res))
5442 ipr_cmd->u.res = res;
5443 ipr_set_sup_dev_dflt(supp_dev, &res->cfgte.std_inq_data.vpids);
5445 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5446 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5447 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5449 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
5450 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
5451 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
5453 ioadl->flags_and_data_len = cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST |
5454 sizeof(struct ipr_supported_device));
5455 ioadl->address = cpu_to_be32(ioa_cfg->vpd_cbs_dma +
5456 offsetof(struct ipr_misc_cbs, supp_dev));
5457 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5458 ioarcb->write_data_transfer_length =
5459 cpu_to_be32(sizeof(struct ipr_supported_device));
5461 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
5462 IPR_SET_SUP_DEVICE_TIMEOUT);
5464 ipr_cmd->job_step = ipr_set_supported_devs;
5465 return IPR_RC_JOB_RETURN;
5468 return IPR_RC_JOB_CONTINUE;
5472 * ipr_setup_write_cache - Disable write cache if needed
5473 * @ipr_cmd: ipr command struct
5475 * This function sets up adapters write cache to desired setting
5478 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5480 static int ipr_setup_write_cache(struct ipr_cmnd *ipr_cmd)
5482 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5484 ipr_cmd->job_step = ipr_set_supported_devs;
5485 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
5486 struct ipr_resource_entry, queue);
5488 if (ioa_cfg->cache_state != CACHE_DISABLED)
5489 return IPR_RC_JOB_CONTINUE;
5491 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5492 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5493 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
5494 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
5496 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5498 return IPR_RC_JOB_RETURN;
5502 * ipr_get_mode_page - Locate specified mode page
5503 * @mode_pages: mode page buffer
5504 * @page_code: page code to find
5505 * @len: minimum required length for mode page
5508 * pointer to mode page / NULL on failure
5510 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
5511 u32 page_code, u32 len)
5513 struct ipr_mode_page_hdr *mode_hdr;
5517 if (!mode_pages || (mode_pages->hdr.length == 0))
5520 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
5521 mode_hdr = (struct ipr_mode_page_hdr *)
5522 (mode_pages->data + mode_pages->hdr.block_desc_len);
5525 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
5526 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
5530 page_length = (sizeof(struct ipr_mode_page_hdr) +
5531 mode_hdr->page_length);
5532 length -= page_length;
5533 mode_hdr = (struct ipr_mode_page_hdr *)
5534 ((unsigned long)mode_hdr + page_length);
5541 * ipr_check_term_power - Check for term power errors
5542 * @ioa_cfg: ioa config struct
5543 * @mode_pages: IOAFP mode pages buffer
5545 * Check the IOAFP's mode page 28 for term power errors
5550 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
5551 struct ipr_mode_pages *mode_pages)
5555 struct ipr_dev_bus_entry *bus;
5556 struct ipr_mode_page28 *mode_page;
5558 mode_page = ipr_get_mode_page(mode_pages, 0x28,
5559 sizeof(struct ipr_mode_page28));
5561 entry_length = mode_page->entry_length;
5563 bus = mode_page->bus;
5565 for (i = 0; i < mode_page->num_entries; i++) {
5566 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
5567 dev_err(&ioa_cfg->pdev->dev,
5568 "Term power is absent on scsi bus %d\n",
5572 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
5577 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
5578 * @ioa_cfg: ioa config struct
5580 * Looks through the config table checking for SES devices. If
5581 * the SES device is in the SES table indicating a maximum SCSI
5582 * bus speed, the speed is limited for the bus.
5587 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
5592 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
5593 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
5594 ioa_cfg->bus_attr[i].bus_width);
5596 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
5597 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
5602 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
5603 * @ioa_cfg: ioa config struct
5604 * @mode_pages: mode page 28 buffer
5606 * Updates mode page 28 based on driver configuration
5611 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
5612 struct ipr_mode_pages *mode_pages)
5614 int i, entry_length;
5615 struct ipr_dev_bus_entry *bus;
5616 struct ipr_bus_attributes *bus_attr;
5617 struct ipr_mode_page28 *mode_page;
5619 mode_page = ipr_get_mode_page(mode_pages, 0x28,
5620 sizeof(struct ipr_mode_page28));
5622 entry_length = mode_page->entry_length;
5624 /* Loop for each device bus entry */
5625 for (i = 0, bus = mode_page->bus;
5626 i < mode_page->num_entries;
5627 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
5628 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
5629 dev_err(&ioa_cfg->pdev->dev,
5630 "Invalid resource address reported: 0x%08X\n",
5631 IPR_GET_PHYS_LOC(bus->res_addr));
5635 bus_attr = &ioa_cfg->bus_attr[i];
5636 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
5637 bus->bus_width = bus_attr->bus_width;
5638 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
5639 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
5640 if (bus_attr->qas_enabled)
5641 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
5643 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
5648 * ipr_build_mode_select - Build a mode select command
5649 * @ipr_cmd: ipr command struct
5650 * @res_handle: resource handle to send command to
5651 * @parm: Byte 2 of Mode Sense command
5652 * @dma_addr: DMA buffer address
5653 * @xfer_len: data transfer length
5658 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
5659 __be32 res_handle, u8 parm, u32 dma_addr,
5662 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5663 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5665 ioarcb->res_handle = res_handle;
5666 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5667 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5668 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
5669 ioarcb->cmd_pkt.cdb[1] = parm;
5670 ioarcb->cmd_pkt.cdb[4] = xfer_len;
5672 ioadl->flags_and_data_len =
5673 cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST | xfer_len);
5674 ioadl->address = cpu_to_be32(dma_addr);
5675 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5676 ioarcb->write_data_transfer_length = cpu_to_be32(xfer_len);
5680 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
5681 * @ipr_cmd: ipr command struct
5683 * This function sets up the SCSI bus attributes and sends
5684 * a Mode Select for Page 28 to activate them.
5689 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
5691 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5692 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
5696 ipr_scsi_bus_speed_limit(ioa_cfg);
5697 ipr_check_term_power(ioa_cfg, mode_pages);
5698 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
5699 length = mode_pages->hdr.length + 1;
5700 mode_pages->hdr.length = 0;
5702 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
5703 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
5706 ipr_cmd->job_step = ipr_setup_write_cache;
5707 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5710 return IPR_RC_JOB_RETURN;
5714 * ipr_build_mode_sense - Builds a mode sense command
5715 * @ipr_cmd: ipr command struct
5716 * @res: resource entry struct
5717 * @parm: Byte 2 of mode sense command
5718 * @dma_addr: DMA address of mode sense buffer
5719 * @xfer_len: Size of DMA buffer
5724 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
5726 u8 parm, u32 dma_addr, u8 xfer_len)
5728 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5729 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5731 ioarcb->res_handle = res_handle;
5732 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
5733 ioarcb->cmd_pkt.cdb[2] = parm;
5734 ioarcb->cmd_pkt.cdb[4] = xfer_len;
5735 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5737 ioadl->flags_and_data_len =
5738 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
5739 ioadl->address = cpu_to_be32(dma_addr);
5740 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5741 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
5745 * ipr_reset_cmd_failed - Handle failure of IOA reset command
5746 * @ipr_cmd: ipr command struct
5748 * This function handles the failure of an IOA bringup command.
5753 static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
5755 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5756 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5758 dev_err(&ioa_cfg->pdev->dev,
5759 "0x%02X failed with IOASC: 0x%08X\n",
5760 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
5762 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5763 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5764 return IPR_RC_JOB_RETURN;
5768 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
5769 * @ipr_cmd: ipr command struct
5771 * This function handles the failure of a Mode Sense to the IOAFP.
5772 * Some adapters do not handle all mode pages.
5775 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5777 static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
5779 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5781 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
5782 ipr_cmd->job_step = ipr_setup_write_cache;
5783 return IPR_RC_JOB_CONTINUE;
5786 return ipr_reset_cmd_failed(ipr_cmd);
5790 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
5791 * @ipr_cmd: ipr command struct
5793 * This function send a Page 28 mode sense to the IOA to
5794 * retrieve SCSI bus attributes.
5799 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
5801 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5804 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
5805 0x28, ioa_cfg->vpd_cbs_dma +
5806 offsetof(struct ipr_misc_cbs, mode_pages),
5807 sizeof(struct ipr_mode_pages));
5809 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
5810 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
5812 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5815 return IPR_RC_JOB_RETURN;
5819 * ipr_init_res_table - Initialize the resource table
5820 * @ipr_cmd: ipr command struct
5822 * This function looks through the existing resource table, comparing
5823 * it with the config table. This function will take care of old/new
5824 * devices and schedule adding/removing them from the mid-layer
5828 * IPR_RC_JOB_CONTINUE
5830 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
5832 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5833 struct ipr_resource_entry *res, *temp;
5834 struct ipr_config_table_entry *cfgte;
5839 if (ioa_cfg->cfg_table->hdr.flags & IPR_UCODE_DOWNLOAD_REQ)
5840 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
5842 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
5843 list_move_tail(&res->queue, &old_res);
5845 for (i = 0; i < ioa_cfg->cfg_table->hdr.num_entries; i++) {
5846 cfgte = &ioa_cfg->cfg_table->dev[i];
5849 list_for_each_entry_safe(res, temp, &old_res, queue) {
5850 if (!memcmp(&res->cfgte.res_addr,
5851 &cfgte->res_addr, sizeof(cfgte->res_addr))) {
5852 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
5859 if (list_empty(&ioa_cfg->free_res_q)) {
5860 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
5865 res = list_entry(ioa_cfg->free_res_q.next,
5866 struct ipr_resource_entry, queue);
5867 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
5868 ipr_init_res_entry(res);
5873 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
5876 list_for_each_entry_safe(res, temp, &old_res, queue) {
5878 res->del_from_ml = 1;
5879 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
5880 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
5882 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
5886 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
5889 return IPR_RC_JOB_CONTINUE;
5893 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
5894 * @ipr_cmd: ipr command struct
5896 * This function sends a Query IOA Configuration command
5897 * to the adapter to retrieve the IOA configuration table.
5902 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
5904 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5905 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5906 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5907 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
5910 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
5911 ucode_vpd->major_release, ucode_vpd->card_type,
5912 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
5913 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5914 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5916 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
5917 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_config_table) >> 8) & 0xff;
5918 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_config_table) & 0xff;
5920 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5921 ioarcb->read_data_transfer_length =
5922 cpu_to_be32(sizeof(struct ipr_config_table));
5924 ioadl->address = cpu_to_be32(ioa_cfg->cfg_table_dma);
5925 ioadl->flags_and_data_len =
5926 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(struct ipr_config_table));
5928 ipr_cmd->job_step = ipr_init_res_table;
5930 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5933 return IPR_RC_JOB_RETURN;
5937 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
5938 * @ipr_cmd: ipr command struct
5940 * This utility function sends an inquiry to the adapter.
5945 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
5946 u32 dma_addr, u8 xfer_len)
5948 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5949 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5952 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5953 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5955 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
5956 ioarcb->cmd_pkt.cdb[1] = flags;
5957 ioarcb->cmd_pkt.cdb[2] = page;
5958 ioarcb->cmd_pkt.cdb[4] = xfer_len;
5960 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5961 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
5963 ioadl->address = cpu_to_be32(dma_addr);
5964 ioadl->flags_and_data_len =
5965 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
5967 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5972 * ipr_inquiry_page_supported - Is the given inquiry page supported
5973 * @page0: inquiry page 0 buffer
5976 * This function determines if the specified inquiry page is supported.
5979 * 1 if page is supported / 0 if not
5981 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
5985 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
5986 if (page0->page[i] == page)
5993 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
5994 * @ipr_cmd: ipr command struct
5996 * This function sends a Page 3 inquiry to the adapter
5997 * to retrieve software VPD information.
6000 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6002 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
6004 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6005 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
6009 if (!ipr_inquiry_page_supported(page0, 1))
6010 ioa_cfg->cache_state = CACHE_NONE;
6012 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
6014 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
6015 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
6016 sizeof(struct ipr_inquiry_page3));
6019 return IPR_RC_JOB_RETURN;
6023 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
6024 * @ipr_cmd: ipr command struct
6026 * This function sends a Page 0 inquiry to the adapter
6027 * to retrieve supported inquiry pages.
6030 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6032 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
6034 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6039 /* Grab the type out of the VPD and store it away */
6040 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
6042 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
6044 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
6046 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
6047 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
6048 sizeof(struct ipr_inquiry_page0));
6051 return IPR_RC_JOB_RETURN;
6055 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
6056 * @ipr_cmd: ipr command struct
6058 * This function sends a standard inquiry to the adapter.
6063 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
6065 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6068 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
6070 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
6071 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
6072 sizeof(struct ipr_ioa_vpd));
6075 return IPR_RC_JOB_RETURN;
6079 * ipr_ioafp_indentify_hrrq - Send Identify Host RRQ.
6080 * @ipr_cmd: ipr command struct
6082 * This function send an Identify Host Request Response Queue
6083 * command to establish the HRRQ with the adapter.
6088 static int ipr_ioafp_indentify_hrrq(struct ipr_cmnd *ipr_cmd)
6090 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6091 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6094 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
6096 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
6097 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6099 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6100 ioarcb->cmd_pkt.cdb[2] =
6101 ((u32) ioa_cfg->host_rrq_dma >> 24) & 0xff;
6102 ioarcb->cmd_pkt.cdb[3] =
6103 ((u32) ioa_cfg->host_rrq_dma >> 16) & 0xff;
6104 ioarcb->cmd_pkt.cdb[4] =
6105 ((u32) ioa_cfg->host_rrq_dma >> 8) & 0xff;
6106 ioarcb->cmd_pkt.cdb[5] =
6107 ((u32) ioa_cfg->host_rrq_dma) & 0xff;
6108 ioarcb->cmd_pkt.cdb[7] =
6109 ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
6110 ioarcb->cmd_pkt.cdb[8] =
6111 (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
6113 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
6115 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6118 return IPR_RC_JOB_RETURN;
6122 * ipr_reset_timer_done - Adapter reset timer function
6123 * @ipr_cmd: ipr command struct
6125 * Description: This function is used in adapter reset processing
6126 * for timing events. If the reset_cmd pointer in the IOA
6127 * config struct is not this adapter's we are doing nested
6128 * resets and fail_all_ops will take care of freeing the
6134 static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
6136 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6137 unsigned long lock_flags = 0;
6139 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6141 if (ioa_cfg->reset_cmd == ipr_cmd) {
6142 list_del(&ipr_cmd->queue);
6143 ipr_cmd->done(ipr_cmd);
6146 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6150 * ipr_reset_start_timer - Start a timer for adapter reset job
6151 * @ipr_cmd: ipr command struct
6152 * @timeout: timeout value
6154 * Description: This function is used in adapter reset processing
6155 * for timing events. If the reset_cmd pointer in the IOA
6156 * config struct is not this adapter's we are doing nested
6157 * resets and fail_all_ops will take care of freeing the
6163 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
6164 unsigned long timeout)
6166 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
6167 ipr_cmd->done = ipr_reset_ioa_job;
6169 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
6170 ipr_cmd->timer.expires = jiffies + timeout;
6171 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
6172 add_timer(&ipr_cmd->timer);
6176 * ipr_init_ioa_mem - Initialize ioa_cfg control block
6177 * @ioa_cfg: ioa cfg struct
6182 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
6184 memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
6186 /* Initialize Host RRQ pointers */
6187 ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
6188 ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
6189 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
6190 ioa_cfg->toggle_bit = 1;
6192 /* Zero out config table */
6193 memset(ioa_cfg->cfg_table, 0, sizeof(struct ipr_config_table));
6197 * ipr_reset_enable_ioa - Enable the IOA following a reset.
6198 * @ipr_cmd: ipr command struct
6200 * This function reinitializes some control blocks and
6201 * enables destructive diagnostics on the adapter.
6206 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
6208 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6209 volatile u32 int_reg;
6212 ipr_cmd->job_step = ipr_ioafp_indentify_hrrq;
6213 ipr_init_ioa_mem(ioa_cfg);
6215 ioa_cfg->allow_interrupts = 1;
6216 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
6218 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
6219 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
6220 ioa_cfg->regs.clr_interrupt_mask_reg);
6221 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
6222 return IPR_RC_JOB_CONTINUE;
6225 /* Enable destructive diagnostics on IOA */
6226 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg);
6228 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg);
6229 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
6231 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
6233 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
6234 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
6235 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
6236 ipr_cmd->done = ipr_reset_ioa_job;
6237 add_timer(&ipr_cmd->timer);
6238 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
6241 return IPR_RC_JOB_RETURN;
6245 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
6246 * @ipr_cmd: ipr command struct
6248 * This function is invoked when an adapter dump has run out
6249 * of processing time.
6252 * IPR_RC_JOB_CONTINUE
6254 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
6256 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6258 if (ioa_cfg->sdt_state == GET_DUMP)
6259 ioa_cfg->sdt_state = ABORT_DUMP;
6261 ipr_cmd->job_step = ipr_reset_alert;
6263 return IPR_RC_JOB_CONTINUE;
6267 * ipr_unit_check_no_data - Log a unit check/no data error log
6268 * @ioa_cfg: ioa config struct
6270 * Logs an error indicating the adapter unit checked, but for some
6271 * reason, we were unable to fetch the unit check buffer.
6276 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
6278 ioa_cfg->errors_logged++;
6279 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
6283 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
6284 * @ioa_cfg: ioa config struct
6286 * Fetches the unit check buffer from the adapter by clocking the data
6287 * through the mailbox register.
6292 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
6294 unsigned long mailbox;
6295 struct ipr_hostrcb *hostrcb;
6296 struct ipr_uc_sdt sdt;
6300 mailbox = readl(ioa_cfg->ioa_mailbox);
6302 if (!ipr_sdt_is_fmt2(mailbox)) {
6303 ipr_unit_check_no_data(ioa_cfg);
6307 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
6308 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
6309 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
6311 if (rc || (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE) ||
6312 !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY)) {
6313 ipr_unit_check_no_data(ioa_cfg);
6317 /* Find length of the first sdt entry (UC buffer) */
6318 length = (be32_to_cpu(sdt.entry[0].end_offset) -
6319 be32_to_cpu(sdt.entry[0].bar_str_offset)) & IPR_FMT2_MBX_ADDR_MASK;
6321 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
6322 struct ipr_hostrcb, queue);
6323 list_del(&hostrcb->queue);
6324 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
6326 rc = ipr_get_ldump_data_section(ioa_cfg,
6327 be32_to_cpu(sdt.entry[0].bar_str_offset),
6328 (__be32 *)&hostrcb->hcam,
6329 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
6332 ipr_handle_log_data(ioa_cfg, hostrcb);
6333 ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
6334 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
6335 ioa_cfg->sdt_state == GET_DUMP)
6336 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
6338 ipr_unit_check_no_data(ioa_cfg);
6340 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
6344 * ipr_reset_restore_cfg_space - Restore PCI config space.
6345 * @ipr_cmd: ipr command struct
6347 * Description: This function restores the saved PCI config space of
6348 * the adapter, fails all outstanding ops back to the callers, and
6349 * fetches the dump/unit check if applicable to this reset.
6352 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6354 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
6356 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6360 rc = pci_restore_state(ioa_cfg->pdev);
6362 if (rc != PCIBIOS_SUCCESSFUL) {
6363 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6364 return IPR_RC_JOB_CONTINUE;
6367 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
6368 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6369 return IPR_RC_JOB_CONTINUE;
6372 ipr_fail_all_ops(ioa_cfg);
6374 if (ioa_cfg->ioa_unit_checked) {
6375 ioa_cfg->ioa_unit_checked = 0;
6376 ipr_get_unit_check_buffer(ioa_cfg);
6377 ipr_cmd->job_step = ipr_reset_alert;
6378 ipr_reset_start_timer(ipr_cmd, 0);
6379 return IPR_RC_JOB_RETURN;
6382 if (ioa_cfg->in_ioa_bringdown) {
6383 ipr_cmd->job_step = ipr_ioa_bringdown_done;
6385 ipr_cmd->job_step = ipr_reset_enable_ioa;
6387 if (GET_DUMP == ioa_cfg->sdt_state) {
6388 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_TIMEOUT);
6389 ipr_cmd->job_step = ipr_reset_wait_for_dump;
6390 schedule_work(&ioa_cfg->work_q);
6391 return IPR_RC_JOB_RETURN;
6396 return IPR_RC_JOB_CONTINUE;
6400 * ipr_reset_bist_done - BIST has completed on the adapter.
6401 * @ipr_cmd: ipr command struct
6403 * Description: Unblock config space and resume the reset process.
6406 * IPR_RC_JOB_CONTINUE
6408 static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
6411 pci_unblock_user_cfg_access(ipr_cmd->ioa_cfg->pdev);
6412 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
6414 return IPR_RC_JOB_CONTINUE;
6418 * ipr_reset_start_bist - Run BIST on the adapter.
6419 * @ipr_cmd: ipr command struct
6421 * Description: This function runs BIST on the adapter, then delays 2 seconds.
6424 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6426 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
6428 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6432 pci_block_user_cfg_access(ioa_cfg->pdev);
6433 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
6435 if (rc != PCIBIOS_SUCCESSFUL) {
6436 pci_unblock_user_cfg_access(ipr_cmd->ioa_cfg->pdev);
6437 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6438 rc = IPR_RC_JOB_CONTINUE;
6440 ipr_cmd->job_step = ipr_reset_bist_done;
6441 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
6442 rc = IPR_RC_JOB_RETURN;
6450 * ipr_reset_allowed - Query whether or not IOA can be reset
6451 * @ioa_cfg: ioa config struct
6454 * 0 if reset not allowed / non-zero if reset is allowed
6456 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
6458 volatile u32 temp_reg;
6460 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
6461 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
6465 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
6466 * @ipr_cmd: ipr command struct
6468 * Description: This function waits for adapter permission to run BIST,
6469 * then runs BIST. If the adapter does not give permission after a
6470 * reasonable time, we will reset the adapter anyway. The impact of
6471 * resetting the adapter without warning the adapter is the risk of
6472 * losing the persistent error log on the adapter. If the adapter is
6473 * reset while it is writing to the flash on the adapter, the flash
6474 * segment will have bad ECC and be zeroed.
6477 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6479 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
6481 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6482 int rc = IPR_RC_JOB_RETURN;
6484 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
6485 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
6486 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
6488 ipr_cmd->job_step = ipr_reset_start_bist;
6489 rc = IPR_RC_JOB_CONTINUE;
6496 * ipr_reset_alert_part2 - Alert the adapter of a pending reset
6497 * @ipr_cmd: ipr command struct
6499 * Description: This function alerts the adapter that it will be reset.
6500 * If memory space is not currently enabled, proceed directly
6501 * to running BIST on the adapter. The timer must always be started
6502 * so we guarantee we do not run BIST from ipr_isr.
6507 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
6509 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6514 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
6516 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
6517 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
6518 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg);
6519 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
6521 ipr_cmd->job_step = ipr_reset_start_bist;
6524 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
6525 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
6528 return IPR_RC_JOB_RETURN;
6532 * ipr_reset_ucode_download_done - Microcode download completion
6533 * @ipr_cmd: ipr command struct
6535 * Description: This function unmaps the microcode download buffer.
6538 * IPR_RC_JOB_CONTINUE
6540 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
6542 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6543 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
6545 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
6546 sglist->num_sg, DMA_TO_DEVICE);
6548 ipr_cmd->job_step = ipr_reset_alert;
6549 return IPR_RC_JOB_CONTINUE;
6553 * ipr_reset_ucode_download - Download microcode to the adapter
6554 * @ipr_cmd: ipr command struct
6556 * Description: This function checks to see if it there is microcode
6557 * to download to the adapter. If there is, a download is performed.
6560 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6562 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
6564 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6565 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
6568 ipr_cmd->job_step = ipr_reset_alert;
6571 return IPR_RC_JOB_CONTINUE;
6573 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6574 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6575 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
6576 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
6577 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
6578 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
6579 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
6581 ipr_build_ucode_ioadl(ipr_cmd, sglist);
6582 ipr_cmd->job_step = ipr_reset_ucode_download_done;
6584 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
6585 IPR_WRITE_BUFFER_TIMEOUT);
6588 return IPR_RC_JOB_RETURN;
6592 * ipr_reset_shutdown_ioa - Shutdown the adapter
6593 * @ipr_cmd: ipr command struct
6595 * Description: This function issues an adapter shutdown of the
6596 * specified type to the specified adapter as part of the
6597 * adapter reset job.
6600 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6602 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
6604 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6605 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
6606 unsigned long timeout;
6607 int rc = IPR_RC_JOB_CONTINUE;
6610 if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
6611 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6612 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6613 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
6614 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
6616 if (shutdown_type == IPR_SHUTDOWN_ABBREV)
6617 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
6618 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
6619 timeout = IPR_INTERNAL_TIMEOUT;
6621 timeout = IPR_SHUTDOWN_TIMEOUT;
6623 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
6625 rc = IPR_RC_JOB_RETURN;
6626 ipr_cmd->job_step = ipr_reset_ucode_download;
6628 ipr_cmd->job_step = ipr_reset_alert;
6635 * ipr_reset_ioa_job - Adapter reset job
6636 * @ipr_cmd: ipr command struct
6638 * Description: This function is the job router for the adapter reset job.
6643 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
6646 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6649 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
6651 if (ioa_cfg->reset_cmd != ipr_cmd) {
6653 * We are doing nested adapter resets and this is
6654 * not the current reset job.
6656 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6660 if (IPR_IOASC_SENSE_KEY(ioasc)) {
6661 rc = ipr_cmd->job_step_failed(ipr_cmd);
6662 if (rc == IPR_RC_JOB_RETURN)
6666 ipr_reinit_ipr_cmnd(ipr_cmd);
6667 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
6668 rc = ipr_cmd->job_step(ipr_cmd);
6669 } while(rc == IPR_RC_JOB_CONTINUE);
6673 * _ipr_initiate_ioa_reset - Initiate an adapter reset
6674 * @ioa_cfg: ioa config struct
6675 * @job_step: first job step of reset job
6676 * @shutdown_type: shutdown type
6678 * Description: This function will initiate the reset of the given adapter
6679 * starting at the selected job step.
6680 * If the caller needs to wait on the completion of the reset,
6681 * the caller must sleep on the reset_wait_q.
6686 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
6687 int (*job_step) (struct ipr_cmnd *),
6688 enum ipr_shutdown_type shutdown_type)
6690 struct ipr_cmnd *ipr_cmd;
6692 ioa_cfg->in_reset_reload = 1;
6693 ioa_cfg->allow_cmds = 0;
6694 scsi_block_requests(ioa_cfg->host);
6696 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
6697 ioa_cfg->reset_cmd = ipr_cmd;
6698 ipr_cmd->job_step = job_step;
6699 ipr_cmd->u.shutdown_type = shutdown_type;
6701 ipr_reset_ioa_job(ipr_cmd);
6705 * ipr_initiate_ioa_reset - Initiate an adapter reset
6706 * @ioa_cfg: ioa config struct
6707 * @shutdown_type: shutdown type
6709 * Description: This function will initiate the reset of the given adapter.
6710 * If the caller needs to wait on the completion of the reset,
6711 * the caller must sleep on the reset_wait_q.
6716 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
6717 enum ipr_shutdown_type shutdown_type)
6719 if (ioa_cfg->ioa_is_dead)
6722 if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
6723 ioa_cfg->sdt_state = ABORT_DUMP;
6725 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
6726 dev_err(&ioa_cfg->pdev->dev,
6727 "IOA taken offline - error recovery failed\n");
6729 ioa_cfg->reset_retries = 0;
6730 ioa_cfg->ioa_is_dead = 1;
6732 if (ioa_cfg->in_ioa_bringdown) {
6733 ioa_cfg->reset_cmd = NULL;
6734 ioa_cfg->in_reset_reload = 0;
6735 ipr_fail_all_ops(ioa_cfg);
6736 wake_up_all(&ioa_cfg->reset_wait_q);
6738 spin_unlock_irq(ioa_cfg->host->host_lock);
6739 scsi_unblock_requests(ioa_cfg->host);
6740 spin_lock_irq(ioa_cfg->host->host_lock);
6743 ioa_cfg->in_ioa_bringdown = 1;
6744 shutdown_type = IPR_SHUTDOWN_NONE;
6748 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
6753 * ipr_reset_freeze - Hold off all I/O activity
6754 * @ipr_cmd: ipr command struct
6756 * Description: If the PCI slot is frozen, hold off all I/O
6757 * activity; then, as soon as the slot is available again,
6758 * initiate an adapter reset.
6760 static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
6762 /* Disallow new interrupts, avoid loop */
6763 ipr_cmd->ioa_cfg->allow_interrupts = 0;
6764 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
6765 ipr_cmd->done = ipr_reset_ioa_job;
6766 return IPR_RC_JOB_RETURN;
6770 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
6771 * @pdev: PCI device struct
6773 * Description: This routine is called to tell us that the PCI bus
6774 * is down. Can't do anything here, except put the device driver
6775 * into a holding pattern, waiting for the PCI bus to come back.
6777 static void ipr_pci_frozen(struct pci_dev *pdev)
6779 unsigned long flags = 0;
6780 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6782 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6783 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
6784 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6788 * ipr_pci_slot_reset - Called when PCI slot has been reset.
6789 * @pdev: PCI device struct
6791 * Description: This routine is called by the pci error recovery
6792 * code after the PCI slot has been reset, just before we
6793 * should resume normal operations.
6795 static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
6797 unsigned long flags = 0;
6798 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6800 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6801 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
6803 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6804 return PCI_ERS_RESULT_RECOVERED;
6808 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
6809 * @pdev: PCI device struct
6811 * Description: This routine is called when the PCI bus has
6812 * permanently failed.
6814 static void ipr_pci_perm_failure(struct pci_dev *pdev)
6816 unsigned long flags = 0;
6817 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6819 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6820 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
6821 ioa_cfg->sdt_state = ABORT_DUMP;
6822 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES;
6823 ioa_cfg->in_ioa_bringdown = 1;
6824 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
6825 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6829 * ipr_pci_error_detected - Called when a PCI error is detected.
6830 * @pdev: PCI device struct
6831 * @state: PCI channel state
6833 * Description: Called when a PCI error is detected.
6836 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
6838 static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
6839 pci_channel_state_t state)
6842 case pci_channel_io_frozen:
6843 ipr_pci_frozen(pdev);
6844 return PCI_ERS_RESULT_NEED_RESET;
6845 case pci_channel_io_perm_failure:
6846 ipr_pci_perm_failure(pdev);
6847 return PCI_ERS_RESULT_DISCONNECT;
6852 return PCI_ERS_RESULT_NEED_RESET;
6856 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
6857 * @ioa_cfg: ioa cfg struct
6859 * Description: This is the second phase of adapter intialization
6860 * This function takes care of initilizing the adapter to the point
6861 * where it can accept new commands.
6864 * 0 on sucess / -EIO on failure
6866 static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
6869 unsigned long host_lock_flags = 0;
6872 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
6873 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
6874 if (ioa_cfg->needs_hard_reset) {
6875 ioa_cfg->needs_hard_reset = 0;
6876 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
6878 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
6881 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
6882 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6883 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
6885 if (ioa_cfg->ioa_is_dead) {
6887 } else if (ipr_invalid_adapter(ioa_cfg)) {
6891 dev_err(&ioa_cfg->pdev->dev,
6892 "Adapter not supported in this hardware configuration.\n");
6895 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
6902 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
6903 * @ioa_cfg: ioa config struct
6908 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
6912 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
6913 if (ioa_cfg->ipr_cmnd_list[i])
6914 pci_pool_free(ioa_cfg->ipr_cmd_pool,
6915 ioa_cfg->ipr_cmnd_list[i],
6916 ioa_cfg->ipr_cmnd_list_dma[i]);
6918 ioa_cfg->ipr_cmnd_list[i] = NULL;
6921 if (ioa_cfg->ipr_cmd_pool)
6922 pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
6924 ioa_cfg->ipr_cmd_pool = NULL;
6928 * ipr_free_mem - Frees memory allocated for an adapter
6929 * @ioa_cfg: ioa cfg struct
6934 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
6938 kfree(ioa_cfg->res_entries);
6939 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
6940 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
6941 ipr_free_cmd_blks(ioa_cfg);
6942 pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
6943 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
6944 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_config_table),
6946 ioa_cfg->cfg_table_dma);
6948 for (i = 0; i < IPR_NUM_HCAMS; i++) {
6949 pci_free_consistent(ioa_cfg->pdev,
6950 sizeof(struct ipr_hostrcb),
6951 ioa_cfg->hostrcb[i],
6952 ioa_cfg->hostrcb_dma[i]);
6955 ipr_free_dump(ioa_cfg);
6956 kfree(ioa_cfg->trace);
6960 * ipr_free_all_resources - Free all allocated resources for an adapter.
6961 * @ipr_cmd: ipr command struct
6963 * This function frees all allocated resources for the
6964 * specified adapter.
6969 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
6971 struct pci_dev *pdev = ioa_cfg->pdev;
6974 free_irq(pdev->irq, ioa_cfg);
6975 iounmap(ioa_cfg->hdw_dma_regs);
6976 pci_release_regions(pdev);
6977 ipr_free_mem(ioa_cfg);
6978 scsi_host_put(ioa_cfg->host);
6979 pci_disable_device(pdev);
6984 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
6985 * @ioa_cfg: ioa config struct
6988 * 0 on success / -ENOMEM on allocation failure
6990 static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
6992 struct ipr_cmnd *ipr_cmd;
6993 struct ipr_ioarcb *ioarcb;
6994 dma_addr_t dma_addr;
6997 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
6998 sizeof(struct ipr_cmnd), 8, 0);
7000 if (!ioa_cfg->ipr_cmd_pool)
7003 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
7004 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
7007 ipr_free_cmd_blks(ioa_cfg);
7011 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
7012 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
7013 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
7015 ioarcb = &ipr_cmd->ioarcb;
7016 ioarcb->ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
7017 ioarcb->host_response_handle = cpu_to_be32(i << 2);
7018 ioarcb->write_ioadl_addr =
7019 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
7020 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
7021 ioarcb->ioasa_host_pci_addr =
7022 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioasa));
7023 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
7024 ipr_cmd->cmd_index = i;
7025 ipr_cmd->ioa_cfg = ioa_cfg;
7026 ipr_cmd->sense_buffer_dma = dma_addr +
7027 offsetof(struct ipr_cmnd, sense_buffer);
7029 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
7036 * ipr_alloc_mem - Allocate memory for an adapter
7037 * @ioa_cfg: ioa config struct
7040 * 0 on success / non-zero for error
7042 static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
7044 struct pci_dev *pdev = ioa_cfg->pdev;
7045 int i, rc = -ENOMEM;
7048 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
7049 IPR_MAX_PHYSICAL_DEVS, GFP_KERNEL);
7051 if (!ioa_cfg->res_entries)
7054 for (i = 0; i < IPR_MAX_PHYSICAL_DEVS; i++)
7055 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
7057 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
7058 sizeof(struct ipr_misc_cbs),
7059 &ioa_cfg->vpd_cbs_dma);
7061 if (!ioa_cfg->vpd_cbs)
7062 goto out_free_res_entries;
7064 if (ipr_alloc_cmd_blks(ioa_cfg))
7065 goto out_free_vpd_cbs;
7067 ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
7068 sizeof(u32) * IPR_NUM_CMD_BLKS,
7069 &ioa_cfg->host_rrq_dma);
7071 if (!ioa_cfg->host_rrq)
7072 goto out_ipr_free_cmd_blocks;
7074 ioa_cfg->cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
7075 sizeof(struct ipr_config_table),
7076 &ioa_cfg->cfg_table_dma);
7078 if (!ioa_cfg->cfg_table)
7079 goto out_free_host_rrq;
7081 for (i = 0; i < IPR_NUM_HCAMS; i++) {
7082 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
7083 sizeof(struct ipr_hostrcb),
7084 &ioa_cfg->hostrcb_dma[i]);
7086 if (!ioa_cfg->hostrcb[i])
7087 goto out_free_hostrcb_dma;
7089 ioa_cfg->hostrcb[i]->hostrcb_dma =
7090 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
7091 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
7092 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
7095 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
7096 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
7098 if (!ioa_cfg->trace)
7099 goto out_free_hostrcb_dma;
7106 out_free_hostrcb_dma:
7108 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
7109 ioa_cfg->hostrcb[i],
7110 ioa_cfg->hostrcb_dma[i]);
7112 pci_free_consistent(pdev, sizeof(struct ipr_config_table),
7113 ioa_cfg->cfg_table, ioa_cfg->cfg_table_dma);
7115 pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
7116 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
7117 out_ipr_free_cmd_blocks:
7118 ipr_free_cmd_blks(ioa_cfg);
7120 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
7121 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
7122 out_free_res_entries:
7123 kfree(ioa_cfg->res_entries);
7128 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
7129 * @ioa_cfg: ioa config struct
7134 static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
7138 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
7139 ioa_cfg->bus_attr[i].bus = i;
7140 ioa_cfg->bus_attr[i].qas_enabled = 0;
7141 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
7142 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
7143 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
7145 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
7150 * ipr_init_ioa_cfg - Initialize IOA config struct
7151 * @ioa_cfg: ioa config struct
7152 * @host: scsi host struct
7153 * @pdev: PCI dev struct
7158 static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
7159 struct Scsi_Host *host, struct pci_dev *pdev)
7161 const struct ipr_interrupt_offsets *p;
7162 struct ipr_interrupts *t;
7165 ioa_cfg->host = host;
7166 ioa_cfg->pdev = pdev;
7167 ioa_cfg->log_level = ipr_log_level;
7168 ioa_cfg->doorbell = IPR_DOORBELL;
7169 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
7170 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
7171 sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
7172 sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
7173 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
7174 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
7175 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
7176 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
7178 INIT_LIST_HEAD(&ioa_cfg->free_q);
7179 INIT_LIST_HEAD(&ioa_cfg->pending_q);
7180 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
7181 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
7182 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
7183 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
7184 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
7185 init_waitqueue_head(&ioa_cfg->reset_wait_q);
7186 ioa_cfg->sdt_state = INACTIVE;
7187 if (ipr_enable_cache)
7188 ioa_cfg->cache_state = CACHE_ENABLED;
7190 ioa_cfg->cache_state = CACHE_DISABLED;
7192 ipr_initialize_bus_attr(ioa_cfg);
7194 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
7195 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
7196 host->max_channel = IPR_MAX_BUS_TO_SCAN;
7197 host->unique_id = host->host_no;
7198 host->max_cmd_len = IPR_MAX_CDB_LEN;
7199 pci_set_drvdata(pdev, ioa_cfg);
7201 p = &ioa_cfg->chip_cfg->regs;
7203 base = ioa_cfg->hdw_dma_regs;
7205 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
7206 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
7207 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
7208 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
7209 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
7210 t->ioarrin_reg = base + p->ioarrin_reg;
7211 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
7212 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
7213 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
7217 * ipr_get_chip_cfg - Find adapter chip configuration
7218 * @dev_id: PCI device id struct
7221 * ptr to chip config on success / NULL on failure
7223 static const struct ipr_chip_cfg_t * __devinit
7224 ipr_get_chip_cfg(const struct pci_device_id *dev_id)
7228 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
7229 if (ipr_chip[i].vendor == dev_id->vendor &&
7230 ipr_chip[i].device == dev_id->device)
7231 return ipr_chip[i].cfg;
7236 * ipr_probe_ioa - Allocates memory and does first stage of initialization
7237 * @pdev: PCI device struct
7238 * @dev_id: PCI device id struct
7241 * 0 on success / non-zero on failure
7243 static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
7244 const struct pci_device_id *dev_id)
7246 struct ipr_ioa_cfg *ioa_cfg;
7247 struct Scsi_Host *host;
7248 unsigned long ipr_regs_pci;
7249 void __iomem *ipr_regs;
7250 int rc = PCIBIOS_SUCCESSFUL;
7251 volatile u32 mask, uproc;
7255 if ((rc = pci_enable_device(pdev))) {
7256 dev_err(&pdev->dev, "Cannot enable adapter\n");
7260 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
7262 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
7265 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
7270 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
7271 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
7272 ata_host_init(&ioa_cfg->ata_host, &pdev->dev,
7273 sata_port_info.flags, &ipr_sata_ops);
7275 ioa_cfg->chip_cfg = ipr_get_chip_cfg(dev_id);
7277 if (!ioa_cfg->chip_cfg) {
7278 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
7279 dev_id->vendor, dev_id->device);
7280 goto out_scsi_host_put;
7283 if (ipr_transop_timeout)
7284 ioa_cfg->transop_timeout = ipr_transop_timeout;
7285 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
7286 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
7288 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
7290 ipr_regs_pci = pci_resource_start(pdev, 0);
7292 rc = pci_request_regions(pdev, IPR_NAME);
7295 "Couldn't register memory range of registers\n");
7296 goto out_scsi_host_put;
7299 ipr_regs = ioremap(ipr_regs_pci, pci_resource_len(pdev, 0));
7303 "Couldn't map memory range of registers\n");
7305 goto out_release_regions;
7308 ioa_cfg->hdw_dma_regs = ipr_regs;
7309 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
7310 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
7312 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
7314 pci_set_master(pdev);
7316 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
7318 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
7322 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
7323 ioa_cfg->chip_cfg->cache_line_size);
7325 if (rc != PCIBIOS_SUCCESSFUL) {
7326 dev_err(&pdev->dev, "Write of cache line size failed\n");
7331 /* Save away PCI config space for use following IOA reset */
7332 rc = pci_save_state(pdev);
7334 if (rc != PCIBIOS_SUCCESSFUL) {
7335 dev_err(&pdev->dev, "Failed to save PCI config space\n");
7340 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
7343 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
7346 rc = ipr_alloc_mem(ioa_cfg);
7349 "Couldn't allocate enough memory for device driver!\n");
7354 * If HRRQ updated interrupt is not masked, or reset alert is set,
7355 * the card is in an unknown state and needs a hard reset
7357 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7358 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
7359 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
7360 ioa_cfg->needs_hard_reset = 1;
7362 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
7363 rc = request_irq(pdev->irq, ipr_isr, IRQF_SHARED, IPR_NAME, ioa_cfg);
7366 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
7371 spin_lock(&ipr_driver_lock);
7372 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
7373 spin_unlock(&ipr_driver_lock);
7380 ipr_free_mem(ioa_cfg);
7383 out_release_regions:
7384 pci_release_regions(pdev);
7386 scsi_host_put(host);
7388 pci_disable_device(pdev);
7393 * ipr_scan_vsets - Scans for VSET devices
7394 * @ioa_cfg: ioa config struct
7396 * Description: Since the VSET resources do not follow SAM in that we can have
7397 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
7402 static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
7406 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
7407 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
7408 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
7412 * ipr_initiate_ioa_bringdown - Bring down an adapter
7413 * @ioa_cfg: ioa config struct
7414 * @shutdown_type: shutdown type
7416 * Description: This function will initiate bringing down the adapter.
7417 * This consists of issuing an IOA shutdown to the adapter
7418 * to flush the cache, and running BIST.
7419 * If the caller needs to wait on the completion of the reset,
7420 * the caller must sleep on the reset_wait_q.
7425 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
7426 enum ipr_shutdown_type shutdown_type)
7429 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
7430 ioa_cfg->sdt_state = ABORT_DUMP;
7431 ioa_cfg->reset_retries = 0;
7432 ioa_cfg->in_ioa_bringdown = 1;
7433 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
7438 * __ipr_remove - Remove a single adapter
7439 * @pdev: pci device struct
7441 * Adapter hot plug remove entry point.
7446 static void __ipr_remove(struct pci_dev *pdev)
7448 unsigned long host_lock_flags = 0;
7449 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7452 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7453 while(ioa_cfg->in_reset_reload) {
7454 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7455 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7456 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7459 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
7461 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7462 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7463 flush_scheduled_work();
7464 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7466 spin_lock(&ipr_driver_lock);
7467 list_del(&ioa_cfg->queue);
7468 spin_unlock(&ipr_driver_lock);
7470 if (ioa_cfg->sdt_state == ABORT_DUMP)
7471 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7472 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7474 ipr_free_all_resources(ioa_cfg);
7480 * ipr_remove - IOA hot plug remove entry point
7481 * @pdev: pci device struct
7483 * Adapter hot plug remove entry point.
7488 static void ipr_remove(struct pci_dev *pdev)
7490 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7494 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7496 ipr_remove_dump_file(&ioa_cfg->host->shost_classdev.kobj,
7498 scsi_remove_host(ioa_cfg->host);
7506 * ipr_probe - Adapter hot plug add entry point
7509 * 0 on success / non-zero on failure
7511 static int __devinit ipr_probe(struct pci_dev *pdev,
7512 const struct pci_device_id *dev_id)
7514 struct ipr_ioa_cfg *ioa_cfg;
7517 rc = ipr_probe_ioa(pdev, dev_id);
7522 ioa_cfg = pci_get_drvdata(pdev);
7523 rc = ipr_probe_ioa_part2(ioa_cfg);
7530 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
7537 rc = ipr_create_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7541 scsi_remove_host(ioa_cfg->host);
7546 rc = ipr_create_dump_file(&ioa_cfg->host->shost_classdev.kobj,
7550 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7552 scsi_remove_host(ioa_cfg->host);
7557 scsi_scan_host(ioa_cfg->host);
7558 ipr_scan_vsets(ioa_cfg);
7559 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
7560 ioa_cfg->allow_ml_add_del = 1;
7561 ioa_cfg->host->max_channel = IPR_VSET_BUS;
7562 schedule_work(&ioa_cfg->work_q);
7567 * ipr_shutdown - Shutdown handler.
7568 * @pdev: pci device struct
7570 * This function is invoked upon system shutdown/reboot. It will issue
7571 * an adapter shutdown to the adapter to flush the write cache.
7576 static void ipr_shutdown(struct pci_dev *pdev)
7578 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7579 unsigned long lock_flags = 0;
7581 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7582 while(ioa_cfg->in_reset_reload) {
7583 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7584 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7585 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7588 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
7589 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7590 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7593 static struct pci_device_id ipr_pci_table[] __devinitdata = {
7594 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7595 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
7596 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7597 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
7598 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7599 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
7600 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7601 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
7602 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7603 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
7604 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7605 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
7606 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7607 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
7608 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7609 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
7610 IPR_USE_LONG_TRANSOP_TIMEOUT },
7611 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7612 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
7613 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7614 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0, 0 },
7615 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7616 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
7617 IPR_USE_LONG_TRANSOP_TIMEOUT },
7618 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7619 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
7620 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7621 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0, 0 },
7622 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7623 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
7624 IPR_USE_LONG_TRANSOP_TIMEOUT },
7625 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7626 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0, 0 },
7627 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7628 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575D, 0, 0,
7629 IPR_USE_LONG_TRANSOP_TIMEOUT },
7630 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7631 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
7632 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7633 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
7634 IPR_USE_LONG_TRANSOP_TIMEOUT },
7635 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
7636 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
7637 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7638 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
7639 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7640 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
7641 IPR_USE_LONG_TRANSOP_TIMEOUT },
7642 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7643 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
7644 IPR_USE_LONG_TRANSOP_TIMEOUT },
7645 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SCAMP_E,
7646 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0,
7647 IPR_USE_LONG_TRANSOP_TIMEOUT },
7650 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
7652 static struct pci_error_handlers ipr_err_handler = {
7653 .error_detected = ipr_pci_error_detected,
7654 .slot_reset = ipr_pci_slot_reset,
7657 static struct pci_driver ipr_driver = {
7659 .id_table = ipr_pci_table,
7661 .remove = ipr_remove,
7662 .shutdown = ipr_shutdown,
7663 .err_handler = &ipr_err_handler,
7664 .dynids.use_driver_data = 1
7668 * ipr_init - Module entry point
7671 * 0 on success / negative value on failure
7673 static int __init ipr_init(void)
7675 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
7676 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
7678 return pci_register_driver(&ipr_driver);
7682 * ipr_exit - Module unload
7684 * Module unload entry point.
7689 static void __exit ipr_exit(void)
7691 pci_unregister_driver(&ipr_driver);
7694 module_init(ipr_init);
7695 module_exit(ipr_exit);